Skip to content
Permalink
Browse files

Merge pull request #207 from slipher/initialize-pre2

VM restarts 2
  • Loading branch information...
slipher committed Jun 9, 2019
2 parents c4772b5 + 70fc28b commit b17dd395a247ad0e0a53435d13ce73efb0863cb8
@@ -1336,6 +1336,7 @@ void LoadPakExplicit(const PakInfo& pak, uint32_t expectedChecksum, std::error_c

void ClearPaks()
{
fsLogs.Verbose("^5Unloading all paks");
fileMap.clear();
for (LoadedPakInfo& x: loadedPaks) {
if (x.fd != -1)
@@ -877,12 +877,6 @@ void CL_SetCGameTime()
Sys::Drop( "CL_SetCGameTime: !cl.snap.valid" );
}

if ( sv_paused->integer && cl_paused->integer && com_sv_running->integer )
{
// paused
return;
}

if ( cl.snap.serverTime < cl.oldFrameServerTime )
{
// Ridah, if this is a localhost, then we are probably loading a savegame
@@ -1023,12 +1023,6 @@ void CL_SendCmd()
return;
}

// don't send commands if paused
if ( com_sv_running->integer && sv_paused->integer && cl_paused->integer )
{
return;
}

// we create commands even if a demo is playing,
CL_CreateNewCommands();

@@ -305,7 +305,7 @@ void CL_WriteDemoMessage( msg_t *msg, int headerBytes )
/**
* If a demo is being recorded, this stops it
*/
void CL_StopRecord()
static void CL_StopRecord()
{
if ( !clc.demorecording )
return;
@@ -697,8 +697,37 @@ void CL_NextDemo()
Cmd::ExecuteCommandBuffer();
}

// stop demo recording and playback
static void StopDemos()
{
// stop demo recording
CL_StopRecord();

// stop demo playback
if ( clc.demofile )
{
FS_FCloseFile( clc.demofile );
clc.demofile = 0;
}
}

//======================================================================

// stop video recording and playback
static void StopVideo()
{
SCR_StopCinematic();
CIN_CloseAllVideos();

// stop recording any video
if ( CL_VideoRecording() )
{
// finish rendering current frame
//SCR_UpdateScreen();
CL_CloseAVI();
}
}

/*
=====================
CL_ShutdownAll
@@ -726,41 +755,37 @@ void CL_ShutdownAll()
re.Shutdown( false ); // don't destroy window or context
}

cls.cgameStarted = false;
cls.rendererStarted = false;
cls.soundRegistered = false;

StopVideo();
// Gordon: stop recording on map change etc, demos aren't valid over map changes anyway
CL_StopRecord();
StopDemos();
}

/*
=================
CL_FlushMemory

Called by CL_MapLoading, CL_Connect_f, CL_PlayDemo_f, and CL_ParseGamestate the only
ways a client gets into a game
Also called by Com_Error
Called by CL_DownloadsComplete (the only way a client gets into a game)
Also called on a DropError
=================
*/
void CL_FlushMemory()
{
// shutdown all the client stuff
CL_ShutdownAll();

// if not running a server clear the whole hunk
if ( !com_sv_running->integer )
{
// clear the whole hunk
Hunk_ShutDownRandomStuffAndClear();
void SV_ShutdownGameProgs();
SV_ShutdownGameProgs();

// clear collision map data
CM_ClearMap();
}
else
{
// clear all the client data on the hunk
Hunk_Clear();
}

Hunk_Clear();

CL_StartHunkUsers();
}
@@ -782,7 +807,6 @@ void CL_MapLoading()
}

Con_Close();
CL_FlushMemory();
cls.keyCatchers = 0;

// if we are already connected to the local host, stay connected
@@ -797,8 +821,6 @@ void CL_MapLoading()
}
else
{
// clear nextmap so the cinematic shutdown doesn't execute it
Cvar_Set( "sv_nextmap", "" );
CL_Disconnect( false );
Q_strncpyz( cls.servername, "loopback", sizeof( cls.servername ) );
*cls.reconnectCmd = 0; // can't reconnect to this!
@@ -856,7 +878,13 @@ void CL_Disconnect( bool showMainMenu )
return;
}

CL_StopRecord();
CL_SendDisconnect();

if ( cl_useMumble->integer && mumble_islinked() )
{
Log::Notice("Mumble: Unlinking from Mumble application" );
mumble_unlink();
}

if ( !cls.bWWWDlDisconnected )
{
@@ -870,21 +898,8 @@ void CL_Disconnect( bool showMainMenu )
Cvar_Set( "cl_downloadName", "" );
}

if ( cl_useMumble->integer && mumble_islinked() )
{
Log::Notice("Mumble: Unlinking from Mumble application" );
mumble_unlink();
}

if ( clc.demofile )
{
FS_FCloseFile( clc.demofile );
clc.demofile = 0;
}

SCR_StopCinematic();

CL_SendDisconnect();
StopVideo();
StopDemos();

// allow cheats locally again
if (showMainMenu) {
@@ -905,17 +920,6 @@ void CL_Disconnect( bool showMainMenu )
FS::PakPath::ClearPaks();
FS_LoadBasePak();

// XreaL BEGIN
// stop recording any video
if ( CL_VideoRecording() )
{
// finish rendering current frame
//SCR_UpdateScreen();
CL_CloseAVI();
}

// XreaL END

// show_bug.cgi?id=589
// don't try a restart if rocket is nullptr, as we might be in the middle of a restart already
if ( cgvm.IsActive() && cls.state > connstate_t::CA_DISCONNECTED )
@@ -1523,14 +1527,8 @@ extern void IN_Restart(); // fretn

void CL_Vid_Restart_f()
{
// XreaL BEGIN
// settings may have changed so stop recording now
if ( CL_VideoRecording() )
{
CL_CloseAVI();
}

// XreaL END
StopVideo();

// don't let them loop during the restart
Audio::StopAllSounds();
@@ -1543,24 +1541,9 @@ void CL_Vid_Restart_f()
CL_ShutdownRef();

cls.rendererStarted = false;
cls.cgameStarted = false;
cls.soundRegistered = false;

// unpause so the cgame definitely gets a snapshot and renders a frame
Cvar_Set( "cl_paused", "0" );

// if not running a server clear the whole hunk
if ( !com_sv_running->integer )
{
// clear the whole hunk
// BUT DO WE REALLY WANT TO SHUT DOWN RANDOM STUFF TOO?
Hunk_ShutDownRandomStuffAndClear();
}
else
{
// clear all the client data on the hunk
Hunk_Clear();
}
Hunk_Clear();

// startup all the client stuff
CL_StartHunkUsers();
@@ -1582,7 +1565,7 @@ void CL_Vid_Restart_f()
CL_Snd_Restart_f

Restart the sound subsystem
The cgame and game must also be forced to restart because
The cgame must also be forced to restart because
handles will be invalid
=================
*/
@@ -1592,6 +1575,8 @@ void CL_Snd_Restart_f()

if( !cls.cgameStarted )
{
// In the main menu case the cgame is not restarted... but is there anything preventing
// the main menu from also using sound handles?
if (!Audio::Init()) {
Sys::Error("Couldn't initialize the audio subsystem.");
}
@@ -2532,8 +2517,7 @@ void CL_CheckTimeout()
//
// check timeout
//
if ( ( !cl_paused->integer || !sv_paused->integer )
&& cls.state >= connstate_t::CA_CONNECTED && cls.state != connstate_t::CA_CINEMATIC && cls.realtime - clc.lastPacketTime > cl_timeout->value * 1000 )
if ( cls.state >= connstate_t::CA_CONNECTED && cls.state != connstate_t::CA_CINEMATIC && cls.realtime - clc.lastPacketTime > cl_timeout->value * 1000 )
{
if ( ++cl.timeoutcount > 5 )
{
@@ -2565,12 +2549,6 @@ void CL_CheckUserinfo()
return;
}

// don't overflow the reliable command buffer when paused
if ( cl_paused->integer )
{
return;
}

// send a reliable userinfo update if needed
if ( cvar_modifiedFlags & CVAR_USERINFO )
{
@@ -2734,8 +2712,8 @@ bool CL_InitRenderer()
============================
CL_StartHunkUsers

After the server has cleared the hunk, these will need to be restarted
This is the only place that any of these functions are called from
Starts any of {renderer, audio, cgame vm} that is not already started.
Only the renderer is really a hunk user.
============================
*/
void CL_StartHunkUsers()
@@ -2881,9 +2859,6 @@ bool CL_InitRef( )

re = *ret;

// unpause so the cgame definitely gets a snapshot and renders a frame
Cvar_Set( "cl_paused", "0" );

return true;
}

@@ -193,10 +193,6 @@ void CL_ParseSnapshot( msg_t *msg )

newSnap.serverTime = MSG_ReadLong( msg );

// if we were just unpaused, we can only *now* really let the
// change come into effect or the client hangs.
cl_paused->modified = false;

newSnap.messageNum = clc.serverMessageSequence;

deltaNum = MSG_ReadByte( msg );
@@ -463,9 +459,6 @@ void CL_ParseGamestate( msg_t *msg )
// This used to call CL_StartHunkUsers, but now we enter the download state before loading the
// cgame
CL_InitDownloads();

// make sure the game starts
Cvar_Set( "cl_paused", "0" );
}

//=====================================================================
@@ -212,26 +212,6 @@ void Hunk_Clear()
Log::Debug( "Hunk_Clear: reset the hunk ok" );
}

/*
=================
Hunk_ShutDownRandomStuffAndClear

The server calls this before shutting down or loading a new map
=================
*/
void Hunk_ShutDownRandomStuffAndClear()
{
#ifdef BUILD_GRAPHICAL_CLIENT // TODO(slipher): Should either of these also happen for tty client?
CL_ShutdownCGame();
#endif
void SV_ShutdownGameProgs();
SV_ShutdownGameProgs();
#ifdef BUILD_GRAPHICAL_CLIENT
CIN_CloseAllVideos();
#endif
Hunk_Clear();
}

static void Hunk_SwapBanks()
{
hunkUsed_t *swap;
@@ -61,10 +61,6 @@ void CL_PacketEvent( netadr_t, msg_t* )
{
}

void CL_Disconnect( bool )
{
}

void CL_MapLoading()
{
}
@@ -87,9 +87,6 @@ cvar_t *com_unfocused;
cvar_t *com_minimized;


cvar_t *cl_paused;
cvar_t *sv_paused;

// com_speeds times
int time_game;
int time_frontend; // renderer frontend time
@@ -656,8 +653,6 @@ void Com_Init()
com_dropsim = Cvar_Get( "com_dropsim", "0", CVAR_CHEAT );
com_speeds = Cvar_Get( "com_speeds", "0", 0 );

cl_paused = Cvar_Get( "cl_paused", "0", CVAR_ROM );
sv_paused = Cvar_Get( "sv_paused", "0", CVAR_ROM );
com_sv_running = Cvar_Get( "sv_running", "0", CVAR_ROM );
com_cl_running = Cvar_Get( "cl_running", "0", CVAR_ROM );

0 comments on commit b17dd39

Please sign in to comment.
You can’t perform that action at this time.