4#include <SDL3_mixer/SDL_mixer.h>
5#include <SDL3_ttf/SDL_ttf.h>
10#include <emscripten.h>
34 const uint64_t now = SDL_GetTicksNS();
45 while (SDL_PollEvent(&e)) {
47 case SDL_EVENT_WINDOW_RESIZED: {
55 SDL_Point window_size;
61 if (render_size.x <= 0 || render_size.y <= 0 || window_size.x <= 0
62 || window_size.y <= 0) {
67 =
static_cast<float>(window_size.x) /
static_cast<float>(render_size.x);
70 =
static_cast<float>(window_size.y) /
static_cast<float>(render_size.y);
72 const auto scale = std::min(x_scale, y_scale);
75 static_cast<int>(
static_cast<float>(render_size.x) * scale),
76 static_cast<int>(
static_cast<float>(render_size.y) * scale));
80 case SDL_EVENT_KEY_DOWN: {
85 case SDL_EVENT_KEY_UP: {
92 case SDL_EVENT_MOUSE_BUTTON_DOWN: {
97 case SDL_EVENT_MOUSE_BUTTON_UP: {
102 case SDL_EVENT_MOUSE_MOTION: {
106 SDL_ConvertEventToRenderCoordinates(r, &e);
113 case SDL_EVENT_MOUSE_WHEEL: {
118 case SDL_EVENT_GAMEPAD_AXIS_MOTION: {
123 case SDL_EVENT_GAMEPAD_BUTTON_DOWN: {
128 case SDL_EVENT_GAMEPAD_BUTTON_UP: {
133 case SDL_EVENT_GAMEPAD_ADDED: {
138 case SDL_EVENT_GAMEPAD_REMOVED: {
143 case SDL_EVENT_TEXT_INPUT: {
148 case SDL_EVENT_QUIT: {
170 if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD)) {
189 if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD)) {
204 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
205 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
206 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
207 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
217 const char* renderer_name =
"none";
219 renderer_name = SDL_GetRendererName(r);
223 "SDL Version: {}.{}.{}", SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_MICRO_VERSION);
262 static std::function<void()> run_frame;
265 emscripten_set_main_loop(
268 emscripten_cancel_main_loop();
Action binding system for the ASW library.
Asset routines for the ASW library.
Settings from a config file, set by whoever runs the game.
Core routines including main loop and initialization.
Display and window routines for the ASW library.
Structured logging system.
constexpr float MAX_DELTA_TIME
void clear_all()
Clear all cached assets. This will remove all cached textures, fonts, samples, and music.
void _shutdown()
Remove all settings. Called by asw::core::shutdown().
void _init()
Load the file named by ASW_CONFIG, if it is set. Called by asw::core::init() before the window opens.
void exit()
Exit the application. Sets exiting flag to true, which will cause the main loop to exit on the next u...
void print_info()
Prints information about the core module.
void init_opengl(int width, int height, int scale=1)
Initializes the core module for opengl.
void run(const std::function< void()> &frame)
Run a main loop until exit() is called.
void shutdown()
Cleanup resources used by the core module. Should be called on application exit.
void init(int width, int height, int scale=1)
Initializes the core module.
void update()
Updates core module functionality.
float get_delta_time()
Get the time between the last two calls to update(). Capped at a quarter of a second,...
bool is_exiting()
Return exiting status.
asw::Vec2< int > get_logical_size()
Get the logical size of the window. This may differ from the actual size if scaling is enabled.
void _init_opengl(int width, int height, int scale)
Initialize the display module with OpenGL support. Called by asw::core::init().
void _shutdown()
Shut down the display module. Called by asw::core::shutdown(). Nulls the renderer and window pointers...
asw::Renderer * get_renderer()
Get the SDL renderer.
asw::Window * get_window()
Get the SDL window.
void _init(int width, int height, int scale)
Initialize the display module. Called by asw::core::init().
void info(const std::string &message)
Log an info message.
void _shutdown()
Shut down the sound module. Called automatically by asw::core::shutdown().
bool _init()
Initialize the sound module. Called automatically by asw::core::init().
void _update()
Update fades, ducking and positional sounds. Called automatically by asw::core::update().
void abort_on_error(const std::string &message)
Abort program and display error message.
Sound module for the ASW library.
General utility functions.