mirror of
https://github.com/rehlds/rehlds.git
synced 2025-02-15 16:18:47 +03:00
Make launcher code cleaner
This commit is contained in:
parent
0c4f5d37ad
commit
87131e27e2
@ -10,9 +10,7 @@ static HANDLE hStdin;
|
||||
BOOL SetConsoleCXCY(HANDLE hStdout, int cx, int cy)
|
||||
{
|
||||
CONSOLE_SCREEN_BUFFER_INFO info;
|
||||
COORD coordMax;
|
||||
|
||||
coordMax = GetLargestConsoleWindowSize(hStdout);
|
||||
COORD coordMax = GetLargestConsoleWindowSize(hStdout);
|
||||
|
||||
if (cy > coordMax.Y)
|
||||
cy = coordMax.Y;
|
||||
@ -113,12 +111,11 @@ BOOL ReadText(LPTSTR pszText, int iBeginLine, int iEndLine)
|
||||
{
|
||||
COORD coord;
|
||||
DWORD dwRead;
|
||||
BOOL bRet;
|
||||
|
||||
coord.X = 0;
|
||||
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.
|
||||
if (bRet)
|
||||
@ -183,23 +180,21 @@ BOOL WriteText(LPCTSTR szText)
|
||||
|
||||
unsigned __stdcall RequestProc(void *arg)
|
||||
{
|
||||
int *pBuffer;
|
||||
DWORD dwRet;
|
||||
HANDLE heventWait[2];
|
||||
int iBeginLine, iEndLine;
|
||||
|
||||
heventWait[0] = heventParentSend;
|
||||
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.
|
||||
if (dwRet == WAIT_OBJECT_0 + 1)
|
||||
break;
|
||||
|
||||
pBuffer = (int *)GetMappedBuffer(hfileBuffer);
|
||||
int* pBuffer = (int *)GetMappedBuffer(hfileBuffer);
|
||||
|
||||
// hfileBuffer is invalid. Just leave.
|
||||
if (!pBuffer)
|
||||
@ -284,14 +279,14 @@ void InitConProc()
|
||||
heventChildSend = heventChild;
|
||||
|
||||
// So we'll know when to go away.
|
||||
heventDone = CreateEvent(NULL, FALSE, FALSE, NULL);
|
||||
heventDone = CreateEvent(nullptr, FALSE, FALSE, nullptr);
|
||||
if (!heventDone)
|
||||
{
|
||||
sys->Printf("InitConProc: Couldn't create heventDone\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_beginthreadex(NULL, 0, RequestProc, NULL, 0, &threadAddr))
|
||||
if (!_beginthreadex(nullptr, 0, RequestProc, nullptr, 0, &threadAddr))
|
||||
{
|
||||
CloseHandle(heventDone);
|
||||
sys->Printf("InitConProc: Couldn't create third party thread\n");
|
||||
|
@ -33,9 +33,8 @@ inline void CPerformanceCounter::InitializePerformanceCounter()
|
||||
|
||||
// get 32 out of the 64 time bits such that we have around
|
||||
// 1 microsecond resolution
|
||||
unsigned int lowpart, highpart;
|
||||
lowpart = (unsigned int)performanceFreq.LowPart;
|
||||
highpart = (unsigned int)performanceFreq.HighPart;
|
||||
auto lowpart = performanceFreq.LowPart;
|
||||
auto highpart = performanceFreq.HighPart;
|
||||
m_iLowShift = 0;
|
||||
|
||||
while (highpart || (lowpart > 2000000.0))
|
||||
@ -46,7 +45,7 @@ inline void CPerformanceCounter::InitializePerformanceCounter()
|
||||
highpart >>= 1;
|
||||
}
|
||||
|
||||
m_flPerfCounterFreq = 1.0 / (double)lowpart;
|
||||
m_flPerfCounterFreq = 1.0 / lowpart;
|
||||
|
||||
#endif // _WIN32
|
||||
}
|
||||
@ -59,18 +58,16 @@ inline double CPerformanceCounter::GetCurTime()
|
||||
static unsigned int oldtime;
|
||||
static int first = 1;
|
||||
LARGE_INTEGER PerformanceCount;
|
||||
unsigned int temp, t2;
|
||||
double time;
|
||||
unsigned int temp;
|
||||
|
||||
QueryPerformanceCounter(&PerformanceCount);
|
||||
if (m_iLowShift == 0)
|
||||
{
|
||||
temp = (unsigned int)PerformanceCount.LowPart;
|
||||
temp = PerformanceCount.LowPart;
|
||||
}
|
||||
else
|
||||
{
|
||||
temp = ((unsigned int)PerformanceCount.LowPart >> m_iLowShift) |
|
||||
((unsigned int)PerformanceCount.HighPart << (32 - m_iLowShift));
|
||||
temp = (PerformanceCount.LowPart >> m_iLowShift) | (PerformanceCount.HighPart << (32 - m_iLowShift));
|
||||
}
|
||||
|
||||
if (first)
|
||||
@ -88,12 +85,8 @@ inline double CPerformanceCounter::GetCurTime()
|
||||
}
|
||||
else
|
||||
{
|
||||
t2 = temp - oldtime;
|
||||
|
||||
time = (double)t2 * m_flPerfCounterFreq;
|
||||
oldtime = temp;
|
||||
|
||||
m_flCurrentTime += time;
|
||||
m_flCurrentTime += (temp - oldtime) * m_flPerfCounterFreq;
|
||||
|
||||
if (m_flCurrentTime == m_flLastCurrentTime)
|
||||
{
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
class CDedicatedExports: IDedicatedExports {
|
||||
public:
|
||||
void Sys_Printf(char *text);
|
||||
void Sys_Printf(char *text) override;
|
||||
};
|
||||
|
||||
EXPOSE_SINGLE_INTERFACE(CDedicatedExports, IDedicatedExports, VENGINE_DEDICATEDEXPORTS_API_VERSION);
|
||||
|
@ -83,7 +83,7 @@ int RunEngine()
|
||||
{
|
||||
engineAPI = (IDedicatedServerAPI *)engineFactory(VENGINE_HLDS_API_VERSION, nullptr);
|
||||
#ifdef LAUNCHER_FIXES
|
||||
rehldsApi = (IRehldsApi *)engineFactory(VREHLDS_HLDS_API_VERSION, NULL);
|
||||
rehldsApi = (IRehldsApi *)engineFactory(VREHLDS_HLDS_API_VERSION, nullptr);
|
||||
if (rehldsApi)
|
||||
{
|
||||
if (rehldsApi->GetMajorVersion() != REHLDS_API_VERSION_MAJOR || rehldsApi->GetMinorVersion() < REHLDS_API_VERSION_MINOR)
|
||||
|
@ -5,22 +5,22 @@ public:
|
||||
CSys();
|
||||
virtual ~CSys();
|
||||
|
||||
void Sleep(int msec);
|
||||
bool GetExecutableName(char *out);
|
||||
NORETURN void ErrorMessage(int level, const char *msg);
|
||||
void Sleep(int msec) override;
|
||||
bool GetExecutableName(char *out) override;
|
||||
NORETURN void ErrorMessage(int level, const char *msg) override;
|
||||
|
||||
void WriteStatusText(char *szText);
|
||||
void UpdateStatus(int force);
|
||||
void WriteStatusText(char *szText) override;
|
||||
void UpdateStatus(int force) override;
|
||||
|
||||
long LoadLibrary(char *lib);
|
||||
void FreeLibrary(long library);
|
||||
long LoadLibrary(char *lib) override;
|
||||
void FreeLibrary(long library) override;
|
||||
|
||||
bool CreateConsoleWindow();
|
||||
void DestroyConsoleWindow();
|
||||
bool CreateConsoleWindow() override;
|
||||
void DestroyConsoleWindow() override;
|
||||
|
||||
void ConsoleOutput(char *string);
|
||||
char *ConsoleInput();
|
||||
void Printf(char *fmt, ...);
|
||||
void ConsoleOutput(char *string) override;
|
||||
char *ConsoleInput() override;
|
||||
void Printf(char *fmt, ...) override;
|
||||
};
|
||||
|
||||
CSys g_Sys;
|
||||
@ -71,7 +71,7 @@ void Sleep_Select(int msec)
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 1000 * msec;
|
||||
|
||||
select(1, NULL, NULL, NULL, &tv);
|
||||
select(1, nullptr, nullptr, nullptr, &tv);
|
||||
}
|
||||
|
||||
void Sleep_Net(int msec)
|
||||
@ -102,7 +102,7 @@ void Sleep_Timer(int msec)
|
||||
g_bPaused = false;
|
||||
|
||||
// set the timer to trigger
|
||||
if (!setitimer(ITIMER_REAL, &tm, NULL)) {
|
||||
if (!setitimer(ITIMER_REAL, &tm, nullptr)) {
|
||||
// wait for the signal
|
||||
pause();
|
||||
}
|
||||
@ -133,9 +133,8 @@ void Sys_InitPingboost()
|
||||
Sys_Sleep = Sleep_Old;
|
||||
|
||||
char *pPingType;
|
||||
int type;
|
||||
if (CommandLine()->CheckParm("-pingboost", &pPingType) && pPingType) {
|
||||
type = atoi(pPingType);
|
||||
int type = atoi(pPingType);
|
||||
switch (type) {
|
||||
case 1:
|
||||
signal(SIGALRM, alarmFunc);
|
||||
|
@ -47,7 +47,7 @@ void CSys::Sleep(int msec)
|
||||
|
||||
bool CSys::GetExecutableName(char *out)
|
||||
{
|
||||
if (!::GetModuleFileName((HINSTANCE)GetModuleHandle(NULL), out, 256))
|
||||
if (!::GetModuleFileName((HINSTANCE)GetModuleHandle(nullptr), out, 256))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@ -67,7 +67,6 @@ void CSys::WriteStatusText(char *szText)
|
||||
void CSys::UpdateStatus(int force)
|
||||
{
|
||||
static double tLast = 0.0;
|
||||
double tCurrent;
|
||||
char szStatus[256];
|
||||
int n, nMax;
|
||||
char szMap[32];
|
||||
@ -76,7 +75,7 @@ void CSys::UpdateStatus(int force)
|
||||
if (!engineAPI)
|
||||
return;
|
||||
|
||||
tCurrent = (double)timeGetTime() * 0.001;
|
||||
double tCurrent = timeGetTime() * 0.001;
|
||||
engineAPI->UpdateStatus(&fps, &n, &nMax, szMap);
|
||||
|
||||
if (!force)
|
||||
@ -190,8 +189,8 @@ bool Sys_SetupConsole()
|
||||
void Sys_PrepareConsoleInput()
|
||||
{
|
||||
MSG msg;
|
||||
while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) {
|
||||
if (!GetMessage(&msg, NULL, 0, 0)) {
|
||||
while (PeekMessage(&msg, nullptr, 0, 0, PM_NOREMOVE)) {
|
||||
if (!GetMessage(&msg, nullptr, 0, 0)) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user