Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
assetmgr.cpp
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.cpp 43 11/01/01 1:11a Jani_p $ */
20/***********************************************************************************************
21 *** Confidential - Westwood Studios ***
22 ***********************************************************************************************
23 * *
24 * Project Name : Commando *
25 * *
26 * $Archive:: /Commando/Code/ww3d2/assetmgr.cpp $*
27 * *
28 * Org Author:: Greg_h *
29 * *
30 * Author : Kenny Mitchell *
31 * *
32 * $Modtime:: 08/05/02 10:14a $*
33 * *
34 * $Revision:: 46 $*
35 * *
36 * 06/27/02 KM Texture class abstraction *
37 * 07/01/02 KM Shader library integration
38 * 08/05/02 KM Texture class redesign (revisited)
39 *---------------------------------------------------------------------------------------------*
40 * Functions: *
41 * WW3DAssetManager::WW3DAssetManager -- Constructor *
42 * WW3DAssetManager::~WW3DAssetManager -- Destructor *
43 * WW3DAssetManager::Free -- free all memory (un-needed?) *
44 * WW3DAssetManager::Free_Assets -- Release all loaded assets *
45 * WW3DAssetManager::Load_3D_Assets -- Load 3D assets from a .W3D file *
46 * WW3DAssetManager::Load_Prototype -- loads a prototype from a W3D chunk *
47 * WW3DAssetManager::Create_Render_Obj -- Create a render object for the user *
48 * WW3DAssetManager::Render_Obj_Exists -- Check whether a render object with the given name *
49 * WW3DAssetManager::Create_Render_Obj_Iterator -- Create an iterator which can enumerate al *
50 * WW3DAssetManager::Release_Render_Obj_Iterator -- release a render object iterator *
51 * WW3DAssetManager::Create_HAnim_Iterator -- Creates an HAnim Iterator *
52 * WW3DAssetManager::Create_HTree_Iterator -- creates an htree iterator *
53 * WW3DAssetManager::Create_Material_Iterator -- Create a material iterator *
54 * WW3DAssetManager::Create_Font3DData_Iterator -- Create a Font3DData iterator *
55 * WW3DAssetManager::Get_HAnim -- Returns a pointer to a names HAnim *
56 * WW3DAssetManager::Get_HTree -- Returns a pointer to the named HTree *
57 * WW3DAssetManager::Get_Material -- Gets a pointer to a loaded material or creates it *
58 * WW3DAssetManager::Get_Material -- Gets a pointer to a loaded material or creates the mate *
59 * WW3DAssetManager::Get_Material -- Gets a pointer to a loaded material or creates it *
60 * WW3DAssetManager::Get_Font3DInstance -- Creates a pointer to a Font3DInstance *
61 * WW3DAssetManager::Get_Font3DData -- Gets a pointer to a loaded Font3DData or creates it *
62 * WW3DAssetManager::Release_Material -- Release a material *
63 * WW3DAssetManager::Release_Font3DData -- Release a Font3DData *
64 * WW3DAssetManager::Add_Material -- Add a material to the list *
65 * WW3DAssetManager::Add_Font3DData -- Add a Font3DData to the list *
66 * WW3DAssetManager::Get_Texture -- get a TextureClass for the specified targa *
67 * WW3DAssetManager::Release_All_Textures -- release all textures in the system *
68 * WW3DAssetManager::Register_Prototype_Loader -- add a new loader to the system *
69 * WW3DAssetManager::Find_Prototype_Loader -- find the loader that handles this chunk type *
70 * WW3DAssetManager::Add_Prototype -- adds the prototype to the hash table *
71 * WW3DAssetManager::Find_Prototype -- searches the hash table for the prototype *
72 * WW3DAssetManager::Open_Texture_File_Cache -- Turn on the texture cache system. *
73 * WW3DAssetManager::Close_Texture_File_Cache -- Turn off the texture cache system. *
74 * CachedTextureFileClass::getMipmapData -- get data for texture - check to see if in cache. *
75 * CachedTextureFileClass::getMipmapLevelPartial -- not yet implemented *
76 * CachedTextureFileClass::setupDefaultValues -- loads texture in to get default data. *
77 * WW3DAssetManager::Get_Streaming_Texture -- Gets a streaming texture. *
78 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
79
80#include "assetmgr.h"
81#include <assert.h>
82
83#include "bittype.h"
84#include "chunkio.h"
85#include "realcrc.h"
86
87#include "wwdebug.h"
88
89#include "htreemgr.h"
90#include "hanimmgr.h"
91#include "texture.h"
92#include "font3d.h"
93#include "render2dsentence.h" // for FontCharsClass
94#include "proto.h"
95#include "hanim.h"
96#include "hcanim.h"
97#include "htree.h"
98#include "collect.h"
99#include "ww3d.h"
100#include "ffactory.h"
101#include "boxrobj.h"
102#include "nullrobj.h"
103#include "distlod.h"
104#include "hlod.h"
105#include "agg_def.h"
106#include "texfcach.h"
107#include "wwstring.h"
108#include "wwmemlog.h"
109#include "dazzle.h"
110#include "dx8wrapper.h"
111#include "dx8renderer.h"
112#include "metalmap.h"
113#include "w3dexclusionlist.h"
114#include <ini.h>
115#include <windows.h>
116#include <stdio.h>
117#include <D3dx8core.h>
118#include "texture.h"
119#include "wwprofile.h"
120#include "assetstatus.h"
121#include "ringobj.h"
122#include "sphereobj.h"
123
124#include "shdlib.h"
125
126/*
127** Static member variable which keeps track of the single instanced asset manager
128*/
130
131/*
132** Static instance of the Null prototype. This render object is special cased
133** to always be available...
134*/
135static NullPrototypeClass _NullPrototype;
136
137/*
138** Iterator for the Render Objects in the asset manager
139*/
141{
142public:
143 virtual bool Is_Done(void);
144 virtual const char * Current_Item_Name(void);
145 virtual int Current_Item_Class_ID(void);
146protected:
147 friend class WW3DAssetManager;
148};
149
150
151/*
152** Iterators for the other types of 3D assets:
153** HAnims, HTrees, Textures, Fonts
154*/
156{
157public:
158 HAnimIterator(void) : Iterator( WW3DAssetManager::Get_Instance()->HAnimManager ) { };
159
160 virtual void First(void) { Iterator.First(); }
161 virtual void Next(void) { Iterator.Next(); }
162 virtual bool Is_Done(void) { return Iterator.Is_Done(); }
163 virtual const char * Current_Item_Name(void) { return Iterator.Get_Current_Anim()->Get_Name(); }
164
165protected:
167 friend class WW3DAssetManager;
168};
169
171{
172public:
173 virtual bool Is_Done(void);
174 virtual const char * Current_Item_Name(void);
175protected:
176 friend class WW3DAssetManager;
177};
178
180{
181public:
182
184 virtual void Next(void) { Node = Node->Next(); }
185 virtual bool Is_Done(void) { return Node==NULL; }
186 virtual const char * Current_Item_Name(void) { return Node->Data()->Name; }
187
188protected:
189
192 friend class WW3DAssetManager;
193};
194
195/***********************************************************************************************
196 * WW3DAssetManager::WW3DAssetManager -- Constructor *
197 * *
198 * INPUT: *
199 * *
200 * OUTPUT: *
201 * *
202 * WARNINGS: *
203 * *
204 * HISTORY: *
205 * 12/21/97 GTH : Created. *
206 * 05/10/1999 SKB : Add TextureCache *
207 *=============================================================================================*/
249
250
251/***********************************************************************************************
252 * WW3DAssetManager::~WW3DAssetManager -- Destructor *
253 * *
254 * INPUT: *
255 * *
256 * OUTPUT: *
257 * *
258 * WARNINGS: *
259 * *
260 * HISTORY: *
261 * 12/21/97 GTH : Created. *
262 *=============================================================================================*/
264{
265 if (MetalManager) delete MetalManager;
266 Free();
268
269 // If we need to, free the hash table
270 if (PrototypeHashTable != NULL) {
271 delete [] PrototypeHashTable;
273 }
274#ifdef WW3D_DX8
275 Close_Texture_File_Cache();
276#endif //WW3D_DX8
277}
278
279static void Create_Number_String(StringClass& number, unsigned value)
280{
281 unsigned miljoonat=value/(1024*1028);
282 unsigned tuhannet=(value/1024)%1024;
283 unsigned ykkoset=value%1024;
284 if (miljoonat) {
285 number.Format("%d %3.3d %3.3d",miljoonat,tuhannet,ykkoset);
286 }
287 else if (tuhannet) {
288 number.Format("%d %3.3d",tuhannet,ykkoset);
289 }
290 else {
291 number.Format("%d",ykkoset);
292 }
293}
294
296{
297 int i,count;
298 if (!MetalManager)
299 {
300 INIClass ini;
301 ini.Load("metals.ini");
303 }
304
305 count=MetalManager->Metal_Map_Count();
306 for (i=0; i<count; i++)
307 {
308 TextureClass *tex=MetalManager->Get_Metal_Map(i);
309 TextureHash.Insert(tex->Get_Texture_Name(),tex);
310 }
311}
312
313static void Log_Textures(bool inited,unsigned& total_count, unsigned& total_mem)
314{
316 for (ite.First();!ite.Is_Done();ite.Next()) {
317 TextureClass * tex=ite.Peek_Value();
318 if (tex->Is_Initialized()!=inited) continue;
319
320 D3DSURFACE_DESC desc;
321 IDirect3DTexture8* d3d_texture=tex->Peek_D3D_Texture();
322 if (!d3d_texture) continue;
323 DX8_ErrorCode(d3d_texture->GetLevelDesc(0,&desc));
324
325 StringClass tex_format="Unknown";
326 switch (desc.Format) {
327 case D3DFMT_A8R8G8B8: tex_format="D3DFMT_A8R8G8B8"; break;
328 case D3DFMT_R8G8B8: tex_format="D3DFMT_R8G8B8"; break;
329 case D3DFMT_A4R4G4B4: tex_format="D3DFMT_A4R4G4B4"; break;
330 case D3DFMT_A1R5G5B5: tex_format="D3DFMT_A1R5G5B5"; break;
331 case D3DFMT_R5G6B5: tex_format="D3DFMT_R5G6B5"; break;
332 case D3DFMT_L8: tex_format="D3DFMT_L8"; break;
333 case D3DFMT_A8: tex_format="D3DFMT_A8"; break;
334 case D3DFMT_P8: tex_format="D3DFMT_P8"; break;
335 case D3DFMT_X8R8G8B8: tex_format="D3DFMT_X8R8G8B8"; break;
336 case D3DFMT_X1R5G5B5: tex_format="D3DFMT_X1R5G5B5"; break;
337 case D3DFMT_R3G3B2: tex_format="D3DFMT_R3G3B2"; break;
338 case D3DFMT_A8R3G3B2: tex_format="D3DFMT_A8R3G3B2"; break;
339 case D3DFMT_X4R4G4B4: tex_format="D3DFMT_X4R4G4B4"; break;
340 case D3DFMT_A8P8: tex_format="D3DFMT_A8P8"; break;
341 case D3DFMT_A8L8: tex_format="D3DFMT_A8L8"; break;
342 case D3DFMT_A4L4: tex_format="D3DFMT_A4L4"; break;
343 case D3DFMT_V8U8: tex_format="D3DFMT_V8U8"; break;
344 case D3DFMT_L6V5U5: tex_format="D3DFMT_L6V5U5"; break;
345 case D3DFMT_X8L8V8U8: tex_format="D3DFMT_X8L8V8U8"; break;
346 case D3DFMT_Q8W8V8U8: tex_format="D3DFMT_Q8W8V8U8"; break;
347 case D3DFMT_V16U16: tex_format="D3DFMT_V16U16"; break;
348 case D3DFMT_W11V11U10: tex_format="D3DFMT_W11V11U10"; break;
349 case D3DFMT_UYVY: tex_format="D3DFMT_UYVY"; break;
350 case D3DFMT_YUY2: tex_format="D3DFMT_YUY2"; break;
351 case D3DFMT_DXT1: tex_format="D3DFMT_DXT1"; break;
352 case D3DFMT_DXT2: tex_format="D3DFMT_DXT2"; break;
353 case D3DFMT_DXT3: tex_format="D3DFMT_DXT3"; break;
354 case D3DFMT_DXT4: tex_format="D3DFMT_DXT4"; break;
355 case D3DFMT_DXT5: tex_format="D3DFMT_DXT5"; break;
356 case D3DFMT_D16_LOCKABLE: tex_format="D3DFMT_D16_LOCKABLE"; break;
357 case D3DFMT_D32: tex_format="D3DFMT_D32"; break;
358 case D3DFMT_D15S1: tex_format="D3DFMT_D15S1"; break;
359 case D3DFMT_D24S8: tex_format="D3DFMT_D24S8"; break;
360 case D3DFMT_D16: tex_format="D3DFMT_D16"; break;
361 case D3DFMT_D24X8: tex_format="D3DFMT_D24X8"; break;
362 case D3DFMT_D24X4S4: tex_format="D3DFMT_D24X4S4"; break;
363 default: break;
364 }
365
366 unsigned texmem=tex->Get_Texture_Memory_Usage();
367 total_mem+=texmem;
368 total_count++;
369 StringClass number;
370 Create_Number_String(number,texmem);
371
372 WWDEBUG_SAY(("%32s %4d * %4d (%15s), init %d, size: %14s bytes, refs: %d\n",
373 tex->Get_Texture_Name(),
374 desc.Width,
375 desc.Height,
376 tex_format,
377 tex->Is_Initialized(),
378 number,
379 tex->Num_Refs()));
380
381 }
382}
383
385{
386 unsigned total_initialized_tex_mem=0;
387 unsigned total_uninitialized_tex_mem=0;
388 unsigned total_initialized_count=0;
389 unsigned total_uninitialized_count=0;
390 StringClass number;
391
392 WWDEBUG_SAY(("\nInitialized textures ------------------------------------------\n\n"));
393 Log_Textures(true,total_initialized_count,total_initialized_tex_mem);
394
395 Create_Number_String(number,total_initialized_tex_mem);
396 WWDEBUG_SAY(("\n%d initialized textures, totalling %14s bytes\n\n",
397 total_initialized_count,
398 number));
399
400 WWDEBUG_SAY(("\nUn-initialized textures ---------------------------------------\n\n"));
401 Log_Textures(false,total_uninitialized_count,total_uninitialized_tex_mem);
402
403 Create_Number_String(number,total_uninitialized_tex_mem);
404 WWDEBUG_SAY(("\n%d un-initialized textures, totalling, totalling %14s bytes\n\n",
405 total_uninitialized_count,
406 number));
407/*
408 RenderObjIterator * rite=WW3DAssetManager::Get_Instance()->Create_Render_Obj_Iterator();
409 if (rite) {
410 for (rite->First(); !rite->Is_Done(); rite->Next()) {
411// RenderObjClass * robj=Create_Render_Obj(rite->Current_Item_Name());
412// if (robj) {
413//
414// robj->Release_Ref();
415// }
416 if (rite->Current_Item_Class_ID()==RenderObjClass::CLASSID_HMODEL) {
417 WWDEBUG_SAY(("robj: %s\n",rite->Current_Item_Name()));
418 }
419 }
420
421 WW3DAssetManager::Get_Instance()->Release_Render_Obj_Iterator(rite);
422 }
423*/
424}
425
426/***********************************************************************************************
427 * WW3DAssetManager::Free -- free all memory (un-needed?) *
428 * *
429 * INPUT: *
430 * *
431 * OUTPUT: *
432 * *
433 * WARNINGS: *
434 * *
435 * HISTORY: *
436 * 12/21/97 GTH : Created. *
437 *=============================================================================================*/
439{
440 Free_Assets();
441}
442
443
444/***********************************************************************************************
445 * WW3DAssetManager::Free_Assets -- Release all loaded assets *
446 * *
447 * INPUT: *
448 * *
449 * OUTPUT: *
450 * *
451 * WARNINGS: *
452 * *
453 * HISTORY: *
454 * 12/21/97 GTH : Created. *
455 * 05/10/1999 SKB : Close down texture cache file. *
456 *=============================================================================================*/
458{
459 WWPROFILE( "WW3DAssetManager::Free_Assets" );
460
461 // delete all of the prototypes
462 int count = Prototypes.Count();
463 while (count-- > 0) {
464
465 PrototypeClass * proto = Prototypes[count];
466 Prototypes.Delete(count);
467
468 if (proto != NULL) {
469 proto->DeleteSelf();
470 }
471 }
472
473 // clear the prototype hash table
475
476 // delete all of the anims and trees
477 HAnimManager.Free_All_Anims();
478 HTreeManager.Free_All_Trees();
479
480 // release all my references to the materials
484
485 // Close down cache if it is open.
486 // NONONONOO.... Don't close it as we might want to free the assets and still be able to load textures.
487// Close_Texture_File_Cache();
488}
489
490
491/***********************************************************************************************
492 * WW3DAssetManager::Free_Unused_Assets -- Release all assets that are referenced only by *
493 * the asset manager. *
494 * INPUT: *
495 * *
496 * OUTPUT: *
497 * *
498 * WARNINGS: *
499 * *
500 * HISTORY: *
501 * 02/18/99 EHC : Created. *
502 *=============================================================================================*/
504{
505 // release all references to objects that have only one reference on them
506 // and remove them from our lists.
509}
510
511/***********************************************************************************************
512 * WW3DAssetManager::Free_Assets_With_Exclusion_List -- Release all assets that are not named *
513 * in the exclusion list. *
514 * *
515 * This function checks if each prototype is named or is a child of something named in the *
516 * given exclusion list. *
517 * *
518 * INPUT: *
519 * exclusion_list - list of names of render object prototypes to not release. *
520 * *
521 * OUTPUT: *
522 * *
523 * WARNINGS: *
524 * *
525 * HISTORY: *
526 * 12/12/2002 GH : Created. *
527 *=============================================================================================*/
529{
530 // Reset the dx8 mesh renderer
531 TheDX8MeshRenderer.Invalidate();
532
533 // Build an exclusion list object that will do the real filtering work for us
534 W3DExclusionListClass exclusion_list(exclusion_names);
535
536 // temporary vector to hold the prototypes that get excluded from being deleted.
537 // grow by the initial size so we don't waste lots of time re-allocating!
538 const int DEFAULT_EXCLUDE_ARRAY_SIZE = 8000;
539 DynamicVectorClass<PrototypeClass *> exclude_array(DEFAULT_EXCLUDE_ARRAY_SIZE);
540 exclude_array.Set_Growth_Step(DEFAULT_EXCLUDE_ARRAY_SIZE);
541
542 // iterate the array of prototypes saving each one that should be excluded from deletion
543 for (int i=0; i<Prototypes.Count(); i++) {
544
545 PrototypeClass * proto = Prototypes[i];
546 if (proto != NULL) {
547
548 // If this prototype is excluded, copy the pointer, otherwise delete it.
549 if (exclusion_list.Is_Excluded(proto)) {
550 //WWDEBUG_SAY(("excluding %s\n",proto->Get_Name()));
551 exclude_array.Add(proto);
552 } else {
553 //WWDEBUG_SAY(("deleting %s\n",proto->Get_Name()));
554 proto->DeleteSelf();
555 }
556 Prototypes[i] = NULL;
557 }
558 }
559
560 // reset the array now that we've gotten rid of everything.
561 Prototypes.Reset_Active();
562
563 // clear the prototype hash table
565
566 // re-add the prototypes that we saved
567 for (i=0; i<exclude_array.Count(); i++) {
568 Add_Prototype(exclude_array[i]);
569 }
570
571 // delete all of the anims and trees
572 HAnimManager.Free_All_Anims_With_Exclusion_List(exclusion_list);
573 HTreeManager.Free_All_Trees_With_Exclusion_List(exclusion_list);
574
575 // release references to textures that are not used
577
578}
579
580/***********************************************************************************************
581 * WW3DAssetManager::Create_Asset_List -- Create a list of the W3D files that are loaded *
582 * *
583 * This function checks if each prototype is named or is a child of something named in the *
584 * given exclusion list. *
585 * *
586 * INPUT: *
587 * model_list - dynamic vector to populate with names of w3d files loaded *
588 * *
589 * OUTPUT: *
590 * *
591 * WARNINGS: *
592 * As in other places in the code, we are assuming that w3d filenames match the "top-level" *
593 * render object contained within them! *
594 * *
595 * HISTORY: *
596 * 12/12/2002 GH : Created. *
597 *=============================================================================================*/
599{
600 for (int i=0; i<Prototypes.Count(); i++) {
601 // ok, we ignore all of the following:
602 // - sub objects, these will have a '.' in their name
603 // - munged objects, these will have # characters in their name
604 PrototypeClass * proto = Prototypes[i];
605 if (proto) {
606 const char * name = proto->Get_Name();
607
608 if ((strchr(name,'#') == NULL) && (strchr(name,'.') == NULL)) {
609 model_list.Add(StringClass(name));
610 }
611 }
612 }
613
614 // Add in the w3d files for all of the animations
615 HAnimManager.Create_Asset_List(model_list);
616}
617
618
619/***********************************************************************************************
620 * WW3DAssetManager::Load_3D_Assets -- Load 3D assets from a file *
621 * *
622 * INPUT: *
623 * *
624 * OUTPUT: *
625 * *
626 * WARNINGS: *
627 * *
628 * HISTORY: *
629 * 10/22/98 BMG : Created. *
630 *=============================================================================================*/
631bool WW3DAssetManager::Load_3D_Assets( const char * filename )
632{
633 bool result = false;
634
635 FileClass * file = _TheFileFactory->Get_File( filename );
636 if ( file ) {
637 if ( file->Is_Available() ) {
638 result = WW3DAssetManager::Load_3D_Assets( *file );
639 } else {
640 WWDEBUG_SAY(("Missing asset '%s'.\n", filename));
641 }
642 _TheFileFactory->Return_File( file );
643 }
644
645 return result;
646}
647
648
649/***********************************************************************************************
650 * WW3DAssetManager::Load_3D_Assets -- Load 3D assets from a .W3D file *
651 * *
652 * INPUT: *
653 * *
654 * OUTPUT: *
655 * *
656 * WARNINGS: *
657 * *
658 * HISTORY: *
659 * 12/21/97 GTH : Created. *
660 *=============================================================================================*/
662{
663 WWPROFILE( "WW3DAssetManager::Load_3D_Assets" );
664 if (!w3dfile.Open()) {
665 return false;
666 }
667
668 ChunkLoadClass cload(&w3dfile);
669
670 while (cload.Open_Chunk()) {
671
672 switch (cload.Cur_Chunk_ID()) {
673
675 HTreeManager.Load_Tree(cload);
676 break;
677
681 HAnimManager.Load_Anim(cload);
682 break;
683
684 default:
685 Load_Prototype(cload);
686 break;
687 }
688
689 cload.Close_Chunk();
690 }
691
692 w3dfile.Close();
693
694 return true;
695}
696
697
698/***********************************************************************************************
699 * WW3DAssetManager::Load_Prototype -- loads a prototype from a W3D chunk *
700 * *
701 * INPUT: *
702 * *
703 * OUTPUT: *
704 * *
705 * WARNINGS: *
706 * *
707 * HISTORY: *
708 * 7/29/98 GTH : Created. *
709 * 2/19/99 EHC : Now has the Add_Prototype call responsible for adding the prototype to *
710 * the Prototypes list object. *
711 *=============================================================================================*/
713{
714 WWPROFILE( "WW3DAssetManager::Load_Prototype" );
716
717 /*
718 ** Get the chunk id
719 */
720 int chunk_id = cload.Cur_Chunk_ID();
721
722 /*
723 ** Find a loader that handles that type of chunk
724 */
725 PrototypeLoaderClass * loader = Find_Prototype_Loader(chunk_id);
726 PrototypeClass * newproto = NULL;
727
728 if (loader != NULL) {
729
730 /*
731 ** Ask it to create a prototype from the contents of the
732 ** chunk.
733 */
734 newproto = loader->Load_W3D(cload);
735
736 } else {
737
738 /*
739 ** Warn user about an unknown chunk type
740 */
741 WWDEBUG_SAY(("Unknown chunk type encountered! Chunk Id = %d\r\n",chunk_id));
742 return false;
743 }
744
745 /*
746 ** Now, see if the prototype that we loaded has a duplicate
747 ** name with any of our currently loaded prototypes (can't have that!)
748 */
749 if (newproto != NULL) {
750
751 if (!Render_Obj_Exists(newproto->Get_Name())) {
752
753 /*
754 ** Add the new, unique prototype to our list
755 */
756 Add_Prototype(newproto);
757
758 } else {
759
760 /*
761 ** Warn the user about a name collision with this prototype
762 ** and dump it
763 */
764 WWDEBUG_SAY(("Render Object Name Collision: %s\r\n",newproto->Get_Name()));
765 newproto->DeleteSelf();
766 newproto = NULL;
767 return false;
768 }
769
770 } else {
771
772 /*
773 ** Warn user that a prototype was not generated from this
774 ** chunk type
775 */
776 WWDEBUG_SAY(("Could not generate prototype! Chunk = %d\r\n",chunk_id));
777 return false;
778 }
779
780 return true;
781}
782
783
784/***********************************************************************************************
785 * WW3DAssetManager::Create_Render_Obj -- Create a render object for the user *
786 * *
787 * This function will create any type of render object. I.e. if you pass in the name *
788 * of an HModel, it will create an hmodel for you. *
789 * *
790 * INPUT: *
791 * *
792 * OUTPUT: *
793 * *
794 * WARNINGS: *
795 * *
796 * HISTORY: *
797 * 12/21/97 GTH : Created. *
798 *=============================================================================================*/
800{
801 WWPROFILE( "WW3DAssetManager::Create_Render_Obj" );
803
804 // Try to find a prototype
805 PrototypeClass * proto = Find_Prototype(name);
806
807 if (WW3D_Load_On_Demand && proto == NULL) { // If we didn't find one, try to load on demand
809
810 char filename [MAX_PATH];
811 char *mesh_name = ::strchr (name, '.');
812 if (mesh_name != NULL) {
813 ::lstrcpyn (filename, name, ((int)mesh_name) - ((int)name) + 1);
814 ::lstrcat (filename, ".w3d");
815 } else {
816 sprintf( filename, "%s.w3d", name);
817 }
818
819 // If we can't find it, try the parent directory
820 if ( Load_3D_Assets( filename ) == false ) {
821 StringClass new_filename(StringClass("..\\"),true);
822 new_filename+=filename;
823 Load_3D_Assets( new_filename );
824 }
825
826 proto = Find_Prototype(name); // try again
827 }
828
829 if (proto == NULL) {
830 static int warning_count = 0;
831 // Note - objects named "#..." are scaled cached objects, so don't warn...
832 if (name[0] != '#') {
833 if (++warning_count <= 20) {
834 WWDEBUG_SAY(("WARNING: Failed to create Render Object: %s\r\n",name));
835 }
837 }
838 return NULL; // Failed to find a prototype
839 }
840
841 return proto->Create();
842}
843
844
845/***********************************************************************************************
846 * WW3DAssetManager::Render_Obj_Exists -- Check whether a render object with the given name ex *
847 * *
848 * INPUT: *
849 * *
850 * OUTPUT: *
851 * *
852 * WARNINGS: *
853 * *
854 * HISTORY: *
855 * 12/21/97 GTH : Created. *
856 *=============================================================================================*/
858{
859 if (Find_Prototype(name) == NULL) return false;
860 else return true;
861}
862
863
864/***********************************************************************************************
865 * WW3DAssetManager::Create_Render_Obj_Iterator -- Create an iterator which can enumerate all *
866 * *
867 * The iterator returned can enumerate all of the loaded render objects for you. *
868 * The user is responsible for releasing the iterator! *
869 * *
870 * INPUT: *
871 * *
872 * OUTPUT: *
873 * *
874 * WARNINGS: *
875 * User must release the iterator back to the asset manager or there will be a memory leak *
876 * *
877 * HISTORY: *
878 * 12/21/97 GTH : Created. *
879 *=============================================================================================*/
884
885
886/***********************************************************************************************
887 * WW3DAssetManager::Release_Render_Obj_Iterator -- release a render object iterator *
888 * *
889 * INPUT: *
890 * *
891 * OUTPUT: *
892 * *
893 * WARNINGS: *
894 * *
895 * HISTORY: *
896 * 9/28/98 GTH : Created. *
897 *=============================================================================================*/
899{
900 WWASSERT(it != NULL);
901 delete it;
902}
903
904/***********************************************************************************************
905 * WW3DAssetManager::Create_HAnim_Iterator -- Creates an HAnim Iterator *
906 * *
907 * Creates an iterator which can enumerate each of the named hierarchical animations *
908 * which are currently loaded. *
909 * *
910 * INPUT: *
911 * *
912 * OUTPUT: *
913 * *
914 * WARNINGS: *
915 * User must delete the iterator! *
916 * *
917 * HISTORY: *
918 * 12/21/97 GTH : Created. *
919 *=============================================================================================*/
924
925
926/***********************************************************************************************
927 * WW3DAssetManager::Create_HTree_Iterator -- creates an htree iterator *
928 * *
929 * INPUT: *
930 * *
931 * OUTPUT: *
932 * *
933 * WARNINGS: *
934 * *
935 * HISTORY: *
936 * 3/11/98 GTH : Created. *
937 *=============================================================================================*/
942
943
944/***********************************************************************************************
945 * WW3DAssetManager::Create_Font3DData_Iterator -- Create a Font3DData iterator *
946 * *
947 * Creates an iterator which can enumerate each of the Font3DDatas currently loaded *
948 * *
949 * INPUT: *
950 * *
951 * OUTPUT: *
952 * *
953 * WARNINGS: *
954 * User must delete the iterator! *
955 * *
956 * HISTORY: *
957 * 1/6/98 GTH : Created. *
958 *=============================================================================================*/
963
964/***********************************************************************************************
965 * WW3DAssetManager::Get_HAnim -- Returns a pointer to a names HAnim *
966 * *
967 * INPUT: *
968 * *
969 * OUTPUT: *
970 * *
971 * WARNINGS: *
972 * The implementation has changed since its inception, the asset manager no longer owns the *
973 * hanim's so they need to be released by the caller. *
974 * *
975 * HISTORY: *
976 * 12/21/97 GTH : Created. *
977 *=============================================================================================*/
979{
980 WWPROFILE( "WW3DAssetManager::Get_HAnim" );
981
982 // Try to find the hanim
983 HAnimClass * anim = HAnimManager.Get_Anim(name);
984
985 if (WW3D_Load_On_Demand && anim == NULL) { // If we didn't find it, try to load on demand
986
987 if ( !HAnimManager.Is_Missing( name ) ) { // if this is NOT a known missing anim
988
990
991 char filename[ MAX_PATH ];
992 char *animname = strchr( name, '.');
993 if (animname != NULL) {
994 sprintf( filename, "%s.w3d", animname+1);
995 } else {
996 WWDEBUG_SAY(( "Animation %s has no . in the name\n", name ));
997 WWASSERT( 0 );
998 return NULL;
999 }
1000
1001 // If we can't find it, try the parent directory
1002 if ( Load_3D_Assets( filename ) == false ) {
1003 StringClass new_filename = StringClass("..\\") + filename;
1004 Load_3D_Assets( new_filename );
1005 }
1006
1007 anim = HAnimManager.Get_Anim(name); // Try agai
1008 if (anim == NULL) {
1009 HAnimManager.Register_Missing( name ); // This is now a KNOWN missing anim
1011 }
1012 }
1013 }
1014
1015 return anim;
1016}
1017
1018
1019/***********************************************************************************************
1020 * WW3DAssetManager::Get_HTree -- Returns a pointer to the named HTree *
1021 * *
1022 * INPUT: *
1023 * *
1024 * OUTPUT: *
1025 * *
1026 * WARNINGS: *
1027 * DO NOT DELETE the HTree you get from this function, it is "owned" by the asset manager. *
1028 * *
1029 * HISTORY: *
1030 * 12/21/97 GTH : Created. *
1031 *=============================================================================================*/
1033{
1034 WWPROFILE( "WW3DAssetManager::Get_HTree" );
1035
1036 // Try to find the htree
1037 HTreeClass * htree = HTreeManager.Get_Tree(name);
1038
1039 if (WW3D_Load_On_Demand && htree == NULL) { // If we didn't find it, try to load on demand
1040
1042
1043 char filename[ MAX_PATH ];
1044 sprintf( filename, "%s.w3d", name);
1045
1046 // If we can't find it, try the parent directory
1047 if ( Load_3D_Assets( filename ) == false ) {
1048 StringClass new_filename("..\\",true);
1049 new_filename+=filename;
1050 Load_3D_Assets( new_filename );
1051 }
1052
1053 htree = HTreeManager.Get_Tree(name); // Try again
1054
1055 if (htree == NULL) {
1057 }
1058 }
1059
1060 return htree;
1061}
1062
1063/***********************************************************************************************
1064 * WW3DAssetManager::Get_Texture -- get a TextureClass from the specified file *
1065 * *
1066 * INPUT: *
1067 * *
1068 * OUTPUT: *
1069 * *
1070 * WARNINGS: *
1071 * *
1072 * HISTORY: *
1073 * 1/31/2001 NH : Created. *
1074 *=============================================================================================*/
1076(
1077 const char * filename,
1078 MipCountType mip_level_count,
1079 WW3DFormat texture_format,
1080 bool allow_compression,
1082 bool allow_reduction
1083)
1084{
1085 WWPROFILE( "WW3DAssetManager::Get_Texture 1" );
1086
1087 /*
1088 ** We cannot currently mip-map bumpmaps
1089 */
1090 if (texture_format==WW3D_FORMAT_U8V8)
1091 {
1092 mip_level_count=MIP_LEVELS_1;
1093 }
1094
1095 /*
1096 ** Bail if the user isn't really asking for anything
1097 */
1098 if ((filename == NULL) || (strlen(filename) == 0))
1099 {
1100 return NULL;
1101 }
1102
1103 StringClass lower_case_name(filename,true);
1104 _strlwr(lower_case_name.Peek_Buffer());
1105
1106 /*
1107 ** See if the texture has already been loaded.
1108 */
1109 TextureClass* tex = TextureHash.Get(lower_case_name);
1110 if (tex && (tex->Is_Initialized() == true) && (texture_format!=WW3D_FORMAT_UNKNOWN))
1111 {
1112 WWASSERT_PRINT(tex->Get_Texture_Format()==texture_format,("Texture %s has already been loaded with different format",filename));
1113 }
1114
1115 /*
1116 ** Didn't have it so we have to create a new texture
1117 */
1118 if (!tex)
1119 {
1121 {
1122 tex = NEW_REF (TextureClass, (lower_case_name, NULL, mip_level_count, texture_format, allow_compression, allow_reduction));
1123 }
1124 else if (type==TextureBaseClass::TEX_CUBEMAP)
1125 {
1126 tex = NEW_REF (CubeTextureClass, (lower_case_name, NULL, mip_level_count, texture_format, allow_compression, allow_reduction));
1127 }
1128 else if (type==TextureBaseClass::TEX_VOLUME)
1129 {
1130 tex = NEW_REF (VolumeTextureClass, (lower_case_name, NULL, mip_level_count, texture_format, allow_compression, allow_reduction));
1131 }
1132 TextureHash.Insert(tex->Get_Texture_Name(),tex);
1133 }
1134
1135 tex->Add_Ref();
1136 return tex;
1137}
1138
1139
1140/***********************************************************************************************
1141 * WW3DAssetManager::Release_All_Textures -- release all textures in the system *
1142 * *
1143 * INPUT: *
1144 * *
1145 * OUTPUT: *
1146 * *
1147 * WARNINGS: *
1148 * *
1149 * HISTORY: *
1150 * 3/10/98 GTH : Created. *
1151 *=============================================================================================*/
1153{
1154 /*
1155 ** for each texture in the list, get it and release ref it
1156 */
1157
1159 for (ite.First();!ite.Is_Done();ite.Next()) {
1160 TextureClass * tex=ite.Peek_Value();
1161// WWASSERT(tex->Num_Refs()==1); // If asset manager is releasing the texture,
1162 // nobody should be referencing to it anymore!
1163 tex->Release_Ref();
1164 }
1165 TextureHash.Remove_All();
1166}
1167
1168
1169/***********************************************************************************************
1170 * WW3DAssetManager::Release_Unused_Textures -- release all textures with refcount == 1 *
1171 * *
1172 * INPUT: *
1173 * *
1174 * OUTPUT: *
1175 * *
1176 * WARNINGS: *
1177 * *
1178 * HISTORY: *
1179 * 2/18/99 EHC : Created. *
1180 *=============================================================================================*/
1182{
1183 /*
1184 ** for each texture in the list, get it, check it's refcount, and and release ref it if the
1185 ** refcount is one.
1186 */
1187
1188 unsigned count=0;
1189 TextureClass* temp_textures[256];
1190
1192 for (ite.First();!ite.Is_Done();ite.Next()) {
1193 TextureClass* tex=ite.Peek_Value();
1194 if (tex->Num_Refs() == 1) {
1195 temp_textures[count++]=tex;
1196 if (count==256) {
1197 for (unsigned i=0;i<256;++i) {
1198 TextureHash.Remove(temp_textures[i]->Get_Texture_Name());
1199 temp_textures[i]->Release_Ref();
1200 }
1201 count=0;
1202 ite.First(); // iterator doesn't support modifying the hash table while iterating, so start from the
1203 // beginning.
1204 }
1205 }
1206 }
1207 for (unsigned i=0;i<count;++i) {
1208 TextureHash.Remove(temp_textures[i]->Get_Texture_Name());
1209 temp_textures[i]->Release_Ref();
1210 }
1211}
1212
1213/***********************************************************************************************
1214 * WW3DAssetManager::Release_Texture -- release a specific texture from the asset manager *
1215 * *
1216 * INPUT: *
1217 * *
1218 * OUTPUT: *
1219 * *
1220 * WARNINGS: *
1221 * *
1222 * HISTORY: *
1223 * 2/18/99 EHC : Created. *
1224 *=============================================================================================*/
1226{
1227 /*
1228 ** Try to find the texture in the list, if found release it and remove it from the list.
1229 */
1230
1231 TextureHash.Remove(tex->Get_Texture_Name());
1232 tex->Release_Ref();
1233}
1234
1236{
1238
1240
1241 // Log lightmaps -----------------------------------
1242
1243 WWDEBUG_SAY((
1244 "Lightmap textures: %d\n\n"
1245 "size name\n"
1246 "--------------------------------------\n"
1247 ,
1249
1250 for (ite.First();!ite.Is_Done();ite.Next()) {
1251 TextureClass* t=ite.Peek_Value();
1252 if (!t->Is_Lightmap()) continue;
1253
1254 StringClass tmp(true);
1255 unsigned bytes=t->Get_Texture_Memory_Usage();
1256 if (!t->Is_Initialized()) {
1257 tmp+="*";
1258 }
1259 else {
1260 tmp+=" ";
1261 }
1262 WWDEBUG_SAY(("%4.4dkb %s%s\n",bytes/1024,tmp,t->Get_Texture_Name()));
1263 }
1264
1265 // Log procedural textures -------------------------------
1266
1267 WWDEBUG_SAY((
1268 "Procedural textures: %d\n\n"
1269 "size name\n"
1270 "--------------------------------------\n"
1271 ,
1273
1274 for (ite.First();!ite.Is_Done();ite.Next()) {
1275 TextureClass* t=ite.Peek_Value();
1276 if (!t->Is_Procedural()) continue;
1277
1278 StringClass tmp(true);
1279 unsigned bytes=t->Get_Texture_Memory_Usage();
1280 if (!t->Is_Initialized()) {
1281 tmp+="*";
1282 }
1283 else {
1284 tmp+=" ";
1285 }
1286 WWDEBUG_SAY(("%4.4dkb %s%s\n",bytes/1024,tmp,t->Get_Texture_Name()));
1287 }
1288
1289 // Log "ordinary" textures -------------------------------
1290
1291 WWDEBUG_SAY((
1292 "Ordinary textures: %d\n\n"
1293 "size name\n"
1294 "--------------------------------------\n"
1295 ,
1297
1298 for (ite.First();!ite.Is_Done();ite.Next()) {
1299 TextureClass* t=ite.Peek_Value();
1300 if (t->Is_Procedural()) continue;
1301 if (t->Is_Lightmap()) continue;
1302
1303 StringClass tmp(true);
1304 unsigned bytes=t->Get_Texture_Memory_Usage();
1305 if (!t->Is_Initialized()) {
1306 tmp+="*";
1307 }
1308 else {
1309 tmp+=" ";
1310 }
1311 WWDEBUG_SAY(("%4.4dkb %s%s\n",bytes/1024,tmp,t->Get_Texture_Name()));
1312 }
1313
1314}
1315
1316
1317
1318/***********************************************************************************************
1319 * WW3DAssetManager::Get_Font3DInstance -- Creates a pointer to a Font3DInstance *
1320 * *
1321 * INPUT: *
1322 * *
1323 * OUTPUT: *
1324 * *
1325 * WARNINGS: *
1326 * *
1327 * HISTORY: *
1328 * 1/6/98 GTH : Created. *
1329 *=============================================================================================*/
1331{
1332 WWPROFILE( "WW3DAssetManager::Get_Font3DInstance" );
1333 return NEW_REF( Font3DInstanceClass, ( name ));
1334}
1335
1336
1337/***********************************************************************************************
1338 * WW3DAssetManager::Get_Font3DData -- Gets a pointer to a loaded Font3DData or creates it *
1339 * *
1340 * INPUT: *
1341 * *
1342 * OUTPUT: *
1343 * *
1344 * WARNINGS: *
1345 * *
1346 * HISTORY: *
1347 * 1/6/98 GTH : Created. *
1348 *=============================================================================================*/
1350{
1351 WWPROFILE( "WW3DAssetManager::Get_Font3DData" );
1352 // loop through and see if the Font3D we are looking for has already been
1353 // allocated and thus we can just return it.
1354 for ( SLNode<Font3DDataClass> *node = Font3DDatas.Head(); node; node = node->Next()) {
1355 if (!stricmp(name, node->Data()->Name)) {
1356 node->Data()->Add_Ref();
1357 return node->Data();
1358 }
1359 }
1360
1361 // if one hasn't been found and a font name has been specified then create it
1362 Font3DDataClass * font = NEW_REF( Font3DDataClass, ( name ));
1363
1364 // add it to the asset manager
1365 Add_Font3DData( font);
1366
1367 // return it
1368 return font;
1369}
1370
1371/***********************************************************************************************
1372 * WW3DAssetManager::Add_Font3DData -- Add a Font3DData to the list *
1373 * *
1374 * INPUT: *
1375 * *
1376 * OUTPUT: *
1377 * *
1378 * WARNINGS: *
1379 * *
1380 * HISTORY: *
1381 * 1/6/98 GTH : Created. *
1382 *=============================================================================================*/
1384{
1385 font->Add_Ref();
1386 Font3DDatas.Add_Head(font);
1387}
1388
1390{
1391 font->Release_Ref();
1392 Font3DDatas.Remove(font);
1393}
1394
1395/***********************************************************************************************
1396 * WW3DAssetManager::Release_All_Font3DDatas -- Release all Font3DDatas from the asset manager *
1397 * *
1398 * INPUT: *
1399 * *
1400 * OUTPUT: *
1401 * *
1402 * WARNINGS: *
1403 * *
1404 * HISTORY: *
1405 * 1/6/98 GTH : Created. *
1406 *=============================================================================================*/
1408{
1409 // for each mat in the list, get it and release ref it
1410 Font3DDataClass *head;
1411 while ((head = Font3DDatas.Remove_Head()) != NULL ) {
1412 head->Release_Ref();
1413 }
1414}
1415
1416/***********************************************************************************************
1417 * WW3DAssetManager::Release_Unused_Font3DDatas -- Release all Font3DDatas with refcount == 1 *
1418 * *
1419 * INPUT: *
1420 * *
1421 * OUTPUT: *
1422 * *
1423 * WARNINGS: *
1424 * *
1425 * HISTORY: *
1426 * 1/6/98 GTH : Created. *
1427 *=============================================================================================*/
1429{
1430 /*
1431 ** for each font data in the list, get it, check it's refcount, and and release ref it if the
1432 ** refcount is one.
1433 */
1434 SLNode<Font3DDataClass> *node, * next;
1435 for ( node = Font3DDatas.Head(); node; node = next) {
1436 next = node->Next();
1437 Font3DDataClass *font = node->Data();
1438 if (font->Num_Refs() == 1) {
1439 Font3DDatas.Remove(font);
1440 font->Release_Ref();
1441 }
1442 }
1443}
1444
1445/***********************************************************************************************
1446 * WW3DAssetManager::Get_FontChars -- Gets a pointer to a loaded FontChars or creates it *
1447 * *
1448 * INPUT: *
1449 * *
1450 * OUTPUT: *
1451 * *
1452 * WARNINGS: *
1453 * *
1454 * HISTORY: *
1455 * 6/1/01 BMG : Created. *
1456 *=============================================================================================*/
1457FontCharsClass * WW3DAssetManager::Get_FontChars( const char * name, int point_size, bool is_bold )
1458{
1459 WWPROFILE( "WW3DAssetManager::Get_FontChars" );
1460
1461 // loop through and see if we already have the font chars and we can just return it.
1462 for ( int i = 0; i < FontCharsList.Count(); i++ ) {
1463 if ( FontCharsList[i]->Is_Font( name, point_size, is_bold ) ) {
1464 FontCharsList[i]->Add_Ref();
1465 return FontCharsList[i];
1466 }
1467 }
1468
1469 // If one hasn't been found, create it
1470 FontCharsClass * font = NEW_REF( FontCharsClass, () );
1471 font->Initialize_GDI_Font( name, point_size, is_bold );
1472 font->Add_Ref();
1473 FontCharsList.Add( font ); // add it to the list
1474 return font; // return it
1475}
1476
1477
1478/***********************************************************************************************
1479 * WW3DAssetManager::Release_All_FontChars -- Release all FontChars from the asset manager *
1480 * *
1481 * INPUT: *
1482 * *
1483 * OUTPUT: *
1484 * *
1485 * WARNINGS: *
1486 * *
1487 * HISTORY: *
1488 * 6/1/01 BMG : Created. *
1489 *=============================================================================================*/
1491{
1492 // for each fontchars in the list, get it and release ref it
1493 while ( FontCharsList.Count() ) {
1494 FontCharsList[0]->Release_Ref();
1495 FontCharsList.Delete( 0 );
1496 }
1497}
1498
1499/***********************************************************************************************
1500 * WW3DAssetManager::Register_Prototype_Loader -- add a new loader to the system *
1501 * *
1502 * The library will automatically install loaders for the "built-in" render object *
1503 * types. This function exists so that the user can design App-specific render objects, *
1504 * define a chunk format for them, and have the asset manager load them in like everything *
1505 * else. *
1506 * *
1507 * INPUT: *
1508 * loader - pointer to a global or static instance of your loader type. *
1509 * *
1510 * OUTPUT: *
1511 * *
1512 * WARNINGS: *
1513 * *
1514 * HISTORY: *
1515 * 7/28/98 GTH : Created. *
1516 *=============================================================================================*/
1518{
1519 WWASSERT(loader != NULL);
1520 PrototypeLoaders.Add(loader);
1521}
1522
1523
1524/***********************************************************************************************
1525 * WW3DAssetManager::Find_Prototype_Loader -- find the loader that handles this chunk type *
1526 * *
1527 * INPUT: *
1528 * chunk_id - chunk type that the loader needs to handle *
1529 * *
1530 * OUTPUT: *
1531 * pointer to the appropriate loader or NULL if one wasn't found *
1532 * *
1533 * WARNINGS: *
1534 * *
1535 * HISTORY: *
1536 * 7/28/98 GTH : Created. *
1537 *=============================================================================================*/
1539{
1540 for (int i=0; i<PrototypeLoaders.Count(); i++) {
1542 if (loader && loader->Chunk_Type() == chunk_id) {
1543 return loader;
1544 }
1545 }
1546 return NULL;
1547}
1548
1549
1550/***********************************************************************************************
1551 * WW3DAssetManager::Add_Prototype -- adds the prototype to the hash table *
1552 * *
1553 * INPUT: *
1554 * *
1555 * OUTPUT: *
1556 * *
1557 * WARNINGS: *
1558 * *
1559 * HISTORY: *
1560 * 7/29/98 GTH : Created. *
1561 * 12/8/98 GTH : Renamed to simply Add_Prototype *
1562 * 2/19/99 EHC : Now adds the prototype to the prototype list *
1563 *=============================================================================================*/
1565{
1566 WWASSERT(newproto != NULL);
1567 int hash = CRC_Stringi(newproto->Get_Name()) & PROTOTYPE_HASH_MASK;
1568 newproto->friend_setNextHash(PrototypeHashTable[hash]);
1569 PrototypeHashTable[hash] = newproto;
1570 Prototypes.Add(newproto);
1571}
1572
1573
1574/***********************************************************************************************
1575 * WW3DAssetManager::Remove_Prototype -- Removes all references to the protype. *
1576 * *
1577 * INPUT: *
1578 * *
1579 * OUTPUT: *
1580 * *
1581 * WARNINGS: *
1582 * *
1583 * HISTORY: *
1584 * 02/4/99 PDS : Created. *
1585 *=============================================================================================*/
1587{
1588 WWASSERT(proto != NULL);
1589 if (proto != NULL) {
1590
1591 //
1592 // Find the prototype in the hash table.
1593 //
1594 const char *pname = proto->Get_Name ();
1595 bool bfound = false;
1596 PrototypeClass *prev = NULL;
1597 int hash = CRC_Stringi(pname) & PROTOTYPE_HASH_MASK;
1599 (test != NULL) && (bfound == false);
1600 test = test->friend_getNextHash()) {
1601
1602 // Is this the prototype?
1603 if (::stricmp (test->Get_Name(), pname) == 0) {
1604
1605 // Remove this prototype from the linked list for this hash index.
1606 if (prev == NULL) {
1607 PrototypeHashTable[hash] = test->friend_getNextHash();
1608 } else {
1609 prev->friend_setNextHash(test->friend_getNextHash());
1610 }
1611
1612 // Success!
1613 bfound = true;
1614 }
1615
1616 // Remember who our previous entry is
1617 prev = test;
1618 }
1619
1620 // Now remove this from our vector-array of prototypes
1621 Prototypes.Delete (proto);
1622 }
1623
1624 return;
1625}
1626
1627
1628/***********************************************************************************************
1629 * WW3DAssetManager::Remove_Prototype -- Removes all references to the protype. *
1630 * *
1631 * INPUT: *
1632 * *
1633 * OUTPUT: *
1634 * *
1635 * WARNINGS: *
1636 * *
1637 * HISTORY: *
1638 * 02/4/99 PDS : Created. *
1639 *=============================================================================================*/
1641{
1642 WWASSERT(name != NULL);
1643 if (name != NULL) {
1644
1645 // Lookup the prototype by name
1646 PrototypeClass *proto = Find_Prototype (name);
1647 if (proto != NULL) {
1648
1649 // Remove the prototype from our lists, and free its memory
1650 Remove_Prototype (proto);
1651 proto->DeleteSelf();
1652 }
1653 }
1654
1655 return;
1656}
1657
1658
1659/***********************************************************************************************
1660 * WW3DAssetManager::Find_Prototype -- searches the hash table for the prototype *
1661 * *
1662 * INPUT: *
1663 * *
1664 * OUTPUT: *
1665 * *
1666 * WARNINGS: *
1667 * *
1668 * HISTORY: *
1669 * 7/29/98 GTH : Created. *
1670 * 12/8/98 GTH : Renamed to simply Find_Prototype *
1671 *=============================================================================================*/
1673{
1674 // Special case Null render object. So we always have it...
1675 if (stricmp(name,"NULL") == 0) {
1676 return &(_NullPrototype);
1677 }
1678
1679 // Find the prototype
1680 int hash = CRC_Stringi(name) & PROTOTYPE_HASH_MASK;
1682
1683 while (test != NULL) {
1684 if (stricmp(test->Get_Name(),name) == 0) {
1685 return test;
1686 }
1687 test = test->friend_getNextHash();
1688 }
1689 return NULL;
1690}
1691
1692/*
1693** Iterator Implementations.
1694** =====================================================================
1695** If the user derives a custom asset manager, you will have
1696** to implement iterators which can walk through your datastructures.
1697*/
1698
1700{
1702}
1703
1705{
1706 if (Index < WW3DAssetManager::Get_Instance()->Prototypes.Count()) {
1707 return WW3DAssetManager::Get_Instance()->Prototypes[Index]->Get_Name();
1708 } else {
1709 return NULL;
1710 }
1711}
1712
1714{
1715 if (Index < WW3DAssetManager::Get_Instance()->Prototypes.Count()) {
1716 return WW3DAssetManager::Get_Instance()->Prototypes[Index]->Get_Class_ID();
1717 } else {
1718 return -1;
1719 }
1720}
1721
1726
1731
1732
#define NULL
Definition BaseType.h:92
void const char * value
#define WWASSERT
@ W3D_CHUNK_HIERARCHY
Definition w3d_file.h:396
@ W3D_CHUNK_COMPRESSED_ANIMATION
Definition w3d_file.h:406
@ W3D_CHUNK_MORPH_ANIMATION
Definition w3d_file.h:411
@ W3D_CHUNK_ANIMATION
Definition w3d_file.h:401
#define W3DNEWARRAY
Definition always.h:110
#define W3DNEW
Definition always.h:109
@ false
Definition bool.h:59
unsigned long CRC_Stringi(const char *string, unsigned long crc)
Definition realcrc.cpp:168
AggregateLoaderClass _AggregateLoader
Definition agg_def.cpp:60
BoxLoaderClass _BoxLoader
Definition boxrobj.cpp:1389
AssetIterator(void)
Definition assetmgr.h:98
void Report_Missing_HTree(const char *name)
void Report_Load_On_Demand_RObj(const char *name)
void Report_Missing_RObj(const char *name)
void Report_Missing_HAnim(const char *name)
void Report_Load_On_Demand_HTree(const char *name)
static AssetStatusClass * Peek_Instance()
Definition assetstatus.h:56
void Report_Load_On_Demand_HAnim(const char *name)
bool Close_Chunk()
Definition chunkio.cpp:448
uint32 Cur_Chunk_ID()
Definition chunkio.cpp:484
bool Open_Chunk()
Definition chunkio.cpp:412
int Count(void) const
Definition Vector.H:507
int Set_Growth_Step(int step)
Definition Vector.H:525
bool Add(T const &object)
Definition Vector.H:671
virtual bool Is_Available(int forced=false)=0
virtual void Close(void)=0
virtual int Open(char const *filename, int rights=READ)=0
virtual bool Is_Done(void)
Definition assetmgr.cpp:185
SLNode< Font3DDataClass > * Node
Definition assetmgr.cpp:191
virtual const char * Current_Item_Name(void)
Definition assetmgr.cpp:186
virtual void First(void)
Definition assetmgr.cpp:183
friend class WW3DAssetManager
Definition assetmgr.cpp:192
virtual void Next(void)
Definition assetmgr.cpp:184
void Initialize_GDI_Font(const char *font_name, int point_size, bool is_bold)
virtual bool Is_Done(void)
Definition assetmgr.cpp:162
HAnimIterator(void)
Definition assetmgr.cpp:158
friend class WW3DAssetManager
Definition assetmgr.cpp:167
virtual void First(void)
Definition assetmgr.cpp:160
HAnimManagerIterator Iterator
Definition assetmgr.cpp:166
virtual void Next(void)
Definition assetmgr.cpp:161
virtual const char * Current_Item_Name(void)
Definition assetmgr.cpp:163
WWINLINE const char * Get_Name(void) const
Definition htree.h:92
virtual const char * Current_Item_Name(void)
virtual bool Is_Done(void)
friend class WW3DAssetManager
Definition assetmgr.cpp:176
HTreeClass * Get_Tree(const char *name)
Definition htreemgr.cpp:296
int Num_Trees(void)
Definition htreemgr.h:73
ValueType & Peek_Value()
Definition INI.H:80
int Load(FileClass &file)
Definition ini.cpp:339
virtual RenderObjClass * Create(void)=0
virtual const char * Get_Name(void) const =0
virtual void DeleteSelf()=0
void friend_setNextHash(PrototypeClass *n)
Definition proto.h:97
virtual PrototypeClass * Load_W3D(ChunkLoadClass &cload)=0
virtual int Chunk_Type(void)=0
friend class WW3DAssetManager
Definition assetmgr.cpp:147
virtual int Current_Item_Class_ID(void)
virtual bool Is_Done(void)
virtual const char * Current_Item_Name(void)
int Num_Refs(void) const
Definition refcount.h:159
WWINLINE void Release_Ref(void) const
Definition refcount.h:146
void Add_Ref(void) const
Definition refcount.cpp:171
SLNode< T > * Next(void)
Definition SLNODE.H:99
T * Data(void)
Definition SLNODE.H:100
SLNode< T > * Head(void) const
Definition SLIST.H:370
int _cdecl Format(const TCHAR *format,...)
Definition wwstring.cpp:273
TCHAR * Peek_Buffer(void)
Definition wwstring.h:560
static int _Get_Total_Procedural_Texture_Count()
Get total procedural texture count.
Definition texture.cpp:552
IDirect3DTexture8 * Peek_D3D_Texture() const
Definition texture.h:205
bool Is_Procedural() const
Definition texture.h:147
const StringClass & Get_Texture_Name(void) const
Definition texture.h:112
static int _Get_Total_Texture_Count()
Get total texture count.
Definition texture.cpp:510
static int _Get_Total_Lightmap_Texture_Count()
Get total light map texture count.
Definition texture.cpp:531
bool Is_Initialized() const
Definition texture.h:145
bool Is_Lightmap() const
Definition texture.h:146
virtual unsigned Get_Texture_Memory_Usage() const
Get texture memory usage.
Definition texture.cpp:1036
WW3DFormat Get_Texture_Format() const
Definition texture.h:338
bool Is_Excluded(PrototypeClass *proto) const
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)
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 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)
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
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
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)
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 Activate_Fog_On_Load
Definition assetmgr.h:417
void Remove_Prototype(PrototypeClass *proto)
friend class Font3DDataIterator
Definition assetmgr.h:439
CollectionLoaderClass _CollectionLoader
Definition collect.cpp:85
DazzleLoaderClass _DazzleLoader
Definition dazzle.cpp:228
DistLODLoaderClass _DistLODLoader
Definition distlod.cpp:96
DX8MeshRendererClass TheDX8MeshRenderer
WWINLINE void DX8_ErrorCode(unsigned res)
Definition dx8wrapper.h:125
FileFactoryClass * _TheFileFactory
Definition ffactory.cpp:51
HLodLoaderClass _HLodLoader
Definition hlod.cpp:145
NullLoaderClass _NullLoader
Definition nullrobj.cpp:44
HModelLoaderClass _HModelLoader
Definition proto.cpp:53
MeshLoaderClass _MeshLoader
Definition proto.cpp:52
#define NEW_REF(C, P)
Definition refcount.h:62
RingLoaderClass _RingLoader
Definition ringobj.cpp:1392
#define SHD_REG_LOADER
Definition shdlib.h:65
SphereLoaderClass _SphereLoader
int test
Definition test6.cpp:32
MipCountType
@ MIP_LEVELS_1
WW3DFormat
Definition ww3dformat.h:75
@ WW3D_FORMAT_UNKNOWN
Definition ww3dformat.h:76
@ WW3D_FORMAT_U8V8
Definition ww3dformat.h:93
#define WWASSERT_PRINT(expr, string)
Definition wwdebug.h:135
#define WWDEBUG_SAY(x)
Definition wwdebug.h:114
@ MEM_GEOMETRY
Definition wwmemlog.h:59
#define WWMEMLOG(category)
Definition wwmemlog.h:183
#define WWPROFILE(name)
Definition wwprofile.h:270