mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-28 12:30:46 +00:00
- 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:
parent
20426a5a4f
commit
fab561d757
11 changed files with 82 additions and 79 deletions
|
@ -118,7 +118,7 @@ CCMD(togglefollow)
|
||||||
gi->ResetFollowPos(true);
|
gi->ResetFollowPos(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
glcycle_t thinktime, actortime, gameupdatetime, drawtime;
|
cycle_t thinktime, actortime, gameupdatetime, drawtime;
|
||||||
|
|
||||||
gamestate_t gamestate = GS_STARTUP;
|
gamestate_t gamestate = GS_STARTUP;
|
||||||
|
|
||||||
|
|
|
@ -229,8 +229,6 @@ CUSTOM_CVARD(Int, in_mousebias, 0, CVAR_GLOBALCONFIG|CVAR_ARCHIVE, "emulates the
|
||||||
else if (self > 32) self = 32;
|
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")
|
CUSTOM_CVARD(Float, in_mousesensitivity, 1, CVAR_ARCHIVE|CVAR_GLOBALCONFIG, "changes the mouse sensitivity")
|
||||||
{
|
{
|
||||||
if (self < 0) self = 0;
|
if (self < 0) self = 0;
|
||||||
|
|
|
@ -88,7 +88,6 @@ EXTERN_CVAR(Int, gl_ssao)
|
||||||
EXTERN_CVAR(Bool, use_joystick)
|
EXTERN_CVAR(Bool, use_joystick)
|
||||||
EXTERN_CVAR(Int, in_mousebias)
|
EXTERN_CVAR(Int, in_mousebias)
|
||||||
EXTERN_CVAR(Bool, in_mouseflip)
|
EXTERN_CVAR(Bool, in_mouseflip)
|
||||||
EXTERN_CVAR(Bool, in_mousesmoothing)
|
|
||||||
EXTERN_CVAR(Float, in_mousesensitivity)
|
EXTERN_CVAR(Float, in_mousesensitivity)
|
||||||
EXTERN_CVAR(Float, in_mousescalex)
|
EXTERN_CVAR(Float, in_mousescalex)
|
||||||
EXTERN_CVAR(Float, in_mousescaley)
|
EXTERN_CVAR(Float, in_mousescaley)
|
||||||
|
|
|
@ -5,6 +5,7 @@ bool System_WantGuiCapture(); // During playing this tells us whether the game m
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "vectors.h"
|
#include "vectors.h"
|
||||||
#include "engineerrors.h"
|
#include "engineerrors.h"
|
||||||
|
#include "packet.h"
|
||||||
|
|
||||||
struct GameStats
|
struct GameStats
|
||||||
{
|
{
|
||||||
|
@ -91,6 +92,7 @@ struct GameInterface
|
||||||
virtual void ExitFromMenu() { throw CExitEvent(0); }
|
virtual void ExitFromMenu() { throw CExitEvent(0); }
|
||||||
virtual ReservedSpace GetReservedScreenSpace(int viewsize) { return { 0, 0 }; }
|
virtual ReservedSpace GetReservedScreenSpace(int viewsize) { return { 0, 0 }; }
|
||||||
virtual void ResetFollowPos(bool) {}
|
virtual void ResetFollowPos(bool) {}
|
||||||
|
virtual void GetInput(InputPacket* packet) {}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#include "stats.h"
|
#include "stats.h"
|
||||||
#include "binaryangle.h"
|
#include "binaryangle.h"
|
||||||
|
|
||||||
extern glcycle_t drawtime, actortime, thinktime, gameupdatetime;
|
extern cycle_t drawtime, actortime, thinktime, gameupdatetime;
|
||||||
|
|
||||||
BEGIN_DUKE_NS
|
BEGIN_DUKE_NS
|
||||||
|
|
||||||
|
@ -57,6 +57,7 @@ struct GameInterface : public ::GameInterface
|
||||||
ReservedSpace GetReservedScreenSpace(int viewsize) override;
|
ReservedSpace GetReservedScreenSpace(int viewsize) override;
|
||||||
void DrawPlayerSprite(const DVector2& origin, bool onteam) override;
|
void DrawPlayerSprite(const DVector2& origin, bool onteam) override;
|
||||||
void ResetFollowPos(bool message) override;
|
void ResetFollowPos(bool message) override;
|
||||||
|
void GetInput(InputPacket* packet) override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -212,7 +212,7 @@ void dobonus(int bonusonly, const CompletionFunc& completion);
|
||||||
void dobonus_d(bool bonusonly, const CompletionFunc& completion);
|
void dobonus_d(bool bonusonly, const CompletionFunc& completion);
|
||||||
void dobonus_r(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 drawbackground(void);
|
||||||
void displayrooms(int32_t playerNum, double smoothratio);
|
void displayrooms(int32_t playerNum, double smoothratio);
|
||||||
void setgamepalette(int palid);
|
void setgamepalette(int palid);
|
||||||
|
@ -234,7 +234,6 @@ void apply_seasick(player_struct* p, double scalefactor);
|
||||||
void calcviewpitch(player_struct* p, double factor);
|
void calcviewpitch(player_struct* p, double factor);
|
||||||
void sethorizon(int snum, ESyncBits actions, double factor, fixed_t adjustment);
|
void sethorizon(int snum, ESyncBits actions, double factor, fixed_t adjustment);
|
||||||
bool movementBlocked(int snum);
|
bool movementBlocked(int snum);
|
||||||
void GetInput();
|
|
||||||
void startmainmenu();
|
void startmainmenu();
|
||||||
void loadcons();
|
void loadcons();
|
||||||
|
|
||||||
|
|
|
@ -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;
|
int i, j;
|
||||||
unsigned char fader = 0, fadeg = 0, fadeb = 0, fadef = 0, tintr = 0, tintg = 0, tintb = 0, tintf = 0, dotint = 0;
|
unsigned char fader = 0, fadeg = 0, fadeb = 0, fadef = 0, tintr = 0, tintg = 0, tintb = 0, tintf = 0, dotint = 0;
|
||||||
|
|
|
@ -51,7 +51,6 @@ static int bufferjitter;
|
||||||
|
|
||||||
void clearfifo(void)
|
void clearfifo(void)
|
||||||
{
|
{
|
||||||
loc = {};
|
|
||||||
memset(&inputfifo, 0, sizeof(inputfifo));
|
memset(&inputfifo, 0, sizeof(inputfifo));
|
||||||
memset(sync, 0, sizeof(sync));
|
memset(sync, 0, sizeof(sync));
|
||||||
}
|
}
|
||||||
|
@ -280,48 +279,17 @@ int domovethings()
|
||||||
//
|
//
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
int moveloop()
|
void GameTicker()
|
||||||
{
|
|
||||||
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()
|
|
||||||
{
|
{
|
||||||
if (ps[myconnectindex].gm == MODE_DEMO)
|
if (ps[myconnectindex].gm == MODE_DEMO)
|
||||||
{
|
{
|
||||||
M_ClearMenus();
|
M_ClearMenus();
|
||||||
return true;
|
gamestate = GS_STARTUP;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Net_GetPackets();
|
//Net_GetPackets();
|
||||||
|
|
||||||
nonsharedkeys();
|
|
||||||
checkTimerActive();
|
|
||||||
|
|
||||||
gameupdatetime.Reset();
|
gameupdatetime.Reset();
|
||||||
gameupdatetime.Clock();
|
gameupdatetime.Clock();
|
||||||
|
@ -332,31 +300,24 @@ bool GameTicker()
|
||||||
while (playrunning() && currentTic - lastTic >= 1)
|
while (playrunning() && currentTic - lastTic >= 1)
|
||||||
{
|
{
|
||||||
lastTic = currentTic;
|
lastTic = currentTic;
|
||||||
|
|
||||||
GetInput();
|
|
||||||
auto const pPlayer = &ps[myconnectindex];
|
|
||||||
auto const q16ang = fix16_to_int(pPlayer->q16ang);
|
|
||||||
auto& input = nextinput(myconnectindex);
|
auto& input = nextinput(myconnectindex);
|
||||||
|
|
||||||
input = loc;
|
gi->GetInput(&input);
|
||||||
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 = {};
|
|
||||||
|
|
||||||
advancequeue(myconnectindex);
|
advancequeue(myconnectindex);
|
||||||
|
|
||||||
if (playrunning())
|
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();
|
gameupdatetime.Unclock();
|
||||||
|
|
||||||
if (ps[myconnectindex].gm & (MODE_EOL | MODE_RESTART))
|
if (ps[myconnectindex].gm & (MODE_EOL | MODE_RESTART))
|
||||||
|
@ -366,17 +327,23 @@ bool GameTicker()
|
||||||
|
|
||||||
if (!cl_syncinput)
|
if (!cl_syncinput)
|
||||||
{
|
{
|
||||||
GetInput();
|
gi->GetInput(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nonsharedkeys();
|
||||||
|
S_Update();
|
||||||
drawtime.Reset();
|
drawtime.Reset();
|
||||||
drawtime.Clock();
|
drawtime.Clock();
|
||||||
S_Update();
|
videoSetBrightness(thunder_brightness);
|
||||||
|
double const smoothRatio = playrunning() ? I_GetTimeFrac() * MaxSmoothRatio : MaxSmoothRatio;
|
||||||
displayrooms(screenpeek, smoothRatio);
|
displayrooms(screenpeek, smoothRatio);
|
||||||
displayrest(smoothRatio);
|
drawoverlays(smoothRatio);
|
||||||
drawtime.Unclock();
|
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();
|
FX_StopAllSounds();
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void GameInterface::RunGameFrame()
|
static void Startup()
|
||||||
{
|
{
|
||||||
switch (gamestate)
|
|
||||||
{
|
|
||||||
default:
|
|
||||||
case GS_STARTUP:
|
|
||||||
I_ResetTime();
|
I_ResetTime();
|
||||||
lastTic = -1;
|
lastTic = -1;
|
||||||
gameclock = 0;
|
gameclock = 0;
|
||||||
|
@ -432,6 +390,21 @@ void GameInterface::RunGameFrame()
|
||||||
{
|
{
|
||||||
fi.ShowLogo([](bool) { startmainmenu(); });
|
fi.ShowLogo([](bool) { startmainmenu(); });
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void GameInterface::RunGameFrame()
|
||||||
|
{
|
||||||
|
switch (gamestate)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
case GS_STARTUP:
|
||||||
|
Startup();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GS_MENUSCREEN:
|
case GS_MENUSCREEN:
|
||||||
|
@ -440,13 +413,12 @@ void GameInterface::RunGameFrame()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GS_LEVEL:
|
case GS_LEVEL:
|
||||||
if (GameTicker()) gamestate = GS_STARTUP;
|
GameTicker();
|
||||||
else videoSetBrightness(thunder_brightness);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GS_INTERMISSION:
|
case GS_INTERMISSION:
|
||||||
case GS_INTRO:
|
case GS_INTRO:
|
||||||
RunScreenJobFrame(); // This handles continuation through its completion callback.
|
RunScreenJobFrame();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,6 @@ int16_t max_ammo_amount[MAX_WEAPONS];
|
||||||
int16_t weaponsandammosprites[15];
|
int16_t weaponsandammosprites[15];
|
||||||
int PHEIGHT = PHEIGHT_DUKE;
|
int PHEIGHT = PHEIGHT_DUKE;
|
||||||
int duke3d_globalflags;
|
int duke3d_globalflags;
|
||||||
InputPacket loc;
|
|
||||||
uint8_t ready2send;
|
uint8_t ready2send;
|
||||||
int playerswhenstarted;
|
int playerswhenstarted;
|
||||||
int show_shareware;
|
int show_shareware;
|
||||||
|
|
|
@ -51,7 +51,6 @@ extern int16_t weaponsandammosprites[15];
|
||||||
extern int32_t PHEIGHT;
|
extern int32_t PHEIGHT;
|
||||||
extern int duke3d_globalflags;
|
extern int duke3d_globalflags;
|
||||||
extern uint8_t ready2send;
|
extern uint8_t ready2send;
|
||||||
extern InputPacket loc;
|
|
||||||
extern int playerswhenstarted;
|
extern int playerswhenstarted;
|
||||||
extern int show_shareware;
|
extern int show_shareware;
|
||||||
extern int screenpeek;
|
extern int screenpeek;
|
||||||
|
|
|
@ -44,6 +44,7 @@ static int nonsharedtimer;
|
||||||
static int turnheldtime;
|
static int turnheldtime;
|
||||||
static int lastcontroltime;
|
static int lastcontroltime;
|
||||||
static double lastCheck;
|
static double lastCheck;
|
||||||
|
static InputPacket loc; // input accumulation buffer.
|
||||||
|
|
||||||
void GameInterface::ResetFollowPos(bool message)
|
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;
|
double elapsedInputTicks;
|
||||||
auto const p = &ps[myconnectindex];
|
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.
|
// This is called from ImputState::ClearAllInput and resets all static state being used here.
|
||||||
|
//
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
void GameInterface::clearlocalinputstate()
|
void GameInterface::clearlocalinputstate()
|
||||||
{
|
{
|
||||||
|
loc = {};
|
||||||
nonsharedtimer = 0;
|
nonsharedtimer = 0;
|
||||||
turnheldtime = 0;
|
turnheldtime = 0;
|
||||||
lastcontroltime = 0;
|
lastcontroltime = 0;
|
||||||
lastCheck = 0;
|
lastCheck = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
END_DUKE_NS
|
END_DUKE_NS
|
||||||
|
|
Loading…
Reference in a new issue