timeddecophys.cpp 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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 : WWPhys *
  23. * *
  24. * $Archive:: /Commando/Code/wwphys/timeddecophys.cpp $*
  25. * *
  26. * Author:: Byon Garrabrant *
  27. * *
  28. * $Modtime:: 9/24/00 1:14p $*
  29. * *
  30. * $Revision:: 6 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "timeddecophys.h"
  36. //#include "rendobj.h"
  37. #include "persistfactory.h"
  38. #include "simpledefinitionfactory.h"
  39. #include "wwphysids.h"
  40. #include "wwhack.h"
  41. #include "wwprofile.h"
  42. //#include "part_emt.h"
  43. DECLARE_FORCE_LINK(timeddecophys);
  44. /****************************************************************************************************
  45. **
  46. ** TimedDecorationPhysClass Implementation
  47. **
  48. ****************************************************************************************************/
  49. /*
  50. ** Persist factory for TimedDecorationPhysClass
  51. */
  52. SimplePersistFactoryClass<TimedDecorationPhysClass,PHYSICS_CHUNKID_TIMEDDECORATIONPHYS> _TimedDecoPhysFactory;
  53. /*
  54. ** Chunk-ID's used by TimedDecoPhys
  55. */
  56. enum
  57. {
  58. TIMEDDECOPHYS_CHUNK_DECOPHYS = 0x005160000, // decophys class data
  59. TIMEDDECOPHYS_CHUNK_VARIABLES,
  60. TIMEDDECOPHYS_VARIABLE_LIFETIME = 0x00,
  61. };
  62. TimedDecorationPhysClass::TimedDecorationPhysClass(void) :
  63. DecorationPhysClass(),
  64. Lifetime(2.0f)
  65. {
  66. }
  67. void TimedDecorationPhysClass::Init(const TimedDecorationPhysDefClass & def)
  68. {
  69. DecorationPhysClass::Init(def);
  70. Lifetime = def.Lifetime;
  71. }
  72. void TimedDecorationPhysClass::Set_Lifetime( float time )
  73. {
  74. Lifetime = time;
  75. }
  76. float TimedDecorationPhysClass::Get_Lifetime( void )
  77. {
  78. return Lifetime;
  79. }
  80. void TimedDecorationPhysClass::Timestep(float dt)
  81. {
  82. DecorationPhysClass::Timestep( dt );
  83. {
  84. WWPROFILE("TimedDecoPhys::Timestep");
  85. /*
  86. ** Decrement our life
  87. */
  88. Lifetime -= dt;
  89. if (Lifetime < 0.0f) {
  90. ExpirationReactionType result = EXPIRATION_APPROVED;
  91. if (Observer != NULL) {
  92. result = Observer->Object_Expired(this);
  93. }
  94. if (result == EXPIRATION_APPROVED) {
  95. PhysicsSceneClass::Get_Instance()->Delayed_Remove_Object(this);
  96. }
  97. }
  98. }
  99. }
  100. const PersistFactoryClass & TimedDecorationPhysClass::Get_Factory (void) const
  101. {
  102. return _TimedDecoPhysFactory;
  103. }
  104. bool TimedDecorationPhysClass::Save (ChunkSaveClass &csave)
  105. {
  106. csave.Begin_Chunk(TIMEDDECOPHYS_CHUNK_DECOPHYS);
  107. DecorationPhysClass::Save(csave);
  108. csave.End_Chunk();
  109. csave.Begin_Chunk(TIMEDDECOPHYS_CHUNK_VARIABLES);
  110. WRITE_MICRO_CHUNK(csave,TIMEDDECOPHYS_VARIABLE_LIFETIME,Lifetime);
  111. csave.End_Chunk();
  112. return true;
  113. }
  114. bool TimedDecorationPhysClass::Load (ChunkLoadClass &cload)
  115. {
  116. while (cload.Open_Chunk()) {
  117. switch(cload.Cur_Chunk_ID())
  118. {
  119. case TIMEDDECOPHYS_CHUNK_DECOPHYS:
  120. DecorationPhysClass::Load(cload);
  121. break;
  122. case TIMEDDECOPHYS_CHUNK_VARIABLES:
  123. while (cload.Open_Micro_Chunk()) {
  124. switch(cload.Cur_Micro_Chunk_ID()) {
  125. READ_MICRO_CHUNK(cload,TIMEDDECOPHYS_VARIABLE_LIFETIME,Lifetime);
  126. }
  127. cload.Close_Micro_Chunk();
  128. }
  129. break;
  130. default:
  131. WWDEBUG_SAY(("Unhandled Chunk: 0x%X File: %s Line: %d\r\n",cload.Cur_Chunk_ID(),__FILE__,__LINE__));
  132. break;
  133. }
  134. cload.Close_Chunk();
  135. }
  136. return true;
  137. }
  138. /****************************************************************************************************
  139. **
  140. ** TimedDecorationPhysDefClass Implementation
  141. **
  142. ****************************************************************************************************/
  143. /*
  144. ** Persist factory for TimedDecorationPhysDefClass's
  145. */
  146. SimplePersistFactoryClass<TimedDecorationPhysDefClass,PHYSICS_CHUNKID_TIMEDDECOPHYSDEF> _TimedDecorationPhysDefFactory;
  147. /*
  148. ** Definition factory for TimedDecorationPhysDefClass. This makes it show up in the editor
  149. */
  150. DECLARE_DEFINITION_FACTORY(TimedDecorationPhysDefClass, CLASSID_TIMEDDECOPHYSDEF, "TimedDecorationPhys") _TimedDecorationPhysDefDefFactory;
  151. /*
  152. ** Chunk ID's used by TimedDecorationPhysDefClass
  153. */
  154. enum
  155. {
  156. TIMEDDECORATIONPHYSDEF_CHUNK_DECORATIONPHYSDEF = 0x01170003, // (parent class)
  157. TIMEDDECORATIONPHYSDEF_CHUNK_VARIABLES,
  158. TIMEDDECORATIONPHYSDEF_VARIABLE_LIFETIME = 0x00,
  159. };
  160. TimedDecorationPhysDefClass::TimedDecorationPhysDefClass(void) :
  161. DecorationPhysDefClass(),
  162. Lifetime(2.0f)
  163. {
  164. #ifdef PARAM_EDITING_ON
  165. // make our parameters editable!
  166. FLOAT_EDITABLE_PARAM(TimedDecorationPhysDefClass, Lifetime, 0.01f, 100.0f);
  167. #endif
  168. }
  169. uint32 TimedDecorationPhysDefClass::Get_Class_ID (void) const
  170. {
  171. return CLASSID_TIMEDDECOPHYSDEF;
  172. }
  173. PersistClass * TimedDecorationPhysDefClass::Create(void) const
  174. {
  175. TimedDecorationPhysClass * new_obj = NEW_REF(TimedDecorationPhysClass,());
  176. new_obj->Init(*this);
  177. return new_obj;
  178. }
  179. const char * TimedDecorationPhysDefClass::Get_Type_Name(void)
  180. {
  181. return "TimedDecorationPhysDef";
  182. }
  183. bool TimedDecorationPhysDefClass::Is_Type(const char * type_name)
  184. {
  185. if (stricmp(type_name,TimedDecorationPhysDefClass::Get_Type_Name()) == 0) {
  186. return true;
  187. } else {
  188. return DecorationPhysDefClass::Is_Type(type_name);
  189. }
  190. }
  191. const PersistFactoryClass & TimedDecorationPhysDefClass::Get_Factory (void) const
  192. {
  193. return _TimedDecorationPhysDefFactory;
  194. }
  195. bool TimedDecorationPhysDefClass::Save(ChunkSaveClass &csave)
  196. {
  197. csave.Begin_Chunk(TIMEDDECORATIONPHYSDEF_CHUNK_DECORATIONPHYSDEF);
  198. DecorationPhysDefClass::Save(csave);
  199. csave.End_Chunk();
  200. csave.Begin_Chunk(TIMEDDECORATIONPHYSDEF_CHUNK_VARIABLES);
  201. WRITE_MICRO_CHUNK(csave,TIMEDDECORATIONPHYSDEF_VARIABLE_LIFETIME,Lifetime);
  202. csave.End_Chunk();
  203. return true;
  204. }
  205. bool TimedDecorationPhysDefClass::Load(ChunkLoadClass &cload)
  206. {
  207. while (cload.Open_Chunk()) {
  208. switch(cload.Cur_Chunk_ID()) {
  209. case TIMEDDECORATIONPHYSDEF_CHUNK_DECORATIONPHYSDEF:
  210. DecorationPhysDefClass::Load(cload);
  211. break;
  212. case TIMEDDECORATIONPHYSDEF_CHUNK_VARIABLES:
  213. while (cload.Open_Micro_Chunk()) {
  214. switch(cload.Cur_Micro_Chunk_ID()) {
  215. READ_MICRO_CHUNK(cload,TIMEDDECORATIONPHYSDEF_VARIABLE_LIFETIME,Lifetime);
  216. }
  217. cload.Close_Micro_Chunk();
  218. }
  219. break;
  220. default:
  221. WWDEBUG_SAY(("Unhandled Chunk: 0x%X File: %s Line: %d\r\n",cload.Cur_Chunk_ID(),__FILE__,__LINE__));
  222. break;
  223. }
  224. cload.Close_Chunk();
  225. }
  226. return true;
  227. }