Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
hanimmgr.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/hanimmgr.cpp 3 1/16/02 9:51a Jani_p $ */
20/***********************************************************************************************
21 *** Confidential - Westwood Studios ***
22 ***********************************************************************************************
23 * *
24 * Project Name : Commando / G 3D Library *
25 * *
26 * $Archive:: /Commando/Code/ww3d2/hanimmgr.cpp $*
27 * *
28 * Author:: Greg_h *
29 * *
30 * $Modtime:: 1/16/02 9:49a $*
31 * *
32 * $Revision:: 3 $*
33 * *
34 *---------------------------------------------------------------------------------------------*
35 * Functions: *
36 * HAnimManagerClass::HAnimManagerClass -- constructor *
37 * HAnimManagerClass::~HAnimManagerClass -- destructor *
38 * HAnimManagerClass::Load_Anim -- loads a set of motion data from a file *
39 * HAnimManagerClass::Get_Anim_ID -- looks up the ID of a named Hierarchy Animation *
40 * HAnimManagerClass::Get_Anim -- returns a pointer to the specified animation data *
41 * HAnimManagerClass::Get_Anim -- returns a pointer to the specified Hierarchy Animation *
42 * HAnimManagerClass::Free -- de-allocate all memory in use *
43 * HAnimManagerClass::Free_All_Anims -- de-allocate all currently loaded animations *
44 * HAnimManagerClass::Load_Raw_Anim -- Load a raw anim *
45 * HAnimManagerClass::Load_Compressed_Anim -- load a compressed animation *
46 * HAnimManagerClass::Add_Anim -- Adds an externally created animation to the manager *
47 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
48
49#include "hanimmgr.h"
50#include <string.h>
51#include "hanim.h"
52#include "hrawanim.h"
53#include "hcanim.h"
54#include "hmorphanim.h"
55#include "chunkio.h"
56#include "wwmemlog.h"
57#include "w3dexclusionlist.h"
58#include "animatedsoundmgr.h"
59
60
61/***********************************************************************************************
62 * HAnimManagerClass::HAnimManagerClass -- constructor *
63 * *
64 * INPUT: *
65 * *
66 * OUTPUT: *
67 * *
68 * WARNINGS: *
69 * *
70 * HISTORY: *
71 * 08/11/1997 GH : Created. *
72 *=============================================================================================*/
74{
75 // Create the hash tables
76 AnimPtrTable = W3DNEW HashTableClass( 2048 );
77 MissingAnimTable = W3DNEW HashTableClass( 2048 );
78}
79
80
81/***********************************************************************************************
82 * HAnimManagerClass::~HAnimManagerClass -- destructor *
83 * *
84 * INPUT: *
85 * *
86 * OUTPUT: *
87 * *
88 * WARNINGS: *
89 * *
90 * HISTORY: *
91 * 08/11/1997 GH : Created. *
92 *=============================================================================================*/
94{
96 Reset_Missing(); // Jani: Deleting missing animations as well
97
98 delete AnimPtrTable;
99 AnimPtrTable = NULL;
100
102 delete MissingAnimTable;
103 MissingAnimTable = NULL;
104}
105
106
107/***********************************************************************************************
108 * HAnimManagerClass::Load_Anim -- loads a set of motion data from a file *
109 * *
110 * INPUT: *
111 * *
112 * OUTPUT: *
113 * *
114 * WARNINGS: *
115 * *
116 * HISTORY: *
117 * 08/11/1997 GH : Created. *
118 *=============================================================================================*/
120{
122
123 switch (cload.Cur_Chunk_ID())
124 {
126 return Load_Raw_Anim(cload);
127 break;
128
130 return Load_Compressed_Anim(cload);
131 break;
132
134 return Load_Morph_Anim(cload);
135 break;
136 }
137
138 return 0;
139}
140
141
142/***********************************************************************************************
143 * HAnimManagerClass::Load_Morph_Anim -- Load a HMorphAnimClass *
144 * *
145 * INPUT: *
146 * *
147 * OUTPUT: *
148 * *
149 * WARNINGS: *
150 * *
151 * HISTORY: *
152 * 5/23/2000 pds : Created. *
153 *=============================================================================================*/
154int HAnimManagerClass::Load_Morph_Anim(ChunkLoadClass & cload)
155{
157
158 if (newanim == NULL) {
159 goto Error;
160 }
161
162 SET_REF_OWNER( newanim );
163
164 if (newanim->Load_W3D(cload) != HMorphAnimClass::OK) {
165 // load failed!
166 newanim->Release_Ref();
167 goto Error;
168 } else if (Peek_Anim(newanim->Get_Name()) != NULL) {
169 // duplicate exists!
170 newanim->Release_Ref(); // Release the one we just loaded
171 goto Error;
172 } else {
173 Add_Anim( newanim );
174 newanim->Release_Ref();
175 }
176
177 return 0;
178
179Error:
180
181 return 1;
182}
183
184
185/***********************************************************************************************
186 * HAnimManagerClass::Load_Raw_Anim -- Load a raw anim *
187 * *
188 * INPUT: *
189 * *
190 * OUTPUT: *
191 * *
192 * WARNINGS: *
193 * *
194 * HISTORY: *
195 * 5/23/2000 gth : Created. *
196 *=============================================================================================*/
197int HAnimManagerClass::Load_Raw_Anim(ChunkLoadClass & cload)
198{
199 HRawAnimClass * newanim = W3DNEW HRawAnimClass;
200
201 if (newanim == NULL) {
202 goto Error;
203 }
204
205 SET_REF_OWNER( newanim );
206
207 if (newanim->Load_W3D(cload) != HRawAnimClass::OK) {
208 // load failed!
209 newanim->Release_Ref();
210 goto Error;
211 } else if (Peek_Anim(newanim->Get_Name()) != NULL) {
212 // duplicate exists!
213 newanim->Release_Ref(); // Release the one we just loaded
214 goto Error;
215 } else {
216 Add_Anim( newanim );
217 newanim->Release_Ref();
218 }
219
220 return 0;
221
222Error:
223
224 return 1;
225}
226
227
228/***********************************************************************************************
229 * HAnimManagerClass::Load_Compressed_Anim -- load a compressed animation *
230 * *
231 * INPUT: *
232 * *
233 * OUTPUT: *
234 * *
235 * WARNINGS: *
236 * *
237 * HISTORY: *
238 * 5/23/2000 gth : Created. *
239 *=============================================================================================*/
240int HAnimManagerClass::Load_Compressed_Anim(ChunkLoadClass & cload)
241{
242 HCompressedAnimClass * newanim = W3DNEW HCompressedAnimClass;
243
244 if (newanim == NULL) {
245 goto Error;
246 }
247
248 SET_REF_OWNER( newanim );
249
250 if (newanim->Load_W3D(cload) != HCompressedAnimClass::OK) {
251 // load failed!
252 newanim->Release_Ref();
253 goto Error;
254 } else if (Peek_Anim(newanim->Get_Name()) != NULL) {
255 // duplicate exists!
256 newanim->Release_Ref(); // Release the one we just loaded
257 goto Error;
258 } else {
259 Add_Anim( newanim );
260 newanim->Release_Ref();
261 }
262
263 return 0;
264
265Error:
266
267 return 1;
268}
269
270/***********************************************************************************************
271 * HAnimManagerClass::Peek_Anim -- returns a pointer to the specified animation data *
272 * *
273 * INPUT: *
274 * *
275 * OUTPUT: *
276 * *
277 * WARNINGS: *
278 * *
279 * HISTORY: *
280 * 08/11/1997 GH : Created. *
281 *=============================================================================================*/
283{
284 return (HAnimClass*)AnimPtrTable->Find( name );
285}
286
287
288/***********************************************************************************************
289 * HAnimManagerClass::Get_Anim -- returns a pointer to the specified animation data *
290 * *
291 * INPUT: *
292 * *
293 * OUTPUT: *
294 * *
295 * WARNINGS: *
296 * *
297 * HISTORY: *
298 * 08/11/1997 GH : Created. *
299 *=============================================================================================*/
301{
302 HAnimClass * anim = Peek_Anim( name );
303 if ( anim != NULL ) {
304 anim->Add_Ref();
305 }
306 return anim;
307}
308
309
310/***********************************************************************************************
311 * HAnimManagerClass::Free_All_Anims -- de-allocate all currently loaded animations *
312 * *
313 * INPUT: *
314 * *
315 * OUTPUT: *
316 * *
317 * WARNINGS: *
318 * *
319 * HISTORY: *
320 * 08/11/1997 GH : Created. *
321 *=============================================================================================*/
323{
324 // Make an iterator, and release all ptrs
325 HAnimManagerIterator it( *this );
326 for( it.First(); !it.Is_Done(); it.Next() ) {
327 HAnimClass *anim = it.Get_Current_Anim();
328 anim->Release_Ref();
329 }
330
331 // Then clear the table
332 AnimPtrTable->Reset();
333}
334
335/***********************************************************************************************
336 * HAnimManagerClass::Free_All_Anims_With_Exclusion_List -- release animations not in the list *
337 * *
338 * INPUT: *
339 * *
340 * OUTPUT: *
341 * *
342 * WARNINGS: *
343 * *
344 * HISTORY: *
345 * 12/12/2002 GH : Created. *
346 *=============================================================================================*/
348{
349 // Remove and Release_Ref any animation not in the exclusion list.
350 HAnimManagerIterator it( *this );
351 for( it.First(); !it.Is_Done(); it.Next() ) {
352 HAnimClass *anim = it.Get_Current_Anim();
353
354 if ((anim->Num_Refs() == 1) && (exclusion_list.Is_Excluded(anim) == false)) {
355 //WWDEBUG_SAY(("deleting HAnim %s\n",anim->Get_Name()));
356 AnimPtrTable->Remove(anim);
357 anim->Release_Ref();
358 }
359 //else
360 //{
361 // WWDEBUG_SAY(("keeping HAnim %s (ref %d)\n",anim->Get_Name(),anim->Num_Refs()));
362 //}
363 }
364}
365
366
367/***********************************************************************************************
368 * HAnimManagerClass::Create_Asset_List -- Create a list of the W3D files that are loaded *
369 * *
370 * INPUT: *
371 * *
372 * OUTPUT: *
373 * *
374 * WARNINGS: *
375 * *
376 * HISTORY: *
377 * 12/12/2002 GH : Created. *
378 *=============================================================================================*/
380{
381 HAnimManagerIterator it( *this );
382 for( it.First(); !it.Is_Done(); it.Next() ) {
383 HAnimClass *anim = it.Get_Current_Anim();
384
385 // File that this anim came from should be the name after the '.'
386 // Anims are named in the format: <skeleton>.<animname>
387 const char * anim_name = anim->Get_Name();
388 char * filename = strchr(anim_name,'.');
389 if (filename != NULL) {
390 exclusion_list.Add(StringClass(filename+1));
391 }
392 }
393}
394
395
396/***********************************************************************************************
397 * HAnimManagerClass::Add_Anim -- Adds an externally created animation to the manager *
398 * *
399 * INPUT: *
400 * *
401 * OUTPUT: *
402 * *
403 * WARNINGS: *
404 * *
405 * HISTORY: *
406 * 05/31/2000 PDS : Created. *
407 *=============================================================================================*/
409{
410 WWASSERT (new_anim != NULL);
411
412 // Increment the refcount on the W3DNEW animation and add it to our table.
413 new_anim->Add_Ref ();
414 AnimPtrTable->Add( new_anim );
415
416 return true;
417}
418
419
420/*
421** Missing Anims
422**
423** The idea here, allow the system to register which anims are determined to be missing
424** so that if they are asked for again, we can quickly return NULL, without searching the
425** disk again.
426*/
427void HAnimManagerClass::Register_Missing( const char * name )
428{
429 MissingAnimTable->Add( W3DNEW MissingAnimClass( name ) );
430}
431
432bool HAnimManagerClass::Is_Missing( const char * name )
433{
434 return ( MissingAnimTable->Find( name ) != NULL );
435}
436
438{
439 // Make an iterator, and release all ptrs
440 HashTableIteratorClass it( *MissingAnimTable );
441 for( it.First(); !it.Is_Done(); it.Next() ) {
443 delete missing;
444 }
445
446 // Then clear the table
447 MissingAnimTable->Reset();
448}
449
450
451/*
452** Iterator converter from HashableClass to HAnimClass
453*/
458
#define NULL
Definition BaseType.h:92
#define WWASSERT
@ 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 W3DNEW
Definition always.h:109
uint32 Cur_Chunk_ID()
Definition chunkio.cpp:484
bool Add(T const &object)
Definition Vector.H:671
virtual const char * Get_Name(void) const =0
void Register_Missing(const char *name)
Definition hanimmgr.cpp:427
void Free_All_Anims_With_Exclusion_List(const W3DExclusionListClass &exclusion_list)
Definition hanimmgr.cpp:347
HAnimClass * Peek_Anim(const char *name)
Definition hanimmgr.cpp:282
void Reset_Missing(void)
Definition hanimmgr.cpp:437
void Free_All_Anims(void)
Definition hanimmgr.cpp:322
~HAnimManagerClass(void)
Definition hanimmgr.cpp:93
int Load_Anim(ChunkLoadClass &cload)
Definition hanimmgr.cpp:119
bool Add_Anim(HAnimClass *new_anim)
Definition hanimmgr.cpp:408
bool Is_Missing(const char *name)
Definition hanimmgr.cpp:432
HAnimClass * Get_Anim(const char *name)
Definition hanimmgr.cpp:300
friend class HAnimManagerIterator
Definition hanimmgr.h:104
void Create_Asset_List(DynamicVectorClass< StringClass > &exclusion_list)
Definition hanimmgr.cpp:379
HAnimManagerClass(void)
Definition hanimmgr.cpp:73
HAnimClass * Get_Current_Anim(void)
Definition hanimmgr.cpp:454
const char * Get_Name(void) const
Definition hcanim.h:89
int Load_W3D(ChunkLoadClass &cload)
Definition hcanim.cpp:235
int Load_W3D(ChunkLoadClass &cload)
const char * Get_Name(void) const
Definition hmorphanim.h:90
int Load_W3D(ChunkLoadClass &cload)
Definition hrawanim.cpp:198
const char * Get_Name(void) const
Definition hrawanim.h:94
HashableClass * Get_Current(void)
Definition hash.h:108
bool Is_Done(void)
Definition hash.h:107
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
bool Is_Excluded(PrototypeClass *proto) const
#define SET_REF_OWNER(P)
Definition refcount.h:63
@ MEM_ANIMATION
Definition wwmemlog.h:60
#define WWMEMLOG(category)
Definition wwmemlog.h:183