afxCameraPuppet.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. docsURL;
  69. addField("cameraSpec", TypeString, myOffset(cam_spec),
  70. "This field is like the effect-wrapper fields for specifying constraint sources, "
  71. "but here it specifies a target for the camera-puppet effect.");
  72. addField("networking", TypeS8, myOffset(networking),
  73. "Specifies the networking model used for the camerapuppet effect. The effect can "
  74. "puppet just the server camera, just the client camera, or both.\n"
  75. "Possible values: $AFX::SERVER_ONLY, $AFX::CLIENT_ONLY, or $AFX::SERVER_AND_CLIENT.");
  76. // disallow some field substitutions
  77. disableFieldSubstitutions("cameraSpec");
  78. disableFieldSubstitutions("networking");
  79. Parent::initPersistFields();
  80. }
  81. bool afxCameraPuppetData::onAdd()
  82. {
  83. if (Parent::onAdd() == false)
  84. return false;
  85. bool runs_on_s = ((networking & (SERVER_ONLY | SERVER_AND_CLIENT)) != 0);
  86. bool runs_on_c = ((networking & (CLIENT_ONLY | SERVER_AND_CLIENT)) != 0);
  87. cam_def.parseSpec(cam_spec, runs_on_s, runs_on_c);
  88. return true;
  89. }
  90. void afxCameraPuppetData::packData(BitStream* stream)
  91. {
  92. Parent::packData(stream);
  93. stream->writeString(cam_spec);
  94. stream->write(networking);
  95. }
  96. void afxCameraPuppetData::unpackData(BitStream* stream)
  97. {
  98. Parent::unpackData(stream);
  99. cam_spec = stream->readSTString();
  100. stream->read(&networking);
  101. }
  102. void afxCameraPuppetData::gather_cons_defs(Vector<afxConstraintDef>& defs)
  103. {
  104. if (cam_def.isDefined())
  105. defs.push_back(cam_def);
  106. };
  107. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//