mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Improve timer logic
Accurate interval to duration conversion.
This commit is contained in:
parent
45c147087a
commit
e1cf700355
@ -6,6 +6,7 @@
|
||||
|
||||
#include "core/stdafx.h"
|
||||
#include "tier1/cvar.h"
|
||||
#include "public/utility/utility.h"
|
||||
#include "engine/sdk_dll.h"
|
||||
#ifndef DEDICATED
|
||||
#include "gameui/IBrowser.h"
|
||||
@ -23,9 +24,7 @@ void CEngineSDK::FixedFrame()
|
||||
g_pBrowser->Think();
|
||||
g_pConsole->Think();
|
||||
#endif // !DEDICATED
|
||||
|
||||
std::chrono::duration<float> interval{ sdk_fixedframe_tickinterval->GetFloat()};
|
||||
std::this_thread::sleep_for(interval);
|
||||
std::this_thread::sleep_for(IntervalToDuration(sdk_fixedframe_tickinterval->GetFloat()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -835,4 +835,13 @@ string PrintPercentageEscape(const string& svInput)
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// For obtaining a duration from a certain interval.
|
||||
std::chrono::nanoseconds IntervalToDuration(const float flInterval)
|
||||
{
|
||||
using namespace std::chrono;
|
||||
using fsec = duration<float>;
|
||||
return round<nanoseconds>(fsec{ flInterval });
|
||||
}
|
||||
|
@ -68,3 +68,7 @@ void AppendPrintf(char* pBuffer, size_t nBufSize, char const* pFormat, ...);
|
||||
string PrintPercentageEscape(const string& svInput);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Time
|
||||
std::chrono::nanoseconds IntervalToDuration(const float flInterval);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
Loading…
x
Reference in New Issue
Block a user