r5sdk/r5dev/engine/sys_engine.cpp
Kawe Mazidjatari 144d5f62e1 IDetour: code refactor
Utilize the new IDetour::DetourSetup() code, IDetour::Attach and IDetour::Detach have been removed in favor of this (significantly reduces chance of user error). Since the template check happens in the idetour header, it is much more aggressive on type mismatches, such as a difference in parameter types, between the function and detour, will now raise a compile time error. As a result, some type mismatches have been fixed in this commit as well.
2024-04-05 16:41:09 +02:00

38 lines
1.0 KiB
C++

#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;
IEngine::QuitState_t* gsm_Quitting = 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);
}
void VEngine::Detour(const bool bAttach) const
{
DetourSetup(&v_CEngine_Frame, &CEngine::_Frame, bAttach);
}