- cleaned up Duke's main GameTicker function.

* moved the part that alters the input before queuing it to GetInput
* moved moveloop into the main function
* reshuffled a few things for better grouping by task.
This commit is contained in:
Christoph Oelckers 2020-08-29 21:20:10 +02:00
parent 20426a5a4f
commit fab561d757
11 changed files with 82 additions and 79 deletions

View file

@ -118,7 +118,7 @@ CCMD(togglefollow)
gi->ResetFollowPos(true);
}
glcycle_t thinktime, actortime, gameupdatetime, drawtime;
cycle_t thinktime, actortime, gameupdatetime, drawtime;
gamestate_t gamestate = GS_STARTUP;

View file

@ -229,8 +229,6 @@ CUSTOM_CVARD(Int, in_mousebias, 0, CVAR_GLOBALCONFIG|CVAR_ARCHIVE, "emulates the
else if (self > 32) self = 32;
}
CVARD(Bool, in_mousesmoothing, false, CVAR_GLOBALCONFIG|CVAR_ARCHIVE, "enable/disable mouse input smoothing")
CUSTOM_CVARD(Float, in_mousesensitivity, 1, CVAR_ARCHIVE|CVAR_GLOBALCONFIG, "changes the mouse sensitivity")
{
if (self < 0) self = 0;

View file

@ -88,7 +88,6 @@ EXTERN_CVAR(Int, gl_ssao)
EXTERN_CVAR(Bool, use_joystick)
EXTERN_CVAR(Int, in_mousebias)
EXTERN_CVAR(Bool, in_mouseflip)
EXTERN_CVAR(Bool, in_mousesmoothing)
EXTERN_CVAR(Float, in_mousesensitivity)
EXTERN_CVAR(Float, in_mousescalex)
EXTERN_CVAR(Float, in_mousescaley)

View file

@ -5,6 +5,7 @@ bool System_WantGuiCapture(); // During playing this tells us whether the game m
#include <stdint.h>
#include "vectors.h"
#include "engineerrors.h"
#include "packet.h"
struct GameStats
{
@ -91,6 +92,7 @@ struct GameInterface
virtual void ExitFromMenu() { throw CExitEvent(0); }
virtual ReservedSpace GetReservedScreenSpace(int viewsize) { return { 0, 0 }; }
virtual void ResetFollowPos(bool) {}
virtual void GetInput(InputPacket* packet) {}
};

View file

@ -22,7 +22,7 @@
#include "stats.h"
#include "binaryangle.h"
extern glcycle_t drawtime, actortime, thinktime, gameupdatetime;
extern cycle_t drawtime, actortime, thinktime, gameupdatetime;
BEGIN_DUKE_NS
@ -57,6 +57,7 @@ struct GameInterface : public ::GameInterface
ReservedSpace GetReservedScreenSpace(int viewsize) override;
void DrawPlayerSprite(const DVector2& origin, bool onteam) override;
void ResetFollowPos(bool message) override;
void GetInput(InputPacket* packet) override;
};

View file

@ -212,7 +212,7 @@ void dobonus(int bonusonly, const CompletionFunc& completion);
void dobonus_d(bool bonusonly, const CompletionFunc& completion);
void dobonus_r(bool bonusonly, const CompletionFunc& completion);
void displayrest(double smoothratio);
void drawoverlays(double smoothratio);
void drawbackground(void);
void displayrooms(int32_t playerNum, double smoothratio);
void setgamepalette(int palid);
@ -234,7 +234,6 @@ void apply_seasick(player_struct* p, double scalefactor);
void calcviewpitch(player_struct* p, double factor);
void sethorizon(int snum, ESyncBits actions, double factor, fixed_t adjustment);
bool movementBlocked(int snum);
void GetInput();
void startmainmenu();
void loadcons();

View file

@ -235,7 +235,7 @@ void V_AddBlend (float r, float g, float b, float a, float v_blend[4])
//
//---------------------------------------------------------------------------
void displayrest(double smoothratio)
void drawoverlays(double smoothratio)
{
int i, j;
unsigned char fader = 0, fadeg = 0, fadeb = 0, fadef = 0, tintr = 0, tintg = 0, tintb = 0, tintf = 0, dotint = 0;

View file

@ -51,7 +51,6 @@ static int bufferjitter;
void clearfifo(void)
{
loc = {};
memset(&inputfifo, 0, sizeof(inputfifo));
memset(sync, 0, sizeof(sync));
}
@ -280,48 +279,17 @@ int domovethings()
//
//---------------------------------------------------------------------------
int moveloop()
{
prediction();
if (numplayers < 2) bufferjitter = 0;
while (shouldprocessinput(myconnectindex))
{
if( domovethings() ) return 1;
}
return 0;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
static void checkTimerActive()
{
FStat *stat = FStat::FindStat("fps");
glcycle_t::active = (stat != NULL && stat->isActive());
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
bool GameTicker()
void GameTicker()
{
if (ps[myconnectindex].gm == MODE_DEMO)
{
M_ClearMenus();
return true;
gamestate = GS_STARTUP;
return;
}
//Net_GetPackets();
nonsharedkeys();
checkTimerActive();
gameupdatetime.Reset();
gameupdatetime.Clock();
@ -332,31 +300,24 @@ bool GameTicker()
while (playrunning() && currentTic - lastTic >= 1)
{
lastTic = currentTic;
GetInput();
auto const pPlayer = &ps[myconnectindex];
auto const q16ang = fix16_to_int(pPlayer->q16ang);
auto& input = nextinput(myconnectindex);
input = loc;
input.fvel = mulscale9(loc.fvel, sintable[(q16ang + 2560) & 2047]) +
mulscale9(loc.svel, sintable[(q16ang + 2048) & 2047]) +
pPlayer->fric.x;
input.svel = mulscale9(loc.fvel, sintable[(q16ang + 2048) & 2047]) +
mulscale9(loc.svel, sintable[(q16ang + 1536) & 2047]) +
pPlayer->fric.y;
loc = {};
gi->GetInput(&input);
advancequeue(myconnectindex);
if (playrunning())
{
moveloop();
prediction();
if (numplayers < 2) bufferjitter = 0;
while (shouldprocessinput(myconnectindex))
{
if (domovethings()) break;
}
}
}
double const smoothRatio = playrunning() ? I_GetTimeFrac() * MaxSmoothRatio : MaxSmoothRatio;
gameupdatetime.Unclock();
if (ps[myconnectindex].gm & (MODE_EOL | MODE_RESTART))
@ -366,17 +327,23 @@ bool GameTicker()
if (!cl_syncinput)
{
GetInput();
gi->GetInput(nullptr);
}
nonsharedkeys();
S_Update();
drawtime.Reset();
drawtime.Clock();
S_Update();
videoSetBrightness(thunder_brightness);
double const smoothRatio = playrunning() ? I_GetTimeFrac() * MaxSmoothRatio : MaxSmoothRatio;
displayrooms(screenpeek, smoothRatio);
displayrest(smoothRatio);
drawoverlays(smoothRatio);
drawtime.Unclock();
return (ps[myconnectindex].gm & MODE_DEMO);
if (ps[myconnectindex].gm == MODE_DEMO)
{
gamestate = GS_STARTUP;
}
}
//---------------------------------------------------------------------------
@ -393,18 +360,9 @@ void startmainmenu()
FX_StopAllSounds();
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void GameInterface::RunGameFrame()
static void Startup()
{
switch (gamestate)
{
default:
case GS_STARTUP:
I_ResetTime();
lastTic = -1;
gameclock = 0;
@ -432,6 +390,21 @@ void GameInterface::RunGameFrame()
{
fi.ShowLogo([](bool) { startmainmenu(); });
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void GameInterface::RunGameFrame()
{
switch (gamestate)
{
default:
case GS_STARTUP:
Startup();
break;
case GS_MENUSCREEN:
@ -440,13 +413,12 @@ void GameInterface::RunGameFrame()
break;
case GS_LEVEL:
if (GameTicker()) gamestate = GS_STARTUP;
else videoSetBrightness(thunder_brightness);
GameTicker();
break;
case GS_INTERMISSION:
case GS_INTRO:
RunScreenJobFrame(); // This handles continuation through its completion callback.
RunScreenJobFrame();
break;
}

View file

@ -63,7 +63,6 @@ int16_t max_ammo_amount[MAX_WEAPONS];
int16_t weaponsandammosprites[15];
int PHEIGHT = PHEIGHT_DUKE;
int duke3d_globalflags;
InputPacket loc;
uint8_t ready2send;
int playerswhenstarted;
int show_shareware;

View file

@ -51,7 +51,6 @@ extern int16_t weaponsandammosprites[15];
extern int32_t PHEIGHT;
extern int duke3d_globalflags;
extern uint8_t ready2send;
extern InputPacket loc;
extern int playerswhenstarted;
extern int show_shareware;
extern int screenpeek;

View file

@ -44,6 +44,7 @@ static int nonsharedtimer;
static int turnheldtime;
static int lastcontroltime;
static double lastCheck;
static InputPacket loc; // input accumulation buffer.
void GameInterface::ResetFollowPos(bool message)
{
@ -1033,7 +1034,7 @@ static void FinalizeInput(int playerNum, InputPacket& input, bool vehicle)
//
//---------------------------------------------------------------------------
void GetInput()
static void GetInputInternal(InputPacket &locInput)
{
double elapsedInputTicks;
auto const p = &ps[myconnectindex];
@ -1090,14 +1091,47 @@ void GetInput()
}
}
//---------------------------------------------------------------------------
//
// External entry point
//
//---------------------------------------------------------------------------
void GameInterface::GetInput(InputPacket* packet)
{
GetInputInternal(loc);
if (packet)
{
auto const pPlayer = &ps[myconnectindex];
auto const q16ang = fix16_to_int(pPlayer->q16ang);
*packet = loc;
auto fvel = loc.fvel;
auto svel = loc.svel;
packet->fvel = mulscale9(fvel, sintable[(q16ang + 2560) & 2047]) +
mulscale9(svel, sintable[(q16ang + 2048) & 2047]) +
pPlayer->fric.x;
packet->svel = mulscale9(fvel, sintable[(q16ang + 2048) & 2047]) +
mulscale9(svel, sintable[(q16ang + 1536) & 2047]) +
pPlayer->fric.y;
loc = {};
}
}
//---------------------------------------------------------------------------
//
// This is called from ImputState::ClearAllInput and resets all static state being used here.
//
//---------------------------------------------------------------------------
void GameInterface::clearlocalinputstate()
{
loc = {};
nonsharedtimer = 0;
turnheldtime = 0;
lastcontroltime = 0;
lastCheck = 0;
}
END_DUKE_NS