agg_def.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /*
  2. ** Command & Conquer Generals(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. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : WW3D *
  23. * *
  24. * $Archive:: /Commando/Code/ww3d2/agg_def.h $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 4/05/01 9:52a $*
  29. * *
  30. * $Revision:: 2 $*
  31. * *
  32. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  33. #if defined(_MSC_VER)
  34. #pragma once
  35. #endif
  36. #ifndef AGGREGATE_DEF_H
  37. #define AGGREGATE_DEF_H
  38. #include "proto.h"
  39. #include "rendobj.h"
  40. #include "w3d_file.h"
  41. #include "w3derr.h"
  42. #include "vector.h"
  43. #include "bittype.h"
  44. #include <string.h>
  45. #ifdef _UNIX
  46. #include "osdep.h"
  47. #endif
  48. // Forward declarations
  49. class ChunkLoadClass;
  50. class ChunkSaveClass;
  51. class IndirectTextureClass;
  52. ///////////////////////////////////////////////////////////////////////////////////
  53. //
  54. // Macros
  55. //
  56. #ifndef SAFE_FREE
  57. #define SAFE_FREE(pointer) \
  58. { \
  59. if (pointer) { \
  60. ::free (pointer); \
  61. pointer = 0; \
  62. } \
  63. }
  64. #endif //SAFE_FREE
  65. //////////////////////////////////////////////////////////////////////////////////
  66. //
  67. // AggregateDefClass
  68. //
  69. // Description of an aggregate object. Used by the asset manager
  70. // to construct aggregates. An 'aggregate' is simply a 'shell' that
  71. // contains references to a hierarchy model and subobjects to attach to its bones.
  72. //
  73. class AggregateDefClass
  74. {
  75. public:
  76. ///////////////////////////////////////////////////////////
  77. //
  78. // Public constructors/destructors
  79. //
  80. AggregateDefClass (void);
  81. AggregateDefClass (RenderObjClass &base_model);
  82. AggregateDefClass (const AggregateDefClass &src);
  83. virtual ~AggregateDefClass (void);
  84. ///////////////////////////////////////////////////////////
  85. //
  86. // Public operators
  87. //
  88. const AggregateDefClass &operator= (const AggregateDefClass &src);
  89. ///////////////////////////////////////////////////////////
  90. //
  91. // Public methods
  92. //
  93. virtual WW3DErrorType Load_W3D (ChunkLoadClass &chunk_load);
  94. virtual WW3DErrorType Save_W3D (ChunkSaveClass &chunk_save);
  95. const char * Get_Name (void) const { return m_pName; }
  96. void Set_Name (const char *pname) { SAFE_FREE (m_pName); m_pName = ::_strdup (pname); }
  97. RenderObjClass * Create (void);
  98. AggregateDefClass * Clone (void) const { return W3DNEW AggregateDefClass (*this); }
  99. //
  100. // Public accessors
  101. //
  102. ULONG Class_ID (void) const { return m_MiscInfo.OriginalClassID; }
  103. //
  104. // Initialization
  105. //
  106. void Initialize (RenderObjClass &base_model);
  107. protected:
  108. ///////////////////////////////////////////////////////////
  109. //
  110. // Protected data types
  111. //
  112. typedef struct _TEXTURE_INFO
  113. {
  114. W3dTextureReplacerStruct names;
  115. IndirectTextureClass * pnew_texture;
  116. bool operator == (_TEXTURE_INFO &src) { return false; }
  117. bool operator != (_TEXTURE_INFO &src) { return true; }
  118. } TEXTURE_INFO;
  119. ///////////////////////////////////////////////////////////
  120. //
  121. // Protected methods
  122. //
  123. //
  124. // Loading methods
  125. //
  126. virtual WW3DErrorType Read_Header (ChunkLoadClass &chunk_load);
  127. virtual WW3DErrorType Read_Info (ChunkLoadClass &chunk_load);
  128. virtual WW3DErrorType Read_Subobject (ChunkLoadClass &chunk_load);
  129. virtual WW3DErrorType Read_Class_Info (ChunkLoadClass &chunk_load);
  130. //
  131. // Saving methods
  132. //
  133. virtual WW3DErrorType Save_Header (ChunkSaveClass &chunk_save);
  134. virtual WW3DErrorType Save_Info (ChunkSaveClass &chunk_save);
  135. virtual WW3DErrorType Save_Subobject (ChunkSaveClass &chunk_save, W3dAggregateSubobjectStruct *psubobject);
  136. virtual WW3DErrorType Save_Class_Info (ChunkSaveClass &chunk_save);
  137. //
  138. // Creation methods
  139. //
  140. virtual void Attach_Subobjects (RenderObjClass &base_model);
  141. //
  142. // Search methods
  143. //
  144. virtual RenderObjClass * Find_Subobject (RenderObjClass &model, const char mesh_path[MESH_PATH_ENTRIES][MESH_PATH_ENTRY_LEN], const char bone_path[MESH_PATH_ENTRIES][MESH_PATH_ENTRY_LEN]);
  145. //
  146. // Misc. methods
  147. //
  148. virtual void Free_Subobject_List (void);
  149. virtual void Add_Subobject (const W3dAggregateSubobjectStruct &subobj_info);
  150. virtual bool Load_Assets (const char *asset_name);
  151. virtual RenderObjClass *Create_Render_Object (const char *passet_name);
  152. virtual bool Is_Object_In_List (const char *passet_name, DynamicVectorClass <RenderObjClass *> &node_list);
  153. virtual void Build_Subobject_List (RenderObjClass &original_model, RenderObjClass &model);
  154. private:
  155. ///////////////////////////////////////////////////////////
  156. //
  157. // Private member data
  158. //
  159. DWORD m_Version;
  160. DynamicVectorClass<W3dAggregateSubobjectStruct *> m_SubobjectList;
  161. W3dAggregateInfoStruct m_Info;
  162. W3dAggregateMiscInfo m_MiscInfo;
  163. char * m_pName;
  164. };
  165. ///////////////////////////////////////////////////////////////////////////////////
  166. //
  167. // AggregatePrototypeClass
  168. //
  169. class AggregatePrototypeClass : public W3DMPO, public PrototypeClass
  170. {
  171. W3DMPO_GLUE(AggregatePrototypeClass)
  172. public:
  173. ///////////////////////////////////////////////////////////
  174. //
  175. // Public constructors/destructors
  176. //
  177. AggregatePrototypeClass (AggregateDefClass *pdef) { m_pDefinition = pdef; }
  178. ///////////////////////////////////////////////////////////
  179. //
  180. // Public methods
  181. //
  182. virtual const char * Get_Name(void) const { return m_pDefinition->Get_Name (); }
  183. virtual int Get_Class_ID(void) const { return m_pDefinition->Class_ID (); }
  184. virtual RenderObjClass * Create (void) { return m_pDefinition->Create (); }
  185. virtual void DeleteSelf() { delete this; }
  186. virtual AggregateDefClass * Get_Definition (void) const { return m_pDefinition; }
  187. virtual void Set_Definition (AggregateDefClass *pdef) { m_pDefinition = pdef; }
  188. protected:
  189. virtual ~AggregatePrototypeClass (void) { delete m_pDefinition; }
  190. private:
  191. ///////////////////////////////////////////////////////////
  192. //
  193. // Private member data
  194. //
  195. AggregateDefClass * m_pDefinition;
  196. };
  197. ///////////////////////////////////////////////////////////////////////////////////
  198. //
  199. // AggregateLoaderClass
  200. //
  201. class AggregateLoaderClass : public PrototypeLoaderClass
  202. {
  203. public:
  204. virtual int Chunk_Type (void) { return W3D_CHUNK_AGGREGATE; }
  205. virtual PrototypeClass * Load_W3D (ChunkLoadClass &chunk_load);
  206. };
  207. ///////////////////////////////////////////////////////////////////////////////////
  208. //
  209. // Global variables
  210. //
  211. extern AggregateLoaderClass _AggregateLoader;
  212. #endif //__AGGREGATE_DEF_H