Torque3D Documentation / _generateds / afxXM_WaveColor.cpp

afxXM_WaveColor.cpp

Engine/source/afx/xm/afxXM_WaveColor.cpp

More...

Classes:

Public Functions

ConsoleDocClass(afxXM_WaveColorData , "@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_WaveRiderColorData , "@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_WaveColorData , "@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_WaveRiderColorData , "@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_WaveColorData )

IMPLEMENT_CO_DATABLOCK_V1(afxXM_WaveRiderColorData )

  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 COLOR INTERPOLATORS
 35
 36class afxXM_WaveInterp_Color : public afxXM_WaveInterp
 37{
 38protected:
 39  LinearColorF   mA_set, mB_set;
 40  LinearColorF   mA_var, mB_var;
 41  LinearColorF   mA, mB;
 42  bool     mSync_var;
 43
 44public:
 45  afxXM_WaveInterp_Color(); 
 46
 47  void set(LinearColorF& a, LinearColorF& b, LinearColorF& a_var, LinearColorF& b_var, bool sync_var);
 48
 49  virtual void interpolate(F32 t, afxXM_Params& params)=0;
 50  virtual void pulse();
 51};
 52
 53afxXM_WaveInterp_Color::afxXM_WaveInterp_Color() 
 54{ 
 55  mA_set.set(0.0f, 0.0f, 0.0f, 0.0f); 
 56  mB_set.set(1.0f, 1.0f, 1.0f, 1.0f); 
 57  mA_var.set(0.0f, 0.0f, 0.0f, 0.0f); 
 58  mB_var.set(0.0f, 0.0f, 0.0f, 0.0f); 
 59  mSync_var = false;
 60  mA.set(0.0f, 0.0f, 0.0f, 0.0f);
 61  mB.set(1.0f, 1.0f, 1.0f, 1.0f);
 62}
 63
 64void afxXM_WaveInterp_Color::set(LinearColorF& a, LinearColorF& b, LinearColorF& a_var, LinearColorF& 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  mB = b;
 73}
 74
 75inline void afxXM_WaveInterp_Color::pulse()
 76{
 77  LinearColorF temp_color;
 78  F32 rand_t = gRandGen.randF()*2.0f;
 79  temp_color.interpolate(-mA_var, mA_var, rand_t);
 80  mA = mA_set + temp_color;
 81  if (!mSync_var) 
 82    rand_t = gRandGen.randF()*2.0f;
 83  temp_color.interpolate(-mB_var, mB_var, rand_t);
 84  mB = mB_set + temp_color;
 85}
 86
 87//~~~~~~~~~~~~~~~~~~~~//
 88
 89class afxXM_WaveInterp_Color_Add : public afxXM_WaveInterp_Color
 90{
 91public:
 92  virtual void interpolate(F32 t, afxXM_Params& params)
 93  {
 94    LinearColorF temp_color;
 95    temp_color.interpolate(mA, mB, t);
 96    params.color += temp_color;
 97  }
 98};
 99
100//~~~~~~~~~~~~~~~~~~~~//
101
102class afxXM_WaveInterp_Color_Mul : public afxXM_WaveInterp_Color
103{
104public:
105  virtual void interpolate(F32 t, afxXM_Params& params)
106  {
107    LinearColorF temp_color;
108    temp_color.interpolate(mA, mB, t);
109    params.color *= temp_color;
110  }
111};
112
113//~~~~~~~~~~~~~~~~~~~~//
114
115class afxXM_WaveInterp_Color_Rep : public afxXM_WaveInterp_Color
116{
117public:
118  virtual void interpolate(F32 t, afxXM_Params& params)
119  {
120    params.color.interpolate(mA, mB, t);
121  }
122};
123
124//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
125// WAVE SCALAR BASE DATABLOCK
126
127class afxXM_WaveColorData_Common : public virtual afxXM_Defs
128{
129protected:
130  static afxXM_WaveInterp_Color* createInterp(U32 op, afxXM_BaseData*);
131};
132
133//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
134
135afxXM_WaveInterp_Color* 
136afxXM_WaveColorData_Common::createInterp(U32 op, afxXM_BaseData* db) 
137{
138  afxXM_WaveInterp_Color* interpolator = 0;
139
140  switch (op)
141  {
142  case afxXM_WaveBaseData::OP_ADD:
143    interpolator = new afxXM_WaveInterp_Color_Add();
144    return 0;
145  case afxXM_WaveBaseData::OP_MULTIPLY:
146    interpolator = new afxXM_WaveInterp_Color_Mul();
147    break;
148  case afxXM_WaveBaseData::OP_REPLACE:
149    interpolator = new afxXM_WaveInterp_Color_Rep();
150    break;
151  }
152
153  if (!interpolator)
154    Con::errorf("%s::%s -- failed to allocate wave color interpolator.", db->getClassName(), db->getName());
155
156  return interpolator; 
157}
158
159//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
160// WAVE COLOR DATABLOCK
161
162class afxXM_WaveColorData : public afxXM_WaveBaseData, afxXM_WaveColorData_Common
163{
164  typedef afxXM_WaveBaseData Parent;
165
166public:
167  LinearColorF        a, b;
168  LinearColorF        a_var, b_var;
169  bool          sync_var;
170
171public:
172  /*C*/         afxXM_WaveColorData();
173  /*C*/         afxXM_WaveColorData(const afxXM_WaveColorData&, bool = false);
174
175  void          packData(BitStream* stream);
176  void          unpackData(BitStream* stream);
177
178  virtual bool  allowSubstitutions() const { return true; }
179
180  static void   initPersistFields();
181
182  afxXM_Base*   create(afxEffectWrapper* fx, bool on_server);
183
184  DECLARE_CONOBJECT(afxXM_WaveColorData);
185  DECLARE_CATEGORY("AFX");
186};
187
188//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
189
190IMPLEMENT_CO_DATABLOCK_V1(afxXM_WaveColorData);
191
192ConsoleDocClass( afxXM_WaveColorData,
193   "@brief An xmod datablock.\n\n"
194
195   "@ingroup afxXMods\n"
196   "@ingroup AFX\n"
197   "@ingroup Datablocks\n"
198);
199
200afxXM_WaveColorData::afxXM_WaveColorData()
201{
202  a.set(0.0f, 0.0f, 0.0f, 0.0f);
203  b.set(1.0f, 1.0f, 1.0f, 1.0f);
204  a_var.set(0.0f, 0.0f, 0.0f, 0.0f);
205  b_var.set(0.0f, 0.0f, 0.0f, 0.0f);
206  sync_var = false;
207}
208
209afxXM_WaveColorData::afxXM_WaveColorData(const afxXM_WaveColorData& other, bool temp_clone) : afxXM_WaveBaseData(other, temp_clone)
210{
211  a = other.a;
212  b = other.b;
213  a_var = other.a_var;
214  b_var = other.b_var;
215  sync_var = other.sync_var;
216}
217
218void afxXM_WaveColorData::initPersistFields()
219{
220  addField("a",               TypeColorF,      Offset(a, afxXM_WaveColorData),
221    "...");
222  addField("b",               TypeColorF,      Offset(b, afxXM_WaveColorData),
223    "...");
224  addField("aVariance",       TypeColorF,      Offset(a_var, afxXM_WaveColorData),
225    "...");
226  addField("bVariance",       TypeColorF,      Offset(b_var, afxXM_WaveColorData),
227    "...");
228  addField("syncVariances",   TypeBool,        Offset(sync_var, afxXM_WaveColorData),
229    "...");
230
231  Parent::initPersistFields();
232}
233
234void afxXM_WaveColorData::packData(BitStream* stream)
235{
236  Parent::packData(stream);
237  stream->write(a);
238  stream->write(b);
239  stream->write(a_var);
240  stream->write(b_var);
241  stream->writeFlag(sync_var);
242}
243
244void afxXM_WaveColorData::unpackData(BitStream* stream)
245{
246  Parent::unpackData(stream);
247  stream->read(&a);
248  stream->read(&b);
249  stream->read(&a_var);
250  stream->read(&b_var);
251  sync_var = stream->readFlag();
252}
253
254afxXM_Base* afxXM_WaveColorData::create(afxEffectWrapper* fx, bool on_server)
255{
256  afxXM_WaveColorData* dblock = this;
257
258  if (getSubstitutionCount() > 0)
259  {
260    dblock = new afxXM_WaveColorData(*this, true);
261    this->performSubstitutions(dblock, fx->getChoreographer(), fx->getGroupIndex());
262  }
263
264  afxXM_WaveInterp_Color* interp;
265  interp = createInterp(dblock->op, dblock);
266  if (!interp)
267    return 0;
268
269  interp->set(dblock->a, dblock->b, dblock->a_var, dblock->b_var, dblock->sync_var);
270
271  return new afxXM_WaveBase(dblock, fx, interp);
272}
273
274//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
275// WAVE RIDER COLOR DATABLOCK
276
277class afxXM_WaveRiderColorData : public afxXM_WaveRiderBaseData, afxXM_WaveColorData_Common
278{
279  typedef afxXM_WaveRiderBaseData Parent;
280
281public:
282  LinearColorF        a, b;
283  LinearColorF        a_var, b_var;
284  bool          sync_var;
285
286public:
287  /*C*/         afxXM_WaveRiderColorData();
288  /*C*/         afxXM_WaveRiderColorData(const afxXM_WaveRiderColorData&, bool = false);
289
290  void          packData(BitStream* stream);
291  void          unpackData(BitStream* stream);
292
293  virtual bool  allowSubstitutions() const { return true; }
294
295  static void   initPersistFields();
296
297  afxXM_Base*   create(afxEffectWrapper* fx, bool on_server);
298
299  DECLARE_CONOBJECT(afxXM_WaveRiderColorData);
300  DECLARE_CATEGORY("AFX");
301};
302
303//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
304
305IMPLEMENT_CO_DATABLOCK_V1(afxXM_WaveRiderColorData);
306
307ConsoleDocClass( afxXM_WaveRiderColorData,
308   "@brief An xmod datablock.\n\n"
309
310   "@ingroup afxXMods\n"
311   "@ingroup AFX\n"
312   "@ingroup Datablocks\n"
313);
314
315afxXM_WaveRiderColorData::afxXM_WaveRiderColorData()
316{
317  a.set(0.0f, 0.0f, 0.0f, 0.0f);
318  b.set(1.0f, 1.0f, 1.0f, 1.0f);
319  a_var.set(0.0f, 0.0f, 0.0f, 0.0f);
320  b_var.set(0.0f, 0.0f, 0.0f, 0.0f);
321  sync_var = false;
322}
323
324afxXM_WaveRiderColorData::afxXM_WaveRiderColorData(const afxXM_WaveRiderColorData& other, bool temp_clone) : afxXM_WaveRiderBaseData(other, temp_clone)
325{
326  a = other.a;
327  b = other.b;
328  a_var = other.a_var;
329  b_var = other.b_var;
330  sync_var = other.sync_var;
331}
332
333void afxXM_WaveRiderColorData::initPersistFields()
334{
335  addField("a",               TypeColorF,      Offset(a, afxXM_WaveRiderColorData),
336    "...");
337  addField("b",               TypeColorF,      Offset(b, afxXM_WaveRiderColorData),
338    "...");
339  addField("aVariance",       TypeColorF,      Offset(a_var, afxXM_WaveRiderColorData),
340    "...");
341  addField("bVariance",       TypeColorF,      Offset(b_var, afxXM_WaveRiderColorData),
342    "...");
343  addField("syncVariances",   TypeBool,        Offset(sync_var, afxXM_WaveRiderColorData),
344    "...");
345
346  Parent::initPersistFields();
347}
348
349void afxXM_WaveRiderColorData::packData(BitStream* stream)
350{
351  Parent::packData(stream);
352  stream->write(a);
353  stream->write(b);
354  stream->write(a_var);
355  stream->write(b_var);
356  stream->writeFlag(sync_var);
357}
358
359void afxXM_WaveRiderColorData::unpackData(BitStream* stream)
360{
361  Parent::unpackData(stream);
362  stream->read(&a);
363  stream->read(&b);
364  stream->read(&a_var);
365  stream->read(&b_var);
366  sync_var = stream->readFlag();
367}
368
369afxXM_Base* afxXM_WaveRiderColorData::create(afxEffectWrapper* fx, bool on_server)
370{
371  afxXM_WaveRiderColorData* dblock = this;
372
373  if (getSubstitutionCount() > 0)
374  {
375    dblock = new afxXM_WaveRiderColorData(*this, true);
376    this->performSubstitutions(dblock, fx->getChoreographer(), fx->getGroupIndex());
377  }
378
379  afxXM_WaveInterp_Color* interp;
380  interp = createInterp(dblock->op, dblock);
381  if (!interp)
382    return 0;
383
384  interp->set(dblock->a, dblock->b, dblock->a_var, dblock->b_var, dblock->sync_var);
385
386  return new afxXM_WaveRiderBase(dblock, fx, interp);
387}
388
389//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
390