PageRenderTime 90ms CodeModel.GetById 30ms app.highlight 33ms RepoModel.GetById 17ms app.codeStats 1ms

/indra/llcharacter/llmotioncontroller.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 232 lines | 99 code | 46 blank | 87 comment | 0 complexity | c129b7568c875cbf8531e190ed7c1b16 MD5 | raw file
  1/** 
  2 * @file llmotioncontroller.h
  3 * @brief Implementation of LLMotionController class.
  4 *
  5 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LL_LLMOTIONCONTROLLER_H
 28#define LL_LLMOTIONCONTROLLER_H
 29
 30//-----------------------------------------------------------------------------
 31// Header files
 32//-----------------------------------------------------------------------------
 33#include <string>
 34#include <map>
 35#include <deque>
 36
 37#include "lluuidhashmap.h"
 38#include "llmotion.h"
 39#include "llpose.h"
 40#include "llframetimer.h"
 41#include "llstatemachine.h"
 42#include "llstring.h"
 43
 44//-----------------------------------------------------------------------------
 45// Class predeclaration
 46// This is necessary because llcharacter.h includes this file.
 47//-----------------------------------------------------------------------------
 48class LLCharacter;
 49
 50//-----------------------------------------------------------------------------
 51// LLMotionRegistry
 52//-----------------------------------------------------------------------------
 53typedef LLMotion*(*LLMotionConstructor)(const LLUUID &id);
 54
 55class LLMotionRegistry
 56{
 57public:
 58	// Constructor
 59	LLMotionRegistry();
 60
 61	// Destructor
 62	~LLMotionRegistry();
 63
 64	// adds motion classes to the registry
 65	// returns true if successfull
 66	BOOL registerMotion( const LLUUID& id, LLMotionConstructor create);
 67
 68	// creates a new instance of a named motion
 69	// returns NULL motion is not registered
 70	LLMotion *createMotion( const LLUUID &id );
 71
 72	// initialization of motion failed, don't try to create this motion again
 73	void markBad( const LLUUID& id );
 74
 75
 76protected:
 77	typedef std::map<LLUUID, LLMotionConstructor> motion_map_t;
 78	motion_map_t mMotionTable;
 79};
 80
 81//-----------------------------------------------------------------------------
 82// class LLMotionController
 83//-----------------------------------------------------------------------------
 84class LLMotionController
 85{
 86public:
 87	typedef std::list<LLMotion*> motion_list_t;
 88	typedef std::set<LLMotion*> motion_set_t;
 89	BOOL mIsSelf;
 90	
 91public:
 92	// Constructor
 93	LLMotionController();
 94
 95	// Destructor
 96	virtual ~LLMotionController();
 97
 98	// set associated character
 99	// this must be called exactly once by the containing character class.
100	// this is generally done in the Character constructor
101	void setCharacter( LLCharacter *character );
102
103	// registers a motion with the controller
104	// (actually just forwards call to motion registry)
105	// returns true if successfull
106	BOOL registerMotion( const LLUUID& id, LLMotionConstructor create );
107
108	// creates a motion from the registry
109	LLMotion *createMotion( const LLUUID &id );
110
111	// unregisters a motion with the controller
112	// (actually just forwards call to motion registry)
113	// returns true if successfull
114	void removeMotion( const LLUUID& id );
115
116	// start motion
117	// begins playing the specified motion
118	// returns true if successful
119	BOOL startMotion( const LLUUID &id, F32 start_offset );
120
121	// stop motion
122	// stops a playing motion
123	// in reality, it begins the ease out transition phase
124	// returns true if successful
125	BOOL stopMotionLocally( const LLUUID &id, BOOL stop_immediate );
126
127	// Move motions from loading to loaded
128	void updateLoadingMotions();
129	
130	// update motions
131	// invokes the update handlers for each active motion
132	// activates sequenced motions
133	// deactivates terminated motions`
134	void updateMotions(bool force_update = false);
135
136	// minimal update (e.g. while hidden)
137	void updateMotionsMinimal();
138
139	void clearBlenders() { mPoseBlender.clearBlenders(); }
140
141	// flush motions
142	// releases all motion instances
143	void flushAllMotions();
144
145	//Flush is a liar.
146	void deactivateAllMotions();	
147
148	// pause and continue all motions
149	void pauseAllMotions();
150	void unpauseAllMotions();
151	BOOL isPaused() const { return mPaused; }
152
153	void setTimeStep(F32 step);
154
155	void setTimeFactor(F32 time_factor);
156	F32 getTimeFactor() const { return mTimeFactor; }
157
158	motion_list_t& getActiveMotions() { return mActiveMotions; }
159
160	void incMotionCounts(S32& num_motions, S32& num_loading_motions, S32& num_loaded_motions, S32& num_active_motions, S32& num_deprecated_motions);
161	
162//protected:
163	bool isMotionActive( LLMotion *motion );
164	bool isMotionLoading( LLMotion *motion );
165	LLMotion *findMotion( const LLUUID& id ) const;
166
167	void dumpMotions();
168
169	const LLFrameTimer& getFrameTimer() { return mTimer; }
170
171protected:
172	// internal operations act on motion instances directly
173	// as there can be duplicate motions per id during blending overlap
174	void deleteAllMotions();
175	BOOL activateMotionInstance(LLMotion *motion, F32 time);
176	BOOL deactivateMotionInstance(LLMotion *motion);
177	void deprecateMotionInstance(LLMotion* motion);
178	BOOL stopMotionInstance(LLMotion *motion, BOOL stop_imemdiate);
179	void removeMotionInstance(LLMotion* motion);
180	void updateRegularMotions();
181	void updateAdditiveMotions();
182	void resetJointSignatures();
183	void updateMotionsByType(LLMotion::LLMotionBlendType motion_type);
184	void updateIdleMotion(LLMotion* motionp);
185	void updateIdleActiveMotions();
186	void purgeExcessMotions();
187	void deactivateStoppedMotions();
188
189protected:
190	F32					mTimeFactor;
191	static LLMotionRegistry	sRegistry;
192	LLPoseBlender		mPoseBlender;
193
194	LLCharacter			*mCharacter;
195
196//	Life cycle of an animation:
197//
198//	Animations are instantiated and immediately put in the mAllMotions map for their entire lifetime.
199//	If the animations depend on any asset data, the appropriate data is fetched from the data server,
200//	and the animation is put on the mLoadingMotions list.
201//	Once an animations is loaded, it will be initialized and put on the mLoadedMotions list.
202//	Any animation that is currently playing also sits in the mActiveMotions list.
203
204	typedef std::map<LLUUID, LLMotion*> motion_map_t;
205	motion_map_t	mAllMotions;
206
207	motion_set_t		mLoadingMotions;
208	motion_set_t		mLoadedMotions;
209	motion_list_t		mActiveMotions;
210	motion_set_t		mDeprecatedMotions;
211	
212	LLFrameTimer		mTimer;
213	F32					mPrevTimerElapsed;
214	F32					mAnimTime;
215	F32					mLastTime;
216	BOOL				mHasRunOnce;
217	BOOL				mPaused;
218	F32					mPauseTime;
219	F32					mTimeStep;
220	S32					mTimeStepCount;
221	F32					mLastInterp;
222
223	U8					mJointSignature[2][LL_CHARACTER_MAX_JOINTS];
224};
225
226//-----------------------------------------------------------------------------
227// Class declaractions
228//-----------------------------------------------------------------------------
229#include "llcharacter.h"
230
231#endif // LL_LLMOTIONCONTROLLER_H
232