From 21e9125f2dcd048a19495946b7984b1066116e55 Mon Sep 17 00:00:00 2001 From: terminx Date: Fri, 10 Jul 2015 21:19:41 +0000 Subject: [PATCH] Mapster32: 2d mode performance improvements git-svn-id: https://svn.eduke32.com/eduke32@5290 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/src/a-c.c | 42 +++--- polymer/eduke32/build/src/build.c | 41 ++--- polymer/eduke32/build/src/engine.c | 233 ++++++++++++++--------------- polymer/eduke32/source/astub.c | 47 +++--- 4 files changed, 166 insertions(+), 197 deletions(-) diff --git a/polymer/eduke32/build/src/a-c.c b/polymer/eduke32/build/src/a-c.c index 91174bfc1..3d1ea261d 100644 --- a/polymer/eduke32/build/src/a-c.c +++ b/polymer/eduke32/build/src/a-c.c @@ -65,33 +65,31 @@ void hlineasm4(int32_t cnt, int32_t skiploadincs, int32_t paloffs, uint32_t by, { if (!skiploadincs) { gbxinc = asm1; gbyinc = asm2; } - { - const char *const A_C_RESTRICT palptr = &ghlinepal[paloffs]; - const char *const A_C_RESTRICT buf = gbuf; - const int32_t bxinc = gbxinc, byinc = gbyinc; - const int32_t logx = glogx, logy = glogy; - char *pp = (char *)p; - const uint8_t logx32 = 32-logx, logy32 = 32-logy; + const char *const A_C_RESTRICT palptr = &ghlinepal[paloffs]; + const char *const A_C_RESTRICT buf = gbuf; + const vec2_t inc ={ gbxinc, gbyinc }; + const vec2_t log ={ glogx, glogy }; + const vec2_t log32 ={ 32-log.x, 32-log.y }; + char *pp = (char *)p; #ifdef CLASSIC_SLICE_BY_4 - for (; cnt>=4; cnt-=4, pp-=4) - { - *pp = palptr[buf[((bx>>logx32)<>logy32)]]; - *(pp-1) = palptr[buf[(((bx-bxinc)>>logx32)<>logy32)]]; - *(pp-2) = palptr[buf[(((bx-(bxinc<<1))>>logx32)<>logy32)]]; - *(pp-3) = palptr[buf[(((bx-(bxinc*3))>>logx32)<>logy32)]]; + for (; cnt>=4; cnt-=4, pp-=4) + { + *pp = palptr[buf[((bx>>log32.x)<>log32.y)]]; + *(pp-1) = palptr[buf[(((bx-inc.x)>>log32.x)<>log32.y)]]; + *(pp-2) = palptr[buf[(((bx-(inc.x<<1))>>log32.x)<>log32.y)]]; + *(pp-3) = palptr[buf[(((bx-(inc.x*3))>>log32.x)<>log32.y)]]; - bx -= bxinc<<2; - by -= byinc<<2; - } + bx -= inc.x<<2; + by -= inc.y<<2; + } #endif - for (; cnt>=0; cnt--, pp--) - { - *pp = palptr[buf[((bx>>logx32)<>logy32)]]; - bx -= bxinc; - by -= byinc; - } + for (; cnt>=0; cnt--, pp--) + { + *pp = palptr[buf[((bx>>log32.x)<>log32.y)]]; + bx -= inc.x; + by -= inc.y; } } diff --git a/polymer/eduke32/build/src/build.c b/polymer/eduke32/build/src/build.c index 5db9906d5..39d9eb5c8 100644 --- a/polymer/eduke32/build/src/build.c +++ b/polymer/eduke32/build/src/build.c @@ -44,9 +44,9 @@ static void CallExtSetupMapFilename(const char *mapname); static void CallExtLoadMap(const char *mapname); static int32_t CallExtPreSaveMap(void); static void CallExtSaveMap(const char *mapname); -static const char *CallExtGetSectorCaption(int16_t sectnum); -static const char *CallExtGetWallCaption(int16_t wallnum); -static const char *CallExtGetSpriteCaption(int16_t spritenum); +static inline const char *CallExtGetSectorCaption(int16_t sectnum) { return ExtGetSectorCaption(sectnum); } +static inline const char *CallExtGetWallCaption(int16_t wallnum) { return ExtGetWallCaption(wallnum); } +static inline const char *CallExtGetSpriteCaption(int16_t spritenum) { return ExtGetSpriteCaption(spritenum); } static void CallExtShowSectorData(int16_t sectnum); static void CallExtShowWallData(int16_t wallnum); static void CallExtShowSpriteData(int16_t spritenum); @@ -3253,24 +3253,21 @@ static void isc_transform(int32_t *x, int32_t *y) static void drawspritelabel(int i) { const char *dabuffer = CallExtGetSpriteCaption(i); - if (dabuffer[0] != 0) - { - int const blocking = (sprite[i].cstat & 1); - int col = spritecol2d[sprite[i].picnum][0] ? editorcolors[spritecol2d[sprite[i].picnum][0]] : getspritecol(i); + if (!dabuffer[0]) + return; - if (col == -1) - col = editorcolors[3]; +// int const blocking = (sprite[i].cstat & 1); - if ((i == pointhighlight - 16384) && (totalclock & 32)) - col += 4; + int col = spritecol2d[sprite[i].picnum][0] ? editorcolors[spritecol2d[sprite[i].picnum][0]] : getspritecol(i); - if (sprite[i].sectnum < 0) - col = editorcolors[4]; // red + if ((i == pointhighlight - 16384) && (totalclock & 32)) + col += 4; + else if (sprite[i].sectnum < 0) + col = editorcolors[4]; // red - drawsmallabel(dabuffer, editorcolors[0], col, /*blocking ? editorcolors[5] :*/ col - 3, - sprite[i].x, sprite[i].y, sprite[i].z); - } + drawsmallabel(dabuffer, editorcolors[0], col, /*blocking ? editorcolors[5] :*/ col - 3, + sprite[i].x, sprite[i].y, sprite[i].z); } #define EDITING_MAP_P() (newnumwalls>=0 || joinsector[0]>=0 || circlewall>=0 || (bstatus&1) || isc.active) @@ -11080,18 +11077,6 @@ static void CallExtSaveMap(const char *mapname) saveboard("backup.map", &pos, ang, cursectnum); VM_OnEvent(EVENT_SAVEMAP, -1); } -static const char *CallExtGetSectorCaption(int16_t sectnum) -{ - return ExtGetSectorCaption(sectnum); -} -static const char *CallExtGetWallCaption(int16_t wallnum) -{ - return ExtGetWallCaption(wallnum); -} -static const char *CallExtGetSpriteCaption(int16_t spritenum) -{ - return ExtGetSpriteCaption(spritenum); -} static void CallExtShowSectorData(int16_t sectnum) { ExtShowSectorData(sectnum); diff --git a/polymer/eduke32/build/src/engine.c b/polymer/eduke32/build/src/engine.c index c6226f4d0..dad067f12 100644 --- a/polymer/eduke32/build/src/engine.c +++ b/polymer/eduke32/build/src/engine.c @@ -16483,145 +16483,124 @@ uint32_t drawlinepat = 0xffffffff; 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; - intptr_t p; - //int32_t odx,ody; //int32_t ox1=x1,oy1=y1, ox2=x2,oy2=y2; - dx = x2-x1; - dy = y2-y1; + vec2_t d ={ x2-x1, y2-y1 }; //odx=dx; //ody=dy; - if (dx >= 0) + if (d.x < 0) { - 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 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; - } + swaplong(&x1, &x2); + swaplong(&y1, &y2); } - if (dy >= 0) + if (x1 >= xres || x2 < 0) + return 0; + + if (x1 < 0) { - if (y1 >= ydim16 || y2 < 0) - return 0; - if (y1 < 0) - { - if (dx) x1 += scale(0-y1,dx,dy); - y1 = 0; - x1 = clamp(x1, 0, xres-1); - } - if (y2 >= ydim16) - { - if (dx) x2 += scale(ydim16-1-y2,dx,dy); - y2 = ydim16-1; - x2 = clamp(x2, 0, xres-1); - } + if (d.y) y1 += scale(0-x1,d.y,d.x); + x1 = 0; } - else + + if (x2 >= xres) { - if (y2 >= ydim16 || y1 < 0) - return 0; - if (y2 < 0) - { - if (dx) x2 += scale(0-y2,dx,dy); - y2 = 0; - x2 = clamp(x2, 0, xres-1); - } - if (y1 >= ydim16) - { - if (dx) x1 += scale(ydim16-1-y1,dx,dy); - y1 = ydim16-1; - x1 = clamp(x1, 0, xres-1); - } + if (d.y) y2 += scale(xres-1-x2,d.y,d.x); + x2 = xres-1; + } + + if ((d.x < 0 && d.y >= 0) || (d.y < 0 && d.x >= 0)) + { + swaplong(&x1, &x2); + swaplong(&y1, &y2); + } + + if (y1 >= ydim16 || y2 < 0) + return 0; + + if (y1 < 0) + { + if (d.x) x1 += scale(0-y1,d.x,d.y); + y1 = 0; + x1 = clamp(x1, 0, xres-1); + } + + if (y2 >= ydim16) + { + if (d.x) x2 += scale(ydim16-1-y2,d.x,d.y); + y2 = ydim16-1; + x2 = clamp(x2, 0, xres-1); + } + + if (d.y < 0) + { + swaplong(&x1, &x2); + swaplong(&y1, &y2); } //if (ox1||ox2||oy1||oy2) // if (x1<0||x1>=xres || y2<0||y2>=yres) // attach_here(); - dx = klabs(x2-x1)+1; dy = klabs(y2-y1)+1; - if (dx >= dy) + d.x = klabs(x2-x1)+1; + d.y = klabs(y2-y1)+1; + + if ((d.x >= d.y && x2 < x1) || (d.x < d.y && y2 < y1)) { - if (x2 < x1) - { - i = x1; x1 = x2; x2 = i; - i = y1; y1 = y2; y2 = i; - } - d = 0; - if (y2 > y1) pinc = bytesperline; else pinc = -bytesperline; - - begindrawing(); //{{{ - p = (y1*bytesperline)+x1+frameplace; - if (dy == 0 && drawlinepat == 0xffffffff) - { - i = ((int32_t)col<<24)|((int32_t)col<<16)|((int32_t)col<<8)|col; - clearbufbyte((void *)p, dx, i); - } - else - for (i=dx; i>0; i--) - { - if (drawlinepat & pow2long[(patc++)&31]) - drawpixel((char *)p, col); - d += dy; - if (d >= dx) { d -= dx; p += pinc; } - p++; - } - enddrawing(); //}}} - - return 1; + swaplong(&x1, &x2); + swaplong(&y1, &y2); } - if (y2 < y1) - { - i = x1; x1 = x2; x2 = i; - i = y1; y1 = y2; y2 = i; - } - d = 0; - if (x2 > x1) pinc = 1; else pinc = -1; + int df = 0; + uint32_t patc=UINT_MAX; + int pinc, inc = 1; begindrawing(); //{{{ - p = (y1*bytesperline)+x1+frameplace; - for (i=dy; i>0; i--) + + intptr_t p = (y1*bytesperline)+x1+frameplace; + + if (d.x >= d.y) { - if (drawlinepat & pow2long[(patc++)&31]) - drawpixel((char *)p, col); - d += dx; - if (d >= dy) { d -= dy; p += pinc; } - p += bytesperline; + pinc = (y2 > y1) ? bytesperline : -bytesperline; } + else + { + pinc = (x2 > x1) ? 1 : -1; + swaplong(&d.x, &d.y); + inc = bytesperline; + } + + if (inc == 1 && d.y == 1 && drawlinepat == 0xffffffff) + clearbufbyte((void *)p, d.x, ((int32_t) col<<24)|((int32_t) col<<16)|((int32_t) col<<8)|col); + else if (drawlinepat == 0xffffffff) + { + for (int i=d.x; i>0; i--) + { + drawpixel((char *) p, col); + df += d.y; + if (df >= d.x) { df -= d.x; p += pinc; } + p += inc; + } + } + else + for (int i=d.x; i>0; i--) + { + if (drawlinepat & pow2long[(++patc)&31]) + drawpixel((char *) p, col); + df += d.y; + if (df >= d.x) { df -= d.x; p += pinc; } + p += inc; + } + enddrawing(); //}}} return 1; } -static void drawline16mid(int32_t x1, int32_t y1, int32_t x2, int32_t y2, char col) +FORCE_INLINE void drawline16mid(int32_t x1, int32_t y1, int32_t x2, int32_t y2, char col) { drawline16(halfxdim16+x1,midydim16+y1, halfxdim16+x2,midydim16+y2, col); } @@ -17246,7 +17225,7 @@ int32_t getspritecol(int32_t spr) if (tilecols[picnum]) return palookup[pal][tilecols[picnum]]; if (!waloff[picnum]) loadtile(picnum); - if (!waloff[picnum]) return -1; + if (!waloff[picnum]) return editorcolors[3]; uint32_t cols[256]; @@ -17284,12 +17263,8 @@ static void drawscreen_drawsprite(int32_t j, int32_t posxe, int32_t posye, int32 if (spritecol2d[sprite[j].picnum][0]) col = spritecol2d[sprite[j].picnum][0]; else - { col = getspritecol(j); - if (col == -1) col = editorcolors[3]; - } - /* else if ((sprite[j].cstat&1) > 0) { @@ -17725,20 +17700,34 @@ int32_t printext16(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol, con letptr = &fontptr[name[i]<<3]; ptr = (char *)(bytesperline*ypos + (stx-(fontsize&1)) + frameplace); - for (y=ymin; y<=ymax; y++) + + if (backcol >= 0) { - for (x=0; x= xdim || ptr < (char *)frameplace) - continue; - if (letptr[y]&pow2char[7-(fontsize&1)-x]) - ptr[x] = (uint8_t)col; - else if (backcol >= 0) - ptr[x] = (uint8_t)backcol; + for (x=0; x= (unsigned)xdim || ptr < (char *) frameplace) break; + ptr[x] = (letptr[y]&pow2char[7-(fontsize&1)-x]) ? (uint8_t) col : (uint8_t) backcol; + } + ptr += bytesperline; } - ptr += bytesperline; } + else + { + for (y=ymin; y<=ymax; y++) + { + for (x=0; x= (unsigned)xdim || ptr < (char *) frameplace) break; + ptr[x] = (letptr[y]&pow2char[7-(fontsize&1)-x]) ? (uint8_t) col : ptr[x]; + } + ptr += bytesperline; + } + } + stx += charxsiz; + if (stx >= xdim) break; } diff --git a/polymer/eduke32/source/astub.c b/polymer/eduke32/source/astub.c index aa253196b..19f549bdf 100644 --- a/polymer/eduke32/source/astub.c +++ b/polymer/eduke32/source/astub.c @@ -623,9 +623,7 @@ int32_t taglab_getnextfreetag(int32_t *duetoptr) static void taglab_handle1(int32_t linktagp, int32_t tagnum, char *buf) { - const char *label = NULL; - if (linktagp && showtags==2) - label = taglab_getlabel(tagnum); + char const * const label = (linktagp && showtags==2) ? taglab_getlabel(tagnum) : NULL; if (label) Bsprintf(buf, "%d<%s>", tagnum, label); @@ -901,38 +899,37 @@ const char *ExtGetSpriteCaption(int16_t spritenum) SpriteName(spritenum,lo); if (lo[0]!=0) { + Bsprintf(tempbuf,"%s",lo); + if (sprite[spritenum].pal==1) - Bsprintf(tempbuf,"%s (MULTIPLAYER)",lo); - else - Bsprintf(tempbuf,"%s",lo); + Bstrcat(tempbuf," (MULTIPLAYER)"); } return tempbuf; } + char histr[TAGLAB_MAX+16], lostr[TAGLAB_MAX+16]; + + taglab_handle1(lt&2, sprite[spritenum].hitag, histr); + + if (sprite[spritenum].picnum==SECTOREFFECTOR) { - char histr[TAGLAB_MAX+16], lostr[TAGLAB_MAX+16]; - - taglab_handle1(lt&2, sprite[spritenum].hitag, histr); - - if (sprite[spritenum].picnum==SECTOREFFECTOR) + if (onnames!=8) { - if (onnames!=8) - { - Bsprintf(lo,"%s",SectorEffectorText(spritenum)); - Bsprintf(tempbuf,"%s, %s",lo, histr); - } + Bsprintf(lo,"%s",SectorEffectorText(spritenum)); + Bsprintf(tempbuf,"%s, %s",lo, histr); } + } + else + { + taglab_handle1(lt&1, sprite[spritenum].lotag, lostr); + + SpriteName(spritenum,lo); + + if (sprite[spritenum].extra != -1) + Bsprintf(tempbuf,"%s,%s,%d %s", histr, lostr, TrackerCast(sprite[spritenum].extra), lo); else - { - taglab_handle1(lt&1, sprite[spritenum].lotag, lostr); - - SpriteName(spritenum,lo); - if (sprite[spritenum].extra != -1) - Bsprintf(tempbuf,"%s,%s,%d %s", histr, lostr, TrackerCast(sprite[spritenum].extra), lo); - else - Bsprintf(tempbuf,"%s,%s %s", histr, lostr, lo); - } + Bsprintf(tempbuf,"%s,%s %s", histr, lostr, lo); } return tempbuf;