Sync variables

This commit is contained in:
Chewico 2026-10-09 18:56:21 +02:00
parent 59918b86b1
commit d592cef1a0
10 changed files with 94 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 // At
#define UNIVERSE_SIMULATION_TICK_FREQ 50 #define UNIVERSE_SIMULATION_TICK_FREQ 50
#define NETWORK_RELATIVE_UNIVERSE_TICK 2 #define NETWORK_RELATIVE_TICK 2
#define NETWORK_DELAY 6 #define NETWORK_DELAY 10
namespace deerith namespace deerith
{ {

View File

@ -0,0 +1,29 @@
#pragma once
#include <deerith/engine.h>
#include <glm/glm.hpp>
#include <array>
#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_SIZE> float_buffer;
};
class vec2_sync_data : public sync_buffer
{
public:
private:
std::array<glm::vec2, BUFFER_SIZE> buffer;
};
}

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,19 @@
#pragma once
#include <deerith/universe/sync_buffer.h>
#include <functional>
#include <vector>
namespace deerith
{
class user
{
public:
void *user_data = nullptr;
void add_sync_buffer(sync_buffer *sync_buffer);
private:
std::vector<sync_buffer *> sync_buffer_container;
};
}

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.h>
#include <deerith/universe_definition.h>
#include <deerith/core/tick.h> #include <deerith/core/tick.h>
#include <deerith/core/log.h> #include <deerith/core/log.h>

View File

@ -0,0 +1,13 @@
#pragma once
#include <deerith/universe/user.h>
#include <deerith/universe/sync_buffer.h>
#include <deerith/universe/universe_definition.h>
#include <string>
struct sandbox_user_data_t
{
deerith::vec2_sync_data position;
};
void define_user();

View File

@ -0,0 +1,16 @@
#include "common/common.h"
#include <deerith/universe/universe_definition.h>
#include <deerith/core/log.h>
void user_definition_function(deerith::user &user_data)
{
deerith_trace("adding 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);
}
void client_definition()
{
deerith::define_client_callback(user_definition_function);
}