From 027ef8a46f47e182c2b629fa799a42d82ef6f368 Mon Sep 17 00:00:00 2001 From: Kevin Trogant Date: Wed, 7 Feb 2024 13:56:06 +0100 Subject: [PATCH] Restructure the project Move asset_compiler into its own (static) library. This removes the dependency on it from the runtime and makes it possible to have a standalone asset_compiler tool (useful for modding support). Split meson.build into sub-files to improve readability. Give each target its own pch directory. This is more inline with what the meson manual recommends. Export dependencies to make it possible to use the engine as a meson subproject. This is currently untested. --- meson.build | 181 ++---------------- meson_options.txt | 3 +- .../asset_compiler.c | 37 ++-- src/asset_compiler/asset_compiler.h | 22 +++ .../description_parser.c | 5 +- .../description_parser.h | 0 .../dxc_shader_compiler.cpp | 2 +- .../framegraph_processor.c | 7 +- src/asset_compiler/meson.build | 44 +++++ .../pipeline_processor.c | 13 +- .../processor.h} | 14 +- .../shader_compiler.c | 0 .../shader_compiler.h | 7 +- src/game/main.c | 11 ++ src/game/meson.build | 10 + src/game/pch/game_pch.h | 2 + src/meson.build | 5 + src/renderer/vk/meson.build | 36 ++++ {pch => src/renderer/vk/pch}/vk_pch.h | 0 src/runtime/app.c | 7 +- src/runtime/app.h | 4 + src/runtime/config.c | 2 + src/runtime/init.c | 22 --- src/runtime/meson.build | 55 ++++++ {pch => src/runtime/pch}/rt_pch.h | 0 tests/meson.build | 6 + {src/tests => tests}/rttest.c | 0 27 files changed, 270 insertions(+), 225 deletions(-) rename src/{runtime => asset_compiler}/asset_compiler.c (95%) create mode 100644 src/asset_compiler/asset_compiler.h rename src/{runtime => asset_compiler}/description_parser.c (99%) rename src/{runtime => asset_compiler}/description_parser.h (100%) rename src/{runtime => asset_compiler}/dxc_shader_compiler.cpp (99%) rename src/{runtime => asset_compiler}/framegraph_processor.c (99%) create mode 100644 src/asset_compiler/meson.build rename src/{runtime => asset_compiler}/pipeline_processor.c (99%) rename src/{runtime/asset_compiler.h => asset_compiler/processor.h} (82%) rename src/{runtime => asset_compiler}/shader_compiler.c (100%) rename src/{runtime => asset_compiler}/shader_compiler.h (88%) create mode 100644 src/game/meson.build create mode 100644 src/game/pch/game_pch.h create mode 100644 src/meson.build create mode 100644 src/renderer/vk/meson.build rename {pch => src/renderer/vk/pch}/vk_pch.h (100%) create mode 100644 src/runtime/meson.build rename {pch => src/runtime/pch}/rt_pch.h (100%) create mode 100644 tests/meson.build rename {src/tests => tests}/rttest.c (100%) diff --git a/meson.build b/meson.build index 9350b5a..f1acedd 100644 --- a/meson.build +++ b/meson.build @@ -46,8 +46,6 @@ if buildtype == 'debug' or buildtype == 'debugoptimized' endif # Gather dependencies -common_incdirs = [include_directories(['contrib', 'src'])] - thread_dep = dependency('threads') m_dep = compiler.find_library('m', required : false) vk_dep = dependency('vulkan', required : false) @@ -61,172 +59,35 @@ endif # Copy file utility copy_util = find_program('scripts/copy_util.py') -runtime_incdirs = common_incdirs -runtime_linkargs = [] -runtime_additional_sources = [] -runtime_cargs = [] -runtime_deps = [thread_dep, m_dep, windowing_dep] +engine_incdir = include_directories('src') -if get_option('build_asset_compiler') - runtime_cargs += ['-DRT_BUILD_ASSET_COMPILER'] - - # DXC for vulkan & directx shaders - if get_option('enable_dxc_shader_compiler') - # We package dxc binaries under contrib/dxc - dxc_include = include_directories('contrib' / 'dxc' / 'inc') - dxc_libdir = 'NONE' - if host_machine.system() == 'windows' - dxc_libdir = meson.project_source_root() / 'contrib' / 'dxc' / 'lib' / 'x64' - custom_target('copy dxcompiler.dll', - input : 'contrib' / 'dxc' / 'bin' / 'x64' / 'dxcompiler.dll', - output : 'dxcompiler.dll', - command : [copy_util, '@INPUT@', '@OUTPUT@'], - install : false, - build_by_default : true) - endif - dxc_dep = declare_dependency(link_args : ['-L'+dxc_libdir, '-ldxcompiler'], include_directories : dxc_include) - runtime_deps += dxc_dep - runtime_additional_sources += [ - 'src/runtime/dxc_shader_compiler.cpp' - ] - runtime_cargs += ['-DRT_BUILD_DXC_SHADER_COMPILER'] - endif - - # Asset compiler sources - runtime_additional_sources += [ - 'src/runtime/asset_compiler.h', - 'src/runtime/description_parser.h', - 'src/runtime/shader_compiler.h', - - 'src/runtime/asset_compiler.c', - 'src/runtime/description_parser.c', - 'src/runtime/framegraph_processor.c', - 'src/runtime/pipeline_processor.c', - 'src/runtime/shader_compiler.c', - ] -endif - -runtime_lib = library('rt', - # Project Sources - 'src/runtime/aio.h', - 'src/runtime/app.h', - 'src/runtime/buffer_manager.h', - 'src/runtime/compression.h', - 'src/runtime/config.h', - 'src/runtime/ds.h', - 'src/runtime/dynamic_libs.h', - 'src/runtime/file_tab.h', - 'src/runtime/fsutils.h', - 'src/runtime/gfx.h', - 'src/runtime/handles.h', - 'src/runtime/hashing.h', - 'src/runtime/jobs.h', - 'src/runtime/mem_arena.h', - 'src/runtime/renderer_api.h', - 'src/runtime/resources.h', - 'src/runtime/runtime.h', - 'src/runtime/threading.h', - - 'src/runtime/aio.c', - 'src/runtime/app.c', - 'src/runtime/assert.c', - 'src/runtime/buffer_manager.c', - 'src/runtime/compression.c', - 'src/runtime/config.c', - 'src/runtime/ds_minheap.c', - 'src/runtime/dynamic_libs.c', - 'src/runtime/error_report.c', - 'src/runtime/file_tab.c', - 'src/runtime/fsutils.c', - 'src/runtime/gfx_framegraph.c', - 'src/runtime/gfx_main.c', - 'src/runtime/hashing.c', - 'src/runtime/init.c', - 'src/runtime/jobs.c', - 'src/runtime/mem_arena.c', - 'src/runtime/resource_manager.c', - 'src/runtime/sprint.c', - 'src/runtime/text.c', - 'src/runtime/threading_cond.c', - 'src/runtime/threading_mutex.c', - 'src/runtime/threading_rwlock.c', - 'src/runtime/threading_thread.c', - - # Contrib Sources - 'contrib/xxhash/xxhash.c', - 'contrib/lz4/lz4.c', - sources : runtime_additional_sources, - dependencies : runtime_deps, - include_directories : runtime_incdirs, - link_args : runtime_linkargs, - c_args : runtime_cargs, - c_pch : 'pch/rt_pch.h', - cpp_args : runtime_cargs, - cpp_pch : 'pch/rt_pch.h') - - -# Renderer libraries -static_renderer_lib = 'NONE' - -if vk_dep.found() - platform_defs = [] - if get_option('use_xlib') - platform_defs = ['-DVK_USE_PLATFORM_XLIB_KHR'] - elif host_machine.system() == 'windows' - platform_defs = ['-DVK_USE_PLATFORM_WIN32_KHR'] - endif - - vk_inc_dep = vk_dep.partial_dependency(compile_args : true, includes : true) - vk_renderer_lib = library('rtvk', - # Project Sources - 'src/renderer/vk/gpu.h', - 'src/renderer/vk/pipelines.h', - 'src/renderer/vk/render_targets.h', - 'src/renderer/vk/swapchain.h', - - 'src/renderer/vk/helper.c', - 'src/renderer/vk/init.c', - 'src/renderer/vk/pipelines.c', - 'src/renderer/vk/render_targets.c', - 'src/renderer/vk/swapchain.c', - - # Contrib Sources - 'contrib/volk/volk.h', - 'contrib/volk/volk.c', - 'contrib/vma/vk_mem_alloc.h', - 'src/renderer/vk/vma_impl.cpp', - dependencies : [m_dep, vk_inc_dep, windowing_dep], - include_directories : common_incdirs, - link_with : [runtime_lib], - c_pch : 'pch/vk_pch.h', - c_args : platform_defs, - cpp_pch : 'pch/vk_pch.h', - cpp_args : platform_defs) - - static_renderer_lib = vk_renderer_lib -endif +contrib_dir = meson.project_source_root() / 'contrib' +subdir('src') # Handle linking against both runtime and renderer if we build static libs engine_link_libs = [] if get_option('default_library') == 'static' - engine_link_libs = [runtime_lib, static_renderer_lib] + if get_option('static_renderer') == 'vk' + engine_link_libs = [runtime_lib, vk_renderer_lib] + else + error('Invalid static_renderer option ', get_option('static_renderer')) + endif else engine_link_libs = [runtime_lib] endif -# Game -executable('voyage', - 'src/game/entry.c', - 'src/game/main.c', - include_directories : common_incdirs, - link_with : engine_link_libs, - win_subsystem : 'windows') +# Unit/Integration test driver +subdir('tests') -# Unit Tests -rttest_exe = executable('rttest', - 'src/tests/rttest.c', - link_with : engine_link_libs, - include_directories : common_incdirs, - win_subsystem : 'console') -test('runtime test', rttest_exe) +# Declare dependencies, to enable using the engine as a subproject +engine_dep = declare_dependency(link_with : engine_link_libs, + include_directories : engine_incdir) + +assetc_dep = declare_dependency(link_with : asset_compiler, + include_directories : engine_incdir) + +# "inline" game +if get_option('game_as_subdir') + subdir('src/game') +endif diff --git a/meson_options.txt b/meson_options.txt index 53da900..8617626 120000 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,4 +1,5 @@ +option('static_renderer', type : 'string', value : 'vk', description : 'Name of the renderer used for static builds') option('use_xlib', type : 'boolean', value : false, description : 'Use Xlib for window creation under linux') option('error_report_debugbreak', type : 'boolean', value : true, description : 'Debugbreak in ReportError') -option('build_asset_compiler', type : 'boolean', value : true, description : 'Enables or disables the asset compiler inside runtime.') option('enable_dxc_shader_compiler', type : 'boolean', value : true, description : 'Enables building the dxc-based shader compiler.') +option('game_as_subdir', type : 'boolean', value : false, description : 'If true, adds the directory "src/game" to the build.') diff --git a/src/runtime/asset_compiler.c b/src/asset_compiler/asset_compiler.c similarity index 95% rename from src/runtime/asset_compiler.c rename to src/asset_compiler/asset_compiler.c index bd3d0c8..e6e643b 100644 --- a/src/runtime/asset_compiler.c +++ b/src/asset_compiler/asset_compiler.c @@ -1,22 +1,21 @@ #include "asset_compiler.h" -#include "buffer_manager.h" -#include "config.h" -#include "file_tab.h" -#include "fsutils.h" -#include "mem_arena.h" -#include "resources.h" -#include "runtime.h" -#include "threading.h" +#include "processor.h" + +#include "runtime/aio.h" +#include "runtime/buffer_manager.h" +#include "runtime/config.h" +#include "runtime/file_tab.h" +#include "runtime/fsutils.h" +#include "runtime/mem_arena.h" +#include "runtime/resources.h" +#include "runtime/runtime.h" +#include "runtime/threading.h" #include #include #include #include -#ifndef RT_BUILD_ASSET_COMPILER -#error This should only be built when RT_BUILD_ASSET_COMPILER is defined. -#endif - typedef struct { uint64_t last_processed; rt_resource_id resources[RT_MAX_RESOURCES_PER_ASSET]; @@ -75,7 +74,15 @@ static rt_asset_processor _processors[] = { static void ProcessorThreadEntry(void *); static void CompilerThreadEntry(void *); -rt_result InitAssetCompiler(void) { + +RT_DLLEXPORT void rtRegisterAssetCompilerCVars(void) { + rtRegisterCVAR(&rt_AssetDirectory); + rtRegisterCVAR(&rt_AssetDBSize); + rtRegisterCVAR(&rt_AssetProcessingThreads); + rtRegisterCVAR(&rt_AssetProcessorArenaSize); +} + +RT_DLLEXPORT rt_result rtInitAssetCompiler(void) { unsigned int db_size = (unsigned int)rt_AssetDBSize.i; void *mem = malloc((sizeof(rt_file_id) + sizeof(rt_asset_data)) * db_size); @@ -125,7 +132,7 @@ rt_result InitAssetCompiler(void) { return RT_SUCCESS; } -void ShutdownAssetCompiler(void) { +RT_DLLEXPORT void rtShutdownAssetCompiler(void) { _keep_running = false; rtJoinThread(_compiler_thread); for (int i = 0; i < rt_AssetProcessingThreads.i; ++i) @@ -384,8 +391,6 @@ static void ProcessorThreadEntry(void *param) { /* Utilities for asset processors*/ -#include "aio.h" - rt_loaded_asset LoadAsset(rt_file_id file) { const char *path = rtGetFilePath(file); size_t file_size = rtGetFileSize(path); diff --git a/src/asset_compiler/asset_compiler.h b/src/asset_compiler/asset_compiler.h new file mode 100644 index 0000000..65572d6 --- /dev/null +++ b/src/asset_compiler/asset_compiler.h @@ -0,0 +1,22 @@ +#ifndef RT_ASSET_PROCESSOR_H +#define RT_ASSET_PROCESSOR_H + +/* Public header for the asset processor */ + +#include "runtime/runtime.h" + +#ifdef __cplusplus +extern "C" { +#endif + +RT_DLLEXPORT void rtRegisterAssetCompilerCVars(void); + +RT_DLLEXPORT rt_result rtInitAssetCompiler(void); + +RT_DLLEXPORT void rtShutdownAssetCompiler(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/runtime/description_parser.c b/src/asset_compiler/description_parser.c similarity index 99% rename from src/runtime/description_parser.c rename to src/asset_compiler/description_parser.c index f5b01d8..90cfc84 100644 --- a/src/runtime/description_parser.c +++ b/src/asset_compiler/description_parser.c @@ -1,6 +1,7 @@ #include "description_parser.h" -#include "runtime.h" -#include "mem_arena.h" + +#include "runtime/runtime.h" +#include "runtime/mem_arena.h" #include #include diff --git a/src/runtime/description_parser.h b/src/asset_compiler/description_parser.h similarity index 100% rename from src/runtime/description_parser.h rename to src/asset_compiler/description_parser.h diff --git a/src/runtime/dxc_shader_compiler.cpp b/src/asset_compiler/dxc_shader_compiler.cpp similarity index 99% rename from src/runtime/dxc_shader_compiler.cpp rename to src/asset_compiler/dxc_shader_compiler.cpp index 81d91d4..ddbc03d 100644 --- a/src/runtime/dxc_shader_compiler.cpp +++ b/src/asset_compiler/dxc_shader_compiler.cpp @@ -4,7 +4,7 @@ #endif #include -#include "asset_compiler.h" +#include "processor.h" #include "shader_compiler.h" extern "C" rt_shader_bytecode CompileVulkanShader(rt_shader_stage stage, diff --git a/src/runtime/framegraph_processor.c b/src/asset_compiler/framegraph_processor.c similarity index 99% rename from src/runtime/framegraph_processor.c rename to src/asset_compiler/framegraph_processor.c index bf25153..9453449 100644 --- a/src/runtime/framegraph_processor.c +++ b/src/asset_compiler/framegraph_processor.c @@ -1,7 +1,8 @@ -#include "asset_compiler.h" -#include "buffer_manager.h" +#include "processor.h" #include "description_parser.h" -#include "gfx.h" + +#include "runtime/buffer_manager.h" +#include "runtime/gfx.h" #include #include diff --git a/src/asset_compiler/meson.build b/src/asset_compiler/meson.build new file mode 100644 index 0000000..e98b44c --- /dev/null +++ b/src/asset_compiler/meson.build @@ -0,0 +1,44 @@ +# Asset Compiler +ac_deps = [] +ac_sources = [] +ac_cargs = [] + +# DXC for vulkan & directx shaders +if get_option('enable_dxc_shader_compiler') + # We package dxc binaries under contrib/dxc + dxc_include = include_directories(meson.project_source_root() / 'contrib' / 'dxc' / 'inc') + dxc_libdir = 'NONE' + if host_machine.system() == 'windows' + dxc_libdir = meson.project_source_root() / 'contrib' / 'dxc' / 'lib' / 'x64' + custom_target('copy dxcompiler.dll', + input : meson.project_source_root() / 'contrib' / 'dxc' / 'bin' / 'x64' / 'dxcompiler.dll', + output : 'dxcompiler.dll', + command : [copy_util, '@INPUT@', '@OUTPUT@'], + install : false, + build_by_default : true) + endif + dxc_dep = declare_dependency(link_args : ['-L'+dxc_libdir, '-ldxcompiler'], include_directories : dxc_include) + ac_deps += dxc_dep + ac_sources += [ + 'dxc_shader_compiler.cpp' + ] + ac_cargs += '-DRT_BUILD_DXC_SHADER_COMPILER' +endif + +asset_compiler = static_library('asset_compiler', + 'asset_compiler.h', + 'description_parser.h', + 'processor.h', + 'shader_compiler.h', + + 'asset_compiler.c', + 'description_parser.c', + 'framegraph_processor.c', + 'pipeline_processor.c', + 'shader_compiler.c', + sources : ac_sources, + include_directories : engine_incdir, + link_with : runtime_lib, + c_args : ac_cargs, + cpp_args : ac_cargs, + dependencies : ac_deps) diff --git a/src/runtime/pipeline_processor.c b/src/asset_compiler/pipeline_processor.c similarity index 99% rename from src/runtime/pipeline_processor.c rename to src/asset_compiler/pipeline_processor.c index 8c4640e..354a169 100644 --- a/src/runtime/pipeline_processor.c +++ b/src/asset_compiler/pipeline_processor.c @@ -1,12 +1,13 @@ -#include "asset_compiler.h" -#include "buffer_manager.h" -#include "config.h" +#include "processor.h" #include "description_parser.h" -#include "gfx.h" -#include "mem_arena.h" -#include "runtime.h" #include "shader_compiler.h" +#include "runtime/buffer_manager.h" +#include "runtime/config.h" +#include "runtime/gfx.h" +#include "runtime/mem_arena.h" +#include "runtime/runtime.h" + #include #include #include diff --git a/src/runtime/asset_compiler.h b/src/asset_compiler/processor.h similarity index 82% rename from src/runtime/asset_compiler.h rename to src/asset_compiler/processor.h index 3b470d3..f8eb851 100644 --- a/src/runtime/asset_compiler.h +++ b/src/asset_compiler/processor.h @@ -1,13 +1,9 @@ -#ifndef RT_ASSET_COMPILER_H -#define RT_ASSET_COMPILER_H +#ifndef RT_PROCESSOR_H +#define RT_PROCESSOR_H -#ifndef RT_BUILD_ASSET_COMPILER -#error This file should only be included if RT_BUILD_ASSET_COMPILER is defined. -#endif - -#include "file_tab.h" -#include "resources.h" -#include "mem_arena.h" +#include "runtime/file_tab.h" +#include "runtime/mem_arena.h" +#include "runtime/resources.h" #ifdef __cplusplus extern "C" { diff --git a/src/runtime/shader_compiler.c b/src/asset_compiler/shader_compiler.c similarity index 100% rename from src/runtime/shader_compiler.c rename to src/asset_compiler/shader_compiler.c diff --git a/src/runtime/shader_compiler.h b/src/asset_compiler/shader_compiler.h similarity index 88% rename from src/runtime/shader_compiler.h rename to src/asset_compiler/shader_compiler.h index 67a11a6..3883012 100644 --- a/src/runtime/shader_compiler.h +++ b/src/asset_compiler/shader_compiler.h @@ -1,10 +1,9 @@ #ifndef RT_SHADER_COMPILER_H #define RT_SHADER_COMPILER_H -#include "mem_arena.h" -#include "runtime.h" - -#include "renderer_api.h" +#include "runtime/runtime.h" +#include "runtime/mem_arena.h" +#include "runtime/renderer_api.h" #ifdef __cplusplus extern "C" { diff --git a/src/game/main.c b/src/game/main.c index a583190..413774c 100644 --- a/src/game/main.c +++ b/src/game/main.c @@ -2,12 +2,20 @@ #include "runtime/resources.h" #include "runtime/mem_arena.h" +#include "asset_compiler/asset_compiler.h" + static rt_framegraph *_framegraph; +void RegisterCVars(void) { + rtRegisterAssetCompilerCVars(); +} + /* Called after the runtime has finished its initialization and before entering the main-loop*/ void Init(void) { rtLog("GAME", "Init"); + rtInitAssetCompiler(); + #if 0 rt_render_target_id rt_ids[4] = {rtCalculateRenderTargetID("rt0", sizeof("rt0")), rtCalculateRenderTargetID("rt1", sizeof("rt1")), @@ -61,6 +69,8 @@ void Init(void) { rt_resource_id id = rtGetResourceID("assets/test.framegraph"); rt_temp_arena temp = rtGetTemporaryArena(NULL, 0); + while (rtGetResourceSize(id) == 0) + ; rt_resource *resource = rtArenaPush(temp.arena, rtGetResourceSize(id)); @@ -72,5 +82,6 @@ void Init(void) { /* Called after exiting the main-loop and before the runtime starts its shutdown */ void Shutdown(void) { rtLog("GAME", "Shutdown"); + rtShutdownAssetCompiler(); rtDestroyFramegraph(_framegraph); } \ No newline at end of file diff --git a/src/game/meson.build b/src/game/meson.build new file mode 100644 index 0000000..ec0003c --- /dev/null +++ b/src/game/meson.build @@ -0,0 +1,10 @@ +vy_link_libs = engine_link_libs +vy_link_libs += asset_compiler + +executable('voyage', + 'entry.c', + 'main.c', + link_with : vy_link_libs, + include_directories : engine_incdir, + c_pch : 'pch/game_pch.h', + win_subsystem : 'windows') diff --git a/src/game/pch/game_pch.h b/src/game/pch/game_pch.h new file mode 100644 index 0000000..d7ec2ad --- /dev/null +++ b/src/game/pch/game_pch.h @@ -0,0 +1,2 @@ +// Runtime dir +#include "runtime/runtime.h" diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 0000000..329ac06 --- /dev/null +++ b/src/meson.build @@ -0,0 +1,5 @@ +subdir('runtime') +subdir('asset_compiler') + +# Renderer libs +subdir('renderer/vk') diff --git a/src/renderer/vk/meson.build b/src/renderer/vk/meson.build new file mode 100644 index 0000000..b367410 --- /dev/null +++ b/src/renderer/vk/meson.build @@ -0,0 +1,36 @@ +if vk_dep.found() + platform_defs = [] + if get_option('use_xlib') + platform_defs = ['-DVK_USE_PLATFORM_XLIB_KHR'] + elif host_machine.system() == 'windows' + platform_defs = ['-DVK_USE_PLATFORM_WIN32_KHR'] + endif + + vk_inc_dep = vk_dep.partial_dependency(compile_args : true, includes : true) + vk_renderer_lib = library('rtvk', + # Project Sources + 'gpu.h', + 'pipelines.h', + 'render_targets.h', + 'swapchain.h', + + 'helper.c', + 'init.c', + 'pipelines.c', + 'render_targets.c', + 'swapchain.c', + + # Contrib Sources + contrib_dir / 'volk/volk.h', + contrib_dir / 'volk/volk.c', + contrib_dir / 'vma/vk_mem_alloc.h', + 'vma_impl.cpp', + dependencies : [m_dep, vk_inc_dep, windowing_dep], + include_directories : [engine_incdir, include_directories(contrib_dir)], + link_with : [runtime_lib], + c_pch : 'pch/vk_pch.h', + c_args : platform_defs, + cpp_pch : 'pch/vk_pch.h', + cpp_args : platform_defs) +endif + diff --git a/pch/vk_pch.h b/src/renderer/vk/pch/vk_pch.h similarity index 100% rename from pch/vk_pch.h rename to src/renderer/vk/pch/vk_pch.h diff --git a/src/runtime/app.c b/src/runtime/app.c index e5dcbd9..b8571ce 100644 --- a/src/runtime/app.c +++ b/src/runtime/app.c @@ -32,6 +32,9 @@ rtWin32Entry(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int n rtRegisterRendererCVars(); + if (app_callbacks.RegisterCVars) + app_callbacks.RegisterCVars(); + WNDCLASSEXW wndclass = { .cbSize = sizeof(wndclass), .hInstance = hInstance, @@ -165,7 +168,9 @@ RT_DLLEXPORT int rtXlibEntry(int argc, char **argv, rt_app_callbacks app_callbac return 1; rtRegisterRendererCVars(); - + + if (app_callbacks.RegisterCVars()) + app_callbacks.RegisterCVars(); Display *dpy = XOpenDisplay(NULL); if (!dpy) { diff --git a/src/runtime/app.h b/src/runtime/app.h index 06b6e4a..6afea75 100644 --- a/src/runtime/app.h +++ b/src/runtime/app.h @@ -9,10 +9,14 @@ extern "C" { #endif +typedef void rt_app_register_cvars_fn(void); typedef void rt_app_init_fn(void); typedef void rt_app_shutdown_fn(void); typedef struct { + /* Called before initialization. */ + rt_app_register_cvars_fn *RegisterCVars; + /* Called after the runtime has finished initialization and * before entering the main-loop */ rt_app_init_fn *Init; diff --git a/src/runtime/config.c b/src/runtime/config.c index 23fce88..a2cbd4f 100644 --- a/src/runtime/config.c +++ b/src/runtime/config.c @@ -12,6 +12,8 @@ static unsigned int _next = 0; static rt_mutex *_mutex = NULL; void rtRegisterCVAR(rt_cvar *cvar) { + /* TODO(Kevin): Check if we have a loaded value for that cvar. + * If yes, override the provided default value. */ if (!_mutex) _mutex = rtCreateMutex(); rtLockMutex(_mutex); diff --git a/src/runtime/init.c b/src/runtime/init.c index 58f48d9..0ee1917 100644 --- a/src/runtime/init.c +++ b/src/runtime/init.c @@ -18,10 +18,6 @@ extern rt_cvar rt_ResourceNamespaceSize; extern rt_cvar rt_DisableResourceNamespaceLoad; extern rt_cvar rt_MaxFramegraphs; -#ifdef RT_BUILD_ASSET_COMPILER -extern rt_cvar rt_AssetDirectory; -#endif - void RegisterRuntimeCVars(void) { rtRegisterCVAR(&rt_Renderer); rtRegisterCVAR(&rt_Fullscreen); @@ -36,9 +32,6 @@ void RegisterRuntimeCVars(void) { rtRegisterCVAR(&rt_ResourceNamespaceSize); rtRegisterCVAR(&rt_DisableResourceNamespaceLoad); rtRegisterCVAR(&rt_MaxFramegraphs); -#ifdef RT_BUILD_ASSET_COMPILER - rtRegisterCVAR(&rt_AssetDirectory); -#endif } extern void SetMainThreadId(void); @@ -52,11 +45,6 @@ extern void ShutdownAIO(void); extern rt_result InitResourceManager(void); extern void ShutdownResourceManager(void); -#ifdef RT_BUILD_ASSET_COMPILER -extern rt_result InitAssetCompiler(void); -extern void ShutdownAssetCompiler(void); -#endif - RT_DLLEXPORT rt_result rtInitRuntime(void) { SetMainThreadId(); RegisterRuntimeCVars(); @@ -82,20 +70,10 @@ RT_DLLEXPORT rt_result rtInitRuntime(void) { return res; } -#ifdef RT_BUILD_ASSET_COMPILER - if ((res = InitAssetCompiler()) != RT_SUCCESS) { - rtReportError("AC", "Init failed."); - return res; - } -#endif - return RT_SUCCESS; } RT_DLLEXPORT void rtShutdownRuntime(void) { -#ifdef RT_BUILD_ASSET_COMPILER - ShutdownAssetCompiler(); -#endif ShutdownResourceManager(); ShutdownAIO(); ShutdownFileTab(); diff --git a/src/runtime/meson.build b/src/runtime/meson.build new file mode 100644 index 0000000..1988f4a --- /dev/null +++ b/src/runtime/meson.build @@ -0,0 +1,55 @@ +# Runtime +runtime_deps = [thread_dep, m_dep, windowing_dep] +runtime_incdirs = include_directories(meson.project_source_root() / 'contrib') +runtime_lib = library('rt', + # Project Sources + 'aio.h', + 'app.h', + 'buffer_manager.h', + 'compression.h', + 'config.h', + 'ds.h', + 'dynamic_libs.h', + 'file_tab.h', + 'fsutils.h', + 'gfx.h', + 'handles.h', + 'hashing.h', + 'jobs.h', + 'mem_arena.h', + 'renderer_api.h', + 'resources.h', + 'runtime.h', + 'threading.h', + + 'aio.c', + 'app.c', + 'assert.c', + 'buffer_manager.c', + 'compression.c', + 'config.c', + 'ds_minheap.c', + 'dynamic_libs.c', + 'error_report.c', + 'file_tab.c', + 'fsutils.c', + 'gfx_framegraph.c', + 'gfx_main.c', + 'hashing.c', + 'init.c', + 'jobs.c', + 'mem_arena.c', + 'resource_manager.c', + 'sprint.c', + 'text.c', + 'threading_cond.c', + 'threading_mutex.c', + 'threading_rwlock.c', + 'threading_thread.c', + + # Contrib Sources + contrib_dir / 'xxhash/xxhash.c', + contrib_dir / 'lz4/lz4.c', + dependencies : runtime_deps, + include_directories : [engine_incdir, runtime_incdirs], + c_pch : 'pch/rt_pch.h') diff --git a/pch/rt_pch.h b/src/runtime/pch/rt_pch.h similarity index 100% rename from pch/rt_pch.h rename to src/runtime/pch/rt_pch.h diff --git a/tests/meson.build b/tests/meson.build new file mode 100644 index 0000000..c976614 --- /dev/null +++ b/tests/meson.build @@ -0,0 +1,6 @@ +rttest_exe = executable('rttest', + 'rttest.c', + link_with : engine_link_libs, + include_directories : engine_incdir, + win_subsystem : 'console') +test('runtime test', rttest_exe) diff --git a/src/tests/rttest.c b/tests/rttest.c similarity index 100% rename from src/tests/rttest.c rename to tests/rttest.c