Skip to content

Commit

Permalink
Added ska sdl file to simplify sdl event loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chukobyte committed Nov 2, 2024
1 parent a108a3c commit 7968f3e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 28 deletions.
42 changes: 42 additions & 0 deletions seika/ska_sdl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "ska_sdl.h"

#include <SDL3/SDL.h>

#if SKA_INPUT
#include "input/sdl_input.h"
#endif

#if SKA_RENDERING
#include "rendering/renderer.h"
#endif

bool ska_sdl_update() {
bool shouldQuit = false;
SDL_Event event;
while (SDL_PollEvent(&event)) {
switch(event.type) {
case SDL_EVENT_QUIT: {
shouldQuit = true;
break;
}
case SDL_EVENT_WINDOW_RESIZED: {
#if SKA_RENDERING
const Sint32 windowWidth = event.window.data1;
const Sint32 windowHeight = event.window.data2;
ska_renderer_update_window_size(windowWidth, windowHeight);
#endif
break;
}
default: {
#if SKA_INPUT
ska_sdl_process_event(event);
#endif
break;
}
}
}
#if SKA_INPUT
ska_sdl_process_axis_events();
#endif
return shouldQuit;
}
5 changes: 5 additions & 0 deletions seika/ska_sdl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include "seika/defines.h"

bool ska_sdl_update();
2 changes: 1 addition & 1 deletion seika/version_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

#define SKA_VERSION_MAJOR 0
#define SKA_VERSION_MINOR 2
#define SKA_VERSION_PATCH 0
#define SKA_VERSION_PATCH 1

#define SKA_VERSION (SKA_MACRO_TO_STRING(SKA_VERSION_MAJOR) "." SKA_MACRO_TO_STRING(SKA_VERSION_MINOR) "." SKA_MACRO_TO_STRING(SKA_VERSION_PATCH))
31 changes: 4 additions & 27 deletions test/game/src/main.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#include <stdlib.h>

#include <SDL3/SDL.h>

#include <seika/time.h>
#include <seika/ska_sdl.h>
#include <seika/math/math.h>
#include <seika/rendering/window.h>
#include <seika/input/input.h>
#include <seika/input/sdl_input.h>
#include <seika/rendering/renderer.h>

static void game_initialize() {
Expand All @@ -28,34 +27,12 @@ static void game_finalize() {
static void game_run() {
while (true) {
ska_input_new_frame();

bool shouldQuit = false;
SDL_Event event;
while (SDL_PollEvent(&event)) {
switch(event.type) {
case SDL_EVENT_QUIT: {
shouldQuit = true;
break;
}
case SDL_EVENT_WINDOW_RESIZED: {
const Sint32 windowWidth = event.window.data1;
const Sint32 windowHeight = event.window.data2;
ska_renderer_update_window_size(windowWidth, windowHeight);
break;
}
default: {
ska_sdl_process_event(event);
break;
}
}
}
ska_sdl_process_axis_events();

const bool shouldQuit = ska_sdl_update();
if (shouldQuit || ska_input_is_key_just_pressed(SkaInputKey_KEYBOARD_ESCAPE, 0)) {
break;
}
ska_window_render(&(SkaColor){ 0.2f, 0.2f, 0.2f, 1.0f });
SDL_Delay(10);
ska_delay(10);
}
}

Expand Down

0 comments on commit 7968f3e

Please sign in to comment.