Prepare for event system

Moved stuff around.
Create an entry point for RSE.
Created base for events module

Signed-off-by: Piotr Krygier <piotrkrygier@everyonecancode@xyz>
This commit is contained in:
Piotr Krygier
2026-03-03 11:26:43 +01:00
parent 7d6156be01
commit bbbe69d73c
13 changed files with 245 additions and 53 deletions
+4 -5
View File
@@ -1,10 +1,9 @@
#ifndef RSE_GRAPHICS_H
#define RSE_GRAPHICS_H
#include "src/graphics_context.h"
#include "utilities/commons.h"
struct rse_graphics_context_t;
/**
* @brief Initializes graphics backend. This has to be called before any new mesh, texture or any other object is
* added
@@ -12,20 +11,20 @@ struct rse_graphics_context_t;
* @param context Graphics context handle. Must be NULL!
* @return rse_err_t RSE_ERROR_NO_ERROR on success
*/
rse_err_t rse_graphics_init(struct rse_graphics_context_t** context);
rse_err_t rse_graphics_init(struct graphics_context_t* context);
/**
* @brief Runs graphics engine. This has to be called after all objects are added to the scene
*
* @return rse_err_t RSE_ERROR_NO_ERROR on success
*/
int rse_graphics_run(void* arg);
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 rse_graphics_context_t* context);
rse_err_t rse_graphics_test_function(struct graphics_context_t* context);
#endif /* RSE_GRAPHICS_H */
+5 -21
View File
@@ -106,32 +106,20 @@ static rse_err_t render_static_mesh(struct graphics_context_t* context, uint32_t
return RSE_ERROR_NO_ERROR;
}
rse_err_t rse_graphics_init(struct rse_graphics_context_t** context)
rse_err_t rse_graphics_init(struct graphics_context_t* context)
{
rse_err_t status = RSE_ERROR_NO_ERROR;
struct rse_graphics_context_t* ctx_ptr = NULL;
if (*context != NULL) {
SDL_LogCritical(SDL_LOG_CATEGORY_GPU, "Graphics already initialized!");
return RSE_ERROR_ALREADY_INITIALIZED;
}
rse_malloc(*context, sizeof(struct rse_graphics_context_t));
ctx_ptr = *context;
rse_malloc(ctx_ptr->context, sizeof(struct graphics_context_t));
rse_memset(ctx_ptr->context, 0, sizeof(struct graphics_context_t));
STATUS_CHECK(window_init(&ctx_ptr->context->window_handle, &ctx_ptr->context->is_framebuffer_resized));
STATUS_CHECK(vulkan_init(ctx_ptr->context));
STATUS_CHECK(window_init(&context->window_handle, &context->is_framebuffer_resized));
STATUS_CHECK(vulkan_init(context));
return status;
}
#define TEXTURES_COUNT (2U)
rse_err_t rse_graphics_test_function(struct rse_graphics_context_t* rse_context)
rse_err_t rse_graphics_test_function(struct graphics_context_t* context)
{
rse_err_t status = RSE_ERROR_NO_ERROR;
struct graphics_context_t* context = rse_context->context;
rse_id_t textures[TEXTURES_COUNT] = {0};
struct pipeline_t pipeline;
rse_id_t descriptor_set_handle = 0;
@@ -257,11 +245,9 @@ rse_err_t rse_graphics_test_function(struct rse_graphics_context_t* rse_context)
return RSE_ERROR_NO_ERROR;
}
int rse_graphics_run(void* arg)
rse_err_t rse_graphics_main_loop(struct graphics_context_t* context)
{
rse_err_t status = RSE_ERROR_NO_ERROR;
struct rse_graphics_context_t* rse_context = (struct rse_graphics_context_t*)arg;
struct graphics_context_t* context = rse_context->context;
STATUS_CHECK(vulkan_run(context));
STATUS_CHECK(window_loop(context));
@@ -270,8 +256,6 @@ int rse_graphics_run(void* arg)
window_terminate(context->window_handle);
rse_free(context->debug_overlay.pixels);
rse_free(context);
rse_free(rse_context);
return status;
}
+9 -3
View File
@@ -18,6 +18,7 @@
#include <stdint.h>
#include <stdio.h>
#include "SDL3/SDL_log.h"
#include "utilities/commons.h"
#include "utilities/errors_common.h"
#include "utilities/time_utils.h"
@@ -43,7 +44,8 @@ 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?
(void)is_framebuffer_resized;
// TODO: Actually use this parameter?
*window_handle = SDL_CreateWindow("RedScarfEngine", 1024, 768, SDL_WINDOW_VULKAN);
@@ -65,8 +67,12 @@ rse_err_t window_loop(struct graphics_context_t* context)
while (0 == done) {
while (SDL_PollEvent(&event)) {
if (SDL_EVENT_QUIT == event.type) {
done = 1;
switch (event.type) {
case SDL_EVENT_QUIT:
done = 1;
break;
case SDL_EVENT_MOUSE_BUTTON_DOWN:
break;
}
}