ObjectCreationList.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: ObjectCreationList.h /////////////////////////////////////////////////////////////////////////////////
  24. // Author: Steven Johnson, December 2001
  25. // Desc: General Effects Descriptions
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #pragma once
  28. #ifndef _ObjectCreationList_H_
  29. #define _ObjectCreationList_H_
  30. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  31. #include "Common/GameMemory.h"
  32. // FORWARD REFERENCES /////////////////////////////////////////////////////////////////////////////
  33. class ObjectCreationNugget;
  34. class ObjectCreationList;
  35. class ObjectCreationListStore;
  36. class INI;
  37. class Object;
  38. //-------------------------------------------------------------------------------------------------
  39. /**
  40. An ObjectCreationNugget encapsulates the creation of an Object. ObjectCreationNuggets are virtually
  41. never used on their own, but rather, as a component of an ObjectCreationList (see below).
  42. Important notes:
  43. -- ObjectCreationNugget is an ABC; all the implementations are (currently) located in ObjectCreationList.cpp,
  44. thought they will probably be spread out more as we add more implementations.
  45. -- As part of an ObjectCreationList, an ObjectCreationNugget is shared between multiple units. The implication is that
  46. an ObjectCreationNugget should not require private data storage to do what it needs to do, aside from stuff
  47. initialized at ObjectCreationNugget instantiation time (eg, parameters from an INI file). To help
  48. enforce this, all it's methods are declared 'const'. If you can't implement what you
  49. need within this framework, please *don't* simply de-const things, because it could lead to very
  50. strange side-effects. Instead, the system will have to be enhanced to allow for multiple instances
  51. of each ObjectCreationNugget.
  52. -- an individual ObjectCreationNugget is generally not directly accessible to anyone outside of the
  53. ObjectCreationList system; in fact, it could probably be a private class, but isn't, mainly for coding convenience.
  54. -- Unlike most other game systems, ObjectCreationNuggets can't be overridden by subsequent INI file
  55. loads. This isn't really a problem, because all you really need to do to "override" one is to
  56. specify a different one.
  57. */
  58. class ObjectCreationNugget : public MemoryPoolObject
  59. {
  60. MEMORY_POOL_GLUE_ABC(ObjectCreationNugget)
  61. public:
  62. ObjectCreationNugget() { }
  63. //virtual ~ObjectCreationNugget() { }
  64. /**
  65. The main guts of the system: actually perform the sound and/or video effects
  66. needed. Note that primary can be null, so you must check for this.
  67. Bool useOwner determines whether we are creating the the master object or not (for deliverpayload)
  68. */
  69. virtual void create( const Object* primaryObj, const Coord3D *primary, const Coord3D* secondary, UnsignedInt lifetimeFrames = 0 ) const = 0;
  70. /**
  71. the object-based version... by default, just call the location-based implementation.
  72. Note that primary can be null, so you must check for this.
  73. */
  74. virtual void create( const Object* primary, const Object* secondary, UnsignedInt lifetimeFrames = 0 ) const;
  75. /**
  76. A variation used by DeliverPayload -- the createOwner Bool specifies whether we are creating the transport
  77. object, or using the existing one.
  78. */
  79. virtual void create( const Object* primaryObj, const Coord3D *primary, const Coord3D *secondary, Bool createOwner, UnsignedInt lifetimeFrames = 0 ) const;
  80. };
  81. EMPTY_DTOR(ObjectCreationNugget)
  82. //-------------------------------------------------------------------------------------------------
  83. /**
  84. An ObjectCreationList is a way of creating a particular set of Objects.
  85. Important notes:
  86. -- an ObjectCreationList is specified solely by name, and the only parameters it receives when performing
  87. its AV effects are a primary (and optional secondary) object position.
  88. -- There is no inheritance or overriding of ObjectCreationLists; if you need an ObjectCreationList that is nearly-but-not-quite
  89. identical to an existing one, you must simply make an entirely new ObjectCreationList. Realistically, this shouldn't
  90. be a problem, since they are pretty simple to specify, and don't consume a lot of memory.
  91. -- an ObjectCreationList is shared between multiple units. To help
  92. enforce this, all it's methods are declared 'const'. If you can't implement the stuff you
  93. need within this framework, please *don't* simply de-const things, because it could lead to very
  94. strange side-effects. Instead, the system will have to be enhanced to allow for multiple instances
  95. of each ObjectCreationNugget.
  96. -- Unlike most other game systems, ObjectCreationList can't be overridden by subsequent INI file
  97. loads. This isn't really a problem, because all you really need to do to "override" one is to
  98. specify a different one.
  99. */
  100. class ObjectCreationList
  101. {
  102. public:
  103. /**
  104. Toss the contents.
  105. */
  106. void clear();
  107. void addObjectCreationNugget(ObjectCreationNugget* nugget);
  108. inline static void create( const ObjectCreationList* ocl, const Object* primaryObj, const Coord3D *primary, const Coord3D *secondary, Bool createOwner, UnsignedInt lifetimeFrames = 0 )
  109. {
  110. if (ocl) ocl->create( primaryObj, primary, secondary, createOwner, lifetimeFrames );
  111. }
  112. /// inline convenience method to avoid having to check for null.
  113. inline static void create(const ObjectCreationList* ocl, const Object* primaryObj, const Coord3D *primary, const Coord3D *secondary, UnsignedInt lifetimeFrames = 0 )
  114. {
  115. if (ocl) ocl->create( primaryObj, primary, secondary, lifetimeFrames );
  116. }
  117. /// inline convenience method to avoid having to check for null.
  118. inline static void create( const ObjectCreationList* ocl, const Object* primary, const Object* secondary, UnsignedInt lifetimeFrames = 0 )
  119. {
  120. if (ocl) ocl->create( primary, secondary, lifetimeFrames );
  121. }
  122. protected:
  123. private:
  124. void create(const Object* primaryObj, const Coord3D *primary, const Coord3D *secondary, Bool createOwner, UnsignedInt lifetimeFrames = 0 ) const;
  125. void create(const Object* primaryObj, const Coord3D *primary, const Coord3D* secondary, UnsignedInt lifetimeFrames = 0 ) const;
  126. void create(const Object* primary, const Object* secondary, UnsignedInt lifetimeFrames = 0 ) const;
  127. // note, this list doesn't own the nuggets; all nuggets are owned by the Store.
  128. typedef std::vector<ObjectCreationNugget*> ObjectCreationNuggetVector;
  129. ObjectCreationNuggetVector m_nuggets;
  130. };
  131. //-------------------------------------------------------------------------------------------------
  132. /**
  133. The "store" used to hold all the ObjectCreationLists in existence.
  134. */
  135. class ObjectCreationListStore : public SubsystemInterface
  136. {
  137. public:
  138. ObjectCreationListStore();
  139. ~ObjectCreationListStore();
  140. void init() { }
  141. void reset() { }
  142. void update() { }
  143. /**
  144. return the ObjectCreationList with the given namekey.
  145. return NULL if no such ObjectCreationList exists.
  146. */
  147. const ObjectCreationList *findObjectCreationList(const char* name) const;
  148. static void parseObjectCreationListDefinition(INI* ini);
  149. void addObjectCreationNugget(ObjectCreationNugget* nugget);
  150. private:
  151. typedef std::map< NameKeyType, ObjectCreationList, std::less<NameKeyType> > ObjectCreationListMap;
  152. ObjectCreationListMap m_ocls;
  153. // note, this list doesn't own the nuggets; all nuggets are owned by the Store.
  154. typedef std::vector<ObjectCreationNugget*> ObjectCreationNuggetVector;
  155. ObjectCreationNuggetVector m_nuggets;
  156. };
  157. // EXTERNALS //////////////////////////////////////////////////////////////////////////////////////
  158. extern ObjectCreationListStore *TheObjectCreationListStore;
  159. #endif // _ObjectCreationList_H_