From: bones_was_here Date: Tue, 2 Jan 2024 06:58:35 +0000 (+1000) Subject: sys: commenting and tidying X-Git-Url: http://git.xonotic.org/?a=commitdiff_plain;h=247234d283ef847fb5dedb8f18eb887003ba2c4f;p=xonotic%2Fdarkplaces.git sys: commenting and tidying Signed-off-by: bones_was_here --- diff --git a/console.c b/console.c index 58409bef..f35645cc 100644 --- a/console.c +++ b/console.c @@ -930,8 +930,6 @@ void Con_Init (void) Cmd_AddCommand(CF_SHARED, "condump", Con_ConDump_f, "output console history to a file (see also log_file)"); con_initialized = true; - - Con_Print("Console initialized.\n"); } void Con_Shutdown (void) diff --git a/host.c b/host.c index 3274be80..7c89c589 100644 --- a/host.c +++ b/host.c @@ -439,6 +439,7 @@ static void Host_Init (void) Memory_Init_Commands(); // initialize console and logging and its cvars/commands + // this enables Con_Printf() messages to be coloured Con_Init(); // initialize various cvars that could not be initialized earlier diff --git a/keys.c b/keys.c index fd0a24b2..4d7ed174 100644 --- a/keys.c +++ b/keys.c @@ -768,7 +768,7 @@ int Key_Parse_CommonKeys(cmd_state_t *cmd, qbool is_console, int key, int unicod if ((key == 'v' && KM_CTRL) || ((key == K_INS || key == K_KP_INS) && KM_SHIFT)) { char *cbd, *p; - if ((cbd = Sys_GetClipboardData()) != 0) + if ((cbd = Sys_SDL_GetClipboardData()) != 0) { int i; #if 1 diff --git a/makefile.inc b/makefile.inc index 2534cff7..fc397415 100644 --- a/makefile.inc +++ b/makefile.inc @@ -126,7 +126,7 @@ OBJ_MENU= \ # note that builddate.c is very intentionally not compiled to a .o before # being linked, because it should be recompiled every time an executable is # built to give the executable a proper date string -OBJ_SV= builddate.c sys_unix.o vid_null.o thread_null.o $(OBJ_SND_NULL) $(OBJ_COMMON) +OBJ_SV= builddate.c sys_null.o vid_null.o thread_null.o $(OBJ_SND_NULL) $(OBJ_COMMON) OBJ_SDL= builddate.c sys_sdl.o vid_sdl.o thread_sdl.o $(OBJ_MENU) $(OBJ_SND_COMMON) $(OBJ_SND_XMP) snd_sdl.o $(OBJ_VIDEO_CAPTURE) $(OBJ_COMMON) diff --git a/sys.h b/sys.h index 1b076a69..119748ed 100644 --- a/sys.h +++ b/sys.h @@ -209,6 +209,7 @@ void Sys_Error (const char *error, ...) DP_FUNC_PRINTF(1) DP_FUNC_NORETURN; /// (may) output text to terminal which launched program void Sys_Print(const char *text); +/// for the console to report failures inside Con_Printf() void Sys_Printf(const char *fmt, ...); /// INFO: This is only called by Host_Shutdown so we dont need testing for recursion @@ -236,6 +237,7 @@ double Sys_DirtyTime(void); void Sys_ProvideSelfFD (void); +/// Reads a line from POSIX stdin or the Windows console char *Sys_ConsoleInput (void); /// called to yield for a little bit so as not to hog cpu when paused or debugging @@ -246,7 +248,7 @@ void Sys_SDL_Init(void); /// Perform Key_Event () callbacks until the input que is empty void Sys_SDL_HandleEvents(void); -char *Sys_GetClipboardData (void); +char *Sys_SDL_GetClipboardData (void); extern qbool sys_supportsdlgetticks; unsigned int Sys_SDL_GetTicks (void); // wrapper to call SDL_GetTicks diff --git a/sys_null.c b/sys_null.c new file mode 100644 index 00000000..e2b9b0a0 --- /dev/null +++ b/sys_null.c @@ -0,0 +1,35 @@ + +#include "darkplaces.h" + + +// ======================================================================= +// General routines +// ======================================================================= + +void Sys_SDL_Shutdown(void) +{ +} + +void Sys_SDL_Dialog(const char *title, const char *string) +{ +} + +char *Sys_SDL_GetClipboardData (void) +{ + return NULL; +} + +void Sys_SDL_Init(void) +{ +} + +qbool sys_supportsdlgetticks = false; +unsigned int Sys_SDL_GetTicks (void) +{ + Sys_Error("Called Sys_SDL_GetTicks on non-SDL target"); + return 0; +} +void Sys_SDL_Delay (unsigned int milliseconds) +{ + Sys_Error("Called Sys_SDL_Delay on non-SDL target"); +} diff --git a/sys_sdl.c b/sys_sdl.c index ce3d28ce..a876b388 100644 --- a/sys_sdl.c +++ b/sys_sdl.c @@ -1,8 +1,3 @@ -#ifdef WIN32 -#else -#include -#endif - /* * Include this BEFORE darkplaces.h because it breaks wrapping * _Static_assert. Cloudwalk has no idea how or why so don't ask. @@ -18,7 +13,6 @@ #endif #endif -sys_t sys; // ======================================================================= // General routines @@ -38,7 +32,7 @@ void Sys_SDL_Dialog(const char *title, const char *string) SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title, string, NULL); } -char *Sys_GetClipboardData (void) +char *Sys_SDL_GetClipboardData (void) { char *data = NULL; char *cliptext; diff --git a/sys_shared.c b/sys_shared.c index 5d19784d..286ff7e5 100644 --- a/sys_shared.c +++ b/sys_shared.c @@ -38,6 +38,8 @@ #include "thread.h" #include "libcurl.h" +sys_t sys; + static char sys_timestring[128]; char *Sys_TimeString(const char *timeformat) { @@ -497,7 +499,7 @@ double Sys_Sleep(double time) } if(sys_debugsleep.integer) - Sys_Printf("sys_debugsleep: requesting %u ", microseconds); + Con_Printf("sys_debugsleep: requesting %u ", microseconds); dt = Sys_DirtyTime(); // less important on newer libcurl so no need to disturb dedicated servers @@ -552,10 +554,19 @@ double Sys_Sleep(double time) dt = Sys_DirtyTime() - dt; if(sys_debugsleep.integer) - Sys_Printf(" got %u oversleep %d\n", (unsigned int)(dt * 1000000), (unsigned int)(dt * 1000000) - microseconds); + Con_Printf(" got %u oversleep %d\n", (unsigned int)(dt * 1000000), (unsigned int)(dt * 1000000) - microseconds); return (dt < 0 || dt >= 1800) ? 0 : dt; } + +/* +=============================================================================== + +STDIO + +=============================================================================== +*/ + void Sys_Print(const char *text) { #ifdef __ANDROID__ @@ -590,6 +601,7 @@ void Sys_Print(const char *text) #endif } +/// for the console to report failures inside Con_Printf() void Sys_Printf(const char *fmt, ...) { va_list argptr; @@ -602,6 +614,7 @@ void Sys_Printf(const char *fmt, ...) Sys_Print(msg); } +/// Reads a line from POSIX stdin or the Windows console char *Sys_ConsoleInput(void) { static char text[MAX_INPUTLINE]; @@ -663,6 +676,14 @@ char *Sys_ConsoleInput(void) } +/* +=============================================================================== + +Startup and Shutdown + +=============================================================================== +*/ + void Sys_Error (const char *error, ...) { va_list argptr; diff --git a/sys_unix.c b/sys_unix.c deleted file mode 100644 index 78b6eeb9..00000000 --- a/sys_unix.c +++ /dev/null @@ -1,42 +0,0 @@ - -#ifdef WIN32 -#include -#include -#else -#include -#endif - -#include "darkplaces.h" - -sys_t sys; - -// ======================================================================= -// General routines -// ======================================================================= -void Sys_SDL_Shutdown(void) -{ -} - -void Sys_SDL_Dialog(const char *title, const char *string) -{ -} - -char *Sys_GetClipboardData (void) -{ - return NULL; -} - -void Sys_SDL_Init(void) -{ -} - -qbool sys_supportsdlgetticks = false; -unsigned int Sys_SDL_GetTicks (void) -{ - Sys_Error("Called Sys_SDL_GetTicks on non-SDL target"); - return 0; -} -void Sys_SDL_Delay (unsigned int milliseconds) -{ - Sys_Error("Called Sys_SDL_Delay on non-SDL target"); -}