afxXfmMod.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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_XFM_MOD_BASE_H_
  25. #define _AFX_XFM_MOD_BASE_H_
  26. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  27. #include "math/mPoint3.h"
  28. #include "math/mMatrix.h"
  29. #include "math/mMathFn.h"
  30. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  31. // BASE CLASSES
  32. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  33. class BitStream;
  34. class afxEffectWrapper;
  35. class afxXM_Defs
  36. {
  37. public:
  38. enum
  39. {
  40. POSITION = BIT(0),
  41. ORIENTATION = BIT(1),
  42. POSITION2 = BIT(2),
  43. SCALE = BIT(3),
  44. COLOR = BIT(4),
  45. VISIBILITY = BIT(5),
  46. ALL_BUT_SCALE = (POSITION | ORIENTATION | POSITION2),
  47. ALL = (ALL_BUT_SCALE | SCALE),
  48. };
  49. };
  50. struct afxXM_Params : public afxXM_Defs
  51. {
  52. Point3F pos;
  53. MatrixF ori;
  54. Point3F scale;
  55. Point3F pos2;
  56. LinearColorF color;
  57. F32 vis;
  58. enum { BAD_OFFSET = S32_MAX };
  59. static U32 getParameterOffset(U32 param, S32 component=-1);
  60. afxXM_Params();
  61. };
  62. class afxXM_Base;
  63. class afxXM_BaseData : public GameBaseData, public afxXM_Defs
  64. {
  65. typedef GameBaseData Parent;
  66. public:
  67. bool ignore_time_factor;
  68. public:
  69. /*C*/ afxXM_BaseData();
  70. /*C*/ afxXM_BaseData(const afxXM_BaseData&, bool = false);
  71. void packData(BitStream* stream);
  72. void unpackData(BitStream* stream);
  73. static void initPersistFields();
  74. virtual afxXM_Base* create(afxEffectWrapper* fx, bool on_server) { return 0; }
  75. DECLARE_CONOBJECT(afxXM_BaseData);
  76. DECLARE_CATEGORY("AFX");
  77. };
  78. class afxXM_Base : public afxXM_Defs
  79. {
  80. protected:
  81. afxEffectWrapper* fx_wrapper;
  82. afxXM_BaseData* datablock;
  83. F32 time_factor;
  84. public:
  85. /*C*/ afxXM_Base(afxXM_BaseData*, afxEffectWrapper*);
  86. virtual ~afxXM_Base();
  87. virtual void start(F32 timestamp) { }
  88. virtual void updateParams(F32 dt, F32 elapsed, afxXM_Params& p);
  89. // old update form for backwards compatibility (deprecated)
  90. virtual void update(F32 dt, F32 elapsed, Point3F& pos, MatrixF& ori, Point3F& pos2, Point3F& scale) { };
  91. };
  92. // New subclasses should define own updateParams() and should *not* call this thru Parent.
  93. // This calls old form of update() for backwards compatibility.
  94. inline void afxXM_Base::updateParams(F32 dt, F32 elapsed, afxXM_Params& p)
  95. {
  96. update(dt, elapsed, p.pos, p.ori, p.pos2, p.scale);
  97. };
  98. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  99. class afxXM_WeightedBaseData : public afxXM_BaseData
  100. {
  101. typedef afxXM_BaseData Parent;
  102. public:
  103. F32 lifetime;
  104. F32 delay;
  105. F32 fade_in_time;
  106. F32 fade_out_time;
  107. Point2F fadein_ease;
  108. Point2F fadeout_ease;
  109. F32 life_bias;
  110. public:
  111. /*C*/ afxXM_WeightedBaseData();
  112. /*C*/ afxXM_WeightedBaseData(const afxXM_WeightedBaseData&, bool = false);
  113. bool hasFixedWeight() const;
  114. F32 getWeightFactor() const;
  115. void packData(BitStream* stream);
  116. void unpackData(BitStream* stream);
  117. static void initPersistFields();
  118. DECLARE_CONOBJECT(afxXM_WeightedBaseData);
  119. DECLARE_CATEGORY("AFX");
  120. };
  121. class afxXM_WeightedBase : public afxXM_Base
  122. {
  123. typedef afxXM_Base Parent;
  124. protected:
  125. F32 wt_fadein;
  126. F32 wt_fadeout;
  127. Point2F wt_fadein_ease;
  128. Point2F wt_fadeout_ease;
  129. F32 wt_start_time;
  130. F32 wt_full_time;
  131. F32 wt_fade_time;
  132. F32 wt_done_time;
  133. F32 calc_weight_factor(F32 elapsed);
  134. public:
  135. /*C*/ afxXM_WeightedBase(afxXM_WeightedBaseData*, afxEffectWrapper*);
  136. virtual ~afxXM_WeightedBase() { }
  137. };
  138. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  139. #endif // _AFX_XFM_MOD_BASE_H_