afxXM_WaveBase.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  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. docsURL;
  129. addField("waveform", TYPEID< afxXM_WaveBaseData::WaveFormType >(), Offset(waveform_type, afxXM_WaveBaseData),
  130. "...");
  131. addField("parameter", TYPEID< afxXM_WaveBaseData::WaveParamType >(), Offset(parameter, afxXM_WaveBaseData),
  132. "...");
  133. addField("op", TYPEID< afxXM_WaveBaseData::WaveOpType >(), Offset(op, afxXM_WaveBaseData),
  134. "...");
  135. addFieldV("speed", TypeRangedF32, Offset(speed, afxXM_WaveBaseData), &CommonValidators::PositiveFloat,
  136. "waves per second");
  137. addFieldV("speedVariance", TypeRangedF32, Offset(speed_vari, afxXM_WaveBaseData), &CommonValidators::PositiveFloat,
  138. "...");
  139. addFieldV("acceleration", TypeRangedF32, Offset(accel, afxXM_WaveBaseData), &CommonValidators::PositiveFloat,
  140. "...");
  141. addFieldV("phaseShift", TypeRangedF32, Offset(phase_shift, afxXM_WaveBaseData), &CommonValidators::PositiveFloat,
  142. "...");
  143. addFieldV("dutyCycle", TypeRangedF32, Offset(duty_cycle, afxXM_WaveBaseData), &CommonValidators::PositiveFloat,
  144. "...");
  145. addFieldV("dutyShift", TypeRangedF32, Offset(duty_shift, afxXM_WaveBaseData), &CommonValidators::PositiveFloat,
  146. "...");
  147. addFieldV("offDutyT", TypeRangedF32, Offset(off_duty_t, afxXM_WaveBaseData), &CommonValidators::PositiveFloat,
  148. "...");
  149. addField("wavesPerPulse", TypeByteRange2, Offset(waves_per_pulse, afxXM_WaveBaseData),
  150. "...");
  151. addField("wavesPerRest", TypeByteRange2, Offset(waves_per_rest, afxXM_WaveBaseData),
  152. "...");
  153. addFieldV("restDuration", TypeRangedF32, Offset(rest_dur, afxXM_WaveBaseData), &CommonValidators::PositiveFloat,
  154. "...");
  155. addFieldV("restDurationVariance", TypeRangedF32, Offset(rest_dur_vari, afxXM_WaveBaseData), &CommonValidators::PositiveFloat,
  156. "...");
  157. addField("axis", TypePoint3F, Offset(axis, afxXM_WaveBaseData),
  158. "...");
  159. addField("axisIsLocal", TypeBool, Offset(local_axis, afxXM_WaveBaseData),
  160. "...");
  161. Parent::initPersistFields();
  162. }
  163. void afxXM_WaveBaseData::packData(BitStream* stream)
  164. {
  165. Parent::packData(stream);
  166. stream->writeInt(waveform_type, WAVEFORM_BITS);
  167. stream->writeInt(parameter, PARAM_BITS);
  168. stream->writeInt(op, OP_BITS);
  169. stream->write(speed);
  170. stream->write(speed_vari);
  171. stream->write(accel);
  172. stream->write(phase_shift);
  173. stream->write(duty_cycle);
  174. stream->write(duty_shift);
  175. stream->write(off_duty_t);
  176. stream->write(waves_per_pulse.low);
  177. stream->write(waves_per_pulse.high);
  178. stream->write(waves_per_rest.low);
  179. stream->write(waves_per_rest.high);
  180. stream->write(rest_dur);
  181. stream->write(rest_dur_vari);
  182. mathWrite(*stream, axis);
  183. stream->writeFlag(local_axis);
  184. }
  185. void afxXM_WaveBaseData::unpackData(BitStream* stream)
  186. {
  187. Parent::unpackData(stream);
  188. waveform_type = stream->readInt(WAVEFORM_BITS);
  189. parameter = stream->readInt(PARAM_BITS);
  190. op = stream->readInt(OP_BITS);
  191. stream->read(&speed);
  192. stream->read(&speed_vari);
  193. stream->read(&accel);
  194. stream->read(&phase_shift);
  195. stream->read(&duty_cycle);
  196. stream->read(&duty_shift);
  197. stream->read(&off_duty_t);
  198. stream->read(&waves_per_pulse.low);
  199. stream->read(&waves_per_pulse.high);
  200. stream->read(&waves_per_rest.low);
  201. stream->read(&waves_per_rest.high);
  202. stream->read(&rest_dur);
  203. stream->read(&rest_dur_vari);
  204. mathRead(*stream, &axis);
  205. local_axis = stream->readFlag();
  206. }
  207. void afxXM_WaveBaseData::initParamInfo(U32 parameter, U32& parambit, S32& component)
  208. {
  209. switch (parameter)
  210. {
  211. case PARAM_POS:
  212. parambit = POSITION;
  213. component = -1;
  214. break;
  215. case PARAM_POS_X:
  216. parambit = POSITION;
  217. component = 0;
  218. break;
  219. case PARAM_POS_Y:
  220. parambit = POSITION;
  221. component = 1;
  222. break;
  223. case PARAM_POS_Z:
  224. parambit = POSITION;
  225. component = 2;
  226. break;
  227. case PARAM_ORI:
  228. parambit = ORIENTATION;
  229. component = -1;
  230. break;
  231. case PARAM_POS2:
  232. parambit = POSITION2;
  233. component = -1;
  234. break;
  235. case PARAM_POS2_X:
  236. parambit = POSITION2;
  237. component = 0;
  238. break;
  239. case PARAM_POS2_Y:
  240. parambit = POSITION2;
  241. component = 1;
  242. break;
  243. case PARAM_POS2_Z:
  244. parambit = POSITION2;
  245. component = 2;
  246. break;
  247. case PARAM_SCALE:
  248. parambit = SCALE;
  249. component = -1;
  250. break;
  251. case PARAM_SCALE_X:
  252. parambit = SCALE;
  253. component = 0;
  254. break;
  255. case PARAM_SCALE_Y:
  256. parambit = SCALE;
  257. component = 1;
  258. break;
  259. case PARAM_SCALE_Z:
  260. parambit = SCALE;
  261. component = 2;
  262. break;
  263. case PARAM_COLOR:
  264. parambit = COLOR;
  265. component = -1;
  266. break;
  267. case PARAM_COLOR_R:
  268. parambit = COLOR;
  269. component = 0;
  270. break;
  271. case PARAM_COLOR_G:
  272. parambit = COLOR;
  273. component = 1;
  274. break;
  275. case PARAM_COLOR_B:
  276. parambit = COLOR;
  277. component = 2;
  278. break;
  279. case PARAM_COLOR_A:
  280. parambit = COLOR;
  281. component = 3;
  282. break;
  283. case PARAM_VIS:
  284. parambit = VISIBILITY;
  285. component = -1;
  286. break;
  287. default:
  288. parambit = 0;
  289. component = -1;
  290. break;
  291. }
  292. }
  293. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  294. IMPLEMENT_CO_DATABLOCK_V1(afxXM_WaveRiderBaseData);
  295. ConsoleDocClass( afxXM_WaveRiderBaseData,
  296. "@brief An xmod datablock.\n\n"
  297. "@ingroup afxXMods\n"
  298. "@ingroup AFX\n"
  299. "@ingroup Datablocks\n"
  300. );
  301. afxXM_WaveRiderBaseData::afxXM_WaveRiderBaseData()
  302. {
  303. waveform_type = afxXM_WaveBaseData::WAVEFORM_NONE;
  304. parameter = afxXM_WaveBaseData::PARAM_NONE;
  305. op = afxXM_WaveBaseData::OP_ADD;
  306. off_duty_t = 0.0f;
  307. axis.zero();
  308. local_axis = true;
  309. }
  310. afxXM_WaveRiderBaseData::afxXM_WaveRiderBaseData(const afxXM_WaveRiderBaseData& other, bool temp_clone) : afxXM_WeightedBaseData(other, temp_clone)
  311. {
  312. waveform_type = other.waveform_type;
  313. parameter = other.parameter;
  314. op = other.op;
  315. off_duty_t = other.off_duty_t;
  316. axis = other.axis;
  317. local_axis = true;
  318. }
  319. void afxXM_WaveRiderBaseData::initPersistFields()
  320. {
  321. docsURL;
  322. addField("waveform", TYPEID< afxXM_WaveBaseData::WaveFormType >(), Offset(waveform_type, afxXM_WaveRiderBaseData),
  323. "...");
  324. addField("parameter", TYPEID< afxXM_WaveBaseData::WaveParamType >(), Offset(parameter, afxXM_WaveRiderBaseData),
  325. "...");
  326. addField("op", TYPEID< afxXM_WaveBaseData::WaveOpType >(), Offset(op, afxXM_WaveRiderBaseData),
  327. "...");
  328. addField("offDutyT", TypeF32, Offset(off_duty_t, afxXM_WaveRiderBaseData),
  329. "...");
  330. addField("axis", TypePoint3F, Offset(axis, afxXM_WaveRiderBaseData),
  331. "...");
  332. addField("axisIsLocal", TypeBool, Offset(local_axis, afxXM_WaveRiderBaseData),
  333. "...");
  334. Parent::initPersistFields();
  335. }
  336. void afxXM_WaveRiderBaseData::packData(BitStream* stream)
  337. {
  338. Parent::packData(stream);
  339. stream->writeInt(waveform_type, afxXM_WaveBaseData::WAVEFORM_BITS);
  340. stream->writeInt(parameter, afxXM_WaveBaseData::PARAM_BITS);
  341. stream->writeInt(op, afxXM_WaveBaseData::OP_BITS);
  342. stream->write(off_duty_t);
  343. mathWrite(*stream, axis);
  344. stream->writeFlag(local_axis);
  345. }
  346. void afxXM_WaveRiderBaseData::unpackData(BitStream* stream)
  347. {
  348. Parent::unpackData(stream);
  349. waveform_type = stream->readInt(afxXM_WaveBaseData::WAVEFORM_BITS);
  350. parameter = stream->readInt(afxXM_WaveBaseData::PARAM_BITS);
  351. op = stream->readInt(afxXM_WaveBaseData::OP_BITS);
  352. stream->read(&off_duty_t);
  353. mathRead(*stream, &axis);
  354. local_axis = stream->readFlag();
  355. }
  356. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
  357. // WAVEFORMS
  358. F32 afxXM_WaveformSine::evaluate(F32 t)
  359. {
  360. t = (0.75f + t)*Float_2Pi;
  361. return 0.5f*(1.0f + mSin(t));
  362. }
  363. F32 afxXM_WaveformSquare::evaluate(F32 t)
  364. {
  365. return (t < 0.25f || t >= 0.75) ? 0.0f : 1.0f;
  366. }
  367. F32 afxXM_WaveformTriangle::evaluate(F32 t)
  368. {
  369. return (t < 0.5f) ? 2.0f*t : 2.0f*(1.0f - t);
  370. }
  371. //~~~~~~~~~~~~~~~~~~~~//
  372. afxXM_Waveform* afxXM_WaveBaseData::getWaveform(U32 waveform_type)
  373. {
  374. static afxXM_WaveformSine sine;
  375. static afxXM_WaveformSquare square;
  376. static afxXM_WaveformTriangle triangle;
  377. static afxXM_WaveformSawtooth sawtooth;
  378. static afxXM_WaveformNoise noise;
  379. static afxXM_WaveformOne one;
  380. switch (waveform_type)
  381. {
  382. case WAVEFORM_SINE:
  383. return &sine;
  384. case WAVEFORM_SQUARE:
  385. return &square;
  386. case WAVEFORM_TRIANGLE:
  387. return &triangle;
  388. case WAVEFORM_SAWTOOTH:
  389. return &sawtooth;
  390. case WAVEFORM_NOISE:
  391. return &noise;
  392. case WAVEFORM_ONE:
  393. return &one;
  394. default:
  395. // error condition
  396. return &sine;
  397. }
  398. }
  399. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  400. bool afxXM_WaveBase::last_was_pulsed = false;
  401. bool afxXM_WaveBase::last_was_off_duty = true;
  402. F32 afxXM_WaveBase::last_t = 0.0f;
  403. F32 afxXM_WaveBase::last_wave_t = 0.0f;
  404. afxXM_WaveBase::afxXM_WaveBase(afxXM_WaveBaseData* db, afxEffectWrapper* fxw, afxXM_WaveInterp* interp)
  405. : afxXM_WeightedBase(db, fxw)
  406. {
  407. this->db = db;
  408. interpolator = interp;
  409. waveform = afxXM_WaveBaseData::getWaveform(db->waveform_type);
  410. speed_is_randomized = !mIsZero(db->speed_vari);
  411. speed = calc_initial_speed();
  412. fixed_weight = db->hasFixedWeight();
  413. is_resting = false;
  414. cur_pulse_time = db->delay;
  415. next_pulse_time = cur_pulse_time + ((F32)calc_new_wavesPerPulse())/speed;
  416. interpolator->pulse();
  417. last_was_pulsed = false;
  418. last_was_off_duty = true;
  419. last_t = 0.0f;
  420. last_wave_t = 0.0f;
  421. }
  422. afxXM_WaveBase::~afxXM_WaveBase()
  423. {
  424. delete interpolator;
  425. }
  426. void afxXM_WaveBase::updateParams(F32 dt, F32 elapsed, afxXM_Params& params)
  427. {
  428. elapsed -= db->delay;
  429. if (elapsed > next_pulse_time)
  430. {
  431. is_resting = !is_resting;
  432. cur_pulse_time = next_pulse_time;
  433. if (is_resting)
  434. {
  435. F32 rest_dt = ((F32)(calc_new_wavesPerRest())/speed) + calc_new_restDur();
  436. if (rest_dt < 0.01)
  437. is_resting = false;
  438. else
  439. next_pulse_time = cur_pulse_time + rest_dt;
  440. }
  441. if (!is_resting)
  442. {
  443. speed = calc_new_speed();
  444. next_pulse_time = cur_pulse_time + ((F32)calc_new_wavesPerPulse())/speed;
  445. interpolator->pulse();
  446. last_was_pulsed = true;
  447. }
  448. }
  449. if (is_resting)
  450. {
  451. last_was_off_duty = true;
  452. interpolator->interpolate(db->off_duty_t, params);
  453. return;
  454. }
  455. F32 n_waves = db->phase_shift + (elapsed - cur_pulse_time)*speed;
  456. F32 wave_t = (n_waves - mFloor(n_waves))/db->duty_cycle;
  457. // we are beyond the duty portion of the wave, use off_duty_t
  458. if (wave_t > 1.0f)
  459. {
  460. last_was_off_duty = true;
  461. interpolator->interpolate(db->off_duty_t, params);
  462. return;
  463. }
  464. if (db->duty_shift > 0.0f)
  465. {
  466. wave_t += db->duty_shift;
  467. if (wave_t > 1.0)
  468. wave_t -= 1.0f;
  469. }
  470. last_was_off_duty = false;
  471. last_wave_t = wave_t;
  472. last_t = waveform->evaluate(wave_t);
  473. if (fixed_weight)
  474. {
  475. interpolator->interpolate(last_t, params);
  476. }
  477. else
  478. {
  479. F32 wt_factor = calc_weight_factor(elapsed);
  480. F32 final_t = mLerp(db->off_duty_t, last_t, wt_factor);
  481. interpolator->interpolate(final_t, params);
  482. }
  483. }
  484. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  485. afxXM_WaveRiderBase::afxXM_WaveRiderBase(afxXM_WaveRiderBaseData* db, afxEffectWrapper* fxw, afxXM_WaveInterp* interp)
  486. : afxXM_WeightedBase(db, fxw)
  487. {
  488. this->db = db;
  489. interpolator = interp;
  490. waveform = afxXM_WaveBaseData::getWaveform(db->waveform_type);
  491. fixed_weight = db->hasFixedWeight();
  492. interpolator->pulse();
  493. }
  494. afxXM_WaveRiderBase::~afxXM_WaveRiderBase()
  495. {
  496. delete interpolator;
  497. }
  498. void afxXM_WaveRiderBase::updateParams(F32 dt, F32 elapsed, afxXM_Params& params)
  499. {
  500. if (afxXM_WaveBase::last_was_pulsed)
  501. interpolator->pulse();
  502. if (afxXM_WaveBase::last_was_off_duty)
  503. {
  504. interpolator->interpolate(db->off_duty_t, params);
  505. return;
  506. }
  507. F32 t;
  508. if (db->waveform_type != afxXM_WaveBaseData::WAVEFORM_NONE)
  509. t = waveform->evaluate(afxXM_WaveBase::last_wave_t);
  510. else
  511. t = afxXM_WaveBase::last_t;
  512. if (fixed_weight)
  513. interpolator->interpolate(t, params);
  514. else
  515. {
  516. F32 wt_factor = calc_weight_factor(elapsed);
  517. F32 final_t = mLerp(db->off_duty_t, t, wt_factor);
  518. interpolator->interpolate(final_t, params);
  519. }
  520. }
  521. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//