PageRenderTime 94ms CodeModel.GetById 52ms app.highlight 34ms RepoModel.GetById 3ms app.codeStats 0ms

/indra/llcharacter/llmotion.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 264 lines | 110 code | 58 blank | 96 comment | 0 complexity | 012cd139b06a2364ea7e7c77a1e2376b MD5 | raw file
  1/** 
  2 * @file llmotion.h
  3 * @brief Implementation of LLMotion 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_LLMOTION_H
 28#define LL_LLMOTION_H
 29
 30//-----------------------------------------------------------------------------
 31// Header files
 32//-----------------------------------------------------------------------------
 33#include <string>
 34
 35#include "llerror.h"
 36#include "llpose.h"
 37#include "lluuid.h"
 38
 39class LLCharacter;
 40
 41//-----------------------------------------------------------------------------
 42// class LLMotion
 43//-----------------------------------------------------------------------------
 44class LLMotion
 45{
 46	friend class LLMotionController;
 47	
 48public:
 49	enum LLMotionBlendType
 50	{
 51		NORMAL_BLEND,
 52		ADDITIVE_BLEND
 53	};
 54
 55	enum LLMotionInitStatus
 56	{
 57		STATUS_FAILURE,
 58		STATUS_SUCCESS,
 59		STATUS_HOLD
 60	};
 61
 62	// Constructor
 63	LLMotion(const LLUUID &id);
 64
 65	// Destructor
 66	virtual ~LLMotion();
 67
 68public:
 69	//-------------------------------------------------------------------------
 70	// functions to support MotionController and MotionRegistry
 71	//-------------------------------------------------------------------------
 72
 73	// get the name of this instance
 74	const std::string &getName() const { return mName; }
 75
 76	// set the name of this instance
 77	void setName(const std::string &name) { mName = name; }
 78
 79	const LLUUID& getID() const { return mID; }
 80
 81	// returns the pose associated with the current state of this motion
 82	virtual LLPose* getPose() { return &mPose;}
 83
 84	void fadeOut();
 85
 86	void fadeIn();
 87
 88	F32 getFadeWeight() const { return mFadeWeight; }
 89
 90	F32 getStopTime() const { return mStopTimestamp; }
 91
 92	virtual void setStopTime(F32 time);
 93
 94	BOOL isStopped() const { return mStopped; }
 95
 96	void setStopped(BOOL stopped) { mStopped = stopped; }
 97
 98	BOOL isBlending();
 99
100	// Activation functions.
101	// It is OK for other classes to activate a motion,
102	// but only the controller can deactivate it.
103	// Thus, if mActive == TRUE, the motion *may* be on the controllers active list,
104	// but if mActive == FALSE, the motion is gauranteed not to be on the active list.
105protected:
106	// Used by LLMotionController only
107	void deactivate();
108	BOOL isActive() { return mActive; }
109public:
110	void activate(F32 time);
111	
112public:
113	//-------------------------------------------------------------------------
114	// animation callbacks to be implemented by subclasses
115	//-------------------------------------------------------------------------
116
117	// motions must specify whether or not they loop
118	virtual BOOL getLoop() = 0;
119
120	// motions must report their total duration
121	virtual F32 getDuration() = 0;
122
123	// motions must report their "ease in" duration
124	virtual F32 getEaseInDuration() = 0;
125
126	// motions must report their "ease out" duration.
127	virtual F32 getEaseOutDuration() = 0;
128
129	// motions must report their priority level
130	virtual LLJoint::JointPriority getPriority() = 0;
131
132	// motions must report their blend type
133	virtual LLMotionBlendType getBlendType() = 0;
134
135	// called to determine when a motion should be activated/deactivated based on avatar pixel coverage
136	virtual F32 getMinPixelArea() = 0;
137
138	// run-time (post constructor) initialization,
139	// called after parameters have been set
140	// must return true to indicate success and be available for activation
141	virtual LLMotionInitStatus onInitialize(LLCharacter *character) = 0;
142
143	// called per time step
144	// must return TRUE while it is active, and
145	// must return FALSE when the motion is completed.
146	virtual BOOL onUpdate(F32 activeTime, U8* joint_mask) = 0;
147
148	// called when a motion is deactivated
149	virtual void onDeactivate() = 0;
150
151	// can we crossfade this motion with a new instance when restarted?
152	// should ultimately always be TRUE, but lack of emote blending, etc
153	// requires this
154	virtual BOOL canDeprecate();
155
156	// optional callback routine called when animation deactivated.
157	void	setDeactivateCallback( void (*cb)(void *), void* userdata );
158
159protected:
160	// called when a motion is activated
161	// must return TRUE to indicate success, or else
162	// it will be deactivated
163	virtual BOOL onActivate() = 0;
164
165	void addJointState(const LLPointer<LLJointState>& jointState);
166
167protected:
168	LLPose		mPose;
169	BOOL		mStopped;		// motion has been stopped;
170	BOOL		mActive;		// motion is on active list (can be stopped or not stopped)
171
172	//-------------------------------------------------------------------------
173	// these are set implicitly by the motion controller and
174	// may be referenced (read only) in the above handlers.
175	//-------------------------------------------------------------------------
176	std::string		mName;			// instance name assigned by motion controller
177	LLUUID			mID;
178	
179	F32 mActivationTimestamp;	// time when motion was activated
180	F32 mStopTimestamp;			// time when motion was told to stop
181	F32 mSendStopTimestamp;		// time when simulator should be told to stop this motion
182	F32 mResidualWeight;		// blend weight at beginning of stop motion phase
183	F32 mFadeWeight;			// for fading in and out based on LOD
184	U8	mJointSignature[3][LL_CHARACTER_MAX_JOINTS];	// signature of which joints are animated at what priority
185	void (*mDeactivateCallback)(void* data);
186	void* mDeactivateCallbackUserData;
187};
188
189
190//-----------------------------------------------------------------------------
191// LLTestMotion
192//-----------------------------------------------------------------------------
193class LLTestMotion : public LLMotion
194{
195public:
196	LLTestMotion(const LLUUID &id) : LLMotion(id){}
197	~LLTestMotion() {}
198	static LLMotion *create(const LLUUID& id) { return new LLTestMotion(id); }
199	BOOL getLoop() { return FALSE; }
200	F32 getDuration() { return 0.0f; }
201	F32 getEaseInDuration() { return 0.0f; }
202	F32 getEaseOutDuration() { return 0.0f; }
203	LLJoint::JointPriority getPriority() { return LLJoint::HIGH_PRIORITY; }
204	LLMotionBlendType getBlendType() { return NORMAL_BLEND; }
205	F32 getMinPixelArea() { return 0.f; }
206	
207	LLMotionInitStatus onInitialize(LLCharacter*) { llinfos << "LLTestMotion::onInitialize()" << llendl; return STATUS_SUCCESS; }
208	BOOL onActivate() { llinfos << "LLTestMotion::onActivate()" << llendl; return TRUE; }
209	BOOL onUpdate(F32 time, U8* joint_mask) { llinfos << "LLTestMotion::onUpdate(" << time << ")" << llendl; return TRUE; }
210	void onDeactivate() { llinfos << "LLTestMotion::onDeactivate()" << llendl; }
211};
212
213
214//-----------------------------------------------------------------------------
215// LLNullMotion
216//-----------------------------------------------------------------------------
217class LLNullMotion : public LLMotion
218{
219public:
220	LLNullMotion(const LLUUID &id) : LLMotion(id) {}
221	~LLNullMotion() {}
222	static LLMotion *create(const LLUUID &id) { return new LLNullMotion(id); }
223
224	// motions must specify whether or not they loop
225	/*virtual*/ BOOL getLoop() { return TRUE; }
226
227	// motions must report their total duration
228	/*virtual*/ F32 getDuration() { return 1.f; }
229
230	// motions must report their "ease in" duration
231	/*virtual*/ F32 getEaseInDuration() { return 0.f; }
232
233	// motions must report their "ease out" duration.
234	/*virtual*/ F32 getEaseOutDuration() { return 0.f; }
235
236	// motions must report their priority level
237	/*virtual*/ LLJoint::JointPriority getPriority() { return LLJoint::HIGH_PRIORITY; }
238
239	// motions must report their blend type
240	/*virtual*/ LLMotionBlendType getBlendType() { return NORMAL_BLEND; }
241
242	// called to determine when a motion should be activated/deactivated based on avatar pixel coverage
243	/*virtual*/ F32 getMinPixelArea() { return 0.f; }
244
245	// run-time (post constructor) initialization,
246	// called after parameters have been set
247	// must return true to indicate success and be available for activation
248	/*virtual*/ LLMotionInitStatus onInitialize(LLCharacter *character) { return STATUS_SUCCESS; }
249
250	// called when a motion is activated
251	// must return TRUE to indicate success, or else
252	// it will be deactivated
253	/*virtual*/ BOOL onActivate() { return TRUE; }
254
255	// called per time step
256	// must return TRUE while it is active, and
257	// must return FALSE when the motion is completed.
258	/*virtual*/ BOOL onUpdate(F32 activeTime, U8* joint_mask) { return TRUE; }
259
260	// called when a motion is deactivated
261	/*virtual*/ void onDeactivate() {}
262};
263#endif // LL_LLMOTION_H
264