add pre-parsing for ActorCommands (though not yet used in ThemeManager)

This commit is contained in:
Chris Danford
2004-01-10 20:34:18 +00:00
parent 7c6321d4a8
commit f7647ae391
15 changed files with 66 additions and 120 deletions
+10 -62
View File
@@ -700,71 +700,24 @@ void Actor::AddRotationR( float rot )
RageQuatMultiply( &DestTweenState().quat, DestTweenState().quat, RageQuatFromR(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; for( int i=0; i<vCommands.size(); i++ )
split( sCommandString, ";", asCommands, true ); this->HandleCommand( vCommands[i] );
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 );
}
return GetTweenTimeLeft(); return GetTweenTimeLeft();
} }
#define sParam(i) (GetParam(asTokens,i,iMaxIndexAccessed)) void Actor::HandleCommand( const ParsedCommand &command )
#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 )
{ {
iMaxIndexAccessed = max( iIndex, iMaxIndexAccessed ); HandleParams;
if( iIndex < int(asTokens.size()) )
return asTokens[iIndex];
else
return "";
}
inline RageColor ColorParam( const CStringArray& asTokens, int iIndex, int& iMaxIndexAccessed ) const CString& sName = sParam(0);
{
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];
// Commands that go in the tweening queue: // Commands that go in the tweening queue:
if ( sName=="sleep" ) { BeginTweening( fParam(1), TWEEN_LINEAR ); BeginTweening( 0, TWEEN_LINEAR ); } 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 ); HOOKS->MessageBoxOK( sError );
} }
if( iMaxIndexAccessed != (int)asTokens.size()-1 ) CheckHandledParams;
{
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 );
}
} }
float Actor::GetCommandLength( CString command ) float Actor::GetCommandLength( CString command )
+3 -2
View File
@@ -12,6 +12,7 @@
*/ */
#include "RageTypes.h" #include "RageTypes.h"
#include "ActorCommands.h" // for ParsedCommand
class Actor class Actor
{ {
@@ -291,8 +292,8 @@ public:
void FadeOn( float fSleepSeconds, CString sFadeString, float fFadeSeconds ) { Fade(fSleepSeconds,sFadeString,fFadeSeconds,false); }; 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); }; void FadeOff( float fSleepSeconds, CString sFadeString, float fFadeSeconds ) { Fade(fSleepSeconds,sFadeString,fFadeSeconds,true); };
float Command( CString sCommandString ); // return length in seconds to execute command float Command( CString sCommands ); // return length in seconds to execute command
virtual void HandleCommand( const CStringArray &asTokens ); // derivable virtual void HandleCommand( const ParsedCommand &command ); // derivable
static float GetCommandLength( CString command ); static float GetCommandLength( CString command );
virtual void SetState( int iNewState ) {}; virtual void SetState( int iNewState ) {};
+1 -8
View File
@@ -133,14 +133,6 @@ Actor* MakeActor( RageTextureID ID )
ID.filename.c_str(), sExt.c_str() ); 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 ) void UtilSetXY( Actor& actor, CString sClassName )
{ {
ASSERT( !actor.GetID().empty() ); 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") ) ); return max( ret, actor.Command( THEME->GetMetric(sClassName,actor.GetID()+sCommandName+"Command") ) );
} }
-19
View File
@@ -70,23 +70,4 @@ protected:
Actor* m_pActor; 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 #endif
+3 -5
View File
@@ -245,16 +245,14 @@ void BGAnimation::PlayCommand( const CString &cmd )
m_Layers[i]->PlayCommand( cmd ); m_Layers[i]->PlayCommand( cmd );
} }
void BGAnimation::HandleCommand( const CStringArray &asTokens ) void BGAnimation::HandleCommand( const ParsedCommand &command )
{ {
HandleParams; HandleParams;
const CString& sName = asTokens[0]; if( sParam(0)=="playcommand" ) PlayCommand( sParam(1) );
if( sName=="playcommand" ) PlayCommand( sParam(1) );
else else
{ {
Actor::HandleCommand( asTokens ); Actor::HandleCommand( command );
return; return;
} }
+1 -1
View File
@@ -41,7 +41,7 @@ public:
float GetLengthSeconds() const { return m_fLengthSeconds; } float GetLengthSeconds() const { return m_fLengthSeconds; }
virtual void HandleCommand( const CStringArray &asTokens ); virtual void HandleCommand( const ParsedCommand &command );
void PlayOffCommand() { PlayCommand("Off"); } void PlayOffCommand() { PlayCommand("Off"); }
void PlayCommand( const CString &cmd ); void PlayCommand( const CString &cmd );
+3 -3
View File
@@ -448,11 +448,11 @@ void BitmapText::SetVertAlign( VertAlign va )
BuildChars(); BuildChars();
} }
void BitmapText::HandleCommand( const CStringArray &asTokens ) void BitmapText::HandleCommand( const ParsedCommand &command )
{ {
HandleParams; HandleParams;
const CString& sName = asTokens[0]; const CString& sName = sParam(0);
// Commands that go in the tweening queue: // Commands that go in the tweening queue:
// Commands that take effect immediately (ignoring 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 if( sName=="maxwidth" ) SetMaxWidth( fParam(1) );
else else
{ {
Actor::HandleCommand( asTokens ); Actor::HandleCommand( command );
return; return;
} }
+1 -1
View File
@@ -44,7 +44,7 @@ public:
/* Return true if the string 's' will use an alternate string, if available. */ /* Return true if the string 's' will use an alternate string, if available. */
bool StringWillUseAlternate(CString sText, CString sAlternateText) const; bool StringWillUseAlternate(CString sText, CString sAlternateText) const;
virtual void HandleCommand( const CStringArray &asTokens ); virtual void HandleCommand( const ParsedCommand &command );
public: public:
Font* m_pFont; Font* m_pFont;
+1 -1
View File
@@ -196,7 +196,7 @@ $(RageSoundFileReaders) \
$(RageFile) $(RageFile)
Actors = \ 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 \ ActorUtil.cpp ActorUtil.h BitmapText.cpp BitmapText.h Milkshape.h Model.cpp Model.h ModelTypes.cpp ModelTypes.h \
Quad.h Sprite.cpp Sprite.h Quad.h Sprite.cpp Sprite.h
+3 -3
View File
@@ -980,7 +980,7 @@ int Model::GetNumStates()
return iMaxStates; return iMaxStates;
} }
void Model::HandleCommand( const CStringArray &asTokens ) void Model::HandleCommand( const ParsedCommand &command )
{ {
HandleParams; HandleParams;
@@ -1004,12 +1004,12 @@ void Model::HandleCommand( const CStringArray &asTokens )
* tween queue. * tween queue.
*/ */
const CString& sName = asTokens[0]; const CString& sName = sParam(0);
if( sName=="play" ) if( sName=="play" )
PlayAnimation( sParam(1),fParam(2) ); PlayAnimation( sParam(1),fParam(2) );
else else
{ {
Actor::HandleCommand( asTokens ); Actor::HandleCommand( command );
return; return;
} }
+1 -1
View File
@@ -51,7 +51,7 @@ public:
void SetDefaultAnimation( CString sAnimation, float fPlayRate = 1 ); void SetDefaultAnimation( CString sAnimation, float fPlayRate = 1 );
bool m_bRevertToDefaultAnimation; bool m_bRevertToDefaultAnimation;
virtual void HandleCommand( const CStringArray &asTokens ); virtual void HandleCommand( const ParsedCommand &command );
private: private:
vector<msMesh> m_Meshes; vector<msMesh> m_Meshes;
+3 -3
View File
@@ -789,11 +789,11 @@ void Sprite::StretchTexCoords( float fX, float fY )
SetCustomTextureCoords( fTexCoords ); SetCustomTextureCoords( fTexCoords );
} }
void Sprite::HandleCommand( const CStringArray &asTokens ) void Sprite::HandleCommand( const ParsedCommand &command )
{ {
HandleParams; HandleParams;
const CString& sName = asTokens[0]; const CString& sName = sParam(0);
// Commands that go in the tweening queue: // Commands that go in the tweening queue:
// Commands that take effect immediately (ignoring 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 if( sName=="rate" ) GetTexture()->SetPlaybackRate( fParam(1) );
else else
{ {
Actor::HandleCommand( asTokens ); Actor::HandleCommand( command );
return; return;
} }
+1 -1
View File
@@ -60,7 +60,7 @@ public:
void ScaleToClipped( float fWidth, float fHeight ); void ScaleToClipped( float fWidth, float fHeight );
static bool IsDiagonalBanner( int iWidth, int iHeight ); static bool IsDiagonalBanner( int iWidth, int iHeight );
virtual void HandleCommand( const CStringArray &asTokens ); virtual void HandleCommand( const ParsedCommand &command );
protected: protected:
virtual bool LoadFromTexture( RageTextureID ID ); virtual bool LoadFromTexture( RageTextureID ID );
+23 -4
View File
@@ -1,5 +1,5 @@
# Microsoft Developer Studio Project File - Name="StepMania" - Package Owner=<4> # 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 ** # ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101 # TARGTYPE "Win32 (x86) Application" 0x0101
@@ -62,7 +62,7 @@ LINK32=link.exe
# SUBTRACT LINK32 /verbose /profile /pdb:none /incremental:no /nodefaultlib # SUBTRACT LINK32 /verbose /profile /pdb:none /incremental:no /nodefaultlib
# Begin Special Build Tool # Begin Special Build Tool
IntDir=.\../Debug6 IntDir=.\../Debug6
TargetDir=\temp\stepmania\Program TargetDir=\stepmania\stepmania\Program
TargetName=StepMania-debug TargetName=StepMania-debug
SOURCE="$(InputPath)" 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)\
@@ -136,11 +136,11 @@ BSC32=bscmake.exe
LINK32=link.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 # 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 # 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 # SUBTRACT LINK32 /verbose /pdb:none
# Begin Special Build Tool # Begin Special Build Tool
IntDir=.\../Release6 IntDir=.\../Release6
TargetDir=\temp\stepmania\Program TargetDir=\stepmania\itg\Program
TargetName=StepMania TargetName=StepMania
SOURCE="$(InputPath)" 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)\
@@ -2790,6 +2790,25 @@ SOURCE=.\ActorCollision.h
# End Source File # End Source File
# Begin 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 SOURCE=.\ActorFrame.cpp
!IF "$(CFG)" == "StepMania - Win32 Debug" !IF "$(CFG)" == "StepMania - Win32 Debug"
+6
View File
@@ -1842,6 +1842,12 @@ cl /Zl /nologo /c verstub.cpp /Fo&quot;$(IntDir)&quot;\
<File <File
RelativePath="ActorCollision.h"> RelativePath="ActorCollision.h">
</File> </File>
<File
RelativePath="ActorCommands.cpp">
</File>
<File
RelativePath="ActorCommands.h">
</File>
<File <File
RelativePath=".\ActorFrame.cpp"> RelativePath=".\ActorFrame.cpp">
</File> </File>