From acb50c6907eee8a851dad4768a64273313ba246e Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Sat, 3 Feb 2018 18:09:19 +0100 Subject: [PATCH] Move the platform independent stuff from main() into Qcommon_*(). There's no need to duplicate machine independent parts of the client initialization and the main loop for every platform. While at it remove the nearly empty unix.h header and move Windows main() into an own file. Not both platform have the same basic layout. --- CMakeLists.txt | 7 +- Makefile | 2 + src/backends/unix/main.c | 99 +++---------------- src/backends/unix/system.c | 8 +- .../{unix/header/unix.h => windows/main.c} | 42 +++++++- src/backends/windows/system.c | 90 ----------------- src/common/frame.c | 88 ++++++++++++++++- src/common/header/common.h | 6 +- 8 files changed, 154 insertions(+), 188 deletions(-) rename src/backends/{unix/header/unix.h => windows/main.c} (53%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 202501be..3c82312a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -184,13 +184,10 @@ set(Backends-Unix-Source ${BACKENDS_SRC_DIR}/unix/shared/hunk.c ) -set(Backends-Unix-Header - ${BACKENDS_SRC_DIR}/unix/header/unix.h - ) - set(Backends-Windows-Source ${BACKENDS_SRC_DIR}/generic/frame.c ${BACKENDS_SRC_DIR}/windows/icon.rc + ${BACKENDS_SRC_DIR}/windows/main.c ${BACKENDS_SRC_DIR}/windows/network.c ${BACKENDS_SRC_DIR}/windows/system.c ${BACKENDS_SRC_DIR}/windows/shared/mem.c @@ -213,7 +210,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") set(Platform-Specific-Source ${Backends-Windows-Source} ${Backends-Windows-Header}) set(REF-Platform-Specific-Source ${REF-Windows-Source}) else() - set(Platform-Specific-Source ${Backends-Unix-Source} ${Backends-Unix-Header}) + set(Platform-Specific-Source ${Backends-Unix-Source}) set(REF-Platform-Specific-Source ${REF-Unix-Source}) endif() diff --git a/Makefile b/Makefile index be0f4873..234a0fcb 100755 --- a/Makefile +++ b/Makefile @@ -863,6 +863,7 @@ CLIENT_OBJS_ := \ ifeq ($(YQ2_OSTYPE), Windows) CLIENT_OBJS_ += \ + src/backends/windows/main.o \ src/backends/windows/network.o \ src/backends/windows/system.o \ src/backends/windows/shared/mem.o @@ -1010,6 +1011,7 @@ SERVER_OBJS_ := \ ifeq ($(YQ2_OSTYPE), Windows) SERVER_OBJS_ += \ + src/backends/windows/main.o \ src/backends/windows/network.o \ src/backends/windows/system.o \ src/backends/windows/shared/mem.o diff --git a/src/backends/unix/main.c b/src/backends/unix/main.c index ca5e1455..9a294bdd 100644 --- a/src/backends/unix/main.c +++ b/src/backends/unix/main.c @@ -19,44 +19,32 @@ * * ======================================================================= * - * This file is the starting point of the program and implements - * the main loop + * This file is the starting point of the program. It does some platform + * specific initialization stuff and calls the common initialization code. * * ======================================================================= */ #include -#include -#include #include #include "../../common/header/common.h" -#include "header/unix.h" + +void registerHandler(void); qboolean is_portable; int main(int argc, char **argv) { - int verLen, i; - long long oldtime, newtime; - const char* versionString; - - // Time slept each frame. -#ifndef DEDICATED_ONLY - struct timespec t = {0, 5000}; -#else - struct timespec t = {0, 850000}; -#endif - - /* register signal handler */ + // register signal handler registerHandler(); - /* Setup FPU if necessary */ + // Setup FPU if necessary Sys_SetupFPU(); - /* Are we portable? */ - for (i = 0; i < argc; i++) { + // Are we portable? + for (int i = 0; i < argc; i++) { if (strcmp(argv[i], "-portable") == 0) { is_portable = true; } @@ -73,8 +61,7 @@ main(int argc, char **argv) return 1; } - /* Enforce the real UID to - prevent setuid crap */ + // Enforce the real UID to prevent setuid crap if (getuid() != geteuid()) { printf("The effective UID is not the real UID! Your binary is probably marked\n"); @@ -85,73 +72,15 @@ main(int argc, char **argv) return 1; } - /* enforce C locale */ + // enforce C locale setenv("LC_ALL", "C", 1); - versionString = va("Yamagi Quake II v%s", YQ2VERSION); - verLen = strlen(versionString); - - printf("\n%s\n", versionString); - for(i=0; i