Move simple task to global fixed frame

Avoids having to create threads for tiny little things.
This commit is contained in:
Kawe Mazidjatari 2022-08-29 02:21:32 +02:00
parent 1c29d5aed5
commit 0f488c685c
10 changed files with 56 additions and 29 deletions

View File

@ -78,6 +78,7 @@
#ifndef CLIENT_DLL
#include "engine/server/sv_main.h"
#endif // !CLIENT_DLL
#include "engine/sdk_dll.h"
#include "engine/sys_dll.h"
#include "engine/sys_dll2.h"
#include "engine/sys_engine.h"
@ -242,6 +243,9 @@ void Systems_Init()
#endif // DEDICATED
SpdLog_PostInit();
std::thread fixed(&CEngineSDK::FixedFrame, g_EngineSDK);
fixed.detach();
}
//////////////////////////////////////////////////////////////////////////

View File

@ -5,4 +5,28 @@
//=============================================================================//
#include "core/stdafx.h"
#include "tier1/cvar.h"
#include "engine/sdk_dll.h"
#ifndef DEDICATED
#include "gameui/IBrowser.h"
#include "gameui/IConsole.h"
#endif // !DEDICATED
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEngineSDK::FixedFrame()
{
for (;;)
{
#ifndef DEDICATED
g_pBrowser->Think();
g_pConsole->Think();
#endif // !DEDICATED
std::chrono::duration<float, std::deci> interval{ sdk_fixedframe_tickinterval->GetFloat()};
std::this_thread::sleep_for(interval);
}
}
CEngineSDK* g_EngineSDK = new CEngineSDK();

View File

@ -1,5 +1,12 @@
#ifndef SDK_DLL_H
#define SDK_DLL_H
class CEngineSDK
{
public:
void FixedFrame();
};
extern CEngineSDK* g_EngineSDK;
#endif // SDK_DLL_H

View File

@ -150,20 +150,16 @@ void CBrowser::RunTask()
//-----------------------------------------------------------------------------
void CBrowser::Think(void)
{
for (;;) // Loop running at 100-tps.
if (m_bActivate)
{
if (m_bActivate)
if (m_flFadeAlpha <= 1.f)
{
if (m_flFadeAlpha <= 1.f)
{
m_flFadeAlpha += .05f;
}
m_flFadeAlpha += .05f;
}
else // Reset to full transparent.
{
m_flFadeAlpha = 0.f;
}
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
else // Reset to full transparent.
{
m_flFadeAlpha = 0.f;
}
}

View File

@ -41,9 +41,6 @@ CConsole::CConsole(void)
m_vCommands.push_back("HISTORY");
snprintf(m_szSummary, sizeof(m_szSummary), "%zu history items", m_vHistory.size());
std::thread think(&CConsole::Think, this);
think.detach(); // !FIXME: Run from SDK MainFrame when finished.
}
//-----------------------------------------------------------------------------
@ -151,21 +148,17 @@ void CConsole::RunTask()
//-----------------------------------------------------------------------------
void CConsole::Think(void)
{
for (;;) // Loop running at 100-tps.
if (m_bActivate)
{
if (m_bActivate)
if (m_flFadeAlpha <= 1.f)
{
if (m_flFadeAlpha <= 1.f)
{
m_flFadeAlpha += .05f;
}
m_flFadeAlpha += .05f;
}
else // Reset to full transparent.
{
m_flFadeAlpha = 0.f;
m_bReclaimFocus = true;
}
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
else // Reset to full transparent.
{
m_flFadeAlpha = 0.f;
m_bReclaimFocus = true;
}
}

View File

@ -12,7 +12,7 @@ cl_threaded_bone_setup "0" // Has to be disabled on
//////////////////////////
cl_predict_cmdlimit "5000" // Num client frames since last valid snapshot before pauzing simulation.
cl_updaterate_mp "20" // Sets the num delta ticks per second.
base_tickinterval_mp "0.0500" // Sets the num simulation frames per second.
base_tickinterval_mp "0.05" // Sets the num simulation frames per second.
//////////////////////////
//// PLATFORM ////

View File

@ -11,7 +11,7 @@ sv_requireOriginToken "0" // Enables origin token verification on th
//// SIMULATION //// !!WARNING!!: CHANGING THESE CAN CAUSE SIMULATION ISSUES. DO NOT CHANGE FOR NON-DEBUG ACTIVITY!
//////////////////////////
sv_updaterate_mp "20" // Sets the num delta ticks per second.
base_tickinterval_mp "0.0500" // Sets the num simulation frames per second.
base_tickinterval_mp "0.05" // Sets the num simulation frames per second.
//////////////////////////
//// DEBUG DRAW ////

View File

@ -65,7 +65,8 @@ void ConVar::Init(void) const
{
//-------------------------------------------------------------------------
// ENGINE |
hostdesc = ConVar::Create("hostdesc", "", FCVAR_RELEASE, "Host game server description.", false, 0.f, false, 0.f, nullptr, nullptr);
hostdesc = ConVar::Create("hostdesc", "", FCVAR_RELEASE, "Host game server description.", false, 0.f, false, 0.f, nullptr, nullptr);
sdk_fixedframe_tickinterval = ConVar::Create("sdk_fixedframe_tickinterval", "0.05", FCVAR_RELEASE, "The tick interval used by the SDK fixed frame.", false, 0.f, false, 0.f, nullptr, nullptr);
staticProp_defaultBuildFrustum = ConVar::Create("staticProp_defaultBuildFrustum", "0", FCVAR_DEVELOPMENTONLY, "Use the old solution for building static prop frustum culling.", false, 0.f, false, 0.f, nullptr, nullptr);
cm_unset_all_cmdquery = ConVar::Create("cm_unset_all_cmdquery" , "0", FCVAR_DEVELOPMENTONLY | FCVAR_REPLICATED, "Returns false on every ConVar/ConCommand query ( !warning! ).", false, 0.f, false, 0.f, nullptr, nullptr);

View File

@ -8,6 +8,7 @@
//-----------------------------------------------------------------------------
// ENGINE |
ConVar* sdk_fixedframe_tickinterval = nullptr;
ConVar* single_frame_shutdown_for_reload = nullptr;
ConVar* old_gather_props = nullptr;
ConVar* enable_debug_overlays = nullptr;

View File

@ -4,6 +4,7 @@
//-------------------------------------------------------------------------
// ENGINE |
extern ConVar* sdk_fixedframe_tickinterval;
extern ConVar* single_frame_shutdown_for_reload;
extern ConVar* old_gather_props;
extern ConVar* enable_debug_overlays;