Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
nodelist.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/Tools/pluglib/nodelist.cpp 8 1/02/01 6:31p Greg_h $ */
20/***********************************************************************************************
21 *** Confidential - Westwood Studios ***
22 ***********************************************************************************************
23 * *
24 * Project Name : Commando / G *
25 * *
26 * File Name : NODELIST.CPP *
27 * *
28 * Programmer : Greg Hjelstrom *
29 * *
30 * Start Date : 06/09/97 *
31 * *
32 * Last Update : June 9, 1997 [GH] *
33 * *
34 *---------------------------------------------------------------------------------------------*
35 * Functions: *
36 * INodeListClass::INodeListClass -- Create an INodeList *
37 * INodeListClass::~INodeListClass -- Delete the INode List *
38 * INode * INodeListClass::operator[] -- Array-like access to the list members *
39 * INodeListClass::callback -- callback function for MAX *
40 * INodeListClass::INodeListClass -- A "copy" contstructor with filtering... *
41 * INodeListClass::INodeListClass -- constructor *
42 * INodeListClass::INodeListClass -- Constructor *
43 * INodeListClass::Insert -- insert a list of nodes into this list *
44 * INodeListClass::Insert -- Inserts an INode into the list *
45 * INodeListClass::Add_Tree -- Add a tree of INodes to the list *
46 * INodeListClass::Remove -- Remove the i'th element of the list *
47 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
48
49#include "nodelist.h"
50
51
52static AnyINodeFilter _AnyFilter;
53
54
55/*******************************************************************************
56* ListEntryClass
57*
58* Used to implement a linked list of INodes.
59*
60*******************************************************************************/
62{
63public:
64
65 INodeListEntryClass(INode * n,TimeValue /*time*/) { Node = n; }
67
68 INode * Node;
70};
71
72/***********************************************************************************************
73 * INodeListClass::INodeListClass -- Constructor *
74 * *
75 * INPUT: *
76 * *
77 * OUTPUT: *
78 * *
79 * WARNINGS: *
80 * *
81 * HISTORY: *
82 * 07/02/1997 GH : Created. *
83 *=============================================================================================*/
84INodeListClass::INodeListClass(TimeValue time,INodeFilterClass * inodefilter) :
85 NumNodes(0),
86 Time(time),
87 ListHead(NULL),
88 INodeFilter(inodefilter)
89{
90 if (INodeFilter == NULL) {
91 INodeFilter = &_AnyFilter;
92 }
93}
94
95/***********************************************************************************************
96 * INodeListClass::INodeListClass -- Create an INodeList *
97 * *
98 * INPUT: *
99 * scene - 3dsMAX scene to enumerate *
100 * time - time at which to create the list of INodes *
101 * inodefilter - object which will accept or reject each INode in the scene *
102 * *
103 * OUTPUT: *
104 * *
105 * WARNINGS: *
106 * *
107 * HISTORY: *
108 * 06/09/1997 GH : Created. *
109 *=============================================================================================*/
110INodeListClass::INodeListClass(IScene * scene,TimeValue time,INodeFilterClass * inodefilter) :
111 NumNodes(0),
112 Time(time),
113 ListHead(NULL),
114 INodeFilter(inodefilter)
115{
116 if (INodeFilter == NULL) {
117 INodeFilter = &_AnyFilter;
118 }
119 scene->EnumTree(this);
120}
121
122
123/***********************************************************************************************
124 * INodeListClass::INodeListClass -- Constructor *
125 * *
126 * INPUT: *
127 * *
128 * OUTPUT: *
129 * *
130 * WARNINGS: *
131 * *
132 * HISTORY: *
133 * 1/13/98 GTH : Created. *
134 *=============================================================================================*/
135INodeListClass::INodeListClass(INode * root,TimeValue time,INodeFilterClass * nodefilter) :
136 NumNodes(0),
137 Time(time),
138 ListHead(NULL),
139 INodeFilter(nodefilter)
140{
141 if (INodeFilter == NULL) {
142 INodeFilter = &_AnyFilter;
143 }
144 Add_Tree(root);
145}
146
147
148/***********************************************************************************************
149 * INodeListClass::INodeListClass -- A "copy" contstructor with filtering... *
150 * *
151 * INPUT: *
152 * *
153 * OUTPUT: *
154 * *
155 * WARNINGS: *
156 * *
157 * HISTORY: *
158 * 07/02/1997 GH : Created. *
159 *=============================================================================================*/
160INodeListClass::INodeListClass(INodeListClass & copyfrom,TimeValue time,INodeFilterClass * inodefilter) :
161 NumNodes(0),
162 Time(time),
163 ListHead(NULL),
164 INodeFilter(inodefilter)
165{
166 if (INodeFilter == NULL) {
167 INodeFilter = &_AnyFilter;
168 }
169 for (unsigned i=0; i<copyfrom.Num_Nodes(); i++) {
170 Insert(copyfrom[i]);
171 }
172}
173
174/***********************************************************************************************
175 * INodeListClass::~INodeListClass -- Delete the INode List *
176 * *
177 * INPUT: *
178 * *
179 * OUTPUT: *
180 * *
181 * WARNINGS: *
182 * *
183 * HISTORY: *
184 * 06/09/1997 GH : Created. *
185 *=============================================================================================*/
187{
188 while (ListHead)
189 {
190 INodeListEntryClass * next = ListHead->Next;
191 delete ListHead;
192 ListHead = next;
193 }
194
195 NumNodes = 0;
196 ListHead = NULL;
197}
198
199
200/***********************************************************************************************
201 * INode * INodeListClass::operator[] -- Array-like access to the list members *
202 * *
203 * INPUT: *
204 * index - index of the list entry *
205 * *
206 * OUTPUT: *
207 * pointer to an INode *
208 * *
209 * WARNINGS: *
210 * *
211 * HISTORY: *
212 * 06/09/1997 GH : Created. *
213 *=============================================================================================*/
214INode * INodeListClass::operator[] ( int index ) const
215{
216 INodeListEntryClass * entry = ListHead;
217 while (index > 0 && entry != NULL )
218 {
219 entry = entry->Next;
220 index--;
221 }
222 return entry->Node;
223}
224
225
226/***********************************************************************************************
227 * INodeListClass::Insert -- insert a list of nodes into this list *
228 * *
229 * INPUT: *
230 * *
231 * OUTPUT: *
232 * *
233 * WARNINGS: *
234 * *
235 * HISTORY: *
236 * 1/14/98 GTH : Created. *
237 *=============================================================================================*/
239{
240 for (unsigned int i=0; i<insertlist.Num_Nodes(); i++) {
241 Insert(insertlist[i]);
242 }
243}
244
245/***********************************************************************************************
246 * INodeListClass::Insert -- Inserts an INode into the list *
247 * *
248 * INPUT: *
249 * *
250 * OUTPUT: *
251 * *
252 * WARNINGS: *
253 * *
254 * HISTORY: *
255 * 07/02/1997 GH : Created. *
256 *=============================================================================================*/
257void INodeListClass::Insert(INode * node)
258{
259 if (INodeFilter->Accept_Node(node,Time))
260 {
261 INodeListEntryClass * newentry = new INodeListEntryClass(node, Time);
262 newentry->Next = ListHead;
263 ListHead = newentry;
264 NumNodes++;
265 }
266}
267
268
269/***********************************************************************************************
270 * INodeListClass::Remove -- Remove the i'th element of the list *
271 * *
272 * INPUT: *
273 * *
274 * OUTPUT: *
275 * *
276 * WARNINGS: *
277 * *
278 * HISTORY: *
279 * 10/27/2000 gth : Created. *
280 *=============================================================================================*/
282{
283 if ((i < 0) || (i > Num_Nodes())) {
284 return;
285 }
286
287 INodeListEntryClass * prev = ListHead;
288 while (i > 1) {
289 prev = prev->Next;
290 }
291
292 INodeListEntryClass * deleteme = prev->Next;
293 if (deleteme != NULL) {
294 prev->Next = prev->Next->Next;
295 delete deleteme;
296 }
297}
298
299
300/***********************************************************************************************
301 * INodeListClass::Add_Tree -- Add a tree of INodes to the list *
302 * *
303 * INPUT: *
304 * *
305 * OUTPUT: *
306 * *
307 * WARNINGS: *
308 * *
309 * HISTORY: *
310 * 1/13/98 GTH : Created. *
311 *=============================================================================================*/
312void INodeListClass::Add_Tree(INode * root)
313{
314 if (root == NULL) return;
315
316 Insert(root);
317 for (int i=0; i<root->NumberOfChildren(); i++) {
318 Add_Tree(root->GetChildNode(i));
319 }
320}
321
322
323/***********************************************************************************************
324 * INodeListClass::callback -- callback function for MAX *
325 * *
326 * 3dsMAX calls this function with a pointer to each INode in the scene. We keep a pointer *
327 * to the ones we like. *
328 * *
329 * INPUT: *
330 * *
331 * OUTPUT: *
332 * *
333 * WARNINGS: *
334 * *
335 * HISTORY: *
336 * 06/09/1997 GH : Created. *
337 *=============================================================================================*/
338int INodeListClass::callback(INode * node)
339{
340 Insert(node);
341
342 return TREE_CONTINUE; // Keep on enumerating....
343}
344
345
346void INodeListClass::Sort(const INodeCompareClass & node_compare)
347{
348 for (unsigned int i=0; i<Num_Nodes(); i++) {
349 for (unsigned int j=0; j<Num_Nodes(); j++) {
350
351 INodeListEntryClass * ni = get_nth_item(i);
352 INodeListEntryClass * nj = get_nth_item(j);
353
354 if (node_compare(ni->Node,nj->Node) > 0) {
355 INode * tmp = ni->Node;
356 ni->Node = nj->Node;
357 nj->Node = tmp;
358 }
359 }
360 }
361}
362
363INodeListEntryClass * INodeListClass::get_nth_item(int index)
364{
365 INodeListEntryClass * entry = ListHead;
366 while (index > 0 && entry != NULL )
367 {
368 entry = entry->Next;
369 index--;
370 }
371 return entry;
372}
373
#define NULL
Definition BaseType.h:92
INode * operator[](int index) const
Definition nodelist.cpp:214
INodeListClass(TimeValue time, INodeFilterClass *nodefilter=NULL)
Definition nodelist.cpp:84
void Add_Tree(INode *root)
Definition nodelist.cpp:312
void Remove(int i)
Definition nodelist.cpp:281
unsigned Num_Nodes(void) const
Definition nodelist.h:75
void Sort(const INodeCompareClass &node_compare)
Definition nodelist.cpp:346
void Insert(INodeListClass &insertlist)
Definition nodelist.cpp:238
Definition nodelist.cpp:62
INode * Node
Definition nodelist.cpp:68
INodeListEntryClass(INode *n, TimeValue)
Definition nodelist.cpp:65
INodeListEntryClass * Next
Definition nodelist.cpp:69
~INodeListEntryClass(void)
Definition nodelist.cpp:66