afxEA_Billboard.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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/afxResidueMgr.h"
  30. #include "afx/ce/afxBillboard.h"
  31. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  32. // afxEA_Billboard -- This is the adapter for geometry primitives.
  33. class afxEA_Billboard : public afxEffectWrapper
  34. {
  35. typedef afxEffectWrapper Parent;
  36. afxBillboardData* bb_data;
  37. afxBillboard* bb;
  38. void do_runtime_substitutions();
  39. public:
  40. /*C*/ afxEA_Billboard();
  41. /*D*/ ~afxEA_Billboard();
  42. virtual void ea_set_datablock(SimDataBlock*);
  43. virtual bool ea_start();
  44. virtual bool ea_update(F32 dt);
  45. virtual void ea_finish(bool was_stopped);
  46. virtual void ea_set_scope_status(bool flag);
  47. virtual void onDeleteNotify(SimObject*);
  48. virtual void getUpdatedBoxCenter(Point3F& pos);
  49. virtual void getBaseColor(LinearColorF& color) { if (bb_data) color = bb_data->color; }
  50. };
  51. afxEA_Billboard::afxEA_Billboard()
  52. {
  53. bb_data = 0;
  54. bb = 0;
  55. }
  56. afxEA_Billboard::~afxEA_Billboard()
  57. {
  58. if (bb)
  59. bb->deleteObject();
  60. if (bb_data && bb_data->isTempClone())
  61. delete bb_data;
  62. bb_data = 0;
  63. }
  64. void afxEA_Billboard::ea_set_datablock(SimDataBlock* db)
  65. {
  66. bb_data = dynamic_cast<afxBillboardData*>(db);
  67. }
  68. bool afxEA_Billboard::ea_start()
  69. {
  70. if (!bb_data)
  71. {
  72. Con::errorf("afxEA_Billboard::ea_start() -- missing or incompatible datablock.");
  73. return false;
  74. }
  75. do_runtime_substitutions();
  76. return true;
  77. }
  78. bool afxEA_Billboard::ea_update(F32 dt)
  79. {
  80. if (!bb)
  81. {
  82. // create and register effect
  83. bb = new afxBillboard();
  84. bb->onNewDataBlock(bb_data, false);
  85. if (!bb->registerObject())
  86. {
  87. delete bb;
  88. bb = 0;
  89. Con::errorf("afxEA_Billboard::ea_update() -- effect failed to register.");
  90. return false;
  91. }
  92. deleteNotify(bb);
  93. ///bb->setSequenceRateFactor(datablock->rate_factor/prop_time_factor);
  94. bb->setSortPriority(mDatablock->sort_priority);
  95. }
  96. if (bb)
  97. {
  98. bb->live_color = mUpdated_color;
  99. if (mDo_fades)
  100. {
  101. bb->setFadeAmount(mFade_value);
  102. }
  103. bb->setTransform(mUpdated_xfm);
  104. bb->setScale(mUpdated_scale);
  105. }
  106. return true;
  107. }
  108. void afxEA_Billboard::ea_finish(bool was_stopped)
  109. {
  110. if (!bb)
  111. return;
  112. bb->deleteObject();
  113. bb = 0;
  114. }
  115. void afxEA_Billboard::ea_set_scope_status(bool in_scope)
  116. {
  117. if (bb)
  118. bb->setVisibility(in_scope);
  119. }
  120. void afxEA_Billboard::onDeleteNotify(SimObject* obj)
  121. {
  122. if (bb == dynamic_cast<afxBillboard*>(obj))
  123. bb = 0;
  124. Parent::onDeleteNotify(obj);
  125. }
  126. void afxEA_Billboard::getUpdatedBoxCenter(Point3F& pos)
  127. {
  128. if (bb)
  129. pos = bb->getBoxCenter();
  130. }
  131. void afxEA_Billboard::do_runtime_substitutions()
  132. {
  133. // only clone the datablock if there are substitutions
  134. if (bb_data->getSubstitutionCount() > 0)
  135. {
  136. // clone the datablock and perform substitutions
  137. afxBillboardData* orig_db = bb_data;
  138. bb_data = new afxBillboardData(*orig_db, true);
  139. orig_db->performSubstitutions(bb_data, mChoreographer, mGroup_index);
  140. }
  141. }
  142. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  143. class afxEA_BillboardDesc : public afxEffectAdapterDesc, public afxEffectDefs
  144. {
  145. static afxEA_BillboardDesc desc;
  146. public:
  147. virtual bool testEffectType(const SimDataBlock*) const;
  148. virtual bool requiresStop(const afxEffectWrapperData*, const afxEffectTimingData&) const;
  149. virtual bool runsOnServer(const afxEffectWrapperData*) const { return false; }
  150. virtual bool runsOnClient(const afxEffectWrapperData*) const { return true; }
  151. virtual afxEffectWrapper* create() const { return new afxEA_Billboard; }
  152. };
  153. //~~~~~~~~~~~~~~~~~~~~//
  154. afxEA_BillboardDesc afxEA_BillboardDesc::desc;
  155. bool afxEA_BillboardDesc::testEffectType(const SimDataBlock* db) const
  156. {
  157. return (typeid(afxBillboardData) == typeid(*db));
  158. }
  159. bool afxEA_BillboardDesc::requiresStop(const afxEffectWrapperData* ew, const afxEffectTimingData& timing) const
  160. {
  161. return (timing.lifetime < 0);
  162. }
  163. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//