animcontrol.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Commando *
  23. * *
  24. * $Archive:: /Commando/Code/Combat/animcontrol.h $*
  25. * *
  26. * $Author:: Byon_g $*
  27. * *
  28. * $Modtime:: 1/04/02 10:33a $*
  29. * *
  30. * $Revision:: 36 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #ifndef ANIMCONTROL_H
  36. #define ANIMCONTROL_H
  37. #ifndef ALWAYS_H
  38. #include "always.h"
  39. #endif
  40. #ifndef HANIM_H
  41. #include "hanim.h"
  42. #endif
  43. #ifndef VECTOR_H
  44. #include "vector.h"
  45. #endif
  46. #include "wwstring.h"
  47. /*
  48. **
  49. */
  50. class RenderObjClass;
  51. typedef enum {
  52. ANIM_MODE_ONCE,
  53. ANIM_MODE_LOOP,
  54. ANIM_MODE_STOP,
  55. ANIM_MODE_TARGET
  56. } AnimMode;
  57. /*
  58. ** AnimationDataRecord
  59. */
  60. struct AnimationDataRecord {
  61. HAnimClass *Animation;
  62. float Frame;
  63. float Weight;
  64. bool operator == (AnimationDataRecord const & rec) const { return false; }
  65. bool operator != (AnimationDataRecord const & rec) const { return true; }
  66. };
  67. typedef DynamicVectorClass<AnimationDataRecord> AnimationDataList;
  68. /*
  69. ** AnimChannelClass
  70. */
  71. class AnimChannelClass {
  72. public:
  73. // Constructor and Destructor
  74. AnimChannelClass( void );
  75. AnimChannelClass(const AnimChannelClass &);
  76. AnimChannelClass & operator = (const AnimChannelClass &);
  77. ~AnimChannelClass(void);
  78. virtual bool Save( ChunkSaveClass & csave );
  79. virtual bool Load( ChunkLoadClass & cload );
  80. // Set Animation
  81. void Set_Animation( const char *name );
  82. void Set_Animation( const HAnimClass *anim );
  83. HAnimClass *Peek_Animation( void ) { return Animation; }
  84. // Set Mode
  85. void Set_Mode( AnimMode mode, float frame = -1 );
  86. AnimMode Get_Mode( void ) { return Mode; }
  87. bool Is_Complete( void ) { return (Animation == NULL) || ((Mode == ANIM_MODE_ONCE) && (Frame == NumFrames-1)) || ((Mode == ANIM_MODE_TARGET) && (Frame == TargetFrame)); }
  88. const char *Get_Animation_Name( void ) { return Animation ? Animation->Get_Name() : ""; }
  89. // Frame
  90. void Set_Frame( float frame ) { Frame = frame; }
  91. float Get_Frame( void ) { return Frame; }
  92. float Get_Progress( void ) { return NumFrames ? Frame / NumFrames : 0; }
  93. void Set_Target_Frame( float frame ) { TargetFrame = frame; }
  94. float Get_Target_Frame( void ) { return TargetFrame; }
  95. // Update the animation
  96. void Update( float dtime );
  97. // Get Animation Data
  98. void Get_Animation_Data( AnimationDataList & list, float weight = 1.0f );
  99. // Update Model
  100. void Update_Model( RenderObjClass *anim_model );
  101. private:
  102. HAnimClass * Animation;
  103. float Frame;
  104. float NumFrames;
  105. float TargetFrame;
  106. AnimMode Mode;
  107. };
  108. /*
  109. ** BlendableAnimChannelClass
  110. */
  111. class BlendableAnimChannelClass {
  112. public:
  113. // Constructor
  114. BlendableAnimChannelClass( void );
  115. virtual bool Save( ChunkSaveClass & csave );
  116. virtual bool Load( ChunkLoadClass & cload );
  117. // Set Animation
  118. void Set_Animation( const char *name, float blendtime = 0.0f, float start_frame = 0.0f );
  119. void Set_Animation( const HAnimClass * anim, float blendtime = 0.0f, float start_frame = 0.0f );
  120. void Set_Mode( AnimMode mode, float frame = -1 ) { NewChannel.Set_Mode( mode, frame ); }
  121. AnimMode Get_Mode( void ) { return NewChannel.Get_Mode(); }
  122. bool Is_Complete( void ) { return NewChannel.Is_Complete(); }
  123. const char *Get_Animation_Name( void ) { return NewChannel.Get_Animation_Name(); }
  124. void Set_Target_Frame( float frame ) { NewChannel.Set_Target_Frame ( frame ); }
  125. float Get_Target_Frame( void ) { return NewChannel.Get_Target_Frame(); }
  126. HAnimClass *Peek_Animation( void ) { return NewChannel.Peek_Animation (); }
  127. // Update the animation
  128. void Update( float dtime );
  129. // Get Animation Data
  130. void Get_Animation_Data( AnimationDataList & list, float weight = 1.0f );
  131. // Update Model
  132. void Update_Model( RenderObjClass *anim_model );
  133. // Data Access
  134. float Get_Frame( void ) { return NewChannel.Get_Frame(); }
  135. float Get_Progress( void ) { return NewChannel.Get_Progress(); }
  136. private:
  137. AnimChannelClass NewChannel;
  138. AnimChannelClass OldChannel;
  139. float BlendTimer; // in seconds
  140. float BlendTotal; // in seconds
  141. };
  142. /*
  143. ** AnimControlClass
  144. */
  145. class AnimControlClass {
  146. public:
  147. // Constructor and Destructor
  148. AnimControlClass( void );
  149. virtual ~AnimControlClass( void );
  150. virtual bool Save( ChunkSaveClass & csave );
  151. virtual bool Load( ChunkLoadClass & cload );
  152. // Set Model
  153. virtual void Set_Model( RenderObjClass *anim_model );
  154. virtual RenderObjClass *Peek_Model( void ) { return Model; }
  155. // Set Animation
  156. virtual void Set_Animation( const char *name, float blendtime = 0.0f, float start_frame = 0.0f ) = 0;
  157. virtual void Set_Animation( const HAnimClass * anim, float blendtime = 0.0f, float start_frame = 0.0f ) = 0;
  158. virtual void Set_Mode( AnimMode mode, float frame = -1 ) = 0;
  159. virtual AnimMode Get_Mode( void ) = 0;
  160. virtual bool Is_Complete( void ) = 0;
  161. virtual const char *Get_Animation_Name( void ) = 0;
  162. virtual void Set_Target_Frame( float frame ) = 0;
  163. virtual float Get_Target_Frame( void ) = 0;
  164. virtual float Get_Current_Frame( void ) = 0;
  165. virtual HAnimClass * Peek_Animation( void ) { return NULL; }
  166. // Update the animation
  167. virtual void Update( float dtime ) = 0;
  168. protected:
  169. RenderObjClass *Model;
  170. };
  171. /*
  172. ** SimpleAnimControlClass
  173. */
  174. class SimpleAnimControlClass : public AnimControlClass {
  175. public:
  176. // Constructor and Destructor
  177. SimpleAnimControlClass( void );
  178. ~SimpleAnimControlClass( void );
  179. virtual bool Save( ChunkSaveClass & csave );
  180. virtual bool Load( ChunkLoadClass & cload );
  181. // Set Animation
  182. virtual void Set_Animation( const char *name, float blendtime = 0.0f, float start_frame = 0.0f );
  183. virtual void Set_Animation( const HAnimClass * anim, float blendtime = 0.0f, float start_frame = 0.0f );
  184. virtual void Set_Mode( AnimMode mode, float frame = -1 ) { Channel.Set_Mode( mode, frame ); }
  185. virtual AnimMode Get_Mode( void ) { return Channel.Get_Mode(); }
  186. virtual bool Is_Complete( void ) { return Channel.Is_Complete(); }
  187. virtual const char *Get_Animation_Name( void ) { return Channel.Get_Animation_Name(); }
  188. virtual void Set_Target_Frame( float frame ) { Channel.Set_Target_Frame( frame ); }
  189. virtual float Get_Target_Frame( void ) { return Channel.Get_Target_Frame(); }
  190. virtual float Get_Current_Frame( void ) { return Channel.Get_Frame(); }
  191. // Update the animation
  192. virtual void Update( float dtime );
  193. private:
  194. BlendableAnimChannelClass Channel;
  195. };
  196. /*
  197. ** HumanAnimControlClass
  198. */
  199. class HumanAnimControlClass : public AnimControlClass {
  200. public:
  201. // Constructor and Destructor
  202. HumanAnimControlClass( void );
  203. ~HumanAnimControlClass( void );
  204. virtual bool Save( ChunkSaveClass & csave );
  205. virtual bool Load( ChunkLoadClass & cload );
  206. virtual void Set_Model( RenderObjClass *anim_model );
  207. // Set Animation
  208. virtual void Set_Animation( const char *name, float blendtime = 0.0f, float start_frame = 0.0f );
  209. virtual void Set_Animation( const HAnimClass * anim, float blendtime = 0.0f, float start_frame = 0.0f );
  210. virtual void Set_Animation( const char *name1, const char * name2, float ratio, float blendtime = 0.0f );
  211. virtual void Set_Mode( AnimMode mode, float frame = -1 );
  212. virtual AnimMode Get_Mode( void ) { return Channel1.Get_Mode(); }
  213. virtual bool Is_Complete( void ) { return Channel1.Is_Complete(); }
  214. virtual const char *Get_Animation_Name( void ) { return Channel1.Get_Animation_Name(); }
  215. virtual float Get_Frame( void ) { return Channel1.Get_Frame(); }
  216. virtual float Get_Progress( void ) { return Channel1.Get_Progress(); }
  217. virtual void Set_Target_Frame( float frame ) { Channel1.Set_Target_Frame( frame ); }
  218. virtual float Get_Target_Frame( void ) { return Channel1.Get_Target_Frame(); }
  219. virtual float Get_Current_Frame( void ) { return Channel1.Get_Frame(); }
  220. virtual void Set_Anim_Speed_Scale( float speed ) { AnimSpeedScale = speed; }
  221. virtual void Update( float dtime );
  222. virtual HAnimClass * Peek_Animation( void ) { return Channel1.Peek_Animation(); }
  223. void Get_Information( StringClass & string );
  224. char Get_Skeleton( void ) { return Skeleton; }
  225. private:
  226. BlendableAnimChannelClass Channel1;
  227. BlendableAnimChannelClass Channel2;
  228. float Channel2Ratio;
  229. float AnimSpeedScale;
  230. AnimationDataList DataList;
  231. HAnimComboClass AnimCombo;
  232. char Skeleton;
  233. void Build_Skeleton_Anim_Name( StringClass& new_name, const char * name );
  234. };
  235. #endif // ANIMCONTROL_H