pretty easy to store / retrieve
Code: Select all
struct CSActionTableEntry
{
public:
char m_AnimationName[255];
int m_AnimationStart;
int m_AnimationEnd;
};
#define MAX_ANIMATIONS 100
class CSActionTable
{
public :
CSActionTableEntry* m_Animations[MAX_ANIMATIONS];
CSActionTable::CSActionTable() { Initialize(); }
virtual CSActionTable::~CSActionTable() { Cleanup(); }
virtual void Initialize()
{
for (int x=0; x<MAX_ANIMATIONS; x++) { CS_INIT(m_Animations[x]); }
}
virtual bool Cleanup()
{
for (int x=0; x<MAX_ANIMATIONS; x++) { CS_SAFE_DELETE(m_Animations[x]); }
return false;
}
virtual int AddEntry(char* name, int start, int end)
{
for (int x=0; x<MAX_ANIMATIONS; x++)
{
if (!m_Animations[x])
{
m_Animations[x] = new CSActionTableEntry();
strcpy(m_Animations[x]->m_AnimationName,name);
m_Animations[x]->m_AnimationStart = start;
m_Animations[x]->m_AnimationEnd = end;
return x;
}
}
return 0;
}
virtual CSActionTableEntry* GetEntry(char* name)
{
for (int x=0; x<MAX_ANIMATIONS; x++)
{
if (m_Animations[x])
{
if (!strcmp(m_Animations[x]->m_AnimationName,name))
return m_Animations[x];
}
}
return NULL;
}
virtual CSActionTableEntry* GetEntry(int index)
{
return m_Animations[index];
}
};
Code: Select all
// setup an action table
if (GetActionTable())
{
GetActionTable()->AddEntry("WALK",2,14);
GetActionTable()->AddEntry("RUN",16,26);
GetActionTable()->AddEntry("JUMP",28,40);
GetActionTable()->AddEntry("JUMP_IN_PLACE",42,54);
GetActionTable()->AddEntry("CROUCH",56,59);
GetActionTable()->AddEntry("CROUCH_IDLE",60,69);
GetActionTable()->AddEntry("STAND_UP",70,74);
GetActionTable()->AddEntry("BATTLE_IDLE_1",75,88);
GetActionTable()->AddEntry("BATTLE_IDLE_2",90,110);
GetActionTable()->AddEntry("ATTACK_1",112,126);
GetActionTable()->AddEntry("ATTACK_2",128,142);
GetActionTable()->AddEntry("ATTACK_3",144,160);
GetActionTable()->AddEntry("ATTACK_4",162,180);
GetActionTable()->AddEntry("ATTACK_5",182,192);
GetActionTable()->AddEntry("BLOCK",194,210);
GetActionTable()->AddEntry("DIE_FORWARD",212,227);
GetActionTable()->AddEntry("DIE_BACKWARD",230,251);
GetActionTable()->AddEntry("NOD_HEAD",253,272);
GetActionTable()->AddEntry("SHAKE_HEAD",274,290);
GetActionTable()->AddEntry("IDLE_1",292,325);
GetActionTable()->AddEntry("iDLE_2",327,360);
}
Code: Select all
virtual void Stop() { CSObject::Stop(); SetAnimation("IDLE_1"); }
virtual void SetMoveForward(bool d) { CSObject::SetMoveForward(d); if (d) SetAnimation("WALK"); }
virtual void SetMoveBackward(bool d) { CSObject::SetMoveBackward(d); if (d) SetAnimation("WALK"); }
virtual void SetMoveTurnLeft(bool d) { CSObject::SetMoveTurnLeft(d); if (d) SetAnimation("WALK"); }
virtual void SetMoveTurnRight(bool d) { CSObject::SetMoveTurnRight(d); if (d) SetAnimation("WALK"); }
virtual void SetMoveStrafeLeft(bool d) { CSObject::SetMoveStrafeLeft(d); if (d) SetAnimation("WALK"); }
virtual void SetMoveStrafeRight(bool d) { CSObject::SetMoveStrafeRight(d); if (d) SetAnimation("WALK"); }
virtual void SetMoveJump(bool d) { CSObject::SetMoveJump(d); if (d) SetAnimation("JUMP"); }
virtual void SetMoveCrouch(bool d) { CSObject::SetMoveCrouch(d); if (d) SetAnimation("CROUCH"); else SetAnimation("STAND_UP"); }
Code: Select all
void CSObject::SetAnimation(char* name)
{
// if we are already playing this animation then bail
if (!strcmp(m_Animation,name)) return;
strcpy(m_Animation,name);
if (!GetActionTable()) { printf("%s - Invalid Action Table\n", m_Info->GetName()); return; }
if (!GetAnimatedSceneNode()) { printf("%s - Set Animation Failed - no animated Node\n", m_Info->GetName()); return; }
CSActionTableEntry* e = GetActionTable()->GetEntry(name);
if (e)
{
GetAnimatedSceneNode()->setLoopMode(true);
GetAnimatedSceneNode()->setFrameLoop(e->m_AnimationStart,e->m_AnimationEnd);
GetAnimatedSceneNode()->setCurrentFrame(e->m_AnimationStart);
}
}