/* ** Command & Conquer Generals Zero Hour(tm) ** Copyright 2025 Electronic Arts Inc. ** ** This program is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program. If not, see . */ //////////////////////////////////////////////////////////////////////////////// // // // (c) 2001-2003 Electronic Arts Inc. // // // //////////////////////////////////////////////////////////////////////////////// // FILE: W3DTreeBuffer.h ////////////////////////////////////////////////// //----------------------------------------------------------------------------- // // Westwood Studios Pacific. // // Confidential Information // Copyright (C) 2001 - All Rights Reserved // //----------------------------------------------------------------------------- // // Project: RTS3 // // File name: W3DTreeBuffer.h // // Created: John Ahlquist, May 2001 // // Desc: Draw buffer to handle all the trees in a scene. // //----------------------------------------------------------------------------- #pragma once #ifndef __W3DTREE_BUFFER_H_ #define __W3DTREE_BUFFER_H_ //----------------------------------------------------------------------------- // Includes //----------------------------------------------------------------------------- #include "always.h" #include "rendobj.h" #include "w3d_file.h" #include "Texture.h" #include "dx8vertexbuffer.h" #include "dx8indexbuffer.h" #include "shader.h" #include "vertmaterial.h" #include "Lib/BaseType.h" #include "common/GameType.h" #include "Common/AsciiString.h" #include "common/GlobalData.h" //----------------------------------------------------------------------------- // Forward References //----------------------------------------------------------------------------- class MeshClass; class W3DTreeBuffer; class TileData; class W3DTreeDrawModuleData; struct BreezeInfo; class GeometryInfo; class W3DProjectedShadow; //----------------------------------------------------------------------------- // Type Defines //----------------------------------------------------------------------------- enum W3DToppleState { TOPPLE_UPRIGHT = 0, TOPPLE_FALLING, TOPPLE_FOGGED, TOPPPLE_SHROUDED, TOPPLE_DOWN }; /// The individual data for a tree. typedef struct { Vector3 location; ///< Drawing location Real scale; ///< Scale at location. Real sin; ///< Sine of the rotation angle at location. Real cos; ///< Cosine of the rotation angle at location. Int treeType; ///< Type of tree. Bool visible; ///< Visible flag, updated each frame. SphereClass bounds; ///< Bounding sphere for culling to set the visible flag. Real sortKey; ///< Sort key, essentially the distance along the look at vector. DrawableID drawableID; ///< Drawable this tree corresponds to. Real pushAside; Real pushAsideDelta; Real pushAsideSin; ///< Sine of the rotation angle at location. Real pushAsideCos; ///< Cosine of the rotation angle at location. ObjectID pushAsideSource; ///< Unit that is pushing us aside. UnsignedInt lastFrameUpdated; ///< Last frame push aside was updated. Int nextInPartition; Int swayType; ///< Which sway array entry we are using. Int firstIndex; ///< First index in the vertex buffer for this tree. Int bufferNdx; ///< Which vertex buffer this is in. // Topple parameters. [7/7/2003] Real m_angularVelocity; ///< Velocity in degrees per frame (or is it radians per frame?) Real m_angularAcceleration; ///< Acceleration angularVelocity is increasing Coord3D m_toppleDirection; ///< Z-less direction we are toppling W3DToppleState m_toppleState; ///< Stage this module is in. Real m_angularAccumulation; ///< How much have I rotated so I know when to bounce. UnsignedInt m_options; ///< topple options Matrix3D m_mtx; UnsignedInt m_sinkFramesLeft; ///< Toppled trees sink into the terrain & disappear, how many frames left. } TTree; /// The individual data for a tree type. typedef struct { MeshClass * m_mesh; ///< Mesh for this kind of tree. SphereClass m_bounds; ///< Bounding boxes for the base tree models. const W3DTreeDrawModuleData *m_data; ICoord2D m_textureOrigin; ///< Texture origin in the mega texture. Int m_numTiles; ///< Number of tex tiles. Int m_firstTile;///< First texture tile. Int m_tileWidth;///< Width in tiles of texture; Bool m_halfTile; ///< Tiles are 64x64 pixels, half tile supports a 32x32 bit texture. Have to adjust the uv values. Vector3 m_offset; Real m_shadowSize; ///< Shadow radius. Bool m_doShadow; ///< Draw shadow. } TTreeType; // // W3DTreeBuffer: Draw buffer for the trees. // // class W3DTreeBuffer : public Snapshot { //friend class BaseHeightMapRenderObjClass; //----------------------------------------------------------------------------- // W3DTreeTextureClass //----------------------------------------------------------------------------- class W3DTreeTextureClass : public TextureClass { W3DMPO_GLUE(W3DTreeTextureClass) protected: virtual void Apply(unsigned int stage); public: /// Create texture. W3DTreeTextureClass(unsigned width, unsigned height); // just use default destructor. ~TerrainTextureClass(void); public: int update(W3DTreeBuffer *buffer); ///< Sets the pixels, and returns the actual height of the texture. void setLOD(Int LOD) const; }; public: W3DTreeBuffer(void); ~W3DTreeBuffer(void); /// Add a tree at location. Name is the w3d model name. void addTree(DrawableID id, Coord3D location, Real scale, Real angle, Real randomScaleAmount, const W3DTreeDrawModuleData *data); /// Notify that an object moved, so check for collisions. void unitMoved(Object *unit); /// Add a type of tree. Name is the w3d model name. Int addTreeType(const W3DTreeDrawModuleData *data); /// Updates a tree's location. Bool updateTreePosition(DrawableID id, Coord3D location, Real angle); void pushAsideTree( DrawableID id, const Coord3D *pusherPos, const Coord3D *pusherDirection, ObjectID pusherID ); /// Remove a tree. void removeTree(DrawableID id); /// Remove trees that would be under a building. void removeTreesForConstruction( const Coord3D* pos, const GeometryInfo& geom, Real angle ); void setTextureLOD(Int lod); ///