afxCameraPuppet.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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/afxCameraPuppet.h"
  31. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  32. // afxCameraPuppetData
  33. IMPLEMENT_CO_DATABLOCK_V1(afxCameraPuppetData);
  34. ConsoleDocClass( afxCameraPuppetData,
  35. "@brief A datablock that specifies a Camera Puppet effect.\n\n"
  36. "A Camera Puppet effect is used to control the position and orientation of the camera using the AFX constraint system. "
  37. "Camera Puppet effects are useful for creating small cut-scenes and can add a lot of visual drama to a spell or effectron "
  38. "effect."
  39. "\n\n"
  40. "Effective use of Camera Puppet effects require a fairly advanced understanding of how Torque cameras work in a "
  41. "server-client context. Care must be taken to prevent client cameras from drifting too far out of sync from the server camera. "
  42. "Otherwise, obvious discontinuities in the motion will result when the Camera Puppet ends and control is restored to the "
  43. "server camera. Scoping problems can also result if a client camera is moved to a location that is inconsistent with the "
  44. "scene scoping done by the server camera."
  45. "\n\n"
  46. "Often it is useful to manage camera controlling in an isolated effectron rather than directly incorporated into a magic-spell. "
  47. "This way the camera controlling effectron can target the specific client associated with the spellcaster. The spellcasting "
  48. "player observes the spell in a dramatic cut-scene-like fashion while other players continue to observe from their own "
  49. "viewing locations."
  50. "\n\n"
  51. "@ingroup afxEffects\n"
  52. "@ingroup AFX\n"
  53. "@ingroup Datablocks\n"
  54. );
  55. afxCameraPuppetData::afxCameraPuppetData()
  56. {
  57. cam_spec = ST_NULLSTRING;
  58. networking = SERVER_AND_CLIENT;
  59. }
  60. afxCameraPuppetData::afxCameraPuppetData(const afxCameraPuppetData& other, bool temp_clone) : GameBaseData(other, temp_clone)
  61. {
  62. cam_spec = other.cam_spec;
  63. networking = other.networking;
  64. }
  65. #define myOffset(field) Offset(field, afxCameraPuppetData)
  66. void afxCameraPuppetData::initPersistFields()
  67. {
  68. addField("cameraSpec", TypeString, myOffset(cam_spec),
  69. "This field is like the effect-wrapper fields for specifying constraint sources, "
  70. "but here it specifies a target for the camera-puppet effect.");
  71. addField("networking", TypeS8, myOffset(networking),
  72. "Specifies the networking model used for the camerapuppet effect. The effect can "
  73. "puppet just the server camera, just the client camera, or both.\n"
  74. "Possible values: $AFX::SERVER_ONLY, $AFX::CLIENT_ONLY, or $AFX::SERVER_AND_CLIENT.");
  75. // disallow some field substitutions
  76. disableFieldSubstitutions("cameraSpec");
  77. disableFieldSubstitutions("networking");
  78. Parent::initPersistFields();
  79. }
  80. bool afxCameraPuppetData::onAdd()
  81. {
  82. if (Parent::onAdd() == false)
  83. return false;
  84. bool runs_on_s = ((networking & (SERVER_ONLY | SERVER_AND_CLIENT)) != 0);
  85. bool runs_on_c = ((networking & (CLIENT_ONLY | SERVER_AND_CLIENT)) != 0);
  86. cam_def.parseSpec(cam_spec, runs_on_s, runs_on_c);
  87. return true;
  88. }
  89. void afxCameraPuppetData::packData(BitStream* stream)
  90. {
  91. Parent::packData(stream);
  92. stream->writeString(cam_spec);
  93. stream->write(networking);
  94. }
  95. void afxCameraPuppetData::unpackData(BitStream* stream)
  96. {
  97. Parent::unpackData(stream);
  98. cam_spec = stream->readSTString();
  99. stream->read(&networking);
  100. }
  101. void afxCameraPuppetData::gather_cons_defs(Vector<afxConstraintDef>& defs)
  102. {
  103. if (cam_def.isDefined())
  104. defs.push_back(cam_def);
  105. };
  106. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//