afxSelectron.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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_SELECTION_EFFECT_H_
  25. #define _AFX_SELECTION_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 afxEffectBaseData;
  33. class afxSelectronDefs
  34. {
  35. public:
  36. enum {
  37. MAIN_PHRASE,
  38. SELECT_PHRASE,
  39. DESELECT_PHRASE,
  40. NUM_PHRASES
  41. };
  42. };
  43. class afxSelectronData : public afxChoreographerData, public afxSelectronDefs
  44. {
  45. typedef afxChoreographerData Parent;
  46. class ewValidator : public TypeValidator
  47. {
  48. U32 id;
  49. public:
  50. ewValidator(U32 id) { this->id = id; }
  51. void validateType(SimObject *object, StringTableEntry varname, void *typePtr) override;
  52. };
  53. bool do_id_convert;
  54. public:
  55. F32 main_dur;
  56. F32 select_dur;
  57. F32 deselect_dur;
  58. S32 n_main_loops;
  59. S32 n_select_loops;
  60. S32 n_deselect_loops;
  61. bool registered;
  62. U8 obj_type_style;
  63. U32 obj_type_mask;
  64. afxEffectBaseData* dummy_fx_entry;
  65. afxEffectList main_fx_list;
  66. afxEffectList select_fx_list;
  67. afxEffectList deselect_fx_list;
  68. private:
  69. void pack_fx(BitStream* stream, const afxEffectList& fx, bool packed);
  70. void unpack_fx(BitStream* stream, afxEffectList& fx);
  71. public:
  72. /*C*/ afxSelectronData();
  73. /*C*/ afxSelectronData(const afxSelectronData&, bool = false);
  74. /*D*/ ~afxSelectronData();
  75. void reloadReset() override;
  76. bool onAdd() override;
  77. void packData(BitStream*) override;
  78. void unpackData(BitStream*) override;
  79. bool preload(bool server, String &errorStr) override;
  80. bool matches(U32 mask, U8 style);
  81. void gatherConstraintDefs(Vector<afxConstraintDef>&);
  82. bool allowSubstitutions() const override { return true; }
  83. static void initPersistFields();
  84. DECLARE_CONOBJECT(afxSelectronData);
  85. };
  86. inline bool afxSelectronData::matches(U32 mask, U8 style)
  87. {
  88. if (obj_type_style != style)
  89. return false;
  90. if (obj_type_mask == 0 && mask == 0)
  91. return true;
  92. return ((obj_type_mask & mask) != 0);
  93. }
  94. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  95. // afxSelectron
  96. class afxSelectron : public afxChoreographer, public afxSelectronDefs
  97. {
  98. typedef afxChoreographer Parent;
  99. friend class arcaneFX;
  100. public:
  101. enum MaskBits
  102. {
  103. StateEventMask = Parent::NextFreeMask << 0,
  104. SyncEventMask = Parent::NextFreeMask << 1,
  105. NextFreeMask = Parent::NextFreeMask << 2
  106. };
  107. enum
  108. {
  109. NULL_EVENT,
  110. ACTIVATE_EVENT,
  111. SHUTDOWN_EVENT,
  112. DEACTIVATE_EVENT,
  113. INTERRUPT_EVENT
  114. };
  115. enum
  116. {
  117. INACTIVE_STATE,
  118. ACTIVE_STATE,
  119. CLEANUP_STATE,
  120. DONE_STATE,
  121. LATE_STATE
  122. };
  123. enum {
  124. MARK_ACTIVATE = BIT(0),
  125. MARK_SHUTDOWN = BIT(1),
  126. MARK_DEACTIVATE = BIT(2),
  127. MARK_INTERRUPT = BIT(3),
  128. };
  129. class ObjectDeleteEvent : public SimEvent
  130. {
  131. public:
  132. void process(SimObject *obj) override { if (obj) obj->deleteObject(); }
  133. };
  134. private:
  135. static StringTableEntry CAMERA_CONS;
  136. static StringTableEntry LISTENER_CONS;
  137. static StringTableEntry FREE_TARGET_CONS;
  138. private:
  139. afxSelectronData* datablock;
  140. SimObject* exeblock;
  141. bool constraints_initialized;
  142. bool client_only;
  143. U8 effect_state;
  144. F32 effect_elapsed;
  145. afxConstraintID listener_cons_id;
  146. afxConstraintID free_target_cons_id;
  147. afxConstraintID camera_cons_id;
  148. SceneObject* camera_cons_obj;
  149. afxPhrase* phrases[NUM_PHRASES];
  150. F32 time_factor;
  151. U8 marks_mask;
  152. private:
  153. void init();
  154. bool state_expired();
  155. void init_constraints();
  156. void setup_main_fx();
  157. void setup_select_fx();
  158. void setup_deselect_fx();
  159. bool cleanup_over();
  160. public:
  161. /*C*/ afxSelectron();
  162. /*C*/ afxSelectron(bool not_default);
  163. /*D*/ ~afxSelectron();
  164. // STANDARD OVERLOADED METHODS //
  165. bool onNewDataBlock(GameBaseData* dptr, bool reload) override;
  166. void processTick(const Move*) override;
  167. void advanceTime(F32 dt) override;
  168. bool onAdd() override;
  169. void onRemove() override;
  170. U32 packUpdate(NetConnection*, U32, BitStream*) override;
  171. void unpackUpdate(NetConnection*, BitStream*) override;
  172. void sync_with_clients() override;
  173. void finish_startup();
  174. DECLARE_CONOBJECT(afxSelectron);
  175. DECLARE_CATEGORY("UNLISTED");
  176. private:
  177. void process_server();
  178. //
  179. void change_state_s(U8 pending_state);
  180. //
  181. void enter_active_state_s();
  182. void leave_active_state_s();
  183. void enter_cleanup_state_s();
  184. void enter_done_state_s();
  185. private:
  186. void process_client(F32 dt);
  187. //
  188. void change_state_c(U8 pending_state);
  189. //
  190. void enter_active_state_c(F32 starttime);
  191. void enter_cleanup_state_c();
  192. void enter_done_state_c();
  193. void leave_active_state_c();
  194. void sync_client(U16 marks, U8 state, F32 elapsed);
  195. public:
  196. void postEvent(U8 event);
  197. void setTimeFactor(F32 f) { time_factor = (f > 0) ? f : 1.0f; }
  198. F32 getTimeFactor() { return time_factor; }
  199. void activate();
  200. public:
  201. static afxSelectron* start_selectron(SceneObject* picked, U8 subcode, SimObject* extra);
  202. };
  203. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  204. #endif // _AFX_SELECTION_EFFECT_H_