Merge branch '164-crash-on-patching-and-possibly-right-after-login' into main/gingo...
[ryzomcore.git] / ryzom / client / src / entity_animation_manager.h
blob369be3332002432f46c63222c8e16b3676972c73
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef CL_ENTITY_ANIMATION_MANAGER_H
21 #define CL_ENTITY_ANIMATION_MANAGER_H
24 /////////////
25 // INCLUDE //
26 /////////////
27 // Misc
28 #include "nel/misc/types_nl.h"
29 #include "nel/misc/vector.h"
30 #include "nel/misc/quat.h"
31 // 3d
32 #include "nel/3d/animation_time.h"
33 #include "nel/3d/u_animation.h"
34 #include "nel/3d/u_track.h"
35 // Client Sheets
36 #include "client_sheets/automaton_list_sheet.h"
37 #include "client_sheets/animation_set_list_sheet.h"
38 #include "client_sheets/emot_list_sheet.h"
39 // Client
40 #include "animation_set.h"
41 #include "animation_misc.h"
42 // STL
43 #include <string>
46 ///////////
47 // USING //
48 ///////////
49 using NL3D::CAnimationTime;
52 ///////////
53 // CLASS //
54 ///////////
55 namespace NL3D
57 class UAnimationSet;
58 class UPlayListManager;
59 class UPlayList;
62 namespace NLMISC
64 class IProgressCallback;
67 /**
68 * Class with infos for each face emotions.
69 * \author Guillaume PUZIN (GUIGUI)
70 * \author Nevrax France
71 * \date 2001
73 class CFaceEmotion
75 public:
76 std::map<std::string, float> _Anims;
78 void addAnim(const std::string &filename, float percentage)
80 _Anims.insert(std::make_pair(filename, percentage));
85 /**
86 * Class to manage animation of entities displayed by the client
87 * \author Guillaume PUZIN (GUIGUI)
88 * \author Stephane Coutelas
89 * \author Nevrax France
90 * \date 2001
92 class CEntityAnimationManager
94 public:
95 // Data tyype for Emotions for the face.
96 typedef std::map<std::string, CFaceEmotion> TFaceEmotions;
98 typedef std::map<std::string, CAnimationSet> TAnimSet;
100 private:
101 /// the only one instance of the class
102 static CEntityAnimationManager *_Instance;
104 /// playlist manager
105 static NL3D::UPlayListManager *_PlayListManager;
107 /// The Animation Set with all character animations.
108 NL3D::UAnimationSet *_AnimationSet;
110 /// list of animation set.
111 TAnimSet _AnimSet;
113 /// Automaton used for animations
114 CAutomatonListSheet *_AutomatonList;
116 /// Emots List
117 CEmotListSheet *_EmotList;
118 //std::vector<TAnimStateId> _Emots;
120 /// Animation set cache
121 std::vector<NL3D::UTrack*> _AnimationSetPosCache;
122 std::vector<NL3D::UTrack*> _AnimationSetRotCache;
127 /// Animation Sets for the face
128 std::map<CTypeEntity, NL3D::UAnimationSet *> _FaceAnimationSets;
129 /// automaton for moving animations
130 std::map<CTypeEntity, TFaceEmotions> _FaceEmotionsPerType;
135 * Load table containing infos about face animations.
136 * \param type : table is different according to the type.
137 * \param fileName : the name of the file containing the animation infos.
139 // void loadFaceAnimations(const CTypeEntity& type, const char * fileName);
141 protected :
142 /// Constructor
143 CEntityAnimationManager();
145 /// Create an animation set for the Face.
146 // void createFaceAnimationSet(const CTypeEntity& type);
149 public :
151 * Instanciate CEntityAnimationManager. There can be only one instance (singleton)
152 * \return CEntityAnimationManager * : Pointer on CEntityAnimationManager.
154 static CEntityAnimationManager * getInstance();
155 /// \warning If you the kept the pointer given by getInstance, it will be invalid.
156 static void delInstance();
158 public :
159 /// Destructor.
160 ~CEntityAnimationManager();
162 /// Release
163 void release();
164 /// (Re-)Initialize
166 void load(NLMISC::IProgressCallback &progress, bool forceRepack = false);
169 * Animate all the playlists.
170 * \param double time : play time.
172 void animate(double time);
173 void setup(double time);
176 * Return a ref on a state of the moving automaton defined by its key.
177 * \param string automatonName : the automaton's name.
178 * \param TAnimStateKey key : the key of the state.
179 * \return CMovingAutomatonState * : pointer on the moving automaton state or 0.
181 const CAutomatonStateSheet *mState(const std::string &automaton, TAnimStateKey key);
185 * Delete a play list.
186 * \param UPlayList * pl : pointer on the play list to delete.
188 void deletePlayList(NL3D::UPlayList * pl);
191 * Process all logical tracks(sound, etc..) which come along with the animation.
192 * \param string animListName : the animation list in witch to search.
193 * \param TAnimStateKey animationId : the id of the animation.
194 * \param CAnimationTime startTimeOffset :the start time in the animation play.
195 * \param CAnimationTime endTimeOffset : the end time in the animation play.
197 void processLogic(const std::string &animListName, TAnimStateKey animationId, CAnimationTime startTimeOffset, CAnimationTime endTimeOffset, NL3D::UTrack *&soundTrack, std::vector<NL3D::CAnimationTime>& result);
200 /** \name INFORMATION ABOUT ANIMATIONS
201 * Methods to get information about an animation.
203 //@{
205 * Function to get the position in animation at timeOffset.
206 * \param idAnim : id of the animation.
207 * \param timeOffset : time for the interpolation.
208 * \param result : is the reference on the value to get the result (position).
209 * \return bool : true if the parameter result is valid.
211 bool interpolate(uint idAnim, double timeOffset, NLMISC::CVector &result) const
213 H_AUTO ( RZ_Client_Entity_Anim_Mngr_Interpolate )
215 // Check Params
216 if(idAnim >= _AnimationSetPosCache.size())
218 //nlwarning("EAM:interpolate(vect): idAnim(%d) invalid.", idAnim);
219 return false;
222 NL3D::UTrack *track = _AnimationSetPosCache[idAnim];
223 if (track)
224 return track->interpolate((CAnimationTime)timeOffset, result);
225 return false;
228 * Function to get the rotation in animation at timeOffset.
229 * \param idAnim : id of the animation.
230 * \param timeOffset : time for the interpolation.
231 * \param result : is the reference on the value to get the result (rotation).
232 * \return bool : true if the parameter result is valid.
234 bool interpolate(uint idAnim, double timeOffset, NLMISC::CQuat &result) const
236 H_AUTO ( RZ_Client_Entity_Anim_Mngr_Interpolate )
238 // Check Params
239 if(idAnim >= _AnimationSetRotCache.size())
241 //nlwarning("EAM:interpolate(quat): idAnim(%d) invalid.", idAnim);
242 return false;
245 NL3D::UTrack *track = _AnimationSetRotCache[idAnim];
246 if (track)
247 return track->interpolate((CAnimationTime)timeOffset, result);
248 return false;
252 * Return an animation length (in sec).
253 * \param string animName : Animation Name.
254 * \return double : the length of the animation.
255 * \warning This method never return a value <= 0.0 and so will return 1.0 instead.
256 * \warning This Method is slower than the one with the animation Id instead of the animation Name.
258 double getAnimationLength(const std::string &animName) const;
260 * Return an animation length (in sec).
261 * \param idAnim : id of the animation.
262 * \return double : the length of the animation.
263 * \warning This method never return a value <= 0.0 and so will return 1.0 instead.
265 double getAnimationLength(uint idAnim)const;
268 * Get the average speed of an animation (in meters/sec).
269 * \param string animName : Animation Name.
270 * \return double : the average speed (in m/s).
272 double getAnimationAverageSpeed(const std::string &animName) const;
274 * Get the average speed of an animation (in meters/sec).
275 * \param idAnim : id of the animation.
276 * \return double : the average speed (in m/s).
278 double getAnimationAverageSpeed(uint idAnim) const;
279 //@}
283 * Get the minimum speed factor that can be used to play the animation.
284 * \param animSet : Set of animations used.
285 * \param animStateId : the animation State.
286 * \param idAnim : the id of the animation.
287 * \return double : the minimum speed factor or -1 if any pb.
289 double getAnimMinSpeedFactor(const std::string &animSet, const TAnimStateId &animStateId, const CAnimation::TAnimId &idAnim) const;
292 * Get the maximum speed factor that can be used to play the animation
293 * \param animSet : Set of animations used.
294 * \param animStateId : the animation State.
295 * \param idAnim : the id of the animation.
296 * \return double : the maximum speed factor or -1 if any pb.
298 double getAnimMaxSpeedFactor(const std::string &animSet, const TAnimStateId &animStateId, const CAnimation::TAnimId &idAnim) const;
302 * Return a pointer on the set according to the set name.
303 * \param animSet : name of the set.
304 * \return CAnimationSet * : pointer of the right Set or 0.
306 const CAnimationSet *getAnimSet(const std::string &animSet) const;
310 * Get the animation set.
311 * \return UAnimationSet * : a pointer on the animation set or 0 if there is not animation set.
313 NL3D::UAnimationSet * getAnimationSet() {return _AnimationSet;}
316 * Create a playlist.
317 * \return UPlayList * : a pointer on a play list or 0 if any pb.
319 NL3D::UPlayList *createPlayList() const;
322 /// Serialize a CEntityAnimationManager.
323 void serial(NLMISC::IStream &f);
325 /** Count the number of emot
326 * \return uint : the number of emot already known.
328 uint getNbEmots() {return (uint)_EmotList->Emots.size();}
329 /** Method to get the emot associated to an index.
330 * \param index : number of the emot asked.
331 * \param result : will be filled with the name of the emot associated.
332 * \return bool : true if the result has been filled, false if the index is invalid.
334 bool getEmot(uint index, TAnimStateId &result)
336 if(index < _EmotList->Emots.size())
338 result = _EmotList->Emots[index];
339 return true;
341 else
342 return false;
345 /// For Reload Sound feature
346 void resetAllSoundAnimId();
347 void reloadAllSoundAnim();
350 * Create an uninitialized playlist for the face animations.
351 * \param type : type of the play list to create.
352 * \return UPlayList * : a pointer on an initialized play list.
354 // NL3D::UPlayList *CEntityAnimationManager::createFacePlayList(const CTypeEntity& type);
357 * Get an animation set for face.
358 * \param type : type of the animation set you want.
359 * \return UAnimationSet * : a pointer on the animation set or 0 if there is not animation set for this type.
361 // NL3D::UAnimationSet * getFaceAnimationSet(const CTypeEntity& type);
364 * Choose an animation for the face according to the type and the emotion.
365 * \param type : type of the face.
366 * \param emotion : emotion to play.
367 * \return uint : the index of the animation.
369 // uint chooseFaceAnim(const CTypeEntity& type, const std::string &emotion);
374 #endif // CL_ENTITY_ANIMATION_MANAGER_H
376 /* End of entity_animation_manager.h */