Compare commits
2 Commits
59918b86b1
...
9d2785541d
| Author | SHA1 | Date | |
|---|---|---|---|
| 9d2785541d | |||
| d592cef1a0 |
@ -1,12 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <deerith/engine.h>
|
|
||||||
|
|
||||||
namespace deerith
|
|
||||||
{
|
|
||||||
template <typename T>
|
|
||||||
class SyncBuffer
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
public:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -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
|
||||||
{
|
{
|
||||||
|
|||||||
35
deerith_engine_core/include/deerith/network/sync_variable.h
Normal file
35
deerith_engine_core/include/deerith/network/sync_variable.h
Normal 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
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <deerith/universe/user.h>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
namespace deerith
|
||||||
|
{
|
||||||
|
|
||||||
|
void define_client_callback(std::function<void(user &)>);
|
||||||
|
}
|
||||||
29
deerith_engine_core/include/deerith/universe/user.h
Normal file
29
deerith_engine_core/include/deerith/universe/user.h
Normal 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);
|
||||||
|
}
|
||||||
@ -1,11 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <functional>
|
|
||||||
|
|
||||||
namespace deerith
|
|
||||||
{
|
|
||||||
class Client
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
void define_client_callback(std::function<void(Client)>);
|
|
||||||
}
|
|
||||||
6
deerith_engine_core/src/user.cpp
Normal file
6
deerith_engine_core/src/user.cpp
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include <deerith/universe/user.h>
|
||||||
|
|
||||||
|
namespace deerit
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@ -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>
|
||||||
|
|||||||
13
sandbox/src/common/common.h
Normal file
13
sandbox/src/common/common.h
Normal 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();
|
||||||
25
sandbox/src/common/user_definition.cpp
Normal file
25
sandbox/src/common/user_definition.cpp
Normal 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);
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user