Skip to content

Commit

Permalink
System utils: added GetCurrentSysTime function
Browse files Browse the repository at this point in the history
  • Loading branch information
SNMetamorph committed Apr 23, 2023
1 parent 6384ec3 commit 253c5e2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
16 changes: 2 additions & 14 deletions sources/library/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ GNU General Public License for more details.
#include "studio.h"
#include "application.h"
#include "matrix.h"
#include "sys_utils.h"
#include <stdint.h>
#include <cstring>
#include <vector>
Expand Down Expand Up @@ -507,20 +508,7 @@ void Utils::GetEntityBoundingBox(int entityIndex, CBoundingBox &bbox)

float Utils::GetCurrentSysTime()
{
static LARGE_INTEGER perfFreq;
static LARGE_INTEGER clockStart;
LARGE_INTEGER currentTime;
LONGLONG timeDiff;

if (!perfFreq.QuadPart)
{
QueryPerformanceFrequency(&perfFreq);
QueryPerformanceCounter(&clockStart);
}

QueryPerformanceCounter(&currentTime);
timeDiff = currentTime.QuadPart - clockStart.QuadPart;
return (float)timeDiff / (float)perfFreq.QuadPart;
return SysUtils::GetCurrentSysTime();
}

DisplayModeIndex Utils::GetCurrentDisplayMode()
Expand Down
20 changes: 20 additions & 0 deletions sources/sys_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,24 @@ void SysUtils::Sleep(size_t timeMsec)
::Sleep(timeMsec);
}

float SysUtils::GetCurrentSysTime()
{
static LARGE_INTEGER perfFreq;
static LARGE_INTEGER clockStart;
LARGE_INTEGER currentTime;
LONGLONG timeDiff;

if (!perfFreq.QuadPart)
{
QueryPerformanceFrequency(&perfFreq);
QueryPerformanceCounter(&clockStart);
}

QueryPerformanceCounter(&currentTime);
timeDiff = currentTime.QuadPart - clockStart.QuadPart;
return (float)timeDiff / (float)perfFreq.QuadPart;
}

ModuleHandle SysUtils::GetCurrentProcessModule()
{
return GetModuleHandle(NULL);
Expand Down Expand Up @@ -270,4 +288,6 @@ void *SysUtils::GetModuleFunction(ModuleHandle moduleHandle, const char *funcNam
{
return GetProcAddress(moduleHandle, funcName);
}
#else
#pragma error "SysUtils functions not yet implemented for this platform!"
#endif
1 change: 1 addition & 0 deletions sources/sys_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ namespace SysUtils
};

void Sleep(size_t timeMsec);
float GetCurrentSysTime();
void InitCurrentLibraryHandle(ModuleHandle handle);
ModuleHandle GetCurrentLibraryHandle();
ModuleHandle GetCurrentProcessModule();
Expand Down

0 comments on commit 253c5e2

Please sign in to comment.