Debian Codegraph @

similar/arch/sdl/init.cpp

raw
1 /*
2 * This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>.
3 * It is copyright by its individual contributors, as recorded in the
4 * project's Git history. See COPYING.txt at the top level for license
5 * terms and a link to the Git history.
6 */
7 // Holds the main init and de-init functions for arch-related program parts
8
9 #include <SDL.h>
10 #include "songs.h"
11 #include "key.h"
12 #include "digi.h"
13 #include "mouse.h"
14 #include "joy.h"
15 #include "gr.h"
16 #include "dxxerror.h"
17 #include "text.h"
18 #include "args.h"
19 #include "window.h"
20 #include "dxxsconf.h"
21
22 #if DXX_USE_SDLIMAGE
23 #include <SDL_image.h>
24 #endif
25
26 namespace dsx {
27
28 static void arch_close(void)
29 {
30 songs_uninit();
31
32 gr_close();
33
34 if (!CGameArg.CtlNoJoystick)
35 joy_close();
36
37 if (!CGameArg.CtlNoMouse)
38 mouse_close();
39
40 if (!CGameArg.SndNoSound)
41 {
42 digi_close();
43 }
44 #if DXX_USE_SDLIMAGE
45 IMG_Quit();
46 #endif
47 SDL_Quit();
48 }
49
50 arch_atexit::~arch_atexit()
51 {
52 arch_close();
53 }
54
55 arch_atexit arch_init()
56 {
57 int t;
58
59 if (SDL_Init(SDL_INIT_VIDEO) < 0)
60 Error("SDL library initialisation failed: %s.",SDL_GetError());
61 #if DXX_USE_SDLIMAGE
62 IMG_Init(0);
63 #endif
64 #if SDL_MAJOR_VERSION == 2
65 /* In SDL1, grabbing input grabbed both the keyboard and the mouse.
66 * Many game management keys assume a keyboard grab.
67 * Tell SDL2 to grab the keyboard.
68 *
69 * Unlike with SDL1, players have the option of overriding this grab
70 * by setting an environment variable. In SDL1, the only choice was
71 * to skip both the keyboard grab and the mouse grab. Now, players
72 * can enable grabbing in the UI, but disable keyboard grab with the
73 * environment variable.
74 */
75 SDL_SetHint(SDL_HINT_GRAB_KEYBOARD, "1");
76 /* Gameplay continues regardless of focus, so keep the window
77 * visible.
78 */
79 SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0");
80 /* Support the Alt+Shift+F4 hotkey for renaming the Guide-Bot
81 */
82 SDL_SetHint(SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4, "1");
83 #endif
84
85 key_init();
86
87 digi_select_system();
88
89 if (!CGameArg.SndNoSound)
90 digi_init();
91
92 if (!CGameArg.CtlNoMouse)
93 mouse_init();
94
95 if (!CGameArg.CtlNoJoystick)
96 joy_init();
97
98 if ((t = gr_init()) != 0)
99 Error(TXT_CANT_INIT_GFX,t);
100
101 return {};
102 }
103
104 }