Effect.hpp 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. //==========================================================================//
  2. // File: gosFX_Effect.hpp //
  3. // Contents: Base Effect Component //
  4. //---------------------------------------------------------------------------//
  5. // Copyright (C) Microsoft Corporation. All rights reserved. //
  6. //===========================================================================//
  7. #pragma once
  8. #include "gosFX.hpp"
  9. #include <MLR\MLR.hpp>
  10. namespace MidLevelRenderer
  11. {
  12. class MLRState;
  13. class MLRClipper;
  14. class MLRClippingState;
  15. }
  16. namespace gosFX
  17. {
  18. class Effect__ClassData;
  19. //############################################################################
  20. //#################################### Event ###############################
  21. //############################################################################
  22. class Event:
  23. public Stuff::Plug
  24. {
  25. public:
  26. Event():
  27. Plug(DefaultData)
  28. {}
  29. Event(const Event& event);
  30. static Event*
  31. Make(
  32. Stuff::MemoryStream *stream,
  33. int gfx_version
  34. );
  35. void
  36. Save(Stuff::MemoryStream *stream);
  37. Stuff::Scalar
  38. m_time;
  39. unsigned
  40. m_flags,
  41. m_effectID;
  42. Stuff::LinearMatrix4D
  43. m_localToParent;
  44. protected:
  45. Event(
  46. Stuff::MemoryStream *stream,
  47. int gfx_version
  48. );
  49. };
  50. //############################################################################
  51. //######################## Effect__Specification #############################
  52. //############################################################################
  53. class Effect__Specification
  54. #if defined(_ARMOR)
  55. : public Stuff::Signature
  56. #endif
  57. {
  58. //----------------------------------------------------------------------
  59. // Constructors/Destructors
  60. //
  61. protected:
  62. Effect__Specification(
  63. Stuff::RegisteredClass::ClassID class_id,
  64. Stuff::MemoryStream *stream,
  65. int gfx_version
  66. );
  67. public:
  68. Effect__Specification(Stuff::RegisteredClass::ClassID class_id=gosFX::EffectClassID);
  69. virtual ~Effect__Specification();
  70. static Effect__Specification*
  71. Create(
  72. Stuff::MemoryStream *stream,
  73. int gfx_version
  74. );
  75. typedef Effect__Specification*
  76. (*Factory)(
  77. Stuff::MemoryStream *stream,
  78. int gfx_version
  79. );
  80. static Effect__Specification*
  81. Make(
  82. Stuff::MemoryStream *stream,
  83. int gfx_version
  84. );
  85. virtual void
  86. Save(Stuff::MemoryStream *stream);
  87. virtual void
  88. BuildDefaults();
  89. virtual bool
  90. IsDataValid(bool fix_data=false);
  91. Stuff::RegisteredClass::ClassID
  92. GetClassID()
  93. {Check_Object(this); return m_class;}
  94. virtual void
  95. Copy(Effect__Specification *spec);
  96. Stuff::MString
  97. m_name;
  98. unsigned
  99. m_effectID;
  100. protected:
  101. Stuff::RegisteredClass::ClassID
  102. m_class;
  103. //----------------------------------------------------------------------
  104. // Events
  105. //
  106. public:
  107. Stuff::ChainOf<Event*>
  108. m_events;
  109. void
  110. AdoptEvent(Event *event);
  111. //-------------------------------------------------------------------------
  112. // FCurves
  113. //
  114. public:
  115. ConstantCurve
  116. m_lifeSpan;
  117. SplineCurve
  118. m_minimumChildSeed,
  119. m_maximumChildSeed;
  120. //----------------------------------------------------------------------
  121. // States
  122. //
  123. public:
  124. MidLevelRenderer::MLRState
  125. m_state;
  126. //----------------------------------------------------------------------
  127. // Testing
  128. //
  129. public:
  130. void
  131. TestInstance() const
  132. {}
  133. };
  134. //############################################################################
  135. //############################### Effect ###################################
  136. //############################################################################
  137. class Effect:
  138. public Stuff::Node
  139. {
  140. friend class EffectCloud;
  141. //----------------------------------------------------------------------------
  142. // Types
  143. //
  144. public:
  145. struct ExecuteInfo
  146. {
  147. Stuff::Time
  148. m_time;
  149. Stuff::Scalar
  150. m_seed, // 0 <= m_seed <= 1
  151. m_age,
  152. m_ageRate;
  153. const Stuff::LinearMatrix4D
  154. *m_parentToWorld;
  155. Stuff::OBB
  156. *m_bounds;
  157. ExecuteInfo(
  158. Stuff::Time time,
  159. const Stuff::LinearMatrix4D *parent_to_world,
  160. Stuff::OBB *bounds,
  161. Stuff::Scalar seed = -1.0f
  162. )
  163. {
  164. m_time = time; m_seed = seed;
  165. m_parentToWorld = parent_to_world;
  166. m_bounds = bounds; m_age = -1.0f; m_ageRate = -1.0f;
  167. }
  168. void TestInstance() const
  169. {}
  170. private:
  171. ExecuteInfo(
  172. Stuff::Scalar time,
  173. const Stuff::LinearMatrix4D *parent_to_world,
  174. Stuff::OBB *bounds,
  175. Stuff::Scalar seed = -1.0f
  176. );
  177. };
  178. struct DrawInfo
  179. {
  180. const Stuff::LinearMatrix4D *m_parentToWorld;
  181. MidLevelRenderer::MLRClippingState m_clippingFlags;
  182. MidLevelRenderer::MLRState m_state;
  183. MidLevelRenderer::MLRClipper *m_clipper;
  184. void TestInstance() const
  185. {}
  186. };
  187. typedef Effect__Specification Specification;
  188. typedef Effect__ClassData ClassData;
  189. //----------------------------------------------------------------------------
  190. // Initialization
  191. //
  192. public:
  193. static void InitializeClass();
  194. static void TerminateClass();
  195. static ClassData
  196. *DefaultData;
  197. //----------------------------------------------------------------------------
  198. // Constructors/Destructors
  199. //
  200. protected:
  201. Effect(
  202. ClassData *class_data,
  203. Specification *spec,
  204. unsigned flags
  205. );
  206. public:
  207. ~Effect();
  208. typedef Effect*
  209. (*Factory)(
  210. Specification *spec,
  211. unsigned flags
  212. );
  213. static Effect*
  214. Make(
  215. Specification *spec,
  216. unsigned flags
  217. );
  218. Specification*
  219. GetSpecification()
  220. {Check_Object(this); return m_specification;}
  221. protected:
  222. Specification
  223. *m_specification;
  224. //----------------------------------------------------------------------------
  225. // Events
  226. //
  227. protected:
  228. Stuff::ChainOf<Effect *>
  229. m_children;
  230. Stuff::ChainIteratorOf<Event*>
  231. m_event;
  232. //----------------------------------------------------------------------------
  233. // Testing
  234. //
  235. public:
  236. void
  237. TestInstance() const;
  238. //----------------------------------------------------------------------------
  239. // API
  240. //
  241. public:
  242. virtual void Start(ExecuteInfo *info);
  243. void Stop();
  244. virtual bool Execute(ExecuteInfo *info);
  245. virtual void Kill();
  246. virtual void Draw(DrawInfo *info);
  247. virtual bool HasFinished();
  248. enum {
  249. ExecuteFlag = 1,
  250. LoopFlag = 2,
  251. LocalSpaceSimulationMode = 0,
  252. DynamicWorldSpaceSimulationMode = 4,
  253. StaticWorldSpaceSimulationMode = 8,
  254. ParentSimulationMode = 12,
  255. SimulationModeMask = 12
  256. };
  257. static Stuff::Vector3D
  258. s_ether;
  259. static Stuff::Vector3D
  260. s_gravity;
  261. public:
  262. void
  263. SetExecuteOn()
  264. {Check_Object(this); m_flags |= ExecuteFlag;}
  265. void
  266. SetExecuteOff()
  267. {Check_Object(this); m_flags &= ~ExecuteFlag;}
  268. bool
  269. IsExecuted()
  270. {Check_Object(this); return (m_flags&ExecuteFlag) != 0;}
  271. void
  272. SetLoopOn()
  273. {Check_Object(this); m_flags |= LoopFlag;}
  274. void
  275. SetLoopOff()
  276. {Check_Object(this); m_flags &= ~LoopFlag;}
  277. bool
  278. IsLooped()
  279. {Check_Object(this); return (m_flags&LoopFlag) != 0;}
  280. void
  281. UseLocalSpaceSimulation()
  282. {Check_Object(this); m_flags &= ~SimulationModeMask;}
  283. void
  284. UseStaticWorldSpaceSimulation()
  285. {
  286. Check_Object(this); m_flags &= ~SimulationModeMask;
  287. m_flags |= StaticWorldSpaceSimulationMode;
  288. }
  289. void
  290. UseDynamicWorldSpaceSimulation()
  291. {
  292. Check_Object(this); m_flags &= ~SimulationModeMask;
  293. m_flags |= DynamicWorldSpaceSimulationMode;
  294. }
  295. int
  296. GetSimulationMode()
  297. {Check_Object(this); return m_flags & SimulationModeMask;}
  298. int
  299. GetSimulationFlags()
  300. {Check_Object(this); return m_flags;}
  301. Stuff::LinearMatrix4D
  302. m_localToWorld;
  303. protected:
  304. Stuff::LinearMatrix4D
  305. m_localToParent;
  306. Stuff::Time
  307. m_lastRan;
  308. Stuff::Scalar
  309. m_age,
  310. m_ageRate,
  311. m_seed;
  312. unsigned
  313. m_flags;
  314. };
  315. //##########################################################################
  316. //######################## Effect__ClassData #########################
  317. //##########################################################################
  318. class Effect__ClassData:
  319. public Stuff::Plug::ClassData
  320. {
  321. //----------------------------------------------------------------------------
  322. //
  323. public:
  324. Effect__ClassData(
  325. Stuff::RegisteredClass::ClassID class_id,
  326. const char* class_name,
  327. Stuff::Plug::ClassData *parent_class,
  328. Effect::Factory effect_factory,
  329. Effect::Specification::Factory spec_factory
  330. ):
  331. RegisteredClass__ClassData(class_id, class_name, parent_class),
  332. effectFactory(effect_factory),
  333. specificationFactory(spec_factory)
  334. {}
  335. Effect::Factory
  336. effectFactory;
  337. Effect::Specification::Factory
  338. specificationFactory;
  339. //----------------------------------------------------------------------------
  340. //
  341. public:
  342. void TestInstance();
  343. };
  344. }