// "Build Engine & Tools" Copyright (c) 1993-1997 Ken Silverman // Ken Silverman's official web site: "http://www.advsys.net/ken" // See the included license file "BUILDLIC.TXT" for license info. // // This file has been modified from Ken Silverman's original release // by Jonathon Fowler (jonof@edgenetwk.com) #ifndef __build_h__ #define __build_h__ #include "compat.h" #ifdef __cplusplus extern "C" { #endif #define MAXSECTORSV8 4096 #define MAXWALLSV8 16384 #define MAXSPRITESV8 16384 #define MAXSECTORSV7 1024 #define MAXWALLSV7 8192 #define MAXSPRITESV7 4096 #define MAXSECTORS MAXSECTORSV8 #define MAXWALLS MAXWALLSV8 #define MAXWALLSB ((MAXWALLS>>2)+(MAXWALLS>>3)) #define MAXSPRITES MAXSPRITESV8 #define MAXTILES 15360 #define MAXVOXELS 4096 #define MAXSTATUS 1024 #define MAXPLAYERS 16 #define MAXXDIM 3072 #define MAXYDIM 2304 #define MAXPALOOKUPS 256 #define MAXPSKYTILES 256 #define MAXSPRITESONSCREEN 4096 #define MAXUNIQHUDID 256 //Extra slots so HUD models can store animation state without messing game sprites #define RESERVEDPALS 8 // don't forget to increment this when adding reserved pals #define DETAILPAL (MAXPALOOKUPS - 1) #define GLOWPAL (MAXPALOOKUPS - 2) #define REDPAL (MAXPALOOKUPS - 3) #define BLUEPAL (MAXPALOOKUPS - 4) #define BROWNPAL (MAXPALOOKUPS - 5) #define GREYPAL (MAXPALOOKUPS - 6) #define GREENPAL (MAXPALOOKUPS - 7) #define SPECPAL (MAXPALOOKUPS - 8) #define TSPR_TEMP 99 #define TSPR_MIRROR 100 #define CLIPMASK0 (((1L)<<16)+1L) #define CLIPMASK1 (((256L)<<16)+64L) //Make all variables in BUILD.H defined in the ENGINE, //and externed in GAME #ifdef ENGINE # define EXTERN #else # define EXTERN extern #endif #ifdef __GNUC__ #define BPACK __attribute__ ((packed)) #else #define BPACK #endif #ifdef _MSC_VER #pragma pack(1) #endif #ifdef __WATCOMC__ #pragma pack(push,1); #endif //ceilingstat/floorstat: // bit 0: 1 = parallaxing, 0 = not "P" // bit 1: 1 = groudraw, 0 = not // bit 2: 1 = swap x&y, 0 = not "F" // bit 3: 1 = double smooshiness "E" // bit 4: 1 = x-flip "F" // bit 5: 1 = y-flip "F" // bit 6: 1 = Align texture to first wall of sector "R" // bits 7-8: "T" // 00 = normal floors // 01 = masked floors // 10 = transluscent masked floors // 11 = reverse transluscent masked floors // bits 9-15: reserved //40 bytes typedef struct BPACK { int16_t wallptr, wallnum; int32_t ceilingz, floorz; int16_t ceilingstat, floorstat; int16_t ceilingpicnum, ceilingheinum; int8_t ceilingshade; uint8_t ceilingpal, ceilingxpanning, ceilingypanning; int16_t floorpicnum, floorheinum; int8_t floorshade; uint8_t floorpal, floorxpanning, floorypanning; uint8_t visibility, filler; int16_t lotag, hitag, extra; } sectortype; //cstat: // bit 0: 1 = Blocking wall (use with clipmove, getzrange) "B" // bit 1: 1 = bottoms of invisible walls swapped, 0 = not "2" // bit 2: 1 = align picture on bottom (for doors), 0 = top "O" // bit 3: 1 = x-flipped, 0 = normal "F" // bit 4: 1 = masking wall, 0 = not "M" // bit 5: 1 = 1-way wall, 0 = not "1" // bit 6: 1 = Blocking wall (use with hitscan / cliptype 1) "H" // bit 7: 1 = Transluscence, 0 = not "T" // bit 8: 1 = y-flipped, 0 = normal "F" // bit 9: 1 = Transluscence reversing, 0 = normal "T" // bits 10-15: reserved //32 bytes typedef struct BPACK { int32_t x, y; int16_t point2, nextwall, nextsector, cstat; int16_t picnum, overpicnum; int8_t shade; uint8_t pal, xrepeat, yrepeat, xpanning, ypanning; int16_t lotag, hitag, extra; } walltype; //cstat: // bit 0: 1 = Blocking sprite (use with clipmove, getzrange) "B" // bit 1: 1 = transluscence, 0 = normal "T" // bit 2: 1 = x-flipped, 0 = normal "F" // bit 3: 1 = y-flipped, 0 = normal "F" // bits 5-4: 00 = FACE sprite (default) "R" // 01 = WALL sprite (like masked walls) // 10 = FLOOR sprite (parallel to ceilings&floors) // bit 6: 1 = 1-sided sprite, 0 = normal "1" // bit 7: 1 = Real centered centering, 0 = foot center "C" // bit 8: 1 = Blocking sprite (use with hitscan / cliptype 1) "H" // bit 9: 1 = Transluscence reversing, 0 = normal "T" // bits 10-14: reserved // bit 15: 1 = Invisible sprite, 0 = not invisible //44 bytes typedef struct BPACK { int32_t x, y, z; int16_t cstat, picnum; int8_t shade; uint8_t pal, clipdist, filler; uint8_t xrepeat, yrepeat; int8_t xoffset, yoffset; int16_t sectnum, statnum; int16_t ang, owner, xvel, yvel, zvel; int16_t lotag, hitag, extra; } spritetype; typedef struct BPACK { uint32_t mdanimtims; int16_t mdanimcur; int16_t angoff; int16_t pitch, roll; int32_t xoff, yoff, zoff; uint8_t flags; uint8_t xpanning, ypanning; uint8_t filler[1]; spritetype *tspr; } spriteext_t; typedef struct BPACK { float smoothduration; int16_t mdcurframe, mdoldframe; int16_t mdsmooth; uint8_t filler[2]; } spritesmooth_t; #define SPREXT_NOTMD 1 #define SPREXT_NOMDANIM 2 #define SPREXT_AWAY1 4 #define SPREXT_AWAY2 8 #define SPREXT_TSPRACCESS 16 EXTERN spriteext_t *spriteext; EXTERN spritesmooth_t *spritesmooth; EXTERN int32_t guniqhudid; EXTERN sectortype *sector; EXTERN walltype *wall; EXTERN int16_t maskwall[MAXWALLSB], maskwallcnt; EXTERN int16_t thewall[MAXWALLSB]; EXTERN spritetype *sprite; EXTERN spritetype *tspriteptr[MAXSPRITESONSCREEN]; EXTERN int32_t spritesortcnt; EXTERN spritetype *tsprite; EXTERN int32_t xdim, ydim, numpages; EXTERN int32_t yxaspect, viewingrange; EXTERN intptr_t ylookup[MAXYDIM+1]; #define MAXVALIDMODES 256 EXTERN int32_t validmodecnt; struct validmode_t { int32_t xdim,ydim; char bpp; char fs; // bit 0 = fullscreen flag char filler[2]; int32_t extra; // internal use }; EXTERN struct validmode_t validmode[MAXVALIDMODES]; EXTERN int16_t numsectors, numwalls; EXTERN char display_mirror; EXTERN /*volatile*/ int32_t totalclock; EXTERN int32_t numframes, randomseed; EXTERN int16_t sintable[2048]; EXTERN uint8_t palette[768]; EXTERN int16_t numpalookups; EXTERN char *palookup[MAXPALOOKUPS]; EXTERN char parallaxtype, showinvisibility; EXTERN int32_t parallaxyoffs, parallaxyscale; EXTERN int32_t visibility, parallaxvisibility; EXTERN int32_t windowx1, windowy1, windowx2, windowy2; EXTERN int16_t startumost[MAXXDIM], startdmost[MAXXDIM]; EXTERN int16_t pskyoff[MAXPSKYTILES], pskybits; EXTERN int16_t headspritesect[MAXSECTORS+1], headspritestat[MAXSTATUS+1]; EXTERN int16_t prevspritesect[MAXSPRITES], prevspritestat[MAXSPRITES]; EXTERN int16_t nextspritesect[MAXSPRITES], nextspritestat[MAXSPRITES]; EXTERN int16_t tilesizx[MAXTILES], tilesizy[MAXTILES]; EXTERN char picsiz[MAXTILES]; EXTERN char walock[MAXTILES]; EXTERN int32_t pow2long[32]; EXTERN int32_t numtiles, picanm[MAXTILES]; EXTERN intptr_t waloff[MAXTILES]; // stores pointers to cache -- SA EXTERN int32_t windowpos, windowx, windowy; //These variables are for auto-mapping with the draw2dscreen function. //When you load a new board, these bits are all set to 0 - since //you haven't mapped out anything yet. Note that these arrays are //bit-mapped. //If you want draw2dscreen() to show sprite #54 then you say: // spritenum = 54; // show2dsprite[spritenum>>3] |= (1<<(spritenum&7)); //And if you want draw2dscreen() to not show sprite #54 then you say: // spritenum = 54; // show2dsprite[spritenum>>3] &= ~(1<<(spritenum&7)); //Automapping defaults to 0 (do nothing). If you set automapping to 1, // then in 3D mode, the walls and sprites that you see will show up the // next time you flip to 2D mode. EXTERN char show2dsector[(MAXSECTORS+7)>>3]; EXTERN char show2dwall[(MAXWALLS+7)>>3]; EXTERN char show2dsprite[(MAXSPRITES+7)>>3]; EXTERN char automapping; EXTERN char gotpic[(MAXTILES+7)>>3]; EXTERN char gotsector[(MAXSECTORS+7)>>3]; EXTERN char captureformat; EXTERN char editorcolors[256]; extern char vgapalette[5*256]; extern uint32_t drawlinepat; extern void faketimerhandler(void); extern char apptitle[256]; typedef struct { char r,g,b,f; } palette_t; extern palette_t curpalette[256], curpalettefaded[256], palfadergb; extern char palfadedelta; extern int32_t dommxoverlay, novoxmips; #ifdef SUPERBUILD extern int32_t tiletovox[MAXTILES]; extern int32_t usevoxels, voxscale[MAXVOXELS]; #endif #ifdef POLYMOST extern int32_t usemodels, usehightile; extern int32_t rendmode; #endif EXTERN int32_t h_xsize[MAXTILES], h_ysize[MAXTILES]; EXTERN int8_t h_xoffs[MAXTILES], h_yoffs[MAXTILES]; extern char *engineerrstr; extern char noclip; EXTERN int32_t editorzrange[2]; static inline int32_t getrendermode(void) { #ifndef POLYMOST return 0; #else return rendmode; #endif } /************************************************************************* POSITION VARIABLES: POSX is your x - position ranging from 0 to 65535 POSY is your y - position ranging from 0 to 65535 (the length of a side of the grid in EDITBORD would be 1024) POSZ is your z - position (height) ranging from 0 to 65535, 0 highest. ANG is your angle ranging from 0 to 2047. Instead of 360 degrees, or 2 * PI radians, I use 2048 different angles, so 90 degrees would be 512 in my system. SPRITE VARIABLES: EXTERN short headspritesect[MAXSECTORS+1], headspritestat[MAXSTATUS+1]; EXTERN short prevspritesect[MAXSPRITES], prevspritestat[MAXSPRITES]; EXTERN short nextspritesect[MAXSPRITES], nextspritestat[MAXSPRITES]; Example: if the linked lists look like the following: ???????????????????????????????? Sector lists: Status lists: ???????????????????????????????J Sector0: 4, 5, 8 Status0: 2, 0, 8 Sector1: 16, 2, 0, 7 Status1: 4, 5, 16, 7, 3, 9 Sector2: 3, 9 ???????????????????????????????? Notice that each number listed above is shown exactly once on both the left and right side. This is because any sprite that exists must be in some sector, and must have some kind of status that you define. Coding example #1: To go through all the sprites in sector 1, the code can look like this: sectnum = 1; i = headspritesect[sectnum]; while (i != -1) { nexti = nextspritesect[i]; //your code goes here //ex: printf("Sprite %d is in sector %d\n",i,sectnum); i = nexti; } Coding example #2: To go through all sprites with status = 1, the code can look like this: statnum = 1; //status 1 i = headspritestat[statnum]; while (i != -1) { nexti = nextspritestat[i]; //your code goes here //ex: printf("Sprite %d has a status of 1 (active)\n",i,statnum); i = nexti; } insertsprite(short sectnum, short statnum); deletesprite(short spritenum); changespritesect(short spritenum, short newsectnum); changespritestat(short spritenum, short newstatnum); TILE VARIABLES: NUMTILES - the number of tiles found TILES.DAT. TILESIZX[MAXTILES] - simply the x-dimension of the tile number. TILESIZY[MAXTILES] - simply the y-dimension of the tile number. WALOFF[MAXTILES] - the actual 32-bit offset pointing to the top-left corner of the tile. PICANM[MAXTILES] - flags for animating the tile. TIMING VARIABLES: TOTALCLOCK - When the engine is initialized, TOTALCLOCK is set to zero. From then on, it is incremented 120 times a second by 1. That means that the number of seconds elapsed is totalclock / 120. NUMFRAMES - The number of times the draw3dscreen function was called since the engine was initialized. This helps to determine frame rate. (Frame rate = numframes * 120 / totalclock.) OTHER VARIABLES: STARTUMOST[320] is an array of the highest y-coordinates on each column that my engine is allowed to write to. You need to set it only once. STARTDMOST[320] is an array of the lowest y-coordinates on each column that my engine is allowed to write to. You need to set it only once. SINTABLE[2048] is a sin table with 2048 angles rather than the normal 360 angles for higher precision. Also since SINTABLE is in all integers, the range is multiplied by 16383, so instead of the normal -1=0 for a particular palette // how: pass -1 to invalidate all instances of the tile in texture memory, or a bitfield // bit 0: opaque or masked (non-translucent) texture, using repeating // bit 1: ignored // bit 2: 33% translucence, using repeating // bit 3: 67% translucence, using repeating // bit 4: opaque or masked (non-translucent) texture, using clamping // bit 5: ignored // bit 6: 33% translucence, using clamping // bit 7: 67% translucence, using clamping // clamping is for sprites, repeating is for walls void invalidatetile(int16_t tilenume, int32_t pal, int32_t how); int32_t animateoffs(int16_t tilenum, int16_t fakevar); void setpolymost2dview(void); // sets up GL for 2D drawing int32_t polymost_drawtilescreen(int32_t tilex, int32_t tiley, int32_t wallnum, int32_t dimen, int32_t tilezoom); void polymost_glreset(void); void polymost_precache(int32_t dapicnum, int32_t dapalnum, int32_t datype); #if defined(POLYMOST) && defined(USE_OPENGL) extern int32_t glanisotropy; extern int32_t glusetexcompr; extern int32_t gltexfiltermode; extern int32_t glredbluemode; extern int32_t glusetexcache, glusetexcachecompression; extern int32_t glmultisample, glnvmultisamplehint; extern int32_t glwidescreen, glprojectionhacks; extern int32_t gltexmaxsize; void gltexapplyprops (void); void invalidatecache(void); extern int32_t r_depthpeeling, r_peelscount; extern int32_t r_detailmapping; extern int32_t r_glowmapping; extern int32_t r_vertexarrays; extern int32_t r_vbos; extern int32_t r_vbocount; extern int32_t r_animsmoothing; extern int32_t r_parallaxskyclamping; extern int32_t r_parallaxskypanning; extern int32_t r_modelocclusionchecking; extern int32_t r_fullbrights; extern int32_t r_downsize; extern int32_t mdtims, omdtims; #endif void hicinit(void); // effect bitset: 1 = greyscale, 2 = invert void hicsetpalettetint(int32_t palnum, char r, char g, char b, char effect); // flags bitset: 1 = don't compress int32_t hicsetsubsttex(int32_t picnum, int32_t palnum, char *filen, float alphacut, float xscale, float yscale, char flags); int32_t hicsetskybox(int32_t picnum, int32_t palnum, char *faces[6]); int32_t hicclearsubst(int32_t picnum, int32_t palnum); int32_t Ptile2tile(int32_t tile, int32_t pallet); int32_t md_loadmodel(const char *fn); int32_t md_setmisc(int32_t modelid, float scale, int32_t shadeoff, float zadd, int32_t flags); int32_t md_tilehasmodel(int32_t tilenume, int32_t pal); int32_t md_defineframe(int32_t modelid, const char *framename, int32_t tilenume, int32_t skinnum, float smoothduration, int32_t pal); int32_t md_defineanimation(int32_t modelid, const char *framestart, const char *frameend, int32_t fps, int32_t flags); int32_t md_defineskin(int32_t modelid, const char *skinfn, int32_t palnum, int32_t skinnum, int32_t surfnum, float param); int32_t md_definehud (int32_t modelid, int32_t tilex, double xadd, double yadd, double zadd, double angadd, int32_t flags); int32_t md_undefinetile(int32_t tile); int32_t md_undefinemodel(int32_t modelid); #define MAXPALCONV 200 void clearconv(); void setpalconv(int32_t pal,int32_t pal1,int32_t pal2); void getpalmap(int32_t *stage,int32_t *pal1,int32_t *pal2); int32_t checkpalmaps(int32_t pal); void applypalmap(char *pic, char *palmap, int32_t size, int32_t pal); int32_t loaddefinitionsfile(char *fn); extern int32_t mapversion; // if loadboard() fails with -2 return, try loadoldboard(). if it fails with -2, board is dodgy int32_t loadoldboard(char *filename, char fromwhere, int32_t *daposx, int32_t *daposy, int32_t *daposz, int16_t *daang, int16_t *dacursectnum); // Hash functions typedef struct _hashitem // size is 12/24 bits. { char *string; int32_t key; struct _hashitem *next; } hashitem_t; typedef struct { int32_t size; hashitem_t **items; } hashtable_t; void hash_init(hashtable_t *t); void hash_free(hashtable_t *t); int32_t hash_findcase(hashtable_t *t, const char *s); int32_t hash_find(hashtable_t *t, const char *s); void hash_replace(hashtable_t *t, const char *s, int32_t key); void hash_add(hashtable_t *t, const char *s, int32_t key); #ifdef POLYMER # include "polymer.h" #endif #ifdef _MSC_VER #pragma pack() #endif #ifdef __WATCOMC__ #pragma pack(pop) #endif #undef BPACK #ifdef __cplusplus } #endif #endif // __build_h__