| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403 |
- /*
- ** Command & Conquer Renegade(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /* $Header: /Commando/Code/ww3d2/hanimmgr.cpp 3 1/16/02 9:51a Jani_p $ */
- /***********************************************************************************************
- *** Confidential - Westwood Studios ***
- ***********************************************************************************************
- * *
- * Project Name : Commando / G 3D Library *
- * *
- * $Archive:: /Commando/Code/ww3d2/hanimmgr.cpp $*
- * *
- * Author:: Greg_h *
- * *
- * $Modtime:: 1/16/02 9:49a $*
- * *
- * $Revision:: 3 $*
- * *
- *---------------------------------------------------------------------------------------------*
- * Functions: *
- * HAnimManagerClass::HAnimManagerClass -- constructor *
- * HAnimManagerClass::~HAnimManagerClass -- destructor *
- * HAnimManagerClass::Load_Anim -- loads a set of motion data from a file *
- * HAnimManagerClass::Get_Anim_ID -- looks up the ID of a named Hierarchy Animation *
- * HAnimManagerClass::Get_Anim -- returns a pointer to the specified animation data *
- * HAnimManagerClass::Get_Anim -- returns a pointer to the specified Hierarchy Animation *
- * HAnimManagerClass::Free -- de-allocate all memory in use *
- * HAnimManagerClass::Free_All_Anims -- de-allocate all currently loaded animations *
- * HAnimManagerClass::Load_Raw_Anim -- Load a raw anim *
- * HAnimManagerClass::Load_Compressed_Anim -- load a compressed animation *
- * HAnimManagerClass::Add_Anim -- Adds an externally created animation to the manager *
- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- #include "hanimmgr.h"
- #include <string.h>
- #include "hanim.h"
- #include "hrawanim.h"
- #include "hcanim.h"
- #include "hmorphanim.h"
- #include "chunkio.h"
- #include "wwmemlog.h"
- #include "animatedsoundmgr.h"
- /***********************************************************************************************
- * HAnimManagerClass::HAnimManagerClass -- constructor *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 08/11/1997 GH : Created. *
- *=============================================================================================*/
- HAnimManagerClass::HAnimManagerClass(void)
- {
- // Create the hash tables
- AnimPtrTable = new HashTableClass( 2048 );
- MissingAnimTable = new HashTableClass( 2048 );
- }
- /***********************************************************************************************
- * HAnimManagerClass::~HAnimManagerClass -- destructor *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 08/11/1997 GH : Created. *
- *=============================================================================================*/
- HAnimManagerClass::~HAnimManagerClass(void)
- {
- Free_All_Anims();
- Reset_Missing(); // Jani: Deleting missing animations as well
- delete AnimPtrTable;
- AnimPtrTable = NULL;
- delete MissingAnimTable;
- MissingAnimTable = NULL;
- }
- /***********************************************************************************************
- * HAnimManagerClass::Load_Anim -- loads a set of motion data from a file *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 08/11/1997 GH : Created. *
- *=============================================================================================*/
- int HAnimManagerClass::Load_Anim(ChunkLoadClass & cload)
- {
- WWMEMLOG(MEM_ANIMATION);
- switch (cload.Cur_Chunk_ID())
- {
- case W3D_CHUNK_ANIMATION:
- return Load_Raw_Anim(cload);
- break;
- case W3D_CHUNK_COMPRESSED_ANIMATION:
- return Load_Compressed_Anim(cload);
- break;
- case W3D_CHUNK_MORPH_ANIMATION:
- return Load_Morph_Anim(cload);
- break;
- }
- return 0;
- }
- /***********************************************************************************************
- * HAnimManagerClass::Load_Morph_Anim -- Load a HMorphAnimClass *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 5/23/2000 pds : Created. *
- *=============================================================================================*/
- int HAnimManagerClass::Load_Morph_Anim(ChunkLoadClass & cload)
- {
- HMorphAnimClass * newanim = new HMorphAnimClass;
- if (newanim == NULL) {
- goto Error;
- }
- SET_REF_OWNER( newanim );
- if (newanim->Load_W3D(cload) != HMorphAnimClass::OK) {
- // load failed!
- newanim->Release_Ref();
- goto Error;
- } else if (Peek_Anim(newanim->Get_Name()) != NULL) {
- // duplicate exists!
- newanim->Release_Ref(); // Release the one we just loaded
- goto Error;
- } else {
- Add_Anim( newanim );
- newanim->Release_Ref();
- }
- return 0;
- Error:
- return 1;
- }
- /***********************************************************************************************
- * HAnimManagerClass::Load_Raw_Anim -- Load a raw anim *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 5/23/2000 gth : Created. *
- *=============================================================================================*/
- int HAnimManagerClass::Load_Raw_Anim(ChunkLoadClass & cload)
- {
- HRawAnimClass * newanim = new HRawAnimClass;
- if (newanim == NULL) {
- goto Error;
- }
- SET_REF_OWNER( newanim );
- if (newanim->Load_W3D(cload) != HRawAnimClass::OK) {
- // load failed!
- newanim->Release_Ref();
- goto Error;
- } else if (Peek_Anim(newanim->Get_Name()) != NULL) {
- // duplicate exists!
- newanim->Release_Ref(); // Release the one we just loaded
- goto Error;
- } else {
- Add_Anim( newanim );
- newanim->Release_Ref();
- }
- return 0;
- Error:
- return 1;
- }
- /***********************************************************************************************
- * HAnimManagerClass::Load_Compressed_Anim -- load a compressed animation *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 5/23/2000 gth : Created. *
- *=============================================================================================*/
- int HAnimManagerClass::Load_Compressed_Anim(ChunkLoadClass & cload)
- {
- HCompressedAnimClass * newanim = new HCompressedAnimClass;
- if (newanim == NULL) {
- goto Error;
- }
- SET_REF_OWNER( newanim );
- if (newanim->Load_W3D(cload) != HCompressedAnimClass::OK) {
- // load failed!
- newanim->Release_Ref();
- goto Error;
- } else if (Peek_Anim(newanim->Get_Name()) != NULL) {
- // duplicate exists!
- newanim->Release_Ref(); // Release the one we just loaded
- goto Error;
- } else {
- Add_Anim( newanim );
- newanim->Release_Ref();
- }
- return 0;
- Error:
- return 1;
- }
- /***********************************************************************************************
- * HAnimManagerClass::Peek_Anim -- returns a pointer to the specified animation data *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 08/11/1997 GH : Created. *
- *=============================================================================================*/
- HAnimClass * HAnimManagerClass::Peek_Anim(const char * name)
- {
- return (HAnimClass*)AnimPtrTable->Find( name );
- }
- /***********************************************************************************************
- * HAnimManagerClass::Get_Anim -- returns a pointer to the specified animation data *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 08/11/1997 GH : Created. *
- *=============================================================================================*/
- HAnimClass * HAnimManagerClass::Get_Anim(const char * name)
- {
- HAnimClass * anim = Peek_Anim( name );
- if ( anim != NULL ) {
- anim->Add_Ref();
- }
- return anim;
- }
- /***********************************************************************************************
- * HAnimManagerClass::Free_All_Anims -- de-allocate all currently loaded animations *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 08/11/1997 GH : Created. *
- *=============================================================================================*/
- void HAnimManagerClass::Free_All_Anims(void)
- {
- // Make an iterator, and release all ptrs
- HAnimManagerIterator it( *this );
- for( it.First(); !it.Is_Done(); it.Next() ) {
- HAnimClass *anim = it.Get_Current_Anim();
- anim->Release_Ref();
- }
- // Then clear the table
- AnimPtrTable->Reset();
- }
-
- /***********************************************************************************************
- * HAnimManagerClass::Add_Anim -- Adds an externally created animation to the manager *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 05/31/2000 PDS : Created. *
- *=============================================================================================*/
- bool HAnimManagerClass::Add_Anim(HAnimClass *new_anim)
- {
- WWASSERT (new_anim != NULL);
- // Increment the refcount on the new animation and add it to our table.
- new_anim->Add_Ref ();
- AnimPtrTable->Add( new_anim );
- //
- // Check to see if this animation has any embedded sounds that may
- // need to play while its animating.
- //
- bool has_sound_trigger = AnimatedSoundMgrClass::Does_Animation_Have_Embedded_Sounds( new_anim );
- new_anim->Set_Has_Embedded_Sounds( has_sound_trigger );
- return true;
- }
- /*
- ** Missing Anims
- **
- ** The idea here, allow the system to register which anims are determined to be missing
- ** so that if they are asked for again, we can quickly return NULL, without searching the
- ** disk again.
- */
- void HAnimManagerClass::Register_Missing( const char * name )
- {
- MissingAnimTable->Add( new MissingAnimClass( name ) );
- }
- bool HAnimManagerClass::Is_Missing( const char * name )
- {
- return ( MissingAnimTable->Find( name ) != NULL );
- }
- void HAnimManagerClass::Reset_Missing( void )
- {
- // Make an iterator, and release all ptrs
- HashTableIteratorClass it( *MissingAnimTable );
- for( it.First(); !it.Is_Done(); it.Next() ) {
- MissingAnimClass *missing = (MissingAnimClass *)it.Get_Current();
- delete missing;
- }
- // Then clear the table
- MissingAnimTable->Reset();
- }
- /*
- ** Iterator converter from HashableClass to HAnimClass
- */
- HAnimClass * HAnimManagerIterator::Get_Current_Anim( void )
- {
- return (HAnimClass *)Get_Current();
- }
|