diff --git a/polymer/eduke32/source/actors.h b/polymer/eduke32/source/actors.h index 059b58f6d..4b4eee4f2 100644 --- a/polymer/eduke32/source/actors.h +++ b/polymer/eduke32/source/actors.h @@ -240,7 +240,8 @@ typedef struct { int32_t cacherange; // formerly SpriteCache // todo: make this a pointer and allocate at runtime - projectile_t defproj; + projectile_t *proj; + projectile_t *defproj; } tiledata_t; diff --git a/polymer/eduke32/source/duke3d.h b/polymer/eduke32/source/duke3d.h index ba7c6fa8c..59a80ad45 100644 --- a/polymer/eduke32/source/duke3d.h +++ b/polymer/eduke32/source/duke3d.h @@ -55,10 +55,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // increase by 3, because atomic GRP adds 1, and Shareware adds 2 #ifdef LUNATIC // Lunatic -# define BYTEVERSION_JF 297 +# define BYTEVERSION_JF 300 #else // Non-Lua build -# define BYTEVERSION_JF 297 +# define BYTEVERSION_JF 300 #endif //#define BYTEVERSION_13 27 diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index 95c0f52d9..9415c2ec6 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -1703,7 +1703,7 @@ static void G_DrawWeapAmounts(const DukePlayer_t *p,int32_t x,int32_t y,int32_t } // yofs: in hud_scale-independent, (<<16)-scaled, 0-200-normalized y coords. -static void G_DrawDigiNum_(int32_t x, int32_t yofs, int32_t y, int32_t n, char s, int32_t cs) +static inline void G_DrawDigiNum_(int32_t x, int32_t yofs, int32_t y, int32_t n, char s, int32_t cs) { if (!(cs & ROTATESPRITE_FULL16)) { diff --git a/polymer/eduke32/source/gamedef.c b/polymer/eduke32/source/gamedef.c index da86e7780..da7cd9d83 100644 --- a/polymer/eduke32/source/gamedef.c +++ b/polymer/eduke32/source/gamedef.c @@ -2316,73 +2316,92 @@ LUNATIC_EXTERN int32_t C_SetDefName(const char *name) return (g_defNamePtr==NULL); } +defaultprojectile_t DefaultProjectile; +int32_t g_numProjectiles = 0; + +EDUKE32_STATIC_ASSERT(sizeof(projectile_t) == sizeof(DefaultProjectile)); + LUNATIC_EXTERN void C_DefineProjectile(int32_t j, int32_t what, int32_t val) { + if (g_tile[j].proj == NULL) + { + g_tile[j].proj = (projectile_t *) Xmalloc(sizeof(projectile_t)); + *g_tile[j].proj = *(projectile_t *)&DefaultProjectile; + g_numProjectiles += 2; + } + + projectile_t * const proj = g_tile[j].proj; + switch (what) { case PROJ_WORKSLIKE: - g_tile[j].defproj.workslike = ProjectileData[j].workslike = val; break; + proj->workslike = val; break; case PROJ_SPAWNS: - g_tile[j].defproj.spawns = ProjectileData[j].spawns = val; break; + proj->spawns = val; break; case PROJ_SXREPEAT: - g_tile[j].defproj.sxrepeat = ProjectileData[j].sxrepeat = val; break; + proj->sxrepeat = val; break; case PROJ_SYREPEAT: - g_tile[j].defproj.syrepeat = ProjectileData[j].syrepeat = val; break; + proj->syrepeat = val; break; case PROJ_SOUND: - g_tile[j].defproj.sound = ProjectileData[j].sound = val; break; + proj->sound = val; break; case PROJ_ISOUND: - g_tile[j].defproj.isound = ProjectileData[j].isound = val; break; + proj->isound = val; break; case PROJ_VEL: - g_tile[j].defproj.vel = ProjectileData[j].vel = val; break; + proj->vel = val; break; case PROJ_EXTRA: - g_tile[j].defproj.extra = ProjectileData[j].extra = val; break; + proj->extra = val; break; case PROJ_DECAL: - g_tile[j].defproj.decal = ProjectileData[j].decal = val; break; + proj->decal = val; break; case PROJ_TRAIL: - g_tile[j].defproj.trail = ProjectileData[j].trail = val; break; + proj->trail = val; break; case PROJ_TXREPEAT: - g_tile[j].defproj.txrepeat = ProjectileData[j].txrepeat = val; break; + proj->txrepeat = val; break; case PROJ_TYREPEAT: - g_tile[j].defproj.tyrepeat = ProjectileData[j].tyrepeat = val; break; + proj->tyrepeat = val; break; case PROJ_TOFFSET: - g_tile[j].defproj.toffset = ProjectileData[j].toffset = val; break; + proj->toffset = val; break; case PROJ_TNUM: - g_tile[j].defproj.tnum = ProjectileData[j].tnum = val; break; + proj->tnum = val; break; case PROJ_DROP: - g_tile[j].defproj.drop = ProjectileData[j].drop = val; break; + proj->drop = val; break; case PROJ_CSTAT: - g_tile[j].defproj.cstat = ProjectileData[j].cstat = val; break; + proj->cstat = val; break; case PROJ_CLIPDIST: - g_tile[j].defproj.clipdist = ProjectileData[j].clipdist = val; break; + proj->clipdist = val; break; case PROJ_SHADE: - g_tile[j].defproj.shade = ProjectileData[j].shade = val; break; + proj->shade = val; break; case PROJ_XREPEAT: - g_tile[j].defproj.xrepeat = ProjectileData[j].xrepeat = val; break; + proj->xrepeat = val; break; case PROJ_YREPEAT: - g_tile[j].defproj.yrepeat = ProjectileData[j].yrepeat = val; break; + proj->yrepeat = val; break; case PROJ_PAL: - g_tile[j].defproj.pal = ProjectileData[j].pal = val; break; + proj->pal = val; break; case PROJ_EXTRA_RAND: - g_tile[j].defproj.extra_rand = ProjectileData[j].extra_rand = val; break; + proj->extra_rand = val; break; case PROJ_HITRADIUS: - g_tile[j].defproj.hitradius = ProjectileData[j].hitradius = val; break; + proj->hitradius = val; break; case PROJ_MOVECNT: - g_tile[j].defproj.movecnt = ProjectileData[j].movecnt = val; break; + proj->movecnt = val; break; case PROJ_OFFSET: - g_tile[j].defproj.offset = ProjectileData[j].offset = val; break; + proj->offset = val; break; case PROJ_BOUNCES: - g_tile[j].defproj.bounces = ProjectileData[j].bounces = val; break; + proj->bounces = val; break; case PROJ_BSOUND: - g_tile[j].defproj.bsound = ProjectileData[j].bsound = val; break; + proj->bsound = val; break; case PROJ_RANGE: - g_tile[j].defproj.range = ProjectileData[j].range = val; break; + proj->range = val; break; case PROJ_FLASH_COLOR: - g_tile[j].defproj.flashcolor = ProjectileData[j].flashcolor = val; break; + proj->flashcolor = val; break; case PROJ_USERDATA: - g_tile[j].defproj.userdata = ProjectileData[j].userdata = val; break; + proj->userdata = val; break; default: break; } + if (g_tile[j].defproj == NULL) + g_tile[j].defproj = (projectile_t *)Xmalloc(sizeof(projectile_t)); + + *g_tile[j].defproj = *proj; + g_tile[j].flags |= SFLAG_PROJECTILE; } @@ -6258,38 +6277,22 @@ static void C_AddDefaultDefinitions(void) void C_InitProjectiles(void) { - int32_t i; - - typedef struct + defaultprojectile_t const Projectile = { - int32_t workslike, cstat; // 8b - int32_t hitradius, range, flashcolor; // 12b - int16_t spawns, sound, isound, vel; // 8b - int16_t decal, trail, tnum, drop; // 8b - int16_t offset, bounces, bsound; // 6b - int16_t toffset; // 2b - int16_t extra, extra_rand; // 4b - int8_t sxrepeat, syrepeat, txrepeat, tyrepeat; // 4b - int8_t shade, xrepeat, yrepeat, pal; // 4b - int8_t movecnt; // 1b - uint8_t clipdist; // 1b - int8_t filler[2]; // 2b - int32_t userdata; // 4b - } defaultprojectile_t; - - defaultprojectile_t DefaultProjectile = - { - 1, -1, 2048, 0, 0, (int16_t)SMALLSMOKE, -1, -1, 600, (int16_t)BULLETHOLE, -1, 0, 0, 448, - (int16_t)g_numFreezeBounces, (int16_t)PIPEBOMB_BOUNCE, 1, 100, -1, -1, -1, -1, -1, -96, 18, 18, - 0, 1, 32, {0,0}, 0, + 1, -1, 2048, 0, 0, (int16_t) SMALLSMOKE, -1, -1, 600, (int16_t) BULLETHOLE, -1, 0, 0, 448, + (int16_t) g_numFreezeBounces, (int16_t) PIPEBOMB_BOUNCE, 1, 100, -1, -1, -1, -1, -1, -96, 18, 18, + 0, 1, 32, { 0, 0 }, 0, }; - EDUKE32_STATIC_ASSERT(sizeof(projectile_t) == sizeof(DefaultProjectile)); + DefaultProjectile = Projectile; - for (i=MAXTILES-1; i>=0; i--) + for (int i=MAXTILES-1; i>=0; i--) { - Bmemcpy(&ProjectileData[i], &DefaultProjectile, sizeof(projectile_t)); - Bmemcpy(&g_tile[i].defproj, &DefaultProjectile, sizeof(projectile_t)); + if (g_tile[i].proj) + *g_tile[i].proj = *(projectile_t *)&DefaultProjectile; + + if (g_tile[i].defproj) + *g_tile[i].defproj = *(projectile_t *)&DefaultProjectile; } } diff --git a/polymer/eduke32/source/gamedef.h b/polymer/eduke32/source/gamedef.h index ccbe5f844..d3cbb0814 100644 --- a/polymer/eduke32/source/gamedef.h +++ b/polymer/eduke32/source/gamedef.h @@ -94,10 +94,30 @@ extern const memberlabel_t InputLabels[]; extern const memberlabel_t TsprLabels[]; #endif +typedef struct +{ + int32_t workslike, cstat; // 8b + int32_t hitradius, range, flashcolor; // 12b + int16_t spawns, sound, isound, vel; // 8b + int16_t decal, trail, tnum, drop; // 8b + int16_t offset, bounces, bsound; // 6b + int16_t toffset; // 2b + int16_t extra, extra_rand; // 4b + int8_t sxrepeat, syrepeat, txrepeat, tyrepeat; // 4b + int8_t shade, xrepeat, yrepeat, pal; // 4b + int8_t movecnt; // 1b + uint8_t clipdist; // 1b + int8_t filler[2]; // 2b + int32_t userdata; // 4b +} defaultprojectile_t; + +extern defaultprojectile_t DefaultProjectile; int32_t C_AllocQuote(int32_t qnum); void C_InitQuotes(void); void C_InitProjectiles(void); +extern int32_t g_numProjectiles; + typedef struct { int g_i, g_p, g_x; int32_t *g_t; diff --git a/polymer/eduke32/source/gameexec.c b/polymer/eduke32/source/gameexec.c index c60024faf..e6654378e 100644 --- a/polymer/eduke32/source/gameexec.c +++ b/polymer/eduke32/source/gameexec.c @@ -1114,7 +1114,7 @@ int32_t G_StartTrack(int32_t level) return 1; } -LUNATIC_EXTERN void G_ShowView(int32_t x, int32_t y, int32_t z, int32_t a, int32_t horiz, int32_t sect, +LUNATIC_EXTERN void G_ShowView(vec3_t vec, int32_t a, int32_t horiz, int32_t sect, int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t unbiasedp) { int32_t smoothratio = calc_smoothratio(totalclock, ototalclock); @@ -1173,17 +1173,17 @@ LUNATIC_EXTERN void G_ShowView(int32_t x, int32_t y, int32_t z, int32_t a, int32 G_DoInterpolations(smoothratio); - G_HandleMirror(x, y, z, a, horiz, smoothratio); + G_HandleMirror(vec.x, vec.y, vec.z, a, horiz, smoothratio); #ifdef POLYMER if (getrendermode() == REND_POLYMER) - polymer_setanimatesprites(G_DoSpriteAnimations, x,y,a,smoothratio); + polymer_setanimatesprites(G_DoSpriteAnimations, vec.x,vec.y,a,smoothratio); #endif yax_preparedrawrooms(); - drawrooms(x,y,z,a,horiz,sect); + drawrooms(vec.x,vec.y,vec.z,a,horiz,sect); yax_drawrooms(G_DoSpriteAnimations, sect, 0, smoothratio); display_mirror = 2; - G_DoSpriteAnimations(x,y,a,smoothratio); + G_DoSpriteAnimations(vec.x,vec.y,a,smoothratio); display_mirror = 0; drawmasks(); G_RestoreInterpolations(); @@ -1218,14 +1218,12 @@ skip_check: if (tw == CON_LEFTBRACE) { - insptr++; - loop++; + insptr++, loop++; continue; } else if (tw == CON_RIGHTBRACE) { - insptr++; - loop--; + insptr++, loop--; continue; } else if (tw == CON_ELSE) @@ -1339,7 +1337,7 @@ skip_check: case CON_IFCANSEE: { - tspritetype *s = (tspritetype *)&sprite[ps->i]; + tspritetype * s = (tspritetype *)&sprite[ps->i]; // select sprite for monster to target // if holoduke is on, let them target holoduke first. @@ -1552,14 +1550,16 @@ skip_check: CON_ERRPRINTF("Invalid sound %d\n", (int32_t)*insptr++); continue; } - if (!S_CheckSoundPlaying(vm.g_i,*insptr++)) + + if (!S_CheckSoundPlaying(vm.g_i, *insptr++)) A_PlaySound(*(insptr-1),vm.g_i); + continue; case CON_IFACTORSOUND: insptr++; { - int32_t i = Gv_GetVarX(*insptr++), j = Gv_GetVarX(*insptr++); + int const i = Gv_GetVarX(*insptr++), j = Gv_GetVarX(*insptr++); if (EDUKE32_PREDICT_FALSE((unsigned)j >= MAXSOUNDS)) { @@ -1567,8 +1567,9 @@ skip_check: insptr++; continue; } + insptr--; - VM_CONDITIONAL(A_CheckSoundPlaying(i,j)); + VM_CONDITIONAL(A_CheckSoundPlaying(i, j)); } continue; @@ -1598,16 +1599,16 @@ skip_check: case CON_STOPACTORSOUND: insptr++; { - int32_t i = Gv_GetVarX(*insptr++), j = Gv_GetVarX(*insptr++); + int const i = Gv_GetVarX(*insptr++), j = Gv_GetVarX(*insptr++); - if (EDUKE32_PREDICT_FALSE((unsigned)j>=MAXSOUNDS)) + if (EDUKE32_PREDICT_FALSE((unsigned)j >= MAXSOUNDS)) { CON_ERRPRINTF("Invalid sound %d\n", j); continue; } - if (A_CheckSoundPlaying(i,j)) - S_StopEnvSound(j,i); + if (A_CheckSoundPlaying(i, j)) + S_StopEnvSound(j, i); continue; } @@ -1615,7 +1616,7 @@ skip_check: case CON_SETACTORSOUNDPITCH: insptr++; { - int32_t i = Gv_GetVarX(*insptr++), j = Gv_GetVarX(*insptr++), pitchoffset = Gv_GetVarX(*insptr++); + int const i = Gv_GetVarX(*insptr++), j = Gv_GetVarX(*insptr++), pitchoffset = Gv_GetVarX(*insptr++); if (EDUKE32_PREDICT_FALSE((unsigned)j>=MAXSOUNDS)) { @@ -1677,7 +1678,7 @@ skip_check: case CON_ADDAMMO: insptr++; { - int32_t weap=*insptr++, amount=*insptr++; + int const weap = *insptr++, amount = *insptr++; if (EDUKE32_PREDICT_FALSE((unsigned)weap >= MAX_WEAPONS)) { @@ -1735,7 +1736,7 @@ skip_check: case CON_ADDWEAPON: insptr++; { - int32_t weap=*insptr++, amount=*insptr++; + int const weap=*insptr++, amount=*insptr++; VM_AddWeapon(weap, amount, ps); continue; @@ -1758,12 +1759,10 @@ skip_check: insptr++; { - int32_t j; - if (ps->newowner >= 0) G_ClearCameraView(ps); - j = sprite[ps->i].extra; + int j = sprite[ps->i].extra; if (vm.g_sp->picnum != ATOMICHEALTH) { @@ -1822,7 +1821,7 @@ skip_check: case CON_ADDWEAPONVAR: insptr++; { - int32_t weap=Gv_GetVarX(*insptr++), amount=Gv_GetVarX(*insptr++); + int const weap = Gv_GetVarX(*insptr++), amount = Gv_GetVarX(*insptr++); VM_AddWeapon(weap, amount, ps); continue; } @@ -1834,7 +1833,8 @@ skip_check: case CON_SSP: insptr++; { - int32_t var1 = Gv_GetVarX(*insptr++), var2; + int const var1 = Gv_GetVarX(*insptr++); + int var2; if (tw == CON_OPERATEACTIVATORS && *insptr == g_iThisActorID) { var2 = vm.g_p; @@ -1886,15 +1886,16 @@ skip_check: case CON_CANSEESPR: insptr++; { - int32_t lVar1 = Gv_GetVarX(*insptr++), lVar2 = Gv_GetVarX(*insptr++), res; + int const lVar1 = Gv_GetVarX(*insptr++), lVar2 = Gv_GetVarX(*insptr++); + int res = 0; if (EDUKE32_PREDICT_FALSE((unsigned)lVar1 >= MAXSPRITES || (unsigned)lVar2 >= MAXSPRITES)) - { CON_ERRPRINTF("Invalid sprite %d\n", (unsigned)lVar1 >= MAXSPRITES ? lVar1 : lVar2); - res=0; + else + { + res = cansee(sprite[lVar1].x, sprite[lVar1].y, sprite[lVar1].z, sprite[lVar1].sectnum, + sprite[lVar2].x, sprite[lVar2].y, sprite[lVar2].z, sprite[lVar2].sectnum); } - else res=cansee(sprite[lVar1].x,sprite[lVar1].y,sprite[lVar1].z,sprite[lVar1].sectnum, - sprite[lVar2].x,sprite[lVar2].y,sprite[lVar2].z,sprite[lVar2].sectnum); Gv_SetVarX(*insptr++, res); continue; @@ -1923,15 +1924,17 @@ skip_check: case CON_QSTRLEN: insptr++; { - int32_t i=*insptr++; - int32_t j=Gv_GetVarX(*insptr++); + int const i = *insptr++, + j = Gv_GetVarX(*insptr++); + if (EDUKE32_PREDICT_FALSE(ScriptQuotes[j] == NULL)) { CON_ERRPRINTF("null quote %d\n", j); - Gv_SetVarX(i,-1); + Gv_SetVarX(i, -1); continue; } - Gv_SetVarX(i,Bstrlen(ScriptQuotes[j])); + + Gv_SetVarX(i, Bstrlen(ScriptQuotes[j])); continue; } @@ -1940,44 +1943,45 @@ skip_check: { vec2_t dim = { 0, 0, }; - int32_t w=*insptr++; - int32_t h=*insptr++; + int const w = *insptr++; + int const h = *insptr++; - int32_t tilenum = Gv_GetVarX(*insptr++); - int32_t x=Gv_GetVarX(*insptr++), y=Gv_GetVarX(*insptr++), z = Gv_GetVarX(*insptr++); - int32_t blockangle=Gv_GetVarX(*insptr++); - int32_t q=Gv_GetVarX(*insptr++); - int32_t orientation=Gv_GetVarX(*insptr++); - int32_t xspace=Gv_GetVarX(*insptr++), yline=Gv_GetVarX(*insptr++); - int32_t xbetween=Gv_GetVarX(*insptr++), ybetween=Gv_GetVarX(*insptr++); - int32_t f=Gv_GetVarX(*insptr++); - int32_t x1=Gv_GetVarX(*insptr++), y1=Gv_GetVarX(*insptr++); - int32_t x2=Gv_GetVarX(*insptr++), y2=Gv_GetVarX(*insptr++); + int32_t params[16]; - orientation &= (ROTATESPRITE_MAX-1); + Gv_GetManyVars(16, params); + + int const tilenum = params[0], x = params[1], y = params[2], z = params[3]; + int const blockangle = params[4], q = params[5]; + int const orientation = params[6] & (ROTATESPRITE_MAX-1); + int const xspace = params[7], yline = params[8], xbetween = params[9]; + int const ybetween = params[10], f = params[11]; + int const x1 = params[12], y1 = params[13], x2 = params[14], y2 = params[15]; if (EDUKE32_PREDICT_FALSE(tilenum < 0 || tilenum+255 >= MAXTILES)) CON_ERRPRINTF("invalid base tilenum %d\n", tilenum); else if (EDUKE32_PREDICT_FALSE((unsigned)q >= MAXQUOTES || ScriptQuotes[q] == NULL)) CON_ERRPRINTF("invalid quote ID %d\n", q); else - dim = G_ScreenTextSize(tilenum,x,y,z,blockangle,ScriptQuotes[q],2|orientation,xspace,yline,xbetween,ybetween,f,x1,y1,x2,y2); + dim = G_ScreenTextSize(tilenum, x, y, z, blockangle, ScriptQuotes[q], 2 | orientation, + xspace, yline, xbetween, ybetween, f, x1, y1, x2, y2); - Gv_SetVarX(w,dim.x); - Gv_SetVarX(h,dim.y); + Gv_SetVarX(w, dim.x); + Gv_SetVarX(h, dim.y); continue; } case CON_HEADSPRITESTAT: insptr++; { - int32_t i=*insptr++; - int32_t j=Gv_GetVarX(*insptr++); + int const i = *insptr++, + j = Gv_GetVarX(*insptr++); + if (EDUKE32_PREDICT_FALSE((unsigned)j > MAXSTATUS)) { CON_ERRPRINTF("invalid status list %d\n", j); continue; } + Gv_SetVarX(i,headspritestat[j]); continue; } @@ -1985,27 +1989,31 @@ skip_check: case CON_PREVSPRITESTAT: insptr++; { - int32_t i=*insptr++; - int32_t j=Gv_GetVarX(*insptr++); + int const i = *insptr++, + j = Gv_GetVarX(*insptr++); + if (EDUKE32_PREDICT_FALSE((unsigned)j >= MAXSPRITES)) { CON_ERRPRINTF("invalid sprite ID %d\n", j); continue; } - Gv_SetVarX(i,prevspritestat[j]); + + Gv_SetVarX(i, prevspritestat[j]); continue; } case CON_NEXTSPRITESTAT: insptr++; { - int32_t i=*insptr++; - int32_t j=Gv_GetVarX(*insptr++); + int const i = *insptr++, + j = Gv_GetVarX(*insptr++); + if (EDUKE32_PREDICT_FALSE((unsigned)j >= MAXSPRITES)) { CON_ERRPRINTF("invalid sprite ID %d\n", j); continue; } + Gv_SetVarX(i,nextspritestat[j]); continue; } @@ -2013,13 +2021,15 @@ skip_check: case CON_HEADSPRITESECT: insptr++; { - int32_t i=*insptr++; - int32_t j=Gv_GetVarX(*insptr++); + int const i = *insptr++, + j = Gv_GetVarX(*insptr++); + if (EDUKE32_PREDICT_FALSE((unsigned)j >= (unsigned)numsectors)) { CON_ERRPRINTF("invalid sector %d\n", j); continue; } + Gv_SetVarX(i,headspritesect[j]); continue; } @@ -2027,27 +2037,31 @@ skip_check: case CON_PREVSPRITESECT: insptr++; { - int32_t i=*insptr++; - int32_t j=Gv_GetVarX(*insptr++); + int const i = *insptr++; + int const j = Gv_GetVarX(*insptr++); + if (EDUKE32_PREDICT_FALSE((unsigned)j >= MAXSPRITES)) { CON_ERRPRINTF("invalid sprite ID %d\n", j); continue; } - Gv_SetVarX(i,prevspritesect[j]); + + Gv_SetVarX(i, prevspritesect[j]); continue; } case CON_NEXTSPRITESECT: insptr++; { - int32_t i=*insptr++; - int32_t j=Gv_GetVarX(*insptr++); + int const i=*insptr++; + int const j=Gv_GetVarX(*insptr++); + if (EDUKE32_PREDICT_FALSE((unsigned)j >= MAXSPRITES)) { CON_ERRPRINTF("invalid sprite ID %d\n", j); continue; } + Gv_SetVarX(i,nextspritesect[j]); continue; } @@ -2055,9 +2069,9 @@ skip_check: case CON_GETKEYNAME: insptr++; { - int32_t i = Gv_GetVarX(*insptr++), - f = Gv_GetVarX(*insptr++); - int32_t j = Gv_GetVarX(*insptr++); + int const i = Gv_GetVarX(*insptr++), + f = Gv_GetVarX(*insptr++), + j = Gv_GetVarX(*insptr++); if (EDUKE32_PREDICT_FALSE((unsigned)i >= MAXQUOTES || ScriptQuotes[i] == NULL)) { @@ -2072,18 +2086,18 @@ skip_check: else { if (j < 2) - Bstrcpy(tempbuf,KB_ScanCodeToString(ud.config.KeyboardKeys[f][j])); + Bstrcpy(tempbuf, KB_ScanCodeToString(ud.config.KeyboardKeys[f][j])); else { - Bstrcpy(tempbuf,KB_ScanCodeToString(ud.config.KeyboardKeys[f][0])); + Bstrcpy(tempbuf, KB_ScanCodeToString(ud.config.KeyboardKeys[f][0])); if (!*tempbuf) - Bstrcpy(tempbuf,KB_ScanCodeToString(ud.config.KeyboardKeys[f][1])); + Bstrcpy(tempbuf, KB_ScanCodeToString(ud.config.KeyboardKeys[f][1])); } } if (*tempbuf) - Bstrcpy(ScriptQuotes[i],tempbuf); + Bstrcpy(ScriptQuotes[i], tempbuf); continue; } @@ -2091,22 +2105,26 @@ skip_check: case CON_QSUBSTR: insptr++; { - int32_t q1 = Gv_GetVarX(*insptr++); - int32_t q2 = Gv_GetVarX(*insptr++); - int32_t st = Gv_GetVarX(*insptr++); - int32_t ln = Gv_GetVarX(*insptr++); + int32_t params[4]; + + Gv_GetManyVars(4, params); + + const int q1 = params[0], q2 = params[1]; if (EDUKE32_PREDICT_FALSE((unsigned)q1>=MAXQUOTES || ScriptQuotes[q1] == NULL)) { CON_ERRPRINTF("invalid quote ID %d\n", q1); continue; } + if (EDUKE32_PREDICT_FALSE((unsigned)q2>=MAXQUOTES || ScriptQuotes[q2] == NULL)) { CON_ERRPRINTF("invalid quote ID %d\n", q2); continue; } + int st = params[2], ln = params[3]; + if (EDUKE32_PREDICT_FALSE((unsigned)st >= MAXQUOTELEN)) { CON_ERRPRINTF("invalid start position %d\n", st); @@ -2120,7 +2138,7 @@ skip_check: } char *s1 = ScriptQuotes[q1]; - char *s2 = ScriptQuotes[q2]; + char const * s2 = ScriptQuotes[q2]; while (*s2 && st--) s2++; while ((*s1 = *s2) && ln--) @@ -2355,29 +2373,26 @@ nullquote: case CON_MYOSPAL: insptr++; { - int32_t x=Gv_GetVarX(*insptr++), y=Gv_GetVarX(*insptr++), tilenum=Gv_GetVarX(*insptr++); - int32_t shade=Gv_GetVarX(*insptr++), orientation=Gv_GetVarX(*insptr++); + int32_t values[5]; + Gv_GetManyVars(5, values); + + vec2_t const pos = *(vec2_t *)values; + int const tilenum = values[2], shade = values[3], orientation = values[4]; switch (tw) { - case CON_MYOS: - G_DrawTile(x,y,tilenum,shade,orientation); - break; - case CON_MYOSPAL: - { - int32_t pal=Gv_GetVarX(*insptr++); - G_DrawTilePal(x,y,tilenum,shade,orientation,pal); - break; - } - case CON_MYOSX: - G_DrawTileSmall(x,y,tilenum,shade,orientation); - break; - case CON_MYOSPALX: - { - int32_t pal=Gv_GetVarX(*insptr++); - G_DrawTilePalSmall(x,y,tilenum,shade,orientation,pal); - break; - } + case CON_MYOS: + G_DrawTile(pos.x, pos.y, tilenum, shade, orientation); + break; + case CON_MYOSPAL: + G_DrawTilePal(pos.x, pos.y, tilenum, shade, orientation, Gv_GetVarX(*insptr++)); + break; + case CON_MYOSX: + G_DrawTileSmall(pos.x, pos.y, tilenum, shade, orientation); + break; + case CON_MYOSPALX: + G_DrawTilePalSmall(pos.x, pos.y, tilenum, shade, orientation, Gv_GetVarX(*insptr++)); + break; } continue; } @@ -2391,14 +2406,14 @@ nullquote: // count of case statements // script offset to default case (null if none) // For each case: value, ptr to code - int32_t lValue = Gv_GetVarX(*insptr++), lEnd = *insptr++, lCases = *insptr++; + int32_t const lValue = Gv_GetVarX(*insptr++), lEnd = *insptr++, lCases = *insptr++; intptr_t const *lpDefault = insptr++, *lpCases = insptr; - int32_t lCheckCase, left = 0, right = lCases - 1; + int32_t left = 0, right = lCases - 1; insptr += lCases << 1; do { - lCheckCase = (left + right) >> 1; + int const lCheckCase = (left + right) >> 1; if (lpCases[lCheckCase << 1] > lValue) right = lCheckCase - 1; @@ -2442,7 +2457,10 @@ nullquote: case CON_DRAGPOINT: insptr++; { - int32_t wallnum = Gv_GetVarX(*insptr++), newx = Gv_GetVarX(*insptr++), newy = Gv_GetVarX(*insptr++); + int const wallnum = Gv_GetVarX(*insptr++); + vec2_t n; + + Gv_GetManyVars(2, (int32_t *)&n); if (EDUKE32_PREDICT_FALSE((unsigned)wallnum >= (unsigned)numwalls)) { @@ -2450,69 +2468,76 @@ nullquote: continue; } - dragpoint(wallnum,newx,newy,0); + dragpoint(wallnum, n.x, n.y, 0); continue; } case CON_LDIST: insptr++; { - int32_t distvar = *insptr++, xvar = Gv_GetVarX(*insptr++), yvar = Gv_GetVarX(*insptr++); + int const out = *insptr++; + vec2_t in; - if (EDUKE32_PREDICT_FALSE((unsigned)xvar >= MAXSPRITES || (unsigned)yvar >= MAXSPRITES)) + Gv_GetManyVars(2, (int32_t *) &in); + + if (EDUKE32_PREDICT_FALSE((unsigned)in.x >= MAXSPRITES || (unsigned)in.y >= MAXSPRITES)) { - CON_ERRPRINTF("invalid sprite %d %d\n", xvar, yvar); + CON_ERRPRINTF("invalid sprite %d %d\n", in.x, in.y); continue; } - Gv_SetVarX(distvar, ldist(&sprite[xvar],&sprite[yvar])); + Gv_SetVarX(out, ldist(&sprite[in.x], &sprite[in.y])); continue; } case CON_DIST: insptr++; { - int32_t distvar = *insptr++, xvar = Gv_GetVarX(*insptr++), yvar = Gv_GetVarX(*insptr++); + int const out = *insptr++; + vec2_t in; - if (EDUKE32_PREDICT_FALSE((unsigned)xvar >= MAXSPRITES || (unsigned)yvar >= MAXSPRITES)) + Gv_GetManyVars(2, (int32_t *) &in); + + if (EDUKE32_PREDICT_FALSE((unsigned)in.x >= MAXSPRITES || (unsigned)in.y >= MAXSPRITES)) { - CON_ERRPRINTF("invalid sprite %d %d\n", xvar, yvar); + CON_ERRPRINTF("invalid sprite %d %d\n", in.x, in.y); continue; } - Gv_SetVarX(distvar, dist(&sprite[xvar],&sprite[yvar])); + Gv_SetVarX(out, dist(&sprite[in.x], &sprite[in.y])); continue; } case CON_GETANGLE: insptr++; { - int32_t angvar = *insptr++; - int32_t xvar = Gv_GetVarX(*insptr++); - int32_t yvar = Gv_GetVarX(*insptr++); + int const out = *insptr++; + vec2_t in; - Gv_SetVarX(angvar, getangle(xvar,yvar)); + Gv_GetManyVars(2, (int32_t *)&in); + Gv_SetVarX(out, getangle(in.x, in.y)); continue; } case CON_GETINCANGLE: insptr++; { - int32_t angvar = *insptr++; - int32_t xvar = Gv_GetVarX(*insptr++); - int32_t yvar = Gv_GetVarX(*insptr++); + int const out = *insptr++; + vec2_t in; - Gv_SetVarX(angvar, G_GetAngleDelta(xvar,yvar)); + Gv_GetManyVars(2, (int32_t *)&in); + Gv_SetVarX(out, G_GetAngleDelta(in.x, in.y)); continue; } case CON_MULSCALE: insptr++; { - int32_t var1 = *insptr++, var2 = Gv_GetVarX(*insptr++); - int32_t var3 = Gv_GetVarX(*insptr++), var4 = Gv_GetVarX(*insptr++); + int const out = *insptr++; + vec3_t in; - Gv_SetVarX(var1, mulscale(var2, var3, var4)); + Gv_GetManyVars(3, (int32_t *)&in); + Gv_SetVarX(out, mulscale(in.x, in.y, in.z)); continue; } @@ -2530,14 +2555,14 @@ nullquote: case CON_QSPAWNVAR: insptr++; { - int32_t lIn=Gv_GetVarX(*insptr++); + int const lIn = Gv_GetVarX(*insptr++); if (EDUKE32_PREDICT_FALSE((unsigned)vm.g_sp->sectnum >= (unsigned)numsectors)) { CON_ERRPRINTF("Invalid sector %d\n", TrackerCast(vm.g_sp->sectnum)); continue; } - int32_t j = A_Spawn(vm.g_i, lIn); + int const j = A_Spawn(vm.g_i, lIn); switch (tw) { @@ -2569,7 +2594,7 @@ nullquote: continue; } - int32_t j = A_Spawn(vm.g_i,*insptr++); + int const j = A_Spawn(vm.g_i,*insptr++); switch (tw) { @@ -2594,7 +2619,7 @@ nullquote: { // NOTE: (int16_t) cast because we want to exclude that // SHOOT_HARDCODED_ZVEL is passed. - const int32_t zvel = (tw == CON_ESHOOT) ? + int const zvel = (tw == CON_ESHOOT) ? SHOOT_HARDCODED_ZVEL : (int16_t)Gv_GetVarX(*insptr++); if (EDUKE32_PREDICT_FALSE((unsigned)vm.g_sp->sectnum >= (unsigned)numsectors)) @@ -2604,7 +2629,7 @@ nullquote: continue; } - int32_t j = A_ShootWithZvel(vm.g_i,*insptr++,zvel); + int const j = A_ShootWithZvel(vm.g_i,*insptr++,zvel); if (tw != CON_ZSHOOT) aGameVars[g_iReturnVarID].val.lValue = j; @@ -2615,7 +2640,7 @@ nullquote: case CON_ESHOOTVAR: insptr++; { - int32_t j=Gv_GetVarX(*insptr++); + int j = Gv_GetVarX(*insptr++); if (EDUKE32_PREDICT_FALSE((unsigned)vm.g_sp->sectnum >= (unsigned)numsectors)) { @@ -2624,8 +2649,10 @@ nullquote: } j = A_Shoot(vm.g_i, j); + if (tw == CON_ESHOOTVAR) aGameVars[g_iReturnVarID].val.lValue = j; + continue; } @@ -2633,8 +2660,8 @@ nullquote: case CON_ZSHOOTVAR: insptr++; { - const int32_t zvel = (int16_t)Gv_GetVarX(*insptr++); - int32_t j=Gv_GetVarX(*insptr++); + int const zvel = (int16_t)Gv_GetVarX(*insptr++); + int j = Gv_GetVarX(*insptr++); if (EDUKE32_PREDICT_FALSE((unsigned)vm.g_sp->sectnum >= (unsigned)numsectors)) { @@ -2643,8 +2670,10 @@ nullquote: } j = A_ShootWithZvel(vm.g_i, j, zvel); + if (tw == CON_EZSHOOTVAR) aGameVars[g_iReturnVarID].val.lValue = j; + continue; } @@ -2660,7 +2689,7 @@ nullquote: case CON_SCREENSOUND: insptr++; { - int32_t j=Gv_GetVarX(*insptr++); + int const j = Gv_GetVarX(*insptr++); if (EDUKE32_PREDICT_FALSE((unsigned)j>=MAXSOUNDS)) { @@ -2693,7 +2722,7 @@ nullquote: case CON_IFCUTSCENE: insptr++; { - int32_t j = Gv_GetVarX(*insptr++); + int const j = Gv_GetVarX(*insptr++); if (EDUKE32_PREDICT_FALSE((unsigned)j >= MAXQUOTES || ScriptQuotes[j] == NULL)) { @@ -2754,30 +2783,28 @@ nullquote: case CON_SHOWVIEWUNBIASED: insptr++; { - int32_t x=Gv_GetVarX(*insptr++); - int32_t y=Gv_GetVarX(*insptr++); - int32_t z=Gv_GetVarX(*insptr++); - int32_t a=Gv_GetVarX(*insptr++); - int32_t horiz=Gv_GetVarX(*insptr++); - int32_t sect=Gv_GetVarX(*insptr++); - int32_t x1=Gv_GetVarX(*insptr++); - int32_t y1=Gv_GetVarX(*insptr++); - int32_t x2=Gv_GetVarX(*insptr++); - int32_t y2=Gv_GetVarX(*insptr++); + vec3_t vec; + Gv_GetManyVars(3, (int32_t *)&vec); - if (EDUKE32_PREDICT_FALSE(x1 < 0 || y1 < 0 || x2 >= 320 || y2 >= 200)) + int32_t params[3]; + Gv_GetManyVars(3, params); + + vec2_t scrn[2]; + Gv_GetManyVars(4, (int32_t *)scrn); + + if (EDUKE32_PREDICT_FALSE(scrn[0].x < 0 || scrn[0].y < 0 || scrn[1].x >= 320 || scrn[1].y >= 200)) { CON_ERRPRINTF("incorrect coordinates\n"); continue; } - if (EDUKE32_PREDICT_FALSE((unsigned)sect >= (unsigned)numsectors)) + if (EDUKE32_PREDICT_FALSE((unsigned)params[2] >= (unsigned)numsectors)) { - CON_ERRPRINTF("Invalid sector %d\n", sect); + CON_ERRPRINTF("Invalid sector %d\n", params[2]); continue; } - G_ShowView(x, y, z, a, horiz, sect, x1, y1, x2, y2, (tw != CON_SHOWVIEW)); + G_ShowView(vec, params[0], params[1], params[2], scrn[0].x, scrn[0].y, scrn[1].x, scrn[1].y, (tw != CON_SHOWVIEW)); continue; } @@ -2787,19 +2814,24 @@ nullquote: case CON_ROTATESPRITE: insptr++; { - int32_t x=Gv_GetVarX(*insptr++), y=Gv_GetVarX(*insptr++), z=Gv_GetVarX(*insptr++); - int32_t a=Gv_GetVarX(*insptr++), tilenum=Gv_GetVarX(*insptr++), shade=Gv_GetVarX(*insptr++); - int32_t pal=Gv_GetVarX(*insptr++), orientation=Gv_GetVarX(*insptr++); - int32_t alpha = (tw == CON_ROTATESPRITEA) ? Gv_GetVarX(*insptr++) : 0; - int32_t x1=Gv_GetVarX(*insptr++), y1=Gv_GetVarX(*insptr++); - int32_t x2=Gv_GetVarX(*insptr++), y2=Gv_GetVarX(*insptr++); + int32_t params[8]; - int32_t blendidx = 0; + Gv_GetManyVars(8, params); + + vec3_t c = *(vec3_t *)params; + int const a = params[3], tilenum = params[4], shade = params[5]; + int const pal = params[6]; + int orientation = params[7] & (ROTATESPRITE_MAX-1); + + int32_t alpha = (tw == CON_ROTATESPRITEA) ? Gv_GetVarX(*insptr++) : 0; + + vec2_t scrn[2]; + Gv_GetManyVars(4, (int32_t *)scrn); if (tw != CON_ROTATESPRITE16 && !(orientation&ROTATESPRITE_FULL16)) { - x<<=16; - y<<=16; + c.x<<=16; + c.y<<=16; } if (EDUKE32_PREDICT_FALSE((unsigned)tilenum >= MAXTILES)) @@ -2808,17 +2840,18 @@ nullquote: continue; } - if (EDUKE32_PREDICT_FALSE(x < -(320<<16) || x >= (640<<16) || y < -(200<<16) || y >= (400<<16))) + if (EDUKE32_PREDICT_FALSE(c.x < -(320<<16) || c.x >= (640<<16) || c.y < -(200<<16) || c.y >= (400<<16))) { - CON_ERRPRINTF("invalid coordinates: %d, %d\n", x, y); + CON_ERRPRINTF("invalid coordinates: %d, %d\n", c.x, c.y); continue; } - orientation &= (ROTATESPRITE_MAX-1); + int32_t blendidx = 0; NEG_ALPHA_TO_BLEND(alpha, blendidx, orientation); - rotatesprite_(x,y,z,a,tilenum,shade,pal,2|orientation,alpha,blendidx,x1,y1,x2,y2); + rotatesprite_(c.x, c.y, c.z, a, tilenum, shade, pal, 2 | orientation, alpha, blendidx, + scrn[0].x, scrn[0].y, scrn[1].x, scrn[1].y); continue; } @@ -2826,15 +2859,21 @@ nullquote: case CON_GAMETEXTZ: insptr++; { - int32_t tilenum = Gv_GetVarX(*insptr++); - int32_t x=Gv_GetVarX(*insptr++), y=Gv_GetVarX(*insptr++), q=Gv_GetVarX(*insptr++); - int32_t shade=Gv_GetVarX(*insptr++), pal=Gv_GetVarX(*insptr++); - int32_t orientation=Gv_GetVarX(*insptr++); - int32_t x1=Gv_GetVarX(*insptr++), y1=Gv_GetVarX(*insptr++); - int32_t x2=Gv_GetVarX(*insptr++), y2=Gv_GetVarX(*insptr++); + int32_t params[11]; + + Gv_GetManyVars(11, params); + + int const tilenum = params[0]; + int const x = params[1], y = params[2], q = params[3]; + int const shade = params[4], pal = params[5]; + int const orientation = params[6] & (ROTATESPRITE_MAX - 1); + + vec2_t const b1 = *(vec2_t *)¶ms[7]; + vec2_t const b2 = *(vec2_t *)¶ms[9]; + int32_t z = (tw == CON_GAMETEXTZ) ? Gv_GetVarX(*insptr++) : 65536; - if (EDUKE32_PREDICT_FALSE(tilenum < 0 || tilenum+255 >= MAXTILES)) + if (EDUKE32_PREDICT_FALSE(tilenum < 0 || tilenum + 255 >= MAXTILES)) { CON_ERRPRINTF("invalid base tilenum %d\n", tilenum); continue; @@ -2846,9 +2885,7 @@ nullquote: continue; } - orientation &= (ROTATESPRITE_MAX-1); - - G_PrintGameText(0,tilenum,x>>1,y,ScriptQuotes[q],shade,pal,orientation,x1,y1,x2,y2,z,0); + G_PrintGameText(0, tilenum, x >> 1, y, ScriptQuotes[q], shade, pal, orientation, b1.x, b1.y, b2.x, b2.y, z, 0); continue; } @@ -2856,12 +2893,17 @@ nullquote: case CON_DIGITALNUMBERZ: insptr++; { - int32_t tilenum = Gv_GetVarX(*insptr++); - int32_t x=Gv_GetVarX(*insptr++), y=Gv_GetVarX(*insptr++), q=Gv_GetVarX(*insptr++); - int32_t shade=Gv_GetVarX(*insptr++), pal=Gv_GetVarX(*insptr++); - int32_t orientation=Gv_GetVarX(*insptr++); - int32_t x1=Gv_GetVarX(*insptr++), y1=Gv_GetVarX(*insptr++); - int32_t x2=Gv_GetVarX(*insptr++), y2=Gv_GetVarX(*insptr++); + int32_t params[11]; + Gv_GetManyVars(11, params); + + int const tilenum = params[0]; + int const x = params[1], y = params[2], q = params[3]; + int const shade = params[4], pal = params[5]; + int const orientation = params[6] & (ROTATESPRITE_MAX - 1); + + vec2_t const b1 = *(vec2_t *) ¶ms[7]; + vec2_t const b2 = *(vec2_t *) ¶ms[9]; + int32_t z = (tw == CON_DIGITALNUMBERZ) ? Gv_GetVarX(*insptr++) : 65536; // NOTE: '-' not taken into account, but we have rotatesprite() bound check now anyway @@ -2871,15 +2913,19 @@ nullquote: continue; } - G_DrawTXDigiNumZ(tilenum,x,y,q,shade,pal,orientation,x1,y1,x2,y2,z); + G_DrawTXDigiNumZ(tilenum, x, y, q, shade, pal, orientation, b1.x, b1.y, b2.x, b2.y, z); continue; } case CON_MINITEXT: insptr++; { - int32_t x=Gv_GetVarX(*insptr++), y=Gv_GetVarX(*insptr++), q=Gv_GetVarX(*insptr++); - int32_t shade=Gv_GetVarX(*insptr++), pal=Gv_GetVarX(*insptr++); + int32_t params[5]; + + Gv_GetManyVars(5, params); + + int const x = params[0], y = params[1], q = params[2]; + int const shade = params[3], pal = params[4]; if (EDUKE32_PREDICT_FALSE((unsigned)q >= MAXQUOTES || ScriptQuotes[q] == NULL)) { @@ -2894,18 +2940,21 @@ nullquote: case CON_SCREENTEXT: insptr++; { - int32_t tilenum = Gv_GetVarX(*insptr++); - int32_t x=Gv_GetVarX(*insptr++), y=Gv_GetVarX(*insptr++), z = Gv_GetVarX(*insptr++); - int32_t blockangle=Gv_GetVarX(*insptr++), charangle=Gv_GetVarX(*insptr++); - int32_t q=Gv_GetVarX(*insptr++); - int32_t shade=Gv_GetVarX(*insptr++), pal=Gv_GetVarX(*insptr++); - int32_t orientation=Gv_GetVarX(*insptr++); - int32_t alpha=Gv_GetVarX(*insptr++); - int32_t xspace=Gv_GetVarX(*insptr++), yline=Gv_GetVarX(*insptr++); - int32_t xbetween=Gv_GetVarX(*insptr++), ybetween=Gv_GetVarX(*insptr++); - int32_t f=Gv_GetVarX(*insptr++); - int32_t x1=Gv_GetVarX(*insptr++), y1=Gv_GetVarX(*insptr++); - int32_t x2=Gv_GetVarX(*insptr++), y2=Gv_GetVarX(*insptr++); + int32_t params[20]; + + Gv_GetManyVars(20, params); + + int const tilenum = params[0]; + vec3_t const v = *(vec3_t *)¶ms[1]; + int const blockangle = params[4], charangle = params[5]; + int const q = params[6]; + int const shade = params[7], pal = params[8]; + int const orientation = params[9] & (ROTATESPRITE_MAX - 1); + int const alpha = params[10]; + int const xspace = params[11], yline = params[12]; + int const xbetween = params[13], ybetween = params[14]; + int const f = params[15]; + vec2_t const scrn[2] = { *(vec2_t *)¶ms[16], *(vec2_t *)¶ms[18] } ; if (EDUKE32_PREDICT_FALSE(tilenum < 0 || tilenum+255 >= MAXTILES)) { @@ -2919,9 +2968,8 @@ nullquote: continue; } - orientation &= (ROTATESPRITE_MAX-1); - - G_ScreenText(tilenum,x,y,z,blockangle,charangle,ScriptQuotes[q],shade,pal,2|orientation,alpha,xspace,yline,xbetween,ybetween,f,x1,y1,x2,y2); + G_ScreenText(tilenum, v.x, v.y, v.z, blockangle, charangle, ScriptQuotes[q], shade, pal, 2 | orientation, + alpha, xspace, yline, xbetween, ybetween, f, scrn[0].x, scrn[0].y, scrn[1].x, scrn[1].y); continue; } @@ -2935,9 +2983,7 @@ nullquote: { vec3_t vect; - vect.x = Gv_GetVarX(*insptr++); - vect.y = Gv_GetVarX(*insptr++); - vect.z = Gv_GetVarX(*insptr++); + Gv_GetManyVars(3, (int32_t *)&vect); int32_t sectnum = Gv_GetVarX(*insptr++); int32_t ceilzvar = *insptr++, ceilhitvar = *insptr++, florzvar = *insptr++, florhitvar = *insptr++; @@ -2963,7 +3009,7 @@ nullquote: case CON_SECTCLEARINTERPOLATION: insptr++; { - int32_t sectnum = Gv_GetVarX(*insptr++); + int const sectnum = Gv_GetVarX(*insptr++); if (EDUKE32_PREDICT_FALSE((unsigned)sectnum >= (unsigned)numsectors)) { @@ -2983,8 +3029,9 @@ nullquote: insptr++; { int32_t retvar=*insptr++; - int64_t dax=Gv_GetVarX(*insptr++), day=Gv_GetVarX(*insptr++); - int64_t hypsq = dax*dax + day*day; + vec2_t da; + Gv_GetManyVars(2, (int32_t *)&da); + int64_t hypsq = (int64_t)da.x*da.x + (int64_t)da.y*da.y; if (hypsq > (int64_t)INT32_MAX) Gv_SetVarX(retvar, (int32_t)sqrt((double)hypsq)); @@ -2998,23 +3045,30 @@ nullquote: case CON_RAYINTERSECT: insptr++; { - int32_t x1=Gv_GetVarX(*insptr++), y1=Gv_GetVarX(*insptr++), z1=Gv_GetVarX(*insptr++); - int32_t x2=Gv_GetVarX(*insptr++), y2=Gv_GetVarX(*insptr++), z2=Gv_GetVarX(*insptr++); - int32_t x3=Gv_GetVarX(*insptr++), y3=Gv_GetVarX(*insptr++), x4=Gv_GetVarX(*insptr++), y4=Gv_GetVarX(*insptr++); - int32_t intxvar=*insptr++, intyvar=*insptr++, intzvar=*insptr++, retvar=*insptr++; - int32_t intx, inty, intz, ret; + vec3_t vec[2]; + + Gv_GetManyVars(6, (int32_t *)vec); + + vec2_t vec2[2]; + + Gv_GetManyVars(4, (int32_t *)vec2); + + int32_t intxvar=*insptr++, intyvar=*insptr++, intzvar=*insptr++, retvar=*insptr++, ret; + + vec3_t in; if (tw==CON_LINEINTERSECT) - ret = lintersect(x1, y1, z1, x2, y2, z2, x3, y3, x4, y4, &intx, &inty, &intz); + ret = lintersect(vec[0].x, vec[0].y, vec[0].z, vec[1].x, vec[1].y, vec[1].z, vec2[0].x, vec2[0].y, vec2[1].x, vec2[1].y, &in.x, &in.y, &in.z); else - ret = rayintersect(x1, y1, z1, x2, y2, z2, x3, y3, x4, y4, &intx, &inty, &intz); + ret = rayintersect(vec[0].x, vec[0].y, vec[0].z, vec[1].x, vec[1].y, vec[1].z, vec2[0].x, vec2[0].y, vec2[1].x, vec2[1].y, &in.x, &in.y, &in.z); Gv_SetVarX(retvar, ret); + if (ret) { - Gv_SetVarX(intxvar, intx); - Gv_SetVarX(intyvar, inty); - Gv_SetVarX(intzvar, intz); + Gv_SetVarX(intxvar, in.x); + Gv_SetVarX(intyvar, in.y); + Gv_SetVarX(intzvar, in.z); } continue; @@ -3024,17 +3078,27 @@ nullquote: case CON_CLIPMOVENOSLIDE: insptr++; { - int32_t retvar=*insptr++, xvar=*insptr++, yvar=*insptr++, z=Gv_GetVarX(*insptr++), sectnumvar=*insptr++; - int32_t xvect=Gv_GetVarX(*insptr++), yvect=Gv_GetVarX(*insptr++); - int32_t walldist=Gv_GetVarX(*insptr++), floordist=Gv_GetVarX(*insptr++), ceildist=Gv_GetVarX(*insptr++); - int32_t clipmask=Gv_GetVarX(*insptr++); - int16_t sectnum; + typedef struct { + int32_t w, f, c; + } vec3dist_t; - vec3_t vect; - vect.x = Gv_GetVarX(xvar); - vect.y = Gv_GetVarX(yvar); - vect.z = z; - sectnum = Gv_GetVarX(sectnumvar); + int32_t retvar=*insptr++, xvar=*insptr++, yvar=*insptr++; + + insptr -= 2; + + vec3_t vec3; + Gv_GetManyVars(3, (int32_t *)&vec3); + + int32_t sectnumvar=*insptr++; + + vec2_t vec2; + Gv_GetManyVars(2, (int32_t *)&vec2); + + vec3dist_t dist; + Gv_GetManyVars(3, (int32_t *)&dist); + + int32_t clipmask = Gv_GetVarX(*insptr++); + int16_t sectnum = Gv_GetVarX(sectnumvar); if (EDUKE32_PREDICT_FALSE((unsigned)sectnum >= (unsigned)numsectors)) { @@ -3043,11 +3107,11 @@ nullquote: continue; } - Gv_SetVarX(retvar, clipmovex(&vect, §num, xvect, yvect, walldist, floordist, ceildist, + Gv_SetVarX(retvar, clipmovex(&vec3, §num, vec2.x, vec2.y, dist.w, dist.f, dist.c, clipmask, (tw==CON_CLIPMOVENOSLIDE))); Gv_SetVarX(sectnumvar, sectnum); - Gv_SetVarX(xvar, vect.x); - Gv_SetVarX(yvar, vect.y); + Gv_SetVarX(xvar, vec3.x); + Gv_SetVarX(yvar, vec3.y); continue; } @@ -3056,15 +3120,15 @@ nullquote: insptr++; { vec3_t vect; - - vect.x = Gv_GetVarX(*insptr++); - vect.y = Gv_GetVarX(*insptr++); - vect.z = Gv_GetVarX(*insptr++); + Gv_GetManyVars(3, (int32_t *)&vect); int32_t sectnum = Gv_GetVarX(*insptr++); - int32_t vx = Gv_GetVarX(*insptr++), vy = Gv_GetVarX(*insptr++), vz = Gv_GetVarX(*insptr++); - int32_t hitsectvar = *insptr++, hitwallvar = *insptr++, hitspritevar = *insptr++; - int32_t hitxvar = *insptr++, hityvar = *insptr++, hitzvar = *insptr++, cliptype = Gv_GetVarX(*insptr++); + + vec3_t v; + Gv_GetManyVars(3, (int32_t *) &v); + + int const hitsectvar = *insptr++, hitwallvar = *insptr++, hitspritevar = *insptr++; + int const hitxvar = *insptr++, hityvar = *insptr++, hitzvar = *insptr++, cliptype = Gv_GetVarX(*insptr++); if (EDUKE32_PREDICT_FALSE((unsigned)sectnum >= (unsigned)numsectors)) { @@ -3073,7 +3137,7 @@ nullquote: } hitdata_t hit; - hitscan((const vec3_t *)&vect, sectnum, vx, vy, vz, &hit, cliptype); + hitscan((const vec3_t *)&vect, sectnum, v.x, v.y, v.z, &hit, cliptype); Gv_SetVarX(hitsectvar, hit.sect); Gv_SetVarX(hitwallvar, hit.wall); @@ -3087,9 +3151,14 @@ nullquote: case CON_CANSEE: insptr++; { - int32_t x1=Gv_GetVarX(*insptr++), y1=Gv_GetVarX(*insptr++), z1=Gv_GetVarX(*insptr++); + vec3_t vec1; + Gv_GetManyVars(3, (int32_t *) &vec1); + int32_t sect1=Gv_GetVarX(*insptr++); - int32_t x2=Gv_GetVarX(*insptr++), y2=Gv_GetVarX(*insptr++), z2=Gv_GetVarX(*insptr++); + + vec3_t vec2; + Gv_GetManyVars(3, (int32_t *) &vec2); + int32_t sect2=Gv_GetVarX(*insptr++), rvar=*insptr++; if (EDUKE32_PREDICT_FALSE((unsigned)sect1 >= (unsigned)numsectors || (unsigned)sect2 >= (unsigned)numsectors)) @@ -3098,21 +3167,25 @@ nullquote: Gv_SetVarX(rvar, 0); } - Gv_SetVarX(rvar, cansee(x1,y1,z1,sect1,x2,y2,z2,sect2)); + Gv_SetVarX(rvar, cansee(vec1.x, vec1.y, vec1.z, sect1, vec2.x, vec2.y, vec2.z, sect2)); continue; } case CON_ROTATEPOINT: insptr++; { - int32_t xpivot=Gv_GetVarX(*insptr++), ypivot=Gv_GetVarX(*insptr++); - int32_t x=Gv_GetVarX(*insptr++), y=Gv_GetVarX(*insptr++), daang=Gv_GetVarX(*insptr++); - int32_t x2var=*insptr++, y2var=*insptr++; - int32_t x2, y2; + vec2_t point[2]; + Gv_GetManyVars(4, (int32_t *)point); - rotatepoint(xpivot,ypivot,x,y,daang,&x2,&y2); - Gv_SetVarX(x2var, x2); - Gv_SetVarX(y2var, y2); + int const angle = Gv_GetVarX(*insptr++); + int const x2var = *insptr++, y2var = *insptr++; + + vec2_t result; + + rotatepoint(point[0].x, point[0].y, point[1].x, point[1].y, angle, &result.x, &result.y); + + Gv_SetVarX(x2var, result.x); + Gv_SetVarX(y2var, result.y); continue; } @@ -3127,10 +3200,11 @@ nullquote: // int32_t neartagrange, //Choose maximum distance to scan (scale: 1024=largest grid size) // char tagsearch) //1-lotag only, 2-hitag only, 3-lotag&hitag - int32_t x=Gv_GetVarX(*insptr++), y=Gv_GetVarX(*insptr++), z=Gv_GetVarX(*insptr++); - int32_t sectnum=Gv_GetVarX(*insptr++), ang=Gv_GetVarX(*insptr++); - int32_t neartagsectorvar=*insptr++, neartagwallvar=*insptr++, neartagspritevar=*insptr++, neartaghitdistvar=*insptr++; - int32_t neartagrange=Gv_GetVarX(*insptr++), tagsearch=Gv_GetVarX(*insptr++); + vec3_t point; + Gv_GetManyVars(3, (int32_t *)&point); + int const sectnum=Gv_GetVarX(*insptr++), ang=Gv_GetVarX(*insptr++); + int const neartagsectorvar=*insptr++, neartagwallvar=*insptr++, neartagspritevar=*insptr++, neartaghitdistvar=*insptr++; + int const neartagrange=Gv_GetVarX(*insptr++), tagsearch=Gv_GetVarX(*insptr++); int16_t neartagsector, neartagwall, neartagsprite; int32_t neartaghitdist; @@ -3140,7 +3214,7 @@ nullquote: CON_ERRPRINTF("Invalid sector %d\n", sectnum); continue; } - neartag(x, y, z, sectnum, ang, &neartagsector, &neartagwall, &neartagsprite, + neartag(point.x, point.y, point.z, sectnum, ang, &neartagsector, &neartagwall, &neartagsprite, &neartaghitdist, neartagrange, tagsearch, NULL); Gv_SetVarX(neartagsectorvar, neartagsector); @@ -3167,12 +3241,10 @@ nullquote: case CON_SETSPRITE: insptr++; { - int32_t spritenum = Gv_GetVarX(*insptr++); - vec3_t davector; + int const spritenum = Gv_GetVarX(*insptr++); + vec3_t vect; - davector.x = Gv_GetVarX(*insptr++); - davector.y = Gv_GetVarX(*insptr++); - davector.z = Gv_GetVarX(*insptr++); + Gv_GetManyVars(3, (int32_t *)&vect); if (tw == CON_SETSPRITE) { @@ -3181,29 +3253,31 @@ nullquote: CON_ERRPRINTF("invalid sprite ID %d\n", spritenum); continue; } - setsprite(spritenum, &davector); + setsprite(spritenum, &vect); continue; } + int const cliptype = Gv_GetVarX(*insptr++); + + if (EDUKE32_PREDICT_FALSE((unsigned)spritenum >= MAXSPRITES)) { - int32_t cliptype = Gv_GetVarX(*insptr++); - - if (EDUKE32_PREDICT_FALSE((unsigned)spritenum >= MAXSPRITES)) - { - CON_ERRPRINTF("invalid sprite ID %d\n", spritenum); - insptr++; - continue; - } - Gv_SetVarX(*insptr++, A_MoveSprite(spritenum, &davector, cliptype)); + CON_ERRPRINTF("invalid sprite ID %d\n", spritenum); + insptr++; continue; } + + Gv_SetVarX(*insptr++, A_MoveSprite(spritenum, &vect, cliptype)); + continue; } case CON_GETFLORZOFSLOPE: case CON_GETCEILZOFSLOPE: insptr++; { - int32_t sectnum = Gv_GetVarX(*insptr++), x = Gv_GetVarX(*insptr++), y = Gv_GetVarX(*insptr++); + int const sectnum = Gv_GetVarX(*insptr++); + vec2_t vect; + Gv_GetManyVars(2, (int32_t *)&vect); + if (EDUKE32_PREDICT_FALSE((unsigned)sectnum >= (unsigned)numsectors)) { CON_ERRPRINTF("Invalid sector %d\n", sectnum); @@ -3213,10 +3287,11 @@ nullquote: if (tw == CON_GETFLORZOFSLOPE) { - Gv_SetVarX(*insptr++, getflorzofslope(sectnum,x,y)); + Gv_SetVarX(*insptr++, getflorzofslope(sectnum, vect.x, vect.y)); continue; } - Gv_SetVarX(*insptr++, getceilzofslope(sectnum,x,y)); + + Gv_SetVarX(*insptr++, getceilzofslope(sectnum, vect.x, vect.y)); continue; } @@ -3224,13 +3299,15 @@ nullquote: case CON_UPDATESECTORZ: insptr++; { - int32_t x=Gv_GetVarX(*insptr++), y=Gv_GetVarX(*insptr++); - int32_t z=(tw==CON_UPDATESECTORZ)?Gv_GetVarX(*insptr++):0; - int32_t var=*insptr++; - int16_t w=sprite[vm.g_i].sectnum; + vec3_t vect = { 0, 0, 0 }; + Gv_GetManyVars(tw == CON_UPDATESECTORZ ? 3 : 2, (int32_t *)&vect); + int const var=*insptr++; + int16_t w = sprite[vm.g_i].sectnum; - if (tw==CON_UPDATESECTOR) updatesector(x,y,&w); - else updatesectorz(x,y,z,&w); + if (tw == CON_UPDATESECTOR) + updatesector(vect.x, vect.y, &w); + else + updatesectorz(vect.x, vect.y, vect.z, &w); Gv_SetVarX(var, w); continue; @@ -3465,9 +3542,9 @@ nullquote: case CON_HITRADIUSVAR: insptr++; { - int32_t v1=Gv_GetVarX(*insptr++),v2=Gv_GetVarX(*insptr++),v3=Gv_GetVarX(*insptr++); - int32_t v4=Gv_GetVarX(*insptr++),v5=Gv_GetVarX(*insptr++); - A_RadiusDamage(vm.g_i,v1,v2,v3,v4,v5); + int32_t params[5]; + Gv_GetManyVars(5, params); + A_RadiusDamage(vm.g_i, params[0], params[1], params[2], params[3], params[4]); } continue; @@ -3478,9 +3555,9 @@ nullquote: case CON_IFP: { - int32_t l = *(++insptr); + int const l = *(++insptr); int32_t j = 0; - int32_t s = sprite[ps->i].xvel; + int const s = sprite[ps->i].xvel; if ((l&8) && ps->on_ground && TEST_SYNC_KEY(g_player[vm.g_p].sync->bits, SK_CROUCH)) j = 1; @@ -3518,9 +3595,10 @@ nullquote: else if ((l&65536L)) { if (vm.g_sp->picnum == APLAYER && (g_netServer || ud.multimode > 1)) - j = G_GetAngleDelta(g_player[otherp].ps->ang,getangle(ps->pos.x-g_player[otherp].ps->pos.x,ps->pos.y-g_player[otherp].ps->pos.y)); + j = G_GetAngleDelta(g_player[otherp].ps->ang, getangle(ps->pos.x - g_player[otherp].ps->pos.x, + ps->pos.y - g_player[otherp].ps->pos.y)); else - j = G_GetAngleDelta(ps->ang,getangle(vm.g_sp->x-ps->pos.x,vm.g_sp->y-ps->pos.y)); + j = G_GetAngleDelta(ps->ang, getangle(vm.g_sp->x - ps->pos.x, vm.g_sp->y - ps->pos.y)); if (j > -128 && j < 128) j = 1; @@ -3570,7 +3648,7 @@ nullquote: case CON_CLEARMAPSTATE: insptr++; { - int32_t j = Gv_GetVarX(*insptr++); + int const j = Gv_GetVarX(*insptr++); if (EDUKE32_PREDICT_FALSE((unsigned)j >= MAXVOLUMES*MAXLEVELS)) { CON_ERRPRINTF("Invalid map number: %d\n", j); @@ -3712,7 +3790,7 @@ nullquote: { int32_t arg[32], i = 0, j = 0, k = 0, numargs; - int32_t len = Bstrlen(ScriptQuotes[sq]); + int const len = Bstrlen(ScriptQuotes[sq]); char tempbuf[MAXQUOTELEN]; while ((*insptr & VM_INSTMASK) != CON_NULLOP && i < 32) @@ -3744,14 +3822,13 @@ nullquote: k++; case 'd': { - char buf[16]; - int32_t ii; - if (i >= numargs) goto finish_qsprintf; + + char buf[16]; Bsprintf(buf, "%d", arg[i++]); - ii = Bstrlen(buf); + int const ii = Bstrlen(buf); Bmemcpy(&tempbuf[j], buf, ii); j += ii; k++; @@ -3760,11 +3837,10 @@ nullquote: case 's': { - int32_t ii; - if (i >= numargs) goto finish_qsprintf; - ii = Bstrlen(ScriptQuotes[arg[i]]); + + int const ii = Bstrlen(ScriptQuotes[arg[i]]); Bmemcpy(&tempbuf[j], ScriptQuotes[arg[i]], ii); j += ii; @@ -3900,7 +3976,7 @@ finish_qsprintf: { // syntax [gs]etsector[].x // - int32_t lVar1=*insptr++, lLabelID=*insptr++, lVar2=*insptr++; + int const lVar1=*insptr++, lLabelID=*insptr++, lVar2=*insptr++; VM_AccessSector(tw==CON_SETSECTOR, lVar1, lLabelID, lVar2); continue; @@ -3910,9 +3986,8 @@ finish_qsprintf: insptr++; { // syntax sqrt - int32_t lInVarID=*insptr++, lOutVarID=*insptr++; - - Gv_SetVarX(lOutVarID, ksqrt((uint32_t)Gv_GetVarX(lInVarID))); + int const sqrtval = ksqrt((uint32_t)Gv_GetVarX(*insptr++)); + Gv_SetVarX(*insptr++, sqrtval); continue; } @@ -3927,7 +4002,7 @@ finish_qsprintf: // that is of into // -1 for none found // - int32_t lType=*insptr++, lMaxDist=*insptr++, lVarID=*insptr++; + int const lType=*insptr++, lMaxDist=*insptr++, lVarID=*insptr++; int32_t lFound=-1, j, k = MAXSTATUS-1; if (tw == CON_FINDNEARACTOR || tw == CON_FINDNEARACTOR3D) @@ -3989,7 +4064,7 @@ finish_qsprintf: // that is of into // -1 for none found // - int32_t lType=*insptr++, lMaxDist=Gv_GetVarX(*insptr++), lVarID=*insptr++; + int const lType=*insptr++, lMaxDist=Gv_GetVarX(*insptr++), lVarID=*insptr++; int32_t lFound=-1, j, k = 1; if (tw == CON_FINDNEARSPRITEVAR || tw == CON_FINDNEARSPRITE3DVAR) @@ -4051,9 +4126,8 @@ finish_qsprintf: // that is of into // -1 for none found // - int32_t lType=*insptr++, lMaxDist=Gv_GetVarX(*insptr++); - int32_t lMaxZDist=Gv_GetVarX(*insptr++); - int32_t lVarID=*insptr++, lFound=-1, lTemp, lTemp2, j, k=MAXSTATUS-1; + int const lType=*insptr++, lMaxDist=Gv_GetVarX(*insptr++), lMaxZDist=Gv_GetVarX(*insptr++), lVarID = *insptr++; + int32_t lFound=-1, lTemp, lTemp2, j, k=MAXSTATUS-1; do { j=headspritestat[tw==CON_FINDNEARACTORZVAR?1:k]; // all sprites @@ -4095,7 +4169,7 @@ finish_qsprintf: // that is of into // -1 for none found // - int32_t lType=*insptr++, lMaxDist=*insptr++, lMaxZDist=*insptr++, lVarID=*insptr++; + int const lType=*insptr++, lMaxDist=*insptr++, lMaxZDist=*insptr++, lVarID=*insptr++; int32_t lTemp, lTemp2, lFound=-1, j, k=MAXSTATUS-1; do { @@ -4145,8 +4219,8 @@ finish_qsprintf: insptr++; { tw=*insptr++; - int32_t lLabelID=*insptr++; - int32_t lParm2 = (PlayerLabels[lLabelID].flags & LABEL_HASPARM2) ? Gv_GetVarX(*insptr++) : 0; + int const lLabelID=*insptr++; + int const lParm2 = (PlayerLabels[lLabelID].flags & LABEL_HASPARM2) ? Gv_GetVarX(*insptr++) : 0; VM_SetPlayer(tw, lLabelID, *insptr++, lParm2); continue; } @@ -4155,8 +4229,8 @@ finish_qsprintf: insptr++; { tw=*insptr++; - int32_t lLabelID=*insptr++; - int32_t lParm2 = (PlayerLabels[lLabelID].flags & LABEL_HASPARM2) ? Gv_GetVarX(*insptr++) : 0; + int const lLabelID=*insptr++; + int const lParm2 = (PlayerLabels[lLabelID].flags & LABEL_HASPARM2) ? Gv_GetVarX(*insptr++) : 0; VM_GetPlayer(tw, lLabelID, *insptr++, lParm2); continue; } @@ -4165,7 +4239,7 @@ finish_qsprintf: insptr++; { tw=*insptr++; - int32_t lLabelID=*insptr++, lVar2=*insptr++; + int const lLabelID=*insptr++, lVar2=*insptr++; VM_AccessPlayerInput(0, tw, lLabelID, lVar2); continue; } @@ -4174,7 +4248,7 @@ finish_qsprintf: insptr++; { tw=*insptr++; - int32_t lLabelID=*insptr++, lVar2=*insptr++; + int const lLabelID=*insptr++, lVar2=*insptr++; VM_AccessPlayerInput(1, tw, lLabelID, lVar2); continue; } @@ -4183,7 +4257,7 @@ finish_qsprintf: insptr++; { tw=*insptr++; - int32_t lVar2=*insptr++; + int const lVar2=*insptr++; VM_AccessUserdef(0, tw, lVar2); continue; } @@ -4192,7 +4266,7 @@ finish_qsprintf: insptr++; { tw=*insptr++; - int32_t lVar2=*insptr++; + int const lVar2=*insptr++; VM_AccessUserdef(1, tw, lVar2); continue; } @@ -4201,7 +4275,7 @@ finish_qsprintf: insptr++; { tw = Gv_GetVarX(*insptr++); - int32_t lLabelID = *insptr++, lVar2 = *insptr++; + int const lLabelID = *insptr++, lVar2 = *insptr++; VM_AccessProjectile(0, tw, lLabelID, lVar2); continue; } @@ -4210,7 +4284,7 @@ finish_qsprintf: insptr++; { tw = Gv_GetVarX(*insptr++); - int32_t lLabelID = *insptr++, lVar2 = *insptr++; + int const lLabelID = *insptr++, lVar2 = *insptr++; VM_AccessProjectile(1, tw, lLabelID, lVar2); continue; } @@ -4219,7 +4293,7 @@ finish_qsprintf: insptr++; { tw=*insptr++; - int32_t lLabelID=*insptr++, lVar2=*insptr++; + int const lLabelID=*insptr++, lVar2=*insptr++; VM_AccessWall(1, tw, lLabelID, lVar2); continue; } @@ -4228,7 +4302,7 @@ finish_qsprintf: insptr++; { tw=*insptr++; - int32_t lLabelID=*insptr++, lVar2=*insptr++; + int const lLabelID=*insptr++, lVar2=*insptr++; VM_AccessWall(0, tw, lLabelID, lVar2); continue; } @@ -4240,8 +4314,8 @@ finish_qsprintf: // syntax [gs]etactorvar[]. // gets the value of the per-actor variable varx into VAR // - int32_t lSprite=Gv_GetVarX(*insptr++), lVar1=*insptr++; - int32_t lVar2=*insptr++; + int const lSprite=Gv_GetVarX(*insptr++), lVar1=*insptr++; + int const lVar2=*insptr++; if (EDUKE32_PREDICT_FALSE((unsigned)lSprite >= MAXSPRITES)) { @@ -4264,11 +4338,11 @@ finish_qsprintf: case CON_GETPLAYERVAR: insptr++; { - int32_t iPlayer = (*insptr != g_iThisActorID) ? Gv_GetVarX(*insptr) : vm.g_p; + int const iPlayer = (*insptr != g_iThisActorID) ? Gv_GetVarX(*insptr) : vm.g_p; insptr++; - int32_t lVar1 = *insptr++, lVar2 = *insptr++; + int const lVar1 = *insptr++, lVar2 = *insptr++; if (EDUKE32_PREDICT_FALSE((unsigned)iPlayer >= (unsigned)playerswhenstarted)) { @@ -4297,8 +4371,8 @@ finish_qsprintf: // syntax [gs]etactor[].x // - int32_t lVar1 = *insptr++, lLabelID = *insptr++; - int32_t lParm2 = (ActorLabels[lLabelID].flags & LABEL_HASPARM2) ? Gv_GetVarX(*insptr++) : 0; + int const lVar1 = *insptr++, lLabelID = *insptr++; + int const lParm2 = (ActorLabels[lLabelID].flags & LABEL_HASPARM2) ? Gv_GetVarX(*insptr++) : 0; VM_SetSprite(lVar1, lLabelID, *insptr++, lParm2); continue; @@ -4310,8 +4384,8 @@ finish_qsprintf: // syntax [gs]etactor[].x // - int32_t lVar1=*insptr++, lLabelID=*insptr++; - int32_t lParm2 = (ActorLabels[lLabelID].flags & LABEL_HASPARM2) ? Gv_GetVarX(*insptr++) : 0; + int const lVar1=*insptr++, lLabelID=*insptr++; + int const lParm2 = (ActorLabels[lLabelID].flags & LABEL_HASPARM2) ? Gv_GetVarX(*insptr++) : 0; VM_GetSprite(lVar1, lLabelID, *insptr++, lParm2); continue; @@ -4324,7 +4398,7 @@ finish_qsprintf: // syntax [gs]etactor[].x // - int32_t lVar1=*insptr++, lLabelID=*insptr++, lVar2=*insptr++; + int const lVar1=*insptr++, lLabelID=*insptr++, lVar2=*insptr++; VM_AccessTsprite(tw==CON_SETTSPR, lVar1, lLabelID, lVar2); continue; @@ -4407,8 +4481,8 @@ finish_qsprintf: insptr++; { tw=*insptr++; - int32_t index = Gv_GetVarX(*insptr++); - int32_t value = Gv_GetVarX(*insptr++); + int const index = Gv_GetVarX(*insptr++); + int const value = Gv_GetVarX(*insptr++); if (EDUKE32_PREDICT_FALSE((unsigned)tw >= (unsigned)g_gameArrayCount || (unsigned)index >= (unsigned)aGameArrays[tw].size)) { @@ -4531,10 +4605,10 @@ finish_qsprintf: case CON_COPY: insptr++; { - int32_t si=*insptr++; - int32_t sidx = Gv_GetVarX(*insptr++); //, vm.g_i, vm.g_p); - int32_t di=*insptr++; - int32_t didx = Gv_GetVarX(*insptr++); + int const si = *insptr++; + int sidx = Gv_GetVarX(*insptr++); //, vm.g_i, vm.g_p); + int const di = *insptr++; + int didx = Gv_GetVarX(*insptr++); int32_t numelts = Gv_GetVarX(*insptr++); tw = 0; @@ -4557,14 +4631,17 @@ finish_qsprintf: if (EDUKE32_PREDICT_FALSE(tw)) continue; // dirty replacement for VMFLAG_ERROR - int32_t ssiz = (aGameArrays[si].dwFlags&GAMEARRAY_VARSIZE) ? - Gv_GetVarX(aGameArrays[si].size) : aGameArrays[si].size; - int32_t dsiz = (aGameArrays[di].dwFlags&GAMEARRAY_VARSIZE) ? - Gv_GetVarX(aGameArrays[si].size) : aGameArrays[di].size; + int const ssiz = + (aGameArrays[si].dwFlags & GAMEARRAY_VARSIZE) ? Gv_GetVarX(aGameArrays[si].size) : aGameArrays[si].size; + int const dsiz = + (aGameArrays[di].dwFlags & GAMEARRAY_VARSIZE) ? Gv_GetVarX(aGameArrays[si].size) : aGameArrays[di].size; - if (EDUKE32_PREDICT_FALSE(sidx > ssiz || didx > dsiz)) continue; - if ((sidx+numelts) > ssiz) numelts = ssiz-sidx; - if ((didx+numelts) > dsiz) numelts = dsiz-didx; + if (EDUKE32_PREDICT_FALSE(sidx > ssiz || didx > dsiz)) + continue; + if ((sidx + numelts) > ssiz) + numelts = ssiz - sidx; + if ((didx + numelts) > dsiz) + numelts = dsiz - didx; // Switch depending on the source array type. switch (aGameArrays[si].dwFlags & GAMEARRAY_TYPE_MASK) @@ -4577,17 +4654,17 @@ finish_qsprintf: // From int32-sized array. Note that the CON array element // type is intptr_t, so it is different-sized on 64-bit // archs, but same-sized on 32-bit ones. - for (; numelts>0; numelts--) + for (; numelts>0; --numelts) (aGameArrays[di].plValues)[didx++] = ((int32_t *)aGameArrays[si].plValues)[sidx++]; break; case GAMEARRAY_OFSHORT: // From int16_t array. Always different-sized. - for (; numelts>0; numelts--) + for (; numelts>0; --numelts) (aGameArrays[di].plValues)[didx++] = ((int16_t *)aGameArrays[si].plValues)[sidx++]; break; case GAMEARRAY_OFCHAR: // From char array. Always different-sized. - for (; numelts>0; numelts--) + for (; numelts>0; --numelts) (aGameArrays[di].plValues)[didx++] = ((uint8_t *)aGameArrays[si].plValues)[sidx++]; break; } diff --git a/polymer/eduke32/source/gameexec.h b/polymer/eduke32/source/gameexec.h index 69fe8aedb..f15120f88 100644 --- a/polymer/eduke32/source/gameexec.h +++ b/polymer/eduke32/source/gameexec.h @@ -100,7 +100,7 @@ void G_GetTimeDate(int32_t *vals); int32_t G_StartTrack(int32_t level); int32_t A_Dodge(spritetype *s); #ifdef LUNATIC -void G_ShowView(int32_t x, int32_t y, int32_t z, int32_t a, int32_t horiz, int32_t sect, +void G_ShowView(vec3_t vec, int32_t a, int32_t horiz, int32_t sect, int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t unbiasedp); void P_AddWeaponMaybeSwitchI(int32_t snum, int32_t weap); void VM_FallSprite(int32_t i); diff --git a/polymer/eduke32/source/gamestructures.c b/polymer/eduke32/source/gamestructures.c index f9aa7d349..ff3fa02f2 100644 --- a/polymer/eduke32/source/gamestructures.c +++ b/polymer/eduke32/source/gamestructures.c @@ -1239,6 +1239,8 @@ badtspr: static void __fastcall VM_AccessProjectile(int32_t iSet, int32_t lVar1, int32_t lLabelID, int32_t lVar2) { + projectile_t * const proj = g_tile[lVar1].proj; + if (EDUKE32_PREDICT_FALSE((unsigned)lVar1 >= MAXTILES)) goto badtile; @@ -1248,72 +1250,72 @@ static void __fastcall VM_AccessProjectile(int32_t iSet, int32_t lVar1, int32_t switch (lLabelID) { - case PROJ_WORKSLIKE: ProjectileData[lVar1].workslike = iSet; break; - case PROJ_SPAWNS: ProjectileData[lVar1].spawns = iSet; break; - case PROJ_SXREPEAT: ProjectileData[lVar1].sxrepeat = iSet; break; - case PROJ_SYREPEAT: ProjectileData[lVar1].syrepeat = iSet; break; - case PROJ_SOUND: ProjectileData[lVar1].sound = iSet; break; - case PROJ_ISOUND: ProjectileData[lVar1].isound = iSet; break; - case PROJ_VEL: ProjectileData[lVar1].vel = iSet; break; - case PROJ_EXTRA: ProjectileData[lVar1].extra = iSet; break; - case PROJ_DECAL: ProjectileData[lVar1].decal = iSet; break; - case PROJ_TRAIL: ProjectileData[lVar1].trail = iSet; break; - case PROJ_TXREPEAT: ProjectileData[lVar1].txrepeat = iSet; break; - case PROJ_TYREPEAT: ProjectileData[lVar1].tyrepeat = iSet; break; - case PROJ_TOFFSET: ProjectileData[lVar1].toffset = iSet; break; - case PROJ_TNUM: ProjectileData[lVar1].tnum = iSet; break; - case PROJ_DROP: ProjectileData[lVar1].drop = iSet; break; - case PROJ_CSTAT: ProjectileData[lVar1].cstat = iSet; break; - case PROJ_CLIPDIST: ProjectileData[lVar1].clipdist = iSet; break; - case PROJ_SHADE: ProjectileData[lVar1].shade = iSet; break; - case PROJ_XREPEAT: ProjectileData[lVar1].xrepeat = iSet; break; - case PROJ_YREPEAT: ProjectileData[lVar1].yrepeat = iSet; break; - case PROJ_PAL: ProjectileData[lVar1].pal = iSet; break; - case PROJ_EXTRA_RAND: ProjectileData[lVar1].extra_rand = iSet; break; - case PROJ_HITRADIUS: ProjectileData[lVar1].hitradius = iSet; break; - case PROJ_MOVECNT: ProjectileData[lVar1].movecnt = iSet; break; - case PROJ_OFFSET: ProjectileData[lVar1].offset = iSet; break; - case PROJ_BOUNCES: ProjectileData[lVar1].bounces = iSet; break; - case PROJ_BSOUND: ProjectileData[lVar1].bsound = iSet; break; - case PROJ_RANGE: ProjectileData[lVar1].range = iSet; break; - case PROJ_FLASH_COLOR: ProjectileData[lVar1].flashcolor = iSet; break; - case PROJ_USERDATA: ProjectileData[lVar1].userdata = iSet; break; + case PROJ_WORKSLIKE: proj->workslike = iSet; break; + case PROJ_SPAWNS: proj->spawns = iSet; break; + case PROJ_SXREPEAT: proj->sxrepeat = iSet; break; + case PROJ_SYREPEAT: proj->syrepeat = iSet; break; + case PROJ_SOUND: proj->sound = iSet; break; + case PROJ_ISOUND: proj->isound = iSet; break; + case PROJ_VEL: proj->vel = iSet; break; + case PROJ_EXTRA: proj->extra = iSet; break; + case PROJ_DECAL: proj->decal = iSet; break; + case PROJ_TRAIL: proj->trail = iSet; break; + case PROJ_TXREPEAT: proj->txrepeat = iSet; break; + case PROJ_TYREPEAT: proj->tyrepeat = iSet; break; + case PROJ_TOFFSET: proj->toffset = iSet; break; + case PROJ_TNUM: proj->tnum = iSet; break; + case PROJ_DROP: proj->drop = iSet; break; + case PROJ_CSTAT: proj->cstat = iSet; break; + case PROJ_CLIPDIST: proj->clipdist = iSet; break; + case PROJ_SHADE: proj->shade = iSet; break; + case PROJ_XREPEAT: proj->xrepeat = iSet; break; + case PROJ_YREPEAT: proj->yrepeat = iSet; break; + case PROJ_PAL: proj->pal = iSet; break; + case PROJ_EXTRA_RAND: proj->extra_rand = iSet; break; + case PROJ_HITRADIUS: proj->hitradius = iSet; break; + case PROJ_MOVECNT: proj->movecnt = iSet; break; + case PROJ_OFFSET: proj->offset = iSet; break; + case PROJ_BOUNCES: proj->bounces = iSet; break; + case PROJ_BSOUND: proj->bsound = iSet; break; + case PROJ_RANGE: proj->range = iSet; break; + case PROJ_FLASH_COLOR: proj->flashcolor = iSet; break; + case PROJ_USERDATA: proj->userdata = iSet; break; } } else { switch (lLabelID) { - case PROJ_WORKSLIKE: iSet = ProjectileData[lVar1].workslike; break; - case PROJ_SPAWNS: iSet = ProjectileData[lVar1].spawns; break; - case PROJ_SXREPEAT: iSet = ProjectileData[lVar1].sxrepeat; break; - case PROJ_SYREPEAT: iSet = ProjectileData[lVar1].syrepeat; break; - case PROJ_SOUND: iSet = ProjectileData[lVar1].sound; break; - case PROJ_ISOUND: iSet = ProjectileData[lVar1].isound; break; - case PROJ_VEL: iSet = ProjectileData[lVar1].vel; break; - case PROJ_EXTRA: iSet = ProjectileData[lVar1].extra; break; - case PROJ_DECAL: iSet = ProjectileData[lVar1].decal; break; - case PROJ_TRAIL: iSet = ProjectileData[lVar1].trail; break; - case PROJ_TXREPEAT: iSet = ProjectileData[lVar1].txrepeat; break; - case PROJ_TYREPEAT: iSet = ProjectileData[lVar1].tyrepeat; break; - case PROJ_TOFFSET: iSet = ProjectileData[lVar1].toffset; break; - case PROJ_TNUM: iSet = ProjectileData[lVar1].tnum; break; - case PROJ_DROP: iSet = ProjectileData[lVar1].drop; break; - case PROJ_CSTAT: iSet = ProjectileData[lVar1].cstat; break; - case PROJ_CLIPDIST: iSet = ProjectileData[lVar1].clipdist; break; - case PROJ_SHADE: iSet = ProjectileData[lVar1].shade; break; - case PROJ_XREPEAT: iSet = ProjectileData[lVar1].xrepeat; break; - case PROJ_YREPEAT: iSet = ProjectileData[lVar1].yrepeat; break; - case PROJ_PAL: iSet = ProjectileData[lVar1].pal; break; - case PROJ_EXTRA_RAND: iSet = ProjectileData[lVar1].extra_rand; break; - case PROJ_HITRADIUS: iSet = ProjectileData[lVar1].hitradius; break; - case PROJ_MOVECNT: iSet = ProjectileData[lVar1].movecnt; break; - case PROJ_OFFSET: iSet = ProjectileData[lVar1].offset; break; - case PROJ_BOUNCES: iSet = ProjectileData[lVar1].bounces; break; - case PROJ_BSOUND: iSet = ProjectileData[lVar1].bsound; break; - case PROJ_RANGE: iSet = ProjectileData[lVar1].range; break; - case PROJ_FLASH_COLOR: iSet = ProjectileData[lVar1].flashcolor; break; - case PROJ_USERDATA: iSet = ProjectileData[lVar1].userdata; break; + case PROJ_WORKSLIKE: iSet = proj->workslike; break; + case PROJ_SPAWNS: iSet = proj->spawns; break; + case PROJ_SXREPEAT: iSet = proj->sxrepeat; break; + case PROJ_SYREPEAT: iSet = proj->syrepeat; break; + case PROJ_SOUND: iSet = proj->sound; break; + case PROJ_ISOUND: iSet = proj->isound; break; + case PROJ_VEL: iSet = proj->vel; break; + case PROJ_EXTRA: iSet = proj->extra; break; + case PROJ_DECAL: iSet = proj->decal; break; + case PROJ_TRAIL: iSet = proj->trail; break; + case PROJ_TXREPEAT: iSet = proj->txrepeat; break; + case PROJ_TYREPEAT: iSet = proj->tyrepeat; break; + case PROJ_TOFFSET: iSet = proj->toffset; break; + case PROJ_TNUM: iSet = proj->tnum; break; + case PROJ_DROP: iSet = proj->drop; break; + case PROJ_CSTAT: iSet = proj->cstat; break; + case PROJ_CLIPDIST: iSet = proj->clipdist; break; + case PROJ_SHADE: iSet = proj->shade; break; + case PROJ_XREPEAT: iSet = proj->xrepeat; break; + case PROJ_YREPEAT: iSet = proj->yrepeat; break; + case PROJ_PAL: iSet = proj->pal; break; + case PROJ_EXTRA_RAND: iSet = proj->extra_rand; break; + case PROJ_HITRADIUS: iSet = proj->hitradius; break; + case PROJ_MOVECNT: iSet = proj->movecnt; break; + case PROJ_OFFSET: iSet = proj->offset; break; + case PROJ_BOUNCES: iSet = proj->bounces; break; + case PROJ_BSOUND: iSet = proj->bsound; break; + case PROJ_RANGE: iSet = proj->range; break; + case PROJ_FLASH_COLOR: iSet = proj->flashcolor; break; + case PROJ_USERDATA: iSet = proj->userdata; break; default: iSet = -1; break; } @@ -1323,7 +1325,7 @@ static void __fastcall VM_AccessProjectile(int32_t iSet, int32_t lVar1, int32_t return; badtile: - CON_ERRPRINTF("invalid tile (%d)\n", lVar1); + CON_ERRPRINTF("invalid projectile (%d)\n", lVar1); insptr += (lVar2 == MAXGAMEVARS); return; } diff --git a/polymer/eduke32/source/gamevars.c b/polymer/eduke32/source/gamevars.c index cf7b2dc20..2333a9007 100644 --- a/polymer/eduke32/source/gamevars.c +++ b/polymer/eduke32/source/gamevars.c @@ -752,10 +752,9 @@ badwall: void __fastcall Gv_SetVar(int32_t const id, int32_t const lValue, int32_t const iActor, int32_t const iPlayer) { - if (EDUKE32_PREDICT_FALSE((unsigned)id >= (unsigned)g_gameVarCount)) goto badvarid; + int const f = aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK); - int f; - f = aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK); + if (EDUKE32_PREDICT_FALSE((unsigned)id >= (unsigned)g_gameVarCount)) goto badvarid; if (!f) aGameVars[id].val.lValue=lValue; else if (f == GAMEVAR_PERPLAYER) @@ -809,6 +808,116 @@ static const char *gvxerrs[] = { "Gv_GetVarX(): invalid array index", }; +int32_t __fastcall Gv_GetSpecialVarX(int32_t id) +{ + int rv = -1; + + if (id & (MAXGAMEVARS << 2)) // array + { + int const index = Gv_GetVarX(*insptr++); + + id &= (MAXGAMEVARS - 1); // ~((MAXGAMEVARS<<2)|(MAXGAMEVARS<<1)); + + int const siz = (aGameArrays[id].dwFlags & GAMEARRAY_VARSIZE) ? + Gv_GetVarX(aGameArrays[id].size) : aGameArrays[id].size; + + if (EDUKE32_PREDICT_FALSE((unsigned) index >= (unsigned) siz)) + { + CON_ERRPRINTF("%s %s[%d]\n", gvxerrs[GVX_BADINDEX], aGameArrays[id].szLabel, index); + return -1; + } + + switch (aGameArrays[id].dwFlags & GAMEARRAY_TYPE_MASK) + { + case 0: rv = (aGameArrays[id].plValues)[index]; break; + case GAMEARRAY_OFINT: rv = ((int32_t *) aGameArrays[id].plValues)[index]; break; + case GAMEARRAY_OFSHORT: rv = ((int16_t *) aGameArrays[id].plValues)[index]; break; + case GAMEARRAY_OFCHAR: rv = ((uint8_t *) aGameArrays[id].plValues)[index]; break; + } + } + else if (id & (MAXGAMEVARS << 3)) // struct shortcut vars + { + int indexvar = *insptr; + int index = Gv_GetVarX(*insptr++); + + switch ((id & (MAXGAMEVARS - 1)) - g_iSpriteVarID) + { + case 0: // if (id == g_iSpriteVarID) + { + int const label = *insptr++; + + /*OSD_Printf("%d %d %d\n",__LINE__,index,label);*/ + indexvar = (EDUKE32_PREDICT_FALSE(ActorLabels[label].flags & LABEL_HASPARM2)) ? + Gv_GetVarX(*insptr++) : 0; + + if (EDUKE32_PREDICT_FALSE((unsigned) index >= MAXSPRITES)) + { + id = index; + CON_ERRPRINTF("%s %d\n", gvxerrs[GVX_BADSPRITE], id); + return -1; + } + + rv = VM_AccessSpriteX(index, label, indexvar); + break; + } + + case 3: // else if (id == g_iPlayerVarID) + { + int const label = *insptr++; + + if (indexvar == g_iThisActorID) + index = vm.g_p; + + indexvar = (EDUKE32_PREDICT_FALSE(PlayerLabels[label].flags & LABEL_HASPARM2)) ? + Gv_GetVarX(*insptr++) : 0; + + if (EDUKE32_PREDICT_FALSE((unsigned) index >= MAXPLAYERS)) + { + id = index; + CON_ERRPRINTF("%s %d\n", gvxerrs[GVX_BADPLAYER], id); + return -1; + } + + rv = VM_AccessPlayerX(index, label, indexvar); + break; + } + + case 4: // else if (id == g_iActorVarID) + rv = Gv_GetVar(*insptr++, index, vm.g_p); + break; + + case 1: // else if (id == g_iSectorVarID) + if (indexvar == g_iThisActorID) + index = sprite[vm.g_i].sectnum; + + if (EDUKE32_PREDICT_FALSE((unsigned) index >= MAXSECTORS)) + { + id = index; + insptr++; + CON_ERRPRINTF("%s %d\n", gvxerrs[GVX_BADSECTOR], id); + return -1; + } + rv = VM_AccessSectorX(index, *insptr++); + break; + + case 2: // else if (id == g_iWallVarID) + if (EDUKE32_PREDICT_FALSE((unsigned) index >= MAXWALLS)) + { + id = index; + insptr++; + CON_ERRPRINTF("%s %d\n", gvxerrs[GVX_BADWALL], id); + return -1; + } + rv = VM_AccessWallX(index, *insptr++); + break; + + default: EDUKE32_UNREACHABLE_SECTION(return -1); + } + } + + return rv; +} + int32_t __fastcall Gv_GetVarX(int32_t id) { if (id == g_iThisActorID) @@ -821,7 +930,7 @@ int32_t __fastcall Gv_GetVarX(int32_t id) int rv = -1; if (EDUKE32_PREDICT_FALSE(id >= g_gameVarCount && negateResult == 0)) - goto nastyhacks; + rv = Gv_GetSpecialVarX(id); else { id &= MAXGAMEVARS-1; @@ -847,121 +956,70 @@ int32_t __fastcall Gv_GetVarX(int32_t id) rv = (*((uint8_t *) aGameVars[id].val.lValue)); break; } - return (rv ^ -negateResult) + negateResult; - } - -nastyhacks: - if (id & (MAXGAMEVARS << 2)) // array - { - int const index = Gv_GetVarX(*insptr++); - - id &= (MAXGAMEVARS - 1); // ~((MAXGAMEVARS<<2)|(MAXGAMEVARS<<1)); - - int const siz = (aGameArrays[id].dwFlags & GAMEARRAY_VARSIZE) ? - Gv_GetVarX(aGameArrays[id].size) : aGameArrays[id].size; - - if (EDUKE32_PREDICT_FALSE((unsigned)index >= (unsigned)siz)) - { - CON_ERRPRINTF("%s %s[%d]\n", gvxerrs[GVX_BADINDEX], aGameArrays[id].szLabel, index); - return -1; - } - - switch (aGameArrays[id].dwFlags & GAMEARRAY_TYPE_MASK) - { - case 0: rv = (aGameArrays[id].plValues)[index]; break; - case GAMEARRAY_OFINT: rv = ((int32_t *)aGameArrays[id].plValues)[index]; break; - case GAMEARRAY_OFSHORT: rv = ((int16_t *)aGameArrays[id].plValues)[index]; break; - case GAMEARRAY_OFCHAR: rv = ((uint8_t *)aGameArrays[id].plValues)[index]; break; - } - } - else if (id & (MAXGAMEVARS << 3)) // struct shortcut vars - { - int indexvar = *insptr; - int index = Gv_GetVarX(*insptr++); - - switch ((id & (MAXGAMEVARS - 1)) - g_iSpriteVarID) - { - case 0: // if (id == g_iSpriteVarID) - { - int const label = *insptr++; - - /*OSD_Printf("%d %d %d\n",__LINE__,index,label);*/ - indexvar = (EDUKE32_PREDICT_FALSE(ActorLabels[label].flags & LABEL_HASPARM2)) ? - Gv_GetVarX(*insptr++) : 0; - - if (EDUKE32_PREDICT_FALSE((unsigned)index >= MAXSPRITES)) - { - id = index; - CON_ERRPRINTF("%s %d\n", gvxerrs[GVX_BADSPRITE], id); - return -1; - } - - rv = VM_AccessSpriteX(index, label, indexvar); - break; - } - - case 3: // else if (id == g_iPlayerVarID) - { - int const label = *insptr++; - - if (indexvar == g_iThisActorID) - index = vm.g_p; - - indexvar = (EDUKE32_PREDICT_FALSE(PlayerLabels[label].flags & LABEL_HASPARM2)) ? - Gv_GetVarX(*insptr++) : 0; - - if (EDUKE32_PREDICT_FALSE((unsigned)index >= MAXPLAYERS)) - { - id = index; - CON_ERRPRINTF("%s %d\n", gvxerrs[GVX_BADPLAYER], id); - return -1; - } - - rv = VM_AccessPlayerX(index, label, indexvar); - break; - } - - case 4: // else if (id == g_iActorVarID) - rv = Gv_GetVar(*insptr++, index, vm.g_p); - break; - - case 1: // else if (id == g_iSectorVarID) - if (indexvar == g_iThisActorID) - index = sprite[vm.g_i].sectnum; - - if (EDUKE32_PREDICT_FALSE((unsigned)index >= MAXSECTORS)) - { - id = index; - insptr++; - CON_ERRPRINTF("%s %d\n", gvxerrs[GVX_BADSECTOR], id); - return -1; - } - rv = VM_AccessSectorX(index, *insptr++); - break; - - case 2: // else if (id == g_iWallVarID) - if (EDUKE32_PREDICT_FALSE((unsigned)index >= MAXWALLS)) - { - id = index; - insptr++; - CON_ERRPRINTF("%s %d\n", gvxerrs[GVX_BADWALL], id); - return -1; - } - rv = VM_AccessWallX(index, *insptr++); - break; - - default: EDUKE32_UNREACHABLE_SECTION(return -1); - } } return (rv ^ -negateResult) + negateResult; perr: - id = vm.g_p; - CON_ERRPRINTF("%s %d\n", gvxerrs[GVX_BADPLAYER], id); + CON_ERRPRINTF("%s %d\n", gvxerrs[GVX_BADPLAYER], vm.g_p); return -1; } +void __fastcall Gv_GetManyVars(int32_t const count, int32_t * const rv) +{ + for (int j = 0; j < count; ++j) + { + int id = *insptr++; + + if (id == g_iThisActorID) + { + rv[j] = vm.g_i; + continue; + } + + if (id == MAXGAMEVARS) + { + rv[j] = *insptr++; + continue; + } + + int const negateResult = !!(id & (MAXGAMEVARS << 1)); + + if (EDUKE32_PREDICT_FALSE(id >= g_gameVarCount && negateResult == 0)) + { + rv[j] = Gv_GetSpecialVarX(id); + continue; + } + + id &= MAXGAMEVARS - 1; + + int const f = aGameVars[id].dwFlags & (GAMEVAR_USER_MASK | GAMEVAR_PTR_MASK); + int val = aGameVars[id].val.lValue; + + if (f == GAMEVAR_PERPLAYER) + { + if (EDUKE32_PREDICT_FALSE((unsigned)vm.g_p >= MAXPLAYERS)) + goto perr; + val = aGameVars[id].val.plValues[vm.g_p]; + } + else if (f == GAMEVAR_PERACTOR) + val = aGameVars[id].val.plValues[vm.g_i]; + else + switch (f) + { + case GAMEVAR_INTPTR: val = (*((int32_t *)aGameVars[id].val.lValue)); break; + case GAMEVAR_SHORTPTR: val = (*((int16_t *)aGameVars[id].val.lValue)); break; + case GAMEVAR_CHARPTR: val = (*((uint8_t *)aGameVars[id].val.lValue)); break; + } + + rv[j] = (val ^ -negateResult) + negateResult; + continue; + + perr: + CON_ERRPRINTF("%s %d\n", gvxerrs[GVX_BADPLAYER], vm.g_p); + } +} + void __fastcall Gv_SetVarX(int32_t const id, int32_t const lValue) { int const f = aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK); @@ -1090,7 +1148,8 @@ void Gv_ResetSystemDefaults(void) #endif for (int i = 0; i <= MAXTILES - 1; i++) - Bmemcpy(&ProjectileData[i], &g_tile[i].defproj, sizeof(projectile_t)); + if (g_tile[i].defproj) + *g_tile[i].proj = *g_tile[i].defproj; #ifndef LUNATIC int i; diff --git a/polymer/eduke32/source/gamevars.h b/polymer/eduke32/source/gamevars.h index ec812e829..775d2efe4 100644 --- a/polymer/eduke32/source/gamevars.h +++ b/polymer/eduke32/source/gamevars.h @@ -103,6 +103,7 @@ extern int32_t g_gameArrayCount; int32_t __fastcall Gv_GetVar(int32_t id, int32_t iActor, int32_t iPlayer); void __fastcall Gv_SetVar(int32_t const id, int32_t const lValue, int32_t const iActor, int32_t const iPlayer); int32_t __fastcall Gv_GetVarX(int32_t id); +void __fastcall Gv_GetManyVars(int32_t const count, int32_t * const rv); void __fastcall Gv_SetVarX(int32_t const id, int32_t const lValue); int32_t Gv_GetVarByLabel(const char *szGameLabel,int32_t const lDefault,int32_t const iActor,int32_t const iPlayer); diff --git a/polymer/eduke32/source/global.h b/polymer/eduke32/source/global.h index 92437f1f5..d1967b781 100644 --- a/polymer/eduke32/source/global.h +++ b/polymer/eduke32/source/global.h @@ -128,7 +128,6 @@ G_EXTERN playerspawn_t g_playerSpawnPoints[MAXPLAYERS]; G_EXTERN input_t inputfifo[MOVEFIFOSIZ][MAXPLAYERS]; #pragma pack(pop) -G_EXTERN projectile_t ProjectileData[MAXTILES]; G_EXTERN projectile_t SpriteProjectile[MAXSPRITES]; G_EXTERN sound_t g_sounds[MAXSOUNDS]; G_EXTERN uint32_t everyothertime; diff --git a/polymer/eduke32/source/lunatic/control.lua b/polymer/eduke32/source/lunatic/control.lua index c582a5793..618e630ae 100644 --- a/polymer/eduke32/source/lunatic/control.lua +++ b/polymer/eduke32/source/lunatic/control.lua @@ -1041,7 +1041,9 @@ function _showview(x, y, z, a, horiz, sect, x1, y1, x2, y2, unbiasedp) error("invalid coordinates "..str, 2) end - CF.G_ShowView(x, y, z, a, horiz, sect, x1, y1, x2, y2, unbiasedp); + local pos = vec3(x, y, z) + + CF.G_ShowView(pos, a, horiz, sect, x1, y1, x2, y2, unbiasedp); end diff --git a/polymer/eduke32/source/lunatic/lunatic_game.c b/polymer/eduke32/source/lunatic/lunatic_game.c index ed209d59b..b8af9fd9b 100644 --- a/polymer/eduke32/source/lunatic/lunatic_game.c +++ b/polymer/eduke32/source/lunatic/lunatic_game.c @@ -368,7 +368,7 @@ extern int32_t A_InsertSprite(int32_t whatsect,int32_t s_x,int32_t s_y,int32_t s extern void A_AddToDeleteQueue(int32_t i); extern int32_t A_PlaySound(uint32_t num, int32_t i); extern void A_DeleteSprite(int32_t s); -extern void G_ShowView(int32_t x, int32_t y, int32_t z, int32_t a, int32_t horiz, int32_t sect, +extern void G_ShowView(vec3_t vec, int32_t a, int32_t horiz, int32_t sect, int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t unbiasedp); extern void G_GameExit(const char *msg); #ifdef __cplusplus @@ -420,7 +420,7 @@ DEFINE_VOID_CFUNC(A_AddToDeleteQueue, ONE_ARG) DEFINE_RET_CFUNC(A_PlaySound, TWO_ARGS) DEFINE_VOID_CFUNC(A_DeleteSprite, ONE_ARG) DEFINE_VOID_CFUNC(G_ShowView, LARG(1), LARG(2), LARG(3), LARG(4), LARG(5), LARG(6), - LARG(7), LARG(8), LARG(9), LARG(10), LARG(11)) + LARG(7), LARG(8), LARG(9)) #define CFUNC_REG(Name) { #Name, Name##_CF } diff --git a/polymer/eduke32/source/player.c b/polymer/eduke32/source/player.c index 9e72e3390..ee575e8f4 100644 --- a/polymer/eduke32/source/player.c +++ b/polymer/eduke32/source/player.c @@ -136,6 +136,11 @@ static void A_DoWaterTracers(int32_t x1,int32_t y1,int32_t z1,int32_t x2,int32_t } } +static inline projectile_t * Proj_GetProjectile(int tile) +{ + return ((unsigned)tile < MAXTILES && g_tile[tile].proj) ? g_tile[tile].proj : (projectile_t *) &DefaultProjectile; +} + static void A_HitscanProjTrail(const vec3_t *sv, const vec3_t *dv, int32_t ang, int32_t atwith) { int32_t n, j, i; @@ -143,7 +148,7 @@ static void A_HitscanProjTrail(const vec3_t *sv, const vec3_t *dv, int32_t ang, vec3_t srcvect; vec3_t destvect; - const projectile_t *const proj = &ProjectileData[atwith]; + const projectile_t *const proj = Proj_GetProjectile(atwith); Bmemcpy(&destvect, dv, sizeof(vec3_t)); @@ -212,7 +217,7 @@ static int32_t A_FindTargetSprite(const spritetype *s, int32_t aang, int32_t atw if (g_player[snum].ps->auto_aim == 2) { - if (A_CheckSpriteTileFlags(atwith,SFLAG_PROJECTILE) && (ProjectileData[atwith].workslike & PROJECTILE_RPG)) + if (A_CheckSpriteTileFlags(atwith,SFLAG_PROJECTILE) && (Proj_GetProjectile(atwith)->workslike & PROJECTILE_RPG)) return -1; switch (DYNAMICTILEMAP(atwith)) @@ -390,7 +395,8 @@ static int32_t GetAutoAimAngle(int32_t i, int32_t p, int32_t atwith, static void Proj_MaybeSpawn(int32_t k, int32_t atwith, const hitdata_t *hit) { // atwith < 0 is for hard-coded projectiles - int32_t spawntile = atwith < 0 ? -atwith : ProjectileData[atwith].spawns; + projectile_t * const proj = Proj_GetProjectile(atwith); + int32_t spawntile = atwith < 0 ? -atwith : proj->spawns; if (spawntile >= 0) { @@ -398,10 +404,10 @@ static void Proj_MaybeSpawn(int32_t k, int32_t atwith, const hitdata_t *hit) if (atwith >= 0) { - if (ProjectileData[atwith].sxrepeat > 4) - sprite[wh].xrepeat = ProjectileData[atwith].sxrepeat; - if (ProjectileData[atwith].syrepeat > 4) - sprite[wh].yrepeat = ProjectileData[atwith].syrepeat; + if (proj->sxrepeat > 4) + sprite[wh].xrepeat = proj->sxrepeat; + if (proj->syrepeat > 4) + sprite[wh].yrepeat = proj->syrepeat; } A_SetHitData(wh, hit); @@ -424,9 +430,10 @@ static int32_t Proj_InsertShotspark(const hitdata_t *hit, int32_t i, int32_t atw static int32_t Proj_GetExtra(int32_t atwith) { - int32_t extra = ProjectileData[atwith].extra; - if (ProjectileData[atwith].extra_rand > 0) - extra += (krand()%ProjectileData[atwith].extra_rand); + projectile_t * const proj = Proj_GetProjectile(atwith); + int32_t extra = proj->extra; + if (proj->extra_rand > 0) + extra += (krand() % proj->extra_rand); return extra; } @@ -566,7 +573,7 @@ static int32_t Proj_DoHitscan(int32_t i, int32_t cstatmask, static void Proj_DoRandDecalSize(int32_t spritenum, int32_t atwith) { - const projectile_t *const proj = &ProjectileData[atwith]; + const projectile_t *const proj = Proj_GetProjectile(atwith); if (proj->workslike & PROJECTILE_RANDDECALSIZE) { @@ -811,7 +818,7 @@ static void Proj_HandleKnee(hitdata_t *hit, int32_t i, int32_t p, int32_t atwith if (proj != NULL) { // Custom projectiles. - SpriteProjectile[j].workslike = ProjectileData[sprite[j].picnum].workslike; + SpriteProjectile[j].workslike = Proj_GetProjectile(sprite[j].picnum)->workslike; sprite[j].extra = proj->extra; } @@ -858,7 +865,7 @@ static void Proj_HandleKnee(hitdata_t *hit, int32_t i, int32_t p, int32_t atwith static int32_t A_ShootCustom(const int32_t i, const int32_t atwith, int16_t sa, vec3_t * const srcvect) { /* Custom projectiles */ - projectile_t *const proj = &ProjectileData[atwith]; + projectile_t *const proj = Proj_GetProjectile(atwith); int32_t j, k = -1, l; int32_t vel, zvel = 0; hitdata_t hit; @@ -999,10 +1006,7 @@ static int32_t A_ShootCustom(const int32_t i, const int32_t atwith, int16_t sa, if (proj->clipdist != 255) sprite[j].clipdist = proj->clipdist; else sprite[j].clipdist = 40; - { - int32_t picnum = sprite[j].picnum; // why? - Bmemcpy(&SpriteProjectile[j], &ProjectileData[picnum], sizeof(projectile_t)); - } + SpriteProjectile[j] = *Proj_GetProjectile(sprite[j].picnum); return j; diff --git a/polymer/eduke32/source/savegame.c b/polymer/eduke32/source/savegame.c index d528cca12..d70387a5b 100644 --- a/polymer/eduke32/source/savegame.c +++ b/polymer/eduke32/source/savegame.c @@ -959,6 +959,12 @@ static void sv_quoteredefload(); static void sv_postquoteredef(); static void sv_restsave(); static void sv_restload(); +static void sv_preprojectilesave(); +static void sv_postprojectilesave(); +static void sv_preprojectileload(); +static void sv_postprojectileload(); + +static projectile_t *ProjectileData; #define SVARDATALEN \ ((sizeof(g_player[0].user_name)+sizeof(g_player[0].pcolor)+sizeof(g_player[0].pteam) \ @@ -1062,7 +1068,6 @@ static const dataspec_t svgm_secwsp[] = { DS_NOCHK, &g_mirrorSector[0], sizeof(g_mirrorSector[0]), ARRAY_SIZE(g_mirrorSector) }, // projectiles { 0, &SpriteProjectile[0], sizeof(projectile_t), MAXSPRITES }, - { 0, &ProjectileData[0], sizeof(projectile_t), MAXTILES }, { 0, &everyothertime, sizeof(everyothertime), 1 }, { DS_END, 0, 0, 0 } }; @@ -1078,6 +1083,11 @@ static const dataspec_t svgm_script[] = { DS_SAVEFN|DS_NOCHK, (void *)&sv_prescriptsave_once, 0, 1 }, #endif { DS_NOCHK, &g_tile[0], sizeof(tiledata_t), MAXTILES }, + { DS_SAVEFN, (void *) &sv_preprojectilesave, 0, 1 }, + { DS_LOADFN, (void *) &sv_preprojectileload, 0, 1 }, + { DS_DYNAMIC|DS_CNT(g_numProjectiles), &ProjectileData, sizeof(projectile_t), (intptr_t)&g_numProjectiles }, + { DS_SAVEFN, (void *) &sv_postprojectilesave, 0, 1 }, + { DS_LOADFN, (void *) &sv_postprojectileload, 0, 1 }, #if !defined LUNATIC { DS_LOADFN|DS_NOCHK, (void *)&sv_prescriptload_once, 0, 1 }, { DS_DYNAMIC|DS_CNT(g_scriptSize)|DS_NOCHK, &script, sizeof(script[0]), (intptr_t)&g_scriptSize }, @@ -1711,6 +1721,59 @@ static void sv_quoteload() } } } + +static void sv_preprojectilesave() +{ + ProjectileData = (projectile_t *) Xrealloc(ProjectileData, sizeof(projectile_t) * g_numProjectiles); + + int onumprojectiles = g_numProjectiles; + g_numProjectiles = 0; + + for (int i=0; i