- make sure that the static time counters in the input code do not accumulate while not in use.

The one for holding the turn key needs to be reset any time there is no turning and everything needs to be cleared when the input state is cleared. And all need to check for the case where the static state is not set yet.
This commit is contained in:
Christoph Oelckers 2020-07-18 13:27:24 +02:00
parent e70115ff5c
commit 36d61fc662
2 changed files with 57 additions and 25 deletions

View file

@ -42,6 +42,12 @@ BEGIN_DUKE_NS
static int WeaponToSend; static int WeaponToSend;
static ESyncBits BitsToSend; static ESyncBits BitsToSend;
// State timer counters.
static int nonsharedtimer;
static int turnheldtime;
static int lastcontroltime;
static double lastCheck;
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// //
// handles UI side input not handled via CCMDs or CVARs. // handles UI side input not handled via CCMDs or CVARs.
@ -51,8 +57,6 @@ static ESyncBits BitsToSend;
void nonsharedkeys(void) void nonsharedkeys(void)
{ {
static int nonsharedtimer;
if (ud.recstat == 2) if (ud.recstat == 2)
{ {
ControlInfo noshareinfo; ControlInfo noshareinfo;
@ -187,8 +191,17 @@ void nonsharedkeys(void)
if (ud.overhead_on != 0) if (ud.overhead_on != 0)
{ {
int j = (int)totalclock - nonsharedtimer; int j;
nonsharedtimer += j; if (nonsharedtimer > 0 || totalclock < nonsharedtimer)
{
j = (int)totalclock - nonsharedtimer;
nonsharedtimer += j;
}
else
{
j = 0;
nonsharedtimer = (int)totalclock;
}
if (buttonMap.ButtonDown(gamefunc_Enlarge_Screen)) if (buttonMap.ButtonDown(gamefunc_Enlarge_Screen))
ps[myconnectindex].zoom += mulscale6(j, max(ps[myconnectindex].zoom, 256)); ps[myconnectindex].zoom += mulscale6(j, max(ps[myconnectindex].zoom, 256));
@ -818,6 +831,19 @@ static void checkCrouchToggle(player_struct* p)
p->crouch_toggle = 0; p->crouch_toggle = 0;
} }
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
int getticssincelastupdate()
{
int tics = lastcontroltime == 0 || (int)totalclock < lastcontroltime ? 0 : (int)totalclock - lastcontroltime;
lastcontroltime = (int)totalclock;
return tics;
}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// //
// handles movement // handles movement
@ -862,10 +888,7 @@ static void processMovement(player_struct *p, input_t &input, ControlInfo &info,
} }
else else
{ {
static int turnheldtime; int tics = getticssincelastupdate();
static int lastcontroltime; // MED
int tics = (int)totalclock - lastcontroltime;
lastcontroltime = (int)totalclock;
if (buttonMap.ButtonDown(gamefunc_Turn_Left)) if (buttonMap.ButtonDown(gamefunc_Turn_Left))
{ {
@ -878,7 +901,11 @@ static void processMovement(player_struct *p, input_t &input, ControlInfo &info,
input.q16avel += fix16_from_dbl(2 * scaleFactor * (turnheldtime >= TURBOTURNTIME) ? turnamount : PREAMBLETURN); input.q16avel += fix16_from_dbl(2 * scaleFactor * (turnheldtime >= TURBOTURNTIME) ? turnamount : PREAMBLETURN);
} }
else else
{
turnheldtime = 0; turnheldtime = 0;
lastcontroltime = 0;
}
} }
if (loc.svel < abs(keymove)) if (loc.svel < abs(keymove))
@ -931,14 +958,10 @@ static void processMovement(player_struct *p, input_t &input, ControlInfo &info,
static int motoApplyTurn(player_struct* p, int turnl, int turnr, int bike_turn, bool goback, double factor) static int motoApplyTurn(player_struct* p, int turnl, int turnr, int bike_turn, bool goback, double factor)
{ {
static int turnheldtime;
static int lastcontroltime;
int tics = totalclock - lastcontroltime;
lastcontroltime = totalclock;
if (p->MotoSpeed == 0 || !p->on_ground) if (p->MotoSpeed == 0 || !p->on_ground)
{ {
turnheldtime = 0;
lastcontroltime = 0;
if (turnl) if (turnl)
{ {
p->TiltStatus -= (float)factor; p->TiltStatus -= (float)factor;
@ -954,6 +977,7 @@ static int motoApplyTurn(player_struct* p, int turnl, int turnr, int bike_turn,
} }
else else
{ {
int tics = getticssincelastupdate();
if (turnl || p->moto_drink < 0) if (turnl || p->moto_drink < 0)
{ {
turnheldtime += tics; turnheldtime += tics;
@ -991,6 +1015,7 @@ static int motoApplyTurn(player_struct* p, int turnl, int turnr, int bike_turn,
else else
{ {
turnheldtime = 0; turnheldtime = 0;
lastcontroltime = 0;
if (p->TiltStatus > 0) if (p->TiltStatus > 0)
p->TiltStatus -= (float)factor; p->TiltStatus -= (float)factor;
@ -1013,11 +1038,7 @@ static int motoApplyTurn(player_struct* p, int turnl, int turnr, int bike_turn,
static int boatApplyTurn(player_struct *p, int turnl, int turnr, int bike_turn, double factor) static int boatApplyTurn(player_struct *p, int turnl, int turnr, int bike_turn, double factor)
{ {
static int turnheldtime; int tics = getticssincelastupdate();
static int lastcontroltime;
int tics = totalclock - lastcontroltime;
lastcontroltime = totalclock;
if (p->MotoSpeed) if (p->MotoSpeed)
{ {
@ -1064,6 +1085,7 @@ static int boatApplyTurn(player_struct *p, int turnl, int turnr, int bike_turn,
else if (!p->NotOnWater) else if (!p->NotOnWater)
{ {
turnheldtime = 0; turnheldtime = 0;
lastcontroltime = 0;
if (p->TiltStatus > 0) if (p->TiltStatus > 0)
p->TiltStatus -= (float)factor; p->TiltStatus -= (float)factor;
@ -1074,6 +1096,11 @@ static int boatApplyTurn(player_struct *p, int turnl, int turnr, int bike_turn,
p->TiltStatus = 0; p->TiltStatus = 0;
} }
} }
else
{
turnheldtime = 0;
lastcontroltime = 0;
}
return 0; return 0;
} }
@ -1199,7 +1226,6 @@ static void FinalizeInput(int playerNum, input_t& input, bool vehicle)
void GetInput() void GetInput()
{ {
static double lastCheck;
double elapsedInputTicks; double elapsedInputTicks;
auto const p = &ps[myconnectindex]; auto const p = &ps[myconnectindex];
updatePauseStatus(); updatePauseStatus();
@ -1305,11 +1331,16 @@ void registerinputcommands()
C_RegisterFunction("invuse", nullptr, [](CCmdFuncPtr)->int { BitsToSend = SKB_INVENTORY; return CCMD_OK; }); C_RegisterFunction("invuse", nullptr, [](CCmdFuncPtr)->int { BitsToSend = SKB_INVENTORY; return CCMD_OK; });
} }
// This is called from ImputState::ClearAllInput // This is called from ImputState::ClearAllInput and resets all static state being used here.
void GameInterface::clearlocalinputstate() void GameInterface::clearlocalinputstate()
{ {
WeaponToSend = 0; WeaponToSend = 0;
BitsToSend = 0; BitsToSend = 0;
nonsharedtimer = 0;
turnheldtime = 0;
lastcontroltime = 0;
lastCheck = 0;
} }
END_DUKE_NS END_DUKE_NS

View file

@ -35,6 +35,8 @@ Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms
// PRIMITIVE // PRIMITIVE
BEGIN_DUKE_NS BEGIN_DUKE_NS
static bool sound445done; // what is this supposed to do? Looks broken.
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// //
// //
@ -2616,11 +2618,10 @@ void checksectors_r(int snum)
if (!isRRRA()) return; if (!isRRRA()) return;
if (numplayers == 1) if (numplayers == 1)
{ {
static bool alreadydone; // what is this supposed to do? Looks broken.
// This is from RedneckGDX - the version in RR Reconstruction looked like broken nonsense. // This is from RedneckGDX - the version in RR Reconstruction looked like broken nonsense.
if (S_CheckSoundPlaying(neartagsprite, 445) || alreadydone != 0) if (S_CheckSoundPlaying(neartagsprite, 445) || sound445done != 0)
{ {
if (!S_CheckSoundPlaying(neartagsprite, 445) && !S_CheckSoundPlaying(neartagsprite, 446) && !S_CheckSoundPlaying(neartagsprite, 447) && alreadydone != 0) if (!S_CheckSoundPlaying(neartagsprite, 445) && !S_CheckSoundPlaying(neartagsprite, 446) && !S_CheckSoundPlaying(neartagsprite, 447) && sound445done != 0)
{ {
if ((krand() % 2) == 1) if ((krand() % 2) == 1)
spritesound(446, neartagsprite); spritesound(446, neartagsprite);
@ -2631,7 +2632,7 @@ void checksectors_r(int snum)
else else
{ {
spritesound(445, neartagsprite); spritesound(445, neartagsprite);
alreadydone = 1; sound445done = 1;
} }
} }
return; return;