TerrainVisual.cpp 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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: TerrainVisual.cpp ////////////////////////////////////////////////////////////////////////
  24. // Interface for visual representation of terrain on the client
  25. // Author: Colin Day, April 2001
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  28. #include "Common/Xfer.h"
  29. #include "GameClient/TerrainVisual.h"
  30. #ifdef _INTERNAL
  31. // for occasional debugging...
  32. //#pragma optimize("", off)
  33. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  34. #endif
  35. // GLOBALS ////////////////////////////////////////////////////////////////////////////////////////
  36. TerrainVisual *TheTerrainVisual = NULL;
  37. ///////////////////////////////////////////////////////////////////////////////////////////////////
  38. // DEFINITIONS
  39. ///////////////////////////////////////////////////////////////////////////////////////////////////
  40. //-------------------------------------------------------------------------------------------------
  41. //-------------------------------------------------------------------------------------------------
  42. TerrainVisual::TerrainVisual()
  43. {
  44. } // end TerrainVisual
  45. //-------------------------------------------------------------------------------------------------
  46. //-------------------------------------------------------------------------------------------------
  47. TerrainVisual::~TerrainVisual()
  48. {
  49. } // end ~TerrainVisual
  50. //-------------------------------------------------------------------------------------------------
  51. /** initialize the device independent functionality of the visual terrain */
  52. //-------------------------------------------------------------------------------------------------
  53. void TerrainVisual::init( void )
  54. {
  55. } // end init
  56. //-------------------------------------------------------------------------------------------------
  57. /** Reset */
  58. //-------------------------------------------------------------------------------------------------
  59. void TerrainVisual::reset( void )
  60. {
  61. m_filenameString.clear();
  62. } // end reset
  63. //-------------------------------------------------------------------------------------------------
  64. /** Update */
  65. //-------------------------------------------------------------------------------------------------
  66. void TerrainVisual::update( void )
  67. {
  68. // All the interesting stuff happens in load. jba.
  69. } // end update
  70. //-------------------------------------------------------------------------------------------------
  71. /** device independent implementation for common terrain visual systems */
  72. //-------------------------------------------------------------------------------------------------
  73. Bool TerrainVisual::load( AsciiString filename )
  74. {
  75. // save the filename
  76. if (filename.isEmpty())
  77. return FALSE;
  78. m_filenameString = filename;
  79. return TRUE;; // success
  80. } // end load
  81. // ------------------------------------------------------------------------------------------------
  82. /** CRC */
  83. // ------------------------------------------------------------------------------------------------
  84. void TerrainVisual::crc( Xfer *xfer )
  85. {
  86. } // end CRC
  87. // ------------------------------------------------------------------------------------------------
  88. /** Xfer
  89. * Version Info:
  90. * 1: Initial version */
  91. // ------------------------------------------------------------------------------------------------
  92. void TerrainVisual::xfer( Xfer *xfer )
  93. {
  94. // version
  95. XferVersion currentVersion = 1;
  96. XferVersion version = currentVersion;
  97. xfer->xferVersion( &version, currentVersion );
  98. } // end xfer
  99. // ------------------------------------------------------------------------------------------------
  100. /** Load post process */
  101. // ------------------------------------------------------------------------------------------------
  102. void TerrainVisual::loadPostProcess( void )
  103. {
  104. } // end loadPostProcess
  105. SeismicSimulationFilterBase::SeismicSimStatusCode DomeStyleSeismicFilter::filterCallback( WorldHeightMapInterfaceClass *heightMap, const SeismicSimulationNode *node )
  106. {
  107. Int life = node->m_life;
  108. if ( heightMap == NULL )
  109. return SEISMIC_STATUS_INVALID;
  110. if ( life == 0 )
  111. return SEISMIC_STATUS_ACTIVE;
  112. if ( life < 15 )
  113. {
  114. // ADD HEIGHT BECAUSE THE EXPLOSION IS PUSHING DIRT UP
  115. Real magnitude = node->m_magnitude;
  116. Real offsScalar = magnitude / (Real)life; // real-life, get it?
  117. Int radius = node->m_radius;
  118. Int border = heightMap->getBorderSize();
  119. Int centerX = node->m_center.x + border ;
  120. Int centerY = node->m_center.y + border ;
  121. UnsignedInt workspaceWidth = radius*2;
  122. Real *workspace = NEW( Real[ sqr(workspaceWidth) ] );
  123. Real *workspaceEnd = workspace + sqr(workspaceWidth);
  124. for ( Real *t = workspace; t < workspaceEnd; ++t ) *t = 0.0f;// clear the workspace
  125. for (Int x = 0; x < radius; ++x)
  126. {
  127. for (Int y = 0; y < radius; ++y)
  128. {
  129. Real distance = sqrt( sqr(x) + sqr(y) );//Pythagoras
  130. if ( distance < radius )
  131. {
  132. Real distScalar = cos( ( distance / radius * (PI/2) ) );
  133. Real height = (offsScalar * distScalar);
  134. workspace[ (radius + x) + workspaceWidth * (radius + y) ] = height + heightMap->getBilinearSampleSeismicZVelocity( centerX + x, centerY + y ) ;//kaleidoscope
  135. if ( x != 0 ) // non-zero test prevents cross-shaped double stamp
  136. {
  137. workspace[ (radius - x) + workspaceWidth * (radius + y) ] = height + heightMap->getBilinearSampleSeismicZVelocity( centerX - x, centerY + y ) ;
  138. if ( y != 0 )
  139. workspace[ (radius - x) + workspaceWidth * (radius - y) ] = height + heightMap->getBilinearSampleSeismicZVelocity( centerX - x, centerY - y ) ;
  140. }
  141. if ( y != 0 )
  142. workspace[ (radius + x) + workspaceWidth * (radius - y) ] = height + heightMap->getBilinearSampleSeismicZVelocity( centerX + x, centerY - y ) ;
  143. }
  144. }
  145. }
  146. // stuff the values from the workspace into the heightmap's velocities
  147. for (x = 0; x < workspaceWidth; ++x)
  148. for (Int y = 0; y < workspaceWidth; ++y)
  149. heightMap->setSeismicZVelocity( centerX - radius + x, centerY - radius + y, MIN( 9.0f, workspace[ x + workspaceWidth * y ]) );
  150. delete [] workspace;
  151. return SEISMIC_STATUS_ACTIVE;
  152. }
  153. else
  154. return SEISMIC_STATUS_ZERO_ENERGY;
  155. }
  156. Real DomeStyleSeismicFilter::applyGravityCallback( Real velocityIn )
  157. {
  158. Real velocityOut = velocityIn;
  159. velocityOut -= 1.5f;
  160. return velocityOut;
  161. }