- more work to switch over to the new loop.

Mainly separation of ticker and render calls
This commit is contained in:
Christoph Oelckers 2020-08-30 10:42:44 +02:00
parent 367b4ce051
commit 0c455acaa2
10 changed files with 93 additions and 56 deletions

View file

@ -74,7 +74,6 @@ enum rendmode_t {
#define MAXVOXELS 1024
#define MAXSTATUS 1024
#define MAXPLAYERS 16
// Maximum number of component tiles in a multi-psky:
#define MAXPSKYTILES 16
#define MAXSPRITESONSCREEN 2560

View file

@ -53,6 +53,8 @@ void Net_SkipCommand (int type, uint8_t **stream);
void Net_ClearBuffers ();
bool D_CheckNetGame(void);
// Netgame stuff (buffers and pointers, i.e. indices).

View file

@ -69,6 +69,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "screenjob.h"
#include "statusbar.h"
#include "uiinput.h"
#include "d_net.h"
CVAR(Bool, autoloadlights, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR(Bool, autoloadbrightmaps, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
@ -100,6 +101,7 @@ int lastTic;
int automapMode;
bool automapFollow;
extern int pauseext;
CCMD(togglemap)
{
@ -137,6 +139,7 @@ void I_DetectOS(void);
void LoadScripts();
void app_loop();
void DrawFullscreenBlends();
void MainLoop();
bool AppActive;
@ -280,15 +283,6 @@ void UserConfig::ProcessOptions()
Printf("Build-format config files not supported and will be ignored\n");
}
#if 0 // MP disabled pending evaluation
auto v = Args->CheckValue("-port");
if (v) netPort = strtol(v, nullptr, 0);
netServerMode = Args->CheckParm("-server");
netServerAddress = Args->CheckValue("-connect");
netPassword = Args->CheckValue("-password");
#endif
auto v = Args->CheckValue("-addon");
if (v)
{
@ -866,9 +860,9 @@ int RunGame()
auto exec = C_ParseCmdLineParams(nullptr);
if (exec) exec->ExecCommands();
gamestate = GS_LEVEL;
SetupGameButtons();
gi->app_init();
app_loop();
return 0; // this is never reached. app_loop only exits via exception.
}
@ -1150,6 +1144,15 @@ void S_SetSoundPaused(int state)
}
}
}
if (!netgame
#if 0 //def _DEBUG
&& !demoplayback
#endif
)
{
pauseext = !state;
}
}
FString G_GetDemoPath()

View file

@ -98,6 +98,11 @@ int oldentertics;
int gametic;
//==========================================================================
//
//
//
//==========================================================================
void G_BuildTiccmd(ticcmd_t* cmd)
{
@ -105,8 +110,13 @@ void G_BuildTiccmd(ticcmd_t* cmd)
cmd->consistancy = consistancy[myconnectindex][(maketic / ticdup) % BACKUPTICS];
}
//==========================================================================
//
//
//
//==========================================================================
void G_Ticker()
static void GameTicker()
{
int i;
@ -116,11 +126,6 @@ void G_Ticker()
// Todo: Migrate state changes to here instead of doing them ad-hoc
while (gameaction != ga_nothing)
{
if (gameaction == ga_newgame2)
{
gameaction = ga_newgame;
break;
}
switch (gameaction)
{
}
@ -181,18 +186,15 @@ void G_Ticker()
gi->Startup();
break;
case GS_MENUSCREEN:
case GS_FULLCONSOLE:
gi->DrawBackground();
break;
case GS_LEVEL:
gi->Ticker();
break;
case GS_MENUSCREEN:
case GS_FULLCONSOLE:
case GS_INTERMISSION:
case GS_INTRO:
RunScreenJobFrame();
// These elements do not tick at game rate.
break;
}
@ -201,54 +203,65 @@ void G_Ticker()
//==========================================================================
//
// D_Display
//
// Draw current display, possibly wiping it from the previous
// Display
//
//==========================================================================
void D_Display()
void Display()
{
FGameTexture* wipe = nullptr;
if (screen == NULL)
return; // for comparative timing / profiling
if (!AppActive && (screen->IsFullscreen() || !vid_activeinbackground))
if (screen == nullptr || !AppActive && (screen->IsFullscreen() || !vid_activeinbackground))
{
return;
}
screen->FrameTime = I_msTimeFS();
screen->BeginFrame();
twodpsp.ClearClipRect();
twod->ClearClipRect();
if ((gamestate == GS_LEVEL) && gametic != 0)
switch (gamestate)
{
// [ZZ] execute event hook that we just started the frame
//E_RenderFrame();
//
gi->Render();
case GS_MENUSCREEN:
gi->DrawBackground();
break;
case GS_FINALE:
// screen jobs are not bound by the game ticker so they need to be ticked in the display loop.
RunScreenJobFrame();
break;
case GS_LEVEL:
if (gametic != 0)
{
gi->Render();
DrawFullscreenBlends();
}
break;
default:
break;
}
// Draw overlay elements to the 2D drawer
NetUpdate(); // send out any new accumulation
// Draw overlay elements
CT_Drawer();
C_DrawConsole();
M_Drawer();
FStat::PrintStat(twod);
// Handle the final 2D overlays.
if (gamestate == GS_LEVEL) DrawFullscreenBlends();
DrawRateStuff();
videoShowFrame(0);
}
//==========================================================================
//
// Forces playsim processing time to be consistent across frames.
// This improves interpolation for frames in between tics.
//
// With this cvar off the mods with a high playsim processing time will appear
// less smooth as the measured time used for interpolation will vary.
//
//==========================================================================
static void TicStabilityWait()
{
@ -280,9 +293,12 @@ static void TicStabilityEnd()
stabilityticduration = std::min(stabilityendtime - stabilitystarttime, (uint64_t)1'000'000);
}
//==========================================================================
//
// TryRunTics
// The most important function in the engine.
//
//==========================================================================
void TryRunTics (void)
{
int i;
@ -296,7 +312,7 @@ void TryRunTics (void)
// will all be wasted anyway.
if (pauseext)
r_NoInterpolate = true;
bool doWait = cl_capfps || r_NoInterpolate /*|| netgame*/;
bool doWait = cl_capfps || r_NoInterpolate;
// get real tics
if (doWait)
@ -328,14 +344,7 @@ void TryRunTics (void)
}
}
if (ticdup == 1)
{
availabletics = lowtic - gametic;
}
else
{
availabletics = lowtic - gametic / ticdup;
}
availabletics = lowtic - gametic / ticdup;
// decide how many tics to run
if (realtics < availabletics-1)
@ -362,6 +371,7 @@ void TryRunTics (void)
gi->Predict(myconnectindex);
#endif
}
gi->GetInput(nullptr);
return;
}
@ -431,10 +441,9 @@ void TryRunTics (void)
D_DoAdvanceDemo ();
}
#endif
//if (debugfile) fprintf (debugfile, "run tic %d\n", gametic);
C_Ticker ();
M_Ticker ();
G_Ticker();
GameTicker();
gametic++;
NetUpdate (); // check for new console commands
@ -482,7 +491,7 @@ void MainLoop ()
// Update display, next frame, with current state.
I_StartTic ();
D_Display();
Display();
Mus_UpdateMusic(); // must be at the end.
}
catch (CRecoverableError &error)

View file

@ -59,6 +59,10 @@ struct GameInterface : public ::GameInterface
void ResetFollowPos(bool message) override;
void GetInput(InputPacket* packet) override;
void UpdateSounds() override;
void Startup() override;
void DrawBackground() override;
void Render() override;
void Ticker() override;
};

View file

@ -400,6 +400,24 @@ static void Startup()
//
//---------------------------------------------------------------------------
void GameInterface::Startup()
{
}
void GameInterface::DrawBackground()
{
}
void GameInterface::Render()
{
}
void GameInterface::Ticker()
{
}
void GameInterface::RunGameFrame()
{
switch (gamestate)

View file

@ -8,6 +8,7 @@
#include "sounds.h"
#include "constants.h"
#include "types.h"
#include "d_net.h"
BEGIN_DUKE_NS

View file

@ -1,6 +1,7 @@
#pragma once
#include "names.h"
#include "packet.h"
#include "d_net.h"
BEGIN_DUKE_NS

View file

@ -355,6 +355,7 @@ public:
};
extern GLInstance GLInterface;
extern F2DDrawer twodpsp;
void renderSetProjectionMatrix(const float* p);
void renderSetViewMatrix(const float* p);

View file

@ -2057,7 +2057,6 @@ extern short numplayers, myconnectindex;
extern short connecthead, connectpoint2[MAXPLAYERS];
*/
extern int *lastpacket2clock;
extern char username[MAXPLAYERS][50];
// save player info when moving to a new level
extern USER puser[MAX_SW_PLAYERS_REG];