The Build Engine
build.h
1 /*
2  * "Build Engine & Tools" Copyright (c) 1993-1997 Ken Silverman
3  * Ken Silverman's official web site: "http://www.advsys.net/ken"
4  * See the included license file "BUILDLIC.TXT" for license info.
5  * This file has been modified from Ken Silverman's original release
6  */
7 
8 #ifndef _INCLUDE_BUILD_H_
9 #define _INCLUDE_BUILD_H_
10 
11 #define MAXSECTORS 1024
12 #define MAXWALLS 8192
13 #define MAXSPRITES 4096
14 
15 #define MAXTILES 9216
16 #define MAXSTATUS 1024
17 #define MAXPLAYERS 16
18 #define MAXXDIM 1600
19 #define MAXYDIM 1200
20 #define MAXPALOOKUPS 256
21 #define MAXPSKYTILES 256
22 #define MAXSPRITESONSCREEN 1024
23 
24 #define CLIPMASK0 (((1L)<<16)+1L)
25 #define CLIPMASK1 (((256L)<<16)+64L)
26 
27 
28  /*
29  * Make all variables in BUILD.H defined in the ENGINE,
30  * and externed in GAME
31  * (dear lord. --ryan.)
32  */
33 #ifdef ENGINE
34  #define EXTERN
35 #else
36  #define EXTERN extern
37 #endif
38 
39 
40 #ifdef PLATFORM_DOS
41 #pragma pack(push,1);
42 #else
43 #pragma pack(1)
44 #endif
45 
46 /*
47  * ceilingstat/floorstat:
48  * bit 0: 1 = parallaxing, 0 = not "P"
49  * bit 1: 1 = groudraw, 0 = not
50  * bit 2: 1 = swap x&y, 0 = not "F"
51  * bit 3: 1 = double smooshiness "E"
52  * bit 4: 1 = x-flip "F"
53  * bit 5: 1 = y-flip "F"
54  * bit 6: 1 = Align texture to first wall of sector "R"
55  * bits 7-8: "T"
56  * 00 = normal floors
57  * 01 = masked floors
58  * 10 = transluscent masked floors
59  * 11 = reverse transluscent masked floors
60  * bits 9-15: reserved
61  */
62 
63  /* 40 bytes */
64 typedef struct
65 {
66  short wallptr, wallnum;
67  long ceilingz, floorz;
68  short ceilingstat, floorstat;
69  short ceilingpicnum, ceilingheinum;
70  signed char ceilingshade;
71  unsigned char ceilingpal, ceilingxpanning, ceilingypanning;
72  short floorpicnum, floorheinum;
73  signed char floorshade;
74  unsigned char floorpal, floorxpanning, floorypanning;
75  unsigned char visibility, filler;
76  short lotag, hitag, extra;
77 } sectortype;
78 
79 /*
80  * cstat:
81  * bit 0: 1 = Blocking wall (use with clipmove, getzrange) "B"
82  * bit 1: 1 = bottoms of invisible walls swapped, 0 = not "2"
83  * bit 2: 1 = align picture on bottom (for doors), 0 = top "O"
84  * bit 3: 1 = x-flipped, 0 = normal "F"
85  * bit 4: 1 = masking wall, 0 = not "M"
86  * bit 5: 1 = 1-way wall, 0 = not "1"
87  * bit 6: 1 = Blocking wall (use with hitscan / cliptype 1) "H"
88  * bit 7: 1 = Transluscence, 0 = not "T"
89  * bit 8: 1 = y-flipped, 0 = normal "F"
90  * bit 9: 1 = Transluscence reversing, 0 = normal "T"
91  * bits 10-15: reserved
92  */
93 
94  /* 32 bytes */
95 typedef struct
96 {
97  long x, y;
98  short point2, nextwall, nextsector, cstat;
99  short picnum, overpicnum;
100  signed char shade;
101  char pal, xrepeat, yrepeat, xpanning, ypanning;
102  short lotag, hitag, extra;
103 } walltype;
104 
105 
106 /*
107  * cstat:
108  * bit 0: 1 = Blocking sprite (use with clipmove, getzrange) "B"
109  * bit 1: 1 = transluscence, 0 = normal "T"
110  * bit 2: 1 = x-flipped, 0 = normal "F"
111  * bit 3: 1 = y-flipped, 0 = normal "F"
112  * bits 5-4: 00 = FACE sprite (default) "R"
113  * 01 = WALL sprite (like masked walls)
114  * 10 = FLOOR sprite (parallel to ceilings&floors)
115  * bit 6: 1 = 1-sided sprite, 0 = normal "1"
116  * bit 7: 1 = Real centered centering, 0 = foot center "C"
117  * bit 8: 1 = Blocking sprite (use with hitscan / cliptype 1) "H"
118  * bit 9: 1 = Transluscence reversing, 0 = normal "T"
119  * bits 10-14: reserved
120  * bit 15: 1 = Invisible sprite, 0 = not invisible
121  */
122 
123  /* 44 bytes */
124 typedef struct
125 {
126  long x, y, z;
127  short cstat, picnum;
128  signed char shade;
129  unsigned char pal, clipdist, filler;
130  unsigned char xrepeat, yrepeat;
131  signed char xoffset, yoffset;
132  short sectnum, statnum;
133  short ang, owner, xvel, yvel, zvel;
134  short lotag, hitag, extra;
135 } spritetype;
136 
137 #ifdef PLATFORM_DOS
138 #pragma pack(pop);
139 #else
140 #pragma pack()
141 #endif
142 
143 EXTERN sectortype sector[MAXSECTORS];
144 EXTERN walltype wall[MAXWALLS];
145 EXTERN spritetype sprite[MAXSPRITES];
146 
147 EXTERN long spritesortcnt;
148 EXTERN spritetype tsprite[MAXSPRITESONSCREEN];
149 
150 EXTERN char vidoption;
151 EXTERN long xdim, ydim, ylookup[MAXYDIM+1], numpages;
152 EXTERN long yxaspect, viewingrange;
153 
154 EXTERN long validmodecnt;
155 EXTERN short validmode[256];
156 EXTERN long validmodexdim[256], validmodeydim[256];
157 
158 EXTERN short numsectors, numwalls;
159 EXTERN volatile long totalclock;
160 EXTERN long numframes, randomseed;
161 EXTERN short sintable[2048];
162 EXTERN unsigned char palette[768];
163 EXTERN short numpalookups;
164 EXTERN char *palookup[MAXPALOOKUPS];
165 EXTERN char parallaxtype, showinvisibility;
166 EXTERN long parallaxyoffs, parallaxyscale;
167 EXTERN long visibility, parallaxvisibility;
168 
169 EXTERN long windowx1, windowy1, windowx2, windowy2;
170 EXTERN short startumost[MAXXDIM], startdmost[MAXXDIM];
171 
172 EXTERN short pskyoff[MAXPSKYTILES], pskybits;
173 
174 EXTERN short headspritesect[MAXSECTORS+1], headspritestat[MAXSTATUS+1];
175 EXTERN short prevspritesect[MAXSPRITES], prevspritestat[MAXSPRITES];
176 EXTERN short nextspritesect[MAXSPRITES], nextspritestat[MAXSPRITES];
177 
178 EXTERN short tilesizx[MAXTILES], tilesizy[MAXTILES];
179 EXTERN char walock[MAXTILES];
180 EXTERN long numtiles, picanm[MAXTILES], waloff[MAXTILES];
181 
182  /*
183  * These variables are for auto-mapping with the draw2dscreen function.
184  * When you load a new board, these bits are all set to 0 - since
185  * you haven't mapped out anything yet. Note that these arrays are
186  * bit-mapped.
187  * If you want draw2dscreen() to show sprite #54 then you say:
188  * spritenum = 54;
189  * show2dsprite[spritenum>>3] |= (1<<(spritenum&7));
190  * And if you want draw2dscreen() to not show sprite #54 then you say:
191  * spritenum = 54;
192  * show2dsprite[spritenum>>3] &= ~(1<<(spritenum&7));
193  * Automapping defaults to 0 (do nothing). If you set automapping to 1,
194  * then in 3D mode, the walls and sprites that you see will show up the
195  * next time you flip to 2D mode.
196  */
197 EXTERN char show2dsector[(MAXSECTORS+7)>>3];
198 EXTERN char show2dwall[(MAXWALLS+7)>>3];
199 EXTERN char show2dsprite[(MAXSPRITES+7)>>3];
200 EXTERN char automapping;
201 
202 EXTERN char gotpic[(MAXTILES+7)>>3];
203 EXTERN char gotsector[(MAXSECTORS+7)>>3];
204 
205 /*************************************************************************
206 POSITION VARIABLES:
207 
208  POSX is your x - position ranging from 0 to 65535
209  POSY is your y - position ranging from 0 to 65535
210  (the length of a side of the grid in EDITBORD would be 1024)
211  POSZ is your z - position (height) ranging from 0 to 65535, 0 highest.
212  ANG is your angle ranging from 0 to 2047. Instead of 360 degrees, or
213  2 * PI radians, I use 2048 different angles, so 90 degrees would
214  be 512 in my system.
215 
216 SPRITE VARIABLES:
217 
218  EXTERN short headspritesect[MAXSECTORS+1], headspritestat[MAXSTATUS+1];
219  EXTERN short prevspritesect[MAXSPRITES], prevspritestat[MAXSPRITES];
220  EXTERN short nextspritesect[MAXSPRITES], nextspritestat[MAXSPRITES];
221 
222  Example: if the linked lists look like the following:
223  ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
224  ³ Sector lists: Status lists: ³
225  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
226  ³ Sector0: 4, 5, 8 Status0: 2, 0, 8 ³
227  ³ Sector1: 16, 2, 0, 7 Status1: 4, 5, 16, 7, 3, 9 ³
228  ³ Sector2: 3, 9 ³
229  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
230  Notice that each number listed above is shown exactly once on both the
231  left and right side. This is because any sprite that exists must
232  be in some sector, and must have some kind of status that you define.
233 
234 
235 Coding example #1:
236  To go through all the sprites in sector 1, the code can look like this:
237 
238  sectnum = 1;
239  i = headspritesect[sectnum];
240  while (i != -1)
241  {
242  nexti = nextspritesect[i];
243 
244  //your code goes here
245  //ex: printf("Sprite %d is in sector %d\n",i,sectnum);
246 
247  i = nexti;
248  }
249 
250 Coding example #2:
251  To go through all sprites with status = 1, the code can look like this:
252 
253  statnum = 1; //status 1
254  i = headspritestat[statnum];
255  while (i != -1)
256  {
257  nexti = nextspritestat[i];
258 
259  //your code goes here
260  //ex: printf("Sprite %d has a status of 1 (active)\n",i,statnum);
261 
262  i = nexti;
263  }
264 
265  insertsprite(short sectnum, short statnum);
266  deletesprite(short spritenum);
267  changespritesect(short spritenum, short newsectnum);
268  changespritestat(short spritenum, short newstatnum);
269 
270 TILE VARIABLES:
271  NUMTILES - the number of tiles found TILES.DAT.
272  TILESIZX[MAXTILES] - simply the x-dimension of the tile number.
273  TILESIZY[MAXTILES] - simply the y-dimension of the tile number.
274  WALOFF[MAXTILES] - the actual 32-bit offset pointing to the top-left
275  corner of the tile.
276  PICANM[MAXTILES] - flags for animating the tile.
277 
278 TIMING VARIABLES:
279  TOTALCLOCK - When the engine is initialized, TOTALCLOCK is set to zero.
280  From then on, it is incremented 120 times a second by 1. That
281  means that the number of seconds elapsed is totalclock / 120.
282  NUMFRAMES - The number of times the draw3dscreen function was called
283  since the engine was initialized. This helps to determine frame
284  rate. (Frame rate = numframes * 120 / totalclock.)
285 
286 OTHER VARIABLES:
287 
288  STARTUMOST[320] is an array of the highest y-coordinates on each column
289  that my engine is allowed to write to. You need to set it only
290  once.
291  STARTDMOST[320] is an array of the lowest y-coordinates on each column
292  that my engine is allowed to write to. You need to set it only
293  once.
294  SINTABLE[2048] is a sin table with 2048 angles rather than the
295  normal 360 angles for higher precision. Also since SINTABLE is in
296  all integers, the range is multiplied by 16383, so instead of the
297  normal -1<sin(x)<1, the range of sintable is -16383<sintable[]<16383
298  If you use this sintable, you can possibly speed up your code as
299  well as save space in memory. If you plan to use sintable, 2
300  identities you may want to keep in mind are:
301  sintable[ang&2047] = sin(ang * (3.141592/1024)) * 16383
302  sintable[(ang+512)&2047] = cos(ang * (3.141592/1024)) * 16383
303  NUMSECTORS - the total number of existing sectors. Modified every time
304  you call the loadboard function.
305 ***************************************************************************/
306 
307 #define PORTSIG "Port by Ryan C. Gordon, Andrew Henderson, Dan Olson, and a cast of thousands."
308 
309 #endif /* defined _INCLUDE_BUILD_H_ */
310 
311 /* end of build.h ... */
312 
313 
314