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 void clearBlenders() { mPoseBlender.clearBlenders(); }
00161
00162
00163
00164 void flushAllMotions();
00165
00166
00167 void deactivateAllMotions();
00168
00169
00170 void pause();
00171 void unpause();
00172 BOOL isPaused() { return mPaused; }
00173
00174 void setTimeStep(F32 step);
00175
00176 void setTimeFactor(F32 time_factor);
00177 F32 getTimeFactor() { return mTimeFactor; }
00178
00179 motion_list_t& getActiveMotions() { return mActiveMotions; }
00180
00181
00182 bool isMotionActive( LLMotion *motion );
00183 bool isMotionLoading( LLMotion *motion );
00184 LLMotion *findMotion( const LLUUID& id );
00185
00186 protected:
00187
00188
00189 void deleteAllMotions();
00190 void addLoadedMotion(LLMotion *motion);
00191 BOOL activateMotionInstance(LLMotion *motion, F32 time);
00192 BOOL deactivateMotionInstance(LLMotion *motion);
00193 void deprecateMotionInstance(LLMotion* motion);
00194 BOOL stopMotionInstance(LLMotion *motion, BOOL stop_imemdiate);
00195 void removeMotionInstance(LLMotion* motion);
00196 void updateRegularMotions();
00197 void updateAdditiveMotions();
00198 void resetJointSignatures();
00199 void updateMotionsByType(LLMotion::LLMotionBlendType motion_type);
00200
00201 protected:
00202 F32 mTimeFactor;
00203 static LLMotionRegistry sRegistry;
00204 LLPoseBlender mPoseBlender;
00205
00206 LLCharacter *mCharacter;
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216 typedef std::map<LLUUID, LLMotion*> motion_map_t;
00217 motion_map_t mAllMotions;
00218
00219 motion_set_t mLoadingMotions;
00220 motion_list_t mLoadedMotions;
00221 motion_list_t mActiveMotions;
00222 motion_set_t mDeprecatedMotions;
00223
00224 LLFrameTimer mTimer;
00225 F32 mTime;
00226 F32 mTimeOffset;
00227 F32 mLastTime;
00228 BOOL mHasRunOnce;
00229 BOOL mPaused;
00230 F32 mTimeStep;
00231 S32 mTimeStepCount;
00232 F32 mLastInterp;
00233 F32 mPauseTime;
00234
00235 U8 mJointSignature[2][LL_CHARACTER_MAX_JOINTS];
00236 };
00237
00238
00239
00240
00241 #include "llcharacter.h"
00242
00243 #endif // LL_LLMOTIONCONTROLLER_H
00244