proto.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. *** 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 PrototypeClass
  76. {
  77. public:
  78. HModelPrototypeClass(HModelDefClass * def) { HModelDef = def; assert(HModelDef); }
  79. virtual ~HModelPrototypeClass(void) { if (HModelDef) delete 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. HModelDefClass * HModelDef;
  84. };
  85. /***********************************************************************************************
  86. * MeshLoaderClass::Load -- reads in a mesh and creates a prototype for it *
  87. * *
  88. * INPUT: *
  89. * *
  90. * OUTPUT: *
  91. * *
  92. * WARNINGS: *
  93. * *
  94. * HISTORY: *
  95. * 7/28/98 GTH : Created. *
  96. *=============================================================================================*/
  97. PrototypeClass * MeshLoaderClass::Load_W3D(ChunkLoadClass & cload)
  98. {
  99. MeshClass * mesh = NEW_REF( MeshClass, () );
  100. if (mesh == NULL) {
  101. return NULL;
  102. }
  103. if (mesh->Load_W3D(cload) != WW3D_ERROR_OK) {
  104. // if the load failed, delete the mesh
  105. assert(mesh->Num_Refs() == 1);
  106. mesh->Release_Ref();
  107. return NULL;
  108. } else {
  109. // create the prototype and add it to the lists
  110. PrimitivePrototypeClass * newproto = new PrimitivePrototypeClass(mesh);
  111. mesh->Release_Ref();
  112. return newproto;
  113. }
  114. }
  115. /***********************************************************************************************
  116. * HModelLoaderClass::Load -- reads in an hmodel and creates a prototype for it *
  117. * *
  118. * INPUT: *
  119. * *
  120. * OUTPUT: *
  121. * *
  122. * WARNINGS: *
  123. * *
  124. * HISTORY: *
  125. * 7/28/98 GTH : Created. *
  126. *=============================================================================================*/
  127. PrototypeClass * HModelLoaderClass::Load_W3D(ChunkLoadClass & cload)
  128. {
  129. HModelDefClass * hdef = new HModelDefClass;
  130. if (hdef == NULL) {
  131. return NULL;
  132. }
  133. if (hdef->Load_W3D(cload) != HModelDefClass::OK) {
  134. // load failed, delete the model and return an error
  135. delete hdef;
  136. return NULL;
  137. } else {
  138. // ok, accept this model!
  139. HModelPrototypeClass * hproto = new HModelPrototypeClass(hdef);
  140. return hproto;
  141. }
  142. }