Debian Codegraph @

manage/texpage.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/manage/texpage.cpp $
21 * $Revision: 61 $
22 * $Date: 10/08/01 4:20p $
23 * $Author: Matt $
24 *
25 * For loading/saving of texture types
26 *
27 * $Log: /DescentIII/Main/manage/texpage.cpp $
28 *
29 * 61 10/08/01 4:20p Matt
30 * Added system to check for errors when reading in add-on data.
31 *
32 * 59 9/06/01 10:32a Matt
33 * Added code to fix problem poping add-on pages when the original pages
34 * were in the extra.gam file.
35 *
36 * 58 3/20/00 12:28p Matt
37 * Merge of Duane's post-1.3 changes.
38 * Added malloc for temp struct instead of delcaring on the stack.
39 *
40 * 57 10/26/99 3:31p Jeff
41 * handle extra.gam addon tablefile
42 *
43 * 56 9/18/99 8:49p Jeff
44 * fixed bug with addon pages that have dependencies on other pages in the
45 * addon tablefile
46 *
47 * 55 8/11/99 5:32p Jeff
48 * changes to fix addon tablefile support so it works correctly
49 *
50 * 54 5/21/99 6:39a Matt
51 * Fixed massive evil caused by recent changes for Mac, which resulted in
52 * two functions using the same static data at the same time.
53 *
54 * 53 5/14/99 12:07p Jeff
55 * error handling (Jason)
56 *
57 * 52 5/13/99 8:36p Matt
58 * Made some local variables global to get around the 32K local variable
59 * limit on the Mac.
60 *
61 * 51 4/14/99 1:34a Jeff
62 * fixed case mismatched #includes
63 *
64 * 50 4/12/99 3:05p Jason
65 * changes for 256 textures
66 *
67 * 49 4/09/99 7:04p Jason
68 * changed some texture defines
69 *
70 * 48 4/09/99 12:51p Jason
71 * corrected buggy sound resolving code
72 *
73 * 47 3/30/99 6:01p Jason
74 * added new procedural effect
75 *
76 * 46 2/20/99 2:17p Matt
77 * Added texture sounds
78 *
79 * 45 2/16/99 11:17a Jason
80 * took out mprintf
81 *
82 * 44 2/01/99 11:47a Jason
83 * fixed bumpmap errors
84 *
85 * 43 1/22/99 3:59p Jason
86 * added 256x256 textures to help with terrain skies
87 *
88 * 42 1/13/99 7:05a Jeff
89 * put #ifdef around #include <windows.h>
90 *
91 * 41 12/29/98 4:30p Jason
92 * added add-on data functionality
93 *
94 * 40 12/17/98 12:02p Jason
95 * fixed dumb procedural thing
96 *
97 * 39 11/06/98 12:35p Jason
98 * more speedups for manage system
99 *
100 * 38 11/05/98 7:55p Jason
101 * changes for new manage system
102 *
103 * 37 11/02/98 6:02p Jason
104 * made yes network updates much faster
105 *
106 * 36 10/09/98 2:27p Jason
107 * reorganized table file system
108 *
109 * 35 10/08/98 10:03p Jason
110 * more filtered table file stuff
111 *
112 * 34 10/07/98 5:03p Jason
113 * more options for textures
114 *
115 * 33 10/01/98 2:47p Jason
116 * added timed procedurals
117 *
118 * 32 8/24/98 2:37p Jason
119 * made table file more efficient with regards to invalid names
120 *
121 * 31 8/15/98 3:46p Matt
122 * Got rid of compile warning
123 *
124 * 30 8/13/98 1:03p Jason
125 * added some more procedural workers
126 *
127 * 29 8/12/98 4:24p Luke
128 * temporary fix for dumb local table file conundrum
129 *
130 * 28 7/14/98 6:50p Jason
131 * made procedurals save out to the table file
132 *
133 * 27 6/12/98 1:06p Jason
134 * added smart loading from local table file
135 *
136 * 26 6/11/98 12:54p Mark
137 * temp fix
138 *
139 * 25 6/10/98 12:21p Matt
140 * Revamped system that controls what textures are displayed on the
141 * texture tab. Should work correctly now, and will now save the settings
142 * to the registry. Also, textures now default to no type set, not all
143 * types set.
144 *
145 * 24 6/03/98 3:46p Jason
146 * made megacell system more robust
147 *
148 * 23 5/20/98 1:08p Jason
149 * more stuff for adding bumpmaps
150 *
151 * 22 5/04/98 6:08p Jason
152 * sped up predictive pagefile loading
153 *
154 * 21 4/06/98 4:42p Jason
155 * added texture alpha change
156 *
157 * 20 3/17/98 4:33p Jason
158 * Added size changing to bitmaps/textures
159 *
160 * 19 2/23/98 1:22p Jason
161 * made FindSpecific* read from the local drive, not the net drive - when
162 * starting the editor
163 *
164 * 18 2/16/98 11:42a Jason
165 * added better error checking for checking out files
166 *
167 * 17 2/12/98 1:32p Jason
168 * got mipmapping working
169 *
170 * 16 1/14/98 7:55p Jason
171 * make textures pageable depending on whether or not you're using the
172 * network
173 *
174 * 15 12/19/97 2:46p Jason
175 * implemented bitmap paging routines
176 *
177 * 14 12/10/97 5:29p Jason
178 * warn if reusing a net texture
179 *
180 * 13 11/21/97 2:02p Jason
181 * made light textures on model render that model face fully bright
182 *
183 * 12 10/20/97 5:05p Mark
184 * FROM JASON: Changed error bitmap from -1 to 0
185 *
186 * 11 10/15/97 5:20p Jason
187 * did a HUGE overhaul of the bitmap system
188 *
189 * 10 9/25/97 4:30p Jason
190 * got destroyable textures working
191 *
192 * 9 8/19/97 1:21p Jason
193 * set reflectivity to .5 by default
194 *
195 * 8 8/19/97 1:57a Jason
196 * made rgb lighting take floats
197 *
198 * 7 8/12/97 1:10a Jason
199 * added code to support radiosity lighting
200 *
201 * 6 8/08/97 12:59p Jason
202 * got texture sliding and pingponging working
203 *
204 * 5 8/06/97 2:57p Jason
205 * fixed alpha problem with reorder net pages
206 *
207 * 4 8/04/97 5:05p Jason
208 * fixed dumb off-by-one error
209 *
210 * 3 8/04/97 3:28p Jason
211 * added alpha blending per texture
212 *
213 * 31 6/24/97 12:42p Jason
214 * checked in for safety
215 *
216 * 30 6/06/97 3:57p Jason
217 * implemented changes for small textures and automatic tmap2 recognition
218 *
219 * 29 6/05/97 2:52p Jason
220 * added megacell functions
221 *
222 * 28 5/30/97 5:46p Jason
223 * added colored light functionality on a vertex level
224 *
225 * 27 5/23/97 7:07p Matt
226 * Added code, data, & dialogs to keep track of what a texture is used for
227 * (mine, terrain, object) so we can display in the texture dialog only
228 * the ones we're interested in.
229 *
230 * 26 5/12/97 1:19p Jason
231 * sped up texture loading a little bit
232 *
233 * 25 5/12/97 11:41a Jason
234 * made game work (default) to 16bit no mip maps mode
235 * Saves us alot of memory
236 *
237 * 24 5/08/97 12:41p Jason
238 * made manage system work with device dependant path names
239 *
240 * 23 4/25/97 6:16p Jason
241 * added switcheroo function
242 *
243 * 22 4/08/97 2:25a Chris
244 * Fixed a problem with uninitialized data. In addition it
245 * fixed a problem with the .used flag that would happen
246 * 1 out of 2^(sizeof(used_flag)) times (it would be zero
247 * when it was supposed to be non-zero)
248 *
249 * 21 3/12/97 6:15 PM Jeremy
250 * in mng_WriteTexturePage moved the declaration of int i outside of the
251 * first for loop to the top of the function so that it will compile on
252 * mac and PC at the same time. :)
253 *
254 * 20 3/03/97 6:21p Matt
255 * Changed cfile functions to use D3 naming convention
256 *
257 * $NoKeywords: $
258 */
259
260 #include <cstring>
261 #include <filesystem>
262
263 #include "cfile.h"
264 #include "manage.h"
265 #include "gametexture.h"
266 #include "bitmap.h"
267 #include "mono.h"
268 #include "pserror.h"
269 #include "texpage.h"
270 #include "vclip.h"
271 #include "ddio.h"
272 #include "args.h"
273 #include "sounds.h"
274 #include "soundpage.h"
275 #include "soundload.h"
276
277 // Texpage commands that are read/written
278 // A command is followed by a byte count describing how many bytes
279 // are in the data for the command
280 #define TEXPAGE_COMMAND_NAME 1
281 #define TEXPAGE_COMMAND_FLAGS 2
282 #define TEXPAGE_COMMAND_END 3
283 #define TEXPAGE_COMMAND_BITMAP_NAME 4
284 #define TEXPAGE_COMMAND_DESTROY_NAME 5
285 #define TEXPAGE_COMMAND_VERSION 6
286 #define TEXPAGE_COMMAND_REFLECT 7
287 #define TEXPAGE_COMMAND_DAMAGE 8
288 #define TEXPAGE_COMMAND_LIGHTING 9
289 #define TEXPAGE_COMMAND_SLIDE 10
290 #define TEXPAGE_COMMAND_NULL_NAME 11 // null terminated name string
291 #define TEXPAGE_COMMAND_BITMAP_NULL_NAME 12
292 #define TEXPAGE_COMMAND_DESTROY_NULL_NAME 13
293 #define TEXPAGE_COMMAND_COLORED_LIGHTING 14
294 #define TEXPAGE_COMMAND_ALPHA 15
295 #define TEXPAGE_COMMAND_SLIDE_FLOAT 16
296 #define TEXPAGE_COMMAND_LIGHTING_FLOAT 17
297 #define TEXPAGE_COMMAND_SPEED 18
298 #define TEXPAGE_COMMAND_FIRST_PROC_PAL 19
299 #define TEXPAGE_COMMAND_SECOND_PROC_PAL 20
300 #define TEXPAGE_COMMAND_PROCEDURAL 21
301 #define TEXPAGE_COMMAND_EXTRA_PROCEDURAL 22
302 #define TEXPAGE_COMMAND_EXTRA_PROCEDURAL2 23
303 #define TEXPAGE_COMMAND_CORONA 24
304
305 // Declare this here because it's too big to put on the stack on the Mac
306 static mngs_texture_page texpage1;
307
308 extern char *TablefileNameOverride;
309
310 #define TEXPAGE_VERSION 7
311 // Given an open file pointer and a texture handle, writes that texture page out
312 void mng_WriteTexturePage(CFILE *outfile, mngs_texture_page *texpage) {
313 int i = 0;
314
315 ASSERT(outfile != NULL);
316 ASSERT(texpage != NULL);
317
318 cf_WriteByte(outfile, PAGETYPE_TEXTURE);
319
320 cf_WriteByte(outfile, TEXPAGE_COMMAND_VERSION);
321 cf_WriteByte(outfile, 1);
322 cf_WriteByte(outfile, TEXPAGE_VERSION);
323
324 // Write out texture name
325 cf_WriteByte(outfile, TEXPAGE_COMMAND_NULL_NAME);
326 cf_WriteByte(outfile, strlen(texpage->tex_struct.name) + 1);
327 cf_WriteString(outfile, texpage->tex_struct.name);
328
329 // Write out its bitmaps name
330 cf_WriteByte(outfile, TEXPAGE_COMMAND_BITMAP_NULL_NAME); // get ready to write out name
331 cf_WriteByte(outfile, strlen(texpage->bitmap_name) + 1);
332 cf_WriteString(outfile, texpage->bitmap_name);
333
334 // Write out its bitmaps name
335 cf_WriteByte(outfile, TEXPAGE_COMMAND_DESTROY_NULL_NAME); // get ready to write out name
336 cf_WriteByte(outfile, strlen(texpage->destroy_name) + 1);
337 cf_WriteString(outfile, texpage->destroy_name);
338
339 cf_WriteByte(outfile, TEXPAGE_COMMAND_LIGHTING_FLOAT);
340 cf_WriteByte(outfile, 4 * 3);
341 cf_WriteFloat(outfile, texpage->tex_struct.r);
342 cf_WriteFloat(outfile, texpage->tex_struct.g);
343 cf_WriteFloat(outfile, texpage->tex_struct.b);
344
345 cf_WriteByte(outfile, TEXPAGE_COMMAND_ALPHA);
346 cf_WriteByte(outfile, 4);
347 cf_WriteFloat(outfile, texpage->tex_struct.alpha);
348
349 cf_WriteByte(outfile, TEXPAGE_COMMAND_SPEED);
350 cf_WriteByte(outfile, 4);
351 cf_WriteFloat(outfile, texpage->tex_struct.speed);
352
353 cf_WriteByte(outfile, TEXPAGE_COMMAND_SLIDE_FLOAT);
354 cf_WriteByte(outfile, 8);
355 cf_WriteFloat(outfile, texpage->tex_struct.slide_u);
356 cf_WriteFloat(outfile, texpage->tex_struct.slide_v);
357
358 cf_WriteByte(outfile, TEXPAGE_COMMAND_REFLECT);
359 cf_WriteByte(outfile, 4);
360 cf_WriteFloat(outfile, texpage->tex_struct.reflectivity);
361
362 cf_WriteByte(outfile, TEXPAGE_COMMAND_CORONA);
363 cf_WriteByte(outfile, 1);
364 cf_WriteByte(outfile, texpage->tex_struct.corona_type);
365
366 cf_WriteByte(outfile, TEXPAGE_COMMAND_DAMAGE);
367 cf_WriteByte(outfile, 4);
368 cf_WriteInt(outfile, texpage->tex_struct.damage);
369
370 cf_WriteByte(outfile, TEXPAGE_COMMAND_FLAGS); // write out flags field
371 cf_WriteByte(outfile, 4);
372 cf_WriteInt(outfile, texpage->tex_struct.flags);
373
374 // Write out the procedural
375 if (texpage->tex_struct.flags & TF_PROCEDURAL) {
376 // Write out the palette in two halves
377 cf_WriteByte(outfile, TEXPAGE_COMMAND_FIRST_PROC_PAL);
378 cf_WriteByte(outfile, (uint8_t)255);
379 for (i = 0; i < 255; i++) {
380 uint16_t val = texpage->proc_palette[i];
381 val >>= 8;
382
383 cf_WriteByte(outfile, val);
384 }
385
386 cf_WriteByte(outfile, TEXPAGE_COMMAND_SECOND_PROC_PAL);
387 cf_WriteByte(outfile, (uint8_t)255);
388 for (i = 0; i < 255; i++) {
389 uint16_t val = texpage->proc_palette[i];
390 val &= 0xFF;
391
392 cf_WriteByte(outfile, val);
393 }
394
395 cf_WriteByte(outfile, TEXPAGE_COMMAND_EXTRA_PROCEDURAL);
396 cf_WriteByte(outfile, 3);
397 cf_WriteByte(outfile, texpage->proc_heat);
398 cf_WriteByte(outfile, texpage->proc_light);
399 cf_WriteByte(outfile, texpage->proc_thickness);
400
401 cf_WriteByte(outfile, TEXPAGE_COMMAND_EXTRA_PROCEDURAL2);
402 cf_WriteByte(outfile, 4);
403 cf_WriteFloat(outfile, texpage->proc_evaluation_time);
404
405 // Write out static procedural
406 for (i = 0; i < texpage->num_proc_elements; i++) {
407 cf_WriteByte(outfile, TEXPAGE_COMMAND_PROCEDURAL);
408
409 cf_WriteByte(outfile, 8);
410
411 cf_WriteByte(outfile, texpage->proc_type[i]);
412 cf_WriteByte(outfile, texpage->proc_frequency[i]);
413 cf_WriteByte(outfile, texpage->proc_speed[i]);
414 cf_WriteByte(outfile, texpage->proc_size[i]);
415
416 cf_WriteByte(outfile, texpage->proc_x1[i]);
417 cf_WriteByte(outfile, texpage->proc_y1[i]);
418
419 cf_WriteByte(outfile, texpage->proc_x2[i]);
420 cf_WriteByte(outfile, texpage->proc_y2[i]);
421 }
422 }
423
424 cf_WriteByte(outfile, TEXPAGE_COMMAND_END); // we're all done
425 cf_WriteByte(outfile, 0);
426 }
427
428 // Given an open file pointer and a texture handle, writes that texture page out
429 void mng_WriteNewTexturePage(CFILE *outfile, mngs_texture_page *texpage) {
430 int i = 0;
431
432 ASSERT(outfile != NULL);
433 ASSERT(texpage != NULL);
434
435 int offset = StartManagePage(outfile, PAGETYPE_TEXTURE);
436
437 cf_WriteShort(outfile, TEXPAGE_VERSION);
438 cf_WriteString(outfile, texpage->tex_struct.name);
439
440 // Write out its bitmaps name
441 cf_WriteString(outfile, texpage->bitmap_name);
442
443 // Write out destroy bitmap name
444 cf_WriteString(outfile, texpage->destroy_name);
445
446 // Write out rgb lighting and alpha
447 cf_WriteFloat(outfile, texpage->tex_struct.r);
448 cf_WriteFloat(outfile, texpage->tex_struct.g);
449 cf_WriteFloat(outfile, texpage->tex_struct.b);
450 cf_WriteFloat(outfile, texpage->tex_struct.alpha);
451
452 // Write out animation speed
453 cf_WriteFloat(outfile, texpage->tex_struct.speed);
454
455 // Write out sliding values
456 cf_WriteFloat(outfile, texpage->tex_struct.slide_u);
457 cf_WriteFloat(outfile, texpage->tex_struct.slide_v);
458
459 // Write reflectivity
460 cf_WriteFloat(outfile, texpage->tex_struct.reflectivity);
461
462 // Write corona type
463 cf_WriteByte(outfile, texpage->tex_struct.corona_type);
464
465 // Write damage
466 cf_WriteInt(outfile, texpage->tex_struct.damage);
467
468 // Write flags
469 cf_WriteInt(outfile, texpage->tex_struct.flags);
470
471 // Write out the procedural
472 if (texpage->tex_struct.flags & TF_PROCEDURAL) {
473 // Write procedural palette
474 for (i = 0; i < 255; i++) {
475 uint16_t val = texpage->proc_palette[i];
476 cf_WriteShort(outfile, val);
477 }
478
479 // Write procedural globals
480 cf_WriteByte(outfile, texpage->proc_heat);
481 cf_WriteByte(outfile, texpage->proc_light);
482 cf_WriteByte(outfile, texpage->proc_thickness);
483 cf_WriteFloat(outfile, texpage->proc_evaluation_time);
484
485 cf_WriteFloat(outfile, texpage->osc_time);
486 cf_WriteByte(outfile, texpage->osc_value);
487
488 // Write out static procedurals
489 cf_WriteShort(outfile, texpage->num_proc_elements);
490 for (i = 0; i < texpage->num_proc_elements; i++) {
491 cf_WriteByte(outfile, texpage->proc_type[i]);
492 cf_WriteByte(outfile, texpage->proc_frequency[i]);
493 cf_WriteByte(outfile, texpage->proc_speed[i]);
494 cf_WriteByte(outfile, texpage->proc_size[i]);
495 cf_WriteByte(outfile, texpage->proc_x1[i]);
496 cf_WriteByte(outfile, texpage->proc_y1[i]);
497 cf_WriteByte(outfile, texpage->proc_x2[i]);
498 cf_WriteByte(outfile, texpage->proc_y2[i]);
499 }
500 }
501
502 cf_WriteString(outfile, texpage->sound_name);
503 cf_WriteFloat(outfile, texpage->tex_struct.sound_volume);
504
505 EndManagePage(outfile, offset);
506 }
507
508 void mng_InitTexturePage(mngs_texture_page *texpage) {
509 memset(texpage, 0, sizeof(mngs_texture_page));
510 texpage->proc_thickness = 4;
511 texpage->proc_heat = 200;
512 texpage->proc_light = 1;
513 texpage->num_proc_elements = 0;
514 texpage->proc_evaluation_time = 0;
515 texpage->osc_time = 0;
516 texpage->osc_value = 8;
517
518 texpage->tex_struct.alpha = 1.0;
519 texpage->tex_struct.speed = 1.0;
520 texpage->tex_struct.reflectivity = .5;
521 texpage->tex_struct.corona_type = 0;
522 texpage->tex_struct.slide_v = 0;
523 texpage->tex_struct.slide_u = 0;
524 texpage->tex_struct.bumpmap = -1;
525 texpage->tex_struct.sound = -1;
526 texpage->tex_struct.sound_volume = 1.0;
527
528 strcpy(texpage->bitmap_name, "");
529 strcpy(texpage->destroy_name, "");
530 strcpy(texpage->sound_name, "");
531 }
532
533 // Reads a texture page from an open file. Returns 0 on error.
534 int mng_ReadTexturePage(CFILE *infile, mngs_texture_page *texpage) {
535 int done = 0;
536 char command;
537 uint8_t len;
538 int i;
539 int proc_index = 0;
540
541 if (!Old_table_method)
542 return mng_ReadNewTexturePage(infile, texpage);
543
544 ASSERT(infile != NULL);
545 mng_InitTexturePage(texpage);
546
547 while (!done) {
548 command = cf_ReadByte(infile);
549 len = cf_ReadByte(infile);
550
551 switch (command) {
552 case TEXPAGE_COMMAND_END:
553 done = 1;
554 break;
555 case TEXPAGE_COMMAND_FLAGS:
556 texpage->tex_struct.flags = cf_ReadInt(infile);
557 break;
558 case TEXPAGE_COMMAND_LIGHTING:
559 cf_ReadInt(infile); // Ignored
560 break;
561 case TEXPAGE_COMMAND_LIGHTING_FLOAT:
562 texpage->tex_struct.r = cf_ReadFloat(infile);
563 texpage->tex_struct.g = cf_ReadFloat(infile);
564 texpage->tex_struct.b = cf_ReadFloat(infile);
565 break;
566 case TEXPAGE_COMMAND_DAMAGE:
567 texpage->tex_struct.damage = cf_ReadInt(infile);
568 break;
569 case TEXPAGE_COMMAND_REFLECT:
570 texpage->tex_struct.reflectivity = cf_ReadFloat(infile);
571 break;
572 case TEXPAGE_COMMAND_CORONA:
573 texpage->tex_struct.corona_type = cf_ReadByte(infile);
574 break;
575 case TEXPAGE_COMMAND_ALPHA:
576 texpage->tex_struct.alpha = cf_ReadFloat(infile);
577 break;
578 case TEXPAGE_COMMAND_SPEED:
579 texpage->tex_struct.speed = cf_ReadFloat(infile);
580 break;
581 case TEXPAGE_COMMAND_SLIDE_FLOAT:
582 texpage->tex_struct.slide_u = cf_ReadFloat(infile);
583 texpage->tex_struct.slide_v = cf_ReadFloat(infile);
584 break;
585 case TEXPAGE_COMMAND_BITMAP_NAME: // the name of the texture's bitmap
586 for (i = 0; i < BITMAP_NAME_LEN; i++)
587 texpage->bitmap_name[i] = cf_ReadByte(infile);
588 break;
589 case TEXPAGE_COMMAND_DESTROY_NAME: // the name of the texture's bitmap
590 for (i = 0; i < BITMAP_NAME_LEN; i++)
591 texpage->destroy_name[i] = cf_ReadByte(infile);
592 break;
593 case TEXPAGE_COMMAND_NAME:
594 for (i = 0; i < PAGENAME_LEN; i++)
595 texpage->tex_struct.name[i] = cf_ReadByte(infile);
596 break;
597 case TEXPAGE_COMMAND_NULL_NAME:
598 cf_ReadString(texpage->tex_struct.name, PAGENAME_LEN, infile);
599 break;
600 case TEXPAGE_COMMAND_BITMAP_NULL_NAME: // the name of the texture's bitmap
601 cf_ReadString(texpage->bitmap_name, PAGENAME_LEN, infile);
602 break;
603 case TEXPAGE_COMMAND_DESTROY_NULL_NAME: // the name of the texture's bitmap
604 cf_ReadString(texpage->destroy_name, PAGENAME_LEN, infile);
605 break;
606 case TEXPAGE_COMMAND_FIRST_PROC_PAL:
607 for (i = 0; i < 255; i++) {
608 uint16_t val = cf_ReadByte(infile);
609 val <<= 8;
610 texpage->proc_palette[i] &= 0xFF;
611 texpage->proc_palette[i] |= val;
612 }
613 break;
614 case TEXPAGE_COMMAND_SECOND_PROC_PAL:
615 for (i = 0; i < 255; i++) {
616 uint8_t val = cf_ReadByte(infile);
617 texpage->proc_palette[i] &= 0xFF00;
618 texpage->proc_palette[i] |= val;
619 }
620 break;
621 case TEXPAGE_COMMAND_EXTRA_PROCEDURAL:
622 texpage->proc_heat = cf_ReadByte(infile);
623 texpage->proc_light = cf_ReadByte(infile);
624 texpage->proc_thickness = cf_ReadByte(infile);
625 break;
626 case TEXPAGE_COMMAND_EXTRA_PROCEDURAL2:
627 texpage->proc_evaluation_time = cf_ReadFloat(infile);
628 break;
629 case TEXPAGE_COMMAND_PROCEDURAL:
630 texpage->proc_type[proc_index] = cf_ReadByte(infile);
631 texpage->proc_frequency[proc_index] = cf_ReadByte(infile);
632 texpage->proc_speed[proc_index] = cf_ReadByte(infile);
633 texpage->proc_size[proc_index] = cf_ReadByte(infile);
634 texpage->proc_x1[proc_index] = cf_ReadByte(infile);
635 texpage->proc_y1[proc_index] = cf_ReadByte(infile);
636
637 texpage->proc_x2[proc_index] = cf_ReadByte(infile);
638 texpage->proc_y2[proc_index] = cf_ReadByte(infile);
639
640 proc_index++;
641 break;
642 default:
643 for (i = 0; i < len; i++)
644 cf_ReadByte(infile);
645 break;
646 }
647 }
648
649 // Jason hack
650 if (texpage->tex_struct.alpha < .9999)
651 texpage->tex_struct.flags |= TF_ALPHA;
652 else
653 texpage->tex_struct.flags &= ~TF_ALPHA;
654
655 texpage->num_proc_elements = proc_index;
656
657 if (texpage->num_proc_elements == 0)
658 texpage->tex_struct.flags &= ~TF_PROCEDURAL;
659
660 if (!strnicmp(texpage->destroy_name, "INVALID", 7))
661 strcpy(texpage->destroy_name, "");
662
663 texpage->tex_struct.used = 1;
664
665 return 1; // successfully read
666 }
667
668 // Reads a texture page from an open file. Returns 0 on error.
669 int mng_ReadNewTexturePage(CFILE *infile, mngs_texture_page *texpage) {
670 int i;
671
672 ASSERT(infile != NULL);
673 mng_InitTexturePage(texpage);
674
675 int version = cf_ReadShort(infile);
676
677 cf_ReadString(texpage->tex_struct.name, PAGENAME_LEN, infile);
678 cf_ReadString(texpage->bitmap_name, PAGENAME_LEN, infile);
679 cf_ReadString(texpage->destroy_name, PAGENAME_LEN, infile);
680
681 texpage->tex_struct.r = cf_ReadFloat(infile);
682 texpage->tex_struct.g = cf_ReadFloat(infile);
683 texpage->tex_struct.b = cf_ReadFloat(infile);
684 texpage->tex_struct.alpha = cf_ReadFloat(infile);
685
686 texpage->tex_struct.speed = cf_ReadFloat(infile);
687
688 texpage->tex_struct.slide_u = cf_ReadFloat(infile);
689 texpage->tex_struct.slide_v = cf_ReadFloat(infile);
690 texpage->tex_struct.reflectivity = cf_ReadFloat(infile);
691
692 texpage->tex_struct.corona_type = cf_ReadByte(infile);
693 texpage->tex_struct.damage = cf_ReadInt(infile);
694 texpage->tex_struct.flags = cf_ReadInt(infile);
695
696 if (texpage->tex_struct.flags & TF_PROCEDURAL) {
697 for (i = 0; i < 255; i++) {
698 uint16_t val = cf_ReadShort(infile);
699 texpage->proc_palette[i] = val;
700 }
701
702 texpage->proc_heat = cf_ReadByte(infile);
703 texpage->proc_light = cf_ReadByte(infile);
704 texpage->proc_thickness = cf_ReadByte(infile);
705 texpage->proc_evaluation_time = cf_ReadFloat(infile);
706
707 if (version >= 6) {
708 texpage->osc_time = cf_ReadFloat(infile);
709 texpage->osc_value = cf_ReadByte(infile);
710 }
711
712 texpage->num_proc_elements = cf_ReadShort(infile);
713
714 if (texpage->num_proc_elements > MAX_PROC_ELEMENTS) {
715 mprintf(0, "Warning! Too many procedural elements!\n");
716 Int3();
717 }
718
719 for (i = 0; i < texpage->num_proc_elements; i++) {
720 texpage->proc_type[i] = cf_ReadByte(infile);
721 texpage->proc_frequency[i] = cf_ReadByte(infile);
722 texpage->proc_speed[i] = cf_ReadByte(infile);
723 texpage->proc_size[i] = cf_ReadByte(infile);
724 texpage->proc_x1[i] = cf_ReadByte(infile);
725 texpage->proc_y1[i] = cf_ReadByte(infile);
726
727 texpage->proc_x2[i] = cf_ReadByte(infile);
728 texpage->proc_y2[i] = cf_ReadByte(infile);
729 }
730 }
731
732 if (texpage->tex_struct.flags & TF_PROCEDURAL) {
733 if (texpage->num_proc_elements == 0)
734 texpage->tex_struct.flags &= ~TF_PROCEDURAL;
735 }
736
737 if (!strnicmp(texpage->destroy_name, "INVALID", 7))
738 strcpy(texpage->destroy_name, "");
739
740 if (version >= 5) {
741
742 if (version < 7) {
743 // Kill buggy version of sound resolving code
744 texpage->tex_struct.sound = cf_ReadInt(infile);
745 texpage->tex_struct.sound = -1;
746 strcpy(texpage->sound_name, "");
747 } else
748 cf_ReadString(texpage->sound_name, PAGENAME_LEN, infile);
749
750 texpage->tex_struct.sound_volume = cf_ReadFloat(infile);
751 } else {
752 texpage->tex_struct.sound = -1;
753 texpage->tex_struct.sound_volume = 1.0;
754 }
755
756 texpage->tex_struct.used = 1;
757
758 return 1; // successfully read
759 }
760
761 // Given some texture names, finds them in the table file and deletes them
762 // If local is 1, deletes from the local table file
763 int mng_DeleteTexPageSeries(char *names[], int num_textures, int local) {
764 CFILE *infile, *outfile;
765 uint8_t pagetype, replaced = 0;
766 int done = 0;
767 int deleted = 0;
768 memset(&texpage1, 0, sizeof(mngs_texture_page));
769
770 if (local)
771 infile = cfopen(LocalTableFilename, "rb");
772 else
773 infile = cfopen(TableFilename, "rb");
774
775 if (!infile) {
776 mprintf(0, "Couldn't open table file to delete texture!\n");
777 Int3();
778 return 0;
779 }
780
781 if (local)
782 outfile = cfopen(LocalTempTableFilename, "wb");
783 else
784 outfile = cfopen(TempTableFilename, "wb");
785
786 if (!outfile) {
787 mprintf(0, "Couldn't open temp table file to delete texture!\n");
788 cfclose(infile);
789 Int3();
790 return 0;
791 }
792
793 while (!done) {
794 if (cfeof(infile)) {
795 done = 1;
796 continue;
797 }
798 pagetype = cf_ReadByte(infile);
799 int len = cf_ReadInt(infile);
800
801 // If not a texture page, just read it in and write it right back out
802 if (pagetype != PAGETYPE_TEXTURE) {
803 mng_ReadWriteDummyPage(infile, outfile, pagetype);
804 continue;
805 }
806
807 mng_ReadNewTexturePage(infile, &texpage1);
808
809 int found = -1;
810 for (int i = 0; i < num_textures && found == -1; i++) {
811 if (!stricmp(names[i], texpage1.tex_struct.name)) {
812 found = i;
813 }
814 }
815
816 if (found == -1) // Not found
817 {
818 mng_WriteNewTexturePage(outfile, &texpage1);
819 } else
820 mprintf(0, "Deleting %s (%s).\n", names[found], local ? "locally" : "on network");
821 }
822
823 cfclose(infile);
824 cfclose(outfile);
825
826 // Now, remove our table file and rename the temp file to be the table file
827
828 if (local) {
829 if (!SwitcherooFiles(LocalTableFilename, LocalTempTableFilename))
830 return 0;
831 } else {
832 if (!SwitcherooFiles(TableFilename, TempTableFilename))
833 return 0;
834 }
835
836 return 1; // successful!
837 }
838
839 // Reads in the texpage named "name" into texpage struct
840 // Returns 0 on error or couldn't find, else 1 if all is good
841 int mng_FindSpecificTexPage(char *name, mngs_texture_page *texpage, int offset) {
842 CFILE *infile;
843 uint8_t pagetype;
844 int done = 0, found = 0;
845 int first_try = 1;
846 std::filesystem::path tablename;
847
848 if (Loading_locals) {
849 infile = cfopen(LocalTableFilename, "rb");
850 } else if (Loading_addon_table != -1) {
851 infile = cfopen(AddOnDataTables[Loading_addon_table].AddOnTableFilename, "rb");
852 } else {
853 if (Network_up && Starting_editor) {
854 int farg = FindArg("-filter");
855
856 if (farg)
857 tablename = GameArgs[farg + 1];
858 else
859 tablename = LocalTableDir / NET_TABLE;
860
861 infile = cfopen(tablename, "rb");
862 } else {
863 infile = NULL;
864 if (TablefileNameOverride) {
865 infile = cfopen(TablefileNameOverride, "rb");
866 }
867
868 if (!infile)
869 infile = cfopen(TableFilename, "rb");
870 }
871 }
872
873 if (!infile) {
874 mprintf(0, "Couldn't open table file to find texture!\n");
875 Int3();
876 return 0;
877 }
878
879 try_again:;
880 if (offset)
881 cfseek(infile, offset, SEEK_SET);
882
883 while (!done) {
884 if (cfeof(infile)) {
885 done = 1;
886 continue;
887 }
888 pagetype = cf_ReadByte(infile);
889 int len = cf_ReadInt(infile);
890
891 // If not a texture page, just read it in and ignore it
892 if (pagetype != PAGETYPE_TEXTURE) {
893 cfseek(infile, len - 4, SEEK_CUR);
894 continue;
895 }
896
897 mng_ReadNewTexturePage(infile, texpage);
898
899 if (!stricmp(name, texpage->tex_struct.name)) {
900 // This is the page we want
901 found = 1;
902 done = 1;
903 }
904 }
905
906 cfclose(infile);
907
908 if (!found && first_try) {
909 done = first_try = 0;
910 infile = cfopen("extra.gam", "rb");
911 if (infile)
912 goto try_again;
913 }
914
915 return found; // successful!
916 }
917
918 // Given a texture page, allocs a texture and calls AssignTexPageToTexture to actually
919 // load bitmaps and values. Rturns texture handle on success, -1 if fail
920 int mng_SetAndLoadTexture(mngs_texture_page *texpage, CFILE *infile) {
921 int n;
922
923 n = AllocTexture();
924 if (n < 0)
925 return -1;
926 if (!mng_AssignTexPageToTexture(texpage, n, infile))
927 return -1;
928
929 return n;
930 }
931
932 // extern char Texture256Names[][80];
933 // extern int Num_256s;
934 // Given a texpage and a texture handle, attempts to make texture n correspond to
935 // to the texpage.
936 // Returns 1 on success, 0 otherwise
937 int mng_AssignTexPageToTexture(mngs_texture_page *texpage, int n, CFILE *infile) {
938 texture *tex = &GameTextures[n];
939 int bm_handle;
940
941 // copy our values
942 memcpy(tex, &texpage->tex_struct, sizeof(texture));
943
944 // Check to see if this image differs from the one on the net
945 // If so, make a local copy
946 // If this is a release, don't do any of this stuff
947 #ifndef RELEASE
948 if (Network_up) {
949 UpdatePrimitive(LocalManageGraphicsDir / texpage->bitmap_name, ManageGraphicsDir / texpage->bitmap_name,
950 texpage->bitmap_name, PAGETYPE_TEXTURE, tex->name);
951 }
952 #endif
953
954 // Try and load our textures bitmaps from the disk
955 uint8_t pageable;
956 uint8_t mipped = 1;
957
958 if (Network_up)
959 pageable = 0;
960 else
961 pageable = 1;
962
963 pageable = 1;
964
965 /*int done=0;
966 for (int i=0;i<Num_256s && !done;i++)
967 {
968 if (!stricmp (Texture256Names[i],tex->name))
969 {
970 tex->flags&=~(TF_TEXTURE_64|TF_TEXTURE_32);
971 tex->flags|=TF_TEXTURE_256;
972 mprintf(0,"Found 256...%s\n",tex->name);
973 int len=strlen (texpage->bitmap_name);
974 texpage->bitmap_name[len-3]='t';
975 texpage->bitmap_name[len-2]='g';
976 texpage->bitmap_name[len-1]='a';
977
978 done=1;
979 }
980 }*/
981
982 if (tex->flags & TF_TEXTURE_64) {
983 bm_handle = LoadTextureImage(texpage->bitmap_name, NULL, SMALL_TEXTURE, mipped, pageable);
984 } else if (tex->flags & TF_TEXTURE_32) {
985 bm_handle = LoadTextureImage(texpage->bitmap_name, NULL, TINY_TEXTURE, mipped, pageable);
986 } else if (tex->flags & TF_TEXTURE_256) {
987 mipped = 0;
988 bm_handle = LoadTextureImage(texpage->bitmap_name, NULL, HUGE_TEXTURE, mipped, pageable);
989 } else
990 bm_handle = LoadTextureImage(texpage->bitmap_name, NULL, NORMAL_TEXTURE, mipped, pageable);
991
992 if (bm_handle < 0) {
993 mprintf(0, "Couldn't load bitmap '%s' in AssignTexPage...\n", texpage->bitmap_name);
994 tex->bm_handle = 0;
995 return 0;
996 } else
997 tex->bm_handle = bm_handle;
998
999 // Load the destroyed texture
1000 if (tex->flags & TF_DESTROYABLE) {
1001 // Are destroyed and non-destroyed the same?
1002 if (!(stricmp(texpage->destroy_name, tex->name))) {
1003 tex->flags &= ~TF_DESTROYABLE;
1004 tex->destroy_handle = -1;
1005 } else {
1006
1007 int destroy_handle = mng_GetGuaranteedTexturePage(texpage->destroy_name, infile);
1008 if (destroy_handle < 0)
1009 tex->destroy_handle = 0;
1010 else
1011 tex->destroy_handle = destroy_handle;
1012 }
1013 }
1014
1015 // Get sound if needed
1016 if (stricmp("", texpage->sound_name))
1017 tex->sound = mng_GetGuaranteedSoundPage(texpage->sound_name, infile);
1018 else
1019 tex->sound = -1;
1020
1021 // Set lighting flag
1022 if (tex->r > 0 || tex->g > 0 || tex->b > 0)
1023 tex->flags |= TF_LIGHT;
1024 else
1025 tex->flags &= ~TF_LIGHT;
1026
1027 // Set procedural if there is one
1028 if (tex->flags & TF_PROCEDURAL) {
1029 if (tex->procedural != NULL)
1030 FreeProceduralForTexture(n);
1031
1032 if (texpage->num_proc_elements == 0) {
1033 tex->flags &= ~TF_PROCEDURAL;
1034
1035 } else {
1036 AllocateProceduralForTexture(n);
1037 AllocateStaticProceduralsForTexture(n, texpage->num_proc_elements);
1038 GameTextures[n].procedural->num_static_elements = texpage->num_proc_elements;
1039 GameTextures[n].procedural->heat = texpage->proc_heat;
1040 GameTextures[n].procedural->light = texpage->proc_light;
1041 GameTextures[n].procedural->thickness = texpage->proc_thickness;
1042 GameTextures[n].procedural->evaluation_time = texpage->proc_evaluation_time;
1043 GameTextures[n].procedural->osc_time = texpage->osc_time;
1044 GameTextures[n].procedural->osc_value = texpage->osc_value;
1045
1046 // Last 2 colors are the same
1047 texpage->proc_palette[255] = texpage->proc_palette[254];
1048
1049 memcpy(GameTextures[n].procedural->palette, texpage->proc_palette, 256 * 2);
1050
1051 for (int i = 0; i < texpage->num_proc_elements; i++) {
1052 static_proc_element *proc = &GameTextures[n].procedural->static_proc_elements[i];
1053 proc->type = texpage->proc_type[i];
1054 proc->frequency = texpage->proc_frequency[i];
1055 proc->speed = texpage->proc_speed[i];
1056 proc->size = texpage->proc_size[i];
1057 proc->x1 = texpage->proc_x1[i];
1058 proc->y1 = texpage->proc_y1[i];
1059 proc->x2 = texpage->proc_x2[i];
1060 proc->y2 = texpage->proc_y2[i];
1061 }
1062 }
1063 }
1064 return 1;
1065 }
1066
1067 // Copies values from a texture into a texture_page
1068 void mng_AssignTextureToTexPage(int n, mngs_texture_page *texpage) {
1069 texture *tex = &GameTextures[n];
1070
1071 memcpy(&texpage->tex_struct, tex, sizeof(texture));
1072
1073 if (tex->bm_handle != -1) {
1074 if (tex->flags & TF_ANIMATED)
1075 strcpy(texpage->bitmap_name, GameVClips[tex->bm_handle].name);
1076 else
1077 strcpy(texpage->bitmap_name, GameBitmaps[tex->bm_handle].name);
1078 } else
1079 strcpy(texpage->bitmap_name, "");
1080
1081 if (tex->destroy_handle != -1)
1082 strcpy(texpage->destroy_name, GameTextures[tex->destroy_handle].name);
1083 else
1084 strcpy(texpage->destroy_name, "");
1085
1086 if (texpage->tex_struct.sound != -1)
1087 strcpy(texpage->sound_name, Sounds[texpage->tex_struct.sound].name);
1088 else
1089 strcpy(texpage->sound_name, "");
1090
1091 // assign procedural if there is one
1092 if (tex->flags & TF_PROCEDURAL) {
1093 memcpy(texpage->proc_palette, tex->procedural->palette, 256 * 2);
1094 texpage->num_proc_elements = tex->procedural->num_static_elements;
1095 texpage->proc_heat = tex->procedural->heat;
1096 texpage->proc_light = tex->procedural->light;
1097 texpage->proc_thickness = tex->procedural->thickness;
1098 texpage->proc_evaluation_time = tex->procedural->evaluation_time;
1099 texpage->osc_time = tex->procedural->osc_time;
1100 texpage->osc_value = tex->procedural->osc_value;
1101
1102 for (int i = 0; i < tex->procedural->num_static_elements; i++) {
1103 texpage->proc_type[i] = tex->procedural->static_proc_elements[i].type;
1104 texpage->proc_frequency[i] = tex->procedural->static_proc_elements[i].frequency;
1105 texpage->proc_speed[i] = tex->procedural->static_proc_elements[i].speed;
1106 texpage->proc_size[i] = tex->procedural->static_proc_elements[i].size;
1107
1108 texpage->proc_x1[i] = tex->procedural->static_proc_elements[i].x1;
1109 texpage->proc_y1[i] = tex->procedural->static_proc_elements[i].y1;
1110 texpage->proc_x2[i] = tex->procedural->static_proc_elements[i].x2;
1111 texpage->proc_y2[i] = tex->procedural->static_proc_elements[i].y2;
1112 }
1113 }
1114 }
1115
1116 // Loads in a texture page
1117 void mng_LoadNetTexturePage(CFILE *infile, bool overlay) {
1118 memset(&texpage1, 0, sizeof(mngs_texture_page));
1119
1120 if (mng_ReadNewTexturePage(infile, &texpage1)) {
1121 int n;
1122 n = FindTextureName(texpage1.tex_struct.name);
1123 if (n != -1) {
1124 if (overlay) {
1125 mprintf(0, "OVERLAYING TEXTURE %s\n", texpage1.tex_struct.name);
1126 mng_FreePagetypePrimitives(PAGETYPE_TEXTURE, texpage1.tex_struct.name, 0);
1127 mng_AssignTexPageToTexture(&texpage1, n);
1128 }
1129 return;
1130 }
1131
1132 int ret = mng_SetAndLoadTexture(&texpage1, infile);
1133 ASSERT(ret >= 0);
1134 } else
1135 mprintf(0, "Could not load texpage named %s!\n", texpage1.tex_struct.name);
1136 }
1137
1138 // Loads in a texture page from a file, superseding any texture with that name
1139 // already in memory
1140 void mng_LoadLocalTexturePage(CFILE *infile) {
1141 int ok = 0;
1142 memset(&texpage1, 0, sizeof(mngs_texture_page));
1143
1144 if (mng_ReadNewTexturePage(infile, &texpage1)) {
1145 int i = FindTextureName(texpage1.tex_struct.name);
1146 if (i != -1) {
1147 // Make sure we really have this page checked out
1148 mngs_Pagelock pl;
1149 // int locked;
1150
1151 strcpy(pl.name, texpage1.tex_struct.name);
1152 pl.pagetype = PAGETYPE_TEXTURE;
1153
1154 /*if (Network_up)
1155 {
1156 locked=mng_CheckIfPageOwned(&pl,TableUser);
1157 if (locked!=1)
1158 Int3(); // Your local vs net copies of the lock file do not match
1159 }*/
1160
1161 ok = 1;
1162 bool need_to_load_page = true;
1163
1164 if (Loading_addon_table != -1) {
1165 AddOnTablefile *addon;
1166 int tidx;
1167
1168 // see if we really need to load this page
1169 // check to see if we already have loaded this page (because it was
1170 // a dependancy of another)
1171 addon = &AddOnDataTables[Loading_addon_table];
1172 for (tidx = 0; tidx < addon->Num_addon_tracklocks; tidx++) {
1173 if (addon->Addon_tracklocks[tidx].pagetype == PAGETYPE_TEXTURE &&
1174 !stricmp(addon->Addon_tracklocks[tidx].name, texpage1.tex_struct.name)) {
1175 // found it!!
1176 mprintf(0, "TexturePage: %s previously loaded\n", texpage1.tex_struct.name);
1177 need_to_load_page = false;
1178 break;
1179 }
1180 }
1181 }
1182
1183 if (need_to_load_page) {
1184 mng_FreePagetypePrimitives(PAGETYPE_TEXTURE, texpage1.tex_struct.name, 0);
1185 mng_AssignTexPageToTexture(&texpage1, i);
1186
1187 // For addon data
1188 if (Loading_addon_table != -1) {
1189 // this is an overlay of some sort..see which we are overlaying
1190 int overlay = 1;
1191 int addidx, tidx;
1192 bool found = false;
1193 for (addidx = Num_addon_tables - 1; addidx >= 0; addidx--) {
1194 if (addidx == Loading_addon_table)
1195 continue;
1196 AddOnTablefile *addon = &AddOnDataTables[addidx];
1197
1198 // look for the page in this table file
1199 for (tidx = 0; tidx < addon->Num_addon_tracklocks; tidx++) {
1200 if (addon->Addon_tracklocks[tidx].pagetype == PAGETYPE_TEXTURE &&
1201 !stricmp(addon->Addon_tracklocks[tidx].name, texpage1.tex_struct.name)) {
1202 // found it!!
1203 found = true;
1204 overlay = addidx + 2;
1205 break;
1206 }
1207 }
1208
1209 if (found)
1210 break;
1211 }
1212
1213 mng_PushAddonPage(PAGETYPE_TEXTURE, texpage1.tex_struct.name, overlay);
1214 }
1215 }
1216 } else {
1217 // This is a local texture that has never been checked in
1218 if ((i = mng_SetAndLoadTexture(&texpage1, infile)) < 0)
1219 ok = 0;
1220 else
1221 ok = 1;
1222
1223 // For addon data
1224 if (ok && Loading_addon_table != -1)
1225 mng_PushAddonPage(PAGETYPE_TEXTURE, texpage1.tex_struct.name, 0);
1226 }
1227
1228 // ASSERT (ok==1); // There was problem loading a page!
1229 if (ok != 1)
1230 DataError("Cannot load texture <%s>, bitmap name <%s>\n", texpage1.tex_struct.name, texpage1.bitmap_name);
1231
1232 if (Loading_addon_table == -1)
1233 mng_AllocTrackLock(texpage1.tex_struct.name, PAGETYPE_TEXTURE);
1234
1235 } else
1236 mprintf(0, "Could not load texpage named %s!\n", texpage1.tex_struct.name);
1237 }
1238
1239 #include "mem.h"
1240
1241 // First searches through the texture index to see if the texture is already
1242 // loaded. If not, searches in the table file and loads it.
1243 // Returns index of texture found, -1 if not
1244 int mng_GetGuaranteedTexturePage(char *name, CFILE *infile) {
1245 int i;
1246
1247 // See if its in memory
1248 i = FindTextureName(name);
1249 if (i != -1)
1250 return i;
1251
1252 mngs_texture_page *texpage = (mngs_texture_page *)mem_malloc(sizeof(*texpage));
1253
1254 // Not in memory. Load it from the table file. Start searching from the
1255 // current spot in the open table file
1256 int ret = mng_FindSpecificTexPage(name, texpage, infile ? infile->position : 0);
1257 if (!ret)
1258 return -1;
1259
1260 // We've found it in the table file, now load it.
1261 ret = mng_SetAndLoadTexture(texpage, infile);
1262 // ASSERT (ret>=0);
1263 if (ret < 0)
1264 DataError("Cannot load texture <%s>, bitmap name <%s>\n", texpage->tex_struct.name, texpage->bitmap_name);
1265
1266 if (Loading_addon_table != -1) {
1267 // we're loading addon table pages, this will not overlay anything
1268 mng_PushAddonPage(PAGETYPE_TEXTURE, texpage->tex_struct.name, 0);
1269 }
1270 mem_free(texpage);
1271
1272 return ret;
1273 }