FXList.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: FXList.h /////////////////////////////////////////////////////////////////////////////////
  24. // Author: Steven Johnson, December 2001
  25. // Desc: General Effects Descriptions
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #pragma once
  28. #ifndef _FXList_H_
  29. #define _FXList_H_
  30. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  31. #include "Common/GameMemory.h"
  32. #include "Common/NameKeyGenerator.h"
  33. #include "Common/STLTypedefs.h"
  34. // FORWARD REFERENCES /////////////////////////////////////////////////////////////////////////////
  35. class FXNugget;
  36. class FXList;
  37. class FXListStore;
  38. class INI;
  39. class Object;
  40. class Matrix3D;
  41. //-------------------------------------------------------------------------------------------------
  42. /**
  43. An FXNugget encapsulates a particular type of audio/video effect. FXNuggets are virtually
  44. never used on their own, but rather, as a component of an FXList (see below).
  45. Important notes:
  46. -- FXNugget is an ABC; all the implementations are (currently) located in FXList.cpp,
  47. thought they will probably be spread out more as we add more implementations.
  48. -- As part of an FXList, an FXNugget is shared between multiple units. The implication is that
  49. an FXNugget should not require private data storage to do what it needs to do, aside from stuff
  50. initialized at FXNugget instantiation time (eg, parameters from an INI file). To help
  51. enforce this, all it's methods are declared 'const'. If you can't implement what you
  52. need within this framework, please *don't* simply de-const things, because it could lead to very
  53. strange side-effects. Instead, the system will have to be enhanced to allow for multiple instances
  54. of each FXNugget.
  55. -- an individual FXNugget is generally not directly accessible to anyone outside of the
  56. FXList system; in fact, it could probably be a private class, but isn't, mainly for coding convenience.
  57. -- Unlike most other game systems, FXNuggets can't be overridden by subsequent INI file
  58. loads. This isn't really a problem, because all you really need to do to "override" one is to
  59. specify a different one.
  60. */
  61. class FXNugget : public MemoryPoolObject
  62. {
  63. MEMORY_POOL_GLUE_ABC(FXNugget)
  64. public:
  65. FXNugget() { }
  66. //virtual ~FXNugget() { }
  67. /**
  68. The main guts of the system: actually perform the sound and/or video effects
  69. needed. Note that primary and/or secondary can be null, so you must check for this.
  70. */
  71. virtual void doFXPos(const Coord3D *primary, const Matrix3D* primaryMtx = NULL, const Real primarySpeed = 0.0f, const Coord3D *secondary = NULL, const Real overrideRadius = 0.0f) const = 0;
  72. /**
  73. the object-based version... by default, just call the location-based implementation.
  74. Note that primary and/or secondary can be null, so you must check for this.
  75. */
  76. virtual void doFXObj(const Object* primary, const Object* secondary = NULL) const;
  77. private:
  78. };
  79. EMPTY_DTOR(FXNugget)
  80. //-------------------------------------------------------------------------------------------------
  81. /**
  82. An FXList is a way of encapsulating a particular set of audio/video effect(s).
  83. Lots of other game systems (eg, DamageFX) use FXLists to abstract AV effects into data files
  84. (rather than hardcoding them, which would be suboptimal).
  85. Important notes:
  86. -- an FXList 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 FXLists; if you need an FXList that is nearly-but-not-quite
  89. identical to an existing one, you must simply make an entirely new FXList. 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 FXList 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 FXNugget.
  96. -- Unlike most other game systems, FXList 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 FXList
  101. {
  102. public:
  103. FXList();
  104. virtual ~FXList();
  105. /**
  106. Toss the contents.
  107. */
  108. void clear();
  109. /**
  110. add a nugget to the list. It belongs to the FXList, who is responsible for freeing it.
  111. */
  112. void addFXNugget(FXNugget *fxn)
  113. {
  114. m_nuggets.push_back(fxn);
  115. }
  116. /// inline convenience method to avoid having to check for null.
  117. inline static void doFXPos(const FXList* fx, const Coord3D *primary, const Matrix3D* primaryMtx = NULL, const Real primarySpeed = 0.0f, const Coord3D *secondary = NULL, const Real overrideRadius = 0.0f)
  118. {
  119. if (fx) fx->doFXPos(primary, primaryMtx, primarySpeed, secondary, overrideRadius);
  120. }
  121. /// inline convenience method to avoid having to check for null.
  122. inline static void doFXObj(const FXList* fx, const Object* primary, const Object* secondary = NULL)
  123. {
  124. if (fx)
  125. {
  126. fx->doFXObj(primary, secondary);
  127. //if (fx->) // here we need to cal doFXRicochet, if fx calls for it
  128. }
  129. }
  130. protected:
  131. /**
  132. The main guts of the system: actually perform the sound and/or video effects
  133. needed. Note that primary and/or secondary can be null, so you must check for this.
  134. */
  135. void doFXPos(const Coord3D *primary, const Matrix3D* primaryMtx = NULL, const Real primarySpeed = 0.0f, const Coord3D *secondary = NULL, const Real overrideRadius = 0.0f) const;
  136. /**
  137. the object-based version... by default, just call the location-based implementation.
  138. Note that primary and/or secondary can be null, so you must check for this.
  139. */
  140. void doFXObj(const Object* primary, const Object* secondary = NULL) const;
  141. private:
  142. typedef std::list< FXNugget* > FXNuggetList;
  143. FXNuggetList m_nuggets;
  144. };
  145. //-------------------------------------------------------------------------------------------------
  146. /**
  147. The "store" used to hold all the FXLists in existence.
  148. */
  149. class FXListStore : public SubsystemInterface
  150. {
  151. public:
  152. FXListStore();
  153. ~FXListStore();
  154. void init() { }
  155. void reset() { }
  156. void update() { }
  157. /**
  158. return the FXList with the given namekey.
  159. return NULL if no such FXList exists.
  160. */
  161. const FXList *findFXList( const char* name ) const;
  162. static void parseFXListDefinition(INI* ini);
  163. private:
  164. // use the hashing function for Ints.
  165. typedef std::hash_map< NameKeyType, FXList, rts::hash<NameKeyType>, rts::equal_to<NameKeyType> > FXListMap;
  166. FXListMap m_fxmap;
  167. };
  168. // EXTERNALS //////////////////////////////////////////////////////////////////////////////////////
  169. extern FXListStore *TheFXListStore;
  170. #endif // _FXList_H_