From 57e3d7998bd4c4bd30f060648806a3bc4becb65f Mon Sep 17 00:00:00 2001 From: Chewico Date: Sat, 10 Oct 2026 19:10:45 +0200 Subject: [PATCH] User definition --- .../include/deerith/network/sync_variable.h | 6 ++---- .../include/deerith/universe/user.h | 15 +++++--------- deerith_engine_core/src/user.cpp | 20 +++++++++++++++++-- sandbox/CMakeLists.txt | 2 +- sandbox/src/{common => runtime}/main.cpp | 5 +++++ .../{common => runtime}/user_definition.cpp | 9 ++------- .../common.h => runtime/user_definition.h} | 7 ++----- 7 files changed, 35 insertions(+), 29 deletions(-) rename sandbox/src/{common => runtime}/main.cpp (62%) rename sandbox/src/{common => runtime}/user_definition.cpp (70%) rename sandbox/src/{common/common.h => runtime/user_definition.h} (51%) diff --git a/deerith_engine_core/include/deerith/network/sync_variable.h b/deerith_engine_core/include/deerith/network/sync_variable.h index 6a50c36..b9a92e4 100644 --- a/deerith_engine_core/include/deerith/network/sync_variable.h +++ b/deerith_engine_core/include/deerith/network/sync_variable.h @@ -21,15 +21,13 @@ namespace deerith }; template - class sync_variable_t + class sync_variable_t : public sync_variable_base_t { public: - virtual ~sync_buffer_t() = default; + ~sync_variable_t() override = default; private: std::array, BUFFER_SIZE> buffer; }; - template <> - class sync_variable_t } \ No newline at end of file diff --git a/deerith_engine_core/include/deerith/universe/user.h b/deerith_engine_core/include/deerith/universe/user.h index 3fe9505..43fb238 100644 --- a/deerith_engine_core/include/deerith/universe/user.h +++ b/deerith_engine_core/include/deerith/universe/user.h @@ -11,19 +11,14 @@ namespace deerith public: void *user_data = nullptr; - template - void register_sync_variable(sync_variable_t *var); + void register_sync_variable(sync_variable_base_t *var); private: std::vector buffers; }; - void register_user_sync_variables_init_callback(std::function); - void register_user_sync_variables_shutdown_callback(std::function); -} + using user_registration_function = std::function; -template -void deerith::user_t::register_sync_variable(sync_variable_t *var) -{ - buffers.push_back(var); -} \ No newline at end of file + void register_user_sync_variables_init_callback(user_registration_function); + void register_user_sync_variables_shutdown_callback(user_registration_function); +} diff --git a/deerith_engine_core/src/user.cpp b/deerith_engine_core/src/user.cpp index 232186f..53b5017 100644 --- a/deerith_engine_core/src/user.cpp +++ b/deerith_engine_core/src/user.cpp @@ -1,6 +1,22 @@ #include -namespace deerit +namespace deerith { - + user_registration_function user_sync_variables_init_function; + user_registration_function user_sync_variables_shutdown_function; } + +void deerith::register_user_sync_variables_init_callback(user_registration_function fn) +{ + user_sync_variables_init_function = fn; +} + +void deerith::register_user_sync_variables_shutdown_callback(user_registration_function fn) +{ + user_sync_variables_shutdown_function = fn; +} + +void deerith::user_t::register_sync_variable(sync_variable_base_t *var) +{ + buffers.push_back(var); +} \ No newline at end of file diff --git a/sandbox/CMakeLists.txt b/sandbox/CMakeLists.txt index d079a58..3730ea6 100644 --- a/sandbox/CMakeLists.txt +++ b/sandbox/CMakeLists.txt @@ -1,6 +1,6 @@ file(GLOB_RECURSE SANDBOX_COMMON CONFIGURE_DEPENDS - src/common/*.cpp + src/runtime/*.cpp ) file(GLOB_RECURSE SANDBOX_CLIENT diff --git a/sandbox/src/common/main.cpp b/sandbox/src/runtime/main.cpp similarity index 62% rename from sandbox/src/common/main.cpp rename to sandbox/src/runtime/main.cpp index 7f01bbb..3c94dcb 100644 --- a/sandbox/src/common/main.cpp +++ b/sandbox/src/runtime/main.cpp @@ -1,5 +1,7 @@ #include +#include "runtime/user_definition.h" + #ifdef DEERITH_CLIENT #include "client/window.h" #endif @@ -12,6 +14,9 @@ int main(int args_count, const char **args) { deerith::init_engine(); + deerith::register_user_sync_variables_init_callback(user_sync_variables_init); + deerith::register_user_sync_variables_shutdown_callback(user_sync_variables_init); + #ifdef DEERITH_CLIENT start_window_loop(); #endif diff --git a/sandbox/src/common/user_definition.cpp b/sandbox/src/runtime/user_definition.cpp similarity index 70% rename from sandbox/src/common/user_definition.cpp rename to sandbox/src/runtime/user_definition.cpp index ff91de8..6c86777 100644 --- a/sandbox/src/common/user_definition.cpp +++ b/sandbox/src/runtime/user_definition.cpp @@ -1,4 +1,5 @@ -#include "common/common.h" +#include "runtime/user_definition.h" + #include #include @@ -17,9 +18,3 @@ void user_sync_variables_shutdown(deerith::user_t &user) delete ((sandbox_user_data_t *)user.user_data); user.user_data = nullptr; } - -void client_definition() -{ - deerith::register_user_sync_variables_init_callback(user_sync_variables_init); - deerith::register_user_sync_variables_shutdown_callback(user_sync_variables_shutdown); -} \ No newline at end of file diff --git a/sandbox/src/common/common.h b/sandbox/src/runtime/user_definition.h similarity index 51% rename from sandbox/src/common/common.h rename to sandbox/src/runtime/user_definition.h index 4224314..e291e2b 100644 --- a/sandbox/src/common/common.h +++ b/sandbox/src/runtime/user_definition.h @@ -1,13 +1,10 @@ #pragma once #include -#include -#include - -#include struct sandbox_user_data_t { deerith::sync_variable_t position_sync; }; -void define_user(); \ No newline at end of file +void user_sync_variables_init(deerith::user_t &user); +void user_sync_variables_shutdown(deerith::user_t &user);