Files
itgmania212121/stepmania/src/RageTexture.cpp
T

139 lines
4.5 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
2001-11-03 10:52:42 +00:00
#include "RageTexture.h"
#include "RageUtil.h"
2002-12-30 03:35:58 +00:00
#include "RageTextureManager.h"
2004-04-05 05:22:32 +00:00
#include <cstring>
2001-11-03 10:52:42 +00:00
2003-01-09 02:55:16 +00:00
RageTexture::RageTexture( RageTextureID name ):
m_ID(name)
2001-11-03 10:52:42 +00:00
{
// LOG->Trace( "RageTexture::RageTexture()" );
2001-11-03 10:52:42 +00:00
m_iRefCount = 1;
2003-06-10 19:24:00 +00:00
m_bWasUsed = false;
2001-11-03 10:52:42 +00:00
2003-05-22 05:28:37 +00:00
// SetActualID();
m_iSourceWidth = m_iSourceHeight = 0;
m_iTextureWidth = m_iTextureHeight = 0;
m_iImageWidth = m_iImageHeight = 0;
m_iFramesWide = m_iFramesHigh = 0;
2001-11-03 10:52:42 +00:00
}
/* Set the initial ActualID; this is what the actual texture will start
* from. */
2003-05-22 05:28:37 +00:00
//void RageTexture::SetActualID()
//{
// m_ActualID = m_ID;
//
// /* Texture color depth preference can be overridden. */
// if(m_ID.iColorDepth == -1)
// m_ActualID.iColorDepth = TEXTUREMAN->GetTextureColorDepth();
//
// /* The max texture size can never be higher than the preference,
// * since it might be set to something to fix driver problems. */
// m_ActualID.iMaxSize = min(m_ActualID.iMaxSize, TEXTUREMAN->GetMaxTextureResolution());
//}
2001-11-03 10:52:42 +00:00
RageTexture::~RageTexture()
{
}
void RageTexture::CreateFrameRects()
2001-11-03 10:52:42 +00:00
{
2003-06-05 19:29:27 +00:00
GetFrameDimensionsFromFileName( GetID().filename, &m_iFramesWide, &m_iFramesHigh );
2001-11-25 04:31:44 +00:00
2001-11-03 10:52:42 +00:00
///////////////////////////////////
// Fill in the m_FrameRects with the bounds of each frame in the animation.
///////////////////////////////////
2002-10-24 20:15:24 +00:00
m_TextureCoordRects.clear();
2002-05-28 20:01:22 +00:00
for( int j=0; j<m_iFramesHigh; j++ ) // traverse along Y
2001-11-03 10:52:42 +00:00
{
for( int i=0; i<m_iFramesWide; i++ ) // traverse along X (important that this is the inner loop)
2001-11-03 10:52:42 +00:00
{
2002-10-31 06:00:30 +00:00
RectF frect( (i+0)/(float)m_iFramesWide*m_iImageWidth /(float)m_iTextureWidth, // these will all be between 0.0 and 1.0
(j+0)/(float)m_iFramesHigh*m_iImageHeight/(float)m_iTextureHeight,
(i+1)/(float)m_iFramesWide*m_iImageWidth /(float)m_iTextureWidth,
(j+1)/(float)m_iFramesHigh*m_iImageHeight/(float)m_iTextureHeight );
2002-10-31 04:23:39 +00:00
m_TextureCoordRects.push_back( frect ); // the index of this array element will be (i + j*m_iFramesWide)
2001-11-03 10:52:42 +00:00
//LOG->Trace( "Adding frect%d %f %f %f %f", (i + j*m_iFramesWide), frect.left, frect.top, frect.right, frect.bottom );
2001-11-03 10:52:42 +00:00
}
}
}
void RageTexture::GetFrameDimensionsFromFileName( CString sPath, int* piFramesWide, int* piFramesHigh )
2001-11-03 10:52:42 +00:00
{
*piFramesWide = *piFramesHigh = 1; // set default values in case we don't find the dimension in the file name
2001-12-28 10:15:59 +00:00
sPath.MakeLower();
2003-10-29 21:00:04 +00:00
const CString sFName = SetExtension( sPath, "" );
2001-12-28 10:15:59 +00:00
2002-01-28 21:24:17 +00:00
CStringArray arrayBits;
split( sFName, " ", arrayBits, false );
2001-12-28 10:15:59 +00:00
/* XXX: allow dims to be in parens */
for( unsigned i=0; i<arrayBits.size(); i++ )
2002-01-28 21:24:17 +00:00
{
CString &sBit = arrayBits[ i ];
// Test to see if it looks like "%ux%u" (e.g. 16x8)
2001-12-28 10:15:59 +00:00
2002-01-28 21:24:17 +00:00
CStringArray arrayDimensionsBits;
split( sBit, "x", arrayDimensionsBits, false );
2001-12-28 10:15:59 +00:00
if( arrayDimensionsBits.size() != 2 )
2002-01-28 21:24:17 +00:00
continue;
else if( !IsAnInt(arrayDimensionsBits[0]) || !IsAnInt(arrayDimensionsBits[1]) )
continue;
2001-12-28 10:15:59 +00:00
*piFramesWide = atoi(arrayDimensionsBits[0]);
*piFramesHigh = atoi(arrayDimensionsBits[1]);
2001-12-28 10:15:59 +00:00
return;
}
2002-05-27 08:23:27 +00:00
}
2003-01-06 11:14:43 +00:00
int RageTexture::GetFrameCountFromFileName( CString sPath )
{
int wide, high;
GetFrameDimensionsFromFileName(sPath, &wide, &high );
return wide*high;
}
const RectF *RageTexture::GetTextureCoordRect( int frameNo ) const
{
return &m_TextureCoordRects[frameNo];
}
2004-05-06 02:40:33 +00:00
/*
* Copyright (c) 2001-2004 Chris Danford
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/