From 4355a447219c81237bf8520c537c224e427b718e Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sat, 18 Mar 2023 19:28:02 +1100 Subject: [PATCH] - Duke: Rework input blocking setup. * Takes the duplicated conditions out of the input handler and makes the ticker responsible by forcing synchronised input. --- source/core/gamecontrol.cpp | 6 +++ source/games/duke/src/gameexec.cpp | 4 +- source/games/duke/src/input.cpp | 37 ------------------- source/games/duke/src/player.cpp | 5 +++ source/games/duke/src/player_d.cpp | 12 +++++- source/games/duke/src/player_r.cpp | 12 +++++- source/games/duke/src/types.h | 5 +++ .../static/zscript/games/duke/actors/crane.zs | 1 + .../zscript/games/duke/actors/viewscreen.zs | 1 + wadsrc/static/zscript/razebase.zs | 1 + 10 files changed, 43 insertions(+), 41 deletions(-) diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index 364f968a9..2a7887895 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -1512,6 +1512,12 @@ DEFINE_ACTION_FUNCTION_NATIVE(_Raze, GetBuildTime, I_GetBuildTime) ACTION_RETURN_INT(I_GetBuildTime()); } +DEFINE_ACTION_FUNCTION_NATIVE(_Raze, forceSyncInput, setForcedSyncInput) +{ + setForcedSyncInput(); + return 0; +} + DEFINE_ACTION_FUNCTION(_Raze, PickTexture) { PARAM_PROLOGUE; diff --git a/source/games/duke/src/gameexec.cpp b/source/games/duke/src/gameexec.cpp index dbe99c024..094a668fb 100644 --- a/source/games/duke/src/gameexec.cpp +++ b/source/games/duke/src/gameexec.cpp @@ -551,7 +551,7 @@ void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor, break; case PLAYER_NEWOWNER: - if (bSet) ps[iPlayer].newOwner = vValue.safeActor(); + if (bSet && (ps[iPlayer].newOwner = vValue.safeActor())) setForcedSyncInput(); else SetGameVarID(lVar2, ps[iPlayer].newOwner, sActor, sPlayer); break; @@ -621,7 +621,7 @@ void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor, break; case PLAYER_ON_CRANE: - if (bSet) ps[iPlayer].on_crane = vValue.safeActor(); + if (bSet && (ps[iPlayer].on_crane = vValue.safeActor())) setForcedSyncInput(); else SetGameVarID(lVar2, (ps[iPlayer].on_crane), sActor, sPlayer); break; diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index cb77ec8ad..8136d78e6 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -741,41 +741,6 @@ static void processVehicleInput(player_struct *p, HIDInput* const hidInput, Inpu inputBuffer->avel += currInput->avel; } -//--------------------------------------------------------------------------- -// -// finalizes the input and passes it to the global input buffer -// -//--------------------------------------------------------------------------- - -static void FinalizeInput(player_struct *p, InputPacket& input) -{ - if (gamestate != GS_LEVEL || movementBlocked(p) || p->GetActor()->spr.extra <= 0) - { - // neutralize all movement when not in a game, blocked or in automap follow mode - loc.fvel = loc.svel = 0; - loc.avel = loc.horz = 0; - input.avel = input.horz = 0; - } - else - { - if (p->on_crane != nullptr) - { - loc.fvel = input.fvel = 0; - loc.svel = input.svel = 0; - } - - if (p->newOwner != nullptr || p->on_crane != nullptr) - { - loc.avel = input.avel = 0; - } - - if (p->newOwner != nullptr || (p->sync.actions & SB_CENTERVIEW && abs(p->GetActor()->spr.Angles.Pitch.Degrees()) > 2.2370)) - { - loc.horz = input.horz = 0; - } - } -} - //--------------------------------------------------------------------------- // @@ -808,8 +773,6 @@ void GameInterface::GetInput(const double scaleAdjust, InputPacket* packet) processMovement(&hidInput, &loc, &input, scaleAdjust, p->drink_amt); } - FinalizeInput(p, input); - if (!SyncInput() && p->GetActor()->spr.extra > 0) { p->Angles.CameraAngles.Yaw += p->adjustavel(input.avel); diff --git a/source/games/duke/src/player.cpp b/source/games/duke/src/player.cpp index 87b2a32bc..96ebdc601 100644 --- a/source/games/duke/src/player.cpp +++ b/source/games/duke/src/player.cpp @@ -545,6 +545,9 @@ void playerisdead(int snum, int psectlotag, double floorz, double ceilingz) auto p = &ps[snum]; auto actor = p->GetActor(); + // lock input when dead. + setForcedSyncInput(); + if (p->dead_flag == 0) { if (actor->spr.pal != 1) @@ -958,6 +961,8 @@ bool movementBlocked(player_struct *p) p->hard_landing || p->access_incs > 0 || p->knee_incs > 0 || + p->GetActor()->spr.extra <= 0 || + (p->dead_flag && !ud.god) || (blockingweapon() && p->kickback_pic > 1 && p->kickback_pic < weapondelay())); } diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index cdc7c255b..4c920a269 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -2713,6 +2713,7 @@ void processinput_d(int snum) if (p->newOwner != nullptr) { + setForcedSyncInput(); p->vel.X = p->vel.Y = 0; pact->vel.X = 0; @@ -2730,7 +2731,10 @@ void processinput_d(int snum) auto oldpos = p->GetActor()->opos; if (p->on_crane != nullptr) + { + setForcedSyncInput(); goto HORIZONLY; + } p->playerweaponsway(pact->vel.X); @@ -2765,6 +2769,7 @@ void processinput_d(int snum) doubvel = 0; p->vel.X = 0; p->vel.Y = 0; + setForcedSyncInput(); } else if (SyncInput()) { @@ -2985,7 +2990,12 @@ HORIZONLY: playerAimDown(snum, actions); } - if (SyncInput()) + if (p->centeringView()) + { + p->sync.horz = 0; + setForcedSyncInput(); + } + else if (SyncInput()) { p->GetActor()->spr.Angles.Pitch += GetPlayerHorizon(snum); } diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index 27d188228..c29d1806b 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -3382,6 +3382,7 @@ void processinput_r(int snum) if (p->newOwner != nullptr) { + setForcedSyncInput(); p->vel.X = p->vel.Y = 0; pact->vel.X = 0; @@ -3399,7 +3400,10 @@ void processinput_r(int snum) auto oldpos = p->GetActor()->opos; if (p->on_crane != nullptr) + { + setForcedSyncInput(); goto HORIZONLY; + } p->playerweaponsway(pact->vel.X); @@ -3448,6 +3452,7 @@ void processinput_r(int snum) doubvel = 0; p->vel.X = 0; p->vel.Y = 0; + setForcedSyncInput(); } else if (SyncInput()) { @@ -3796,7 +3801,12 @@ HORIZONLY: p->GetActor()->spr.Angles.Pitch += maphoriz(d); } - if (SyncInput()) + if (p->centeringView()) + { + p->sync.horz = 0; + setForcedSyncInput(); + } + else if (SyncInput()) { p->GetActor()->spr.Angles.Pitch += GetPlayerHorizon(snum); } diff --git a/source/games/duke/src/types.h b/source/games/duke/src/types.h index 368134a08..042cbde11 100644 --- a/source/games/duke/src/types.h +++ b/source/games/duke/src/types.h @@ -345,6 +345,11 @@ struct player_struct { bobpos = GetActor()->spr.pos.XY(); } + + bool centeringView() + { + return (sync.actions & SB_CENTERVIEW) && abs(GetActor()->spr.Angles.Pitch.Degrees()) > 2.2370; + } }; struct Cycler diff --git a/wadsrc/static/zscript/games/duke/actors/crane.zs b/wadsrc/static/zscript/games/duke/actors/crane.zs index b55db4265..414eeedad 100644 --- a/wadsrc/static/zscript/games/duke/actors/crane.zs +++ b/wadsrc/static/zscript/games/duke/actors/crane.zs @@ -151,6 +151,7 @@ class DukeCrane : DukeActor plr.on_crane = self; plr.actor.PlayActorSound("CRANEGRAB"); plr.settargetangle(self.angle + 180); + Raze.forceSyncInput(); } else { diff --git a/wadsrc/static/zscript/games/duke/actors/viewscreen.zs b/wadsrc/static/zscript/games/duke/actors/viewscreen.zs index 5a2962526..e04c9fd2b 100644 --- a/wadsrc/static/zscript/games/duke/actors/viewscreen.zs +++ b/wadsrc/static/zscript/games/duke/actors/viewscreen.zs @@ -47,6 +47,7 @@ class DukeViewscreen : DukeActor camsprite = self; user.newOwner = acti; + Raze.forceSyncInput(); return true; } } diff --git a/wadsrc/static/zscript/razebase.zs b/wadsrc/static/zscript/razebase.zs index a3f412e33..b4a161713 100644 --- a/wadsrc/static/zscript/razebase.zs +++ b/wadsrc/static/zscript/razebase.zs @@ -171,6 +171,7 @@ struct Raze static double bobval(double angle) { return sin(angle * (360. / 2048)); } native static TextureID PickTexture(TextureID texid); native static int GetBuildTime(); + native static void forceSyncInput(); native static Font PickBigFont(String cmptext = ""); native static Font PickSmallFont(String cmptext = ""); native static int SoundEnabled();