afxStaticShape.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. docsURL;
  61. addGroup("Animation");
  62. addField("sequence", TypeString, myOffset(sequence),
  63. "An animation sequence in the StaticShape to play.");
  64. endGroup("Animation");
  65. addGroup("Rendering");
  66. addField("ignoreSceneAmbient", TypeBool, myOffset(ignore_scene_amb), "...");
  67. addField("useCustomSceneAmbient", TypeBool, myOffset(use_custom_scene_amb), "...");
  68. addField("customSceneAmbient", TypeColorF, myOffset(custom_scene_amb), "...");
  69. endGroup("Rendering");
  70. addGroup("Behaviour");
  71. addField("doSpawn", TypeBool, myOffset(do_spawn),
  72. "When true, the StaticShape effect will leave behind the StaticShape object as a "
  73. "permanent part of the scene.");
  74. endGroup("Behaviour");
  75. Parent::initPersistFields();
  76. }
  77. void afxStaticShapeData::packData(BitStream* stream)
  78. {
  79. Parent::packData(stream);
  80. stream->writeString(sequence);
  81. stream->writeFlag(ignore_scene_amb);
  82. if (stream->writeFlag(use_custom_scene_amb))
  83. stream->write(custom_scene_amb);
  84. stream->writeFlag(do_spawn);
  85. }
  86. void afxStaticShapeData::unpackData(BitStream* stream)
  87. {
  88. Parent::unpackData(stream);
  89. sequence = stream->readSTString();
  90. ignore_scene_amb = stream->readFlag();
  91. if ((use_custom_scene_amb = stream->readFlag()) == true)
  92. stream->read(&custom_scene_amb);
  93. do_spawn = stream->readFlag();
  94. }
  95. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  96. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  97. // afxStaticShape
  98. IMPLEMENT_CO_NETOBJECT_V1(afxStaticShape);
  99. ConsoleDocClass( afxStaticShape,
  100. "@brief A StaticShape effect as defined by an afxStaticShapeData datablock.\n\n"
  101. "@ingroup afxEffects\n"
  102. "@ingroup AFX\n"
  103. );
  104. afxStaticShape::afxStaticShape()
  105. {
  106. mDataBlock = NULL;
  107. mAFX_data = 0;
  108. mIs_visible = true;
  109. mChor_id = 0;
  110. mHookup_with_chor = false;
  111. mGhost_cons_name = ST_NULLSTRING;
  112. }
  113. afxStaticShape::~afxStaticShape()
  114. {
  115. }
  116. void afxStaticShape::init(U32 chor_id, StringTableEntry cons_name)
  117. {
  118. mChor_id = chor_id;
  119. mGhost_cons_name = cons_name;
  120. }
  121. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
  122. bool afxStaticShape::onNewDataBlock(GameBaseData* dptr, bool reload)
  123. {
  124. mDataBlock = dynamic_cast<StaticShapeData*>(dptr);
  125. if (!mDataBlock || !Parent::onNewDataBlock(dptr, reload))
  126. return false;
  127. mAFX_data = dynamic_cast<afxStaticShapeData*>(mDataBlock);
  128. if (!mShapeInstance)
  129. return true;
  130. const char* seq_name = 0;
  131. // if datablock is afxStaticShapeData we get the sequence setting
  132. // directly from the datablock on the client-side only
  133. if (mAFX_data)
  134. {
  135. if (isClientObject())
  136. seq_name = mAFX_data->sequence;
  137. }
  138. // otherwise datablock is stock StaticShapeData and we look for
  139. // a sequence name on a dynamic field on the server.
  140. else
  141. {
  142. if (isServerObject())
  143. seq_name = mDataBlock->getDataField(StringTable->insert("sequence"),0);
  144. }
  145. // if we have a sequence name, attempt to start a thread
  146. if (seq_name)
  147. {
  148. TSShape* shape = mShapeInstance->getShape();
  149. if (shape)
  150. {
  151. S32 seq = shape->findSequence(seq_name);
  152. if (seq != -1)
  153. setThreadSequence(0,seq);
  154. }
  155. }
  156. return true;
  157. }
  158. void afxStaticShape::advanceTime(F32 dt)
  159. {
  160. Parent::advanceTime(dt);
  161. if (mHookup_with_chor)
  162. {
  163. afxChoreographer* chor = arcaneFX::findClientChoreographer(mChor_id);
  164. if (chor)
  165. {
  166. chor->setGhostConstraintObject(this, mGhost_cons_name);
  167. mHookup_with_chor = false;
  168. }
  169. }
  170. }
  171. U32 afxStaticShape::packUpdate(NetConnection* conn, U32 mask, BitStream* stream)
  172. {
  173. U32 retMask = Parent::packUpdate(conn, mask, stream);
  174. // InitialUpdate
  175. if (stream->writeFlag(mask & InitialUpdateMask))
  176. {
  177. stream->write(mChor_id);
  178. stream->writeString(mGhost_cons_name);
  179. }
  180. return retMask;
  181. }
  182. //~~~~~~~~~~~~~~~~~~~~//
  183. void afxStaticShape::unpackUpdate(NetConnection * conn, BitStream * stream)
  184. {
  185. Parent::unpackUpdate(conn, stream);
  186. // InitialUpdate
  187. if (stream->readFlag())
  188. {
  189. stream->read(&mChor_id);
  190. mGhost_cons_name = stream->readSTString();
  191. if (mChor_id != 0 && mGhost_cons_name != ST_NULLSTRING)
  192. mHookup_with_chor = true;
  193. }
  194. }
  195. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
  196. void afxStaticShape::prepRenderImage(SceneRenderState* state)
  197. {
  198. if (mIs_visible)
  199. Parent::prepRenderImage(state);
  200. }
  201. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//