llmotioncontroller.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_LLMOTIONCONTROLLER_H
00033 #define LL_LLMOTIONCONTROLLER_H
00034 
00035 //-----------------------------------------------------------------------------
00036 // Header files
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 // Class predeclaration
00051 // This is necessary because llcharacter.h includes this file.
00052 //-----------------------------------------------------------------------------
00053 class LLCharacter;
00054 
00055 //-----------------------------------------------------------------------------
00056 // LLMotionRegistry
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         // Constructor
00088         LLMotionRegistry();
00089 
00090         // Destructor
00091         ~LLMotionRegistry();
00092 
00093         // adds motion classes to the registry
00094         // returns true if successfull
00095         BOOL addMotion( const LLUUID& id, LLMotionConstructor create);
00096 
00097         // creates a new instance of a named motion
00098         // returns NULL motion is not registered
00099         LLMotion *createMotion( const LLUUID &id );
00100 
00101         // initialization of motion failed, don't try to create this motion again
00102         void markBad( const LLUUID& id );
00103 
00104 
00105 protected:
00106         LLUUIDHashMap<LLMotionTableEntry, 32>   mMotionTable;
00107 };
00108 
00109 //-----------------------------------------------------------------------------
00110 // class LLMotionController
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         // Constructor
00120         LLMotionController();
00121 
00122         // Destructor
00123         virtual ~LLMotionController();
00124 
00125         // set associated character
00126         // this must be called exactly once by the containing character class.
00127         // this is generally done in the Character constructor
00128         void setCharacter( LLCharacter *character );
00129 
00130         // registers a motion with the controller
00131         // (actually just forwards call to motion registry)
00132         // returns true if successfull
00133         BOOL addMotion( const LLUUID& id, LLMotionConstructor create );
00134 
00135         // creates a motion from the registry
00136         LLMotion *createMotion( const LLUUID &id );
00137 
00138         // unregisters a motion with the controller
00139         // (actually just forwards call to motion registry)
00140         // returns true if successfull
00141         void removeMotion( const LLUUID& id );
00142 
00143         // start motion
00144         // begins playing the specified motion
00145         // returns true if successful
00146         BOOL startMotion( const LLUUID &id, F32 start_offset );
00147 
00148         // stop motion
00149         // stops a playing motion
00150         // in reality, it begins the ease out transition phase
00151         // returns true if successful
00152         BOOL stopMotionLocally( const LLUUID &id, BOOL stop_immediate );
00153 
00154         // update motions
00155         // invokes the update handlers for each active motion
00156         // activates sequenced motions
00157         // deactivates terminated motions`
00158         void updateMotion();
00159 
00160         void clearBlenders() { mPoseBlender.clearBlenders(); }
00161 
00162         // flush motions
00163         // releases all motion instances
00164         void flushAllMotions();
00165 
00166         //Flush is a liar.
00167         void deactivateAllMotions();    
00168 
00169         // pause and continue all motions
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 //protected:
00182         bool isMotionActive( LLMotion *motion );
00183         bool isMotionLoading( LLMotion *motion );
00184         LLMotion *findMotion( const LLUUID& id );
00185 
00186 protected:
00187         // internal operations act on motion instances directly
00188         // as there can be duplicate motions per id during blending overlap
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 //      Life cycle of an animation:
00209 //
00210 //      Animations are instantiated and immediately put in the mAllMotions map for their entire lifetime.
00211 //      If the animations depend on any asset data, the appropriate data is fetched from the data server,
00212 //      and the animation is put on the mLoadingMotions list.
00213 //      Once an animations is loaded, it will be initialized and put on the mLoadedMotions deque.
00214 //      Any animation that is currently playing also sits in the mActiveMotions list.
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 // Class declaractions
00240 //-----------------------------------------------------------------------------
00241 #include "llcharacter.h"
00242 
00243 #endif // LL_LLMOTIONCONTROLLER_H
00244 

Generated on Fri May 16 08:32:00 2008 for SecondLife by  doxygen 1.5.5