diff --git a/polymer/eduke32/build/include/baselayer.h b/polymer/eduke32/build/include/baselayer.h index 488aaced0..1c8e325a0 100644 --- a/polymer/eduke32/build/include/baselayer.h +++ b/polymer/eduke32/build/include/baselayer.h @@ -101,6 +101,7 @@ void initprintf(const char *, ...); void debugprintf(const char *,...); int32_t handleevents(void); +extern void (*after_handleevents_hook)(void); extern inline void idle(void); extern inline void idle_waitevent(void); extern inline void idle_waitevent_timeout(uint32_t timeout); diff --git a/polymer/eduke32/build/include/build.h b/polymer/eduke32/build/include/build.h index 0b483fafb..f7552dc34 100644 --- a/polymer/eduke32/build/include/build.h +++ b/polymer/eduke32/build/include/build.h @@ -488,6 +488,7 @@ int32_t hitscan(const vec3_t *sv, int16_t sectnum, int32_t vx, int32_t vy, int int32_t neartag(int32_t xs, int32_t ys, int32_t zs, int16_t sectnum, int16_t ange, int16_t *neartagsector, int16_t *neartagwall, int16_t *neartagsprite, int32_t *neartaghitdist, int32_t neartagrange, char tagsearch); int32_t cansee(int32_t x1, int32_t y1, int32_t z1, int16_t sect1, int32_t x2, int32_t y2, int32_t z2, int16_t sect2); void updatesector(int32_t x, int32_t y, int16_t *sectnum); +void updatesectorexclude(int32_t x, int32_t y, int16_t *sectnum, const uint8_t *excludesectbitmap); void updatesectorz(int32_t x, int32_t y, int32_t z, int16_t *sectnum); int32_t inside(int32_t x, int32_t y, int16_t sectnum); void dragpoint(int16_t pointhighlight, int32_t dax, int32_t day); @@ -584,10 +585,10 @@ void qsetmode640350(void); void qsetmode640480(void); void qsetmodeany(int32_t,int32_t); void clear2dscreen(void); -void draw2dgrid(int32_t posxe, int32_t posye, int16_t ange, int32_t zoome, int16_t gride); -void draw2dscreen(int32_t posxe, int32_t posye, int16_t ange, int32_t zoome, int16_t gride); -void drawline16(int32_t x1, int32_t y1, int32_t x2, int32_t y2, char col); -void drawcircle16(int32_t x1, int32_t y1, int32_t r, char col); +void draw2dgrid(int32_t posxe, int32_t posye, int32_t posze, int16_t ange, int32_t zoome, int16_t gride); +void draw2dscreen(const vec3_t *pos, int16_t ange, int32_t zoome, int16_t gride); +int32_t drawline16(int32_t x1, int32_t y1, int32_t x2, int32_t y2, char col); +void drawcircle16(int32_t x1, int32_t y1, int32_t r, int32_t eccen, char col); int32_t setrendermode(int32_t renderer); int32_t getrendermode(void); diff --git a/polymer/eduke32/build/include/editor.h b/polymer/eduke32/build/include/editor.h index 4d1db0089..8610b4183 100644 --- a/polymer/eduke32/build/include/editor.h +++ b/polymer/eduke32/build/include/editor.h @@ -67,6 +67,20 @@ extern int32_t m32_osd_tryscript; extern int32_t showheightindicators; extern int32_t showambiencesounds; +// editor side view +extern int32_t m32_sideview; +extern int32_t m32_sideelev; +extern int16_t m32_sideang; +extern int32_t m32_sidecos, m32_sidesin; +extern int32_t m32_swcnt; +extern int16_t *m32_wallsprite; +extern int8_t sideview_reversehrot; +extern inline int32_t scalescreeny(int32_t sy); +extern void screencoords(int32_t *xres, int32_t *yres, int32_t x, int32_t y, int32_t zoome); +extern inline int32_t getscreenvdisp(int32_t bz, int32_t zoome); +extern void setup_sideview_sincos(void); +extern void m32_setkeyfilter(int32_t on); + extern int32_t ExtInit(void); extern int32_t ExtPreInit(int32_t argc,const char **argv); extern void ExtUnInit(void); diff --git a/polymer/eduke32/build/src/baselayer.c b/polymer/eduke32/build/src/baselayer.c index ff73e8bb8..b40ad94a6 100644 --- a/polymer/eduke32/build/src/baselayer.c +++ b/polymer/eduke32/build/src/baselayer.c @@ -24,6 +24,7 @@ int32_t joyaxespresent=0; void(*keypresscallback)(int32_t,int32_t) = 0; void(*mousepresscallback)(int32_t,int32_t) = 0; void(*joypresscallback)(int32_t,int32_t) = 0; +void (*after_handleevents_hook)(void) = 0; extern int16_t brightness; diff --git a/polymer/eduke32/build/src/build.c b/polymer/eduke32/build/src/build.c index ff5cff1b6..b89e16df1 100644 --- a/polymer/eduke32/build/src/build.c +++ b/polymer/eduke32/build/src/build.c @@ -155,6 +155,17 @@ static int32_t mousx, mousy; int16_t prefixtiles[16] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; uint8_t hlsectorbitmap[MAXSECTORS>>3]; // show2dsector is already taken... +typedef struct +{ + int16_t numsectors, numwalls, numsprites; + sectortype *sector; + walltype *wall; + spritetype *sprite; +} mapinfofull_t; + +static int32_t backup_highlighted_map(mapinfofull_t *mapinfo); +static int32_t restore_highlighted_map(mapinfofull_t *mapinfo); + /* static char scantoasc[128] = { @@ -190,8 +201,12 @@ int32_t pk_turnaccel=16; int32_t pk_turndecel=12; int32_t pk_uedaccel=3; +int8_t sideview_reversehrot = 0; + char lastpm16buf[156]; +static int32_t checksectorpointer_warn = 0; + char changechar(char dachar, int32_t dadir, char smooshyalign, char boundcheck); static int32_t adjustmark(int32_t *xplc, int32_t *yplc, int16_t danumwalls); static void locktogrid(int32_t *dax, int32_t *day); @@ -208,7 +223,7 @@ 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); -void copysector(int16_t soursector, int16_t destsector, int16_t deststartwall, char copystat); +static void copysector(int16_t soursector, int16_t destsector, int16_t deststartwall, char copystat, const int16_t *oldtonewsect); int32_t drawtilescreen(int32_t pictopleft, int32_t picbox); void overheadeditor(void); static int32_t getlinehighlight(int32_t xplc, int32_t yplc, int32_t line); @@ -1260,6 +1275,163 @@ char changechar(char dachar, int32_t dadir, char smooshyalign, char boundcheck) ////////////////////// OVERHEADEDITOR ////////////////////// +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); +} + +// backup highlighted sectors with sprites as mapinfo for later restoration +// return values: +// -1: highlightsectorcnt<=0 +// -2: out of mem +// 0: ok +static int32_t backup_highlighted_map(mapinfofull_t *mapinfo) +{ + int32_t i, j, k, m, tmpnumwalls=0, tmpnumsprites=0; + + if (highlightsectorcnt <= 0) + return -1; + + // count walls & sprites + for (i=0; isector = Bmalloc(highlightsectorcnt * sizeof(sectortype)); + if (!mapinfo->sector) return -2; + mapinfo->wall = Bmalloc(tmpnumwalls * sizeof(walltype)); + if (!mapinfo->wall) { Bfree(mapinfo->sector); return -2; } + if (tmpnumsprites>0) + { + mapinfo->sprite = Bmalloc(tmpnumsprites * sizeof(spritetype)); + if (!mapinfo->sprite) + { + Bfree(mapinfo->sector); + Bfree(mapinfo->wall); + return -2; + } + } + + + // copy everything over + tmpnumwalls = 0; + tmpnumsprites = 0; + for (i=0; isector[i], §or[k], sizeof(sectortype)); + mapinfo->sector[i].wallptr = tmpnumwalls; + + for (j=0; jwall[tmpnumwalls+j], &wall[sector[k].wallptr+j], sizeof(walltype)); + mapinfo->wall[tmpnumwalls+j].point2 += (tmpnumwalls-sector[k].wallptr); + mapinfo->wall[tmpnumwalls+j].nextsector = -1; + mapinfo->wall[tmpnumwalls+j].nextwall = -1; + } + tmpnumwalls += j; + + m = headspritesect[highlightsector[i]]; + while (m != -1) + { + Bmemcpy(&mapinfo->sprite[tmpnumsprites], &sprite[m], sizeof(spritetype)); + mapinfo->sprite[tmpnumsprites].sectnum = i; + m = nextspritesect[m]; + tmpnumsprites++; + } + } + + + mapinfo->numsectors = highlightsectorcnt; + mapinfo->numwalls = tmpnumwalls; + mapinfo->numsprites = tmpnumsprites; + + return 0; +} + +static void mapinfofull_free(mapinfofull_t *mapinfo) +{ + Bfree(mapinfo->sector); + Bfree(mapinfo->wall); + if (mapinfo->numsprites>0) + Bfree(mapinfo->sprite); +} + +// restore map saved with backup_highlighted_map, also +// frees mapinfo's sector, wall, (sprite) in any case. +// return values: +// -1: limits exceeded +// 0: ok +static int32_t restore_highlighted_map(mapinfofull_t *mapinfo) +{ + int32_t i, j, sect, onumsectors=numsectors, newnumsectors, newnumwalls; + + updatenumsprites(); + if (numsectors+mapinfo->numsectors>MAXSECTORS || numwalls+mapinfo->numwalls>MAXWALLS + || numsprites+mapinfo->numsprites>MAXSPRITES) + { + mapinfofull_free(mapinfo); + return -1; + } + + newnumsectors = numsectors + mapinfo->numsectors; + newnumwalls = numwalls + mapinfo->numwalls; + + // copy sectors & walls + Bmemcpy(§or[numsectors], mapinfo->sector, mapinfo->numsectors*sizeof(sectortype)); + Bmemcpy(&wall[numwalls], mapinfo->wall, mapinfo->numwalls*sizeof(walltype)); + + // tweak index members + for (i=numsectors; i>3] |= (1<<(i&7)); + } + for (i=numwalls; inumsprites; i++) + { + sect = onumsectors+mapinfo->sprite[i].sectnum; + j = insertsprite(sect, mapinfo->sprite[i].statnum); + Bmemcpy(&sprite[j], &mapinfo->sprite[i], sizeof(spritetype)); + sprite[j].sectnum = sect; + } + + numwalls = newnumwalls; + updatenumsprites(); + + update_highlightsector(); + + mapinfofull_free(mapinfo); + return 0; +} + + static int32_t newnumwalls=-1; static void ovh_whiteoutgrab() @@ -1276,10 +1448,12 @@ static void ovh_whiteoutgrab() { if (wall[j].nextwall >= 0) { - for (k=highlightsectorcnt-1; k>=0; k--) - if (highlightsector[k] == wall[j].nextsector) - break; - if (k < 0) +// for (k=highlightsectorcnt-1; k>=0; k--) +// if (highlightsector[k] == wall[j].nextsector) +// break; + k = wall[j].nextsector; + if ((hlsectorbitmap[k>>3]&(1<<(k&7)))==0) +// if (k < 0) { NEXTWALL(j).nextwall = -1; NEXTWALL(j).nextsector = -1; @@ -1291,29 +1465,40 @@ static void ovh_whiteoutgrab() } } -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); -} - static void duplicate_selected_sectors() { int32_t i, j, startwall, endwall, newnumsectors, newwalls = 0; + int32_t minx=INT_MAX, maxx=INT_MIN, miny=INT_MAX, maxy=INT_MIN, dx, dy; for (i=0; i= 0) checksectorpointer(wall[j].nextwall,wall[j].nextsector); checksectorpointer(j, highlightsector[i]); + + minx = min(minx, wall[j].x); + maxx = max(maxx, wall[j].x); + miny = min(miny, wall[j].y); + maxy = max(maxy, wall[j].y); } // Then, highlight the ones just copied. @@ -1334,6 +1524,29 @@ static void duplicate_selected_sectors() hlsectorbitmap[j>>3] |= (1<<(j&7)); } + // displace walls of new sectors by a small amount + dx = 512; //((maxx-minx)+255)&~255; + dy = -256; //((maxy-miny)+255)&~255; + if (maxx+dx >= editorgridextent) dx*=-1; + if (minx+dx <= -editorgridextent) dx*=-1; + if (maxy+dy >= editorgridextent) dy*=-1; + if (miny+dy <= -editorgridextent) dy*=-1; + + for (i=numsectors; i=0; j=nextspritesect[j]) + { + sprite[j].x += dx; + sprite[j].y += dy; + } + } + numsectors = newnumsectors; numwalls = newnumwalls; @@ -1354,9 +1567,12 @@ static void duplicate_selected_sectors() static void duplicate_selected_sprites() { - int32_t i, j, k; + int32_t i, j, k=0; - if (highlightcnt + numsprites <= MAXSPRITES) + for (i=0; i>1) == 0) { if (!((vel|angvel|svel) //DOWN_BK(MOVEFORWARD) || DOWN_BK(MOVEBACKWARD) || DOWN_BK(TURNLEFT) || DOWN_BK(TURNRIGHT) - || DOWN_BK(MOVEUP) || DOWN_BK(MOVEDOWN) + || DOWN_BK(MOVEUP) || DOWN_BK(MOVEDOWN) || keystatus[0x10] || keystatus[0x11] || keystatus[0x48] || keystatus[0x4b] || keystatus[0x4d] || keystatus[0x50] // keypad keys || bstatus || OSD_IsMoving())) { if (totalclock > waitdelay) { + uint32_t ms = (highlightsectorcnt>0) ? 75 : 200; // wait for event, timeout after 200 ms - (last loop time) - idle_waitevent_timeout(200 - min(getticks()-lasttick, 200)); + idle_waitevent_timeout(ms - min(getticks()-lasttick, ms)); // have synctics reset to 0 after we've slept to avoid zooming out to the max instantly resetsynctics = 1; } @@ -1602,14 +1869,16 @@ void overheadeditor(void) if (numwalls < 0) numwalls = tempint; if ((getticks() - lastdraw) >= 5 || (vel|angvel|svel) || DOWN_BK(MOVEUP) || DOWN_BK(MOVEDOWN) - || mousx || mousy || bstatus + || mousx || mousy || bstatus || keystatus[0x10] || keystatus[0x11] || newnumwalls>=0 || OSD_IsMoving()) { lastdraw = getticks(); clear2dscreen(); - if (graphicsmode) + setup_sideview_sincos(); + + if (graphicsmode && !m32_sideview) { Bmemset(show2dsector, 255, sizeof(show2dsector)); setview(0, 0, xdim-1, ydim16-1); @@ -1620,30 +1889,36 @@ void overheadeditor(void) drawmapview(pos.x, pos.y, zoom, 1536); } - draw2dgrid(pos.x,pos.y,ang,zoom,grid); + draw2dgrid(pos.x,pos.y,pos.z,ang,zoom,grid); ExtPreCheckKeys(); { int32_t cx, cy; - x2 = mulscale14(startposx-pos.x,zoom); //Draw brown arrow (start) - y2 = mulscale14(startposy-pos.y,zoom); + // Draw brown arrow (start) + screencoords(&x2, &y2, startposx-pos.x,startposy-pos.y, zoom); + if (m32_sideview) + y2 += getscreenvdisp(startposz-pos.z, 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; + int16_t angofs = m32_sideview ? m32_sideang : 0; + x1 = mulscale11(sintable[(startang+angofs+2560)&2047],zoom) / 768; + y1 = mulscale11(sintable[(startang+angofs+2048)&2047],zoom) / 768; + i = scalescreeny(x1); + j = scalescreeny(y1); 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]); + drawline16base(cx,cy, x1,j, -x1,-j, editorcolors[2]); + drawline16base(cx,cy, x1,j, +y1,-i, editorcolors[2]); + drawline16base(cx,cy, x1,j, -y1,+i, editorcolors[2]); enddrawing(); //}}} } } - draw2dscreen(pos.x,pos.y,ang,zoom,grid); + draw2dscreen(&pos,ang,zoom,grid); VM_OnEvent(EVENT_DRAW2DSCREEN, -1); begindrawing(); //{{{ @@ -1656,6 +1931,8 @@ void overheadeditor(void) dabuffer = (char *)ExtGetSectorCaption(i); if (dabuffer[0] != 0) { + int32_t vdisp; + dax = 0; //Get average point of sector day = 0; startwall = sector[i].wallptr; @@ -1671,8 +1948,11 @@ void overheadeditor(void) day /= (endwall-startwall+1); } - dax = mulscale14(dax-pos.x,zoom); - day = mulscale14(day-pos.y,zoom); + if (m32_sideview) + vdisp = getscreenvdisp(getflorzofslope(i,dax,day)-pos.z, zoom); + screencoords(&dax,&day, dax-pos.x,day-pos.y, zoom); + if (m32_sideview) + day += vdisp; x1 = halfxdim16+dax-(Bstrlen(dabuffer)<<1); y1 = midydim16+day-4; @@ -1717,8 +1997,10 @@ void overheadeditor(void) dabuffer = (char *)ExtGetWallCaption(i); if (dabuffer[0] != 0) { - dax = mulscale14(dax-pos.x,zoom); - day = mulscale14(day-pos.y,zoom); + screencoords(&dax,&day, dax-pos.x,day-pos.y, zoom); + if (m32_sideview) + day += getscreenvdisp(getflorzofslope(sectorofwall(i), dax,day)-pos.z, zoom); + x1 = halfxdim16+dax-(Bstrlen(dabuffer)<<1); y1 = midydim16+day-4; x2 = x1 + (Bstrlen(dabuffer)<<2)+2; @@ -1738,10 +2020,18 @@ void overheadeditor(void) } } - i = 0; j = numsprites; + i = 0; j = numsprites; k=0; if (zoom >= 768) - while (j > 0 && i < MAXSPRITES) + while (j > 0 && i < MAXSPRITES && (!m32_sideview || k 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]; - } + int32_t blocking = (sprite[i].cstat&1); + + col = 3 + 2*blocking; + if (spritecol2d[sprite[i].picnum][blocking]) + col = spritecol2d[sprite[i].picnum][blocking]; if ((i == pointhighlight-16384) && (totalclock & 32)) col += (2<<2); @@ -1793,7 +2081,7 @@ void overheadeditor(void) numwalls = tempint; - if (highlightsectorcnt >= 0) + if (highlightsectorcnt >= 0 && !m32_sideview) for (i=0; i>3]&(1<<(i&7))) fillsector(i,2); @@ -1848,7 +2136,7 @@ void overheadeditor(void) drawline16base(searchx,searchy, +2,+1, +9,+1, col); //Draw the white pixel closest to mouse cursor on linehighlight - if (linehighlight>=0) + if (linehighlight>=0 && !m32_sideview) { getclosestpointonwall(mousxplc,mousyplc,(int32_t)linehighlight,&dax,&day); x2 = mulscale14(dax-pos.x,zoom); @@ -2481,6 +2769,8 @@ void overheadeditor(void) } else { + int32_t didmakered = (highlightsectorcnt<0); + for (i=0; i= 0) checksectorpointer(wall[j].nextwall,wall[j].nextsector); - checksectorpointer((int16_t)j,highlightsector[i]); + didmakered |= !!checksectorpointer((int16_t)j,highlightsector[i]); } } + + while (!didmakered && newnumwalls<0) // if + { + int32_t tmpnumwalls=0, refwall, n; + int16_t refsect, ignore; + uint8_t *visitedwall = Bcalloc((numwalls+7)>>3,1); + + if (!visitedwall) + { + message("out of memory!"); + break; + } + + for (i=0; i>3]&(1<<(j&7)))) + { + n=tmpnumwalls; + refwall = j; + k = numwalls; + + ignore = 0; + refsect = -1; + updatesectorexclude(wall[j].x, wall[j].y, &refsect, hlsectorbitmap); + if (refsect<0) + goto outtathis; + + do + { + if (j!=refwall && visitedwall[j>>3]&(1<<(j&7))) + ignore = 1; + visitedwall[j>>3] |= (1<<(j&7)); + + if (inside(wall[j].x, wall[j].y, refsect)!=1) + ignore = 1; + + if (!ignore) + { + if (k>=MAXWALLS) + { + message("Wall limits exceeded while trying to trace outer loop."); + goto outtathis; + } + + Bmemcpy(&wall[k], &wall[j], sizeof(walltype)); + wall[k].point2 = k+1; + wall[k].nextsector = wall[k].nextwall = wall[k].extra = -1; + k++; + } + + j = wall[j].point2; + n--; + + while (wall[j].nextwall>=0 && n>0) + { + j = wall[wall[j].nextwall].point2; +// if (j!=refwall && (visitedwall[j>>3]&(1<<(j&7)))) +// ignore = 1; +// visitedwall[j>>3] |= (1<<(j&7)); + n--; + } + } while (j!=refwall && n>0); + if (j!=refwall) + { + message("internal error while trying to trace outer loop: j!=refwall"); + goto outtathis; + } + + if (!ignore) + { + wall[k-1].point2 = numwalls; // close the loop + newnumwalls = k; + n = (newnumwalls-numwalls); // number of walls in just constructed loop + + if (clockdir(numwalls)==0) + { + int16_t begwalltomove = sector[refsect].wallptr+sector[refsect].wallnum; + + flipwalls(numwalls, newnumwalls); + + sector[refsect].wallnum += n; + if (refsect != numsectors-1) + { + walltype *tmpwall = Bmalloc(n * sizeof(walltype)); + + if (!tmpwall) + { + message("out of memory!"); + goto outtathis; + } + + for (m=0; m= begwalltomove) + wall[m].nextwall += n; + } + for (m=refsect+1; m 0) - updatesector(pos.x,pos.y,&cursectnum); + updatesectorz(pos.x,pos.y,pos.z,&cursectnum); if (circlewall != -1 && (keystatus[0x4a] || ((bstatus&32) && !eitherCTRL))) // - { @@ -2876,32 +3339,85 @@ SKIP: bstatus &= ~16; } - if ((DOWN_BK(MOVEUP) || (bstatus&16)) && zoom < 65536) + if (keystatus[0x3d]) // F3 { - zoom += synctics*(zoom>>4); - if (zoom < 24) zoom += 2; - if ((bstatus&16) && eitherALT) + keystatus[0x3d]=0; + if (!m32_sideview && (newnumwalls>=0 || joinsector[0]>=0 || circlewall>=0 || (bstatus&1))) + message("Must not be editing map while switching to side view mode."); + else { - searchx = halfxdim16; - searchy = midydim16; - pos.x = mousxplc; - pos.y = mousyplc; + m32_sideview = !m32_sideview; + message("Side view %s", m32_sideview?"enabled":"disabled"); + + m32_setkeyfilter(1); } - if (zoom > 65536) zoom = 65536; - _printmessage16("Zoom: %d",zoom); } - if ((DOWN_BK(MOVEDOWN) || (bstatus&32)) && zoom > 8) + + if (m32_sideview && (keystatus[0x10] || keystatus[0x11])) { - zoom -= synctics*(zoom>>4); - if ((bstatus&32) && eitherALT) + if (eitherCTRL) { - searchx = halfxdim16; - searchy = midydim16; - pos.x = mousxplc; - pos.y = mousyplc; + m32_sideang += 32; + m32_sideang &= (2047&~63); + } + else + { + if (keystatus[0x10]) + m32_sideang -= (1-2*sideview_reversehrot)*synctics<<(eitherSHIFT*2); + else + m32_sideang += (1-2*sideview_reversehrot)*synctics<<(eitherSHIFT*2); + + m32_sideang &= 2047; + } + _printmessage16("Sideview angle: %d", (int32_t)m32_sideang); + } + + if (m32_sideview && keystatus[0x2a]) // LShift + { + if (DOWN_BK(MOVEUP) && m32_sideelev < 512) + { + m32_sideelev += synctics<<1; + if (m32_sideelev > 512) + m32_sideelev = 512; + _printmessage16("Sideview elevation: %d", m32_sideelev); + } + if (DOWN_BK(MOVEDOWN) && m32_sideelev > 0) + { + m32_sideelev -= synctics<<1; + if (m32_sideelev < 0) + m32_sideelev = 0; + _printmessage16("Sideview elevation: %d", m32_sideelev); + } + } + else + { + if ((DOWN_BK(MOVEUP) || (bstatus&16)) && zoom < 65536) + { + zoom += synctics*(zoom>>4); + if (zoom < 24) zoom += 2; + if ((bstatus&16) && eitherALT) + { + searchx = halfxdim16; + searchy = midydim16; + pos.x = mousxplc; + pos.y = mousyplc; + } + if (zoom > 65536) zoom = 65536; + _printmessage16("Zoom: %d",zoom); + } + if ((DOWN_BK(MOVEDOWN) || (bstatus&32)) && zoom > 8) + { + zoom -= synctics*(zoom>>4); + if ((bstatus&32) && eitherALT) + { + searchx = halfxdim16; + searchy = midydim16; + pos.x = mousxplc; + pos.y = mousyplc; + } + if (zoom < 8) zoom = 8; + _printmessage16("Zoom: %d",zoom); } - if (zoom < 8) zoom = 8; - _printmessage16("Zoom: %d",zoom); } if (keystatus[0x22]) // G (grid on/off) @@ -4240,6 +4756,8 @@ CANCEL: if (keystatus[1]) { + m32_setkeyfilter(0); + keystatus[1] = 0; _printmessage16("(N)ew, (L)oad, (S)ave, save (A)s, (T)est map, (U)ndo, (R)edo, (Q)uit"); showframe(1); @@ -4281,8 +4799,14 @@ CANCEL: if (ch == 'Y' || ch == 'y') { - Bmemset(hlsectorbitmap, 0, sizeof(hlsectorbitmap)); - highlightsectorcnt = -1; + int32_t bakstat=-1; + mapinfofull_t bakmap; + + if (highlightsectorcnt > 0) + bakstat = backup_highlighted_map(&bakmap); + +// Bmemset(hlsectorbitmap, 0, sizeof(hlsectorbitmap)); +// highlightsectorcnt = -1; highlightcnt = -1; //Clear all highlights @@ -4310,6 +4834,14 @@ CANCEL: initspritelists(); Bstrcpy(boardfilename,"newboard.map"); map_undoredo_free(); + + if (bakstat==0) + { + bakstat = restore_highlighted_map(&bakmap); + if (bakstat == -1) + message("Can't copy highlighted portion of old map: limits exceeded."); + } + break; } else if (ch == 'N' || ch == 'n' || ch == 13 || ch == ' ') @@ -4331,68 +4863,14 @@ CANCEL: } else { + int32_t bakstat=-1; + mapinfofull_t bakmap; + Bstrcpy(boardfilename, selectedboardfilename); - if (highlightsectorcnt >= 0) - { - j = 0; k = 0; - for (i=0; i MAXSECTORS) || (numwalls+j > MAXWALLS) || (numsprites+k > MAXSPRITES)) - { - Bmemset(hlsectorbitmap, 0, sizeof(hlsectorbitmap)); - highlightsectorcnt = -1; - } - else - { - //Put sectors&walls to end of lists - j = MAXWALLS; - for (i=0; i=0; i--) - if (sprite[i].statnum < MAXSTATUS) - { - k = sprite[i].sectnum; - for (j=0; j 0) + bakstat = backup_highlighted_map(&bakmap); +// __old_mapcopy_2__ highlightcnt = -1; Bmemset(show2dwall, 0, sizeof(show2dwall)); //Clear all highlights Bmemset(show2dsprite, 0, sizeof(show2dsprite)); @@ -4403,9 +4881,9 @@ CANCEL: circlewall = -1; circlepoints = 7; -// for (i=0; i= 0) + if (bakstat==0) { - if ((numsectors+highlightsectorcnt > MAXSECTORS) || (sector[MAXSECTORS-highlightsectorcnt].wallptr < numwalls)) - { - Bmemset(hlsectorbitmap, 0, sizeof(hlsectorbitmap)); - highlightsectorcnt = -1; - } - else - { - //Re-attach sectors&walls - Bmemset(hlsectorbitmap, 0, sizeof(hlsectorbitmap)); - for (i=0; i>3] |= (1<<(numsectors&7)); - numwalls += sector[numsectors].wallnum; - numsectors++; - } - update_highlightsector(); - - //Re-attach sprites - while (m < MAXSPRITES) - { - //HACK - THESE 2 buffers back up .sectnum and .statnum - //for initspritelists() inside the loadboard call - //tsprite[m].picnum = sprite[i].sectnum; - //tsprite[m].owner = sprite[i].statnum; - - j = insertsprite(spriteext[m].mdanimcur+(numsectors-MAXSECTORS),spriteext[m].angoff); - Bmemcpy(&sprite[j],&sprite[m],sizeof(spritetype)); - //sprite[j].sectnum = tsprite[m].picnum+(numsectors-MAXSECTORS); - //sprite[j].statnum = tsprite[m].owner; - - // JBF: I see your hack and raise you another - sprite[j].sectnum = spriteext[m].mdanimcur+(numsectors-MAXSECTORS); - sprite[j].statnum = spriteext[m].angoff; - spriteext[m].mdanimcur = spriteext[m].angoff = 0; - - m++; - } - - for (i=0; i= 0) - checksectorpointer(wall[j].nextwall,wall[j].nextsector); - checksectorpointer((int16_t)j,highlightsector[i]); - } - } - - } + bakstat = restore_highlighted_map(&bakmap); + if (bakstat == -1) + message("Can't copy highlighted portion of old map: limits exceeded."); } - +// __old_mapcopy_2__ if (mapversion < 7) printmessage16("Map %s loaded successfully and autoconverted to V7!",boardfilename); else printmessage16("Map %s loaded successfully.",boardfilename); } + updatenumsprites(); startposx = pos.x; //this is same startposy = pos.y; @@ -4699,6 +5132,8 @@ CANCEL: } } clearkeys(); + + m32_setkeyfilter(1); } VM_OnEvent(EVENT_KEYS2D, -1); @@ -4738,6 +5173,8 @@ CANCEL: searchx = clamp(scale(searchx,xdimgame,xdim2d), 8, xdimgame-8-1); searchy = clamp(scale(searchy,ydimgame,ydim2d-STATUS2DSIZ), 8, ydimgame-8-1); + m32_setkeyfilter(0); + VM_OnEvent(EVENT_ENTER3DMODE, -1); } @@ -4746,8 +5183,18 @@ void getpoint(int32_t searchxe, int32_t searchye, int32_t *x, int32_t *y) bclamp(&pos.x, -editorgridextent, editorgridextent); bclamp(&pos.y, -editorgridextent, editorgridextent); - *x = pos.x + divscale14(searchxe-halfxdim16,zoom); - *y = pos.y + divscale14(searchye-midydim16,zoom); + searchxe -= halfxdim16; + searchye -= midydim16; + + if (m32_sideview) + { + if (m32_sidesin!=0) + searchye = divscale14(searchye, m32_sidesin); + rotatepoint(0,0, searchxe,searchye, -m32_sideang, &searchxe,&searchye); + } + + *x = pos.x + divscale14(searchxe,zoom); + *y = pos.y + divscale14(searchye,zoom); bclamp(x, -editorgridextent, editorgridextent); bclamp(y, -editorgridextent, editorgridextent); @@ -5113,9 +5560,9 @@ int32_t checksectorpointer(int16_t i, int16_t sectnum) { int32_t j, k, startwall, endwall, x1, y1, x2, y2, numnewwalls=0; - char buf[128]; - if (i<0 || i>=max(numwalls,newnumwalls)) + if (checksectorpointer_warn && (i<0 || i>=max(numwalls,newnumwalls))) { + char buf[128]; Bsprintf(buf, "WARN: checksectorpointer called with i=%d but (new)numwalls=%d", i, max(numwalls,newnumwalls)); OSD_Printf("%s\n", buf); printmessage16(buf); @@ -5858,6 +6305,8 @@ int32_t fillsector(int16_t sectnum, char fillcolor) int32_t lborder, rborder, uborder, dborder, miny, maxy, dax; int16_t z, zz, startwall, endwall, fillcnt; + UNREFERENCED_PARAMETER(fillcolor); + lborder = 0; rborder = xdim; uborder = 0; dborder = ydim16; @@ -5882,7 +6331,8 @@ int32_t fillsector(int16_t sectnum, char fillcolor) if (miny < uborder) miny = uborder; if (maxy >= dborder) maxy = dborder-1; - for (sy=miny+((totalclock>>2)&3); sy<=maxy; sy+=3) // JBF 20040116: numframes%3 -> (totalclock>>2)&3 +//+((totalclock>>2)&3) + for (sy=miny; sy<=maxy; sy+=3) // JBF 20040116: numframes%3 -> (totalclock>>2)&3 { y = pos.y+(((sy-midydim16)<<14)/zoom); @@ -5922,7 +6372,8 @@ int32_t fillsector(int16_t sectnum, char fillcolor) 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, 159 //editorcolors[fillcolor] + -klabs(sintable[((totalclock<<3)&2047)]>>11)); } } } @@ -6151,9 +6602,10 @@ void updatenumsprites(void) numsprites += (sprite[i].statnum < MAXSTATUS); } -void copysector(int16_t soursector, int16_t destsector, int16_t deststartwall, char copystat) +static void copysector(int16_t soursector, int16_t destsector, int16_t deststartwall, char copystat, + const int16_t *oldtonewsect) { - int16_t j, k, m, newnumwalls, startwall, endwall; + int16_t i, j, k, m, newnumwalls, startwall, endwall; newnumwalls = deststartwall; //erase existing sector fragments @@ -6162,12 +6614,40 @@ void copysector(int16_t soursector, int16_t destsector, int16_t deststartwall, c endwall = startwall + sector[soursector].wallnum; for (j=startwall; j= 0) { - wall[newnumwalls].nextwall = -1; - wall[newnumwalls].nextsector = -1; + k = wall[newnumwalls].nextsector; + if (oldtonewsect && oldtonewsect[k]>=0) + { + wall[newnumwalls].nextsector = oldtonewsect[k]; + m = 0; + for (i=0; i= 0) { - k = nextspritesect[j]; - m = insertsprite(destsector,sprite[j].statnum); - Bmemcpy(&sprite[m],&sprite[j],sizeof(spritetype)); - sprite[m].sectnum = destsector; //Don't let memcpy overwrite sector! - - j = k; + if (m>=0) + { + Bmemcpy(&sprite[m],&sprite[j],sizeof(spritetype)); + sprite[m].sectnum = destsector; //Don't let memcpy overwrite sector! + } + j = nextspritesect[j]; } } - } } diff --git a/polymer/eduke32/build/src/config.c b/polymer/eduke32/build/src/config.c index a90b095d7..a25c72252 100644 --- a/polymer/eduke32/build/src/config.c +++ b/polymer/eduke32/build/src/config.c @@ -216,13 +216,14 @@ int32_t loadsetup(const char *fn) if (readconfig(fp, "mousesensitivity", val, VL) > 0) msens = Bstrtod(val, NULL); - if (readconfig(fp, "mousenavigation", val, VL) > 0) unrealedlook = Batoi(val); + if (readconfig(fp, "mousenavigation", val, VL) > 0) unrealedlook = !!Batoi(val); if (readconfig(fp, "mousenavigationaccel", val, VL) > 0) pk_uedaccel = Batoi(val); if (readconfig(fp, "quickmapcycling", val, VL) > 0) quickmapcycling = Batoi(val); - if (readconfig(fp, "revertCTRL", val, VL) > 0) revertCTRL = Batoi(val); + if (readconfig(fp, "sideview_reversehorizrot", val, VL) > 0) sideview_reversehrot = !!Batoi(val); + if (readconfig(fp, "revertCTRL", val, VL) > 0) revertCTRL = !!Batoi(val); if (readconfig(fp, "scrollamount", val, VL) > 0) scrollamount = Batoi(val); @@ -242,10 +243,10 @@ int32_t loadsetup(const char *fn) graphicsmode = min(max(Batoi(val),0),2); if (readconfig(fp, "samplerate", val, VL) > 0) MixRate = min(max(8000, Batoi(val)), 48000); - if (readconfig(fp, "ambiencetoggle", val, VL) > 0) AmbienceToggle = Batoi(val); - if (readconfig(fp, "parlock", val, VL) > 0) ParentalLock = Batoi(val); + if (readconfig(fp, "ambiencetoggle", val, VL) > 0) AmbienceToggle = !!Batoi(val); + if (readconfig(fp, "parlock", val, VL) > 0) ParentalLock = !!Batoi(val); - if (readconfig(fp, "osdtryscript", val, VL) > 0) m32_osd_tryscript = Batoi(val); + if (readconfig(fp, "osdtryscript", val, VL) > 0) m32_osd_tryscript = !!Batoi(val); for (i=0; i<256; i++) remap[i]=i; @@ -399,12 +400,15 @@ int32_t writesetup(const char *fn) "; 1 - Yes\n" "quickmapcycling = %d\n" "\n" + "; Reverse meaning of Q and W keys in side view mode\n" + "sideview_reversehorizrot = %d\n" + "\n" "; Revert CTRL for tile selction\n" "; 0 - WHEEL:scrolling, CTRL+WHEEL:zooming\n" "; 1 - CTRL+WHEEL:scrolling, WHEEL:zooming\n" "revertCTRL = %d\n" "\n" - "; Scroll amount for WHEEL in the tile selcetion\n" + "; Scroll amount for WHEEL in the tile selection\n" "scrollamount = %d\n" "\n" "; Turning acceleration+declaration\n" @@ -480,10 +484,9 @@ int32_t writesetup(const char *fn) #endif // "; Console key scancode, in hex\n" "keyconsole = %X\n" - "; example: make 'Q' function as CapsLock, KP. as AltGr\n" - "; and KP0 as KP5 (counters inability to pan using Shift-KP5-KP8/2\n" - "; in 3D mode)\n" - "; remap = 10-3A,52-4C,53-B8\n" + "; example: make KP0 function as KP5 (counters inability\n" + "; inability to pan using Shift-KP5-KP8/2 in 3D mode)\n" + "; remap = 52-4C\n" "remap = ", forcesetup, fullscreen, xdim2d, ydim2d, xdimgame, ydimgame, bppgame, vsync, @@ -506,6 +509,7 @@ int32_t writesetup(const char *fn) option[7]>>4, option[2], #endif option[3], msens, unrealedlook, pk_uedaccel, quickmapcycling, + sideview_reversehrot, revertCTRL,scrollamount,pk_turnaccel,pk_turndecel,autosave, showheightindicators,showambiencesounds,graphicsmode, MixRate,AmbienceToggle,ParentalLock, !!m32_osd_tryscript, diff --git a/polymer/eduke32/build/src/engine.c b/polymer/eduke32/build/src/engine.c index dc0c036f8..ac8583f31 100644 --- a/polymer/eduke32/build/src/engine.c +++ b/polymer/eduke32/build/src/engine.c @@ -167,6 +167,18 @@ qlz_state_decompress *state_decompress = NULL; int32_t whitecol; +////////// editor side view ////////// +int32_t m32_sideview = 0; +int32_t m32_sideelev = 256; // elevation in BUILD degrees, 0..512 +int16_t m32_sideang = 200; // azimuth, 0..2047 + +int32_t m32_sidecos, m32_sidesin; +int32_t m32_swcnt; +int16_t *m32_wallsprite; // [MAXSWALLS+MAXSPRITES] +static int32_t *m32_sidedist; // [MAXSWALLS+MAXSPRITES] +static vec3_t m32_viewplane; + + ////// sector-like clipping for sprites ////// typedef struct { @@ -10255,6 +10267,43 @@ void updatesector(int32_t x, int32_t y, int16_t *sectnum) *sectnum = -1; } +void updatesectorexclude(int32_t x, int32_t y, int16_t *sectnum, const uint8_t *excludesectbitmap) +{ + walltype *wal; + int32_t i, j; + + if (!(excludesectbitmap[*sectnum>>3]&(1<<(*sectnum&7))) && inside(x,y,*sectnum) == 1) + return; + + if ((*sectnum >= 0) && (*sectnum < numsectors)) + { + wal = &wall[sector[*sectnum].wallptr]; + j = sector[*sectnum].wallnum; + do + { + i = wal->nextsector; + if (i >= 0) + if (!(excludesectbitmap[i>>3]&(1<<(i&7))) && inside(x,y,(int16_t)i) == 1) + { + *sectnum = i; + return; + } + wal++; + j--; + } + while (j != 0); + } + + for (i=numsectors-1; i>=0; i--) + if (!(excludesectbitmap[i>>3]&(1<<(i&7))) && inside(x,y,(int16_t)i) == 1) + { + *sectnum = i; + return; + } + + *sectnum = -1; +} + void updatesectorz(int32_t x, int32_t y, int32_t z, int16_t *sectnum) { walltype *wal; @@ -11661,7 +11710,7 @@ void drawline256(int32_t x1, int32_t y1, int32_t x2, int32_t y2, char col) // after clipping or crashes would ensue uint32_t drawlinepat = 0xffffffff; -void drawline16(int32_t x1, int32_t y1, int32_t x2, int32_t y2, char col) +int32_t drawline16(int32_t x1, int32_t y1, int32_t x2, int32_t y2, char col) { int32_t i, dx, dy, pinc, d; uint32_t patc=0; @@ -11670,25 +11719,25 @@ void drawline16(int32_t x1, int32_t y1, int32_t x2, int32_t y2, char col) dx = x2-x1; dy = y2-y1; if (dx >= 0) { - if ((x1 >= xres) || (x2 < 0)) return; + if ((x1 >= xres) || (x2 < 0)) return 0; if (x1 < 0) { if (dy) y1 += scale(0-x1,dy,dx); x1 = 0; } if (x2 >= xres) { if (dy) y2 += scale(xres-1-x2,dy,dx); x2 = xres-1; } } else { - if ((x2 >= xres) || (x1 < 0)) return; + if ((x2 >= xres) || (x1 < 0)) return 0; if (x2 < 0) { if (dy) y2 += scale(0-x2,dy,dx); x2 = 0; } if (x1 >= xres) { if (dy) y1 += scale(xres-1-x1,dy,dx); x1 = xres-1; } } if (dy >= 0) { - if ((y1 >= ydim16) || (y2 < 0)) return; + if ((y1 >= ydim16) || (y2 < 0)) return 0; if (y1 < 0) { if (dx) x1 += scale(0-y1,dx,dy); y1 = 0; if (x1 < 0) x1 = 0; } if (y2 >= ydim16) { if (dx) x2 += scale(ydim16-1-y2,dx,dy); y2 = ydim16-1; if (x2 < 0) x2 = 0; } } else { - if ((y2 >= ydim16) || (y1 < 0)) return; + if ((y2 >= ydim16) || (y1 < 0)) return 0; if (y2 < 0) { if (dx) x2 += scale(0-y2,dx,dy); y2 = 0; if (x2 < 0) x2 = 0; } if (y1 >= ydim16) { if (dx) x1 += scale(ydim16-1-y1,dx,dy); y1 = ydim16-1; if (x1 < 0) x1 = 0; } } @@ -11721,7 +11770,8 @@ void drawline16(int32_t x1, int32_t y1, int32_t x2, int32_t y2, char col) p++; } enddrawing(); //}}} - return; + + return 1; } if (y2 < y1) @@ -11743,113 +11793,127 @@ void drawline16(int32_t x1, int32_t y1, int32_t x2, int32_t y2, char col) p += bytesperline; } enddrawing(); //}}} + + return 1; } -void drawcircle16(int32_t x1, int32_t y1, int32_t r, char col) +static void drawline16mid(int32_t x1, int32_t y1, int32_t x2, int32_t y2, char col) { -#if 1 - intptr_t p; - int32_t xp, yp, xpbpl, ypbpl, d, de, dse, patc=0; + drawline16(halfxdim16+x1,midydim16+y1, halfxdim16+x2,midydim16+y2, col); +} - if (r < 0) r = -r; - if (x1+r < 0 || x1-r >= xres) return; - if (y1+r < 0 || y1-r >= ydim16) return; - - /* - * d - * 6 | 7 - * \ | / - * 5 \|/ 8 - * c----+----a - * 4 /|\ 1 - * / | \ - * 3 | 2 - * b - */ - - xp = 0; - yp = r; - d = 1 - r; - de = 2; - dse = 5 - (r << 1); - - begindrawing(); - p = (y1*bytesperline)+x1+frameplace; - - if (drawlinepat & pow2long[(patc++)&31]) +// eccen: eccentricity of the ellipse, +// 16384: circle +// <16384: shrink in y +// >16384: grow in y +void drawcircle16(int32_t x1, int32_t y1, int32_t r, int32_t eccen, char col) +{ + if (eccen==16384) { - if ((uint32_t)y1 < (uint32_t)ydim16 && (uint32_t)(x1+r) < (uint32_t)xres) - drawpixel_safe((char *)(p+r), col); // a - if ((uint32_t)x1 < (uint32_t)xres && (uint32_t)(y1+r) < (uint32_t)ydim16) - drawpixel_safe((char *)(p+(r*bytesperline)), col); // b - if ((uint32_t)y1 < (uint32_t)ydim16 && (uint32_t)(x1-r) < (uint32_t)xres) - drawpixel_safe((char *)(p-r), col); // c - if ((uint32_t)x1 < (uint32_t)xres && (uint32_t)(y1-r) < (uint32_t)ydim16) - drawpixel_safe((char *)(p-(r*bytesperline)), col); // d - } + intptr_t p; + int32_t xp, yp, xpbpl, ypbpl, d, de, dse, patc=0; - do - { - if (d < 0) - { - d += de; - de += 2; - dse += 2; - xp++; - } - else - { - d += dse; - de += 2; - dse += 4; - xp++; - yp--; - } + if (r < 0) r = -r; + if (x1+r < 0 || x1-r >= xres) return; + if (y1+r < 0 || y1-r >= ydim16) return; + + /* + * d + * 6 | 7 + * \ | / + * 5 \|/ 8 + * c----+----a + * 4 /|\ 1 + * / | \ + * 3 | 2 + * b + */ + + xp = 0; + yp = r; + d = 1 - r; + de = 2; + dse = 5 - (r << 1); + + begindrawing(); + p = (y1*bytesperline)+x1+frameplace; - ypbpl = yp*bytesperline; - xpbpl = xp*bytesperline; if (drawlinepat & pow2long[(patc++)&31]) { - if ((uint32_t)(x1+yp) < (uint32_t)xres && (uint32_t)(y1+xp) < (uint32_t)ydim16) - drawpixel_safe((char *)(p+yp+xpbpl), col); // 1 - if ((uint32_t)(x1+xp) < (uint32_t)xres && (uint32_t)(y1+yp) < (uint32_t)ydim16) - drawpixel_safe((char *)(p+xp+ypbpl), col); // 2 - if ((uint32_t)(x1-xp) < (uint32_t)xres && (uint32_t)(y1+yp) < (uint32_t)ydim16) - drawpixel_safe((char *)(p-xp+ypbpl), col); // 3 - if ((uint32_t)(x1-yp) < (uint32_t)xres && (uint32_t)(y1+xp) < (uint32_t)ydim16) - drawpixel_safe((char *)(p-yp+xpbpl), col); // 4 - if ((uint32_t)(x1-yp) < (uint32_t)xres && (uint32_t)(y1-xp) < (uint32_t)ydim16) - drawpixel_safe((char *)(p-yp-xpbpl), col); // 5 - if ((uint32_t)(x1-xp) < (uint32_t)xres && (uint32_t)(y1-yp) < (uint32_t)ydim16) - drawpixel_safe((char *)(p-xp-ypbpl), col); // 6 - if ((uint32_t)(x1+xp) < (uint32_t)xres && (uint32_t)(y1-yp) < (uint32_t)ydim16) - drawpixel_safe((char *)(p+xp-ypbpl), col); // 7 - if ((uint32_t)(x1+yp) < (uint32_t)xres && (uint32_t)(y1-xp) < (uint32_t)ydim16) - drawpixel_safe((char *)(p+yp-xpbpl), col); // 8 + if ((uint32_t)y1 < (uint32_t)ydim16 && (uint32_t)(x1+r) < (uint32_t)xres) + drawpixel_safe((char *)(p+r), col); // a + if ((uint32_t)x1 < (uint32_t)xres && (uint32_t)(y1+r) < (uint32_t)ydim16) + drawpixel_safe((char *)(p+(r*bytesperline)), col); // b + if ((uint32_t)y1 < (uint32_t)ydim16 && (uint32_t)(x1-r) < (uint32_t)xres) + drawpixel_safe((char *)(p-r), col); // c + if ((uint32_t)x1 < (uint32_t)xres && (uint32_t)(y1-r) < (uint32_t)ydim16) + drawpixel_safe((char *)(p-(r*bytesperline)), col); // d } + + do + { + if (d < 0) + { + d += de; + de += 2; + dse += 2; + xp++; + } + else + { + d += dse; + de += 2; + dse += 4; + xp++; + yp--; + } + + ypbpl = yp*bytesperline; + xpbpl = xp*bytesperline; + if (drawlinepat & pow2long[(patc++)&31]) + { + if ((uint32_t)(x1+yp) < (uint32_t)xres && (uint32_t)(y1+xp) < (uint32_t)ydim16) + drawpixel_safe((char *)(p+yp+xpbpl), col); // 1 + if ((uint32_t)(x1+xp) < (uint32_t)xres && (uint32_t)(y1+yp) < (uint32_t)ydim16) + drawpixel_safe((char *)(p+xp+ypbpl), col); // 2 + if ((uint32_t)(x1-xp) < (uint32_t)xres && (uint32_t)(y1+yp) < (uint32_t)ydim16) + drawpixel_safe((char *)(p-xp+ypbpl), col); // 3 + if ((uint32_t)(x1-yp) < (uint32_t)xres && (uint32_t)(y1+xp) < (uint32_t)ydim16) + drawpixel_safe((char *)(p-yp+xpbpl), col); // 4 + if ((uint32_t)(x1-yp) < (uint32_t)xres && (uint32_t)(y1-xp) < (uint32_t)ydim16) + drawpixel_safe((char *)(p-yp-xpbpl), col); // 5 + if ((uint32_t)(x1-xp) < (uint32_t)xres && (uint32_t)(y1-yp) < (uint32_t)ydim16) + drawpixel_safe((char *)(p-xp-ypbpl), col); // 6 + if ((uint32_t)(x1+xp) < (uint32_t)xres && (uint32_t)(y1-yp) < (uint32_t)ydim16) + drawpixel_safe((char *)(p+xp-ypbpl), col); // 7 + if ((uint32_t)(x1+yp) < (uint32_t)xres && (uint32_t)(y1-xp) < (uint32_t)ydim16) + drawpixel_safe((char *)(p+yp-xpbpl), col); // 8 + } + } + while (yp > xp); + enddrawing(); } - while (yp > xp); - enddrawing(); -#else - // JonoF's rough approximation of a circle - int32_t l,spx,spy,lpx,lpy,px,py; - - spx = lpx = x1+mulscale14(r,sintable[0]); - spy = lpy = y1+mulscale14(r,sintable[512]); - - for (l=64; l<2048; l+=64) + else { - px = x1+mulscale14(r,sintable[l]); - py = y1+mulscale14(r,sintable[(l+512)&2047]); + // JonoF's rough approximation of a circle + int32_t l,spx,spy,lpx,lpy,px,py; - drawline16(lpx,lpy,px,py,col); + spx = lpx = x1 + mulscale14(r,sintable[0]); + spy = lpy = y1 + mulscale14(eccen, mulscale14(r,sintable[512])); - lpx = px; - lpy = py; + for (l=64; l<2048; l+=64) + { + px = x1 + mulscale14(r,sintable[l]); + py = y1 + mulscale14(eccen, mulscale14(r,sintable[(l+512)&2047])); + + drawline16(lpx,lpy,px,py,col); + + lpx = px; + lpy = py; + } + + drawline16(lpx,lpy,spx,spy,col); } - - drawline16(lpx,lpy,spx,spy,col); -#endif } @@ -11966,469 +12030,720 @@ void clear2dscreen(void) enddrawing(); //}}} } + +////////// editor side view ////////// + +inline int32_t scalescreeny(int32_t sy) +{ + if (m32_sideview) + return mulscale14(sy, m32_sidesin); + else + return sy; +} + +// return screen coordinates for BUILD coords x and y (relative to current position) +void screencoords(int32_t *xres, int32_t *yres, int32_t x, int32_t y, int32_t zoome) +{ + if (m32_sideview) + rotatepoint(0,0, x,y, m32_sideang, &x,&y); + + *xres = mulscale14(x,zoome); + *yres = scalescreeny(mulscale14(y,zoome)); +} + +// return vertical screen coordinate displacement for BUILD z coord +inline int32_t getscreenvdisp(int32_t bz, int32_t zoome) +{ + return mulscale32(bz,zoome*m32_sidecos); +} + +void setup_sideview_sincos() +{ + if (m32_sideview) + { + m32_viewplane.x = 0; + m32_viewplane.y = -512; + + m32_sidesin = sintable[m32_sideelev&2047]; + m32_sidecos = sintable[(m32_sideelev+512)&2047]; + + rotatepoint(0,0, m32_viewplane.x,m32_viewplane.y, -m32_sideang, &m32_viewplane.x,&m32_viewplane.y); + m32_viewplane.x = mulscale14(m32_viewplane.x, m32_sidecos); + m32_viewplane.y = mulscale14(m32_viewplane.y, m32_sidecos); + m32_viewplane.z = m32_sidesin>>5; + } +} + +static void sideview_getdist(int16_t sw, int16_t sect) +{ + vec3_t *p; + vec3_t v; + + if (sw>1; + v.y = (wall[sw].y + wall[wall[sw].point2].y)>>1; + v.z = getflorzofslope(sect, v.x, v.y); + p = &v; + } + else + p = (vec3_t *)&sprite[sw-MAXWALLS]; + + m32_sidedist[sw] = p->x*m32_viewplane.x + p->y*m32_viewplane.y + (p->z>>4)*m32_viewplane.z; +} + +static int sideview_cmppoints(const int16_t *sw1, const int16_t *sw2) +{ + int32_t dist1 = m32_sidedist[*sw1]; + int32_t dist2 = m32_sidedist[*sw2]; + + if (dist2>dist1) + return 1; + else if (dist1>dist2) + return -1; + +// if (*sw1=0) - (wall[*sw1].nextwall>=0); + + return 0; +} + // // draw2dgrid // -void draw2dgrid(int32_t posxe, int32_t posye, int16_t ange, int32_t zoome, int16_t gride) +void draw2dgrid(int32_t posxe, int32_t posye, int32_t posze, int16_t ange, int32_t zoome, int16_t gride) { int64_t i, xp1, yp1, xp2=0, yp2, tempy; UNREFERENCED_PARAMETER(ange); - if (gride > 0) - { - begindrawing(); //{{{ + if (gride <= 0) + return; + begindrawing(); //{{{ + + if (m32_sideview) + { + int32_t sx1,sy1, sx2,sy2, dx=0,dy=0; + int32_t xinc=0, yinc=2048>>gride, yofs; + + yofs = getscreenvdisp((yinc-posze)&((yinc<<4)-1), zoome); + + while (scalescreeny(mulscale14(yinc, zoome))==0 && gride>2) + { + gride--; + yinc = 2048>>gride; + } + + xp2 = xp1 = ((posxe+(1024>>gride))&(((int64_t)(-1))<<(11-gride))); + yp2 = yp1 = ((posye+(1024>>gride))&(((int64_t)(-1))<<(11-gride))); + + do + { + if (xinc==0) + { + screencoords(&sx1,&sy1, -editorgridextent-posxe,yp2-posye, zoome); + if (yp2 == yp1) + { + screencoords(&sx2,&sy2, editorgridextent-posxe,yp2-posye, zoome); + dx = sx2-sx1; + dy = sy2-sy1; + } + yp2 += yinc; + } + else // if (yinc==0) + { + screencoords(&sx1,&sy1, xp2-posxe, -editorgridextent-posye, zoome); + if (xp2 == xp1) + { + screencoords(&sx2,&sy2, xp2-posxe, editorgridextent-posye, zoome); + dx = sx2-sx1; + dy = sy2-sy1; + } + xp2 += xinc; + } + + i = drawline16(halfxdim16+sx1,midydim16+sy1+yofs, halfxdim16+sx1+dx,midydim16+sy1+dy+yofs, whitecol-25); + if (i==0 || (xp2<-editorgridextent || xp2>editorgridextent || + yp2<-editorgridextent || yp2>editorgridextent)) + { + xp2 = xp1; + yp2 = yp1; + + i = 1; + + if (yinc>0) + yinc *= -1; + else if (yinc<0) + { + xinc = -yinc; + yinc = 0; + } + else if (xinc>0) + xinc *= -1; + else // if (xinc<0) + i = 0; + } + } + while (i); + } + else + { + // vertical lines yp1 = midydim16-mulscale14(posye+editorgridextent,zoome); if (yp1 < 0) yp1 = 0; + yp2 = midydim16-mulscale14(posye-editorgridextent,zoome); if (yp2 >= ydim16) yp2 = ydim16-1; if ((yp1 < ydim16) && (yp2 >= 0) && (yp2 >= yp1)) { xp1 = halfxdim16-mulscale14(posxe+editorgridextent,zoome); + for (i=-editorgridextent; i<=editorgridextent; i+=(2048>>gride)) { xp2 = xp1; xp1 = halfxdim16-mulscale14(posxe-i,zoome); - if (xp1 >= xdim) break; + + if (xp1 >= xdim) + break; + if (xp1 >= 0) { if (xp1 != xp2) - { drawline16(xp1,yp1,xp1,yp2,whitecol-25); - } } } - if ((i >= editorgridextent) && (xp1 < xdim)) + if (i >= editorgridextent && xp1 < xdim) xp2 = xp1; - if ((xp2 >= 0) && (xp2 < xdim)) - { - drawline16(xp2,yp1,xp2,yp2,whitecol-25); - } + if (xp2 >= 0 && xp2 < xdim) + drawline16(xp2,yp1, xp2,yp2, whitecol-25); } + + // horizontal lines xp1 = mulscale14(posxe+editorgridextent,zoome); xp2 = mulscale14(posxe-editorgridextent,zoome); tempy = 0x80000000l; + for (i=-editorgridextent; i<=editorgridextent; i+=(2048>>gride)) { - yp1 = (((posye-i)*zoome)>>14); + yp1 = ((posye-i)*zoome)>>14; if (yp1 != tempy) { if ((yp1 > midydim16-ydim16) && (yp1 <= midydim16)) { - drawline16(halfxdim16-xp1,midydim16-yp1,halfxdim16-xp2,midydim16-yp1,whitecol-25); + drawline16mid(-xp1,-yp1, -xp2,-yp1, whitecol-25); tempy = yp1; } } } - enddrawing(); //}}} } + + enddrawing(); //}}} } +static void drawscreen_drawwall(int32_t i, int32_t posxe, int32_t posye, int32_t posze, int32_t zoome) +{ + const walltype *wal = &wall[i]; + int32_t j, x1, y1, x2, y2, dz, dz2; +// intptr_t tempint; + char col; + + int64_t dist,dx,dy; + + if (editstatus == 0) + { + if ((show2dwall[i>>3]&pow2char[i&7]) == 0) return; + j = wal->nextwall; + if ((j >= 0) && (i > j)) + if ((show2dwall[j>>3]&pow2char[j&7]) > 0) return; + } + else + { + j = wal->nextwall; + if (!m32_sideview && (j >= 0) && (i > j)) return; + } + + if (j < 0) + { + col = 15; + if (i == linehighlight) + col = (totalclock & 16) ? 15 : 7; + } + else + { + col = 33; + if ((wal->cstat&1) != 0) + col = 5; + if (wal->nextwall >= 0 && ((wal->cstat^wall[wal->nextwall].cstat)&1)) + col = 2; + if ((i == linehighlight) || ((linehighlight >= 0) && (i == wall[linehighlight].nextwall))) + if (totalclock & 16) + col += (2<<2); + } + + screencoords(&x1,&y1, wal->x-posxe,wal->y-posye, zoome); + screencoords(&x2,&y2, wall[wal->point2].x-posxe,wall[wal->point2].y-posye, zoome); + + dx = wal->x-wall[wal->point2].x; + dy = wal->y-wall[wal->point2].y; + dist = dx*dx+dy*dy; + + if (dist > 0xffffffff) + { + col=9; + if (i == linehighlight || ((linehighlight >= 0) && (i == wall[linehighlight].nextwall))) + if (totalclock & 16) col -= (2<<2); + } + else if (showfirstwall && searchsector>=0 && (sector[searchsector].wallptr == i || + sector[searchsector].wallptr == wall[i].nextwall)) + { + col = 14; + if (i == linehighlight) if (totalclock & 16) col -= (2<<2); + } + else if (circlewall >= 0 && (i == circlewall || wal->nextwall == circlewall)) + col = 14; + + if (m32_sideview) + { + int32_t fz, fz2, fzn; + int32_t sect=sectorofwall(i); + + fz = getflorzofslope(sect, wal->x,wal->y); + fz2 = getflorzofslope(sect, wall[wal->point2].x,wall[wal->point2].y); + + dz = getscreenvdisp(fz-posze,zoome); + dz2 = getscreenvdisp(fz2-posze,zoome); + + y1 += dz; + y2 += dz2; + + if (wal->nextwall>=0) + { + fzn = getflorzofslope(wal->nextsector, wal->x,wal->y)-fz; + drawline16mid(x1,y1, x1,y1+getscreenvdisp(fzn,zoome), editorcolors[col]); + } + } + + if ((wal->cstat&64) > 0) // if hitscan bit set + { + int32_t one=(klabs(x2-x1) >= klabs(y2-y1)), no=!one; + + drawline16mid(x1+no,y1+one, x2+no,y2+one, editorcolors[col]); + drawline16mid(x1-no,y1-one, x2-no,y2-one, editorcolors[col]); + + col += 8; + } + + drawline16mid(x1,y1, x2,y2, editorcolors[col]); + + if (showheightindicators && !m32_sideview) + { + int32_t dax,day, k=getangle(x1-x2, y1-y2); //+angofs; + + screencoords(&dax,&day, ((wal->x+wall[wal->point2].x)>>1)-posxe,((wal->y+wall[wal->point2].y)>>1)-posye, zoome); + if (m32_sideview) + day += (dz2+dz)>>1; + + if (wal->nextsector >= 0) + { + int32_t ii = sector[sectorofwall(i)].floorz; + int32_t jj = sector[wal->nextsector].floorz; + + if (jj == ii && showheightindicators > 1) + { + int32_t dax3 = mulscale11(sintable[(k+1024)&2047],zoome) / 2560; + int32_t day3 = mulscale11(sintable[(k+512)&2047],zoome) / 2560; + int32_t dax2 = mulscale11(sintable[(k+2048)&2047],zoome) / 2560; + int32_t day2 = mulscale11(sintable[(k+1536)&2047],zoome) / 2560; + + day2 = scalescreeny(day2); + day3 = scalescreeny(day3); + + drawline16mid(dax+dax3,day+day3, dax+dax2,day+day2, editorcolors[col]); + } + else if (jj > ii) + { + int32_t dax2 = mulscale11(sintable[(k+1024)&2047],zoome) / 2560; + int32_t day2 = mulscale11(sintable[(k+512)&2047],zoome) / 2560; + + day2 = scalescreeny(day2); + drawline16mid(dax,day, dax+dax2,day+day2, editorcolors[col]); + } + else if (jj < ii) + { + int32_t dax2 = mulscale11(sintable[(k+2048)&2047],zoome) / 2560; + int32_t day2 = mulscale11(sintable[(k+1536)&2047],zoome) / 2560; + + day2 = scalescreeny(day2); + drawline16mid(dax,day, dax+dax2,day+day2, editorcolors[col]); + } + } + else if (showheightindicators > 1) + { + int32_t dax2 = mulscale11(sintable[(k+2048)&2047],zoome) / 2560; + int32_t day2 = mulscale11(sintable[(k+1536)&2047],zoome) / 2560; + + day2 = scalescreeny(day2); + drawline16mid(dax,day, dax+dax2,day+day2, editorcolors[col]); + } + } + + if (zoome >= 256 && editstatus == 1) + if ((halfxdim16+x1 >= 2) && (halfxdim16+x1 <= xdim-3) && + (midydim16+y1 >= 2) && (midydim16+y1 <= ydim16-3)) + { + int32_t pointsize = 2; + + if (i == pointhighlight || ((pointhighlight < MAXWALLS) && (pointhighlight >= 0) && + (wall[i].x == wall[pointhighlight].x) && (wall[i].y == wall[pointhighlight].y))) + { + if (totalclock & 16) + pointsize++; + } + else //if (highlightcnt > 0) + { + if (show2dwall[i>>3]&pow2char[i&7]) + { + if (totalclock & 16) + pointsize++; + } + } + + col = 15; + if (m32_sideview) + { + int16_t nw = wall[i].nextwall; + if (nw>=0) + { + int32_t fz = getflorzofslope(sectorofwall(i), wall[i].x, wall[i].y); + int32_t fz2 = getflorzofslope(wall[i].nextsector, wall[i].x, wall[i].y); + + if (fz < fz2) + col = 7; + else if (fz==fz2) + col = 4; + } + } + +// tempint = ((midydim16+y1)*bytesperline)+(halfxdim16+x1)+frameplace; + do + drawcircle16(halfxdim16+x1, midydim16+y1, pointsize--, 16384, editorcolors[col]); + while (pointsize); + } +} + +static void drawscreen_drawsprite(int32_t j, int32_t posxe, int32_t posye, int32_t posze, int32_t zoome) +{ + int32_t x1, y1, x2, y2; + char col; + + int16_t angofs = m32_sideview ? m32_sideang : 0; + + if (sprite[j].sectnum<0) + col = 4; // red + else + { + col = 3; + if (spritecol2d[sprite[j].picnum][0]) + col = spritecol2d[sprite[j].picnum][0]; + else if ((sprite[j].cstat&1) > 0) + { + col = 5; + if (spritecol2d[sprite[j].picnum][1]) + col = spritecol2d[sprite[j].picnum][1]; + } + } + + if (editstatus == 1) + { + if ((pointhighlight) >= 16384 && (j+16384 == pointhighlight || + (!m32_sideview && ((sprite[j].x == sprite[pointhighlight-16384].x) && + (sprite[j].y == sprite[pointhighlight-16384].y))))) + { + if (totalclock & 32) col += 8; + } + else // if (highlightcnt > 0) + { + if (show2dsprite[j>>3]&pow2char[j&7]) + if (totalclock & 32) col += 8; + } + } + + screencoords(&x1,&y1, sprite[j].x-posxe,sprite[j].y-posye, zoome); +// tempint = ((midydim16+y1)*bytesperline)+(halfxdim16+x1)+frameplace; + + if (m32_sideview) + y1 += getscreenvdisp(sprite[j].z-posze,zoome); + + if ((halfxdim16+x1 >= 0) && (halfxdim16+x1 < xdim) && + (midydim16+y1 >= 0) && (midydim16+y1 < ydim16)) + { + drawcircle16(halfxdim16+x1, midydim16+y1, 4, 16384, editorcolors[col]); + + x2 = mulscale11(sintable[(sprite[j].ang+angofs+2560)&2047],zoome) / 768; + y2 = mulscale11(sintable[(sprite[j].ang+angofs+2048)&2047],zoome) / 768; + y2 = scalescreeny(y2); + + drawline16mid(x1,y1, x1+x2,y1+y2, editorcolors[col]); + + if ((sprite[j].cstat&256) > 0) + { + drawline16mid(x1,y1+1, x1+x2,y1+y2+1, editorcolors[col]); + drawline16mid(x1,y1-1, x1+x2,y1+y2-1, editorcolors[col]); + drawline16mid(x1-1,y1, x1+x2-1,y1+y2, editorcolors[col]); + drawline16mid(x1+1,y1, x1+x2+1,y1+y2, editorcolors[col]); + + if ((sprite[j].cstat&32) > 0) + { + int32_t fx = mulscale10(mulscale6(tilesizx[sprite[j].picnum], sprite[j].xrepeat),zoome) >> 1; + int32_t fy = mulscale10(mulscale6(tilesizy[sprite[j].picnum], sprite[j].yrepeat),zoome) >> 1; + int32_t co[4][2], ii; + int32_t sinang = sintable[(sprite[j].ang+angofs+1536)&2047]; + int32_t cosang = sintable[(sprite[j].ang+angofs+1024)&2047]; + int32_t r,s; + + co[0][0] = co[3][0] = -fx; + co[0][1] = co[1][1] = -fy; + co[1][0] = co[2][0] = fx; + co[2][1] = co[3][1] = fy; + + for (ii=3; ii>=0; ii--) + { + r = mulscale14(cosang,co[ii][0]) - mulscale14(sinang,co[ii][1]); + s = mulscale14(sinang,co[ii][0]) + mulscale14(cosang,co[ii][1]); + s = scalescreeny(s); + co[ii][0] = r; + co[ii][1] = s; + } + drawlinepat = 0xcfcfcfcf; + for (ii=3; ii>=0; ii--) + { + drawline16mid(x1+co[ii][0], y1-co[ii][1], x1+co[(ii+1)&3][0], y1-co[(ii+1)&3][1], editorcolors[col]); + drawline16mid(x1+co[ii][0], y1-co[ii][1]+1, x1+co[(ii+1)&3][0], y1-co[(ii+1)&3][1]+1, editorcolors[col]); + drawline16mid(x1+co[ii][0], y1-co[ii][1]-1, x1+co[(ii+1)&3][0], y1-co[(ii+1)&3][1]-1, editorcolors[col]); + drawline16mid(x1+co[ii][0]+1, y1-co[ii][1], x1+co[(ii+1)&3][0]+1, y1-co[(ii+1)&3][1], editorcolors[col]); + drawline16mid(x1+co[ii][0]-1, y1-co[ii][1], x1+co[(ii+1)&3][0]-1, y1-co[(ii+1)&3][1], editorcolors[col]); + drawline16mid(x1, y1, x1 + co[(ii+1)&3][0], y1 - co[(ii+1)&3][1], editorcolors[col]); + } + drawlinepat = 0xffffffff; + } + else if ((sprite[j].cstat&16) > 0) + { + int32_t fx = mulscale6(tilesizx[sprite[j].picnum], sprite[j].xrepeat); + int32_t one=(((sprite[j].ang+angofs+256)&512) == 0), no=!one; + + x2 = mulscale11(sintable[(sprite[j].ang+angofs+2560)&2047],zoome) / 6144; + y2 = mulscale11(sintable[(sprite[j].ang+angofs+2048)&2047],zoome) / 6144; + y2 = scalescreeny(y2); + + if (!(sprite[j].cstat&64)) + { + drawline16mid(x1-no,y1-one, x1-x2-no,y1-y2-one, editorcolors[col]); + drawline16mid(x1,y1, x1-x2,y1-y2, editorcolors[col]); + drawline16mid(x1+no,y1+one, x1-x2+no,y1-y2+one, editorcolors[col]); + } + + drawline16mid(x1-no,y1-one, x1+x2-no,y1+y2-one, editorcolors[col]); + drawline16mid(x1,y1, x1+x2,y1+y2, editorcolors[col]); + drawline16mid(x1+no,y1+one, x1+x2+no,y1+y2+one, editorcolors[col]); + + + x2 = mulscale13(sintable[(sprite[j].ang+angofs+1024)&2047],zoome) * fx / 4096; + y2 = mulscale13(sintable[(sprite[j].ang+angofs+512)&2047],zoome) * fx / 4096; + y2 = scalescreeny(y2); + + drawline16mid(x1+1,y1, x1+x2+1,y1+y2, editorcolors[col]); + drawline16mid(x1-1,y1, x1-x2-1,y1-y2, editorcolors[col]); + drawline16mid(x1-1,y1, x1+x2-1,y1+y2, editorcolors[col]); + drawline16mid(x1+1,y1, x1-x2+1,y1-y2, editorcolors[col]); + + drawline16mid(x1,y1, x1-x2,y1-y2, editorcolors[col]); + drawline16mid(x1,y1, x1+x2,y1+y2, editorcolors[col]); + + drawline16mid(x1,y1-1, x1+x2,y1+y2-1, editorcolors[col]); + drawline16mid(x1,y1+1, x1-x2,y1-y2+1, editorcolors[col]); + drawline16mid(x1,y1+1, x1+x2,y1+y2+1, editorcolors[col]); + drawline16mid(x1,y1-1, x1-x2,y1-y2-1, editorcolors[col]); + } + + col += 8; + } + else if ((sprite[j].cstat&16) > 0) + { + int32_t fx = mulscale6(tilesizx[sprite[j].picnum], sprite[j].xrepeat); + + x2 = mulscale11(sintable[(sprite[j].ang+angofs+2560)&2047],zoome) / 6144; + y2 = mulscale11(sintable[(sprite[j].ang+angofs+2048)&2047],zoome) / 6144; + y2 = scalescreeny(y2); + + drawline16mid(x1,y1, x1+x2,y1+y2, editorcolors[col]); + if (!(sprite[j].cstat&64)) + drawline16mid(x1,y1, x1-x2,y1-y2, editorcolors[col]); + + x2 = mulscale13(sintable[(sprite[j].ang+angofs+1024)&2047],zoome) * fx / 4096; + y2 = mulscale13(sintable[(sprite[j].ang+angofs+512)&2047],zoome) * fx / 4096; + y2 = scalescreeny(y2); + + drawline16mid(x1,y1, x1+x2,y1+y2, editorcolors[col]); + drawline16mid(x1,y1, x1-x2,y1-y2, editorcolors[col]); + + col += 8; + } + else if ((sprite[j].cstat&32) > 0) + { + int32_t fx = mulscale10(mulscale6(tilesizx[sprite[j].picnum], sprite[j].xrepeat),zoome) >> 1; + int32_t fy = mulscale10(mulscale6(tilesizy[sprite[j].picnum], sprite[j].yrepeat),zoome) >> 1; + int32_t co[4][2], ii; + int32_t sinang = sintable[(sprite[j].ang+angofs+1536)&2047]; + int32_t cosang = sintable[(sprite[j].ang+angofs+1024)&2047]; + int32_t r,s; + + co[0][0] = co[3][0] = -fx; + co[0][1] = co[1][1] = -fy; + co[1][0] = co[2][0] = fx; + co[2][1] = co[3][1] = fy; + + for (ii=3; ii>=0; ii--) + { + r = mulscale14(cosang,co[ii][0]) - mulscale14(sinang,co[ii][1]); + s = mulscale14(sinang,co[ii][0]) + mulscale14(cosang,co[ii][1]); + s = scalescreeny(s); + co[ii][0] = r; + co[ii][1] = s; + } + + drawlinepat = 0xcfcfcfcf; + for (ii=3; ii>=0; ii--) + { + drawline16mid(x1+co[ii][0], y1-co[ii][1], x1+co[(ii+1)&3][0], y1-co[(ii+1)&3][1], editorcolors[col]); + drawline16mid(x1, y1, x1+co[(ii+1)&3][0], y1-co[(ii+1)&3][1], editorcolors[col]); + } + drawlinepat = 0xffffffff; + } + } +} + // // draw2dscreen // -void draw2dscreen(int32_t posxe, int32_t posye, int16_t ange, int32_t zoome, int16_t gride) +void draw2dscreen(const vec3_t *pos, int16_t ange, int32_t zoome, int16_t gride) { - walltype *wal; - int32_t i, j, xp1, yp1, xp2, yp2; - intptr_t tempint; - char col; + int32_t i, j, x1, y1; + int16_t angofs = m32_sideview ? m32_sideang : 0; + + int32_t posxe=pos->x, posye=pos->y, posze=pos->z; if (qsetmode == 200) return; + setup_sideview_sincos(); + if (m32_sideview && !m32_wallsprite) + { + m32_wallsprite = Bmalloc((MAXWALLS+MAXSPRITES)*sizeof(int16_t)); + m32_sidedist = Bmalloc((MAXWALLS+MAXSPRITES)*sizeof(m32_sidedist[0])); + if (!m32_wallsprite || !m32_sidedist) + { + if (m32_wallsprite) Bfree(m32_wallsprite); + if (m32_sidedist) { Bfree(m32_sidedist); m32_sidedist=NULL; } + initprintf("out of memory!"); + m32_sideview = 0; + } + } + begindrawing(); //{{{ + if (editstatus == 0) { - faketimerhandler(); +// faketimerhandler(); clear2dscreen(); - faketimerhandler(); - draw2dgrid(posxe,posye,ange,zoome,gride); +// faketimerhandler(); + draw2dgrid(posxe,posye,posze,ange,zoome,gride); } faketimerhandler(); - for (i=numwalls-1,wal=&wall[i]; i>=0; i--,wal--) + + m32_swcnt = 0; + + if (!m32_sideview) + for (i=numwalls-1; i>=0; i--) + drawscreen_drawwall(i,posxe,posye,posze,zoome); + else { - int64_t dist,dx,dy; - if (editstatus == 0) - { - if ((show2dwall[i>>3]&pow2char[i&7]) == 0) continue; - j = wal->nextwall; - if ((j >= 0) && (i > j)) - if ((show2dwall[j>>3]&pow2char[j&7]) > 0) continue; - } - else - { - j = wal->nextwall; - if ((j >= 0) && (i > j)) continue; - } - - if (j < 0) - { - col = 15; - if (i == linehighlight) col = (totalclock & 16) ? 15 : 7; - } - else - { - col = 33; - if ((wal->cstat&1) != 0) col = 5; - if (wal->nextwall >= 0 && wal->nextwall < MAXWALLS && ((wal->cstat^wall[wal->nextwall].cstat)&1)) col = 2; - if ((i == linehighlight) || ((linehighlight >= 0) && (i == wall[linehighlight].nextwall))) - if (totalclock & 16) col += (2<<2); - } - - xp1 = mulscale14(wal->x-posxe,zoome); - yp1 = mulscale14(wal->y-posye,zoome); - xp2 = mulscale14(wall[wal->point2].x-posxe,zoome); - yp2 = mulscale14(wall[wal->point2].y-posye,zoome); - - dx=wal->x-wall[wal->point2].x; - dy=wal->y-wall[wal->point2].y; - dist=dx*dx+dy*dy; - - if (dist > 0xffffffff) - { - col=9; - if (i == linehighlight || ((linehighlight >= 0) && (i == wall[linehighlight].nextwall))) - if (totalclock & 16) col -= (2<<2); - } - else if (showfirstwall && searchsector>=0 && (sector[searchsector].wallptr == i || sector[searchsector].wallptr == wall[i].nextwall)) - { - col = 14; - if (i == linehighlight) if (totalclock & 16) col -= (2<<2); - } - else if (circlewall >= 0 && (i == circlewall || wal->nextwall == circlewall)) - col = 14; - - if ((wal->cstat&64) > 0) - { - if (klabs(xp2-xp1) >= klabs(yp2-yp1)) + for (i=0; ix+wall[wal->point2].x)>>1)-posxe,zoome); - int32_t day = mulscale14(((wal->y+wall[wal->point2].y)>>1)-posye,zoome); - - if (wal->nextsector >= 0 && showheightindicators) - { - int32_t ii = sector[sectorofwall(i)].floorz; - int32_t jj = sector[wal->nextsector].floorz; - - if (jj == ii && showheightindicators > 1) - { - int32_t dax3 = mulscale11(sintable[(k+1024)&2047],zoome) / 2560; - int32_t day3 = mulscale11(sintable[(k+512)&2047],zoome) / 2560; - int32_t dax2 = mulscale11(sintable[(k+2048)&2047],zoome) / 2560; - int32_t day2 = mulscale11(sintable[(k+1536)&2047],zoome) / 2560; - drawline16(halfxdim16+dax+dax3,midydim16+day+day3,halfxdim16+dax+dax2,midydim16+day+day2,editorcolors[col]); - } - else if (jj > ii) - { - int32_t dax2 = mulscale11(sintable[(k+1024)&2047],zoome) / 2560; - int32_t day2 = mulscale11(sintable[(k+512)&2047],zoome) / 2560; - drawline16(halfxdim16+dax,midydim16+day,halfxdim16+dax+dax2,midydim16+day+day2,editorcolors[col]); - } - else if (jj < ii) - { - int32_t dax2 = mulscale11(sintable[(k+2048)&2047],zoome) / 2560; - int32_t day2 = mulscale11(sintable[(k+1536)&2047],zoome) / 2560; - drawline16(halfxdim16+dax,midydim16+day,halfxdim16+dax+dax2,midydim16+day+day2,editorcolors[col]); - } - } - else if (showheightindicators > 1) - { - int32_t dax2 = mulscale11(sintable[(k+2048)&2047],zoome) / 2560; - int32_t day2 = mulscale11(sintable[(k+1536)&2047],zoome) / 2560; - drawline16(halfxdim16+dax,midydim16+day,halfxdim16+dax+dax2,midydim16+day+day2,editorcolors[col]); - } + m32_wallsprite[m32_swcnt++] = j; + m32_sidedist[j] = sideview_getdist(j, 0); } - if ((zoome >= 256) && (editstatus == 1)) - if (((halfxdim16+xp1) >= 2) && ((halfxdim16+xp1) <= xdim-3)) - if (((midydim16+yp1) >= 2) && ((midydim16+yp1) <= ydim16-3)) - { - int32_t pointsize = 2; - - if (i == pointhighlight || ((pointhighlight < MAXWALLS) && (pointhighlight >= 0) && - (wall[i].x == wall[pointhighlight].x) && (wall[i].y == wall[pointhighlight].y))) - { - if (totalclock & 16) - pointsize++; - } - else //if (highlightcnt > 0) - { - if (show2dwall[i>>3]&pow2char[i&7]) - { - if (totalclock & 16) - pointsize++; - } - } - - tempint = ((midydim16+yp1)*bytesperline)+(halfxdim16+xp1)+frameplace; - do - drawcircle16(halfxdim16+xp1, midydim16+yp1, pointsize--, editorcolors[15]); - while (pointsize); - } +*/ } + faketimerhandler(); - if ((zoome >= 256) || (editstatus == 0)) + if (zoome >= 256 || editstatus == 0) for (j=0; j=0; j=nextspritesect[j]) - if ((editstatus == 1) || (show2dsprite[j>>3]&pow2char[j&7])) + if (sprite[j].statnum>3]&pow2char[j&7]))) + { + if (!m32_sideview) + drawscreen_drawsprite(j,posxe,posye,posze,zoome); + else { - if (sprite[j].sectnum<0) - col = 4; // red - else - { - col = 3; - if (spritecol2d[sprite[j].picnum][0]) - col = spritecol2d[sprite[j].picnum][0]; - else if ((sprite[j].cstat&1) > 0) - { - col = 5; - if (spritecol2d[sprite[j].picnum][1]) - col = spritecol2d[sprite[j].picnum][1]; - } - } - - if (editstatus == 1) - { - if ((pointhighlight-16384) >= 0 && (j+16384 == pointhighlight || ((sprite[j].x == sprite[pointhighlight-16384].x) && (sprite[j].y == sprite[pointhighlight-16384].y)))) - { - if (totalclock & 32) col += (2<<2); - } - else // if (highlightcnt > 0) - { - if (show2dsprite[j>>3]&pow2char[j&7]) - if (totalclock & 32) col += (2<<2); - } - } - - xp1 = mulscale14(sprite[j].x-posxe,zoome); - yp1 = mulscale14(sprite[j].y-posye,zoome); - if (((halfxdim16+xp1) >= 4) && ((halfxdim16+xp1) <= xdim-6)) - if (((midydim16+yp1) >= 4) && ((midydim16+yp1) <= ydim16-6)) - { - tempint = ((midydim16+yp1)*bytesperline)+(halfxdim16+xp1)+frameplace; - - drawcircle16(halfxdim16+xp1, midydim16+yp1, 4, editorcolors[col]); - - xp2 = mulscale11(sintable[(sprite[j].ang+2560)&2047],zoome) / 768; - yp2 = mulscale11(sintable[(sprite[j].ang+2048)&2047],zoome) / 768; - - drawline16(halfxdim16+xp1,midydim16+yp1,halfxdim16+xp1+xp2,midydim16+yp1+yp2,editorcolors[col]); - - if ((sprite[j].cstat&256) > 0) - { - if (((sprite[j].ang+256)&512) == 0) - { - drawline16(halfxdim16+xp1,midydim16+yp1+1,halfxdim16+xp1+xp2,midydim16+yp1+yp2+1,editorcolors[col]); - drawline16(halfxdim16+xp1,midydim16+yp1-1,halfxdim16+xp1+xp2,midydim16+yp1+yp2-1,editorcolors[col]); - drawline16(halfxdim16+xp1-1,midydim16+yp1,halfxdim16+xp1+xp2-1,midydim16+yp1+yp2,editorcolors[col]); - drawline16(halfxdim16+xp1+1,midydim16+yp1,halfxdim16+xp1+xp2+1,midydim16+yp1+yp2,editorcolors[col]); - - } - else - { - drawline16(halfxdim16+xp1,midydim16+yp1+1,halfxdim16+xp1+xp2,midydim16+yp1+yp2+1,editorcolors[col]); - drawline16(halfxdim16+xp1,midydim16+yp1-1,halfxdim16+xp1+xp2,midydim16+yp1+yp2-1,editorcolors[col]); - drawline16(halfxdim16+xp1-1,midydim16+yp1,halfxdim16+xp1+xp2-1,midydim16+yp1+yp2,editorcolors[col]); - drawline16(halfxdim16+xp1+1,midydim16+yp1,halfxdim16+xp1+xp2+1,midydim16+yp1+yp2,editorcolors[col]); - - } - - if ((sprite[j].cstat&32) > 0) - { - int32_t fx = mulscale10(mulscale6(tilesizx[sprite[j].picnum], sprite[j].xrepeat),zoome) >> 1; - int32_t fy = mulscale10(mulscale6(tilesizy[sprite[j].picnum], sprite[j].yrepeat),zoome) >> 1; - int32_t co[4][2], ii; - int32_t sinang = sintable[(sprite[j].ang+512+1024)&2047]; - int32_t cosang = sintable[(sprite[j].ang+1024)&2047]; - int32_t r,s; - - - co[0][0] = co[3][0] = -fx; - co[0][1] = co[1][1] = -fy; - co[1][0] = co[2][0] = fx; - co[2][1] = co[3][1] = fy; - - for (ii=3; ii>=0; ii--) - { - r = mulscale14(cosang,co[ii][0]) - mulscale14(sinang,co[ii][1]); - s = mulscale14(sinang,co[ii][0]) + mulscale14(cosang,co[ii][1]); - co[ii][0] = r; - co[ii][1] = s; - } - drawlinepat = 0xcfcfcfcf; - for (ii=3; ii>=0; ii--) - { - drawline16(halfxdim16 + xp1 + co[ii][0], midydim16 + yp1 - co[ii][1], - halfxdim16 + xp1 + co[(ii+1)&3][0], midydim16 + yp1 - co[(ii+1)&3][1], - editorcolors[col]); - drawline16(halfxdim16 + xp1 + co[ii][0], midydim16 + yp1 - co[ii][1] + 1, - halfxdim16 + xp1 + co[(ii+1)&3][0], midydim16 + yp1 - co[(ii+1)&3][1] + 1, - editorcolors[col]); - drawline16(halfxdim16 + xp1 + co[ii][0], midydim16 + yp1 - co[ii][1] - 1, - halfxdim16 + xp1 + co[(ii+1)&3][0], midydim16 + yp1 - co[(ii+1)&3][1] - 1, - editorcolors[col]); - drawline16(halfxdim16 + xp1 + co[ii][0] + 1, midydim16 + yp1 - co[ii][1], - halfxdim16 + xp1 + co[(ii+1)&3][0] + 1, midydim16 + yp1 - co[(ii+1)&3][1], - editorcolors[col]); - drawline16(halfxdim16 + xp1 + co[ii][0] - 1, midydim16 + yp1 - co[ii][1], - halfxdim16 + xp1 + co[(ii+1)&3][0] - 1, midydim16 + yp1 - co[(ii+1)&3][1], - editorcolors[col]); - drawline16(halfxdim16 + xp1, midydim16 + yp1, - halfxdim16 + xp1 + co[(ii+1)&3][0], midydim16 + yp1 - co[(ii+1)&3][1], - editorcolors[col]); - } - drawlinepat = 0xffffffff; - } - - else if ((sprite[j].cstat&16) > 0) - { - int32_t fx = mulscale6(tilesizx[sprite[j].picnum], sprite[j].xrepeat); - xp2 = mulscale11(sintable[(sprite[j].ang+2560)&2047],zoome) / 6144; - yp2 = mulscale11(sintable[(sprite[j].ang+2048)&2047],zoome) / 6144; - - - if (((sprite[j].ang+256)&512) == 0) - { - if (!(sprite[j].cstat&64)) - { - drawline16(halfxdim16+xp1,midydim16+yp1-1,halfxdim16+xp1-xp2,midydim16+yp1-yp2-1,editorcolors[col]); - drawline16(halfxdim16+xp1,midydim16+yp1,halfxdim16+xp1-xp2,midydim16+yp1-yp2,editorcolors[col]); - drawline16(halfxdim16+xp1,midydim16+yp1+1,halfxdim16+xp1-xp2,midydim16+yp1-yp2+1,editorcolors[col]); - } - drawline16(halfxdim16+xp1,midydim16+yp1-1,halfxdim16+xp1+xp2,midydim16+yp1+yp2-1,editorcolors[col]); - drawline16(halfxdim16+xp1,midydim16+yp1,halfxdim16+xp1+xp2,midydim16+yp1+yp2,editorcolors[col]); - drawline16(halfxdim16+xp1,midydim16+yp1+1,halfxdim16+xp1+xp2,midydim16+yp1+yp2+1,editorcolors[col]); - xp2 = mulscale13(sintable[(sprite[j].ang+1024)&2047],zoome) * fx / 4096; - yp2 = mulscale13(sintable[(sprite[j].ang+512)&2047],zoome) * fx / 4096; - drawline16(halfxdim16+xp1+1,midydim16+yp1,halfxdim16+xp1+xp2+1,midydim16+yp1+yp2,editorcolors[col]); - drawline16(halfxdim16+xp1-1,midydim16+yp1,halfxdim16+xp1-xp2-1,midydim16+yp1-yp2,editorcolors[col]); - drawline16(halfxdim16+xp1-1,midydim16+yp1,halfxdim16+xp1+xp2-1,midydim16+yp1+yp2,editorcolors[col]); - drawline16(halfxdim16+xp1+1,midydim16+yp1,halfxdim16+xp1-xp2+1,midydim16+yp1-yp2,editorcolors[col]); - - drawline16(halfxdim16+xp1,midydim16+yp1,halfxdim16+xp1-xp2,midydim16+yp1-yp2,editorcolors[col]); - drawline16(halfxdim16+xp1,midydim16+yp1,halfxdim16+xp1+xp2,midydim16+yp1+yp2,editorcolors[col]); - - drawline16(halfxdim16+xp1,midydim16+yp1-1,halfxdim16+xp1+xp2,midydim16+yp1+yp2-1,editorcolors[col]); - drawline16(halfxdim16+xp1,midydim16+yp1+1,halfxdim16+xp1-xp2,midydim16+yp1-yp2+1,editorcolors[col]); - drawline16(halfxdim16+xp1,midydim16+yp1+1,halfxdim16+xp1+xp2,midydim16+yp1+yp2+1,editorcolors[col]); - drawline16(halfxdim16+xp1,midydim16+yp1-1,halfxdim16+xp1-xp2,midydim16+yp1-yp2-1,editorcolors[col]); - } - else - { - if (!(sprite[j].cstat&64)) - { - drawline16(halfxdim16+xp1-1,midydim16+yp1,halfxdim16+xp1-xp2-1,midydim16+yp1-yp2,editorcolors[col]); - drawline16(halfxdim16+xp1,midydim16+yp1,halfxdim16+xp1-xp2,midydim16+yp1-yp2,editorcolors[col]); - drawline16(halfxdim16+xp1+1,midydim16+yp1,halfxdim16+xp1-xp2+1,midydim16+yp1-yp2,editorcolors[col]); - } - drawline16(halfxdim16+xp1-1,midydim16+yp1,halfxdim16+xp1+xp2-1,midydim16+yp1+yp2,editorcolors[col]); - drawline16(halfxdim16+xp1,midydim16+yp1,halfxdim16+xp1+xp2,midydim16+yp1+yp2,editorcolors[col]); - drawline16(halfxdim16+xp1+1,midydim16+yp1,halfxdim16+xp1+xp2+1,midydim16+yp1+yp2,editorcolors[col]); - xp2 = mulscale13(sintable[(sprite[j].ang+1024)&2047],zoome) * fx / 4096; - yp2 = mulscale13(sintable[(sprite[j].ang+512)&2047],zoome) * fx / 4096; - drawline16(halfxdim16+xp1+1,midydim16+yp1,halfxdim16+xp1+xp2+1,midydim16+yp1+yp2,editorcolors[col]); - drawline16(halfxdim16+xp1-1,midydim16+yp1,halfxdim16+xp1-xp2-1,midydim16+yp1-yp2,editorcolors[col]); - drawline16(halfxdim16+xp1-1,midydim16+yp1,halfxdim16+xp1+xp2-1,midydim16+yp1+yp2,editorcolors[col]); - drawline16(halfxdim16+xp1+1,midydim16+yp1,halfxdim16+xp1-xp2+1,midydim16+yp1-yp2,editorcolors[col]); - - drawline16(halfxdim16+xp1,midydim16+yp1,halfxdim16+xp1-xp2,midydim16+yp1-yp2,editorcolors[col]); - drawline16(halfxdim16+xp1,midydim16+yp1,halfxdim16+xp1+xp2,midydim16+yp1+yp2,editorcolors[col]); - - drawline16(halfxdim16+xp1,midydim16+yp1-1,halfxdim16+xp1+xp2,midydim16+yp1+yp2-1,editorcolors[col]); - drawline16(halfxdim16+xp1,midydim16+yp1+1,halfxdim16+xp1-xp2,midydim16+yp1-yp2+1,editorcolors[col]); - drawline16(halfxdim16+xp1,midydim16+yp1+1,halfxdim16+xp1+xp2,midydim16+yp1+yp2+1,editorcolors[col]); - drawline16(halfxdim16+xp1,midydim16+yp1-1,halfxdim16+xp1-xp2,midydim16+yp1-yp2-1,editorcolors[col]); - } - - } - - col += 8; - } - - else if ((sprite[j].cstat&16) > 0) - { - int32_t fx = mulscale6(tilesizx[sprite[j].picnum], sprite[j].xrepeat); - - xp2 = mulscale11(sintable[(sprite[j].ang+2560)&2047],zoome) / 6144; - yp2 = mulscale11(sintable[(sprite[j].ang+2048)&2047],zoome) / 6144; - - drawline16(halfxdim16+xp1,midydim16+yp1,halfxdim16+xp1+xp2,midydim16+yp1+yp2,editorcolors[col]); - if (!(sprite[j].cstat&64)) drawline16(halfxdim16+xp1,midydim16+yp1,halfxdim16+xp1-xp2,midydim16+yp1-yp2,editorcolors[col]); - xp2 = mulscale13(sintable[(sprite[j].ang+1024)&2047],zoome) * fx / 4096; - yp2 = mulscale13(sintable[(sprite[j].ang+512)&2047],zoome) * fx / 4096; - - drawline16(halfxdim16+xp1,midydim16+yp1,halfxdim16+xp1+xp2,midydim16+yp1+yp2,editorcolors[col]); - drawline16(halfxdim16+xp1,midydim16+yp1,halfxdim16+xp1-xp2,midydim16+yp1-yp2,editorcolors[col]); - - - col += 8; - } - - else if ((sprite[j].cstat&32) > 0) - { - int32_t fx = mulscale10(mulscale6(tilesizx[sprite[j].picnum], sprite[j].xrepeat),zoome) >> 1; - int32_t fy = mulscale10(mulscale6(tilesizy[sprite[j].picnum], sprite[j].yrepeat),zoome) >> 1; - int32_t co[4][2], ii; - int32_t sinang = sintable[(sprite[j].ang+512+1024)&2047]; - int32_t cosang = sintable[(sprite[j].ang+1024)&2047]; - int32_t r,s; - - co[0][0] = co[3][0] = -fx; - co[0][1] = co[1][1] = -fy; - co[1][0] = co[2][0] = fx; - co[2][1] = co[3][1] = fy; - - for (ii=3; ii>=0; ii--) - { - r = mulscale14(cosang,co[ii][0]) - mulscale14(sinang,co[ii][1]); - s = mulscale14(sinang,co[ii][0]) + mulscale14(cosang,co[ii][1]); - co[ii][0] = r; - co[ii][1] = s; - } - - drawlinepat = 0xcfcfcfcf; - for (ii=3; ii>=0; ii--) - { - drawline16(halfxdim16 + xp1 + co[ii][0], midydim16 + yp1 - co[ii][1], - halfxdim16 + xp1 + co[(ii+1)&3][0], midydim16 + yp1 - co[(ii+1)&3][1], - editorcolors[col]); - drawline16(halfxdim16 + xp1, midydim16 + yp1, - halfxdim16 + xp1 + co[(ii+1)&3][0], midydim16 + yp1 - co[(ii+1)&3][1], - editorcolors[col]); - } - drawlinepat = 0xffffffff; - } - } + m32_wallsprite[m32_swcnt++] = MAXWALLS+j; + sideview_getdist(MAXWALLS+j, -1); } + } faketimerhandler(); - xp1 = mulscale11(sintable[(ange+2560)&2047],zoome) / 768; //Draw white arrow - yp1 = mulscale11(sintable[(ange+2048)&2047],zoome) / 768; - drawline16(halfxdim16+xp1,midydim16+yp1,halfxdim16-xp1,midydim16-yp1,editorcolors[15]); - drawline16(halfxdim16+xp1,midydim16+yp1,halfxdim16+yp1,midydim16-xp1,editorcolors[15]); - drawline16(halfxdim16+xp1,midydim16+yp1,halfxdim16-yp1,midydim16+xp1,editorcolors[15]); + + if (m32_sideview) + { + qsort(m32_wallsprite, m32_swcnt, sizeof(int16_t), (int(*)(const void *, const void *))&sideview_cmppoints); + + for (i=0; i= 0 && ((bstatus&1) || sectorofwall(linehighlight)==cursectornum)) + else if (linehighlight >= 0 /* && ((bstatus&1) || sectorofwall(linehighlight)==cursectornum)*/) { drawgradient(); showwalldata(linehighlight, 0); @@ -6823,14 +6825,24 @@ static void Keys2d(void) { // PK_ if (numhelppages>0) + { + m32_setkeyfilter(0); IntegratedHelp(); + m32_setkeyfilter(1); + } else printmessage16("m32help.hlp invalid or not found!"); } if (PRESSED_KEYSC(F2)) if (g_numsounds > 0) + { + m32_setkeyfilter(0); SoundDisplay(); + m32_setkeyfilter(1); + } + + // F3: side view toggle (handled in build.c) getpoint(searchx,searchy, &mousxplc,&mousyplc); ppointhighlight = getpointhighlight(mousxplc,mousyplc, ppointhighlight); @@ -7739,6 +7751,11 @@ static int32_t osdcmd_vars_pk(const osdfuncparm_t *parm) m32_osd_tryscript = !m32_osd_tryscript; OSD_Printf("Try M32 script execution on invalid OSD command: %s\n", m32_osd_tryscript?"on":"off"); } + else if (!Bstrcasecmp(parm->name, "sideview_reversehorizrot")) + { + sideview_reversehrot = !sideview_reversehrot; + OSD_Printf("Side view reverse horizontal rotation: %s\n", sideview_reversehrot?"on":"off"); + } else if (!Bstrcasecmp(parm->name, "script_expertmode")) { m32_script_expertmode = !m32_script_expertmode; @@ -8060,6 +8077,7 @@ static int32_t registerosdcommands(void) OSD_RegisterFunction("enableevent", "enableevent ", osdcmd_endisableevent); OSD_RegisterFunction("disableevent", "disableevent ", osdcmd_endisableevent); OSD_RegisterFunction("osd_tryscript", "osd_tryscript: toggles execution of M32 script on invalid OSD command", osdcmd_vars_pk); + OSD_RegisterFunction("sideview_reversehorizrot", "sideview_reversehorizrot: toggles reversion of Q and W keys in side view mode", osdcmd_vars_pk); #ifdef DEBUGGINGAIDS OSD_RegisterFunction("disasm", "disasm [s|e] ", osdcmd_disasm); #endif @@ -9352,7 +9370,7 @@ void ExtPreCheckKeys(void) // just before drawrooms // if (cursectornum >= 0) // fillsector(cursectornum, 31); - if (graphicsmode && zoom >= 256) + if (graphicsmode && !m32_sideview && zoom >= 256) { for (i=ii=0; i= 256*/ && sprite[i].sectnum != MAXSECTORS) - { - if (showambiencesounds==1 && sprite[i].sectnum!=cursectnum) - continue; + { + for (ii=0; ii=0; i=nextspritesect[i]) + if (sprite[i].picnum == MUSICANDSFX /*&& zoom >= 256*/ ) + { + if (showambiencesounds==1 && sprite[i].sectnum!=cursectnum) + continue; - xp1 = mulscale14(sprite[i].x-pos.x,zoom); - yp1 = mulscale14(sprite[i].y-pos.y,zoom); + screencoords(&xp1,&yp1, sprite[i].x-pos.x,sprite[i].y-pos.y, zoom); + if (m32_sideview) + yp1 += getscreenvdisp(sprite[i].z-pos.z, zoom); - radius = mulscale14(sprite[i].hitag,zoom); - col = 6; - if (i+16384 == pointhighlight) - if (totalclock & 32) col += (2<<2); - drawlinepat = 0xf0f0f0f0; - drawcircle16(halfxdim16+xp1, midydim16+yp1, radius, editorcolors[(int32_t)col]); - drawlinepat = 0xffffffff; - // radius = mulscale15(sprite[i].hitag,zoom); - // drawcircle16(halfxdim16+xp1, midydim16+yp1, radius, col); - } + radius = mulscale14(sprite[i].hitag,zoom); + col = 6; + if (i+16384 == pointhighlight) + if (totalclock & 32) col += (2<<2); + drawlinepat = 0xf0f0f0f0; + drawcircle16(halfxdim16+xp1, midydim16+yp1, radius, scalescreeny(16384), editorcolors[(int32_t)col]); + drawlinepat = 0xffffffff; + // radius = mulscale15(sprite[i].hitag,zoom); + // drawcircle16(halfxdim16+xp1, midydim16+yp1, radius, col); + } + } enddrawing(); } diff --git a/polymer/eduke32/source/m32def.c b/polymer/eduke32/source/m32def.c index e89777c92..35e3f4694 100644 --- a/polymer/eduke32/source/m32def.c +++ b/polymer/eduke32/source/m32def.c @@ -409,8 +409,10 @@ const char *keyw[] = "drawline16", "drawline16b", + "drawline16z", "drawcircle16", "drawcircle16b", + "drawcircle16z", "rotatesprite16", "rotatesprite", "setgamepalette", @@ -3401,14 +3403,21 @@ repeatcase: case CON_DRAWLINE16: case CON_DRAWLINE16B: + case CON_DRAWLINE16Z: case CON_DRAWCIRCLE16: case CON_DRAWCIRCLE16B: + case CON_DRAWCIRCLE16Z: if (cs.parsingEventOfs < 0 && cs.currentStateIdx < 0) { C_ReportError(ERROR_EVENTONLY); g_numCompilerErrors++; } - C_GetManyVars((tw==CON_DRAWLINE16||tw==CON_DRAWLINE16B) ? 5 : 4); + if (tw==CON_DRAWLINE16 || tw==CON_DRAWLINE16B || tw==CON_DRAWCIRCLE16Z) + C_GetManyVars(5); + else if (tw==CON_DRAWLINE16Z) + C_GetManyVars(7); + else + C_GetManyVars(4); break; case CON_ROTATESPRITE16: diff --git a/polymer/eduke32/source/m32def.h b/polymer/eduke32/source/m32def.h index 0a46d21d0..1a3c0b816 100644 --- a/polymer/eduke32/source/m32def.h +++ b/polymer/eduke32/source/m32def.h @@ -531,8 +531,10 @@ enum ScriptKeywords_t /// CON_DIGITALNUMBERZ, CON_DRAWLINE16, CON_DRAWLINE16B, + CON_DRAWLINE16Z, CON_DRAWCIRCLE16, CON_DRAWCIRCLE16B, + CON_DRAWCIRCLE16Z, CON_ROTATESPRITE16, CON_ROTATESPRITE, CON_SETGAMEPALETTE, diff --git a/polymer/eduke32/source/m32exec.c b/polymer/eduke32/source/m32exec.c index f13dcb4dc..936d87b22 100644 --- a/polymer/eduke32/source/m32exec.c +++ b/polymer/eduke32/source/m32exec.c @@ -2822,19 +2822,27 @@ dodefault: // ^^^ case CON_DRAWLINE16: case CON_DRAWLINE16B: + case CON_DRAWLINE16Z: insptr++; { int32_t x1=Gv_GetVarX(*insptr++), y1=Gv_GetVarX(*insptr++); + int32_t z1=tw==CON_DRAWLINE16Z?Gv_GetVarX(*insptr++):0; int32_t x2=Gv_GetVarX(*insptr++), y2=Gv_GetVarX(*insptr++); + int32_t z2=tw==CON_DRAWLINE16Z?Gv_GetVarX(*insptr++):0; int32_t col=Gv_GetVarX(*insptr++), odrawlinepat=drawlinepat; int32_t xofs=0, yofs=0; - if (tw==CON_DRAWLINE16B) + if (tw==CON_DRAWLINE16B || tw==CON_DRAWLINE16Z) { - x1 = mulscale14(x1-pos.x,zoom); - y1 = mulscale14(y1-pos.y,zoom); - x2 = mulscale14(x2-pos.x,zoom); - y2 = mulscale14(y2-pos.y,zoom); + screencoords(&x1,&y1, x1-pos.x,y1-pos.y, zoom); + screencoords(&x2,&y2, x2-pos.x,y2-pos.y, zoom); + + if (tw==CON_DRAWLINE16Z && m32_sideview) + { + y1 += getscreenvdisp(z1-pos.z,zoom); + y2 += getscreenvdisp(z2-pos.z,zoom); + } + xofs = halfxdim16; yofs = midydim16; } @@ -2847,24 +2855,28 @@ dodefault: case CON_DRAWCIRCLE16: case CON_DRAWCIRCLE16B: + case CON_DRAWCIRCLE16Z: insptr++; { int32_t x1=Gv_GetVarX(*insptr++), y1=Gv_GetVarX(*insptr++); + int32_t z1 = tw==CON_DRAWCIRCLE16Z ? Gv_GetVarX(*insptr++) : 0; int32_t r=Gv_GetVarX(*insptr++); int32_t col=Gv_GetVarX(*insptr++), odrawlinepat=drawlinepat; - int32_t xofs=0, yofs=0; + int32_t xofs=0, yofs=0, eccen=16384; if (tw==CON_DRAWCIRCLE16B) { - x1 = mulscale14(x1-pos.x,zoom); - y1 = mulscale14(y1-pos.y,zoom); + screencoords(&x1,&y1, x1-pos.x,y1-pos.y, zoom); + if (m32_sideview) + y1 += getscreenvdisp(z1, zoom); r = mulscale14(r,zoom); + eccen = scalescreeny(eccen); xofs = halfxdim16; yofs = midydim16; } drawlinepat = m32_drawlinepat; - drawcircle16(xofs+x1, yofs+y1, r, col>=0?editorcolors[col&15]:(-col&255)); + drawcircle16(xofs+x1, yofs+y1, r, eccen, col>=0?editorcolors[col&15]:(-col&255)); drawlinepat = odrawlinepat; continue; } diff --git a/polymer/eduke32/source/m32vars.c b/polymer/eduke32/source/m32vars.c index a643e367e..b98f32794 100644 --- a/polymer/eduke32/source/m32vars.c +++ b/polymer/eduke32/source/m32vars.c @@ -617,6 +617,7 @@ static void Gv_AddSystemVars(void) Gv_NewVar("halfxdim16", (intptr_t)&halfxdim16, GAMEVAR_READONLY | GAMEVAR_INTPTR | GAMEVAR_SYSTEM); Gv_NewVar("midydim16", (intptr_t)&midydim16, GAMEVAR_READONLY | GAMEVAR_INTPTR | GAMEVAR_SYSTEM); Gv_NewVar("ydim16",(intptr_t)&ydim16, GAMEVAR_INTPTR | GAMEVAR_SYSTEM | GAMEVAR_READONLY); + Gv_NewVar("m32_sideview",(intptr_t)&m32_sideview, GAMEVAR_INTPTR | GAMEVAR_SYSTEM | GAMEVAR_READONLY); Gv_NewVar("SV1",(intptr_t)&m32_sortvar1, GAMEVAR_INTPTR | GAMEVAR_SYSTEM | GAMEVAR_READONLY); Gv_NewVar("SV2",(intptr_t)&m32_sortvar2, GAMEVAR_INTPTR | GAMEVAR_SYSTEM | GAMEVAR_READONLY);