| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 |
- /*
- ** Command & Conquer Generals(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/htreemgr.cpp 1 1/22/01 3:36p Greg_h $ */
- /***********************************************************************************************
- *** Confidential - Westwood Studios ***
- ***********************************************************************************************
- * *
- * Project Name : Commando / G 3D Library *
- * *
- * $Archive:: /Commando/Code/ww3d2/htreemgr.cpp $*
- * *
- * Author:: Byon_g *
- * *
- * $Modtime:: 1/08/01 10:04a $*
- * *
- * $Revision:: 1 $*
- * *
- *---------------------------------------------------------------------------------------------*
- * Functions: *
- * HTreeManagerClass::HTreeManagerClass -- constructor *
- * HTreeManagerClass::~HTreeManagerClass -- destructor *
- * HTreeManagerClass::Free -- de-allocate all memory in use *
- * HTreeManagerClass::Free_All_Trees -- de-allocates all hierarchy trees currently loaded *
- * HTreeManagerClass::Load_Tree -- load a hierarchy tree from a file *
- * HTreeManagerClass::Get_Tree_ID -- look up the ID of a named hierarchy tree *
- * HTreeManagerClass::Get_Tree -- get a pointer to the specified hierarchy tree *
- * HTreeManagerClass::Get_Tree -- get a pointer to the specified hierarchy tree *
- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- #include "htreemgr.h"
- #include <string.h>
- #include "htree.h"
- #include "chunkio.h"
- #include "wwmemlog.h"
- #include "w3dexclusionlist.h"
- /***********************************************************************************************
- * HTreeManagerClass::HTreeManagerClass -- constructor *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 08/11/1997 GH : Created. *
- *=============================================================================================*/
- HTreeManagerClass::HTreeManagerClass(void) :
- NumTrees(0)
- {
- for (int treeidx=0; treeidx < MAX_TREES; treeidx++) {
- TreePtr[treeidx] = NULL;
- }
- }
- /***********************************************************************************************
- * HTreeManagerClass::~HTreeManagerClass -- destructor *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 08/11/1997 GH : Created. *
- *=============================================================================================*/
- HTreeManagerClass::~HTreeManagerClass(void)
- {
- Free();
- }
- /***********************************************************************************************
- * HTreeManagerClass::Free -- de-allocate all memory in use *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 08/11/1997 GH : Created. *
- *=============================================================================================*/
- void HTreeManagerClass::Free(void)
- {
- Free_All_Trees();
- }
- /***********************************************************************************************
- * HTreeManagerClass::Free_All_Trees -- de-allocates all hierarchy trees currently loaded *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 08/11/1997 GH : Created. *
- *=============================================================================================*/
- void HTreeManagerClass::Free_All_Trees(void)
- {
- for (int treeidx=0; treeidx < MAX_TREES; treeidx++) {
- if (TreePtr[treeidx] != NULL) {
- delete TreePtr[treeidx];
- TreePtr[treeidx] = NULL;
- }
- }
- NumTrees = 0;
- }
- /***********************************************************************************************
- * HTreeManagerClass::Free_All_Trees_With_Exclusion_List -- de-allocates all trees not in list *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 12/12/2002 GH : Created. *
- *=============================================================================================*/
- void HTreeManagerClass::Free_All_Trees_With_Exclusion_List(const W3DExclusionListClass & exclusion_list)
- {
- // For this system, since it is so simplistic, we simply loop over the array either deleting the tree
- // or copying it to the new tail index if it is excluded.
- int new_tail = 0;
- for (int treeidx=0; treeidx < MAX_TREES; treeidx++) {
- if (TreePtr[treeidx] != NULL) {
-
- if (exclusion_list.Is_Excluded(TreePtr[treeidx])) {
- //WWDEBUG_SAY(("excluding tree %s\n",TreePtr[treeidx]->Get_Name()));
- TreePtr[new_tail] = TreePtr[treeidx];
- new_tail++;
- } else {
-
- //WWDEBUG_SAY(("deleting tree %s\n",TreePtr[treeidx]->Get_Name()));
- delete TreePtr[treeidx];
- TreePtr[treeidx] = NULL;
- }
- }
- }
- NumTrees = new_tail;
- }
- /***********************************************************************************************
- * HTreeManagerClass::Load_Tree -- load a hierarchy tree from a file *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 08/11/1997 GH : Created. *
- *=============================================================================================*/
- int HTreeManagerClass::Load_Tree(ChunkLoadClass & cload)
- {
- WWMEMLOG(MEM_ANIMATION);
- HTreeClass * newtree = W3DNEW HTreeClass;
- if (newtree == NULL) {
- goto Error;
- }
- if (newtree->Load_W3D(cload) != HTreeClass::OK) {
-
- // load failed, delete and return error
- delete newtree;
- goto Error;
- } else if (Get_Tree_ID(newtree->Get_Name()) != -1) {
-
- // tree with this name already exists, reject it!
- delete newtree;
- goto Error;
- } else {
- // ok, accept this hierarchy tree!
- TreePtr[NumTrees] = newtree;
- NumTrees++;
- }
- return 0;
- Error:
- return 1;
- }
- /***********************************************************************************************
- * HTreeManagerClass::Get_Tree_ID -- look up the ID of a named hierarchy tree *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 08/11/1997 GH : Created. *
- *=============================================================================================*/
- int HTreeManagerClass::Get_Tree_ID(const char * name)
- {
- for (int i=0; i<NumTrees; i++) {
- if (TreePtr[i] && (stricmp(name,TreePtr[i]->Get_Name()) == 0)) {
- return i;
- }
- }
- return -1;
- }
- /***********************************************************************************************
- * HTreeManagerClass::Get_Tree_Name -- look up the name of a id'd hierarchy tree *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 08/11/1997 GH : Created. *
- *=============================================================================================*/
- char *HTreeManagerClass::Get_Tree_Name(const int idx)
- {
- if ((idx < NumTrees) && TreePtr[idx]) {
- if (TreePtr[idx]) {
- return (char *)TreePtr[idx]->Get_Name();
- }
- }
- return NULL;
- }
- /***********************************************************************************************
- * HTreeManagerClass::Get_Tree -- get a pointer to the specified hierarchy tree *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 08/11/1997 GH : Created. *
- *=============================================================================================*/
- HTreeClass * HTreeManagerClass::Get_Tree(const char * name)
- {
- for (int i=0; i<NumTrees; i++) {
- if (TreePtr[i] && (stricmp(name,TreePtr[i]->Get_Name()) == 0)) {
- return TreePtr[i];
- }
- }
- return NULL;
- }
- /***********************************************************************************************
- * HTreeManagerClass::Get_Tree -- get a pointer to the specified hierarchy tree *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 08/11/1997 GH : Created. *
- *=============================================================================================*/
- HTreeClass * HTreeManagerClass::Get_Tree(int id)
- {
- if ((id >= 0) && (id < NumTrees)) {
- return TreePtr[id];
- } else {
- return NULL;
- }
- }
|