afxXM_WaveBase.cpp
Engine/source/afx/xm/afxXM_WaveBase.cpp
Public Variables
Public Functions
ConsoleDocClass(afxXM_WaveBaseData , "@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_WaveRiderBaseData , "@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>" )
ImplementEnumType(afxXM_WaveFormType , "Possible waveform <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">types.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxXM_WaveBase\n\n</a>" )
ImplementEnumType(afxXM_WaveOpType , "Possible wave operation <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">types.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxXM_WaveBase\n\n</a>" )
ImplementEnumType(afxXM_WaveParamType , "Possible wave parameter <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">types.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxXM_WaveBase\n\n</a>" )
Detailed Description
Public Variables
EndImplementEnumType
Public Functions
ConsoleDocClass(afxXM_WaveBaseData , "@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_WaveRiderBaseData , "@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_WaveBaseData )
IMPLEMENT_CO_DATABLOCK_V1(afxXM_WaveRiderBaseData )
ImplementEnumType(afxXM_WaveFormType , "Possible waveform <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">types.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxXM_WaveBase\n\n</a>" )
ImplementEnumType(afxXM_WaveOpType , "Possible wave operation <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">types.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxXM_WaveBase\n\n</a>" )
ImplementEnumType(afxXM_WaveParamType , "Possible wave parameter <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">types.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxXM_WaveBase\n\n</a>" )
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 "math/mathIO.h" 30 31#include "afx/afxEffectWrapper.h" 32#include "afx/afxChoreographer.h" 33#include "afx/xm/afxXM_WaveBase.h" 34 35//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 36 37IMPLEMENT_CO_DATABLOCK_V1(afxXM_WaveBaseData); 38 39ConsoleDocClass( afxXM_WaveBaseData, 40 "@brief An xmod datablock.\n\n" 41 42 "@ingroup afxXMods\n" 43 "@ingroup AFX\n" 44 "@ingroup Datablocks\n" 45); 46 47afxXM_WaveBaseData::afxXM_WaveBaseData() 48{ 49 waveform_type = WAVEFORM_SINE; 50 parameter = PARAM_NONE; 51 op = OP_ADD; 52 speed = 1.0f; 53 speed_vari = 0.0; 54 accel = 0.0f; 55 phase_shift = 0.0f; 56 duty_cycle = 1.0f; 57 duty_shift = 0.0f; 58 off_duty_t = 0.0f; 59 60 waves_per_pulse.set(1,1); 61 waves_per_rest.set(0,0); 62 rest_dur = 0.0f; 63 rest_dur_vari = 0.0f; 64 65 axis.zero(); 66 local_axis = true; 67} 68 69afxXM_WaveBaseData::afxXM_WaveBaseData(const afxXM_WaveBaseData& other, bool temp_clone) : afxXM_WeightedBaseData(other, temp_clone) 70{ 71 waveform_type = other.waveform_type; 72 parameter = other.parameter; 73 op = other.op; 74 speed = other.speed; 75 speed_vari = other.speed; 76 accel = other.accel; 77 phase_shift = other.phase_shift; 78 duty_cycle = other.duty_cycle; 79 duty_shift = other.duty_shift; 80 off_duty_t = other.off_duty_t; 81 82 waves_per_pulse = other.waves_per_pulse; 83 waves_per_rest = other.waves_per_rest; 84 rest_dur = other.rest_dur; 85 rest_dur_vari = other.rest_dur_vari; 86 87 axis = other.axis; 88 local_axis = true; 89} 90 91ImplementEnumType( afxXM_WaveFormType, "Possible waveform types.\n" "@ingroup afxXM_WaveBase\n\n" ) 92 { afxXM_WaveBaseData::WAVEFORM_NONE, "none", "..." }, 93 { afxXM_WaveBaseData::WAVEFORM_SINE, "sine", "..." }, 94 { afxXM_WaveBaseData::WAVEFORM_SQUARE, "square", "..." }, 95 { afxXM_WaveBaseData::WAVEFORM_TRIANGLE, "triangle", "..." }, 96 { afxXM_WaveBaseData::WAVEFORM_SAWTOOTH, "sawtooth", "..." }, 97 { afxXM_WaveBaseData::WAVEFORM_NOISE, "noise", "..." }, 98 { afxXM_WaveBaseData::WAVEFORM_ONE, "one", "..." }, 99EndImplementEnumType; 100 101ImplementEnumType( afxXM_WaveParamType, "Possible wave parameter types.\n" "@ingroup afxXM_WaveBase\n\n" ) 102 { afxXM_WaveBaseData::PARAM_NONE, "none", "..." }, 103 { afxXM_WaveBaseData::PARAM_POS, "pos", "..." }, 104 { afxXM_WaveBaseData::PARAM_POS_X, "pos.x", "..." }, 105 { afxXM_WaveBaseData::PARAM_POS_Y, "pos.y", "..." }, 106 { afxXM_WaveBaseData::PARAM_POS_Z, "pos.z", "..." }, 107 { afxXM_WaveBaseData::PARAM_ORI, "ori", "..." }, 108 { afxXM_WaveBaseData::PARAM_POS2, "pos2", "..." }, 109 { afxXM_WaveBaseData::PARAM_POS2_X, "pos2.x", "..." }, 110 { afxXM_WaveBaseData::PARAM_POS2_Y, "pos2.y", "..." }, 111 { afxXM_WaveBaseData::PARAM_POS2_Z, "pos2.z", "..." }, 112 { afxXM_WaveBaseData::PARAM_SCALE, "scale", "..." }, 113 { afxXM_WaveBaseData::PARAM_SCALE_X, "scale.x", "..." }, 114 { afxXM_WaveBaseData::PARAM_SCALE_Y, "scale.y", "..." }, 115 { afxXM_WaveBaseData::PARAM_SCALE_Z, "scale.z", "..." }, 116 { afxXM_WaveBaseData::PARAM_COLOR, "color", "..." }, 117 { afxXM_WaveBaseData::PARAM_COLOR_R, "color.red", "..." }, 118 { afxXM_WaveBaseData::PARAM_COLOR_G, "color.green", "..." }, 119 { afxXM_WaveBaseData::PARAM_COLOR_B, "color.blue", "..." }, 120 { afxXM_WaveBaseData::PARAM_COLOR_A, "color.alpha", "..." }, 121 { afxXM_WaveBaseData::PARAM_VIS, "vis", "..." }, 122 { afxXM_WaveBaseData::PARAM_POS, "position", "..." }, 123 { afxXM_WaveBaseData::PARAM_POS_X, "position.x", "..." }, 124 { afxXM_WaveBaseData::PARAM_POS_Y, "position.y", "..." }, 125 { afxXM_WaveBaseData::PARAM_POS_Z, "position.z", "..." }, 126 { afxXM_WaveBaseData::PARAM_ORI, "orientation", "..." }, 127 { afxXM_WaveBaseData::PARAM_POS2, "position2", "..." }, 128 { afxXM_WaveBaseData::PARAM_POS2_X, "position2.x", "..." }, 129 { afxXM_WaveBaseData::PARAM_POS2_Y, "position2.y", "..." }, 130 { afxXM_WaveBaseData::PARAM_POS2_Z, "position2.z", "..." }, 131 { afxXM_WaveBaseData::PARAM_COLOR_R, "color.r", "..." }, 132 { afxXM_WaveBaseData::PARAM_COLOR_G, "color.g", "..." }, 133 { afxXM_WaveBaseData::PARAM_COLOR_B, "color.b", "..." }, 134 { afxXM_WaveBaseData::PARAM_COLOR_A, "color.a", "..." }, 135 { afxXM_WaveBaseData::PARAM_VIS, "visibility", "..." }, 136EndImplementEnumType; 137 138ImplementEnumType( afxXM_WaveOpType, "Possible wave operation types.\n" "@ingroup afxXM_WaveBase\n\n" ) 139 { afxXM_WaveBaseData::OP_ADD, "add", "..." }, 140 { afxXM_WaveBaseData::OP_MULTIPLY, "multiply", "..." }, 141 { afxXM_WaveBaseData::OP_REPLACE, "replace", "..." }, 142 { afxXM_WaveBaseData::OP_MULTIPLY, "mult", "..." }, 143EndImplementEnumType; 144 145void afxXM_WaveBaseData::initPersistFields() 146{ 147 addField("waveform", TYPEID< afxXM_WaveBaseData::WaveFormType >(), Offset(waveform_type, afxXM_WaveBaseData), 148 "..."); 149 addField("parameter", TYPEID< afxXM_WaveBaseData::WaveParamType >(), Offset(parameter, afxXM_WaveBaseData), 150 "..."); 151 addField("op", TYPEID< afxXM_WaveBaseData::WaveOpType >(), Offset(op, afxXM_WaveBaseData), 152 "..."); 153 154 addField("speed", TypeF32, Offset(speed, afxXM_WaveBaseData), 155 "waves per second"); 156 addField("speedVariance", TypeF32, Offset(speed_vari, afxXM_WaveBaseData), 157 "..."); 158 addField("acceleration", TypeF32, Offset(accel, afxXM_WaveBaseData), 159 "..."); 160 addField("phaseShift", TypeF32, Offset(phase_shift, afxXM_WaveBaseData), 161 "..."); 162 addField("dutyCycle", TypeF32, Offset(duty_cycle, afxXM_WaveBaseData), 163 "..."); 164 addField("dutyShift", TypeF32, Offset(duty_shift, afxXM_WaveBaseData), 165 "..."); 166 addField("offDutyT", TypeF32, Offset(off_duty_t, afxXM_WaveBaseData), 167 "..."); 168 169 addField("wavesPerPulse", TypeByteRange2, Offset(waves_per_pulse, afxXM_WaveBaseData), 170 "..."); 171 addField("wavesPerRest", TypeByteRange2, Offset(waves_per_rest, afxXM_WaveBaseData), 172 "..."); 173 addField("restDuration", TypeF32, Offset(rest_dur, afxXM_WaveBaseData), 174 "..."); 175 addField("restDurationVariance", TypeF32, Offset(rest_dur_vari, afxXM_WaveBaseData), 176 "..."); 177 178 addField("axis", TypePoint3F, Offset(axis, afxXM_WaveBaseData), 179 "..."); 180 addField("axisIsLocal", TypeBool, Offset(local_axis, afxXM_WaveBaseData), 181 "..."); 182 183 Parent::initPersistFields(); 184} 185 186void afxXM_WaveBaseData::packData(BitStream* stream) 187{ 188 Parent::packData(stream); 189 190 stream->writeInt(waveform_type, WAVEFORM_BITS); 191 stream->writeInt(parameter, PARAM_BITS); 192 stream->writeInt(op, OP_BITS); 193 stream->write(speed); 194 stream->write(speed_vari); 195 stream->write(accel); 196 stream->write(phase_shift); 197 stream->write(duty_cycle); 198 stream->write(duty_shift); 199 stream->write(off_duty_t); 200 201 stream->write(waves_per_pulse.low); 202 stream->write(waves_per_pulse.high); 203 stream->write(waves_per_rest.low); 204 stream->write(waves_per_rest.high); 205 206 stream->write(rest_dur); 207 stream->write(rest_dur_vari); 208 209 mathWrite(*stream, axis); 210 stream->writeFlag(local_axis); 211} 212 213void afxXM_WaveBaseData::unpackData(BitStream* stream) 214{ 215 Parent::unpackData(stream); 216 217 waveform_type = stream->readInt(WAVEFORM_BITS); 218 parameter = stream->readInt(PARAM_BITS); 219 op = stream->readInt(OP_BITS); 220 stream->read(&speed); 221 stream->read(&speed_vari); 222 stream->read(&accel); 223 stream->read(&phase_shift); 224 stream->read(&duty_cycle); 225 stream->read(&duty_shift); 226 stream->read(&off_duty_t); 227 228 stream->read(&waves_per_pulse.low); 229 stream->read(&waves_per_pulse.high); 230 stream->read(&waves_per_rest.low); 231 stream->read(&waves_per_rest.high); 232 233 stream->read(&rest_dur); 234 stream->read(&rest_dur_vari); 235 236 mathRead(*stream, &axis); 237 local_axis = stream->readFlag(); 238} 239 240void afxXM_WaveBaseData::initParamInfo(U32 parameter, U32& parambit, S32& component) 241{ 242 switch (parameter) 243 { 244 case PARAM_POS: 245 parambit = POSITION; 246 component = -1; 247 break; 248 case PARAM_POS_X: 249 parambit = POSITION; 250 component = 0; 251 break; 252 case PARAM_POS_Y: 253 parambit = POSITION; 254 component = 1; 255 break; 256 case PARAM_POS_Z: 257 parambit = POSITION; 258 component = 2; 259 break; 260 261 case PARAM_ORI: 262 parambit = ORIENTATION; 263 component = -1; 264 break; 265 266 case PARAM_POS2: 267 parambit = POSITION2; 268 component = -1; 269 break; 270 case PARAM_POS2_X: 271 parambit = POSITION2; 272 component = 0; 273 break; 274 case PARAM_POS2_Y: 275 parambit = POSITION2; 276 component = 1; 277 break; 278 case PARAM_POS2_Z: 279 parambit = POSITION2; 280 component = 2; 281 break; 282 283 case PARAM_SCALE: 284 parambit = SCALE; 285 component = -1; 286 break; 287 case PARAM_SCALE_X: 288 parambit = SCALE; 289 component = 0; 290 break; 291 case PARAM_SCALE_Y: 292 parambit = SCALE; 293 component = 1; 294 break; 295 case PARAM_SCALE_Z: 296 parambit = SCALE; 297 component = 2; 298 break; 299 300 case PARAM_COLOR: 301 parambit = COLOR; 302 component = -1; 303 break; 304 case PARAM_COLOR_R: 305 parambit = COLOR; 306 component = 0; 307 break; 308 case PARAM_COLOR_G: 309 parambit = COLOR; 310 component = 1; 311 break; 312 case PARAM_COLOR_B: 313 parambit = COLOR; 314 component = 2; 315 break; 316 case PARAM_COLOR_A: 317 parambit = COLOR; 318 component = 3; 319 break; 320 321 case PARAM_VIS: 322 parambit = VISIBILITY; 323 component = -1; 324 break; 325 326 default: 327 parambit = 0; 328 component = -1; 329 break; 330 } 331} 332 333//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 334 335IMPLEMENT_CO_DATABLOCK_V1(afxXM_WaveRiderBaseData); 336 337ConsoleDocClass( afxXM_WaveRiderBaseData, 338 "@brief An xmod datablock.\n\n" 339 340 "@ingroup afxXMods\n" 341 "@ingroup AFX\n" 342 "@ingroup Datablocks\n" 343); 344 345afxXM_WaveRiderBaseData::afxXM_WaveRiderBaseData() 346{ 347 waveform_type = afxXM_WaveBaseData::WAVEFORM_NONE; 348 parameter = afxXM_WaveBaseData::PARAM_NONE; 349 op = afxXM_WaveBaseData::OP_ADD; 350 off_duty_t = 0.0f; 351 352 axis.zero(); 353 local_axis = true; 354} 355 356afxXM_WaveRiderBaseData::afxXM_WaveRiderBaseData(const afxXM_WaveRiderBaseData& other, bool temp_clone) : afxXM_WeightedBaseData(other, temp_clone) 357{ 358 waveform_type = other.waveform_type; 359 parameter = other.parameter; 360 op = other.op; 361 off_duty_t = other.off_duty_t; 362 363 axis = other.axis; 364 local_axis = true; 365} 366 367void afxXM_WaveRiderBaseData::initPersistFields() 368{ 369 addField("waveform", TYPEID< afxXM_WaveBaseData::WaveFormType >(), Offset(waveform_type, afxXM_WaveRiderBaseData), 370 "..."); 371 addField("parameter", TYPEID< afxXM_WaveBaseData::WaveParamType >(), Offset(parameter, afxXM_WaveRiderBaseData), 372 "..."); 373 addField("op", TYPEID< afxXM_WaveBaseData::WaveOpType >(), Offset(op, afxXM_WaveRiderBaseData), 374 "..."); 375 376 addField("offDutyT", TypeF32, Offset(off_duty_t, afxXM_WaveRiderBaseData), 377 "..."); 378 379 addField("axis", TypePoint3F, Offset(axis, afxXM_WaveRiderBaseData), 380 "..."); 381 addField("axisIsLocal", TypeBool, Offset(local_axis, afxXM_WaveRiderBaseData), 382 "..."); 383 384 Parent::initPersistFields(); 385} 386 387void afxXM_WaveRiderBaseData::packData(BitStream* stream) 388{ 389 Parent::packData(stream); 390 391 stream->writeInt(waveform_type, afxXM_WaveBaseData::WAVEFORM_BITS); 392 stream->writeInt(parameter, afxXM_WaveBaseData::PARAM_BITS); 393 stream->writeInt(op, afxXM_WaveBaseData::OP_BITS); 394 stream->write(off_duty_t); 395 396 mathWrite(*stream, axis); 397 stream->writeFlag(local_axis); 398} 399 400void afxXM_WaveRiderBaseData::unpackData(BitStream* stream) 401{ 402 Parent::unpackData(stream); 403 404 waveform_type = stream->readInt(afxXM_WaveBaseData::WAVEFORM_BITS); 405 parameter = stream->readInt(afxXM_WaveBaseData::PARAM_BITS); 406 op = stream->readInt(afxXM_WaveBaseData::OP_BITS); 407 stream->read(&off_duty_t); 408 409 mathRead(*stream, &axis); 410 local_axis = stream->readFlag(); 411} 412 413//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~// 414// WAVEFORMS 415 416F32 afxXM_WaveformSine::evaluate(F32 t) 417{ 418 t = (0.75f + t)*Float_2Pi; 419 return 0.5f*(1.0f + mSin(t)); 420} 421 422F32 afxXM_WaveformSquare::evaluate(F32 t) 423{ 424 return (t < 0.25f || t >= 0.75) ? 0.0f : 1.0f; 425} 426 427F32 afxXM_WaveformTriangle::evaluate(F32 t) 428{ 429 return (t < 0.5f) ? 2.0f*t : 2.0f*(1.0f - t); 430} 431 432//~~~~~~~~~~~~~~~~~~~~// 433 434afxXM_Waveform* afxXM_WaveBaseData::getWaveform(U32 waveform_type) 435{ 436 static afxXM_WaveformSine sine; 437 static afxXM_WaveformSquare square; 438 static afxXM_WaveformTriangle triangle; 439 static afxXM_WaveformSawtooth sawtooth; 440 static afxXM_WaveformNoise noise; 441 static afxXM_WaveformOne one; 442 443 switch (waveform_type) 444 { 445 case WAVEFORM_SINE: 446 return &sine; 447 case WAVEFORM_SQUARE: 448 return □ 449 case WAVEFORM_TRIANGLE: 450 return ▵ 451 case WAVEFORM_SAWTOOTH: 452 return &sawtooth; 453 case WAVEFORM_NOISE: 454 return &noise; 455 case WAVEFORM_ONE: 456 return &one; 457 default: 458 // error condition 459 return &sine; 460 } 461} 462 463//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 464 465bool afxXM_WaveBase::last_was_pulsed = false; 466bool afxXM_WaveBase::last_was_off_duty = true; 467F32 afxXM_WaveBase::last_t = 0.0f; 468F32 afxXM_WaveBase::last_wave_t = 0.0f; 469 470afxXM_WaveBase::afxXM_WaveBase(afxXM_WaveBaseData* db, afxEffectWrapper* fxw, afxXM_WaveInterp* interp) 471 : afxXM_WeightedBase(db, fxw) 472{ 473 this->db = db; 474 interpolator = interp; 475 waveform = afxXM_WaveBaseData::getWaveform(db->waveform_type); 476 477 speed_is_randomized = !mIsZero(db->speed_vari); 478 speed = calc_initial_speed(); 479 480 fixed_weight = db->hasFixedWeight(); 481 482 is_resting = false; 483 cur_pulse_time = db->delay; 484 next_pulse_time = cur_pulse_time + ((F32)calc_new_wavesPerPulse())/<a href="/coding/class/classafxxm__wavebase/#classafxxm__wavebase_1a6cd2458eea62c1a64339c61a15462379">speed</a>; 485 interpolator->pulse(); 486 487 last_was_pulsed = false; 488 last_was_off_duty = true; 489 last_t = 0.0f; 490 last_wave_t = 0.0f; 491} 492 493afxXM_WaveBase::~afxXM_WaveBase() 494{ 495 delete interpolator; 496} 497 498void afxXM_WaveBase::updateParams(F32 dt, F32 elapsed, afxXM_Params& params) 499{ 500 elapsed -= db->delay; 501 502 if (elapsed > next_pulse_time) 503 { 504 is_resting = !is_resting; 505 cur_pulse_time = next_pulse_time; 506 507 if (is_resting) 508 { 509 F32 rest_dt = ((F32)(calc_new_wavesPerRest())/<a href="/coding/class/classafxxm__wavebase/#classafxxm__wavebase_1a6cd2458eea62c1a64339c61a15462379">speed</a>) + calc_new_restDur(); 510 if (rest_dt < 0.01) 511 is_resting = false; 512 else 513 next_pulse_time = cur_pulse_time + rest_dt; 514 } 515 516 if (!is_resting) 517 { 518 speed = calc_new_speed(); 519 next_pulse_time = cur_pulse_time + ((F32)calc_new_wavesPerPulse())/<a href="/coding/class/classafxxm__wavebase/#classafxxm__wavebase_1a6cd2458eea62c1a64339c61a15462379">speed</a>; 520 interpolator->pulse(); 521 last_was_pulsed = true; 522 } 523 } 524 525 if (is_resting) 526 { 527 last_was_off_duty = true; 528 interpolator->interpolate(db->off_duty_t, params); 529 return; 530 } 531 532 F32 n_waves = db->phase_shift + (elapsed - cur_pulse_time)*speed; 533 F32 wave_t = (n_waves - mFloor(n_waves))/<a href="/coding/class/classafxxm__wavebase/#classafxxm__wavebase_1a18e83343401fb891fe17587851b5025e">db</a>->duty_cycle; 534 535 // we are beyond the duty portion of the wave, use off_duty_t 536 if (wave_t > 1.0f) 537 { 538 last_was_off_duty = true; 539 interpolator->interpolate(db->off_duty_t, params); 540 return; 541 } 542 543 if (db->duty_shift > 0.0f) 544 { 545 wave_t += db->duty_shift; 546 if (wave_t > 1.0) 547 wave_t -= 1.0f; 548 } 549 550 last_was_off_duty = false; 551 last_wave_t = wave_t; 552 553 last_t = waveform->evaluate(wave_t); 554 555 if (fixed_weight) 556 { 557 interpolator->interpolate(last_t, params); 558 } 559 else 560 { 561 F32 wt_factor = calc_weight_factor(elapsed); 562 F32 final_t = afxXM_WaveInterp::lerp(wt_factor, db->off_duty_t, last_t); 563 interpolator->interpolate(final_t, params); 564 } 565} 566 567//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 568 569afxXM_WaveRiderBase::afxXM_WaveRiderBase(afxXM_WaveRiderBaseData* db, afxEffectWrapper* fxw, afxXM_WaveInterp* interp) 570 : afxXM_WeightedBase(db, fxw) 571{ 572 this->db = db; 573 interpolator = interp; 574 waveform = afxXM_WaveBaseData::getWaveform(db->waveform_type); 575 fixed_weight = db->hasFixedWeight(); 576 interpolator->pulse(); 577} 578 579afxXM_WaveRiderBase::~afxXM_WaveRiderBase() 580{ 581 delete interpolator; 582} 583 584void afxXM_WaveRiderBase::updateParams(F32 dt, F32 elapsed, afxXM_Params& params) 585{ 586 if (afxXM_WaveBase::last_was_pulsed) 587 interpolator->pulse(); 588 589 if (afxXM_WaveBase::last_was_off_duty) 590 { 591 interpolator->interpolate(db->off_duty_t, params); 592 return; 593 } 594 595 F32 t; 596 if (db->waveform_type != afxXM_WaveBaseData::WAVEFORM_NONE) 597 t = waveform->evaluate(afxXM_WaveBase::last_wave_t); 598 else 599 t = afxXM_WaveBase::last_t; 600 601 if (fixed_weight) 602 interpolator->interpolate(t, params); 603 else 604 { 605 F32 wt_factor = calc_weight_factor(elapsed); 606 F32 final_t = afxXM_WaveInterp::lerp(wt_factor, db->off_duty_t, t); 607 interpolator->interpolate(final_t, params); 608 } 609} 610 611//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 612