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