W3DTreeDraw.cpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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: W3DTreeDraw.cpp ////////////////////////////////////////////////////////////////////////
  24. // Author: Colin Day, December 2001
  25. // Desc: Tracer drawing
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include <stdlib.h>
  29. #include "Common/Thing.h"
  30. #include "Common/ThingTemplate.h"
  31. #include "Common/Xfer.h"
  32. #include "GameLogic/Object.h"
  33. #include "GameClient/Drawable.h"
  34. #include "W3DDevice/GameClient/Module/W3DTreeDraw.h"
  35. #include "W3DDevice/GameClient/BaseHeightMap.h"
  36. #ifdef _INTERNAL
  37. // for occasional debugging...
  38. //#pragma optimize("", off)
  39. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  40. #endif
  41. //-------------------------------------------------------------------------------------------------
  42. W3DTreeDrawModuleData::W3DTreeDrawModuleData() :
  43. m_framesToMoveInward(1),
  44. m_framesToMoveOutward(1),
  45. m_darkening(0.0f),
  46. m_maxOutwardMovement(1.0f)
  47. {
  48. // Topple parameters. [7/7/2003]
  49. const Real START_VELOCITY_PERCENT = 0.2f;
  50. const Real START_ACCEL_PERCENT = 0.01f;
  51. const Real VELOCITY_BOUNCE_PERCENT = 0.3f; // multiply the velocity by this when you bounce
  52. const Real MINIMUM_TOPPLE_SPEED = 0.5f; // Won't let trees fall slower than this
  53. m_toppleFX = NULL;
  54. m_bounceFX = NULL;
  55. m_stumpName.clear();
  56. m_killWhenToppled = true;
  57. m_doTopple = false;
  58. m_doShadow = false;
  59. m_initialVelocityPercent = START_VELOCITY_PERCENT;
  60. m_initialAccelPercent = START_ACCEL_PERCENT;
  61. m_bounceVelocityPercent = VELOCITY_BOUNCE_PERCENT;
  62. m_minimumToppleSpeed = MINIMUM_TOPPLE_SPEED;
  63. m_sinkFrames = 10*LOGICFRAMES_PER_SECOND;
  64. m_sinkDistance = 20.0f;
  65. }
  66. //-------------------------------------------------------------------------------------------------
  67. W3DTreeDrawModuleData::~W3DTreeDrawModuleData()
  68. {
  69. }
  70. //-------------------------------------------------------------------------------------------------
  71. void W3DTreeDrawModuleData::buildFieldParse(MultiIniFieldParse& p)
  72. {
  73. ModuleData::buildFieldParse(p);
  74. static const FieldParse dataFieldParse[] =
  75. {
  76. { "ModelName", INI::parseAsciiString, NULL, offsetof(W3DTreeDrawModuleData, m_modelName) },
  77. { "TextureName", INI::parseAsciiString, NULL, offsetof(W3DTreeDrawModuleData, m_textureName) },
  78. { "MoveOutwardTime", INI::parseDurationUnsignedInt, NULL, offsetof(W3DTreeDrawModuleData, m_framesToMoveOutward) },
  79. { "MoveInwardTime", INI::parseDurationUnsignedInt, NULL, offsetof(W3DTreeDrawModuleData, m_framesToMoveInward) },
  80. { "MoveOutwardDistanceFactor", INI::parseReal, NULL, offsetof(W3DTreeDrawModuleData, m_maxOutwardMovement) },
  81. { "DarkeningFactor", INI::parseReal, NULL, offsetof(W3DTreeDrawModuleData, m_darkening) },
  82. // Topple parameters [7/7/2003]
  83. { "ToppleFX", INI::parseFXList, NULL, offsetof( W3DTreeDrawModuleData, m_toppleFX ) },
  84. { "BounceFX", INI::parseFXList, NULL, offsetof( W3DTreeDrawModuleData, m_bounceFX ) },
  85. { "StumpName", INI::parseAsciiString, NULL, offsetof( W3DTreeDrawModuleData, m_stumpName ) },
  86. { "KillWhenFinishedToppling", INI::parseBool, NULL, offsetof( W3DTreeDrawModuleData, m_killWhenToppled ) },
  87. { "DoTopple", INI::parseBool, NULL, offsetof( W3DTreeDrawModuleData, m_doTopple ) },
  88. { "InitialVelocityPercent", INI::parsePercentToReal, NULL, offsetof( W3DTreeDrawModuleData, m_initialVelocityPercent ) },
  89. { "InitialAccelPercent", INI::parsePercentToReal, NULL, offsetof( W3DTreeDrawModuleData, m_initialAccelPercent ) },
  90. { "BounceVelocityPercent", INI::parsePercentToReal, NULL, offsetof( W3DTreeDrawModuleData, m_bounceVelocityPercent ) },
  91. { "MinimumToppleSpeed", INI::parsePositiveNonZeroReal, NULL, offsetof( W3DTreeDrawModuleData, m_minimumToppleSpeed ) },
  92. { "SinkDistance", INI::parsePositiveNonZeroReal, NULL, offsetof( W3DTreeDrawModuleData, m_sinkDistance ) },
  93. { "SinkTime", INI::parseDurationUnsignedInt, NULL, offsetof(W3DTreeDrawModuleData, m_sinkFrames) },
  94. { "DoShadow", INI::parseBool, NULL, offsetof( W3DTreeDrawModuleData, m_doShadow ) },
  95. { 0, 0, 0, 0 }
  96. };
  97. p.add(dataFieldParse);
  98. }
  99. ///////////////////////////////////////////////////////////////////////////////////////////////////
  100. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////////////////////////
  101. ///////////////////////////////////////////////////////////////////////////////////////////////////
  102. //-------------------------------------------------------------------------------------------------
  103. //-------------------------------------------------------------------------------------------------
  104. W3DTreeDraw::W3DTreeDraw( Thing *thing, const ModuleData* moduleData ) : DrawModule( thing, moduleData ),
  105. m_treeAdded(false)
  106. {
  107. } // end W3DTreeDraw
  108. //-------------------------------------------------------------------------------------------------
  109. //-------------------------------------------------------------------------------------------------
  110. W3DTreeDraw::~W3DTreeDraw( void )
  111. {
  112. }
  113. //-------------------------------------------------------------------------------------------------
  114. void W3DTreeDraw::reactToTransformChange( const Matrix3D *oldMtx,
  115. const Coord3D *oldPos,
  116. Real oldAngle )
  117. {
  118. Drawable *draw = getDrawable();
  119. if (m_treeAdded) {
  120. return;
  121. }
  122. if (draw->getPosition()->x==0.0f && draw->getPosition()->y == 0.0f) {
  123. return;
  124. }
  125. m_treeAdded = true;
  126. const W3DTreeDrawModuleData *moduleData = getW3DTreeDrawModuleData();
  127. if (!moduleData) {
  128. return;
  129. }
  130. Real scale = draw->getScale();
  131. Real scaleRandomness = draw->getTemplate()->getInstanceScaleFuzziness();
  132. scaleRandomness = 0.0f; // We use the scale fuzziness inside WB to generate random scales, so they don't change at load time. jba. [4/22/2003]
  133. TheTerrainRenderObject->addTree(draw->getID(), *draw->getPosition(),
  134. scale, draw->getOrientation(), scaleRandomness, moduleData);
  135. }
  136. //-------------------------------------------------------------------------------------------------
  137. //-------------------------------------------------------------------------------------------------
  138. void W3DTreeDraw::doDrawModule(const Matrix3D* transformMtx)
  139. {
  140. return;
  141. }
  142. // ------------------------------------------------------------------------------------------------
  143. /** CRC */
  144. // ------------------------------------------------------------------------------------------------
  145. void W3DTreeDraw::crc( Xfer *xfer )
  146. {
  147. // extend base class
  148. DrawModule::crc( xfer );
  149. } // end crc
  150. // ------------------------------------------------------------------------------------------------
  151. /** Xfer method
  152. * Version Info:
  153. * 1: Initial version */
  154. // ------------------------------------------------------------------------------------------------
  155. void W3DTreeDraw::xfer( Xfer *xfer )
  156. {
  157. // version
  158. XferVersion currentVersion = 1;
  159. XferVersion version = currentVersion;
  160. xfer->xferVersion( &version, currentVersion );
  161. // extend base class
  162. DrawModule::xfer( xfer );
  163. // no data to save here, nobody will ever notice
  164. } // end xfer
  165. // ------------------------------------------------------------------------------------------------
  166. /** Load post process */
  167. // ------------------------------------------------------------------------------------------------
  168. void W3DTreeDraw::loadPostProcess( void )
  169. {
  170. // extend base class
  171. DrawModule::loadPostProcess();
  172. } // end loadPostProcess