]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
deduplicate main()
authorbones_was_here <bones_was_here@xonotic.au>
Mon, 1 Jan 2024 03:58:00 +0000 (13:58 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Wed, 3 Jan 2024 00:13:52 +0000 (10:13 +1000)
Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
host.c
sys.h
sys_sdl.c
sys_shared.c
sys_unix.c

diff --git a/host.c b/host.c
index e7dd4a421b0d311a76bdd83051a632aff5b0f777..8ba2f272b3dd72eb41eeb3a06ba4ec3f3fcf5f2a 100644 (file)
--- 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 41d595b927785c41770fc1a5f8a4b8d5cde037c5..82134615407092afe3705719e486ace42952f4dd 100644 (file)
--- 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);
 
index a6bff96315790a871e6e6af9046285c0f55401a9..df25ae6a05ddfda7a3873fa1ff4f1f3c17564e8f 100644 (file)
--- a/sys_sdl.c
+++ b/sys_sdl.c
@@ -11,8 +11,6 @@
 #include <android/log.h>
 #endif
 
-#include <signal.h>
-
 /*
  * 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;
index d1c4eddea00951805c54758347a1b5d21f42ee3a..0bb69c2576d2cffc77006a1743cb9e831d46cac9 100644 (file)
@@ -31,6 +31,8 @@
 # endif
 #endif
 
+#include <signal.h>
+
 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;
+}
index 2ff100da32ab779cd5cdeee98ad20601993f1922..49990f1f377a5ebf20af3e15c7a424bbc1c2aa8a 100644 (file)
@@ -10,8 +10,6 @@
 #include <fcntl.h>
 #endif
 
-#include <signal.h>
-
 #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;