afxForce.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. docsURL;
  47. addField("forceSetName", TypeString, myOffset(force_set_name),
  48. "...");
  49. Parent::initPersistFields();
  50. }
  51. bool afxForceData::onAdd()
  52. {
  53. if (Parent::onAdd() == false)
  54. return false;
  55. return true;
  56. }
  57. void afxForceData::packData(BitStream* stream)
  58. {
  59. Parent::packData(stream);
  60. stream->writeString(force_set_name);
  61. }
  62. void afxForceData::unpackData(BitStream* stream)
  63. {
  64. Parent::unpackData(stream);
  65. force_set_name = stream->readSTString();
  66. }
  67. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  68. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  69. // afxForce
  70. afxForce::afxForce()
  71. {
  72. datablock = 0;
  73. fade_amt = 1.0f;
  74. }
  75. afxForce::~afxForce()
  76. {
  77. }
  78. bool afxForce::onNewDataBlock(afxForceData* dptr, bool reload)
  79. {
  80. datablock = dptr;
  81. return true;
  82. }
  83. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  84. Vector<afxForceDesc*>* afxForceDesc::forces = 0;
  85. afxForceDesc::afxForceDesc()
  86. {
  87. if (!forces)
  88. forces = new Vector<afxForceDesc*>;
  89. forces->push_back(this);
  90. }
  91. bool afxForceDesc::identifyForce(afxForceData* force_data)
  92. {
  93. if (!force_data)
  94. {
  95. Con::errorf("afxForceDesc::identifyForce() -- force datablock was not specified.");
  96. return false;
  97. }
  98. if (!forces)
  99. {
  100. Con::errorf("afxForceDesc::identifyForce() -- force registration list has not been allocated.");
  101. return false;
  102. }
  103. if (forces->size() == 0)
  104. {
  105. Con::errorf("afxForceDesc::identifyForce() -- no forces have been registered.");
  106. return false;
  107. }
  108. for (S32 i = 0; i < forces->size(); i++)
  109. {
  110. if ((*forces)[i]->testForceType(force_data))
  111. {
  112. force_data->force_desc = (*forces)[i];
  113. return true;
  114. }
  115. }
  116. Con::errorf("afxForceDesc::identifyForce() -- force %s has an undefined type. -- %d",
  117. force_data, forces->size());
  118. return false;
  119. }
  120. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//