afxEffectron.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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, StringTableEntry varname, void *typePtr) override;
  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. void reloadReset() override;
  56. bool onAdd() override;
  57. void packData(BitStream*) override;
  58. void unpackData(BitStream*) override;
  59. bool preload(bool server, String &errorStr) override;
  60. void gatherConstraintDefs(Vector<afxConstraintDef>&);
  61. bool allowSubstitutions() const override { return true; }
  62. static void initPersistFields();
  63. DECLARE_CONOBJECT(afxEffectronData);
  64. };
  65. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  66. // afxEffectron
  67. class afxEffectron : public afxChoreographer
  68. {
  69. typedef afxChoreographer Parent;
  70. public:
  71. enum MaskBits
  72. {
  73. StateEventMask = Parent::NextFreeMask << 0,
  74. SyncEventMask = Parent::NextFreeMask << 1,
  75. NextFreeMask = Parent::NextFreeMask << 2
  76. };
  77. enum
  78. {
  79. NULL_EVENT,
  80. ACTIVATE_EVENT,
  81. SHUTDOWN_EVENT,
  82. DEACTIVATE_EVENT,
  83. INTERRUPT_EVENT
  84. };
  85. enum
  86. {
  87. INACTIVE_STATE,
  88. ACTIVE_STATE,
  89. CLEANUP_STATE,
  90. DONE_STATE,
  91. LATE_STATE
  92. };
  93. enum {
  94. MARK_ACTIVATE = BIT(0),
  95. MARK_SHUTDOWN = BIT(1),
  96. MARK_DEACTIVATE = BIT(2),
  97. MARK_INTERRUPT = BIT(3),
  98. };
  99. class ObjectDeleteEvent : public SimEvent
  100. {
  101. public:
  102. void process(SimObject *obj) override { if (obj) obj->deleteObject(); }
  103. };
  104. private:
  105. static StringTableEntry CAMERA_CONS;
  106. static StringTableEntry LISTENER_CONS;
  107. private:
  108. afxEffectronData* datablock;
  109. SimObject* exeblock;
  110. bool constraints_initialized;
  111. bool scoping_initialized;
  112. U8 effect_state;
  113. F32 effect_elapsed;
  114. U8 marks_mask;
  115. afxConstraintID listener_cons_id;
  116. afxConstraintID camera_cons_id;
  117. SceneObject* camera_cons_obj;
  118. afxPhrase* active_phrase;
  119. F32 time_factor;
  120. private:
  121. void init();
  122. bool state_expired();
  123. void init_constraints();
  124. void init_scoping();
  125. void setup_active_fx();
  126. bool cleanup_over();
  127. public:
  128. /*C*/ afxEffectron();
  129. /*C*/ afxEffectron(bool not_default);
  130. /*D*/ ~afxEffectron();
  131. // STANDARD OVERLOADED METHODS //
  132. bool onNewDataBlock(GameBaseData* dptr, bool reload) override;
  133. void processTick(const Move*) override;
  134. void advanceTime(F32 dt) override;
  135. bool onAdd() override;
  136. U32 packUpdate(NetConnection*, U32, BitStream*) override;
  137. void unpackUpdate(NetConnection*, BitStream*) override;
  138. void inflictDamage(const char * label, const char* flavor, SimObjectId target,
  139. F32 amt, U8 count, F32 ad_amt, F32 rad, Point3F pos, F32 imp) override;
  140. void sync_with_clients() override;
  141. void finish_startup();
  142. DECLARE_CONOBJECT(afxEffectron);
  143. private:
  144. void process_server();
  145. //
  146. void change_state_s(U8 pending_state);
  147. //
  148. void enter_active_state_s();
  149. void leave_active_state_s();
  150. void enter_cleanup_state_s();
  151. void enter_done_state_s();
  152. private:
  153. void process_client(F32 dt);
  154. //
  155. void change_state_c(U8 pending_state);
  156. //
  157. void enter_active_state_c(F32 starttime);
  158. void leave_active_state_c();
  159. void sync_client(U16 marks, U8 state, F32 elapsed);
  160. public:
  161. void postEvent(U8 event);
  162. void setTimeFactor(F32 f) { time_factor = (f > 0) ? f : 1.0f; }
  163. F32 getTimeFactor() { return time_factor; }
  164. bool activationCallInit(bool postponed=false);
  165. void activate();
  166. public:
  167. static afxEffectron* start_effect(afxEffectronData*, SimObject* extra);
  168. };
  169. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  170. #endif // _AFX_EFFECTRON_H_