From: bones_was_here Date: Mon, 1 Jan 2024 03:58:00 +0000 (+1000) Subject: deduplicate main() X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=bfbabeee8f8ae8c5f35a147be7ab6ca31960b0e8;p=xonotic%2Fdarkplaces.git deduplicate main() Signed-off-by: bones_was_here --- diff --git a/host.c b/host.c index e7dd4a42..8ba2f272 100644 --- a/host.c +++ b/host.c @@ -370,6 +370,10 @@ static void Host_Init (void) int i; char vabuf[1024]; + Sys_SDL_Init(); + + Memory_Init(); + host.hook.ConnectLocal = NULL; host.hook.Disconnect = NULL; host.hook.ToggleMenu = NULL; diff --git a/sys.h b/sys.h index 41d595b9..82134615 100644 --- a/sys.h +++ b/sys.h @@ -241,6 +241,7 @@ char *Sys_ConsoleInput (void); /// called to yield for a little bit so as not to hog cpu when paused or debugging double Sys_Sleep(double time); +void Sys_SDL_Init(void); /// Perform Key_Event () callbacks until the input que is empty void Sys_SDL_HandleEvents(void); diff --git a/sys_sdl.c b/sys_sdl.c index a6bff963..df25ae6a 100644 --- a/sys_sdl.c +++ b/sys_sdl.c @@ -11,8 +11,6 @@ #include #endif -#include - /* * Include this BEFORE darkplaces.h because it breaks wrapping * _Static_assert. Cloudwalk has no idea how or why so don't ask. @@ -46,7 +44,9 @@ void Sys_Shutdown (void) SDL_Quit(); } -static qbool nocrashdialog; +// Sys_Error early in startup might screw with automated +// workflows or something if we show the dialog by default. +static qbool nocrashdialog = true; void Sys_Error (const char *error, ...) { va_list argptr; @@ -181,51 +181,15 @@ char *Sys_GetClipboardData (void) return data; } -int main (int argc, char *argv[]) +void Sys_SDL_Init(void) { - signal(SIGFPE, SIG_IGN); - -#ifdef __ANDROID__ - Sys_AllowProfiling(true); -#endif - - sys.selffd = -1; - sys.argc = argc; - sys.argv = (const char **)argv; - - // Sys_Error this early in startup might screw with automated - // workflows or something if we show the dialog by default. - nocrashdialog = true; - - Sys_ProvideSelfFD(); + // we don't know which systems we'll want to init, yet... + if (SDL_Init(0) < 0) + Sys_Error("SDL_Init failed: %s\n", SDL_GetError()); - // COMMANDLINEOPTION: -nocrashdialog disables "Engine Error" crash dialog boxes + // COMMANDLINEOPTION: sdl: -nocrashdialog disables "Engine Error" crash dialog boxes if(!Sys_CheckParm("-nocrashdialog")) nocrashdialog = false; - // COMMANDLINEOPTION: sdl: -noterminal disables console output on stdout - if(Sys_CheckParm("-noterminal")) - sys.outfd = -1; - // COMMANDLINEOPTION: sdl: -stderr moves console output to stderr - else if(Sys_CheckParm("-stderr")) - sys.outfd = 2; - else - sys.outfd = 1; - -#ifndef WIN32 - fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | O_NONBLOCK); -#endif - - // we don't know which systems we'll want to init, yet... - SDL_Init(0); - - // used by everything - Memory_Init(); - - Host_Main(); - - Sys_Quit(0); - - return 0; } qbool sys_supportsdlgetticks = true; diff --git a/sys_shared.c b/sys_shared.c index d1c4edde..0bb69c25 100644 --- a/sys_shared.c +++ b/sys_shared.c @@ -31,6 +31,8 @@ # endif #endif +#include + static char sys_timestring[128]; char *Sys_TimeString(const char *timeformat) { @@ -745,3 +747,37 @@ void Sys_MakeProcessMean (void) { } #endif + +int main (int argc, char **argv) +{ + signal(SIGFPE, SIG_IGN); + + sys.argc = argc; + sys.argv = (const char **)argv; + + // COMMANDLINEOPTION: -noterminal disables console output on stdout + if(Sys_CheckParm("-noterminal")) + sys.outfd = -1; + // COMMANDLINEOPTION: -stderr moves console output to stderr + else if(Sys_CheckParm("-stderr")) + sys.outfd = 2; + else + sys.outfd = 1; + + sys.selffd = -1; + Sys_ProvideSelfFD(); // may call Con_Printf() so must be after sys.outfd is set + +#ifndef WIN32 + fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | O_NONBLOCK); +#endif + +#ifdef __ANDROID__ + Sys_AllowProfiling(true); +#endif + + Host_Main(); + + Sys_Quit(0); + + return 0; +} diff --git a/sys_unix.c b/sys_unix.c index 2ff100da..49990f1f 100644 --- a/sys_unix.c +++ b/sys_unix.c @@ -10,8 +10,6 @@ #include #endif -#include - #include "darkplaces.h" sys_t sys; @@ -138,34 +136,8 @@ char *Sys_GetClipboardData (void) return NULL; } -int main (int argc, char **argv) +void Sys_SDL_Init(void) { - signal(SIGFPE, SIG_IGN); - sys.selffd = -1; - sys.argc = argc; - sys.argv = (const char **)argv; - Sys_ProvideSelfFD(); - - // COMMANDLINEOPTION: sdl: -noterminal disables console output on stdout - if(Sys_CheckParm("-noterminal")) - sys.outfd = -1; - // COMMANDLINEOPTION: sdl: -stderr moves console output to stderr - else if(Sys_CheckParm("-stderr")) - sys.outfd = 2; - else - sys.outfd = 1; -#ifndef WIN32 - fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | O_NONBLOCK); -#endif - - // used by everything - Memory_Init(); - - Host_Main(); - - Sys_Quit(0); - - return 0; } qbool sys_supportsdlgetticks = false;