00001 #ifndef MERCURYOBJECTCOMMANDS_H
00002 #define MERCURYOBJECTCOMMANDS_H
00003
00004 #include "global.h"
00005 #include "MercuryCommands.h"
00006 #include <map>
00007 #include <vector>
00008
00009
00010 class MercuryObject;
00011 class MercuryTweenOperation;
00012
00013 typedef void (*MercuryTweenFunction)( const float fPercent, const float fLastPercent, MercuryObject * pObject, MercuryTweenOperation * pOperation );
00014 typedef float (*MercuryTweenType)( const float fPercent, PStack & pArgs );
00015
00017 class AutoCommandRegisterer
00018 {
00019 public:
00020 MercuryTweenFunction GetFunction( const MString &name );
00021 int RegisterFunction( MercuryTweenFunction fnct, const MString & name );
00022
00023 MercuryTweenType GetTweenType( const MString &name );
00024 int RegisterTweenType( MercuryTweenType fnct, const MString & name );
00025
00026 std::map< MString, MercuryTweenFunction > * sMapFunctions;
00027 std::map< MString, MercuryTweenType > * sMapTweens;
00028
00029 int sNumFunctions;
00030 };
00031 extern AutoCommandRegisterer CommandRegisterer;
00032
00034 class MercuryTweenOperation
00035 {
00036 public:
00037 MercuryTweenFunction Function;
00038 MString Command;
00039 PStack Parameters;
00040 };
00041
00043 class MercuryTween
00044 {
00045 public:
00046 MercuryTween();
00047 MercuryTween( const MercuryTween & rhs );
00048 MercuryTween & operator = ( const MercuryTween & rhs );
00049 ~MercuryTween();
00050 MVector< MercuryTweenOperation *> Operations;
00051 void Operate( const float fPercent, const float fLastPercent, MercuryObject * pObject );
00052 float fStart;
00053 float fEnd;
00054 MercuryTweenType pTT;
00055 PStack pTArgs;
00056 PStack pKArgs;
00057 bool bAutoDelete;
00058 bool bDeleteChildren;
00059 int iEndBase;
00060 };
00061
00063 class MercuryTweenState
00064 {
00065 public:
00066 enum SPACE
00067 {
00068 CURRENT = 0,
00069 LOCAL,
00070 GLOBAL
00071 };
00072 MercuryTweenState();
00073 MercuryTweenState( const MercuryTweenState & rhs );
00074 MercuryTweenState & operator = ( const MercuryTweenState & rhs );
00075 ~MercuryTweenState();
00076
00077 void AttachToObject( MercuryObject * object );
00078 void Update( float fDeltaTime );
00079
00080
00082 void AddCommand( MercuryTween * ToPush, float fFuture = 0, SPACE iWhichPlace = CURRENT, MString sTweenName = "" );
00084 void AddCommand( const MString &command, SPACE iWhichPlace = CURRENT, MString sTweenName = "" );
00085
00087 void ExecuteCommand( const MString & sName, const PStack & pKArgs );
00088
00090 void FinishTweening();
00092 void StopTweening();
00094 void PauseTweening() { m_bPauseTweening = true; }
00096 void ResumeTweening() { m_bPauseTweening = false; }
00098 bool IsTweeningPaused() { return m_bPauseTweening; }
00099
00100
00101
00102 MercuryTween * m_pCurrentTween;
00103
00104 bool IsTweening() const { return !m_qTweens.empty(); }
00105 private:
00106
00107 float CalculateRemainingPercent( float fDeltaTime );
00108 float CalculateCurrentPercent( float fDeltaTime );
00109
00110 float m_fCurTime;
00111 bool m_bPauseTweening;
00112 float m_fRunningEnd;
00113
00114 MercuryObject * m_pObject;
00115 MDeque< MercuryTween * > m_qTweens;
00116
00117 void InternalUpdate( float fDeltaTime, bool bFinish = false );
00118
00119 std::map< MString, std::vector< MercuryTween * > > m_LocalTweens;
00120 static std::map< MString, std::vector< MercuryTween * > > m_GlobalTweens;
00121 bool m_bCloned;
00122 };
00123
00124 #endif
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152