afxSelectron.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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, void *typePtr);
  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. virtual void reloadReset();
  76. virtual bool onAdd();
  77. virtual void packData(BitStream*);
  78. virtual void unpackData(BitStream*);
  79. bool preload(bool server, String &errorStr);
  80. bool matches(U32 mask, U8 style);
  81. void gatherConstraintDefs(Vector<afxConstraintDef>&);
  82. virtual bool allowSubstitutions() const { return true; }
  83. static void initPersistFields();
  84. DECLARE_CONOBJECT(afxSelectronData);
  85. DECLARE_CATEGORY("AFX");
  86. };
  87. inline bool afxSelectronData::matches(U32 mask, U8 style)
  88. {
  89. if (obj_type_style != style)
  90. return false;
  91. if (obj_type_mask == 0 && mask == 0)
  92. return true;
  93. return ((obj_type_mask & mask) != 0);
  94. }
  95. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  96. // afxSelectron
  97. class afxSelectron : public afxChoreographer, public afxSelectronDefs
  98. {
  99. typedef afxChoreographer Parent;
  100. friend class arcaneFX;
  101. public:
  102. enum MaskBits
  103. {
  104. StateEventMask = Parent::NextFreeMask << 0,
  105. SyncEventMask = Parent::NextFreeMask << 1,
  106. NextFreeMask = Parent::NextFreeMask << 2
  107. };
  108. enum
  109. {
  110. NULL_EVENT,
  111. ACTIVATE_EVENT,
  112. SHUTDOWN_EVENT,
  113. DEACTIVATE_EVENT,
  114. INTERRUPT_EVENT
  115. };
  116. enum
  117. {
  118. INACTIVE_STATE,
  119. ACTIVE_STATE,
  120. CLEANUP_STATE,
  121. DONE_STATE,
  122. LATE_STATE
  123. };
  124. enum {
  125. MARK_ACTIVATE = BIT(0),
  126. MARK_SHUTDOWN = BIT(1),
  127. MARK_DEACTIVATE = BIT(2),
  128. MARK_INTERRUPT = BIT(3),
  129. };
  130. class ObjectDeleteEvent : public SimEvent
  131. {
  132. public:
  133. void process(SimObject *obj) { if (obj) obj->deleteObject(); }
  134. };
  135. private:
  136. static StringTableEntry CAMERA_CONS;
  137. static StringTableEntry LISTENER_CONS;
  138. static StringTableEntry FREE_TARGET_CONS;
  139. private:
  140. afxSelectronData* datablock;
  141. SimObject* exeblock;
  142. bool constraints_initialized;
  143. bool client_only;
  144. U8 effect_state;
  145. F32 effect_elapsed;
  146. afxConstraintID listener_cons_id;
  147. afxConstraintID free_target_cons_id;
  148. afxConstraintID camera_cons_id;
  149. SceneObject* camera_cons_obj;
  150. afxPhrase* phrases[NUM_PHRASES];
  151. F32 time_factor;
  152. U8 marks_mask;
  153. private:
  154. void init();
  155. bool state_expired();
  156. void init_constraints();
  157. void setup_main_fx();
  158. void setup_select_fx();
  159. void setup_deselect_fx();
  160. bool cleanup_over();
  161. public:
  162. /*C*/ afxSelectron();
  163. /*C*/ afxSelectron(bool not_default);
  164. /*D*/ ~afxSelectron();
  165. // STANDARD OVERLOADED METHODS //
  166. virtual bool onNewDataBlock(GameBaseData* dptr, bool reload);
  167. virtual void processTick(const Move*);
  168. virtual void advanceTime(F32 dt);
  169. virtual bool onAdd();
  170. virtual void onRemove();
  171. virtual U32 packUpdate(NetConnection*, U32, BitStream*);
  172. virtual void unpackUpdate(NetConnection*, BitStream*);
  173. virtual void sync_with_clients();
  174. void finish_startup();
  175. DECLARE_CONOBJECT(afxSelectron);
  176. DECLARE_CATEGORY("AFX");
  177. private:
  178. void process_server();
  179. //
  180. void change_state_s(U8 pending_state);
  181. //
  182. void enter_active_state_s();
  183. void leave_active_state_s();
  184. void enter_cleanup_state_s();
  185. void enter_done_state_s();
  186. private:
  187. void process_client(F32 dt);
  188. //
  189. void change_state_c(U8 pending_state);
  190. //
  191. void enter_active_state_c(F32 starttime);
  192. void enter_cleanup_state_c();
  193. void enter_done_state_c();
  194. void leave_active_state_c();
  195. void sync_client(U16 marks, U8 state, F32 elapsed);
  196. public:
  197. void postEvent(U8 event);
  198. void setTimeFactor(F32 f) { time_factor = (f > 0) ? f : 1.0f; }
  199. F32 getTimeFactor() { return time_factor; }
  200. void activate();
  201. public:
  202. static afxSelectron* start_selectron(SceneObject* picked, U8 subcode, SimObject* extra);
  203. };
  204. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  205. #endif // _AFX_SELECTION_EFFECT_H_