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