23#define __WIZARD_ENGINE_INTERNAL__
37std::vector<SDL_Event> wze::engine::_events = {};
39void wze::engine::play_intro() {
41 static_assert(
sizeof(size_t) == 4 ||
sizeof(size_t) == 8);
42 constexpr size_t logo_hash =
43 sizeof(size_t) == 4 ? 291788640 : 14466144734576808089U;
44 constexpr float scale = .6;
45 constexpr float speed = .1;
47 std::shared_ptr<image> logo;
52 logo = assets::load_image(
"./wizard_engine/logo.png");
53 if (assets::hash_image(logo) != logo_hash) {
54 throw exception(
"Invalid ./wizard_engine/logo.png");
57 size = (float)std::min(window::width(), window::height()) * scale;
58 intro = sprite(0, 0, 0, 0, size, size,
false, assets::create_texture(logo));
61 while (opacity <= std::numeric_limits<uint8_t>::max()) {
62 intro.set_color_a((uint8_t)opacity);
69 opacity = std::numeric_limits<uint8_t>::max();
70 while (0 <= opacity) {
71 intro.set_color_a((uint8_t)opacity);
79std::vector<SDL_Event>
const& wze::engine::events() {
83void wze::engine::initialize(std::string
const& title, uint16_t width,
85 constexpr uint16_t MIX_DEFAULT_CHUNKSIZE = 4096;
87 std::set_terminate([]() ->
void {
88 std::function<void(
char const*)> log;
89 std::exception_ptr exception_ptr;
91 log = [](
char const* message) ->
void {
92 engine::log(message, LOG_LEVEL_CRITICAL);
93 if ((
bool)SDL_ShowSimpleMessageBox(
95 (
bool)window::base() ? SDL_GetWindowTitle(window::base())
98 engine::log(SDL_GetError(), LOG_LEVEL_CRITICAL);
102 exception_ptr = std::current_exception();
105 std::rethrow_exception(exception_ptr);
106 }
catch (std::exception
const& exception) {
107 log(exception.what());
109 log(
"Unknown exception");
112 log(
"Unknown error");
119 if (!(
bool)SDL_SetHint(SDL_HINT_ORIENTATIONS,
"LandscapeLeft")) {
120 throw exception(SDL_GetError());
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());
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());
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());
139 if ((
bool)TTF_Init()) {
140 throw exception(TTF_GetError());
142 if ((
bool)SDLNet_Init()) {
143 throw exception(SDLNet_GetError());
147 window::initialize(title, width, height);
148 camera::initialize();
149 renderer::initialize();
154bool wze::engine::update() {
162 while ((
bool)SDL_PollEvent(&event)) {
163 if (event.type == SDL_QUIT) {
166 _events.push_back(event);
176 SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, (SDL_LogPriority)
log_level,
Image file in host memory.
Subsystem to handle global audio.
Subsystem to handle transformations and spatial projections.
static float delta_time()
Gets the current delta time in milliseconds.
Master singleton of the Wizard Engine.
Subsystem to handle graphics.
Renderable animatable component.
Subsystem to handle game window.