Wizard Engine
2D cross-platform game engine built around SDL2
 
Loading...
Searching...
No Matches
wze::engine Class Referencefinal

Static Public Member Functions

static void initialize (std::string const &title, uint16_t width, uint16_t height)
 
static bool update ()
 
static void log (char const *message, log_level log_level=LOG_LEVEL_INFO)
 
static void log (std::string const &message, log_level log_level=LOG_LEVEL_INFO)
 

Detailed Description

Definition at line 34 of file engine.hpp.

Member Function Documentation

◆ initialize()

void wze::engine::initialize ( std::string const & title,
uint16_t width,
uint16_t height )
static

Definition at line 83 of file engine.cpp.

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 /* __ANDROID__ */
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 /* __EMSCRIPTEN__ */
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}

◆ update()

bool wze::engine::update ( )
staticnodiscard

Definition at line 154 of file engine.cpp.

154 {
155 SDL_Event event;
156
157 renderer::update();
158 audio::update();
159 timer::update();
160
161 _events.clear();
162 while ((bool)SDL_PollEvent(&event)) {
163 if (event.type == SDL_QUIT) {
164 return false;
165 }
166 _events.push_back(event);
167 }
168
169 input::update();
170
171 return true;
172}

◆ log() [1/2]

void wze::engine::log ( char const * message,
log_level log_level = LOG_LEVEL_INFO )
static

Definition at line 174 of file engine.cpp.

174 {
175 // NOLINTNEXTLINE(hicpp-vararg,cppcoreguidelines-pro-type-vararg)
176 SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, (SDL_LogPriority)log_level,
177 "%s", message);
178}
log_level
Log levels.
Definition enums.hpp:337

◆ log() [2/2]

void wze::engine::log ( std::string const & message,
log_level log_level = LOG_LEVEL_INFO )
static

Definition at line 180 of file engine.cpp.

180 {
181 log(message.c_str(), log_level);
182}

The documentation for this class was generated from the following files: