proto.cpp 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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/proto.cpp $*
  25. * *
  26. * Org Author:: Greg Hjelstrom *
  27. * *
  28. * Author : Kenny Mitchell *
  29. * *
  30. * $Modtime:: 06/27/02 3:51p $*
  31. * *
  32. * $Revision:: 2 $*
  33. * *
  34. * 06/26/02 KM Integrating shader system
  35. *---------------------------------------------------------------------------------------------*
  36. * Functions: *
  37. * MeshLoaderClass::Load -- reads in a mesh and creates a prototype for it *
  38. * HModelLoaderClass::Load -- reads in an hmodel definition and creates a prototype for it *
  39. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  40. #include "proto.h"
  41. #include "mesh.h"
  42. #include "hmdldef.h"
  43. #include "hlod.h"
  44. #include "w3derr.h"
  45. /*
  46. ** Global instances of the default loaders for the asset manager to install
  47. */
  48. MeshLoaderClass _MeshLoader;
  49. HModelLoaderClass _HModelLoader;
  50. /*
  51. ** Prototype Classes
  52. ** These prototypes are the "built-in" ones for the W3D library.
  53. */
  54. PrimitivePrototypeClass::PrimitivePrototypeClass(RenderObjClass * proto)
  55. {
  56. Proto = proto;
  57. assert(Proto);
  58. Proto->Add_Ref();
  59. }
  60. PrimitivePrototypeClass::~PrimitivePrototypeClass(void)
  61. {
  62. if (Proto) {
  63. Proto->Release_Ref();
  64. }
  65. }
  66. const char * PrimitivePrototypeClass::Get_Name(void) const
  67. {
  68. return Proto->Get_Name();
  69. }
  70. int PrimitivePrototypeClass::Get_Class_ID(void) const
  71. {
  72. return Proto->Class_ID();
  73. }
  74. RenderObjClass * PrimitivePrototypeClass::Create(void)
  75. {
  76. return (RenderObjClass *)( SET_REF_OWNER( Proto->Clone() ) );
  77. }
  78. class HModelPrototypeClass : public W3DMPO, public PrototypeClass
  79. {
  80. W3DMPO_GLUE(HModelPrototypeClass)
  81. public:
  82. HModelPrototypeClass(HModelDefClass * def) { HModelDef = def; assert(HModelDef); }
  83. virtual const char * Get_Name(void) const { return HModelDef->Get_Name(); }
  84. virtual int Get_Class_ID(void) const { return RenderObjClass::CLASSID_HLOD; }
  85. virtual RenderObjClass * Create(void) { return NEW_REF( HLodClass, (*HModelDef) ); }
  86. virtual void DeleteSelf() { delete this; }
  87. HModelDefClass * HModelDef;
  88. protected:
  89. virtual ~HModelPrototypeClass(void) { if (HModelDef) delete HModelDef; }
  90. };
  91. /***********************************************************************************************
  92. * MeshLoaderClass::Load -- reads in a mesh and creates a prototype for it *
  93. * *
  94. * INPUT: *
  95. * *
  96. * OUTPUT: *
  97. * *
  98. * WARNINGS: *
  99. * *
  100. * HISTORY: *
  101. * 7/28/98 GTH : Created. *
  102. *=============================================================================================*/
  103. PrototypeClass * MeshLoaderClass::Load_W3D(ChunkLoadClass & cload)
  104. {
  105. MeshClass * mesh = NEW_REF( MeshClass, () );
  106. if (mesh == NULL) {
  107. return NULL;
  108. }
  109. if (mesh->Load_W3D(cload) != WW3D_ERROR_OK) {
  110. // if the load failed, delete the mesh
  111. assert(mesh->Num_Refs() == 1);
  112. mesh->Release_Ref();
  113. return NULL;
  114. } else {
  115. // create the prototype and add it to the lists
  116. PrimitivePrototypeClass * newproto = W3DNEW PrimitivePrototypeClass(mesh);
  117. mesh->Release_Ref();
  118. return newproto;
  119. }
  120. }
  121. /***********************************************************************************************
  122. * HModelLoaderClass::Load -- reads in an hmodel and creates a prototype for it *
  123. * *
  124. * INPUT: *
  125. * *
  126. * OUTPUT: *
  127. * *
  128. * WARNINGS: *
  129. * *
  130. * HISTORY: *
  131. * 7/28/98 GTH : Created. *
  132. *=============================================================================================*/
  133. PrototypeClass * HModelLoaderClass::Load_W3D(ChunkLoadClass & cload)
  134. {
  135. HModelDefClass * hdef = W3DNEW HModelDefClass;
  136. if (hdef == NULL) {
  137. return NULL;
  138. }
  139. if (hdef->Load_W3D(cload) != HModelDefClass::OK) {
  140. // load failed, delete the model and return an error
  141. delete hdef;
  142. return NULL;
  143. } else {
  144. // ok, accept this model!
  145. HModelPrototypeClass * hproto = W3DNEW HModelPrototypeClass(hdef);
  146. return hproto;
  147. }
  148. }