afxEA_AnimLock.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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/ce/afxAnimLock.h"
  29. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  30. // afxEA_AnimLock
  31. class afxEA_AnimLock : public afxEffectWrapper
  32. {
  33. typedef afxEffectWrapper Parent;
  34. bool started;
  35. U32 lock_tag;
  36. public:
  37. /*C*/ afxEA_AnimLock();
  38. virtual bool ea_update(F32 dt);
  39. virtual void ea_finish(bool was_stopped);
  40. };
  41. //~~~~~~~~~~~~~~~~~~~~//
  42. afxEA_AnimLock::afxEA_AnimLock()
  43. {
  44. started = false;
  45. lock_tag = 0;
  46. }
  47. bool afxEA_AnimLock::ea_update(F32 dt)
  48. {
  49. afxConstraint* pos_constraint = getPosConstraint();
  50. if (!started && pos_constraint != 0)
  51. {
  52. lock_tag = pos_constraint->lockAnimation();
  53. started = true;
  54. }
  55. return true;
  56. }
  57. void afxEA_AnimLock::ea_finish(bool was_stopped)
  58. {
  59. afxConstraint* pos_constraint = getPosConstraint();
  60. if (pos_constraint && lock_tag != 0)
  61. {
  62. pos_constraint->unlockAnimation(lock_tag);
  63. }
  64. started = false;
  65. }
  66. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  67. class afxEA_AnimLockDesc : public afxEffectAdapterDesc, public afxEffectDefs
  68. {
  69. static afxEA_AnimLockDesc desc;
  70. public:
  71. virtual bool testEffectType(const SimDataBlock*) const;
  72. virtual bool requiresStop(const afxEffectWrapperData*, const afxEffectTimingData&) const;
  73. virtual bool runsOnServer(const afxEffectWrapperData*) const { return true; }
  74. virtual bool runsOnClient(const afxEffectWrapperData*) const { return true; }
  75. virtual bool isPositional(const afxEffectWrapperData*) const { return false; }
  76. virtual afxEffectWrapper* create() const { return new afxEA_AnimLock; }
  77. };
  78. afxEA_AnimLockDesc afxEA_AnimLockDesc::desc;
  79. bool afxEA_AnimLockDesc::testEffectType(const SimDataBlock* db) const
  80. {
  81. return (typeid(afxAnimLockData) == typeid(*db));
  82. }
  83. bool afxEA_AnimLockDesc::requiresStop(const afxEffectWrapperData* ew, const afxEffectTimingData& timing) const
  84. {
  85. return (timing.lifetime < 0);
  86. }
  87. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//