proto.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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.h $*
  25. * *
  26. * Author:: Greg Hjelstrom *
  27. * *
  28. * $Modtime:: 1/08/01 10:04a $*
  29. * *
  30. * $Revision:: 1 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef PROTO_H
  39. #define PROTO_H
  40. #include "always.h"
  41. #include <stdlib.h>
  42. #include "w3d_file.h"
  43. class RenderObjClass;
  44. class ChunkLoadClass;
  45. /*
  46. ** W3D Prototype system
  47. **
  48. ** Prototypes are basically abstract factories for render objects.
  49. ** Prototype Loaders are abstract factories for prototypes.
  50. ** Here is an example of the sequence of events that happen when
  51. ** a mesh is loaded into the asset manager and then used by the
  52. ** user:
  53. **
  54. ** - At initialization time, a mesh prototype loader is installed automatically
  55. ** - User asks the asset manager to load "mesh.w3d"
  56. ** - asset manager encounters a W3D_CHUNK_MESH
  57. ** - asset manager looks through its loaders to find one that claims to handle this chunk
  58. ** - the meshloader object is found and its Load method called
  59. ** - the meshloader creates a mesh prototype object which the asset manager adds to its list
  60. ** - User asks for the render object named "Mesh"
  61. ** - asset manager searches through its prototypes to find the one named "Mesh"
  62. ** - the mesh prototype object is found and the asset manager calls its "Create" method
  63. ** - the mesh prototype creates a mesh (clones the one it contains) which is returned to the user.
  64. */
  65. /*
  66. ** PrototypeClass
  67. ** This class is a generic interface to a render object prototype.
  68. ** The asset manager will store a these and use them whenever the
  69. ** user wants to create an instance of a named render object.
  70. ** Some simple render objects will be created through cloning. In
  71. ** that case, their associated prototype simply stores an object and
  72. ** clones it whenever the Create method is called. More complex
  73. ** composite render objects will be created from a "blueprint" object.
  74. ** Basically this class simply associates a name with a render object
  75. ** creation function.
  76. */
  77. class PrototypeClass
  78. {
  79. public:
  80. PrototypeClass(void) : NextHash(NULL) {}
  81. virtual ~PrototypeClass(void) {};
  82. virtual const char * Get_Name(void) const = 0;
  83. virtual int Get_Class_ID(void) const = 0;
  84. virtual RenderObjClass * Create(void) = 0;
  85. private:
  86. PrototypeClass * NextHash;
  87. // Not Implemented
  88. PrototypeClass(const PrototypeClass & that);
  89. PrototypeClass & operator = (const PrototypeClass & that);
  90. friend class WW3DAssetManager;
  91. };
  92. class PrimitivePrototypeClass : public PrototypeClass
  93. {
  94. public:
  95. PrimitivePrototypeClass(RenderObjClass * proto);
  96. virtual ~PrimitivePrototypeClass(void);
  97. virtual const char * Get_Name(void) const;
  98. virtual int Get_Class_ID(void) const;
  99. virtual RenderObjClass * Create(void);
  100. RenderObjClass * Proto;
  101. };
  102. /*
  103. ** PrototypeLoaderClass
  104. ** This is the interface for an object which recognizes a certain
  105. ** chunk type in a W3D file and can load it and create a PrototypeClass
  106. ** for it.
  107. */
  108. class PrototypeLoaderClass
  109. {
  110. public:
  111. PrototypeLoaderClass(void) {}
  112. ~PrototypeLoaderClass(void) {}
  113. virtual int Chunk_Type(void) = 0;
  114. virtual PrototypeClass * Load_W3D(ChunkLoadClass & cload) = 0;
  115. private:
  116. // Not Implemented:
  117. PrototypeLoaderClass(const PrototypeLoaderClass & that);
  118. PrototypeLoaderClass & operator = (const PrototypeLoaderClass & that);
  119. };
  120. /*
  121. ** Default Prototype Loaders for Meshes and HModels
  122. */
  123. class MeshLoaderClass : public PrototypeLoaderClass
  124. {
  125. public:
  126. virtual int Chunk_Type(void) { return W3D_CHUNK_MESH; }
  127. virtual PrototypeClass * Load_W3D(ChunkLoadClass & cload);
  128. };
  129. class HModelLoaderClass : public PrototypeLoaderClass
  130. {
  131. public:
  132. virtual int Chunk_Type(void) { return W3D_CHUNK_HMODEL; }
  133. virtual PrototypeClass * Load_W3D(ChunkLoadClass & cload);
  134. };
  135. /*
  136. ** Instances of the default loaders which the asset manager can
  137. ** automatically install at creation time
  138. */
  139. extern MeshLoaderClass _MeshLoader;
  140. extern HModelLoaderClass _HModelLoader;
  141. #endif