Debian Codegraph @

Descent3/megacell.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: /descent3/main/megacell.cpp $
21 * $Revision: 3 $
22 * $Date: 6/06/97 5:25p $
23 * $Author: Mark $
24 *
25 * $Log: /descent3/main/megacell.cpp $
26 *
27 * 3 6/06/97 5:25p Mark
28 * FROM JASON:Fixed megacell bug
29 *
30 * 2 6/05/97 2:52p Jason
31 * added megacell functions
32 *
33 * 1 6/05/97 10:56a Jason
34 *
35
36 *
37 * $NoKeywords: $
38 */
39
40 #include "pserror.h"cxx . . $ `<file>/misc/pserror.h`/
41 #include "megacell.h"cxx . . $ `<file>/lib/megacell.h`/
42 #include "bitmap.h"cxx . . $ `<file>/lib/bitmap.h`/
43 #include <stdarg.h>
44 #include <string.h>
45
46 megacellcxx . . $ megacell# Megacellscxx . . $ Megacells.[MAX_MEGACELLScxx . . $ `lib/megacell.h:26:9`!];
47 int Num_megacellscxx . . $ Num_megacells. = 0;
48
49 // Sets all megacells to unused
50 void InitMegacellscxx . . $ InitMegacells(49f6e7a06ebc5aa8).() {
51 for (int i = 0; i < MAX_MEGACELLScxx . . $ `lib/megacell.h:26:9`!; i++) {
52 Megacellscxx . . $ Megacells.[i].usedcxx . . $ megacell#used. = 0;
53 Megacellscxx . . $ Megacells.[i].namecxx . . $ megacell#name.[0] = 0;
54 }
55 Num_megacellscxx . . $ Num_megacells. = 0;
56 }
57
58 // Allocs a megacell for use, returns -1 if error, else index on success
59 int AllocMegacellcxx . . $ AllocMegacell(b126dc7c1de90089).() {
60 for (int i = 0; i < MAX_MEGACELLScxx . . $ `lib/megacell.h:26:9`!; i++) {
61 if (Megacellscxx . . $ Megacells.[i].usedcxx . . $ megacell#used. == 0) {
62 memset(&Megacellscxx . . $ Megacells.[i], 0, sizeof(megacellcxx . . $ megacell#));
63 Megacellscxx . . $ Megacells.[i].usedcxx . . $ megacell#used. = 1;
64 Megacellscxx . . $ Megacells.[i].widthcxx . . $ megacell#width. = DEFAULT_MEGACELL_WIDTHcxx . . $ `lib/megacell.h:28:9`!;
65 Megacellscxx . . $ Megacells.[i].heightcxx . . $ megacell#height. = DEFAULT_MEGACELL_HEIGHTcxx . . $ `lib/megacell.h:29:9`!;
66 Num_megacellscxx . . $ Num_megacells.++;
67 return i;
68 }
69 }
70
71 Int3cxx . . $ `misc/pserror.h:247:9`!(); // No megacells free!
72 return -1;
73 }
74
75 // Frees megacell index n
76 void FreeMegacellcxx . . $ FreeMegacell(d4f767463ce0a6b3).(int n) {
77 ASSERTcxx . . $ `misc/pserror.h:246:9`!(Megacells[n].used > 0);
78
79 Megacellscxx . . $ Megacells.[n].usedcxx . . $ megacell#used. = 0;
80 Megacellscxx . . $ Megacells.[n].namecxx . . $ megacell#name.[0] = 0;
81 Num_megacellscxx . . $ Num_megacells.--;
82 }
83
84 // Gets next megacell from n that has actually been alloced
85 int GetNextMegacellcxx . . $ GetNextMegacell(7864480464b09eea).(int n) {
86 int i;
87
88 ASSERTcxx . . $ `misc/pserror.h:246:9`!(n >= 0 && n < MAX_MEGACELLScxx . . $ `lib/megacell.h:26:9`!);
89
90 if (Num_megacellscxx . . $ Num_megacells. == 0)
91 return 0;
92
93 for (i = n + 1; i < MAX_MEGACELLScxx . . $ `lib/megacell.h:26:9`!; i++)
94 if (Megacellscxx . . $ Megacells.[i].usedcxx . . $ megacell#used.)
95 return i;
96 for (i = 0; i < n; i++)
97 if (Megacellscxx . . $ Megacells.[i].usedcxx . . $ megacell#used.)
98 return i;
99
100 // this is the only one
101
102 return n;
103 }
104
105 // Gets previous megacell from n that has actually been alloced
106 int GetPrevMegacellcxx . . $ GetPrevMegacell(7864480464b09eea).(int n) {
107 int i;
108
109 ASSERTcxx . . $ `misc/pserror.h:246:9`!(n >= 0 && n < MAX_MEGACELLScxx . . $ `lib/megacell.h:26:9`!);
110
111 if (Num_megacellscxx . . $ Num_megacells. == 0)
112 return 0;
113
114 for (i = n - 1; i >= 0; i--) {
115 if (Megacellscxx . . $ Megacells.[i].usedcxx . . $ megacell#used.)
116 return i;
117 }
118 for (i = MAX_MEGACELLScxx . . $ `lib/megacell.h:26:9`! - 1; i > n; i--) {
119 if (Megacellscxx . . $ Megacells.[i].usedcxx . . $ megacell#used.)
120 return i;
121 }
122
123 // this is the only one
124 return n;
125 }
126 // Searches thru all megacells for a specific name, returns -1 if not found
127 // or index of megacell with name
128 int FindMegacellNamecxx . . $ FindMegacellName(1ef8e6ec083aabb9).(char *name) {
129 int i;
130
131 ASSERTcxx . . $ `misc/pserror.h:246:9`!(name != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
132
133 for (i = 0; i < MAX_MEGACELLScxx . . $ `lib/megacell.h:26:9`!; i++)
134 if (Megacellscxx . . $ Megacells.[i].usedcxx . . $ megacell#used. && !stricmpcxx . . $ `linux/linux_fix.h:43:9`!(name, Megacells[i].name))
135 return i;
136
137 return -1;
138 }