afxChoreographer.h 8.5 KB

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