From 4f47472ef4cacaa72215fcfce87aa2552a93bdd7 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 13 Oct 2022 00:25:30 +0200 Subject: [PATCH] - floatified the vect variables. No change to the logic yet, only the copies have been transitioned. --- source/games/sw/src/game.h | 26 ++++++++----------- source/games/sw/src/player.cpp | 47 +++++++++++++++++++--------------- source/games/sw/src/save.cpp | 20 +++++++-------- 3 files changed, 47 insertions(+), 46 deletions(-) diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index b89bb8361..59926c9d0 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -581,13 +581,9 @@ struct REMOTE_CONTROL { sectortype* cursectp, * lastcursectp; int pang; - vec2_t _vect, _ovect, _slide_vect; + DVector2 vect, ovect, slide_vect; DVector3 pos; SECTOR_OBJECT* sop_control; - - vec2_t int_vect() const { return _vect; } - vec2_t int_ovect() const { return _ovect; } - vec2_t int_slide_vect() const { return _slide_vect; } }; struct PLAYER @@ -633,17 +629,17 @@ struct PLAYER DVector3 si; // save player interp position for PlayerSprite DAngle siang; - vec2_t _vect, _ovect, _slide_vect; // these need floatification, but must be done together. vect is in 14.18 format! - vec2_t int_vect() const { return _vect; } - vec2_t int_ovect() const { return _ovect; } - vec2_t int_slide_vect() const { return _slide_vect; } + DVector2 vect, ovect, slide_vect; // these need floatification, but must be done together. vect is in 14.18 format! + vec2_t int_vect() const { return vec2_t(FloatToFixed<18>(vect.X), FloatToFixed<18>(vect.Y)); } + vec2_t int_ovect() const { return vec2_t(FloatToFixed<18>(ovect.X), FloatToFixed<18>(ovect.Y)); } + vec2_t int_slide_vect() const { return vec2_t(FloatToFixed<18>(slide_vect.X), FloatToFixed<18>(slide_vect.Y)); } - void set_int_vect_x(int v) { _vect.X = v; } - void set_int_vect_y(int v) { _vect.Y = v; } - void add_int_vect_x(int v) { _vect.X += v; } - void add_int_vect_y(int v) { _vect.Y += v; } - void set_int_slide_vect_x(int v) { _slide_vect.X = v; } - void set_int_slide_vect_y(int v) { _slide_vect.Y = v; } + void set_int_vect_x(int v) { vect.X = FixedToFloat<18>(v); } + void set_int_vect_y(int v) { vect.Y = FixedToFloat<18>(v); } + void add_int_vect_x(int v) { vect.X += FixedToFloat<18>(v); } + void add_int_vect_y(int v) { vect.Y += FixedToFloat<18>(v); } + void set_int_slide_vect_x(int v) { slide_vect.X = FixedToFloat<18>(v); } + void set_int_slide_vect_y(int v) { slide_vect.Y = FixedToFloat<18>(v); } int friction; int16_t slide_ang; // todo: floatify diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index 35f5e892d..e35e244e0 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -1243,8 +1243,9 @@ DSWActor* DoPickTarget(DSWActor* actor, DAngle max_delta_ang, int skip_targets) void DoPlayerResetMovement(PLAYER* pp) { - pp->_vect = pp->_ovect = { 0, 0 }; - pp->_slide_vect = { 0, 0 }; + pp->vect.Zero(); + pp->ovect.Zero(); + pp->slide_vect.Zero(); pp->drive_avel = 0; pp->Flags &= ~(PF_PLAYER_MOVED); } @@ -1855,7 +1856,7 @@ void DoPlayerSlide(PLAYER* pp) pp->set_int_slide_vect_y(MulScale(pp->int_slide_vect().Y, PLAYER_SLIDE_FRICTION, 16)); if (abs(pp->int_slide_vect().X) < 12800 && abs(pp->int_slide_vect().Y) < 12800) - pp->_slide_vect = { 0, 0 }; + pp->slide_vect.Zero(); push_ret = pushmove(pp->pos, &pp->cursector, ((int)actor->spr.clipdist<<2), pp->p_ceiling_dist, pp->p_floor_dist, CLIPMASK_PLAYER); if (push_ret < 0) @@ -1959,7 +1960,7 @@ void DoPlayerMove(PLAYER* pp) DoPlayerSlide(pp); - pp->_ovect = pp->_vect; + pp->ovect = pp->vect; pp->add_int_vect_x(((pp->input.fvel*synctics*2)<<6)); pp->add_int_vect_y(((pp->input.svel*synctics*2)<<6)); @@ -1987,7 +1988,7 @@ void DoPlayerMove(PLAYER* pp) } if (abs(pp->int_vect().X) < 12800 && abs(pp->int_vect().Y) < 12800) - pp->_vect = { 0,0 }; + pp->vect.Zero(); actor->set_int_xvel(FindDistance2D(pp->int_vect().X,pp->int_vect().Y)>>14); @@ -2477,7 +2478,7 @@ void DoPlayerMoveVehicle(PLAYER* pp) else pp->Flags |= (PF_PLAYER_MOVED); - pp->_ovect = pp->_vect; + pp->ovect = pp->vect; if (sop->drive_speed) { @@ -2501,7 +2502,7 @@ void DoPlayerMoveVehicle(PLAYER* pp) } if (abs(pp->int_vect().X) < 12800 && abs(pp->int_vect().Y) < 12800) - pp->_vect = { 0, 0 }; + pp->vect.Zero(); pp->lastcursector = pp->cursector; z = pp->int_ppos().Z + Z(10); @@ -2581,7 +2582,8 @@ void DoPlayerMoveVehicle(PLAYER* pp) if (vel > 12000) { - pp->_vect = pp->_ovect = { 0, 0 }; + pp->vect.Zero(); + pp->ovect.Zero(); } } } @@ -2626,7 +2628,8 @@ void DoPlayerMoveVehicle(PLAYER* pp) if (vel > 12000) { - pp->_vect = pp->_ovect = { 0, 0 }; + pp->vect.Zero(); + pp->ovect.Zero(); } } } @@ -3090,7 +3093,7 @@ void DoPlayerClimb(PLAYER* pp) pp->set_int_vect_x(MulScale(pp->int_vect().X, PLAYER_CLIMB_FRICTION, 16)); pp->set_int_vect_y(MulScale(pp->int_vect().Y, PLAYER_CLIMB_FRICTION, 16)); if (abs(pp->int_vect().X) < 12800 && abs(pp->int_vect().Y) < 12800) - pp->_vect = { 0, 0 }; + pp->vect.Zero(); climbVel = DVector2(pp->int_vect().X, pp->int_vect().Y).Length() * (1. / 512) * zinttoworld; dot = DOT_PRODUCT_2D(pp->int_vect().X, pp->int_vect().Y, pp->angle.ang.Cos() * (1 << 14), pp->angle.ang.Sin() * (1 << 14)); @@ -4955,9 +4958,9 @@ void PlayerToRemote(PLAYER* pp) pp->remote.pos = pp->pos; - pp->remote._vect = pp->_vect; - pp->remote._ovect = pp->_ovect; - pp->remote._slide_vect = pp->_slide_vect; + pp->remote.vect = pp->vect; + pp->remote.ovect = pp->ovect; + pp->remote.slide_vect = pp->slide_vect; } void RemoteToPlayer(PLAYER* pp) @@ -4967,9 +4970,9 @@ void RemoteToPlayer(PLAYER* pp) pp->pos = pp->remote.pos; - pp->_vect = pp->remote._vect; - pp->_ovect = pp->remote._ovect; - pp->_slide_vect = pp->remote._slide_vect; + pp->vect = pp->remote.vect; + pp->ovect = pp->remote.ovect; + pp->slide_vect = pp->remote.slide_vect; } void PlayerRemoteReset(PLAYER* pp, sectortype* sect) @@ -4981,16 +4984,18 @@ void PlayerRemoteReset(PLAYER* pp, sectortype* sect) pp->pos.XY() = rsp->spr.pos.XY(); pp->pos.Z = sect->floorz - PLAYER_HEIGHTF; - pp->_vect = pp->_ovect = pp->_slide_vect = { 0,0 }; + pp->vect.Zero(); + pp->ovect.Zero(); + pp->slide_vect.Zero(); UpdatePlayerSprite(pp); } void PlayerRemoteInit(PLAYER* pp) { - pp->remote._vect = { 0,0 }; - pp->remote._ovect = { 0,0 }; - pp->remote._slide_vect = { 0,0 }; + pp->remote.vect.Zero(); + pp->remote.ovect.Zero(); + pp->remote.slide_vect.Zero(); } void DoPlayerStopOperate(PLAYER* pp) @@ -5397,7 +5402,7 @@ void DoPlayerBeginDie(PLAYER* pp) pp->input.actions &= ~SB_CENTERVIEW; pp->friction = PLAYER_RUN_FRICTION; - pp->_slide_vect = { 0,0 }; + pp->slide_vect.Zero(); pp->p_floor_dist = PLAYER_WADE_FLOOR_DIST; pp->p_ceiling_dist = PLAYER_WADE_CEILING_DIST; ASSERT(pp->DeathType < SIZ(PlayerDeathFunc)); diff --git a/source/games/sw/src/save.cpp b/source/games/sw/src/save.cpp index 8eff4b19c..d68626c22 100644 --- a/source/games/sw/src/save.cpp +++ b/source/games/sw/src/save.cpp @@ -394,10 +394,10 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, REMOTE_CONTROL& w, arc("cursectnum", w.cursectp) ("lastcursectnum", w.lastcursectp) ("pang", w.pang) - ("xvect", w._vect.X) - ("yvect", w._vect.Y) - ("slide_xvect", w._slide_vect.X) - ("slide_yvect", w._slide_vect.Y) + ("xvect", w.vect.X) + ("yvect", w.vect.Y) + ("slide_xvect", w.slide_vect.X) + ("slide_yvect", w.slide_vect.Y) ("x", w.pos.X) ("y", w.pos.Y) ("z", w.pos.Z) @@ -406,7 +406,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, REMOTE_CONTROL& w, } if (arc.isReading()) { - w._ovect = w.int_vect(); + w.ovect = w.vect; } return arc; } @@ -464,11 +464,11 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, PLAYER& w, PLAYER* ("siy", w.si.Y) ("siz", w.si.Z) ("siang", w.siang) - ("xvect", w._vect.X) - ("yvect", w._vect.Y) + ("xvect", w.vect.X) + ("yvect", w.vect.Y) ("friction", w.friction) - ("slide_xvect", w._slide_vect.X) - ("slide_yvect", w._slide_vect.Y) + ("slide_xvect", w.slide_vect.X) + ("slide_yvect", w.slide_vect.Y) ("slide_ang", w.slide_ang) ("slide_dec", w.slide_dec) ("drive_avel", w.drive_avel) @@ -575,7 +575,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, PLAYER& w, PLAYER* if (arc.isReading()) { w.opos = w.pos; - w._ovect = w.int_vect(); + w.ovect = w.vect; w.obob_z = w.bob_z; w.input = {}; w.lastinput = {};