84 {
85 constexpr uint16_t MIX_DEFAULT_CHUNKSIZE = 4096;
86
87 std::set_terminate([]() -> void {
88 std::function<void(char const*)> log;
89 std::exception_ptr exception_ptr;
90
91 log = [](char const* message) -> void {
92 engine::log(message, LOG_LEVEL_CRITICAL);
93 if ((bool)SDL_ShowSimpleMessageBox(
94 SDL_MESSAGEBOX_ERROR,
95 (bool)window::base() ? SDL_GetWindowTitle(window::base())
96 : "Wizard Engine",
97 message, nullptr)) {
98 engine::log(SDL_GetError(), LOG_LEVEL_CRITICAL);
99 }
100 };
101
102 exception_ptr = std::current_exception();
103 if (exception_ptr) {
104 try {
105 std::rethrow_exception(exception_ptr);
106 } catch (std::exception const& exception) {
107 log(exception.what());
108 } catch (...) {
109 log("Unknown exception");
110 }
111 } else {
112 log("Unknown error");
113 }
114
115 abort();
116 });
117
118#ifdef __ANDROID__
119 if (!(bool)SDL_SetHint(SDL_HINT_ORIENTATIONS, "LandscapeLeft")) {
120 throw exception(SDL_GetError());
121 }
122#endif
123 if ((bool)SDL_Init(SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO |
124 SDL_INIT_EVENTS | SDL_INIT_JOYSTICK |
125 SDL_INIT_GAMECONTROLLER | SDL_INIT_SENSOR)) {
126 throw exception(SDL_GetError());
127 }
128#ifndef __EMSCRIPTEN__
129 if (IMG_Init(IMG_INIT_JPG | IMG_INIT_PNG) !=
130 (IMG_INIT_JPG | IMG_INIT_PNG)) {
131 throw exception(IMG_GetError());
132 }
133#endif
134 if ((Mix_Init(MIX_INIT_OGG) != MIX_INIT_OGG) ||
135 (bool)Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT,
136 MIX_DEFAULT_CHANNELS, MIX_DEFAULT_CHUNKSIZE)) {
137 throw exception(Mix_GetError());
138 }
139 if ((bool)TTF_Init()) {
140 throw exception(TTF_GetError());
141 }
142 if ((bool)SDLNet_Init()) {
143 throw exception(SDLNet_GetError());
144 }
145
146 _events = {};
147 window::initialize(title, width, height);
148 camera::initialize();
149 renderer::initialize();
150 input::initialize();
151 play_intro();
152}