Torque3D Documentation / _generateds / afxXM_WaveScalar.cpp

afxXM_WaveScalar.cpp

Engine/source/afx/xm/afxXM_WaveScalar.cpp

More...

Classes:

Public Functions

ConsoleDocClass(afxXM_WaveRiderScalarData , "@brief An xmod <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">datablock.\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxXMods\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Datablocks\n</a>" )
ConsoleDocClass(afxXM_WaveScalarData , "@brief An xmod <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">datablock.\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxXMods\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Datablocks\n</a>" )

Detailed Description

Public Functions

ConsoleDocClass(afxXM_WaveRiderScalarData , "@brief An xmod <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">datablock.\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxXMods\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Datablocks\n</a>" )

ConsoleDocClass(afxXM_WaveScalarData , "@brief An xmod <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">datablock.\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxXMods\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Datablocks\n</a>" )

IMPLEMENT_CO_DATABLOCK_V1(afxXM_WaveRiderScalarData )

IMPLEMENT_CO_DATABLOCK_V1(afxXM_WaveScalarData )

  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#include "afx/arcaneFX.h"
 28
 29#include "afx/afxEffectWrapper.h"
 30#include "afx/afxChoreographer.h"
 31#include "afx/xm/afxXM_WaveBase.h"
 32
 33//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 34// WAVE SCALAR INTERPOLATORS
 35
 36class afxXM_WaveInterp_Scalar : public afxXM_WaveInterp
 37{
 38protected:
 39  F32   mA_set, mB_set;
 40  F32   mA_var, mB_var;
 41  F32   mA, mB;
 42  bool  mSync_var;
 43
 44public:
 45  afxXM_WaveInterp_Scalar(); 
 46
 47  void set(F32 a, F32 b, F32 a_var, F32 b_var, bool sync_var);
 48
 49  virtual void interpolate(F32 t, afxXM_Params& params)=0;
 50  virtual void pulse();
 51};
 52
 53afxXM_WaveInterp_Scalar::afxXM_WaveInterp_Scalar() 
 54{ 
 55  mA_set = 0.0f; 
 56  mB_set = 1.0f;
 57  mA_var = 0.0f;
 58  mB_var = 0.0;
 59  mSync_var = false;
 60  mA = 0.0f;
 61  mB = 1.0f;
 62}
 63
 64void afxXM_WaveInterp_Scalar::set(F32 a, F32 b, F32 a_var, F32 b_var, bool sync_var)
 65{
 66  mA_set = a; 
 67  mB_set = b;
 68  mA_var = a_var;
 69  mB_var = b_var;
 70  mSync_var = sync_var;
 71  mA = a; 
 72  mA = b;
 73}
 74
 75inline void afxXM_WaveInterp_Scalar::pulse()
 76{
 77  F32 rand_t = gRandGen.randF()*2.0f;
 78  mA = mA_set + rand_t*mA_var - mA_var;
 79  if (!mSync_var) 
 80    rand_t = gRandGen.randF()*2.0f;
 81  mB = mB_set + rand_t*mB_var - mB_var;
 82}
 83
 84//~~~~~~~~~~~~~~~~~~~~//
 85
 86class afxXM_WaveInterp_Scalar_Add : public afxXM_WaveInterp_Scalar
 87{
 88protected:
 89  U32 offset;
 90public:
 91  afxXM_WaveInterp_Scalar_Add(U32 o) : afxXM_WaveInterp_Scalar() { offset = o; }
 92  virtual void interpolate(F32 t, afxXM_Params& params)
 93  {
 94    *((F32*)(((char*)(&params)) + offset)) += lerp(t, mA, mB);
 95  }
 96};
 97
 98//~~~~~~~~~~~~~~~~~~~~//
 99
100class afxXM_WaveInterp_Scalar_Mul : public afxXM_WaveInterp_Scalar
101{
102protected:
103  U32 offset;
104public:
105  afxXM_WaveInterp_Scalar_Mul(U32 o) : afxXM_WaveInterp_Scalar() { offset = o; }
106  virtual void interpolate(F32 t, afxXM_Params& params)
107  {
108    *((F32*)(((char*)(&params)) + offset)) *= lerp(t, mA, mB);
109  }
110};
111
112//~~~~~~~~~~~~~~~~~~~~//
113
114class afxXM_WaveInterp_Scalar_Rep : public afxXM_WaveInterp_Scalar
115{
116protected:
117  U32 offset;
118public:
119  afxXM_WaveInterp_Scalar_Rep(U32 o) : afxXM_WaveInterp_Scalar() { offset = o; }
120  virtual void interpolate(F32 t, afxXM_Params& params)
121  {
122    *((F32*)(((char*)(&params)) + offset)) = lerp(t, mA, mB);
123  }
124};
125
126//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
127
128class afxXM_WaveInterp_Scalar_PointAdd : public afxXM_WaveInterp_Scalar
129{
130protected:
131  U32 offset;
132public:
133  afxXM_WaveInterp_Scalar_PointAdd(U32 o) : afxXM_WaveInterp_Scalar() { offset = o; }
134  virtual void interpolate(F32 t, afxXM_Params& params)
135  {
136    F32 scalar_at_t = lerp(t, mA, mB);
137    Point3F point_at_t(scalar_at_t, scalar_at_t, scalar_at_t);
138    *((Point3F*)(((char*)(&params)) + offset)) += point_at_t;
139  }
140};
141
142//~~~~~~~~~~~~~~~~~~~~//
143
144class afxXM_WaveInterp_Scalar_PointMul : public afxXM_WaveInterp_Scalar
145{
146protected:
147  U32 offset;
148public:
149  afxXM_WaveInterp_Scalar_PointMul(U32 o) : afxXM_WaveInterp_Scalar() { offset = o; }
150  virtual void interpolate(F32 t, afxXM_Params& params)
151  {
152    *((Point3F*)(((char*)(&params)) + offset)) *= lerp(t, mA, mB);
153  }
154};
155
156//~~~~~~~~~~~~~~~~~~~~//
157
158class afxXM_WaveInterp_Scalar_PointRep : public afxXM_WaveInterp_Scalar
159{
160protected:
161  U32 offset;
162public:
163  afxXM_WaveInterp_Scalar_PointRep(U32 o) : afxXM_WaveInterp_Scalar() { offset = o; }
164  virtual void interpolate(F32 t, afxXM_Params& params)
165  {
166    F32 scalar_at_t = lerp(t,mA, mB);
167    Point3F point_at_t(scalar_at_t, scalar_at_t, scalar_at_t);
168    *((Point3F*)(((char*)(&params)) + offset)) = point_at_t;
169  }
170};
171
172//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
173
174class afxXM_WaveInterp_Scalar_Axis_PointAdd : public afxXM_WaveInterp_Scalar
175{
176protected:
177  Point3F   axis;
178  U32       offset;
179public:
180  afxXM_WaveInterp_Scalar_Axis_PointAdd(U32 o, Point3F ax) : afxXM_WaveInterp_Scalar() { offset = o; axis = ax; }
181  virtual void interpolate(F32 t, afxXM_Params& params)
182  {
183    Point3F point_at_t = axis*lerp(t, mA, mB);
184    *((Point3F*)(((char*)(&params)) + offset)) += point_at_t;
185  }
186};
187
188class afxXM_WaveInterp_Scalar_LocalAxis_PointAdd : public afxXM_WaveInterp_Scalar
189{
190protected:
191  Point3F   axis;
192  U32       offset;
193public:
194  afxXM_WaveInterp_Scalar_LocalAxis_PointAdd(U32 o, Point3F ax) : afxXM_WaveInterp_Scalar() { offset = o; axis = ax; }
195  virtual void interpolate(F32 t, afxXM_Params& params)
196  {
197    Point3F local_axis(axis); 
198    params.ori.mulV(local_axis);
199    Point3F point_at_t = local_axis*lerp(t, mA, mB);
200    *((Point3F*)(((char*)(&params)) + offset)) += point_at_t;
201  }
202};
203
204//~~~~~~~~~~~~~~~~~~~~//
205
206class afxXM_WaveInterp_Scalar_Axis_PointMul : public afxXM_WaveInterp_Scalar
207{
208protected:
209  Point3F   axis;
210  U32       offset;
211public:
212  afxXM_WaveInterp_Scalar_Axis_PointMul(U32 o, Point3F ax) : afxXM_WaveInterp_Scalar() { offset = o; axis = ax; }
213  virtual void interpolate(F32 t, afxXM_Params& params)
214  {
215    Point3F point_at_t = axis*lerp(t, mA, mB);
216    *((Point3F*)(((char*)(&params)) + offset)) *= point_at_t;
217  }
218};
219
220class afxXM_WaveInterp_Scalar_LocalAxis_PointMul : public afxXM_WaveInterp_Scalar
221{
222protected:
223  Point3F   axis;
224  U32       offset;
225public:
226  afxXM_WaveInterp_Scalar_LocalAxis_PointMul(U32 o, Point3F ax) : afxXM_WaveInterp_Scalar() { offset = o; axis = ax; }
227  virtual void interpolate(F32 t, afxXM_Params& params)
228  {
229    Point3F local_axis(axis); 
230    params.ori.mulV(local_axis);
231    Point3F point_at_t = local_axis*lerp(t, mA, mB);
232    *((Point3F*)(((char*)(&params)) + offset)) *= point_at_t;
233  }
234};
235
236//~~~~~~~~~~~~~~~~~~~~//
237
238class afxXM_WaveInterp_Scalar_Axis_PointRep : public afxXM_WaveInterp_Scalar
239{
240protected:
241  Point3F   axis;
242  U32       offset;
243public:
244  afxXM_WaveInterp_Scalar_Axis_PointRep(U32 o, Point3F ax) : afxXM_WaveInterp_Scalar() { offset = o; axis = ax; }
245  virtual void interpolate(F32 t, afxXM_Params& params)
246  {
247    Point3F point_at_t = axis*lerp(t, mA, mB);
248    *((Point3F*)(((char*)(&params)) + offset)) = point_at_t;
249  }
250};
251
252class afxXM_WaveInterp_Scalar_LocalAxis_PointRep : public afxXM_WaveInterp_Scalar
253{
254protected:
255  Point3F   axis;
256  U32       offset;
257public:
258  afxXM_WaveInterp_Scalar_LocalAxis_PointRep(U32 o, Point3F ax) : afxXM_WaveInterp_Scalar() { offset = o; axis = ax; }
259  virtual void interpolate(F32 t, afxXM_Params& params)
260  {
261    Point3F local_axis(axis); 
262    params.ori.mulV(local_axis);
263    Point3F point_at_t = local_axis*lerp(t, mA, mB);
264    *((Point3F*)(((char*)(&params)) + offset)) = point_at_t;
265  }
266};
267
268//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
269
270class afxXM_WaveInterp_Scalar_ColorAdd : public afxXM_WaveInterp_Scalar
271{
272public:
273  afxXM_WaveInterp_Scalar_ColorAdd() : afxXM_WaveInterp_Scalar() { }
274  virtual void interpolate(F32 t, afxXM_Params& params)
275  {
276    F32 scalar_at_t = lerp(t, mA, mB);
277    LinearColorF color_at_t(scalar_at_t, scalar_at_t, scalar_at_t, scalar_at_t);
278    params.color += color_at_t;
279  }
280};
281
282//~~~~~~~~~~~~~~~~~~~~//
283
284class afxXM_WaveInterp_Scalar_ColorMul : public afxXM_WaveInterp_Scalar
285{
286public:
287  afxXM_WaveInterp_Scalar_ColorMul() : afxXM_WaveInterp_Scalar() { }
288  virtual void interpolate(F32 t, afxXM_Params& params)
289  {
290    params.color *= lerp(t, mA, mB);
291  }
292};
293
294//~~~~~~~~~~~~~~~~~~~~//
295
296class afxXM_WaveInterp_Scalar_ColorRep : public afxXM_WaveInterp_Scalar
297{
298public:
299  afxXM_WaveInterp_Scalar_ColorRep() : afxXM_WaveInterp_Scalar() { }
300  virtual void interpolate(F32 t, afxXM_Params& params)
301  {
302    F32 scalar_at_t = lerp(t, mA, mB);
303    params.color.set(scalar_at_t, scalar_at_t, scalar_at_t, scalar_at_t);
304  }
305};
306
307//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
308
309class afxXM_WaveInterp_Scalar_OriMul : public afxXM_WaveInterp_Scalar
310{
311protected:
312  Point3F axis;
313public:
314  afxXM_WaveInterp_Scalar_OriMul(Point3F& ax) : afxXM_WaveInterp_Scalar() { axis = ax;  }
315  virtual void interpolate(F32 t, afxXM_Params& params)
316  {
317    F32 theta = mDegToRad(lerp(t, mA, mB));
318    AngAxisF rot_aa(axis, theta);
319    MatrixF rot_xfm; rot_aa.setMatrix(&rot_xfm);
320    params.ori.mul(rot_xfm);  
321  }
322};
323
324//~~~~~~~~~~~~~~~~~~~~//
325
326class afxXM_WaveInterp_Scalar_OriRep : public afxXM_WaveInterp_Scalar
327{
328protected:
329  Point3F axis;
330public:
331  afxXM_WaveInterp_Scalar_OriRep(Point3F& ax) : afxXM_WaveInterp_Scalar() { axis = ax;  }
332  virtual void interpolate(F32 t, afxXM_Params& params)
333  {
334    F32 theta = mDegToRad(lerp(t, mA, mB));
335    AngAxisF rot_aa(axis, theta);
336    rot_aa.setMatrix(&params.ori);
337  }
338};
339
340//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
341// WAVE SCALAR BASE DATABLOCK
342
343class afxXM_WaveScalarData_Common : public virtual afxXM_Defs
344{
345  static afxXM_WaveInterp_Scalar* alloc_interp(U32 param, S32 comp, U32 op, U32 off, 
346                                               Point3F& axis, bool loc_axis, afxXM_BaseData*);
347  static bool needs_offset(U32 param, S32 component);
348  static bool needs_axis(U32 param, S32 component);
349
350protected:
351  static afxXM_WaveInterp_Scalar* createInterp(U32 param, U32 op, Point3F axis, bool loc_axis,
352                                               afxXM_BaseData*);
353};
354
355//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
356
357bool afxXM_WaveScalarData_Common::needs_offset(U32 param, S32 component)
358{
359  switch (param)
360  {
361  case ORIENTATION:
362    return false;
363
364  case POSITION:
365  case POSITION2:
366  case SCALE:
367  case VISIBILITY:
368    return true;
369
370  case COLOR:
371    return (component != -1);
372  }
373
374  return false;
375}
376
377bool afxXM_WaveScalarData_Common::needs_axis(U32 param, S32 component)
378{
379  switch (param)
380  {
381  case ORIENTATION:
382    return true;
383
384  case POSITION:
385  case POSITION2:
386  case SCALE:
387  case COLOR:
388  case VISIBILITY:
389    return false;
390  }
391
392  return true;
393}
394
395afxXM_WaveInterp_Scalar* 
396afxXM_WaveScalarData_Common::alloc_interp(U32 param, S32 component, U32 op, U32 offset, Point3F& axis, bool loc_axis, afxXM_BaseData* db) 
397{ 
398  afxXM_WaveInterp_Scalar* interpolator = 0;
399
400  switch (param)
401  {
402  case ORIENTATION:
403    switch (op)
404    {
405    case afxXM_WaveBaseData::OP_ADD:
406      Con::errorf("%s::%s -- invalid orientation op.", db->getClassName(), db->getName());
407      return 0;
408    case afxXM_WaveBaseData::OP_MULTIPLY:
409      interpolator = new afxXM_WaveInterp_Scalar_OriMul(axis);
410      break;
411    case afxXM_WaveBaseData::OP_REPLACE:
412      interpolator = new afxXM_WaveInterp_Scalar_OriRep(axis);
413      break;
414    }
415    break;
416  case POSITION:
417  case POSITION2:
418  case SCALE:
419    if (component == -1)
420    {
421      if (axis.isZero())
422      {
423        switch (op)
424        {
425        case afxXM_WaveBaseData::OP_ADD:
426          interpolator = new afxXM_WaveInterp_Scalar_PointAdd(offset);
427          break;
428        case afxXM_WaveBaseData::OP_MULTIPLY:
429          interpolator = new afxXM_WaveInterp_Scalar_PointMul(offset);
430          break;
431        case afxXM_WaveBaseData::OP_REPLACE:
432          interpolator = new afxXM_WaveInterp_Scalar_PointRep(offset);
433          break;
434        }
435      }
436      else if (loc_axis)
437      {
438        switch (op)
439        {
440        case afxXM_WaveBaseData::OP_ADD:
441          interpolator = new afxXM_WaveInterp_Scalar_LocalAxis_PointAdd(offset, axis);
442          break;
443        case afxXM_WaveBaseData::OP_MULTIPLY:
444          interpolator = new afxXM_WaveInterp_Scalar_LocalAxis_PointMul(offset, axis);
445          break;
446        case afxXM_WaveBaseData::OP_REPLACE:
447          interpolator = new afxXM_WaveInterp_Scalar_LocalAxis_PointRep(offset, axis);
448          break;
449        }
450      }
451      else
452      {
453        switch (op)
454        {
455        case afxXM_WaveBaseData::OP_ADD:
456          interpolator = new afxXM_WaveInterp_Scalar_Axis_PointAdd(offset, axis);
457          break;
458        case afxXM_WaveBaseData::OP_MULTIPLY:
459          interpolator = new afxXM_WaveInterp_Scalar_Axis_PointMul(offset, axis);
460          break;
461        case afxXM_WaveBaseData::OP_REPLACE:
462          interpolator = new afxXM_WaveInterp_Scalar_Axis_PointRep(offset, axis);
463          break;
464        }
465      }
466    }
467    else
468    {
469      switch (op)
470      {
471      case afxXM_WaveBaseData::OP_ADD:
472        interpolator = new afxXM_WaveInterp_Scalar_Add(offset);
473        break;
474      case afxXM_WaveBaseData::OP_MULTIPLY:
475        interpolator = new afxXM_WaveInterp_Scalar_Mul(offset);
476        break;
477      case afxXM_WaveBaseData::OP_REPLACE:
478        interpolator = new afxXM_WaveInterp_Scalar_Rep(offset);
479        break;
480      }
481    }
482    break;  
483
484  case COLOR:
485    if (component == -1)
486    {
487      switch (op)
488      {
489      case afxXM_WaveBaseData::OP_ADD:
490        interpolator = new afxXM_WaveInterp_Scalar_ColorAdd();
491        break;
492      case afxXM_WaveBaseData::OP_MULTIPLY:
493        interpolator = new afxXM_WaveInterp_Scalar_ColorMul();
494        break;
495      case afxXM_WaveBaseData::OP_REPLACE:
496        interpolator = new afxXM_WaveInterp_Scalar_ColorRep();
497        break;
498      }
499    }
500    else
501    {
502      switch (op)
503      {
504      case afxXM_WaveBaseData::OP_ADD:
505        interpolator = new afxXM_WaveInterp_Scalar_Add(offset);
506        break;
507      case afxXM_WaveBaseData::OP_MULTIPLY:
508        interpolator = new afxXM_WaveInterp_Scalar_Mul(offset);
509        break;
510      case afxXM_WaveBaseData::OP_REPLACE:
511        interpolator = new afxXM_WaveInterp_Scalar_Rep(offset);
512        break;
513      }
514    }
515    break;  
516
517  case VISIBILITY:
518    switch (op)
519    {
520    case afxXM_WaveBaseData::OP_ADD:
521      interpolator = new afxXM_WaveInterp_Scalar_Add(offset);
522      break;
523    case afxXM_WaveBaseData::OP_MULTIPLY:
524      interpolator = new afxXM_WaveInterp_Scalar_Mul(offset);
525      break;
526    case afxXM_WaveBaseData::OP_REPLACE:
527      interpolator = new afxXM_WaveInterp_Scalar_Rep(offset);
528      break;
529    }
530  }
531
532  if (!interpolator)
533    Con::errorf("%s::%s -- failed to allocate wave interpolator.", db->getClassName(), db->getName());
534
535  return interpolator; 
536}
537
538afxXM_WaveInterp_Scalar* 
539afxXM_WaveScalarData_Common::createInterp(U32 parameter, U32 op, Point3F axis, bool loc_axis, afxXM_BaseData* db) 
540{
541  S32 component; U32 param_bit;
542  afxXM_WaveBaseData::initParamInfo(parameter, param_bit, component);
543
544  if (param_bit == 0)
545  {
546    Con::errorf("%s::%s -- unknown parameter specified.", db->getClassName(), db->getName());
547    return 0;
548  }
549
550  if (axis.isZero() && needs_axis(param_bit, component))
551  {
552    Con::errorf("%s::%s -- axis required.", db->getClassName(), db->getName());
553    return 0;
554  }
555
556  if (!axis.isZero())
557    axis.normalize();
558
559  U32 offset = afxXM_Params::BAD_OFFSET;
560  if (needs_offset(param_bit, component))
561  {
562    offset = afxXM_Params::getParameterOffset(param_bit, component);
563    if (offset == afxXM_Params::BAD_OFFSET)
564    {
565      Con::errorf("%s::%s -- bad component offset.", db->getClassName(), db->getName());
566      return 0;
567    }
568  }
569
570  return alloc_interp(param_bit, component, op, offset, axis, loc_axis, db);
571}
572
573
574//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
575// WAVE SCALAR DATABLOCK
576
577class afxXM_WaveScalarData : public afxXM_WaveBaseData, afxXM_WaveScalarData_Common
578{
579  typedef afxXM_WaveBaseData Parent;
580
581public:
582  F32           a, b;
583  F32           a_var, b_var;
584  bool          sync_var;
585
586public:
587  /*C*/         afxXM_WaveScalarData();
588  /*C*/         afxXM_WaveScalarData(const afxXM_WaveScalarData&, bool = false);
589
590  void          packData(BitStream* stream);
591  void          unpackData(BitStream* stream);
592
593  virtual bool  allowSubstitutions() const { return true; }
594
595  static void   initPersistFields();
596
597  afxXM_Base*   create(afxEffectWrapper* fx, bool on_server);
598
599  DECLARE_CONOBJECT(afxXM_WaveScalarData);
600  DECLARE_CATEGORY("AFX");
601};
602
603//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
604
605IMPLEMENT_CO_DATABLOCK_V1(afxXM_WaveScalarData);
606
607ConsoleDocClass( afxXM_WaveScalarData,
608   "@brief An xmod datablock.\n\n"
609
610   "@ingroup afxXMods\n"
611   "@ingroup AFX\n"
612   "@ingroup Datablocks\n"
613);
614
615afxXM_WaveScalarData::afxXM_WaveScalarData()
616{
617  a = 0.0f;
618  b = 1.0f;
619  a_var = 0.0f;
620  b_var = 0.0f;
621  sync_var = false;
622}
623
624afxXM_WaveScalarData::afxXM_WaveScalarData(const afxXM_WaveScalarData& other, bool temp_clone) : afxXM_WaveBaseData(other, temp_clone)
625{
626  a = other.a;
627  b = other.b;
628  a_var = other.a_var;
629  b_var = other.b_var;
630  sync_var = other.sync_var;
631}
632
633void afxXM_WaveScalarData::initPersistFields()
634{
635  addField("a",               TypeF32,      Offset(a, afxXM_WaveScalarData),
636    "...");
637  addField("b",               TypeF32,      Offset(b, afxXM_WaveScalarData),
638    "...");
639  addField("aVariance",       TypeF32,      Offset(a_var, afxXM_WaveScalarData),
640    "...");
641  addField("bVariance",       TypeF32,      Offset(b_var, afxXM_WaveScalarData),
642    "...");
643  addField("syncVariances",   TypeBool,     Offset(sync_var, afxXM_WaveScalarData),
644    "...");
645
646  Parent::initPersistFields();
647}
648
649void afxXM_WaveScalarData::packData(BitStream* stream)
650{
651  Parent::packData(stream);
652  stream->write(a);
653  stream->write(b);
654  if (stream->writeFlag(a_var != 0.0f || b_var != 0.0f))
655  {
656    stream->write(a_var);
657    stream->write(b_var);
658    stream->writeFlag(sync_var);
659  }
660}
661
662void afxXM_WaveScalarData::unpackData(BitStream* stream)
663{
664  Parent::unpackData(stream);
665  stream->read(&a);
666  stream->read(&b);
667  if (stream->readFlag())
668  {
669    stream->read(&a_var);
670    stream->read(&b_var);
671    sync_var = stream->readFlag();
672  }
673  else
674  {
675    a_var = b_var = 0.0f;
676    sync_var = false;
677  }
678}
679
680afxXM_Base* afxXM_WaveScalarData::create(afxEffectWrapper* fx, bool on_server)
681{
682  afxXM_WaveScalarData* dblock = this;
683
684  if (getSubstitutionCount() > 0)
685  {
686    dblock = new afxXM_WaveScalarData(*this, true);
687    this->performSubstitutions(dblock, fx->getChoreographer(), fx->getGroupIndex());
688  }
689
690  afxXM_WaveInterp_Scalar* interp;
691  interp = createInterp(dblock->parameter, dblock->op, dblock->axis, dblock->local_axis, dblock);
692  if (!interp)
693    return 0;
694
695  interp->set(dblock->a, dblock->b, dblock->a_var, dblock->b_var, dblock->sync_var);
696
697  return new afxXM_WaveBase(dblock, fx, interp);
698}
699
700//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
701// WAVE RIDER SCALAR DATABLOCK
702
703class afxXM_WaveRiderScalarData : public afxXM_WaveRiderBaseData, afxXM_WaveScalarData_Common
704{
705  typedef afxXM_WaveRiderBaseData Parent;
706
707public:
708  F32           a, b;
709  F32           a_var, b_var;
710  bool          sync_var;
711
712public:
713  /*C*/         afxXM_WaveRiderScalarData();
714  /*C*/         afxXM_WaveRiderScalarData(const afxXM_WaveRiderScalarData&, bool = false);
715
716  void          packData(BitStream* stream);
717  void          unpackData(BitStream* stream);
718
719  virtual bool  allowSubstitutions() const { return true; }
720
721  static void   initPersistFields();
722
723  afxXM_Base*   create(afxEffectWrapper* fx, bool on_server);
724
725  DECLARE_CONOBJECT(afxXM_WaveRiderScalarData);
726  DECLARE_CATEGORY("AFX");
727};
728
729//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
730
731IMPLEMENT_CO_DATABLOCK_V1(afxXM_WaveRiderScalarData);
732
733ConsoleDocClass( afxXM_WaveRiderScalarData,
734   "@brief An xmod datablock.\n\n"
735
736   "@ingroup afxXMods\n"
737   "@ingroup AFX\n"
738   "@ingroup Datablocks\n"
739);
740
741afxXM_WaveRiderScalarData::afxXM_WaveRiderScalarData()
742{
743  a = 0.0f;
744  b = 1.0f;
745  a_var = 0.0f;
746  b_var = 0.0f;
747  sync_var = false;
748}
749
750afxXM_WaveRiderScalarData::afxXM_WaveRiderScalarData(const afxXM_WaveRiderScalarData& other, bool temp_clone) : afxXM_WaveRiderBaseData(other, temp_clone)
751{
752  a = other.a;
753  b = other.b;
754  a_var = other.a_var;
755  b_var = other.b_var;
756  sync_var = other.sync_var;
757}
758
759void afxXM_WaveRiderScalarData::initPersistFields()
760{
761  addField("a",               TypeF32,      Offset(a, afxXM_WaveRiderScalarData),
762    "...");
763  addField("b",               TypeF32,      Offset(b, afxXM_WaveRiderScalarData),
764    "...");
765  addField("aVariance",       TypeF32,      Offset(a_var, afxXM_WaveRiderScalarData),
766    "...");
767  addField("bVariance",       TypeF32,      Offset(b_var, afxXM_WaveRiderScalarData),
768    "...");
769  addField("syncVariances",   TypeBool,     Offset(sync_var, afxXM_WaveRiderScalarData),
770    "...");
771
772  Parent::initPersistFields();
773}
774
775void afxXM_WaveRiderScalarData::packData(BitStream* stream)
776{
777  Parent::packData(stream);
778  stream->write(a);
779  stream->write(b);
780  if (stream->writeFlag(a_var != 0.0f || b_var != 0.0f))
781  {
782    stream->write(a_var);
783    stream->write(b_var);
784    stream->writeFlag(sync_var);
785  }
786}
787
788void afxXM_WaveRiderScalarData::unpackData(BitStream* stream)
789{
790  Parent::unpackData(stream);
791  stream->read(&a);
792  stream->read(&b);
793  if (stream->readFlag())
794  {
795    stream->read(&a_var);
796    stream->read(&b_var);
797    sync_var = stream->readFlag();
798  }
799  else
800  {
801    a_var = b_var = 0.0f;
802    sync_var = false;
803  }
804}
805
806afxXM_Base* afxXM_WaveRiderScalarData::create(afxEffectWrapper* fx, bool on_server)
807{
808  afxXM_WaveRiderScalarData* dblock = this;
809
810  if (getSubstitutionCount() > 0)
811  {
812    dblock = new afxXM_WaveRiderScalarData(*this, true);
813    this->performSubstitutions(dblock, fx->getChoreographer(), fx->getGroupIndex());
814  }
815
816  afxXM_WaveInterp_Scalar* interp;
817  interp = createInterp(dblock->parameter, dblock->op, dblock->axis, dblock->local_axis, dblock);
818  if (!interp)
819    return 0;
820
821  interp->set(dblock->a, dblock->b, dblock->a_var, dblock->b_var, dblock->sync_var);
822
823  return new afxXM_WaveRiderBase(dblock, fx, interp);
824}
825
826//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
827