diff --git a/source/build/include/clip.h b/source/build/include/clip.h index 2d2d7330e..117213e18 100644 --- a/source/build/include/clip.h +++ b/source/build/include/clip.h @@ -49,6 +49,7 @@ int32_t clipmovex(vec3_t *const pos, int16_t *const sectnum, int32_t xvect, int3 int pushmove(vec3_t *const vect, int16_t *const sectnum, int32_t const walldist, int32_t const ceildist, int32_t const flordist, uint32_t const cliptype, bool clear = true) ATTRIBUTE((nonnull(1, 2))); +[[deprecated]] inline int pushmove(int* x, int* y, int* z, int16_t* const sectnum, int32_t const walldist, int32_t const ceildist, int32_t const flordist, uint32_t const cliptype, bool clear = true) { @@ -60,4 +61,17 @@ inline int pushmove(int* x, int* y, int* z, int16_t* const sectnum, int32_t cons return r; } +inline int pushmove(int* x, int* y, int* z, int* const sectnum, int32_t const walldist, int32_t const ceildist, int32_t const flordist, + uint32_t const cliptype, bool clear = true) +{ + short sect16 = *sectnum; + vec3_t v = { *x,*y,*z }; + auto r = pushmove(&v, §16, walldist, ceildist, flordist, cliptype, clear); + *sectnum = sect16; + *x = v.x; + *y = v.y; + *z = v.z; + return r; +} + #endif diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index 7bcdbc64c..e5271ac8c 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -878,7 +878,7 @@ int32_t spriteheightofsptr(uspriteptr_t spr, int32_t *height, int32_t alsotileyo // int32_t setsprite(int16_t spritenum, const vec3_t *newpos) { - int16_t tempsectnum = sprite[spritenum].sectnum; + int tempsectnum = sprite[spritenum].sectnum; if (newpos != &sprite[spritenum].pos) sprite[spritenum].pos = *newpos; diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index e4d32926d..cb0f48f38 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -1503,10 +1503,13 @@ bool queball(DDukeActor *actor, int pocket, int queball, int stripeball) } Collision coll; - int j = clipmove_ex(&s->x, &s->y, &s->z, &s->sectnum, + static_assert(sizeof(s->sectnum) != sizeof(int)); // this will error out when sectnum gets expanded. + int sect = s->sectnum; + int j = clipmove_ex(&s->x, &s->y, &s->z, §, (MulScale(s->xvel, bcos(s->ang), 14) * TICSPERFRAME) << 11, (MulScale(s->xvel, bsin(s->ang), 14) * TICSPERFRAME) << 11, 24L, (4 << 8), (4 << 8), CLIPMASK1, coll); + s->sectnum = sect; if (j == kHitWall) { @@ -5314,7 +5317,7 @@ void fall_common(DDukeActor *actor, int playernum, int JIBS6, int DRONE, int BLO else if (s->zvel > 2048 && s->sector()->lotag != 1) { - short j = s->sectnum; + int j = s->sectnum; int x = s->x, y = s->y, z = s->z; pushmove(&x, &y, &z, &j, 128, (4 << 8), (4 << 8), CLIPMASK0); s->x = x; s->y = y; s->z = z; diff --git a/source/games/duke/src/actors_d.cpp b/source/games/duke/src/actors_d.cpp index 6bd2d496d..c158cd7da 100644 --- a/source/games/duke/src/actors_d.cpp +++ b/source/games/duke/src/actors_d.cpp @@ -540,7 +540,8 @@ SKIPWALLCHECK: int movesprite_ex_d(DDukeActor* actor, int xchange, int ychange, int zchange, unsigned int cliptype, Collision &result) { int daz, h, oldx, oldy; - short retval, dasectnum, cd; + short cd; + int dasectnum; auto spri = actor->s; int bg = badguy(actor); @@ -567,7 +568,7 @@ int movesprite_ex_d(DDukeActor* actor, int xchange, int ychange, int zchange, un oldy = spri->y; if (spri->xrepeat > 60) - retval = clipmove(&spri->x, &spri->y, &daz, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), 1024L, (4 << 8), (4 << 8), cliptype); + clipmove_ex(&spri->x, &spri->y, &daz, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), 1024L, (4 << 8), (4 << 8), cliptype, result); else { if (spri->picnum == LIZMAN) @@ -577,7 +578,7 @@ int movesprite_ex_d(DDukeActor* actor, int xchange, int ychange, int zchange, un else cd = 192; - retval = clipmove(&spri->x, &spri->y, &daz, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), cd, (4 << 8), (4 << 8), cliptype); + clipmove_ex(&spri->x, &spri->y, &daz, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), cd, (4 << 8), (4 << 8), cliptype, result); } // conditional code from hell... @@ -599,15 +600,13 @@ int movesprite_ex_d(DDukeActor* actor, int xchange, int ychange, int zchange, un if (dasectnum < 0) dasectnum = 0; return result.setSector(dasectnum); } - if ((retval & kHitTypeMask) > kHitSector && (actor->cgg == 0)) spri->ang += 768; + if ((result.type == kHitWall || result.type == kHitSprite) && (actor->cgg == 0)) spri->ang += 768; } else { if (spri->statnum == STAT_PROJECTILE) - retval = clipmove_ex(&spri->x, &spri->y, &daz, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), 8L, (4 << 8), (4 << 8), cliptype, result); else - retval = clipmove_ex(&spri->x, &spri->y, &daz, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), (int)(spri->clipdist << 2), (4 << 8), (4 << 8), cliptype, result); } @@ -617,10 +616,10 @@ int movesprite_ex_d(DDukeActor* actor, int xchange, int ychange, int zchange, un daz = spri->z + ((zchange * TICSPERFRAME) >> 3); if ((daz > actor->ceilingz) && (daz <= actor->floorz)) spri->z = daz; - else if (retval == kHitNone) + else if (result.type == kHitNone) return result.setSector(dasectnum); - return retval; + return result.type; } //--------------------------------------------------------------------------- // diff --git a/source/games/duke/src/actors_r.cpp b/source/games/duke/src/actors_r.cpp index 519b86194..c6cb4a4ca 100644 --- a/source/games/duke/src/actors_r.cpp +++ b/source/games/duke/src/actors_r.cpp @@ -383,7 +383,8 @@ SKIPWALLCHECK: int movesprite_ex_r(DDukeActor* actor, int xchange, int ychange, int zchange, unsigned int cliptype, Collision &result) { int daz, h, oldx, oldy; - short retval, dasectnum, cd; + int dasectnum; + short cd; auto spri = actor->s; int bg = badguy(actor); @@ -409,11 +410,11 @@ int movesprite_ex_r(DDukeActor* actor, int xchange, int ychange, int zchange, un oldy = spri->y; if (spri->xrepeat > 60) - retval = clipmove(&spri->x, &spri->y, &daz, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), 1024L, (4 << 8), (4 << 8), cliptype); + clipmove_ex(&spri->x, &spri->y, &daz, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), 1024L, (4 << 8), (4 << 8), cliptype, result); else { cd = 192; - retval = clipmove(&spri->x, &spri->y, &daz, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), cd, (4 << 8), (4 << 8), cliptype); + clipmove_ex(&spri->x, &spri->y, &daz, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), cd, (4 << 8), (4 << 8), cliptype, result); } if (dasectnum < 0 || (dasectnum >= 0 && actor->actorstayput >= 0 && actor->actorstayput != dasectnum)) @@ -428,15 +429,13 @@ int movesprite_ex_r(DDukeActor* actor, int xchange, int ychange, int zchange, un if (dasectnum < 0) dasectnum = 0; return result.setSector(dasectnum); } - if ((retval & kHitTypeMask) > kHitSector && (actor->cgg == 0)) spri->ang += 768; + if ((result.type == kHitSector || result.type == kHitSprite) && (actor->cgg == 0)) spri->ang += 768; } else { if (spri->statnum == STAT_PROJECTILE) - retval = clipmove_ex(&spri->x, &spri->y, &daz, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), 8L, (4 << 8), (4 << 8), cliptype, result); else - retval = clipmove_ex(&spri->x, &spri->y, &daz, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), 128, (4 << 8), (4 << 8), cliptype, result); } @@ -446,10 +445,10 @@ int movesprite_ex_r(DDukeActor* actor, int xchange, int ychange, int zchange, un daz = spri->z + ((zchange * TICSPERFRAME) >> 3); if ((daz > actor->ceilingz) && (daz <= actor->floorz)) spri->z = daz; - else if (retval == 0) + else if (result.type == kHitNone) return result.setSector(dasectnum); - return retval; + return result.type; } //--------------------------------------------------------------------------- diff --git a/source/games/duke/src/dukeactor.h b/source/games/duke/src/dukeactor.h index d7804b525..43279e32b 100644 --- a/source/games/duke/src/dukeactor.h +++ b/source/games/duke/src/dukeactor.h @@ -179,9 +179,11 @@ inline int movesprite_ex(DDukeActor* actor, int xchange, int ychange, int zchang return f(actor, xchange, ychange, zchange, cliptype, result); } -inline int clipmove_ex(int* x, int* y, int* z, short* sect, int xv, int yv, int wal, int ceil, int flor, int ct, Collision& result) +inline int clipmove_ex(int* x, int* y, int* z, int* sect, int xv, int yv, int wal, int ceil, int flor, int ct, Collision& result) { - int res = clipmove(x, y, z, sect, xv, yv, wal, ceil, flor, ct); + short sect16 = *sect; + int res = clipmove(x, y, z, §16, xv, yv, wal, ceil, flor, ct); + *sect = sect16; return result.setFromEngine(res); } diff --git a/source/games/duke/src/player.cpp b/source/games/duke/src/player.cpp index ff14829e7..970367ff0 100644 --- a/source/games/duke/src/player.cpp +++ b/source/games/duke/src/player.cpp @@ -618,8 +618,8 @@ void playerisdead(int snum, int psectlotag, int fz, int cz) s->zvel = -348; } - clipmove(&p->pos.x, &p->pos.y, &p->pos.z, &p->cursectnum, 0, 0, 164, (4 << 8), (4 << 8), CLIPMASK0); - // p->bobcounter += 32; + Collision coll; + clipmove_ex(&p->pos.x, &p->pos.y, &p->pos.z, &p->cursectnum, 0, 0, 164, (4 << 8), (4 << 8), CLIPMASK0, coll); } backupplayer(p); diff --git a/source/games/duke/src/premap.cpp b/source/games/duke/src/premap.cpp index 4a099c5f3..987d5e968 100644 --- a/source/games/duke/src/premap.cpp +++ b/source/games/duke/src/premap.cpp @@ -945,7 +945,9 @@ static int LoadTheMap(MapRecord *mi, struct player_struct *p, int gamemode) } currentLevel = mi; - engineLoadBoard(mi->fileName, isShareware(), &p->pos, &lbang, &p->cursectnum); + short sect; + engineLoadBoard(mi->fileName, isShareware(), &p->pos, &lbang, §);// &p->cursectnum); + p->cursectnum = sect; SECRET_SetMapName(mi->DisplayName(), mi->name); STAT_NewLevel(mi->fileName); diff --git a/source/games/duke/src/sectors_d.cpp b/source/games/duke/src/sectors_d.cpp index 92a9d9e2e..d5d82d5d4 100644 --- a/source/games/duke/src/sectors_d.cpp +++ b/source/games/duke/src/sectors_d.cpp @@ -1410,7 +1410,7 @@ void checkhitsprite_d(DDukeActor* targ, DDukeActor* proj) if ((s->cstat & 48) == 0) s->ang = (pspr->ang + 1024) & 2047; s->xvel = -(pspr->extra << 2); - short j = s->sectnum; + j = s->sectnum; pushmove(&s->x, &s->y, &s->z, &j, 128L, (4 << 8), (4 << 8), CLIPMASK0); if (j != s->sectnum && j >= 0 && j < MAXSECTORS) changeactorsect(targ, j); diff --git a/source/games/duke/src/types.h b/source/games/duke/src/types.h index 9d92ba1c1..d60c76064 100644 --- a/source/games/duke/src/types.h +++ b/source/games/duke/src/types.h @@ -198,7 +198,8 @@ struct player_struct int aim_mode, ftt; - short cursectnum, last_extra, subweapon; + int cursectnum; + short last_extra, subweapon; short ammo_amount[MAX_WEAPONS], frag, fraggedself; short curr_weapon, last_weapon, tipincs, wantweaponfire; @@ -302,6 +303,11 @@ struct Collision int legacyVal; // should be removed later, but needed for converting back for unadjusted code. DDukeActor* actor; + Collision() = default; + explicit Collision(int v) + { + setFromEngine(v); + } int setNone() { type = kHitNone; diff --git a/wadsrc/static/zscript/games/duke/dukegame.zs b/wadsrc/static/zscript/games/duke/dukegame.zs index 25ef14cad..995cb7c5f 100644 --- a/wadsrc/static/zscript/games/duke/dukegame.zs +++ b/wadsrc/static/zscript/games/duke/dukegame.zs @@ -158,9 +158,9 @@ struct DukePlayer native int bobcounter; native int randomflamex, crack_time; - native int aim_mode, ftt; + native int cursectnum, aim_mode, ftt; - native int16 cursectnum, last_extra, subweapon; + native int16 last_extra, subweapon; native int16 ammo_amount[DukeWpn.MAX_WEAPONS], frag, fraggedself; native int16 curr_weapon, last_weapon, tipincs, wantweaponfire;