forked from Oniryck/POSTAL-1-Open-Source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Anim3D.cpp
435 lines (396 loc) · 13.7 KB
/
Anim3D.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
////////////////////////////////////////////////////////////////////////////////
//
// Copyright 2016 RWS Inc, All Rights Reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of version 2 of the GNU General Public License as published by
// the Free Software Foundation
//
// 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, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// Anim3D.CPP
// Project: Postal
//
// History:
// 05/23/97 JMI Started. Moved here from thing.h.
// Also, added events.
//
// 08/01/97 BRH Took out loading/releasing .hot channels since
// we aren't using them.
//
// 08/07/97 JMI Added m_ptransWeapon rigid body transforms channel for
// weapons.
// Also, added SetLooping().
// Also, removed all (including commented out) references to
// hots and floors.
//
// 08/11/97 JMI Now has TRACEs to complain when an animation fails to
// load.
// Also, on the first component to fail, no more are loaded.
// Also, if any fail to load, all that were loaded are
// released.
//
// 08/12/97 BRH Added yet another overloaded version of Get which
// takes a number of a texture file to be loaded.
//
// 12/17/97 JMI Now if the sTextureScheme values is less than zero, no
// number is used (i.e., the default texture scheme is used).
//
// 10/07/99 JMI Added conditional compile options for some error messages.
//
//////////////////////////////////////////////////////////////////////////////
//
// 3D animation class that is a collection of channels that make up a 3D
// animation.
//
//////////////////////////////////////////////////////////////////////////////
#define ANIM3D_CPP
#include "RSPiX.h"
#include "Anim3D.h"
#include "game.h"
////////////////////////////////////////////////////////////////////////////////
// Macros/types/etc.
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Variables/data
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Functions.
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Default constructor.
////////////////////////////////////////////////////////////////////////////////
CAnim3D::CAnim3D()
{
m_psops = NULL;
m_pmeshes = NULL;
m_ptextures = NULL;
m_pbounds = NULL;
m_ptransRigid = NULL;
m_pevent = NULL;
m_ptransWeapon = NULL;
}
////////////////////////////////////////////////////////////////////////////////
// Get the various components of this animation from the resource names
// specified in the provided array of pointers to strings.
// (virtual)
////////////////////////////////////////////////////////////////////////////////
short CAnim3D::Get( // Returns 0 on success.
char** ppszFileNames) // Pointer to array of pointers to filenames.
// These filenames should be in the order
// the members are listed in this class's
// definition.
{
short sRes;
short sComplainIndex; // If sRes is non-zero, this is the index of the
// resname that could not load.
// NOTE: If you add any new channel loads here, please make sure
// you maintain the order described above.
sComplainIndex = 0;
sRes = rspGetResource(&g_resmgrGame, ppszFileNames[sComplainIndex], &m_psops);
if (sRes == 0)
{
sComplainIndex = 1;
sRes = rspGetResource(&g_resmgrGame, ppszFileNames[sComplainIndex], &m_pmeshes);
if (sRes == 0)
{
sComplainIndex = 2;
sRes = rspGetResource(&g_resmgrGame, ppszFileNames[sComplainIndex], &m_ptextures);
if (sRes == 0)
{
sComplainIndex = 4;
sRes = rspGetResource(&g_resmgrGame, ppszFileNames[sComplainIndex], &m_pbounds);
if (sRes == 0)
{
sComplainIndex = 6;
if (ppszFileNames[sComplainIndex] != NULL)
{
sRes = rspGetResource(&g_resmgrGame, ppszFileNames[sComplainIndex], &m_ptransRigid);
}
}
}
}
}
// No current support for events since that might break existing
// arrays of size 6 elements.
// No current support for weapon transforms either.
// If an error occurred . . .
if (sRes != 0)
{
#if defined(VERBOSE)
// Complain.
TRACE("Get(): Unable to load \"%s\".\n", ppszFileNames[sComplainIndex] );
#endif
// Clean.
Release();
}
return sRes;
}
////////////////////////////////////////////////////////////////////////////////
// Get the various components of this animation from the resource names
// specified in the provided array of pointers to strings.
// (virtual)
////////////////////////////////////////////////////////////////////////////////
short CAnim3D::Get( // Returns 0 on success.
char** ppszFileNames, // Pointer to array of pointers to filenames.
// These filenames should be in the order
// the members are listed in this class's
// definition.
short sLoopFlags) // Looping flags to apply to all channels in this anim
{
short sRes = Get(ppszFileNames);
// If successful . . .
if (sRes == 0)
{
SetLooping(sLoopFlags);
}
return sRes;
}
////////////////////////////////////////////////////////////////////////////////
// Get the various components of this animation from the resource names
// specified by base name, optionally, with a rigid name.
// (virtual)
////////////////////////////////////////////////////////////////////////////////
short CAnim3D::Get( // Returns 0 on success.
char* pszBaseFileName, // In: Base string for resource filenames.
char* pszRigidName, // In: String to add for rigid transform channel,
// "", or NULL for none.
char* pszEventName, // In: String to add for event states channel,
// "", or NULL for none.
char* pszWeaponTransName, // In: String to add for weapon transforms channel,
// "", or NULL for none.
short sLoopFlags) // In: Looping flags to apply to all channels
// in this anim.
{
short sRes;
char szResName[RSP_MAX_PATH];
sprintf(szResName, "%s.sop", pszBaseFileName);
sRes = rspGetResource(&g_resmgrGame, szResName, &m_psops);
if (sRes == 0)
{
sprintf(szResName, "%s.mesh", pszBaseFileName);
sRes = rspGetResource(&g_resmgrGame, szResName, &m_pmeshes);
if (sRes == 0)
{
sprintf(szResName, "%s.tex", pszBaseFileName);
sRes = rspGetResource(&g_resmgrGame, szResName, &m_ptextures);
if (sRes == 0)
{
sprintf(szResName, "%s.bounds", pszBaseFileName);
sRes = rspGetResource(&g_resmgrGame, szResName, &m_pbounds);
if (sRes == 0)
{
if (pszRigidName != NULL)
{
if (*pszRigidName != '\0')
{
sprintf(szResName, "%s_%s.trans", pszBaseFileName, pszRigidName);
sRes = rspGetResource(&g_resmgrGame, szResName, &m_ptransRigid);
}
}
if (sRes == 0)
{
if (pszEventName != NULL)
{
if (*pszEventName != '\0')
{
sprintf(szResName, "%s_%s.event", pszBaseFileName, pszEventName);
sRes = rspGetResource(&g_resmgrGame, szResName, &m_pevent);
}
}
if (sRes == 0)
{
if (pszWeaponTransName != NULL)
{
if (*pszWeaponTransName != '\0')
{
sprintf(szResName, "%s_%s.trans", pszBaseFileName, pszWeaponTransName);
sRes = rspGetResource(&g_resmgrGame, szResName, &m_ptransWeapon);
}
}
}
}
}
}
}
}
// If successful . . .
if (sRes == 0)
{
SetLooping(sLoopFlags);
}
else
{
#if defined(VERBOSE)
TRACE("Get(): Unable to load \"%s\".\n", szResName);
#endif
// Clean.
Release();
}
return sRes;
}
////////////////////////////////////////////////////////////////////////////////
// Get the various components of this animation from the resource names
// specified by base name, optionally, with a rigid name.
// (virtual)
////////////////////////////////////////////////////////////////////////////////
short CAnim3D::Get( // Returns 0 on success.
char* pszBaseFileName, // In: Base string for resource filenames.
char* pszVerb, // In: Action name to be appended to the base
char* pszRigidName, // In: String to add for rigid transform channel,
// "", or NULL for none.
char* pszEventName, // In: String to add for event states channel,
// "", or NULL for none.
char* pszWeaponTransName, // In: String to add for weapon transforms channel,
// "", or NULL for none.
short sLoopFlags) // In: Looping flags to apply to all channels
// in this anim.
{
char szVerbedBaseName[RSP_MAX_PATH];
sprintf(szVerbedBaseName, "%s_%s", pszBaseFileName, pszVerb);
return Get(szVerbedBaseName, pszRigidName, pszEventName, pszWeaponTransName, sLoopFlags);
}
////////////////////////////////////////////////////////////////////////////////
// Get the various components of the animation using the given resource names,
// but load only 1 .tex file based on the color scheme number passed in.
////////////////////////////////////////////////////////////////////////////////
short CAnim3D::Get( // Returns 0 on success.
char* pszBaseFileName, // In: Base string for resource filenames.
short sTextureScheme, // In: Number to append after name for texture file
char* pszVerb, // In: Action name to be appended to the base
char* pszRigidName, // In: String to add for rigid transform channel,
// "", or NULL for none.
char* pszEventName, // In: String to add for event states channel,
// "", or NULL for none.
char* pszWeaponTransName, // In: String to add for weapon transforms channel,
// "", or NULL for none.
short sLoopFlags) // In: Looping flags to apply to all channels
// in this anim.
{
char szVerbedBaseName[RSP_MAX_PATH];
sprintf(szVerbedBaseName, "%s_%s", pszBaseFileName, pszVerb);
short sRes;
char szResName[RSP_MAX_PATH];
sprintf(szResName, "%s.sop", szVerbedBaseName);
sRes = rspGetResource(&g_resmgrGame, szResName, &m_psops);
if (sRes == 0)
{
sprintf(szResName, "%s.mesh", szVerbedBaseName);
sRes = rspGetResource(&g_resmgrGame, szResName, &m_pmeshes);
if (sRes == 0)
{
// If there's an associated texture scheme . . .
if (sTextureScheme >= 0)
{
sprintf(szResName, "%s%d.tex", pszBaseFileName, sTextureScheme);
}
else
{
sprintf(szResName, "%s.tex", szVerbedBaseName);
}
sRes = rspGetResource(&g_resmgrGame, szResName, &m_ptextures);
if (sRes == 0)
{
sprintf(szResName, "%s.bounds", szVerbedBaseName);
sRes = rspGetResource(&g_resmgrGame, szResName, &m_pbounds);
if (sRes == 0)
{
if (pszRigidName != NULL)
{
if (*pszRigidName != '\0')
{
sprintf(szResName, "%s_%s.trans", szVerbedBaseName, pszRigidName);
sRes = rspGetResource(&g_resmgrGame, szResName, &m_ptransRigid);
}
}
if (sRes == 0)
{
if (pszEventName != NULL)
{
if (*pszEventName != '\0')
{
sprintf(szResName, "%s_%s.event", szVerbedBaseName, pszEventName);
sRes = rspGetResource(&g_resmgrGame, szResName, &m_pevent);
}
}
if (sRes == 0)
{
if (pszWeaponTransName != NULL)
{
if (*pszWeaponTransName != '\0')
{
sprintf(szResName, "%s_%s.trans", szVerbedBaseName, pszWeaponTransName);
sRes = rspGetResource(&g_resmgrGame, szResName, &m_ptransWeapon);
}
}
}
}
}
}
}
}
// If successful . . .
if (sRes == 0)
{
SetLooping(sLoopFlags);
}
else
{
#if defined(VERBOSE)
TRACE("Get(): Unable to load \"%s\".\n", szResName);
#endif
// Clean.
Release();
}
return sRes;
}
////////////////////////////////////////////////////////////////////////////////
// Release all resources.
// (virtual)
////////////////////////////////////////////////////////////////////////////////
void CAnim3D::Release(void) // Returns nothing.
{
if (m_psops != NULL)
rspReleaseResource(&g_resmgrGame, &m_psops);
if (m_pmeshes != NULL)
rspReleaseResource(&g_resmgrGame, &m_pmeshes);
if (m_ptextures != NULL)
rspReleaseResource(&g_resmgrGame, &m_ptextures);
if (m_pbounds != NULL)
rspReleaseResource(&g_resmgrGame, &m_pbounds);
if (m_ptransRigid != NULL)
rspReleaseResource(&g_resmgrGame, &m_ptransRigid);
if (m_pevent != NULL)
rspReleaseResource(&g_resmgrGame, &m_pevent);
if (m_ptransWeapon)
rspReleaseResource(&g_resmgrGame, &m_ptransWeapon);
}
////////////////////////////////////////////////////////////////////////////////
// Set looping flags for this channel.
// (virtual)
////////////////////////////////////////////////////////////////////////////////
void CAnim3D::SetLooping( // Returns nothing.
short sLoopFlags) // In: Looping flags to apply to all channels
// in this anim.
{
m_psops->SetLooping(sLoopFlags);
m_pmeshes->SetLooping(sLoopFlags);
m_ptextures->SetLooping(sLoopFlags);
m_pbounds->SetLooping(sLoopFlags);
if (m_ptransRigid != NULL)
m_ptransRigid->SetLooping(sLoopFlags);
if (m_pevent != NULL)
m_pevent->SetLooping(sLoopFlags);
if (m_ptransWeapon)
m_ptransWeapon->SetLooping(sLoopFlags);
}
////////////////////////////////////////////////////////////////////////////////
// EOF
////////////////////////////////////////////////////////////////////////////////