From c93096e938ae68693ff8d5ba486a5d89c9623798 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Fri, 14 Dec 2012 19:28:17 +0000 Subject: [PATCH] Factor out multiply repeated code into calc_ylookup(). git-svn-id: https://svn.eduke32.com/eduke32@3291 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/include/baselayer.h | 2 ++ polymer/eduke32/build/src/baselayer.c | 17 +++++++++++++++++ polymer/eduke32/build/src/engine.c | 19 ++++++++----------- polymer/eduke32/build/src/sdlayer.c | 7 ++----- polymer/eduke32/build/src/winlayer.c | 8 +------- 5 files changed, 30 insertions(+), 23 deletions(-) diff --git a/polymer/eduke32/build/include/baselayer.h b/polymer/eduke32/build/include/baselayer.h index ebf057372..33456dc16 100644 --- a/polymer/eduke32/build/include/baselayer.h +++ b/polymer/eduke32/build/include/baselayer.h @@ -40,6 +40,8 @@ extern char offscreenrendering; extern void (*baselayer_onvideomodechange)(int32_t); +void calc_ylookup(int32_t bpl, int32_t lastyidx); + #ifdef USE_OPENGL void fullscreen_tint_gl(uint8_t r, uint8_t g, uint8_t b, uint8_t f); extern int32_t osdcmd_glinfo(const osdfuncparm_t *parm); diff --git a/polymer/eduke32/build/src/baselayer.c b/polymer/eduke32/build/src/baselayer.c index 5479ef1d9..8a3c8c535 100644 --- a/polymer/eduke32/build/src/baselayer.c +++ b/polymer/eduke32/build/src/baselayer.c @@ -5,6 +5,7 @@ #include "renderlayer.h" +#include "a.h" #include "polymost.h" // input @@ -126,6 +127,22 @@ void readjoybstatus(int32_t *b) *b = joyb; } +// Calculate ylookup[] and call setvlinebpl() +void calc_ylookup(int32_t bpl, int32_t lastyidx) +{ + int32_t i, j=0; + + Bassert(lastyidx <= MAXYDIM); + + for (i=0; i<=lastyidx; i++) + { + ylookup[i] = j; + j += bpl; + } + + setvlinebpl(bpl); +} + #ifdef USE_OPENGL void fullscreen_tint_gl(uint8_t r, uint8_t g, uint8_t b, uint8_t f) { diff --git a/polymer/eduke32/build/src/engine.c b/polymer/eduke32/build/src/engine.c index 4ed8fc0e5..d7fbc6b03 100644 --- a/polymer/eduke32/build/src/engine.c +++ b/polymer/eduke32/build/src/engine.c @@ -10312,7 +10312,7 @@ int32_t saveboard(const char *filename, const vec3_t *dapos, int16_t daang, int1 extern char videomodereset; int32_t setgamemode(char davidoption, int32_t daxdim, int32_t daydim, int32_t dabpp) { - int32_t i, j; + int32_t j; #ifdef USE_OPENGL extern char nogl; @@ -10370,9 +10370,7 @@ int32_t setgamemode(char davidoption, int32_t daxdim, int32_t daydim, int32_t da //Force drawrooms to call dosetaspect & recalculate stuff oxyaspect = oxdimen = oviewingrange = -1; - setvlinebpl(bytesperline); - j = 0; - for (i=0; i<=ydim; i++) ylookup[i] = j, j += bytesperline; + calc_ylookup(bytesperline, ydim); setview(0L,0L,xdim-1,ydim-1); clearallviews(0L); @@ -14066,8 +14064,6 @@ char getpixel(int32_t x, int32_t y) // void setviewtotile(int16_t tilenume, int32_t xsiz, int32_t ysiz) { - int32_t i, j; - //DRAWROOMS TO TILE BACKUP&SET CODE tilesizx[tilenume] = xsiz; tilesizy[tilenume] = ysiz; bakxsiz[setviewcnt] = xsiz; bakysiz[setviewcnt] = ysiz; @@ -14089,8 +14085,8 @@ void setviewtotile(int16_t tilenume, int32_t xsiz, int32_t ysiz) offscreenrendering = 1; setview(0,0,ysiz-1,xsiz-1); setaspect(65536,65536); - j = 0; for (i=0; i<=xsiz; i++) { ylookup[i] = j, j += ysiz; } - setvlinebpl(ysiz); + + calc_ylookup(ysiz, xsiz); } @@ -14100,7 +14096,7 @@ void setviewtotile(int16_t tilenume, int32_t xsiz, int32_t ysiz) extern char modechange; void setviewback(void) { - int32_t i, j, k; + int32_t k; if (setviewcnt <= 0) return; setviewcnt--; @@ -14119,12 +14115,13 @@ void setviewback(void) copybufbyte(&bakumost[windowx1],&startumost[windowx1],(windowx2-windowx1+1)*sizeof(startumost[0])); copybufbyte(&bakdmost[windowx1],&startdmost[windowx1],(windowx2-windowx1+1)*sizeof(startdmost[0])); frameplace = bakframeplace[setviewcnt]; + if (setviewcnt == 0) k = bakxsiz[0]; else k = max(bakxsiz[setviewcnt-1],bakxsiz[setviewcnt]); - j = 0; for (i=0; i<=k; i++) ylookup[i] = j, j += bytesperline; - setvlinebpl(bytesperline); + calc_ylookup(bytesperline, k); + modechange=1; } diff --git a/polymer/eduke32/build/src/sdlayer.c b/polymer/eduke32/build/src/sdlayer.c index 6ef9e7ae0..5eb9c562c 100644 --- a/polymer/eduke32/build/src/sdlayer.c +++ b/polymer/eduke32/build/src/sdlayer.c @@ -1662,8 +1662,6 @@ void resetvideomode(void) // void begindrawing(void) { - int32_t i,j; - if (bpp > 8) { if (offscreenrendering) return; @@ -1685,10 +1683,9 @@ void begindrawing(void) if (sdl_surface->pitch != bytesperline || modechange) { bytesperline = sdl_surface->pitch; - setvlinebpl(bytesperline); - j = 0; - for (i=0; i<=ydim; i++) ylookup[i] = j, j += bytesperline; + calc_ylookup(bytesperline, ydim); + modechange=0; } } diff --git a/polymer/eduke32/build/src/winlayer.c b/polymer/eduke32/build/src/winlayer.c index 0ca387d25..1e675bf19 100644 --- a/polymer/eduke32/build/src/winlayer.c +++ b/polymer/eduke32/build/src/winlayer.c @@ -1908,13 +1908,7 @@ void begindrawing(void) bytesperline = xres|1; } - setvlinebpl(bytesperline); - - { - int32_t i = 0, j = 0; - for (; i<=ydim; i++) - ylookup[i] = j, j += bytesperline; - } + calc_ylookup(bytesperline, ydim); }