afxXfmMod.h

Engine/source/afx/xm/afxXfmMod.h

More...

Classes:

Detailed Description

  1
  2
  3//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  4// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  5// Copyright (C) 2015 Faust Logic, Inc.
  6//
  7// Permission is hereby granted, free of charge, to any person obtaining a copy
  8// of this software and associated documentation files (the "Software"), to
  9// deal in the Software without restriction, including without limitation the
 10// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 11// sell copies of the Software, and to permit persons to whom the Software is
 12// furnished to do so, subject to the following conditions:
 13//
 14// The above copyright notice and this permission notice shall be included in
 15// all copies or substantial portions of the Software.
 16//
 17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 23// IN THE SOFTWARE.
 24//
 25//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 26
 27#ifndef _AFX_XFM_MOD_BASE_H_
 28#define _AFX_XFM_MOD_BASE_H_
 29
 30//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 31
 32#include "math/mPoint3.h"
 33#include "math/mMatrix.h"
 34#include "math/mMathFn.h"
 35
 36//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 37// BASE CLASSES
 38//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 39
 40class BitStream;
 41class afxEffectWrapper;
 42
 43class afxXM_Defs
 44{
 45public:
 46  enum
 47  {
 48    POSITION      = BIT(0),
 49    ORIENTATION   = BIT(1),
 50    POSITION2     = BIT(2),
 51    SCALE         = BIT(3),
 52    COLOR         = BIT(4),
 53    VISIBILITY    = BIT(5),
 54    ALL_BUT_SCALE = (POSITION | ORIENTATION | POSITION2),
 55    ALL           = (ALL_BUT_SCALE | SCALE),
 56  };
 57};
 58
 59struct afxXM_Params : public afxXM_Defs
 60{
 61  Point3F   pos;
 62  MatrixF   ori;
 63  Point3F   scale;
 64  Point3F   pos2;
 65  LinearColorF    color;
 66  F32       vis;
 67
 68  enum { BAD_OFFSET = S32_MAX };
 69
 70  static U32 getParameterOffset(U32 param, S32 component=-1);
 71  afxXM_Params();
 72};
 73
 74class afxXM_Base;
 75
 76class afxXM_BaseData : public  GameBaseData, public afxXM_Defs
 77{
 78  typedef GameBaseData Parent;
 79
 80public:
 81  bool          ignore_time_factor;
 82
 83public:
 84  /*C*/         afxXM_BaseData();
 85  /*C*/         afxXM_BaseData(const afxXM_BaseData&, bool = false);
 86
 87  void          packData(BitStream* stream);
 88  void          unpackData(BitStream* stream);
 89
 90  static void   initPersistFields();
 91
 92  virtual afxXM_Base* create(afxEffectWrapper* fx, bool on_server) { return 0; }
 93
 94  DECLARE_CONOBJECT(afxXM_BaseData);
 95  DECLARE_CATEGORY("AFX");
 96};
 97
 98class afxXM_Base : public afxXM_Defs
 99{
100protected:
101  afxEffectWrapper* fx_wrapper;
102  afxXM_BaseData*   datablock;
103  F32               time_factor;
104
105public:
106  /*C*/             afxXM_Base(afxXM_BaseData*, afxEffectWrapper*);
107  virtual           ~afxXM_Base();
108
109  virtual void      start(F32 timestamp) { }
110  virtual void      updateParams(F32 dt, F32 elapsed, afxXM_Params& p);
111
112  // old update form for backwards compatibility (deprecated)
113  virtual void      update(F32 dt, F32 elapsed, Point3F& pos, MatrixF& ori, Point3F& pos2, Point3F& scale) { };
114};
115
116// New subclasses should define own updateParams() and should *not* call this thru Parent. 
117// This calls old form of update() for backwards compatibility.
118inline void afxXM_Base::updateParams(F32 dt, F32 elapsed, afxXM_Params& p) 
119{ 
120  update(dt, elapsed, p.pos, p.ori, p.pos2, p.scale); 
121};
122
123//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
124
125class afxXM_WeightedBaseData : public  afxXM_BaseData
126{
127  typedef afxXM_BaseData Parent;
128
129public:
130  F32           lifetime;
131  F32           delay;
132  F32           fade_in_time;
133  F32           fade_out_time;
134  Point2F       fadein_ease;
135  Point2F       fadeout_ease;
136  F32           life_bias;
137
138public:
139  /*C*/         afxXM_WeightedBaseData();
140  /*C*/         afxXM_WeightedBaseData(const afxXM_WeightedBaseData&, bool = false);
141
142  bool          hasFixedWeight() const;
143  F32           getWeightFactor() const;
144
145  void          packData(BitStream* stream);
146  void          unpackData(BitStream* stream);
147
148  static void   initPersistFields();
149
150  DECLARE_CONOBJECT(afxXM_WeightedBaseData);
151  DECLARE_CATEGORY("AFX");
152};
153
154class afxXM_WeightedBase : public afxXM_Base
155{
156  typedef afxXM_Base Parent;
157
158protected:
159  F32           wt_fadein;
160  F32           wt_fadeout;
161  Point2F       wt_fadein_ease;
162  Point2F       wt_fadeout_ease;
163  F32           wt_start_time;
164  F32           wt_full_time;
165  F32           wt_fade_time;
166  F32           wt_done_time;
167
168  F32           calc_weight_factor(F32 elapsed);
169
170public:
171  /*C*/         afxXM_WeightedBase(afxXM_WeightedBaseData*, afxEffectWrapper*);
172  virtual       ~afxXM_WeightedBase() { }
173};
174
175//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
176
177#endif // _AFX_XFM_MOD_BASE_H_
178