TerrainVisual.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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.h //////////////////////////////////////////////////////////////////////////
  24. // Interface for visual representation of terrain on the client
  25. // Author: Colin Day, April 2001
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #pragma once
  28. #ifndef __TERRAINVISUAL_H_
  29. #define __TERRAINVISUAL_H_
  30. #include "Common/Terrain.h"
  31. #include "Common/Snapshot.h"
  32. #include "Common/MapObject.h"
  33. // FORWARD REFERENCES /////////////////////////////////////////////////////////////////////////////
  34. class TerrainType;
  35. class WaterHandle;
  36. class Matrix3D;
  37. class Object;
  38. class Drawable;
  39. class GeometryInfo;
  40. class WorldHeightMap;
  41. struct SeismicSimulationNode;
  42. class SeismicSimulationFilterBase;
  43. #define DEFAULT_SEISMIC_SIMULATION_MAGNITUDE (20.0f)
  44. struct SeismicSimulationNode; // just a forward declaration folks, no cause for alarm
  45. class SeismicSimulationFilterBase
  46. {
  47. public:
  48. enum SeismicSimStatusCode
  49. {
  50. SEISMIC_STATUS_INVALID,
  51. SEISMIC_STATUS_ACTIVE,
  52. SEISMIC_STATUS_ZERO_ENERGY,
  53. };
  54. virtual SeismicSimStatusCode filterCallback( WorldHeightMapInterfaceClass *heightMap, const SeismicSimulationNode *node ) = 0;
  55. virtual Real applyGravityCallback( Real velocityIn ) = 0;
  56. };
  57. struct SeismicSimulationNode
  58. {
  59. SeismicSimulationNode()
  60. {
  61. m_center.x = 0;
  62. m_center.y = 0;
  63. m_radius = 0;
  64. m_region.lo.x = 0;
  65. m_region.lo.y = 0;
  66. m_region.hi.x = 0;
  67. m_region.hi.y = 0;
  68. m_clean = FALSE;
  69. callbackFilter = NULL;
  70. m_life = 0;
  71. m_magnitude = DEFAULT_SEISMIC_SIMULATION_MAGNITUDE;
  72. }
  73. SeismicSimulationNode( const SeismicSimulationNode &ssn )
  74. {
  75. m_center.x = ssn.m_center.x;
  76. m_center.y = ssn.m_center.y;
  77. m_radius = ssn.m_radius;
  78. m_region.lo.x = ssn.m_region.lo.x;
  79. m_region.lo.y = ssn.m_region.lo.y;
  80. m_region.hi.x = ssn.m_region.hi.x;
  81. m_region.hi.y = ssn.m_region.hi.y;
  82. m_clean = ssn.m_clean;
  83. callbackFilter= ssn.callbackFilter;
  84. m_life = ssn.m_life;
  85. m_magnitude = ssn.m_magnitude;
  86. }
  87. SeismicSimulationNode( const Coord3D* ctr, Real rad, Real mag, SeismicSimulationFilterBase *cbf = NULL )
  88. {
  89. m_center.x = REAL_TO_INT_FLOOR(ctr->x/MAP_XY_FACTOR);
  90. m_center.y = REAL_TO_INT_FLOOR(ctr->y/MAP_XY_FACTOR);
  91. m_radius = (rad-1)/MAP_XY_FACTOR;
  92. UnsignedInt regionSize = rad/MAP_XY_FACTOR;
  93. m_region.lo.x = m_center.x - regionSize;
  94. m_region.lo.y = m_center.y - regionSize;
  95. m_region.hi.x = m_center.x + regionSize;
  96. m_region.hi.y = m_center.y + regionSize;
  97. m_clean = false;
  98. callbackFilter= cbf;
  99. m_life = 0;
  100. m_magnitude = mag;
  101. }
  102. SeismicSimulationFilterBase::SeismicSimStatusCode handleFilterCallback( WorldHeightMapInterfaceClass *heightMap )
  103. {
  104. if ( callbackFilter == NULL )
  105. return SeismicSimulationFilterBase::SEISMIC_STATUS_INVALID;
  106. ++m_life;
  107. return callbackFilter->filterCallback( heightMap, this );
  108. }
  109. Real applyGravity( Real velocityIn )
  110. {
  111. DEBUG_ASSERTCRASH( callbackFilter, ("SeismicSimulationNode::applyGravity() has no callback filter!") );
  112. if ( callbackFilter == NULL )
  113. return velocityIn;//oops, we have no callback!
  114. return callbackFilter->applyGravityCallback( velocityIn );
  115. }
  116. IRegion2D m_region;
  117. ICoord2D m_center;
  118. Bool m_clean;
  119. Real m_magnitude;
  120. UnsignedInt m_radius;
  121. UnsignedInt m_life;
  122. SeismicSimulationFilterBase *callbackFilter;
  123. };
  124. typedef std::list<SeismicSimulationNode> SeismicSimulationList;
  125. typedef SeismicSimulationList::iterator SeismicSimulationListIt;
  126. class DomeStyleSeismicFilter : public SeismicSimulationFilterBase
  127. {
  128. virtual SeismicSimStatusCode filterCallback( WorldHeightMapInterfaceClass *heightMap, const SeismicSimulationNode *node );
  129. virtual Real applyGravityCallback( Real velocityIn );
  130. };
  131. //-------------------------------------------------------------------------------------------------
  132. /** LOD values for terrain, keep this in sync with TerrainLODNames[] */
  133. //-------------------------------------------------------------------------------------------------
  134. typedef enum _TerrainLOD
  135. {
  136. TERRAIN_LOD_INVALID = 0,
  137. TERRAIN_LOD_MIN = 1, // note that this is less than max
  138. TERRAIN_LOD_STRETCH_NO_CLOUDS = 2,
  139. TERRAIN_LOD_HALF_CLOUDS = 3,
  140. TERRAIN_LOD_NO_CLOUDS = 4,
  141. TERRAIN_LOD_STRETCH_CLOUDS = 5,
  142. TERRAIN_LOD_NO_WATER = 6,
  143. TERRAIN_LOD_MAX = 7, // note that this is larger than min
  144. TERRAIN_LOD_AUTOMATIC = 8,
  145. TERRAIN_LOD_DISABLE = 9,
  146. TERRAIN_LOD_NUM_TYPES // keep this last
  147. } TerrainLOD;
  148. #ifdef DEFINE_TERRAIN_LOD_NAMES
  149. static char * TerrainLODNames[] =
  150. {
  151. "NONE",
  152. "MIN",
  153. "STRETCH_NO_CLOUDS",
  154. "HALF_CLOUDS",
  155. "NO_CLOUDS",
  156. "STRETCH_CLOUDS",
  157. "NO_WATER",
  158. "MAX",
  159. "AUTOMATIC",
  160. "DISABLE",
  161. NULL
  162. };
  163. #endif // end DEFINE_TERRAIN_LOD_NAMES
  164. //-------------------------------------------------------------------------------------------------
  165. /** Device independent implementation for visual terrain */
  166. //-------------------------------------------------------------------------------------------------
  167. class TerrainVisual : public Snapshot,
  168. public SubsystemInterface
  169. {
  170. public:
  171. enum {NumSkyboxTextures = 5};
  172. TerrainVisual();
  173. virtual ~TerrainVisual();
  174. virtual void init( void );
  175. virtual void reset( void );
  176. virtual void update( void );
  177. virtual Bool load( AsciiString filename );
  178. /// get color of texture on the terrain at location specified
  179. virtual void getTerrainColorAt( Real x, Real y, RGBColor *pColor ) = 0;
  180. /// get the terrain tile type at the world location in the (x,y) plane ignoring Z
  181. virtual TerrainType *getTerrainTile( Real x, Real y ) = 0;
  182. /** intersect the ray with the terrain, if a hit occurs TRUE is returned
  183. and the result point on the terrain is returned in "result" */
  184. virtual Bool intersectTerrain( Coord3D *rayStart,
  185. Coord3D *rayEnd,
  186. Coord3D *result ) { return FALSE; }
  187. //
  188. // water methods
  189. //
  190. virtual void enableWaterGrid( Bool enable ) = 0;
  191. /// set min/max height values allowed in water grid pointed to by waterTable
  192. virtual void setWaterGridHeightClamps( const WaterHandle *waterTable, Real minZ, Real maxZ ) = 0;
  193. /// adjust fallof parameters for grid change method
  194. virtual void setWaterAttenuationFactors( const WaterHandle *waterTable, Real a, Real b, Real c, Real range ) = 0;
  195. /// set the water table position and orientation in world space
  196. virtual void setWaterTransform( const WaterHandle *waterTable, Real angle, Real x, Real y, Real z ) = 0;
  197. virtual void setWaterTransform( const Matrix3D *transform ) = 0;
  198. /// get water transform parameters
  199. virtual void getWaterTransform( const WaterHandle *waterTable, Matrix3D *transform ) = 0;
  200. /// water grid resolution spacing
  201. virtual void setWaterGridResolution( const WaterHandle *waterTable, Real gridCellsX, Real gridCellsY, Real cellSize ) = 0;
  202. virtual void getWaterGridResolution( const WaterHandle *waterTable, Real *gridCellsX, Real *gridCellsY, Real *cellSize ) = 0;
  203. /// adjust the water grid in world coords by the delta
  204. virtual void changeWaterHeight( Real x, Real y, Real delta ) = 0;
  205. /// adjust the velocity at a water grid point corresponding to the world x,y
  206. virtual void addWaterVelocity( Real worldX, Real worldY, Real velocity, Real preferredHeight ) = 0;
  207. /// get height of water grid at specified position
  208. virtual Bool getWaterGridHeight( Real worldX, Real worldY, Real *height) = 0;
  209. /// set detail of terrain tracks.
  210. virtual void setTerrainTracksDetail(void)=0;
  211. virtual void setShoreLineDetail(void)=0;
  212. /// Add a bib for an object at location.
  213. virtual void addFactionBib(Object *factionBuilding, Bool highlight, Real extra = 0)=0;
  214. /// Remove a bib.
  215. virtual void removeFactionBib(Object *factionBuilding)=0;
  216. /// Add a bib for a drawable at location.
  217. virtual void addFactionBibDrawable(Drawable *factionBuilding, Bool highlight, Real extra = 0)=0;
  218. /// Remove a bib.
  219. virtual void removeFactionBibDrawable(Drawable *factionBuilding)=0;
  220. virtual void removeAllBibs(void)=0;
  221. virtual void removeBibHighlighting(void)=0;
  222. virtual void removeTreesAndPropsForConstruction(
  223. const Coord3D* pos,
  224. const GeometryInfo& geom,
  225. Real angle
  226. ) = 0;
  227. virtual void addProp(const ThingTemplate *tt, const Coord3D *pos, Real angle) = 0;
  228. //
  229. // Modify height.
  230. //
  231. virtual void setRawMapHeight(const ICoord2D *gridPos, Int height)=0;
  232. virtual Int getRawMapHeight(const ICoord2D *gridPos)=0;
  233. ////////////////////////////////////////////////////
  234. ////////////////////////////////////////////////////
  235. ////////////////////////////////////////////////////
  236. #ifdef DO_SEISMIC_SIMULATIONS
  237. virtual void updateSeismicSimulations( void ) = 0; /// walk the SeismicSimulationList and, well, do it.
  238. virtual void addSeismicSimulation( const SeismicSimulationNode& sim ) = 0;
  239. #endif
  240. virtual WorldHeightMap* getLogicHeightMap( void ) {return NULL;};
  241. virtual WorldHeightMap* getClientHeightMap( void ) {return NULL;};
  242. ////////////////////////////////////////////////////
  243. ////////////////////////////////////////////////////
  244. ////////////////////////////////////////////////////
  245. /// Replace the skybox texture
  246. virtual void replaceSkyboxTextures(const AsciiString *oldTexName[NumSkyboxTextures], const AsciiString *newTexName[NumSkyboxTextures])=0;
  247. protected:
  248. // snapshot methods
  249. virtual void crc( Xfer *xfer );
  250. virtual void xfer( Xfer *xfer );
  251. virtual void loadPostProcess( void );
  252. AsciiString m_filenameString; ///< file with terrain data
  253. }; // end class TerrainVisual
  254. // EXTERNALS //////////////////////////////////////////////////////////////////////////////////////
  255. extern TerrainVisual *TheTerrainVisual; ///< singleton extern
  256. #endif // end __TERRAINVISUAL_H_