mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Significantly reduce CPU time in CEngine::Frame for dedicated
Significant reduction of CPU time in CEngine::Frame for the dedicated server, by assigning the ConVar 'fps_max' to the tickrate of the server.
This commit is contained in:
parent
b45055dafd
commit
f37743e068
r5dev/engine
@ -1,9 +1,35 @@
|
||||
#include "core/stdafx.h"
|
||||
#include "tier1/cvar.h"
|
||||
#include "sys_engine.h"
|
||||
#ifdef DEDICATED
|
||||
#include "game/shared/shareddefs.h"
|
||||
#endif // DEDICATED
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
CEngine* g_pEngine = nullptr;
|
||||
|
||||
bool CEngine::_Frame(CEngine* thisp)
|
||||
{
|
||||
#ifdef DEDICATED
|
||||
|
||||
// The first engine frame is ran before the global variables are initialized.
|
||||
// By default, the tick interval is set to '0.0f'; we can't divide by zero.
|
||||
if (TICK_INTERVAL > 0.0f)
|
||||
{
|
||||
int nTickRate = TIME_TO_TICKS(1.0f);
|
||||
if (fps_max->GetInt() != nTickRate)
|
||||
{
|
||||
// Clamp the framerate of the server to its simulation tick rate.
|
||||
// This saves a significant amount of CPU time in CEngine::Frame,
|
||||
// as the engine uses this to decided when to run a new frame.
|
||||
fps_max->SetValue(nTickRate);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // DEDICATED
|
||||
return v_CEngine_Frame(thisp);
|
||||
}
|
||||
|
||||
/*
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Start initializing the engine.
|
||||
@ -82,4 +108,14 @@ void CEngine::SetQuitting(EngineDllQuitting_t quitDllState)
|
||||
const static int index = 9;
|
||||
CallVFunc<void>(index, this, quitDllState);
|
||||
}
|
||||
*/
|
||||
*/
|
||||
|
||||
void VEngine::Attach() const
|
||||
{
|
||||
DetourAttach((LPVOID*)&v_CEngine_Frame, &CEngine::_Frame);
|
||||
}
|
||||
|
||||
void VEngine::Detach() const
|
||||
{
|
||||
DetourDetach((LPVOID*)&v_CEngine_Frame, &CEngine::_Frame);
|
||||
}
|
@ -4,6 +4,9 @@
|
||||
|
||||
class CEngine : public IEngine
|
||||
{
|
||||
public:
|
||||
static bool _Frame(CEngine* thisp);
|
||||
|
||||
private:
|
||||
EngineState_t m_nDLLState;
|
||||
EngineState_t m_nNextDLLState;
|
||||
@ -19,6 +22,9 @@ private:
|
||||
};
|
||||
|
||||
/* ==== CENGINE ======================================================================================================================================================= */
|
||||
inline CMemory p_CEngine_Frame;
|
||||
inline auto v_CEngine_Frame = p_CEngine_Frame.RCast<bool(*)(CEngine* thisp)>();
|
||||
|
||||
extern CEngine* g_pEngine;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -30,9 +36,20 @@ class VEngine : public IDetour
|
||||
{
|
||||
virtual void GetAdr(void) const
|
||||
{
|
||||
LogVarAdr("g_pEngine", reinterpret_cast<uintptr_t>(g_pEngine));
|
||||
LogFunAdr("CEngine::Frame", p_CEngine_Frame.GetPtr());
|
||||
LogVarAdr("g_Engine", reinterpret_cast<uintptr_t>(g_pEngine));
|
||||
}
|
||||
virtual void GetFun(void) const
|
||||
{
|
||||
#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) || defined (GAMEDLL_S2)
|
||||
p_CEngine_Frame = g_GameDll.FindPatternSIMD("40 55 53 56 48 8D AC 24 ?? ?? ?? ?? 48 81 EC ?? ?? ?? ?? 48 8B 05 ?? ?? ?? ?? 48 8B F1");
|
||||
#elif defined (GAMEDLL_S2)
|
||||
p_CEngine_Frame = g_GameDll.FindPatternSIMD("48 8B C4 56 48 81 EC ?? ?? ?? ?? 0F 29 70 B8");
|
||||
#else
|
||||
p_CEngine_Frame = g_GameDll.FindPatternSIMD("48 8B C4 55 56 48 8D A8 ?? ?? ?? ?? 48 81 EC ?? ?? ?? ?? 0F 29 70 B8");
|
||||
#endif
|
||||
v_CEngine_Frame = p_CEngine_Frame.RCast<bool(*)(CEngine* thisp)>();
|
||||
}
|
||||
virtual void GetFun(void) const { }
|
||||
virtual void GetVar(void) const
|
||||
{
|
||||
#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1)
|
||||
@ -42,7 +59,7 @@ class VEngine : public IDetour
|
||||
#endif
|
||||
}
|
||||
virtual void GetCon(void) const { }
|
||||
virtual void Attach(void) const { }
|
||||
virtual void Detach(void) const { }
|
||||
virtual void Attach(void) const;
|
||||
virtual void Detach(void) const;
|
||||
};
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
Loading…
x
Reference in New Issue
Block a user