From a9b19943dd8b3a9df21853d95e55f022b3d02f8d Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 1 Sep 2022 19:17:51 +0200 Subject: [PATCH] - floatified bob_z and all actor spawns using it. --- source/games/sw/src/draw.cpp | 2 +- source/games/sw/src/game.h | 3 ++- source/games/sw/src/jweapon.cpp | 16 ++++---------- source/games/sw/src/player.cpp | 14 +++--------- source/games/sw/src/weapon.cpp | 28 ++++++++++++------------ wadsrc/static/zscript/games/sw/swgame.zs | 2 +- 6 files changed, 25 insertions(+), 40 deletions(-) diff --git a/source/games/sw/src/draw.cpp b/source/games/sw/src/draw.cpp index eb29a0d3c..0152b6650 100644 --- a/source/games/sw/src/draw.cpp +++ b/source/games/sw/src/draw.cpp @@ -1465,7 +1465,7 @@ void drawscreen(PLAYER* pp, double smoothratio, bool sceneonly) if (cl_viewbob) { tz += bob_amt; - tz += interpolatedvalue(pp->obob_z, pp->bob_z, smoothratio); + tz += interpolatedvalue(pp->obob_z, pp->bob_z, smoothratio) * zworldtoint; } // recoil only when not in camera diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index d0d49532a..46d43d518 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -664,7 +664,8 @@ struct PLAYER int16_t WadeDepth; int16_t bob_ndx; int16_t bcnt; // bob count - int bob_z, obob_z; + double bob_z, obob_z; + int int_bob_z() const { return bob_z * worldtoint; } //Multiplayer variables InputPacket input; diff --git a/source/games/sw/src/jweapon.cpp b/source/games/sw/src/jweapon.cpp index 2ce3c6c87..02ae19ba8 100644 --- a/source/games/sw/src/jweapon.cpp +++ b/source/games/sw/src/jweapon.cpp @@ -1206,7 +1206,6 @@ int DoRadiationCloud(DSWActor* actor) int PlayerInitChemBomb(PLAYER* pp) { DSWActor* plActor = pp->actor; - int nx, ny, nz; short oclipdist; @@ -1215,14 +1214,11 @@ int PlayerInitChemBomb(PLAYER* pp) if (!pp->insector()) return 0; - nx = pp->int_ppos().X; - ny = pp->int_ppos().Y; - nz = pp->int_ppos().Z + pp->bob_z + Z(8); + auto pos = pp->pos.plusZ(pp->bob_z + 8); // Spawn a shot // Inserting and setting up variables - auto actorNew = SpawnActor(STAT_MISSILE, CHEMBOMB, s_ChemBomb, pp->cursector, - nx, ny, nz, pp->angle.ang.Buildang(), CHEMBOMB_VELOCITY); + auto actorNew = SpawnActor(STAT_MISSILE, CHEMBOMB, s_ChemBomb, pp->cursector, pos, pp->angle.ang, CHEMBOMB_VELOCITY); // don't throw it as far if crawling if (pp->Flags & (PF_CRAWLING)) @@ -1560,7 +1556,6 @@ void SpawnFlashBombOnActor(DSWActor* actor) int PlayerInitCaltrops(PLAYER* pp) { DSWActor* plActor = pp->actor; - int nx, ny, nz; short oclipdist; PlaySound(DIGI_THROW, pp, v3df_dontpan | v3df_doppler); @@ -1568,12 +1563,9 @@ int PlayerInitCaltrops(PLAYER* pp) if (!pp->insector()) return 0; - nx = pp->int_ppos().X; - ny = pp->int_ppos().Y; - nz = pp->int_ppos().Z + pp->bob_z + Z(8); + auto pos = pp->pos.plusZ(pp->bob_z + 8); - auto actorNew = SpawnActor(STAT_DEAD_ACTOR, CALTROPS, s_Caltrops, pp->cursector, - nx, ny, nz, pp->angle.ang.Buildang(), (CHEMBOMB_VELOCITY + RandomRange(CHEMBOMB_VELOCITY)) / 2); + auto actorNew = SpawnActor(STAT_DEAD_ACTOR, CALTROPS, s_Caltrops, pp->cursector, pos, pp->angle.ang, (CHEMBOMB_VELOCITY + RandomRange(CHEMBOMB_VELOCITY)) / 2); // don't throw it as far if crawling if (pp->Flags & (PF_CRAWLING)) diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index 462a23016..21867768a 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -1607,8 +1607,7 @@ void DoPlayerBob(PLAYER* pp) pp->bcnt &= 2047; // move pp->q16horiz up and down from 100 using sintable - //pp->bob_z = Z((8 * bsin(pp->bcnt)) >> 14); - pp->bob_z = MulScale(Z(amt), bsin(pp->bcnt), 14); + pp->bob_z = amt * DAngle::fromBuild(pp->bcnt).Sin(); } void DoPlayerBeginRecoil(PLAYER* pp, short pix_amt) @@ -1661,7 +1660,7 @@ void UpdatePlayerUnderSprite(PLAYER* pp) ASSERT(act_over->hasU()); // dont bother spawning if you ain't really in the water - water_level_z = act_over->sector()->floorz; // - Z(pp->WadeDepth); + water_level_z = act_over->sector()->floorz; // if not below water above_water = (ActorZOfBottom(act_over) <= water_level_z); @@ -1737,13 +1736,6 @@ void UpdatePlayerSprite(PLAYER* pp) actor->spr.pos.Z = pp->pos.Z + PLAYER_CRAWL_HEIGHTF; ChangeActorSect(pp->actor, pp->cursector); } -#if 0 - else if (pp->DoPlayerAction == DoPlayerSwim) - { - actor->spr.z = pp->loz - Z(pp->WadeDepth) + Z(1); - ChangeActorSect(pp->actor, pp->cursector); - } -#endif else if (pp->DoPlayerAction == DoPlayerWade) { actor->spr.pos.Z = pp->pos.Z + PLAYER_HEIGHTF; @@ -1977,7 +1969,7 @@ void DoPlayerMove(PLAYER* pp) friction = pp->friction; if (!(pp->Flags & PF_SWIMMING) && pp->WadeDepth) { - friction -= pp->WadeDepth * 100L; + friction -= pp->WadeDepth * 100; } pp->vect.X = MulScale(pp->vect.X, friction, 16); diff --git a/source/games/sw/src/weapon.cpp b/source/games/sw/src/weapon.cpp index 0cb203dcb..a9528bf2d 100644 --- a/source/games/sw/src/weapon.cpp +++ b/source/games/sw/src/weapon.cpp @@ -12369,7 +12369,7 @@ int InitStar(PLAYER* pp) nx = pp->int_ppos().X; ny = pp->int_ppos().Y; - nz = pp->int_ppos().Z + pp->bob_z + Z(8); + nz = pp->int_ppos().Z + pp->int_bob_z() + Z(8); // Spawn a shot // Inserting and setting up variables @@ -12607,7 +12607,7 @@ int InitShotgun(PLAYER* pp) nx = pp->int_ppos().X; ny = pp->int_ppos().Y; - daz = nz = pp->int_ppos().Z + pp->bob_z; + daz = nz = pp->int_ppos().Z + pp->int_bob_z(); daang = 64; if (WeaponAutoAimHitscan(pp->actor, &daz, &daang, false) != nullptr) @@ -12762,7 +12762,7 @@ int InitLaser(PLAYER* pp) nx = pp->int_ppos().X; ny = pp->int_ppos().Y; - nz = pp->int_ppos().Z + pp->bob_z + Z(8); + nz = pp->int_ppos().Z + pp->int_bob_z() + Z(8); // Spawn a shot // Inserting and setting up variables @@ -12862,7 +12862,7 @@ int InitRail(PLAYER* pp) nx = pp->int_ppos().X; ny = pp->int_ppos().Y; - nz = pp->int_ppos().Z + pp->bob_z + Z(11); + nz = pp->int_ppos().Z + pp->int_bob_z() + Z(11); // Spawn a shot // Inserting and setting up variables @@ -13025,7 +13025,7 @@ int InitRocket(PLAYER* pp) // Spawn a shot // Inserting and setting up variables - nz = pp->int_ppos().Z + pp->bob_z + Z(8); + nz = pp->int_ppos().Z + pp->int_bob_z() + Z(8); auto actorNew = SpawnActor(STAT_MISSILE, BOLT_THINMAN_R0, &s_Rocket[0][0], pp->cursector, nx, ny, nz, pp->angle.ang.Buildang(), ROCKET_VELOCITY); @@ -13131,8 +13131,8 @@ int InitBunnyRocket(PLAYER* pp) // Spawn a shot // Inserting and setting up variables - //nz = pp->posz + pp->bob_z + Z(12); - nz = pp->int_ppos().Z + pp->bob_z + Z(8); + //nz = pp->posz + pp->int_bob_z() + Z(12); + nz = pp->int_ppos().Z + pp->int_bob_z() + Z(8); auto actorNew = SpawnActor(STAT_MISSILE, BOLT_THINMAN_R4, &s_BunnyRocket[0][0], pp->cursector, nx, ny, nz, pp->angle.ang.Buildang(), ROCKET_VELOCITY); @@ -13233,7 +13233,7 @@ int InitNuke(PLAYER* pp) // Spawn a shot // Inserting and setting up variables - nz = pp->int_ppos().Z + pp->bob_z + Z(8); + nz = pp->int_ppos().Z + pp->int_bob_z() + Z(8); auto actorNew = SpawnActor(STAT_MISSILE, BOLT_THINMAN_R0, &s_Rocket[0][0], pp->cursector, nx, ny, nz, pp->angle.ang.Buildang(), 700); @@ -13409,7 +13409,7 @@ int InitMicro(PLAYER* pp) ang = pp->angle.ang.Buildang(); } - nz = pp->int_ppos().Z + pp->bob_z + Z(14); + nz = pp->int_ppos().Z + pp->int_bob_z() + Z(14); nz += Z(RandomRange(20)) - Z(10); // Spawn a shot @@ -14733,8 +14733,8 @@ int InitUzi(PLAYER* pp) if (RANDOM_P2(1024) < 400) InitTracerUzi(pp); - nz = pp->int_ppos().Z + pp->bob_z; - daz = pp->int_ppos().Z + pp->bob_z; + nz = pp->int_ppos().Z + pp->int_bob_z(); + daz = pp->int_ppos().Z + pp->int_bob_z(); daang = 32; if (WeaponAutoAimHitscan(pp->actor, &daz, &daang, false) != nullptr) { @@ -15854,7 +15854,7 @@ int InitGrenade(PLAYER* pp) nx = pp->int_ppos().X; ny = pp->int_ppos().Y; - nz = pp->int_ppos().Z + pp->bob_z + Z(8); + nz = pp->int_ppos().Z + pp->int_bob_z() + Z(8); // Spawn a shot // Inserting and setting up variables @@ -15988,7 +15988,7 @@ int InitMine(PLAYER* pp) nx = pp->int_ppos().X; ny = pp->int_ppos().Y; - nz = pp->int_ppos().Z + pp->bob_z + Z(8); + nz = pp->int_ppos().Z + pp->int_bob_z() + Z(8); // Spawn a shot // Inserting and setting up variables @@ -16114,7 +16114,7 @@ int InitFireball(PLAYER* pp) nx += pp->int_ppos().X; ny += pp->int_ppos().Y; - nz = pp->int_ppos().Z + pp->bob_z + Z(15); + nz = pp->int_ppos().Z + pp->int_bob_z() + Z(15); auto actorNew = SpawnActor(STAT_MISSILE, FIREBALL1, s_Fireball, pp->cursector, nx, ny, nz, pp->angle.ang.Buildang(), FIREBALL_VELOCITY); diff --git a/wadsrc/static/zscript/games/sw/swgame.zs b/wadsrc/static/zscript/games/sw/swgame.zs index f2d0e3156..c73a50727 100644 --- a/wadsrc/static/zscript/games/sw/swgame.zs +++ b/wadsrc/static/zscript/games/sw/swgame.zs @@ -221,7 +221,7 @@ struct SWPlayer native native double pbob_amt; native int16 bob_ndx; native int16 bcnt; // bob count - native int bob_z, obob_z; + native double bob_z, obob_z; // must start out as 0 native int playerreadyflag;