From 2fc6e2e6b0412d82cae3f93c22c94d5a459e07d1 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Sat, 26 May 2012 21:58:21 +0000 Subject: [PATCH] Various cleanup and rewrites. - make allocatepermanenttile() return intptr_t - the usual git-svn-id: https://svn.eduke32.com/eduke32@2697 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/include/build.h | 2 +- polymer/eduke32/build/src/engine.c | 17 +--- polymer/eduke32/source/game.c | 126 ++++++++++++++------------ polymer/eduke32/source/premap.c | 3 +- polymer/eduke32/source/sector.c | 5 +- 5 files changed, 77 insertions(+), 76 deletions(-) diff --git a/polymer/eduke32/build/include/build.h b/polymer/eduke32/build/include/build.h index 3c42eb045..abe4e7e1a 100644 --- a/polymer/eduke32/build/include/build.h +++ b/polymer/eduke32/build/include/build.h @@ -575,7 +575,7 @@ void set_picsizanm(int32_t picnum, int16_t dasizx, int16_t dasizy, int32_t daanm int32_t loadpics(const char *filename, int32_t askedsize); void loadtile(int16_t tilenume); int32_t qloadkvx(int32_t voxindex, const char *filename); -int32_t allocatepermanenttile(int16_t tilenume, int32_t xsiz, int32_t ysiz); +intptr_t allocatepermanenttile(int16_t tilenume, int32_t xsiz, int32_t ysiz); //void copytilepiece(int32_t tilenume1, int32_t sx1, int32_t sy1, int32_t xsiz, int32_t ysiz, int32_t tilenume2, int32_t sx2, int32_t sy2); void makepalookup(int32_t palnum, const char *remapbuf, int8_t r, int8_t g, int8_t b, char dastat); //void setvgapalette(void); diff --git a/polymer/eduke32/build/src/engine.c b/polymer/eduke32/build/src/engine.c index ba5de952b..08849acbe 100644 --- a/polymer/eduke32/build/src/engine.c +++ b/polymer/eduke32/build/src/engine.c @@ -7233,8 +7233,8 @@ static void dosetaspect(void) for (i=0; i>16); x += xinc; - if (j != 0) j = mulscale16((int32_t)radarang[k+1]-(int32_t)radarang[k],j); - radarang2[i] = (int16_t)(((int32_t)radarang[k]+j)>>6); + if (j != 0) j = mulscale16(radarang[k+1]-radarang[k], j); + radarang2[i] = (int16_t)((radarang[k]+j)>>6); } for (i=1; i<(int32_t)(sizeof(distrecip)/sizeof(distrecip[0])); i++) distrecip[i] = divscale20(xdimen,i); @@ -10537,9 +10537,9 @@ void loadtile(int16_t tilenume) // // allocatepermanenttile // -int32_t allocatepermanenttile(int16_t tilenume, int32_t xsiz, int32_t ysiz) +intptr_t allocatepermanenttile(int16_t tilenume, int32_t xsiz, int32_t ysiz) { - int32_t j, dasiz; + int32_t dasiz; if ((xsiz <= 0) || (ysiz <= 0) || ((unsigned)tilenume >= (unsigned)MAXTILES)) return(0); @@ -10549,14 +10549,7 @@ int32_t allocatepermanenttile(int16_t tilenume, int32_t xsiz, int32_t ysiz) walock[tilenume] = 255; allocache(&waloff[tilenume],dasiz,&walock[tilenume]); - tilesizx[tilenume] = xsiz; - tilesizy[tilenume] = ysiz; - picanm[tilenume] = 0; - - j = 15; while ((j > 1) && (pow2long[j] > xsiz)) j--; - picsiz[tilenume] = ((uint8_t)j); - j = 15; while ((j > 1) && (pow2long[j] > ysiz)) j--; - picsiz[tilenume] += ((uint8_t)(j<<4)); + set_picsizanm(tilenume, xsiz, ysiz, 0); return(waloff[tilenume]); } diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index 91385a105..4b11c880e 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -3491,11 +3491,8 @@ void G_HandleMirror(int32_t x, int32_t y, int32_t z, int32_t a, int32_t horiz, i void G_DrawRooms(int32_t snum, int32_t smoothratio) { - int32_t j,fz,cz; int32_t i; - DukePlayer_t *p = g_player[snum].ps; - int16_t tang; - int32_t tiltcx,tiltcy,tiltcs=0; // JBF 20030807 + DukePlayer_t *const p = g_player[snum].ps; int32_t tmpyx=yxaspect, tmpvr=viewingrange; @@ -3517,12 +3514,12 @@ void G_DrawRooms(int32_t snum, int32_t smoothratio) setaspect_new(); } -// smoothratio = min(max(smoothratio,0),65536); - smoothratio = min(max((totalclock - ototalclock) * (65536 / 4),0),65536); + smoothratio = clamp((totalclock-ototalclock)*(65536/4), 0, 65536); visibility = (int32_t)(p->visibility * (numplayers > 1 ? 1.f : r_ambientlightrecip)); - if (ud.pause_on || g_player[snum].ps->on_crane > -1) smoothratio = 65536; + if (ud.pause_on || g_player[snum].ps->on_crane > -1) + smoothratio = 65536; ud.camerasect = p->cursectnum; @@ -3531,13 +3528,14 @@ void G_DrawRooms(int32_t snum, int32_t smoothratio) if (ud.camerasprite >= 0) { - spritetype *s = &sprite[ud.camerasprite]; + spritetype *const s = &sprite[ud.camerasprite]; + // XXX: what? if (s->yvel < 0) s->yvel = -100; else if (s->yvel > 199) s->yvel = 300; - ud.cameraang = actor[ud.camerasprite].tempang+ - mulscale16((int32_t)(((s->ang+1024-actor[ud.camerasprite].tempang)&2047)-1024),smoothratio); + ud.cameraang = actor[ud.camerasprite].tempang + + mulscale16(((s->ang+1024-actor[ud.camerasprite].tempang)&2047)-1024, smoothratio); G_SE40(smoothratio); @@ -3554,15 +3552,20 @@ void G_DrawRooms(int32_t snum, int32_t smoothratio) } else { - i = divscale22(1,sprite[p->i].yrepeat+28); + int32_t j,fz,cz; + int32_t tiltcx, tiltcy, tiltcs=0; // JBF 20030807 + + const int32_t vr = divscale22(1,sprite[p->i].yrepeat+28); + const int32_t software_screen_tilting = + (getrendermode() == 0 && ((ud.screen_tilting && p->rotscrnang) || !ud.detail)); if (!r_usenewaspect) { - setaspect(i, yxaspect); + setaspect(vr, yxaspect); } else { - tmpvr = i; + tmpvr = vr; tmpyx = (65536*ydim*8)/(xdim*5); setaspect(mulscale16(tmpvr,viewingrange), yxaspect); @@ -3575,14 +3578,12 @@ void G_DrawRooms(int32_t snum, int32_t smoothratio) allocache(&waloff[TILE_SAVESHOT],200*320,&walock[TILE_SAVESHOT]); if (getrendermode()==0) - setviewtotile(TILE_SAVESHOT,200L,320L); + setviewtotile(TILE_SAVESHOT, 200, 320); } - else if (getrendermode() == 0 && ((ud.screen_tilting && p->rotscrnang) || ud.detail==0)) + else if (software_screen_tilting) { int32_t oviewingrange = viewingrange; // save it from setviewtotile() - - if (ud.screen_tilting) tang = p->rotscrnang; - else tang = 0; + const int16_t tang = (ud.screen_tilting) ? p->rotscrnang : 0; if (xres <= 320 && yres <= 240) { @@ -3608,8 +3609,8 @@ void G_DrawRooms(int32_t snum, int32_t smoothratio) if ((tang&1023) == 512) { //Block off unscreen section of 90ΓΈ tilted screen - j = ((tiltcx-(60*tiltcs))>>(1-ud.detail)); - for (i=((60*tiltcs)>>(1-ud.detail))-1; i>=0; i--) + j = ((tiltcx-(60*tiltcs))>>!ud.detail); + for (i=((60*tiltcs)>>!ud.detail)-1; i>=0; i--) { startumost[i] = 1; startumost[i+j] = 1; @@ -3619,8 +3620,10 @@ void G_DrawRooms(int32_t snum, int32_t smoothratio) } i = (tang&511); - if (i > 256) i = 512-i; + if (i > 256) + i = 512-i; i = sintable[i+512]*8 + sintable[i]*5; + // setaspect(i>>1, yxaspect); setaspect(mulscale16(oviewingrange,i>>1), yxaspect); @@ -3630,37 +3633,39 @@ void G_DrawRooms(int32_t snum, int32_t smoothratio) else if (getrendermode() > 0 && ud.screen_tilting /*&& (p->rotscrnang || p->orotscrnang)*/) { #ifdef USE_OPENGL - setrollangle(p->orotscrnang + mulscale16(((p->rotscrnang - p->orotscrnang + 1024)&2047)-1024,smoothratio)); + setrollangle(p->orotscrnang + mulscale16(((p->rotscrnang - p->orotscrnang + 1024)&2047)-1024, smoothratio)); #endif p->orotscrnang = p->rotscrnang; // JBF: save it for next time } { - vec3_t cam = { p->opos.x+mulscale16((int32_t)(p->pos.x-p->opos.x),smoothratio), - p->opos.y+mulscale16((int32_t)(p->pos.y-p->opos.y),smoothratio), - p->opos.z+mulscale16((int32_t)(p->pos.z-p->opos.z),smoothratio) + vec3_t cam = { p->opos.x+mulscale16(p->pos.x-p->opos.x, smoothratio), + p->opos.y+mulscale16(p->pos.y-p->opos.y, smoothratio), + p->opos.z+mulscale16(p->pos.z-p->opos.z, smoothratio) }; Bmemcpy(&ud.camera, &cam, sizeof(vec3_t)); - ud.cameraang = p->oang+mulscale16((int32_t)(((p->ang+1024-p->oang)&2047)-1024),smoothratio); - ud.camerahoriz = p->ohoriz+p->ohorizoff+mulscale16((int32_t)(p->horiz+p->horizoff-p->ohoriz-p->ohorizoff),smoothratio); + ud.cameraang = p->oang + mulscale16(((p->ang+1024-p->oang)&2047)-1024, smoothratio); + ud.camerahoriz = p->ohoriz+p->ohorizoff + + mulscale16((p->horiz+p->horizoff-p->ohoriz-p->ohorizoff), smoothratio); } ud.cameraang += p->look_ang; if (p->newowner >= 0) { - ud.cameraang = p->ang+p->look_ang; - ud.camerahoriz = p->horiz+p->horizoff; + ud.cameraang = p->ang + p->look_ang; + ud.camerahoriz = p->horiz + p->horizoff; Bmemcpy(&ud.camera, p, sizeof(vec3_t)); ud.camerasect = sprite[p->newowner].sectnum; - smoothratio = 65536L; + smoothratio = 65536; } else if (ud.viewbob) // if (p->over_shoulder_on == 0) { if (p->over_shoulder_on) - ud.camera.z += (p->opyoff+mulscale16((int32_t)(p->pyoff-p->opyoff),smoothratio))>>3; - else ud.camera.z += p->opyoff+mulscale16((int32_t)(p->pyoff-p->opyoff),smoothratio); + ud.camera.z += (p->opyoff + mulscale16(p->pyoff-p->opyoff, smoothratio))>>3; + else ud.camera.z += p->opyoff + mulscale16(p->pyoff-p->opyoff, smoothratio); } + if (p->over_shoulder_on) { ud.camera.z -= 3072; @@ -3676,14 +3681,17 @@ void G_DrawRooms(int32_t snum, int32_t smoothratio) ud.cameraang += (2-((g_earthquakeTime)&2))<<2; } - if (sprite[p->i].pal == 1) ud.camera.z -= (18<<8); + if (sprite[p->i].pal == 1) + ud.camera.z -= (18<<8); if (p->newowner >= 0) ud.camerahoriz = 100+sprite[p->newowner].shade; else if (p->spritebridge == 0) { - if (ud.camera.z < (p->truecz + (4<<8))) ud.camera.z = cz + (4<<8); - else if (ud.camera.z > (p->truefz - (4<<8))) ud.camera.z = fz - (4<<8); + if (ud.camera.z < (p->truecz + (4<<8))) + ud.camera.z = cz + (4<<8); + else if (ud.camera.z > (p->truefz - (4<<8))) + ud.camera.z = fz - (4<<8); } while (ud.camerasect >= 0) // if, really @@ -3702,7 +3710,8 @@ void G_DrawRooms(int32_t snum, int32_t smoothratio) } else #endif - if (ud.camera.z < cz+(4<<8)) ud.camera.z = cz+(4<<8); + if (ud.camera.z < cz+(4<<8)) + ud.camera.z = cz+(4<<8); #ifdef YAX_ENABLE if (yax_getbunch(ud.camerasect, YAX_FLOOR) >= 0) @@ -3712,7 +3721,8 @@ void G_DrawRooms(int32_t snum, int32_t smoothratio) } else #endif - if (ud.camera.z > fz-(4<<8)) ud.camera.z = fz-(4<<8); + if (ud.camera.z > fz-(4<<8)) + ud.camera.z = fz-(4<<8); break; } @@ -3749,13 +3759,13 @@ void G_DrawRooms(int32_t snum, int32_t smoothratio) // viewing from bottom if (drawing_ror == 1) { - int32_t k = headspritesect[sp->sectnum]; + int32_t k; - while (k != -1) + for (k=headspritesect[sp->sectnum]; k != -1; k=nextspritesect[k]) { if (sprite[k].picnum != SECTOREFFECTOR && (sprite[k].z >= sp->z)) { - Bmemcpy((spritetype *)&tsprite[spritesortcnt],(spritetype *)&sprite[k],sizeof(spritetype)); + Bmemcpy(&tsprite[spritesortcnt], &sprite[k], sizeof(spritetype)); tsprite[spritesortcnt].x += (sprite[sp->yvel].x-sp->x); tsprite[spritesortcnt].y += (sprite[sp->yvel].y-sp->y); @@ -3766,7 +3776,6 @@ void G_DrawRooms(int32_t snum, int32_t smoothratio) //OSD_Printf("duped sprite of pic %d at %d %d %d\n",tsprite[spritesortcnt].picnum,tsprite[spritesortcnt].x,tsprite[spritesortcnt].y,tsprite[spritesortcnt].z); spritesortcnt++; } - k = nextspritesect[k]; } } } @@ -3825,23 +3834,23 @@ void G_DrawRooms(int32_t snum, int32_t smoothratio) } #endif } - else if (getrendermode() == 0 && ((ud.screen_tilting && p->rotscrnang) || ud.detail==0)) + else if (software_screen_tilting) { - if (ud.screen_tilting) tang = p->rotscrnang; - else tang = 0; + const int16_t tang = (ud.screen_tilting) ? p->rotscrnang : 0; - if (getrendermode() == 0) - { - setviewback(); - picanm[TILE_TILT] &= 0xff0000ff; - i = (tang&511); - if (i > 256) i = 512-i; - i = sintable[i+512]*8 + sintable[i]*5; - if ((1-ud.detail) == 0) i >>= 1; - i>>=(tiltcs-1); // JBF 20030807 - rotatesprite_win(160<<16,100<<16,i,tang+512,TILE_TILT,0,0,4+2+64); - walock[TILE_TILT] = 199; - } + setviewback(); + picanm[TILE_TILT] &= 0xff0000ff; + + i = (tang&511); + if (i > 256) + i = 512-i; + i = sintable[i+512]*8 + sintable[i]*5; + if (ud.detail) + i >>= 1; + i >>= (tiltcs-1); // JBF 20030807 + + rotatesprite_win(160<<16,100<<16,i,tang+512,TILE_TILT,0,0,4+2+64); + walock[TILE_TILT] = 199; } } @@ -3934,7 +3943,8 @@ static void G_DumpDebugInfo(void) &g_player[myconnectindex].ps->pos.z,&g_player[myconnectindex].ps->ang,&g_player[myconnectindex].ps->cursectnum); } -int32_t A_InsertSprite(int32_t whatsect,int32_t s_x,int32_t s_y,int32_t s_z,int32_t s_pn,int32_t s_s,int32_t s_xr,int32_t s_yr,int32_t s_a,int32_t s_ve,int32_t s_zv,int32_t s_ow,int32_t s_ss) +int32_t A_InsertSprite(int32_t whatsect,int32_t s_x,int32_t s_y,int32_t s_z,int32_t s_pn,int32_t s_s, + int32_t s_xr,int32_t s_yr,int32_t s_a,int32_t s_ve,int32_t s_zv,int32_t s_ow,int32_t s_ss) { int32_t p, i = insertsprite(whatsect,s_ss); spritetype *s = &sprite[i]; @@ -10621,12 +10631,10 @@ MAIN_LOOP_RESTART: char ch; static uint32_t bufpos = 0; static char buf[128]; - #ifndef GEKKO int32_t flag = 1; ioctl(0, FIONBIO, &flag); #endif - if ((nb = read(0, &ch, 1)) > 0 && bufpos < sizeof(buf)) { if (ch != '\n') diff --git a/polymer/eduke32/source/premap.c b/polymer/eduke32/source/premap.c index b37875d37..946be5d3f 100644 --- a/polymer/eduke32/source/premap.c +++ b/polymer/eduke32/source/premap.c @@ -591,8 +591,7 @@ void G_UpdateScreenArea(void) if (qsetmode != 200) return; - if (ud.screen_size < 0) ud.screen_size = 0; - if (ud.screen_size > 64) ud.screen_size = 64; + ud.screen_size = clamp(ud.screen_size, 0, 64); if (ud.screen_size == 0) flushperms(); ss = max(ud.screen_size-8,0); diff --git a/polymer/eduke32/source/sector.c b/polymer/eduke32/source/sector.c index 253d6a4f4..c6873534c 100644 --- a/polymer/eduke32/source/sector.c +++ b/polymer/eduke32/source/sector.c @@ -372,7 +372,8 @@ void G_AnimateCamSprite(void) #ifdef DEBUG_VALGRIND_NO_SMC return; #endif - if (camsprite <= 0) return; + if (camsprite < 0) + return; if (T1 >= 4) { @@ -385,7 +386,7 @@ void G_AnimateCamSprite(void) if (waloff[TILE_VIEWSCR] == 0) allocatepermanenttile(TILE_VIEWSCR,tilesizx[PN],tilesizy[PN]); else walock[TILE_VIEWSCR] = 255; - G_SetupCamTile(OW,/*PN*/TILE_VIEWSCR); + G_SetupCamTile(OW, TILE_VIEWSCR); #ifdef POLYMER // HACK: force texture update on viewscreen sprite in Polymer! if (rendmode==4)