add pre-parsing for ActorCommands (though not yet used in ThemeManager)
This commit is contained in:
+10
-62
@@ -700,71 +700,24 @@ void Actor::AddRotationR( float rot )
|
||||
RageQuatMultiply( &DestTweenState().quat, DestTweenState().quat, RageQuatFromR(rot) );
|
||||
}
|
||||
|
||||
float Actor::Command( CString sCommandString )
|
||||
float Actor::Command( CString sCommands )
|
||||
{
|
||||
// OPTIMIZATION OPPORTUNITY: sCommandString could be parsed more efficiently.
|
||||
sCommands.MakeLower();
|
||||
|
||||
sCommandString.MakeLower();
|
||||
vector<ParsedCommand> vCommands;
|
||||
ParseCommands( sCommands, vCommands );
|
||||
|
||||
CStringArray asCommands;
|
||||
split( sCommandString, ";", asCommands, true );
|
||||
|
||||
for( unsigned c=0; c<asCommands.size(); c++ )
|
||||
{
|
||||
CStringArray asTokens;
|
||||
split( asCommands[c], ",", asTokens, true );
|
||||
|
||||
for(unsigned d=0; d < asTokens.size(); d++)
|
||||
{
|
||||
TrimLeft(asTokens[d]);
|
||||
TrimRight(asTokens[d]);
|
||||
}
|
||||
|
||||
if( asTokens[0].size() == 0 )
|
||||
continue;
|
||||
|
||||
this->HandleCommand( asTokens );
|
||||
}
|
||||
for( int i=0; i<vCommands.size(); i++ )
|
||||
this->HandleCommand( vCommands[i] );
|
||||
|
||||
return GetTweenTimeLeft();
|
||||
}
|
||||
|
||||
#define sParam(i) (GetParam(asTokens,i,iMaxIndexAccessed))
|
||||
#define fParam(i) ((float)atof(sParam(i)))
|
||||
#define iParam(i) (atoi(sParam(i)))
|
||||
#define bParam(i) (iParam(i)!=0)
|
||||
#define cParam(i) (ColorParam(asTokens,i,iMaxIndexAccessed))
|
||||
|
||||
inline CString GetParam( const CStringArray& asTokens, int iIndex, int& iMaxIndexAccessed )
|
||||
void Actor::HandleCommand( const ParsedCommand &command )
|
||||
{
|
||||
iMaxIndexAccessed = max( iIndex, iMaxIndexAccessed );
|
||||
if( iIndex < int(asTokens.size()) )
|
||||
return asTokens[iIndex];
|
||||
else
|
||||
return "";
|
||||
}
|
||||
HandleParams;
|
||||
|
||||
inline RageColor ColorParam( const CStringArray& asTokens, int iIndex, int& iMaxIndexAccessed )
|
||||
{
|
||||
const CString first = GetParam( asTokens, iIndex, iMaxIndexAccessed );
|
||||
if( first == "" )
|
||||
return RageColor( 1,1,1,1 );
|
||||
|
||||
if( (first[0] >= '0' && first[0] <= '9') || first[0] == '.' )
|
||||
return RageColor( fParam(iIndex+0),fParam(iIndex+1),fParam(iIndex+2),fParam(iIndex+3) );
|
||||
|
||||
RageColor ret;
|
||||
if( !ret.FromString( first ) )
|
||||
return RageColor( 1,1,1,1 );
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Actor::HandleCommand( const CStringArray &asTokens )
|
||||
{
|
||||
int iMaxIndexAccessed = 0;
|
||||
|
||||
const CString& sName = asTokens[0];
|
||||
const CString& sName = sParam(0);
|
||||
|
||||
// Commands that go in the tweening queue:
|
||||
if ( sName=="sleep" ) { BeginTweening( fParam(1), TWEEN_LINEAR ); BeginTweening( 0, TWEEN_LINEAR ); }
|
||||
@@ -862,12 +815,7 @@ void Actor::HandleCommand( const CStringArray &asTokens )
|
||||
HOOKS->MessageBoxOK( sError );
|
||||
}
|
||||
|
||||
if( iMaxIndexAccessed != (int)asTokens.size()-1 )
|
||||
{
|
||||
CString sError = ssprintf( "Actor::HandleCommand: Wrong number of parameters in command '%s'. Expected %d but there are %d.", join(",",asTokens).c_str(), iMaxIndexAccessed+1, (int)asTokens.size() );
|
||||
LOG->Warn( sError );
|
||||
HOOKS->MessageBoxOK( sError );
|
||||
}
|
||||
CheckHandledParams;
|
||||
}
|
||||
|
||||
float Actor::GetCommandLength( CString command )
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
*/
|
||||
|
||||
#include "RageTypes.h"
|
||||
#include "ActorCommands.h" // for ParsedCommand
|
||||
|
||||
class Actor
|
||||
{
|
||||
@@ -291,8 +292,8 @@ public:
|
||||
void FadeOn( float fSleepSeconds, CString sFadeString, float fFadeSeconds ) { Fade(fSleepSeconds,sFadeString,fFadeSeconds,false); };
|
||||
void FadeOff( float fSleepSeconds, CString sFadeString, float fFadeSeconds ) { Fade(fSleepSeconds,sFadeString,fFadeSeconds,true); };
|
||||
|
||||
float Command( CString sCommandString ); // return length in seconds to execute command
|
||||
virtual void HandleCommand( const CStringArray &asTokens ); // derivable
|
||||
float Command( CString sCommands ); // return length in seconds to execute command
|
||||
virtual void HandleCommand( const ParsedCommand &command ); // derivable
|
||||
static float GetCommandLength( CString command );
|
||||
|
||||
virtual void SetState( int iNewState ) {};
|
||||
|
||||
@@ -133,14 +133,6 @@ Actor* MakeActor( RageTextureID ID )
|
||||
ID.filename.c_str(), sExt.c_str() );
|
||||
}
|
||||
|
||||
void IncorrectActorParametersWarning( const CStringArray &asTokens, int iMaxIndexAccessed, int size )
|
||||
{
|
||||
const CString sError = ssprintf( "Actor::HandleCommand: Wrong number of parameters in command '%s'. Expected %d but there are %d.",
|
||||
join(",",asTokens).c_str(), iMaxIndexAccessed+1, size );
|
||||
LOG->Warn( sError );
|
||||
HOOKS->MessageBoxOK( sError );
|
||||
}
|
||||
|
||||
void UtilSetXY( Actor& actor, CString sClassName )
|
||||
{
|
||||
ASSERT( !actor.GetID().empty() );
|
||||
@@ -169,3 +161,4 @@ float UtilCommand( Actor& actor, CString sClassName, CString sCommandName )
|
||||
|
||||
return max( ret, actor.Command( THEME->GetMetric(sClassName,actor.GetID()+sCommandName+"Command") ) );
|
||||
}
|
||||
|
||||
|
||||
@@ -70,23 +70,4 @@ protected:
|
||||
Actor* m_pActor;
|
||||
};
|
||||
|
||||
|
||||
/* Actor command parsing helpers. */
|
||||
#define HandleParams int iMaxIndexAccessed = 0;
|
||||
#define sParam(i) (GetParam(asTokens,i,iMaxIndexAccessed))
|
||||
#define fParam(i) ((float)atof(sParam(i)))
|
||||
#define iParam(i) (atoi(sParam(i)))
|
||||
#define bParam(i) (iParam(i)!=0)
|
||||
#define CheckHandledParams if( iMaxIndexAccessed != (int)asTokens.size()-1 ) { IncorrectActorParametersWarning( asTokens, iMaxIndexAccessed, asTokens.size() ); }
|
||||
void IncorrectActorParametersWarning( const CStringArray &asTokens, int iMaxIndexAccessed, int size );
|
||||
inline CString GetParam( const CStringArray& sParams, int iIndex, int& iMaxIndexAccessed )
|
||||
{
|
||||
iMaxIndexAccessed = max( iIndex, iMaxIndexAccessed );
|
||||
if( iIndex < int(sParams.size()) )
|
||||
return sParams[iIndex];
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -245,16 +245,14 @@ void BGAnimation::PlayCommand( const CString &cmd )
|
||||
m_Layers[i]->PlayCommand( cmd );
|
||||
}
|
||||
|
||||
void BGAnimation::HandleCommand( const CStringArray &asTokens )
|
||||
void BGAnimation::HandleCommand( const ParsedCommand &command )
|
||||
{
|
||||
HandleParams;
|
||||
|
||||
const CString& sName = asTokens[0];
|
||||
|
||||
if( sName=="playcommand" ) PlayCommand( sParam(1) );
|
||||
if( sParam(0)=="playcommand" ) PlayCommand( sParam(1) );
|
||||
else
|
||||
{
|
||||
Actor::HandleCommand( asTokens );
|
||||
Actor::HandleCommand( command );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
|
||||
float GetLengthSeconds() const { return m_fLengthSeconds; }
|
||||
|
||||
virtual void HandleCommand( const CStringArray &asTokens );
|
||||
virtual void HandleCommand( const ParsedCommand &command );
|
||||
void PlayOffCommand() { PlayCommand("Off"); }
|
||||
void PlayCommand( const CString &cmd );
|
||||
|
||||
|
||||
@@ -448,11 +448,11 @@ void BitmapText::SetVertAlign( VertAlign va )
|
||||
BuildChars();
|
||||
}
|
||||
|
||||
void BitmapText::HandleCommand( const CStringArray &asTokens )
|
||||
void BitmapText::HandleCommand( const ParsedCommand &command )
|
||||
{
|
||||
HandleParams;
|
||||
|
||||
const CString& sName = asTokens[0];
|
||||
const CString& sName = sParam(0);
|
||||
|
||||
// Commands that go in the tweening queue:
|
||||
// Commands that take effect immediately (ignoring the tweening queue):
|
||||
@@ -460,7 +460,7 @@ void BitmapText::HandleCommand( const CStringArray &asTokens )
|
||||
else if( sName=="maxwidth" ) SetMaxWidth( fParam(1) );
|
||||
else
|
||||
{
|
||||
Actor::HandleCommand( asTokens );
|
||||
Actor::HandleCommand( command );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
/* Return true if the string 's' will use an alternate string, if available. */
|
||||
bool StringWillUseAlternate(CString sText, CString sAlternateText) const;
|
||||
|
||||
virtual void HandleCommand( const CStringArray &asTokens );
|
||||
virtual void HandleCommand( const ParsedCommand &command );
|
||||
|
||||
public:
|
||||
Font* m_pFont;
|
||||
|
||||
@@ -196,7 +196,7 @@ $(RageSoundFileReaders) \
|
||||
$(RageFile)
|
||||
|
||||
Actors = \
|
||||
Actor.cpp Actor.h ActorCollision.h ActorFrame.cpp ActorFrame.h ActorScroller.cpp ActorScroller.h \
|
||||
Actor.cpp Actor.h ActorCollision.h ActorCommands.cpp ActorCommands.h ActorFrame.cpp ActorFrame.h ActorScroller.cpp ActorScroller.h \
|
||||
ActorUtil.cpp ActorUtil.h BitmapText.cpp BitmapText.h Milkshape.h Model.cpp Model.h ModelTypes.cpp ModelTypes.h \
|
||||
Quad.h Sprite.cpp Sprite.h
|
||||
|
||||
|
||||
@@ -980,7 +980,7 @@ int Model::GetNumStates()
|
||||
return iMaxStates;
|
||||
}
|
||||
|
||||
void Model::HandleCommand( const CStringArray &asTokens )
|
||||
void Model::HandleCommand( const ParsedCommand &command )
|
||||
{
|
||||
HandleParams;
|
||||
|
||||
@@ -1004,12 +1004,12 @@ void Model::HandleCommand( const CStringArray &asTokens )
|
||||
* tween queue.
|
||||
*/
|
||||
|
||||
const CString& sName = asTokens[0];
|
||||
const CString& sName = sParam(0);
|
||||
if( sName=="play" )
|
||||
PlayAnimation( sParam(1),fParam(2) );
|
||||
else
|
||||
{
|
||||
Actor::HandleCommand( asTokens );
|
||||
Actor::HandleCommand( command );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
void SetDefaultAnimation( CString sAnimation, float fPlayRate = 1 );
|
||||
bool m_bRevertToDefaultAnimation;
|
||||
|
||||
virtual void HandleCommand( const CStringArray &asTokens );
|
||||
virtual void HandleCommand( const ParsedCommand &command );
|
||||
|
||||
private:
|
||||
vector<msMesh> m_Meshes;
|
||||
|
||||
@@ -789,11 +789,11 @@ void Sprite::StretchTexCoords( float fX, float fY )
|
||||
SetCustomTextureCoords( fTexCoords );
|
||||
}
|
||||
|
||||
void Sprite::HandleCommand( const CStringArray &asTokens )
|
||||
void Sprite::HandleCommand( const ParsedCommand &command )
|
||||
{
|
||||
HandleParams;
|
||||
|
||||
const CString& sName = asTokens[0];
|
||||
const CString& sName = sParam(0);
|
||||
|
||||
// Commands that go in the tweening queue:
|
||||
// Commands that take effect immediately (ignoring the tweening queue):
|
||||
@@ -813,7 +813,7 @@ void Sprite::HandleCommand( const CStringArray &asTokens )
|
||||
else if( sName=="rate" ) GetTexture()->SetPlaybackRate( fParam(1) );
|
||||
else
|
||||
{
|
||||
Actor::HandleCommand( asTokens );
|
||||
Actor::HandleCommand( command );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ public:
|
||||
void ScaleToClipped( float fWidth, float fHeight );
|
||||
static bool IsDiagonalBanner( int iWidth, int iHeight );
|
||||
|
||||
virtual void HandleCommand( const CStringArray &asTokens );
|
||||
virtual void HandleCommand( const ParsedCommand &command );
|
||||
|
||||
protected:
|
||||
virtual bool LoadFromTexture( RageTextureID ID );
|
||||
|
||||
+29
-10
@@ -1,5 +1,5 @@
|
||||
# Microsoft Developer Studio Project File - Name="StepMania" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 60000
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Application" 0x0101
|
||||
@@ -62,10 +62,10 @@ LINK32=link.exe
|
||||
# SUBTRACT LINK32 /verbose /profile /pdb:none /incremental:no /nodefaultlib
|
||||
# Begin Special Build Tool
|
||||
IntDir=.\../Debug6
|
||||
TargetDir=\temp\stepmania\Program
|
||||
TargetDir=\stepmania\stepmania\Program
|
||||
TargetName=StepMania-debug
|
||||
SOURCE="$(InputPath)"
|
||||
PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\
|
||||
PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\
|
||||
PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi
|
||||
# End Special Build Tool
|
||||
|
||||
@@ -102,8 +102,8 @@ IntDir=.\Debug
|
||||
TargetDir=\stepmania\stepmania
|
||||
TargetName=default
|
||||
SOURCE="$(InputPath)"
|
||||
PreLink_Cmds=disasm\verinc cl /Zl /nologo /c \
|
||||
verstub.cpp /Fo$(IntDir)\
|
||||
PreLink_Cmds=disasm\verinc cl /Zl /nologo /c \
|
||||
verstub.cpp /Fo$(IntDir)\
|
||||
PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi ia32.vdi
|
||||
# End Special Build Tool
|
||||
|
||||
@@ -136,14 +136,14 @@ BSC32=bscmake.exe
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 $(intdir)\verstub.obj kernel32.lib gdi32.lib shell32.lib user32.lib advapi32.lib winmm.lib /nologo /subsystem:windows /pdb:"../release6/StepMania.pdb" /map /debug /machine:I386
|
||||
# SUBTRACT BASE LINK32 /verbose /pdb:none
|
||||
# ADD LINK32 $(intdir)\verstub.obj kernel32.lib gdi32.lib shell32.lib user32.lib advapi32.lib winmm.lib /nologo /subsystem:windows /map /debug /machine:I386 /out:"../Program/StepMania.exe"
|
||||
# ADD LINK32 $(intdir)\verstub.obj kernel32.lib gdi32.lib shell32.lib user32.lib advapi32.lib winmm.lib /nologo /subsystem:windows /map /debug /machine:I386 /out:"../../itg/Program/StepMania.exe"
|
||||
# SUBTRACT LINK32 /verbose /pdb:none
|
||||
# Begin Special Build Tool
|
||||
IntDir=.\../Release6
|
||||
TargetDir=\temp\stepmania\Program
|
||||
TargetDir=\stepmania\itg\Program
|
||||
TargetName=StepMania
|
||||
SOURCE="$(InputPath)"
|
||||
PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\
|
||||
PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\
|
||||
PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi
|
||||
# End Special Build Tool
|
||||
|
||||
@@ -184,8 +184,8 @@ IntDir=.\StepMania___Xbox_Release
|
||||
TargetDir=\stepmania\stepmania
|
||||
TargetName=default
|
||||
SOURCE="$(InputPath)"
|
||||
PreLink_Cmds=disasm\verinc cl /Zl /nologo /c \
|
||||
verstub.cpp /Fo$(IntDir)\
|
||||
PreLink_Cmds=disasm\verinc cl /Zl /nologo /c \
|
||||
verstub.cpp /Fo$(IntDir)\
|
||||
PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi ia32.vdi
|
||||
# End Special Build Tool
|
||||
|
||||
@@ -2790,6 +2790,25 @@ SOURCE=.\ActorCollision.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ActorCommands.cpp
|
||||
|
||||
!IF "$(CFG)" == "StepMania - Win32 Debug"
|
||||
|
||||
!ELSEIF "$(CFG)" == "StepMania - Xbox Debug"
|
||||
|
||||
!ELSEIF "$(CFG)" == "StepMania - Win32 Release"
|
||||
|
||||
!ELSEIF "$(CFG)" == "StepMania - Xbox Release"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ActorCommands.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ActorFrame.cpp
|
||||
|
||||
!IF "$(CFG)" == "StepMania - Win32 Debug"
|
||||
|
||||
@@ -1842,6 +1842,12 @@ cl /Zl /nologo /c verstub.cpp /Fo"$(IntDir)"\
|
||||
<File
|
||||
RelativePath="ActorCollision.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="ActorCommands.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="ActorCommands.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\ActorFrame.cpp">
|
||||
</File>
|
||||
|
||||
Reference in New Issue
Block a user