afxPlayerMovement.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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/afxPlayerMovement.h"
  31. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  32. // afxPlayerMovementData
  33. IMPLEMENT_CO_DATABLOCK_V1(afxPlayerMovementData);
  34. ConsoleDocClass( afxPlayerMovementData,
  35. "@brief A datablock that specifies a Player Movement effect.\n\n"
  36. "Player Movement effects are used to directly alter the speed and/or movement direction of Player objects. The Player "
  37. "Movement effect is similar to the Player Puppet effect, but where puppet effects totally take over a Player's transformation "
  38. "using the AFX constraint system, Player Movement effects 'steer' the player using the same mechanisms that allow "
  39. "Player control from mouse and keyboard input. Another difference is that Player Movement effects only influence the "
  40. "server instance of a Player. Puppet effects can influence both the Player's server instance and its client ghosts."
  41. "\n\n"
  42. "@ingroup afxEffects\n"
  43. "@ingroup AFX\n"
  44. "@ingroup Datablocks\n"
  45. );
  46. static Point3F default_movement(F32_MAX, F32_MAX, F32_MAX);
  47. afxPlayerMovementData::afxPlayerMovementData()
  48. {
  49. speed_bias = 1.0f;
  50. movement = default_movement;
  51. movement_op = OP_MULTIPLY;
  52. }
  53. afxPlayerMovementData::afxPlayerMovementData(const afxPlayerMovementData& other, bool temp_clone) : GameBaseData(other, temp_clone)
  54. {
  55. speed_bias = other.speed_bias;
  56. movement = other.movement;
  57. movement_op = other.movement_op;
  58. }
  59. ImplementEnumType( afxPlayerMovement_OpType, "Possible player movement operation types.\n" "@ingroup afxPlayerMovemen\n\n" )
  60. { afxPlayerMovementData::OP_ADD, "add", "..." },
  61. { afxPlayerMovementData::OP_MULTIPLY, "multiply", "..." },
  62. { afxPlayerMovementData::OP_REPLACE, "replace", "..." },
  63. { afxPlayerMovementData::OP_MULTIPLY, "mult", "..." },
  64. EndImplementEnumType;
  65. #define myOffset(field) Offset(field, afxPlayerMovementData)
  66. void afxPlayerMovementData::initPersistFields()
  67. {
  68. addField("speedBias", TypeF32, myOffset(speed_bias),
  69. "A floating-point multiplier that scales the constraint Player's movement speed.");
  70. addField("movement", TypePoint3F, myOffset(movement),
  71. "");
  72. addField("movementOp", TYPEID<afxPlayerMovementData::OpType>(), myOffset(movement_op),
  73. "Possible values: add, multiply, or replace.");
  74. Parent::initPersistFields();
  75. }
  76. bool afxPlayerMovementData::onAdd()
  77. {
  78. if (Parent::onAdd() == false)
  79. return false;
  80. return true;
  81. }
  82. void afxPlayerMovementData::packData(BitStream* stream)
  83. {
  84. Parent::packData(stream);
  85. stream->write(speed_bias);
  86. if (stream->writeFlag(movement != default_movement))
  87. {
  88. stream->write(movement.x);
  89. stream->write(movement.y);
  90. stream->write(movement.z);
  91. stream->writeInt(movement_op, OP_BITS);
  92. }
  93. }
  94. void afxPlayerMovementData::unpackData(BitStream* stream)
  95. {
  96. Parent::unpackData(stream);
  97. stream->read(&speed_bias);
  98. if (stream->readFlag())
  99. {
  100. stream->read(&movement.x);
  101. stream->read(&movement.y);
  102. stream->read(&movement.z);
  103. movement_op = stream->readInt(OP_BITS);
  104. }
  105. else
  106. {
  107. movement = default_movement;
  108. movement_op = OP_MULTIPLY;
  109. }
  110. }
  111. bool afxPlayerMovementData::hasMovementOverride()
  112. {
  113. return (movement != default_movement);
  114. }
  115. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//