Refactoring

Cleaned up a project, removed uneccessary includes.
Fixed few errors, nothing major.
This commit is contained in:
Piotr Krygier committed 2025-06-20 13:44:33 +02:00
1 parent 42dc4d6fcd
commit 1f585b4d8e
20 files changed
+39 -71

No files matched your search

+5 -1
View File
@@ -39,4 +39,8 @@ bin/*
.vscode/ .vscode/
# Third party libraires # Third party libraires
third_party/ third_party/
# Cache folder
.cache/
+2 -24
View File
@@ -4,34 +4,12 @@ project("RedScarfEngine"
DESCRIPTION "Vulkan based 3D engine" DESCRIPTION "Vulkan based 3D engine"
LANGUAGES C CXX) LANGUAGES C CXX)
set(CMAKE_C_STANDARD 23)
# make sure c++ 20 is set
set(CMAKE_CXX_STANDARD 20)# turn on the dynamic depends for ninja
set(CMAKE_C_STANDARD 23)# turn on the dynamic depends for ninja
# set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1)
# Enable C++ modules
# set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "3c375311-a3c9-4396-a187-3227ef642046")
# if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# include(gcc_modules.cmake)
# endif()
# string(CONCAT CMAKE_EXPERIMENTAL_CXX_SCANDEP_SOURCE
# "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> <SOURCE>"
# " -MT <DYNDEP_FILE> -MD -MF <DEP_FILE>"
# " ${flags_to_scan_deps} -fdep-file=<DYNDEP_FILE> -fdep-output=<OBJECT>"
# )
# set(CMAKE_EXPERIMENTAL_CXX_MODULE_MAP_FORMAT "gcc")
# set(CMAKE_EXPERIMENTAL_CXX_MODULE_MAP_FLAG
# "${compiler_flags_for_module_map} -fmodule-mapper=<MODULE_MAP_FILE>")
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror")
add_subdirectory(red_scarf_engine) add_subdirectory(red_scarf_engine)
add_subdirectory(utilities) add_subdirectory(utilities)
add_subdirectory(graphics) add_subdirectory(graphics)
add_subdirectory(tests) add_subdirectory(tests)
+2 -1
View File
@@ -1 +1,2 @@
# Red Scarf Engine # Red Scarf Engine
+1 -1
View File
@@ -34,7 +34,7 @@ rse_err_t rse_graphics_init(void)
void rse_graphics_test_function(void) void rse_graphics_test_function(void)
{ {
rse_err_t status = RSE_ERROR_NO_ERROR; rse_err_t status = RSE_ERROR_NO_ERROR;
uint8_t tex_id_2 = 0; uint16_t tex_id_2 = 0;
status = rse_load_texture("../../test_image.png", &tex_id_2); status = rse_load_texture("../../test_image.png", &tex_id_2);
if (status != RSE_ERROR_NO_ERROR) { if (status != RSE_ERROR_NO_ERROR) {
+2 -1
View File
@@ -1,5 +1,6 @@
#include "rse_vulkan_commands.h" #include "rse_vulkan_commands.h"
#include "vulkan_commons.h"
#include "vulkan_errors.h" #include "vulkan_errors.h"
#include "locale_vulkan.h" #include "locale_vulkan.h"
#include "utilities/logger.h" #include "utilities/logger.h"
@@ -113,4 +114,4 @@ rse_err_t init_commands()
void destroy_commands() void destroy_commands()
{ {
vkDestroyCommandPool(g_vulkan_state.device, g_command_pool, NULL); vkDestroyCommandPool(g_vulkan_state.device, g_command_pool, NULL);
} }
+1 -2
View File
@@ -12,7 +12,6 @@
#ifndef RSE_VULKAN_COMMANDS_H #ifndef RSE_VULKAN_COMMANDS_H
#define RSE_VULKAN_COMMANDS_H #define RSE_VULKAN_COMMANDS_H
#include "vulkan_commons.h"
#include "vk_mem_alloc.h" #include "vk_mem_alloc.h"
#include "utilities/rse_commons.h" #include "utilities/rse_commons.h"
@@ -43,4 +42,4 @@ VkCommandBuffer rse_begin_single_time_command();
*/ */
void rse_end_single_time_comands(VkCommandBuffer command_buffer); void rse_end_single_time_comands(VkCommandBuffer command_buffer);
#endif /* RSE_VULKAN_COMMANDS_H */ #endif /* RSE_VULKAN_COMMANDS_H */
+5 -5
View File
@@ -15,7 +15,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <math.h>
#define IMAGE_TAKEN 1U #define IMAGE_TAKEN 1U
#define IMAGE_FREE 0U #define IMAGE_FREE 0U
@@ -208,7 +207,7 @@ static rse_err_t create_vulkan_image(uint32_t width,
uint32_t height, uint32_t height,
VkFormat format, VkFormat format,
unsigned char* pixels, unsigned char* pixels,
uint8_t* texture_id) uint16_t* texture_id)
{ {
rse_err_t status = RSE_ERROR_NO_ERROR; rse_err_t status = RSE_ERROR_NO_ERROR;
struct rse_vulkan_buffer_t staging_buffer = {0}; struct rse_vulkan_buffer_t staging_buffer = {0};
@@ -222,9 +221,10 @@ static rse_err_t create_vulkan_image(uint32_t width,
VkExtent3D image_extent = {0}; VkExtent3D image_extent = {0};
VkImageViewCreateInfo image_view_create_info = {0}; VkImageViewCreateInfo image_view_create_info = {0};
struct rse_vulkan_image_t* free_texture_image = NULL; struct rse_vulkan_image_t* free_texture_image = NULL;
*texture_id = 0U; *texture_id = 0U;
while(free_texture_image == NULL || *texture_id > RSE_MAX_IMAGE_COUNT) { while(free_texture_image == NULL && *texture_id < RSE_MAX_IMAGE_COUNT) {
if(g_texture_images[*texture_id].id_taken == IMAGE_FREE) { if(g_texture_images[*texture_id].id_taken == IMAGE_FREE) {
free_texture_image = &g_texture_images[*texture_id]; free_texture_image = &g_texture_images[*texture_id];
} else { } else {
@@ -399,7 +399,7 @@ rse_err_t init_vulkan_images()
return status; return status;
} }
rse_err_t rse_load_texture(const char* file_path, uint8_t* texture_id) rse_err_t rse_load_texture(const char* file_path, uint16_t* texture_id)
{ {
rse_err_t status = RSE_ERROR_NO_ERROR; rse_err_t status = RSE_ERROR_NO_ERROR;
int width = 0; int width = 0;
@@ -493,4 +493,4 @@ rse_err_t find_depth_format(VkFormat* found_format)
return status; return status;
#undef formats_count #undef formats_count
} }
+4 -3
View File
@@ -15,7 +15,8 @@
#include "utilities/file_utils.h" #include "utilities/file_utils.h"
#include "utilities/rse_commons.h" #include "utilities/rse_commons.h"
#include "vulkan_commons.h"
#include "vulkan/vulkan_core.h"
#include <stdint.h> #include <stdint.h>
@@ -39,7 +40,7 @@ rse_err_t init_vulkan_images(void);
* @param texture_id Texture ID will be set up here * @param texture_id Texture ID will be set up here
* @return rse_err_t RSE_ERROR_NO_ERROR on success * @return rse_err_t RSE_ERROR_NO_ERROR on success
*/ */
rse_err_t rse_load_texture(const char* file_path, uint8_t* texture_id); rse_err_t rse_load_texture(const char* file_path, uint16_t* texture_id);
/** /**
* @brief Destroy all loaded textures. Usefull for closing application or just clearing. * @brief Destroy all loaded textures. Usefull for closing application or just clearing.
@@ -81,4 +82,4 @@ rse_err_t find_depth_format(VkFormat* found_format);
VkImageView rse_get_depth_image_view(); VkImageView rse_get_depth_image_view();
#endif /* RSE_TEXTURE_H */ #endif /* RSE_TEXTURE_H */
+3 -4
View File
@@ -27,7 +27,6 @@
// #pragma GCC diagnostic pop // #pragma GCC diagnostic pop
#include "locale_vulkan.h" #include "locale_vulkan.h"
#include "utilities/locale_common.h"
#include "utilities/rse_errors_common.h" #include "utilities/rse_errors_common.h"
#include "utilities/logger.h" #include "utilities/logger.h"
#include "vulkan_errors.h" #include "vulkan_errors.h"
@@ -345,7 +344,7 @@ static rse_err_t pick_physical_device()
vkEnumeratePhysicalDevices(g_vulkan_instance, &physical_device_count, NULL); vkEnumeratePhysicalDevices(g_vulkan_instance, &physical_device_count, NULL);
if (0 == physical_device_count) { if (0 == physical_device_count) {
LOGF(vulkan_messages[VULKAN_ERROR_NO_PHYSICAL_DEVICE_FOUND]); LOGF(vulkan_messages[VULKAN_NO_PHYSICAL_DEVICES]);
return VULKAN_ERROR_NO_PHYSICAL_DEVICE_FOUND; return VULKAN_ERROR_NO_PHYSICAL_DEVICE_FOUND;
} }
@@ -527,7 +526,7 @@ static rse_err_t create_memory_allocator()
allocator_create_info.pVulkanFunctions = &vulkan_functions; allocator_create_info.pVulkanFunctions = &vulkan_functions;
if (VK_SUCCESS != vmaCreateAllocator(&allocator_create_info, &g_vulkan_state.allocator)) { if (VK_SUCCESS != vmaCreateAllocator(&allocator_create_info, &g_vulkan_state.allocator)) {
LOGF(vulkan_messages[VULKAN_ERROR_ALLOCATOR_CREATION_FAILED]); LOGF(vulkan_messages[VULKAN_ALLOCATOR_CREATION_FAILED]);
return VULKAN_ERROR_ALLOCATOR_CREATION_FAILED; return VULKAN_ERROR_ALLOCATOR_CREATION_FAILED;
} }
@@ -692,4 +691,4 @@ void deinit_vulkan()
#endif #endif
vkDestroySurfaceKHR(g_vulkan_instance, g_vulkan_state.surface, NULL); vkDestroySurfaceKHR(g_vulkan_instance, g_vulkan_state.surface, NULL);
vkDestroyInstance(g_vulkan_instance, NULL); vkDestroyInstance(g_vulkan_instance, NULL);
} }
+1 -4
View File
@@ -12,11 +12,8 @@
#ifndef RSE_GRAPHICS_VULKANBASE_H #ifndef RSE_GRAPHICS_VULKANBASE_H
#define RSE_GRAPHICS_VULKANBASE_H #define RSE_GRAPHICS_VULKANBASE_H
#include <stdint.h>
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "vulkan_commons.h"
#include "utilities/rse_commons.h" #include "utilities/rse_commons.h"
/** /**
@@ -46,4 +43,4 @@ void deinit_vulkan();
*/ */
rse_err_t draw_frame(); rse_err_t draw_frame();
#endif /* RSE_GRAPHICS_VULKANBASE_HPP */ #endif /* RSE_GRAPHICS_VULKANBASE_HPP */
+1 -2
View File
@@ -4,7 +4,6 @@
#include "locale_vulkan.h" #include "locale_vulkan.h"
#include "utilities/logger.h" #include "utilities/logger.h"
#include "utilities/rse_errors_common.h" #include "utilities/rse_errors_common.h"
#include "mesh_controller.h"
#include "rse_math.h" #include "rse_math.h"
#include "rse_vulkan_commands.h" #include "rse_vulkan_commands.h"
@@ -431,4 +430,4 @@ void destroy_buffers()
for(i = 0; i < MAX_MESH_NUMBER; ++i) { for(i = 0; i < MAX_MESH_NUMBER; ++i) {
vmaDestroyBuffer(g_vulkan_state.allocator, g_instance_buffers[i].buffer, g_instance_buffers[i].allocation); vmaDestroyBuffer(g_vulkan_state.allocator, g_instance_buffers[i].buffer, g_instance_buffers[i].allocation);
} }
} }
+1 -4
View File
@@ -7,9 +7,6 @@
#include "vulkan_commons.h" #include "vulkan_commons.h"
#include "rse_vulkan_image.h" #include "rse_vulkan_image.h"
#include "vulkan/vulkan.h"
VkDescriptorPool gDescriptorPool; VkDescriptorPool gDescriptorPool;
VkDescriptorPool gDescriptorPool_bindless; VkDescriptorPool gDescriptorPool_bindless;
@@ -155,4 +152,4 @@ void destroy_descriptors()
vkDestroyDescriptorPool(g_vulkan_state.device, gDescriptorPool_bindless, NULL); vkDestroyDescriptorPool(g_vulkan_state.device, gDescriptorPool_bindless, NULL);
vkDestroyDescriptorSetLayout(g_vulkan_state.device, g_vulkan_state.descriptor_set_layout, NULL); vkDestroyDescriptorSetLayout(g_vulkan_state.device, g_vulkan_state.descriptor_set_layout, NULL);
vkDestroyDescriptorSetLayout(g_vulkan_state.device, g_vulkan_state.descriptor_set_layout_bindless, NULL); vkDestroyDescriptorSetLayout(g_vulkan_state.device, g_vulkan_state.descriptor_set_layout_bindless, NULL);
} }
+1 -2
View File
@@ -1,7 +1,6 @@
#ifndef RSE_VULKAN_DESCRIPTORS_H #ifndef RSE_VULKAN_DESCRIPTORS_H
#define RSE_VULKAN_DESCRIPTORS_H #define RSE_VULKAN_DESCRIPTORS_H
#include <stdint.h>
#include "utilities/rse_commons.h" #include "utilities/rse_commons.h"
@@ -21,4 +20,4 @@ rse_err_t create_descriptors();
*/ */
void destroy_descriptors(); void destroy_descriptors();
#endif /* RSE_VULKAN_DESCRIPTORS_H */ #endif /* RSE_VULKAN_DESCRIPTORS_H */
+2 -4
View File
@@ -5,11 +5,9 @@
#include "utilities/logger.h" #include "utilities/logger.h"
#include "utilities/rse_errors_common.h" #include "utilities/rse_errors_common.h"
#include "vulkan_errors.h" #include "vulkan_errors.h"
#include "mesh_controller.h"
#include "rse_vulkan_image.h" #include "rse_vulkan_image.h"
#include "vulkan_descriptors.h" #include "vulkan_descriptors.h"
#include "vulkan_commons.h"
#include "vulkan/vulkan.h"
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
@@ -812,4 +810,4 @@ void destroy_pipeline()
for (size_t i = 0; i < SHADER_MODULES_COUNT; i++) { for (size_t i = 0; i < SHADER_MODULES_COUNT; i++) {
vkDestroyShaderModule(g_vulkan_state.device, g_shader_modules[i], NULL); vkDestroyShaderModule(g_vulkan_state.device, g_shader_modules[i], NULL);
} }
} }
-3
View File
@@ -1,11 +1,8 @@
#ifndef RSE_VULKAN_PIPELINE_H #ifndef RSE_VULKAN_PIPELINE_H
#define RSE_VULKAN_PIPELINE_H #define RSE_VULKAN_PIPELINE_H
#include "vulkan_commons.h"
#include "utilities/rse_commons.h" #include "utilities/rse_commons.h"
#include <stdint.h>
/** /**
* @brief Create a graphics pipeline * @brief Create a graphics pipeline
* *
+2 -1
View File
@@ -12,6 +12,7 @@
#include "window.h" #include "window.h"
#include "locale_window.h" #include "locale_window.h"
#include "rse_window_errors.h"
#include "utilities/logger.h" #include "utilities/logger.h"
#include "utilities/rse_errors_common.h" #include "utilities/rse_errors_common.h"
#include "vulkan_base.h" #include "vulkan_base.h"
@@ -105,4 +106,4 @@ void window_terminate()
GLFWwindow* get_window_handle() GLFWwindow* get_window_handle()
{ {
return g_window_handle; return g_window_handle;
} }
+1 -2
View File
@@ -17,7 +17,6 @@
/* Vulkan header MUST be included before glfw */ /* Vulkan header MUST be included before glfw */
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include "rse_window_errors.h"
#include "utilities/rse_commons.h" #include "utilities/rse_commons.h"
/** /**
@@ -46,4 +45,4 @@ void window_terminate();
GLFWwindow* get_window_handle(); GLFWwindow* get_window_handle();
#endif /* RSE_WINDOW_H */ #endif /* RSE_WINDOW_H */
+1 -1
View File
@@ -15,5 +15,5 @@ int main(int argc, char** argv)
rse_task_join(&graphics_task); rse_task_join(&graphics_task);
rse_task_exit(); rse_task_exit();
return 0;
} }
+2 -5
View File
@@ -1,10 +1,6 @@
#include "criterion/criterion.h" #include "criterion/criterion.h"
#include "graphics/src/rse_math.h" #include "graphics/src/rse_math.h"
#include <stdio.h>
#include <math.h>
/*-----------------RSE MATH TEST------------------------*/ /*-----------------RSE MATH TEST------------------------*/
TestSuite(rse_math); TestSuite(rse_math);
@@ -177,10 +173,11 @@ Test(rse_math, perspective)
} }
/*-----------------RSE TEXTURES TEST------------------------*/ /*-----------------RSE TEXTURES TEST------------------------*/
#include "graphics/src/rse_texture.h" #include "graphics/src/rse_texture.h"
TestSuite(rse_textures); TestSuite(rse_textures);
Test(rse_textures, load_png_image) Test(rse_textures, load_png_image)
{ {
rse_load_texture("../../miotacz_piorunów.png"); rse_load_texture("../../miotacz_piorunów.png");
} }
+2 -1
View File
@@ -12,6 +12,7 @@
#ifndef RSE_COMMONS_H #ifndef RSE_COMMONS_H
#define RSE_COMMONS_H #define RSE_COMMONS_H
#include "utilities/locale_common.h"
#include <stdint.h> #include <stdint.h>
/** /**
@@ -31,4 +32,4 @@ if (ptr == NULL) { \
*/ */
typedef uint32_t rse_err_t; typedef uint32_t rse_err_t;
#endif /* RSE_COMMONS_H */ #endif /* RSE_COMMONS_H */