Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | pmbaty | 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 | #endif |
||
| 81 | |||
| 82 | key_init(); |
||
| 83 | |||
| 84 | digi_select_system(); |
||
| 85 | |||
| 86 | if (!CGameArg.SndNoSound) |
||
| 87 | digi_init(); |
||
| 88 | |||
| 89 | if (!CGameArg.CtlNoMouse) |
||
| 90 | mouse_init(); |
||
| 91 | |||
| 92 | if (!CGameArg.CtlNoJoystick) |
||
| 93 | joy_init(); |
||
| 94 | |||
| 95 | if ((t = gr_init()) != 0) |
||
| 96 | Error(TXT_CANT_INIT_GFX,t); |
||
| 97 | |||
| 98 | return {}; |
||
| 99 | } |
||
| 100 | |||
| 101 | } |