afxChoreographer.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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_CHOREOGRAPHER_H_
  25. #define _AFX_CHOREOGRAPHER_H_
  26. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  27. #include "afxEffectDefs.h"
  28. #include "afxEffectWrapper.h"
  29. #include "afxMagicMissile.h"
  30. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  31. // afxChoreographerData
  32. class afxChoreographerData : public GameBaseData, public afxEffectDefs
  33. {
  34. typedef GameBaseData Parent;
  35. public:
  36. bool exec_on_new_clients;
  37. U8 echo_packet_usage;
  38. StringTableEntry client_script_file;
  39. StringTableEntry client_init_func;
  40. public:
  41. /*C*/ afxChoreographerData();
  42. /*C*/ afxChoreographerData(const afxChoreographerData&, bool = false);
  43. virtual void packData(BitStream*);
  44. virtual void unpackData(BitStream*);
  45. bool preload(bool server, String &errorStr);
  46. static void initPersistFields();
  47. DECLARE_CONOBJECT(afxChoreographerData);
  48. DECLARE_CATEGORY("AFX");
  49. };
  50. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  51. // afxChoreographer
  52. class afxConstraint;
  53. class afxConstraintMgr;
  54. class afxEffectWrapper;
  55. class afxParticlePool;
  56. class afxParticlePoolData;
  57. class SimSet;
  58. class afxForceSetMgr;
  59. class afxChoreographer : public GameBase, public afxEffectDefs, public afxMagicMissileCallback
  60. {
  61. typedef GameBase Parent;
  62. public:
  63. enum MaskBits
  64. {
  65. TriggerMask = Parent::NextFreeMask << 0,
  66. RemapConstraintMask = Parent::NextFreeMask << 1, // CONSTRAINT REMAPPING
  67. NextFreeMask = Parent::NextFreeMask << 2
  68. };
  69. enum
  70. {
  71. USER_EXEC_CONDS_MASK = 0x00ffffff
  72. };
  73. protected:
  74. struct dynConstraintDef
  75. {
  76. StringTableEntry cons_name;
  77. U8 cons_type;
  78. union
  79. {
  80. SceneObject* object;
  81. Point3F* point;
  82. MatrixF* xfm;
  83. U16 scope_id;
  84. } cons_obj;
  85. };
  86. private:
  87. afxChoreographerData* datablock;
  88. SimSet named_effects;
  89. SimObject* exeblock;
  90. afxForceSetMgr* force_set_mgr;
  91. Vector<afxParticlePool*> particle_pools;
  92. Vector<dynConstraintDef> dc_defs_a;
  93. Vector<dynConstraintDef> dc_defs_b;
  94. GameBase* proc_after_obj;
  95. U32 trigger_mask;
  96. protected:
  97. Vector<dynConstraintDef>* dyn_cons_defs;
  98. Vector<dynConstraintDef>* dyn_cons_defs2;
  99. afxConstraintMgr* constraint_mgr;
  100. U32 choreographer_id;
  101. U8 ranking;
  102. U8 lod;
  103. U32 exec_conds_mask;
  104. SimObject* mExtra;
  105. Vector<NetConnection*> explicit_clients;
  106. bool started_with_newop;
  107. bool postpone_activation;
  108. virtual void pack_constraint_info(NetConnection* conn, BitStream* stream);
  109. virtual void unpack_constraint_info(NetConnection* conn, BitStream* stream);
  110. void setup_dynamic_constraints();
  111. void check_packet_usage(NetConnection*, BitStream*, S32 mark_stream_pos, const char* msg_tag);
  112. SceneObject* get_camera(Point3F* cam_pos=0) const;
  113. public:
  114. /*C*/ afxChoreographer();
  115. virtual ~afxChoreographer();
  116. static void initPersistFields();
  117. virtual bool onAdd();
  118. virtual void onRemove();
  119. virtual void onDeleteNotify(SimObject*);
  120. virtual bool onNewDataBlock(GameBaseData* dptr, bool reload);
  121. virtual U32 packUpdate(NetConnection*, U32, BitStream*);
  122. virtual void unpackUpdate(NetConnection*, BitStream*);
  123. virtual void sync_with_clients() { }
  124. afxConstraintMgr* getConstraintMgr() { return constraint_mgr; }
  125. afxForceSetMgr* getForceSetMgr() { return force_set_mgr; }
  126. afxParticlePool* findParticlePool(afxParticlePoolData* key_block, U32 key_index);
  127. void registerParticlePool(afxParticlePool*);
  128. void unregisterParticlePool(afxParticlePool*);
  129. void setRanking(U8 value) { ranking = value; }
  130. U8 getRanking() const { return ranking; }
  131. bool testRanking(U8 low, U8 high) { return (ranking <= high && ranking >= low); }
  132. void setLevelOfDetail(U8 value) { lod = value; }
  133. U8 getLevelOfDetail() const { return lod; }
  134. bool testLevelOfDetail(U8 low, U8 high) { return (lod <= high && lod >= low); }
  135. void setExecConditions(U32 mask) { exec_conds_mask = mask; }
  136. U32 getExecConditions() const { return exec_conds_mask; }
  137. virtual void executeScriptEvent(const char* method, afxConstraint*,
  138. const MatrixF& xfm, const char* data);
  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. void addObjectConstraint(SceneObject*, const char* cons_name);
  142. void addObjectConstraint(U16 scope_id, const char* cons_name, bool is_shape);
  143. void addPointConstraint(Point3F&, const char* cons_name);
  144. void addTransformConstraint(MatrixF&, const char* cons_name);
  145. bool addConstraint(const char* source_spec, const char* cons_name);
  146. void addNamedEffect(afxEffectWrapper*);
  147. void removeNamedEffect(afxEffectWrapper*);
  148. afxEffectWrapper* findNamedEffect(StringTableEntry);
  149. void clearChoreographerId() { choreographer_id = 0; }
  150. U32 getChoreographerId() { return choreographer_id; }
  151. void setGhostConstraintObject(SceneObject*, StringTableEntry cons_name);
  152. void setExtra(SimObject* extra) { mExtra = extra; }
  153. void addExplicitClient(NetConnection* conn);
  154. void removeExplicitClient(NetConnection* conn);
  155. U32 getExplicitClientCount() { return explicit_clients.size(); }
  156. void restoreScopedObject(SceneObject* obj);
  157. virtual void restoreObject(SceneObject*) { };
  158. void postProcessAfterObject(GameBase* obj);
  159. U32 getTriggerMask() const { return trigger_mask; }
  160. void setTriggerMask(U32 trigger_mask);
  161. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
  162. // missile watcher callbacks
  163. public:
  164. virtual void impactNotify(const Point3F& p, const Point3F& n, SceneObject*) { }
  165. DECLARE_CONOBJECT(afxChoreographer);
  166. DECLARE_CATEGORY("AFX");
  167. // CONSTRAINT REMAPPING <<
  168. protected:
  169. Vector<dynConstraintDef*> remapped_cons_defs;
  170. bool remapped_cons_sent;
  171. virtual bool remap_builtin_constraint(SceneObject*, const char* cons_name) { return false; }
  172. dynConstraintDef* find_cons_def_by_name(const char* cons_name);
  173. public:
  174. void remapObjectConstraint(SceneObject*, const char* cons_name);
  175. void remapObjectConstraint(U16 scope_id, const char* cons_name, bool is_shape);
  176. void remapPointConstraint(Point3F&, const char* cons_name);
  177. void remapTransformConstraint(MatrixF&, const char* cons_name);
  178. bool remapConstraint(const char* source_spec, const char* cons_name);
  179. // CONSTRAINT REMAPPING >>
  180. };
  181. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  182. #endif // _AFX_CHOREOGRAPHER_H_