Compare commits

...

2 Commits

Author SHA1 Message Date
9d2785541d Sync 2026-10-09 18:57:01 +02:00
d592cef1a0 Sync variables 2026-10-09 18:56:21 +02:00
10 changed files with 119 additions and 26 deletions

View File

@ -1,12 +0,0 @@
#pragma once
#include <deerith/engine.h>
namespace deerith
{
template <typename T>
class SyncBuffer
{
private:
public:
}
}

View File

@ -3,8 +3,8 @@
// At
#define UNIVERSE_SIMULATION_TICK_FREQ 50
#define NETWORK_RELATIVE_UNIVERSE_TICK 2
#define NETWORK_DELAY 6
#define NETWORK_RELATIVE_TICK 2
#define NETWORK_DELAY 10
namespace deerith
{

View File

@ -0,0 +1,35 @@
#pragma once
#include <deerith/engine.h>
#include <glm/glm.hpp>
#include <array>
#define BUFFER_SIZE (NETWORK_DELAY + 20)
namespace deerith
{
struct sync_variable_base_t
{
public:
virtual ~sync_variable_base_t() = default;
};
template <typename T>
struct sync_variable_entry_t
{
T value;
uint32_t tick_id;
};
template <typename T>
class sync_variable_t
{
public:
virtual ~sync_buffer_t() = default;
private:
std::array<sync_variable_entry_t<T>, BUFFER_SIZE> buffer;
};
template <>
class sync_variable_t
}

View File

@ -0,0 +1,9 @@
#pragma once
#include <deerith/universe/user.h>
#include <functional>
namespace deerith
{
void define_client_callback(std::function<void(user &)>);
}

View File

@ -0,0 +1,29 @@
#pragma once
#include <deerith/network/sync_variable.h>
#include <functional>
#include <vector>
namespace deerith
{
class user_t
{
public:
void *user_data = nullptr;
template <typename T>
void register_sync_variable(sync_variable_t<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 &)>);
}
template <typename T>
void deerith::user_t::register_sync_variable(sync_variable_t<T> *var)
{
buffers.push_back(var);
}

View File

@ -1,11 +0,0 @@
#pragma once
#include <functional>
namespace deerith
{
class Client
{
};
void define_client_callback(std::function<void(Client)>);
}

View File

@ -0,0 +1,6 @@
#include <deerith/universe/user.h>
namespace deerit
{
}

View File

@ -1,5 +1,4 @@
#include <deerith/universe.h>
#include <deerith/universe_definition.h>
#include <deerith/core/tick.h>
#include <deerith/core/log.h>

View File

@ -0,0 +1,13 @@
#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();

View File

@ -0,0 +1,25 @@
#include "common/common.h"
#include <deerith/universe/user.h>
#include <deerith/core/log.h>
void user_sync_variables_init(deerith::user_t &user)
{
deerith_trace("removing user data to new user");
sandbox_user_data_t *sandbox_user_data = new sandbox_user_data_t();
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::register_user_sync_variables_init_callback(user_sync_variables_init);
deerith::register_user_sync_variables_shutdown_callback(user_sync_variables_shutdown);
}