afxXM_WaveScalar.cpp 22 KB

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