afxEA_Mooring.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. #include <typeinfo>
  25. #include "afx/arcaneFX.h"
  26. #include "afx/afxEffectDefs.h"
  27. #include "afx/afxEffectWrapper.h"
  28. #include "afx/afxChoreographer.h"
  29. #include "afx/ce/afxMooring.h"
  30. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  31. // afxEA_Mooring
  32. class afxEA_Mooring : public afxEffectWrapper
  33. {
  34. typedef afxEffectWrapper Parent;
  35. afxMooringData* mMooring_data;
  36. afxMooring* mObj;
  37. void do_runtime_substitutions();
  38. public:
  39. /*C*/ afxEA_Mooring();
  40. /*D*/ ~afxEA_Mooring();
  41. virtual void ea_set_datablock(SimDataBlock*);
  42. virtual bool ea_start();
  43. virtual bool ea_update(F32 dt);
  44. virtual void ea_finish(bool was_stopped);
  45. virtual void onDeleteNotify(SimObject*);
  46. };
  47. //~~~~~~~~~~~~~~~~~~~~//
  48. afxEA_Mooring::afxEA_Mooring()
  49. {
  50. mMooring_data = 0;
  51. mObj = 0;
  52. }
  53. afxEA_Mooring::~afxEA_Mooring()
  54. {
  55. if (mObj)
  56. mObj->deleteObject();
  57. if (mMooring_data && mMooring_data->isTempClone())
  58. delete mMooring_data;
  59. mMooring_data = 0;
  60. }
  61. void afxEA_Mooring::ea_set_datablock(SimDataBlock* db)
  62. {
  63. mMooring_data = dynamic_cast<afxMooringData*>(db);
  64. }
  65. bool afxEA_Mooring::ea_start()
  66. {
  67. if (!mMooring_data)
  68. {
  69. Con::errorf("afxEA_Mooring::ea_start() -- missing or incompatible datablock.");
  70. return false;
  71. }
  72. do_runtime_substitutions();
  73. return true;
  74. }
  75. bool afxEA_Mooring::ea_update(F32 dt)
  76. {
  77. if (!mObj)
  78. {
  79. if (mDatablock->use_ghost_as_cons_obj && mDatablock->effect_name != ST_NULLSTRING)
  80. {
  81. mObj = new afxMooring(mMooring_data->networking,
  82. mChoreographer->getChoreographerId(),
  83. mDatablock->effect_name);
  84. }
  85. else
  86. {
  87. mObj = new afxMooring(mMooring_data->networking, 0, ST_NULLSTRING);
  88. }
  89. mObj->onNewDataBlock(mMooring_data, false);
  90. if (!mObj->registerObject())
  91. {
  92. delete mObj;
  93. mObj = 0;
  94. Con::errorf("afxEA_Mooring::ea_update() -- effect failed to register.");
  95. return false;
  96. }
  97. deleteNotify(mObj);
  98. }
  99. if (mObj)
  100. {
  101. mObj->setTransform(mUpdated_xfm);
  102. }
  103. return true;
  104. }
  105. void afxEA_Mooring::ea_finish(bool was_stopped)
  106. {
  107. }
  108. void afxEA_Mooring::onDeleteNotify(SimObject* obj)
  109. {
  110. if (mObj == obj)
  111. obj = 0;
  112. Parent::onDeleteNotify(obj);
  113. }
  114. void afxEA_Mooring::do_runtime_substitutions()
  115. {
  116. // only clone the datablock if there are substitutions
  117. if (mMooring_data->getSubstitutionCount() > 0)
  118. {
  119. // clone the datablock and perform substitutions
  120. afxMooringData* orig_db = mMooring_data;
  121. mMooring_data = new afxMooringData(*orig_db, true);
  122. orig_db->performSubstitutions(mMooring_data, mChoreographer, mGroup_index);
  123. }
  124. }
  125. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  126. class afxEA_MooringDesc : public afxEffectAdapterDesc, public afxEffectDefs
  127. {
  128. static afxEA_MooringDesc desc;
  129. public:
  130. virtual bool testEffectType(const SimDataBlock*) const;
  131. virtual bool requiresStop(const afxEffectWrapperData*, const afxEffectTimingData&) const;
  132. virtual bool runsOnServer(const afxEffectWrapperData*) const;
  133. virtual bool runsOnClient(const afxEffectWrapperData*) const;
  134. virtual afxEffectWrapper* create() const { return new afxEA_Mooring; }
  135. };
  136. afxEA_MooringDesc afxEA_MooringDesc::desc;
  137. bool afxEA_MooringDesc::testEffectType(const SimDataBlock* db) const
  138. {
  139. return (typeid(afxMooringData) == typeid(*db));
  140. }
  141. bool afxEA_MooringDesc::requiresStop(const afxEffectWrapperData* ew, const afxEffectTimingData& timing) const
  142. {
  143. return (timing.lifetime < 0);
  144. }
  145. bool afxEA_MooringDesc::runsOnServer(const afxEffectWrapperData* ew) const
  146. {
  147. U8 networking = ((const afxMooringData*)ew->effect_data)->networking;
  148. return ((networking & CLIENT_ONLY) == 0);
  149. }
  150. bool afxEA_MooringDesc::runsOnClient(const afxEffectWrapperData* ew) const
  151. {
  152. U8 networking = ((const afxMooringData*)ew->effect_data)->networking;
  153. return ((networking & CLIENT_ONLY) != 0);
  154. }
  155. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//