W3DBridgeBuffer.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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: W3DBridgeBuffer.h //////////////////////////////////////////////////
  24. //-----------------------------------------------------------------------------
  25. //
  26. // Westwood Studios Pacific.
  27. //
  28. // Confidential Information
  29. // Copyright (C) 2001 - All Rights Reserved
  30. //
  31. //-----------------------------------------------------------------------------
  32. //
  33. // Project: RTS3
  34. //
  35. // File name: W3DBridgeBuffer.h
  36. //
  37. // Created: John Ahlquist, May 2001
  38. //
  39. // Desc: Draw buffer to handle all the bridges in a scene.
  40. //
  41. //-----------------------------------------------------------------------------
  42. #pragma once
  43. #ifndef __W3DBRIDGE_BUFFER_H_
  44. #define __W3DBRIDGE_BUFFER_H_
  45. //-----------------------------------------------------------------------------
  46. // Includes
  47. //-----------------------------------------------------------------------------
  48. #include "always.h"
  49. #include "rendobj.h"
  50. #include "w3d_file.h"
  51. #include "dx8vertexbuffer.h"
  52. #include "dx8indexbuffer.h"
  53. #include "shader.h"
  54. #include "vertmaterial.h"
  55. #include "Lib/BaseType.h"
  56. #include "common/GameType.h"
  57. #include "Common/Dict.h"
  58. #include "Common/AsciiString.h"
  59. //-----------------------------------------------------------------------------
  60. // Forward References
  61. //-----------------------------------------------------------------------------
  62. class MeshClass;
  63. class W3DTerrainLogic;
  64. class W3DAssetManager;
  65. class SimpleSceneClass;
  66. //-----------------------------------------------------------------------------
  67. // Type Defines
  68. //-----------------------------------------------------------------------------
  69. typedef enum {
  70. FIXED_BRIDGE = 0,
  71. SECTIONAL_BRIDGE = 1
  72. } TBridgeType;
  73. class BridgeInfo;
  74. /// The individual data for a bridge.
  75. class W3DBridge
  76. {
  77. protected:
  78. Vector3 m_start; ///< Drawing location
  79. Vector3 m_end; ///< Drawing location
  80. Real m_scale; ///< Width scale.
  81. Real m_length;
  82. TBridgeType m_bridgeType; ///< Type of bridge. Currently only 2 supported.
  83. SphereClass m_bounds; ///< Bounding sphere for culling to set the visible flag.
  84. TextureClass *m_bridgeTexture;
  85. MeshClass *m_leftMesh; ///< W3D mesh models for the bridges.
  86. Matrix3D m_leftMtx; ///< Transform for the left mesh.
  87. Real m_minY; ///< min y vertex.
  88. Real m_maxY; ///< max y vertex.
  89. Real m_leftMinX; ///< m_leftMesh min x vertex.
  90. Real m_leftMaxX; ///< m_leftMesh max x vertex.
  91. MeshClass *m_sectionMesh; ///< W3D mesh models for the bridges.
  92. Matrix3D m_sectionMtx; ///< Transform for the section mesh.
  93. Real m_sectionMinX; ///< m_sectionMesh min x vertex.
  94. Real m_sectionMaxX; ///< m_sectionMesh max x vertex.
  95. MeshClass *m_rightMesh; ///< W3D mesh models for the bridges.
  96. Matrix3D m_rightMtx; ///< Transform for the right mesh.
  97. Real m_rightMinX; ///< m_rightMesh min x vertex.
  98. Real m_rightMaxX; ///< m_rightMesh max x vertex.
  99. Int m_firstIndex; ///< Starting index buffer.
  100. Int m_numVertex; ///< Number of vertex used.
  101. Int m_firstVertex; ///< First vertex.
  102. Int m_numPolygons; ///< Number of polygons to draw.
  103. Bool m_visible;
  104. AsciiString m_templateName; ///< Name of the bridge type.
  105. enum BodyDamageType m_curDamageState;
  106. Bool m_enabled;
  107. protected:
  108. Int getModelVerticesFixed(VertexFormatXYZNDUV1 *destination_vb, Int curVertex, const Matrix3D &mtx, MeshClass *pMesh, RefRenderObjListIterator *pLightsIterator);
  109. Int getModelIndices(UnsignedShort *destination_ib, Int curIndex, Int vertexOffset, MeshClass *pMesh);
  110. Int getModelVertices(VertexFormatXYZNDUV1 *destination_vb, Int curVertex, Real xOffset,
  111. Vector3 &vec, Vector3 &vecNormal, Vector3 &vecZ, Vector3 &offset,
  112. const Matrix3D &mtx,
  113. MeshClass *pMesh, RefRenderObjListIterator *pLightsIterator);
  114. public:
  115. W3DBridge(void);
  116. ~W3DBridge(void);
  117. void init(Vector3 fromLoc, Vector3 toLoc, AsciiString name);
  118. AsciiString getTemplateName(void) {return m_templateName;}
  119. const Vector3* getStart(void) const {return &m_start;}
  120. const Vector3* getEnd(void) const { return &m_end;}
  121. Bool load(enum BodyDamageType curDamageState);
  122. enum BodyDamageType getDamageState(void) {return m_curDamageState;};
  123. void setDamageState(enum BodyDamageType state) { m_curDamageState = state;};
  124. void getIndicesNVertices(UnsignedShort *destination_ib, VertexFormatXYZNDUV1 *destination_vb, Int *curIndexP, Int *curVertexP, RefRenderObjListIterator *pLightsIterator);
  125. Bool cullBridge(CameraClass * camera); ///< Culls the bridges. Returns true if visibility changed.
  126. void clearBridge(void); ///< Frees all objects associated with a bridge.
  127. Bool isVisible(void) {return m_visible;};
  128. Bool isEnabled(void) {return m_enabled;};
  129. void setEnabled(Bool enable) {m_enabled = enable;};
  130. void renderBridge(Bool wireframe);
  131. void getBridgeInfo(BridgeInfo *pInfo);
  132. };
  133. //
  134. // W3DBridgeBuffer: Draw buffer for the bridges.
  135. //
  136. //
  137. class W3DBridgeBuffer
  138. {
  139. friend class BaseHeightMapRenderObjClass;
  140. public:
  141. W3DBridgeBuffer(void);
  142. ~W3DBridgeBuffer(void);
  143. /// Empties the bridge buffer.
  144. void clearAllBridges(void);
  145. /// Draws the bridges. Uses camera for culling.
  146. void drawBridges(CameraClass * camera, Bool wireframe, TextureClass *cloudTexture);
  147. /// Called when the view changes, and sort key needs to be recalculated.
  148. /// Normally sortKey gets calculated when a bridge becomes visible.
  149. void doFullUpdate(void) {m_updateVis = true;};
  150. void loadBridges(W3DTerrainLogic *pTerrainLogic, Bool saveGame); ///< Loads the bridges from the map objects list.
  151. void worldBuilderUpdateBridgeTowers( W3DAssetManager *assetManager, SimpleSceneClass *scene ); ///< for the editor and showing visual bridge towers
  152. void updateCenter(CameraClass *camera, RefRenderObjListIterator *pLightsIterator);
  153. enum { MAX_BRIDGE_VERTEX=12000, //make sure it stays under 65535
  154. MAX_BRIDGE_INDEX=2*MAX_BRIDGE_VERTEX, //make sure it stays under 65535
  155. MAX_BRIDGES=200};
  156. protected:
  157. DX8VertexBufferClass *m_vertexBridge; ///<Bridge vertex buffer.
  158. DX8IndexBufferClass *m_indexBridge; ///<indices defining a triangles for the bridge drawing.
  159. VertexMaterialClass *m_vertexMaterial;
  160. TextureClass *m_bridgeTexture; ///<Bridges texture
  161. Int m_curNumBridgeVertices; ///<Number of vertices used in m_vertexBridge.
  162. Int m_curNumBridgeIndices; ///<Number of indices used in b_indexBridge;
  163. W3DBridge m_bridges[MAX_BRIDGES]; ///< The bridge buffer. All bridges are stored here.
  164. Int m_numBridges; ///< Number of bridges in m_bridges.
  165. Bool m_initialized; ///< True if the subsystem initialized.
  166. Bool m_updateVis; ///< True if the camera moved, and we need to recalculate visibility.
  167. Bool m_anythingChanged; ///< Set to true if visibility changed.
  168. /// Add a bridge at location. Name is the gdf item name.
  169. void addBridge(Vector3 fromLoc, Vector3 toLoc, AsciiString name, W3DTerrainLogic *pTerrainLogic, Dict *props);
  170. void loadBridgesInVertexAndIndexBuffers(RefRenderObjListIterator *pLightsIterator); ///< Fills the index and vertex buffers for drawing.
  171. void allocateBridgeBuffers(void); ///< Allocates the buffers.
  172. void cull(CameraClass * camera); ///< Culls the bridges.
  173. void freeBridgeBuffers(void); ///< Frees the index and vertex buffers.
  174. };
  175. #endif // end __W3DBRIDGE_BUFFER_H_