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         // flush motions
00161         // releases all motion instances
00162         void flushAllMotions();
00163 
00164         //Flush is a liar.
00165         void deactivateAllMotions();    
00166 
00167         // pause and continue all motions
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 //protected:
00180         bool isMotionActive( LLMotion *motion );
00181         bool isMotionLoading( LLMotion *motion );
00182         LLMotion *findMotion( const LLUUID& id );
00183 
00184 protected:
00185         // internal operations act on motion instances directly
00186         // as there can be duplicate motions per id during blending overlap
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 //      Life cycle of an animation:
00207 //
00208 //      Animations are instantiated and immediately put in the mAllMotions map for their entire lifetime.
00209 //      If the animations depend on any asset data, the appropriate data is fetched from the data server,
00210 //      and the animation is put on the mLoadingMotions list.
00211 //      Once an animations is loaded, it will be initialized and put on the mLoadedMotions deque.
00212 //      Any animation that is currently playing also sits in the mActiveMotions list.
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 // Class declaractions
00238 //-----------------------------------------------------------------------------
00239 #include "llcharacter.h"
00240 
00241 #endif // LL_LLMOTIONCONTROLLER_H
00242 

Generated on Thu Jul 1 06:08:54 2010 for Second Life Viewer by  doxygen 1.4.7