Sanity checking for frame and texuture hints from filenames.
This commit is contained in:
@@ -26,8 +26,15 @@ static void GetResolutionFromFileName( RString sPath, int &iWidth, int &iHeight
|
|||||||
if( !re.Compare(sPath, asMatches) )
|
if( !re.Compare(sPath, asMatches) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
iWidth = StringToInt( asMatches[0] );
|
// Check for nonsense values. Some people might not intend the hint. -Kyz
|
||||||
iHeight = StringToInt( asMatches[1] );
|
int maybe_width= StringToInt(asMatches[0]);
|
||||||
|
int maybe_height= StringToInt(asMatches[1]);
|
||||||
|
if(maybe_width <= 0 || maybe_height <= 0 || maybe_width > iWidth || maybe_height > iHeight)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
iWidth = maybe_width;
|
||||||
|
iHeight = maybe_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
RageBitmapTexture::RageBitmapTexture( RageTextureID name ) :
|
RageBitmapTexture::RageBitmapTexture( RageTextureID name ) :
|
||||||
|
|||||||
+23
-4
@@ -22,7 +22,7 @@ RageTexture::~RageTexture()
|
|||||||
|
|
||||||
void RageTexture::CreateFrameRects()
|
void RageTexture::CreateFrameRects()
|
||||||
{
|
{
|
||||||
GetFrameDimensionsFromFileName( GetID().filename, &m_iFramesWide, &m_iFramesHigh );
|
GetFrameDimensionsFromFileName( GetID().filename, &m_iFramesWide, &m_iFramesHigh, m_iSourceWidth, m_iSourceHeight );
|
||||||
|
|
||||||
// Fill in the m_FrameRects with the bounds of each frame in the animation.
|
// Fill in the m_FrameRects with the bounds of each frame in the animation.
|
||||||
m_TextureCoordRects.clear();
|
m_TextureCoordRects.clear();
|
||||||
@@ -42,7 +42,7 @@ void RageTexture::CreateFrameRects()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RageTexture::GetFrameDimensionsFromFileName( RString sPath, int* piFramesWide, int* piFramesHigh )
|
void RageTexture::GetFrameDimensionsFromFileName( RString sPath, int* piFramesWide, int* piFramesHigh, int source_width, int source_height )
|
||||||
{
|
{
|
||||||
static Regex match( " ([0-9]+)x([0-9]+)([\\. ]|$)" );
|
static Regex match( " ([0-9]+)x([0-9]+)([\\. ]|$)" );
|
||||||
vector<RString> asMatch;
|
vector<RString> asMatch;
|
||||||
@@ -51,8 +51,27 @@ void RageTexture::GetFrameDimensionsFromFileName( RString sPath, int* piFramesWi
|
|||||||
*piFramesWide = *piFramesHigh = 1;
|
*piFramesWide = *piFramesHigh = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
*piFramesWide = StringToInt(asMatch[0]);
|
// Check for nonsense values. Some people might not intend the hint. -Kyz
|
||||||
*piFramesHigh = StringToInt(asMatch[1]);
|
int maybe_width= StringToInt(asMatch[0]);
|
||||||
|
int maybe_height= StringToInt(asMatch[1]);
|
||||||
|
if(maybe_width <= 0 || maybe_height <= 0)
|
||||||
|
{
|
||||||
|
*piFramesWide = *piFramesHigh = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Font.cpp uses this function, but can't pass in a texture size. Other
|
||||||
|
// textures can pass in a size though, and having more frames than pixels
|
||||||
|
// makes no sense. -Kyz
|
||||||
|
if(source_width > 0 && source_height > 0)
|
||||||
|
{
|
||||||
|
if(maybe_width > source_width || maybe_height > source_height)
|
||||||
|
{
|
||||||
|
*piFramesWide = *piFramesHigh = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*piFramesWide = maybe_width;
|
||||||
|
*piFramesHigh = maybe_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
const RectF *RageTexture::GetTextureCoordRect( int iFrameNo ) const
|
const RectF *RageTexture::GetTextureCoordRect( int iFrameNo ) const
|
||||||
|
|||||||
+1
-1
@@ -61,7 +61,7 @@ public:
|
|||||||
// The ID that we were asked to load:
|
// The ID that we were asked to load:
|
||||||
const RageTextureID &GetID() const { return m_ID; }
|
const RageTextureID &GetID() const { return m_ID; }
|
||||||
|
|
||||||
static void GetFrameDimensionsFromFileName( RString sPath, int* puFramesWide, int* puFramesHigh );
|
static void GetFrameDimensionsFromFileName( RString sPath, int* puFramesWide, int* puFramesHigh, int source_width= 0, int source_height= 0 );
|
||||||
|
|
||||||
// Lua
|
// Lua
|
||||||
virtual void PushSelf( lua_State *L );
|
virtual void PushSelf( lua_State *L );
|
||||||
|
|||||||
Reference in New Issue
Block a user