W3DTerrainTracks.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 __W3DTERRAINTRACKS_H_
  25. #define __W3DTERRAINTRACKS_H_
  26. #include "always.h"
  27. #include "rendobj.h"
  28. #include "w3d_file.h"
  29. #include "dx8vertexbuffer.h"
  30. #include "dx8indexbuffer.h"
  31. #include "shader.h"
  32. #include "vertmaterial.h"
  33. #include "Lib/BaseType.h"
  34. #define MAX_TRACK_EDGE_COUNT 100 //maximum number of edges or divisions in track mark
  35. #define MAX_TRACK_OPAQUE_EDGE 25 //linear fade of edges will begin at this edge
  36. #define FADE_TIME_FRAMES 300000 // 300 seconds at 30 fps - time to fade out an edge and remove it from the system.
  37. class TerrainTracksRenderObjClassSystem;
  38. class Drawable;
  39. /// Custom render object that draws tracks on the terrain.
  40. /**
  41. This render object handles drawing tracks left by objects moving on the terrain.
  42. */
  43. class TerrainTracksRenderObjClass : public W3DMPO, public RenderObjClass
  44. {
  45. W3DMPO_GLUE(TerrainTracksRenderObjClass)
  46. friend class TerrainTracksRenderObjClassSystem;
  47. public:
  48. TerrainTracksRenderObjClass(void);
  49. ~TerrainTracksRenderObjClass(void);
  50. /////////////////////////////////////////////////////////////////////////////
  51. // Render Object Interface (W3D methods)
  52. /////////////////////////////////////////////////////////////////////////////
  53. virtual RenderObjClass * Clone(void) const;
  54. virtual int Class_ID(void) const;
  55. virtual void Render(RenderInfoClass & rinfo);
  56. virtual void Get_Obj_Space_Bounding_Sphere(SphereClass & sphere) const;
  57. virtual void Get_Obj_Space_Bounding_Box(AABoxClass & aabox) const;
  58. Int freeTerrainTracksResources(void); ///<free W3D assets used for this track
  59. void init( Real width, Real length, const Char *texturename); ///<allocate W3D resources and set size
  60. void addEdgeToTrack(Real x, Real y); ///< add a new segment to the track
  61. void addCapEdgeToTrack(Real x, Real y); ///< cap the existing segment so we can resume at an unconnected position.
  62. void setAirborne(void) {m_airborne = true; } ///< Starts a new section of track, generally after going airborne.
  63. void setOwnerDrawable(const Drawable *owner) {m_ownerDrawable = owner;}
  64. protected:
  65. TextureClass *m_stageZeroTexture; ///<primary texture
  66. SphereClass m_boundingSphere; ///<bounding sphere of TerrainTracks
  67. AABoxClass m_boundingBox; ///<bounding box of TerrainTracks
  68. Int m_activeEdgeCount; ///<number of active edges in segment list
  69. Int m_totalEdgesAdded; ///<number of edges ever added to this track
  70. const Drawable *m_ownerDrawable; ///<logical object that's laying down tread marks.
  71. struct edgeInfo{
  72. Vector3 endPointPos[2]; ///<the 2 endpoints on the edge
  73. Vector2 endPointUV[2]; ///< uv coordinates at each end point
  74. Int timeAdded; ///< time when edge was created.
  75. Real alpha; ///< current alpha value for rendering
  76. };
  77. edgeInfo m_edges[MAX_TRACK_EDGE_COUNT]; ///<edges at each segment break
  78. Vector3 m_lastAnchor; ///<location of last edge center
  79. Int m_bottomIndex; ///<points at oldest edge on track
  80. Int m_topIndex; ///<points to newest edge on track
  81. Bool m_haveAnchor; ///<set to false until first edge is added
  82. Bool m_bound; ///<object is bound to owner and accepts new edges
  83. Real m_width; ///<track width
  84. Real m_length; ///<length of each track segment
  85. Bool m_airborne; ///< Did the vehicle bounce up into the air?
  86. Bool m_haveCap; ///< is the segment capped so we can stop and resume at new location.
  87. TerrainTracksRenderObjClass *m_nextSystem; ///<next track system
  88. TerrainTracksRenderObjClass *m_prevSystem; ///<previous track system
  89. };
  90. /// System for drawing, updating, and re-using tread mark render objects.
  91. /**
  92. This system keeps track of all the active track mark objects and reuses them
  93. when they expire. It also renders all the track marks that were submitted in
  94. this frame.
  95. */
  96. class TerrainTracksRenderObjClassSystem
  97. {
  98. friend class TerrainTracksRenderObjClass;
  99. public:
  100. TerrainTracksRenderObjClassSystem( void );
  101. ~TerrainTracksRenderObjClassSystem( void );
  102. void ReleaseResources(void); ///< Release all dx8 resources so the device can be reset.
  103. void ReAcquireResources(void); ///< Reacquire all resources after device reset.
  104. void setDetail(void);
  105. void flush (void); ///<draw all tracks that were requested for rendering.
  106. void update(void); ///<update the state of all edges (fade alpha, remove old, etc.)
  107. void init( SceneClass *TerrainTracksScene); ///< pre-allocate track objects
  108. void shutdown( void ); ///< release all pre-allocated track objects, called by destructor
  109. void Reset(void); ///<empties the system, ready for a new scene.
  110. TerrainTracksRenderObjClass *bindTrack(RenderObjClass *renderObject, Real length, const Char *texturename); ///<track object to be controlled by owner
  111. void unbindTrack( TerrainTracksRenderObjClass *mod ); ///<releases control of track object
  112. protected:
  113. DX8VertexBufferClass *m_vertexBuffer; ///<vertex buffer used to draw all tracks
  114. DX8IndexBufferClass *m_indexBuffer; ///<indices defining triangles in maximum length track
  115. VertexMaterialClass *m_vertexMaterialClass; ///< vertex lighting material
  116. ShaderClass m_shaderClass; ///<shader or rendering state for heightmap
  117. TerrainTracksRenderObjClass *m_usedModules; ///<active objects being rendered in the scene
  118. TerrainTracksRenderObjClass *m_freeModules; //<unused modules that are free to use again
  119. SceneClass *m_TerrainTracksScene; ///<scene that will contain all the TerrainTracks
  120. Int m_edgesToFlush; ///< number of edges to flush on next render.
  121. void releaseTrack( TerrainTracksRenderObjClass *mod ); ///<returns track object to free store.
  122. void clearTracks(void); ///<reset the amount of visible track marks of each object.
  123. Int m_maxTankTrackEdges; ///<maximum length of tank track
  124. Int m_maxTankTrackOpaqueEdges; ///<maximum length of tank track before it starts fading.
  125. Int m_maxTankTrackFadeDelay; ///<maximum amount of time a tank track segment remains visible.
  126. }; // end class TerrainTracksRenderObjClassSystem
  127. extern TerrainTracksRenderObjClassSystem *TheTerrainTracksRenderObjClassSystem; ///< singleton for track drawing system.
  128. #endif // end __W3DTERRAINTRACKS_H_