User definition

This commit is contained in:
Chewico 2026-10-10 19:10:45 +02:00
parent 9d2785541d
commit 57e3d7998b
7 changed files with 35 additions and 29 deletions

View File

@ -21,15 +21,13 @@ namespace deerith
};
template <typename T>
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<sync_variable_entry_t<T>, BUFFER_SIZE> buffer;
};
template <>
class sync_variable_t
}

View File

@ -11,19 +11,14 @@ namespace deerith
public:
void *user_data = nullptr;
template <typename T>
void register_sync_variable(sync_variable_t<T> *var);
void register_sync_variable(sync_variable_base_t *var);
private:
std::vector<sync_variable_base_t *> buffers;
};
void register_user_sync_variables_init_callback(std::function<void(user_t &)>);
void register_user_sync_variables_shutdown_callback(std::function<void(user_t &)>);
}
using user_registration_function = std::function<void(user_t &)>;
template <typename T>
void deerith::user_t::register_sync_variable(sync_variable_t<T> *var)
{
buffers.push_back(var);
void register_user_sync_variables_init_callback(user_registration_function);
void register_user_sync_variables_shutdown_callback(user_registration_function);
}

View File

@ -1,6 +1,22 @@
#include <deerith/universe/user.h>
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);
}

View File

@ -1,6 +1,6 @@
file(GLOB_RECURSE SANDBOX_COMMON
CONFIGURE_DEPENDS
src/common/*.cpp
src/runtime/*.cpp
)
file(GLOB_RECURSE SANDBOX_CLIENT

View File

@ -1,5 +1,7 @@
#include <deerith/engine.h>
#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

View File

@ -1,4 +1,5 @@
#include "common/common.h"
#include "runtime/user_definition.h"
#include <deerith/universe/user.h>
#include <deerith/core/log.h>
@ -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);
}

View File

@ -1,13 +1,10 @@
#pragma once
#include <deerith/universe/user.h>
#include <deerith/network/sync_variable.h>
#include <deerith/universe/universe_definition.h>
#include <string>
struct sandbox_user_data_t
{
deerith::sync_variable_t<glm::vec2> position_sync;
};
void define_user();
void user_sync_variables_init(deerith::user_t &user);
void user_sync_variables_shutdown(deerith::user_t &user);