Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
htreemgr.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/htreemgr.cpp 2 9/19/01 6:17p Jani_p $ */
20/***********************************************************************************************
21 *** Confidential - Westwood Studios ***
22 ***********************************************************************************************
23 * *
24 * Project Name : Commando / G 3D Library *
25 * *
26 * $Archive:: /Commando/Code/ww3d2/htreemgr.cpp $*
27 * *
28 * Author:: Byon_g *
29 * *
30 * $Modtime:: 9/14/01 12:01p $*
31 * *
32 * $Revision:: 2 $*
33 * *
34 *---------------------------------------------------------------------------------------------*
35 * Functions: *
36 * HTreeManagerClass::HTreeManagerClass -- constructor *
37 * HTreeManagerClass::~HTreeManagerClass -- destructor *
38 * HTreeManagerClass::Free -- de-allocate all memory in use *
39 * HTreeManagerClass::Free_All_Trees -- de-allocates all hierarchy trees currently loaded *
40 * HTreeManagerClass::Load_Tree -- load a hierarchy tree from a file *
41 * HTreeManagerClass::Get_Tree_ID -- look up the ID of a named hierarchy tree *
42 * HTreeManagerClass::Get_Tree -- get a pointer to the specified hierarchy tree *
43 * HTreeManagerClass::Get_Tree -- get a pointer to the specified hierarchy tree *
44 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
45
46
47#include "htreemgr.h"
48#include <string.h>
49#include "htree.h"
50#include "chunkio.h"
51#include "wwmemlog.h"
52#include "w3dexclusionlist.h"
53
54
55/***********************************************************************************************
56 * HTreeManagerClass::HTreeManagerClass -- constructor *
57 * *
58 * INPUT: *
59 * *
60 * OUTPUT: *
61 * *
62 * WARNINGS: *
63 * *
64 * HISTORY: *
65 * 08/11/1997 GH : Created. *
66 *=============================================================================================*/
68 NumTrees(0)
69{
70 for (int treeidx=0; treeidx < MAX_TREES; treeidx++) {
71 TreePtr[treeidx] = NULL;
72 }
73}
74
75/***********************************************************************************************
76 * HTreeManagerClass::~HTreeManagerClass -- destructor *
77 * *
78 * INPUT: *
79 * *
80 * OUTPUT: *
81 * *
82 * WARNINGS: *
83 * *
84 * HISTORY: *
85 * 08/11/1997 GH : Created. *
86 *=============================================================================================*/
91
92/***********************************************************************************************
93 * HTreeManagerClass::Free -- de-allocate all memory in use *
94 * *
95 * INPUT: *
96 * *
97 * OUTPUT: *
98 * *
99 * WARNINGS: *
100 * *
101 * HISTORY: *
102 * 08/11/1997 GH : Created. *
103 *=============================================================================================*/
104void HTreeManagerClass::Free(void)
105{
107}
108
109/***********************************************************************************************
110 * HTreeManagerClass::Free_All_Trees -- de-allocates all hierarchy trees currently loaded *
111 * *
112 * INPUT: *
113 * *
114 * OUTPUT: *
115 * *
116 * WARNINGS: *
117 * *
118 * HISTORY: *
119 * 08/11/1997 GH : Created. *
120 *=============================================================================================*/
122{
123 // Clear the hash table
124 TreeHash.Remove_All();
125
126 for (int treeidx=0; treeidx < MAX_TREES; treeidx++) {
127 if (TreePtr[treeidx] != NULL) {
128 delete TreePtr[treeidx];
129 TreePtr[treeidx] = NULL;
130 }
131 }
132 NumTrees = 0;
133}
134/***********************************************************************************************
135 * HTreeManagerClass::Free_All_Trees_With_Exclusion_List -- de-allocates all trees not in list *
136 * *
137 * INPUT: *
138 * *
139 * OUTPUT: *
140 * *
141 * WARNINGS: *
142 * *
143 * HISTORY: *
144 * 12/12/2002 GH : Created. *
145 *=============================================================================================*/
147{
148 // For this system, since it is so simplistic, we simply loop over the array either deleting the tree
149 // or copying it to the new tail index if it is excluded.
150 int new_tail = 0;
151
152 for (int treeidx=0; treeidx < MAX_TREES; treeidx++) {
153 if (TreePtr[treeidx] != NULL) {
154
155 if (exclusion_list.Is_Excluded(TreePtr[treeidx])) {
156
157 //WWDEBUG_SAY(("excluding tree %s\n",TreePtr[treeidx]->Get_Name()));
158 TreePtr[new_tail] = TreePtr[treeidx];
159 new_tail++;
160
161 } else {
162
163 //WWDEBUG_SAY(("deleting tree %s\n",TreePtr[treeidx]->Get_Name()));
164 delete TreePtr[treeidx];
165 TreePtr[treeidx] = NULL;
166 }
167 }
168 }
169 NumTrees = new_tail;
170
171 // Clear the hash table
172 TreeHash.Remove_All();
173
174 // Add back any trees that were not deleted
175 for (treeidx=0; treeidx < new_tail; treeidx++)
176 {
177 // Insert to hash table for fast name based search
178 StringClass lower_case_name(TreePtr[treeidx]->Get_Name(),true);
179 _strlwr(lower_case_name.Peek_Buffer());
180 TreeHash.Insert(lower_case_name,TreePtr[treeidx]);
181 }
182}
183
184/***********************************************************************************************
185 * HTreeManagerClass::Load_Tree -- load a hierarchy tree from a file *
186 * *
187 * INPUT: *
188 * *
189 * OUTPUT: *
190 * *
191 * WARNINGS: *
192 * *
193 * HISTORY: *
194 * 08/11/1997 GH : Created. *
195 *=============================================================================================*/
197{
199 HTreeClass * newtree = W3DNEW HTreeClass;
200
201 if (newtree == NULL) {
202 goto Error;
203 }
204
205 if (newtree->Load_W3D(cload) != HTreeClass::OK) {
206
207 // load failed, delete and return error
208 delete newtree;
209 goto Error;
210
211 } else if (Get_Tree_ID(newtree->Get_Name()) != -1) {
212
213 // tree with this name already exists, reject it!
214 delete newtree;
215 goto Error;
216
217 } else {
218
219 // ok, accept this hierarchy tree!
220 TreePtr[NumTrees] = newtree;
221 NumTrees++;
222
223 // Insert to hash table for fast name based search
224 StringClass lower_case_name(newtree->Get_Name(),true);
225 _strlwr(lower_case_name.Peek_Buffer());
226 TreeHash.Insert(lower_case_name,newtree);
227 }
228
229 return 0;
230
231Error:
232
233 return 1;
234
235}
236
237/***********************************************************************************************
238 * HTreeManagerClass::Get_Tree_ID -- look up the ID of a named hierarchy tree *
239 * *
240 * INPUT: *
241 * *
242 * OUTPUT: *
243 * *
244 * WARNINGS: *
245 * *
246 * HISTORY: *
247 * 08/11/1997 GH : Created. *
248 *=============================================================================================*/
249int HTreeManagerClass::Get_Tree_ID(const char * name)
250{
251 for (int i=0; i<NumTrees; i++) {
252 if (TreePtr[i] && (stricmp(name,TreePtr[i]->Get_Name()) == 0)) {
253 return i;
254 }
255 }
256 return -1;
257}
258
259/***********************************************************************************************
260 * HTreeManagerClass::Get_Tree_Name -- look up the name of a id'd hierarchy tree *
261 * *
262 * INPUT: *
263 * *
264 * OUTPUT: *
265 * *
266 * WARNINGS: *
267 * *
268 * HISTORY: *
269 * 08/11/1997 GH : Created. *
270 *=============================================================================================*/
272{
273 if ((idx < NumTrees) && TreePtr[idx]) {
274 if (TreePtr[idx]) {
275 return (char *)TreePtr[idx]->Get_Name();
276 }
277 }
278
279 return NULL;
280}
281
282
283
284/***********************************************************************************************
285 * HTreeManagerClass::Get_Tree -- get a pointer to the specified hierarchy tree *
286 * *
287 * INPUT: *
288 * *
289 * OUTPUT: *
290 * *
291 * WARNINGS: *
292 * *
293 * HISTORY: *
294 * 08/11/1997 GH : Created. *
295 *=============================================================================================*/
297{
298 StringClass lower_case_name(name,true);
299 _strlwr(lower_case_name.Peek_Buffer());
300 return TreeHash.Get(lower_case_name);
301
302// for (int i=0; i<NumTrees; i++) {
303// if (TreePtr[i] && (stricmp(name,TreePtr[i]->Get_Name()) == 0)) {
304//
305// return TreePtr[i];
306// }
307// }
308// return NULL;
309}
310
311
312/***********************************************************************************************
313 * HTreeManagerClass::Get_Tree -- get a pointer to the specified hierarchy tree *
314 * *
315 * INPUT: *
316 * *
317 * OUTPUT: *
318 * *
319 * WARNINGS: *
320 * *
321 * HISTORY: *
322 * 08/11/1997 GH : Created. *
323 *=============================================================================================*/
325{
326 if ((id >= 0) && (id < NumTrees)) {
327 return TreePtr[id];
328 } else {
329 return NULL;
330 }
331}
#define NULL
Definition BaseType.h:92
#define W3DNEW
Definition always.h:109
int Load_W3D(ChunkLoadClass &cload)
Definition htree.cpp:176
WWINLINE const char * Get_Name(void) const
Definition htree.h:92
int Get_Tree_ID(const char *name)
Definition htreemgr.cpp:249
HTreeClass * Get_Tree(const char *name)
Definition htreemgr.cpp:296
int Load_Tree(ChunkLoadClass &cload)
Definition htreemgr.cpp:196
void Free_All_Trees_With_Exclusion_List(const W3DExclusionListClass &exclusion_list)
Definition htreemgr.cpp:146
char * Get_Tree_Name(const int id)
Definition htreemgr.cpp:271
void Free_All_Trees(void)
Definition htreemgr.cpp:121
~HTreeManagerClass(void)
Definition htreemgr.cpp:87
HTreeManagerClass(void)
Definition htreemgr.cpp:67
TCHAR * Peek_Buffer(void)
Definition wwstring.h:560
bool Is_Excluded(PrototypeClass *proto) const
@ MEM_ANIMATION
Definition wwmemlog.h:60
#define WWMEMLOG(category)
Definition wwmemlog.h:183