00001 
00032 #ifndef LL_LLMOTIONCONTROLLER_H
00033 #define LL_LLMOTIONCONTROLLER_H
00034 
00035 
00036 
00037 
00038 #include <string>
00039 #include <map>
00040 #include <deque>
00041 
00042 #include "lluuidhashmap.h"
00043 #include "llmotion.h"
00044 #include "llpose.h"
00045 #include "llframetimer.h"
00046 #include "llstatemachine.h"
00047 #include "llstring.h"
00048 
00049 
00050 
00051 
00052 
00053 class LLCharacter;
00054 
00055 
00056 
00057 
00058 typedef LLMotion*(*LLMotionConstructor)(const LLUUID &id);
00059 
00060 class LLMotionTableEntry
00061 {
00062 public:
00063         LLMotionTableEntry();
00064         LLMotionTableEntry(LLMotionConstructor constructor, const LLUUID& id);
00065         ~LLMotionTableEntry(){};
00066 
00067         LLMotion* create(const LLUUID& id);
00068         static BOOL uuidEq(const LLUUID &uuid, const LLMotionTableEntry &id_pair)
00069         {
00070                 if (uuid == id_pair.mID)
00071                 {
00072                         return TRUE;
00073                 }
00074                 return FALSE;
00075         }
00076 
00077         const LLUUID& getID() { return mID; }
00078 
00079 protected:
00080         LLMotionConstructor             mConstructor;
00081         LLUUID  mID;
00082 };
00083 
00084 class LLMotionRegistry
00085 {
00086 public:
00087         
00088         LLMotionRegistry();
00089 
00090         
00091         ~LLMotionRegistry();
00092 
00093         
00094         
00095         BOOL addMotion( const LLUUID& id, LLMotionConstructor create);
00096 
00097         
00098         
00099         LLMotion *createMotion( const LLUUID &id );
00100 
00101         
00102         void markBad( const LLUUID& id );
00103 
00104 
00105 protected:
00106         LLUUIDHashMap<LLMotionTableEntry, 32>   mMotionTable;
00107 };
00108 
00109 
00110 
00111 
00112 class LLMotionController
00113 {
00114 public:
00115         typedef std::list<LLMotion*> motion_list_t;
00116         typedef std::set<LLMotion*> motion_set_t;
00117         
00118 public:
00119         
00120         LLMotionController();
00121 
00122         
00123         virtual ~LLMotionController();
00124 
00125         
00126         
00127         
00128         void setCharacter( LLCharacter *character );
00129 
00130         
00131         
00132         
00133         BOOL addMotion( const LLUUID& id, LLMotionConstructor create );
00134 
00135         
00136         LLMotion *createMotion( const LLUUID &id );
00137 
00138         
00139         
00140         
00141         void removeMotion( const LLUUID& id );
00142 
00143         
00144         
00145         
00146         BOOL startMotion( const LLUUID &id, F32 start_offset );
00147 
00148         
00149         
00150         
00151         
00152         BOOL stopMotionLocally( const LLUUID &id, BOOL stop_immediate );
00153 
00154         
00155         
00156         
00157         
00158         void updateMotion();
00159 
00160         
00161         
00162         void flushAllMotions();
00163 
00164         
00165         void deactivateAllMotions();    
00166 
00167         
00168         void pause();
00169         void unpause();
00170         BOOL isPaused() { return mPaused; }
00171 
00172         void setTimeStep(F32 step);
00173 
00174         void setTimeFactor(F32 time_factor);
00175         F32 getTimeFactor() { return mTimeFactor; }
00176 
00177         motion_list_t& getActiveMotions() { return mActiveMotions; }
00178 
00179 
00180         bool isMotionActive( LLMotion *motion );
00181         bool isMotionLoading( LLMotion *motion );
00182         LLMotion *findMotion( const LLUUID& id );
00183 
00184 protected:
00185         
00186         
00187         void deleteAllMotions();
00188         void addLoadedMotion(LLMotion *motion);
00189         BOOL activateMotionInstance(LLMotion *motion, F32 time);
00190         BOOL deactivateMotionInstance(LLMotion *motion);
00191         void deprecateMotionInstance(LLMotion* motion);
00192         BOOL stopMotionInstance(LLMotion *motion, BOOL stop_imemdiate);
00193         void removeMotionInstance(LLMotion* motion);
00194         void updateRegularMotions();
00195         void updateAdditiveMotions();
00196         void resetJointSignatures();
00197         void updateMotionsByType(LLMotion::LLMotionBlendType motion_type);
00198 
00199 protected:
00200         F32                                     mTimeFactor;
00201         static LLMotionRegistry sRegistry;
00202         LLPoseBlender           mPoseBlender;
00203 
00204         LLCharacter                     *mCharacter;
00205 
00206 
00207 
00208 
00209 
00210 
00211 
00212 
00213 
00214         typedef std::map<LLUUID, LLMotion*> motion_map_t;
00215         motion_map_t    mAllMotions;
00216 
00217         motion_set_t            mLoadingMotions;
00218         motion_list_t           mLoadedMotions;
00219         motion_list_t           mActiveMotions;
00220         motion_set_t            mDeprecatedMotions;
00221         
00222         LLFrameTimer            mTimer;
00223         F32                                     mTime;
00224         F32                                     mTimeOffset;
00225         F32                                     mLastTime;
00226         BOOL                            mHasRunOnce;
00227         BOOL                            mPaused;
00228         F32                                     mTimeStep;
00229         S32                                     mTimeStepCount;
00230         F32                                     mLastInterp;
00231         F32                                     mPauseTime;
00232 
00233         U8                                      mJointSignature[2][LL_CHARACTER_MAX_JOINTS];
00234 };
00235 
00236 
00237 
00238 
00239 #include "llcharacter.h"
00240 
00241 #endif // LL_LLMOTIONCONTROLLER_H
00242