Torque3D Documentation / _generateds / afxXM_WaveBase.h

afxXM_WaveBase.h

Engine/source/afx/xm/afxXM_WaveBase.h

More...

Classes:

Public Typedefs

Detailed Description

Public Typedefs

typedef afxXM_WaveBaseData::WaveFormType afxXM_WaveFormType 
typedef afxXM_WaveBaseData::WaveOpType afxXM_WaveOpType 
typedef afxXM_WaveBaseData::WaveParamType afxXM_WaveParamType 

Public Functions

DefineEnumType(afxXM_WaveFormType )

DefineEnumType(afxXM_WaveOpType )

DefineEnumType(afxXM_WaveParamType )

  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_WAVE_BASE_H_
 28#define _AFX_XFM_WAVE_BASE_H_
 29
 30#include "afx/xm/afxXfmMod.h"
 31
 32//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 33// WAVEFORM
 34
 35class afxXM_Waveform
 36{
 37public:
 38  virtual F32 evaluate(F32 t) = 0;
 39};
 40
 41//~~~~~~~~~~~~~~~~~~~~//
 42
 43class afxXM_WaveformSine : public afxXM_Waveform
 44{
 45public:
 46  virtual F32 evaluate(F32 t);
 47};
 48
 49class afxXM_WaveformSquare : public afxXM_Waveform
 50{
 51public:
 52  virtual F32 evaluate(F32 t);
 53};
 54
 55class afxXM_WaveformTriangle : public afxXM_Waveform
 56{
 57public:
 58  virtual F32 evaluate(F32 t);
 59};
 60
 61class afxXM_WaveformSawtooth : public afxXM_Waveform
 62{
 63public:
 64  virtual F32 evaluate(F32 t) { return t; }
 65};
 66
 67class afxXM_WaveformNoise : public afxXM_Waveform
 68{
 69public:
 70  virtual F32 evaluate(F32 t) { return gRandGen.randF(); };
 71};
 72
 73class afxXM_WaveformOne : public afxXM_Waveform
 74{
 75public:
 76  virtual F32 evaluate(F32 t) { return 1.0f; };
 77};
 78
 79//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 80// WAVE INTERPOLATOR
 81
 82class afxXM_WaveInterp
 83{
 84public:
 85  virtual void interpolate(F32 t, afxXM_Params& params)=0;
 86  virtual void pulse()=0;
 87
 88  static F32 lerp(F32 t, F32 a, F32 b) { return a + t * (b - a); }
 89};
 90
 91//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 92// WAVE BASE DATABLOCK
 93
 94class afxXM_WaveBaseData : public afxXM_WeightedBaseData
 95{
 96  typedef afxXM_WeightedBaseData Parent;
 97  friend class afxXM_WaveRiderBaseData;
 98
 99public:
100  enum  WaveFormType
101  {
102    WAVEFORM_NONE = 0,
103    WAVEFORM_SINE,
104    WAVEFORM_SQUARE,
105    WAVEFORM_TRIANGLE,
106    WAVEFORM_SAWTOOTH,
107    WAVEFORM_NOISE,
108    WAVEFORM_ONE,
109    WAVEFORM_BITS = 3
110  };
111
112  enum WaveOpType
113  {
114    OP_ADD = 0,
115    OP_MULTIPLY,
116    OP_REPLACE,
117    OP_BITS = 2
118  };
119
120  enum WaveParamType
121  {
122     PARAM_NONE = 0,
123     PARAM_POS,
124        PARAM_POS_X,
125        PARAM_POS_Y,
126        PARAM_POS_Z,
127     PARAM_ORI,
128     PARAM_POS2,
129        PARAM_POS2_X,
130        PARAM_POS2_Y,
131        PARAM_POS2_Z,
132     PARAM_SCALE,
133        PARAM_SCALE_X,
134        PARAM_SCALE_Y,
135        PARAM_SCALE_Z,
136     PARAM_COLOR,
137        PARAM_COLOR_R,
138        PARAM_COLOR_G,
139        PARAM_COLOR_B,
140        PARAM_COLOR_A,
141     PARAM_VIS,
142     PARAM_BITS = 5,
143  };  
144  
145  U32             waveform_type;
146  U32             parameter;
147  U32             op;
148  F32             speed;
149  F32             speed_vari;
150  F32             accel;
151  F32             phase_shift;
152  F32             duty_cycle;
153  F32             duty_shift;
154  F32             off_duty_t;
155
156  ByteRange       waves_per_pulse;
157  ByteRange       waves_per_rest;
158  F32             rest_dur;
159  F32             rest_dur_vari;
160
161  Point3F         axis;
162  bool            local_axis;
163
164public:
165  /*C*/           afxXM_WaveBaseData();
166  /*C*/           afxXM_WaveBaseData(const afxXM_WaveBaseData&, bool = false);
167
168  void            packData(BitStream* stream);
169  void            unpackData(BitStream* stream);
170
171  static void     initPersistFields();
172
173  static void     initParamInfo(U32 parameter, U32& parambit, S32& component);
174  static afxXM_Waveform* getWaveform(U32 waveform_type);
175
176  DECLARE_CONOBJECT(afxXM_WaveBaseData);
177  DECLARE_CATEGORY("AFX");
178};
179
180typedef afxXM_WaveBaseData::WaveFormType afxXM_WaveFormType;
181DefineEnumType( afxXM_WaveFormType );
182
183typedef afxXM_WaveBaseData::WaveOpType afxXM_WaveOpType;
184DefineEnumType( afxXM_WaveOpType );
185
186typedef afxXM_WaveBaseData::WaveParamType afxXM_WaveParamType;
187DefineEnumType( afxXM_WaveParamType );
188
189//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
190// WAVE RIDER BASE DATABLOCK
191
192class afxXM_WaveRiderBaseData : public afxXM_WeightedBaseData
193{
194  typedef afxXM_WeightedBaseData Parent;
195
196public:  
197  U32             waveform_type;
198  F32             off_duty_t;
199  U32             parameter;
200  U32             op;
201
202  Point3F         axis;
203  bool            local_axis;
204
205public:
206  /*C*/           afxXM_WaveRiderBaseData();
207  /*C*/           afxXM_WaveRiderBaseData(const afxXM_WaveRiderBaseData&, bool = false);
208
209  void            packData(BitStream* stream);
210  void            unpackData(BitStream* stream);
211
212  static void     initPersistFields();
213
214  DECLARE_CONOBJECT(afxXM_WaveRiderBaseData);
215  DECLARE_CATEGORY("AFX");
216};
217
218//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
219// WAVE BASE 
220
221class afxXM_WaveBase : public afxXM_WeightedBase
222{
223  typedef afxXM_WeightedBase Parent;
224  friend class afxXM_WaveRiderBase;
225
226protected:
227  static bool           last_was_pulsed;
228  static bool           last_was_off_duty;
229  static F32            last_t;
230  static F32            last_wave_t;
231
232  afxXM_WaveInterp*     interpolator;
233
234protected:
235  afxXM_Waveform*       waveform;
236
237  afxXM_WaveBaseData*   db;
238  F32                   speed;
239  bool                  fixed_weight;
240
241  bool                  speed_is_randomized;
242  bool                  is_resting;
243  F32                   cur_pulse_time;
244  F32                   next_pulse_time;
245
246  F32                   calc_initial_speed();
247  F32                   calc_new_speed();
248  F32                   calc_new_restDur();
249  S32                   calc_new_wavesPerPulse();
250  S32                   calc_new_wavesPerRest();
251
252public:
253  /*C*/                 afxXM_WaveBase(afxXM_WaveBaseData*, afxEffectWrapper*, afxXM_WaveInterp*);
254  /*D*/                 ~afxXM_WaveBase();
255
256  virtual void          updateParams(F32 dt, F32 elapsed, afxXM_Params& params);
257};
258
259inline F32 afxXM_WaveBase::calc_initial_speed()
260{
261  return (!speed_is_randomized) ? 
262                db->speed : 
263                (db->speed + gRandGen.randF()*2.0f*db->speed_vari - db->speed_vari);
264}
265
266inline F32 afxXM_WaveBase::calc_new_speed()
267{
268  return mClampF((!speed_is_randomized) ? 
269                (speed + speed*db->accel) : 
270                (db->speed + gRandGen.randF()*2.0f*db->speed_vari - db->speed_vari), 0.001f, 200.0f);
271}
272
273inline F32 afxXM_WaveBase::calc_new_restDur()
274{
275  return db->rest_dur + gRandGen.randF()*2.0f*db->rest_dur_vari - db->rest_dur_vari;
276}
277
278inline S32 afxXM_WaveBase::calc_new_wavesPerPulse()
279{
280  return (db->waves_per_pulse.getSpan() == 0) ? 
281                db->waves_per_pulse.low : 
282                gRandGen.randI(db->waves_per_pulse.low, db->waves_per_pulse.high);
283}
284
285inline S32 afxXM_WaveBase::calc_new_wavesPerRest()
286{
287  return (db->waves_per_rest.getSpan() == 0) ? 
288                db->waves_per_rest.low : 
289                gRandGen.randI(db->waves_per_rest.low, db->waves_per_rest.high);
290}
291
292//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
293// WAVE RIDER BASE 
294
295class afxXM_WaveRiderBase : public afxXM_WeightedBase
296{
297  typedef afxXM_WeightedBase Parent;
298
299protected:
300  afxXM_WaveInterp*         interpolator;
301  afxXM_WaveRiderBaseData*  db;
302  afxXM_Waveform*           waveform;
303  bool                      fixed_weight;
304
305public:
306  /*C*/                 afxXM_WaveRiderBase(afxXM_WaveRiderBaseData*, afxEffectWrapper*, afxXM_WaveInterp*);
307  /*D*/                 ~afxXM_WaveRiderBase();
308
309  virtual void          updateParams(F32 dt, F32 elapsed, afxXM_Params& params);
310};
311
312//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
313
314#endif // _AFX_XFM_WAVE_BASE_H_
315
316