AnimationSteeringUpdate.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: AnimationSteeringUpdate.cpp //////////////////////////////////////////////////////////////////////////
  24. // Author: Kris Morness, May 2003
  25. // Desc: Uses animation states to handle steering.
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // USER INCLUDES //////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  29. #include "Common/ModelState.h"
  30. #include "Common/Xfer.h"
  31. #include "GameClient/Drawable.h"
  32. #include "GameLogic/GameLogic.h"
  33. #include "GameLogic/Object.h"
  34. #include "GameLogic/Module/AnimationSteeringUpdate.h"
  35. #include "GameLogic/Module/PhysicsUpdate.h"
  36. //-------------------------------------------------------------------------------------------------
  37. //-------------------------------------------------------------------------------------------------
  38. AnimationSteeringUpdateModuleData::AnimationSteeringUpdateModuleData( void )
  39. {
  40. m_transitionFrames = 0;
  41. }
  42. ///////////////////////////////////////////////////////////////////////////////////////////////////
  43. ///////////////////////////////////////////////////////////////////////////////////////////////////
  44. ///////////////////////////////////////////////////////////////////////////////////////////////////
  45. //-------------------------------------------------------------------------------------------------
  46. //-------------------------------------------------------------------------------------------------
  47. AnimationSteeringUpdate::AnimationSteeringUpdate( Thing *thing, const ModuleData *moduleData )
  48. : UpdateModule( thing, moduleData )
  49. {
  50. m_currentTurnAnim = MODELCONDITION_INVALID;
  51. m_nextTransitionFrame = 0;
  52. }
  53. //-------------------------------------------------------------------------------------------------
  54. //-------------------------------------------------------------------------------------------------
  55. AnimationSteeringUpdate::~AnimationSteeringUpdate( void )
  56. {
  57. }
  58. //-------------------------------------------------------------------------------------------------
  59. //-------------------------------------------------------------------------------------------------
  60. UpdateSleepTime AnimationSteeringUpdate::update( void )
  61. {
  62. const AnimationSteeringUpdateModuleData *data = getAnimationSteeringUpdateModuleData();
  63. PhysicsBehavior *physics = getObject()->getPhysics();
  64. Drawable *draw = getObject()->getDrawable();
  65. UnsignedInt now = TheGameLogic->getFrame();
  66. if( physics && draw && now >= m_nextTransitionFrame )
  67. {
  68. PhysicsTurningType currentTurn = physics->getTurning();
  69. switch( m_currentTurnAnim )
  70. {
  71. case MODELCONDITION_INVALID:
  72. //We're currently going straight. Check if we want to turn.
  73. if( currentTurn == TURN_NEGATIVE )
  74. {
  75. //Initiate a right turn
  76. draw->setModelConditionState( MODELCONDITION_CENTER_TO_RIGHT );
  77. m_nextTransitionFrame = now + data->m_transitionFrames;
  78. m_currentTurnAnim = MODELCONDITION_CENTER_TO_RIGHT;
  79. }
  80. else if( currentTurn == TURN_POSITIVE )
  81. {
  82. //Initiate a left turn
  83. draw->setModelConditionState( MODELCONDITION_CENTER_TO_LEFT );
  84. m_nextTransitionFrame = now + data->m_transitionFrames;
  85. m_currentTurnAnim = MODELCONDITION_CENTER_TO_LEFT;
  86. }
  87. break;
  88. case MODELCONDITION_CENTER_TO_RIGHT:
  89. //We're currently initiating a turn to the right. The only thing
  90. //we can do go back to center or maintain the turn.
  91. if( currentTurn != TURN_NEGATIVE )
  92. {
  93. //Recenter!
  94. draw->clearAndSetModelConditionState( MODELCONDITION_CENTER_TO_RIGHT, MODELCONDITION_RIGHT_TO_CENTER );
  95. m_nextTransitionFrame = now + data->m_transitionFrames;
  96. m_currentTurnAnim = MODELCONDITION_RIGHT_TO_CENTER;
  97. }
  98. break;
  99. case MODELCONDITION_CENTER_TO_LEFT:
  100. //We're currently initiating a turn to the left. The only thing
  101. //we can do go back to center or maintain the turn.
  102. if( currentTurn != TURN_POSITIVE )
  103. {
  104. //Recenter!
  105. draw->clearAndSetModelConditionState( MODELCONDITION_CENTER_TO_LEFT, MODELCONDITION_LEFT_TO_CENTER );
  106. m_nextTransitionFrame = now + data->m_transitionFrames;
  107. m_currentTurnAnim = MODELCONDITION_LEFT_TO_CENTER;
  108. }
  109. break;
  110. case MODELCONDITION_LEFT_TO_CENTER:
  111. case MODELCONDITION_RIGHT_TO_CENTER:
  112. if( currentTurn == TURN_NONE )
  113. {
  114. //Finish the turn
  115. draw->clearModelConditionFlags( MAKE_MODELCONDITION_MASK2( MODELCONDITION_LEFT_TO_CENTER, MODELCONDITION_RIGHT_TO_CENTER ) );
  116. m_nextTransitionFrame = now;
  117. m_currentTurnAnim = MODELCONDITION_INVALID;
  118. }
  119. break;
  120. }
  121. }
  122. return UPDATE_SLEEP_NONE;
  123. }
  124. // ------------------------------------------------------------------------------------------------
  125. /** CRC */
  126. // ------------------------------------------------------------------------------------------------
  127. void AnimationSteeringUpdate::crc( Xfer *xfer )
  128. {
  129. // extend base class
  130. UpdateModule::crc( xfer );
  131. } // end crc
  132. // ------------------------------------------------------------------------------------------------
  133. /** Xfer method
  134. * Version Info:
  135. * 1: Initial version */
  136. // ------------------------------------------------------------------------------------------------
  137. void AnimationSteeringUpdate::xfer( Xfer *xfer )
  138. {
  139. // version
  140. XferVersion currentVersion = 1;
  141. XferVersion version = currentVersion;
  142. xfer->xferVersion( &version, currentVersion );
  143. // extend base class
  144. UpdateModule::xfer( xfer );
  145. }
  146. // ------------------------------------------------------------------------------------------------
  147. /** Load post process */
  148. // ------------------------------------------------------------------------------------------------
  149. void AnimationSteeringUpdate::loadPostProcess( void )
  150. {
  151. // extend base class
  152. UpdateModule::loadPostProcess();
  153. }