Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
assetmgr.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/* $Header: /Commando/Code/ww3d2/assetmgr.h 19 12/17/01 7:55p Jani_p $ */
20/***********************************************************************************************
21 *** Confidential - Westwood Studios ***
22 ***********************************************************************************************
23 * *
24 * Project Name : Commando *
25 * *
26 * $Archive:: /Commando/Code/ww3d2/assetmgr.h $*
27 * *
28 * Author:: Greg_h *
29 * *
30 * $Modtime:: 12/15/01 4:14p $*
31 * *
32 * $Revision:: 19 $*
33 * *
34 *---------------------------------------------------------------------------------------------*
35 * Functions: *
36 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
37
38
39#if defined(_MSC_VER)
40#pragma once
41#endif
42
43#ifndef ASSETMGR_H
44#define ASSETMGR_H
45
46#include "always.h"
47#include "vector.h"
48#include "htreemgr.h"
49#include "hanimmgr.h"
50#include "slist.h"
51#include "texture.h"
52#include "hashtemplate.h"
53#include "simplevec.h"
54
55class HAnimClass;
56class HTreeClass;
57class ChunkLoadClass;
58
59class FileClass;
62class Font3DDataClass;
64class FontCharsClass;
65class RenderObjClass;
66class HModelClass;
67class PrototypeClass;
70class HAnimIterator;
71class TextureIterator;
72class TextureFileCache;
73class StreamingTextureClass;
74struct StreamingTextureConfig;
75class TextureClass;
77
78
79/*
80** AssetIterator
81** This object can iterate through the 3D assets which
82** currently exist in the Asset Manager. It tells you the names
83** of the assets which the manager can create for you.
84*/
86{
87
88public:
89
90 virtual ~AssetIterator(void) { };
91 virtual void First(void) { Index = 0; }
92 virtual void Next(void) { Index ++; }
93 virtual bool Is_Done(void) = 0;
94 virtual const char * Current_Item_Name(void) = 0;
95
96protected:
97
98 AssetIterator(void) { Index = 0; }
99 int Index;
100};
101
102/*
103** RenderObjIterator
104** The render obj iterator simply adds a method for determining
105** the class id of a render object prototype in the system.
106*/
108{
109public:
110 virtual int Current_Item_Class_ID(void) = 0;
111};
112
113
114/*
115
116 WW3DAssetManager
117
118 This object is the manager of all of the 3D data. Load your meshes, animations,
119 etc etc using the Load_3D_Assets function.
120
121 WARNING: hierarchy trees should be loaded before the meshes and animations
122 which attach to them.
123
124 -------------------------------------------------------------------------------------
125 Dec 11, 1997, Asset Manager Brainstorming:
126
127 - WW3DAssetManager will be diferentiated from other game data asset managers
128 (sounds, strings, etc) because they behave differently and serve different
129 purposes
130
131 - WW3D creates "clones" from the blueprints it has of render objects whereas
132 Our commando data asset manager will provide the data (file images) for the
133 blueprints. Maybe the CommandoDataManager could deal in MemoryFileClasses.
134 Or void * and then the ww3d manager could convert to MemoryFiles...
135
136 - Future caching: In the case that we want to implement a caching system,
137 assets must be "released" when not in use.
138
139 - CommandoW3d asset manager asks the game data asset manager for assets by name.
140 Game data manager must have a "directory" structure which maps each named
141 asset to data on disk. It then returns an image of the file once it has
142 been loaded into ram.
143
144 - Assets must be individual files, named with the asset name used in code/scripting
145 We will write a tool which chops w3d files up so that all of the individual assets
146 are brought out into their own file and named with the actual w3d name.
147
148 - Data Asset Manager will load the file into ram, give it to us and forget about it
149 W3d will release_ref it or delete it and the file image will go away.
150
151 - Each time the 3d asset manager is requested for an asset, it will look through
152 the render objects it has, if the asset isn't found, it will ask for the asset
153 from the generic data asset manager. When creating the actual render object,
154 the 3d asset manager may find that it needs another asset (such as a hierarchy tree).
155 It will then recurse, and ask for that asset.
156
157 - Copy Mode will go away. It will be internally set based on whether the mesh
158 contains vertex animation. All other render objects will simply "Clone".
159
160 - Commando will derive a Cmdo3DAssetManager which knows about the special chunks
161 required for the terrains.
162
163 -------------------------------------------------------------------------------------
164 July 28, 1998
165
166 - Exposed the prototype system and added prototype loaders (PrototypeClass and
167 PrototypeLoaderClass in proto.h). This now allows the user to install his own
168 loaders for new render object types.
169
170 - Simplified the interface by removing the special purpose creation functions,
171 leaving only the Create_Render_Obj function.
172
173 - In certain cases some users need to know what kind of render object was created
174 so we added a Class_ID mechanism to RenderObjClass.
175
176 - Class_ID for render objects is not enough. Need the asset iterator to be able
177 to tell you the Class_ID of each asset in the asset manager. This also means that
178 the prototype class needs to be able to tell you the class ID. Actually this
179 code only seems to be used by tools such as SView but is needed anyway...
180
181*/
182
183
185{
186
187public:
188
189 /*
190 ** Constructor and destructor
191 */
192 WW3DAssetManager(void);
193 virtual ~WW3DAssetManager(void);
194
195 /*
196 ** Access to the single instance of a WW3DAssetManager. The user
197 ** can subclass their own asset manager class but should only
198 ** create one instance. (a violation of this will be caught with
199 ** a run-time assertion)
200 **
201 ** The "official" way to get at the global asset manager is to
202 ** use a line of code like this:
203 ** WW3DAssetManager::Get_Instance();
204 */
205 static WW3DAssetManager * Get_Instance(void) { return TheInstance; }
206 static void Delete_This(void) { if (TheInstance) delete TheInstance; TheInstance=NULL; }
207
208 /*
209 ** Load data from any type of w3d file
210 */
211 virtual bool Load_3D_Assets( const char * filename);
212 virtual bool Load_3D_Assets(FileClass & assetfile);
213
214 /*
215 ** Get rid of all of the currently loaded assets
216 */
217 virtual void Free_Assets(void);
218
219 /*
220 ** Release any assets that only the asset manager has a reference to.
221 */
222 virtual void Release_Unused_Assets(void);
223
224 /*
225 ** Release assets not in the given exclusion list.
226 */
227 virtual void Free_Assets_With_Exclusion_List(const DynamicVectorClass<StringClass> & model_exclusion_list);
228 virtual void Create_Asset_List(DynamicVectorClass<StringClass> & model_exclusion_list);
229
230 /*
231 ** create me an instance of one of the prototype render objects
232 */
233 virtual RenderObjClass * Create_Render_Obj(const char * name);
234
235 /*
236 ** query if there is a render object with the specified name
237 */
238 virtual bool Render_Obj_Exists(const char * name);
239
240 /*
241 ** Iterate through all render objects or through the
242 ** sub-categories of render objects. NOTE! the user is responsible
243 ** for releasing the iterator when finished with it!
244 */
247
248 /*
249 ** Access to HAnims, Used by Animatable3DObj's
250 ** TODO: make HAnims accessible from the HMODELS (or Animatable3DObj...)
251 */
252 virtual AssetIterator * Create_HAnim_Iterator(void);
253 virtual HAnimClass * Get_HAnim(const char * name);
254 virtual bool Add_Anim (HAnimClass *new_anim) { return HAnimManager.Add_Anim (new_anim); }
255
256 /*
257 ** Access to textures
258 */
259// virtual AssetIterator * Create_Texture_Iterator(void);
260
262
263 static void Log_Texture_Statistics();
264
265 virtual TextureClass * Get_Texture
266 (
267 const char * filename,
268 MipCountType mip_level_count=MIP_LEVELS_ALL,
269 WW3DFormat texture_format=WW3D_FORMAT_UNKNOWN,
270 bool allow_compression=true,
272 bool allow_reduction=true
273 );
274
275 virtual void Release_All_Textures(void);
276 virtual void Release_Unused_Textures(void);
277 virtual void Release_Texture(TextureClass *);
278 virtual void Load_Procedural_Textures();
280
281 /*
282 ** Access to Font3DInstances. (These are not saved, we just use the
283 ** asset manager as a convienient way to create them.)
284 */
285 virtual Font3DInstanceClass * Get_Font3DInstance( const char * name);
286
287 /*
288 ** Access to FontChars. Used by Render2DSentenceClass
289 */
290 virtual FontCharsClass * Get_FontChars( const char * name, int point_size, bool is_bold = false );
291
292 /*
293 ** Access to HTrees, Used by Animatable3DObj's
294 */
295 virtual AssetIterator * Create_HTree_Iterator(void);
296 virtual HTreeClass * Get_HTree(const char * name);
297
298 /*
299 ** Prototype Loaders, The user can register new loaders here. Note that
300 ** a the pointer to your loader will be stored inside the asset manager.
301 ** For this reason, your loader should be a static or global object.
302 */
303 virtual void Register_Prototype_Loader(PrototypeLoaderClass * loader);
304
305 /*
306 ** The Add_Prototype is public so that we can add prototypes for procedurally
307 ** generated objects to the asset manager.
308 */
309 void Add_Prototype(PrototypeClass * newproto);
310 void Remove_Prototype(PrototypeClass *proto);
311 void Remove_Prototype(const char *name);
312 PrototypeClass * Find_Prototype(const char * name);
313
314 /*
315 ** Load on Demand
316 */
318 void Set_WW3D_Load_On_Demand( bool on_off ) { WW3D_Load_On_Demand = on_off; }
319
320 /*
321 ** Add fog to objects on load
322 */
324 void Set_Activate_Fog_On_Load( bool on_off ) { Activate_Fog_On_Load = on_off; }
325
326 // Log texture statistics
327 void Log_All_Textures();
328
329protected:
330
331 /*
332 ** Access to Font3DData. (These are privately managed/accessed)
333 */
335 virtual void Add_Font3DData(Font3DDataClass * font);
336 virtual void Remove_Font3DData(Font3DDataClass * font);
337 virtual Font3DDataClass * Get_Font3DData(const char * name);
338 virtual void Release_All_Font3DDatas( void);
339 virtual void Release_Unused_Font3DDatas( void);
340
341 virtual void Release_All_FontChars( void );
342
343 void Free(void);
344
346 bool Load_Prototype(ChunkLoadClass & cload);
347
348 /*
349 ** Compile time control over the dynamic arrays:
350 */
351 enum
352 {
355
358 };
359
360 /*
361 ** Prototype Loaders
362 ** These objects are responsible for importing certain W3D chunk types and turning
363 ** them into prototypes.
364 */
365 DynamicVectorClass < PrototypeLoaderClass * > PrototypeLoaders;
366
367 /*
368 ** Prototypes
369 ** These objects are abstract factories for named render objects. Prototypes is
370 ** a dynamic array of pointers to the currently loaded prototypes.
371 */
372 DynamicVectorClass < PrototypeClass * > Prototypes;
373
374 /*
375 ** Prototype Hash Table
376 ** This structure is simply used to speed up the name lookup for prototypes
377 */
378 enum
379 {
383 };
384
386
387 /*
388 ** managers of HTrees, HAnims, Textures....
389 */
392
393 /*
394 ** When enabled, this handles all the caching for the texture class.
395 ** If NULL then textures are not being cached.
396 */
397 TextureFileCache * TextureCache;
398
399 /*
400 ** list of Font3DDatas
401 */
403
404 /*
405 ** list of FontChars
406 */
408
409 /*
410 ** Should .W3D be loaded if not in memory
411 */
413
414 /*
415 ** Should we activate fog on objects while loading them
416 */
418
419 // Metal Map Manager
421
422 /*
423 ** Texture hash table for quick texture lookups
424 */
426
427 /*
428 ** The 3d asset manager is a singleton, there should be only
429 ** one and it is accessible through Get_Instance()
430 */
432
433 /*
434 ** the iterator classes are friends
435 */
436 friend class RObjIterator;
437 friend class HAnimIterator;
438 friend class HTreeIterator;
439 friend class Font3DDataIterator;
440 friend class TextureIterator;
441
442 // Font3DInstance need access to the Font3DData
444};
445
446#endif
#define NULL
Definition BaseType.h:92
virtual bool Is_Done(void)=0
AssetIterator(void)
Definition assetmgr.h:98
virtual void First(void)
Definition assetmgr.h:91
virtual ~AssetIterator(void)
Definition assetmgr.h:90
virtual const char * Current_Item_Name(void)=0
virtual void Next(void)
Definition assetmgr.h:92
virtual int Current_Item_Class_ID(void)=0
Definition SLIST.H:67
HTreeManagerClass HTreeManager
Definition assetmgr.h:390
bool Load_Prototype(ChunkLoadClass &cload)
Definition assetmgr.cpp:712
virtual AssetIterator * Create_HTree_Iterator(void)
Definition assetmgr.cpp:938
virtual void Add_Font3DData(Font3DDataClass *font)
DynamicVectorClass< PrototypeClass * > Prototypes
Definition assetmgr.h:372
void Log_All_Textures()
virtual TextureClass * Get_Texture(const char *filename, MipCountType mip_level_count=MIP_LEVELS_ALL, WW3DFormat texture_format=WW3D_FORMAT_UNKNOWN, bool allow_compression=true, TextureBaseClass::TexAssetType type=TextureBaseClass::TEX_REGULAR, bool allow_reduction=true)
void Set_WW3D_Load_On_Demand(bool on_off)
Definition assetmgr.h:318
SList< Font3DDataClass > Font3DDatas
Definition assetmgr.h:402
bool WW3D_Load_On_Demand
Definition assetmgr.h:412
@ PROTOTYPE_HASH_TABLE_SIZE
Definition assetmgr.h:380
virtual bool Load_3D_Assets(const char *filename)
Definition assetmgr.cpp:631
virtual MetalMapManagerClass * Peek_Metal_Map_Manager()
Definition assetmgr.h:279
virtual Font3DDataClass * Get_Font3DData(const char *name)
void Add_Prototype(PrototypeClass *newproto)
PrototypeClass ** PrototypeHashTable
Definition assetmgr.h:385
MetalMapManagerClass * MetalManager
Definition assetmgr.h:420
virtual void Load_Procedural_Textures()
Definition assetmgr.cpp:295
virtual void Release_All_FontChars(void)
static void Delete_This(void)
Definition assetmgr.h:206
virtual AssetIterator * Create_HAnim_Iterator(void)
Definition assetmgr.cpp:920
TextureFileCache * TextureCache
Definition assetmgr.h:397
virtual bool Render_Obj_Exists(const char *name)
Definition assetmgr.cpp:857
virtual void Release_Unused_Textures(void)
virtual void Release_All_Font3DDatas(void)
virtual RenderObjClass * Create_Render_Obj(const char *name)
Definition assetmgr.cpp:799
HAnimManagerClass HAnimManager
Definition assetmgr.h:391
virtual ~WW3DAssetManager(void)
Definition assetmgr.cpp:263
HashTemplateClass< StringClass, TextureClass * > & Texture_Hash()
Definition assetmgr.h:261
PrototypeClass * Find_Prototype(const char *name)
static WW3DAssetManager * Get_Instance(void)
Definition assetmgr.h:205
bool Get_WW3D_Load_On_Demand(void)
Definition assetmgr.h:317
SimpleDynVecClass< FontCharsClass * > FontCharsList
Definition assetmgr.h:407
virtual void Release_Unused_Assets(void)
Definition assetmgr.cpp:503
virtual FontCharsClass * Get_FontChars(const char *name, int point_size, bool is_bold=false)
virtual AssetIterator * Create_Font3DData_Iterator(void)
Definition assetmgr.cpp:959
void Free(void)
Definition assetmgr.cpp:438
virtual void Release_Unused_Font3DDatas(void)
PrototypeLoaderClass * Find_Prototype_Loader(int chunk_id)
virtual void Remove_Font3DData(Font3DDataClass *font)
virtual RenderObjIterator * Create_Render_Obj_Iterator(void)
Definition assetmgr.cpp:880
HashTemplateClass< StringClass, TextureClass * > TextureHash
Definition assetmgr.h:425
friend class HTreeIterator
Definition assetmgr.h:438
virtual void Register_Prototype_Loader(PrototypeLoaderClass *loader)
virtual HAnimClass * Get_HAnim(const char *name)
Definition assetmgr.cpp:978
static void Log_Texture_Statistics()
Definition assetmgr.cpp:384
virtual Font3DInstanceClass * Get_Font3DInstance(const char *name)
static WW3DAssetManager * TheInstance
Definition assetmgr.h:431
virtual HTreeClass * Get_HTree(const char *name)
virtual void Release_Render_Obj_Iterator(RenderObjIterator *)
Definition assetmgr.cpp:898
friend class TextureIterator
Definition assetmgr.h:440
virtual void Release_Texture(TextureClass *)
virtual void Create_Asset_List(DynamicVectorClass< StringClass > &model_exclusion_list)
Definition assetmgr.cpp:598
virtual void Release_All_Textures(void)
virtual bool Add_Anim(HAnimClass *new_anim)
Definition assetmgr.h:254
friend class Font3DInstanceClass
Definition assetmgr.h:443
virtual void Free_Assets(void)
Definition assetmgr.cpp:457
friend class RObjIterator
Definition assetmgr.h:436
friend class HAnimIterator
Definition assetmgr.h:437
DynamicVectorClass< PrototypeLoaderClass * > PrototypeLoaders
Definition assetmgr.h:365
virtual void Free_Assets_With_Exclusion_List(const DynamicVectorClass< StringClass > &model_exclusion_list)
Definition assetmgr.cpp:528
bool Get_Activate_Fog_On_Load(void)
Definition assetmgr.h:323
bool Activate_Fog_On_Load
Definition assetmgr.h:417
void Remove_Prototype(PrototypeClass *proto)
void Set_Activate_Fog_On_Load(bool on_off)
Definition assetmgr.h:324
friend class Font3DDataIterator
Definition assetmgr.h:439
MipCountType
@ MIP_LEVELS_ALL
WW3DFormat
Definition ww3dformat.h:75
@ WW3D_FORMAT_UNKNOWN
Definition ww3dformat.h:76