Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
hmdldef.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 : WW3D *
24 * *
25 * $Archive:: /Commando/Code/ww3d2/hmdldef.cpp $*
26 * *
27 * Author:: Greg_h *
28 * *
29 * $Modtime:: 1/08/01 10:04a $*
30 * *
31 * $Revision:: 1 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * HModelDefClass::HModelDefClass -- Constructor *
36 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
37
38
39#include "hmdldef.h"
40#include <assert.h>
41#include <string.h>
42#include "w3d_file.h"
43#include "chunkio.h"
44#include "snappts.h"
45
46
47/***********************************************************************************************
48 * HModelDefClass::HModelDefClass -- Constructor *
49 * *
50 * INPUT: *
51 * *
52 * OUTPUT: *
53 * *
54 * WARNINGS: *
55 * *
56 * HISTORY: *
57 * 12/15/97 GTH : Created. *
58 *=============================================================================================*/
60 SubObjectCount(0),
61 SubObjects(NULL),
62 SnapPoints(NULL)
63{
64
65}
66
67/***********************************************************************************************
68 * HModelDefClass::~HModelDefClass -- destructor *
69 * *
70 * INPUT: *
71 * *
72 * OUTPUT: *
73 * *
74 * WARNINGS: *
75 * *
76 * HISTORY: *
77 * 08/11/1997 GH : Created. *
78 *=============================================================================================*/
80{
81 Free();
82}
83
84/***********************************************************************************************
85 * HModelDefClass::Free -- de-allocate all memory in use *
86 * *
87 * INPUT: *
88 * *
89 * OUTPUT: *
90 * *
91 * WARNINGS: *
92 * *
93 * HISTORY: *
94 * 08/11/1997 GH : Created. *
95 *=============================================================================================*/
96void HModelDefClass::Free(void)
97{
98 if (SubObjects != NULL) {
99 delete[] SubObjects;
100 SubObjects = NULL;
101 }
102 SubObjectCount = 0;
103
104 if (SnapPoints != NULL) {
105 SnapPoints->Release_Ref();
106 SnapPoints = NULL;
107 }
108}
109
110
111/***********************************************************************************************
112 * HModelDefClass::Load -- load a set of mesh connections from a file *
113 * *
114 * INPUT: *
115 * *
116 * OUTPUT: *
117 * *
118 * WARNINGS: *
119 * *
120 * HISTORY: *
121 * 08/11/1997 GH : Created. *
122 *=============================================================================================*/
124{
125 bool pre30 = false;
126 int subobjcounter = 0;
127
128 Free();
129
130 /*
131 ** Read the first chunk, it should be the header
132 */
133 if (!cload.Open_Chunk()) {
134 return false;
135 }
136
137 if (cload.Cur_Chunk_ID() != W3D_CHUNK_HMODEL_HEADER) {
138 goto Error;
139 }
140
141 /*
142 ** read in the header
143 */
145 if (cload.Read(&header,sizeof(W3dHModelHeaderStruct)) != sizeof(W3dHModelHeaderStruct)) {
146 goto Error;
147 }
148
149 cload.Close_Chunk();
150
151 /*
152 ** process the header info
153 */
154 strncpy(ModelName,header.Name,W3D_NAME_LEN);
155 ModelName[W3D_NAME_LEN - 1] = 0;
156 strncpy(BasePoseName,header.HierarchyName,W3D_NAME_LEN);
157 BasePoseName[W3D_NAME_LEN-1] = 0;
158 strcpy(Name,ModelName);
159
160 /*
161 ** Just allocate a node for the number of sub objects we're expecting
162 */
163 SubObjectCount = header.NumConnections;
164 SubObjects = W3DNEWARRAY HmdlNodeDefStruct[SubObjectCount];
165 if (SubObjects == NULL) {
166 goto Error;
167 }
168
169 /*
170 ** If this is pre-3.0 set a flag so that each render object's
171 ** bone id will be incremented by one to account for the new
172 ** root node added with version3.0 of the file format. Basically,
173 ** I'm making all of the code assume that node 0 is the root and
174 ** therefore, pre-3.0 files have to have it added and all of
175 ** the indices adjusted
176 */
177 if (header.Version < W3D_MAKE_VERSION(3,0)) {
178 pre30 = true;
179 }
180
181 /*
182 ** Process the rest of the chunks
183 */
184 subobjcounter = 0;
185
186 while (cload.Open_Chunk()) {
187
188 switch (cload.Cur_Chunk_ID()) {
189
190 case W3D_CHUNK_NODE:
193 if (!read_connection(cload,&(SubObjects[subobjcounter]),pre30)) {
194 goto Error;
195 }
196 subobjcounter++;
197 break;
198
199 case W3D_CHUNK_POINTS:
200 SnapPoints = W3DNEW SnapPointsClass;
201 SnapPoints->Load_W3D(cload);
202 break;
203
204 default:
205 break;
206 }
207 cload.Close_Chunk();
208 }
209
210 return OK;
211
212Error:
213
214 return LOAD_ERROR;
215
216}
217
218
219/***********************************************************************************************
220 * HModelDefClass::read_connection -- read a single connection from the file *
221 * *
222 * INPUT: *
223 * *
224 * OUTPUT: *
225 * *
226 * WARNINGS: *
227 * *
228 * HISTORY: *
229 * 08/11/1997 GH : Created. *
230 * 10/22/97 GH : Check for mesh connections with PivotID=-1 *
231 *=============================================================================================*/
232bool HModelDefClass::read_connection(ChunkLoadClass & cload,HmdlNodeDefStruct * node,bool pre30)
233{
234
236 if (cload.Read(&con,sizeof(W3dHModelNodeStruct)) != sizeof(W3dHModelNodeStruct)) {
237 return false;
238 }
239
240 strcpy(node->RenderObjName,ModelName);
241 strcat(node->RenderObjName,".");
242 strcat(node->RenderObjName,con.RenderObjName);
243
244 if (pre30) {
245 if (con.PivotIdx == 65535) {
246 node->PivotID = 0;
247 } else {
248 node->PivotID = con.PivotIdx + 1;
249 }
250 } else {
251 assert(con.PivotIdx != 65535);
252 node->PivotID = con.PivotIdx;
253 }
254
255 return true;
256}
257
#define NULL
Definition BaseType.h:92
#define W3D_NAME_LEN
Definition w3d_file.h:319
@ W3D_CHUNK_SKIN_NODE
Definition w3d_file.h:422
@ W3D_CHUNK_HMODEL_HEADER
Definition w3d_file.h:419
@ W3D_CHUNK_POINTS
Definition w3d_file.h:436
@ W3D_CHUNK_NODE
Definition w3d_file.h:420
@ W3D_CHUNK_COLLISION_NODE
Definition w3d_file.h:421
#define W3D_MAKE_VERSION(major, minor)
Definition w3d_file.h:315
#define W3DNEWARRAY
Definition always.h:110
#define W3DNEW
Definition always.h:109
bool Close_Chunk()
Definition chunkio.cpp:448
uint32 Cur_Chunk_ID()
Definition chunkio.cpp:484
uint32 Read(void *buf, uint32 nbytes)
Definition chunkio.cpp:692
bool Open_Chunk()
Definition chunkio.cpp:412
HModelDefClass(void)
Definition hmdldef.cpp:59
~HModelDefClass(void)
Definition hmdldef.cpp:79
int Load_W3D(ChunkLoadClass &cload)
Definition hmdldef.cpp:123
WW3DErrorType Load_W3D(ChunkLoadClass &cload)
Definition snappts.cpp:42
char RenderObjName[2 *W3D_NAME_LEN]
Definition hmdldef.H:61
char Name[W3D_NAME_LEN]
Definition w3d_file.h:1583
char HierarchyName[W3D_NAME_LEN]
Definition w3d_file.h:1584
char RenderObjName[W3D_NAME_LEN]
Definition w3d_file.h:1592