From 8077dcd63305963a4cec7a0b29f17306fe39e920 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Tue, 18 May 2010 05:14:17 +0000 Subject: [PATCH] Mapster32 maintenance pack #1 The bulk of this commit is "code rape"--or rather, caressing, rewritten for readability. Actual changes/fixes: - fixed "walking" in 2d mode - fixed DELETE key in OSD in SDL build - main loop in general (timeout for event wait after 200 ms so that highlights blink) - access to some pr_override* variables in m32script (suggested by Roma Loom) - API cleanup (added statics and consts here and there) git-svn-id: https://svn.eduke32.com/eduke32@1644 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/a.m32 | 54 +- polymer/eduke32/build/include/baselayer.h | 1 + polymer/eduke32/build/include/build.h | 20 +- polymer/eduke32/build/include/editor.h | 21 +- polymer/eduke32/build/include/m32script.h | 2 +- polymer/eduke32/build/include/osd.h | 1 + polymer/eduke32/build/include/polymost.h | 2 +- polymer/eduke32/build/src/build.c | 2559 +++++------ polymer/eduke32/build/src/config.c | 2 +- polymer/eduke32/build/src/engine.c | 6 +- polymer/eduke32/build/src/osd.c | 14 +- polymer/eduke32/build/src/polymost.c | 2 +- polymer/eduke32/build/src/sdlayer.c | 66 +- polymer/eduke32/build/src/winlayer.c | 5 + polymer/eduke32/source/astub.c | 4853 ++++++++------------- polymer/eduke32/source/m32def.c | 17 + polymer/eduke32/source/m32def.h | 2 + polymer/eduke32/source/m32exec.c | 24 + polymer/eduke32/source/m32vars.c | 38 +- polymer/eduke32/source/mapster32.h | 115 +- polymer/eduke32/source/old.diff | 177 + 21 files changed, 3469 insertions(+), 4512 deletions(-) create mode 100644 polymer/eduke32/source/old.diff diff --git a/polymer/eduke32/a.m32 b/polymer/eduke32/a.m32 index a5f259766..5a8880d5f 100644 --- a/polymer/eduke32/a.m32 +++ b/polymer/eduke32/a.m32 @@ -12,6 +12,10 @@ gamevar m 0 1 gamevar p 0 1 gamevar q 0 1 +gamevar gi 0 0 +gamevar gj 0 0 +gamevar gk 0 0 + gamevar tmp 0 0 gamevar davr 65536 0 @@ -50,6 +54,17 @@ definequote 17 PICNUM: definequote 18 NUMBER KEY: %d (SCANCODE: %d) +// Corruption checker +definequote 19 PANIC!!! SECTOR OR WALL LIMIT EXCEEDED!!! +definequote 20 SECTOR[%d].WALLPTR=%d out of range: numwalls=%d!!! +definequote 21 SECTOR[%d].WALLPTR=%d inconsistent, expected %d!!! +definequote 22 SECTOR[%d]: wallptr+wallnum=%d out of range: numwalls=%d!!! +definequote 23 WALL[%d].POINT2=%d out of range: sector[%d].wallptr=%d, endwall=%d!!! +definequote 24 WALL[%d].NEXTWALL=%d out of range: numwalls=%d!!! +definequote 25 WALL[%d].NEXTSECTOR=%d out of range: numsectors=%d!!! + +definequote 26 FLOAT ACCESS TEST + gamearray ar 128 gamearray parm 8 @@ -78,6 +93,16 @@ defstate tests ife i 5 break } ife i 5 quote 0 else quote 1 + + quote 26 + set tmp pr_parallaxscale + + set gi tmp set gj tmp set gk tmp + al gi al gj al gk + ftoi gi 20 ftoi gj 200 ftoi gk 2000 + al gi al gj al gk + mul gk 2 + itof gk 2000 ends // prints out maphack light definitions based on SE lights in map @@ -112,10 +137,30 @@ ends // convenient polymer SE light manipulation with keypad keys defstate fiddlewithlights + ifn searchstat 0 ifn searchstat 4 nullop + else + { + // polymer override parallaxscale + set j 0 + ifhitkey KEY_KP8 set j 1 + ifhitkey KEY_KP5 set j -1 + ifeithershift nullop else mul j 10 + + ifn j 0 + { + set k pr_parallaxscale // also available: ~bias, specularfactor, ~power + ftoi k 2000000 // must convert to scaled integer + add k j + itof k 2000000 // convert back + set pr_parallaxscale k + } + + } + ife searchstat 3 ife sprite[searchwall].picnum SECTOREFFECTOR ifge sprite[searchwall].lotag 49 ifle sprite[searchwall].lotag 50 { - set i searchwall, seti i + set i searchwall, seti i // set current sprite = targeted sprite // horiz ifeithershift set j 1 else set j 10 @@ -531,13 +576,6 @@ defstate jumptosec // (tmp) ends // Map corruption checker -definequote 19 PANIC!!! SECTOR OR WALL LIMIT EXCEEDED!!! -definequote 20 SECTOR[%d].WALLPTR=%d out of range: numwalls=%d!!! -definequote 21 SECTOR[%d].WALLPTR=%d inconsistent, expected %d!!! -definequote 22 SECTOR[%d]: wallptr+wallnum=%d out of range: numwalls=%d!!! -definequote 23 WALL[%d].POINT2=%d out of range: sector[%d].wallptr=%d, endwall=%d!!! -definequote 24 WALL[%d].NEXTWALL=%d out of range: numwalls=%d!!! -definequote 25 WALL[%d].NEXTSECTOR=%d out of range: numsectors=%d!!! gamevar ewall 0 0 gamevar endwall 0 0 diff --git a/polymer/eduke32/build/include/baselayer.h b/polymer/eduke32/build/include/baselayer.h index 88d80f819..476909833 100644 --- a/polymer/eduke32/build/include/baselayer.h +++ b/polymer/eduke32/build/include/baselayer.h @@ -98,6 +98,7 @@ void debugprintf(const char *,...); int32_t handleevents(void); extern inline void idle(void); extern inline void idle_waitevent(void); +extern inline void idle_waitevent_timeout(int32_t timeout); typedef void (*KeyPressCallback)(int32_t,int32_t); typedef void (*MousePressCallback)(int32_t,int32_t); diff --git a/polymer/eduke32/build/include/build.h b/polymer/eduke32/build/include/build.h index f2746638d..d68ffbe0f 100644 --- a/polymer/eduke32/build/include/build.h +++ b/polymer/eduke32/build/include/build.h @@ -414,6 +414,10 @@ OTHER VARIABLES: you call the loadboard function. ***************************************************************************/ +typedef struct { + int32_t x, y; +} vec2_t; + typedef struct { int32_t x, y, z; } vec3_t; @@ -463,8 +467,8 @@ void clearallviews(int32_t dacol); void drawmapview(int32_t dax, int32_t day, int32_t zoome, int16_t ang); void rotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum, int8_t dashade, char dapalnum, char dastat, int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2); void drawline256(int32_t x1, int32_t y1, int32_t x2, int32_t y2, char col); -int32_t printext16(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol, char *name, char fontsize); -void printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol, char *name, char fontsize); +int32_t printext16(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol, const char *name, char fontsize); +void printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol, const char *name, char fontsize); int32_t clipmove(vec3_t *vect, int16_t *sectnum, int32_t xvect, int32_t yvect, int32_t walldist, int32_t ceildist, int32_t flordist, uint32_t cliptype); int32_t clipinsidebox(int32_t x, int32_t y, int16_t wallnum, int32_t walldist); @@ -494,13 +498,13 @@ EXTERN int16_t radarang[1280]; static inline int32_t getangle(int32_t xvect, int32_t yvect) { if ((xvect|yvect) == 0) return(0); - if (xvect == 0) return(512+((yvect<0)<<10)); - if (yvect == 0) return(((xvect<0)<<10)); - if (xvect == yvect) return(256+((xvect<0)<<10)); - if (xvect == -yvect) return(768+((xvect>0)<<10)); + if (xvect == 0) return 512+((yvect<0)<<10); + if (yvect == 0) return ((xvect<0)<<10); + if (xvect == yvect) return 256+((xvect<0)<<10); + if (xvect == -yvect) return 768+((xvect>0)<<10); if (klabs(xvect) > klabs(yvect)) - return(((radarang[640+scale(160,yvect,xvect)]>>6)+((xvect<0)<<10))&2047); - return(((radarang[640-scale(160,xvect,yvect)]>>6)+512+((yvect<0)<<10))&2047); + return ((radarang[640+scale(160,yvect,xvect)]>>6)+((xvect<0)<<10))&2047; + return ((radarang[640-scale(160,xvect,yvect)]>>6)+512+((yvect<0)<<10))&2047; } void rotatepoint(int32_t xpivot, int32_t ypivot, int32_t x, int32_t y, int16_t daang, int32_t *x2, int32_t *y2); diff --git a/polymer/eduke32/build/include/editor.h b/polymer/eduke32/build/include/editor.h index dac63d174..b5954819f 100644 --- a/polymer/eduke32/build/include/editor.h +++ b/polymer/eduke32/build/include/editor.h @@ -90,11 +90,14 @@ int32_t writesetup(const char *fn); // from config.c void editinput(void); void clearmidstatbar16(void); -int32_t _getnumber256(char *namestart, int32_t num, int32_t maxnumber, char sign, void *(func)(int32_t)); +int32_t _getnumber256(const char *namestart, int32_t num, int32_t maxnumber, char sign, void *(func)(int32_t)); #define getnumber256(namestart, num, maxnumber, sign) _getnumber256(namestart, num, maxnumber, sign, NULL) -int32_t _getnumber16(char *namestart, int32_t num, int32_t maxnumber, char sign, void *(func)(int32_t)); +int32_t _getnumber16(const char *namestart, int32_t num, int32_t maxnumber, char sign, void *(func)(int32_t)); #define getnumber16(namestart, num, maxnumber, sign) _getnumber16(namestart, num, maxnumber, sign, NULL) -void printmessage256(int32_t x, int32_t y, char *name); +void printmessage256(int32_t x, int32_t y, const char *name); + +// like snprintf, but pads the output buffer with 'fill' at the end +int32_t snfillprintf(char *outbuf, size_t bufsiz, int32_t fill, const char *fmt, ...); void _printmessage16(const char *fmt, ...); extern int32_t lastpm16time; @@ -115,6 +118,18 @@ int32_t getpointhighlight(int32_t xplc, int32_t yplc, int32_t point); void test_map(int32_t mode); + +#define NEXTWALL(i) (wall[wall[i].nextwall]) +#define POINT2(i) (wall[wall[i].point2]) +#define SPRITESEC(j) (sector[sprite[j].sectnum]) + +static inline int32_t wallength(int16_t i) +{ + int32_t dax = POINT2(i).x - wall[i].x; + int32_t day = POINT2(i).y - wall[i].y; + return ksqrt(dax*dax + day*day); +} + #ifdef __cplusplus } #endif diff --git a/polymer/eduke32/build/include/m32script.h b/polymer/eduke32/build/include/m32script.h index 9b2e5fa72..bcc06ecf4 100644 --- a/polymer/eduke32/build/include/m32script.h +++ b/polymer/eduke32/build/include/m32script.h @@ -118,7 +118,7 @@ enum GamevarFlags_t { GAMEVAR_SYSTEM = 0x00000800, // cannot change mode flags...(only default value) GAMEVAR_READONLY = 0x00001000, // values are read-only (no setvar allowed) GAMEVAR_INTPTR = 0x00002000, // plValues is a pointer to an int32_t - + GAMEVAR_FLOATPTR = 0x00004000, // plValues is a pointer to a float GAMEVAR_SHORTPTR = 0x00008000, // plValues is a pointer to a short GAMEVAR_CHARPTR = 0x00010000, // plValues is a pointer to a char // GAMEVAR_NORESET = 0x00020000, // var values are not reset when restoring map state diff --git a/polymer/eduke32/build/include/osd.h b/polymer/eduke32/build/include/osd.h index 399561d2c..4aa5e6fe4 100644 --- a/polymer/eduke32/build/include/osd.h +++ b/polymer/eduke32/build/include/osd.h @@ -80,6 +80,7 @@ char *OSD_GetTextPtr(void); char *OSD_GetFmtPtr(void); int32_t OSD_GetCols(void); +int32_t OSD_IsMoving(void); // initializes things void OSD_Init(void); diff --git a/polymer/eduke32/build/include/polymost.h b/polymer/eduke32/build/include/polymost.h index 2aad8bfb7..e4e2d1617 100644 --- a/polymer/eduke32/build/include/polymost.h +++ b/polymer/eduke32/build/include/polymost.h @@ -49,7 +49,7 @@ void polymost_glreset(void); void gltexinvalidate(int32_t dapicnum, int32_t dapalnum, int32_t dameth); void gltexinvalidateall(void); void gltexinvalidate8(void); -int32_t polymost_printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol, char *name, char fontsize); +int32_t polymost_printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol, const char *name, char fontsize); extern float curpolygonoffset; diff --git a/polymer/eduke32/build/src/build.c b/polymer/eduke32/build/src/build.c index 0f1dc78a7..0bab6720e 100644 --- a/polymer/eduke32/build/src/build.c +++ b/polymer/eduke32/build/src/build.c @@ -67,7 +67,7 @@ uint8_t buildkeys[NUMBUILDKEYS] = vec3_t pos; int32_t horiz = 100; -int32_t mousexsurp = 0, mouseysurp = 0; +static int32_t mousexsurp = 0, mouseysurp = 0; int16_t ang, cursectnum; int32_t hvel; @@ -148,8 +148,9 @@ static int32_t currentlist=0; static int32_t fillist[640]; -int32_t mousx, mousy; +static int32_t mousx, mousy; int16_t prefixtiles[16] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + /* static char scantoasc[128] = { @@ -174,6 +175,13 @@ static char scantoascwithshift[128] = 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, }; */ + +#define eitherALT (keystatus[0x38]|keystatus[0xb8]) +#define eitherCTRL (keystatus[0x1d]|keystatus[0x9d]) +#define eitherSHIFT (keystatus[0x2a]|keystatus[0x36]) + +#define DOWN_BK(BuildKey) (keystatus[buildkeys[BK_##BuildKey]]) + int32_t pk_turnaccel=16; int32_t pk_turndecel=12; int32_t pk_uedaccel=3; @@ -181,17 +189,18 @@ int32_t pk_uedaccel=3; char lastpm16buf[156]; char changechar(char dachar, int32_t dadir, char smooshyalign, char boundcheck); -int32_t adjustmark(int32_t *xplc, int32_t *yplc, int16_t danumwalls); -int32_t checkautoinsert(int32_t dax, int32_t day, int16_t danumwalls); +static int32_t adjustmark(int32_t *xplc, int32_t *yplc, int16_t danumwalls); +static void locktogrid(int32_t *dax, int32_t *day); +static int32_t checkautoinsert(int32_t dax, int32_t day, int16_t danumwalls); void keytimerstuff(void); -int32_t clockdir(int16_t wallstart); -void flipwalls(int16_t numwalls, int16_t newnumwalls); -void insertpoint(int16_t linehighlight, int32_t dax, int32_t day); -void deletepoint(int16_t point); -int32_t deletesector(int16_t sucksect); +static int32_t clockdir(int16_t wallstart); +static void flipwalls(int16_t numwalls, int16_t newnumwalls); +static void insertpoint(int16_t linehighlight, int32_t dax, int32_t day); +static void deletepoint(int16_t point); +static int32_t deletesector(int16_t sucksect); int32_t checksectorpointer(int16_t i, int16_t sectnum); void fixrepeats(int16_t i); -int16_t loopinside(int32_t x, int32_t y, int16_t startwall); +static int16_t loopinside(int32_t x, int32_t y, int16_t startwall); int32_t fillsector(int16_t sectnum, char fillcolor); int16_t whitelinescan(int16_t dalinehighlight); void printcoords16(int32_t posxe, int32_t posye, int16_t ange); @@ -201,28 +210,33 @@ void showwalldata(int16_t wallnum); void showspritedata(int16_t spritenum); int32_t drawtilescreen(int32_t pictopleft, int32_t picbox); void overheadeditor(void); -int32_t getlinehighlight(int32_t xplc, int32_t yplc, int32_t line); +static int32_t getlinehighlight(int32_t xplc, int32_t yplc, int32_t line); void fixspritesectors(void); -int32_t movewalls(int32_t start, int32_t offs); +static int32_t movewalls(int32_t start, int32_t offs); int32_t loadnames(void); void updatenumsprites(void); -void getclosestpointonwall(int32_t x, int32_t y, int32_t dawall, int32_t *nx, int32_t *ny); -void initcrc(void); +static void getclosestpointonwall(int32_t x, int32_t y, int32_t dawall, int32_t *nx, int32_t *ny); +static void initcrc(void); void AutoAlignWalls(int32_t nWall0, int32_t ply); int32_t gettile(int32_t tilenum); -int32_t menuselect(void); +static int32_t menuselect(void); +static int32_t menuselect_pk(int32_t); //PK -int32_t menuselect_pk(int32_t); //PK - -int32_t getfilenames(char *path, char *kind); -void clearfilenames(void); +static int32_t getfilenames(const char *path, const char *kind); +static void clearfilenames(void); void loadmhk(); extern int32_t map_revision; extern int32_t map_undoredo(int32_t dir); extern void map_undoredo_free(void); -void clearkeys(void) { memset(keystatus,0,sizeof(keystatus)); } +void clearkeys(void) { Bmemset(keystatus,0,sizeof(keystatus)); } + +static inline void bclamp(int32_t *x, int32_t mi, int32_t ma) +{ + if (*x>ma) *x=ma; + if (*x 0) //F12 { - screencapture("captxxxx.tga",keystatus[0x2a]|keystatus[0x36]); + screencapture("captxxxx.tga",eitherSHIFT); keystatus[88] = 0; }*/ @@ -786,10 +811,9 @@ void editinput(void) // horiz--; // if (mousx && !(mousx/2)) // ang++; - if (horiz > 299) - horiz = 299; - if (horiz < -99) - horiz = -99; + + bclamp(&horiz, -99, 299); + if (mlook == 1) { searchx = xdim>>1; @@ -804,10 +828,9 @@ void editinput(void) osearchy = searchy; searchx += mousx; searchy += mousy; - if (searchx < 12) searchx = 12; - if (searchy < 12) searchy = 12; - if (searchx > xdim-13) searchx = xdim-13; - if (searchy > ydim-13) searchy = ydim-13; + + bclamp(&searchx, 12, xdim-13); + bclamp(&searchy, 12, ydim-13); } } @@ -820,48 +843,52 @@ void editinput(void) // if (keystatus[0x43] > 0) ang--; // if (keystatus[0x44] > 0) ang++; - if (keystatus[0x43]) + if (keystatus[0x43]) // F9 { mhk=1; loadmhk(); keystatus[0x43] = 0; } - if (keystatus[0x44]) + if (keystatus[0x44]) // F10 { - memset(spriteext, 0, sizeof(spriteext_t) * MAXSPRITES); - memset(spritesmooth, 0, sizeof(spritesmooth_t) *(MAXSPRITES+MAXUNIQHUDID)); + Bmemset(spriteext, 0, sizeof(spriteext_t) * MAXSPRITES); + Bmemset(spritesmooth, 0, sizeof(spritesmooth_t) *(MAXSPRITES+MAXUNIQHUDID)); mhk=0; initprintf("Maphacks disabled\n"); keystatus[0x44] = 0; } + begindrawing(); //{{{ - if (mhk)printext256(0,16,whitecol,0,(mhk==1)?"Maphacks ON":"Maphacks ON (not found)",0); + if (mhk) + printext256(0,16,whitecol,0,(mhk==1)?"Maphacks ON":"Maphacks ON (not found)",0); enddrawing(); //}}} if (angvel != 0) //ang += angvel * constant { //ENGINE calculates angvel for you doubvel = synctics; - if (keystatus[buildkeys[BK_RUN]]) //Lt. shift makes turn velocity 50% faster + if (DOWN_BK(RUN)) //Lt. shift makes turn velocity 50% faster doubvel += (synctics>>1); ang += ((angvel*doubvel)>>4); ang = (ang+2048)&2047; } if ((vel|svel) != 0) { - doubvel = synctics; - if (keystatus[buildkeys[BK_RUN]]) //Lt. shift doubles forward velocity - doubvel += synctics; - xvect = 0, yvect = 0; + //Lt. shift doubles forward velocity + doubvel = (1+(DOWN_BK(RUN)))*synctics; + + xvect = 0; + yvect = 0; + if (vel != 0) { - xvect += ((vel*doubvel*(int32_t)sintable[(ang+2560)&2047])>>3); - yvect += ((vel*doubvel*(int32_t)sintable[(ang+2048)&2047])>>3); + xvect += (vel*doubvel*(int32_t)sintable[(ang+2560)&2047])>>3; + yvect += (vel*doubvel*(int32_t)sintable[(ang+2048)&2047])>>3; } if (svel != 0) { - xvect += ((svel*doubvel*(int32_t)sintable[(ang+2048)&2047])>>3); - yvect += ((svel*doubvel*(int32_t)sintable[(ang+1536)&2047])>>3); + xvect += (svel*doubvel*(int32_t)sintable[(ang+2048)&2047])>>3; + yvect += (svel*doubvel*(int32_t)sintable[(ang+1536)&2047])>>3; } if (noclip) { @@ -871,6 +898,7 @@ void editinput(void) } else clipmove(&pos,&cursectnum,xvect,yvect,128L,4L<<8,4L<<8,CLIPMASK0); } + getzrange(&pos,cursectnum,&hiz,&hihit,&loz,&lohit,128L,CLIPMASK0); /* if (keystatus[0x3a] > 0) @@ -883,33 +911,30 @@ void editinput(void) if (zmode == 0) { - goalz = loz-(kensplayerheight<<8); //playerheight pixels above floor - if (goalz < hiz+(16<<8)) //ceiling&floor too close - goalz = ((loz+hiz)>>1); + goalz = loz-(kensplayerheight<<8); //playerheight pixels above floor + if (goalz < hiz+(16<<8)) //ceiling&floor too close + goalz = (loz+hiz)>>1; goalz += mousz; - if (keystatus[buildkeys[BK_MOVEUP]]) //A (stand high) + + if (DOWN_BK(MOVEUP)) //A (stand high) { - /* - if (keystatus[0x1d]|keystatus[0x9d]) - horiz = max(-100,horiz-((keystatus[buildkeys[BK_RUN]]+1)*synctics*2)); - else - */ + /* if (eitherCTRL) + horiz = max(-100,horiz-((DOWN_BK(RUN)+1)*synctics*2)); + else */ { goalz -= (16<<8); - if (keystatus[buildkeys[BK_RUN]]) //Either shift key + if (DOWN_BK(RUN)) //Either shift key goalz -= (24<<8); } } - if (keystatus[buildkeys[BK_MOVEDOWN]]) //Z (stand low) + if (DOWN_BK(MOVEDOWN)) //Z (stand low) { - /* - if (keystatus[0x1d]|keystatus[0x9d]) - horiz = min(300,horiz+((keystatus[buildkeys[BK_RUN]]+1)*synctics*2)); - else - */ + /* if (eitherCTRL) + horiz = min(300,horiz+((DOWN_BK(RUN)+1)*synctics*2)); + else */ { goalz += (12<<8); - if (keystatus[buildkeys[BK_RUN]]) //Either shift key + if (DOWN_BK(RUN)) //Either shift key goalz += (12<<8); } } @@ -927,11 +952,11 @@ void editinput(void) else { goalz = pos.z; - if (keystatus[buildkeys[BK_MOVEUP]]) //A + if (DOWN_BK(MOVEUP)) //A { - if (keystatus[0x1d]|keystatus[0x9d]) + if (eitherCTRL) { - horiz = max(-100,horiz-((keystatus[buildkeys[BK_RUN]]+1)*synctics*2)); + horiz = max(-100,horiz-((DOWN_BK(RUN)+1)*synctics*2)); } else { @@ -940,15 +965,15 @@ void editinput(void) else { zlock += (4<<8); - keystatus[buildkeys[BK_MOVEUP]] = 0; + DOWN_BK(MOVEUP) = 0; } } } - if (keystatus[buildkeys[BK_MOVEDOWN]]) //Z (stand low) + if (DOWN_BK(MOVEDOWN)) //Z (stand low) { - if (keystatus[0x1d]|keystatus[0x9d]) + if (eitherCTRL) { - horiz = min(300,horiz+((keystatus[buildkeys[BK_RUN]]+1)*synctics*2)); + horiz = min(300,horiz+((DOWN_BK(RUN)+1)*synctics*2)); } else { @@ -957,26 +982,25 @@ void editinput(void) else if (zlock > 0) { zlock -= (4<<8); - keystatus[buildkeys[BK_MOVEDOWN]] = 0; + DOWN_BK(MOVEDOWN) = 0; } } } if (!noclip) - { - if (goalz < hiz+(4<<8)) goalz = hiz+(4<<8); - if (goalz > loz-(4<<8)) goalz = loz-(4<<8); - } + bclamp(&goalz, hiz+(4<<8), loz-(4<<8)); + if (zmode == 1) goalz = loz-zlock; - if (!noclip && (goalz < hiz+(4<<8))) goalz = ((loz+hiz)>>1); //ceiling&floor too close + if (!noclip && (goalz < hiz+(4<<8))) + goalz = ((loz+hiz)>>1); //ceiling&floor too close if (zmode == 1) pos.z = goalz; if (goalz != pos.z) { - //if (pos.z < goalz) hvel += (32< goalz) hvel -= (32< goalz) hvel = ((synctics*-192)< goalz) hvel -= (32< goalz) hvel = ((synctics*-192)<>1),xdim>>1); rotatepoint(0,0,dax,day,ang,&dax,&day); - hitscan((const vec3_t *)&pos,cursectnum, //Start position + hitscan((const vec3_t *)&pos,cursectnum, //Start position dax,day,(scale(searchy,200,ydim)-horiz)*2000, //vector of 3D ang &hitinfo,CLIPMASK1); @@ -1010,17 +1034,12 @@ void editinput(void) { dax = hitinfo.pos.x; day = hitinfo.pos.y; - if ((gridlock > 0) && (grid > 0)) + if (gridlock && grid > 0) { - if ((searchstat == 0) || (searchstat == 4)) - { + if (searchstat == 0 || searchstat == 4) hitinfo.pos.z = (hitinfo.pos.z&0xfffffc00); - } else - { - dax = ((dax+(1024>>grid))&(0xffffffff<<(11-grid))); - day = ((day+(1024>>grid))&(0xffffffff<<(11-grid))); - } + locktogrid(&dax, &day); } i = insertsprite(hitinfo.hitsect,0); @@ -1038,15 +1057,15 @@ void editinput(void) sprite[i].hitag = 0; sprite[i].extra = -1; - for (k=0; k localartfreq[j]) j = k; + if (localartfreq[j] > 0) sprite[i].picnum = j; else @@ -1066,12 +1085,11 @@ void editinput(void) } sprite[i].picnum = j; } + sprite[i].shade = tempshade; sprite[i].pal = temppal; - sprite[i].xrepeat = tempxrepeat; - sprite[i].yrepeat = tempyrepeat; - if (sprite[i].xrepeat < 1) sprite[i].xrepeat = 1; - if (sprite[i].yrepeat < 1) sprite[i].yrepeat = 1; + sprite[i].xrepeat = max(tempxrepeat, 1); + sprite[i].yrepeat = max(tempyrepeat, 1); sprite[i].cstat = tempcstat; } @@ -1085,12 +1103,12 @@ void editinput(void) getceilzofslope(hitinfo.hitsect,hitinfo.pos.x,hitinfo.pos.y)+j), getflorzofslope(hitinfo.hitsect,hitinfo.pos.x,hitinfo.pos.y)-j); - if ((searchstat == 0) || (searchstat == 4)) + if (searchstat == 0 || searchstat == 4) { sprite[i].cstat = (sprite[i].cstat&~48)|(16+64); if (hitinfo.hitwall >= 0) - sprite[i].ang = ((getangle(wall[wall[hitinfo.hitwall].point2].x-wall[hitinfo.hitwall].x, - wall[wall[hitinfo.hitwall].point2].y-wall[hitinfo.hitwall].y)+512)&2047); + sprite[i].ang = ((getangle(POINT2(hitinfo.hitwall).x-wall[hitinfo.hitwall].x, + POINT2(hitinfo.hitwall).y-wall[hitinfo.hitwall].y)+512)&2047); //Make sure sprite's in right sector if (inside(sprite[i].x,sprite[i].y,sprite[i].sectnum) == 0) @@ -1101,9 +1119,7 @@ void editinput(void) } } else - { - if (tilesizy[sprite[i].picnum] >= 32) sprite[i].cstat |= 1; - } + sprite[i].cstat |= (tilesizy[sprite[i].picnum]>=32); updatenumsprites(); asksave = 1; @@ -1159,10 +1175,10 @@ void editinput(void) if (keystatus[buildkeys[BK_MODE2D_3D]]) // Enter { double gamma = vid_gamma; + keystatus[buildkeys[BK_MODE2D_3D]] = 0; vid_gamma = 1.0; setbrightness(0,palette,0); overheadeditor(); - keystatus[buildkeys[BK_MODE2D_3D]] = 0; vid_gamma = gamma; setbrightness(brightness,palette,0); } @@ -1194,8 +1210,45 @@ char changechar(char dachar, int32_t dadir, char smooshyalign, char boundcheck) return(dachar); } + +////////////////////// OVERHEADEDITOR ////////////////////// + static int32_t newnumwalls=-1; +static void ovh_whiteoutgrab() +{ + int32_t i, j, k, startwall, endwall; + + //White out all bordering lines of grab that are + //not highlighted on both sides + for (i=highlightsectorcnt-1; i>=0; i--) + { + startwall = sector[highlightsector[i]].wallptr; + endwall = startwall + sector[highlightsector[i]].wallnum; + for (j=startwall; j= 0) + { + for (k=highlightsectorcnt-1; k>=0; k--) + if (highlightsector[k] == wall[j].nextsector) + break; + if (k < 0) + { + NEXTWALL(j).nextwall = -1; + NEXTWALL(j).nextsector = -1; + wall[j].nextwall = -1; + wall[j].nextsector = -1; + } + } + } + } +} + +static inline void drawline16base(int32_t bx, int32_t by, int32_t x1, int32_t y1, int32_t x2, int32_t y2, char col) +{ + drawline16(bx+x1, by+y1, bx+x2, by+y2, col); +} + void overheadeditor(void) { char buffer[80], *dabuffer, ch; @@ -1214,7 +1267,8 @@ void overheadeditor(void) walltype *wal; int32_t prefixarg = 0; hitdata_t hitinfo; - int32_t resetsynctics = 0; + int32_t resetsynctics = 0, lasttick=getticks(); + int32_t tsign; //qsetmode640480(); qsetmodeany(xdim2d,ydim2d); @@ -1251,34 +1305,10 @@ void overheadeditor(void) cursectorhighlight = -1; lastpm16time = -1; - //White out all bordering lines of grab that are - //not highlighted on both sides - for (i=highlightsectorcnt-1; i>=0; i--) - { - startwall = sector[highlightsector[i]].wallptr; - endwall = startwall + sector[highlightsector[i]].wallnum; - for (j=startwall; j= 0) - { - for (k=highlightsectorcnt-1; k>=0; k--) - if (highlightsector[k] == wall[j].nextsector) - break; - if (k < 0) - { - wall[wall[j].nextwall].nextwall = -1; - wall[wall[j].nextwall].nextsector = -1; - wall[j].nextwall = -1; - wall[j].nextsector = -1; - } - } - } - } + ovh_whiteoutgrab(); - for (i=0; i<(MAXWALLS>>3); i++) //Clear all highlights - show2dwall[i] = 0; - for (i=0; i<(MAXSPRITES>>3); i++) - show2dsprite[i] = 0; + Bmemset(show2dwall, 0, sizeof(show2dwall)); //Clear all highlights + Bmemset(show2dsprite, 0, sizeof(show2dsprite)); sectorhighlightstat = -1; newnumwalls = -1; @@ -1286,17 +1316,18 @@ void overheadeditor(void) circlewall = -1; circlepoints = 7; bstatus = 0; - keystatus[buildkeys[BK_MODE2D_3D]] = 0; + while ((keystatus[buildkeys[BK_MODE2D_3D]]>>1) == 0) { + if (!((vel|angvel|svel) //DOWN_BK(MOVEFORWARD) || DOWN_BK(MOVEBACKWARD) || DOWN_BK(TURNLEFT) || DOWN_BK(TURNRIGHT) + || DOWN_BK(MOVEUP) || DOWN_BK(MOVEDOWN) || bstatus || OSD_IsMoving())) { - if ((keystatus[buildkeys[BK_MOVEUP]] || (bstatus/*&(16|32)*/) || keystatus[buildkeys[BK_MOVEDOWN]]) == 0) - { - idle_waitevent(); - // have synctics reset to 0 after we've slept to avoid zooming out to the max instantly - resetsynctics = 1; - } + // wait for event, timeout after 200 ms - (last loop time) + idle_waitevent_timeout(200 - min(getticks()-lasttick, 200)); + // have synctics reset to 0 after we've slept to avoid zooming out to the max instantly + resetsynctics = 1; } + lasttick = getticks(); if (handleevents()) { @@ -1336,10 +1367,8 @@ void overheadeditor(void) searchx += mousx; searchy += mousy; - if (searchx < 8) searchx = 8; - if (searchx > xdim-8-1) searchx = xdim-8-1; - if (searchy < 8) searchy = 8; - if (searchy > ydim-8-1) searchy = ydim-8-1; + bclamp(&searchx, 8, xdim-8-1); + bclamp(&searchy, 8, ydim-8-1); /* if (keystatus[0x3b] > 0) pos.x--, keystatus[0x3b] = 0; if (keystatus[0x3c] > 0) pos.x++, keystatus[0x3c] = 0; @@ -1347,11 +1376,12 @@ void overheadeditor(void) if (keystatus[0x3e] > 0) pos.y++, keystatus[0x3e] = 0; if (keystatus[0x43] > 0) ang--, keystatus[0x43] = 0; if (keystatus[0x44] > 0) ang++, keystatus[0x44] = 0; */ + if (angvel != 0) //ang += angvel * constant { //ENGINE calculates angvel for you doubvel = synctics; - if (keystatus[buildkeys[BK_RUN]]) //Lt. shift makes turn velocity 50% faster + if (DOWN_BK(RUN)) //Lt. shift makes turn velocity 50% faster doubvel += (synctics>>1); ang += ((angvel*doubvel)>>4); ang = (ang+2048)&2047; @@ -1359,18 +1389,18 @@ void overheadeditor(void) if ((vel|svel) != 0) { doubvel = synctics; - if (keystatus[buildkeys[BK_RUN]]) //Lt. shift doubles forward velocity + if (DOWN_BK(RUN)) //Lt. shift doubles forward velocity doubvel += synctics; xvect = 0, yvect = 0; if (vel != 0) { - xvect += ((vel*doubvel*(int32_t)sintable[(ang+2560)&2047])>>3); - yvect += ((vel*doubvel*(int32_t)sintable[(ang+2048)&2047])>>3); + xvect += (vel*doubvel*(int32_t)sintable[(ang+2560)&2047])>>3; + yvect += (vel*doubvel*(int32_t)sintable[(ang+2048)&2047])>>3; } if (svel != 0) { - xvect += ((svel*doubvel*(int32_t)sintable[(ang+2048)&2047])>>3); - yvect += ((svel*doubvel*(int32_t)sintable[(ang+1536)&2047])>>3); + xvect += (svel*doubvel*(int32_t)sintable[(ang+2048)&2047])>>3; + yvect += (svel*doubvel*(int32_t)sintable[(ang+1536)&2047])>>3; } if (noclip) { @@ -1399,255 +1429,273 @@ void overheadeditor(void) numwalls = newnumwalls; if (numwalls < 0) numwalls = tempint; - if (keystatus[buildkeys[BK_MOVEUP]] || keystatus[buildkeys[BK_MOVEDOWN]] || mousx || mousy || bstatus || (totalclock & 8) == 0 || newnumwalls>=0) - { - clear2dscreen(); + if (DOWN_BK(MOVEUP) || DOWN_BK(MOVEDOWN) || mousx || mousy || bstatus || (totalclock & 8) == 0 || newnumwalls>=0) + { + clear2dscreen(); - if (graphicsmode) - { - int32_t ii = xyaspect; + if (graphicsmode) + { + int32_t ii = xyaspect; - i = yxaspect; - Bmemset(show2dsector, 255, sizeof(show2dsector)); - setview(0, 0, xdim-1, ydim16-1); - yxaspect = xyaspect = 65536; + i = yxaspect; + Bmemset(show2dsector, 255, sizeof(show2dsector)); + setview(0, 0, xdim-1, ydim16-1); + yxaspect = xyaspect = 65536; - if (graphicsmode == 2) - totalclocklock = totalclock; + if (graphicsmode == 2) + totalclocklock = totalclock; - drawmapview(pos.x, pos.y + scale((65536/zoom), ydim, 240), zoom, 1536); - yxaspect = i; - xyaspect = ii; - } + drawmapview(pos.x, pos.y + scale((65536/zoom), ydim, 240), zoom, 1536); + yxaspect = i; + xyaspect = ii; + } - draw2dgrid(pos.x,pos.y,ang,zoom,grid); + draw2dgrid(pos.x,pos.y,ang,zoom,grid); - ExtPreCheckKeys(); + ExtPreCheckKeys(); - x2 = mulscale14(startposx-pos.x,zoom); //Draw brown arrow (start) - y2 = mulscale14(startposy-pos.y,zoom); - if (((halfxdim16+x2) >= 2) && ((halfxdim16+x2) <= xdim-3)) - if (((midydim16+y2) >= 2) && ((midydim16+y2) <= ydim16-3)) - { - x1 = mulscale11(sintable[(startang+2560)&2047],zoom) / 768; - y1 = mulscale11(sintable[(startang+2048)&2047],zoom) / 768; - begindrawing(); //{{{ - drawline16((halfxdim16+x2)+x1,(midydim16+y2)+y1,(halfxdim16+x2)-x1,(midydim16+y2)-y1,editorcolors[2]); - drawline16((halfxdim16+x2)+x1,(midydim16+y2)+y1,(halfxdim16+x2)+y1,(midydim16+y2)-x1,editorcolors[2]); - drawline16((halfxdim16+x2)+x1,(midydim16+y2)+y1,(halfxdim16+x2)-y1,(midydim16+y2)+x1,editorcolors[2]); - enddrawing(); //}}} - } + { + int32_t cx, cy; - draw2dscreen(pos.x,pos.y,ang,zoom,grid); - VM_OnEvent(EVENT_DRAW2DSCREEN, -1); + x2 = mulscale14(startposx-pos.x,zoom); //Draw brown arrow (start) + y2 = mulscale14(startposy-pos.y,zoom); + cx = halfxdim16+x2; + cy = midydim16+y2; + if ((cx >= 2 && cx <= xdim-3) && (cy >= 2 && cy <= ydim16-3)) + { + x1 = mulscale11(sintable[(startang+2560)&2047],zoom) / 768; + y1 = mulscale11(sintable[(startang+2048)&2047],zoom) / 768; + begindrawing(); //{{{ + drawline16base(cx,cy, x1,y1, -x1,-y1, editorcolors[2]); + drawline16base(cx,cy, x1,y1, +y1,-x1, editorcolors[2]); + drawline16base(cx,cy, x1,y1, -y1,+x1, editorcolors[2]); + enddrawing(); //}}} + } + } - begindrawing(); //{{{ - if (showtags == 1) - { - if (zoom >= 768) - for (i=0; i startwall) - { - dax /= (endwall-startwall+1); - day /= (endwall-startwall+1); - } + draw2dscreen(pos.x,pos.y,ang,zoom,grid); + VM_OnEvent(EVENT_DRAW2DSCREEN, -1); - dax = mulscale14(dax-pos.x,zoom); - day = mulscale14(day-pos.y,zoom); + begindrawing(); //{{{ + if (showtags == 1) + { + if (zoom >= 768) + { + for (i=0; i startwall) + { + dax /= (endwall-startwall+1); + day /= (endwall-startwall+1); + } - x1 = halfxdim16+dax-(Bstrlen(dabuffer)<<1); - y1 = midydim16+day-4; - x2 = x1 + (Bstrlen(dabuffer)<<2)+2; - y2 = y1 + 7; - if ((x1 > 3) && (x2 < xdim) && (y1 > 1) && (y2 < ydim16)) - { - printext16(x1,y1,editorcolors[0],editorcolors[7],dabuffer,1); - drawline16(x1-1,y1-1,x2-3,y1-1,editorcolors[7]); - drawline16(x1-1,y2+1,x2-3,y2+1,editorcolors[7]); + dax = mulscale14(dax-pos.x,zoom); + day = mulscale14(day-pos.y,zoom); - drawline16(x1-2,y1,x1-2,y2,editorcolors[7]); - drawline16(x2-2,y1,x2-2,y2,editorcolors[7]); - drawline16(x2-3,y1,x2-3,y2,editorcolors[7]); - } - } - } + x1 = halfxdim16+dax-(Bstrlen(dabuffer)<<1); + y1 = midydim16+day-4; + x2 = x1 + (Bstrlen(dabuffer)<<2)+2; + y2 = y1 + 7; + if ((x1 > 3) && (x2 < xdim) && (y1 > 1) && (y2 < ydim16)) + { + printext16(x1,y1,editorcolors[0],editorcolors[7],dabuffer,1); + drawline16(x1-1,y1-1, x2-3,y1-1, editorcolors[7]); + drawline16(x1-1,y2+1, x2-3,y2+1, editorcolors[7]); - x3 = divscale14(-halfxdim16,zoom)+pos.x; - y3 = divscale14(-(midydim16-4),zoom)+pos.y; - x4 = divscale14(halfxdim16,zoom)+pos.x; - y4 = divscale14(ydim16-(midydim16-4),zoom)+pos.y; + drawline16(x1-2,y1, x1-2,y2, editorcolors[7]); + drawline16(x2-2,y1, x2-2,y2, editorcolors[7]); + drawline16(x2-3,y1, x2-3,y2, editorcolors[7]); + } + } + } + } - if (newnumwalls >= 0) - { - for (i=newnumwalls; i>=tempint; i--) - wall[i].cstat |= (1<<14); - } + x3 = divscale14(-halfxdim16,zoom)+pos.x; + y3 = divscale14(-(midydim16-4),zoom)+pos.y; + x4 = divscale14(halfxdim16,zoom)+pos.x; + y4 = divscale14(ydim16-(midydim16-4),zoom)+pos.y; - i = numwalls-1; - if (newnumwalls >= 0) i = newnumwalls-1; - for (wal=&wall[i]; i>=0; i--,wal--) - { - if (zoom < 768 && !(wal->cstat & (1<<14))) continue; - //Get average point of wall - dax = ((wal->x+wall[wal->point2].x)>>1); - day = ((wal->y+wall[wal->point2].y)>>1); - if ((dax > x3) && (dax < x4) && (day > y3) && (day < y4)) - { - dabuffer = (char *)ExtGetWallCaption(i); - if (dabuffer[0] != 0) - { - dax = mulscale14(dax-pos.x,zoom); - day = mulscale14(day-pos.y,zoom); - x1 = halfxdim16+dax-(Bstrlen(dabuffer)<<1); - y1 = midydim16+day-4; - x2 = x1 + (Bstrlen(dabuffer)<<2)+2; - y2 = y1 + 7; - if ((x1 > 3) && (x2 < xdim) && (y1 > 1) && (y2 < ydim16)) - { - printext16(x1,y1,editorcolors[0],editorcolors[31],dabuffer,1); - drawline16(x1-1,y1-1,x2-3,y1-1,editorcolors[31]); - drawline16(x1-1,y2+1,x2-3,y2+1,editorcolors[31]); + if (newnumwalls >= 0) + { + for (i=newnumwalls; i>=tempint; i--) + wall[i].cstat |= (1<<14); + } - drawline16(x1-2,y1,x1-2,y2,editorcolors[31]); - drawline16(x2-2,y1,x2-2,y2,editorcolors[31]); - drawline16(x2-3,y1,x2-3,y2,editorcolors[31]); - } - } - } - } + i = numwalls-1; + if (newnumwalls >= 0) + i = newnumwalls-1; + for (wal=&wall[i]; i>=0; i--,wal--) + { + if (zoom < 768 && !(wal->cstat & (1<<14))) continue; + //Get average point of wall + dax = (wal->x+wall[wal->point2].x)>>1; + day = (wal->y+wall[wal->point2].y)>>1; + if ((dax > x3) && (dax < x4) && (day > y3) && (day < y4)) + { + dabuffer = (char *)ExtGetWallCaption(i); + if (dabuffer[0] != 0) + { + dax = mulscale14(dax-pos.x,zoom); + day = mulscale14(day-pos.y,zoom); + x1 = halfxdim16+dax-(Bstrlen(dabuffer)<<1); + y1 = midydim16+day-4; + x2 = x1 + (Bstrlen(dabuffer)<<2)+2; + y2 = y1 + 7; - i = 0; j = numsprites; - if (zoom >= 768) - while ((j > 0) && (i < MAXSPRITES)) - { - if (sprite[i].statnum < MAXSTATUS) - { - dabuffer = (char *)ExtGetSpriteCaption(i); - if (dabuffer[0] != 0) - { - //Get average point of sprite - dax = sprite[i].x; - day = sprite[i].y; + if ((x1 > 3) && (x2 < xdim) && (y1 > 1) && (y2 < ydim16)) + { + printext16(x1,y1,editorcolors[0],editorcolors[31],dabuffer,1); + drawline16(x1-1,y1-1, x2-3,y1-1, editorcolors[31]); + drawline16(x1-1,y2+1, x2-3,y2+1, editorcolors[31]); - dax = mulscale14(dax-pos.x,zoom); - day = mulscale14(day-pos.y,zoom); - x1 = halfxdim16+dax-(Bstrlen(dabuffer)<<1); - y1 = midydim16+day-4; - x2 = x1 + (Bstrlen(dabuffer)<<2)+2; - y2 = y1 + 7; - if ((x1 > 3) && (x2 < xdim) && (y1 > 1) && (y2 < ydim16)) - { - col = 3; - if (spritecol2d[sprite[i].picnum][0]) - col = spritecol2d[sprite[i].picnum][0]; - if ((sprite[i].cstat&1) > 0) - { - col = 5; - if (spritecol2d[sprite[i].picnum][1]) - col = spritecol2d[sprite[i].picnum][1]; - } + drawline16(x1-2,y1, x1-2,y2, editorcolors[31]); + drawline16(x2-2,y1, x2-2,y2, editorcolors[31]); + drawline16(x2-3,y1, x2-3,y2, editorcolors[31]); + } + } + } + } - if ((i == pointhighlight-16384) && (totalclock & 32)) col += (2<<2); + i = 0; j = numsprites; + if (zoom >= 768) + while (j > 0 && i < MAXSPRITES) + { + if (sprite[i].statnum < MAXSTATUS) + { + dabuffer = (char *)ExtGetSpriteCaption(i); + if (dabuffer[0] != 0) + { + //Get average point of sprite + dax = sprite[i].x; + day = sprite[i].y; - printext16(x1,y1,editorcolors[0],editorcolors[col],dabuffer,1); + dax = mulscale14(dax-pos.x,zoom); + day = mulscale14(day-pos.y,zoom); + x1 = halfxdim16+dax-(Bstrlen(dabuffer)<<1); + y1 = midydim16+day-4; + x2 = x1 + (Bstrlen(dabuffer)<<2)+2; + y2 = y1 + 7; - drawline16(x1-1,y1-1,x2-3,y1-1,editorcolors[col]); - drawline16(x1-1,y2+1,x2-3,y2+1,editorcolors[col]); + if ((x1 > 3) && (x2 < xdim) && (y1 > 1) && (y2 < ydim16)) + { + col = 3; + if (spritecol2d[sprite[i].picnum][0]) + col = spritecol2d[sprite[i].picnum][0]; + if ((sprite[i].cstat&1) > 0) + { + col = 5; + if (spritecol2d[sprite[i].picnum][1]) + col = spritecol2d[sprite[i].picnum][1]; + } - drawline16(x1-2,y1,x1-2,y2,editorcolors[col]); - drawline16(x2-2,y1,x2-2,y2,editorcolors[col]); - drawline16(x2-3,y1,x2-3,y2,editorcolors[col]); - } - } - j--; - } - i++; - } - } + if ((i == pointhighlight-16384) && (totalclock & 32)) + col += (2<<2); - printcoords16(pos.x,pos.y,ang); + printext16(x1,y1,editorcolors[0],editorcolors[col],dabuffer,1); - numwalls = tempint; + drawline16(x1-1,y1-1, x2-3,y1-1, editorcolors[col]); + drawline16(x1-1,y2+1, x2-3,y2+1, editorcolors[col]); - if (highlightsectorcnt > 0) - for (i=0; i= 0)col = 11; + if (highlightsectorcnt > 0) + for (i=0; i=0) - { - getclosestpointonwall(mousxplc,mousyplc,(int32_t)linehighlight,&dax,&day); - x2 = mulscale14(dax-pos.x,zoom); - y2 = mulscale14(day-pos.y,zoom); - if (wall[linehighlight].nextsector >= 0) - drawline16(halfxdim16+x2,midydim16+y2,halfxdim16+x2,midydim16+y2,editorcolors[15]); - else - drawline16(halfxdim16+x2,midydim16+y2,halfxdim16+x2,midydim16+y2,editorcolors[5]); - } - enddrawing(); //}}} + Bsprintf(tempbuf,"(%d,%d)",mousxplc,mousyplc); + /* + i = (Bstrlen(tempbuf)<<3)+6; + if ((searchx+i) < (xdim2d-1)) + i = 0; + else i = (searchx+i)-(xdim2d-1); + if ((searchy+16) < (ydim2d-STATUS2DSIZ2-1)) + j = 0; + else j = (searchy+16)-(ydim2d-STATUS2DSIZ2-1); + printext16(searchx+6-i,searchy+6-j,editorcolors[11],-1,tempbuf,0); + */ + _printmessage16(tempbuf); + } + drawline16(searchx,0, searchx,8, editorcolors[15]); + drawline16(0,searchy, 8,searchy, editorcolors[15]); - OSD_Draw(); - } + col = 15-((gridlock<<1)+gridlock); + if (joinsector[0] >= 0) + col = 11; + + drawline16base(searchx,searchy, +0,-8, +0,-1, editorcolors[col]); + drawline16base(searchx,searchy, +1,-8, +1,-1, editorcolors[col]); + drawline16base(searchx,searchy, +0,+2, +0,+9, editorcolors[col]); + drawline16base(searchx,searchy, +1,+2, +1,+9, editorcolors[col]); + drawline16base(searchx,searchy, -8,+0, -1,+0, editorcolors[col]); + drawline16base(searchx,searchy, -8,+1, -1,+1, editorcolors[col]); + drawline16base(searchx,searchy, +2,+0, +9,+0, editorcolors[col]); + drawline16base(searchx,searchy, +2,+1, +9,+1, editorcolors[col]); + + //Draw the white pixel closest to mouse cursor on linehighlight + if (linehighlight>=0) + { + getclosestpointonwall(mousxplc,mousyplc,(int32_t)linehighlight,&dax,&day); + x2 = mulscale14(dax-pos.x,zoom); + y2 = mulscale14(day-pos.y,zoom); + + if (wall[linehighlight].nextsector >= 0) + drawline16base(halfxdim16+x2,midydim16+y2, 0,0, 0,0, editorcolors[15]); + else + drawline16base(halfxdim16+x2,midydim16+y2, 0,0, 0,0, editorcolors[5]); + } + enddrawing(); //}}} + + OSD_Draw(); + } VM_OnEvent(EVENT_PREKEYS2D, -1); ExtCheckKeys(); // TX 20050101, it makes more sense to have this here so keys can be overwritten with new functions in bstub.c // Flip/mirror sector Ed Coolidge - if (keystatus[0x2d]) // X (2D) + if (keystatus[0x2d] || keystatus[0x15]) // X or Y (2D) { + int32_t about_x=keystatus[0x2d]; + + keystatus[0x2d] = keystatus[0x15] = 0; + if (highlightsectorcnt > 0) { k = 0; dax = 0; day = 0; + for (i=0; i 0) && (grid > 0)) - { - dax = ((dax+(1024>>grid))&(0xffffffff<<(11-grid))); - day = ((day+(1024>>grid))&(0xffffffff<<(11-grid))); + if (gridlock && grid > 0) + locktogrid(&dax, &day); // dax = ((dax+(GRIDMAX>>grid))&(0xffffffff-(GRIDMAX>>(grid-1))+1)); // day = ((day+(GRIDMAX>>grid))&(0xffffffff-(GRIDMAX>>(grid-1))+1)); - } for (i=0; i>1; for (w=1; w<=numtoswap; w++) @@ -1725,9 +1785,7 @@ void overheadeditor(void) //make point2 point to next wall in loop for (w=startofloop; w 0) - { - k = 0; - dax = 0; - day = 0; - for (i=0; i 0) - { - dax /= k; - day /= k; - } - k = (keystatus[0x38]|keystatus[0xb8]); //ALT-Y mirror sectors in y - - if ((gridlock > 0) && (grid > 0)) - { - dax = ((dax+(1024>>grid))&(0xffffffff<<(11-grid))); - day = ((day+(1024>>grid))&(0xffffffff<<(11-grid))); - // dax = ((dax+(GRIDMAX>>grid))&(0xffffffff-(GRIDMAX>>(grid-1))+1)); - // day = ((day+(GRIDMAX>>grid))&(0xffffffff-(GRIDMAX>>(grid-1))+1)); - } - - for (i=0; i>1; - for (w=1; w<=numtoswap; w++) - { - Bmemcpy(&tempwall,&wall[startofloop+w],sizeof(walltype)); - Bmemcpy(&wall[startofloop+w],&wall[endofloop-w+1],sizeof(walltype)); - Bmemcpy(&wall[endofloop-w+1],&tempwall,sizeof(walltype)); - } - - //make point2 point to next wall in loop - for (w=startofloop; w= 0) && ((keystatus[0x2a]|keystatus[0x36]) == 0)) + if ((wall[linehighlight].nextwall >= 0) && !eitherSHIFT) { - wall[wall[linehighlight].nextwall].cstat &= ~(1+64); - wall[wall[linehighlight].nextwall].cstat |= (wall[linehighlight].cstat&1); + NEXTWALL(linehighlight).cstat &= ~(1+64); + NEXTWALL(linehighlight).cstat |= (wall[linehighlight].cstat&1); } asksave = 1; } @@ -1931,7 +1872,7 @@ void overheadeditor(void) if (keystatus[0x21]) //F (F alone does nothing in 2D right now) { keystatus[0x21] = 0; - if (keystatus[0x38]|keystatus[0xb8]) //ALT-F (relative alignmment flip) + if (eitherALT) //ALT-F (relative alignmment flip) { linehighlight = getlinehighlight(mousxplc, mousyplc, linehighlight); if (linehighlight >= 0) @@ -1953,7 +1894,7 @@ void overheadeditor(void) hitscan((const vec3_t *)&sprite[i],sprite[i].sectnum, sintable[(sprite[i].ang+2560+1024)&2047], - sintable[(sprite[i].ang+2048+1024)&2047], + sintable[(sprite[i].ang+1024)&2047], 0,&hitinfo,CLIPMASK1); sprite[i].x = hitinfo.pos.x; @@ -1961,7 +1902,8 @@ void overheadeditor(void) sprite[i].z = hitinfo.pos.z; changespritesect(i,hitinfo.hitsect); if (hitinfo.hitwall >= 0) - sprite[i].ang = ((getangle(wall[wall[hitinfo.hitwall].point2].x-wall[hitinfo.hitwall].x,wall[wall[hitinfo.hitwall].point2].y-wall[hitinfo.hitwall].y)+512)&2047); + sprite[i].ang = (getangle(POINT2(hitinfo.hitwall).x - wall[hitinfo.hitwall].x, + POINT2(hitinfo.hitwall).y - wall[hitinfo.hitwall].y)+512)&2047; //Make sure sprite's in right sector if (inside(sprite[i].x,sprite[i].y,sprite[i].sectnum) == 0) @@ -1973,7 +1915,14 @@ void overheadeditor(void) } } - if (keystatus[0x33] || (bstatus&1 && bstatus&32)) // , (2D) + + tsign = 0; + if (keystatus[0x33] || (bstatus&33)==33) // , (2D) + tsign = +1; + if (keystatus[0x34] || (bstatus&17)==17) // . (2D) + tsign = -1; + + if (tsign) { if (highlightsectorcnt > 0) { @@ -1997,15 +1946,12 @@ void overheadeditor(void) day /= k; } - k = (keystatus[0x2a]|keystatus[0x36]); + k = eitherSHIFT; if (k == 0) { - if ((gridlock > 0) && (grid > 0)) - { - dax = ((dax+(1024>>grid))&(0xffffffff<<(11-grid))); - day = ((day+(1024>>grid))&(0xffffffff<<(11-grid))); - } + if (gridlock && grid > 0) + locktogrid(&dax, &day); } for (i=0; i= 16384) { i = pointhighlight-16384; - if (keystatus[0x2a]|keystatus[0x36]) - sprite[i].ang = ((sprite[i].ang+2048-1)&2047); + if (eitherSHIFT) + sprite[i].ang = ((sprite[i].ang-tsign)&2047); else { - sprite[i].ang = ((sprite[i].ang+2048-128)&2047); - keystatus[0x33] = 0; + sprite[i].ang = ((sprite[i].ang-128*tsign)&2047); + keystatus[0x33] = keystatus[0x34] = 0; } - mouseb &= ~32; - bstatus &= ~32; + mouseb &= ~(16|32); + bstatus &= ~(16|32); // clearmidstatbar16(); // showspritedata((int16_t)pointhighlight-16384); } } } - if (keystatus[0x34] || (bstatus&1 && bstatus&16)) // . (2D) - { - if (highlightsectorcnt > 0) - { - k = 0; - dax = 0; - day = 0; - for (i=0; i 0) - { - dax /= k; - day /= k; - } - k = (keystatus[0x2a]|keystatus[0x36]); - - if (k == 0) - { - if ((gridlock > 0) && (grid > 0)) - { - dax = ((dax+(1024>>grid))&(0xffffffff<<(11-grid))); - day = ((day+(1024>>grid))&(0xffffffff<<(11-grid))); - } - } - - for (i=0; i= 16384) - { - i = pointhighlight-16384; - if (keystatus[0x2a]|keystatus[0x36]) - sprite[i].ang = ((sprite[i].ang+2048+1)&2047); - else - { - sprite[i].ang = ((sprite[i].ang+2048+128)&2047); - keystatus[0x34] = 0; - } - - mouseb &= ~16; - bstatus &= ~16; -// clearmidstatbar16(); -// showspritedata((int16_t)pointhighlight-16384); - } - } - } if (keystatus[0x46]) //Scroll lock (set starting position) { startposx = pos.x; @@ -2186,15 +2032,10 @@ void overheadeditor(void) if (keystatus[0x3f]) //F5 { // keystatus[0x3f] = 0; - -// for (i=0; i= 0) { wall[linehighlight].cstat ^= 64; - if ((wall[linehighlight].nextwall >= 0) && ((keystatus[0x2a]|keystatus[0x36]) == 0)) + if ((wall[linehighlight].nextwall >= 0) && !eitherSHIFT) { - wall[wall[linehighlight].nextwall].cstat &= ~64; - wall[wall[linehighlight].nextwall].cstat |= (wall[linehighlight].cstat&64); + NEXTWALL(linehighlight).cstat &= ~64; + NEXTWALL(linehighlight).cstat |= (wall[linehighlight].cstat&64); } asksave = 1; } } - else if (keystatus[0x38]|keystatus[0xb8]) //ALT + else if (eitherALT) //ALT { if (pointhighlight >= 16384) { i = pointhighlight-16384; Bsprintf(buffer,"Sprite (%d) Hi-tag: ",i); sprite[i].hitag = getnumber16(buffer,sprite[i].hitag,65536L,0); -// clearmidstatbar16(); -// showspritedata((int16_t)i); } else if (linehighlight >= 0) { i = linehighlight; Bsprintf(buffer,"Wall (%d) Hi-tag: ",i); wall[i].hitag = getnumber16(buffer,wall[i].hitag,65536L,0); -// clearmidstatbar16(); -// showwalldata((int16_t)i); } } else @@ -2308,8 +2145,6 @@ void overheadeditor(void) { Bsprintf(buffer,"Sector (%d) Hi-tag: ",i); sector[i].hitag = getnumber16(buffer,sector[i].hitag,65536L,0); -// clearmidstatbar16(); -// showsectordata((int16_t)i); break; } } @@ -2324,20 +2159,16 @@ void overheadeditor(void) { Bsprintf(buffer,"Sector (%d) Ceilingpal: ",i); sector[i].ceilingpal = getnumber16(buffer,sector[i].ceilingpal,256L,0); -// clearmidstatbar16(); -// showsectordata((int16_t)i); Bsprintf(buffer,"Sector (%d) Floorpal: ",i); sector[i].floorpal = getnumber16(buffer,sector[i].floorpal,256L,0); -// clearmidstatbar16(); -// showsectordata((int16_t)i); - - // printmessage16(""); break; } } if (keystatus[0x12]) // E (status list) { + keystatus[0x12] = 0; + if (pointhighlight >= 16384) { i = pointhighlight-16384; @@ -2346,10 +2177,7 @@ void overheadeditor(void) // clearmidstatbar16(); // showspritedata((int16_t)i); } - // printmessage16(""); - - keystatus[0x12] = 0; } if (highlightsectorcnt < 0) @@ -2360,41 +2188,36 @@ void overheadeditor(void) { highlightx2 = searchx, highlighty2 = searchy; ydim16 = ydim-STATUS2DSIZ2; - drawline16(highlightx2,highlighty1,highlightx1,highlighty1,editorcolors[5]); - drawline16(highlightx2,highlighty2,highlightx1,highlighty2,editorcolors[5]); - drawline16(highlightx1,highlighty2,highlightx1,highlighty1,editorcolors[5]); - drawline16(highlightx2,highlighty2,highlightx2,highlighty1,editorcolors[5]); + drawline16(highlightx2,highlighty1, highlightx1,highlighty1, editorcolors[5]); + drawline16(highlightx2,highlighty2, highlightx1,highlighty2, editorcolors[5]); + drawline16(highlightx1,highlighty2, highlightx1,highlighty1, editorcolors[5]); + drawline16(highlightx2,highlighty2, highlightx2,highlighty1, editorcolors[5]); } - if (highlightcnt != 0) + else { + highlightcnt = 0; highlightx1 = searchx; highlighty1 = searchy; highlightx2 = searchx; highlighty2 = searchx; - highlightcnt = 0; - for (i=0; i<(MAXWALLS>>3); i++) //Clear all highlights - show2dwall[i] = 0; - for (i=0; i<(MAXSPRITES>>3); i++) - show2dsprite[i] = 0; + Bmemset(show2dwall, 0, sizeof(show2dwall)); + Bmemset(show2dsprite, 0, sizeof(show2dsprite)); } } else { if (highlightcnt == 0) { - getpoint(highlightx1,highlighty1,&highlightx1,&highlighty1); - getpoint(highlightx2,highlighty2,&highlightx2,&highlighty2); - if (highlightx1 > highlightx2) - { - tempint = highlightx1; highlightx1 = highlightx2; highlightx2 = tempint; - } - if (highlighty1 > highlighty2) - { - tempint = highlighty1; highlighty1 = highlighty2; highlighty2 = tempint; - } + getpoint(highlightx1,highlighty1, &highlightx1,&highlighty1); + getpoint(highlightx2,highlighty2, &highlightx2,&highlighty2); - if (keystatus[0x1d]|keystatus[0x9d]) + if (highlightx1 > highlightx2) + swaplong(&highlightx1, &highlightx2); + if (highlighty1 > highlighty2) + swaplong(&highlighty1, &highlighty2); + + if (eitherCTRL) { if ((linehighlight >= 0) && (linehighlight < MAXWALLS)) { @@ -2405,13 +2228,11 @@ void overheadeditor(void) show2dwall[i>>3] |= (1<<(i&7)); for (j=0; j>3] |= (1<<(j&7)); - } + if (j!=i && wall[j].x==wall[i].x && wall[j].y==wall[i].y) + { + highlight[highlightcnt++] = j; + show2dwall[j>>3] |= (1<<(j&7)); + } i = wall[i].point2; } @@ -2421,16 +2242,16 @@ void overheadeditor(void) else { for (i=0; i= highlightx1) && (wall[i].x <= highlightx2)) - if ((wall[i].y >= highlighty1) && (wall[i].y <= highlighty2)) + if (wall[i].x >= highlightx1 && wall[i].x <= highlightx2) + if (wall[i].y >= highlighty1 && wall[i].y <= highlighty2) { highlight[highlightcnt++] = i; show2dwall[i>>3] |= (1<<(i&7)); } for (i=0; i= highlightx1) && (sprite[i].x <= highlightx2)) - if ((sprite[i].y >= highlighty1) && (sprite[i].y <= highlighty2)) + if (sprite[i].x >= highlightx1 && sprite[i].x <= highlightx2) + if (sprite[i].y >= highlighty1 && sprite[i].y <= highlighty2) { highlight[highlightcnt++] = i+16384; show2dsprite[i>>3] |= (1<<(i&7)); @@ -2451,10 +2272,10 @@ void overheadeditor(void) highlightx2 = searchx, highlighty2 = searchy; ydim16 = ydim-STATUS2DSIZ2; begindrawing(); //{{{ - drawline16(highlightx2,highlighty1,highlightx1,highlighty1,editorcolors[10]); - drawline16(highlightx2,highlighty2,highlightx1,highlighty2,editorcolors[10]); - drawline16(highlightx1,highlighty2,highlightx1,highlighty1,editorcolors[10]); - drawline16(highlightx2,highlighty2,highlightx2,highlighty1,editorcolors[10]); + drawline16(highlightx2,highlighty1, highlightx1,highlighty1, editorcolors[10]); + drawline16(highlightx2,highlighty2, highlightx1,highlighty2, editorcolors[10]); + drawline16(highlightx1,highlighty2, highlightx1,highlighty1, editorcolors[10]); + drawline16(highlightx2,highlighty2, highlightx2,highlighty1, editorcolors[10]); enddrawing(); //}}} } if (highlightsectorcnt != 0) @@ -2481,16 +2302,13 @@ void overheadeditor(void) { if (highlightsectorcnt == 0) { - getpoint(highlightx1,highlighty1,&highlightx1,&highlighty1); - getpoint(highlightx2,highlighty2,&highlightx2,&highlighty2); + getpoint(highlightx1,highlighty1, &highlightx1,&highlighty1); + getpoint(highlightx2,highlighty2, &highlightx2,&highlighty2); + if (highlightx1 > highlightx2) - { - tempint = highlightx1; highlightx1 = highlightx2; highlightx2 = tempint; - } + swaplong(&highlightx1, &highlightx2); if (highlighty1 > highlighty2) - { - tempint = highlighty1; highlighty1 = highlighty2; highlighty2 = tempint; - } + swaplong(&highlighty1, &highlighty2); for (i=0; i=0; i--) - { - startwall = sector[highlightsector[i]].wallptr; - endwall = startwall + sector[highlightsector[i]].wallnum; - for (j=startwall; j= 0) - { - for (k=highlightsectorcnt-1; k>=0; k--) - if (highlightsector[k] == wall[j].nextsector) - break; - if (k < 0) - { - wall[wall[j].nextwall].nextwall = -1; - wall[wall[j].nextwall].nextsector = -1; - wall[j].nextwall = -1; - wall[j].nextsector = -1; - } - } - } - } - + ovh_whiteoutgrab(); } } } - if (((bstatus&1) < (oldmousebstatus&1)) && (highlightsectorcnt < 0)) //after dragging + if (((bstatus&1) < (oldmousebstatus&1)) && highlightsectorcnt < 0) //after dragging { - int32_t wallsdrawn = newnumwalls-numwalls; + int32_t wallsdrawn = newnumwalls-numwalls, runi; if (newnumwalls != -1) { @@ -2583,8 +2378,8 @@ void overheadeditor(void) tempint = ((tilesizy[sprite[j].picnum]*sprite[j].yrepeat)<<2); - sprite[j].z = max(sprite[j].z,getceilzofslope(sprite[j].sectnum,sprite[j].x,sprite[j].y)+tempint); - sprite[j].z = min(sprite[j].z,getflorzofslope(sprite[j].sectnum,sprite[j].x,sprite[j].y)); + sprite[j].z = max(sprite[j].z, getceilzofslope(sprite[j].sectnum,sprite[j].x,sprite[j].y)+tempint); + sprite[j].z = min(sprite[j].z, getflorzofslope(sprite[j].sectnum,sprite[j].x,sprite[j].y)); } if ((pointhighlight&0xc000) == 0) @@ -2598,46 +2393,39 @@ void overheadeditor(void) day = sprite[pointhighlight&16383].y; } - for (i=numwalls-1; i>=0; i--) //delete points - { - if (wall[i].x == wall[wall[i].point2].x) - if (wall[i].y == wall[wall[i].point2].y) + for (runi=0; runi<2; runi++) + for (i=numwalls-1; i>=0; i--) //delete points + { + if (wall[i].x == POINT2(i).x && wall[i].y == POINT2(i).y) if (sector[sectorofwall((int16_t)i)].wallnum > 3) if (sector[sectorofwall(wall[i].point2)].wallnum > 3) - if (!(wall[i].nextwall == -1 || - (sector[sectorofwall(wall[i].nextwall)].wallnum > 3 && - sector[sectorofwall(wall[wall[i].nextwall].point2)].wallnum > 3))) + { + int32_t b = (wall[i].nextwall == -1 || + (sector[sectorofwall(wall[i].nextwall)].wallnum > 3 && + sector[sectorofwall(NEXTWALL(i).point2)].wallnum > 3)); + if (runi==0 && !b) { printmessage16("Invalid operation, delete or join sector instead."); goto SKIP; } - } - - for (i=numwalls-1; i>=0; i--) //delete points - { - if (wall[i].x == wall[wall[i].point2].x) - if (wall[i].y == wall[wall[i].point2].y) - if (sector[sectorofwall((int16_t)i)].wallnum > 3) - if (sector[sectorofwall(wall[i].point2)].wallnum > 3) - if (wall[i].nextwall == -1 || - (sector[sectorofwall(wall[i].nextwall)].wallnum > 3 && - sector[sectorofwall(wall[wall[i].nextwall].point2)].wallnum > 3)) + else if (runi==1 && b) { deletepoint((int16_t)i); printmessage16("Point deleted."); asksave = 1; } - } + } + } for (i=0; i 0) && (grid > 0)) - { - dax = ((dax+(1024>>grid))&(0xffffffff<<(11-grid))); - day = ((day+(1024>>grid))&(0xffffffff<<(11-grid))); - } - sectorhighlightx = dax; - sectorhighlighty = day; + dax = mousxplc; + day = mousyplc; + if (gridlock && grid > 0) + locktogrid(&dax, &day); + + sectorhighlightx = dax; + sectorhighlighty = day; // break; - } + } } } else if (sectorhighlightstat == 1) { dax = mousxplc; day = mousyplc; - if ((gridlock > 0) && (grid > 0)) - { - dax = ((dax+(1024>>grid))&(0xffffffff<<(11-grid))); - day = ((day+(1024>>grid))&(0xffffffff<<(11-grid))); - } + if (gridlock && grid > 0) + locktogrid(&dax, &day); dax -= sectorhighlightx; day -= sectorhighlighty; @@ -2744,11 +2527,8 @@ SKIP: { dax = mousxplc; day = mousyplc; - if ((gridlock > 0) && (grid > 0)) - { - dax = ((dax+(1024>>grid))&(0xffffffff<<(11-grid))); - day = ((day+(1024>>grid))&(0xffffffff<<(11-grid))); - } + if (gridlock && grid > 0) + locktogrid(&dax, &day); j = 1; if (highlightcnt > 0) @@ -2826,7 +2606,7 @@ SKIP: if ((bstatus&6) > 0) { - if (keystatus[0x1d]|keystatus[0x9d]) + if (eitherCTRL) { int16_t cursectornum; @@ -2842,13 +2622,9 @@ SKIP: ExtEditSpriteData((int16_t)i); } else if ((linehighlight >= 0) && (bstatus&1 || sectorofwall(linehighlight) == cursectornum)) - { ExtEditWallData((int16_t)linehighlight); - } else if (cursectornum >= 0) - { ExtEditSectorData((int16_t)cursectornum); - } } bstatus &= ~6; @@ -2862,7 +2638,7 @@ SKIP: } } - if (circlewall != -1 && (keystatus[0x4a] || (bstatus&32 && !(keystatus[0x1d]|keystatus[0x9d])))) // - + if (circlewall != -1 && (keystatus[0x4a] || ((bstatus&32) && !eitherCTRL))) // - { if (circlepoints > 1) circlepoints--; @@ -2870,7 +2646,7 @@ SKIP: mouseb &= ~32; bstatus &= ~32; } - if (circlewall != -1 && (keystatus[0x4e] || (bstatus&16 && !(keystatus[0x1d]|keystatus[0x9d])))) // + + if (circlewall != -1 && (keystatus[0x4e] || ((bstatus&16) && !eitherCTRL))) // + { if (circlepoints < 63) circlepoints++; @@ -2879,11 +2655,11 @@ SKIP: bstatus &= ~16; } - if ((keystatus[buildkeys[BK_MOVEUP]] || (bstatus&16)) && (zoom < 65536)) + if ((DOWN_BK(MOVEUP) || (bstatus&16)) && zoom < 65536) { zoom += synctics*(zoom>>4); if (zoom < 24) zoom += 2; - if (bstatus&16 && (keystatus[0x38] || keystatus[0xb8])) + if ((bstatus&16) && eitherALT) { searchx = halfxdim16; searchy = midydim16; @@ -2893,10 +2669,10 @@ SKIP: if (zoom > 65536) zoom = 65536; _printmessage16("Zoom: %d",zoom); } - if ((keystatus[buildkeys[BK_MOVEDOWN]] || (bstatus&32)) && (zoom > 8)) + if ((DOWN_BK(MOVEDOWN) || (bstatus&32)) && zoom > 8) { zoom -= synctics*(zoom>>4); - if (bstatus&32 && (keystatus[0x38] || keystatus[0xb8])) + if ((bstatus&32) && eitherALT) { searchx = halfxdim16; searchy = midydim16; @@ -2909,17 +2685,15 @@ SKIP: if (keystatus[0x22]) // G (grid on/off) { + keystatus[0x22] = 0; grid++; if (grid == 7) grid = 0; - keystatus[0x22] = 0; } if (keystatus[0x26]) // L (grid lock) { - gridlock = 1-gridlock, keystatus[0x26] = 0; - if (gridlock == 0) - printmessage16("Grid locking off"); - else - printmessage16("Grid locking on"); + keystatus[0x26] = 0; + gridlock = !gridlock; + printmessage16("Grid locking %s", gridlock?"on":"off"); } if (keystatus[0x24]) // J (join sectors) @@ -2948,12 +2722,8 @@ SKIP: while (keystatus[1] == 0) { if (handleevents()) - { - if (quitevent) - { - quitevent = 0; - } - } + quitevent = 0; + idle(); ch = bgetchar(); @@ -3010,7 +2780,7 @@ SKIP: i = wall[i].point2; if (wall[i].nextsector == joinsector[1-joinsectnum]) { - i = wall[wall[i].nextwall].point2; + i = NEXTWALL(i).point2; joinsectnum = 1 - joinsectnum; } } @@ -3043,8 +2813,8 @@ SKIP: { if (wall[i].nextwall >= 0) { - wall[wall[i].nextwall].nextwall = i; - wall[wall[i].nextwall].nextsector = numsectors-1; + NEXTWALL(i).nextwall = i; + NEXTWALL(i).nextsector = numsectors-1; } } @@ -3070,9 +2840,8 @@ SKIP: } } else - { printmessage16("No sectors joined."); - } + joinsector[0] = -1; } else @@ -3097,9 +2866,9 @@ SKIP: break; } - if ((keystatus[0x38]||keystatus[0xb8])&&keystatus[0x1f]) //ALT-S + if (eitherALT && keystatus[0x1f]) //ALT-S { - if ((linehighlight >= 0) && (wall[linehighlight].nextwall == -1)) + if (linehighlight >= 0 && wall[linehighlight].nextwall == -1) { if ((newnumwalls = whitelinescan(linehighlight)) < numwalls) { @@ -3109,8 +2878,8 @@ SKIP: { for (i=numwalls; i 0) && (grid > 0)) - { - dax = ((dax+(1024>>grid))&(0xffffffff<<(11-grid))); - day = ((day+(1024>>grid))&(0xffffffff<<(11-grid))); - } + if (gridlock && grid > 0) + locktogrid(&dax, &day); i = insertsprite(sucksect,0); sprite[i].x = dax, sprite[i].y = day; @@ -3159,15 +2925,15 @@ SKIP: if ((sprite[i].cstat&128) != 0) sprite[i].z -= ((tilesizy[sprite[i].picnum]*sprite[i].yrepeat)<<1); - for (k=0; k localartfreq[j]) j = k; + if (localartfreq[j] > 0) sprite[i].picnum = j; else @@ -3183,11 +2949,11 @@ SKIP: else if (somethingintab == 3) { sprite[i].picnum = temppicnum; - if ((tilesizx[temppicnum] <= 0) || (tilesizy[temppicnum] <= 0)) + if (tilesizx[temppicnum] <= 0 || tilesizy[temppicnum] <= 0) { j = 0; for (k=0; k 0) && (tilesizy[k] > 0)) + if (tilesizx[k] > 0 && tilesizy[k] > 0) { j = k; break; @@ -3196,10 +2962,8 @@ SKIP: } sprite[i].shade = tempshade; sprite[i].pal = temppal; - sprite[i].xrepeat = tempxrepeat; - sprite[i].yrepeat = tempyrepeat; - if (sprite[i].xrepeat < 1) sprite[i].xrepeat = 1; - if (sprite[i].yrepeat < 1) sprite[i].yrepeat = 1; + sprite[i].xrepeat = max(tempxrepeat, 1); + sprite[i].yrepeat = max(tempyrepeat, 1); sprite[i].cstat = tempcstat; } @@ -3233,6 +2997,7 @@ SKIP: { startwall = sector[highlightsector[i]].wallptr; endwall = startwall+sector[highlightsector[i]].wallnum-1; + for (j=startwall; j<=endwall; j++) { if (wall[j].nextwall >= 0) @@ -3286,24 +3051,25 @@ SKIP: { x1 = wall[circlewall].x; y1 = wall[circlewall].y; - x2 = wall[wall[circlewall].point2].x; - y2 = wall[wall[circlewall].point2].y; + x2 = POINT2(circlewall).x; + y2 = POINT2(circlewall).y; x3 = mousxplc; y3 = mousyplc; adjustmark(&x3,&y3,newnumwalls); - tempint1 = dmulscale4(x3-x2,x1-x3,y1-y3,y3-y2); - tempint2 = dmulscale4(y1-y2,x1-x3,y1-y3,x2-x1); + tempint1 = dmulscale4(x3-x2,x1-x3, y1-y3,y3-y2); + tempint2 = dmulscale4(y1-y2,x1-x3, y1-y3,x2-x1); + if (tempint2 != 0) { - int32_t pointsize = 2; + int32_t ps = 2; // pointsize - centerx = (((x1+x2) + scale(y1-y2,tempint1,tempint2))>>1); - centery = (((y1+y2) + scale(x2-x1,tempint1,tempint2))>>1); + centerx = ((x1+x2) + scale(y1-y2,tempint1,tempint2))>>1; + centery = ((y1+y2) + scale(x2-x1,tempint1,tempint2))>>1; dax = mulscale14(centerx-pos.x,zoom); day = mulscale14(centery-pos.y,zoom); - drawline16(halfxdim16+dax-2,midydim16+day-2,halfxdim16+dax+2,midydim16+day+2,editorcolors[14]); - drawline16(halfxdim16+dax-2,midydim16+day+2,halfxdim16+dax+2,midydim16+day-2,editorcolors[14]); + drawline16base(halfxdim16+dax,midydim16+day, -2,-2, +2,+2, editorcolors[14]); + drawline16base(halfxdim16+dax,midydim16+day, -2,+2, +2,-2, editorcolors[14]); circleang1 = getangle(x1-centerx,y1-centery); circleang2 = getangle(x2-centerx,y2-centery); @@ -3316,33 +3082,28 @@ SKIP: k = -((circleang1-circleang2)&2047); } - circlerad = (ksqrt(dmulscale4(centerx-x1,centerx-x1,centery-y1,centery-y1))<<2); + circlerad = ksqrt(dmulscale4(centerx-x1,centerx-x1, centery-y1,centery-y1))<<2; for (i=circlepoints; i>0; i--) { - j = ((circleang1 + scale(i,k,circlepoints+1))&2047); - dax = centerx+mulscale14(sintable[(j+512)&2047],circlerad); - day = centery+mulscale14(sintable[j],circlerad); + j = (circleang1 + scale(i,k,circlepoints+1))&2047; + dax = centerx + mulscale14(sintable[(j+512)&2047],circlerad); + day = centery + mulscale14(sintable[j],circlerad); - if (dax <= -editorgridextent) dax = -editorgridextent; - if (dax >= editorgridextent) dax = editorgridextent; - if (day <= -editorgridextent) day = -editorgridextent; - if (day >= editorgridextent) day = editorgridextent; + bclamp(&dax, -editorgridextent, editorgridextent); + bclamp(&day, -editorgridextent, editorgridextent); if (bad > 0) { - m = 0; - if (wall[circlewall].nextwall >= 0) - if (wall[circlewall].nextwall < circlewall) m = 1; insertpoint(circlewall,dax,day); - circlewall += m; + circlewall += (wall[circlewall].nextwall >= 0 && wall[circlewall].nextwall < circlewall); } dax = mulscale14(dax-pos.x,zoom); day = mulscale14(day-pos.y,zoom); - drawline16(halfxdim16+dax-pointsize,midydim16+day-pointsize,halfxdim16+dax+pointsize,midydim16+day-pointsize,editorcolors[14]); - drawline16(halfxdim16+dax+pointsize,midydim16+day-pointsize,halfxdim16+dax+pointsize,midydim16+day+pointsize,editorcolors[14]); - drawline16(halfxdim16+dax+pointsize,midydim16+day+pointsize,halfxdim16+dax-pointsize,midydim16+day+pointsize,editorcolors[14]); - drawline16(halfxdim16+dax-pointsize,midydim16+day+pointsize,halfxdim16+dax-pointsize,midydim16+day-pointsize,editorcolors[14]); + drawline16base(halfxdim16+dax,midydim16+day, -ps,-ps, +ps,-ps, editorcolors[14]); + drawline16base(halfxdim16+dax,midydim16+day, +ps,-ps, +ps,+ps, editorcolors[14]); + drawline16base(halfxdim16+dax,midydim16+day, +ps,+ps, -ps,+ps, editorcolors[14]); + drawline16base(halfxdim16+dax,midydim16+day, -ps,+ps, -ps,-ps, editorcolors[14]); // drawcircle16(halfxdim16+dax, midydim16+day, 3, 14); } if (bad > 0) @@ -3412,8 +3173,9 @@ SKIP: //check if starting to split a sector if (newnumwalls == numwalls+1) { - dax = ((wall[numwalls].x+mousxplc)>>1); - day = ((wall[numwalls].y+mousyplc)>>1); + dax = (wall[numwalls].x+mousxplc)>>1; + day = (wall[numwalls].y+mousyplc)>>1; + for (i=0; i= 0) - if ((wall[wall[k].point2].x != mousxplc) || (wall[wall[k].point2].y != mousyplc)) - if ((wall[lastwall((int16_t)k)].x != mousxplc) || (wall[lastwall((int16_t)k)].y != mousyplc)) + if (POINT2(k).x != mousxplc || POINT2(k).y != mousyplc) + if (wall[lastwall(k)].x != mousxplc || wall[lastwall(k)].y != mousyplc) { split = 1; splitsect = i; @@ -3448,11 +3211,11 @@ SKIP: { if (wall[i].nextwall >= 0) { - if ((wall[i].x == mousxplc) && (wall[i].y == mousyplc)) - if ((wall[wall[i].point2].x == wall[newnumwalls-1].x) && (wall[wall[i].point2].y == wall[newnumwalls-1].y)) + if (wall[i].x == mousxplc && wall[i].y == mousyplc) + if (POINT2(i).x == wall[newnumwalls-1].x && POINT2(i).y == wall[newnumwalls-1].y) bad = 1; - if ((wall[i].x == wall[newnumwalls-1].x) && (wall[i].y == wall[newnumwalls-1].y)) - if ((wall[wall[i].point2].x == mousxplc) && (wall[wall[i].point2].y == mousyplc)) + if (wall[i].x == wall[newnumwalls-1].x && wall[i].y == wall[newnumwalls-1].y) + if (POINT2(i).x == mousxplc && POINT2(i).y == mousyplc) bad = 1; } } @@ -3609,271 +3372,68 @@ SKIP: endwall = startwall + sector[splitsect].wallnum - 1; // OSD_Printf("numwalls: %d, newnumwalls: %d\n", numwalls, newnumwalls); for (k=startwall; k<=endwall; k++) - if (wall[k].x == wall[newnumwalls-1].x) - if (wall[k].y == wall[newnumwalls-1].y) + if (wall[k].x == wall[newnumwalls-1].x && wall[k].y == wall[newnumwalls-1].y) + { + bad = 0; + if (loopnumofsector(splitsect,splitstartwall) != loopnumofsector(splitsect,(int16_t)k)) + bad = 1; + + if (numwalls+2*(newnumwalls-numwalls-1) > MAXWALLS) { - bad = 0; - if (loopnumofsector(splitsect,splitstartwall) != loopnumofsector(splitsect,(int16_t)k)) - bad = 1; - - if (numwalls+2*(newnumwalls-numwalls-1) > MAXWALLS) - { - if (bad==0) - printmessage16("Splitting sector would exceed wall limit."); - else - printmessage16("Joining sector loops would exceed wall limit."); - newnumwalls--; - break; - } - - if (bad == 0) - { - //SPLIT IT! - //Split splitsect given: startwall, - // new points: numwalls to newnumwalls-2 - - splitendwall = k; - newnumwalls--; //first fix up the new walls - for (i=numwalls; inumwalls; j--) - { - Bmemcpy(&wall[danumwalls],&wall[j],sizeof(walltype)); - wall[danumwalls].nextwall = -1; - wall[danumwalls].nextsector = -1; - wall[danumwalls].point2 = danumwalls+1; - danumwalls++; - } - m = splitstartwall; //copy rest of loop next - while (m != splitendwall) - { - Bmemcpy(&wall[danumwalls],&wall[m],sizeof(walltype)); - wall[danumwalls].point2 = danumwalls+1; - danumwalls++; - m = wall[m].point2; - } - wall[danumwalls-1].point2 = secondstartwall; - - //Add other loops for 2nd sector - loopnum = loopnumofsector(splitsect,splitstartwall); - i = loopnum; - for (j=startwall; j<=endwall; j++) - { - k = loopnumofsector(splitsect,(int16_t)j); - if ((k != i) && (k != loopnum)) - { - i = k; - if (loopinside(wall[j].x,wall[j].y,secondstartwall) == 1) - { - m = j; //copy loop - k = danumwalls; - do - { - Bmemcpy(&wall[danumwalls],&wall[m],sizeof(walltype)); - wall[danumwalls].point2 = danumwalls+1; - danumwalls++; - m = wall[m].point2; - } - while (m != j); - wall[danumwalls-1].point2 = k; - } - } - } - - //fix all next pointers on old sector line - for (j=numwalls; j= 0) - { - wall[wall[j].nextwall].nextwall = j; - if (j < secondstartwall) - wall[wall[j].nextwall].nextsector = numsectors; - else - wall[wall[j].nextwall].nextsector = numsectors+1; - } - } - //set all next pointers on split - for (j=numwalls; j= 0) - checksectorpointer(wall[j].nextwall,wall[j].nextsector); - checksectorpointer((int16_t)j,sectorofwall((int16_t)j)); - } - - //k now safe to use as temp - - for (m=numsectors-2; mnumwalls; j--) - { - Bmemcpy(&wall[danumwalls],&wall[j],sizeof(walltype)); - wall[danumwalls].nextwall = -1; - wall[danumwalls].nextsector = -1; - wall[danumwalls].point2 = danumwalls+1; - danumwalls++; - } - - m = splitstartwall; //copy rest of loop next - do - { - Bmemcpy(&wall[danumwalls],&wall[m],sizeof(walltype)); - wall[danumwalls].point2 = danumwalls+1; - danumwalls++; - m = wall[m].point2; - } - while (m != splitstartwall); - wall[danumwalls-1].point2 = numwalls; - - //Add other loops to sector - loopnum = loopnumofsector(splitsect,splitstartwall); - i = loopnum; - for (j=startwall; j<=endwall; j++) - { - k = loopnumofsector(splitsect,(int16_t)j); - if ((k != i) && (k != loopnumofsector(splitsect,splitstartwall)) && (k != loopnumofsector(splitsect,splitendwall))) + i = k; + if (loopinside(wall[j].x,wall[j].y,numwalls) == 1) { - i = k; - m = j; k = danumwalls; //copy loop + m = j; //copy loop + k = danumwalls; do { Bmemcpy(&wall[danumwalls],&wall[m],sizeof(walltype)); @@ -3885,58 +3445,260 @@ SKIP: wall[danumwalls-1].point2 = k; } } + } - //fix all next pointers on old sector line - for (j=numwalls; jnumwalls; j--) + { + Bmemcpy(&wall[danumwalls],&wall[j],sizeof(walltype)); + wall[danumwalls].nextwall = -1; + wall[danumwalls].nextsector = -1; + wall[danumwalls].point2 = danumwalls+1; + danumwalls++; + } + m = splitstartwall; //copy rest of loop next + while (m != splitendwall) + { + Bmemcpy(&wall[danumwalls],&wall[m],sizeof(walltype)); + wall[danumwalls].point2 = danumwalls+1; + danumwalls++; + m = wall[m].point2; + } + wall[danumwalls-1].point2 = secondstartwall; + + //Add other loops for 2nd sector + loopnum = loopnumofsector(splitsect,splitstartwall); + i = loopnum; + for (j=startwall; j<=endwall; j++) + { + k = loopnumofsector(splitsect,(int16_t)j); + if ((k != i) && (k != loopnum)) { - if (wall[j].nextwall >= 0) + i = k; + if (loopinside(wall[j].x,wall[j].y,secondstartwall) == 1) { - wall[wall[j].nextwall].nextwall = j; - wall[wall[j].nextwall].nextsector = numsectors; + m = j; //copy loop + k = danumwalls; + do + { + Bmemcpy(&wall[danumwalls],&wall[m],sizeof(walltype)); + wall[danumwalls].point2 = danumwalls+1; + danumwalls++; + m = wall[m].point2; + } + while (m != j); + wall[danumwalls-1].point2 = k; } } + } - //copy sector attributes & fix wall pointers - Bmemcpy(§or[numsectors],§or[splitsect],sizeof(sectortype)); - sector[numsectors].wallptr = numwalls; - sector[numsectors].wallnum = danumwalls-numwalls; + //fix all next pointers on old sector line + for (j=numwalls; j= 0) + { + NEXTWALL(j).nextwall = j; + if (j < secondstartwall) + NEXTWALL(j).nextsector = numsectors; + else + NEXTWALL(j).nextsector = numsectors+1; + } + } + //set all next pointers on split + for (j=numwalls; j= 0) + checksectorpointer(wall[j].nextwall,wall[j].nextsector); + checksectorpointer((int16_t)j,sectorofwall((int16_t)j)); + } + + //k now safe to use as temp + + for (m=numsectors-2; m= 0) - checksectorpointer(wall[j].nextwall,wall[j].nextsector); - checksectorpointer((int16_t)j,numsectors-1); - } - - newnumwalls = -1; - printmessage16("Loops joined."); - break; } + + newnumwalls = -1; + printmessage16("Sector split."); + break; } + else + { + //Sector split - actually loop joining + + splitendwall = k; + newnumwalls--; //first fix up the new walls + for (i=numwalls; inumwalls; j--) + { + Bmemcpy(&wall[danumwalls],&wall[j],sizeof(walltype)); + wall[danumwalls].nextwall = -1; + wall[danumwalls].nextsector = -1; + wall[danumwalls].point2 = danumwalls+1; + danumwalls++; + } + + m = splitstartwall; //copy rest of loop next + do + { + Bmemcpy(&wall[danumwalls],&wall[m],sizeof(walltype)); + wall[danumwalls].point2 = danumwalls+1; + danumwalls++; + m = wall[m].point2; + } + while (m != splitstartwall); + wall[danumwalls-1].point2 = numwalls; + + //Add other loops to sector + loopnum = loopnumofsector(splitsect,splitstartwall); + i = loopnum; + for (j=startwall; j<=endwall; j++) + { + k = loopnumofsector(splitsect,(int16_t)j); + if ((k != i) && (k != loopnumofsector(splitsect,splitstartwall)) && (k != loopnumofsector(splitsect,splitendwall))) + { + i = k; + m = j; k = danumwalls; //copy loop + do + { + Bmemcpy(&wall[danumwalls],&wall[m],sizeof(walltype)); + wall[danumwalls].point2 = danumwalls+1; + danumwalls++; + m = wall[m].point2; + } + while (m != j); + wall[danumwalls-1].point2 = k; + } + } + + //fix all next pointers on old sector line + for (j=numwalls; j= 0) + { + NEXTWALL(j).nextwall = j; + NEXTWALL(j).nextsector = numsectors; + } + } + + //copy sector attributes & fix wall pointers + Bmemcpy(§or[numsectors],§or[splitsect],sizeof(sectortype)); + sector[numsectors].wallptr = numwalls; + sector[numsectors].wallnum = danumwalls-numwalls; + + //fix sprites + j = headspritesect[splitsect]; + while (j != -1) + { + k = nextspritesect[j]; + changespritesect(j,numsectors); + j = k; + } + + numsectors++; + + //Back of number of walls of new sector for later + k = danumwalls-numwalls; + + //clear out old sector's next pointers for clean deletesector + numwalls = danumwalls; + for (j=startwall; j<=endwall; j++) + { + wall[j].nextwall = -1; + wall[j].nextsector = -1; + } + deletesector(splitsect); + + //Check pointers + for (j=numwalls-k; j= 0) + checksectorpointer(wall[j].nextwall,wall[j].nextsector); + checksectorpointer((int16_t)j,numsectors-1); + } + + newnumwalls = -1; + printmessage16("Loops joined."); + break; + } + } } } } @@ -3986,42 +3748,27 @@ SKIP: if (keystatus[0x0e]) //Backspace { + keystatus[0x0e] = 0; + if (newnumwalls >= numwalls) { if (newnumwalls > numwalls) - { newnumwalls--; -// asksave = 1; - keystatus[0x0e] = 0; - } - if (newnumwalls == numwalls) - { + else newnumwalls = -1; -// asksave = 1; - keystatus[0x0e] = 0; - } } else { - if (keystatus[buildkeys[BK_RUN]] || keystatus[0x36]) - { - if (--graphicsmode < 0) - graphicsmode = 2; - } - else - { - if (++graphicsmode > 2) - graphicsmode = 0; - } + graphicsmode += (1-2*(DOWN_BK(RUN) || keystatus[0x36]))+3; + graphicsmode %= 3; printmessage16("2D mode textures %s", (graphicsmode == 2)?"enabled w/ animation":graphicsmode?"enabled":"disabled"); - keystatus[0x0e] = 0; } + } - if (keystatus[0xd3] && (keystatus[0x1d]||keystatus[0x9d]) && (numwalls >= 0)) + if (keystatus[0xd3] && eitherCTRL && (numwalls >= 0)) //sector delete { - //sector delete keystatus[0xd3] = 0; sucksect = -1; @@ -4163,20 +3910,14 @@ SKIP: j = 0; //Check to see if point was inserted over another point for (i=numwalls-1; i>=0; i--) //delete points - if (wall[i].x == wall[wall[i].point2].x) - if (wall[i].y == wall[wall[i].point2].y) - { - deletepoint((int16_t)i); - j++; - } + if (wall[i].x == POINT2(i).x && wall[i].y == POINT2(i).y) + { + deletepoint((int16_t)i); + j++; + } for (i=0; i>1); - // day = ((wall[linehighlight].y + wall[wall[linehighlight].point2].y)>>1); + // dax = ((wall[linehighlight].x + POINT2(linehighlight).x)>>1); + // day = ((wall[linehighlight].y + POINT2(linehighlight).y)>>1); // if ((dax != wall[linehighlight].x) || (day != wall[linehighlight].y)) - // if ((dax != wall[wall[linehighlight].point2].x) || (day != wall[wall[linehighlight].point2].y)) + // if ((dax != POINT2(linehighlight).x) || (day != POINT2(linehighlight).y)) // { // insertpoint(linehighlight,dax,day); // printmessage16("Point inserted at midpoint."); @@ -4197,7 +3938,7 @@ SKIP: if (wallsdrawn != -1) { - Bmemcpy(&wall[numwalls],&wall[MAXWALLS-wallsdrawn],sizeof(walltype) * wallsdrawn); + Bmemcpy(&wall[numwalls],&wall[MAXWALLS-wallsdrawn], sizeof(walltype)*wallsdrawn); newnumwalls = numwalls + wallsdrawn; for (i=numwalls; i 0)) //X + if (quickmapcycling && keystatus[0x2d]) //X { - if ((keystatus[0x1d]|keystatus[0x9d]) > 0) //Ctrl + if (eitherCTRL) //Ctrl { nextmap: // bad = 0; - i = menuselect_pk(keystatus[0x2a]>0 ? 0:1); // Left Shift: prev map + i = menuselect_pk(keystatus[0x2a] ? 0:1); // Left Shift: prev map if (i < 0) { if (i == -2) @@ -4338,12 +4079,8 @@ CANCEL: while (keystatus[1] == 0) { if (handleevents()) - { - if (quitevent) - { - quitevent = 0; - } - } + quitevent = 0; + idle(); ch = bgetchar(); @@ -4353,10 +4090,9 @@ CANCEL: highlightsectorcnt = -1; highlightcnt = -1; - for (i=0; i<(MAXWALLS>>3); i++) //Clear all highlights - show2dwall[i] = 0; - for (i=0; i<(MAXSPRITES>>3); i++) - show2dsprite[i] = 0; + //Clear all highlights + Bmemset(show2dwall, 0, sizeof(show2dwall)); + Bmemset(show2dsprite, 0, sizeof(show2dsprite)); for (i=0; i= editorgridextent) pos.x = editorgridextent; - if (pos.y <= -editorgridextent) pos.y = -editorgridextent; - if (pos.y >= editorgridextent) pos.y = editorgridextent; + bclamp(&pos.x, -editorgridextent, editorgridextent); + bclamp(&pos.y, -editorgridextent, editorgridextent); *x = pos.x + divscale14(searchxe-halfxdim16,zoom); *y = pos.y + divscale14(searchye-midydim16,zoom); - if (*x <= -editorgridextent) *x = -editorgridextent; - if (*x >= editorgridextent) *x = editorgridextent; - if (*y <= -editorgridextent) *y = -editorgridextent; - if (*y >= editorgridextent) *y = editorgridextent; + bclamp(x, -editorgridextent, editorgridextent); + bclamp(y, -editorgridextent, editorgridextent); } -int32_t getlinehighlight(int32_t xplc, int32_t yplc, int32_t line) +static int32_t getlinehighlight(int32_t xplc, int32_t yplc, int32_t line) { int32_t i, dst, dist, closest, x1, y1, x2, y2, nx, ny; if (numwalls == 0) return(-1); - if (mouseb & 1) return line; + if (mouseb & 1) + return line; dist = 1024; closest = -1; @@ -4846,8 +4576,8 @@ int32_t getlinehighlight(int32_t xplc, int32_t yplc, int32_t line) //if red line, allow highlighting of both sides x1 = wall[closest].x; y1 = wall[closest].y; - x2 = wall[wall[closest].point2].x; - y2 = wall[wall[closest].point2].y; + x2 = POINT2(closest).x; + y2 = POINT2(closest).y; if (dmulscale32(xplc-x1,y2-y1,-(x2-x1),yplc-y1) >= 0) closest = wall[closest].nextwall; } @@ -4862,7 +4592,8 @@ int32_t getpointhighlight(int32_t xplc, int32_t yplc, int32_t point) if (numwalls == 0) return(-1); - if (mouseb & 1) return point; + if (mouseb & 1) + return point; if (grid < 1) dist = 0; @@ -4886,7 +4617,13 @@ int32_t getpointhighlight(int32_t xplc, int32_t yplc, int32_t point) return(closest); } -int32_t adjustmark(int32_t *xplc, int32_t *yplc, int16_t danumwalls) +static void locktogrid(int32_t *dax, int32_t *day) +{ + *dax = ((*dax+(1024>>grid))&(0xffffffff<<(11-grid))); + *day = ((*day+(1024>>grid))&(0xffffffff<<(11-grid))); +} + +static int32_t adjustmark(int32_t *xplc, int32_t *yplc, int16_t danumwalls) { int32_t i, dst, dist, dax, day, pointlockdist; @@ -4894,12 +4631,13 @@ int32_t adjustmark(int32_t *xplc, int32_t *yplc, int16_t danumwalls) danumwalls = numwalls; pointlockdist = 0; - if ((grid > 0) && (gridlock > 0)) + if (grid > 0 && gridlock) pointlockdist = (128>>grid); dist = pointlockdist; dax = *xplc; day = *yplc; + for (i=0; i 0) && (grid > 0)) - { - dax = ((dax+(1024>>grid))&(0xffffffff<<(11-grid))); - day = ((day+(1024>>grid))&(0xffffffff<<(11-grid))); - } + if (gridlock && grid > 0) + locktogrid(&dax, &day); *xplc = dax; *yplc = day; return(0); } -int32_t checkautoinsert(int32_t dax, int32_t day, int16_t danumwalls) +static int32_t checkautoinsert(int32_t dax, int32_t day, int16_t danumwalls) { int32_t i, x1, y1, x2, y2; if (danumwalls < 0) danumwalls = numwalls; + for (i=0; i= y2) && (y1 <= y0)) return(0); - if ((y1 >= y0) && (y1 <= y2)) return(1); + if (y1 >= y2 && y1 <= y0) return(0); + if (y1 >= y0 && y1 <= y2) return(1); tempint = (x0-x1)*(y2-y1) - (x2-x1)*(y0-y1); if (tempint < 0) @@ -4981,7 +4717,7 @@ int32_t clockdir(int16_t wallstart) //Returns: 0 is CW, 1 is CCW return(1); } -void flipwalls(int16_t numwalls, int16_t newnumwalls) +static void flipwalls(int16_t numwalls, int16_t newnumwalls) { int32_t i, j, nume, tempint; @@ -4995,7 +4731,7 @@ void flipwalls(int16_t numwalls, int16_t newnumwalls) } } -void insertpoint(int16_t linehighlight, int32_t dax, int32_t day) +static void insertpoint(int16_t linehighlight, int32_t dax, int32_t day) { int16_t sucksect; int32_t i, j, k; @@ -5043,7 +4779,7 @@ void insertpoint(int16_t linehighlight, int32_t dax, int32_t day) } } -void deletepoint(int16_t point) +static void deletepoint(int16_t point) { int32_t i, j, k, sucksect; @@ -5059,20 +4795,20 @@ void deletepoint(int16_t point) if (wall[j].nextwall >= 0) { - wall[wall[j].nextwall].nextwall = -1; - wall[wall[j].nextwall].nextsector = -1; + NEXTWALL(j).nextwall = -1; + NEXTWALL(j).nextsector = -1; } if (wall[point].nextwall >= 0) { - wall[wall[point].nextwall].nextwall = -1; - wall[wall[point].nextwall].nextsector = -1; + NEXTWALL(point).nextwall = -1; + NEXTWALL(point).nextsector = -1; } movewalls((int32_t)point,-1L); checksectorpointer((int16_t)j,(int16_t)sucksect); } -int32_t deletesector(int16_t sucksect) +static int32_t deletesector(int16_t sucksect) { int32_t i, j, k, nextk, startwall, endwall; @@ -5103,13 +4839,15 @@ int32_t deletesector(int16_t sucksect) for (i=startwall; i<=endwall; i++) if (wall[i].nextwall != -1) { - wall[wall[i].nextwall].nextwall = -1; - wall[wall[i].nextwall].nextsector = -1; + NEXTWALL(i).nextwall = -1; + NEXTWALL(i).nextsector = -1; } + movewalls(startwall,-j); for (i=0; i= startwall) wall[i].nextsector--; + return(0); } @@ -5126,9 +4864,10 @@ void fixspritesectors(void) { dax = sprite[i].x; day = sprite[i].y; + if (inside(dax,day,sprite[i].sectnum) != 1) { - daz = ((tilesizy[sprite[i].picnum]*sprite[i].yrepeat)<<2); + daz = (tilesizy[sprite[i].picnum]*sprite[i].yrepeat)<<2; for (j=0; j= 0) //Check for early exit { k = wall[i].nextwall; - if ((wall[k].x == x2) && (wall[k].y == y2)) - if ((wall[wall[k].point2].x == x1) && (wall[wall[k].point2].y == y1)) + if (wall[k].x == x2 && wall[k].y == y2) + if (POINT2(k).x == x1 && POINT2(k).y == y1) return(0); } @@ -5199,8 +4938,8 @@ int32_t checksectorpointer(int16_t i, int16_t sectnum) endwall = startwall + sector[j].wallnum - 1; for (k=startwall; k<=endwall; k++) { - if ((wall[k].x == x2) && (wall[k].y == y2)) - if ((wall[wall[k].point2].x == x1) && (wall[wall[k].point2].y == y1)) + if (wall[k].x == x2 && wall[k].y == y2) + if (POINT2(k).x == x1 && POINT2(k).y == y1) if (j != sectnum) { wall[i].nextsector = j; @@ -5215,13 +4954,10 @@ int32_t checksectorpointer(int16_t i, int16_t sectnum) void fixrepeats(int16_t i) { - int32_t dax, day, dist; + int32_t dist = wallength(i); + int32_t day = wall[i].yrepeat; - dax = wall[wall[i].point2].x-wall[i].x; - day = wall[wall[i].point2].y-wall[i].y; - dist = ksqrt(dax*dax+day*day); - dax = wall[i].xrepeat; day = wall[i].yrepeat; - wall[i].xrepeat = (uint8_t)min(max(mulscale10(dist,day),1),255); + wall[i].xrepeat = clamp(mulscale10(dist,day), 1, 255); } @@ -5229,22 +4965,23 @@ int32_t overridepm16y = -1; void clearmidstatbar16(void) { + int32_t x = overridepm16y<0 ? STATUS2DSIZ : overridepm16y; + begindrawing(); ydim16 = ydim; + // clearbuf((char *)(frameplace + (bytesperline*(ydim-STATUS2DSIZ+25L))),(bytesperline*(STATUS2DSIZ-1-(25<<1))) >> 2, 0x08080808l); - if (overridepm16y < 0) - clearbuf((char *)(frameplace + (bytesperline*(ydim-STATUS2DSIZ+25L))),(bytesperline*(STATUS2DSIZ+2-(25<<1))) >> 2, 0x00000000l); - else - clearbuf((char *)(frameplace + (bytesperline*(ydim-overridepm16y+25L))),(bytesperline*(overridepm16y+2-(25<<1))) >> 2, 0x00000000l); + clearbuf((char *)(frameplace + (bytesperline*(ydim-x+25L))), (bytesperline*(STATUS2DSIZ+2-(25<<1))) >> 2, 0x00000000l); + /* drawline16(0,ydim-STATUS2DSIZ,0,ydim-1,editorcolors[7]); - drawline16(xdim-1,ydim-STATUS2DSIZ,xdim-1,ydim-1,editorcolors[7]); + drawline16base(xdim,ydim, -1,-STATUS2DSIZ, -1,-1, editorcolors[7]); */ ydim16 = ydim-STATUS2DSIZ2; enddrawing(); } -void clearministatbar16(void) +static void clearministatbar16(void) { int32_t i, col = whitecol - 21; char tempbuf[32]; @@ -5261,41 +4998,47 @@ void clearministatbar16(void) clearbufbyte((char *)(frameplace + (i*bytesperline)), (ydim-i)*(bytesperline), 0); Bsprintf(tempbuf, "Mapster32" VERSION); - printext16(xdim2d-(Bstrlen(tempbuf)<<3)-3,ydim2d-STATUS2DSIZ2+10L,editorcolors[4],-1,tempbuf,0); - printext16(xdim2d-(Bstrlen(tempbuf)<<3)-2,ydim2d-STATUS2DSIZ2+9L,editorcolors[12],-1,tempbuf,0); + printext16(xdim2d-(Bstrlen(tempbuf)<<3)-3,ydim2d-STATUS2DSIZ2+10L, editorcolors[4],-1,tempbuf,0); + printext16(xdim2d-(Bstrlen(tempbuf)<<3)-2,ydim2d-STATUS2DSIZ2+9L, editorcolors[12],-1,tempbuf,0); enddrawing(); } -int16_t loopinside(int32_t x, int32_t y, int16_t startwall) +static int16_t loopinside(int32_t x, int32_t y, int16_t startwall) { - int32_t x1, y1, x2, y2, tempint; + int32_t x1, y1, x2, y2; int16_t i, cnt; cnt = clockdir(startwall); i = startwall; do { - x1 = wall[i].x; x2 = wall[wall[i].point2].x; - if ((x1 >= x) || (x2 >= x)) + x1 = wall[i].x; + x2 = POINT2(i).x; + + if (x1 >= x || x2 >= x) { - y1 = wall[i].y; y2 = wall[wall[i].point2].y; + y1 = wall[i].y; + y2 = POINT2(i).y; + if (y1 > y2) { - tempint = x1, x1 = x2, x2 = tempint; - tempint = y1, y1 = y2, y2 = tempint; + swaplong(&x1, &x2); + swaplong(&y1, &y2); } - if ((y1 <= y) && (y2 > y)) + if (y1 <= y && y2 > y) if (x1*(y-y2)+x2*(y1-y) <= x*(y1-y2)) cnt ^= 1; } i = wall[i].point2; } while (i != startwall); + return(cnt); } -int32_t numloopsofsector(int16_t sectnum) +#if 0 +static int32_t numloopsofsector(int16_t sectnum) { int32_t i, numloops, startwall, endwall; @@ -5306,8 +5049,9 @@ int32_t numloopsofsector(int16_t sectnum) if (wall[i].point2 < i) numloops++; return(numloops); } +#endif -int32_t _getnumber16(char *namestart, int32_t num, int32_t maxnumber, char sign, void *(func)(int32_t)) +int32_t _getnumber16(const char *namestart, int32_t num, int32_t maxnumber, char sign, void *(func)(int32_t)) { char buffer[80], ch; int32_t n, danum, oldnum; @@ -5372,7 +5116,7 @@ int32_t _getnumber16(char *namestart, int32_t num, int32_t maxnumber, char sign, return(oldnum); } -int32_t _getnumber256(char *namestart, int32_t num, int32_t maxnumber, char sign, void *(func)(int32_t)) +int32_t _getnumber256(const char *namestart, int32_t num, int32_t maxnumber, char sign, void *(func)(int32_t)) { char buffer[80], ch; int32_t n, danum, oldnum; @@ -5383,9 +5127,7 @@ int32_t _getnumber256(char *namestart, int32_t num, int32_t maxnumber, char sign while (keystatus[0x1] == 0) { if (handleevents()) - { - if (quitevent) quitevent = 0; - } + quitevent = 0; drawrooms(pos.x,pos.y,pos.z,ang,horiz,cursectnum); #ifdef SUPERBUILD @@ -5460,7 +5202,7 @@ int32_t _getnumber256(char *namestart, int32_t num, int32_t maxnumber, char sign return(oldnum); } -void clearfilenames(void) +static void clearfilenames(void) { klistfree(finddirs); klistfree(findfiles); @@ -5468,7 +5210,7 @@ void clearfilenames(void) numfiles = numdirs = 0; } -int32_t getfilenames(char *path, char *kind) +static int32_t getfilenames(const char *path, const char *kind) { CACHE1D_FIND_REC *r; @@ -5489,8 +5231,8 @@ int32_t getfilenames(char *path, char *kind) // vvv PK ------------------------------------ // copied off menuselect -const char *g_oldpath=NULL; -int32_t menuselect_pk(int32_t direction) // 20080104: jump to next (direction!=0) or prev (direction==0) file +static const char *g_oldpath=NULL; +static int32_t menuselect_pk(int32_t direction) // 20080104: jump to next (direction!=0) or prev (direction==0) file { const char *chptr; @@ -5504,7 +5246,7 @@ int32_t menuselect_pk(int32_t direction) // 20080104: jump to next (direction!=0 getfilenames(selectedboardfilename, "*.map"); - chptr = strrchr(boardfilename,'/'); // PK + chptr = Bstrrchr(boardfilename,'/'); // PK if (!chptr) chptr=boardfilename; else chptr++; for (; findfileshigh; findfileshigh=findfileshigh->next) { @@ -5515,11 +5257,13 @@ int32_t menuselect_pk(int32_t direction) // 20080104: jump to next (direction!=0 if (direction) { - if (findfileshigh->next) findfileshigh=findfileshigh->next; + if (findfileshigh->next) + findfileshigh=findfileshigh->next; } else { - if (findfileshigh->prev) findfileshigh=findfileshigh->prev; + if (findfileshigh->prev) + findfileshigh=findfileshigh->prev; } Bstrcat(selectedboardfilename, findfileshigh->name); @@ -5528,7 +5272,7 @@ int32_t menuselect_pk(int32_t direction) // 20080104: jump to next (direction!=0 } // ^^^ PK ------------------------------------ -int32_t menuselect(void) +static int32_t menuselect(void) { int32_t listsize = (ydim16-32)/9; int32_t i; @@ -5548,7 +5292,7 @@ int32_t menuselect(void) getfilenames(selectedboardfilename, "*.map"); // PK 20080103: start with last selected map - chptr = strrchr(boardfilename,'/'); + chptr = Bstrrchr(boardfilename,'/'); if (!chptr) chptr=boardfilename; else chptr++; for (; findfileshigh; findfileshigh=findfileshigh->next) { @@ -5568,18 +5312,16 @@ int32_t menuselect(void) clearbuf((char *)frameplace, (bytesperline*ydim16) >> 2, 0l); if (pathsearchmode) - { - strcpy(buffer,"Local filesystem mode; press F for game filesystem."); - } + Bstrcpy(buffer,"Local filesystem mode; press F for game filesystem."); else - { Bsprintf(buffer,"Game filesystem %smode; press F for local filesystem or G for %s.", grponlymode?"GRP-only ":"", grponlymode?"all files":"GRP contents only"); - } - printext16(halfxdim16-(8*strlen(buffer)/2), 4, editorcolors[12],editorcolors[0],buffer,0); + + printext16(halfxdim16-(8*Bstrlen(buffer)/2), 4, editorcolors[12],editorcolors[0],buffer,0); Bsnprintf(buffer,sizeof(buffer)-1,"(%d dirs, %d files) %s",numdirs,numfiles,selectedboardfilename); buffer[sizeof(buffer)-1] = 0; + printext16(8,ydim16-8-1,editorcolors[8],editorcolors[0],buffer,0); if (finddirshigh) @@ -5595,7 +5337,7 @@ int32_t menuselect(void) int32_t c = (dir->type == CACHE1D_FIND_DIR ? 2 : 3); //PK memset(buffer,0,sizeof(buffer)); Bstrncpy(buffer,dir->name,25); - if (strlen(buffer) == 25) + if (Bstrlen(buffer) == 25) buffer[21] = buffer[22] = buffer[23] = '.', buffer[24] = 0; if (dir == finddirshigh) { @@ -5644,14 +5386,14 @@ int32_t menuselect(void) while (ch == 0) { if (handleevents()) - { if (quitevent) { keystatus[1] = 1; quitevent = 0; } - } + idle(); + ch = bgetchar(); { // JBF 20040208: seek to first name matching pressed character @@ -5720,10 +5462,11 @@ int32_t menuselect(void) pathsearchmode = 1-pathsearchmode; if (pathsearchmode) { - strcpy(selectedboardfilename, ""); + Bstrcpy(selectedboardfilename, ""); Bcanonicalisefilename(selectedboardfilename, 0); } - else strcpy(selectedboardfilename, "/"); + else Bstrcpy(selectedboardfilename, "/"); + getfilenames(selectedboardfilename, "*.map"); Bstrcpy(oldpath,selectedboardfilename); } @@ -5745,35 +5488,37 @@ int32_t menuselect(void) { if (currentlist == 0) { - if (finddirshigh && finddirshigh->prev) finddirshigh = finddirshigh->prev; + if (finddirshigh && finddirshigh->prev) + finddirshigh = finddirshigh->prev; } else { - if (findfileshigh && findfileshigh->prev) findfileshigh = findfileshigh->prev; + if (findfileshigh && findfileshigh->prev) + findfileshigh = findfileshigh->prev; } } else if (keystatus[0xd0] /*(ch == 77) || (ch == 80)*/) { if (currentlist == 0) { - if (finddirshigh && finddirshigh->next) finddirshigh = finddirshigh->next; + if (finddirshigh && finddirshigh->next) + finddirshigh = finddirshigh->next; } else { - if (findfileshigh && findfileshigh->next) findfileshigh = findfileshigh->next; + if (findfileshigh && findfileshigh->next) + findfileshigh = findfileshigh->next; } } else if ((ch == 13) && (currentlist == 0)) { if (finddirshigh->type == CACHE1D_FIND_DRIVE) - { - strcpy(selectedboardfilename, finddirshigh->name); - } + Bstrcpy(selectedboardfilename, finddirshigh->name); else - { - strcat(selectedboardfilename, finddirshigh->name); - } - strcat(selectedboardfilename, "/"); + Bstrcat(selectedboardfilename, finddirshigh->name); + + Bstrcat(selectedboardfilename, "/"); + if (pathsearchmode) Bcanonicalisefilename(selectedboardfilename, 1); else @@ -5814,20 +5559,23 @@ int32_t fillsector(int16_t sectnum, char fillcolor) uborder = 0; dborder = ydim16; if (sectnum == -1) - return(0); + return 0; + miny = dborder-1; maxy = uborder; + startwall = sector[sectnum].wallptr; endwall = startwall + sector[sectnum].wallnum - 1; for (z=startwall; z<=endwall; z++) { y1 = (((wall[z].y-pos.y)*zoom)>>14)+midydim16; - y2 = (((wall[wall[z].point2].y-pos.y)*zoom)>>14)+midydim16; + y2 = (((POINT2(z).y-pos.y)*zoom)>>14)+midydim16; if (y1 < miny) miny = y1; if (y2 < miny) miny = y2; if (y1 > maxy) maxy = y1; if (y2 > maxy) maxy = y2; } + if (miny < uborder) miny = uborder; if (maxy >= dborder) maxy = dborder-1; @@ -5838,8 +5586,8 @@ int32_t fillsector(int16_t sectnum, char fillcolor) fillist[0] = lborder; fillcnt = 1; for (z=startwall; z<=endwall; z++) { - x1 = wall[z].x; x2 = wall[wall[z].point2].x; - y1 = wall[z].y; y2 = wall[wall[z].point2].y; + x1 = wall[z].x; x2 = POINT2(z).x; + y1 = wall[z].y; y2 = POINT2(z).y; if (y1 > y2) { tempint = x1; x1 = x2; x2 = tempint; @@ -5860,15 +5608,18 @@ int32_t fillsector(int16_t sectnum, char fillcolor) for (zz=0; zz rborder) break; + if (fillist[z] > rborder) + break; if (fillist[z+1] > rborder) fillist[z+1] = rborder; - drawline16(fillist[z],sy,fillist[z+1],sy,editorcolors[fillcolor]); + drawline16(fillist[z],sy, fillist[z+1],sy, editorcolors[fillcolor]); } } } @@ -5885,6 +5636,7 @@ int16_t whitelinescan(int16_t dalinehighlight) Bmemcpy(§or[numsectors],§or[sucksect],sizeof(sectortype)); sector[numsectors].wallptr = numwalls; sector[numsectors].wallnum = 0; + i = dalinehighlight; newnumwalls = numwalls; do @@ -5895,13 +5647,12 @@ int16_t whitelinescan(int16_t dalinehighlight) j = wall[j].point2; for (k=0; k 0) angvel = max(angvel-pk_turndecel /*12*/,0); - if (svel < 0) svel = min(svel+6,0); - if (svel > 0) svel = max(svel-6,0); - if (vel < 0) vel = min(vel+6,0); - if (vel > 0) vel = max(vel-6,0); + if (angvel < 0) angvel = min(angvel+pk_turndecel, 0); + if (angvel > 0) angvel = max(angvel-pk_turndecel, 0); + if (svel < 0) svel = min(svel+6, 0); + if (svel > 0) svel = max(svel-6, 0); + if (vel < 0) vel = min(vel+6, 0); + if (vel > 0) vel = max(vel-6, 0); /* if(mlook) pos.z -= (horiz-101)*(vel/40); */ } +int32_t snfillprintf(char *outbuf, size_t bufsiz, int32_t fill, const char *fmt, ...) +{ + char tmpstr[256]; + int32_t nwritten, ofs; + va_list va; + + va_start(va, fmt); + nwritten = Bvsnprintf(tmpstr, bufsiz, fmt, va); + va_end(va); + + ofs = min(nwritten, (signed)bufsiz-1); + Bmemset(outbuf, fill, bufsiz-ofs); + + return ofs; +} + void _printmessage16(const char *fmt, ...) { int32_t i, ybase; @@ -6411,7 +6175,7 @@ void _printmessage16(const char *fmt, ...) va_end(va); i = 0; - while ((tmpstr[i] != 0) && (i < 146)) + while (tmpstr[i] && i < 146) { snotbuf[i] = tmpstr[i]; i++; @@ -6426,17 +6190,17 @@ void _printmessage16(const char *fmt, ...) // ybase = (overridepm16y >= 0) ? ydim-overridepm16y : ydim-STATUS2DSIZ+128-8; ybase = ydim-STATUS2DSIZ+128-8; - printext16(/*(overridepm16y >= 0) ? 200L-24 :*/ 8, ybase+8L, whitecol, -1, snotbuf, 0); + printext16(/*(overridepm16y >= 0) ? 200L-24 :*/ 8, ybase+8, whitecol, -1, snotbuf, 0); enddrawing(); } -void printmessage256(int32_t x, int32_t y, char *name) +void printmessage256(int32_t x, int32_t y, const char *name) { - char snotbuf[64]; + char snotbuf[80]; int32_t i; i = 0; - while ((name[i] != 0) && (i < 62)) + while (name[i] && i < 62) { snotbuf[i] = name[i]; i++; @@ -6452,14 +6216,14 @@ void printmessage256(int32_t x, int32_t y, char *name) } //Find closest point (*dax, *day) on wall (dawall) to (x, y) -void getclosestpointonwall(int32_t x, int32_t y, int32_t dawall, int32_t *nx, int32_t *ny) +static void getclosestpointonwall(int32_t x, int32_t y, int32_t dawall, int32_t *nx, int32_t *ny) { walltype *wal; int64_t i, j, dx, dy; wal = &wall[dawall]; - dx = wall[wal->point2].x-wal->x; - dy = wall[wal->point2].y-wal->y; + dx = wall[wal->point2].x - wal->x; + dy = wall[wal->point2].y - wal->y; i = dx*(x-wal->x) + dy*(y-wal->y); if (i <= 0) { *nx = wal->x; *ny = wal->y; return; } j = dx*dx+dy*dy; @@ -6469,7 +6233,7 @@ void getclosestpointonwall(int32_t x, int32_t y, int32_t dawall, int32_t *nx, in *ny = wal->y + ((dy*i)>>30); } -void initcrc(void) +static void initcrc(void) { int32_t i, j, k, a; @@ -6490,7 +6254,7 @@ void initcrc(void) static char visited[MAXWALLS]; -int32_t GetWallZPeg(int32_t nWall) +static int32_t GetWallZPeg(int32_t nWall) { int32_t z=0, nSector, nNextSector; @@ -6518,7 +6282,7 @@ int32_t GetWallZPeg(int32_t nWall) return(z); } -void AlignWalls(int32_t nWall0, int32_t z0, int32_t nWall1, int32_t z1, int32_t nTile) +static void AlignWalls(int32_t nWall0, int32_t z0, int32_t nWall1, int32_t z1, int32_t nTile) { int32_t n; @@ -6573,7 +6337,7 @@ void AutoAlignWalls(int32_t nWall0, int32_t ply) else { //ignore two sided walls that have no visible face - nSector = wall[wall[nWall1].nextwall].nextsector; + nSector = NEXTWALL(nWall1).nextsector; if (getceilzofslope((int16_t)nSector,wall[nWall1].x,wall[nWall1].y) < getceilzofslope((int16_t)nNextSector,wall[nWall1].x,wall[nWall1].y)) visible = 1; @@ -6603,7 +6367,7 @@ void AutoAlignWalls(int32_t nWall0, int32_t ply) } if (wall[nWall1].nextwall < 0) break; - nWall1 = wall[wall[nWall1].nextwall].point2; + nWall1 = NEXTWALL(nWall1).point2; } } @@ -6649,7 +6413,7 @@ void test_map(int32_t mode) } if (current_cwd[0] != '\0') // Temporarily changing back, - chdir(current_cwd); // after checking if file exists. + chdir(current_cwd); // after checking if file exists. if (testplay_addparam) slen = Bstrlen(testplay_addparam); @@ -6674,7 +6438,9 @@ void test_map(int32_t mode) saveboard("autosave.map",&startposx,&startposy,&startposz,&startang,&startsectnum); else saveboard("autosave.map",&pos.x,&pos.y,&pos.z,&ang,&cursectnum); + _printmessage16("Board saved to AUTOSAVE.MAP. Starting the game..."); + showframe(1); uninitmouse(); #ifdef _WIN32 @@ -6702,11 +6468,10 @@ void test_map(int32_t mode) #endif printmessage16("Game process exited"); initmouse(); - Bmemset(keystatus, 0, sizeof(keystatus)); + clearkeys(); Bfree(fullparam); } else printmessage16("Position must be in valid player space to test map!"); - } diff --git a/polymer/eduke32/build/src/config.c b/polymer/eduke32/build/src/config.c index 7767c3aeb..fbbe95b81 100644 --- a/polymer/eduke32/build/src/config.c +++ b/polymer/eduke32/build/src/config.c @@ -59,7 +59,7 @@ extern int16_t brightness; extern int32_t vsync; extern char game_executable[BMAX_PATH]; extern int32_t fullscreen; -extern char option[8]; +extern char option[9]; extern char keys[NUMBUILDKEYS]; extern char remap[256]; extern int32_t remapinit; diff --git a/polymer/eduke32/build/src/engine.c b/polymer/eduke32/build/src/engine.c index 4276788d2..c3b08457a 100644 --- a/polymer/eduke32/build/src/engine.c +++ b/polymer/eduke32/build/src/engine.c @@ -130,7 +130,7 @@ int32_t circlewall=-1; char cachedebug = 0; -qlz_state_compress *state_compress = NULL; +qlz_state_compress *state_compress = NULL; qlz_state_decompress *state_decompress = NULL; #if defined(_MSC_VER) && !defined(NOASM) @@ -11468,7 +11468,7 @@ void draw2dscreen(int32_t posxe, int32_t posye, int16_t ange, int32_t zoome, int // // printext16 // -int32_t printext16(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol, char *name, char fontsize) +int32_t printext16(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol, const char *name, char fontsize) { int32_t stx, i, x, y, charxsiz, ocol = col, obackcol = backcol; char *fontptr, *letptr, *ptr; @@ -11573,7 +11573,7 @@ int32_t printext16(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol, cha // // printext256 // -void printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol, char *name, char fontsize) +void printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol, const char *name, char fontsize) { int32_t stx, i, x, y, charxsiz; char *fontptr, *letptr, *ptr; diff --git a/polymer/eduke32/build/src/osd.c b/polymer/eduke32/build/src/osd.c index 22407c476..2ac24c220 100644 --- a/polymer/eduke32/build/src/osd.c +++ b/polymer/eduke32/build/src/osd.c @@ -253,6 +253,11 @@ int32_t OSD_GetCols(void) return osdcols; } +int32_t OSD_IsMoving(void) +{ + return (osdrowscur!=-1 && osdrowscur!=osdrows); +} + int32_t OSD_GetTextMode(void) { return osdtextmode; @@ -884,7 +889,7 @@ int32_t OSD_HandleChar(char ch) if (osdeditcursor < osdeditlen) osdeditcursor++; return 0; case 8: - case 127: // control h, backspace +// case 127: // control h, backspace if (!osdeditcursor || !osdeditlen) return 0; if ((osdflags & OSD_OVERTYPE) == 0) { @@ -894,6 +899,7 @@ int32_t OSD_HandleChar(char ch) } osdeditcursor--; if (osdeditcursor0) { @@ -1286,7 +1292,7 @@ void OSD_ResizeDisplay(int32_t w, int32_t h) // void OSD_CaptureInput(int32_t cap) { - osdflags = (osdflags & ~(OSD_CAPTURE|OSD_CTRL|OSD_SHIFT)) | (-cap & OSD_CAPTURE); + osdflags = (osdflags & ~(OSD_CAPTURE|OSD_CTRL|OSD_SHIFT)) | (-cap & OSD_CAPTURE); grabmouse(cap == 0); onshowosd(cap); diff --git a/polymer/eduke32/build/src/polymost.c b/polymer/eduke32/build/src/polymost.c index 10697e2de..f236b0433 100644 --- a/polymer/eduke32/build/src/polymost.c +++ b/polymer/eduke32/build/src/polymost.c @@ -5705,7 +5705,7 @@ int32_t polymost_drawtilescreen(int32_t tilex, int32_t tiley, int32_t wallnum, i #endif } -int32_t polymost_printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol, char *name, char fontsize) +int32_t polymost_printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol, const char *name, char fontsize) { #ifndef USE_OPENGL return -1; diff --git a/polymer/eduke32/build/src/sdlayer.c b/polymer/eduke32/build/src/sdlayer.c index 8dc44808a..267c84ea7 100644 --- a/polymer/eduke32/build/src/sdlayer.c +++ b/polymer/eduke32/build/src/sdlayer.c @@ -16,6 +16,11 @@ #include "build.h" #include "osd.h" +#if (SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION < 3) // SDL 1.2 +// for SDL_WaitEventTimeout defined below +#include +#endif + #ifdef USE_OPENGL # include "glbuild.h" #endif @@ -32,6 +37,10 @@ int32_t startwin_idle(void *s) { s=s; return 0; } int32_t startwin_settitle(const char *s) { s=s; return 0; } #endif +/// These can be useful for debugging sometimes... +//#define SDL_WM_GrabInput(x) SDL_WM_GrabInput(SDL_GRAB_OFF) +//#define SDL_ShowCursor(x) SDL_ShowCursor(SDL_ENABLE) + #define SURFACE_FLAGS (SDL_SWSURFACE|SDL_HWPALETTE|SDL_HWACCEL) // undefine to restrict windowed resolutions to conventional sizes @@ -232,6 +241,7 @@ static void attach_debugger_here(void){} static void sighandler(int signum) { + UNREFERENCED_PARAMETER(signum); // if (signum==SIGSEGV) { SDL_WM_GrabInput(SDL_GRAB_OFF); @@ -607,6 +617,9 @@ void grabmouse(char a) void readmousexy(int32_t *x, int32_t *y) { if (!mouseacquired || !appactive || !moustat) { *x = *y = 0; return; } + +// if (mousex|mousey)printf("r:%d,%d\n",mousex,mousey); /// + *x = mousex; *y = mousey; mousex = mousey = 0; @@ -1566,6 +1579,8 @@ int32_t handleevents(void) if (code != scantoasc[OSD_OSDKey()] && ((keyasciififoend+1)&(KEYFIFOSIZ-1)) != keyasciififoplc) { +// printf("got char %d\n",code); + if (OSD_HandleChar(code)) { keyasciififo[keyasciififoend] = code; @@ -1579,7 +1594,7 @@ int32_t handleevents(void) case SDL_KEYDOWN: case SDL_KEYUP: code = keytranslation[ev.key.keysym.scancode]; -// initprintf("got key %d, %d\n",ev.key.keysym.scancode,code); +// printf("got key %d, %d\n",ev.key.keysym.scancode,code); // hook in the osd if (OSD_HandleScanCode(code, (ev.key.type == SDL_KEYDOWN)) == 0) @@ -1645,7 +1660,9 @@ int32_t handleevents(void) } break; */ -#else +#warning "Using SDL 1.3" +#else // SDL 1.3 ^^^ | vvv SDL 1.2 +#warning "Using SDL 1.2" case SDL_KEYDOWN: case SDL_KEYUP: code = keytranslation[ev.key.keysym.sym]; @@ -1654,6 +1671,8 @@ int32_t handleevents(void) (ev.key.keysym.unicode & 0xff80) == 0 && ((keyasciififoend+1)&(KEYFIFOSIZ-1)) != keyasciififoplc) { +// if (ev.type==SDL_KEYDOWN) +// printf("got char %d\n",ev.key.keysym.unicode & 0x7f); if (OSD_HandleChar(ev.key.keysym.unicode & 0x7f)) { keyasciififo[keyasciififoend] = ev.key.keysym.unicode & 0x7f; @@ -1662,6 +1681,8 @@ int32_t handleevents(void) } // hook in the osd +// if (ev.type==SDL_KEYDOWN) +// printf("got key %d\n",code); if (OSD_HandleScanCode(code, (ev.key.type == SDL_KEYDOWN)) == 0) break; @@ -1808,6 +1829,8 @@ int32_t handleevents(void) } } +// if (mousex|mousey) printf("%d,%d\n",mousex,mousey); /// + sampletimer(); if (moustat) @@ -1841,6 +1864,43 @@ inline void idle_waitevent(void) SDL_WaitEvent(NULL); } +#if (SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION < 3) // SDL 1.2 +// from SDL HG, modified +static int32_t SDL_WaitEventTimeout(SDL_Event * event, int32_t timeout) +{ + uint32_t expiration = 0; + + if (timeout > 0) + expiration = SDL_GetTicks() + timeout; + + for (;;) { + SDL_PumpEvents(); + switch (SDL_PeepEvents(event, 1, SDL_GETEVENT, ~0)) { //SDL_FIRSTEVENT, SDL_LASTEVENT)) { + case -1: + return 0; + case 1: + return 1; + case 0: + if (timeout == 0) { + /* Polling and no events, just return */ + return 0; + } + if (timeout > 0 && ((int32_t) (SDL_GetTicks() - expiration) >= 0)) { + /* Timeout expired and no events */ + return 0; + } + SDL_Delay(10); + break; + } + } +} +#endif + +inline void idle_waitevent_timeout(int32_t timeout) +{ + SDL_WaitEventTimeout(NULL, timeout); +} + #if (SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION < 3) // SDL 1.2 static int32_t buildkeytranslationtable(void) { @@ -1975,7 +2035,7 @@ static int32_t buildkeytranslationtable(void) return 0; } -#else // SDL 1.3 +#else // if SDL 1.3 static int32_t buildkeytranslationtable(void) { memset(keytranslation,0,sizeof(keytranslation)); diff --git a/polymer/eduke32/build/src/winlayer.c b/polymer/eduke32/build/src/winlayer.c index 24ead37f3..ecb998ca1 100644 --- a/polymer/eduke32/build/src/winlayer.c +++ b/polymer/eduke32/build/src/winlayer.c @@ -861,6 +861,11 @@ inline void idle_waitevent(void) while (--i); } +inline void idle_waitevent_timeout(int32_t timeout) +{ + idle_waitevent(); +} + inline void idle(void) { idle_waitevent(); diff --git a/polymer/eduke32/source/astub.c b/polymer/eduke32/source/astub.c index 854061b45..37500dedb 100644 --- a/polymer/eduke32/source/astub.c +++ b/polymer/eduke32/source/astub.c @@ -64,7 +64,7 @@ static char *g_grpNamePtr = defaultduke3dgrp; static int32_t fixmapbeforesaving = 1; static int32_t lastsave = -180*60; static int32_t NoAutoLoad = 0; -int32_t spnoclip=1; +static int32_t spnoclip=1; // Sound in Mapster32 static char defaultgamecon[BMAX_PATH] = "game.con"; @@ -78,6 +78,7 @@ static int16_t g_definedsndnum[MAXSOUNDS]; // maps parse order index to g_sound static int16_t g_sndnum[MAXSOUNDS]; // maps current order index to g_sounds index int32_t g_numsounds = 0; + #if !defined(_WIN32) static int32_t usecwd = 0; #endif @@ -89,17 +90,88 @@ static struct strllist } *CommandPaths = NULL, *CommandGrps = NULL; -#define eitherALT (keystatus[KEYSC_LALT]| keystatus[KEYSC_RALT]) -#define eitherCTRL (keystatus[KEYSC_LCTRL]| keystatus[KEYSC_RCTRL]) -#define eitherSHIFT (keystatus[KEYSC_LSHIFT]|keystatus[KEYSC_RSHIFT]) +//////////////////// Key stuff //////////////////// + +#define eitherALT (keystatus[KEYSC_LALT] || keystatus[KEYSC_RALT]) +#define eitherCTRL (keystatus[KEYSC_LCTRL] || keystatus[KEYSC_RCTRL]) +#define eitherSHIFT (keystatus[KEYSC_LSHIFT] || keystatus[KEYSC_RSHIFT]) + +#define PRESSED_KEYSC(Key) (keystatus[KEYSC_##Key] && !(keystatus[KEYSC_##Key]=0)) + + +//////////////////// Aiming //////////////////// #define SEARCH_WALL 0 #define SEARCH_CEILING 1 #define SEARCH_FLOOR 2 #define SEARCH_SPRITE 3 #define SEARCH_MASKWALL 4 -static char *type2str[]={"Wall","Sector","Sector","Sprite","Wall"}; +static const char *Typestr[] = { "Wall", "Ceiling", "Floor", "Sprite", "Wall" }; +static const char *typestr[] = { "wall", "ceiling", "floor", "sprite", "wall" }; +static const char *Typestr_wss[] = { "Wall", "Sector", "Sector", "Sprite", "Wall" }; +static const char *typestr_wss[] = { "wall", "sector", "sector", "sprite", "wall" }; + +//#define AIMED_obj (typestr[searchstat]) + +#define ASSERT_AIMING (searchstat>=0 && searchstat<=4) + +#define AIMING_AT_WALL (searchstat==0) +#define AIMING_AT_CEILING (searchstat==1) +#define AIMING_AT_FLOOR (searchstat==2) +#define AIMING_AT_SPRITE (searchstat==3) +#define AIMING_AT_MASKWALL (searchstat==4) + +#define AIMING_AT_WALL_OR_MASK (AIMING_AT_WALL || AIMING_AT_MASKWALL) +#define AIMING_AT_CEILING_OR_FLOOR (AIMING_AT_CEILING || AIMING_AT_FLOOR) + + +/** The following macros multiplex between identically named fields of sector/wall/sprite, + * based on a macro parameter or the currently aimed at object (AIMED_ versions). + * They can be used on either side of an assignment. */ + +// select wall, only makes a difference with walls that have 'swap bottom of walls' bit set +#define SELECT_WALL() (AIMING_AT_WALL ? searchbottomwall : searchwall) + +#define SECFLD(i, Field) (sector[i].Field) +#define WALFLD(i, Field) (wall[i].Field) +#define SPRFLD(i, Field) (sprite[i].Field) + +// valid fields: z, stat, picnum, heinum, shade, pal, xpanning, ypanning +#define CEILINGFLOOR(iSec, Field) (*(AIMING_AT_CEILING ? &(sector[iSec].ceiling##Field) : &(sector[iSec].floor##Field))) +#define AIMED_CEILINGFLOOR(Field) CEILINGFLOOR(searchsector, Field) + +#define AIMED_SEL_WALL(Field) WALFLD(SELECT_WALL(), Field) + +// selects from wall proper or its mask +#define OVR_WALL(iWal, Field) (*(AIMING_AT_WALL ? &WALFLD(iWal, Field) : &(wall[iWal].over##Field))) +#define AIMED_SELOVR_WALL(Field) OVR_WALL(SELECT_WALL(), Field) + +// the base macro to construct field multiplexing macros: wall and sector cases undetermined +#define MUXBASE(Field, SectorCase, WallCase) (*(AIMING_AT_CEILING_OR_FLOOR ? (SectorCase) : \ + (AIMING_AT_WALL_OR_MASK ? (WallCase) : \ + &SPRFLD(searchwall, Field)))) + +#define SFBASE_CF(Field, WallCase) MUXBASE(Field, &AIMED_CEILINGFLOOR(Field), WallCase) + +#define SFBASE_(Field, WallCase) MUXBASE(Field, &SECFLD(searchsector,Field), WallCase) + +#define AIMED(Field) SFBASE_(Field, &WALFLD(searchwall, Field)) +#define AIMED_SEL(Field) SFBASE_(Field, &AIMED_SEL_WALL(Field)) +//#define AIMED_CF(Field) SFBASE_CF(Field, &WALFLD(searchwall,Field)) +#define AIMED_CF_SEL(Field) SFBASE_CF(Field, &AIMED_SEL_WALL(Field)) + +// OVR makes sense only with picnum +//#define AIMED_OVR_PICNUM SFBASE_CF(picnum, &OVR_WALL(searchwall, picnum)) +#define AIMED_SELOVR_PICNUM SFBASE_CF(picnum, &AIMED_SELOVR_WALL(picnum)) + + +#define BTAG_MAX 65535 + + +static const char *ONOFF_[] = {"OFF","ON"}; +#define ONOFF(b) (ONOFF_[!!(b)]) + static CACHE1D_FIND_REC *finddirs=NULL, *findfiles=NULL, *finddirshigh=NULL, *findfileshigh=NULL; static int32_t numdirs=0, numfiles=0; @@ -128,6 +200,17 @@ extern char game_executable[BMAX_PATH]; extern int32_t fillsector(int16_t sectnum, char fillcolor); +static void drawgradient() +{ + int32_t i, col = whitecol-21; + begindrawing(); + for (i=ydim-STATUS2DSIZ+16; i0; i++,col--) + clearbufbyte((char *)(frameplace + i*bytesperline), bytesperline, + (col<<24)|(col<<16)|(col<<8)|col); + clearbufbyte((char *)(frameplace + i*bytesperline), (ydim-i)*bytesperline, 0); + enddrawing(); +} + void message(const char *fmt, ...) { char tmpstr[256]; @@ -138,9 +221,11 @@ void message(const char *fmt, ...) va_end(va); Bstrcpy(getmessage,tmpstr); - getmessageleng = strlen(getmessage); + + getmessageleng = Bstrlen(getmessage); getmessagetimeoff = totalclock+120*2; lastmessagetime = totalclock; + if (!mouseaction) { Bstrcat(tmpstr,"\n"); @@ -199,9 +284,12 @@ void create_map_snapshot(void) do { - if (next->sectors && (next->prev == NULL || (next->sectcrc != next->prev->sectcrc))) Bfree(next->sectors); - if (next->walls && (next->prev == NULL || (next->wallcrc != next->prev->wallcrc))) Bfree(next->walls); - if (next->sprites && (next->prev == NULL || (next->spritecrc != next->prev->spritecrc))) Bfree(next->sprites); + if (next->sectors && (next->prev == NULL || (next->sectcrc != next->prev->sectcrc))) + Bfree(next->sectors); + if (next->walls && (next->prev == NULL || (next->wallcrc != next->prev->wallcrc))) + Bfree(next->walls); + if (next->sprites && (next->prev == NULL || (next->spritecrc != next->prev->spritecrc))) + Bfree(next->sprites); if (!next->prev) { Bfree(next); @@ -368,9 +456,9 @@ int32_t map_undoredo(int32_t dir) initspritelists(); - clearbuf(&show2dsector[0],(int32_t)((MAXSECTORS+3)>>5),0L); - clearbuf(&show2dsprite[0],(int32_t)((MAXSPRITES+3)>>5),0L); - clearbuf(&show2dwall[0],(int32_t)((MAXWALLS+3)>>5),0L); + Bmemset(show2dsector, 0, sizeof(show2dsector)); + Bmemset(show2dsprite, 0, sizeof(show2dsprite)); + Bmemset(show2dwall, 0, sizeof(show2dwall)); if (mapstate->numsectors) { @@ -398,7 +486,7 @@ int32_t map_undoredo(int32_t dir) return 0; } -static char *SpriteMode[]= +static const char *SpriteMode[]= { "NONE", "SECTORS", @@ -412,7 +500,7 @@ static char *SpriteMode[]= }; #define MAXSKILL 5 -static char *SKILLMODE[MAXSKILL]= +static const char *SKILLMODE[MAXSKILL]= { "Actor skill display: PIECE OF CAKE", "Actor skill display: LET'S ROCK", @@ -422,7 +510,7 @@ static char *SKILLMODE[MAXSKILL]= }; #define MAXNOSPRITES 4 -static char *SPRDSPMODE[MAXNOSPRITES]= +static const char *SPRDSPMODE[MAXNOSPRITES]= { "Sprite display: DISPLAY ALL SPRITES", "Sprite display: NO EFFECTORS", @@ -431,7 +519,7 @@ static char *SPRDSPMODE[MAXNOSPRITES]= }; #define MAXHELP3D (int32_t)(sizeof(Help3d)/sizeof(Help3d[0])) -static char *Help3d[]= +static const char *Help3d[]= { "Mapster32 3D mode help", " ", @@ -473,7 +561,7 @@ static void clearfilenames(void) numfiles = numdirs = 0; } -static int32_t getfilenames(const char *path, char kind[]) +static int32_t getfilenames(const char *path, const char *kind) { CACHE1D_FIND_REC *r; @@ -560,24 +648,21 @@ void ExtSaveMap(const char *mapname) saveboard("backup.map",&pos.x,&pos.y,&pos.z,&ang,&cursectnum); } -int32_t getTileGroup(const char *groupName) +static int32_t getTileGroup(const char *groupName) { int32_t temp; for (temp = 0; temp < MAX_TILE_GROUPS; temp++) { if (s_TileGroups[temp].szText == NULL) - { return -1; - } - if (!strcmp(s_TileGroups[temp].szText, groupName)) - { + + if (!Bstrcmp(s_TileGroups[temp].szText, groupName)) return temp; - } } return -1; } -int32_t tileInGroup(int32_t group, int32_t tilenum) +static int32_t tileInGroup(int32_t group, int32_t tilenum) { // @todo Make a bitmap instead of doing this slow search.. int32_t temp; @@ -586,12 +671,10 @@ int32_t tileInGroup(int32_t group, int32_t tilenum) // group isn't valid. return 0; } - for (temp = 0; temp < s_TileGroups[group].nIds; temp++) + for (temp=0; temp=0 && lotag<(int32_t)(sizeof(tags)/sizeof(tags[0]))) + Bsprintf(tempbuf, "%d: %s", lotag, tags[lotag]); + else + switch (lotag) + { + case 36: + Bsprintf(tempbuf,"%d: SKRINK RAY SHOOTER",lotag); + break; + case 49: + Bsprintf(tempbuf,"%d: POINT LIGHT",lotag); + break; + case 50: + Bsprintf(tempbuf,"%d: SPOTLIGHT",lotag); + break; + default: + Bsprintf(tempbuf,"%d: (UNKNOWN)",lotag); + break; + } + return (tempbuf); } @@ -872,42 +892,36 @@ const char *MusicAndSFXTagText(int32_t lotag) const char *SectorEffectorText(int32_t spritenum) { static char tempbuf[64]; - Bmemset(tempbuf,0,sizeof(tempbuf)); - Bmemset(lo,0,sizeof(lo)); - Bstrcpy(lo,SectorEffectorTagText(sprite[spritenum].lotag)); + + Bmemset(tempbuf, 0, sizeof(tempbuf)); + Bmemset(lo, 0, sizeof(lo)); + + Bstrcpy(lo, SectorEffectorTagText(sprite[spritenum].lotag)); if (!lo[5]) // tags are 5 chars or less - SpriteName(spritenum,tempbuf); - else Bsprintf(tempbuf,"SE %s",lo); + SpriteName(spritenum, tempbuf); + else + Bsprintf(tempbuf, "SE %s",lo); + return (tempbuf); } const char *ExtGetSpriteCaption(int16_t spritenum) { static char tempbuf[1024]; + int32_t retfast = 0; Bmemset(tempbuf,0,sizeof(tempbuf)); - if ((onnames!=5 && onnames!=6 &&(!(onnames==3 || onnames==4 || onnames==7 || onnames==8))) || (onnames==7 && sprite[spritenum].picnum!=1)) - { - tempbuf[0] = 0; - return(tempbuf); - } - - if (onnames==5) - { - if (!tileInGroup(tilegroupItems, sprite[spritenum].picnum)) - { - tempbuf[0] = 0; - return(tempbuf); - } - } + if (!(onnames>=3 && onnames<=8) || (onnames==7 && sprite[spritenum].picnum!=SECTOREFFECTOR)) + retfast = 1; + if (onnames==5 && !tileInGroup(tilegroupItems, sprite[spritenum].picnum)) + retfast = 1; if (onnames==6 && sprite[spritenum].picnum != sprite[cursprite].picnum) - { - tempbuf[0] = 0; - return(tempbuf); - } + retfast = 1; + + if (retfast) + return(tempbuf); - tempbuf[0] = 0; if ((sprite[spritenum].lotag|sprite[spritenum].hitag) == 0) { SpriteName(spritenum,lo); @@ -919,9 +933,7 @@ const char *ExtGetSpriteCaption(int16_t spritenum) } else if (sprite[spritenum].picnum==SECTOREFFECTOR) { - if (onnames==8) - tempbuf[0] = 0; - else + if (onnames!=8) { Bsprintf(lo,"%s",SectorEffectorText(spritenum)); Bsprintf(tempbuf,"%s, %hu",lo,sprite[spritenum].hitag); @@ -935,6 +947,7 @@ const char *ExtGetSpriteCaption(int16_t spritenum) else Bsprintf(tempbuf,"%hu,%hu %s",sprite[spritenum].hitag,sprite[spritenum].lotag,lo); } + return(tempbuf); } //end @@ -957,9 +970,8 @@ const char *ExtGetSpriteCaption(int16_t spritenum) void ExtShowSectorData(int16_t sectnum) //F5 { - int16_t statnum=0; int32_t x,x2,y; - int32_t i,color; + int32_t i,yi; int32_t secrets=0; int32_t totalactors1=0,totalactors2=0,totalactors3=0,totalactors4=0; int32_t totalrespawn=0; @@ -969,12 +981,9 @@ void ExtShowSectorData(int16_t sectnum) //F5 return; for (i=0; i to exit"); - if (keystatus[KEYSC_T]) // goto table of contents + if (PRESSED_KEYSC(T)) // goto table of contents { - keystatus[KEYSC_T]=0; curhp=0; curline=0; } - else if (keystatus[KEYSC_G]) // goto arbitrary page + else if (PRESSED_KEYSC(G)) // goto arbitrary page { - keystatus[KEYSC_G]=0; - Bsprintf(tempbuf, "Goto page: "); - curhp=getnumber16(tempbuf, 0, numhelppages-1, 0); + curhp=getnumber16("Goto page: ", 0, numhelppages-1, 0); curline=0; } - else if (keystatus[KEYSC_UP]) // scroll up + else if (PRESSED_KEYSC(UP)) // scroll up { - keystatus[KEYSC_UP]=0; if (curline>0) curline--; } - else if (keystatus[KEYSC_DOWN]) // scroll down + else if (PRESSED_KEYSC(DOWN)) // scroll down { - keystatus[KEYSC_DOWN]=0; if (curline + 32/*+IHELP_NUMDISPLINES*/ < helppage[curhp]->numlines) curline++; } - else if (keystatus[KEYSC_PGUP]) // scroll one page up + else if (PRESSED_KEYSC(PGUP)) // scroll one page up { - keystatus[KEYSC_PGUP]=0; i=IHELP_NUMDISPLINES; while (i>0 && curline>0) i--, curline--; } - else if (keystatus[KEYSC_PGDN]) // scroll one page down + else if (PRESSED_KEYSC(PGDN)) // scroll one page down { - keystatus[KEYSC_PGDN]=0; i=IHELP_NUMDISPLINES; while (i>0 && curline + 32/*+IHELP_NUMDISPLINES*/ < helppage[curhp]->numlines) i--, curline++; } - else if (keystatus[KEYSC_SPACE]) // goto next paragraph + else if (PRESSED_KEYSC(SPACE)) // goto next paragraph { - keystatus[KEYSC_SPACE]=0; for (i=curline, j=0; i < helppage[curhp]->numlines; i++) { if (emptyline(helppage[curhp]->line[i])) { j=1; continue; } @@ -1711,9 +1554,8 @@ static void IntegratedHelp() curline = helppage[curhp]->numlines - 32/*-IHELP_NUMDISPLINES*/; } } - else if (keystatus[KEYSC_BS]) // goto prev paragraph + else if (PRESSED_KEYSC(BS)) // goto prev paragraph { - keystatus[KEYSC_BS]=0; for (i=curline-1, j=0; i>=0; i--) { if (!emptyline(helppage[curhp]->line[i])) { j=1; continue; } @@ -1721,29 +1563,25 @@ static void IntegratedHelp() } if (j==2 || i==-1) curline=i+1; } - else if (keystatus[KEYSC_HOME]) // goto beginning of page + else if (PRESSED_KEYSC(HOME)) // goto beginning of page { - keystatus[KEYSC_HOME]=0; curline=0; } - else if (keystatus[KEYSC_END]) // goto end of page + else if (PRESSED_KEYSC(END)) // goto end of page { - keystatus[KEYSC_END]=0; if ((curline=helppage[curhp]->numlines - 32/*-IHELP_NUMDISPLINES*/) >= 0) /**/; else curline=0; } - else if (keystatus[KEYSC_LEFT] || keystatus[KEYSC_LBRACK]) // prev page + else if (PRESSED_KEYSC(LEFT) || PRESSED_KEYSC(LBRACK)) // prev page { - keystatus[KEYSC_LEFT] = keystatus[KEYSC_LBRACK] = 0; if (curhp>0) { curhp--; curline=0; } } - else if (keystatus[KEYSC_RIGHT] || keystatus[KEYSC_RBRACK]) // next page + else if (PRESSED_KEYSC(RIGHT) || PRESSED_KEYSC(RBRACK)) // next page { - keystatus[KEYSC_RIGHT] = keystatus[KEYSC_RBRACK] = 0; if (curhpnumlines) - { - _printmessage16(helppage[0]->line[curhp]); - } + _printmessage16("%s", helppage[0]->line[curhp]); else - { - for (i=Bsprintf(tempbuf, "%d. (Untitled page)", curhp); i<80; i++) - tempbuf[i]=0; - _printmessage16(tempbuf); - } + _printmessage16("%d. (Untitled page)", curhp); for (i=0; j=(curhp==0)?(i+curline+1):(i+curline), inumlines; i++) @@ -2046,40 +1863,23 @@ static void SoundDisplay() // SoundToggle = 1; while (keystatus[KEYSC_ESC]==0 && keystatus[KEYSC_Q]==0 && keystatus[KEYSC_F2]==0 - && keystatus[buildkeys[BK_MODE2D_3D]]==0) // quickjump to 3d mode + && keystatus[buildkeys[BK_MODE2D_3D]]==0) // quickjump to 3d mode { idle_waitevent(); if (handleevents()) + quitevent = 0; + + drawgradient(); + + begindrawing(); + printext16(9, ydim2d-overridepm16y+9, editorcolors[4], -1, "Sound Index", 0); + printext16(8, ydim2d-overridepm16y+8, editorcolors[12], -1, "Sound Index", 0); + enddrawing(); + + if (PRESSED_KEYSC(G)) // goto specified sound# { - if (quitevent) quitevent = 0; - } - - { - int32_t col = whitecol-21; - - begindrawing(); - for (i=ydim-overridepm16y; i0) curofs--; else if (cursnd>0) cursnd--; } - else if (keystatus[KEYSC_DOWN]) // scroll down + else if (PRESSED_KEYSC(DOWN)) // scroll down { - keystatus[KEYSC_DOWN]=0; if (curofs<32/*SOUND_NUMDISPLINES*/-1 && cursnd+curofs0 && curofs>0) i--, curofs--; while (i>0 && cursnd>0) i--, cursnd--; } - else if (keystatus[KEYSC_PGDN]) // scroll one page down + else if (PRESSED_KEYSC(PGDN)) // scroll one page down { - keystatus[KEYSC_PGDN]=0; i=SOUND_NUMDISPLINES; while (i>0 && curofs<32/*SOUND_NUMDISPLINES*/-1 && cursnd+curofs0 && cursnd+32/*SOUND_NUMDISPLINES*/ < g_numsounds) i--, cursnd++; } - else if (keystatus[KEYSC_SPACE] || keystatus[KEYSC_ENTER]) // play/stop sound + else if (PRESSED_KEYSC(SPACE) || PRESSED_KEYSC(ENTER)) // play/stop sound { int32_t j = cursnd+curofs; int32_t k = g_sndnum[j]; - keystatus[KEYSC_SPACE] = keystatus[KEYSC_ENTER] = 0; + if (S_CheckSoundPlaying(0, k) > 0) S_StopSound(k); else S_PlaySound(k); } - else if (keystatus[KEYSC_HOME]) // goto first sound# + else if (PRESSED_KEYSC(HOME)) // goto first sound# { - keystatus[KEYSC_HOME]=0; cursnd = curofs = 0; } - else if (keystatus[KEYSC_END]) // goto last sound# + else if (PRESSED_KEYSC(END)) // goto last sound# { - keystatus[KEYSC_END]=0; if ((cursnd=g_numsounds-32/*SOUND_NUMDISPLINES*/) >= 0) curofs=32/*SOUND_NUMDISPLINES*/-1; else @@ -2162,8 +1956,7 @@ static void SoundDisplay() bflushchars(); while (bad == 0) { - Bsprintf(tempbuf,"Sort by: (S)num (D)ef (F)ile ori(g) or (12345)"); - _printmessage16(tempbuf); + _printmessage16("Sort by: (S)num (D)ef (F)ile ori(g) or (12345)"); showframe(1); idle_waitevent(); @@ -2216,7 +2009,7 @@ static void SoundDisplay() disptext[i][5+l] = ' '; if (snd->filename) { - l = strlen(snd->filename); + l = Bstrlen(snd->filename); if (l<=16) cp = snd->filename; else @@ -2256,9 +2049,9 @@ static void SoundDisplay() // from sector.c static int32_t dist(spritetype *s1,spritetype *s2) { - int32_t x= klabs(s1->x-s2->x); - int32_t y= klabs(s1->y-s2->y); - int32_t z= klabs((s1->z-s2->z)>>4); + int32_t x = klabs(s1->x-s2->x); + int32_t y = klabs(s1->y-s2->y); + int32_t z = klabs((s1->z-s2->z)>>4); if (x= 0; j = nextspritestat[j]) { if (s->picnum == MUSICANDSFX && j != i && sprite[j].lotag < 999 && - (sprite[j].filler&1) == 1 && dist(&sprite[j],(spritetype*)&pos) > x) + (sprite[j].filler&1) == 1 && dist(&sprite[j],(spritetype*)&pos) > x) { S_StopEnvSound(sprite[j].lotag,j); break; @@ -2381,42 +2174,8 @@ static void Show3dText(char *name) kclose(fp); }// end Show3dText -#if 0 -static void ShowHelpText(char *name) -{ - BFILE *fp; - char x=0,y=4; - UNREFERENCED_PARAMETER(name); - if ((fp=fopenfrompath("helpdoc.txt","rb")) == NULL) - { - begindrawing(); - printext256(1*4,4*8,whitecol,-1,"ERROR: file not found.",0); - enddrawing(); - return; - } - /* - Bfgets(tempbuf,80,fp); - while(!Bfeof(fp) && Bstrcmp(tempbuf,"SectorEffector")) - { - Bfgets(tempbuf,80,fp); - } - */ - y=2; - Bfgets(tempbuf,80,fp); - Bstrcat(tempbuf,"\n"); - begindrawing(); - while (!Bfeof(fp) && !(Bstrcmp(tempbuf,"SectorEffector")==0)) - { - Bfgets(tempbuf,80,fp); - Bstrcat(tempbuf,"\n"); - printext256(x*4,(y*6)+2,whitecol,-1,tempbuf,1); - y++; - } - enddrawing(); +///__ShowHelpText__ - Bfclose(fp); -}// end ShowHelpText -#endif void ExtShowSpriteData(int16_t spritenum) //F6 { UNREFERENCED_PARAMETER(spritenum); @@ -2438,8 +2197,8 @@ void ExtShowSpriteData(int16_t spritenum) //F6 // If standing in sector with SE43 or SE45 // then draw viewing to SE40 and lower all =hi SE42 floors. -int32_t fofsizex = -1; -int32_t fofsizey = -1; +static int32_t fofsizex = -1; +static int32_t fofsizey = -1; #if 0 static void ResetFOFSize() { @@ -2534,16 +2293,16 @@ static void ExtSE40Draw(int32_t spnum,int32_t x,int32_t y,int32_t z,int16_t a,in if (sprite[floor2].ang >= 1024) offz = sprite[floor2].z; else if (fofmode==41) - offz = sector[sprite[floor2].sectnum].floorz; + offz = SPRITESEC(floor2).floorz; else - offz = sector[sprite[floor2].sectnum].ceilingz; + offz = SPRITESEC(floor2).ceilingz; if (sprite[floor1].ang >= 1024) offz -= sprite[floor1].z; else if (fofmode==40) - offz -= sector[sprite[floor1].sectnum].floorz; + offz -= SPRITESEC(floor1).floorz; else - offz -= sector[sprite[floor1].sectnum].ceilingz; + offz -= SPRITESEC(floor1).ceilingz; // if(ok==2) { Message("no floor2",RED); return; } @@ -2553,17 +2312,17 @@ static void ExtSE40Draw(int32_t spnum,int32_t x,int32_t y,int32_t z,int16_t a,in { if (k==40) { - tempsectorz[sprite[j].sectnum]=sector[sprite[j].sectnum].floorz; - sector[sprite[j].sectnum].floorz+=(((z-sector[sprite[j].sectnum].floorz)/32768)+1)*32768; - tempsectorpicnum[sprite[j].sectnum]=sector[sprite[j].sectnum].floorpicnum; - sector[sprite[j].sectnum].floorpicnum=562; + tempsectorz[sprite[j].sectnum] = SPRITESEC(j).floorz; + SPRITESEC(j).floorz += (((z-SPRITESEC(j).floorz)/32768)+1)*32768; + tempsectorpicnum[sprite[j].sectnum] = SPRITESEC(j).floorpicnum; + SPRITESEC(j).floorpicnum = 562; } else { - tempsectorz[sprite[j].sectnum]=sector[sprite[j].sectnum].ceilingz; - sector[sprite[j].sectnum].ceilingz+=(((z-sector[sprite[j].sectnum].ceilingz)/32768)-1)*32768; - tempsectorpicnum[sprite[j].sectnum]=sector[sprite[j].sectnum].ceilingpicnum; - sector[sprite[j].sectnum].ceilingpicnum=562; + tempsectorz[sprite[j].sectnum] = SPRITESEC(j).ceilingz; + SPRITESEC(j).ceilingz += (((z-SPRITESEC(j).ceilingz)/32768)-1)*32768; + tempsectorpicnum[sprite[j].sectnum] = SPRITESEC(j).ceilingpicnum; + SPRITESEC(j).ceilingpicnum = 562; } draw_both = 1; } @@ -2577,19 +2336,18 @@ static void ExtSE40Draw(int32_t spnum,int32_t x,int32_t y,int32_t z,int16_t a,in { for (j=0; j 640)?2:1); i++) { plotpixel(searchx+i,searchy,whitecol); @@ -2821,7 +2581,9 @@ static void m32_showmouse(void) plotpixel(searchx,searchy-i,whitecol); plotpixel(searchx,searchy+i,whitecol); } - i=((xdim > 640)?8:4); + + i = (xdim > 640)?8:4; + plotpixel(searchx+i,searchy,0); plotpixel(searchx-i,searchy,0); plotpixel(searchx,searchy-i,0); @@ -2868,36 +2630,26 @@ static int32_t AskIfSure(char *text) } } idle(); - if (keystatus[KEYSC_Y]||keystatus[KEYSC_ENTER]) + + if (PRESSED_KEYSC(Y) || PRESSED_KEYSC(ENTER)) { - keystatus[KEYSC_Y] = 0; - keystatus[KEYSC_ENTER] = 0; retval = 0; break; } } - while (keystatus[KEYSC_ESC]) + + while (PRESSED_KEYSC(ESC)) { - keystatus[KEYSC_ESC] = 0; retval = 1; break; } + return(retval); } -static int32_t IsValidTile(const int32_t idTile) +static int32_t IsValidTile(int32_t idTile) { - int32_t bValid = 0; - - if ((idTile >= 0) && (idTile < MAXTILES)) - { - if ((tilesizx[idTile] != 0) && (tilesizy[idTile] != 0)) - { - bValid = 1; - } - } - - return bValid; + return (idTile>=0 && idTile= MAXTILES) - { - idInitialTile = MAXTILES - 1; - } + idInitialTile = clamp(idInitialTile, 0, MAXTILES-1); // Ensure zoom not to big (which can happen if display size // changes whilst Mapster is running) @@ -2977,7 +2718,6 @@ static int32_t m32gettile(int32_t idInitialTile) for (i = 0; i < MAXTILES; i++) { localartfreq[i] = 0; - localartlookup[i] = i; } @@ -2987,9 +2727,7 @@ static int32_t m32gettile(int32_t idInitialTile) { case SEARCH_WALL: for (i = 0; i < numwalls; i++) - { localartfreq[ wall[i].picnum ]++; - } break; case SEARCH_CEILING: @@ -3003,19 +2741,12 @@ static int32_t m32gettile(int32_t idInitialTile) case SEARCH_SPRITE: for (i=0; i= 0)) + while (localartfreq[temp]= 0) { int32_t tempint; @@ -3048,13 +2779,9 @@ static int32_t m32gettile(int32_t idInitialTile) localartlookup[temp+gap] = tempint; if (iTile == temp) - { iTile = temp + gap; - } else if (iTile == temp + gap) - { iTile = temp; - } temp -= gap; } @@ -3069,9 +2796,7 @@ static int32_t m32gettile(int32_t idInitialTile) localartlookupnum = 0; while (localartfreq[localartlookupnum] > 0) - { localartlookupnum++; - } // // Check : If no tiles used at all then switch to displaying all tiles @@ -3095,19 +2820,10 @@ static int32_t m32gettile(int32_t idInitialTile) // iTopLeftTile = iTile - (iTile % nXTiles); + iTopLeftTile = clamp(iTopLeftTile, 0, MAXTILES-nDisplayedTiles); - if (iTopLeftTile < 0) - { - iTopLeftTile = 0; - } - - if (iTopLeftTile > MAXTILES-nDisplayedTiles) - { - iTopLeftTile = MAXTILES-nDisplayedTiles; - } - - searchx=((iTile-iTopLeftTile)%nXTiles)*ZoomToThumbSize[s_Zoom]+ZoomToThumbSize[s_Zoom]/2; - searchy=((iTile-iTopLeftTile)/nXTiles)*ZoomToThumbSize[s_Zoom]+ZoomToThumbSize[s_Zoom]/2; + searchx = ((iTile-iTopLeftTile)%nXTiles)*ZoomToThumbSize[s_Zoom] + ZoomToThumbSize[s_Zoom]/2; + searchy = ((iTile-iTopLeftTile)/nXTiles)*ZoomToThumbSize[s_Zoom] + ZoomToThumbSize[s_Zoom]/2; //////////////////////////////// // Start of key handling code // @@ -3115,16 +2831,19 @@ static int32_t m32gettile(int32_t idInitialTile) while ((keystatus[KEYSC_ENTER]|keystatus[KEYSC_ESC]|(bstatus&1)) == 0) // <- Presumably one of these is escape key ?? { - DrawTiles(iTopLeftTile, (iTile >= localartlookupnum)?localartlookupnum-1:iTile, nXTiles, nYTiles, ZoomToThumbSize[s_Zoom],moffset); + DrawTiles(iTopLeftTile, (iTile >= localartlookupnum) ? localartlookupnum-1 : iTile, + nXTiles, nYTiles, ZoomToThumbSize[s_Zoom], moffset); getmousevalues(&mousedx,&mousedy,&bstatus); searchx += mousedx; searchy += mousedy; + if (bstatus&2) { - moffset+=mousedy*2; + moffset += mousedy*2; searchy += mousedy; searchx -= mousedx; + if ((moffset < 0 && iTopLeftTile > localartlookupnum-nDisplayedTiles-1) || (moffset > 0 && iTopLeftTile==0)) { @@ -3161,6 +2880,7 @@ static int32_t m32gettile(int32_t idInitialTile) mouseb &= ~32; iTopLeftTile += (nXTiles*scrollamount); } + mtile=iTile=(searchx/ZoomToThumbSize[s_Zoom])+((searchy-moffset)/ZoomToThumbSize[s_Zoom])*nXTiles+iTopLeftTile; while (iTile >= iTopLeftTile + nDisplayedTiles) { @@ -3172,10 +2892,9 @@ static int32_t m32gettile(int32_t idInitialTile) idle_waitevent(); else idle(); + if (handleevents()) - { - if (quitevent) quitevent = 0; - } + quitevent = 0; // These two lines are so obvious I don't need to comment them ...;-) synctics = totalclock-lockclock; @@ -3185,16 +2904,14 @@ static int32_t m32gettile(int32_t idInitialTile) if (((keystatus[KEYSC_gSLASH] || (!scrollmode && bstatus&16)) && s_Zoom<(signed)(NUM_ZOOMS-1)) || ((keystatus[KEYSC_gSTAR] || (!scrollmode && bstatus&32)) && s_Zoom>0)) { - if (keystatus[KEYSC_gSLASH] || (!scrollmode && bstatus&16)) + if (PRESSED_KEYSC(gSLASH) || (!scrollmode && bstatus&16)) { - keystatus[KEYSC_gSLASH] = 0; mouseb &= ~16; bstatus &= ~16; // Watch out : If editor window is small, then the next zoom level // might get so large that even one tile might not fit ! - if ((ZoomToThumbSize[s_Zoom+1] <= xdim) - && (ZoomToThumbSize[s_Zoom+1] <= ydim)) + if (ZoomToThumbSize[s_Zoom+1]<=xdim && ZoomToThumbSize[s_Zoom+1]<=ydim) { // Phew, plenty of room. s_Zoom++; @@ -3220,152 +2937,87 @@ static int32_t m32gettile(int32_t idInitialTile) // Determine if the top-left displayed tile needs to // alter in order to display selected tile iTopLeftTile = iTile - (iTile % nXTiles); + iTopLeftTile = clamp(iTopLeftTile, 0, MAXTILES - nDisplayedTiles); - if (iTopLeftTile < 0) - { - iTopLeftTile = 0; - } - else if (iTopLeftTile > MAXTILES - nDisplayedTiles) - { - iTopLeftTile = MAXTILES - nDisplayedTiles; - } // scroll window so mouse points the same tile as it was before zooming - iTopLeftTile-=(searchx/ZoomToThumbSize[s_Zoom])+((searchy-moffset)/ZoomToThumbSize[s_Zoom])*nXTiles+iTopLeftTile-iTile; + iTopLeftTile -= (searchx/ZoomToThumbSize[s_Zoom]) + ((searchy-moffset)/ZoomToThumbSize[s_Zoom])*nXTiles + + iTopLeftTile-iTile; } - if (keystatus[KEYSC_LEFT]) - { + if (PRESSED_KEYSC(LEFT)) iTile -= (iTile > 0); - keystatus[KEYSC_LEFT] = 0; - } - if (keystatus[KEYSC_RIGHT]) - { + if (PRESSED_KEYSC(RIGHT)) iTile += (iTile < MAXTILES); - keystatus[KEYSC_RIGHT] = 0; - } - if (keystatus[KEYSC_UP]) - { + if (PRESSED_KEYSC(UP)) iTile -= nXTiles; - keystatus[KEYSC_UP] = 0; - } - if (keystatus[KEYSC_DOWN]) - { + if (PRESSED_KEYSC(DOWN)) iTile += nXTiles; - keystatus[KEYSC_DOWN] = 0; - } - if (keystatus[KEYSC_PGUP]) - { + if (PRESSED_KEYSC(PGUP)) iTile -= nDisplayedTiles; - keystatus[KEYSC_PGUP] = 0; - } - if (keystatus[KEYSC_PGDN]) - { + if (PRESSED_KEYSC(PGDN)) iTile += nDisplayedTiles; - keystatus[KEYSC_PGDN] = 0; - } // // Ensure tilenum is within valid range // - if (iTile < 0) - { - iTile = 0; - } - - if (iTile >= MAXTILES) // shouldn't this be the count of num tiles ?? - { - iTile = MAXTILES-1; - } + iTile = clamp(iTile, 0, MAXTILES-1); // shouldn't this be the count of num tiles ?? // 'V' KEYPRESS - if (keystatus[KEYSC_V]) - { - keystatus[KEYSC_V] = 0; - + if (PRESSED_KEYSC(V)) iTile = SelectAllTiles(iTile); - } // 'G' KEYPRESS - Goto frame - if (keystatus[KEYSC_G]) - { - keystatus[KEYSC_G] = 0; - + if (PRESSED_KEYSC(G)) iTile = OnGotoTile(iTile); - } // 'U' KEYPRESS : go straight to user defined art - if (keystatus[KEYSC_U]) + if (PRESSED_KEYSC(U)) { SelectAllTiles(iTile); - iTile = FIRST_USER_ART_TILE; - keystatus[KEYSC_U] = 0; } // 'A' KEYPRESS : Go straight to start of Atomic edition's art - if (keystatus[KEYSC_A]) + if (PRESSED_KEYSC(A)) { SelectAllTiles(iTile); - iTile = FIRST_ATOMIC_TILE; - keystatus[KEYSC_A] = 0; } // 'T' KEYPRESS = Select from pre-defined tileset - if (keystatus[KEYSC_T]) - { - keystatus[KEYSC_T] = 0; - + if (PRESSED_KEYSC(T)) iTile = OnSelectTile(iTile); - } // 'E' KEYPRESS : Go straight to start of extended art - if (keystatus[KEYSC_E]) + if (PRESSED_KEYSC(E)) { SelectAllTiles(iTile); if (iTile == FIRST_EXTENDED_TILE) iTile = SECOND_EXTENDED_TILE; else iTile = FIRST_EXTENDED_TILE; - - keystatus[KEYSC_E] = 0; } - if (keystatus[KEYSC_Z]) - { + if (PRESSED_KEYSC(Z)) s_TileZoom = !s_TileZoom; - keystatus[KEYSC_Z] = 0; - } // // Adjust top-left to ensure tilenum is within displayed range of tiles // while (iTile < iTopLeftTile - (moffset<0)?nXTiles:0) - { iTopLeftTile -= nXTiles; - } while (iTile >= iTopLeftTile + nDisplayedTiles) - { iTopLeftTile += nXTiles; - } - if (iTopLeftTile < 0) - { - iTopLeftTile = 0; - } - - if (iTopLeftTile > MAXTILES - nDisplayedTiles) - { - iTopLeftTile = MAXTILES - nDisplayedTiles; - } + iTopLeftTile = clamp(iTopLeftTile, 0, MAXTILES - nDisplayedTiles); if ((keystatus[KEYSC_ENTER] || (bstatus&1)) == 0) // uh ? Not escape key ? { @@ -3380,9 +3032,7 @@ static int32_t m32gettile(int32_t idInitialTile) // Check : if invalid tile selected, return original tile num if (!IsValidTile(idSelectedTile)) - { idSelectedTile = idInitialTile; - } } else { @@ -3395,7 +3045,9 @@ static int32_t m32gettile(int32_t idInitialTile) searchy=((iTile-iTopLeftTile)/nXTiles)*ZoomToThumbSize[s_Zoom]+ZoomToThumbSize[s_Zoom]/2+moffset; } } - searchx=omousex; searchy=omousey; + + searchx=omousex; + searchy=omousey; keystatus[KEYSC_ESC] = 0; keystatus[KEYSC_ENTER] = 0; @@ -3425,9 +3077,8 @@ static int32_t OnGotoTile(int32_t iTile) while (keystatus[KEYSC_ESC] == 0) { if (handleevents()) - { - if (quitevent) quitevent = 0; - } + quitevent = 0; + idle(); ch = bgetchar(); @@ -3440,9 +3091,7 @@ static int32_t OnGotoTile(int32_t iTile) { iTemp = (iNewTile*10) + (ch-'0'); if (iTemp < MAXTILES) - { iNewTile = iTemp; - } } else if (ch == 8) { @@ -3475,13 +3124,10 @@ static int32_t LoadTileSet(const int32_t idCurrentTile, const int32_t *pIds, con localartfreq[i] = 0; if (idCurrentTile == pIds[i]) - { iNewTile = i; - } } return iNewTile; - } static int32_t OnSelectTile(int32_t iTile) @@ -3513,12 +3159,11 @@ static int32_t OnSelectTile(int32_t iTile) bDone = 0; - while (keystatus[KEYSC_ESC] == 0 && (!bDone)) + while (keystatus[KEYSC_ESC] == 0 && !bDone) { if (handleevents()) - { - if (quitevent) quitevent = 0; - } + quitevent = 0; + idle(); // @@ -3535,7 +3180,6 @@ static int32_t OnSelectTile(int32_t iTile) } showframe(1); - ch = bgetchar(); for (i = 0; (unsigned)i < tile_groups; i++) @@ -3557,21 +3201,17 @@ static int32_t OnSelectTile(int32_t iTile) return iTile; } -const char * GetTilePixels(const int32_t idTile) +static const char * GetTilePixels(int32_t idTile) { char *pPixelData = 0; - if ((idTile >= 0) && (idTile < MAXTILES)) + if (idTile >= 0 && idTile < MAXTILES) { if (!waloff[idTile]) - { loadtile(idTile); - } if (IsValidTile(idTile)) - { pPixelData = (char *)waloff[idTile]; - } } return pPixelData; @@ -3623,16 +3263,14 @@ static int32_t DrawTiles(int32_t iTopLeft, int32_t iSelected, int32_t nXTiles, i DivInc = 1; MulInc = 1; - while ((TileSizeX/DivInc > TileDim) - || (TileSizeY/DivInc) > TileDim) + while ((TileSizeX/DivInc > TileDim) || (TileSizeY/DivInc) > TileDim) { DivInc++; } if (DivInc == 1 && s_TileZoom) { - while (((TileSizeX*(MulInc+1)) <= TileDim) - && ((TileSizeY*(MulInc+1)) <= TileDim)) + while ((TileSizeX*(MulInc+1)) <= TileDim && (TileSizeY*(MulInc+1)) <= TileDim) { MulInc++; } @@ -3654,6 +3292,7 @@ static int32_t DrawTiles(int32_t iTopLeft, int32_t iSelected, int32_t nXTiles, i } } } + if (localartfreq[iTile] != 0 && YPos >= 0 && YPos <= ydim-20) { Bsprintf(szT, "%d", localartfreq[iTile]); @@ -3692,9 +3331,7 @@ static int32_t DrawTiles(int32_t iTopLeft, int32_t iSelected, int32_t nXTiles, i // Clear out behind the text for improved visibility. //drawline256(0, (ydim-12)<<12, xdim<<12, (ydim-12)<<12, whitecol); for (i=ydim-12; i640?0:1; i = ydimgame>>6; - x1=x+80; - if (j)x1/=2; - x1=(int32_t)(x1*(320./xdimgame)); - scale=(int32_t)(scale/(max(tilesizx[picnum],tilesizy[picnum])/24.)); + x1 = x+80; + if (small) + x1 /= 2; + + x1 *= 320.0/xdimgame; + scale /= (max(tilesizx[picnum],tilesizy[picnum])/24.0); setaspect(65536L, (int32_t)divscale16(ydim*320L,xdim*200L)); rotatesprite((x1+13)<<16,(y+11)<<16,scale,0,picnum,shade,pal,2,0L,0L,xdim-1L,ydim-1L); setaspect(oviewingrange, oyxaspect); - x=(int32_t)(x*(xdimgame/320.)); - y=(int32_t)(y*(ydimgame/200.)); + x *= xdimgame/320.0; + y *= ydimgame/200.0; + begindrawing(); - printext256(x+2,y+2,0,-1,title,j); - printext256(x,y,255-13,-1,title,j); + printext256(x+2,y+2,0,-1,title,small); + printext256(x,y,255-13,-1,title,small); + +#define DOPRINT(N) \ + printext256(x+2, y+2+i*N, 0, -1, buf, small); \ + printext256(x, y+i*N, whitecol, -1, buf, small); Bsprintf(buf,"Pic:%4d",picnum); - printext256(x+2,y+2+i*1,0,-1,buf,j); - printext256(x,y+i*1,whitecol,-1,buf,j); + DOPRINT(1); Bsprintf(buf,"Shd:%4d",shade); - printext256(x+2,y+2+i*2,0,-1,buf,j); - printext256(x,y+i*2,whitecol,-1,buf,j); + DOPRINT(2); Bsprintf(buf,"Pal:%4d",pal); - printext256(x+2,y+2+i*3,0,-1,buf,j); - printext256(x,y+i*3,whitecol,-1,buf,j); + DOPRINT(3); Bsprintf(buf,"Cst:%4d",cstat); - printext256(x+2,y+2+i*4,0,-1,buf,j); - printext256(x,y+i*4,whitecol,-1,buf,j); + DOPRINT(4); Bsprintf(buf,"Lot:%4d",lotag); - printext256(x+2,y+2+i*5,0,-1,buf,j); - printext256(x,y+i*5,whitecol,-1,buf,j); + DOPRINT(5); Bsprintf(buf,"Hit:%4d",hitag); - printext256(x+2,y+2+i*6,0,-1,buf,j); - printext256(x,y+i*6,whitecol,-1,buf,j); + DOPRINT(6); Bsprintf(buf,"Ext:%4d",extra); - printext256(x+2,y+2+i*7,0,-1,buf,j); - printext256(x,y+i*7,whitecol,-1,buf,j); + DOPRINT(7); enddrawing(); +#undef DOPRINT } -int32_t snap=0; -int32_t saveval1,saveval2,saveval3; +//int32_t snap=0; +//int32_t saveval1,saveval2,saveval3; static inline void getnumber_dochar(char *ptr, int32_t num) { @@ -3838,9 +3481,7 @@ void getnumberptr256(char *namestart, void *num, int32_t bytes, int32_t maxnumbe while (keystatus[0x1] == 0) { if (handleevents()) - { - if (quitevent) quitevent = 0; - } + quitevent = 0; drawrooms(pos.x,pos.y,pos.z,ang,horiz,cursectnum); #ifdef SUPERBUILD @@ -3946,12 +3587,12 @@ void getnumberptr256(char *namestart, void *num, int32_t bytes, int32_t maxnumbe static void DoSpriteOrnament(int32_t i) { - int32_t j; + int32_t j, hitw; hitdata_t hitinfo; hitscan((const vec3_t *)&sprite[i],sprite[i].sectnum, - sintable[(sprite[i].ang+2560+1024)&2047], - sintable[(sprite[i].ang+2048+1024)&2047], + sintable[(sprite[i].ang+1536)&2047], + sintable[(sprite[i].ang+1024)&2047], 0, &hitinfo,CLIPMASK1); @@ -3959,16 +3600,19 @@ static void DoSpriteOrnament(int32_t i) sprite[i].y = hitinfo.pos.y; sprite[i].z = hitinfo.pos.z; changespritesect(i,hitinfo.hitsect); - if (hitinfo.hitwall >= 0) - sprite[i].ang = ((getangle(wall[wall[hitinfo.hitwall].point2].x-wall[hitinfo.hitwall].x, - wall[wall[hitinfo.hitwall].point2].y-wall[hitinfo.hitwall].y)+512)&2047); + + hitw = hitinfo.hitwall; + + if (hitw >= 0) + sprite[i].ang = (getangle(POINT2(hitw).x-wall[hitw].x, + POINT2(hitw).y-wall[hitw].y)+512)&2047; //Make sure sprite's in right sector if (inside(sprite[i].x,sprite[i].y,sprite[i].sectnum) == 0) { - j = wall[hitinfo.hitwall].point2; - sprite[i].x -= ksgn(wall[j].y-wall[hitinfo.hitwall].y); - sprite[i].y += ksgn(wall[j].x-wall[hitinfo.hitwall].x); + j = wall[hitw].point2; + sprite[i].x -= ksgn(wall[j].y-wall[hitw].y); + sprite[i].y += ksgn(wall[j].x-wall[hitw].x); } } @@ -4054,8 +3698,8 @@ ENDFOR1: Bmemcpy(sp, &sprite[startspr], sizeof(spritetype)); sp->yoffset = 0; sp->picnum = SMALLFNTCURSOR; - sp->xrepeat = min(max(sp->xrepeat/tilesizx[sp->picnum],2),255); - sp->yrepeat = min(max((sp->yrepeat*tilesizy[sprite[startspr].picnum])/tilesizy[sp->picnum],4),255); + sp->xrepeat = clamp(sp->xrepeat/tilesizx[sp->picnum], 2, 255); + sp->yrepeat = clamp((sp->yrepeat*tilesizy[sprite[startspr].picnum])/tilesizy[sp->picnum], 4, 255); sp->pal = 0; sp->cstat = 18; @@ -4063,64 +3707,38 @@ ENDFOR1: while (keystatus[0x1] == 0) { if (handleevents()) - { - if (quitevent) quitevent = 0; - } + quitevent = 0; - if (keystatus[KEYSC_UP]) // vertical gap in pixels (32 x-units) - { - keystatus[KEYSC_UP]=0; - if (vgap<255) vgap++; - } - if (keystatus[KEYSC_DOWN]) - { - keystatus[KEYSC_DOWN]=0; - if (vgap>0) vgap--; - } - if (keystatus[KEYSC_RIGHT]) // horizontal gap in half pixels - { - keystatus[KEYSC_RIGHT]=0; - if (hgap<255) hgap++; - } - if (keystatus[KEYSC_LEFT]) - { - keystatus[KEYSC_LEFT]=0; - if (hgap>0) hgap--; - } + if (PRESSED_KEYSC(UP)) // vertical gap in pixels (32 x-units) + vgap += (vgap<255); - if (keystatus[KEYSC_INSERT]) // space gap in half pixels - { - keystatus[KEYSC_INSERT]=0; - if (spcgap[alphidx]<255) spcgap[alphidx]++; - } - if (keystatus[KEYSC_DELETE]) - { - keystatus[KEYSC_DELETE]=0; - if (spcgap[alphidx]>1) spcgap[alphidx]--; - } + if (PRESSED_KEYSC(DOWN)) + vgap -= (vgap>0); - if (keystatus[KEYSC_HOME]) // shade - { - keystatus[KEYSC_HOME]=0; - if (sprite[linebegspr].shade<127) sprite[linebegspr].shade++; - } - if (keystatus[KEYSC_END]) - { - keystatus[KEYSC_END]=0; - if (sprite[linebegspr].shade>-128) sprite[linebegspr].shade--; - } + if (PRESSED_KEYSC(RIGHT)) // horizontal gap in half pixels + hgap += (hgap<255); - if (keystatus[KEYSC_PGUP]) // pal - { - keystatus[KEYSC_PGUP]=0; - if (sprite[linebegspr].pal<255) sprite[linebegspr].pal++; - } - if (keystatus[KEYSC_PGDN]) - { - keystatus[KEYSC_PGDN]=0; - if (sprite[linebegspr].pal>0) sprite[linebegspr].pal--; - } + if (PRESSED_KEYSC(LEFT)) + hgap -= (hgap>0); + + if (PRESSED_KEYSC(INSERT)) // space gap in half pixels + spcgap[alphidx] += (spcgap[alphidx]<255); + + if (PRESSED_KEYSC(DELETE)) + spcgap[alphidx] -= (spcgap[alphidx]>1); + + if (PRESSED_KEYSC(HOME)) // shade + sprite[linebegspr].shade += (sprite[linebegspr].shade<127); + + if (PRESSED_KEYSC(END)) + sprite[linebegspr].shade -= (sprite[linebegspr].shade>-128); + + if (PRESSED_KEYSC(PGUP)) // pal + sprite[linebegspr].pal += (sprite[linebegspr].pal<255); + + if (PRESSED_KEYSC(PGDN)) + sprite[linebegspr].pal -= (sprite[linebegspr].pal>0); drawrooms(pos.x,pos.y,pos.z,ang,horiz,cursectnum); #ifdef SUPERBUILD @@ -4297,11 +3915,11 @@ ERROR_NOMEMORY: static void Keys3d(void) { - int32_t i,count,nexti,changedir; + int32_t i,changedir,tsign; // ,count,nexti int32_t j, k, tempint = 0, hiz, loz; int32_t hihit, lohit; - char smooshyalign=0, repeatpanalign=0, buffer[80]; - int16_t startwall, endwall, dasector, statnum=0; + char smooshyalign=0, repeatpanalign=0; //, buffer[80]; + int16_t startwall, endwall, dasector; //, statnum=0; char tempbuf[128]; /* start Mapster32 */ @@ -4331,7 +3949,8 @@ static void Keys3d(void) if (usedcount && !helpon) { - if (searchstat!=SEARCH_SPRITE) +#if 0 + if (!AIMING_AT_SPRITE) { count=0; for (i=0; i= 0 && wall[searchwall].nextsector < numsectors) { - int32_t nextsect=wall[searchwall].nextsector; - height1=sector[searchsector].floorz-sector[nextsect].floorz; - height2=sector[nextsect].floorz-sector[nextsect].ceilingz; - height3=sector[nextsect].ceilingz-sector[searchsector].ceilingz; + int32_t nextsect = wall[searchwall].nextsector; + height1 = sector[searchsector].floorz - sector[nextsect].floorz; + height2 = sector[nextsect].floorz - sector[nextsect].ceilingz; + height3 = sector[nextsect].ceilingz - sector[searchsector].ceilingz; } - Bsprintf(lines[num++],"Panning: %d, %d",wall[w].xpanning,wall[w].ypanning); - Bsprintf(lines[num++],"Repeat: %d, %d",wall[searchwall].xrepeat,wall[searchwall].yrepeat); - Bsprintf(lines[num++],"Overpic: %d",wall[searchwall].overpicnum); + + Bsprintf(lines[num++],"Panning: %d, %d", wall[w].xpanning, wall[w].ypanning); + Bsprintf(lines[num++],"Repeat: %d, %d", wall[searchwall].xrepeat, wall[searchwall].yrepeat); + Bsprintf(lines[num++],"Overpic: %d", wall[searchwall].overpicnum); lines[num++][0]=0; + if (getmessageleng) break; - Bsprintf(lines[num++],"^251Wall %d^31",searchwall); + + Bsprintf(lines[num++],"^251Wall %d^31", searchwall); + if (wall[searchwall].nextsector!=-1) Bsprintf(lines[num++],"LoHeight:%d, HiHeight:%d, Length:%d",height1,height3,dist); else Bsprintf(lines[num++],"Height:%d, Length:%d",height2,dist); break; + case SEARCH_CEILING: - drawtileinfo("Current",WIND1X,WIND1Y,sector[searchsector].ceilingpicnum,sector[searchsector].ceilingshade, - sector[searchsector].ceilingpal,sector[searchsector].ceilingstat, - sector[searchsector].lotag,sector[searchsector].hitag,sector[searchsector].extra); - - Bsprintf(lines[num++],"Panning: %d, %d",sector[searchsector].ceilingxpanning,sector[searchsector].ceilingypanning); - Bsprintf(lines[num++],"CeilingZ: %d",sector[searchsector].ceilingz); - Bsprintf(lines[num++],"Slope: %d",sector[searchsector].ceilingheinum); - lines[num++][0]=0; - if (getmessageleng) - break; - Bsprintf(lines[num++],"^251Sector %d^31 ceiling, Lotag:%s",searchsector,ExtGetSectorCaption(searchsector)); - Bsprintf(lines[num++],"Height: %d, Visibility:%d",height2,sector[searchsector].visibility); - break; case SEARCH_FLOOR: - drawtileinfo("Current",WIND1X,WIND1Y,sector[searchsector].floorpicnum,sector[searchsector].floorshade, - sector[searchsector].floorpal,sector[searchsector].floorstat, - sector[searchsector].lotag,sector[searchsector].hitag,sector[searchsector].extra); + drawtileinfo("Current", WIND1X, WIND1Y, AIMED_CEILINGFLOOR(picnum), AIMED_CEILINGFLOOR(shade), + AIMED_CEILINGFLOOR(pal), AIMED_CEILINGFLOOR(stat), + sector[searchsector].lotag, sector[searchsector].hitag, sector[searchsector].extra); - Bsprintf(lines[num++],"Panning: %d,%d",sector[searchsector].floorxpanning,sector[searchsector].floorypanning); - Bsprintf(lines[num++],"FloorZ: %d",sector[searchsector].floorz); - Bsprintf(lines[num++],"Slope: %d",sector[searchsector].floorheinum); + Bsprintf(lines[num++],"Panning: %d, %d", AIMED_CEILINGFLOOR(xpanning), AIMED_CEILINGFLOOR(ypanning)); + Bsprintf(lines[num++],"%sZ: %d", Typestr[searchstat], AIMED_CEILINGFLOOR(z)); + Bsprintf(lines[num++],"Slope: %d", AIMED_CEILINGFLOOR(heinum)); lines[num++][0]=0; + if (getmessageleng) break; - Bsprintf(lines[num++],"^251Sector %d^31 floor, Lotag:%s",searchsector,ExtGetSectorCaption(searchsector)); - Bsprintf(lines[num++],"Height:%d, Visibility:%d",height2,sector[searchsector].visibility); + + Bsprintf(lines[num++],"^251Sector %d^31 %s, Lotag:%s", searchsector, typestr[searchstat], ExtGetSectorCaption(searchsector)); + Bsprintf(lines[num++],"Height: %d, Visibility:%d", height2, sector[searchsector].visibility); break; - case SEARCH_SPRITE: - drawtileinfo("Current",WIND1X,WIND1Y,sprite[searchwall].picnum,sprite[searchwall].shade, - sprite[searchwall].pal,sprite[searchwall].cstat,sprite[searchwall].lotag, - sprite[searchwall].hitag,sprite[searchwall].extra); - Bsprintf(lines[num++],"Repeat: %d,%d",sprite[searchwall].xrepeat,sprite[searchwall].yrepeat); - Bsprintf(lines[num++],"PosXY: %d,%d",sprite[searchwall].x,sprite[searchwall].y); - Bsprintf(lines[num++],"PosZ: "" %d",sprite[searchwall].z);// prevents tab character + case SEARCH_SPRITE: + drawtileinfo("Current", WIND1X, WIND1Y, sprite[searchwall].picnum, sprite[searchwall].shade, + sprite[searchwall].pal, sprite[searchwall].cstat, sprite[searchwall].lotag, + sprite[searchwall].hitag, sprite[searchwall].extra); + + Bsprintf(lines[num++], "Repeat: %d,%d", sprite[searchwall].xrepeat, sprite[searchwall].yrepeat); + Bsprintf(lines[num++], "PosXY: %d,%d", sprite[searchwall].x, sprite[searchwall].y); + Bsprintf(lines[num++], "PosZ: "" %d", sprite[searchwall].z);// prevents tab character lines[num++][0]=0; if (getmessageleng) break; - if (strlen(names[sprite[searchwall].picnum]) > 0) + + if (names[sprite[searchwall].picnum][0]) { if (sprite[searchwall].picnum==SECTOREFFECTOR) - Bsprintf(lines[num++],"^251Sprite %d^31 %s",searchwall,SectorEffectorText(searchwall)); - else Bsprintf(lines[num++],"^251Sprite %d^31 %s",searchwall,names[sprite[searchwall].picnum]); + Bsprintf(lines[num++],"^251Sprite %d^31 %s", searchwall, SectorEffectorText(searchwall)); + else + Bsprintf(lines[num++],"^251Sprite %d^31 %s", searchwall, names[sprite[searchwall].picnum]); } - else Bsprintf(lines[num++],"^251Sprite %d^31, picnum %d",searchwall,sprite[searchwall].picnum); - Bsprintf(lines[num++],"Elevation:%d",getflorzofslope(searchsector,sprite[searchwall].x,sprite[searchwall].y)-sprite[searchwall].z); + else Bsprintf(lines[num++],"^251Sprite %d^31, picnum %d", searchwall, sprite[searchwall].picnum); + + Bsprintf(lines[num++], "Elevation:%d", + getflorzofslope(searchsector, sprite[searchwall].x, sprite[searchwall].y) - sprite[searchwall].z); break; } } - x=WIND1X; y=WIND1Y; - x=(int32_t)(x*(xdimgame/320.)); - y=(int32_t)(y*(ydimgame/200.)); - y+=(ydimgame>>6)*8; + + x = WIND1X*(xdimgame/320.); + y = WIND1Y*(ydimgame/200.); + y += (ydimgame>>6)*8; + if (getmessageleng) { while (num < 4) lines[num++][0] = 0; Bsprintf(lines[num++],"^251%s",getmessage); } + begindrawing(); for (i=0; i640?0:1); - printext256(x,y,whitecol,-1,lines[i],xdimgame>640?0:1); - y+=ydimgame>>6; + printext256(x+2, y+2, 0, -1, lines[i], xdimgame<=640); + printext256(x, y, whitecol, -1, lines[i], xdimgame<=640); + y += ydimgame>>6; } enddrawing(); } VM_OnEvent(EVENT_PREKEYS3D, -1); - if (keystatus[KEYSC_QUOTE] && keystatus[KEYSC_V]) // ' V + if (keystatus[KEYSC_QUOTE] && PRESSED_KEYSC(V)) // ' V { - keystatus[KEYSC_V] = 0; - switch (searchstat) - { - case SEARCH_CEILING: - case SEARCH_FLOOR: - getnumberptr256("Sector visibility: ",§or[searchsector].visibility,sizeof(sector[searchsector].visibility),256L,0,NULL); - break; - } + if (AIMING_AT_CEILING_OR_FLOOR) + getnumberptr256("Sector visibility: ", §or[searchsector].visibility, sizeof(sector[0].visibility), 255, 0, NULL); } - if (keystatus[KEYSC_SEMI] && keystatus[KEYSC_V]) // ; V + if (keystatus[KEYSC_SEMI] && PRESSED_KEYSC(V)) // ; V { int16_t currsector; uint8_t visval; - keystatus[KEYSC_V] = 0; - if (highlightsectorcnt == -1) { message("You didn't select any sectors!"); return; } - visval = (uint8_t)getnumber256("Visibility of selected sectors: ",sector[searchsector].visibility,256L,0); - if (AskIfSure(0)) return; - for (i = 0; i < highlightsectorcnt; i++) + visval = getnumber256("Visibility of selected sectors: ", sector[searchsector].visibility, 255, 0); + + if (AskIfSure(0)) + return; + + for (i=0; i= 0) - wall[wall[searchwall].nextwall].overpicnum = tempint; + int32_t oldtile = AIMED_SELOVR_PICNUM; + + tempint = m32gettile(oldtile); + AIMED_SELOVR_PICNUM = tempint; + + if (AIMING_AT_MASKWALL && wall[searchwall].nextwall >= 0) + NEXTWALL(searchwall).overpicnum = tempint; + + if (oldtile != tempint) + asksave = 1; } - if (oldtile!=tempint)asksave = 1; - keystatus[KEYSC_V] = 0; } - if (keystatus[KEYSC_3]) /* 3 (toggle floor-over-floor (cduke3d only) */ + if (PRESSED_KEYSC(3)) /* 3 (toggle floor-over-floor (cduke3d only) */ { floor_over_floor = !floor_over_floor; // if (!floor_over_floor) ResetFOFSize(); message("Floor-over-floor display %s",floor_over_floor?"enabled":"disabled"); - keystatus[KEYSC_3] = 0; } - if (keystatus[KEYSC_F3]) + if (PRESSED_KEYSC(F3)) { mlook = !mlook; message("Mouselook: %s",mlook?"enabled":"disabled"); - keystatus[KEYSC_F3] = 0; } - if (keystatus[KEYSC_F4]) + if (PRESSED_KEYSC(F4)) { AmbienceToggle = !AmbienceToggle; message("Ambience sounds: %s",AmbienceToggle?"enabled":"disabled"); @@ -4561,72 +4167,75 @@ static void Keys3d(void) FX_StopAllSounds(); S_ClearSoundLocks(); } - keystatus[KEYSC_F4] = 0; } // PK - if (keystatus[KEYSC_F5]) + if (PRESSED_KEYSC(F5)) { unrealedlook = !unrealedlook; message("UnrealEd mouse navigation: %s",unrealedlook?"enabled":"disabled"); - keystatus[KEYSC_F5] = 0; } - if (keystatus[KEYSC_QUOTE] && keystatus[KEYSC_DELETE]) // ' del + if (keystatus[KEYSC_QUOTE] && PRESSED_KEYSC(DELETE)) // ' del { - keystatus[KEYSC_DELETE] = 0; - switch (searchstat) + if (AIMING_AT_WALL_OR_MASK) { - case SEARCH_WALL: - case SEARCH_MASKWALL: wall[searchwall].cstat = 0; - message("Wall %d cstat = 0",searchwall); - break; - // case 1: case 2: sector[searchsector].cstat = 0; break; - case SEARCH_SPRITE: + message("Wall %d cstat = 0", searchwall); + } + else if (AIMING_AT_SPRITE) + { sprite[searchwall].cstat = 0; - message("Sprite %d cstat = 0",searchwall); - break; + message("Sprite %d cstat = 0", searchwall); } } - // 'P - Will copy palette to all sectors highlighted with R-Alt key - if (keystatus[KEYSC_QUOTE] && keystatus[KEYSC_P]) // ' P + // 'P and ;P - Will copy palette to all sectors/walls/sprites highlighted with R-Alt key + if ((keystatus[KEYSC_QUOTE] || keystatus[KEYSC_SEMI]) && PRESSED_KEYSC(P)) // ' P ; P { int16_t w, start_wall, end_wall, currsector; int8_t pal[4]; - keystatus[KEYSC_P] = 0; - if (highlightsectorcnt == -1) { message("You didn't select any sectors!"); return; } - pal[0] = getnumber256("Ceiling palette: ",-1,MAXPALOOKUPS,1); - pal[1] = getnumber256("Floor palette: ",-1,MAXPALOOKUPS,1); - pal[2] = getnumber256("Wall palette: ",-1,MAXPALOOKUPS,1); - pal[3] = getnumber256("Sprite palette: ",-1,MAXPALOOKUPS,1); + if (keystatus[KEYSC_QUOTE]) + { + pal[0] = getnumber256("Ceiling palette: ", -1, MAXPALOOKUPS, 1); + pal[1] = getnumber256("Floor palette: ", -1, MAXPALOOKUPS, 1); + pal[2] = getnumber256("Wall palette: ", -1, MAXPALOOKUPS, 1); + pal[3] = getnumber256("Sprite palette: ", -1, MAXPALOOKUPS, 1); + } + else + { + pal[0] = getnumber256("Global palette: ", 0, MAXPALOOKUPS, 0); + pal[1] = pal[2] = pal[3] = pal[0]; + } + if (AskIfSure(0)) return; for (i = 0; i < highlightsectorcnt; i++) { currsector = highlightsector[i]; + if (pal[0] > -1) sector[currsector].ceilingpal = pal[0]; if (pal[1] > -1) sector[currsector].floorpal = pal[1]; + // Do all the walls in the sector start_wall = sector[currsector].wallptr; end_wall = start_wall + sector[currsector].wallnum; if (pal[2] > -1) for (w = start_wall; w < end_wall; w++) - { wall[w].pal = pal[2]; - } + if (pal[3] > -1) + { for (k=0; k= 0) - { - j = nextspritesect[w]; - sprite[w].pal = pal; - w = j; - } - } - } - message("Palettes changed"); - } - - if (keystatus[KEYSC_DELETE]) - { - if (searchstat == SEARCH_SPRITE) + if (AIMING_AT_SPRITE) { deletesprite(searchwall); updatenumsprites(); @@ -4698,98 +4266,86 @@ static void Keys3d(void) } asksave = 1; } - keystatus[KEYSC_DELETE] = 0; } - if (keystatus[KEYSC_F6]) //F6 + if (PRESSED_KEYSC(F6)) //F6 { - keystatus[KEYSC_F6] = 0; - autospritehelp=!autospritehelp; - message("Automatic SECTOREFFECTOR help %s",autospritehelp?"enabled":"disabled"); + autospritehelp = !autospritehelp; + message("Automatic SECTOREFFECTOR help %s", autospritehelp?"enabled":"disabled"); } - if (keystatus[KEYSC_F7]) //F7 + if (PRESSED_KEYSC(F7)) //F7 { - keystatus[KEYSC_F7] = 0; - autosecthelp=!autosecthelp; - message("Automatic sector tag help %s",autosecthelp?"enabled":"disabled"); + autosecthelp = !autosecthelp; + message("Automatic sector tag help %s", autosecthelp?"enabled":"disabled"); } - if ((searchstat == SEARCH_SPRITE) && (sprite[searchwall].picnum==SECTOREFFECTOR)) - if (autospritehelp && helpon==0) Show3dText("sehelp.hlp"); - - if (searchstat == SEARCH_CEILING || searchstat == SEARCH_FLOOR) - if (autosecthelp && helpon==0) Show3dText("sthelp.hlp"); - - - - if (keystatus[KEYSC_COMMA]) // , Search & fix panning to the left (3D) + if (autospritehelp && helpon==0) { - if (searchstat == SEARCH_SPRITE) + if (AIMING_AT_SPRITE && sprite[searchwall].picnum==SECTOREFFECTOR) + Show3dText("sehelp.hlp"); + else if (AIMING_AT_CEILING_OR_FLOOR) + Show3dText("sthelp.hlp"); + } + + if (AIMING_AT_WALL_OR_MASK && PRESSED_KEYSC(PERIOD)) + { + AutoAlignWalls((int32_t)searchwall, 0); + message("Wall %d autoalign", searchwall); + } + + + tsign = 0; + tsign -= PRESSED_KEYSC(COMMA); + tsign += PRESSED_KEYSC(PERIOD);; + + if (tsign) // , . Search & fix panning to the left/right (3D) + { + if (AIMING_AT_SPRITE) { - i = searchwall; - if (eitherSHIFT) - sprite[i].ang = ((sprite[i].ang+2048-1)&2047); - else - { - sprite[i].ang = ((sprite[i].ang+2048-128)&2047); - keystatus[KEYSC_COMMA] = 0; - } - message("Sprite %d angle: %d",i,sprite[i].ang); - } - } - if (keystatus[KEYSC_PERIOD]) // . Search & fix panning to the right (3D) - { - if ((searchstat == SEARCH_WALL) || (searchstat == SEARCH_MASKWALL)) - { - AutoAlignWalls((int32_t)searchwall,0L); - message("Wall %d autoalign",searchwall); - keystatus[KEYSC_PERIOD] = 0; - } - if (searchstat == SEARCH_SPRITE) - { - i = searchwall; - if (eitherSHIFT) - sprite[i].ang = ((sprite[i].ang+2048+1)&2047); - else - { - sprite[i].ang = ((sprite[i].ang+2048+128)&2047); - keystatus[KEYSC_PERIOD] = 0; - } - message("Sprite %d angle: %d",i,sprite[i].ang); + sprite[searchwall].ang += tsign<<(eitherSHIFT*7); + sprite[searchwall].ang &= 2047; + message("Sprite %d angle: %d", searchwall, sprite[searchwall].ang); } } - if (keystatus[KEYSC_QUOTE] && keystatus[KEYSC_L]) // ' L + if (keystatus[KEYSC_QUOTE] && PRESSED_KEYSC(L)) // ' L { i = noclip; noclip = 1; + switch (searchstat) { case SEARCH_CEILING: - getnumberptr256("Sector ceilingz: ",§or[searchsector].ceilingz,sizeof(sector[searchsector].ceilingz),8388608,1,NULL); + getnumberptr256("Sector ceilingz: ", §or[searchsector].ceilingz, + sizeof(sector[0].ceilingz), 8388608, 1, NULL); if (!(sector[searchsector].ceilingstat&2)) { sector[searchsector].ceilingstat |= 2; sector[searchsector].ceilingheinum = 0; } - getnumberptr256("Sector ceiling slope: ",§or[searchsector].ceilingheinum,sizeof(sector[searchsector].ceilingheinum),65536,1,NULL); + getnumberptr256("Sector ceiling slope: ", §or[searchsector].ceilingheinum, + sizeof(sector[0].ceilingheinum), 65536, 1, NULL); break; case SEARCH_FLOOR: - getnumberptr256("Sector floorz: ",§or[searchsector].floorz,sizeof(sector[searchsector].floorz),8388608,1,NULL); + getnumberptr256("Sector floorz: ", §or[searchsector].floorz, + sizeof(sector[0].floorz), 8388608, 1, NULL); if (!(sector[searchsector].floorstat&2)) { sector[searchsector].floorheinum = 0; sector[searchsector].floorstat |= 2; } - getnumberptr256("Sector floor slope: ",§or[searchsector].floorheinum,sizeof(sector[searchsector].floorheinum),65536,1,NULL); + getnumberptr256("Sector floor slope: ", §or[searchsector].floorheinum, + sizeof(sector[0].floorheinum), 65536, 1, NULL); break; + case SEARCH_SPRITE: - getnumberptr256("Sprite x: ",&sprite[searchwall].x,sizeof(sprite[searchwall].x),131072,1,NULL); - getnumberptr256("Sprite y: ",&sprite[searchwall].y,sizeof(sprite[searchwall].y),131072,1,NULL); - getnumberptr256("Sprite z: ",&sprite[searchwall].z,sizeof(sprite[searchwall].z),8388608,1,NULL); - getnumberptr256("Sprite angle: ",&sprite[searchwall].ang,sizeof(sprite[searchwall].ang),2048L,0,NULL); + getnumberptr256("Sprite x: ", &sprite[searchwall].x, sizeof(sprite[0].x), 131072, 1, NULL); + getnumberptr256("Sprite y: ", &sprite[searchwall].y, sizeof(sprite[0].y), 131072, 1, NULL); + getnumberptr256("Sprite z: ", &sprite[searchwall].z, sizeof(sprite[0].z), 8388608, 1, NULL); + getnumberptr256("Sprite angle: ", &sprite[searchwall].ang, sizeof(sprite[0].ang), 2047, 0, NULL); break; } + if (sector[searchsector].ceilingheinum == 0) sector[searchsector].ceilingstat &= ~2; else @@ -4799,238 +4355,195 @@ static void Keys3d(void) sector[searchsector].floorstat &= ~2; else sector[searchsector].floorstat |= 2; + asksave = 1; - keystatus[KEYSC_L] = 0; noclip = i; } - getzrange(&pos,cursectnum,&hiz,&hihit,&loz,&lohit,128L,CLIPMASK0); - if (keystatus[KEYSC_CAPS] || (keystatus[KEYSC_QUOTE] && keystatus[KEYSC_Z])) + getzrange(&pos, cursectnum, &hiz, &hihit, &loz, &lohit, 128L, CLIPMASK0); + + if (PRESSED_KEYSC(CAPS) || (keystatus[KEYSC_QUOTE] && PRESSED_KEYSC(Z))) // CAPS LOCK { - zmode++; - if (zmode == 3) zmode = 0; - else if (zmode == 1) zlock = (loz-pos.z)&0xfffffc00; + zmode = (zmode+1)%3; + if (zmode == 1) + zlock = (loz-pos.z)&0xfffffc00; switch (zmode) { case 0: message("Zmode = Gravity"); break; case 1: message("Zmode = Locked/Sector"); break; case 2: message("Zmode = Locked/Free"); break; } - keystatus[KEYSC_CAPS] = keystatus[KEYSC_Z] = 0; } - if (keystatus[KEYSC_QUOTE] && keystatus[KEYSC_M]) // M + if (keystatus[KEYSC_QUOTE] && PRESSED_KEYSC(M)) // 'M { - switch (searchstat) + if (ASSERT_AIMING) { - case SEARCH_WALL: - case SEARCH_MASKWALL: - strcpy(buffer,"Wall extra: "); - wall[searchwall].extra = getnumber256(buffer,(int32_t)wall[searchwall].extra,65536L,1); - break; - case SEARCH_CEILING: - case SEARCH_FLOOR: - strcpy(buffer,"Sector extra: "); - sector[searchsector].extra = getnumber256(buffer,(int32_t)sector[searchsector].extra,65536L,1); - break; - case SEARCH_SPRITE: - // strcpy(buffer,"Sprite extra: "); - // sprite[searchwall].extra = getnumber256(buffer,(int32_t)sprite[searchwall].extra,65536L,1); - getnumberptr256("Sprite extra: ",&sprite[searchwall].extra,sizeof(sprite[searchwall].extra),65536,1,NULL); - break; + Bsprintf(tempbuf, "%s extra: ", Typestr_wss[searchstat]); + getnumberptr256(tempbuf, &AIMED(extra), sizeof(int16_t), BTAG_MAX, 0, NULL); + asksave = 1; } - asksave = 1; - keystatus[KEYSC_M] = 0; } - if (keystatus[KEYSC_1]) // 1 (make 1-way wall) + if (PRESSED_KEYSC(1) && ASSERT_AIMING) // 1 (make 1-way wall) { - if (searchstat != SEARCH_SPRITE) + if (!AIMING_AT_SPRITE) { wall[searchwall].cstat ^= 32; - Bsprintf(getmessage,"Wall %d one side masking bit %s",searchwall,wall[searchwall].cstat&32?"ON":"OFF"); - message(getmessage); - asksave = 1; + message("Wall %d one side masking bit %s", searchwall, ONOFF(wall[searchwall].cstat&32)); } else { - sprite[searchwall].cstat ^= 64; i = sprite[searchwall].cstat; + i ^= 64; if ((i&48) == 32) { - sprite[searchwall].cstat &= ~8; - if ((i&64) > 0) - if (pos.z > sprite[searchwall].z) - sprite[searchwall].cstat |= 8; + i &= ~8; + if ((i&64) && pos.z>sprite[searchwall].z) + i |= 8; } - asksave = 1; - Bsprintf(getmessage,"Sprite %d one sided bit %s",searchwall,sprite[searchwall].cstat&64?"ON":"OFF"); - message(getmessage); - + message("Sprite %d one sided bit %s", searchwall, ONOFF(i&64)); + sprite[searchwall].cstat = i; } - keystatus[KEYSC_1] = 0; + asksave = 1; } - if (keystatus[KEYSC_2]) // 2 (bottom wall swapping) + + if (PRESSED_KEYSC(2)) // 2 (bottom wall swapping) { if (searchstat != SEARCH_SPRITE) { wall[searchwall].cstat ^= 2; - Bsprintf(getmessage,"Wall %d bottom texture swap bit %s",searchwall,wall[searchwall].cstat&2?"ON":"OFF"); - message(getmessage); + message("Wall %d bottom texture swap bit %s", searchwall, ONOFF(wall[searchwall].cstat&2)); asksave = 1; } - keystatus[KEYSC_2] = 0; } - if (keystatus[KEYSC_O]) // O (top/bottom orientation - for doors) - { - if ((searchstat == SEARCH_WALL) || (searchstat == SEARCH_MASKWALL)) - { - int16_t w = (searchstat==SEARCH_WALL)?searchbottomwall:searchwall; - wall[w].cstat ^= 4; - Bsprintf(getmessage,"Wall %d %s orientation",w,wall[w].cstat&4?"bottom":"top"); - message(getmessage); - asksave = 1; - } - if (searchstat == SEARCH_SPRITE) // O (ornament onto wall) (2D) - { - asksave = 1; - i = searchwall; - DoSpriteOrnament(i); - Bsprintf(getmessage,"Sprite %d ornament onto wall",i); - message(getmessage); - } - keystatus[KEYSC_O] = 0; - } - if (keystatus[KEYSC_M]) // M (masking walls) + if (PRESSED_KEYSC(O)) // O (top/bottom orientation - for doors) { - if (searchstat != SEARCH_SPRITE) + if (AIMING_AT_WALL_OR_MASK) { - i = wall[searchwall].nextwall; - tempint = eitherSHIFT; - if (i >= 0) + int16_t w = SELECT_WALL(); + wall[w].cstat ^= 4; + message("Wall %d %s orientation", w, wall[w].cstat&4?"bottom":"top"); + asksave = 1; + } + else if (AIMING_AT_SPRITE) // O (ornament onto wall) (2D) + { + DoSpriteOrnament(searchwall); + message("Sprite %d ornament onto wall", searchwall); + asksave = 1; + } + } + + if (PRESSED_KEYSC(M)) // M (masking walls) + { + if (!AIMING_AT_SPRITE && ASSERT_AIMING) + { + int16_t next = wall[searchwall].nextwall; + + if (next >= 0) { wall[searchwall].cstat ^= 16; - Bsprintf(getmessage,"Wall %d masking bit %s",searchwall,wall[searchwall].cstat&16?"ON":"OFF"); - message(getmessage); - if ((wall[searchwall].cstat&16) > 0) + message("Wall %d masking bit %s", searchwall, ONOFF(wall[searchwall].cstat&16)); + + wall[searchwall].cstat &= ~8; + + if (wall[searchwall].cstat&16) { - wall[searchwall].cstat &= ~8; - if (tempint == 0) + if (!eitherSHIFT) { - wall[i].cstat |= 8; //auto other-side flip - wall[i].cstat |= 16; - wall[i].overpicnum = wall[searchwall].overpicnum; + wall[next].cstat |= 8; //auto other-side flip + wall[next].cstat |= 16; + wall[next].overpicnum = wall[searchwall].overpicnum; } } else { - wall[searchwall].cstat &= ~8; - if (tempint == 0) + if (!eitherSHIFT) { - wall[i].cstat &= ~8; //auto other-side unflip - wall[i].cstat &= ~16; + wall[next].cstat &= ~8; //auto other-side unflip + wall[next].cstat &= ~16; } } + wall[searchwall].cstat &= ~32; - if (tempint == 0) wall[i].cstat &= ~32; + if (!eitherSHIFT) + wall[next].cstat &= ~32; + asksave = 1; } } - keystatus[KEYSC_M] = 0; } - if (keystatus[KEYSC_H]) // H (hitscan sensitivity) + if (PRESSED_KEYSC(H)) // H (hitscan sensitivity) { - if ((keystatus[KEYSC_QUOTE])) + if (keystatus[KEYSC_QUOTE]) { - switch (searchstat) + if (ASSERT_AIMING) { - case SEARCH_WALL: - case SEARCH_MASKWALL: - strcpy(buffer,"Wall hitag: "); - wall[searchwall].hitag = getnumber256(buffer,(int32_t)wall[searchwall].hitag,65536L,0); - break; - case SEARCH_CEILING: - case SEARCH_FLOOR: - strcpy(buffer,"Sector hitag: "); - sector[searchsector].hitag = getnumber256(buffer,(int32_t)sector[searchsector].hitag,65536L,0); - break; - case SEARCH_SPRITE: - strcpy(buffer,"Sprite hitag: "); - // sprite[searchwall].hitag = getnumber256(buffer,(int32_t)sprite[searchwall].hitag,65536L,0); - getnumberptr256(buffer,&sprite[searchwall].hitag,sizeof(sprite[searchwall].hitag),INT16_MAX,1,NULL); - break; + Bsprintf(tempbuf, "%s hitag: ", Typestr_wss[searchstat]); + getnumberptr256(tempbuf, &AIMED(hitag), sizeof(int16_t), BTAG_MAX, 0, NULL); } } - else { - - if (searchstat == SEARCH_SPRITE) + if (AIMING_AT_SPRITE) { sprite[searchwall].cstat ^= 256; - Bsprintf(getmessage,"Sprite %d hitscan sensitivity bit %s",searchwall,sprite[searchwall].cstat&256?"ON":"OFF"); - message(getmessage); + message("Sprite %d hitscan sensitivity bit %s", searchwall, ONOFF(sprite[searchwall].cstat&256)); asksave = 1; } else { wall[searchwall].cstat ^= 64; - if ((wall[searchwall].nextwall >= 0) && (eitherSHIFT == 0)) + if (wall[searchwall].nextwall >= 0 && !eitherSHIFT) { - wall[wall[searchwall].nextwall].cstat &= ~64; - wall[wall[searchwall].nextwall].cstat |= (wall[searchwall].cstat&64); + NEXTWALL(searchwall).cstat &= ~64; + NEXTWALL(searchwall).cstat |= (wall[searchwall].cstat&64); } - Bsprintf(getmessage,"Wall %d hitscan sensitivity bit %s",searchwall,wall[searchwall].cstat&64?"ON":"OFF"); - message(getmessage); + message("Wall %d hitscan sensitivity bit %s", searchwall, ONOFF(wall[searchwall].cstat&64)); asksave = 1; } } - keystatus[KEYSC_H] = 0; } smooshyalign = keystatus[KEYSC_gKP5]; - repeatpanalign = (eitherSHIFT || (bstatus&2)); + repeatpanalign = eitherSHIFT || (bstatus&2); if (mlook == 2) mlook = 0; - if (!unrealedlook && (bstatus&4)) mlook = 2; + if (!unrealedlook && (bstatus&4)) + mlook = 2; - // if (bstatus&4) - if ((bstatus&(16|32) && !(bstatus&(1|2|4))) || keystatus[KEYSC_gMINUS] || keystatus[KEYSC_gPLUS]) // PK: no btn: wheel changes shade + // PK: no btn: wheel changes shade + if ((bstatus&(16|32) && !(bstatus&(1|2|4))) || keystatus[KEYSC_gMINUS] || keystatus[KEYSC_gPLUS]) { // if (bstatus&1) - // { // mlook = 2; - // } tsign = 0; - if (bstatus&32 || keystatus[KEYSC_gMINUS]) // - + if (bstatus&32 || PRESSED_KEYSC(gMINUS)) // - tsign = 1; - if (bstatus&16 || keystatus[KEYSC_gPLUS]) // + + if (bstatus&16 || PRESSED_KEYSC(gPLUS)) // + tsign = -1; if (tsign) { - keystatus[KEYSC_gMINUS] = keystatus[KEYSC_gPLUS] = 0; mouseb &= ~(16|32); bstatus &= ~(16|32); + if (eitherALT) //ALT { if (eitherCTRL) //CTRL { if (tsign==1) - { - if (visibility < 16384) visibility += visibility; - } + visibility <<= (visibility < 16384); else - if (visibility > 32) visibility >>= 1; - Bsprintf(getmessage,"Global visibility %d",visibility); - message(getmessage); + visibility >>= (visibility > 32); + message("Global visibility %d", visibility); } else { @@ -5045,6 +4558,7 @@ static void Keys3d(void) for (i=0; i 0) { sector[searchsector].visibility += tsign; + if (tsign==1) { if (sector[searchsector].visibility == 240) @@ -5071,12 +4587,11 @@ static void Keys3d(void) sector[searchsector].visibility = 240; k--; } - Bsprintf(getmessage,"Sector %d visibility %d",searchsector,sector[searchsector].visibility); - message(getmessage); + message("Sector %d visibility %d",searchsector,sector[searchsector].visibility); asksave = 1; } } - else + else // if !eitherALT { k = 0; if (highlightsectorcnt >= 0) @@ -5091,16 +4606,10 @@ static void Keys3d(void) if (k == 0) { - int32_t shade=-1, i=-1; - if (searchstat == SEARCH_WALL) shade = (wall[i=searchbottomwall].shade += tsign); - if (searchstat == SEARCH_CEILING) shade = (sector[i=searchsector].ceilingshade += tsign); - if (searchstat == SEARCH_FLOOR) shade = (sector[i=searchsector].floorshade += tsign); - if (searchstat == SEARCH_SPRITE) shade = (sprite[i=searchwall].shade += tsign); - if (searchstat == SEARCH_MASKWALL) shade = (wall[i=searchwall].shade += tsign); - if (i!=-1) + if (ASSERT_AIMING) { - Bsprintf(getmessage,"%s %d shade %d",type2str[searchstat],i,shade); - message(getmessage); + AIMED_CF_SEL(shade) += tsign; + message("%s %d shade %d", Typestr[searchstat], i, AIMED_CF_SEL(shade)); } } else @@ -5114,6 +4623,7 @@ static void Keys3d(void) startwall = sector[dasector].wallptr; //wall shade endwall = startwall + sector[dasector].wallnum - 1; + for (j=startwall; j<=endwall; j++) wall[j].shade += tsign; @@ -5130,287 +4640,141 @@ static void Keys3d(void) } } - // if ((keystatus[KEYSC_DASH]|keystatus[KEYSC_EQUAL]|((bstatus&(16|32)) && !(bstatus&2))) > 0) // mousewheel, -, and +, cycle picnum - if (keystatus[KEYSC_DASH] | keystatus[KEYSC_EQUAL] | (bstatus&(16|32) && (bstatus&1) && !(bstatus&2))) // PK: lmb only & mousewheel, -, and +, cycle picnum + // PK: lmb only & mousewheel, -, and +, cycle picnum + if (keystatus[KEYSC_DASH] || keystatus[KEYSC_EQUAL] || (bstatus&(16|32) && (bstatus&1) && !(bstatus&2))) { - j = i = (keystatus[KEYSC_EQUAL] || (bstatus&16))?1:-1; - switch (searchstat) + if (ASSERT_AIMING) { - case SEARCH_WALL: - while (!tilesizx[wall[searchwall].picnum]||!tilesizy[wall[searchwall].picnum]||j) + j = i = (keystatus[KEYSC_EQUAL] || (bstatus&16)) ? 1 : -1; + + while (!tilesizx[AIMED_SELOVR_PICNUM] || !tilesizy[AIMED_SELOVR_PICNUM] || j) { - if (wall[searchwall].picnum+i >= MAXTILES) wall[searchwall].picnum = 0; - else if (wall[searchwall].picnum+i < 0) wall[searchwall].picnum = MAXTILES-1; - else wall[searchwall].picnum += i; + AIMED_SELOVR_PICNUM += i; + AIMED_SELOVR_PICNUM &= (MAXTILES-1); j = 0; } - break; - case SEARCH_CEILING: - while (!tilesizx[sector[searchsector].ceilingpicnum]||!tilesizy[sector[searchsector].ceilingpicnum]||j) - { - if (sector[searchsector].ceilingpicnum+i >= MAXTILES) sector[searchsector].ceilingpicnum = 0; - else if (sector[searchsector].ceilingpicnum+i < 0) sector[searchsector].ceilingpicnum = MAXTILES-1; - else sector[searchsector].ceilingpicnum += i; - j = 0; - } - break; - case SEARCH_FLOOR: - while (!tilesizx[sector[searchsector].floorpicnum]||!tilesizy[sector[searchsector].floorpicnum]||j) - { - if (sector[searchsector].floorpicnum+i >= MAXTILES) sector[searchsector].floorpicnum = 0; - else if (sector[searchsector].floorpicnum+i < 0) sector[searchsector].floorpicnum = MAXTILES-1; - else sector[searchsector].floorpicnum += i; - j = 0; - } - break; - case SEARCH_SPRITE: - while (!tilesizx[sprite[searchwall].picnum]||!tilesizy[sprite[searchwall].picnum]||j) - { - if (sprite[searchwall].picnum+i >= MAXTILES) sprite[searchwall].picnum = 0; - else if (sprite[searchwall].picnum+i < 0) sprite[searchwall].picnum = MAXTILES-1; - else sprite[searchwall].picnum += i; - j = 0; - } - break; - case SEARCH_MASKWALL: - while (!tilesizx[wall[searchwall].overpicnum]||!tilesizy[wall[searchwall].overpicnum]||j) - { - if (wall[searchwall].overpicnum+i >= MAXTILES) wall[searchwall].overpicnum = 0; - else if (wall[searchwall].overpicnum+i < 0) wall[searchwall].overpicnum = MAXTILES-1; - else wall[searchwall].overpicnum += i; - j = 0; - } - break; + + asksave = 1; } - asksave = 1; keystatus[KEYSC_DASH] = keystatus[KEYSC_EQUAL] = 0; mouseb &= ~(16|32); } - if (keystatus[KEYSC_E]) // E (expand) + if (PRESSED_KEYSC(E)) // E (expand) { - if (searchstat == SEARCH_CEILING) + if (AIMING_AT_CEILING_OR_FLOOR) { - sector[searchsector].ceilingstat ^= 8; - Bsprintf(getmessage,"Sector %d ceiling texture expansion bit %s",searchsector,sector[searchsector].ceilingstat&8?"ON":"OFF"); - message(getmessage); + AIMED_CEILINGFLOOR(stat) ^= 8; + message("Sector %d %s texture expansion bit %s", searchsector, typestr[searchstat], ONOFF(sector[searchsector].ceilingstat&8)); asksave = 1; } - if (searchstat == SEARCH_FLOOR) - { - sector[searchsector].floorstat ^= 8; - Bsprintf(getmessage,"Sector %d floor texture expansion bit %s",searchsector,sector[searchsector].floorstat&8?"ON":"OFF"); - message(getmessage); - asksave = 1; - } - keystatus[KEYSC_E] = 0; } - if (keystatus[KEYSC_R]) // R (relative alignment, rotation) + + if (PRESSED_KEYSC(R)) // R (relative alignment, rotation) { if (keystatus[KEYSC_QUOTE]) // FRAMERATE TOGGLE { framerateon = !framerateon; - if (framerateon) message("Show framerate ON"); - else message("Show framerate OFF"); + message("Show framerate %s", ONOFF(framerateon)); } else { - if (searchstat == SEARCH_CEILING) + if (AIMING_AT_CEILING_OR_FLOOR) { - sector[searchsector].ceilingstat ^= 64; - Bsprintf(getmessage,"Sector %d ceiling texture relativity bit %s",searchsector,sector[searchsector].ceilingstat&64?"ON":"OFF"); - message(getmessage); + AIMED_CEILINGFLOOR(stat) ^= 64; + message("Sector %d %s texture relativity bit %s", searchsector, typestr[searchstat], ONOFF(AIMED_CEILINGFLOOR(stat)&64)); asksave = 1; } - if (searchstat == SEARCH_FLOOR) - { - sector[searchsector].floorstat ^= 64; - Bsprintf(getmessage,"Sector %d floor texture relativity bit %s",searchsector,sector[searchsector].floorstat&64?"ON":"OFF"); //PK (was ceiling in string) - message(getmessage); - asksave = 1; - } - if (searchstat == SEARCH_SPRITE) + else if (AIMING_AT_SPRITE) { + static const char *aligntype[4] = { "view", "wall", "floor", "???" }; + i = sprite[searchwall].cstat; if ((i&48) < 32) i += 16; - else i &= ~48; sprite[searchwall].cstat = i; - if (sprite[searchwall].cstat&16) - Bsprintf(getmessage,"Sprite %d now wall aligned",searchwall); - else if (sprite[searchwall].cstat&32) - Bsprintf(getmessage,"Sprite %d now floor aligned",searchwall); - else - Bsprintf(getmessage,"Sprite %d now view aligned",searchwall); - message(getmessage); + message("Sprite %d now %s aligned", searchwall, aligntype[(i&48)/16]); asksave = 1; } } - keystatus[KEYSC_R] = 0; } - if (keystatus[KEYSC_F]) //F (Flip) + + if (PRESSED_KEYSC(F)) //F (Flip) { - keystatus[KEYSC_F] = 0; if (eitherALT) //ALT-F (relative alignmment flip) { - if (searchstat != SEARCH_SPRITE) + if (!AIMING_AT_SPRITE && ASSERT_AIMING) { - setfirstwall(searchsector,searchwall); - Bsprintf(getmessage,"Sector %d first wall",searchsector); - message(getmessage); + setfirstwall(searchsector, searchwall); + message("Sector %d first wall", searchsector); asksave = 1; } } else { - if ((searchstat == SEARCH_WALL) || (searchstat == SEARCH_MASKWALL)) + if (AIMING_AT_WALL_OR_MASK) { + static const int32_t next[4] = { 1, 3, 0, 2 }; // 0->1->3->2->0 + i = wall[searchbottomwall].cstat; i = ((i>>3)&1)+((i>>7)&2); //3-x,8-y - switch (i) - { - case 0: - i = 1; - break; - case 1: - i = 3; - break; - case 2: - i = 0; - break; - case 3: - i = 2; - break; - } - Bsprintf(getmessage,"Wall %d flip %d",searchwall,i); - message(getmessage); + + i = next[i]; + message("Wall %d flip %d",searchwall,i); + i = ((i&1)<<3)+((i&2)<<7); wall[searchbottomwall].cstat &= ~0x0108; wall[searchbottomwall].cstat |= i; asksave = 1; } - if (searchstat == SEARCH_CEILING) //8-way ceiling flipping (bits 2,4,5) + else if (AIMING_AT_CEILING_OR_FLOOR) //8-way ceiling/floor flipping (bits 2,4,5) { - i = sector[searchsector].ceilingstat; + static const int32_t next[8] = { 6, 7, 4, 5, 0, 1, 3, 2 }; // 0->6->3->5->1->7->2->4->0 + int16_t *stat = AIMING_AT_CEILING ? §or[searchsector].ceilingstat : §or[searchsector].floorstat; + + i = *stat; i = (i&0x4)+((i>>4)&3); - switch (i) - { - case 0: - i = 6; - break; - case 6: - i = 3; - break; - case 3: - i = 5; - break; - case 5: - i = 1; - break; - case 1: - i = 7; - break; - case 7: - i = 2; - break; - case 2: - i = 4; - break; - case 4: - i = 0; - break; - } - Bsprintf(getmessage,"Sector %d flip %d",searchsector,i); - message(getmessage); + i = next[i]; + message("Sector %d flip %d", searchsector, i); i = (i&0x4)+((i&3)<<4); - sector[searchsector].ceilingstat &= ~0x34; - sector[searchsector].ceilingstat |= i; + *stat &= ~0x34; + *stat |= i; asksave = 1; } - if (searchstat == 2) //8-way floor flipping (bits 2,4,5) - { - i = sector[searchsector].floorstat; - i = (i&0x4)+((i>>4)&3); - switch (i) - { - case 0: - i = 6; - break; - case 6: - i = 3; - break; - case 3: - i = 5; - break; - case 5: - i = 1; - break; - case 1: - i = 7; - break; - case 7: - i = 2; - break; - case 2: - i = 4; - break; - case 4: - i = 0; - break; - } - Bsprintf(getmessage,"Sector %d flip %d",searchsector,i); - message(getmessage); - i = (i&0x4)+((i&3)<<4); - sector[searchsector].floorstat &= ~0x34; - sector[searchsector].floorstat |= i; - asksave = 1; - } - if (searchstat == SEARCH_SPRITE) + else if (AIMING_AT_SPRITE) { i = sprite[searchwall].cstat; if (((i&48) == 32) && ((i&64) == 0)) { sprite[searchwall].cstat &= ~0xc; sprite[searchwall].cstat |= ((i&4)^4); - Bsprintf(getmessage,"Sprite %d flip bit %s",searchwall,sprite[searchwall].cstat&4?"ON":"OFF"); - message(getmessage); + message("Sprite %d flip bit %s",searchwall, ONOFF(sprite[searchwall].cstat&4)); } else { + int32_t next[4] = { 1, 3, 0, 2 }; // 0->1->3->2->0 i = ((i>>2)&3); - switch (i) - { - case 0: - i = 1; - break; - case 1: - i = 3; - break; - case 2: - i = 0; - break; - case 3: - i = 2; - break; - } - Bsprintf(getmessage,"Sprite %d flip %d",searchwall,i); - message(getmessage); - i <<= 2; + + i = next[i]; + message("Sprite %d flip %d",searchwall,i); + sprite[searchwall].cstat &= ~0xc; - sprite[searchwall].cstat |= i; + sprite[searchwall].cstat |= (i<<2); } asksave = 1; } } } + if (keystatus[KEYSC_HOME]) updownunits = 256; else if (keystatus[KEYSC_END]) updownunits = 512; else updownunits = 1024; + mouseaction=0; if (eitherALT && (bstatus&1)) { @@ -5422,11 +4786,15 @@ static void Keys3d(void) } } + tsign = 0; - if (keystatus[KEYSC_PGUP] || (mouseaction && mousey<0) || ((bstatus&2) && (bstatus&16) && !(bstatus&1))) // PK: PGUP, rmb only & mwheel - tsign = -1; - if (keystatus[KEYSC_PGDN] || (mouseaction && mousey>0) || ((bstatus&2) && (bstatus&32) && !(bstatus&1))) // PK: PGDN, rmb only & mwheel - tsign = 1; + if (ASSERT_AIMING) + { + // PK: PGUP/PGDN, rmb only & mwheel + tsign -= (PRESSED_KEYSC(PGUP) || (mouseaction && mousey<0) || ((bstatus&18)==18 && !(bstatus&1))); + tsign += (PRESSED_KEYSC(PGDN) || (mouseaction && mousey>0) || ((bstatus&34)==34 && !(bstatus&1))); + } + if (tsign) { k = 0; @@ -5440,29 +4808,34 @@ static void Keys3d(void) } } - if ((searchstat == SEARCH_WALL) || (searchstat == SEARCH_CEILING)) + if (AIMING_AT_WALL || AIMING_AT_CEILING) { int16_t sect = k ? highlightsector[0] : - ((searchstat==SEARCH_WALL && eitherSHIFT && wall[searchwall].nextsector>=0) ? wall[searchwall].nextsector : searchsector); + ((AIMING_AT_WALL && eitherSHIFT && wall[searchwall].nextsector>=0) ? + wall[searchwall].nextsector : searchsector); for (j=0; j<(k?k:1); j++, sect=highlightsector[j]) { i = headspritesect[sect]; while (i != -1) { - tempint = getceilzofslope(sect,sprite[i].x,sprite[i].y); - tempint += ((tilesizy[sprite[i].picnum]*sprite[i].yrepeat)<<2); - if (sprite[i].cstat&128) tempint += ((tilesizy[sprite[i].picnum]*sprite[i].yrepeat)<<1); + tempint = getceilzofslope(sect, sprite[i].x, sprite[i].y); + tempint += (tilesizy[sprite[i].picnum]*sprite[i].yrepeat)<<2; + + if (sprite[i].cstat&128) + tempint += (tilesizy[sprite[i].picnum]*sprite[i].yrepeat)<<1; + if (sprite[i].z == tempint) sprite[i].z += tsign * (updownunits << (eitherCTRL<<1)); // JBF 20031128 + i = nextspritesect[i]; } + sector[sect].ceilingz += tsign * (updownunits << (eitherCTRL<<1)); // JBF 20031128 - Bsprintf(getmessage,"Sector %d ceilingz = %d",sect,sector[sect].ceilingz); - message(getmessage); + message("Sector %d ceilingz = %d", sect, sector[sect].ceilingz); } } - else if (searchstat == SEARCH_FLOOR) + else if (AIMING_AT_FLOOR) { int16_t sect = k ? highlightsector[0] : searchsector; @@ -5472,14 +4845,18 @@ static void Keys3d(void) while (i != -1) { tempint = getflorzofslope(sect,sprite[i].x,sprite[i].y); - if (sprite[i].cstat&128) tempint += ((tilesizy[sprite[i].picnum]*sprite[i].yrepeat)<<1); + + if (sprite[i].cstat&128) + tempint += ((tilesizy[sprite[i].picnum]*sprite[i].yrepeat)<<1); + if (sprite[i].z == tempint) sprite[i].z += tsign * (updownunits << (eitherCTRL<<1)); // JBF 20031128 + i = nextspritesect[i]; } + sector[sect].floorz += tsign * (updownunits << (eitherCTRL<<1)); // JBF 20031128 - Bsprintf(getmessage,"Sector %d floorz = %d",sect,sector[sect].floorz); - message(getmessage); + message("Sector %d floorz = %d",sect,sector[sect].floorz); } } @@ -5491,7 +4868,7 @@ static void Keys3d(void) sector[searchsector].ceilingz = sector[searchsector].floorz; } - if (searchstat == SEARCH_SPRITE) + if (AIMING_AT_SPRITE) { if (eitherCTRL && !eitherALT) //CTRL - put sprite on ceiling/floor { @@ -5514,9 +4891,10 @@ static void Keys3d(void) if (k == 0) { sprite[searchwall].z += tsign * (updownunits << ((eitherCTRL && mouseaction)*3)); - if (!spnoclip)sprite[searchwall].z = max(sprite[searchwall].z,spriteonceilingz(searchwall)); - Bsprintf(getmessage,"Sprite %d z = %d",searchwall,sprite[searchwall].z); - message(getmessage); + if (!spnoclip) + sprite[searchwall].z = max(sprite[searchwall].z, spriteonceilingz(searchwall)); + + message("Sprite %d z = %d", searchwall, sprite[searchwall].z); } else @@ -5524,22 +4902,26 @@ static void Keys3d(void) for (i=0; i= 0) { int32_t thisSec = ms/1000; @@ -5584,11 +4968,9 @@ static void Keys3d(void) } tempbuf[0] = 0; + if (bstatus&4 && !(bstatus&(1|2)) && !unrealedlook) //PK - { Bsprintf(tempbuf,"VIEW"); - // else Bsprintf(tempbuf,"SHADE"); - } else if (bstatus&2 && !(bstatus&1)) Bsprintf(tempbuf,"Z"); else if (bstatus&1 && !(bstatus&2)) @@ -5611,7 +4993,7 @@ static void Keys3d(void) case SEARCH_CEILING: case SEARCH_FLOOR: if (eitherALT) - Bsprintf(tempbuf,"%s Z %s", searchstat==SEARCH_CEILING?"CEILING":"FLOOR", eitherCTRL?"512":""); + Bsprintf(tempbuf,"%s Z %s", AIMING_AT_CEILING?"CEILING":"FLOOR", eitherCTRL?"512":""); else if (eitherSHIFT) Bsprintf(tempbuf,"PAN"); else if (eitherCTRL) @@ -5631,27 +5013,27 @@ static void Keys3d(void) if (tempbuf[0] != 0) { i = (Bstrlen(tempbuf)<<3)+6; - if ((searchx+i) < (xdim-1)) - i = 0; - else i = (searchx+i)-(xdim-1); - if ((searchy+16) < (ydim-1)) - j = 0; - else j = (searchy+16)-(ydim-1); + i = max((searchx+i)-(xdim-1), 0); + + j = max((searchy+16)-(ydim-1), 0); + // printext16(searchx+6-i,searchy+6-j,11,-1,tempbuf,0); - printext256(searchx+4+2-i,searchy+4+2-j,0,-1,tempbuf,!(xdimgame > 640)); - printext256(searchx+4-i,searchy+4-j,whitecol,-1,tempbuf,!(xdimgame > 640)); + printext256(searchx+4+2-i, searchy+4+2-j, 0,-1,tempbuf,!(xdimgame > 640)); + printext256(searchx+4-i, searchy+4-j, whitecol,-1,tempbuf,!(xdimgame > 640)); // printext256(searchx+4+2,searchy+4+2,0,-1,tempbuf,!(xdimgame > 640)); // printext256(searchx+4,searchy+4,whitecol,-1,tempbuf,!(xdimgame > 640)); } if (helpon==1) { + int32_t small = !(xdimgame > 640); for (i=0; i 640)))+2,0,-1,Help3d[i],!(xdimgame > 640)); - printext256(0*8,8+(i*(8+(xdimgame > 640))),whitecol,-1,Help3d[i],!(xdimgame > 640)); + printext256(2, 8+(i*(8+!small))+2, 0, -1, Help3d[i], small); + printext256(0, 8+(i*(8+!small)), whitecol, -1, Help3d[i], small); enddrawing(); + switch (i) { case 8: @@ -5676,16 +5058,17 @@ static void Keys3d(void) Bsprintf(tempbuf," "); break; } + begindrawing(); - if (!strcmp(tempbuf,"0")) + if (!Bstrcmp(tempbuf,"0")) Bsprintf(tempbuf,"OFF"); - else if (!strcmp(tempbuf,"1")) + else if (!Bstrcmp(tempbuf,"1")) Bsprintf(tempbuf,"ON"); - else if (!strcmp(tempbuf,"2")) + else if (!Bstrcmp(tempbuf,"2")) Bsprintf(tempbuf,"ON (2)"); - printext256((20+((xdimgame > 640) * 20))*8+2,8+(i*(8+(xdimgame > 640)))+2,0,-1,tempbuf,!(xdimgame > 640)); - printext256((20+((xdimgame > 640) * 20))*8,8+(i*(8+(xdimgame > 640))),whitecol,-1,tempbuf,!(xdimgame > 640)); + printext256((20+(!small * 20))*8+2, 8+(i*(8+!small))+2, 0, -1, tempbuf, small); + printext256((20+(!small * 20))*8, 8+(i*(8+!small)), whitecol, -1, tempbuf, small); enddrawing(); } } @@ -5693,15 +5076,17 @@ static void Keys3d(void) /* if(purpleon) { begindrawing(); // printext256(1*4,1*8,whitecol,-1,"Purple ON",0); - sprintf(getmessage,"Purple ON"); - message(getmessage); + message("Purple ON"); enddrawing(); } */ + if (sector[cursectnum].lotag==2) { - if (sector[cursectnum].ceilingpicnum==FLOORSLIME) SetSLIMEPalette(); - else SetWATERPalette(); + if (sector[cursectnum].ceilingpicnum==FLOORSLIME) + SetSLIMEPalette(); + else + SetWATERPalette(); } else SetGAMEPalette(); @@ -5710,6 +5095,7 @@ static void Keys3d(void) SetGAMEPalette(); FX_StopAllSounds(); S_ClearSoundLocks(); + #ifdef POLYMER for (i=0; iMAXSKILL-1) skill=0; - message("%s",SKILLMODE[skill]); + skill = (skill+1)%MAXSKILL; + message("%s", SKILLMODE[skill]); // printext256(1*4,1*8,11,-1,tempbuf,0); } - /* if (keystatus[KEYSC_QUOTE] && keystatus[KEYSC_G]) // ' g + if (keystatus[KEYSC_QUOTE] && PRESSED_KEYSC(X)) // ' x { - keystatus[KEYSC_G] = 0; - tabgraphic++; - if (tabgraphic > 2) tabgraphic = 0; - if (tabgraphic) message("Graphics ON"); - else message("Graphics OFF"); - }*/ + shadepreview = !shadepreview; + message("Map shade preview %s", shadepreview?"enabled":"disabled"); - if (keystatus[KEYSC_QUOTE] && keystatus[KEYSC_X]) // ' x - { - keystatus[KEYSC_X] = 0; - shadepreview=!shadepreview; - message("Map shade preview %s",shadepreview?"enabled":"disabled"); #ifdef POLYMER for (i=0; i + { + keystatus[KEYSC_G] = 0; + tabgraphic++; + if (tabgraphic > 2) tabgraphic = 0; + if (tabgraphic) message("Graphics ON"); + else message("Graphics OFF"); + }*/ + /* if (keystatus[KEYSC_QUOTE] && keystatus[KEYSC_R]) // ' r { keystatus[KEYSC_R] = 0; @@ -5772,95 +5150,72 @@ static void Keys3d(void) else message("Framerate OFF"); }*/ - if (keystatus[KEYSC_QUOTE] && keystatus[KEYSC_W]) // ' w + if (keystatus[KEYSC_QUOTE] && PRESSED_KEYSC(W)) // ' w { - keystatus[KEYSC_W] = 0; - nosprites++; - if (nosprites>3) nosprites=0; - message("%s",SPRDSPMODE[nosprites]); - // printext256(1*4,1*8,whitecol,-1,tempbuf,0); + nosprites = (nosprites+1)%MAXNOSPRITES; + message("%s", SPRDSPMODE[nosprites]); } - if (keystatus[KEYSC_QUOTE] && keystatus[KEYSC_Y]) // ' y + if (keystatus[KEYSC_QUOTE] && PRESSED_KEYSC(Y)) // ' y { - keystatus[KEYSC_Y] = 0; - purpleon=!purpleon; + purpleon = !purpleon; if (nosprites>3) nosprites=0; - if (purpleon) message("Purple ON"); - else message("Purple OFF"); + message("Purple %s", ONOFF(purpleon)); } - if (keystatus[KEYSC_QUOTE] && keystatus[KEYSC_C]) // ' C + if (keystatus[KEYSC_QUOTE] && PRESSED_KEYSC(C)) // ' C { - keystatus[KEYSC_C] = 0; - switch (searchstat) + if (AIMING_AT_WALL_OR_MASK) { - case SEARCH_WALL: - case SEARCH_MASKWALL: for (i=0; i= 0) && (eitherSHIFT == 0)) + if ((wall[searchwall].nextwall >= 0) && !eitherSHIFT) { - wall[wall[searchwall].nextwall].cstat &= ~(1+64); - wall[wall[searchwall].nextwall].cstat |= (wall[searchwall].cstat&1); + NEXTWALL(searchwall).cstat &= ~(1+64); + NEXTWALL(searchwall).cstat |= (wall[searchwall].cstat&1); } - Bsprintf(getmessage,"Wall %d blocking bit %s",searchwall,wall[searchwall].cstat&1?"ON":"OFF"); - message(getmessage); + + message("Wall %d blocking bit %s", searchwall, ONOFF(wall[searchwall].cstat&1)); asksave = 1; } - keystatus[KEYSC_B] = 0; } - if (keystatus[KEYSC_T]) // T (transluscence for sprites/masked walls) + if (PRESSED_KEYSC(T)) // T (transluscence for sprites/masked walls) { - if (searchstat == SEARCH_CEILING) //Set masked/transluscent ceilings/floors + if (AIMING_AT_CEILING_OR_FLOOR) //Set masked/transluscent ceilings/floors { - i = (sector[searchsector].ceilingstat&(128+256)); - sector[searchsector].ceilingstat &= ~(128+256); - switch (i) - { - case 0: - sector[searchsector].ceilingstat |= 128; - break; - case 128: - sector[searchsector].ceilingstat |= 256; - break; - case 256: - sector[searchsector].ceilingstat |= 384; - break; - case 384: - sector[searchsector].ceilingstat |= 0; - break; - } - asksave = 1; - } - if (searchstat == SEARCH_FLOOR) - { - i = (sector[searchsector].floorstat&(128+256)); - sector[searchsector].floorstat &= ~(128+256); - switch (i) - { - case 0: - sector[searchsector].floorstat |= 128; - break; - case 128: - sector[searchsector].floorstat |= 256; - break; - case 256: - sector[searchsector].floorstat |= 384; - break; - case 384: - sector[searchsector].floorstat |= 0; - break; - } + int32_t nexti[4] = { 128, 256, 384, 0 }; + int16_t *stat = &AIMED_CEILINGFLOOR(stat); + i = (*stat&(128+256))>>7; + i = nexti[i]; + *stat &= ~(128+256); + *stat |= i; asksave = 1; } if (keystatus[KEYSC_QUOTE]) { - switch (searchstat) + if (ASSERT_AIMING) { - case SEARCH_WALL: - case SEARCH_MASKWALL: - strcpy(buffer,"Wall lotag: "); - wall[searchwall].lotag = getnumber256(buffer,(int32_t)wall[searchwall].lotag,65536L,0); - break; - case SEARCH_CEILING: - case SEARCH_FLOOR: - strcpy(buffer,"Sector lotag: "); - sector[searchsector].lotag = getnumber256(buffer,(int32_t)sector[searchsector].lotag,65536L,0); - break; - case SEARCH_SPRITE: - strcpy(buffer,"Sprite lotag: "); - sprite[searchwall].lotag = getnumber256(buffer,(int32_t)sprite[searchwall].lotag,65536L,0); - break; + Bsprintf(tempbuf, "%s lotag: ", Typestr_wss[searchstat]); + AIMED(lotag) = getnumber256(tempbuf, AIMED(lotag), BTAG_MAX, 0); } } else if (eitherCTRL) { - if (searchstat == SEARCH_SPRITE) + if (AIMING_AT_SPRITE) TextEntryMode(searchwall); } else { - if (searchstat == SEARCH_SPRITE) + if (AIMING_AT_SPRITE) { if ((sprite[searchwall].cstat&2) == 0) sprite[searchwall].cstat |= 2; @@ -6097,7 +5370,7 @@ static void Keys3d(void) sprite[searchwall].cstat &= ~(2+512); asksave = 1; } - if (searchstat == SEARCH_MASKWALL) + else if (AIMING_AT_MASKWALL) { if ((wall[searchwall].cstat&128) == 0) wall[searchwall].cstat |= 128; @@ -6108,44 +5381,26 @@ static void Keys3d(void) if (wall[searchwall].nextwall >= 0) { - wall[wall[searchwall].nextwall].cstat &= ~(128+512); - wall[wall[searchwall].nextwall].cstat |= (wall[searchwall].cstat&(128+512)); + NEXTWALL(searchwall).cstat &= ~(128+512); + NEXTWALL(searchwall).cstat |= (wall[searchwall].cstat&(128+512)); } asksave = 1; } } - keystatus[KEYSC_T] = 0; } - if (keystatus[KEYSC_QUOTE] && keystatus[KEYSC_ENTER]) // ' ENTER + if (keystatus[KEYSC_QUOTE] && PRESSED_KEYSC(ENTER)) // ' ENTER { + AIMED_SELOVR_PICNUM = temppicnum; message("Pasted picnum only"); - switch (searchstat) - { - case SEARCH_WALL: - wall[searchbottomwall].picnum = temppicnum; - break; - case SEARCH_CEILING: - sector[searchsector].ceilingpicnum = temppicnum; - break; - case SEARCH_FLOOR: - sector[searchsector].floorpicnum = temppicnum; - break; - case SEARCH_SPRITE: - sprite[searchwall].picnum = temppicnum; - break; - case SEARCH_MASKWALL: - wall[searchwall].overpicnum = temppicnum; - break; - } - keystatus[KEYSC_ENTER]=0; } i = 512; if (keystatus[KEYSC_RSHIFT]) i = 8; if (keystatus[KEYSC_LSHIFT]) i = 1; mouseaction=0; - if (eitherCTRL && !eitherSHIFT && (bstatus&1) && (searchstat == SEARCH_CEILING || searchstat == SEARCH_FLOOR)) + + if (eitherCTRL && !eitherSHIFT && (bstatus&1) && AIMING_AT_CEILING_OR_FLOOR) { mousex=0; mskip=1; if (mousey) @@ -6156,46 +5411,42 @@ static void Keys3d(void) } tsign = 0; - if (keystatus[KEYSC_LBRACK] || (mouseaction && mousey<0)) // [ - tsign = -1; - if (keystatus[KEYSC_RBRACK] || (mouseaction && mousey>0)) // ] - tsign = 1; + if (ASSERT_AIMING) + { + tsign -= (PRESSED_KEYSC(LBRACK) || (mouseaction && mousey<0)); // [ + tsign += (PRESSED_KEYSC(RBRACK) || (mouseaction && mousey>0)); // ] + } if (tsign) { - keystatus[KEYSC_LBRACK] = keystatus[KEYSC_RBRACK] = 0; if (eitherALT) { - i = wall[searchwall].nextsector; - if (i >= 0 && !mouseaction) + int32_t ns=wall[searchwall].nextsector, sx=wall[searchwall].x, sy=wall[searchwall].y; + + if (ns >= 0 && !mouseaction) { - if (searchstat==SEARCH_CEILING || (tsign < 0 && (searchstat==SEARCH_WALL || searchstat==SEARCH_MASKWALL))) + if (AIMING_AT_CEILING || (tsign < 0 && AIMING_AT_WALL_OR_MASK)) { - alignceilslope(searchsector,wall[searchwall].x,wall[searchwall].y,getceilzofslope(i,wall[searchwall].x,wall[searchwall].y)); - message("Sector %d align ceiling to wall %d",searchsector,searchwall); + alignceilslope(searchsector, sx, sy, getceilzofslope(ns, sx, sy)); + message("Sector %d align ceiling to wall %d", searchsector, searchwall); } - if (searchstat==SEARCH_FLOOR || (tsign > 0 && (searchstat==SEARCH_WALL || searchstat==SEARCH_MASKWALL))) + if (AIMING_AT_FLOOR || (tsign > 0 && AIMING_AT_WALL_OR_MASK)) { - alignflorslope(searchsector,wall[searchwall].x,wall[searchwall].y,getflorzofslope(i,wall[searchwall].x,wall[searchwall].y)); - message("Sector %d align floor to wall %d",searchsector,searchwall); + alignflorslope(searchsector, sx, sy, getflorzofslope(ns, sx, sy)); + message("Sector %d align floor to wall %d", searchsector, searchwall); } - } + } } else { - if (searchstat == SEARCH_CEILING) + if (AIMING_AT_CEILING_OR_FLOOR) { - if (!(sector[searchsector].ceilingstat&2)) - sector[searchsector].ceilingheinum = 0; - sector[searchsector].ceilingheinum = min(max(-32768, sector[searchsector].ceilingheinum + tsign*i), 32767); - message("Sector %d ceiling slope = %d",searchsector,sector[searchsector].ceilingheinum); - } - if (searchstat == SEARCH_FLOOR) - { - if (!(sector[searchsector].floorstat&2)) - sector[searchsector].floorheinum = 0; - sector[searchsector].floorheinum = min(max(-32768, sector[searchsector].floorheinum + tsign*i), 32767); - message("Sector %d floor slope = %d",searchsector,sector[searchsector].floorheinum); + if (!(AIMED_CEILINGFLOOR(stat)&2)) + AIMED_CEILINGFLOOR(heinum) = 0; + + AIMED_CEILINGFLOOR(heinum) = clamp(AIMED_CEILINGFLOOR(heinum) + tsign*i, -32768, 32767); + + message("Sector %d ceiling slope = %d",searchsector,AIMED_CEILINGFLOOR(heinum)); } } @@ -6212,17 +5463,19 @@ static void Keys3d(void) } - if (bstatus&1 && eitherSHIFT) mskip=1; - if (bstatus&1 && eitherSHIFT && (searchstat == SEARCH_CEILING || searchstat == SEARCH_FLOOR) && (mousex|mousey)) + if ((bstatus&1) && eitherSHIFT) + mskip=1; + + if ((bstatus&1) && eitherSHIFT && AIMING_AT_CEILING_OR_FLOOR && (mousex|mousey)) { int32_t fw,x1,y1,x2,y2,stat,ma,a=0; - stat=(searchstat==SEARCH_FLOOR)?sector[searchsector].floorstat:sector[searchsector].ceilingstat; + stat = AIMING_AT_FLOOR ? sector[searchsector].floorstat : sector[searchsector].ceilingstat; if (stat&64) // align to first wall { fw=sector[searchsector].wallptr; x1=wall[fw].x,y1=wall[fw].y; - x2=wall[wall[fw].point2].x,y2=wall[wall[fw].point2].y; + x2=POINT2(fw).x,y2=POINT2(fw).y; a=getangle(x1-x2,y1-y2); } mouseax+=mousex; mouseay+=mousey; @@ -6256,121 +5509,133 @@ static void Keys3d(void) case 7:ma+=512; break; } - a=ksqrt(mouseax*mouseax+mouseay*mouseay); + a = ksqrt(mouseax*mouseax + mouseay*mouseay); if (a) { - int32_t mult=(stat&8)?8192:8192*2; - x1=-a*sintable[(ma+2048)&2047]/mult; - y1=-a*sintable[(ma+1536)&2047]/mult; + int32_t mult = (stat&8) ? 8192 : 8192*2; + x1 = -a*sintable[(ma+2048)&2047]/mult; + y1 = -a*sintable[(ma+1536)&2047]/mult; + if (x1||y1) { - mouseax=0; mouseay=0; - if (searchstat==SEARCH_CEILING) + mouseax=0; + mouseay=0; + + if (AIMING_AT_CEILING_OR_FLOOR) { - changedir=1; if (x1<0) {changedir=-1; x1*=-1;} - while (x1--)sector[searchsector].ceilingxpanning = changechar(sector[searchsector].ceilingxpanning,changedir,0,0); - changedir=1; if (y1<0) {changedir=-1; y1*=-1;} - while (y1--)sector[searchsector].ceilingypanning = changechar(sector[searchsector].ceilingypanning,changedir,0,0); - message("Sector %d ceiling panning: %d, %d",searchsector,sector[searchsector].ceilingxpanning,sector[searchsector].ceilingypanning); - } - else - { - changedir=1; if (x1<0) {changedir=-1; x1*=-1;} - while (x1--)sector[searchsector].floorxpanning = changechar(sector[searchsector].floorxpanning,changedir,0,0); - changedir=1; if (y1<0) {changedir=-1; y1*=-1;} - while (y1--)sector[searchsector].floorypanning = changechar(sector[searchsector].floorypanning,changedir,0,0); - message("Sector %d floor panning: %d, %d",searchsector,sector[searchsector].floorxpanning,sector[searchsector].floorypanning); + changedir = 1-2*(x1<0); + x1 = klabs(x1); + + while (x1--) + AIMED_CEILINGFLOOR(xpanning) = changechar(AIMED_CEILINGFLOOR(xpanning),changedir,0,0); + + changedir = 1-2*(y1<0); + y1 = klabs(y1); + + while (y1--) + AIMED_CEILINGFLOOR(ypanning) = changechar(AIMED_CEILINGFLOOR(ypanning),changedir,0,0); + + message("Sector %d %s panning: %d, %d", searchsector, typestr[searchstat], + AIMED_CEILINGFLOOR(xpanning), AIMED_CEILINGFLOOR(ypanning)); } asksave=1; } } - mousex=0; mousey=0; + mousex=0; + mousey=0; } - if (!mouseb) {mouseax=0; mouseay=0;} + smooshyalign = keystatus[KEYSC_gKP5]; repeatpanalign = eitherSHIFT; + //////////////////// updownunits=1; mouseaction=0; - if (bstatus&1 && searchstat != SEARCH_CEILING && searchstat != SEARCH_FLOOR) + if (!mouseb) + { + mouseax=0; + mouseay=0; + } + + if ((bstatus&1) && searchstat != SEARCH_CEILING && searchstat != SEARCH_FLOOR) { if (eitherSHIFT) { mskip=1; - if (mousex!=0) + if (mousex) { - mouseaction=1; - mouseax+=mousex; - updownunits=klabs((int32_t)(mouseax/2.)); - if (updownunits) {mouseax=0;} + mouseaction = 1; + mouseax += mousex; + updownunits = klabs((int32_t)(mouseax/2.)); + if (updownunits) + mouseax=0; } } else if (eitherCTRL && !eitherALT) { mskip=1; - if (mousex!=0) + if (mousex) { - mouseaction=2; - repeatpanalign=0; - if (searchstat==SEARCH_SPRITE) - { - updownunits=klabs(mouseax+=mousex)/4; - if (updownunits)mouseax=0; - } - else - { - updownunits=klabs(mouseax+=mousex)/16; - if (updownunits)mouseax=0; - } + mouseaction = 2; + repeatpanalign = 0; + updownunits = klabs(mouseax+=mousex)/(16 - 12*AIMING_AT_SPRITE); + if (updownunits) + mouseax=0; } } } if (keystatus[KEYSC_gLEFT] || keystatus[KEYSC_gRIGHT] || mouseaction) // 4 & 6 (keypad) { - if ((repeatcountx == 0) || (repeatcountx > 32) || mouseaction) + if (repeatcountx == 0 || repeatcountx > 32 || mouseaction) { changedir = 0; - if (keystatus[KEYSC_gLEFT] || mousex>0) changedir = -1; - if (keystatus[KEYSC_gRIGHT] || mousex<0) changedir = 1; + if (keystatus[KEYSC_gLEFT] || mousex>0) + changedir = -1; + if (keystatus[KEYSC_gRIGHT] || mousex<0) + changedir = 1; - if ((searchstat == SEARCH_WALL) || (searchstat == SEARCH_MASKWALL)) + if (AIMING_AT_WALL_OR_MASK) { if (repeatpanalign == 0) { - while (updownunits--)wall[searchwall].xrepeat = changechar(wall[searchwall].xrepeat,changedir,smooshyalign,1); - message("Wall %d repeat: %d, %d",searchwall,wall[searchwall].xrepeat,wall[searchwall].yrepeat); + while (updownunits--) + wall[searchwall].xrepeat = changechar(wall[searchwall].xrepeat, changedir, smooshyalign, 1); + message("Wall %d repeat: %d, %d", searchwall, wall[searchwall].xrepeat, wall[searchwall].yrepeat); } else { - int16_t w = (searchstat==SEARCH_WALL)?searchbottomwall:searchwall; + int16_t w = SELECT_WALL(); + if (mouseaction) { i=wall[w].cstat; i=((i>>3)&1)+((i>>7)&2); - if (i==1||i==3)changedir*=-1; - if (eitherCTRL) updownunits *= 8; + + if (i==1||i==3) + changedir*=-1; + + if (eitherCTRL) + updownunits *= 8; } - while (updownunits--)wall[w].xpanning = changechar(wall[w].xpanning,changedir,smooshyalign,0); - message("Wall %d panning: %d, %d",w,wall[w].xpanning,wall[w].ypanning); + + while (updownunits--) + wall[w].xpanning = changechar(wall[w].xpanning, changedir, smooshyalign, 0); + message("Wall %d panning: %d, %d", w, wall[w].xpanning, wall[w].ypanning); } + asksave = 1; } - if ((searchstat == SEARCH_CEILING) || (searchstat == SEARCH_FLOOR)) + else if (AIMING_AT_CEILING_OR_FLOOR) { - if (searchstat == SEARCH_CEILING) - { - while (updownunits--)sector[searchsector].ceilingxpanning = changechar(sector[searchsector].ceilingxpanning,changedir,smooshyalign,0); - message("Sector %d ceiling panning: %d, %d",searchsector,sector[searchsector].ceilingxpanning,sector[searchsector].ceilingypanning); - } - else - { - while (updownunits--)sector[searchsector].floorxpanning = changechar(sector[searchsector].floorxpanning,changedir,smooshyalign,0); - message("Sector %d floor panning: %d, %d",searchsector,sector[searchsector].floorxpanning,sector[searchsector].floorypanning); - } + while (updownunits--) + AIMED_CEILINGFLOOR(xpanning) = changechar(AIMED_CEILINGFLOOR(xpanning), changedir, smooshyalign, 0); + message("Sector %d %s panning: %d, %d", searchsector, typestr[searchstat], + AIMED_CEILINGFLOOR(xpanning), AIMED_CEILINGFLOOR(ypanning)); + asksave = 1; } - if (searchstat == SEARCH_SPRITE) + else if (AIMING_AT_SPRITE) { static int32_t sumxvect=0, sumyvect=0; @@ -6416,11 +5681,13 @@ static void Keys3d(void) else { sumxvect = sumyvect = 0; - if (mouseaction==2)changedir*=-1; - while (updownunits--)sprite[searchwall].xrepeat = changechar(sprite[searchwall].xrepeat,changedir,smooshyalign,1); + if (mouseaction==2) + changedir *= -1; + while (updownunits--) + sprite[searchwall].xrepeat = changechar(sprite[searchwall].xrepeat, changedir, smooshyalign, 1); if (sprite[searchwall].xrepeat < 4) sprite[searchwall].xrepeat = 4; - message("Sprite %d repeat: %d, %d",searchwall,sprite[searchwall].xrepeat,sprite[searchwall].yrepeat); + message("Sprite %d repeat: %d, %d", searchwall, sprite[searchwall].xrepeat, sprite[searchwall].yrepeat); } } asksave = 1; @@ -6431,86 +5698,83 @@ static void Keys3d(void) else repeatcountx = 0; + + //////////////////// updownunits=1; mouseaction=0; - if (bstatus&1 && searchstat != SEARCH_CEILING && searchstat != SEARCH_FLOOR) + + if ((bstatus&1) && !AIMING_AT_CEILING_OR_FLOOR) { if (eitherSHIFT) { mskip=1; - if (mousey!=0) + if (mousey) { - mouseaction=1; - updownunits=klabs(mousey); - if (searchstat != SEARCH_SPRITE) - { - updownunits=klabs((int32_t)(mousey*128./tilesizy[wall[searchwall].picnum])); - } + mouseaction = 1; + updownunits = klabs(mousey); + + if (!AIMING_AT_SPRITE) + updownunits = klabs((int32_t)(mousey*128./tilesizy[wall[searchwall].picnum])); } } else if (eitherCTRL && !eitherALT) { mskip=1; - if (mousey!=0) + if (mousey) { - mouseaction=2; - repeatpanalign=0; - if (searchstat==SEARCH_SPRITE) - { - updownunits=klabs(mouseay+=mousey)/4; - if (updownunits)mouseay=0; - } - else - { - updownunits=klabs(mouseay+=mousey)/32; - if (updownunits)mouseay=0; - } + mouseaction = 2; + repeatpanalign = 0; + mouseay += mousey; + updownunits = klabs(mouseay)/(32 - 28*AIMING_AT_SPRITE); + if (updownunits) + mouseay=0; } } } - if (!mouseb) {mouseax=0; mouseay=0;} + + if (!mouseb) + { + mouseax=0; + mouseay=0; + } + if (keystatus[KEYSC_gUP] || keystatus[KEYSC_gDOWN] || mouseaction) // 2 & 8 (keypad) { - if ((repeatcounty == 0) || (repeatcounty > 32) || mouseaction) + if (repeatcounty == 0 || repeatcounty > 32 || mouseaction) { changedir = 0; - if (keystatus[KEYSC_gUP] || mousey>0) changedir = -1; - if (keystatus[KEYSC_gDOWN] || mousey<0) changedir = 1; + if (keystatus[KEYSC_gUP] || mousey>0) + changedir = -1; + if (keystatus[KEYSC_gDOWN] || mousey<0) + changedir = 1; - if ((searchstat == SEARCH_WALL) || (searchstat == SEARCH_MASKWALL)) + if (AIMING_AT_WALL_OR_MASK) { if (repeatpanalign == 0) { while (updownunits--) - wall[searchwall].yrepeat = changechar(wall[searchwall].yrepeat,changedir,smooshyalign,1); - message("Wall %d repeat: %d, %d",searchwall,wall[searchwall].xrepeat,wall[searchwall].yrepeat); + wall[searchwall].yrepeat = changechar(wall[searchwall].yrepeat, changedir, smooshyalign, 1); + message("Wall %d repeat: %d, %d", searchwall, wall[searchwall].xrepeat, wall[searchwall].yrepeat); } else { - int16_t w = (searchstat==SEARCH_WALL)?searchbottomwall:searchwall; + int16_t w = AIMING_AT_WALL?searchbottomwall:searchwall; if (mouseaction && eitherCTRL) updownunits *= 8; while (updownunits--) - wall[w].ypanning = changechar(wall[w].ypanning,changedir,smooshyalign,0); - message("Wall %d panning: %d, %d",w,wall[w].xpanning,wall[w].ypanning); + wall[w].ypanning = changechar(wall[w].ypanning, changedir, smooshyalign, 0); + message("Wall %d panning: %d, %d", w, wall[w].xpanning, wall[w].ypanning); } } - if ((searchstat == SEARCH_CEILING) || (searchstat == SEARCH_FLOOR)) + else if (AIMING_AT_CEILING_OR_FLOOR) { - if (searchstat == SEARCH_CEILING) - { - while (updownunits--) - sector[searchsector].ceilingypanning = changechar(sector[searchsector].ceilingypanning,changedir,smooshyalign,0); - message("Sector %d ceiling panning: %d, %d",searchsector,sector[searchsector].ceilingxpanning,sector[searchsector].ceilingypanning); - } - else - { - while (updownunits--) - sector[searchsector].floorypanning = changechar(sector[searchsector].floorypanning,changedir,smooshyalign,0); - message("Sector %d floor panning: %d, %d",searchsector,sector[searchsector].floorxpanning,sector[searchsector].floorypanning); - } + while (updownunits--) + AIMED_CEILINGFLOOR(ypanning) = changechar(AIMED_CEILINGFLOOR(ypanning), changedir, smooshyalign, 0); + message("Sector %d %s panning: %d, %d", searchsector, typestr[searchstat], + AIMED_CEILINGFLOOR(xpanning), AIMED_CEILINGFLOOR(ypanning)); + asksave = 1; } - if (searchstat == SEARCH_SPRITE) + else if (AIMING_AT_SPRITE) { static int32_t sumxvect=0, sumyvect=0; @@ -6556,10 +5820,11 @@ static void Keys3d(void) else { sumxvect = sumyvect = 0; - while (updownunits--)sprite[searchwall].yrepeat = changechar(sprite[searchwall].yrepeat,changedir,smooshyalign,1); + while (updownunits--) + sprite[searchwall].yrepeat = changechar(sprite[searchwall].yrepeat, changedir, smooshyalign, 1); if (sprite[searchwall].yrepeat < 4) sprite[searchwall].yrepeat = 4; - message("Sprite %d repeat: %d, %d",searchwall,sprite[searchwall].xrepeat,sprite[searchwall].yrepeat); + message("Sprite %d repeat: %d, %d", searchwall, sprite[searchwall].xrepeat, sprite[searchwall].yrepeat); } } asksave = 1; @@ -6570,160 +5835,122 @@ static void Keys3d(void) else repeatcounty = 0; - if (keystatus[KEYSC_F11]) //F11 - brightness + //////////////////// + + if (PRESSED_KEYSC(F11)) //F11 - brightness { extern int16_t brightness; - keystatus[KEYSC_F11] = 0; - - if (eitherSHIFT) - { - brightness--; - if (brightness < 0) brightness = 15; - } - else - { - brightness++; - if (brightness >= 16) brightness = 0; - } + brightness = brightness + (1-2*eitherSHIFT); + brightness &= 15; vid_gamma = 1.0 + ((float)brightness / 10.0); - setbrightness(brightness,palette,0); - message("Brightness: %d/16",brightness+1); + setbrightness(brightness, palette, 0); + message("Brightness: %d/16", brightness+1); } - if (keystatus[KEYSC_TAB]) //TAB + if (PRESSED_KEYSC(TAB)) //TAB { - if (searchstat == SEARCH_WALL) + if (ASSERT_AIMING) { - temppicnum = wall[searchbottomwall].picnum; - tempshade = wall[searchbottomwall].shade; - temppal = wall[searchbottomwall].pal; - tempxrepeat = wall[searchbottomwall].xrepeat; - tempyrepeat = wall[searchbottomwall].yrepeat; - tempcstat = wall[searchbottomwall].cstat; - templotag = wall[searchbottomwall].lotag; - temphitag = wall[searchbottomwall].hitag; - tempextra = wall[searchbottomwall].extra; + tempshade = AIMED_CF_SEL(shade); + temppal = AIMED_CF_SEL(pal); + templotag = AIMED_SEL(lotag); + temphitag = AIMED_SEL(hitag); + tempextra = AIMED_SEL(extra); + + if (AIMING_AT_WALL_OR_MASK) + { + temppicnum = AIMED_SELOVR_WALL(picnum); + tempxrepeat = AIMED_SEL_WALL(xrepeat); + tempyrepeat = AIMED_SEL_WALL(yrepeat); + tempcstat = AIMED_SEL_WALL(cstat); + } + else if (AIMING_AT_CEILING_OR_FLOOR) + { + temppicnum = AIMED_CEILINGFLOOR(picnum); + tempvis = sector[searchsector].visibility; + tempxrepeat = AIMED_CEILINGFLOOR(xpanning); + tempyrepeat = AIMED_CEILINGFLOOR(ypanning); + tempcstat = AIMED_CEILINGFLOOR(stat); + } + else if (AIMING_AT_SPRITE) + { + temppicnum = sprite[searchwall].picnum; + tempxrepeat = sprite[searchwall].xrepeat; + tempyrepeat = sprite[searchwall].yrepeat; + tempcstat = sprite[searchwall].cstat; + tempxvel = sprite[searchwall].xvel; + tempyvel = sprite[searchwall].yvel; + tempzvel = sprite[searchwall].zvel; + } + + somethingintab = searchstat; } - if (searchstat == SEARCH_CEILING) - { - temppicnum = sector[searchsector].ceilingpicnum; - tempshade = sector[searchsector].ceilingshade; - temppal = sector[searchsector].ceilingpal; - tempvis = sector[searchsector].visibility; - tempxrepeat = sector[searchsector].ceilingxpanning; - tempyrepeat = sector[searchsector].ceilingypanning; - tempcstat = sector[searchsector].ceilingstat; - templotag = sector[searchsector].lotag; - temphitag = sector[searchsector].hitag; - tempextra = sector[searchsector].extra; - } - if (searchstat == SEARCH_FLOOR) - { - temppicnum = sector[searchsector].floorpicnum; - tempshade = sector[searchsector].floorshade; - temppal = sector[searchsector].floorpal; - tempvis = sector[searchsector].visibility; - tempxrepeat = sector[searchsector].floorxpanning; - tempyrepeat = sector[searchsector].floorypanning; - tempcstat = sector[searchsector].floorstat; - templotag = sector[searchsector].lotag; - temphitag = sector[searchsector].hitag; - tempextra = sector[searchsector].extra; - } - if (searchstat == SEARCH_SPRITE) - { - temppicnum = sprite[searchwall].picnum; - tempshade = sprite[searchwall].shade; - temppal = sprite[searchwall].pal; - tempxrepeat = sprite[searchwall].xrepeat; - tempyrepeat = sprite[searchwall].yrepeat; - tempcstat = sprite[searchwall].cstat; - templotag = sprite[searchwall].lotag; - temphitag = sprite[searchwall].hitag; - tempextra = sprite[searchwall].extra; - tempxvel = sprite[searchwall].xvel; - tempyvel = sprite[searchwall].yvel; - tempzvel = sprite[searchwall].zvel; - } - if (searchstat == SEARCH_MASKWALL) - { - temppicnum = wall[searchwall].overpicnum; - tempshade = wall[searchwall].shade; - temppal = wall[searchwall].pal; - tempxrepeat = wall[searchwall].xrepeat; - tempyrepeat = wall[searchwall].yrepeat; - tempcstat = wall[searchwall].cstat; - templotag = wall[searchwall].lotag; - temphitag = wall[searchwall].hitag; - tempextra = wall[searchwall].extra; - } - somethingintab = searchstat; - keystatus[KEYSC_TAB] = 0; } - if (keystatus[KEYSC_ENTER]) + if (PRESSED_KEYSC(ENTER)) // ENTER -- paste clipboard contents { extern char pskysearch[MAXSECTORS]; int16_t daang; int32_t dashade[2]; + if (eitherSHIFT) { - if (((searchstat == SEARCH_WALL) || (searchstat == SEARCH_MASKWALL)) && eitherCTRL) //Ctrl-shift Enter (auto-shade) + if (AIMING_AT_WALL_OR_MASK && eitherCTRL) //Ctrl-shift Enter (auto-shade) { dashade[0] = 127; dashade[1] = -128; + i = searchwall; do { - if ((int32_t)wall[i].shade < dashade[0]) dashade[0] = wall[i].shade; - if ((int32_t)wall[i].shade > dashade[1]) dashade[1] = wall[i].shade; + if (dashade[0] > (int32_t)wall[i].shade) + dashade[0] = wall[i].shade; + if (dashade[1] < (int32_t)wall[i].shade) + dashade[1] = wall[i].shade; i = wall[i].point2; } while (i != searchwall); - daang = getangle(wall[wall[searchwall].point2].x-wall[searchwall].x,wall[wall[searchwall].point2].y-wall[searchwall].y); + daang = getangle(POINT2(searchwall).x-wall[searchwall].x, POINT2(searchwall).y-wall[searchwall].y); + i = searchwall; do { - j = getangle(wall[wall[i].point2].x-wall[i].x,wall[wall[i].point2].y-wall[i].y); - k = ((j+2048-daang)&2047); + j = getangle(POINT2(i).x-wall[i].x,POINT2(i).y-wall[i].y); + k = (j+2048-daang)&2047; if (k > 1024) k = 2048-k; - wall[i].shade = dashade[0]+mulscale10(k,dashade[1]-dashade[0]); + + wall[i].shade = dashade[0]+mulscale10(k, dashade[1]-dashade[0]); i = wall[i].point2; } while (i != searchwall); - message("Wall %d auto-shaded",searchwall); + + message("Wall %d auto-shaded", searchwall); } else if (somethingintab < 255) { - if (searchstat == SEARCH_WALL) + if (ASSERT_AIMING) { - wall[searchbottomwall].shade = tempshade; - wall[searchbottomwall].pal = temppal; + AIMED_CF_SEL(shade) = tempshade; + AIMED_CF_SEL(pal) = temppal; + + if (AIMING_AT_CEILING_OR_FLOOR) + { + if (somethingintab == SEARCH_CEILING || somethingintab == SEARCH_FLOOR) + sector[searchsector].visibility = tempvis; + } + + message("Pasted shading+pal"); + asksave = 1; } - if (searchstat == SEARCH_CEILING) - { - sector[searchsector].ceilingshade = tempshade, sector[searchsector].ceilingpal = temppal; - if ((somethingintab == 1) || (somethingintab == 2)) - sector[searchsector].visibility = tempvis; - } - if (searchstat == SEARCH_FLOOR) - { - sector[searchsector].floorshade = tempshade, sector[searchsector].floorpal = temppal; - if ((somethingintab == 1) || (somethingintab == 2)) - sector[searchsector].visibility = tempvis; - } - if (searchstat == SEARCH_SPRITE) sprite[searchwall].shade = tempshade, sprite[searchwall].pal = temppal; - if (searchstat == SEARCH_MASKWALL) wall[searchwall].shade = tempshade, wall[searchwall].pal = temppal; - message("Pasted shading+pal"); } } - else if (((searchstat == SEARCH_WALL) || (searchstat == SEARCH_MASKWALL)) && eitherCTRL && (somethingintab < 255)) //Either ctrl key + else if (AIMING_AT_WALL_OR_MASK && eitherCTRL && somethingintab < 255) //Either ctrl key { i = searchwall; do @@ -6731,101 +5958,73 @@ static void Keys3d(void) wall[i].picnum = temppicnum; wall[i].shade = tempshade; wall[i].pal = temppal; - if ((somethingintab == 0) || (somethingintab == 4)) + + if (somethingintab == SEARCH_WALL || somethingintab == SEARCH_MASKWALL) { wall[i].xrepeat = tempxrepeat; wall[i].yrepeat = tempyrepeat; wall[i].cstat = tempcstat; } + fixrepeats((int16_t)i); i = wall[i].point2; } while (i != searchwall); + message("Pasted picnum+shading+pal"); + asksave = 1; } - else if (((searchstat == SEARCH_CEILING) || (searchstat == SEARCH_FLOOR)) && eitherCTRL && (somethingintab < 255)) //Either ctrl key + else if (AIMING_AT_CEILING_OR_FLOOR && eitherCTRL && somethingintab < 255) //Either ctrl key { - clearbuf(&pskysearch[0],(int32_t)((numsectors+3)>>2),0L); - if (searchstat == SEARCH_CEILING) + Bmemset(pskysearch, 0, numsectors); + + i = searchsector; + if (CEILINGFLOOR(i, stat)&1) + pskysearch[i] = 1; + + while (pskysearch[i] == 1) { - i = searchsector; - if ((sector[i].ceilingstat&1) > 0) - pskysearch[i] = 1; + CEILINGFLOOR(i, picnum) = temppicnum; + CEILINGFLOOR(i, shade) = tempshade; + CEILINGFLOOR(i, pal) = temppal; - while (pskysearch[i] == 1) + if (somethingintab == SEARCH_CEILING || somethingintab == SEARCH_FLOOR) { - sector[i].ceilingpicnum = temppicnum; - sector[i].ceilingshade = tempshade; - sector[i].ceilingpal = temppal; - if ((somethingintab == 1) || (somethingintab == 2)) - { - sector[i].ceilingxpanning = tempxrepeat; - sector[i].ceilingypanning = tempyrepeat; - sector[i].ceilingstat = tempcstat; - } - pskysearch[i] = 2; - - startwall = sector[i].wallptr; - endwall = startwall + sector[i].wallnum - 1; - for (j=startwall; j<=endwall; j++) - { - k = wall[j].nextsector; - if (k >= 0) - if ((sector[k].ceilingstat&1) > 0) - if (pskysearch[k] == 0) - pskysearch[k] = 1; - } - - for (j=0; j 0) - pskysearch[i] = 1; + pskysearch[i] = 2; - while (pskysearch[i] == 1) + startwall = sector[i].wallptr; + endwall = startwall + sector[i].wallnum - 1; + + for (j=startwall; j<=endwall; j++) { - sector[i].floorpicnum = temppicnum; - sector[i].floorshade = tempshade; - sector[i].floorpal = temppal; - if ((somethingintab == 1) || (somethingintab == 2)) - { - sector[i].floorxpanning = tempxrepeat; - sector[i].floorypanning = tempyrepeat; - sector[i].floorstat = tempcstat; - } - pskysearch[i] = 2; - - startwall = sector[i].wallptr; - endwall = startwall + sector[i].wallnum - 1; - for (j=startwall; j<=endwall; j++) - { - k = wall[j].nextsector; - if (k >= 0) - if ((sector[k].floorstat&1) > 0) - if (pskysearch[k] == 0) - pskysearch[k] = 1; - } - - for (j=0; j= 0) + if ((CEILINGFLOOR(k, stat)&1) > 0) + if (pskysearch[k] == 0) + pskysearch[k] = 1; } + + for (j=0; j= 0) + NEXTWALL(searchwall).overpicnum = temppicnum; + + wall[searchwall].shade = tempshade; + wall[searchwall].pal = temppal; + + if (somethingintab == SEARCH_MASKWALL) { - sector[searchsector].ceilingxpanning = tempxrepeat; - sector[searchsector].ceilingypanning = tempyrepeat; - sector[searchsector].ceilingstat = tempcstat; + wall[searchwall].xrepeat = tempxrepeat; + wall[searchwall].yrepeat = tempyrepeat; + wall[searchwall].cstat = tempcstat; + wall[searchwall].lotag = templotag; + wall[searchwall].hitag = temphitag; + wall[searchwall].extra = tempextra; + } + fixrepeats(searchwall); + asksave = 1; + } + else if (AIMING_AT_CEILING_OR_FLOOR) + { + AIMED_CEILINGFLOOR(picnum) = temppicnum; + AIMED_CEILINGFLOOR(shade) = tempshade; + AIMED_CEILINGFLOOR(pal) = temppal; + + if (somethingintab == SEARCH_CEILING || somethingintab == SEARCH_FLOOR) + { + AIMED_CEILINGFLOOR(xpanning) = tempxrepeat; + AIMED_CEILINGFLOOR(ypanning) = tempyrepeat; + AIMED_CEILINGFLOOR(stat) = tempcstat; + sector[searchsector].visibility = tempvis; sector[searchsector].lotag = templotag; sector[searchsector].hitag = temphitag; sector[searchsector].extra = tempextra; } + asksave = 1; } - if (searchstat == SEARCH_FLOOR) - { - sector[searchsector].floorpicnum = temppicnum; - sector[searchsector].floorshade = tempshade; - sector[searchsector].floorpal = temppal; - if ((somethingintab == 1) || (somethingintab == 2)) - { - sector[searchsector].floorxpanning= tempxrepeat; - sector[searchsector].floorypanning= tempyrepeat; - sector[searchsector].floorstat = tempcstat; - sector[searchsector].visibility = tempvis; - sector[searchsector].lotag = templotag; - sector[searchsector].hitag = temphitag; - sector[searchsector].extra = tempextra; - } - } - if (searchstat == SEARCH_SPRITE) + else if (AIMING_AT_SPRITE) { sprite[searchwall].picnum = temppicnum; - if ((tilesizx[temppicnum] <= 0) || (tilesizy[temppicnum] <= 0)) + + if (tilesizx[temppicnum] <= 0 || tilesizy[temppicnum] <= 0) { j = 0; for (k=0; k 0) && (tilesizy[k] > 0)) + if (tilesizx[k] > 0 && tilesizy[k] > 0) { j = k; break; } sprite[searchwall].picnum = j; } + sprite[searchwall].shade = tempshade; sprite[searchwall].pal = temppal; - if (somethingintab == 3) + + if (somethingintab == SEARCH_SPRITE) { - sprite[searchwall].xrepeat = tempxrepeat; - sprite[searchwall].yrepeat = tempyrepeat; - if (sprite[searchwall].xrepeat < 1) sprite[searchwall].xrepeat = 1; - if (sprite[searchwall].yrepeat < 1) sprite[searchwall].yrepeat = 1; + sprite[searchwall].xrepeat = max(tempxrepeat, 1); + sprite[searchwall].yrepeat = max(tempyrepeat, 1); sprite[searchwall].cstat = tempcstat; sprite[searchwall].lotag = templotag; sprite[searchwall].hitag = temphitag; @@ -6899,34 +6108,14 @@ static void Keys3d(void) sprite[searchwall].zvel = tempzvel; } } - if (searchstat == SEARCH_MASKWALL) - { - wall[searchwall].overpicnum = temppicnum; - if (wall[searchwall].nextwall >= 0) - wall[wall[searchwall].nextwall].overpicnum = temppicnum; - wall[searchwall].shade = tempshade; - wall[searchwall].pal = temppal; - if (somethingintab == 4) - { - wall[searchwall].xrepeat = tempxrepeat; - wall[searchwall].yrepeat = tempyrepeat; - wall[searchwall].cstat = tempcstat; - wall[searchwall].lotag = templotag; - wall[searchwall].hitag = temphitag; - wall[searchwall].extra = tempextra; - } - fixrepeats(searchwall); - } message("Pasted clipboard"); + asksave = 1; } - asksave = 1; - keystatus[KEYSC_ENTER] = 0; } - if (keystatus[KEYSC_C]) + if (PRESSED_KEYSC(C)) { - keystatus[KEYSC_C] = 0; - if (eitherALT) + if (eitherALT) // Alt-C picnum replacer { if (somethingintab < 255) { @@ -6935,28 +6124,28 @@ static void Keys3d(void) case SEARCH_WALL: j = wall[searchbottomwall].picnum; for (i=0; i=0: forwards char did_wrap = 0; int32_t i, j, k = 0; - for (dir<0 ? gs_cursprite-- : gs_cursprite++;; dir<0 ? gs_cursprite-- : gs_cursprite++) + dir = 1-2*(dir<0); + + for (gs_cursprite += dir;; gs_cursprite += dir) { - if (gs_cursprite < 0) + if (gs_cursprite < 0 || gs_cursprite >= MAXSPRITES) { - if (!did_wrap) - { - did_wrap = 1; - gs_cursprite = MAXSPRITES-1; - } - else break; - } - if (gs_cursprite >= MAXSPRITES) - { - if (!did_wrap) - { - did_wrap = 1; - gs_cursprite = 0; - } - else break; + if (did_wrap) + break; + + did_wrap = 1; + gs_cursprite &= (MAXSPRITES-1); } if (sprite[gs_cursprite].statnum == MAXSTATUS) continue; @@ -7195,19 +6343,13 @@ extern int32_t graphicsmode; static void Keys2d(void) { - int16_t temp=0; - int32_t i=0, j,k; - int32_t smooshyalign,changedir; - static int32_t repeatcountx=0,repeatcounty=0; + int32_t i=0, j, k; + int32_t smooshy, changedir; + static int32_t repeatcnt[2] = {0,0}; // was repeatcountx, repeatcounty - /* - for(i=0;i<0x50;i++) - {if(keystatus[i]==1) {Bsprintf(tempbuf,"key %d",i); printmessage16(tempbuf); - }} - */ +// for(i=0;i<0x50;i++) if(keystatus[i]==1) Bsprintf(tempbuf,"key %d",i); printmessage16(tempbuf); cursectornum = -1; - for (i=0; i= 40 && totalclock >= 120*6) + if (counter >= 40 && totalclock >= 120*6) { if (pointhighlight >= 16384) { @@ -7260,104 +6401,53 @@ static void Keys2d(void) showspritedata((int16_t)i+16384); if (sprite[i].picnum==SECTOREFFECTOR) - { - char buffer[80]; - - Bsprintf(buffer,"^10%s",SectorEffectorText(i)); - _printmessage16(buffer); - } + _printmessage16("^10%s", SectorEffectorText(i)); } - else if ((linehighlight >= 0) && (bstatus&1 || sectorofwall(linehighlight) == cursectornum)) - { + else if (linehighlight >= 0 && ((bstatus&1) || sectorofwall(linehighlight)==cursectornum)) showwalldata((int16_t)linehighlight+16384); - } else if (cursectornum >= 0) - { showsectordata((int16_t)cursectornum+16384); - } } - if (totalclock < (lastpm16time + 120*2)) + + if (totalclock < lastpm16time + 120*2) _printmessage16(lastpm16buf); } - /* - if ((totalclock > getmessagetimeoff) && (totalclock > (lastpm16time + 120*3))) - { - if (pointhighlight >= 16384) - { - char tmpbuf[2048]; - i = pointhighlight-16384; - if (strlen(names[sprite[i].picnum]) > 0) - { - if (sprite[i].picnum==SECTOREFFECTOR) - Bsprintf(tmpbuf,"Sprite %d %s, hi:%d ex:%d",i,SectorEffectorText(i),sprite[i].hitag,sprite[i].extra); - else Bsprintf(tmpbuf,"Sprite %d %s: lo:%d hi:%d ex:%d",i,names[sprite[i].picnum],sprite[i].lotag,sprite[i].hitag,sprite[i].extra); - } - else Bsprintf(tmpbuf,"Sprite %d picnum %d: lo:%d hi:%d ex:%d",i,sprite[i].picnum,sprite[i].lotag,sprite[i].hitag,sprite[i].extra); - _printmessage16(tmpbuf); - } - else if ((linehighlight >= 0) && (sectorofwall(linehighlight) == cursectornum)) - { - int32_t dax, day, dist; - dax = wall[linehighlight].x-wall[wall[linehighlight].point2].x; - day = wall[linehighlight].y-wall[wall[linehighlight].point2].y; - dist = ksqrt(dax*dax+day*day); - Bsprintf(tempbuf,"Wall %d: length:%d lo:%d hi:%d ex:%d",linehighlight,dist,wall[linehighlight].lotag,wall[linehighlight].hitag,wall[linehighlight].extra); - _printmessage16(tempbuf); - } - else if (cursectornum >= 0) - { - Bsprintf(tempbuf,"Sector %d: lo:%d hi:%d ex:%d",cursectornum,sector[cursectornum].lotag,sector[cursectornum].hitag,sector[cursectornum].extra); - _printmessage16(tempbuf); - } - else _printmessage16(""); - } - */ - if (keystatus[KEYSC_QUOTE] && keystatus[KEYSC_Z]) // ' z - { - keystatus[KEYSC_Z] = 0; +///__bigcomment__ - editorzrange[0]=getnumber16("Upper Z range: ",editorzrange[0],INT32_MAX,1); - editorzrange[1]=getnumber16("Lower Z range: ",editorzrange[1],INT32_MAX,1); + if (keystatus[KEYSC_QUOTE] && PRESSED_KEYSC(Z)) // ' z + { + editorzrange[0] = getnumber16("Upper Z range: ", editorzrange[0], INT32_MAX, 1); + editorzrange[1] = getnumber16("Lower Z range: ", editorzrange[1], INT32_MAX, 1); // printmessage16(""); } - if (keystatus[0x14]) // T (tag) + if (PRESSED_KEYSC(T)) // T (tag) { char buffer[80]; - keystatus[0x14] = 0; - if (keystatus[0x1d]|keystatus[0x9d]) //Ctrl-T + if (eitherCTRL) //Ctrl-T { extern int32_t showtags; showtags ^= 1; - if (showtags == 0) - printmessage16("Show tags OFF"); - else - printmessage16("Show tags ON"); + printmessage16("Show tags %s", ONOFF( showtags)); } - else if (keystatus[0x38]|keystatus[0xb8]) //ALT + else if (eitherALT) //ALT { if (pointhighlight >= 16384) { i = pointhighlight-16384; - Bsprintf(buffer,"Sprite (%d) Lo-tag: ",i); - if (sprite[i].picnum == SECTOREFFECTOR) - sprite[i].lotag = _getnumber16(buffer,sprite[i].lotag,65536L,0,(void *)SectorEffectorTagText); - else sprite[i].lotag = getnumber16(buffer,sprite[i].lotag,65536L,0); - clearmidstatbar16(); - showspritedata((int16_t)i); + Bsprintf(buffer,"Sprite (%d) Lo-tag: ", i); + sprite[i].lotag = _getnumber16(buffer, sprite[i].lotag, BTAG_MAX, 0, sprite[i].picnum==SECTOREFFECTOR ? + (void *)SectorEffectorTagText : NULL); } else if (linehighlight >= 0) { i = linehighlight; - Bsprintf(buffer,"Wall (%d) Lo-tag: ",i); - wall[i].lotag = getnumber16(buffer,wall[i].lotag,65536L,0); - clearmidstatbar16(); - showwalldata((int16_t)i); + Bsprintf(buffer,"Wall (%d) Lo-tag: ", i); + wall[i].lotag = getnumber16(buffer, wall[i].lotag, BTAG_MAX, 0); } - // printmessage16(""); } else { @@ -7367,78 +6457,62 @@ static void Keys2d(void) Bsprintf(buffer,"Sector (%d) Lo-tag: ",i); j = qsetmode; qsetmode = 200; - sector[i].lotag = _getnumber16(buffer,sector[i].lotag,65536L,0,(void *)ExtGetSectorType); + sector[i].lotag = _getnumber16(buffer, sector[i].lotag, BTAG_MAX, 0, (void *)ExtGetSectorType); qsetmode = j; - clearmidstatbar16(); - showsectordata((int16_t)i); - break; +// break; } - // printmessage16(""); } } - if (keystatus[KEYSC_F1] || (keystatus[KEYSC_QUOTE] && keystatus[KEYSC_TILDE])) //F1 or ' ~ + if (PRESSED_KEYSC(F1) || (keystatus[KEYSC_QUOTE] && keystatus[KEYSC_TILDE])) //F1 or ' ~ { - keystatus[KEYSC_F1]=0; // PK_ - if (numhelppages>0) IntegratedHelp(); - else printmessage16("m32help.hlp invalid or not found!"); + if (numhelppages>0) + IntegratedHelp(); + else + printmessage16("m32help.hlp invalid or not found!"); } - if (keystatus[KEYSC_F2]) - { - keystatus[KEYSC_F2]=0; - + if (PRESSED_KEYSC(F2)) if (g_numsounds > 0) SoundDisplay(); - } - getpoint(searchx,searchy,&mousxplc,&mousyplc); + getpoint(searchx,searchy, &mousxplc,&mousyplc); ppointhighlight = getpointhighlight(mousxplc,mousyplc, ppointhighlight); if ((ppointhighlight&0xc000) == 16384) { // sprite[ppointhighlight&16383].cstat ^= 1; - cursprite=(ppointhighlight&16383); + cursprite = ppointhighlight&16383; } - if (keystatus[KEYSC_F9]) // F9 f1=3b - { - keystatus[KEYSC_F9] = 0; + if (PRESSED_KEYSC(F9)) // F9 f1=3b Show2dText("sthelp.hlp"); - } /* start Mapster32 */ - if (keystatus[KEYSC_F4]) + if (PRESSED_KEYSC(F4)) { showfirstwall = !showfirstwall; - message("Sector firstwall highlight %s",showfirstwall?"enabled":"disabled"); - keystatus[KEYSC_F4] = 0; + message("Sector firstwall highlight %s", showfirstwall?"enabled":"disabled"); } - if (keystatus[KEYSC_M]) // M (tag) + if (PRESSED_KEYSC(M)) // M (tag) { - keystatus[KEYSC_M] = 0; if (eitherALT) //ALT { if (pointhighlight >= 16384) { i = pointhighlight-16384; - Bsprintf(tempbuf,"Sprite %d Extra: ",i); - sprite[i].extra = getnumber16(tempbuf,sprite[i].extra,65536L,1); - clearmidstatbar16(); - showspritedata((int16_t)i); + Bsprintf(tempbuf, "Sprite %d Extra: ", i); + sprite[i].extra = getnumber16(tempbuf, sprite[i].extra, BTAG_MAX, 1); } else if (linehighlight >= 0) { i = linehighlight; Bsprintf(tempbuf,"Wall %d Extra: ",i); - wall[i].extra = getnumber16(tempbuf,wall[i].extra,65536L,1); - clearmidstatbar16(); - showwalldata((int16_t)i); + wall[i].extra = getnumber16(tempbuf,wall[i].extra,BTAG_MAX,1); } - // printmessage16(""); } else { @@ -7446,41 +6520,34 @@ static void Keys2d(void) if (inside(mousxplc,mousyplc,i) == 1) { Bsprintf(tempbuf,"Sector %d Extra: ",i); - sector[i].extra = getnumber16(tempbuf,sector[i].extra,65536L,1); - clearmidstatbar16(); - showsectordata((int16_t)i); - break; + sector[i].extra = getnumber16(tempbuf,sector[i].extra,BTAG_MAX,1); +// clearmidstatbar16(); +// showsectordata((int16_t)i); +// break; } - // printmessage16(""); } } - if (keystatus[KEYSC_E]) // E (expand) + if (PRESSED_KEYSC(E)) // E (expand) { for (i=0; i 32)) - { - changedir = 0; - if (keystatus[KEYSC_gLEFT]) changedir = -1; - if (keystatus[KEYSC_gRIGHT]) changedir = 1; - - if ((ppointhighlight&0xc000) == 16384 && (sprite[cursprite].cstat & 48)) - { - sprite[cursprite].xrepeat = changechar(sprite[cursprite].xrepeat,changedir,smooshyalign,1); - if (sprite[cursprite].xrepeat < 4) - sprite[cursprite].xrepeat = 4; - message("Sprite %d repeat: %d, %d",cursprite,sprite[cursprite].xrepeat,sprite[cursprite].yrepeat); - } - else - { - for (i=0; i 32)) + if (k==0) + j = (keystatus[KEYSC_gLEFT]<<2)|keystatus[KEYSC_gRIGHT]; // 4 & 6 (keypad 2D) + else + j = (keystatus[KEYSC_gUP]<<2)|keystatus[KEYSC_gDOWN]; // 2 & 8 (keypad 2D) + + if (j) { - changedir = 0; - if (keystatus[KEYSC_gUP]) changedir = -1; - if (keystatus[KEYSC_gDOWN]) changedir = 1; + smooshy = keystatus[KEYSC_gKP5]; - if ((ppointhighlight&0xc000) == 16384 && (sprite[cursprite].cstat & 48)) + if (repeatcnt[k] == 0 || repeatcnt[k] > 32) { - sprite[cursprite].yrepeat = changechar(sprite[cursprite].yrepeat,changedir,smooshyalign,1); - if (sprite[cursprite].yrepeat < 4) - sprite[cursprite].yrepeat = 4; - message("Sprite %d repeat: %d, %d",cursprite,sprite[cursprite].xrepeat,sprite[cursprite].yrepeat); + changedir = 1-(j&2); + + if ((ppointhighlight&0xc000) == 16384 && (sprite[cursprite].cstat & 48)) + { + uint8_t *repeat = (k==0) ? &sprite[cursprite].xrepeat : &sprite[cursprite].yrepeat; + *repeat = max(4, changechar(*repeat, changedir, smooshy, 1)); + message("Sprite %d repeat: %d, %d", cursprite, sprite[cursprite].xrepeat, sprite[cursprite].yrepeat); + } + else + { + for (i=0; i= 16384) { - i = sprite[cursprite].cstat; - if ((i&48) < 32) i += 16; + const char *aligntype[4] = { "view", "wall", "floor", "???" }; - else i &= ~48; + i = sprite[cursprite].cstat; + if ((i&48) < 32) + i += 16; + else + i &= ~48; sprite[cursprite].cstat = i; - if (sprite[cursprite].cstat&16) - Bsprintf(getmessage,"Sprite %d now wall aligned",cursprite); - else if (sprite[cursprite].cstat&32) - Bsprintf(getmessage,"Sprite %d now floor aligned",cursprite); - else - Bsprintf(getmessage,"Sprite %d now view aligned",cursprite); - message(getmessage); + message("Sprite %d now view aligned", cursprite, aligntype[(i&48)/16]); asksave = 1; - } - keystatus[KEYSC_R] = 0; } - if (keystatus[KEYSC_QUOTE] && keystatus[KEYSC_S]) // ' S { if (pointhighlight >= 16384) { keystatus[KEYSC_S] = 0; - Bsprintf(tempbuf,"Sprite %d xrepeat: ",cursprite); - sprite[cursprite].xrepeat=getnumber16(tempbuf, sprite[cursprite].xrepeat, 256,0); - Bsprintf(tempbuf,"Sprite %d yrepeat: ",cursprite); - sprite[cursprite].yrepeat=getnumber16(tempbuf, sprite[cursprite].yrepeat, 256,0); - Bsprintf(tempbuf,"Sprite %d updated",i); + Bsprintf(tempbuf, "Sprite %d xrepeat: ", cursprite); + sprite[cursprite].xrepeat = getnumber16(tempbuf, sprite[cursprite].xrepeat, 255, 0); + Bsprintf(tempbuf, "Sprite %d yrepeat: ", cursprite); + sprite[cursprite].yrepeat = getnumber16(tempbuf, sprite[cursprite].yrepeat, 255, 0); + Bsprintf(tempbuf, "Sprite %d updated", i); printmessage16(tempbuf); } } - if (keystatus[KEYSC_QUOTE] && keystatus[KEYSC_F]) // ' F + if (keystatus[KEYSC_QUOTE] && PRESSED_KEYSC(F)) // ' F { - keystatus[KEYSC_F] = 0; FuncMenu(); } - if (keystatus[KEYSC_LBRACK]) // [ search backward + tsign = 0; + if (PRESSED_KEYSC(LBRACK)) // [ search backward + tsign = -1; + if (PRESSED_KEYSC(RBRACK)) // ] search forward + tsign = +1; + + if (tsign) { - keystatus[KEYSC_LBRACK]=0; if (wallsprite==0) - { - SearchSectorsBackward(); - } + SearchSectors(tsign); else if (wallsprite==1) { - if (curwallnum>0) curwallnum--; - for (i=curwallnum; i>=0; i--) + if ((tsign<0 && curwallnum>0) || (tsign>0 && curwallnum=0 && i"); return; } curwallnum--; } - printmessage16("< Wall search: none found"); + printmessage16("%s Wall search: none found", tsign<0?"<":">"); } else if (wallsprite==2) - DoSpriteSearch(-1); -#if 0 - { - if (cursearchspritenum>0) cursearchspritenum--; - for (i=cursearchspritenum; i>=0; i--) - { + DoSpriteSearch(tsign); + +///__old_sprite_search_1__ + +///__old_sprite_search_2__ - if ( - (sprite[i].picnum==sprite[cursearchsprite].picnum && - sprite[i].statnum==0) - &&((search_lotag==0)|| - (search_lotag!=0 && search_lotag==sprite[i].lotag)) - &&((search_hitag==0)|| - (search_hitag!=0 && search_hitag==sprite[i].hitag)) - ) - { - pos.x=sprite[i].x; - pos.y=sprite[i].y; - ang= sprite[i].ang; - printmessage16("< Sprite search: found"); - // curspritenum--; - keystatus[KEYSC_LBRACK]=0; - return; - } - cursearchspritenum--; - } - printmessage16("< Sprite search: none found"); - } -#endif } - - if (keystatus[KEYSC_RBRACK]) // ] search forward + if (PRESSED_KEYSC(G)) // G (grid on/off) { - keystatus[KEYSC_RBRACK]=0; - if (wallsprite==0) - { - SearchSectorsForward(); - } - else if (wallsprite==1) - { - if (curwallnum Wall search: found"); - // curwallnum++; - keystatus[KEYSC_RBRACK]=0; - return; - } - curwallnum++; - } - printmessage16("> Wall search: none found"); - } - else if (wallsprite==2) - DoSpriteSearch(1); -#if 0 - { - if (cursearchspritenum Sprite search: found"); - // curspritenum++; - keystatus[KEYSC_RBRACK]=0; - return; - } - cursearchspritenum++; - } - printmessage16("> Sprite search: none found"); - } -#endif - } - - { - if (keystatus[KEYSC_G]) // G (grid on/off) - { - if (autogrid) - { - grid = 0; - if (eitherSHIFT) - grid = 8; - autogrid = 0; - } - else - { - grid += eitherSHIFT?-1:1; - if (grid == -1 || grid == 9) - { - autogrid = 1; - grid = 0; - } - } - if (autogrid) Bsprintf(tempbuf,"Grid size: 9 (autosize)"); - else if (!grid) Bsprintf(tempbuf,"Grid off"); - else Bsprintf(tempbuf,"Grid size: %d (%d units)",grid,2048>>grid); - printmessage16(tempbuf); - keystatus[KEYSC_G] = 0; - } if (autogrid) { - grid = zoom+512; - if (grid > 65536) grid = 65536; - grid = scale(grid,6,6144); - if (grid > 7) grid = 7; - if (grid < 0) grid = 0; + grid = 0; + if (eitherSHIFT) + grid = 8; + + autogrid = 0; } + else + { + grid += (1-2*eitherSHIFT); + if (grid == -1 || grid == 9) + { + autogrid = 1; + grid = 0; + } + } + if (autogrid) + Bsprintf(tempbuf,"Grid size: 9 (autosize)"); + else if (!grid) + Bsprintf(tempbuf,"Grid off"); + else + Bsprintf(tempbuf,"Grid size: %d (%d units)", grid, 2048>>grid); + + printmessage16(tempbuf); + } + if (autogrid) + { + grid = min(zoom+512, 65536); + grid = scale(grid, 6, 6144); + grid = clamp(grid, 0, 7); } - if (keystatus[KEYSC_QUOTE] && keystatus[KEYSC_L]) // ' L + + if (keystatus[KEYSC_QUOTE] && PRESSED_KEYSC(L)) // ' L (set sprite/wall coordinates) { if (pointhighlight >= 16384) { i = pointhighlight - 16384; - Bsprintf(tempbuf,"Sprite %d x: ",i); - sprite[i].x = getnumber16(tempbuf,sprite[i].x,editorgridextent-1,1); - Bsprintf(tempbuf,"Sprite %d y: ",i); - sprite[i].y = getnumber16(tempbuf,sprite[i].y,editorgridextent-1,1); - Bsprintf(tempbuf,"Sprite %d z: ",i); - sprite[i].z = getnumber16(tempbuf,sprite[i].z,8388608,1); - Bsprintf(tempbuf,"Sprite %d angle: ",i); - sprite[i].ang = getnumber16(tempbuf,sprite[i].ang,2048L,0); - Bsprintf(tempbuf,"Sprite %d updated",i); + Bsprintf(tempbuf, "Sprite %d x: ", i); + sprite[i].x = getnumber16(tempbuf, sprite[i].x, editorgridextent-1, 1); + Bsprintf(tempbuf, "Sprite %d y: ", i); + sprite[i].y = getnumber16(tempbuf, sprite[i].y, editorgridextent-1, 1); + Bsprintf(tempbuf, "Sprite %d z: ", i); + sprite[i].z = getnumber16(tempbuf, sprite[i].z, 8388608, 1); + Bsprintf(tempbuf, "Sprite %d angle: ", i); + sprite[i].ang = getnumber16(tempbuf, sprite[i].ang, 2047, 0); + Bsprintf(tempbuf, "Sprite %d updated", i); printmessage16(tempbuf); } @@ -7789,99 +6736,53 @@ static void Keys2d(void) i = linehighlight; j = wall[i].x; k = wall[i].y; - Bsprintf(tempbuf,"Wall %d x: ",i); - j = getnumber16(tempbuf,j,editorgridextent,1); - Bsprintf(tempbuf,"Wall %d y: ",i); - k = getnumber16(tempbuf,k,editorgridextent,1); + + Bsprintf(tempbuf, "Wall %d x: ", i); + j = getnumber16(tempbuf, j, editorgridextent, 1); + Bsprintf(tempbuf, "Wall %d y: ", i); + k = getnumber16(tempbuf, k, editorgridextent, 1); dragpoint(i, j, k); - Bsprintf(tempbuf,"Wall %d updated",i); + Bsprintf(tempbuf, "Wall %d updated", i); printmessage16(tempbuf); } - - keystatus[KEYSC_L] = 0; } - if (keystatus[KEYSC_QUOTE] && keystatus[KEYSC_3]) // ' 3 + if (keystatus[KEYSC_QUOTE] && PRESSED_KEYSC(3)) // ' 3 { - onnames++; - if (onnames>8) onnames=0; - keystatus[KEYSC_3]=0; - Bsprintf(tempbuf,"Mode %d %s",onnames,SpriteMode[onnames]); + onnames = (onnames+1)%8; + Bsprintf(tempbuf, "Mode %d %s", onnames, SpriteMode[onnames]); printmessage16(tempbuf); // clearmidstatbar16(); // for(i=0;i=20 && sprite[i].picnum<=59) - { - sprite[i].xrepeat = 32; - sprite[i].yrepeat = 32; - } - } +///__motorcycle___ - } - */ - - // What the fuck is this supposed to do? - - /* Motorcycle ha ha ha - if(keystatus[KEYSC_QUOTE] && keystatus[KEYSC_5]) // ' 5 + if (keystatus[KEYSC_QUOTE] && PRESSED_KEYSC(7)) // ' 7 : swap hilo { - keystatus[KEYSC_5]=0; - sidemode++; if (sidemode > 2) sidemode = 0; - if (sidemode == 1) - { - editstatus = 0; - zmode = 2; - pos.z = ((sector[cursectnum].ceilingz+sector[cursectnum].floorz)>>1); - } - else - { - editstatus = 1; - zmode = 1; - } - } - */ - - if (keystatus[KEYSC_QUOTE] && keystatus[KEYSC_7]) // ' 7 : swap hilo - { - keystatus[KEYSC_7]=0; if (pointhighlight >= 16384) { - temp=sprite[cursprite].lotag; - sprite[cursprite].lotag=sprite[cursprite].hitag; - sprite[cursprite].hitag=temp; - Bsprintf(tempbuf,"Sprite %d tags swapped",cursprite); + swapshort(&sprite[cursprite].lotag, &sprite[cursprite].hitag); + Bsprintf(tempbuf, "Sprite %d tags swapped", cursprite); printmessage16(tempbuf); } else if (linehighlight >= 0) { - temp=wall[linehighlight].lotag; - wall[linehighlight].lotag=wall[linehighlight].hitag; - wall[linehighlight].hitag=temp; - Bsprintf(tempbuf,"Wall %d tags swapped",linehighlight); + swapshort(&wall[linehighlight].lotag, &wall[linehighlight].hitag); + Bsprintf(tempbuf, "Wall %d tags swapped", linehighlight); printmessage16(tempbuf); } } - if (keystatus[KEYSC_QUOTE] && keystatus[KEYSC_J]) // ' J + if (keystatus[KEYSC_QUOTE] && PRESSED_KEYSC(J)) // ' J { - pos.x=getnumber16("X-coordinate: ",pos.x,editorgridextent,1); - pos.y=getnumber16("Y-coordinate: ",pos.y,editorgridextent,1); - Bsprintf(tempbuf,"Current pos now (%d, %d)",pos.x,pos.y); + pos.x = getnumber16("X-coordinate: ", pos.x, editorgridextent, 1); + pos.y = getnumber16("Y-coordinate: ", pos.y, editorgridextent, 1); + Bsprintf(tempbuf, "Current pos now (%d, %d)", pos.x, pos.y); printmessage16(tempbuf); - keystatus[KEYSC_J]=0; } }// end key2d @@ -7978,12 +6879,14 @@ void ExtPreSaveMap(void) { startwall = sector[i].wallptr; for (j=startwall; j=0; i--) sector[i].wallnum = sector[i+1].wallptr-sector[i].wallptr; - sector[numsectors-1].wallnum = numwalls-sector[numsectors-1].wallptr; + sector[numsectors-1].wallnum = numwalls - sector[numsectors-1].wallptr; for (i=0; i 1) { lengths = Bmalloc(argc*sizeof(int32_t)); - for (j=1; jnumparms != 1) return OSDCMD_SHOWHELP; + else if (parm->numparms != 1) + return OSDCMD_SHOWHELP; i = Batol(parm->parms[0]); @@ -8323,7 +7228,9 @@ static int32_t osdcmd_editorgridextent(const osdfuncparm_t *parm) editorgridextent = i; OSD_Printf("editorgridextent %d\n", editorgridextent); } - else OSD_Printf("editorgridextent: value out of range\n"); + else + OSD_Printf("editorgridextent: value out of range (65536 to 524288)\n"); + return OSDCMD_OK; } @@ -8333,7 +7240,7 @@ static int32_t osdcmd_addpath(const osdfuncparm_t *parm) if (parm->numparms != 1) return OSDCMD_SHOWHELP; - strcpy(pathname,parm->parms[0]); + Bstrcpy(pathname,parm->parms[0]); addsearchpath(pathname); return OSDCMD_OK; } @@ -8344,7 +7251,7 @@ static int32_t osdcmd_initgroupfile(const osdfuncparm_t *parm) if (parm->numparms != 1) return OSDCMD_SHOWHELP; - strcpy(file,parm->parms[0]); + Bstrcpy(file,parm->parms[0]); initgroupfile(file); return OSDCMD_OK; } @@ -8426,7 +7333,7 @@ static int32_t osdcmd_showheightindicators(const osdfuncparm_t *parm) extern int32_t showheightindicators; if (parm->numparms == 1) - showheightindicators = min(max(atoi(parm->parms[0]),0),2); + showheightindicators = clamp(atoi(parm->parms[0]), 0, 2); OSD_Printf("height indicators: %s\n", showheightindicators==0 ? "none" : @@ -8443,7 +7350,8 @@ static int32_t osdcmd_vars_pk(const osdfuncparm_t *parm) // this is something of a misnomer, since it's actually accel+decel if (!Bstrcasecmp(parm->name, "pk_turnaccel")) { - if (showval) { OSD_Printf("Turning acceleration+declaration is %d\n", pk_turnaccel); } + if (showval) + OSD_Printf("Turning acceleration+declaration is %d\n", pk_turnaccel); else { pk_turnaccel = atoi(parm->parms[0]); @@ -8453,7 +7361,8 @@ static int32_t osdcmd_vars_pk(const osdfuncparm_t *parm) } else if (!Bstrcasecmp(parm->name, "pk_turndecel")) { - if (showval) { OSD_Printf("Turning deceleration is %d\n", pk_turndecel); } + if (showval) + OSD_Printf("Turning deceleration is %d\n", pk_turndecel); else { pk_turndecel = atoi(parm->parms[0]); @@ -8469,7 +7378,8 @@ static int32_t osdcmd_vars_pk(const osdfuncparm_t *parm) } else if (!Bstrcasecmp(parm->name, "pk_uedaccel")) { - if (showval) { OSD_Printf("UnrealEd mouse navigation acceleration is %d\n", pk_uedaccel); } + if (showval) + OSD_Printf("UnrealEd mouse navigation acceleration is %d\n", pk_uedaccel); else { pk_uedaccel = atoi(parm->parms[0]); @@ -8699,6 +7609,7 @@ static int32_t registerosdcommands(void) // OSD_RegisterFunction("disasm", "disasm [s|e] ", osdcmd_disasm); return 0; } + #define DUKEOSD #ifdef DUKEOSD void GAME_drawosdchar(int32_t x, int32_t y, char ch, int32_t shade, int32_t pal) @@ -8866,15 +7777,22 @@ static int32_t getatoken(scriptfile *sf, tokenlist *tl, int32_t ntokens) static void DoAutoload(const char *fn) { - Bsprintf(tempbuf,"autoload/%s",fn); - getfilenames(tempbuf,"*.grp"); - while (findfiles) { Bsprintf(tempbuf,"autoload/%s/%s",fn,findfiles->name); initprintf("Using group file '%s'.\n",tempbuf); initgroupfile(tempbuf); findfiles = findfiles->next; } - Bsprintf(tempbuf,"autoload/%s",fn); - getfilenames(tempbuf,"*.zip"); - while (findfiles) { Bsprintf(tempbuf,"autoload/%s/%s",fn,findfiles->name); initprintf("Using group file '%s'.\n",tempbuf); initgroupfile(tempbuf); findfiles = findfiles->next; } - Bsprintf(tempbuf,"autoload/%s",fn); - getfilenames(tempbuf,"*.pk3"); - while (findfiles) { Bsprintf(tempbuf,"autoload/%s/%s",fn,findfiles->name); initprintf("Using group file '%s'.\n",tempbuf); initgroupfile(tempbuf); findfiles = findfiles->next; } + static const char *extensions[3] = { "*.grp", "*.zip", "*.pk3" }; + int32_t i; + + for (i=0; i<3; i++) + { + Bsprintf(tempbuf, "autoload/%s", fn); + getfilenames(tempbuf, extensions[i]); + + while (findfiles) + { + Bsprintf(tempbuf, "autoload/%s/%s", fn, findfiles->name); + initprintf("Using group file '%s'.\n", tempbuf); + initgroupfile(tempbuf); + findfiles = findfiles->next; + } + } } int32_t parsegroupfiles(scriptfile *script) @@ -9365,7 +8283,7 @@ int32_t parseconsounds(scriptfile *script) break; } - slen = strlen(filename); + slen = Bstrlen(filename); if (slen >= BMAX_PATH) { initprintf("Warning: invalid sound definition %s (filename too long) on line %s:%d\n", @@ -9542,12 +8460,20 @@ int32_t ExtInit(void) if (!NoAutoLoad) { - getfilenames("autoload","*.grp"); - while (findfiles) { Bsprintf(tempbuf,"autoload/%s",findfiles->name); initprintf("Using group file '%s'.\n",tempbuf); initgroupfile(tempbuf); findfiles = findfiles->next; } - getfilenames("autoload","*.zip"); - while (findfiles) { Bsprintf(tempbuf,"autoload/%s",findfiles->name); initprintf("Using group file '%s'.\n",tempbuf); initgroupfile(tempbuf); findfiles = findfiles->next; } - getfilenames("autoload","*.pk3"); - while (findfiles) { Bsprintf(tempbuf,"autoload/%s",findfiles->name); initprintf("Using group file '%s'.\n",tempbuf); initgroupfile(tempbuf); findfiles = findfiles->next; } + static const char *extensions[3] = { "*.grp", "*.zip", "*.pk3" }; + int32_t exti; + + for (exti=0; exti<3; exti++) + { + getfilenames("autoload", extensions[exti]); + while (findfiles) + { + Bsprintf(tempbuf,"autoload/%s",findfiles->name); + initprintf("Using group file '%s'.\n",tempbuf); + initgroupfile(tempbuf); + findfiles = findfiles->next; + } + } if (i != -1) DoAutoload(g_grpNamePtr); @@ -9672,7 +8598,7 @@ void app_crashhandler(void) { // virtual filesystem mode can't save to directories so drop the file into // the current directory - f = strrchr(levelname, '/'); + f = Bstrrchr(levelname, '/'); if (!f) f = levelname; else f++; } f=strstr(levelname,".map"); @@ -9739,10 +8665,10 @@ void ExtPreCheckKeys(void) // just before drawrooms { if (!wallflag[wall[w].nextwall]) { - wallshades[wall[w].nextwall] = wall[wall[w].nextwall].shade; - wall[wall[w].nextwall].shade = sprite[i].shade; - wallpals[wall[w].nextwall] = wall[wall[w].nextwall].pal; - wall[wall[w].nextwall].pal = sprite[i].pal; + wallshades[wall[w].nextwall] = NEXTWALL(w).shade; + NEXTWALL(w).shade = sprite[i].shade; + wallpals[wall[w].nextwall] = NEXTWALL(w).pal; + NEXTWALL(w).pal = sprite[i].pal; wallflag[wall[w].nextwall] = 1; } } */ @@ -9911,9 +8837,12 @@ void ExtPreCheckKeys(void) // just before drawrooms #endif // POLYMER } } + if (floor_over_floor) SE40Code(pos.x,pos.y,pos.z,ang,horiz); + if (purpleon) clearview(255); - if (sidemode != 0) + + if (sidemode) { lockbyte4094 = 1; if (waloff[4094] == 0) @@ -10277,9 +9206,9 @@ void ExtAnalyzeSprites(void) } } - if (frames==2) tspr->picnum+=((((4-(totalclock>>5)))&1)*5); - if (frames==4) tspr->picnum+=((((4-(totalclock>>5)))&3)*5); - if (frames==5) tspr->picnum+=(((totalclock>>5)%5))*5; + if (frames==2) tspr->picnum += (((4-(totalclock>>5)))&1)*5; + if (frames==4) tspr->picnum += (((4-(totalclock>>5)))&3)*5; + if (frames==5) tspr->picnum += ((totalclock>>5)%5)*5; if (tilesizx[tspr->picnum] == 0) tspr->picnum -= 5; //Hack, for actors @@ -10309,31 +9238,27 @@ static void Keys2d3d(void) // mapstate = mapstate->prev; } - if (keystatus[KEYSC_QUOTE] && keystatus[KEYSC_A]) // ' a + if (keystatus[KEYSC_QUOTE] && PRESSED_KEYSC(A)) // 'A { - keystatus[KEYSC_A] = 0; - - if (qsetmode == 200) autosave=autosave?0:getnumber256("Autosave interval, in seconds: ",180,3600,0); - else autosave=autosave?0:getnumber16("Autosave interval, in seconds: ",180,3600,0); + if (qsetmode == 200) + autosave = autosave?0:getnumber256("Autosave interval, in seconds: ",180,3600,0); + else + autosave = autosave?0:getnumber16("Autosave interval, in seconds: ",180,3600,0); if (autosave) message("Autosave enabled, interval: %d seconds",autosave); else message("Autosave disabled"); } - if (keystatus[KEYSC_QUOTE] && keystatus[KEYSC_N]) // ' n + if (keystatus[KEYSC_QUOTE] && PRESSED_KEYSC(N)) // 'N { - keystatus[KEYSC_N] = 0; - noclip=!noclip; - if (noclip) message("Clipping disabled"); - else message("Clipping enabled"); + noclip = !noclip; + message("Clipping %s", noclip?"disabled":"enabled"); } - if (eitherCTRL && keystatus[KEYSC_N]) // CTRL+N + if (eitherCTRL && PRESSED_KEYSC(N)) // CTRL+N { - keystatus[KEYSC_N] = 0; - spnoclip=!spnoclip; - if (spnoclip) message("Sprite clipping disabled"); - else message("Sprite clipping enabled"); + spnoclip = !spnoclip; + message("Sprite clipping %s", spnoclip?"disabled":"enabled"); } if (eitherCTRL) //CTRL @@ -10344,13 +9269,12 @@ static void Keys2d3d(void) { // virtual filesystem mode can't save to directories so drop the file into // the current directory - f = strrchr(levelname, '/'); + f = Bstrrchr(levelname, '/'); if (!f) f = levelname; else f++; } - if (keystatus[KEYSC_P]) // Ctrl-P: Map playtesting + if (PRESSED_KEYSC(P)) // Ctrl-P: Map playtesting { - keystatus[KEYSC_P] = 0; if (qsetmode != 200) test_map(eitherALT); } @@ -10359,6 +9283,7 @@ static void Keys2d3d(void) { if (levelname[0]) { + keystatus[KEYSC_S] = 0; fixspritesectors(); //Do this before saving! updatesector(startposx,startposy,&startsectnum); ExtPreSaveMap(); @@ -10366,7 +9291,6 @@ static void Keys2d3d(void) ExtSaveMap(f); message("Board saved"); asksave = 0; - keystatus[KEYSC_S] = 0; lastsave=totalclock; } } @@ -10525,8 +9449,8 @@ void ExtCheckKeys(void) { if (wallflag[wall[w].nextwall]) { - wall[wall[w].nextwall].shade = wallshades[wall[w].nextwall]; - wall[wall[w].nextwall].pal = wallpals[wall[w].nextwall]; + NEXTWALL(w).shade = wallshades[wall[w].nextwall]; + NEXTWALL(w).pal = wallpals[wall[w].nextwall]; wallflag[wall[w].nextwall] = 0; } } */ @@ -10572,7 +9496,7 @@ void ExtCheckKeys(void) } else if (asksave == 2) asksave++; - if ((totalclock > autosavetimer) && (autosave)) + if (totalclock > autosavetimer && autosave) { if (asksave == 3) { @@ -10587,22 +9511,21 @@ void ExtCheckKeys(void) autosavetimer = totalclock+120*autosave; } - if (keystatus[KEYSC_F12]) //F12 + if (PRESSED_KEYSC(F12)) //F12 { - screencapture("captxxxx.tga",keystatus[KEYSC_LSHIFT]|keystatus[KEYSC_RSHIFT]); - message("Saved screenshot %04d",capturecount-1); - keystatus[KEYSC_F12] = 0; + screencapture("captxxxx.tga", keystatus[KEYSC_LSHIFT]|keystatus[KEYSC_RSHIFT]); + message("Saved screenshot %04d", capturecount-1); } } void faketimerhandler(void) { - int32_t i, dist; + int32_t i, dist, angdiff; int32_t hiz, hihit, loz, lohit, oposx, oposy; int16_t hitwall, daang; - counter++; - if (counter>=5) counter=0; +// counter++; +// if (counter>=5) counter=0; sampletimer(); if (totalclock < ototalclock+TICSPERFRAME || qsetmode != 200 || sidemode != 1) @@ -10613,39 +9536,39 @@ void faketimerhandler(void) oposy = pos.y; hitwall = clipmove(&pos,&cursectnum,xvel,yvel,128L,4L<<8,4L<<8,0); - xvel = ((pos.x-oposx)<<14); - yvel = ((pos.y-oposy)<<14); + xvel = (pos.x-oposx)<<14; + yvel = (pos.y-oposy)<<14; yvel += 80000; + if ((hitwall&0xc000) == 32768) { hitwall &= (MAXWALLS-1); i = wall[hitwall].point2; - daang = getangle(wall[i].x-wall[hitwall].x,wall[i].y-wall[hitwall].y); + daang = getangle(wall[i].x-wall[hitwall].x, wall[i].y-wall[hitwall].y); xvel -= (xvel>>4); - if (xvel < 0) xvel++; - if (xvel > 0) xvel--; + xvel -= ksgn(xvel); yvel -= (yvel>>4); - if (yvel < 0) yvel++; - if (yvel > 0) yvel--; + yvel -= ksgn(yvel); i = 4-keystatus[buildkeys[BK_RUN]]; - xvel += mulscale(vel,(int32_t)sintable[(ang+512)&2047],i); - yvel += mulscale(vel,(int32_t)sintable[ang&2047],i); + xvel += mulscale(vel, sintable[(ang+512)&2047], i); + yvel += mulscale(vel, sintable[ang&2047], i); - if (((daang-ang)&2047) < 1024) - ang = ((ang+((((daang-ang)&2047)+24)>>4))&2047); + angdiff = (daang-ang)&2047; + if (angdiff < 1024) + ang = (ang+((angdiff+24)>>4))&2047; else - ang = ((ang-((((ang-daang)&2047)+24)>>4))&2047); + ang = (ang-((angdiff+24)>>4))&2047; timoff = ototalclock; } else { if (ototalclock > timoff+32) - ang = ((ang+((timoff+32-ototalclock)>>4))&2047); + ang = (ang+((timoff+32-ototalclock)>>4))&2047; } getzrange(&pos,cursectnum,&hiz,&hihit,&loz,&lohit,128L,0); @@ -10653,15 +9576,18 @@ void faketimerhandler(void) oposx -= pos.x; oposy -= pos.y; - dist = ksqrt(oposx*oposx+oposy*oposy); - if (ototalclock > timoff+32) dist = 0; + dist = ksqrt(oposx*oposx + oposy*oposy); + if (ototalclock > timoff+32) + dist = 0; daang = mulscale(dist,angvel,9); pos.z += (daang<<6); - if (pos.z > loz-(4<<8)) pos.z = loz-(4<<8), hvel = 0; - if (pos.z < hiz+(4<<8)) pos.z = hiz+(4<<8), hvel = 0; + if (pos.z > loz-(4<<8)) + pos.z = loz-(4<<8), hvel = 0; + if (pos.z < hiz+(4<<8)) + pos.z = hiz+(4<<8), hvel = 0; - horiz = ((horiz*7+(100-(daang>>1)))>>3); + horiz = (horiz*7 + (100-(daang>>1)))>>3; if (horiz < 100) horiz++; if (horiz > 100) horiz--; } @@ -10696,50 +9622,29 @@ void SetGAMEPalette(void) setbrightness(brightness,GAMEpalette,0); } -static void SearchSectorsForward() +static void SearchSectors(int32_t dir) // <0: backwards, >=0: forwards { int32_t ii=0; - if (cursector_lotag!=0) - { - if (cursectornum Sector search: found"); - // cursectornum++; - keystatus[KEYSC_RBRACK]=0; // ] - return; - } - cursectornum++; - } - } - printmessage16("> Sector search: none found"); -} + dir = 1-2*(dir<0); -static void SearchSectorsBackward() -{ - int32_t ii=0; if (cursector_lotag!=0) { - if (cursectornum>0) cursectornum--; - for (ii=cursectornum; ii>=0; ii--) + if ((dir>0 && cursectornum=0)) + cursectornum += dir; + + for (ii=cursectornum; ii>=0 && ii"); return; } - cursectornum--; + cursectornum += dir; } } - printmessage16("< Sector search: none found"); + printmessage16("%s Sector search: none found", dir<0?"<":">"); } // Build edit originally by Ed Coolidge @@ -10750,23 +9655,9 @@ static void EditSectorData(int16_t sectnum) int32_t col=1, row=0, rowmax = 6, dispwidth = 24, editval = 0, i = -1; int32_t xpos = 208, ypos = ydim-STATUS2DSIZ+48; + drawgradient(); + disptext[dispwidth] = 0; - col = whitecol-21; - - begindrawing(); - for (i=ydim-STATUS2DSIZ+16; i to exit"); - if (keystatus[KEYSC_DOWN]) + if (PRESSED_KEYSC(DOWN)) { if (row < rowmax) { printext16(xpos,ypos+row*8,editorcolors[11],editorcolors[0],disptext,0); row++; } - keystatus[KEYSC_DOWN] = 0; } - if (keystatus[KEYSC_UP]) + if (PRESSED_KEYSC(UP)) { if (row > 0) { printext16(xpos,ypos+row*8,editorcolors[11],editorcolors[0],disptext,0); row--; } - keystatus[KEYSC_UP] = 0; } - if (keystatus[KEYSC_LEFT]) + if (PRESSED_KEYSC(LEFT)) { if (col == 2) { @@ -10810,9 +9697,8 @@ static void EditSectorData(int16_t sectnum) disptext[dispwidth] = 0; if (row > rowmax) row = rowmax; } - keystatus[KEYSC_LEFT] = 0; } - if (keystatus[KEYSC_RIGHT]) + if (PRESSED_KEYSC(RIGHT)) { if (col == 1) { @@ -10824,13 +9710,9 @@ static void EditSectorData(int16_t sectnum) disptext[dispwidth] = 0; if (row > rowmax) row = rowmax; } - keystatus[KEYSC_RIGHT] = 0; } - if (keystatus[KEYSC_ENTER]) - { - keystatus[KEYSC_ENTER] = 0; + if (PRESSED_KEYSC(ENTER)) editval = 1; - } if (col == 1) { @@ -11004,23 +9886,10 @@ static void EditWallData(int16_t wallnum) char edittext[80]; int32_t row=0, dispwidth = 24, editval = 0, i = -1; int32_t xpos = 208, ypos = ydim-STATUS2DSIZ+48; - int32_t col; + + drawgradient(); disptext[dispwidth] = 0; - col = whitecol-21; - - begindrawing(); - for (i=ydim-STATUS2DSIZ+16; i to exit"); - if (keystatus[KEYSC_DOWN]) + if (PRESSED_KEYSC(DOWN)) { if (row < 6) { printext16(xpos,ypos+row*8,editorcolors[11],editorcolors[0],disptext,0); row++; } - keystatus[KEYSC_DOWN] = 0; } - if (keystatus[KEYSC_UP]) + if (PRESSED_KEYSC(UP)) { if (row > 0) { printext16(xpos,ypos+row*8,editorcolors[11],editorcolors[0],disptext,0); row--; } - keystatus[KEYSC_UP] = 0; } - if (keystatus[KEYSC_ENTER]) - { - keystatus[KEYSC_ENTER] = 0; + if (PRESSED_KEYSC(ENTER)) editval = 1; - } + switch (row) { case 0: @@ -11154,26 +10017,11 @@ static void EditSpriteData(int16_t spritenum) int32_t col=0, row=0, rowmax=4, dispwidth = 24, editval = 0, i = -1; int32_t xpos = 8, ypos = ydim-STATUS2DSIZ+48; + drawgradient(); + disptext[dispwidth] = 0; // clearmidstatbar16(); - col = whitecol-21; - - begindrawing(); - for (i=ydim-STATUS2DSIZ+16; i to exit"); - if (keystatus[KEYSC_DOWN]) + if (PRESSED_KEYSC(DOWN)) { if (row < rowmax) { printext16(xpos,ypos+row*8,editorcolors[11],editorcolors[0],disptext,0); row++; } - keystatus[KEYSC_DOWN] = 0; } - if (keystatus[KEYSC_UP]) + if (PRESSED_KEYSC(UP)) { if (row > 0) { printext16(xpos,ypos+row*8,editorcolors[11],editorcolors[0],disptext,0); row--; } - keystatus[KEYSC_UP] = 0; } - if (keystatus[KEYSC_LEFT]) + if (PRESSED_KEYSC(LEFT)) { switch (col) { @@ -11231,9 +10077,8 @@ static void EditSpriteData(int16_t spritenum) } break; } - keystatus[KEYSC_LEFT] = 0; } - if (keystatus[KEYSC_RIGHT]) + if (PRESSED_KEYSC(RIGHT)) { switch (col) { @@ -11260,13 +10105,10 @@ static void EditSpriteData(int16_t spritenum) } break; } - keystatus[KEYSC_RIGHT] = 0; } - if (keystatus[KEYSC_ENTER]) - { - keystatus[KEYSC_ENTER] = 0; + if (PRESSED_KEYSC(ENTER)) editval = 1; - } + switch (col) { case 0: @@ -11491,7 +10333,7 @@ static void EditSpriteData(int16_t spritenum) if (editval) { printmessage16(edittext); - sprite[spritenum].extra = getnumber16(edittext,(int32_t)sprite[spritenum].extra,65536,1); + sprite[spritenum].extra = getnumber16(edittext,(int32_t)sprite[spritenum].extra,BTAG_MAX,1); } } break; @@ -11516,12 +10358,12 @@ static void EditSpriteData(int16_t spritenum) keystatus[KEYSC_ESC] = 0; } -static void GenSearchSprite() +static void GenericSpriteSearch() { char disptext[80]; char edittext[80]; static int32_t col=0, row=0; - int32_t i, j, k, color; + int32_t i, j, k; int32_t rowmax[3]={6,5,6}, dispwidth[3] = {24,24,28}; int32_t xpos[3] = {8,200,400}, ypos = ydim-STATUS2DSIZ+48; @@ -11543,13 +10385,19 @@ static void GenSearchSprite() { 8388608 , MAXPALOOKUPS, 65536 }, { MAXSECTORS-1, 128 , 65536 }, { MAXSTATUS-1 , 128 , MAXSPRITES-1 }, - { 65536 , MAXTILES , 256 }, - { 65536 , 0 , 65536 } + { BTAG_MAX , MAXTILES , 256 }, + { BTAG_MAX , 0 , BTAG_MAX } }; static char sign[7][3] = { - {1,0,1}, {1,1,1}, {1,0,1}, {0,0,1}, {0,1,0}, {0,0,0}, {0,0,1} + {1, 0, 1}, + {1, 1, 1}, + {1, 0, 1}, + {0, 0, 1}, + {0, 1, 0}, + {0, 0, 0}, + {0, 0, 1} }; static char firstrun=1; @@ -11562,16 +10410,7 @@ static void GenSearchSprite() clearmidstatbar16(); - color = whitecol-21; - begindrawing(); - for (i=ydim-STATUS2DSIZ+16; i to exit"); - if (keystatus[KEYSC_DOWN]) + if (PRESSED_KEYSC(DOWN)) { - keystatus[KEYSC_DOWN] = 0; if (row < rowmax[col]) { printext16(xpos[col],ypos+row*8,editorcolors[11],editorcolors[0],disptext,0); row++; } } - if (keystatus[KEYSC_UP]) + if (PRESSED_KEYSC(UP)) { - keystatus[KEYSC_UP] = 0; if (row > 0) { printext16(xpos[col],ypos+row*8,editorcolors[11],editorcolors[0],disptext,0); row--; } } - if (keystatus[KEYSC_LEFT]) + if (PRESSED_KEYSC(LEFT)) { - keystatus[KEYSC_LEFT] = 0; if (col > 0) { printext16(xpos[col],ypos+row*8,editorcolors[11],editorcolors[0],disptext,0); @@ -11632,9 +10468,8 @@ static void GenSearchSprite() if (row > rowmax[col]) row = rowmax[col]; } } - if (keystatus[KEYSC_RIGHT]) + if (PRESSED_KEYSC(RIGHT)) { - keystatus[KEYSC_RIGHT] = 0; if (col < 2) { printext16(xpos[col],ypos+row*8,editorcolors[11],editorcolors[0],disptext,0); @@ -11643,9 +10478,8 @@ static void GenSearchSprite() if (row > rowmax[col]) row = rowmax[col]; } } - if (keystatus[KEYSC_ENTER]) + if (PRESSED_KEYSC(ENTER)) { - keystatus[KEYSC_ENTER] = 0; Bsprintf(edittext, "%s: ", labels[row][col]); enddrawing(); printmessage16(edittext); @@ -11659,9 +10493,8 @@ static void GenSearchSprite() if (col == 1 && row == 5) // picnum printext16(xpos[1], ypos-2*8, editorcolors[14], editorcolors[0], names[i], 0); } - if (keystatus[KEYSC_BS] || keystatus[KEYSC_DELETE]) + if (PRESSED_KEYSC(BS) || PRESSED_KEYSC(DELETE)) { - keystatus[KEYSC_BS] = keystatus[KEYSC_DELETE] = 0; gs_spritewhat[col][row] = 0; if (col == 1 && row == 5) // picnum @@ -11695,7 +10528,7 @@ static void GenSearchSprite() // Build edit -static char *FuncMenuStrings[] = +static const char *FuncMenuStrings[] = { "Replace invalid tiles", "Delete all spr of tile #", @@ -11745,56 +10578,39 @@ static void FuncMenu(void) int32_t col=0, row=0, rowmax=7, dispwidth = 24, editval = 0, i = -1, j; int32_t xpos = 8, ypos = MENU_BASE_Y+16; + drawgradient(); + disptext[dispwidth] = 0; // clearmidstatbar16(); - col = whitecol-21; - - begindrawing(); - for (i=ydim-STATUS2DSIZ+16; i to exit"); - if (keystatus[KEYSC_DOWN]) + if (PRESSED_KEYSC(DOWN)) { if (row < rowmax) { printext16(xpos,ypos+row*MENU_Y_SPACING,editorcolors[11],editorcolors[0],disptext,0); row++; } - keystatus[KEYSC_DOWN] = 0; } - if (keystatus[KEYSC_UP]) + if (PRESSED_KEYSC(UP)) { if (row > 0) { printext16(xpos,ypos+row*MENU_Y_SPACING,editorcolors[11],editorcolors[0],disptext,0); row--; } - keystatus[KEYSC_UP] = 0; } #if 0 - if (keystatus[KEYSC_LEFT]) + if (PRESSED_KEYSC(LEFT)) { /* if (col == 2) { @@ -11817,10 +10633,9 @@ static void FuncMenu(void) disptext[dispwidth] = 0; if (row > rowmax) row = rowmax; } - keystatus[KEYSC_LEFT] = 0; } - if (keystatus[KEYSC_RIGHT]) + if (PRESSED_KEYSC(RIGHT)) { if (col == 0) { @@ -11842,14 +10657,11 @@ static void FuncMenu(void) disptext[dispwidth] = 0; if (row > rowmax) row = rowmax; } */ - keystatus[KEYSC_RIGHT] = 0; } #endif - if (keystatus[KEYSC_ENTER]) - { - keystatus[KEYSC_ENTER] = 0; + if (PRESSED_KEYSC(ENTER)) editval = 1; - } + switch (col) { case 0: @@ -12059,4 +10871,3 @@ static void FuncMenu(void) showframe(1); keystatus[KEYSC_ESC] = 0; } - diff --git a/polymer/eduke32/source/m32def.c b/polymer/eduke32/source/m32def.c index 66d12a776..509af7718 100644 --- a/polymer/eduke32/source/m32def.c +++ b/polymer/eduke32/source/m32def.c @@ -247,6 +247,8 @@ const char *keyw[] = "displayrand", + "itof", + "ftoi", "clamp", "inv", // inversion function.. not internal "sqrt", @@ -2555,6 +2557,21 @@ repeatcase: C_GetNextVarType(GAMEVAR_READONLY); break; +// *** float access: convert float to int and back + case CON_ITOF: + case CON_FTOI: + // syntax: itof <> SCALE + // ftoi <> SCALE + C_GetNextVarType(GAMEVAR_READONLY); + C_GetNextValue(LABEL_DEFINE); + + if (*(g_scriptPtr-1)<=0) + { + initprintf("%s:%d: error: scale value in integer/float conversion must be greater zero.\n",g_szScriptFileName,g_lineNumber); + g_numCompilerErrors++; + } + return 0; + // *** other math case CON_CLAMP: C_GetNextVarType(GAMEVAR_READONLY); diff --git a/polymer/eduke32/source/m32def.h b/polymer/eduke32/source/m32def.h index dd1647d76..9c711179d 100644 --- a/polymer/eduke32/source/m32def.h +++ b/polymer/eduke32/source/m32def.h @@ -313,6 +313,8 @@ enum ScriptKeywords_t CON_DISPLAYRAND, // other math + CON_ITOF, + CON_FTOI, CON_CLAMP, CON_INV, CON_SQRT, diff --git a/polymer/eduke32/source/m32exec.c b/polymer/eduke32/source/m32exec.c index 59c2bb247..2a6adf2c3 100644 --- a/polymer/eduke32/source/m32exec.c +++ b/polymer/eduke32/source/m32exec.c @@ -89,6 +89,7 @@ static int32_t dist(spritetype *s1,spritetype *s2) } /// +#if 0 void X_Disasm(ofstype beg, int32_t size) { instype *p; @@ -106,6 +107,7 @@ void X_Disasm(ofstype beg, int32_t size) } initprintf("\n"); } +#endif void VM_ScriptInfo(void) { @@ -828,6 +830,28 @@ skip_check: continue; // *** other math + case CON_FTOI: + insptr++; + { + int32_t bits=Gv_GetVarX(*insptr), scale=*(insptr+1); + double fval=(double)(*((float*)&bits)); + + Gv_SetVarX(*insptr, (int32_t)((fval/scale)*2e9)); + } + insptr += 2; + continue; + + case CON_ITOF: + insptr++; + { + int32_t scaled=Gv_GetVarX(*insptr), scale=*(insptr+1); + float fval = (float)((((double)scaled)*scale)/2e9); + + Gv_SetVarX(*insptr, *((int32_t *)&fval)); + } + insptr += 2; + continue; + case CON_CLAMP: insptr++; { diff --git a/polymer/eduke32/source/m32vars.c b/polymer/eduke32/source/m32vars.c index 9158ebf74..5cdc996cf 100644 --- a/polymer/eduke32/source/m32vars.c +++ b/polymer/eduke32/source/m32vars.c @@ -26,6 +26,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "m32def.h" #include "osd.h" #include "keys.h" +#ifdef POLYMER +#include "polymer.h" +#endif #define _m32vars_c_ #include "m32structures.c" @@ -159,7 +162,7 @@ int32_t Gv_NewVar(const char *pszLabel, intptr_t lValue, uint32_t dwFlags) if (i >= 0 && !(aGameVars[i].dwFlags & GAMEVAR_RESET)) { // found it... - if (aGameVars[i].dwFlags & (GAMEVAR_INTPTR|GAMEVAR_SHORTPTR|GAMEVAR_CHARPTR)) + if (aGameVars[i].dwFlags & (GAMEVAR_INTPTR|GAMEVAR_FLOATPTR|GAMEVAR_SHORTPTR|GAMEVAR_CHARPTR)) { C_ReportError(-1); initprintf("%s:%d: warning: cannot redefine internal gamevar `%s'.\n",g_szScriptFileName,g_lineNumber,label+(g_numLabels<<6)); @@ -232,12 +235,13 @@ int32_t __fastcall Gv_GetVarN(register int32_t id) // 'N' for "no side-effects" id &= (MAXGAMEVARS-1); switch (aGameVars[id].dwFlags & - (GAMEVAR_USER_MASK|GAMEVAR_INTPTR|GAMEVAR_SHORTPTR|GAMEVAR_CHARPTR)) + (GAMEVAR_USER_MASK|GAMEVAR_INTPTR|GAMEVAR_FLOATPTR|GAMEVAR_SHORTPTR|GAMEVAR_CHARPTR)) { case 0: return aGameVars[id].val.lValue; case GAMEVAR_PERBLOCK: return aGameVars[id].val.plValues[vm.g_st]; + case GAMEVAR_FLOATPTR: case GAMEVAR_INTPTR: return *((int32_t*)aGameVars[id].val.lValue); case GAMEVAR_SHORTPTR: @@ -354,12 +358,18 @@ int32_t __fastcall Gv_GetVarX(register int32_t id) } switch (aGameVars[id].dwFlags & - (GAMEVAR_USER_MASK|GAMEVAR_INTPTR|GAMEVAR_SHORTPTR|GAMEVAR_CHARPTR)) + (GAMEVAR_USER_MASK|GAMEVAR_INTPTR|GAMEVAR_FLOATPTR|GAMEVAR_SHORTPTR|GAMEVAR_CHARPTR)) { case 0: return ((aGameVars[id].val.lValue ^ -negateResult) + negateResult); case GAMEVAR_PERBLOCK: return ((aGameVars[id].val.plValues[vm.g_st] ^ -negateResult) + negateResult); + case GAMEVAR_FLOATPTR: + if (negateResult) + { + float fval = -(*(float*)aGameVars[id].val.lValue); + return *(int32_t *)&fval; + } case GAMEVAR_INTPTR: return ((*((int32_t*)aGameVars[id].val.lValue) ^ -negateResult) + negateResult); case GAMEVAR_SHORTPTR: @@ -457,7 +467,7 @@ void __fastcall Gv_SetVarX(register int32_t id, register int32_t lValue) } switch (aGameVars[id].dwFlags & - (GAMEVAR_USER_MASK|GAMEVAR_INTPTR|GAMEVAR_SHORTPTR|GAMEVAR_CHARPTR)) + (GAMEVAR_USER_MASK|GAMEVAR_INTPTR|GAMEVAR_FLOATPTR|GAMEVAR_SHORTPTR|GAMEVAR_CHARPTR)) { case 0: aGameVars[id].val.lValue=lValue; @@ -465,6 +475,17 @@ void __fastcall Gv_SetVarX(register int32_t id, register int32_t lValue) case GAMEVAR_PERBLOCK: aGameVars[id].val.plValues[vm.g_st] = lValue; return; + case GAMEVAR_FLOATPTR: + { + int32_t ival = lValue; + float fval = *(float *)&ival; + if (fval!=fval || fval<-3.3e38 || fval > 3.3e38) + { + OSD_Printf(CON_ERROR "Gv_SetVarX(): tried to set float var to NaN or infinity\n",g_errorLineNum,keyw[g_tw]); + vm.flags |= VMFLAG_ERROR; + return; + } + } case GAMEVAR_INTPTR: *((int32_t*)aGameVars[id].val.lValue)=(int32_t)lValue; return; @@ -604,6 +625,15 @@ static void Gv_AddSystemVars(void) Gv_NewVar("SV2",(intptr_t)&m32_sortvar2, GAMEVAR_INTPTR | GAMEVAR_SYSTEM | GAMEVAR_READONLY); Gv_NewVar("spritesortcnt",(intptr_t)&spritesortcnt, GAMEVAR_INTPTR | GAMEVAR_SYSTEM | GAMEVAR_READONLY); +#ifdef POLYMER + Gv_NewVar("pr_overrideparallax",(intptr_t)&pr_overrideparallax, GAMEVAR_INTPTR | GAMEVAR_SYSTEM); + Gv_NewVar("pr_parallaxscale",(intptr_t)&pr_parallaxscale, GAMEVAR_FLOATPTR | GAMEVAR_SYSTEM); + Gv_NewVar("pr_parallaxbias",(intptr_t)&pr_parallaxbias, GAMEVAR_FLOATPTR | GAMEVAR_SYSTEM); + Gv_NewVar("pr_overridespecular",(intptr_t)&pr_overridespecular, GAMEVAR_INTPTR | GAMEVAR_SYSTEM); + Gv_NewVar("pr_specularpower",(intptr_t)&pr_specularpower, GAMEVAR_FLOATPTR | GAMEVAR_SYSTEM); + Gv_NewVar("pr_specularfactor",(intptr_t)&pr_specularfactor, GAMEVAR_FLOATPTR | GAMEVAR_SYSTEM); +#endif + g_systemVarCount = g_gameVarCount; diff --git a/polymer/eduke32/source/mapster32.h b/polymer/eduke32/source/mapster32.h index 510c06ce1..b15d66cb2 100644 --- a/polymer/eduke32/source/mapster32.h +++ b/polymer/eduke32/source/mapster32.h @@ -51,8 +51,8 @@ extern int16_t searchbottomwall; static int32_t ototalclock = 0; #define NUMOPTIONS 9 - char option[NUMOPTIONS] = {0,0,0,0,0,0,1,0,0}; + uint8_t keys[NUMBUILDKEYS] = { 0xc8,0xd0,0xcb,0xcd,0x2a,0x9d,0x1d,0x39, @@ -72,35 +72,38 @@ extern int32_t lastpm16time, synctics; extern int32_t halfxdim16, midydim16, zoom; extern void fixrepeats(int16_t i); -char autospritehelp=0,autosecthelp=0; -int16_t MinRate=24, MinD=3; -int32_t xoldtimerhandler, lastmessagetime=-1; +static char autospritehelp=0,autosecthelp=0; +//int16_t MinRate=24, MinD=3; +//int32_t xoldtimerhandler; +static int32_t lastmessagetime=-1; -char tempbuf[1024]; //1024 -int32_t numsprite[MAXSPRITES]; -int32_t multisprite[MAXSPRITES]; -char lo[64]; -char levelname[255]; -int16_t curwall=0,curwallnum=0; -int16_t cursearchsprite=0,cursearchspritenum=0,cursector_lotag=0,cursectornum=0; -int16_t search_lotag=0,search_hitag=0; -char wallsprite=0; -char helpon=0; +static char tempbuf[1024]; +static int32_t numsprite[MAXSPRITES], multisprite[MAXSPRITES]; +static char lo[64]; +static char levelname[255]; +static int16_t curwall=0, curwallnum=0; +static int16_t /*cursearchsprite=0,*/ cursearchspritenum=0, cursector_lotag=0, cursectornum=0; +static int16_t search_lotag=0,search_hitag=0; +static char wallsprite=0; +static char helpon=0; //static char onwater=0; -uint8_t onnames=4, usedcount=1; -int16_t cursprite; -int32_t mousxplc, mousyplc, ppointhighlight; -int32_t counter=0; -uint8_t nosprites=0,purpleon=0,skill=4; -uint8_t framerateon=1,shadepreview=0,sidemode=0; -int32_t autosave=180; -extern int32_t vel, svel, hvel, angvel; -int32_t xvel, yvel, timoff; +static uint8_t onnames=4, usedcount=1; +static int16_t cursprite; +int32_t mousxplc, mousyplc; +static int32_t ppointhighlight; +//static int32_t counter=0; +static uint8_t nosprites=0,purpleon=0,skill=4; +static uint8_t framerateon=1,shadepreview=0,sidemode=0; +static int32_t xvel, yvel, timoff; -static void SearchSectorsForward(); -static void SearchSectorsBackward(); +int32_t autosave=180; +static int32_t autosavetimer; + +extern int32_t vel, svel, hvel, angvel; + +static void SearchSectors(int32_t dir); static inline void SpriteName(int16_t spritenum, char *lo2); -static void PrintStatus(char *string,int32_t num,char x,char y,char color); +static void PrintStatus(const char *string,int32_t num,char x,char y,char color); void SetBOSS1Palette(); void SetSLIMEPalette(); void SetWATERPalette(); @@ -113,32 +116,33 @@ static void EditWallData(int16_t wallnum); static void EditSectorData(int16_t sectnum); static void FuncMenu(void); -uint8_t GAMEpalette[768], WATERpalette[768], SLIMEpalette[768], TITLEpalette[768]; -uint8_t REALMSpalette[768], BOSS1palette[768]; +static uint8_t GAMEpalette[768], WATERpalette[768], SLIMEpalette[768], TITLEpalette[768]; +static uint8_t REALMSpalette[768], BOSS1palette[768]; -char num_tables; +static char num_tables; + +static int32_t updownunits=1024; -int32_t updownunits=1024; extern int16_t highlightsector[MAXSECTORS], highlightsectorcnt; extern int16_t highlight[MAXWALLS]; extern int16_t pointhighlight, linehighlight, highlightcnt; extern int16_t asksave; -char getmessage[162], getmessageleng; -int32_t getmessagetimeoff, charsperline; +static char getmessage[162], getmessageleng; +static int32_t getmessagetimeoff; //, charsperline; + extern int32_t startposx, startposy, startposz; extern int16_t startang, startsectnum; -int32_t autosavetimer; extern int32_t numsprites; extern int32_t showfirstwall; extern char spritecol2d[MAXTILES][2]; extern char custom2dcolors; -int32_t intro=0; +//int32_t intro=0; extern int32_t ydim16, halfxdim16, midydim16, zoom; extern intptr_t frameplace; -extern char pow2char[8]; +//extern char pow2char[8]; static int32_t acurpalette=0; @@ -149,48 +153,45 @@ extern int32_t checksectorpointer(int16_t i, int16_t sectnum); extern double msens; -void ContextHelp(int16_t spritenum); -void ResetKeys(); +//void ContextHelp(int16_t spritenum); +//void ResetKeys(); extern void fixspritesectors(void); - #define KEY_PRESSED(sc) KB_KeyPressed((sc)) +//#define KEY_PRESSED(sc) KB_KeyPressed((sc)) // This table defines the various zoom levels, the numbers being the pixel width // and height of the sprite when plotted on the screen. Probably zooms in too far // for some, but I'm a blind old git :-( #define FUCKING_GOOD_EYESIGHT 16 - static const int32_t ZoomToThumbSize[] = { FUCKING_GOOD_EYESIGHT, 32, 64, 128, 192, 256, 384, 512 -} ; +}; #define NUM_ZOOMS (sizeof(ZoomToThumbSize)/sizeof(ZoomToThumbSize[0])) - #define INITIAL_ZOOM 2 typedef struct { - int32_t *pIds ; // ptr to list of tile Ids - int32_t nIds ; // num of tile ids - char *szText ; // description to present to user. - char key1 ; // key1 and key2 are two alternative keypresses used to - char key2 ; // select tile set. Bodge to do eary upper/lower case handling - char color1; // 2d sprite color 1 - char color2; // 2d sprite color 2 + int32_t *pIds; // ptr to list of tile Ids + int32_t nIds; // num of tile ids + char *szText; // description to present to user. + char key1; // key1 and key2 are two alternative keypresses used to + char key2; // select tile set. Bodge to do eary upper/lower case handling + char color1; // 2d sprite color 1 + char color2; // 2d sprite color 2 } TileGroup; #define MAX_TILE_GROUPS 32 #define MAX_TILE_GROUP_ENTRIES 1024 -TileGroup s_TileGroups[MAX_TILE_GROUPS]; - -int32_t tilegroupItems; -int32_t tilegroupActors; - +static TileGroup s_TileGroups[MAX_TILE_GROUPS]; +static int32_t tilegroupItems; +static int32_t tilegroupActors; static uint32_t tile_groups = 0; + #define NUMPRINTABLES 94 #define MAX_ALPHABETS 32 // alphabet definitions struct for the sprite text renderer @@ -201,7 +202,7 @@ typedef struct int8_t yofs[NUMPRINTABLES]; } alphabet_t; -alphabet_t alphabets[MAX_ALPHABETS]; +static alphabet_t alphabets[MAX_ALPHABETS]; static int32_t numalphabets = 0; #define FIRST_USER_ART_TILE 3584 @@ -216,8 +217,8 @@ extern int16_t localartlookup[MAXTILES], localartlookupnum; extern int32_t lockclock; extern void clearkeys(void); -int32_t gs_sprite[3][7]; -char gs_spritewhat[3][7]; -int16_t gs_cursprite=-1; +static int32_t gs_sprite[3][7]; +static char gs_spritewhat[3][7]; +static int16_t gs_cursprite=-1; int32_t g_musicSize=0; diff --git a/polymer/eduke32/source/old.diff b/polymer/eduke32/source/old.diff new file mode 100644 index 000000000..6cfa24d39 --- /dev/null +++ b/polymer/eduke32/source/old.diff @@ -0,0 +1,177 @@ +// All things old go here to keep the sources clean. To have a reference to the place +// in the code, place a marker like __SomeMarker__ in the source file, and refer to it +// by placing it as the first context line of the corresponding hunk. + +Index: astub.c +============================== ++++ astub.c +--- astub.c +@@ -2118,1 +2118,37 @@ + ///__ShowHelpText__ ++#if 0 ++static void ShowHelpText(char *name) ++{ ++ BFILE *fp; ++ char x=0,y=4; ++ UNREFERENCED_PARAMETER(name); ++ if ((fp=fopenfrompath("helpdoc.txt","rb")) == NULL) ++ { ++ begindrawing(); ++ printext256(1*4,4*8,whitecol,-1,"ERROR: file not found.",0); ++ enddrawing(); ++ return; ++ } ++ /* ++ Bfgets(tempbuf,80,fp); ++ while(!Bfeof(fp) && Bstrcmp(tempbuf,"SectorEffector")) ++ { ++ Bfgets(tempbuf,80,fp); ++ } ++ */ ++ y=2; ++ Bfgets(tempbuf,80,fp); ++ Bstrcat(tempbuf,"\n"); ++ begindrawing(); ++ while (!Bfeof(fp) && !(Bstrcmp(tempbuf,"SectorEffector")==0)) ++ { ++ Bfgets(tempbuf,80,fp); ++ Bstrcat(tempbuf,"\n"); ++ printext256(x*4,(y*6)+2,whitecol,-1,tempbuf,1); ++ y++; ++ } ++ enddrawing(); ++ ++ Bfclose(fp); ++}// end ShowHelpText ++#endif +@@ -6777,1 +6777,34 @@ + ///__bigcomment__ ++ /* ++ if ((totalclock > getmessagetimeoff) && (totalclock > (lastpm16time + 120*3))) ++ { ++ if (pointhighlight >= 16384) ++ { ++ char tmpbuf[2048]; ++ i = pointhighlight-16384; ++ if (strlen(names[sprite[i].picnum]) > 0) ++ { ++ if (sprite[i].picnum==SECTOREFFECTOR) ++ Bsprintf(tmpbuf,"Sprite %d %s, hi:%d ex:%d",i,SectorEffectorText(i),sprite[i].hitag,sprite[i].extra); ++ else Bsprintf(tmpbuf,"Sprite %d %s: lo:%d hi:%d ex:%d",i,names[sprite[i].picnum],sprite[i].lotag,sprite[i].hitag,sprite[i].extra); ++ } ++ else Bsprintf(tmpbuf,"Sprite %d picnum %d: lo:%d hi:%d ex:%d",i,sprite[i].picnum,sprite[i].lotag,sprite[i].hitag,sprite[i].extra); ++ _printmessage16(tmpbuf); ++ } ++ else if ((linehighlight >= 0) && (sectorofwall(linehighlight) == cursectornum)) ++ { ++ int32_t dax, day, dist; ++ dax = wall[linehighlight].x-wall[wall[linehighlight].point2].x; ++ day = wall[linehighlight].y-wall[wall[linehighlight].point2].y; ++ dist = ksqrt(dax*dax+day*day); ++ Bsprintf(tempbuf,"Wall %d: length:%d lo:%d hi:%d ex:%d",linehighlight,dist,wall[linehighlight].lotag,wall[linehighlight].hitag,wall[linehighlight].extra); ++ _printmessage16(tempbuf); ++ } ++ else if (cursectornum >= 0) ++ { ++ Bsprintf(tempbuf,"Sector %d: lo:%d hi:%d ex:%d",cursectornum,sector[cursectornum].lotag,sector[cursectornum].hitag,sector[cursectornum].extra); ++ _printmessage16(tempbuf); ++ } ++ else _printmessage16(""); ++ } ++ */ +@@ -6723,1 +6723,29 @@ + ///__old_sprite_search_1__ ++#if 0 ++ { ++ if (cursearchspritenum>0) cursearchspritenum--; ++ for (i=cursearchspritenum; i>=0; i--) ++ { ++ ++ if ( ++ (sprite[i].picnum==sprite[cursearchsprite].picnum && ++ sprite[i].statnum==0) ++ &&((search_lotag==0)|| ++ (search_lotag!=0 && search_lotag==sprite[i].lotag)) ++ &&((search_hitag==0)|| ++ (search_hitag!=0 && search_hitag==sprite[i].hitag)) ++ ) ++ { ++ pos.x=sprite[i].x; ++ pos.y=sprite[i].y; ++ ang= sprite[i].ang; ++ printmessage16("< Sprite search: found"); ++ // curspritenum--; ++ keystatus[KEYSC_LBRACK]=0; ++ return; ++ } ++ cursearchspritenum--; ++ } ++ printmessage16("< Sprite search: none found"); ++ } ++#endif +@@ -6757,1 +6757,27 @@ + ///__old_sprite_search_2__ ++#if 0 ++ { ++ if (cursearchspritenum Sprite search: found"); ++ // curspritenum++; ++ keystatus[KEYSC_RBRACK]=0; ++ return; ++ } ++ cursearchspritenum++; ++ } ++ printmessage16("> Sprite search: none found"); ++ } ++#endif +@@ -6840,1 +6840,37 @@ + ///__motorcycle__ ++ /* ++ if (keystatus[KEYSC_QUOTE] && PRESSED_KEYSC(5)) // ' 5 ++ { ++ sprintf(tempbuf,"Power-Up Ammo now equals Normal"); ++ printmessage16(tempbuf); ++ for(i=0;i=20 && sprite[i].picnum<=59) ++ { ++ sprite[i].xrepeat = 32; ++ sprite[i].yrepeat = 32; ++ } ++ } ++ ++ } ++ */ ++ ++ // What the fuck is this supposed to do? ++ ++ /* Motorcycle ha ha ha ++ if (keystatus[KEYSC_QUOTE] && PRESSED_KEYSC(5)) // ' 5 ++ { ++ sidemode++; if (sidemode > 2) sidemode = 0; ++ if (sidemode == 1) ++ { ++ editstatus = 0; ++ zmode = 2; ++ pos.z = ((sector[cursectnum].ceilingz+sector[cursectnum].floorz)>>1); ++ } ++ else ++ { ++ editstatus = 1; ++ zmode = 1; ++ } ++ } ++ */