W3DWaterTracks.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. ** Command & Conquer Generals(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. #pragma once
  24. #ifndef __W3DWaterTracks_H_
  25. #define __W3DWaterTracks_H_
  26. enum waveType; //forward reference
  27. /// Custom render object that draws animated tracks/waves on the water.
  28. /**
  29. This is an object which draws a small breaking wave or splash animation. These objects are
  30. to be managed/accessed only by the WaterTracksRenderObjClassSystem
  31. */
  32. class WaterTracksObj
  33. {
  34. friend class WaterTracksRenderSystem;
  35. public:
  36. WaterTracksObj(void);
  37. ~WaterTracksObj(void);
  38. virtual void Render(void) {}; ///<draw this object
  39. virtual void Get_Obj_Space_Bounding_Sphere(SphereClass & sphere) const; ///<bounding sphere of this object
  40. virtual void Get_Obj_Space_Bounding_Box(AABoxClass & aabox) const; ///<bounding box of this object
  41. Int freeWaterTracksResources(void); ///<free W3D assets used for this track
  42. void init( Real width, Real length, Vector2 &start, Vector2 &end, Char *texturename, Int waveTimeOffset); ///<allocate W3D resources and set size
  43. void init( Real width, Vector2 &start, Vector2 &end, Char *texturename); ///<allocate W3D resources and set size
  44. Int update(Int msElapsed); ///< update animation state
  45. Int render(DX8VertexBufferClass *vertexBuffer, Int batchStart); ///<draw this object
  46. protected:
  47. TextureClass *m_stageZeroTexture; ///<primary texture
  48. SphereClass m_boundingSphere; ///<bounding sphere of WaterTracks
  49. AABoxClass m_boundingBox; ///<bounding box of WaterTracks
  50. waveType m_type; ///<used for render state sorting (set this to texture pointer for now).
  51. Int m_x; ///<vertex count
  52. Int m_y; ///<vertex count
  53. Bool m_bound; ///<object is bound to owner and accepts new edges
  54. Vector2 m_startPos; ///<starting position of wave
  55. // Vector2 m_endPos; ///<ending position of wave
  56. Vector2 m_waveDir; ///<direction of wave travel
  57. Vector2 m_perpDir; ///<direction perpendicular to wave travel
  58. Vector2 m_initStartPos; ///<original settings used to create wave
  59. Vector2 m_initEndPos; ///<original settings used to create wave
  60. Int m_initTimeOffset; ///<time offset when wave is added into the system
  61. Int m_fadeMs; ///<time for wave to fade out after it stops moving
  62. Int m_totalMs; ///<amount of time to complete full motion
  63. Int m_elapsedMs; ///<amount of time since start of motion
  64. //New version
  65. Real m_waveInitialWidth; ///<width of wave segment when it first appears
  66. Real m_waveInitialHeight; ///<height of wave segment when it first appears
  67. Real m_waveFinalWidth; ///<width of wave segment at full size
  68. Real m_waveFinalWidthPeakFrac; ///<fraction along path when wave reaches full width
  69. Real m_waveFinalHeight; ///<final height of unstretched wave
  70. Real m_initialVelocity; //initial velocity in world units per ms.
  71. Real m_waveDistance; //<total distance traveled by wave front.
  72. Real m_timeToReachBeach;
  73. Real m_frontSlowDownAcc;
  74. Real m_timeToStop;
  75. Real m_timeToRetreat;
  76. Real m_backSlowDownAcc;
  77. Real m_timeToCompress;
  78. Real m_flipU; ///<force uv coordinates to flip
  79. WaterTracksObj *m_nextSystem; ///<next track in system
  80. WaterTracksObj *m_prevSystem; ///<previous track in system
  81. };
  82. /// System for drawing, updating, and re-using water mark render objects.
  83. /**
  84. This system keeps track of all the active track mark objects and reuses them
  85. when they expire. It also renders all the track marks that were submitted in
  86. this frame.
  87. */
  88. class WaterTracksRenderSystem
  89. {
  90. friend class WaterTracksObj;
  91. public:
  92. WaterTracksRenderSystem( void );
  93. ~WaterTracksRenderSystem( void );
  94. void ReleaseResources(void); ///< Release all dx8 resources so the device can be reset.
  95. void ReAcquireResources(void); ///< Reacquire all resources after device reset.
  96. void flush (RenderInfoClass & rinfo); ///<draw all tracks that were requested for rendering.
  97. void update(void); ///<update the state of all edges (fade alpha, remove old, etc.)
  98. void init(void); ///< pre-allocate track objects
  99. void shutdown( void ); ///< release all pre-allocated track objects, called by destructor
  100. void reset(void); ///< free all map dependent items.
  101. WaterTracksObj *bindTrack(waveType type); ///<track object to be controlled by owner
  102. void unbindTrack( WaterTracksObj *mod ); ///<releases control of track object
  103. void saveTracks(void); ///<save all used tracks to disk
  104. void loadTracks(void); ///<load tracks from disk
  105. WaterTracksObj *findTrack(Vector2 &start, Vector2 &end, waveType type);
  106. protected:
  107. DX8VertexBufferClass *m_vertexBuffer; ///<vertex buffer used to draw all tracks
  108. DX8IndexBufferClass *m_indexBuffer; ///<indices defining triangles in maximum length track
  109. VertexMaterialClass *m_vertexMaterialClass; ///< vertex lighting material
  110. ShaderClass m_shaderClass; ///<shader or rendering state for heightmap
  111. WaterTracksObj *m_usedModules; ///<active objects being rendered in the scene
  112. WaterTracksObj *m_freeModules; //<unused modules that are free to use again
  113. Int m_stripSizeX; ///< resolution (vertex count) of wave strip
  114. Int m_stripSizeY; ///< resolution (vertex count) of wave strip
  115. Int m_batchStart; ///< start of unused vertices in vertex buffer
  116. Real m_level; ///< water level
  117. void releaseTrack( WaterTracksObj *mod ); ///<returns track object to free store.
  118. }; // end class WaterTracksRenderObjClassSystem
  119. #endif //__W3DWaterTracks_H_