Debian Codegraph @

bitmap/bumpmap.cpp

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
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
19 #include <stdlib.h>
20 #include <string.h>
21 #include "bumpmap.h"cxx . . $ `<file>/lib/bumpmap.h`/
22 #include "pstypes.h"cxx . . $ `<file>/lib/pstypes.h`/
23 #include "pserror.h"cxx . . $ `<file>/misc/pserror.h`/
24 #include "mono.h"cxx . . $ `<file>/ddebug/mono.h`/
25 #include "mem.h"cxx . . $ `<file>/mem/mem.h`/
26
27 static int Num_of_bumpmapscxx . . $ Num_of_bumpmaps. = 0;
28 static uint16_tcxx . . $ uint16_t# Free_bumpmap_listcxx . . $ Free_bumpmap_list.[MAX_BUMPMAPScxx . . $ `lib/bumpmap.h:24:9`!];
29
30 bms_bumpmapcxx . . $ bms_bumpmap# GameBumpmapscxx . . $ GameBumpmaps.[MAX_BUMPMAPScxx . . $ `lib/bumpmap.h:24:9`!];
31 static int Bumpmap_mem_usedcxx . . $ Bumpmap_mem_used. = 0;
32
33 // Sets all the bumpmaps to unused
34 void bump_InitBumpmapscxx . . $ bump_InitBumpmaps(49f6e7a06ebc5aa8).() {
35 int i;
36
37 for (i = 0; i < MAX_BUMPMAPScxx . . $ `lib/bumpmap.h:24:9`!; i++) {
38 GameBumpmapscxx . . $ GameBumpmaps.[i].flagscxx . . $ bms_bumpmap#flags. = 0;
39 GameBumpmapscxx . . $ GameBumpmaps.[i].datacxx . . $ bms_bumpmap#data. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
40 GameBumpmapscxx . . $ GameBumpmaps.[i].cache_slotcxx . . $ bms_bumpmap#cache_slot. = -1;
41 Free_bumpmap_listcxx . . $ Free_bumpmap_list.[i] = i;
42 }
43
44 atexitcxx . . $ atexit(cc8c495369588262).(bump_ShutdownBumpmapscxx . . $ bump_ShutdownBumpmaps(49f6e7a06ebc5aa8).);
45 }
46 void bump_ShutdownBumpmapscxx . . $ bump_ShutdownBumpmaps(49f6e7a06ebc5aa8).(void) {
47 int i;
48
49 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Freeing all bumpmap memory.\n");
50
51 for (i = 0; i < MAX_BUMPMAPScxx . . $ `lib/bumpmap.h:24:9`!; i++) {
52 while (GameBumpmapscxx . . $ GameBumpmaps.[i].flagscxx . . $ bms_bumpmap#flags. & BUMPF_USEDcxx . . $ `lib/bumpmap.h:27:9`!)
53 bump_FreeBumpmapcxx . . $ bump_FreeBumpmap(d4f767463ce0a6b3).(i);
54 }
55 }
56
57 // Allocs a bumpmap of w*h size
58 // Returns bumpmap handle if successful, -1 if otherwise
59
60 int bump_AllocBumpmapcxx . . $ bump_AllocBumpmap(9b79fb6aee4c0440).(int w, int h) {
61 int n; //,i;
62
63 if (Num_of_bumpmapscxx . . $ Num_of_bumpmaps. == MAX_BUMPMAPScxx . . $ `lib/bumpmap.h:24:9`!)
64 Int3cxx . . $ `misc/pserror.h:247:9`!(); // Ran out of bumpmaps!
65
66 n = Free_bumpmap_listcxx . . $ Free_bumpmap_list.[Num_of_bumpmapscxx . . $ Num_of_bumpmaps.++];
67 ASSERTcxx . . $ `misc/pserror.h:246:9`!(!(GameBumpmaps[n].flags & BUMPF_USEDcxx . . $ `lib/bumpmap.h:27:9`!));
68
69 // If no go on the malloc, bail out with -1
70
71 memset(&GameBumpmapscxx . . $ GameBumpmaps.[n], 0, sizeof(bms_bumpmapcxx . . $ bms_bumpmap#));
72
73 GameBumpmapscxx . . $ GameBumpmaps.[n].datacxx . . $ bms_bumpmap#data. = (uint16_tcxx . . $ uint16_t# *)mem_malloccxx . . $ `mem/mem.h:79:9`!(w * h * 2);
74 if (!GameBumpmapscxx . . $ GameBumpmaps.[n].datacxx . . $ bms_bumpmap#data.) {
•75 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "NOT ENOUGH MEMORY FOR BUMPMAP!\n");
76 Int3cxx . . $ `misc/pserror.h:247:9`!();
77 return BAD_BUMP_INDEXcxx . . $ `lib/bumpmap.h:25:9`!;
78 }
79
80 GameBumpmapscxx . . $ GameBumpmaps.[n].cache_slotcxx . . $ bms_bumpmap#cache_slot. = -1;
81 GameBumpmapscxx . . $ GameBumpmaps.[n].flagscxx . . $ bms_bumpmap#flags. = BUMPF_USEDcxx . . $ `lib/bumpmap.h:27:9`! | BUMPF_CHANGEDcxx . . $ `lib/bumpmap.h:28:9`!;
82 GameBumpmapscxx . . $ GameBumpmaps.[n].widthcxx . . $ bms_bumpmap#width. = w;
83 GameBumpmapscxx . . $ GameBumpmaps.[n].heightcxx . . $ bms_bumpmap#height. = h;
84
85 Bumpmap_mem_usedcxx . . $ Bumpmap_mem_used. += (w * h * 2);
86
87 return n;
88 }
89
90 // Given a handle, frees the bumpmap memory and flags this bumpmap as unused
91 void bump_FreeBumpmapcxx . . $ bump_FreeBumpmap(d4f767463ce0a6b3).(int handle) {
92 ASSERTcxx . . $ `misc/pserror.h:246:9`!(GameBumpmaps[handle].flags & BUMPF_USEDcxx . . $ `lib/bumpmap.h:27:9`!);
93
94 if (GameBumpmapscxx . . $ GameBumpmaps.[handle].datacxx . . $ bms_bumpmap#data. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
95 mem_freecxx . . $ `mem/mem.h:80:9`!(GameBumpmaps[handle].data);
96
97 Bumpmap_mem_usedcxx . . $ Bumpmap_mem_used. -= (GameBumpmapscxx . . $ GameBumpmaps.[handle].widthcxx . . $ bms_bumpmap#width. * GameBumpmapscxx . . $ GameBumpmaps.[handle].heightcxx . . $ bms_bumpmap#height. * 2);
98
99 GameBumpmapscxx . . $ GameBumpmaps.[handle].datacxx . . $ bms_bumpmap#data. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
100 GameBumpmapscxx . . $ GameBumpmaps.[handle].flagscxx . . $ bms_bumpmap#flags. &= ~BUMPF_USEDcxx . . $ `lib/bumpmap.h:27:9`!;
101
102 Free_bumpmap_listcxx . . $ Free_bumpmap_list.[--Num_of_bumpmapscxx . . $ Num_of_bumpmaps.] = handle;
103 }
104
105 // returns a bumpmaps data else NULL if something is wrong
106 uint16_tcxx . . $ uint16_t# *bump_datacxx . . $ bump_data(2fbd6a760478ca0f).(int handle) {
107 uint16_tcxx . . $ uint16_t# *d;
108
109 if (!(GameBumpmapscxx . . $ GameBumpmaps.[handle].flagscxx . . $ bms_bumpmap#flags. & BUMPF_USEDcxx . . $ `lib/bumpmap.h:27:9`!)) {
110 Int3cxx . . $ `misc/pserror.h:247:9`!();
111 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
112 }
113
114 d = GameBumpmapscxx . . $ GameBumpmaps.[handle].datacxx . . $ bms_bumpmap#data.;
115
116 return (d);
117 }
118
119 // returns width of bumpmap
120 uint8_tcxx . . $ uint8_t# bump_wcxx . . $ bump_w(bc0fba5608a0bfe7).(int handle) {
121 ASSERTcxx . . $ `misc/pserror.h:246:9`!(GameBumpmaps[handle].flags & BUMPF_USEDcxx . . $ `lib/bumpmap.h:27:9`!);
122 return GameBumpmapscxx . . $ GameBumpmaps.[handle].widthcxx . . $ bms_bumpmap#width.;
123 }
124
125 // returns height of bumpmap
126 uint8_tcxx . . $ uint8_t# bump_hcxx . . $ bump_h(bc0fba5608a0bfe7).(int handle) {
127 ASSERTcxx . . $ `misc/pserror.h:246:9`!(GameBumpmaps[handle].flags & BUMPF_USEDcxx . . $ `lib/bumpmap.h:27:9`!);
128 return GameBumpmapscxx . . $ GameBumpmaps.[handle].heightcxx . . $ bms_bumpmap#height.;
129 }