2
0
mirror of https://github.com/rehlds/rehlds.git synced 2025-02-16 00:28:50 +03:00

Make launcher code cleaner

This commit is contained in:
asmodai 2017-05-05 18:45:24 +03:00
parent 0c4f5d37ad
commit 87131e27e2
6 changed files with 47 additions and 61 deletions

View File

@ -10,9 +10,7 @@ static HANDLE hStdin;
BOOL SetConsoleCXCY(HANDLE hStdout, int cx, int cy) BOOL SetConsoleCXCY(HANDLE hStdout, int cx, int cy)
{ {
CONSOLE_SCREEN_BUFFER_INFO info; CONSOLE_SCREEN_BUFFER_INFO info;
COORD coordMax; COORD coordMax = GetLargestConsoleWindowSize(hStdout);
coordMax = GetLargestConsoleWindowSize(hStdout);
if (cy > coordMax.Y) if (cy > coordMax.Y)
cy = coordMax.Y; cy = coordMax.Y;
@ -113,12 +111,11 @@ BOOL ReadText(LPTSTR pszText, int iBeginLine, int iEndLine)
{ {
COORD coord; COORD coord;
DWORD dwRead; DWORD dwRead;
BOOL bRet;
coord.X = 0; coord.X = 0;
coord.Y = iBeginLine; coord.Y = iBeginLine;
bRet = ReadConsoleOutputCharacter(hStdout, pszText, 80 * (iEndLine - iBeginLine + 1), coord, &dwRead); BOOL bRet = ReadConsoleOutputCharacter(hStdout, pszText, 80 * (iEndLine - iBeginLine + 1), coord, &dwRead);
// Make sure it's null terminated. // Make sure it's null terminated.
if (bRet) if (bRet)
@ -183,23 +180,21 @@ BOOL WriteText(LPCTSTR szText)
unsigned __stdcall RequestProc(void *arg) unsigned __stdcall RequestProc(void *arg)
{ {
int *pBuffer;
DWORD dwRet;
HANDLE heventWait[2]; HANDLE heventWait[2];
int iBeginLine, iEndLine; int iBeginLine, iEndLine;
heventWait[0] = heventParentSend; heventWait[0] = heventParentSend;
heventWait[1] = heventDone; heventWait[1] = heventDone;
while (1) for (;;)
{ {
dwRet = WaitForMultipleObjects(2, heventWait, FALSE, INFINITE); DWORD dwRet = WaitForMultipleObjects(2, heventWait, FALSE, INFINITE);
// heventDone fired, so we're exiting. // heventDone fired, so we're exiting.
if (dwRet == WAIT_OBJECT_0 + 1) if (dwRet == WAIT_OBJECT_0 + 1)
break; break;
pBuffer = (int *)GetMappedBuffer(hfileBuffer); int* pBuffer = (int *)GetMappedBuffer(hfileBuffer);
// hfileBuffer is invalid. Just leave. // hfileBuffer is invalid. Just leave.
if (!pBuffer) if (!pBuffer)
@ -284,14 +279,14 @@ void InitConProc()
heventChildSend = heventChild; heventChildSend = heventChild;
// So we'll know when to go away. // So we'll know when to go away.
heventDone = CreateEvent(NULL, FALSE, FALSE, NULL); heventDone = CreateEvent(nullptr, FALSE, FALSE, nullptr);
if (!heventDone) if (!heventDone)
{ {
sys->Printf("InitConProc: Couldn't create heventDone\n"); sys->Printf("InitConProc: Couldn't create heventDone\n");
return; return;
} }
if (!_beginthreadex(NULL, 0, RequestProc, NULL, 0, &threadAddr)) if (!_beginthreadex(nullptr, 0, RequestProc, nullptr, 0, &threadAddr))
{ {
CloseHandle(heventDone); CloseHandle(heventDone);
sys->Printf("InitConProc: Couldn't create third party thread\n"); sys->Printf("InitConProc: Couldn't create third party thread\n");

View File

@ -33,9 +33,8 @@ inline void CPerformanceCounter::InitializePerformanceCounter()
// get 32 out of the 64 time bits such that we have around // get 32 out of the 64 time bits such that we have around
// 1 microsecond resolution // 1 microsecond resolution
unsigned int lowpart, highpart; auto lowpart = performanceFreq.LowPart;
lowpart = (unsigned int)performanceFreq.LowPart; auto highpart = performanceFreq.HighPart;
highpart = (unsigned int)performanceFreq.HighPart;
m_iLowShift = 0; m_iLowShift = 0;
while (highpart || (lowpart > 2000000.0)) while (highpart || (lowpart > 2000000.0))
@ -46,7 +45,7 @@ inline void CPerformanceCounter::InitializePerformanceCounter()
highpart >>= 1; highpart >>= 1;
} }
m_flPerfCounterFreq = 1.0 / (double)lowpart; m_flPerfCounterFreq = 1.0 / lowpart;
#endif // _WIN32 #endif // _WIN32
} }
@ -59,18 +58,16 @@ inline double CPerformanceCounter::GetCurTime()
static unsigned int oldtime; static unsigned int oldtime;
static int first = 1; static int first = 1;
LARGE_INTEGER PerformanceCount; LARGE_INTEGER PerformanceCount;
unsigned int temp, t2; unsigned int temp;
double time;
QueryPerformanceCounter(&PerformanceCount); QueryPerformanceCounter(&PerformanceCount);
if (m_iLowShift == 0) if (m_iLowShift == 0)
{ {
temp = (unsigned int)PerformanceCount.LowPart; temp = PerformanceCount.LowPart;
} }
else else
{ {
temp = ((unsigned int)PerformanceCount.LowPart >> m_iLowShift) | temp = (PerformanceCount.LowPart >> m_iLowShift) | (PerformanceCount.HighPart << (32 - m_iLowShift));
((unsigned int)PerformanceCount.HighPart << (32 - m_iLowShift));
} }
if (first) if (first)
@ -88,12 +85,8 @@ inline double CPerformanceCounter::GetCurTime()
} }
else else
{ {
t2 = temp - oldtime;
time = (double)t2 * m_flPerfCounterFreq;
oldtime = temp; oldtime = temp;
m_flCurrentTime += (temp - oldtime) * m_flPerfCounterFreq;
m_flCurrentTime += time;
if (m_flCurrentTime == m_flLastCurrentTime) if (m_flCurrentTime == m_flLastCurrentTime)
{ {

View File

@ -2,7 +2,7 @@
class CDedicatedExports: IDedicatedExports { class CDedicatedExports: IDedicatedExports {
public: public:
void Sys_Printf(char *text); void Sys_Printf(char *text) override;
}; };
EXPOSE_SINGLE_INTERFACE(CDedicatedExports, IDedicatedExports, VENGINE_DEDICATEDEXPORTS_API_VERSION); EXPOSE_SINGLE_INTERFACE(CDedicatedExports, IDedicatedExports, VENGINE_DEDICATEDEXPORTS_API_VERSION);

View File

@ -83,7 +83,7 @@ int RunEngine()
{ {
engineAPI = (IDedicatedServerAPI *)engineFactory(VENGINE_HLDS_API_VERSION, nullptr); engineAPI = (IDedicatedServerAPI *)engineFactory(VENGINE_HLDS_API_VERSION, nullptr);
#ifdef LAUNCHER_FIXES #ifdef LAUNCHER_FIXES
rehldsApi = (IRehldsApi *)engineFactory(VREHLDS_HLDS_API_VERSION, NULL); rehldsApi = (IRehldsApi *)engineFactory(VREHLDS_HLDS_API_VERSION, nullptr);
if (rehldsApi) if (rehldsApi)
{ {
if (rehldsApi->GetMajorVersion() != REHLDS_API_VERSION_MAJOR || rehldsApi->GetMinorVersion() < REHLDS_API_VERSION_MINOR) if (rehldsApi->GetMajorVersion() != REHLDS_API_VERSION_MAJOR || rehldsApi->GetMinorVersion() < REHLDS_API_VERSION_MINOR)

View File

@ -5,22 +5,22 @@ public:
CSys(); CSys();
virtual ~CSys(); virtual ~CSys();
void Sleep(int msec); void Sleep(int msec) override;
bool GetExecutableName(char *out); bool GetExecutableName(char *out) override;
NORETURN void ErrorMessage(int level, const char *msg); NORETURN void ErrorMessage(int level, const char *msg) override;
void WriteStatusText(char *szText); void WriteStatusText(char *szText) override;
void UpdateStatus(int force); void UpdateStatus(int force) override;
long LoadLibrary(char *lib); long LoadLibrary(char *lib) override;
void FreeLibrary(long library); void FreeLibrary(long library) override;
bool CreateConsoleWindow(); bool CreateConsoleWindow() override;
void DestroyConsoleWindow(); void DestroyConsoleWindow() override;
void ConsoleOutput(char *string); void ConsoleOutput(char *string) override;
char *ConsoleInput(); char *ConsoleInput() override;
void Printf(char *fmt, ...); void Printf(char *fmt, ...) override;
}; };
CSys g_Sys; CSys g_Sys;
@ -71,7 +71,7 @@ void Sleep_Select(int msec)
tv.tv_sec = 0; tv.tv_sec = 0;
tv.tv_usec = 1000 * msec; tv.tv_usec = 1000 * msec;
select(1, NULL, NULL, NULL, &tv); select(1, nullptr, nullptr, nullptr, &tv);
} }
void Sleep_Net(int msec) void Sleep_Net(int msec)
@ -102,7 +102,7 @@ void Sleep_Timer(int msec)
g_bPaused = false; g_bPaused = false;
// set the timer to trigger // set the timer to trigger
if (!setitimer(ITIMER_REAL, &tm, NULL)) { if (!setitimer(ITIMER_REAL, &tm, nullptr)) {
// wait for the signal // wait for the signal
pause(); pause();
} }
@ -133,9 +133,8 @@ void Sys_InitPingboost()
Sys_Sleep = Sleep_Old; Sys_Sleep = Sleep_Old;
char *pPingType; char *pPingType;
int type;
if (CommandLine()->CheckParm("-pingboost", &pPingType) && pPingType) { if (CommandLine()->CheckParm("-pingboost", &pPingType) && pPingType) {
type = atoi(pPingType); int type = atoi(pPingType);
switch (type) { switch (type) {
case 1: case 1:
signal(SIGALRM, alarmFunc); signal(SIGALRM, alarmFunc);

View File

@ -47,7 +47,7 @@ void CSys::Sleep(int msec)
bool CSys::GetExecutableName(char *out) bool CSys::GetExecutableName(char *out)
{ {
if (!::GetModuleFileName((HINSTANCE)GetModuleHandle(NULL), out, 256)) if (!::GetModuleFileName((HINSTANCE)GetModuleHandle(nullptr), out, 256))
return false; return false;
return true; return true;
@ -67,7 +67,6 @@ void CSys::WriteStatusText(char *szText)
void CSys::UpdateStatus(int force) void CSys::UpdateStatus(int force)
{ {
static double tLast = 0.0; static double tLast = 0.0;
double tCurrent;
char szStatus[256]; char szStatus[256];
int n, nMax; int n, nMax;
char szMap[32]; char szMap[32];
@ -76,7 +75,7 @@ void CSys::UpdateStatus(int force)
if (!engineAPI) if (!engineAPI)
return; return;
tCurrent = (double)timeGetTime() * 0.001; double tCurrent = timeGetTime() * 0.001;
engineAPI->UpdateStatus(&fps, &n, &nMax, szMap); engineAPI->UpdateStatus(&fps, &n, &nMax, szMap);
if (!force) if (!force)
@ -190,8 +189,8 @@ bool Sys_SetupConsole()
void Sys_PrepareConsoleInput() void Sys_PrepareConsoleInput()
{ {
MSG msg; MSG msg;
while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { while (PeekMessage(&msg, nullptr, 0, 0, PM_NOREMOVE)) {
if (!GetMessage(&msg, NULL, 0, 0)) { if (!GetMessage(&msg, nullptr, 0, 0)) {
break; break;
} }