afxPlayerPuppet.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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/ce/afxPlayerPuppet.h"
  31. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  32. // afxPlayerPuppetData
  33. IMPLEMENT_CO_DATABLOCK_V1(afxPlayerPuppetData);
  34. ConsoleDocClass( afxPlayerPuppetData,
  35. "@brief A datablock that specifies a Player Puppet effect.\n\n"
  36. "Player Puppet effects are defined using the afxPlayerPuppetData datablock and are used to control the movement of "
  37. "Player objects with the AFX constraint system. The Player Puppet effect is similar to the Player Movement effect, but "
  38. "where movement effects 'steer' the player using the same mechanisms that allow Player control from mouse and keyboard "
  39. "input, Player Puppet effects totally take over a Player's transformation using the AFX constraint system."
  40. "\n\n"
  41. "Player Puppet can be configured to directly move a Player's client ghosts as well as its server instance. When doing this, "
  42. "it is important to keep the general motion of the Player object and its ghosts somewhat consistent. Otherwise, obvious "
  43. "discontinuities in the motion will result when the Player Puppet ends and control is restored to the server Player."
  44. "\n\n"
  45. "@ingroup afxEffects\n"
  46. "@ingroup AFX\n"
  47. "@ingroup Datablocks\n"
  48. );
  49. afxPlayerPuppetData::afxPlayerPuppetData()
  50. {
  51. obj_spec = ST_NULLSTRING;
  52. networking = SERVER_ONLY;
  53. }
  54. afxPlayerPuppetData::afxPlayerPuppetData(const afxPlayerPuppetData& other, bool temp_clone) : GameBaseData(other, temp_clone)
  55. {
  56. obj_spec = other.obj_spec;
  57. networking = other.networking;
  58. }
  59. #define myOffset(field) Offset(field, afxPlayerPuppetData)
  60. void afxPlayerPuppetData::initPersistFields()
  61. {
  62. addField("objectSpec", TypeString, myOffset(obj_spec),
  63. "...");
  64. addField("networking", TypeS8, myOffset(networking),
  65. "...");
  66. Parent::initPersistFields();
  67. // disallow some field substitutions
  68. disableFieldSubstitutions("objectSpec");
  69. disableFieldSubstitutions("networking");
  70. }
  71. bool afxPlayerPuppetData::onAdd()
  72. {
  73. if (Parent::onAdd() == false)
  74. return false;
  75. bool runs_on_s = ((networking & (SERVER_ONLY | SERVER_AND_CLIENT)) != 0);
  76. bool runs_on_c = ((networking & (CLIENT_ONLY | SERVER_AND_CLIENT)) != 0);
  77. obj_def.parseSpec(obj_spec, runs_on_s, runs_on_c);
  78. return true;
  79. }
  80. void afxPlayerPuppetData::packData(BitStream* stream)
  81. {
  82. Parent::packData(stream);
  83. stream->writeString(obj_spec);
  84. stream->write(networking);
  85. }
  86. void afxPlayerPuppetData::unpackData(BitStream* stream)
  87. {
  88. Parent::unpackData(stream);
  89. obj_spec = stream->readSTString();
  90. stream->read(&networking);
  91. }
  92. void afxPlayerPuppetData::gather_cons_defs(Vector<afxConstraintDef>& defs)
  93. {
  94. if (obj_def.isDefined())
  95. defs.push_back(obj_def);
  96. };
  97. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//