]> git.xonotic.org Git - xonotic/darkplaces.git/blob - sys_sdl.c
deduplicate Sys_Print()
[xonotic/darkplaces.git] / sys_sdl.c
1 #ifdef WIN32
2 #else
3 #include <fcntl.h>
4 #include <sys/time.h>
5 #endif
6
7 /*
8  * Include this BEFORE darkplaces.h because it breaks wrapping
9  * _Static_assert. Cloudwalk has no idea how or why so don't ask.
10  */
11 #include <SDL.h>
12
13 #include "darkplaces.h"
14
15 #ifdef WIN32
16 #ifdef _MSC_VER
17 #pragma comment(lib, "sdl2.lib")
18 #pragma comment(lib, "sdl2main.lib")
19 #endif
20 #endif
21
22 sys_t sys;
23
24 // =======================================================================
25 // General routines
26 // =======================================================================
27
28 void Sys_Shutdown (void)
29 {
30 #ifdef __ANDROID__
31         Sys_AllowProfiling(false);
32 #endif
33 #ifndef WIN32
34         fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK);
35 #endif
36         fflush(stdout);
37         SDL_Quit();
38 }
39
40 // Sys_Error early in startup might screw with automated
41 // workflows or something if we show the dialog by default.
42 static qbool nocrashdialog = true;
43 void Sys_SDL_Dialog(const char *title, const char *string)
44 {
45         if(!nocrashdialog)
46                 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title, string, NULL);
47 }
48
49 char *Sys_GetClipboardData (void)
50 {
51         char *data = NULL;
52         char *cliptext;
53
54         cliptext = SDL_GetClipboardText();
55         if (cliptext != NULL) {
56                 size_t allocsize;
57                 allocsize = min(MAX_INPUTLINE, strlen(cliptext) + 1);
58                 data = (char *)Z_Malloc (allocsize);
59                 strlcpy (data, cliptext, allocsize);
60                 SDL_free(cliptext);
61         }
62
63         return data;
64 }
65
66 void Sys_SDL_Init(void)
67 {
68         // we don't know which systems we'll want to init, yet...
69         if (SDL_Init(0) < 0)
70                 Sys_Error("SDL_Init failed: %s\n", SDL_GetError());
71
72         // COMMANDLINEOPTION: sdl: -nocrashdialog disables "Engine Error" crash dialog boxes
73         if(!Sys_CheckParm("-nocrashdialog"))
74                 nocrashdialog = false;
75 }
76
77 qbool sys_supportsdlgetticks = true;
78 unsigned int Sys_SDL_GetTicks (void)
79 {
80         return SDL_GetTicks();
81 }
82 void Sys_SDL_Delay (unsigned int milliseconds)
83 {
84         SDL_Delay(milliseconds);
85 }