afxEffectron.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  2. // Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  3. // Copyright (C) 2015 Faust Logic, Inc.
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to
  7. // deal in the Software without restriction, including without limitation the
  8. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9. // sell copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. // IN THE SOFTWARE.
  22. //
  23. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  24. #ifndef _AFX_COMPOSITE_EFFECT_H_
  25. #define _AFX_COMPOSITE_EFFECT_H_
  26. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  27. #include "console/typeValidators.h"
  28. #include "afxChoreographer.h"
  29. #include "afxEffectWrapper.h"
  30. #include "afxPhrase.h"
  31. class afxChoreographerData;
  32. class afxEffectWrapperData;
  33. class afxEffectronData : public afxChoreographerData
  34. {
  35. typedef afxChoreographerData Parent;
  36. class ewValidator : public TypeValidator
  37. {
  38. U32 id;
  39. public:
  40. ewValidator(U32 id) { this->id = id; }
  41. void validateType(SimObject *object, void *typePtr);
  42. };
  43. bool do_id_convert;
  44. public:
  45. F32 duration;
  46. S32 n_loops;
  47. afxEffectBaseData* dummy_fx_entry;
  48. afxEffectList fx_list;
  49. private:
  50. void pack_fx(BitStream* stream, const afxEffectList& fx, bool packed);
  51. void unpack_fx(BitStream* stream, afxEffectList& fx);
  52. public:
  53. /*C*/ afxEffectronData();
  54. /*C*/ afxEffectronData(const afxEffectronData&, bool = false);
  55. virtual void reloadReset();
  56. virtual bool onAdd();
  57. virtual void packData(BitStream*);
  58. virtual void unpackData(BitStream*);
  59. bool preload(bool server, String &errorStr);
  60. void gatherConstraintDefs(Vector<afxConstraintDef>&);
  61. virtual bool allowSubstitutions() const { return true; }
  62. static void initPersistFields();
  63. DECLARE_CONOBJECT(afxEffectronData);
  64. DECLARE_CATEGORY("AFX");
  65. };
  66. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  67. // afxEffectron
  68. class afxEffectron : public afxChoreographer
  69. {
  70. typedef afxChoreographer Parent;
  71. public:
  72. enum MaskBits
  73. {
  74. StateEventMask = Parent::NextFreeMask << 0,
  75. SyncEventMask = Parent::NextFreeMask << 1,
  76. NextFreeMask = Parent::NextFreeMask << 2
  77. };
  78. enum
  79. {
  80. NULL_EVENT,
  81. ACTIVATE_EVENT,
  82. SHUTDOWN_EVENT,
  83. DEACTIVATE_EVENT,
  84. INTERRUPT_EVENT
  85. };
  86. enum
  87. {
  88. INACTIVE_STATE,
  89. ACTIVE_STATE,
  90. CLEANUP_STATE,
  91. DONE_STATE,
  92. LATE_STATE
  93. };
  94. enum {
  95. MARK_ACTIVATE = BIT(0),
  96. MARK_SHUTDOWN = BIT(1),
  97. MARK_DEACTIVATE = BIT(2),
  98. MARK_INTERRUPT = BIT(3),
  99. };
  100. class ObjectDeleteEvent : public SimEvent
  101. {
  102. public:
  103. void process(SimObject *obj) { if (obj) obj->deleteObject(); }
  104. };
  105. private:
  106. static StringTableEntry CAMERA_CONS;
  107. static StringTableEntry LISTENER_CONS;
  108. private:
  109. afxEffectronData* datablock;
  110. SimObject* exeblock;
  111. bool constraints_initialized;
  112. bool scoping_initialized;
  113. U8 effect_state;
  114. F32 effect_elapsed;
  115. U8 marks_mask;
  116. afxConstraintID listener_cons_id;
  117. afxConstraintID camera_cons_id;
  118. SceneObject* camera_cons_obj;
  119. afxPhrase* active_phrase;
  120. F32 time_factor;
  121. private:
  122. void init();
  123. bool state_expired();
  124. void init_constraints();
  125. void init_scoping();
  126. void setup_active_fx();
  127. bool cleanup_over();
  128. public:
  129. /*C*/ afxEffectron();
  130. /*C*/ afxEffectron(bool not_default);
  131. /*D*/ ~afxEffectron();
  132. // STANDARD OVERLOADED METHODS //
  133. virtual bool onNewDataBlock(GameBaseData* dptr, bool reload);
  134. virtual void processTick(const Move*);
  135. virtual void advanceTime(F32 dt);
  136. virtual bool onAdd();
  137. virtual U32 packUpdate(NetConnection*, U32, BitStream*);
  138. virtual void unpackUpdate(NetConnection*, BitStream*);
  139. virtual void inflictDamage(const char * label, const char* flavor, SimObjectId target,
  140. F32 amt, U8 count, F32 ad_amt, F32 rad, Point3F pos, F32 imp);
  141. virtual void sync_with_clients();
  142. void finish_startup();
  143. DECLARE_CONOBJECT(afxEffectron);
  144. DECLARE_CATEGORY("AFX");
  145. private:
  146. void process_server();
  147. //
  148. void change_state_s(U8 pending_state);
  149. //
  150. void enter_active_state_s();
  151. void leave_active_state_s();
  152. void enter_cleanup_state_s();
  153. void enter_done_state_s();
  154. private:
  155. void process_client(F32 dt);
  156. //
  157. void change_state_c(U8 pending_state);
  158. //
  159. void enter_active_state_c(F32 starttime);
  160. void leave_active_state_c();
  161. void sync_client(U16 marks, U8 state, F32 elapsed);
  162. public:
  163. void postEvent(U8 event);
  164. void setTimeFactor(F32 f) { time_factor = (f > 0) ? f : 1.0f; }
  165. F32 getTimeFactor() { return time_factor; }
  166. bool activationCallInit(bool postponed=false);
  167. void activate();
  168. public:
  169. static afxEffectron* start_effect(afxEffectronData*, SimObject* extra);
  170. };
  171. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  172. #endif // _AFX_EFFECTRON_H_