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