Debian Codegraph @

Descent3/vclip.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
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 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Main/vclip.cpp $
21 * $Revision: 26 $
22 * $Date: 5/10/00 2:43p $
23 * $Author: Jeff $
24 *
25 * <insert description of file here>
26 *
27 * $Log: /DescentIII/Main/vclip.cpp $
28 *
29 * 26 5/10/00 2:43p Jeff
30 * fixed bug when paging in data if the tablefile specifies a full path to
31 * a primative instead of just a filename (bug in 3rd party tablefile
32 * editors)
33 *
34 * 25 4/19/00 5:07p Matt
35 * From Duane for 1.4
36 * Added checks, asserts, and fixes for bad return values
37 *
38 * 24 10/21/99 9:27p Jeff
39 * B.A. Macintosh code merge
40 *
41 * 23 5/07/99 7:23p Jason
42 * changes for low video memory
43 *
44 * 22 4/14/99 3:57a Jeff
45 * fixed case mismatch in #includes
46 *
47 * 21 4/12/99 3:53p Jason
48 * fixed loading of erroneous vclips
49 *
50 * 20 3/02/99 1:17p Jason
51 * fixed loading of alpha numeric IFLs
52 *
53 * 19 2/10/99 3:47p Jason
54 * table filter changes
55 *
56 * 18 1/22/99 3:59p Jason
57 * added 256x256 textures to help with terrain skies
58 *
59 * 17 1/19/99 11:04a Jason
60 * fixed scaling problem
61 *
62 * 16 1/18/99 11:11a Jason
63 * made vclips be specular
64 *
65 * 15 10/18/98 2:59p Jason
66 * fixes for beta4
67 *
68 * 14 10/14/98 5:50p Jason
69 * added lowmem modes for quartering textures
70 *
71 * 13 10/09/98 3:32p Kevin
72 * New memory library
73 *
74 * 12 10/08/98 4:23p Kevin
75 * Changed code to comply with memory library usage. Always use mem_malloc
76 * , mem_free and mem_strdup
77 *
78 * 11 5/19/98 5:43p Jason
79 * free all vclips at the end of the program
80 *
81 * 10 5/14/98 2:38p Jason
82 * made temp solution for vclip residency problem
83 *
84 * 9 5/14/98 12:56p Jason
85 * changes to help lower memory usage
86 *
87 * 8 2/26/98 2:47p Mark
88 * added assert
89 *
90 * 7 2/11/98 4:58p Jason
91 * fixed some memory problems with resizing and mipping
92 *
93 * 6 11/03/97 6:21p Jason
94 * fixed some problems with animating textures being remapped improperly
95 *
96 * 5 10/31/97 6:33p Jason
97 * fixed bug with whitespace in ifl files
98 *
99 * 4 10/15/97 5:20p Jason
100 * did a HUGE overhaul of the bitmap system
101 *
102 * 3 9/04/97 12:03p Matt
103 * Got rid of warnings
104 *
105 * 2 8/20/97 6:09p Jason
106 * fixed out of bounds problem that bounds checker reported
107 *
108 * 16 5/13/97 2:24p Jason
109 * fixed a couple of animating texture bugs
110 *
111 * 15 5/12/97 11:41a Jason
112 * made game work (default) to 16bit no mip maps mode
113 * Saves us alot of memory
114 *
115 * 14 5/08/97 1:16p Jason
116 * made ChangeEndName work with device independant calls
117 *
118 * 13 5/01/97 1:05p Mark
119 * FROM JASON: Fixed stupid =/== bug in vclip loading
120 *
121 * 12 4/28/97 6:36p Jason
122 * fixed a bug with vclips
123 *
124 * 11 4/25/97 3:31p Jason
125 * implemented better memory management for vclips and bitmaps
126 *
127 * 10 4/24/97 5:42p Jason
128 * got fireball vclips working
129 *
130 * 9 3/03/97 6:21p Matt
131 * Changed cfile functions to use D3 naming convention
132 *
133 * 8 2/20/97 3:27p Jason
134 * made ifl reader ignore lines beginning with spaces
135 *
136 * 7 2/19/97 3:23p Jason
137 * added hooks to import animated iffs
138 *
139 * 6 2/19/97 11:37a Jason
140 * take gametime into consideration when animating a vclip
141 *
142 * 5 2/10/97 1:58p Jason
143 * made vclips free their bitmaps when they are deallocated
144 *
145 * 4 2/04/97 3:19p Jason
146 * better error checking
147 *
148 * 3 1/25/97 5:56p Jason
149 * changes to support new 8bit palettized textures and vclips
150 *
151 * 2 1/21/97 12:22p Jason
152 * added vclip support
153 *
154 * $NoKeywords: $
155 */
156
157 #include <cctype>
158 #include <cstdlib>
159 #include <cstring>
160 #include <filesystem>
161
162 #include "pstypes.h"cxx . . $ `<file>/lib/pstypes.h`/
163 #include "pserror.h"cxx . . $ `<file>/misc/pserror.h`/
164 #include "bitmap.h"cxx . . $ `<file>/lib/bitmap.h`/
165 #include "vclip.h"cxx . . $ `<file>/Descent3/vclip.h`/
166 #include "cfile.h"cxx . . $ `<file>/cfile/cfile.h`/
167 #include "mono.h"cxx . . $ `<file>/ddebug/mono.h`/
168 #include "ddio.h"cxx . . $ `<file>/ddio/ddio.h`/
169 #include "gametexture.h"cxx . . $ `<file>/Descent3/gametexture.h`/
170 #include "mem.h"cxx . . $ `<file>/mem/mem.h`/
171 #include "game.h"cxx . . $ `<file>/Descent3/game.h`/
172
173 vclipcxx . . $ vclip# GameVClipscxx . . $ GameVClips.[MAX_VCLIPScxx . . $ `Descent3/vclip.h:28:9`!];
174 int Num_vclipscxx . . $ Num_vclips. = 0;
175
176 #define DEFAULT_FRAMETIMEcxx . . $ `Descent3/vclip.cpp:176:9`! .07f
177
178 #define VCLIP_VERSIONcxx . . $ `Descent3/vclip.cpp:178:9`! 1
179 // Frees all the memory used by vclips
180 void FreeAllVClipscxx . . $ FreeAllVClips(49f6e7a06ebc5aa8).() {
181 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Freeing all vclips!\n");
182
183 for (int i = 0; i < MAX_VCLIPScxx . . $ `Descent3/vclip.h:28:9`!; i++) {
184 if (GameVClipscxx . . $ GameVClips.[i].usedcxx . . $ vclip#used. > 0) {
185 GameVClipscxx . . $ GameVClips.[i].usedcxx . . $ vclip#used. = 1;
186 FreeVClipcxx . . $ FreeVClip(d4f767463ce0a6b3).(i);
187 }
188 }
189 }
190
191 // Simply sets all vclips to unused
192 void InitVClipscxx . . $ InitVClips(49f6e7a06ebc5aa8).() {
193 for (int i = 0; i < MAX_VCLIPScxx . . $ `Descent3/vclip.h:28:9`!; i++)
194 GameVClipscxx . . $ GameVClips.[i].usedcxx . . $ vclip#used. = 0;
195
196 atexit(FreeAllVClipscxx . . $ FreeAllVClips(49f6e7a06ebc5aa8).);
197 }
198
199 // Allocs a vclip for use
200 // Returns -1 on error
201 int AllocVClipcxx . . $ AllocVClip(b126dc7c1de90089).() {
202 int i;
203
204 for (i = 0; i < MAX_VCLIPScxx . . $ `Descent3/vclip.h:28:9`!; i++) {
205 if (GameVClipscxx . . $ GameVClips.[i].usedcxx . . $ vclip#used. == 0) {
206 memset(&GameVClipscxx . . $ GameVClips.[i], 0, sizeof(vclipcxx . . $ vclip#));
207 GameVClipscxx . . $ GameVClips.[i].framescxx . . $ vclip#frames. = (int16_t *)mem_malloccxx . . $ `mem/mem.h:79:9`!(VCLIP_MAX_FRAMEScxx . . $ `Descent3/vclip.h:29:9`! * sizeof(int16_t));
208 ASSERTcxx . . $ `misc/pserror.h:246:9`!(GameVClips[i].frames);
209 GameVClipscxx . . $ GameVClips.[i].frame_timecxx . . $ vclip#frame_time. = DEFAULT_FRAMETIMEcxx . . $ `Descent3/vclip.cpp:176:9`!;
210 GameVClipscxx . . $ GameVClips.[i].flagscxx . . $ vclip#flags. = VCF_NOT_RESIDENTcxx . . $ `Descent3/vclip.h:31:9`!;
211 GameVClipscxx . . $ GameVClips.[i].usedcxx . . $ vclip#used. = 1;
212 Num_vclipscxx . . $ Num_vclips.++;
213 return i;
214 }
215 }
216
217 Int3cxx . . $ `misc/pserror.h:247:9`!(); // Ran out of vclips. What the hell are you doing? Get Jason
218 return -1;
219 }
220
221 void FreeVClipcxx . . $ FreeVClip(d4f767463ce0a6b3).(int num) {
222 ASSERTcxx . . $ `misc/pserror.h:246:9`!(GameVClips[num].used > 0);
223
224 GameVClipscxx . . $ GameVClips.[num].usedcxx . . $ vclip#used.--;
225 if (GameVClipscxx . . $ GameVClips.[num].usedcxx . . $ vclip#used. > 0)
226 return; // other things are using this vclip
227
228 if (!(GameVClipscxx . . $ GameVClips.[num].flagscxx . . $ vclip#flags. & VCF_NOT_RESIDENTcxx . . $ `Descent3/vclip.h:31:9`!)) {
229 for (int i = 0; i < GameVClipscxx . . $ GameVClips.[num].num_framescxx . . $ vclip#num_frames.; i++)
230 bm_FreeBitmapcxx . . $ bm_FreeBitmap(d4f767463ce0a6b3).(GameVClipscxx . . $ GameVClips.[num].framescxx . . $ vclip#frames.[i]);
231 }
232
233 mem_freecxx . . $ `mem/mem.h:80:9`!(GameVClips[num].frames);
234
235 Num_vclipscxx . . $ Num_vclips.--;
236 ASSERTcxx . . $ `misc/pserror.h:246:9`!(Num_vclips >= 0);
237 }
238
239 // Saves a given video clip to a file
240 // Returns 1 if everything ok, 0 otherwise
241 // "num" is index into GameVClip array
242 int SaveVClipcxx . . $ SaveVClip(220e687f58daa9be).(const stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path#& filename, int num) {
243 CFILEcxx . . $ CFILE# *outfile;
244 vclipcxx . . $ vclip# *vc = &GameVClipscxx . . $ GameVClips.[num];
245
246 ASSERTcxx . . $ `misc/pserror.h:246:9`!(vc->used);
247 ASSERTcxx . . $ `misc/pserror.h:246:9`!(!filename.empty());
248
249 PageInVClipcxx . . $ PageInVClip(d4f767463ce0a6b3).(num);
250
251 outfile = (CFILEcxx . . $ CFILE# *)cfopencxx . . $ cfopen(7c7b94e455f1ae56).(filename, "wb");
252 if (!outfile) {
253 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Couldn't save vclip %s!\n", filename.u8string().c_str());
254 return 0;
255 }
256
257 // write out the header for this vclip
258 cf_WriteBytecxx . . $ cf_WriteByte(17377ebd5835367f).(outfile, 127);
259 cf_WriteBytecxx . . $ cf_WriteByte(17377ebd5835367f).(outfile, (int8_t)VCLIP_VERSIONcxx . . $ `Descent3/vclip.cpp:178:9`!);
260
261 cf_WriteBytecxx . . $ cf_WriteByte(17377ebd5835367f).(outfile, vc->num_framescxx . . $ vclip#num_frames.);
262 // cf_WriteFloat (outfile,vc->play_time);
263 cf_WriteFloatcxx . . $ cf_WriteFloat(c51c6cf5f6d5270c).(outfile, vc->frame_timecxx . . $ vclip#frame_time.);
264 // cf_WriteInt (outfile,vc->flags);
265 // cf_WriteFloat (outfile,vc->light_value);
266
267 // Now save each frame of this vclip
268 for (int i = 0; i < vc->num_framescxx . . $ vclip#num_frames.; i++) {
269 if (bm_SaveBitmapcxx . . $ bm_SaveBitmap(3041dee38160abc0).(outfile, vc->framescxx . . $ vclip#frames.[i]) != 1) {
270 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Couldn't save frame %d of vclip %s!\n", i, filename.u8string().c_str());
271 Int3cxx . . $ `misc/pserror.h:247:9`!();
272 cfclosecxx . . $ cfclose(3639e799710acb68).(outfile);
273 return 0;
274 }
275 }
276
277 cfclosecxx . . $ cfclose(3639e799710acb68).(outfile);
278 return 1;
279 }
280
281 extern int Low_vidmemcxx . . $ Low_vidmem.;
282 // Pages in a vclip if it needs to be
283 void PageInVClipcxx . . $ PageInVClip(d4f767463ce0a6b3).(int vcnum) {
284 ASSERTcxx . . $ `misc/pserror.h:246:9`!(GameVClips[vcnum].used);
285 if (!(GameVClipscxx . . $ GameVClips.[vcnum].flagscxx . . $ vclip#flags. & VCF_NOT_RESIDENTcxx . . $ `Descent3/vclip.h:31:9`!))
286 return;
287
288 int mipped = 0;
289 int texture_size = GameVClipscxx . . $ GameVClips.[vcnum].target_sizecxx . . $ vclip#target_size.;
290 vclipcxx . . $ vclip# *vc = &GameVClipscxx . . $ GameVClips.[vcnum];
291 if (vc->flagscxx . . $ vclip#flags. & VCF_WANTS_MIPPEDcxx . . $ `Descent3/vclip.h:32:9`!)
292 mipped = 1;
293
294 CFILEcxx . . $ CFILE# *infile = (CFILEcxx . . $ CFILE# *)cfopencxx . . $ cfopen(7c7b94e455f1ae56).(vccxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d).->namecxx . . $ vclip#name., "rb");
295 if (!infile) {
296 // due to a bug in some 3rd party tablefile editors, full paths might
297 // have been used when they shouldn't have been
298 char *end_ptr, *start_ptr;
299 start_ptr = vc->namecxx . . $ vclip#name.;
300 end_ptr = start_ptr + strlen(start_ptr) - 1;
301 while ((end_ptr >= start_ptr) && (*end_ptr != '\\'))
302 end_ptr--;
303 if (end_ptr < start_ptr) {
304 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Couldn't load vclip %s!\n", vc->name);
305 return;
306 }
307
308 ASSERTcxx . . $ `misc/pserror.h:246:9`!(*end_ptr == '\\');
309 end_ptr++;
310
311 infile = (CFILEcxx . . $ CFILE# *)cfopencxx . . $ cfopen(7c7b94e455f1ae56).(end_ptrcxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d)., "rb");
312 if (!infile) {
313 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Couldn't load vclip %s!\n", vc->name);
314 return;
315 }
316 }
317
318 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Paging in vclip %s!\n", vc->name);
319
320 uint8_tcxx . . $ uint8_t# start_val = cf_ReadBytecxx . . $ cf_ReadByte(dcbbf0b0e13758ec).(infile);
321 int version = 0;
322 if (start_val != 127) {
323 version = 0;
324 vc->num_framescxx . . $ vclip#num_frames. = start_val;
325 cf_ReadFloatcxx . . $ cf_ReadFloat(9a03a00aead0d542).(infile);
326 vc->frame_timecxx . . $ vclip#frame_time. = cf_ReadFloatcxx . . $ cf_ReadFloat(9a03a00aead0d542).(infile);
327 cf_ReadIntcxx . . $ cf_ReadInt(d60d6f5e30f0c96a).(infile);
328 cf_ReadFloatcxx . . $ cf_ReadFloat(9a03a00aead0d542).(infile);
329 vc->frame_timecxx . . $ vclip#frame_time. = DEFAULT_FRAMETIMEcxx . . $ `Descent3/vclip.cpp:176:9`!;
330 } else {
331 version = cf_ReadBytecxx . . $ cf_ReadByte(dcbbf0b0e13758ec).(infile);
332 vc->num_framescxx . . $ vclip#num_frames. = cf_ReadBytecxx . . $ cf_ReadByte(dcbbf0b0e13758ec).(infile);
333 vc->frame_timecxx . . $ vclip#frame_time. = cf_ReadFloatcxx . . $ cf_ReadFloat(9a03a00aead0d542).(infile);
334 vc->frame_timecxx . . $ vclip#frame_time. = DEFAULT_FRAMETIMEcxx . . $ `Descent3/vclip.cpp:176:9`!;
335 }
336
337 for (int i = 0; i < vc->num_framescxx . . $ vclip#num_frames.; i++) {
338 int n = bm_AllocLoadBitmapcxx . . $ bm_AllocLoadBitmap(9615a1d56f56ba5b).(infile, mipped);
339
340 ASSERTcxx . . $ `misc/pserror.h:246:9`!(n > 0);
341
342 int w, h;
343
344 if (texture_size == NORMAL_TEXTUREcxx . . $ `Descent3/gametexture.h:239:9`!) {
345 w = TEXTURE_WIDTHcxx . . $ `lib/renderer.h:308:9`!;
346 h = TEXTURE_HEIGHTcxx . . $ `lib/renderer.h:309:9`!;
347
348 #ifndef EDITOR
349 if (Mem_low_memory_modecxx . . $ Mem_low_memory_mode. || Low_vidmemcxx . . $ Low_vidmem.)
350 {
351 w = TEXTURE_WIDTHcxx . . $ `lib/renderer.h:308:9`! / 2;
352 h = TEXTURE_HEIGHTcxx . . $ `lib/renderer.h:309:9`! / 2;
353 }
354 #endif
355 } else if (texture_size == SMALL_TEXTUREcxx . . $ `Descent3/gametexture.h:240:9`!) {
356 // Make small textures a quarter of the size of normal textures
357 w = TEXTURE_WIDTHcxx . . $ `lib/renderer.h:308:9`! / 2;
358 h = TEXTURE_HEIGHTcxx . . $ `lib/renderer.h:309:9`! / 2;
359
360 #ifndef EDITOR
361 if (Mem_low_memory_modecxx . . $ Mem_low_memory_mode. || Low_vidmemcxx . . $ Low_vidmem.)
362 {
363 w = TEXTURE_WIDTHcxx . . $ `lib/renderer.h:308:9`! / 4;
364 h = TEXTURE_HEIGHTcxx . . $ `lib/renderer.h:309:9`! / 4;
365 }
366 #endif
367 } else if (texture_size == TINY_TEXTUREcxx . . $ `Descent3/gametexture.h:241:9`!) {
368 // Make these tinys an eigth of the size of normal textures
369 w = TEXTURE_WIDTHcxx . . $ `lib/renderer.h:308:9`! / 4;
370 h = TEXTURE_HEIGHTcxx . . $ `lib/renderer.h:309:9`! / 4;
371 } else if (texture_size == HUGE_TEXTUREcxx . . $ `Descent3/gametexture.h:242:9`!) {
372 // Make these tinys an eigth of the size of normal textures
373 w = TEXTURE_WIDTHcxx . . $ `lib/renderer.h:308:9`! * 2;
374 h = TEXTURE_HEIGHTcxx . . $ `lib/renderer.h:309:9`! * 2;
375 } else {
376 w = bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(n, 0);
377 h = bm_hcxx . . $ bm_h(9b79fb6aee4c0440).(n, 0);
378 }
379
380 // If differing size, resize!
381 if (w != bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(n, 0) || h != bm_hcxx . . $ bm_h(9b79fb6aee4c0440).(n, 0)) {
382 int dest_bm;
383
384 dest_bm = bm_AllocBitmapcxx . . $ bm_AllocBitmap(2326284602b0bb2d).(w, h, mipped * ((w * h * 2) / 3));
385 ASSERTcxx . . $ `misc/pserror.h:246:9`!(dest_bm >= 0);
386 if (mipped)
387 GameBitmapscxx . . $ GameBitmaps.[dest_bm].flagscxx . . $ bms_bitmap#flags. |= BF_MIPMAPPEDcxx . . $ `lib/bitmap.h:47:9`!;
388 GameBitmapscxx . . $ GameBitmaps.[dest_bm].formatcxx . . $ bms_bitmap#format. = GameBitmapscxx . . $ GameBitmaps.[n].formatcxx . . $ bms_bitmap#format.;
389
390 bm_ScaleBitmapToBitmapcxx . . $ bm_ScaleBitmapToBitmap(3e454b8ccf442868).(dest_bm, n);
391 strcpy(GameBitmapscxx . . $ GameBitmaps.[dest_bm].namecxx . . $ bms_bitmap#name., GameBitmapscxx . . $ GameBitmaps.[n].namecxx . . $ bms_bitmap#name.);
392 bm_FreeBitmapcxx . . $ bm_FreeBitmap(d4f767463ce0a6b3).(n);
393
394 n = dest_bm;
395 }
396
397 ASSERTcxx . . $ `misc/pserror.h:246:9`!(n >= 0);
398 vc->framescxx . . $ vclip#frames.[i] = n; // assign frame to bitmap
399 }
400
401 cfclosecxx . . $ cfclose(3639e799710acb68).(infile);
402
403 vc->flagscxx . . $ vclip#flags. &= ~VCF_NOT_RESIDENTcxx . . $ `Descent3/vclip.h:31:9`!;
404 }
405
406 // Allocs and loads a vclip from the file named "filename"
407 // Returns -1 on error, index into GameVClip array on success
408 int AllocLoadVClipcxx . . $ AllocLoadVClip(cf529e05df08c24).(const char *filename, int texture_size, int mipped, int pageable, int format) {
409 char name[PAGENAME_LENcxx . . $ `lib/manage_external.h:49:9`!];
410 int i;
411
412 ASSERTcxx . . $ `misc/pserror.h:246:9`!(filename != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
413
414 i = strlen(filename);
415
416 if (filename[i - 4] == '.' && filename[i - 3] == 'i' && filename[i - 2] == 'f' && filename[i - 1] == 'l')
417 return AllocLoadIFLVClipcxx . . $ AllocLoadIFLVClip(c0ca7c05705093b).(IGNORE_TABLEcxx . . $ `lib/manage_external.h:54:9`!(filename), texture_size, mipped, format);
418
419 if (filename[i - 4] == '.' && filename[i - 3] == 'a' && filename[i - 2] == 'b' && filename[i - 1] == 'm')
420 Int3cxx . . $ `misc/pserror.h:247:9`!(); // Get Jason
421 // return AllocLoadIFFAnimClip(filename,);
422
423 ChangeVClipNamecxx . . $ ChangeVClipName(611124a97efc52dd).(filename, name);
424
425 // Check to see if this vclip already exists in memory
426 if ((i = FindVClipNamecxx . . $ FindVClipName(5c4306d8553b3696).(IGNORE_TABLEcxx . . $ `lib/manage_external.h:54:9`!(name))) != -1) {
427 GameVClipscxx . . $ GameVClips.[i].usedcxx . . $ vclip#used.++;
428 return i;
429 }
430
431 // mprintf(0,"Loading OAF vclip %s\n",name);
432
433 int vcnum = AllocVClipcxx . . $ AllocVClip(b126dc7c1de90089).();
434
435 ASSERTcxx . . $ `misc/pserror.h:246:9`!(vcnum >= 0);
436 strncpy(GameVClipscxx . . $ GameVClips.[vcnum].namecxx . . $ vclip#name., name, PAGENAME_LENcxx . . $ `lib/manage_external.h:49:9`!);
437
438 if (mipped)
439 GameVClipscxx . . $ GameVClips.[vcnum].flagscxx . . $ vclip#flags. |= VCF_WANTS_MIPPEDcxx . . $ `Descent3/vclip.h:32:9`!;
440
441 GameVClipscxx . . $ GameVClips.[vcnum].target_sizecxx . . $ vclip#target_size. = texture_size;
442
443 if (pageable == 1)
444 return vcnum;
445
446 PageInVClipcxx . . $ PageInVClip(d4f767463ce0a6b3).(vcnum);
447
448 if (GameVClipscxx . . $ GameVClips.[vcnum].num_framescxx . . $ vclip#num_frames. < 1) {
449 FreeVClipcxx . . $ FreeVClip(d4f767463ce0a6b3).(vcnum);
450 return -1;
451 }
452
453 return vcnum;
454 }
455
456 // Allocs and loads a vclip from a 3DS ILS file
457 // Returns -1 on error, else index into GameVClips on success
458 // Argument texture means that this vclip is an animated texture and
459 // needs to have an 8bit version
460 int AllocLoadIFLVClipcxx . . $ AllocLoadIFLVClip(c0ca7c05705093b).(const char *filename, int texture_size, int mipped, int format) {
461 CFILEcxx . . $ CFILE# *infile;
462 char name[PAGENAME_LENcxx . . $ `lib/manage_external.h:49:9`!];
463 uint32_tcxx . . $ uint32_t# i, done = 0;
464
465 ASSERTcxx . . $ `misc/pserror.h:246:9`!(filename != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
466
467 ChangeVClipNamecxx . . $ ChangeVClipName(611124a97efc52dd).(filename, name);
468
469 // Check to see if this vclip already exists in memory
470 if ((i = FindVClipNamecxx . . $ FindVClipName(5c4306d8553b3696).(IGNORE_TABLEcxx . . $ `lib/manage_external.h:54:9`!(name))) != -1) {
471 GameVClipscxx . . $ GameVClips.[i].usedcxx . . $ vclip#used.++;
472 return i;
473 }
474
475 infile = (CFILEcxx . . $ CFILE# *)cfopencxx . . $ cfopen(7c7b94e455f1ae56).(filenamecxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d)., "rt");
476 if (!infile) {
477 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Couldn't load IFL vclip %s!\n", filename);
478 return -1;
479 }
480
481 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Loading IFL vclip %s\n", name);
482
483 int vcnum = AllocVClipcxx . . $ AllocVClip(b126dc7c1de90089).();
484
485 ASSERTcxx . . $ `misc/pserror.h:246:9`!(vcnum >= 0);
486
487 vclipcxx . . $ vclip# *vc = &GameVClipscxx . . $ GameVClips.[vcnum];
488
489 while (!done) {
490 char curline[200];
491
492 if (cfeofcxx . . $ cfeof(413716a422df0036).(infile)) {
493 done = 1;
494 continue;
495 }
496
497 // Read a line and parse it
498 cf_ReadStringcxx . . $ cf_ReadString(38cd788e4423eff6).(curline, 200, infile);
499
500 if (curline[0] == ';' || curline[1] == ';' || curline[0] == ' ' || curline[1] == ' ')
501 continue;
502 if (!(isalnum(curline[0])))
503 continue;
504
505 else if (curline[0] == '$') {
506 char new_command[50];
507
508 int i;
509 for (i = 0; curline[i + 1] != '=' && i < 50; i++) {
510 new_command[i] = curline[i + 1];
511 }
512 if (i == 50) {
513 Int3cxx . . $ `misc/pserror.h:247:9`!(); // bad command in IFL!
514 return -1;
515 }
516
517 i++; // advance to data
518
519 // parse data
520 if (!stricmpcxx . . $ `linux/linux_fix.h:43:9`!(new_command, "TIME")) {
521 // Set play time
522 float play_time = atof(&curline[i]);
523 ASSERTcxx . . $ `misc/pserror.h:246:9`!(play_time >= 0);
524 }
525 } else {
526 int lastslash = -1;
527 char bmname[200];
528
529 for (i = 0; i < strlen(curline); i++)
530 if (curline[i] == '\\')
531 lastslash = i;
532
533 if (lastslash == -1) {
534 for (i = 0; i < strlen(filename); i++)
535 if (filename[i] == '\\')
536 lastslash = i;
537
538 ASSERTcxx . . $ `misc/pserror.h:246:9`!(lastslash != -1);
539
540 strcpy(bmname, filename);
541 bmname[lastslash + 1] = 0;
542 strcat(bmname, curline);
543 } else
544 strcpy(bmname, curline);
545
546 // Try and load this file
547
548 int bm = bm_AllocLoadFileBitmapcxx . . $ bm_AllocLoadFileBitmap(1163be050dbfff7).(IGNORE_TABLEcxx . . $ `lib/manage_external.h:54:9`!(bmname), 0, format);
549 if (bm < 1) {
550 Errorcxx . . $ Error(326aeb464d16410c).("Error loading frame %d of ILS file %s!\n", vc->num_framescxx . . $ vclip#num_frames., filename);
551 cfclosecxx . . $ cfclose(3639e799710acb68).(infile);
552 return -1;
553 }
554
555 int w, h;
556
557 if (texture_size == NORMAL_TEXTUREcxx . . $ `Descent3/gametexture.h:239:9`!) {
558 w = TEXTURE_WIDTHcxx . . $ `lib/renderer.h:308:9`!;
559 h = TEXTURE_HEIGHTcxx . . $ `lib/renderer.h:309:9`!;
560 } else if (texture_size == SMALL_TEXTUREcxx . . $ `Descent3/gametexture.h:240:9`!) {
561 // Make small textures a quarter of the size of normal textures
562 w = TEXTURE_WIDTHcxx . . $ `lib/renderer.h:308:9`! / 2;
563 h = TEXTURE_HEIGHTcxx . . $ `lib/renderer.h:309:9`! / 2;
564 } else if (texture_size == TINY_TEXTUREcxx . . $ `Descent3/gametexture.h:241:9`!) {
565 // Make these tinys an eigth of the size of normal textures
566 w = TEXTURE_WIDTHcxx . . $ `lib/renderer.h:308:9`! / 4;
567 h = TEXTURE_HEIGHTcxx . . $ `lib/renderer.h:309:9`! / 4;
568 } else {
569 w = bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(bm, 0);
570 h = bm_hcxx . . $ bm_h(9b79fb6aee4c0440).(bm, 0);
571 }
572
573 // If differing size, resize!
574 if (w != bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(bm, 0) || h != bm_hcxx . . $ bm_h(9b79fb6aee4c0440).(bm, 0)) {
575 int dest_bm;
576
577 dest_bm = bm_AllocBitmapcxx . . $ bm_AllocBitmap(2326284602b0bb2d).(w, h, mipped * ((w * h) / 3));
578 ASSERTcxx . . $ `misc/pserror.h:246:9`!(dest_bm >= 0);
579 if (mipped)
580 GameBitmapscxx . . $ GameBitmaps.[dest_bm].flagscxx . . $ bms_bitmap#flags. |= BF_MIPMAPPEDcxx . . $ `lib/bitmap.h:47:9`!;
581 GameBitmapscxx . . $ GameBitmaps.[dest_bm].formatcxx . . $ bms_bitmap#format. = GameBitmapscxx . . $ GameBitmaps.[bm].formatcxx . . $ bms_bitmap#format.;
582
583 bm_ScaleBitmapToBitmapcxx . . $ bm_ScaleBitmapToBitmap(3e454b8ccf442868).(dest_bm, bm);
584 strcpy(GameBitmapscxx . . $ GameBitmaps.[dest_bm].namecxx . . $ bms_bitmap#name., GameBitmapscxx . . $ GameBitmaps.[bm].namecxx . . $ bms_bitmap#name.);
585 bm_FreeBitmapcxx . . $ bm_FreeBitmap(d4f767463ce0a6b3).(bm);
586
587 bm = dest_bm;
588 }
589
590 vc->framescxx . . $ vclip#frames.[vc->num_framescxx . . $ vclip#num_frames.] = bm;
591 vc->num_framescxx . . $ vclip#num_frames.++;
592 }
593 }
594
595 cfclosecxx . . $ cfclose(3639e799710acb68).(infile);
596
597 if (vc->num_framescxx . . $ vclip#num_frames. == 0) {
598 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "vclip had no valid bitmap names!\n");
599 FreeVClipcxx . . $ FreeVClip(d4f767463ce0a6b3).(vcnum);
600 return -1;
601 }
602
603 strcpy(vc->namecxx . . $ vclip#name., name);
604 return vcnum;
605 }
606
607 // gets the filename from a path, plus appends our .oaf extension
608 void ChangeVClipNamecxx . . $ ChangeVClipName(611124a97efc52dd).(const char *src, char *dest) {
609 int limit;
610 char path[256], ext[256], filename[256];
611
612 limit = PAGENAME_LENcxx . . $ `lib/manage_external.h:49:9`! - 5;
613
614 ddio_SplitPathcxx . . $ ddio_SplitPath(b05ba7ab99603c07).(src, path, filename, ext);
615
616 // Make sure we don't go over our name length limit
617 strncpy(dest, filename, limit);
618
619 strcat(dest, ".oaf");
620 }
621 // Searches thru all vclips for a specific name, returns -1 if not found
622 // or index of vclip with name
623 int FindVClipNamecxx . . $ FindVClipName(5c4306d8553b3696).(const char *name) {
624 int i;
625
626 for (i = 0; i < MAX_VCLIPScxx . . $ `Descent3/vclip.h:28:9`!; i++)
627 if (GameVClipscxx . . $ GameVClips.[i].usedcxx . . $ vclip#used. && !stricmpcxx . . $ `linux/linux_fix.h:43:9`!(GameVClips[i].name, name))
628 return i;
629
630 return -1;
631 }