afxEA_Explosion.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 "T3D/fx/explosion.h"
  27. #include "afx/afxEffectDefs.h"
  28. #include "afx/afxEffectWrapper.h"
  29. #include "afx/afxChoreographer.h"
  30. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  31. // afxEA_Explosion
  32. class afxEA_Explosion : public afxEffectWrapper
  33. {
  34. typedef afxEffectWrapper Parent;
  35. ExplosionData* explosion_data;
  36. Explosion* explosion;
  37. bool exploded;
  38. void do_runtime_substitutions();
  39. public:
  40. /*C*/ afxEA_Explosion();
  41. virtual bool isDone() { return exploded; }
  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. };
  47. //~~~~~~~~~~~~~~~~~~~~//
  48. afxEA_Explosion::afxEA_Explosion()
  49. {
  50. explosion_data = 0;
  51. explosion = 0;
  52. exploded = false;
  53. }
  54. void afxEA_Explosion::ea_set_datablock(SimDataBlock* db)
  55. {
  56. explosion_data = dynamic_cast<ExplosionData*>(db);
  57. }
  58. bool afxEA_Explosion::ea_start()
  59. {
  60. if (!explosion_data)
  61. {
  62. Con::errorf("afxEA_Explosion::ea_start() -- missing or incompatible datablock.");
  63. return false;
  64. }
  65. do_runtime_substitutions();
  66. explosion = new Explosion();
  67. explosion->setSubstitutionData(mChoreographer, mGroup_index);
  68. explosion->setDataBlock(explosion_data);
  69. return true;
  70. }
  71. bool afxEA_Explosion::ea_update(F32 dt)
  72. {
  73. if (!exploded && explosion)
  74. {
  75. if (mIn_scope)
  76. {
  77. Point3F norm(0,0,1); mUpdated_xfm.mulV(norm);
  78. explosion->setInitialState(mUpdated_pos, norm);
  79. if (!explosion->registerObject())
  80. {
  81. delete explosion;
  82. explosion = 0;
  83. Con::errorf("afxEA_Explosion::ea_update() -- effect failed to register.");
  84. return false;
  85. }
  86. }
  87. exploded = true;
  88. }
  89. return true;
  90. }
  91. void afxEA_Explosion::ea_finish(bool was_stopped)
  92. {
  93. explosion = 0;
  94. exploded = false;
  95. }
  96. void afxEA_Explosion::do_runtime_substitutions()
  97. {
  98. explosion_data = explosion_data->cloneAndPerformSubstitutions(mChoreographer, mGroup_index);
  99. }
  100. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  101. class afxEA_ExplosionDesc : public afxEffectAdapterDesc, public afxEffectDefs
  102. {
  103. static afxEA_ExplosionDesc desc;
  104. public:
  105. virtual bool testEffectType(const SimDataBlock*) const;
  106. virtual bool requiresStop(const afxEffectWrapperData*, const afxEffectTimingData&) const { return false; }
  107. virtual bool runsOnServer(const afxEffectWrapperData*) const { return false; }
  108. virtual bool runsOnClient(const afxEffectWrapperData*) const { return true; }
  109. virtual afxEffectWrapper* create() const { return new afxEA_Explosion; }
  110. };
  111. afxEA_ExplosionDesc afxEA_ExplosionDesc::desc;
  112. bool afxEA_ExplosionDesc::testEffectType(const SimDataBlock* db) const
  113. {
  114. return (typeid(ExplosionData) == typeid(*db));
  115. }
  116. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//