Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
shddefmanager.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 /***********************************************************************************************
20 *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
21 ***********************************************************************************************
22 * *
23 * Project Name : WWSHADE *
24 * *
25 * $Archive:: wwshade/shddefmanager.cpp $*
26 * *
27 * $Org Author:: Jani_p
28 *
29 * $Author:: Kenny_m
30 *
31 * $Modtime:: 5/20/02 3:12p $*
32 * *
33 * $Revision:: 2 $*
34 * *
35 * 5/20/02 KM Added save load behavior
36 *---------------------------------------------------------------------------------------------*
37 * Functions: *
38 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
39
40#include "w3d_file.h"
41#include "chunkio.h"
42#include "shddef.h"
43#include "shddefmanager.h"
44#include "shddeffactory.h"
45#include "wwdebug.h"
46#include "string.h"
47
48
49/*
50** Static head of the factory list
51*/
52ShdDefFactoryClass *ShdDefManagerClass::_FactoryListHead = NULL;
53
54
55//**********************************************************************************************
57
63{
64 ShdDefFactoryClass *factory = 0;
65
66 //
67 // Loop through all the factories and see if we can
68 // find the one who owns the corresponding class-id.
69 //
70 for ( ShdDefFactoryClass *curr_factory = _FactoryListHead;
71 (factory == 0) && (curr_factory != 0);
72 curr_factory = curr_factory->NextFactory)
73 {
74 //
75 // Is this the factory we were looking for?
76 //
77 if (curr_factory->Get_Class_ID () == class_id) {
78 factory = curr_factory;
79 }
80 }
81
82 return factory;
83}
84
85
86//**********************************************************************************************
88
93{
94 ShdDefFactoryClass * factory = 0;
95
96 //
97 // Loop through all the factories and see if we can
98 // find the one who owns the corresponding class-id.
99 //
100 for ( ShdDefFactoryClass *curr_factory = _FactoryListHead;
101 (factory == 0) && (curr_factory != 0);
102 curr_factory = curr_factory->NextFactory) {
103
104 //
105 // Is this the factory we were looking for?
106 //
107 if (::stricmp (curr_factory->Get_Name (), name) == 0) {
108 factory = curr_factory;
109 }
110 }
111
112 return factory;
113}
114
115
116//**********************************************************************************************
118
122{
123 WWASSERT (factory->NextFactory == 0);
124 WWASSERT (factory->PrevFactory == 0);
125 Link_Factory (factory);
126}
127
128
129//**********************************************************************************************
131
135{
136 WWASSERT (factory != 0);
137 Unlink_Factory (factory);
138 return ;
139}
140
141
143{
144 return _FactoryListHead;
145}
146
148{
149 //
150 // Simply return the next factory in the chain
151 //
152 if (current != NULL) {
153 return current->NextFactory;
154 }
155
156 return _FactoryListHead;
157}
158
159void ShdDefManagerClass::Link_Factory (ShdDefFactoryClass *factory)
160{
161 WWASSERT (factory->NextFactory == 0);
162 WWASSERT (factory->PrevFactory == 0);
163
164 // Adding this factory in front of the current head of the list
165 factory->NextFactory = _FactoryListHead;
166
167 // If the list wasn't empty, link the next factory back to this factory
168 if (factory->NextFactory != 0) {
169 factory->NextFactory->PrevFactory = factory;
170 }
171
172 // Point the head of the list at this factory now
173 _FactoryListHead = factory;
174 return ;
175}
176
177void ShdDefManagerClass::Unlink_Factory (ShdDefFactoryClass *factory)
178{
179 WWASSERT(factory != 0);
180
181 // Handle the factory's prev pointer:
182 if (factory->PrevFactory == 0) {
183
184 // this factory is the head
185 WWASSERT (_FactoryListHead == factory);
186 _FactoryListHead = factory->NextFactory;
187
188 } else {
189
190 // link it's prev with it's next
191 factory->PrevFactory->NextFactory = factory->NextFactory;
192
193 }
194
195 // Handle the factory's next pointer if its not at the end of the list:
196 if (factory->NextFactory != 0) {
197
198 factory->NextFactory->PrevFactory = factory->PrevFactory;
199
200 }
201
202 // factory is now un-linked
203 factory->NextFactory = 0;
204 factory->PrevFactory = 0;
205 return ;
206}
207
209{
210 // first look up the factory for this classid
211 ShdDefFactoryClass * factory = Find_Factory (class_id);
212
213 if (factory != NULL)
214 {
215 return factory->Create();
216 }
217 else
218 {
219 return NULL;
220 }
221}
222
224{
226 uint32 id=shddef->Get_Class_ID();
227 csave.Write(&id,sizeof(uint32));
228 csave.End_Chunk();
229
231 shddef->Save(csave);
232 csave.End_Chunk();
233
234}
235
237{
238 uint32 id;
239
240 cload.Open_Chunk();
241 cload.Read(&id,sizeof(uint32));
242 cload.Close_Chunk();
243
244 *shddef=Create_ShdDefClass_Instance(id);
245
246 cload.Open_Chunk();
247 (*shddef)->Load(cload);
248 cload.Close_Chunk();
249}
250
#define NULL
Definition BaseType.h:92
#define WWASSERT
@ W3D_CHUNK_SHDSUBMESH_SHADER_CLASSID
Definition w3d_file.h:500
@ W3D_CHUNK_SHDSUBMESH_SHADER_DEF
Definition w3d_file.h:501
unsigned long uint32
Definition bittype.h:46
bool Close_Chunk()
Definition chunkio.cpp:448
uint32 Read(void *buf, uint32 nbytes)
Definition chunkio.cpp:692
bool Open_Chunk()
Definition chunkio.cpp:412
uint32 Write(const void *buf, uint32 nbytes)
Definition chunkio.cpp:264
bool Begin_Chunk(uint32 id)
Definition chunkio.cpp:108
bool End_Chunk()
Definition chunkio.cpp:148
WWINLINE uint32 Get_Class_ID(void) const
Definition shddef.h:97
virtual bool Save(ChunkSaveClass &csave)
Serialize this ShdDef into a chunk saver.
Definition shddef.cpp:140
ShdDefFactoryClass * NextFactory
ShdDefFactoryClass * PrevFactory
virtual ShdDefClass * Create(void) const =0
static ShdDefClass * Create_ShdDefClass_Instance(uint32 class_id)
static ShdDefFactoryClass * Get_First(void)
static void Load_Shader(ChunkLoadClass &cload, ShdDefClass **shddef)
static void Save_Shader(ChunkSaveClass &csave, ShdDefClass *shddef)
static ShdDefFactoryClass * Find_Factory(uint32 class_id)
Used to look up the ShdDefFactory for a given class id.
static void Unregister_Factory(ShdDefFactoryClass *factory)
removes a factory from the system
static void Register_Factory(ShdDefFactoryClass *factory)
Registers a factory with the system.
static ShdDefFactoryClass * Get_Next(ShdDefFactoryClass *current, uint32 superclass_id)
else return(RetVal)