afxForce.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 "console/consoleTypes.h"
  26. #include "core/stream/bitStream.h"
  27. #include "scene/sceneRenderState.h"
  28. #include "math/mathIO.h"
  29. #include "afx/afxChoreographer.h"
  30. #include "afx/forces/afxForce.h"
  31. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  32. // afxForceData
  33. afxForceData::afxForceData()
  34. {
  35. force_set_name = ST_NULLSTRING;
  36. force_desc = 0;
  37. }
  38. afxForceData::afxForceData(const afxForceData& other, bool temp_clone) : GameBaseData(other, temp_clone)
  39. {
  40. force_set_name = other.force_set_name;
  41. force_desc = other.force_desc;
  42. }
  43. #define myOffset(field) Offset(field, afxForceData)
  44. void afxForceData::initPersistFields()
  45. {
  46. addField("forceSetName", TypeString, myOffset(force_set_name),
  47. "...");
  48. Parent::initPersistFields();
  49. }
  50. bool afxForceData::onAdd()
  51. {
  52. if (Parent::onAdd() == false)
  53. return false;
  54. return true;
  55. }
  56. void afxForceData::packData(BitStream* stream)
  57. {
  58. Parent::packData(stream);
  59. stream->writeString(force_set_name);
  60. }
  61. void afxForceData::unpackData(BitStream* stream)
  62. {
  63. Parent::unpackData(stream);
  64. force_set_name = stream->readSTString();
  65. }
  66. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  67. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  68. // afxForce
  69. afxForce::afxForce()
  70. {
  71. datablock = 0;
  72. fade_amt = 1.0f;
  73. }
  74. afxForce::~afxForce()
  75. {
  76. }
  77. bool afxForce::onNewDataBlock(afxForceData* dptr, bool reload)
  78. {
  79. datablock = dptr;
  80. return true;
  81. }
  82. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  83. Vector<afxForceDesc*>* afxForceDesc::forces = 0;
  84. afxForceDesc::afxForceDesc()
  85. {
  86. if (!forces)
  87. forces = new Vector<afxForceDesc*>;
  88. forces->push_back(this);
  89. }
  90. bool afxForceDesc::identifyForce(afxForceData* force_data)
  91. {
  92. if (!force_data)
  93. {
  94. Con::errorf("afxForceDesc::identifyForce() -- force datablock was not specified.");
  95. return false;
  96. }
  97. if (!forces)
  98. {
  99. Con::errorf("afxForceDesc::identifyForce() -- force registration list has not been allocated.");
  100. return false;
  101. }
  102. if (forces->size() == 0)
  103. {
  104. Con::errorf("afxForceDesc::identifyForce() -- no forces have been registered.");
  105. return false;
  106. }
  107. for (S32 i = 0; i < forces->size(); i++)
  108. {
  109. if ((*forces)[i]->testForceType(force_data))
  110. {
  111. force_data->force_desc = (*forces)[i];
  112. return true;
  113. }
  114. }
  115. Con::errorf("afxForceDesc::identifyForce() -- force %s has an undefined type. -- %d",
  116. force_data, forces->size());
  117. return false;
  118. }
  119. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//