Implement event handler

Added event handler implementation.
Moved enginge specific implementation outside graphics module

Signed-off-by: Piotr Krygier <piotrkrygier@everyonecancode@xyz>
This commit is contained in:
Piotr Krygier
2026-03-04 11:04:53 +01:00
parent bbbe69d73c
commit c6825caa69
18 changed files with 143 additions and 152 deletions
+1
View File
@@ -1,4 +1,5 @@
#include "red_scarf_engine.h"
#include "utilities/errors_common.h"
int main(int argc, char** argv)
{
+34 -3
View File
@@ -1,14 +1,30 @@
#include "red_scarf_engine.h"
#include "graphics/rse_graphics.h"
#include "graphics/src/graphics_context.h"
#include "utilities/commons.h"
#include "utilities/errors_common.h"
#include "utilities/time_utils.h"
#include "events/rse_events_manager.h"
struct rse_context_t {
struct graphics_context_t graphics_context;
struct events_context_t events_context;
};
static void fps_print(double* start_time)
{
static uint32_t frame_counts = 0U;
double now = time_get_sec_from_start();
frame_counts++;
if ((now - *start_time) > 1.0) {
printf("\rFPS: %u", frame_counts);
fflush(stdout);
frame_counts = 0;
*start_time += 1.0;
}
}
rse_err_t rse_init(rse_context* context)
{
rse_err_t status = RSE_ERROR_NO_ERROR;
@@ -18,10 +34,12 @@ rse_err_t rse_init(rse_context* context)
rse_context = *context;
SDL_Init(SDL_INIT_VIDEO);
SDL_SetLogPriorities(SDL_LOG_PRIORITY_VERBOSE);
STATUS_CHECK(time_init());
rse_graphics_init(&(rse_context->graphics_context));
STATUS_CHECK(rse_events_init(&rse_context->events_context));
STATUS_CHECK(rse_graphics_init(&rse_context->graphics_context));
return RSE_ERROR_NO_ERROR;
}
@@ -29,11 +47,24 @@ rse_err_t rse_init(rse_context* context)
rse_err_t rse_run(rse_context context)
{
rse_err_t status = RSE_ERROR_NO_ERROR;
double start_time;
start_time = time_get_sec_from_start();
STATUS_CHECK(rse_graphics_test_function(&context->graphics_context));
STATUS_CHECK(rse_graphics_main_loop(&context->graphics_context));
STATUS_CHECK(rse_graphics_run(&context->graphics_context));
while(true) {
time_update();
rse_events_main_loop(&context->events_context);
if (context->events_context.should_stop == EVENT_SHOULD_STOP_ENGINE_TRUE) {
break;
}
rse_graphics_main_loop(&context->graphics_context);
fps_print(&start_time);
}
rse_graphics_deinit(&context->graphics_context);
rse_free(context);
return status;