proto.cpp 7.2 KB

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