Give process time to shutdown properly

Game gets max 10 seconds to shutdown properly when closed directly by the external console window (g_pHostState->m_iNextState = HostStates_t::HS_SHUTDOWN).
This commit is contained in:
Kawe Mazidjatari 2022-07-26 00:36:35 +02:00
parent 93375d9a1f
commit b846809ac3
3 changed files with 30 additions and 0 deletions

View File

@ -11,6 +11,7 @@
#ifndef DEDICATED
#include "windows/id3dx.h"
#endif // !DEDICATED
#include "windows/system.h"
#include "windows/console.h"
#include "common/opcodes.h"
@ -111,6 +112,7 @@ void Console_Init()
SetConsoleBackgroundColor(0x0000);
AnsiColors_Init();
}
SetConsoleCtrlHandler(ConsoleHandlerRoutine, true);
}
//#############################################################################

View File

@ -1,5 +1,6 @@
#include "core/stdafx.h"
#include "windows/system.h"
#include "engine/host_state.h"
///////////////////////////////////////////////////////////////////////////////
typedef BOOL(WINAPI* IGetVersionExA)(
@ -48,6 +49,28 @@ HPeekMessage(
#endif // DEDICATED
}
BOOL
WINAPI
ConsoleHandlerRoutine(
DWORD eventCode)
{
switch (eventCode)
{
case CTRL_CLOSE_EVENT:
case CTRL_LOGOFF_EVENT:
case CTRL_SHUTDOWN_EVENT:
if (g_pHostState)
{
g_pHostState->m_iNextState = HostStates_t::HS_SHUTDOWN;
}
Sleep(10000);
return TRUE;
}
return FALSE;
}
//#############################################################################
// MANAGEMENT
//#############################################################################

View File

@ -1,4 +1,9 @@
#pragma once
BOOL
WINAPI
ConsoleHandlerRoutine(
DWORD eventCode);
void WinSys_Attach();
void WinSys_Detach();