Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
decalsys.h
Go to the documentation of this file.
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 O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
21 ***********************************************************************************************
22 * *
23 * Project Name : WW3D *
24 * *
25 * $Archive:: /Commando/Code/ww3d2/decalsys.h $*
26 * *
27 * Original Author:: Greg Hjelstrom *
28 * *
29 * $Author:: Greg_h $*
30 * *
31 * $Modtime:: 6/29/01 11:30a $*
32 * *
33 * $Revision:: 6 $*
34 * *
35 *---------------------------------------------------------------------------------------------*
36 * Functions: *
37 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
38
39#if defined(_MSC_VER)
40#pragma once
41#endif
42
43#ifndef DECALSYS_H
44#define DECALSYS_H
45
46#include "always.h"
47#include "matrix3d.h"
48#include "matrix4.h"
49#include "obbox.h"
50#include "robjlist.h"
51#include "matpass.h"
52#include "projector.h"
53
55class DecalMeshClass;
56
86{
87public:
88 DecalSystemClass(void);
89 virtual ~DecalSystemClass(void);
90
91 /*
92 ** Create and release DecalGenerators. Note that this is the point at which the
93 ** decal system can track "logical" decals. The generator will keep an internal list
94 ** of all of the render objects which generated decals which you should copy if you
95 ** want to track them (e.g. if you want to cap the maximum number of active decals and
96 ** kill the old ones...)
97 */
99 virtual void Unlock_Decal_Generator(DecalGeneratorClass * generator);
100
101 /*
102 ** When a decal-mesh is destroyed, it must inform the DecalSystem. Otherwise, systems
103 ** which track decals can get dangling pointers.
104 */
105 virtual void Decal_Mesh_Destroyed(uint32 decal_id,DecalMeshClass * mesh) { }
106
107protected:
108
109 /*
110 ** This generates the decal ID when a generator is created. This decal system reroutes this
111 ** to Generate_Unique_Global_Decal_Id(), but other decal systems may use a different method.
112 */
114
115 /*
116 ** Unique ID generation for decals. Not all decal systems have to use
117 ** this method of generating ids. Some may wish to assign the id as the
118 ** array index of the logical id or use some other aritrary method.
119 */
121
123};
124
125
132{
133public:
134
135 /*
136 ** All meshes that actually generate decal polygons should register themselves in the
137 ** list. Then when the decal generation is finished, this list can be copied so that
138 ** we can come back to those meshes and remove the decals if we want to.
139 */
140 void Add_Mesh(RenderObjClass * mesh);
142
143 /*
144 ** Decal generator parameters.
145 ** see ProjectorClass for control over the coordinate system, projection, etc
146 */
147 uint32 Get_Decal_ID(void) { return DecalID; }
149
150 /*
151 ** Backface rejection thresh-hold. The dot-product between the projection vector and
152 ** the normal of each polygon is taken, if the result is greater than this value the polygon
153 ** is accepted into the decal. Set it to -1 if you want to accept all polygons.
154 */
155 void Set_Backface_Threshhold(float val) { BackfaceVal = val; }
156 float Get_Backface_Threshhold(void) { return BackfaceVal; }
157
158 /*
159 ** Normally, decals are not generated on translucent meshes. This is due to the "floating
160 ** decals" that you can get on things like trees. The user can override this behavior
161 ** through the following interface.
162 */
165
166 /*
167 ** Material parameters: just grab a pointer the material pass and modify it.
168 ** Remember to release your ref to it when you are done.
169 */
171
172 /*
173 ** Decal generation support. Call Set_Mesh_Transform for the mesh you want to add
174 ** a decal to. Then for each vertex, you can call 'Compute_Texture_Coordinate'
175 */
176 void Set_Mesh_Transform(const Matrix3D & tm);
177
178protected:
179
182
183 /*
184 ** Logical Decal ID, DecalSystem that this generator is tied to
185 */
187 uint32 DecalID; // unique ID generated by the DecalSystem
188
189 /*
190 ** Backface Threshhold, Translucent mesh decal enable
191 */
194
195 /*
196 ** Material settings
197 */
198 MaterialPassClass * Material; // material settings for the decal
199
200 /*
201 ** Results, list of the meshes which actually generated decal polygons for this logical decal.
202 */
204
205 friend class DecalSystemClass;
206};
207
208
215
217{
218
219public:
220
221 MultiFixedPoolDecalSystemClass(uint32 num_pools, const uint32 *pool_sizes);
224
225 // This clears the slot in addition to locking the generator, thus preventing any decal id
226 // collisions (since any decal previously in that slot will have the same id as the new one).
228
229 // This will register the decal in the system in the appropriate pool and slot (determined by
230 // the generator's pool and slot ids), removing any decal which may have been there before.
231 virtual void Unlock_Decal_Generator(DecalGeneratorClass * generator);
232
233 // This notifies the system that a mesh which has decals on it was destroyed - therefore we
234 // need to remove the mesh from our list to avoid dangling pointers.
235 virtual void Decal_Mesh_Destroyed(uint32 id,DecalMeshClass * mesh);
236
237 // Not part of the DecalSystemClass interface - this function removes any decal currently in
238 // the given slot in the given pool.
239 void Clear_Decal_Slot(uint32 pool_id, uint32 slot_id);
240
241 // This one removes all decals in a given pool.
242 void Clear_Pool(uint32 pool_id);
243
244 // And this one removes all decals in the system.
245 void Clear_All_Decals(void);
246
247protected:
248
249 /*
250 ** This generates the decal ID when a generator is created. This decal system generates the
251 ** decal ID from a pool ID and slot ID which are part of the state of the system so someone
252 ** can set them before calling Lock_Decal_Generator() (which is where this function is called).
253 ** We do it this way to avoid needing to override Lock_Decal_Generator().
254 */
256 uint32 Generator_PoolID; // These should be set before calling Lock_Decal_Generator()
257 uint32 Generator_SlotID; // These should be set before calling Lock_Decal_Generator()
258
259 class LogicalDecalClass;
260
261 // Get a reference to the logical decal at the given pool and slot id (performs range chacking)
263
264 // Get a reference to the logical decal with the given decal id
266
267 // The decal ids are formed so that the upper 16 bits are equal to the pool id and the lower
268 // 16 bits are equal to the slot id.
269 static uint32 encode_decal_id(uint32 pool_id, uint32 slot_id) { return (slot_id & 0xFFFF) | (pool_id << 16); }
270 static void decode_decal_id(uint32 decal_id, uint32 & pool_id, uint32 & slot_id) { slot_id = decal_id & 0xFFFF; pool_id = decal_id >> 16; }
271
272 // A class to store the meshes to which the decal has been applied (so that they can be removed when needed)
274 {
275 public:
276 LogicalDecalClass(void);
277 ~LogicalDecalClass(void);
278
279 void Set(DecalGeneratorClass * generator);
280
281 // Just clears any existing logical decal information, leaving the decal empty.
282 void Clear(uint32 decal_id);
283
285 };
286
288 {
289 public:
292
293 void Initialize(uint32 size);
294
297 };
298
301
302};
303
304
305
306
307#endif //DECALSYS_H
308
#define NULL
Definition BaseType.h:92
#define WWASSERT
unsigned long uint32
Definition bittype.h:46
bool ApplyToTranslucentMeshes
Definition decalsys.h:193
friend class DecalSystemClass
Definition decalsys.h:205
void Add_Mesh(RenderObjClass *mesh)
Definition decalsys.cpp:219
DecalSystemClass * System
Definition decalsys.h:186
void Set_Mesh_Transform(const Matrix3D &tm)
Definition decalsys.cpp:261
void Set_Backface_Threshhold(float val)
Definition decalsys.h:155
NonRefRenderObjListClass & Get_Mesh_List(void)
Definition decalsys.cpp:240
MaterialPassClass * Material
Definition decalsys.h:198
NonRefRenderObjListClass MeshList
Definition decalsys.h:203
DecalSystemClass * Peek_Decal_System(void)
Definition decalsys.h:148
void Apply_To_Translucent_Meshes(bool onoff)
Definition decalsys.h:163
MaterialPassClass * Get_Material(void)
Definition decalsys.h:170
uint32 Get_Decal_ID(void)
Definition decalsys.h:147
bool Is_Applied_To_Translucent_Meshes(void)
Definition decalsys.h:164
float Get_Backface_Threshhold(void)
Definition decalsys.h:156
DecalGeneratorClass(uint32 id, DecalSystemClass *system)
Definition decalsys.cpp:172
static uint32 DecalIDGenerator
Definition decalsys.h:122
DecalSystemClass(void)
Definition decalsys.cpp:76
virtual void Decal_Mesh_Destroyed(uint32 decal_id, DecalMeshClass *mesh)
Definition decalsys.h:105
static uint32 Generate_Unique_Global_Decal_Id(void)
Definition decalsys.cpp:150
virtual DecalGeneratorClass * Lock_Decal_Generator(void)
Definition decalsys.cpp:109
virtual uint32 Generate_Decal_Id(void)
Definition decalsys.h:113
virtual void Unlock_Decal_Generator(DecalGeneratorClass *generator)
Definition decalsys.cpp:131
virtual ~DecalSystemClass(void)
Definition decalsys.cpp:92
void Set(DecalGeneratorClass *generator)
Definition decalsys.cpp:432
virtual void Unlock_Decal_Generator(DecalGeneratorClass *generator)
Definition decalsys.cpp:348
void Clear_Decal_Slot(uint32 pool_id, uint32 slot_id)
Definition decalsys.cpp:368
static uint32 encode_decal_id(uint32 pool_id, uint32 slot_id)
Definition decalsys.h:269
virtual uint32 Generate_Decal_Id(void)
Definition decalsys.h:255
virtual void Decal_Mesh_Destroyed(uint32 id, DecalMeshClass *mesh)
Definition decalsys.cpp:356
static void decode_decal_id(uint32 decal_id, uint32 &pool_id, uint32 &slot_id)
Definition decalsys.h:270
MultiFixedPoolDecalSystemClass(uint32 num_pools, const uint32 *pool_sizes)
Definition decalsys.cpp:297
LogicalDecalClass & find_logical_decal(uint32 pool_id, uint32 slot_id)
Definition decalsys.cpp:396
LogicalDecalPoolClass * Pools
Definition decalsys.h:299
void Clear_Pool(uint32 pool_id)
Definition decalsys.cpp:374
virtual ~MultiFixedPoolDecalSystemClass(void)
Definition decalsys.cpp:330
virtual DecalGeneratorClass * Lock_Decal_Generator(void)
Definition decalsys.cpp:340
ProjectorClass(void)
Definition projector.cpp:64
MultiListClass< RenderObjClass > NonRefRenderObjListClass
Definition robjlist.h:62