move attribute loading into the class that owns the attribute

This commit is contained in:
Chris Danford
2005-01-16 23:40:21 +00:00
parent 7b43001220
commit 8a1fb93003
8 changed files with 84 additions and 56 deletions
+50 -10
View File
@@ -8,6 +8,7 @@
#include "RageLog.h" #include "RageLog.h"
#include "arch/Dialog/Dialog.h" #include "arch/Dialog/Dialog.h"
#include "Foreach.h" #include "Foreach.h"
#include "XmlFile.h"
float Actor::g_fCurrentBGMTime = 0, Actor::g_fCurrentBGMBeat; float Actor::g_fCurrentBGMTime = 0, Actor::g_fCurrentBGMBeat;
@@ -62,6 +63,44 @@ Actor::Actor()
m_bFirstUpdate = true; m_bFirstUpdate = true;
} }
void Actor::LoadFromNode( const XNode* pNode )
{
// Load Name, if any.
pNode->GetAttrValue( "Name", m_sName );
float f;
if( pNode->GetAttrValue( "BaseRotationXDegrees", f ) ) SetBaseRotationX( f );
if( pNode->GetAttrValue( "BaseRotationYDegrees", f ) ) SetBaseRotationY( f );
if( pNode->GetAttrValue( "BaseRotationZDegrees", f ) ) SetBaseRotationZ( f );
if( pNode->GetAttrValue( "BaseZoomX", f ) ) SetBaseZoomX( f );
if( pNode->GetAttrValue( "BaseZoomY", f ) ) SetBaseZoomY( f );
if( pNode->GetAttrValue( "BaseZoomZ", f ) ) SetBaseZoomZ( f );
//
// Load commands
//
FOREACH_CONST_Attr( pNode, a )
{
CString sKeyName = a->m_sName; /* "OnCommand" */
sKeyName.MakeLower();
if( sKeyName.Right(7) != "command" )
continue; /* not a command */
const CString &sCommands = a->m_sValue;
Commands cmds = ParseCommands( sCommands );
CString sCmdName;
/* Special case: "Command=foo" -> "OnCommand=foo" */
if( sKeyName.size() == 7 )
sCmdName="on";
else
sCmdName = sKeyName.Left( sKeyName.size()-7 );
m_mapNameToCommands[sCmdName] = cmds;
}
}
void Actor::Draw() void Actor::Draw()
{ {
if( m_bHidden ) if( m_bHidden )
@@ -624,13 +663,6 @@ void Actor::AddRotationR( float rot )
RageQuatMultiply( &DestTweenState().quat, DestTweenState().quat, RageQuatFromR(rot) ); RageQuatMultiply( &DestTweenState().quat, DestTweenState().quat, RageQuatFromR(rot) );
} }
void Actor::AddCommands( const CString sName, const Commands &cmds )
{
CString sKey = sName;
sKey.MakeLower();
m_mapNameToCommands[sKey] = cmds;
}
void Actor::RunCommands( const Commands &cmds ) void Actor::RunCommands( const Commands &cmds )
{ {
FOREACH_CONST( Command, cmds.v, c ) FOREACH_CONST( Command, cmds.v, c )
@@ -755,10 +787,18 @@ void Actor::HandleCommand( const Command &command )
* sent to all sub-actors (which aren't necessarily Sprites) on * sent to all sub-actors (which aren't necessarily Sprites) on
* GainFocus and LoseFocus. So, don't run EndHandleArgs * GainFocus and LoseFocus. So, don't run EndHandleArgs
* on these commands. */ * on these commands. */
else if( sName=="customtexturerect" || sName=="texcoordvelocity" || sName=="scaletoclipped" || else if(
sName=="stretchtexcoords" || sName=="position" || sName=="loop" || sName=="customtexturerect" ||
sName=="rate" || sName=="propagate" ) sName=="texcoordvelocity" ||
sName=="scaletoclipped" ||
sName=="stretchtexcoords" ||
sName=="position" ||
sName=="loop" ||
sName=="rate" ||
sName=="propagate" )
{
return; return;
}
else else
{ {
CString sError = ssprintf( "Actor::HandleCommand: Unrecognized command name '%s'.", sName.c_str() ); CString sError = ssprintf( "Actor::HandleCommand: Unrecognized command name '%s'.", sName.c_str() );
+3 -2
View File
@@ -7,6 +7,7 @@
#include "Command.h" #include "Command.h"
#include <deque> #include <deque>
#include <map> #include <map>
struct XNode;
#define DRAW_ORDER_BEFORE_EVERYTHING -100 #define DRAW_ORDER_BEFORE_EVERYTHING -100
#define DRAW_ORDER_TRANSITIONS 100 #define DRAW_ORDER_TRANSITIONS 100
@@ -18,6 +19,7 @@ public:
Actor(); Actor();
virtual ~Actor() {} virtual ~Actor() {}
virtual void Reset(); virtual void Reset();
void LoadFromNode( const XNode* pNode );
static void SetBGMTime( float fTime, float fBeat ) { g_fCurrentBGMTime = fTime; g_fCurrentBGMBeat = fBeat; } static void SetBGMTime( float fTime, float fBeat ) { g_fCurrentBGMTime = fTime; g_fCurrentBGMBeat = fBeat; }
@@ -301,7 +303,7 @@ public:
// //
// Commands // Commands
// //
void AddCommands( const CString sName, const Commands &cmds ); virtual void PlayCommand( const CString &sCommandName );
void RunCommands( const Commands &cmds ); void RunCommands( const Commands &cmds );
virtual void HandleCommand( const Command &command ); // derivable virtual void HandleCommand( const Command &command ); // derivable
static float GetCommandsLengthSeconds( const Commands &cmds ); static float GetCommandsLengthSeconds( const Commands &cmds );
@@ -319,7 +321,6 @@ public:
// //
virtual void GainFocus( float fRate, bool bRewindMovie, bool bLoop ) {} virtual void GainFocus( float fRate, bool bRewindMovie, bool bLoop ) {}
virtual void LoseFocus() {} virtual void LoseFocus() {}
virtual void PlayCommand( const CString &sCommandName );
protected: protected:
+20
View File
@@ -2,6 +2,8 @@
#include "ActorFrame.h" #include "ActorFrame.h"
#include "arch/Dialog/Dialog.h" #include "arch/Dialog/Dialog.h"
#include "RageUtil.h" #include "RageUtil.h"
#include "XmlFile.h"
#include "ActorUtil.h"
ActorFrame::ActorFrame() ActorFrame::ActorFrame()
{ {
@@ -15,6 +17,24 @@ ActorFrame::~ActorFrame()
DeleteAllChildren(); DeleteAllChildren();
} }
void ActorFrame::LoadFromNode( const CString &sDir, const XNode* pNode )
{
Actor::LoadFromNode( pNode );
//
// Load children
//
const XNode* pChildren = pNode->GetChild("children");
if( pChildren )
{
FOREACH_CONST_Child( pChildren, pChild )
{
Actor* pChildActor = LoadFromActorFile( sDir, *pChild );
AddChild( pChildActor );
}
}
}
void ActorFrame::AddChild( Actor* pActor ) void ActorFrame::AddChild( Actor* pActor )
{ {
#if _DEBUG #if _DEBUG
+3
View File
@@ -10,6 +10,9 @@ class ActorFrame : public Actor
public: public:
ActorFrame(); ActorFrame();
virtual ~ActorFrame(); virtual ~ActorFrame();
void LoadFromNode( const CString &sDir, const XNode* pNode );
virtual void AddChild( Actor* pActor ); virtual void AddChild( Actor* pActor );
virtual void RemoveChild( Actor* pActor ); virtual void RemoveChild( Actor* pActor );
virtual void MoveToTail( Actor* pActor ); virtual void MoveToTail( Actor* pActor );
+4 -2
View File
@@ -39,11 +39,13 @@ void ActorScroller::Load(
m_bLoaded = true; m_bLoaded = true;
} }
void ActorScroller::LoadFromNode( const CString &sFile, const XNode *pNode ) void ActorScroller::LoadFromNode( const CString &sDir, const XNode *pNode )
{ {
ActorFrame::LoadFromNode( sDir, pNode );
#define REQUIRED_GET_VALUE( szName, valueOut ) \ #define REQUIRED_GET_VALUE( szName, valueOut ) \
if( !pNode->GetAttrValue( szName, valueOut ) ) \ if( !pNode->GetAttrValue( szName, valueOut ) ) \
Dialog::OK( ssprintf("File '%s' is missing the value Scroller::%s", sFile.c_str(), szName) ); Dialog::OK( ssprintf("Animation in '%s' is missing the value Scroller::%s", sDir.c_str(), szName) );
float fSecondsPerItem = 1; float fSecondsPerItem = 1;
float fNumItemsToDraw = 7; float fNumItemsToDraw = 7;
+1 -1
View File
@@ -22,7 +22,7 @@ public:
virtual void Update( float fDelta ); virtual void Update( float fDelta );
virtual void DrawPrimitives(); // DOES draw virtual void DrawPrimitives(); // DOES draw
void LoadFromNode( const CString &sFile, const XNode *pNode ); void LoadFromNode( const CString &sDir, const XNode *pNode );
void SetDestinationItem( int iItem ) { m_fDestinationItem = float(iItem); } void SetDestinationItem( int iItem ) { m_fDestinationItem = float(iItem); }
void SetCurrentAndDestinationItem( int iItem ) { m_fCurrentItem = m_fDestinationItem = float(iItem); } void SetCurrentAndDestinationItem( int iItem ) { m_fCurrentItem = m_fDestinationItem = float(iItem); }
+2 -31
View File
@@ -230,37 +230,8 @@ retry:
} }
float f; // TODO: LoadFromNode should be called when we still have a pointer to the derived type.
if( layer.GetAttrValue( "BaseRotationXDegrees", f ) ) pActor->SetBaseRotationX( f ); pActor->LoadFromNode( &layer );
if( layer.GetAttrValue( "BaseRotationYDegrees", f ) ) pActor->SetBaseRotationY( f );
if( layer.GetAttrValue( "BaseRotationZDegrees", f ) ) pActor->SetBaseRotationZ( f );
if( layer.GetAttrValue( "BaseZoomX", f ) ) pActor->SetBaseZoomX( f );
if( layer.GetAttrValue( "BaseZoomY", f ) ) pActor->SetBaseZoomY( f );
if( layer.GetAttrValue( "BaseZoomZ", f ) ) pActor->SetBaseZoomZ( f );
//
// Load commands
//
FOREACH_CONST_Attr( &layer, a )
{
CString KeyName = a->m_sName; /* "OnCommand" */
KeyName.MakeLower();
if( KeyName.Right(7) != "command" )
continue; /* not a command */
const CString &sCommands = a->m_sValue;
Commands cmds = ParseCommands( sCommands );
CString sCmdName;
/* Special case: "Command=foo" -> "OnCommand=foo" */
if( KeyName.size() == 7 )
sCmdName="on";
else
sCmdName = KeyName.Left( KeyName.size()-7 );
pActor->AddCommands( sCmdName, cmds );
}
ASSERT( pActor ); // we should have filled this in above ASSERT( pActor ); // we should have filled this in above
return pActor; return pActor;
+1 -10
View File
@@ -170,7 +170,6 @@ void BGAnimation::LoadFromNode( const CString &sDir, const XNode& node )
{ {
DEBUG_ASSERT( node.m_sName == "BGAnimation" ); DEBUG_ASSERT( node.m_sName == "BGAnimation" );
CString sInitCommand; CString sInitCommand;
if( node.GetAttrValue( "InitCommand", sInitCommand ) ) if( node.GetAttrValue( "InitCommand", sInitCommand ) )
{ {
@@ -180,15 +179,7 @@ void BGAnimation::LoadFromNode( const CString &sDir, const XNode& node )
this->RunCommands( ParseCommands(sInitCommand) ); this->RunCommands( ParseCommands(sInitCommand) );
} }
const XNode* pChildren = node.GetChild("children"); ActorFrame::LoadFromNode( sDir, &node );
if( pChildren )
{
FOREACH_CONST_Child( pChildren, pChild )
{
Actor* pChildActor = LoadFromActorFile( sDir, *pChild );
AddChild( pChildActor );
}
}
Command cmd; Command cmd;
cmd.Load( "PlayCommand,Init" ); cmd.Load( "PlayCommand,Init" );