From 9d2785541d46617e43c170c59baca18a1f2d3a52 Mon Sep 17 00:00:00 2001 From: Chewico Date: Fri, 9 Oct 2026 18:57:01 +0200 Subject: [PATCH] Sync --- .../include/deerith/network/sync_variable.h | 35 +++++++++++++++++++ .../include/deerith/universe/sync_buffer.h | 29 --------------- .../include/deerith/universe/user.h | 18 +++++++--- sandbox/src/common/common.h | 4 +-- sandbox/src/common/user_definition.cpp | 21 +++++++---- 5 files changed, 66 insertions(+), 41 deletions(-) create mode 100644 deerith_engine_core/include/deerith/network/sync_variable.h delete mode 100644 deerith_engine_core/include/deerith/universe/sync_buffer.h diff --git a/deerith_engine_core/include/deerith/network/sync_variable.h b/deerith_engine_core/include/deerith/network/sync_variable.h new file mode 100644 index 0000000..6a50c36 --- /dev/null +++ b/deerith_engine_core/include/deerith/network/sync_variable.h @@ -0,0 +1,35 @@ +#pragma once +#include +#include +#include + +#define BUFFER_SIZE (NETWORK_DELAY + 20) + +namespace deerith +{ + struct sync_variable_base_t + { + public: + virtual ~sync_variable_base_t() = default; + }; + + template + struct sync_variable_entry_t + { + T value; + uint32_t tick_id; + }; + + template + class sync_variable_t + { + public: + virtual ~sync_buffer_t() = 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/sync_buffer.h b/deerith_engine_core/include/deerith/universe/sync_buffer.h deleted file mode 100644 index c795e64..0000000 --- a/deerith_engine_core/include/deerith/universe/sync_buffer.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once -#include -#include -#include - -#define BUFFER_SIZE (NETWORK_DELAY + 20) - -namespace deerith -{ - class sync_buffer - { - public: - virtual ~sync_buffer() = default; - }; - - class float_sync_data : public sync_buffer - { - public: - private: - std::array float_buffer; - }; - - class vec2_sync_data : public sync_buffer - { - public: - private: - std::array buffer; - }; -} \ 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 f820b77..3fe9505 100644 --- a/deerith_engine_core/include/deerith/universe/user.h +++ b/deerith_engine_core/include/deerith/universe/user.h @@ -1,19 +1,29 @@ #pragma once -#include +#include + #include #include namespace deerith { - class user + class user_t { public: void *user_data = nullptr; - void add_sync_buffer(sync_buffer *sync_buffer); + template + void register_sync_variable(sync_variable_t *var); private: - std::vector sync_buffer_container; + std::vector buffers; }; + void register_user_sync_variables_init_callback(std::function); + void register_user_sync_variables_shutdown_callback(std::function); +} + +template +void deerith::user_t::register_sync_variable(sync_variable_t *var) +{ + buffers.push_back(var); } \ No newline at end of file diff --git a/sandbox/src/common/common.h b/sandbox/src/common/common.h index b63a3a9..4224314 100644 --- a/sandbox/src/common/common.h +++ b/sandbox/src/common/common.h @@ -1,13 +1,13 @@ #pragma once #include -#include +#include #include #include struct sandbox_user_data_t { - deerith::vec2_sync_data position; + deerith::sync_variable_t position_sync; }; void define_user(); \ No newline at end of file diff --git a/sandbox/src/common/user_definition.cpp b/sandbox/src/common/user_definition.cpp index 4dfeb93..ff91de8 100644 --- a/sandbox/src/common/user_definition.cpp +++ b/sandbox/src/common/user_definition.cpp @@ -1,16 +1,25 @@ #include "common/common.h" -#include +#include #include -void user_definition_function(deerith::user &user_data) +void user_sync_variables_init(deerith::user_t &user) { - deerith_trace("adding user data to new user"); - + deerith_trace("removing user data to new user"); sandbox_user_data_t *sandbox_user_data = new sandbox_user_data_t(); - user_data.add_sync_buffer(&sandbox_user_data->position); + + user.user_data = sandbox_user_data; + user.register_sync_variable(&sandbox_user_data->position_sync); +} + +void user_sync_variables_shutdown(deerith::user_t &user) +{ + deerith_trace("removing user"); + delete ((sandbox_user_data_t *)user.user_data); + user.user_data = nullptr; } void client_definition() { - deerith::define_client_callback(user_definition_function); + 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