afxXM_WaveBase.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  2. // Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  3. // Copyright (C) 2015 Faust Logic, Inc.
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to
  7. // deal in the Software without restriction, including without limitation the
  8. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9. // sell copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. // IN THE SOFTWARE.
  22. //
  23. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  24. #include "afx/arcaneFX.h"
  25. #include "math/mathIO.h"
  26. #include "afx/afxEffectWrapper.h"
  27. #include "afx/afxChoreographer.h"
  28. #include "afx/xm/afxXM_WaveBase.h"
  29. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  30. IMPLEMENT_CO_DATABLOCK_V1(afxXM_WaveBaseData);
  31. ConsoleDocClass( afxXM_WaveBaseData,
  32. "@brief An xmod datablock.\n\n"
  33. "@ingroup afxXMods\n"
  34. "@ingroup AFX\n"
  35. "@ingroup Datablocks\n"
  36. );
  37. afxXM_WaveBaseData::afxXM_WaveBaseData()
  38. {
  39. waveform_type = WAVEFORM_SINE;
  40. parameter = PARAM_NONE;
  41. op = OP_ADD;
  42. speed = 1.0f;
  43. speed_vari = 0.0;
  44. accel = 0.0f;
  45. phase_shift = 0.0f;
  46. duty_cycle = 1.0f;
  47. duty_shift = 0.0f;
  48. off_duty_t = 0.0f;
  49. waves_per_pulse.set(1,1);
  50. waves_per_rest.set(0,0);
  51. rest_dur = 0.0f;
  52. rest_dur_vari = 0.0f;
  53. axis.zero();
  54. local_axis = true;
  55. }
  56. afxXM_WaveBaseData::afxXM_WaveBaseData(const afxXM_WaveBaseData& other, bool temp_clone) : afxXM_WeightedBaseData(other, temp_clone)
  57. {
  58. waveform_type = other.waveform_type;
  59. parameter = other.parameter;
  60. op = other.op;
  61. speed = other.speed;
  62. speed_vari = other.speed;
  63. accel = other.accel;
  64. phase_shift = other.phase_shift;
  65. duty_cycle = other.duty_cycle;
  66. duty_shift = other.duty_shift;
  67. off_duty_t = other.off_duty_t;
  68. waves_per_pulse = other.waves_per_pulse;
  69. waves_per_rest = other.waves_per_rest;
  70. rest_dur = other.rest_dur;
  71. rest_dur_vari = other.rest_dur_vari;
  72. axis = other.axis;
  73. local_axis = true;
  74. }
  75. ImplementEnumType( afxXM_WaveFormType, "Possible waveform types.\n" "@ingroup afxXM_WaveBase\n\n" )
  76. { afxXM_WaveBaseData::WAVEFORM_NONE, "none", "..." },
  77. { afxXM_WaveBaseData::WAVEFORM_SINE, "sine", "..." },
  78. { afxXM_WaveBaseData::WAVEFORM_SQUARE, "square", "..." },
  79. { afxXM_WaveBaseData::WAVEFORM_TRIANGLE, "triangle", "..." },
  80. { afxXM_WaveBaseData::WAVEFORM_SAWTOOTH, "sawtooth", "..." },
  81. { afxXM_WaveBaseData::WAVEFORM_NOISE, "noise", "..." },
  82. { afxXM_WaveBaseData::WAVEFORM_ONE, "one", "..." },
  83. EndImplementEnumType;
  84. ImplementEnumType( afxXM_WaveParamType, "Possible wave parameter types.\n" "@ingroup afxXM_WaveBase\n\n" )
  85. { afxXM_WaveBaseData::PARAM_NONE, "none", "..." },
  86. { afxXM_WaveBaseData::PARAM_POS, "pos", "..." },
  87. { afxXM_WaveBaseData::PARAM_POS_X, "pos.x", "..." },
  88. { afxXM_WaveBaseData::PARAM_POS_Y, "pos.y", "..." },
  89. { afxXM_WaveBaseData::PARAM_POS_Z, "pos.z", "..." },
  90. { afxXM_WaveBaseData::PARAM_ORI, "ori", "..." },
  91. { afxXM_WaveBaseData::PARAM_POS2, "pos2", "..." },
  92. { afxXM_WaveBaseData::PARAM_POS2_X, "pos2.x", "..." },
  93. { afxXM_WaveBaseData::PARAM_POS2_Y, "pos2.y", "..." },
  94. { afxXM_WaveBaseData::PARAM_POS2_Z, "pos2.z", "..." },
  95. { afxXM_WaveBaseData::PARAM_SCALE, "scale", "..." },
  96. { afxXM_WaveBaseData::PARAM_SCALE_X, "scale.x", "..." },
  97. { afxXM_WaveBaseData::PARAM_SCALE_Y, "scale.y", "..." },
  98. { afxXM_WaveBaseData::PARAM_SCALE_Z, "scale.z", "..." },
  99. { afxXM_WaveBaseData::PARAM_COLOR, "color", "..." },
  100. { afxXM_WaveBaseData::PARAM_COLOR_R, "color.red", "..." },
  101. { afxXM_WaveBaseData::PARAM_COLOR_G, "color.green", "..." },
  102. { afxXM_WaveBaseData::PARAM_COLOR_B, "color.blue", "..." },
  103. { afxXM_WaveBaseData::PARAM_COLOR_A, "color.alpha", "..." },
  104. { afxXM_WaveBaseData::PARAM_VIS, "vis", "..." },
  105. { afxXM_WaveBaseData::PARAM_POS, "position", "..." },
  106. { afxXM_WaveBaseData::PARAM_POS_X, "position.x", "..." },
  107. { afxXM_WaveBaseData::PARAM_POS_Y, "position.y", "..." },
  108. { afxXM_WaveBaseData::PARAM_POS_Z, "position.z", "..." },
  109. { afxXM_WaveBaseData::PARAM_ORI, "orientation", "..." },
  110. { afxXM_WaveBaseData::PARAM_POS2, "position2", "..." },
  111. { afxXM_WaveBaseData::PARAM_POS2_X, "position2.x", "..." },
  112. { afxXM_WaveBaseData::PARAM_POS2_Y, "position2.y", "..." },
  113. { afxXM_WaveBaseData::PARAM_POS2_Z, "position2.z", "..." },
  114. { afxXM_WaveBaseData::PARAM_COLOR_R, "color.r", "..." },
  115. { afxXM_WaveBaseData::PARAM_COLOR_G, "color.g", "..." },
  116. { afxXM_WaveBaseData::PARAM_COLOR_B, "color.b", "..." },
  117. { afxXM_WaveBaseData::PARAM_COLOR_A, "color.a", "..." },
  118. { afxXM_WaveBaseData::PARAM_VIS, "visibility", "..." },
  119. EndImplementEnumType;
  120. ImplementEnumType( afxXM_WaveOpType, "Possible wave operation types.\n" "@ingroup afxXM_WaveBase\n\n" )
  121. { afxXM_WaveBaseData::OP_ADD, "add", "..." },
  122. { afxXM_WaveBaseData::OP_MULTIPLY, "multiply", "..." },
  123. { afxXM_WaveBaseData::OP_REPLACE, "replace", "..." },
  124. { afxXM_WaveBaseData::OP_MULTIPLY, "mult", "..." },
  125. EndImplementEnumType;
  126. void afxXM_WaveBaseData::initPersistFields()
  127. {
  128. addField("waveform", TYPEID< afxXM_WaveBaseData::WaveFormType >(), Offset(waveform_type, afxXM_WaveBaseData),
  129. "...");
  130. addField("parameter", TYPEID< afxXM_WaveBaseData::WaveParamType >(), Offset(parameter, afxXM_WaveBaseData),
  131. "...");
  132. addField("op", TYPEID< afxXM_WaveBaseData::WaveOpType >(), Offset(op, afxXM_WaveBaseData),
  133. "...");
  134. addField("speed", TypeF32, Offset(speed, afxXM_WaveBaseData),
  135. "waves per second");
  136. addField("speedVariance", TypeF32, Offset(speed_vari, afxXM_WaveBaseData),
  137. "...");
  138. addField("acceleration", TypeF32, Offset(accel, afxXM_WaveBaseData),
  139. "...");
  140. addField("phaseShift", TypeF32, Offset(phase_shift, afxXM_WaveBaseData),
  141. "...");
  142. addField("dutyCycle", TypeF32, Offset(duty_cycle, afxXM_WaveBaseData),
  143. "...");
  144. addField("dutyShift", TypeF32, Offset(duty_shift, afxXM_WaveBaseData),
  145. "...");
  146. addField("offDutyT", TypeF32, Offset(off_duty_t, afxXM_WaveBaseData),
  147. "...");
  148. addField("wavesPerPulse", TypeByteRange2, Offset(waves_per_pulse, afxXM_WaveBaseData),
  149. "...");
  150. addField("wavesPerRest", TypeByteRange2, Offset(waves_per_rest, afxXM_WaveBaseData),
  151. "...");
  152. addField("restDuration", TypeF32, Offset(rest_dur, afxXM_WaveBaseData),
  153. "...");
  154. addField("restDurationVariance", TypeF32, Offset(rest_dur_vari, afxXM_WaveBaseData),
  155. "...");
  156. addField("axis", TypePoint3F, Offset(axis, afxXM_WaveBaseData),
  157. "...");
  158. addField("axisIsLocal", TypeBool, Offset(local_axis, afxXM_WaveBaseData),
  159. "...");
  160. Parent::initPersistFields();
  161. }
  162. void afxXM_WaveBaseData::packData(BitStream* stream)
  163. {
  164. Parent::packData(stream);
  165. stream->writeInt(waveform_type, WAVEFORM_BITS);
  166. stream->writeInt(parameter, PARAM_BITS);
  167. stream->writeInt(op, OP_BITS);
  168. stream->write(speed);
  169. stream->write(speed_vari);
  170. stream->write(accel);
  171. stream->write(phase_shift);
  172. stream->write(duty_cycle);
  173. stream->write(duty_shift);
  174. stream->write(off_duty_t);
  175. stream->write(waves_per_pulse.low);
  176. stream->write(waves_per_pulse.high);
  177. stream->write(waves_per_rest.low);
  178. stream->write(waves_per_rest.high);
  179. stream->write(rest_dur);
  180. stream->write(rest_dur_vari);
  181. mathWrite(*stream, axis);
  182. stream->writeFlag(local_axis);
  183. }
  184. void afxXM_WaveBaseData::unpackData(BitStream* stream)
  185. {
  186. Parent::unpackData(stream);
  187. waveform_type = stream->readInt(WAVEFORM_BITS);
  188. parameter = stream->readInt(PARAM_BITS);
  189. op = stream->readInt(OP_BITS);
  190. stream->read(&speed);
  191. stream->read(&speed_vari);
  192. stream->read(&accel);
  193. stream->read(&phase_shift);
  194. stream->read(&duty_cycle);
  195. stream->read(&duty_shift);
  196. stream->read(&off_duty_t);
  197. stream->read(&waves_per_pulse.low);
  198. stream->read(&waves_per_pulse.high);
  199. stream->read(&waves_per_rest.low);
  200. stream->read(&waves_per_rest.high);
  201. stream->read(&rest_dur);
  202. stream->read(&rest_dur_vari);
  203. mathRead(*stream, &axis);
  204. local_axis = stream->readFlag();
  205. }
  206. void afxXM_WaveBaseData::initParamInfo(U32 parameter, U32& parambit, S32& component)
  207. {
  208. switch (parameter)
  209. {
  210. case PARAM_POS:
  211. parambit = POSITION;
  212. component = -1;
  213. break;
  214. case PARAM_POS_X:
  215. parambit = POSITION;
  216. component = 0;
  217. break;
  218. case PARAM_POS_Y:
  219. parambit = POSITION;
  220. component = 1;
  221. break;
  222. case PARAM_POS_Z:
  223. parambit = POSITION;
  224. component = 2;
  225. break;
  226. case PARAM_ORI:
  227. parambit = ORIENTATION;
  228. component = -1;
  229. break;
  230. case PARAM_POS2:
  231. parambit = POSITION2;
  232. component = -1;
  233. break;
  234. case PARAM_POS2_X:
  235. parambit = POSITION2;
  236. component = 0;
  237. break;
  238. case PARAM_POS2_Y:
  239. parambit = POSITION2;
  240. component = 1;
  241. break;
  242. case PARAM_POS2_Z:
  243. parambit = POSITION2;
  244. component = 2;
  245. break;
  246. case PARAM_SCALE:
  247. parambit = SCALE;
  248. component = -1;
  249. break;
  250. case PARAM_SCALE_X:
  251. parambit = SCALE;
  252. component = 0;
  253. break;
  254. case PARAM_SCALE_Y:
  255. parambit = SCALE;
  256. component = 1;
  257. break;
  258. case PARAM_SCALE_Z:
  259. parambit = SCALE;
  260. component = 2;
  261. break;
  262. case PARAM_COLOR:
  263. parambit = COLOR;
  264. component = -1;
  265. break;
  266. case PARAM_COLOR_R:
  267. parambit = COLOR;
  268. component = 0;
  269. break;
  270. case PARAM_COLOR_G:
  271. parambit = COLOR;
  272. component = 1;
  273. break;
  274. case PARAM_COLOR_B:
  275. parambit = COLOR;
  276. component = 2;
  277. break;
  278. case PARAM_COLOR_A:
  279. parambit = COLOR;
  280. component = 3;
  281. break;
  282. case PARAM_VIS:
  283. parambit = VISIBILITY;
  284. component = -1;
  285. break;
  286. default:
  287. parambit = 0;
  288. component = -1;
  289. break;
  290. }
  291. }
  292. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  293. IMPLEMENT_CO_DATABLOCK_V1(afxXM_WaveRiderBaseData);
  294. ConsoleDocClass( afxXM_WaveRiderBaseData,
  295. "@brief An xmod datablock.\n\n"
  296. "@ingroup afxXMods\n"
  297. "@ingroup AFX\n"
  298. "@ingroup Datablocks\n"
  299. );
  300. afxXM_WaveRiderBaseData::afxXM_WaveRiderBaseData()
  301. {
  302. waveform_type = afxXM_WaveBaseData::WAVEFORM_NONE;
  303. parameter = afxXM_WaveBaseData::PARAM_NONE;
  304. op = afxXM_WaveBaseData::OP_ADD;
  305. off_duty_t = 0.0f;
  306. axis.zero();
  307. local_axis = true;
  308. }
  309. afxXM_WaveRiderBaseData::afxXM_WaveRiderBaseData(const afxXM_WaveRiderBaseData& other, bool temp_clone) : afxXM_WeightedBaseData(other, temp_clone)
  310. {
  311. waveform_type = other.waveform_type;
  312. parameter = other.parameter;
  313. op = other.op;
  314. off_duty_t = other.off_duty_t;
  315. axis = other.axis;
  316. local_axis = true;
  317. }
  318. void afxXM_WaveRiderBaseData::initPersistFields()
  319. {
  320. addField("waveform", TYPEID< afxXM_WaveBaseData::WaveFormType >(), Offset(waveform_type, afxXM_WaveRiderBaseData),
  321. "...");
  322. addField("parameter", TYPEID< afxXM_WaveBaseData::WaveParamType >(), Offset(parameter, afxXM_WaveRiderBaseData),
  323. "...");
  324. addField("op", TYPEID< afxXM_WaveBaseData::WaveOpType >(), Offset(op, afxXM_WaveRiderBaseData),
  325. "...");
  326. addField("offDutyT", TypeF32, Offset(off_duty_t, afxXM_WaveRiderBaseData),
  327. "...");
  328. addField("axis", TypePoint3F, Offset(axis, afxXM_WaveRiderBaseData),
  329. "...");
  330. addField("axisIsLocal", TypeBool, Offset(local_axis, afxXM_WaveRiderBaseData),
  331. "...");
  332. Parent::initPersistFields();
  333. }
  334. void afxXM_WaveRiderBaseData::packData(BitStream* stream)
  335. {
  336. Parent::packData(stream);
  337. stream->writeInt(waveform_type, afxXM_WaveBaseData::WAVEFORM_BITS);
  338. stream->writeInt(parameter, afxXM_WaveBaseData::PARAM_BITS);
  339. stream->writeInt(op, afxXM_WaveBaseData::OP_BITS);
  340. stream->write(off_duty_t);
  341. mathWrite(*stream, axis);
  342. stream->writeFlag(local_axis);
  343. }
  344. void afxXM_WaveRiderBaseData::unpackData(BitStream* stream)
  345. {
  346. Parent::unpackData(stream);
  347. waveform_type = stream->readInt(afxXM_WaveBaseData::WAVEFORM_BITS);
  348. parameter = stream->readInt(afxXM_WaveBaseData::PARAM_BITS);
  349. op = stream->readInt(afxXM_WaveBaseData::OP_BITS);
  350. stream->read(&off_duty_t);
  351. mathRead(*stream, &axis);
  352. local_axis = stream->readFlag();
  353. }
  354. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
  355. // WAVEFORMS
  356. F32 afxXM_WaveformSine::evaluate(F32 t)
  357. {
  358. t = (0.75f + t)*Float_2Pi;
  359. return 0.5f*(1.0f + mSin(t));
  360. }
  361. F32 afxXM_WaveformSquare::evaluate(F32 t)
  362. {
  363. return (t < 0.25f || t >= 0.75) ? 0.0f : 1.0f;
  364. }
  365. F32 afxXM_WaveformTriangle::evaluate(F32 t)
  366. {
  367. return (t < 0.5f) ? 2.0f*t : 2.0f*(1.0f - t);
  368. }
  369. //~~~~~~~~~~~~~~~~~~~~//
  370. afxXM_Waveform* afxXM_WaveBaseData::getWaveform(U32 waveform_type)
  371. {
  372. static afxXM_WaveformSine sine;
  373. static afxXM_WaveformSquare square;
  374. static afxXM_WaveformTriangle triangle;
  375. static afxXM_WaveformSawtooth sawtooth;
  376. static afxXM_WaveformNoise noise;
  377. static afxXM_WaveformOne one;
  378. switch (waveform_type)
  379. {
  380. case WAVEFORM_SINE:
  381. return &sine;
  382. case WAVEFORM_SQUARE:
  383. return &square;
  384. case WAVEFORM_TRIANGLE:
  385. return &triangle;
  386. case WAVEFORM_SAWTOOTH:
  387. return &sawtooth;
  388. case WAVEFORM_NOISE:
  389. return &noise;
  390. case WAVEFORM_ONE:
  391. return &one;
  392. default:
  393. // error condition
  394. return &sine;
  395. }
  396. }
  397. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  398. bool afxXM_WaveBase::last_was_pulsed = false;
  399. bool afxXM_WaveBase::last_was_off_duty = true;
  400. F32 afxXM_WaveBase::last_t = 0.0f;
  401. F32 afxXM_WaveBase::last_wave_t = 0.0f;
  402. afxXM_WaveBase::afxXM_WaveBase(afxXM_WaveBaseData* db, afxEffectWrapper* fxw, afxXM_WaveInterp* interp)
  403. : afxXM_WeightedBase(db, fxw)
  404. {
  405. this->db = db;
  406. interpolator = interp;
  407. waveform = afxXM_WaveBaseData::getWaveform(db->waveform_type);
  408. speed_is_randomized = !mIsZero(db->speed_vari);
  409. speed = calc_initial_speed();
  410. fixed_weight = db->hasFixedWeight();
  411. is_resting = false;
  412. cur_pulse_time = db->delay;
  413. next_pulse_time = cur_pulse_time + ((F32)calc_new_wavesPerPulse())/speed;
  414. interpolator->pulse();
  415. last_was_pulsed = false;
  416. last_was_off_duty = true;
  417. last_t = 0.0f;
  418. last_wave_t = 0.0f;
  419. }
  420. afxXM_WaveBase::~afxXM_WaveBase()
  421. {
  422. delete interpolator;
  423. }
  424. void afxXM_WaveBase::updateParams(F32 dt, F32 elapsed, afxXM_Params& params)
  425. {
  426. elapsed -= db->delay;
  427. if (elapsed > next_pulse_time)
  428. {
  429. is_resting = !is_resting;
  430. cur_pulse_time = next_pulse_time;
  431. if (is_resting)
  432. {
  433. F32 rest_dt = ((F32)(calc_new_wavesPerRest())/speed) + calc_new_restDur();
  434. if (rest_dt < 0.01)
  435. is_resting = false;
  436. else
  437. next_pulse_time = cur_pulse_time + rest_dt;
  438. }
  439. if (!is_resting)
  440. {
  441. speed = calc_new_speed();
  442. next_pulse_time = cur_pulse_time + ((F32)calc_new_wavesPerPulse())/speed;
  443. interpolator->pulse();
  444. last_was_pulsed = true;
  445. }
  446. }
  447. if (is_resting)
  448. {
  449. last_was_off_duty = true;
  450. interpolator->interpolate(db->off_duty_t, params);
  451. return;
  452. }
  453. F32 n_waves = db->phase_shift + (elapsed - cur_pulse_time)*speed;
  454. F32 wave_t = (n_waves - mFloor(n_waves))/db->duty_cycle;
  455. // we are beyond the duty portion of the wave, use off_duty_t
  456. if (wave_t > 1.0f)
  457. {
  458. last_was_off_duty = true;
  459. interpolator->interpolate(db->off_duty_t, params);
  460. return;
  461. }
  462. if (db->duty_shift > 0.0f)
  463. {
  464. wave_t += db->duty_shift;
  465. if (wave_t > 1.0)
  466. wave_t -= 1.0f;
  467. }
  468. last_was_off_duty = false;
  469. last_wave_t = wave_t;
  470. last_t = waveform->evaluate(wave_t);
  471. if (fixed_weight)
  472. {
  473. interpolator->interpolate(last_t, params);
  474. }
  475. else
  476. {
  477. F32 wt_factor = calc_weight_factor(elapsed);
  478. F32 final_t = afxXM_WaveInterp::lerp(wt_factor, db->off_duty_t, last_t);
  479. interpolator->interpolate(final_t, params);
  480. }
  481. }
  482. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  483. afxXM_WaveRiderBase::afxXM_WaveRiderBase(afxXM_WaveRiderBaseData* db, afxEffectWrapper* fxw, afxXM_WaveInterp* interp)
  484. : afxXM_WeightedBase(db, fxw)
  485. {
  486. this->db = db;
  487. interpolator = interp;
  488. waveform = afxXM_WaveBaseData::getWaveform(db->waveform_type);
  489. fixed_weight = db->hasFixedWeight();
  490. interpolator->pulse();
  491. }
  492. afxXM_WaveRiderBase::~afxXM_WaveRiderBase()
  493. {
  494. delete interpolator;
  495. }
  496. void afxXM_WaveRiderBase::updateParams(F32 dt, F32 elapsed, afxXM_Params& params)
  497. {
  498. if (afxXM_WaveBase::last_was_pulsed)
  499. interpolator->pulse();
  500. if (afxXM_WaveBase::last_was_off_duty)
  501. {
  502. interpolator->interpolate(db->off_duty_t, params);
  503. return;
  504. }
  505. F32 t;
  506. if (db->waveform_type != afxXM_WaveBaseData::WAVEFORM_NONE)
  507. t = waveform->evaluate(afxXM_WaveBase::last_wave_t);
  508. else
  509. t = afxXM_WaveBase::last_t;
  510. if (fixed_weight)
  511. interpolator->interpolate(t, params);
  512. else
  513. {
  514. F32 wt_factor = calc_weight_factor(elapsed);
  515. F32 final_t = afxXM_WaveInterp::lerp(wt_factor, db->off_duty_t, t);
  516. interpolator->interpolate(final_t, params);
  517. }
  518. }
  519. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//