hanim.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. /* $Header: /Commando/Code/ww3d2/hanim.h 3 12/13/01 7:01p Patrick $ */
  19. /***********************************************************************************************
  20. *** Confidential - Westwood Studios ***
  21. ***********************************************************************************************
  22. * *
  23. * Project Name : Commando / G 3D Library *
  24. * *
  25. * $Archive:: /Commando/Code/ww3d2/hanim.h $*
  26. * *
  27. * Author:: Greg_h *
  28. * *
  29. * $Modtime:: 12/13/01 6:54p $*
  30. * *
  31. * $Revision:: 3 $*
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  36. #if defined(_MSC_VER)
  37. #pragma once
  38. #endif
  39. #ifndef HANIM_H
  40. #define HANIM_H
  41. #include "always.h"
  42. #include "quat.h"
  43. #include "refcount.h"
  44. #include "w3d_file.h"
  45. #include "hash.h"
  46. #include "mempool.h"
  47. #include <refcount.h>
  48. #include <slist.h>
  49. #include <vector.h>
  50. struct NodeMotionStruct;
  51. class MotionChannelClass;
  52. class BitChannelClass;
  53. class HTreeClass;
  54. class ChunkLoadClass;
  55. class ChunkSaveClass;
  56. class HTreeClass;
  57. /**********************************************************************************
  58. HAnimClass
  59. This is the base class for all animation formats used in W3D. It
  60. contains the virtual interface that all animations must support.
  61. **********************************************************************************/
  62. class HAnimClass : public RefCountClass, public HashableClass
  63. {
  64. public:
  65. HAnimClass(void) :
  66. HasEmbeddedSounds (false) { }
  67. virtual ~HAnimClass(void) { }
  68. virtual const char * Get_Name(void) const = 0;
  69. virtual const char * Get_HName(void) const = 0;
  70. virtual const char * Get_Key( void ) { return Get_Name(); }
  71. virtual int Get_Num_Frames(void) = 0;
  72. virtual float Get_Frame_Rate() = 0;
  73. virtual float Get_Total_Time() = 0;
  74. // virtual Vector3 Get_Translation(int pividx,float frame) = 0;
  75. // virtual Quaternion Get_Orientation(int pividx,float frame) = 0;
  76. // Jani: Changed to pass in reference of destination to avoid copying
  77. virtual void Get_Translation(int pividx,float frame) {} // todo: remove
  78. virtual void Get_Orientation(int pividx,float frame) {} // todo: remove
  79. virtual void Get_Translation(Vector3& translation, int pividx,float frame) const = 0;
  80. virtual void Get_Orientation(Quaternion& orientation, int pividx,float frame) const = 0;
  81. virtual void Get_Transform(Matrix3D&, int pividx, float frame) const = 0;
  82. virtual bool Get_Visibility(int pividx,float frame) = 0;
  83. virtual int Get_Num_Pivots(void) const = 0;
  84. virtual bool Is_Node_Motion_Present(int pividx) = 0;
  85. // Methods that test the presence of a certain motion channel.
  86. virtual bool Has_X_Translation (int pividx) { return true; }
  87. virtual bool Has_Y_Translation (int pividx) { return true; }
  88. virtual bool Has_Z_Translation (int pividx) { return true; }
  89. virtual bool Has_Rotation (int pividx) { return true; }
  90. virtual bool Has_Visibility (int pividx) { return true; }
  91. // Animated sound-triggering support
  92. virtual bool Has_Embedded_Sounds (void) const { return HasEmbeddedSounds; }
  93. virtual void Set_Has_Embedded_Sounds (bool onoff) { HasEmbeddedSounds = onoff; }
  94. protected:
  95. bool HasEmbeddedSounds;
  96. };
  97. /*
  98. ** The PivotMapClass is used by the HAnimComboDataClass (sometimes) to keep track of animation
  99. ** weights per-pivot point.
  100. */
  101. class NamedPivotMapClass;
  102. class PivotMapClass : public DynamicVectorClass<float>, public RefCountClass
  103. {
  104. public:
  105. virtual NamedPivotMapClass * As_Named_Pivot_Map() { return 0; }
  106. };
  107. /*
  108. ** The NamedPivotMapClass allows us to create HAnimComboDataClass objects with pivot maps without
  109. ** having to have the HAnim available. Later, when an HAnim is retrieved from the asset manager,
  110. ** the pivot map can be updated to produce the correct map.
  111. */
  112. class NamedPivotMapClass : public PivotMapClass
  113. {
  114. public:
  115. ~NamedPivotMapClass(void);
  116. virtual NamedPivotMapClass * As_Named_Pivot_Map() { return this; }
  117. // add a name & weight to the arrays
  118. void Add(const char *Name, float Weight);
  119. // configure the base pivot map using the specified tree
  120. void Update_Pivot_Map(const HTreeClass *Tree);
  121. private:
  122. // This info is packaged into a struct to minimize DynamicVectorClass overhead
  123. struct WeightInfoStruct {
  124. WeightInfoStruct() : Name(0) {}
  125. ~WeightInfoStruct() { if(Name) delete [] Name; }
  126. char *Name;
  127. float Weight;
  128. // operators required for the DynamicVectorClass
  129. WeightInfoStruct & operator = (WeightInfoStruct const &that);
  130. bool operator == (WeightInfoStruct const &that) const { return &that == this; }
  131. bool operator != (WeightInfoStruct const &that) const { return &that != this; }
  132. };
  133. DynamicVectorClass<WeightInfoStruct> WeightInfo;
  134. };
  135. /*
  136. ** The HAnimComboDataClass is used by the new HAnimComboClass to allow for a mix of shared/unshared data
  137. ** which will allow us to have the anim combo refer to data whereever we wish to put it.
  138. */
  139. class HAnimComboDataClass : public AutoPoolClass<HAnimComboDataClass,256> {
  140. public:
  141. HAnimComboDataClass(bool shared = false);
  142. HAnimComboDataClass(const HAnimComboDataClass &);
  143. ~HAnimComboDataClass(void);
  144. void Copy(const HAnimComboDataClass *);
  145. void Clear(void);
  146. void Set_HAnim(HAnimClass *motion);
  147. void Give_HAnim(HAnimClass *motion) { if(HAnim) HAnim->Release_Ref(); HAnim = motion; } // used for giving this object the reference
  148. void Set_Frame(float frame) { PrevFrame = Frame; Frame = frame; }
  149. void Set_Prev_Frame(float frame) { PrevFrame = frame; }
  150. void Set_Weight(float weight) { Weight = weight; }
  151. void Set_Pivot_Map(PivotMapClass *map);
  152. HAnimClass * Peek_HAnim(void) const { return HAnim; } // note: does not add reference
  153. HAnimClass * Get_HAnim(void) const { if(HAnim) HAnim->Add_Ref(); return HAnim; } // note: does not add reference
  154. float Get_Frame(void) const { return Frame; }
  155. float Get_Prev_Frame(void) const { return PrevFrame; }
  156. float Get_Weight(void) const { return Weight; }
  157. PivotMapClass * Peek_Pivot_Map(void) const { return PivotMap; }
  158. PivotMapClass * Get_Pivot_Map(void) const { if(PivotMap) PivotMap->Add_Ref(); return PivotMap; }
  159. bool Is_Shared(void) const { return Shared; }
  160. void Build_Active_Pivot_Map(void);
  161. private:
  162. HAnimClass *HAnim;
  163. float Frame;
  164. float PrevFrame;
  165. float Weight;
  166. PivotMapClass * PivotMap;
  167. bool Shared; // this is set to false when the HAnimCombo allocates it
  168. };
  169. /*
  170. ** defines a combination of animations for blending/mixing
  171. */
  172. class HAnimComboClass {
  173. public:
  174. HAnimComboClass(void);
  175. HAnimComboClass( int num_animations ); // allocates specified number of channels and sets then all to not-shared
  176. ~HAnimComboClass(void);
  177. void Clear( void ); // zeros all data
  178. void Reset( void ); // empties the dynamic vector
  179. bool Normalize_Weights(void); // Normalizes all weights (returns true if succeeded)
  180. int Get_Num_Anims( void ) { return HAnimComboData.Count(); }
  181. void Set_Motion( int indx, HAnimClass *motion );
  182. HAnimClass *Get_Motion( int indx );
  183. HAnimClass *Peek_Motion( int indx );
  184. void Set_Frame( int indx, float frame );
  185. void Set_Prev_Frame( int indx, float frame );
  186. float Get_Frame( int indx );
  187. float Get_Prev_Frame( int indx );
  188. void Set_Weight( int indx, float weight );
  189. float Get_Weight( int indx );
  190. void Set_Pivot_Weight_Map( int indx, PivotMapClass * map );
  191. PivotMapClass * Get_Pivot_Weight_Map( int indx );
  192. PivotMapClass * Peek_Pivot_Weight_Map( int indx );
  193. // add an entry to the dynamic vector
  194. void Append_Anim_Combo_Data(HAnimComboDataClass * AnimComboData);
  195. // remove an entry from the vector
  196. void Remove_Anim_Combo_Data(HAnimComboDataClass * AnimComboData);
  197. // retrieve a specific combo data
  198. HAnimComboDataClass * Peek_Anim_Combo_Data(int index) { return HAnimComboData[index]; }
  199. protected:
  200. DynamicVectorClass<HAnimComboDataClass *> HAnimComboData;
  201. };
  202. #endif