afxStaticShape.cpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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 "ts/tsShapeInstance.h"
  26. #include "afx/afxChoreographer.h"
  27. #include "afx/ce/afxStaticShape.h"
  28. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  29. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  30. // afxStaticShapeData
  31. IMPLEMENT_CO_DATABLOCK_V1(afxStaticShapeData);
  32. ConsoleDocClass( afxStaticShapeData,
  33. "@brief A datablock that specifies a StaticShape effect.\n\n"
  34. "afxStaticShapeData inherits from StaticShapeData and adds some AFX specific fields. StaticShape effects should be "
  35. "specified using afxStaticShapeData rather than StaticShapeData datablocks."
  36. "\n\n"
  37. "@ingroup afxEffects\n"
  38. "@ingroup AFX\n"
  39. "@ingroup Datablocks\n"
  40. );
  41. afxStaticShapeData::afxStaticShapeData()
  42. {
  43. sequence = ST_NULLSTRING;
  44. ignore_scene_amb = false;
  45. use_custom_scene_amb = false;
  46. custom_scene_amb.set(0.5f, 0.5f, 0.5f);
  47. do_spawn = false;
  48. }
  49. afxStaticShapeData::afxStaticShapeData(const afxStaticShapeData& other, bool temp_clone) : StaticShapeData(other, temp_clone)
  50. {
  51. sequence = other.sequence;
  52. ignore_scene_amb = other.ignore_scene_amb;
  53. use_custom_scene_amb = other.use_custom_scene_amb;
  54. custom_scene_amb = other.custom_scene_amb;
  55. do_spawn = other.do_spawn;
  56. }
  57. #define myOffset(field) Offset(field, afxStaticShapeData)
  58. void afxStaticShapeData::initPersistFields()
  59. {
  60. addField("sequence", TypeString, myOffset(sequence),
  61. "An animation sequence in the StaticShape to play.");
  62. addField("ignoreSceneAmbient", TypeBool, myOffset(ignore_scene_amb),
  63. "...");
  64. addField("useCustomSceneAmbient", TypeBool, myOffset(use_custom_scene_amb),
  65. "...");
  66. addField("customSceneAmbient", TypeColorF, myOffset(custom_scene_amb),
  67. "...");
  68. addField("doSpawn", TypeBool, myOffset(do_spawn),
  69. "When true, the StaticShape effect will leave behind the StaticShape object as a "
  70. "permanent part of the scene.");
  71. Parent::initPersistFields();
  72. }
  73. void afxStaticShapeData::packData(BitStream* stream)
  74. {
  75. Parent::packData(stream);
  76. stream->writeString(sequence);
  77. stream->writeFlag(ignore_scene_amb);
  78. if (stream->writeFlag(use_custom_scene_amb))
  79. stream->write(custom_scene_amb);
  80. stream->writeFlag(do_spawn);
  81. }
  82. void afxStaticShapeData::unpackData(BitStream* stream)
  83. {
  84. Parent::unpackData(stream);
  85. sequence = stream->readSTString();
  86. ignore_scene_amb = stream->readFlag();
  87. if ((use_custom_scene_amb = stream->readFlag()) == true)
  88. stream->read(&custom_scene_amb);
  89. do_spawn = stream->readFlag();
  90. }
  91. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  92. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  93. // afxStaticShape
  94. IMPLEMENT_CO_NETOBJECT_V1(afxStaticShape);
  95. ConsoleDocClass( afxStaticShape,
  96. "@brief A StaticShape effect as defined by an afxStaticShapeData datablock.\n\n"
  97. "@ingroup afxEffects\n"
  98. "@ingroup AFX\n"
  99. );
  100. afxStaticShape::afxStaticShape()
  101. {
  102. mDataBlock = NULL;
  103. mAFX_data = 0;
  104. mIs_visible = true;
  105. mChor_id = 0;
  106. mHookup_with_chor = false;
  107. mGhost_cons_name = ST_NULLSTRING;
  108. }
  109. afxStaticShape::~afxStaticShape()
  110. {
  111. }
  112. void afxStaticShape::init(U32 chor_id, StringTableEntry cons_name)
  113. {
  114. mChor_id = chor_id;
  115. mGhost_cons_name = cons_name;
  116. }
  117. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
  118. bool afxStaticShape::onNewDataBlock(GameBaseData* dptr, bool reload)
  119. {
  120. mDataBlock = dynamic_cast<StaticShapeData*>(dptr);
  121. if (!mDataBlock || !Parent::onNewDataBlock(dptr, reload))
  122. return false;
  123. mAFX_data = dynamic_cast<afxStaticShapeData*>(mDataBlock);
  124. if (!mShapeInstance)
  125. return true;
  126. const char* seq_name = 0;
  127. // if datablock is afxStaticShapeData we get the sequence setting
  128. // directly from the datablock on the client-side only
  129. if (mAFX_data)
  130. {
  131. if (isClientObject())
  132. seq_name = mAFX_data->sequence;
  133. }
  134. // otherwise datablock is stock StaticShapeData and we look for
  135. // a sequence name on a dynamic field on the server.
  136. else
  137. {
  138. if (isServerObject())
  139. seq_name = mDataBlock->getDataField(StringTable->insert("sequence"),0);
  140. }
  141. // if we have a sequence name, attempt to start a thread
  142. if (seq_name)
  143. {
  144. TSShape* shape = mShapeInstance->getShape();
  145. if (shape)
  146. {
  147. S32 seq = shape->findSequence(seq_name);
  148. if (seq != -1)
  149. setThreadSequence(0,seq);
  150. }
  151. }
  152. return true;
  153. }
  154. void afxStaticShape::advanceTime(F32 dt)
  155. {
  156. Parent::advanceTime(dt);
  157. if (mHookup_with_chor)
  158. {
  159. afxChoreographer* chor = arcaneFX::findClientChoreographer(mChor_id);
  160. if (chor)
  161. {
  162. chor->setGhostConstraintObject(this, mGhost_cons_name);
  163. mHookup_with_chor = false;
  164. }
  165. }
  166. }
  167. U32 afxStaticShape::packUpdate(NetConnection* conn, U32 mask, BitStream* stream)
  168. {
  169. U32 retMask = Parent::packUpdate(conn, mask, stream);
  170. // InitialUpdate
  171. if (stream->writeFlag(mask & InitialUpdateMask))
  172. {
  173. stream->write(mChor_id);
  174. stream->writeString(mGhost_cons_name);
  175. }
  176. return retMask;
  177. }
  178. //~~~~~~~~~~~~~~~~~~~~//
  179. void afxStaticShape::unpackUpdate(NetConnection * conn, BitStream * stream)
  180. {
  181. Parent::unpackUpdate(conn, stream);
  182. // InitialUpdate
  183. if (stream->readFlag())
  184. {
  185. stream->read(&mChor_id);
  186. mGhost_cons_name = stream->readSTString();
  187. if (mChor_id != 0 && mGhost_cons_name != ST_NULLSTRING)
  188. mHookup_with_chor = true;
  189. }
  190. }
  191. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
  192. void afxStaticShape::prepRenderImage(SceneRenderState* state)
  193. {
  194. if (mIs_visible)
  195. Parent::prepRenderImage(state);
  196. }
  197. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//