gdle/Source/Globals.cpp

158 lines
2.6 KiB
C++
Raw Permalink Normal View History

2018-03-29 17:01:57 -04:00
2019-07-07 20:56:15 +00:00
#include <StdAfx.h>
2018-03-29 17:01:57 -04:00
#include "Globals.h"
bool g_bDebugToggle = false;
CGlobals *g_pGlobals = NULL;
double g_TimeAdjustment = time(0) - 936144000; // 24000.0 + 2700.0 + (35.0 * 60.0) + (105 * 60.0);
2018-03-29 17:01:57 -04:00
CGlobals::CGlobals()
{
m_hWnd = NULL;
m_hConsoleWnd = NULL;
m_last = m_start = steady_clock::now();
m_fTime = g_TimeAdjustment;
2018-03-29 17:01:57 -04:00
2019-07-07 20:56:15 +00:00
m_GameDir = fs::current_path();
// int GameDirLen = GetCurrentDirectory(MAX_PATH, m_GameDir);
// if (GameDirLen > 0)
// {
// if (m_GameDir[GameDirLen - 1] == '\\')
// {
// m_GameDir[GameDirLen - 1] = 0;
// }
// }
2018-03-29 17:01:57 -04:00
ResetPackets();
UpdateTime();
}
CGlobals::~CGlobals()
{
}
const char *CGlobals::GetGameDirectory()
{
2019-07-07 20:56:15 +00:00
//return (char *)m_GameDir;
return m_GameDir.string().c_str();
2018-03-29 17:01:57 -04:00
}
std::string CGlobals::GetGameFile(const char *filename)
{
2019-07-07 20:56:15 +00:00
fs::path filepath = m_GameDir / filename;
return filepath.string();
//std::string filepath = GetGameDirectory();
//filepath += "\\";
//filepath += filename;
//return filepath;
}
std::string CGlobals::GetGameData(const char *type, const char *filename)
{
fs::path filepath = m_GameDir / type / filename;
return filepath.string();
2018-03-29 17:01:57 -04:00
}
void CGlobals::SetWindowHandle(HWND hWnd)
{
m_hWnd = hWnd;
}
HWND CGlobals::GetWindowHandle()
{
return (HWND)m_hWnd;
}
void CGlobals::SetConsoleWindowHandle(HWND hConsoleWnd)
{
m_hConsoleWnd = hConsoleWnd;
}
HWND CGlobals::GetConsoleWindowHandle()
{
return (HWND)m_hConsoleWnd;
}
void CGlobals::SetClientCount(WORD wCount)
{
m_wClientCount = wCount;
}
WORD CGlobals::GetClientCount()
{
return (WORD)m_wClientCount;
}
2019-07-07 20:56:15 +00:00
void CGlobals::PacketSent(uint32_t dwLength)
2018-03-29 17:01:57 -04:00
{
m_cPacketSendCount++;
m_cPacketSendSize += dwLength;
}
2019-07-07 20:56:15 +00:00
void CGlobals::PacketRecv(uint32_t dwLength)
2018-03-29 17:01:57 -04:00
{
m_cPacketRecvCount++;
m_cPacketRecvSize += dwLength;
}
UINT64 CGlobals::GetPacketSendCount()
{
return m_cPacketSendCount;
}
UINT64 CGlobals::GetPacketRecvCount()
{
return m_cPacketRecvCount;
}
UINT64 CGlobals::GetPacketSendSize()
{
return m_cPacketSendSize;
}
UINT64 CGlobals::GetPacketRecvSize()
{
return m_cPacketRecvSize;
}
void CGlobals::ResetPackets()
{
m_cPacketSendCount = 0;
m_cPacketRecvCount = 0;
m_cPacketSendSize = 0;
m_cPacketRecvSize = 0;
}
double CGlobals::Time()
{
return m_fTime;
}
int CGlobals::Timestamp()
{
return time(0);
}
double CGlobals::UpdateTime()
{
time_point current = steady_clock::now();
std::chrono::duration<double> elapsed = current - m_last;
m_last = current;
m_fTime += elapsed.count();
return m_fTime;
//QueryPerformanceCounter((LARGE_INTEGER *)&m_CounterTime);
//double fTime = (m_CounterTime - m_CounterStart) / (double)m_CounterFreq;
//fTime += g_TimeAdjustment;
//m_fTime = fTime;
2018-03-29 17:01:57 -04:00
//return fTime;
2018-03-29 17:01:57 -04:00
}