diff --git a/core/smn_core.cpp b/core/smn_core.cpp index 7e76cdba..03f3b968 100644 --- a/core/smn_core.cpp +++ b/core/smn_core.cpp @@ -18,8 +18,15 @@ #include "PluginSys.h" #include "HandleSys.h" -HandleType_t g_PlIter; +#if defined PLATFORM_WINDOWS +#include +#elif defined PLATFORM_LINUX +#include +#include +#include +#endif +HandleType_t g_PlIter; class CoreNativeHelpers : public SMGlobalClass, @@ -257,12 +264,32 @@ static cell_t SetFailState(IPluginContext *pContext, const cell_t *params) return pContext->ThrowNativeErrorEx(SP_ERROR_ABORTED, "%s", str); } +static cell_t GetSysTickCount(IPluginContext *pContext, const cell_t *params) +{ +#if defined PLATFORM_WINDOWS + return (cell_t)GetTickCount(); +#elif defined PLATFORM_LINUX + tms tm; + clock_t ticks = times(&tm); + long ticks_per_sec = sysconf(_SC_CLK_TCK); + double ftcks = (double)ticks / (double)ticks_per_sec; + fticks *= 1000.0f; + if (fticks > INT_MAX) + { + double r = (int)(fticks / INT_MAX) * (double)INT_MAX; + fticks -= r; + } + return (cell_t)fticks; +#endif +} + REGISTER_NATIVES(coreNatives) { {"GetPluginFilename", GetPluginFilename}, {"GetPluginInfo", GetPluginInfo}, {"GetPluginIterator", GetPluginIterator}, {"GetPluginStatus", GetPluginStatus}, + {"GetSysTickCount", GetSysTickCount}, {"GetTime", GetTime}, {"IsPluginDebugging", IsPluginDebugging}, {"MorePlugins", MorePlugins}, diff --git a/plugins/include/sourcemod.inc b/plugins/include/sourcemod.inc index 5598b457..394d9b35 100644 --- a/plugins/include/sourcemod.inc +++ b/plugins/include/sourcemod.inc @@ -281,9 +281,18 @@ native GameConfGetOffset(Handle:gc, const String:key[]); * @param key Key to retrieve from the Keys section. * @param buffer Destination string buffer. * @param maxlen Maximum length of output string buffer. - * @return True if key existed, false otherwise. + * @return True if key existed, false otherwise. */ native bool:GameConfGetKeyValue(Handle:gc, const String:key[], String:buffer[], maxlen); +/** + * Returns the operating system's "tick count," which is a number of + * milliseconds since the operating system loaded. This can be used + * for basic benchmarks. + * + * @return Tick count in milliseconds. + */ +native GetSysTickCount(); + #include #include