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
@@ -9,7 +9,6 @@ rse_graphics_sources = [
'src/vulkan_base.c',
'src/vulkan_buffers.c',
'src/vulkan_commands.c',
'src/vulkan_commons.c',
'src/vulkan_image.c',
'src/vulkan_render_pass.c',
'src/vulkan_swapchain.c',
+5 -1
View File
@@ -18,13 +18,17 @@ rse_err_t rse_graphics_init(struct graphics_context_t* context);
*
* @return rse_err_t RSE_ERROR_NO_ERROR on success
*/
rse_err_t rse_graphics_main_loop(struct graphics_context_t* context);
rse_err_t rse_graphics_run(struct graphics_context_t* context);
rse_err_t rse_graphics_main_loop(struct graphics_context_t* context);
/**
* @brief Custom function for testing engine. TODO: Remove it whe releasing
*
*/
rse_err_t rse_graphics_test_function(struct graphics_context_t* context);
void rse_graphics_deinit(struct graphics_context_t* context);
#endif /* RSE_GRAPHICS_H */
+15 -4
View File
@@ -245,17 +245,28 @@ rse_err_t rse_graphics_test_function(struct graphics_context_t* context)
return RSE_ERROR_NO_ERROR;
}
rse_err_t rse_graphics_main_loop(struct graphics_context_t* context)
rse_err_t rse_graphics_run(struct graphics_context_t* context)
{
rse_err_t status = RSE_ERROR_NO_ERROR;
STATUS_CHECK(vulkan_run(context));
STATUS_CHECK(window_loop(context));
return status;
}
rse_err_t rse_graphics_main_loop(struct graphics_context_t* context)
{
rse_err_t status = RSE_ERROR_NO_ERROR;
STATUS_CHECK(vulkan_draw_frame(context));
return status;
}
void rse_graphics_deinit(struct graphics_context_t* context)
{
vulkan_deinit(context);
window_terminate(context->window_handle);
rse_free(context->debug_overlay.pixels);
return status;
}
+2 -5
View File
@@ -559,12 +559,10 @@ rse_err_t vulkan_run(struct graphics_context_t* context)
STATUS_CHECK(create_sync_objects(context));
init_time();
return status;
}
rse_err_t draw_frame(struct graphics_context_t* context)
rse_err_t vulkan_draw_frame(struct graphics_context_t* context)
{
rse_err_t status = RSE_ERROR_NO_ERROR;
uint32_t image_index = 0U;
@@ -580,8 +578,6 @@ rse_err_t draw_frame(struct graphics_context_t* context)
STATUS_CHECK(buffers_update(context));
update_time();
result = vkAcquireNextImageKHR(context->vulkan_handles.device, context->swapchain_data.swapchain, UINT64_MAX, context->vulkan_handles.image_available_semaphores[context->current_frame],
VK_NULL_HANDLE, &image_index);
@@ -649,6 +645,7 @@ rse_err_t draw_frame(struct graphics_context_t* context)
void vulkan_deinit(struct graphics_context_t* context)
{
vkDeviceWaitIdle(context->vulkan_handles.device);
destroy_buffers(context);
for (size_t i = 0; i < SWAP_BUFFER_COUNT; ++i) {
vkDestroySemaphore(context->vulkan_handles.device, context->vulkan_handles.image_available_semaphores[i], NULL);
+1 -1
View File
@@ -46,6 +46,6 @@ void vulkan_deinit(struct graphics_context_t* context);
* @param context Graphics context
* @return rse_err_t
*/
rse_err_t draw_frame(struct graphics_context_t* context);
rse_err_t vulkan_draw_frame(struct graphics_context_t* context);
#endif /* GRAPHICS_VULKANBASE_H */
-24
View File
@@ -1,24 +0,0 @@
#include "vulkan_commons.h"
#include <time.h>
time_t g_last_frame_time;
time_t g_this_frame_time;
float g_float_delta_time;
void init_time(void)
{
time(&g_last_frame_time);
}
void update_time(void)
{
g_last_frame_time = g_this_frame_time;
time(&g_this_frame_time);
g_float_delta_time = (float)difftime(g_this_frame_time, g_last_frame_time);
}
float get_time_diff(void)
{
return g_float_delta_time;
}
-4
View File
@@ -58,8 +58,4 @@ struct instance_data_t {
alignas(4) uint32_t texture_id;
};
void init_time(void);
void update_time(void);
float get_time_diff(void);
#endif /* VULKAN_GLOBAL_H */
-48
View File
@@ -21,29 +21,9 @@
#include "SDL3/SDL_log.h"
#include "utilities/commons.h"
#include "utilities/errors_common.h"
#include "utilities/time_utils.h"
#include "vulkan/vulkan_core.h"
#include "vulkan_base.h"
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 window_init(SDL_Window** window_handle, bool* is_framebuffer_resized)
{
SDL_Init(SDL_INIT_VIDEO); // TODO: Move to initial phase of RSE initialization
(void)is_framebuffer_resized;
// TODO: Actually use this parameter?
@@ -57,34 +37,6 @@ rse_err_t window_init(SDL_Window** window_handle, bool* is_framebuffer_resized)
return RSE_ERROR_NO_ERROR;
}
rse_err_t window_loop(struct graphics_context_t* context)
{
uint8_t done = 0;
SDL_Event event;
double start_time;
start_time = time_get_sec_from_start();
while (0 == done) {
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_EVENT_QUIT:
done = 1;
break;
case SDL_EVENT_MOUSE_BUTTON_DOWN:
break;
}
}
time_update();
draw_frame(context);
fps_print(&start_time);
}
vkDeviceWaitIdle(context->vulkan_handles.device);
return RSE_ERROR_NO_ERROR;
}
void window_terminate(SDL_Window* window_handle)
{
SDL_DestroyWindow(window_handle);
-8
View File
@@ -32,14 +32,6 @@
*/
rse_err_t window_init(SDL_Window **window_handle, bool *is_framebuffer_resized);
/**
* @brief Main window loop
*
* @param context Graphics context
* @return rse_err_t WINDOW_SUCCESS or error code
*/
rse_err_t window_loop(struct graphics_context_t* context);
/**
* @brief Closes window and terminates GLFW
*