Compare commits

..

2 Commits

Author SHA1 Message Date
535bc27c56 simple box render 2026-11-03 18:56:57 +01:00
59e939a1ea voxels are transmited 2026-10-29 22:05:11 +01:00
40 changed files with 1254 additions and 210 deletions

View File

@ -4,4 +4,132 @@
namespace deerith namespace deerith
{ {
glm::vec2 get_joystick_axes(int controller_id, int axe_id); glm::vec2 get_joystick_axes(int controller_id, int axe_id);
glm::vec2 get_mouse_delta();
bool get_key_down(int key_id);
void set_mouse_locked(bool locked);
bool get_mouse_button(int id);
} }
/* Printable keys */
#define DEERITH_KEY_SPACE 32
#define DEERITH_KEY_APOSTROPHE 39 /* ' */
#define DEERITH_KEY_COMMA 44 /* , */
#define DEERITH_KEY_MINUS 45 /* - */
#define DEERITH_KEY_PERIOD 46 /* . */
#define DEERITH_KEY_SLASH 47 /* / */
#define DEERITH_KEY_0 48
#define DEERITH_KEY_1 49
#define DEERITH_KEY_2 50
#define DEERITH_KEY_3 51
#define DEERITH_KEY_4 52
#define DEERITH_KEY_5 53
#define DEERITH_KEY_6 54
#define DEERITH_KEY_7 55
#define DEERITH_KEY_8 56
#define DEERITH_KEY_9 57
#define DEERITH_KEY_SEMICOLON 59 /* ; */
#define DEERITH_KEY_EQUAL 61 /* = */
#define DEERITH_KEY_A 65
#define DEERITH_KEY_B 66
#define DEERITH_KEY_C 67
#define DEERITH_KEY_D 68
#define DEERITH_KEY_E 69
#define DEERITH_KEY_F 70
#define DEERITH_KEY_G 71
#define DEERITH_KEY_H 72
#define DEERITH_KEY_I 73
#define DEERITH_KEY_J 74
#define DEERITH_KEY_K 75
#define DEERITH_KEY_L 76
#define DEERITH_KEY_M 77
#define DEERITH_KEY_N 78
#define DEERITH_KEY_O 79
#define DEERITH_KEY_P 80
#define DEERITH_KEY_Q 81
#define DEERITH_KEY_R 82
#define DEERITH_KEY_S 83
#define DEERITH_KEY_T 84
#define DEERITH_KEY_U 85
#define DEERITH_KEY_V 86
#define DEERITH_KEY_W 87
#define DEERITH_KEY_X 88
#define DEERITH_KEY_Y 89
#define DEERITH_KEY_Z 90
#define DEERITH_KEY_LEFT_BRACKET 91 /* [ */
#define DEERITH_KEY_BACKSLASH 92 /* \ */
#define DEERITH_KEY_RIGHT_BRACKET 93 /* ] */
#define DEERITH_KEY_GRAVE_ACCENT 96 /* ` */
#define DEERITH_KEY_WORLD_1 161 /* non-US #1 */
#define DEERITH_KEY_WORLD_2 162 /* non-US #2 */
/* Function keys */
#define DEERITH_KEY_ESCAPE 256
#define DEERITH_KEY_ENTER 257
#define DEERITH_KEY_TAB 258
#define DEERITH_KEY_BACKSPACE 259
#define DEERITH_KEY_INSERT 260
#define DEERITH_KEY_DELETE 261
#define DEERITH_KEY_RIGHT 262
#define DEERITH_KEY_LEFT 263
#define DEERITH_KEY_DOWN 264
#define DEERITH_KEY_UP 265
#define DEERITH_KEY_PAGE_UP 266
#define DEERITH_KEY_PAGE_DOWN 267
#define DEERITH_KEY_HOME 268
#define DEERITH_KEY_END 269
#define DEERITH_KEY_CAPS_LOCK 280
#define DEERITH_KEY_SCROLL_LOCK 281
#define DEERITH_KEY_NUM_LOCK 282
#define DEERITH_KEY_PRINT_SCREEN 283
#define DEERITH_KEY_PAUSE 284
#define DEERITH_KEY_F1 290
#define DEERITH_KEY_F2 291
#define DEERITH_KEY_F3 292
#define DEERITH_KEY_F4 293
#define DEERITH_KEY_F5 294
#define DEERITH_KEY_F6 295
#define DEERITH_KEY_F7 296
#define DEERITH_KEY_F8 297
#define DEERITH_KEY_F9 298
#define DEERITH_KEY_F10 299
#define DEERITH_KEY_F11 300
#define DEERITH_KEY_F12 301
#define DEERITH_KEY_F13 302
#define DEERITH_KEY_F14 303
#define DEERITH_KEY_F15 304
#define DEERITH_KEY_F16 305
#define DEERITH_KEY_F17 306
#define DEERITH_KEY_F18 307
#define DEERITH_KEY_F19 308
#define DEERITH_KEY_F20 309
#define DEERITH_KEY_F21 310
#define DEERITH_KEY_F22 311
#define DEERITH_KEY_F23 312
#define DEERITH_KEY_F24 313
#define DEERITH_KEY_F25 314
#define DEERITH_KEY_KP_0 320
#define DEERITH_KEY_KP_1 321
#define DEERITH_KEY_KP_2 322
#define DEERITH_KEY_KP_3 323
#define DEERITH_KEY_KP_4 324
#define DEERITH_KEY_KP_5 325
#define DEERITH_KEY_KP_6 326
#define DEERITH_KEY_KP_7 327
#define DEERITH_KEY_KP_8 328
#define DEERITH_KEY_KP_9 329
#define DEERITH_KEY_KP_DECIMAL 330
#define DEERITH_KEY_KP_DIVIDE 331
#define DEERITH_KEY_KP_MULTIPLY 332
#define DEERITH_KEY_KP_SUBTRACT 333
#define DEERITH_KEY_KP_ADD 334
#define DEERITH_KEY_KP_ENTER 335
#define DEERITH_KEY_KP_EQUAL 336
#define DEERITH_KEY_LEFT_SHIFT 340
#define DEERITH_KEY_LEFT_CONTROL 341
#define DEERITH_KEY_LEFT_ALT 342
#define DEERITH_KEY_LEFT_SUPER 343
#define DEERITH_KEY_RIGHT_SHIFT 344
#define DEERITH_KEY_RIGHT_CONTROL 345
#define DEERITH_KEY_RIGHT_ALT 346
#define DEERITH_KEY_RIGHT_SUPER 347
#define DEERITH_KEY_MENU 348

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <vector>
namespace deerith namespace deerith
{ {
@ -14,17 +15,32 @@ namespace deerith
~mesh_2d_t(); ~mesh_2d_t();
private: private:
unsigned int vao; unsigned int vao = 0;
unsigned int vbo; unsigned int vbo = 0;
unsigned int ebo; unsigned int ebo = 0;
size_t index_count; size_t index_count;
}; };
struct vertex_3d_t
{
glm::vec3 position;
glm::vec3 normal;
glm::vec2 uv;
};
struct mesh_3d_data_t
{
std::vector<vertex_3d_t> vertices;
std::vector<unsigned int> indices;
};
class mesh_3d_t class mesh_3d_t
{ {
public: public:
// obsolete
mesh_3d_t(const glm::vec3 *vertices, size_t vertex_size, const unsigned int *indices, size_t index_count); mesh_3d_t(const glm::vec3 *vertices, size_t vertex_size, const unsigned int *indices, size_t index_count);
mesh_3d_t(const mesh_3d_data_t &mesh_data);
void bind() const; void bind() const;
void draw() const; void draw() const;
@ -37,7 +53,8 @@ namespace deerith
unsigned int vbo; unsigned int vbo;
unsigned int ebo; unsigned int ebo;
size_t index_count; size_t index_count = 0;
size_t vertex_count; size_t vertex_count = 0;
}; };
} }

View File

@ -0,0 +1,73 @@
#pragma once
#include <glm/glm.hpp>
namespace deerith
{
glm::ivec3 voxel_direction_order[6] = {
glm::ivec3(-1, 0, 0),
glm::ivec3(1, 0, 0),
glm::ivec3(0, -1, 0),
glm::ivec3(0, 1, 0),
glm::ivec3(0, 0, -1),
glm::ivec3(0, 0, 1),
};
glm::vec3 voxel_direction_vertices[6][4] = {
// -X
{
{0, 0, 0},
{0, 0, 1},
{0, 1, 1},
{0, 1, 0},
},
// +X
{
{1, 0, 0},
{1, 1, 0},
{1, 1, 1},
{1, 0, 1},
},
// -Y
{
{0, 0, 0},
{1, 0, 0},
{1, 0, 1},
{0, 0, 1},
},
// +Y
{
{0, 1, 0},
{0, 1, 1},
{1, 1, 1},
{1, 1, 0},
},
// -Z
{
{0, 0, 0},
{0, 1, 0},
{1, 1, 0},
{1, 0, 0},
},
// +Z
{
{0, 0, 1},
{1, 0, 1},
{1, 1, 1},
{0, 1, 1},
},
};
uint32_t face_indices_order[6] = {
0,
1,
2,
0,
2,
3,
};
}

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <deerith/world/world_core.h> #include <deerith/world/world_core.h>
#include <glm/glm.hpp>
namespace deerith namespace deerith
{ {
@ -11,5 +12,8 @@ namespace deerith
bool is_world_running(); bool is_world_running();
void render_world(); void render_world();
void generate_cluster(glm::ivec2 cluster_id, size_t cluster_height_id);
void load_clusters_to_gpu();
client_t *get_server_client(); client_t *get_server_client();
} }

View File

@ -1,13 +0,0 @@
#pragma once
#include <deerith/engine.h>
#include <deerith/client/graphics/mesh.h>
namespace deerith
{
struct chunk_render_t
{
std::unique_ptr<mesh_2d_t> chunk_mesh;
void draw();
};
}

View File

@ -1,10 +1,28 @@
#version 330 core #version 330 core
uniform vec4 u_color = vec4(0.75, 0.8, 0.9, 1.0); in vec3 frag_position;
in vec3 frag_normal;
out vec4 frag_color; uniform vec3 u_color = vec3(1,1,1);
uniform vec3 u_light_direction = vec3(1, 3, 2);
out vec4 FragColor;
void main() void main()
{ {
frag_color = u_color;
// Face normal
vec3 normal = normalize(frag_normal);
// Directional lighting
vec3 light_direction = normalize(u_light_direction);
float diffuse = max(dot(normal, light_direction), 0.0);
// Ambient + diffuse
float ambient = 0.25;
float lighting = ambient + diffuse * 0.75;
vec3 color = u_color * lighting;
FragColor = vec4(color, 1.0);
} }

View File

@ -1,12 +1,21 @@
#version 330 core #version 330 core
layout (location = 0) in vec3 a_position; layout (location = 0) in vec3 a_position;
layout (location = 1) in vec3 a_normal;
uniform mat4 u_model; uniform mat4 u_model;
uniform mat4 u_view; uniform mat4 u_view;
uniform mat4 u_projection; uniform mat4 u_projection;
out vec3 frag_position;
out vec3 frag_normal;
void main() void main()
{ {
gl_Position = u_projection * u_view * u_model * vec4(a_position, 1.0); vec4 world_position = u_model * vec4(a_position, 1.0);
gl_Position = u_projection * u_view * world_position;
frag_position = world_position.xyz;
frag_normal = mat3(transpose(inverse(u_model))) * a_normal;
} }

View File

@ -1,5 +1,5 @@
#include <deerith/engine.h> #include <deerith/engine.h>
#include <deerith/client/network/network_internals.h> #include <deerith/client/internals/network.h>
void deerith::init_engine() void deerith::init_engine()
{ {

View File

@ -29,3 +29,69 @@ glm::vec2 deerith::get_joystick_axes(int controller_id, int axe_id)
return glm::vec2(corrected_axe_x, corrected_axe_y); return glm::vec2(corrected_axe_x, corrected_axe_y);
} }
glm::vec2 deerith::get_mouse_delta()
{
static double last_x = 0.0;
static double last_y = 0.0;
static bool first_call = true;
GLFWwindow *window = glfwGetCurrentContext();
if (!window)
{
return glm::vec2(0.0f);
}
double current_x, current_y;
glfwGetCursorPos(window, &current_x, &current_y);
if (first_call)
{
last_x = current_x;
last_y = current_y;
first_call = false;
return glm::vec2(0.0f);
}
glm::vec2 delta(
static_cast<float>(current_x - last_x),
static_cast<float>(last_y - current_y));
last_x = current_x;
last_y = current_y;
return delta;
}
bool deerith::get_key_down(int key_id)
{
GLFWwindow *window = glfwGetCurrentContext();
if (!window)
{
return false;
}
return glfwGetKey(window, key_id) == GLFW_PRESS;
}
bool deerith::get_mouse_button(int button)
{
GLFWwindow *window = glfwGetCurrentContext();
if (!window)
return false;
return glfwGetMouseButton(window, button) == GLFW_PRESS;
}
void deerith::set_mouse_locked(bool locked)
{
GLFWwindow *window = glfwGetCurrentContext();
if (!window)
return;
glfwSetInputMode(
window,
GLFW_CURSOR,
locked ? GLFW_CURSOR_DISABLED : GLFW_CURSOR_NORMAL);
}

View File

@ -1,5 +1,7 @@
#include <deerith/client/graphics/mesh.h> #include <deerith/client/graphics/mesh.h>
#include <deerith/engine.h>
#include <glad/gl.h> #include <glad/gl.h>
#include <cstddef>
deerith::mesh_2d_t::mesh_2d_t( deerith::mesh_2d_t::mesh_2d_t(
const glm::vec2 *vertices, const glm::vec2 *vertices,
@ -65,6 +67,51 @@ void deerith::mesh_2d_t::draw() const
nullptr); nullptr);
} }
deerith::mesh_3d_t::mesh_3d_t(const mesh_3d_data_t &mesh_data)
: index_count(mesh_data.indices.size()), vertex_count(mesh_data.vertices.size())
{
glGenVertexArrays(1, &vao);
glGenBuffers(1, &vbo);
glGenBuffers(1, &ebo);
glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(
GL_ARRAY_BUFFER,
mesh_data.vertices.size() * sizeof(vertex_3d_t),
mesh_data.vertices.data(),
GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
glBufferData(
GL_ELEMENT_ARRAY_BUFFER,
mesh_data.indices.size() * sizeof(unsigned int),
mesh_data.indices.data(),
GL_STATIC_DRAW);
glVertexAttribPointer(
0,
3,
GL_FLOAT,
GL_FALSE,
sizeof(vertex_3d_t),
(void *)offsetof(vertex_3d_t, position));
glVertexAttribPointer(
1,
3,
GL_FLOAT,
GL_FALSE,
sizeof(vertex_3d_t),
(void *)offsetof(vertex_3d_t, normal));
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glBindVertexArray(0);
}
deerith::mesh_3d_t::mesh_3d_t( deerith::mesh_3d_t::mesh_3d_t(
const glm::vec3 *vertices, const glm::vec3 *vertices,
std::size_t _vertex_count, std::size_t _vertex_count,
@ -92,13 +139,12 @@ deerith::mesh_3d_t::mesh_3d_t(
indices, indices,
GL_STATIC_DRAW); GL_STATIC_DRAW);
// Position: vec2
glVertexAttribPointer( glVertexAttribPointer(
0, 0,
3, 3,
GL_FLOAT, GL_FLOAT,
GL_FALSE, GL_FALSE,
3 * sizeof(float), sizeof(glm::vec3),
nullptr); nullptr);
glEnableVertexAttribArray(0); glEnableVertexAttribArray(0);

View File

@ -1,6 +1,6 @@
#include <deerith/client/graphics/window.h> #include <deerith/client/graphics/window.h>
#include <deerith/client/graphics/primitive_internals.h> #include <deerith/client/graphics/primitive_internals.h>
#include <deerith/client/network/network_internals.h> #include <deerith/client/internals/network.h>
#include <deerith/client/world.h> #include <deerith/client/world.h>
#include <glad/gl.h> #include <glad/gl.h>
@ -65,11 +65,13 @@ int deerith::init_window()
return -1; return -1;
} }
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);
glFrontFace(GL_CCW);
glDisable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
init_primitives(); init_primitives();
init_imgui(); init_imgui();
@ -90,6 +92,17 @@ bool deerith::begin_window_display()
return false; return false;
} }
int display_w, display_h;
glfwGetFramebufferSize(window, &display_w, &display_h);
glViewport(0, 0, display_w, display_h);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glClearColor(0.1f, 0.1f, 0.15f, 1.0f);
glClearDepth(1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame(); ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame(); ImGui::NewFrame();
@ -122,10 +135,6 @@ void deerith::finish_window_display()
frame_id++; frame_id++;
glfwSwapBuffers(window); glfwSwapBuffers(window);
glClearColor(0.1f, 0.1f, 0.15f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glClear(GL_DEPTH_BUFFER_BIT);
} }
void deerith::shutdown_window() void deerith::shutdown_window()

View File

@ -14,13 +14,6 @@ int main(int argc, const char **argv)
int port = 8080; int port = 8080;
cmdl("port", 8080) >> port; cmdl("port", 8080) >> port;
if (cmdl[{"-s", "--single"}] && !deerith::execute_client("../sandbox/SandboxServer", port))
{
deerith_error("could not start server");
deerith::shutdown_engine();
return 1;
}
std::this_thread::sleep_for(std::chrono::milliseconds(100)); std::this_thread::sleep_for(std::chrono::milliseconds(100));
if (deerith::connect_to_world("127.0.0.1", port)) if (deerith::connect_to_world("127.0.0.1", port))

View File

@ -6,7 +6,7 @@
#include <thread> #include <thread>
#include <memory> #include <memory>
#include <deerith/client/network/network_internals.h> #include <deerith/client/internals/network.h>
namespace deerith namespace deerith
{ {

View File

@ -0,0 +1,134 @@
#include <deerith/client/world.h>
#include <deerith/world/environment.h>
#include <deerith/client/internals/cluster_generation.h>
#include <vector>
#include <memory>
#include <deerith/client/graphics/mesh.h>
namespace deerith
{
cluster_voxel_type_id_data_t *cluster_data = nullptr;
glm::ivec2 cluster_id;
size_t cluster_height_id;
void generate_voxel(int x, int y, int z);
voxel_type_id_t get_cluster_voxel(int x, int y, int z);
std::unique_ptr<mesh_3d_t> test_mesh;
std::unique_ptr<mesh_3d_data_t> build_data;
}
void deerith::load_clusters_to_gpu()
{
if (build_data)
{
test_mesh = std::make_unique<mesh_3d_t>(*build_data);
build_data.reset();
}
}
void deerith::generate_cluster(glm::ivec2 _cluster_id, size_t _cluster_height_id)
{
if (build_data)
{
return;
}
build_data = std::make_unique<mesh_3d_data_t>();
cluster_data = get_cluster_voxel_type_id_raw_ponter(_cluster_id, _cluster_height_id);
cluster_id = _cluster_id;
cluster_height_id = _cluster_height_id;
if (cluster_data == nullptr)
{
deerith_error("cluster data is null and it should not generate_cluster");
return;
}
for (int x = 0; x < CLUSTER_SIZE; x++)
{
for (int y = 0; y < CLUSTER_SIZE; y++)
{
for (int z = 0; z < CLUSTER_SIZE; z++)
{
generate_voxel(x, y, z);
}
}
}
}
void deerith::generate_voxel(int x, int y, int z)
{
voxel_type_id_t cur_type_id = (*cluster_data)[x][y][z];
const voxel_type_t &cur_type = get_voxel_type(cur_type_id);
if (!cur_type.is_solid)
{
// nothing to build
return;
}
glm::vec3 voxel_position = glm::vec3(x, y, z) * VOXEL_SIZE;
for (int i = 0; i < 6; i++)
{
const int check_x = x + voxel_direction_order[i].x;
const int check_y = y + voxel_direction_order[i].y;
const int check_z = z + voxel_direction_order[i].z;
voxel_type_id_t check_voxel_id = get_cluster_voxel(check_x, check_y, check_z);
const voxel_type_t &check_voxel_type = get_voxel_type(check_voxel_id);
if (check_voxel_type.is_solid)
{
continue;
}
uint32_t starting_index = build_data->vertices.size();
// HEY BUILD FACE
for (int v = 0; v < 4; v++)
{
vertex_3d_t vertex = {
.position = voxel_position + voxel_direction_vertices[i][v] * VOXEL_SIZE,
.normal = voxel_direction_order[i],
};
build_data->vertices.push_back(vertex);
}
for (int index = 0; index < 6; index++)
{
build_data->indices.push_back(starting_index + face_indices_order[index]);
}
}
}
deerith::voxel_type_id_t deerith::get_cluster_voxel(int x, int y, int z)
{
bool in_bounds_check = true;
if (x < 0 || x >= CLUSTER_SIZE)
{
in_bounds_check = false;
}
if (y < 0 || y >= CLUSTER_SIZE)
{
in_bounds_check = false;
}
if (z < 0 || z >= CLUSTER_SIZE)
{
in_bounds_check = false;
}
if (in_bounds_check)
{
return (*cluster_data)[x][y][z];
}
glm::ivec3 coords(x + CLUSTER_SIZE * cluster_id.x,
y + (cluster_height_id - STARTING_CLUSTER_HEIGHT) * CLUSTER_SIZE,
z + cluster_id.y * CLUSTER_SIZE);
return get_voxel_id(coords);
}

View File

@ -5,11 +5,100 @@
#include <deerith/network/packets.h> #include <deerith/network/packets.h>
#include <deerith/world/components.h> #include <deerith/world/components.h>
#include <deerith/client/world/world_internals.h> #include <deerith/client/internals/world.h>
namespace deerith namespace deerith
{ {
void process_player_look(component_client_sync_character_t &sync);
void process_player_movement(component_client_sync_character_t &sync);
}
void deerith::process_player_look(component_client_sync_character_t &sync)
{
if (self_entity == entt::null)
return;
if (!is_windows_focused())
return;
bool looking = get_mouse_button(0);
set_mouse_locked(looking);
glm::vec2 mouse_delta = get_mouse_delta();
if (!looking)
return;
sync.player_look.x += mouse_delta.x * 0.1f;
sync.player_look.y -= mouse_delta.y * 0.1f;
sync.player_look.y = glm::clamp(
sync.player_look.y,
-89.0f,
89.0f);
}
void deerith::process_player_movement(component_client_sync_character_t &sync)
{
if (self_entity == entt::null)
{
return;
}
if (!is_windows_focused())
{
sync.move_input = glm::vec3(0.0f);
return;
}
glm::vec3 movement(0.0f);
// WASD
if (get_key_down(DEERITH_KEY_W))
{
movement.z += 1.0f;
}
if (get_key_down(DEERITH_KEY_S))
movement.z -= 1.0f;
if (get_key_down(DEERITH_KEY_D))
movement.x += 1.0f;
if (get_key_down(DEERITH_KEY_A))
movement.x -= 1.0f;
// Up / Down
if (get_key_down(DEERITH_KEY_SPACE))
movement.y += 1.0f;
if (get_key_down(DEERITH_KEY_LEFT_CONTROL))
movement.y -= 1.0f;
// Normalize to prevent faster diagonal movement
if (glm::length(movement) > 0.0f)
movement = glm::normalize(movement);
float yaw = glm::radians(sync.player_look.x);
glm::vec3 forward(
glm::sin(yaw),
0.0f,
glm::cos(yaw));
glm::vec3 right(
glm::cos(yaw),
0.0f,
-glm::sin(yaw));
sync.move_input =
right * movement.x +
glm::vec3(0.0f, movement.y, 0.0f) +
forward * movement.z;
sync.move_input = right * movement.x + glm::vec3(0.0f, movement.y, 0.0f) + forward * movement.z;
sync.position = sync.position.read_value() + sync.move_input.read_value() * 0.075f;
} }
void deerith::process_player_input() void deerith::process_player_input()
@ -17,23 +106,22 @@ void deerith::process_player_input()
if (self_entity == entt::null) if (self_entity == entt::null)
return; return;
glm::vec2 movment = get_joystick_axes(0, 0); auto &sync = get_component<component_client_sync_character_t>(self_entity);
if (!is_windows_focused())
{
movment = glm::vec2(0, 0);
}
component_player_sync_input_t &entity_sync_position = get_component<component_player_sync_input_t>(self_entity); packet_update_player_input_t packet{};
entity_sync_position.move_input = movment; process_player_look(sync);
entity_sync_position.position = entity_sync_position.position.read_value() + movment * 0.1f; process_player_movement(sync);
packet.input_transport.load(sync.move_input);
packet.position_transport.load(sync.position);
} }
void deerith::send_player_input() void deerith::send_player_input()
{ {
if (self_entity == entt::null) if (self_entity == entt::null)
return; return;
component_player_sync_input_t &entity_sync_position = get_component<component_player_sync_input_t>(self_entity); component_client_sync_character_t &entity_sync_position = get_component<component_client_sync_character_t>(self_entity);
packet_update_player_input_t packet{}; packet_update_player_input_t packet{};
packet.input_transport.load(entity_sync_position.move_input); packet.input_transport.load(entity_sync_position.move_input);

View File

@ -3,10 +3,12 @@
#include <deerith/network/packets.h> #include <deerith/network/packets.h>
#include <deerith/network/packets_voxel.h> #include <deerith/network/packets_voxel.h>
#include <deerith/world/components.h> #include <deerith/world/components.h>
#include <deerith/world/environment.h>
#include <deerith/client/world.h> #include <deerith/client/world.h>
#include <deerith/client/world/world_internals.h> #include <deerith/client/internals/world.h>
#include <deerith/client/network/network_internals.h> #include <deerith/client/internals/network.h>
void deerith::setup_base_protocols() void deerith::setup_base_protocols()
{ {
@ -16,6 +18,8 @@ void deerith::setup_base_protocols()
router_add_packet_processor<packet_update_entities_coordinates_t>(); router_add_packet_processor<packet_update_entities_coordinates_t>();
router_add_packet_processor<packet_destroy_entity_t>(); router_add_packet_processor<packet_destroy_entity_t>();
router_add_packet_processor<packet_voxel_data_definition_t>(); router_add_packet_processor<packet_voxel_data_definition_t>();
router_add_packet_processor<packet_surface_data_t>();
router_add_packet_processor<packet_cluster_data_t>();
} }
template <> template <>
@ -29,7 +33,7 @@ template <>
void deerith::process_packet(deerith::packet_create_player_entity_t &packet, client_t *client) void deerith::process_packet(deerith::packet_create_player_entity_t &packet, client_t *client)
{ {
self_entity = create_entity(); self_entity = create_entity();
add_component<component_player_sync_input_t>(self_entity); add_component<component_client_sync_character_t>(self_entity);
} }
template <> template <>
@ -89,3 +93,16 @@ void deerith::process_packet(deerith::packet_voxel_data_definition_t &packet, cl
set_voxel_materials(packet.voxel_materials); set_voxel_materials(packet.voxel_materials);
set_voxel_types(packet.voxel_types); set_voxel_types(packet.voxel_types);
} }
template <>
void deerith::process_packet(deerith::packet_surface_data_t &packet, client_t *client)
{
set_surface_height_raw_data(*packet.__surface_data, packet.surface_id);
}
template <>
void deerith::process_packet(deerith::packet_cluster_data_t &packet, client_t *client)
{
set_cluster_voxel_type_id_raw_data(*packet.__cluster_data, packet.surface_id, packet.cluster_height_id);
generate_cluster(packet.surface_id, packet.cluster_height_id);
}

View File

@ -1,8 +1,8 @@
#include <deerith/engine.h> #include <deerith/engine.h>
#include <deerith/client/world.h> #include <deerith/client/world.h>
#include <deerith/client/network/network_internals.h> #include <deerith/client/internals/network.h>
#include <deerith/client/world/world_internals.h> #include <deerith/client/internals/world.h>
#include <thread> #include <thread>
#include <memory> #include <memory>
@ -46,8 +46,6 @@ void deerith::world_simulation()
{ {
flush_network_events(); flush_network_events();
process_player_input();
if (get_world_tick() % 2 == 0) if (get_world_tick() % 2 == 0)
{ {
send_player_input(); send_player_input();

View File

@ -5,31 +5,55 @@
#include <deerith/client/graphics/mesh.h> #include <deerith/client/graphics/mesh.h>
#include <deerith/client/graphics/shader.h> #include <deerith/client/graphics/shader.h>
#include <deerith/client/graphics/primitive.h> #include <deerith/client/graphics/primitive.h>
#include <deerith/client/internals/world.h>
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp> #include <glm/gtc/quaternion.hpp>
namespace deerith
{
extern std::unique_ptr<mesh_3d_t> test_mesh;
}
void deerith::render_world() void deerith::render_world()
{ {
process_player_input();
load_clusters_to_gpu();
get_lit_shader()->set_vec3("u_color", glm::vec3(0.8f, 0.8f, 0.8f));
set_primitive_viewspace(glm::vec2(-10, -10), glm::vec2(10, 10)); set_primitive_viewspace(glm::vec2(-10, -10), glm::vec2(10, 10));
camera_t camera; camera_t camera;
camera.position = glm::vec3(0, 3, -10);
auto self_view = get_entity_registry().view<component_sync_coordinates_t, component_client_sync_character_t>();
for (auto [entity, sync_coords, client_sync_coords] : self_view.each())
{
camera.position = client_sync_coords.position.read_value();
float yaw = glm::radians(client_sync_coords.player_look.x);
float pitch = glm::radians(client_sync_coords.player_look.y);
glm::quat yaw_rotation = glm::angleAxis(yaw, glm::vec3(0, 1, 0));
glm::quat pitch_rotation = glm::angleAxis(pitch, glm::vec3(1, 0, 0));
camera.rotation = glm::normalize(yaw_rotation * pitch_rotation);
set_camera_to_shader(camera, get_lit_shader()); set_camera_to_shader(camera, get_lit_shader());
}
get_lit_shader()->use(); get_lit_shader()->use();
get_lit_shader()->set_vec4("u_color", glm::vec4(0.8f, 0.8f, 0.8f, 1)); get_lit_shader()->set_vec3("u_color", glm::vec3(0.8f, 0.8f, 0.8f));
set_transform_to_shader(glm::vec3(0, 0, 0), glm::identity<glm::quat>(), glm::vec3(1, 1, 1), get_lit_shader()); set_transform_to_shader(glm::vec3(0, 0, 0), glm::identity<glm::quat>(), glm::vec3(1, 1, 1), get_lit_shader());
get_grid_mesh()->draw_lines(); get_grid_mesh()->draw_lines();
auto entities_view = get_entity_registry().view<component_sync_coordinates_t>(entt::exclude<component_player_sync_input_t>); auto entities_view = get_entity_registry().view<component_sync_coordinates_t>(entt::exclude<component_client_sync_character_t>);
for (auto [entity, sync_coords] : entities_view.each()) for (auto [entity, sync_coords] : entities_view.each())
{ {
glm::vec2 chords; glm::vec3 chords;
if (sync_coords.position.read_synced(chords)) if (sync_coords.position.read_synced(chords))
{ {
glm::vec3 position = glm::vec3(chords.x, 0, chords.y); glm::vec3 position = chords;
glm::quat rotation = glm::identity<glm::quat>(); glm::quat rotation = glm::identity<glm::quat>();
glm::vec3 scale = glm::vec3(1, 1, 1); glm::vec3 scale = glm::vec3(1, 1, 1);
@ -42,19 +66,17 @@ void deerith::render_world()
} }
// we should expect only one registry // we should expect only one registry
auto self_view = get_entity_registry().view<component_sync_coordinates_t, component_player_sync_input_t>();
for (auto [entity, sync_coords, client_sync_coords] : self_view.each())
{
glm::vec2 user_pos = client_sync_coords.position.read_value(); if (test_mesh)
glm::vec3 position = glm::vec3(user_pos.x, 0, user_pos.y); {
get_lit_shader()->set_vec3("u_color", glm::vec3(0.9f, 0.9f, 0.9f));
glm::vec3 position = glm::vec3(0, 0, 0);
glm::quat rotation = glm::identity<glm::quat>(); glm::quat rotation = glm::identity<glm::quat>();
glm::vec3 scale = glm::vec3(1, 1, 1); glm::vec3 scale = glm::vec3(1, 1, 1);
get_lit_shader()->set_vec4("u_color", glm::vec4(0.8f, 0.8f, 0.8f, 1));
set_transform_to_shader(position, rotation, scale, get_lit_shader()); set_transform_to_shader(position, rotation, scale, get_lit_shader());
get_lit_shader()->use(); get_lit_shader()->use();
get_cube_mesh()->draw(); test_mesh->draw();
} }
} }

View File

@ -16,4 +16,7 @@ namespace deerith
bool execute_client(const char *server_executable_path, int port); bool execute_client(const char *server_executable_path, int port);
void shutdown_executing_servers(); void shutdown_executing_servers();
void start_chrono();
float get_chrono_ms();
} }

View File

@ -31,8 +31,8 @@ namespace deerith
static constexpr uint16_t packet_id = 3; static constexpr uint16_t packet_id = 3;
static constexpr bool reliable = false; static constexpr bool reliable = false;
sync_variable_transport_t<glm::vec2> position_transport; sync_variable_transport_t<glm::vec3> position_transport;
sync_variable_transport_t<glm::vec2> input_transport; sync_variable_transport_t<glm::vec3> input_transport;
template <typename Archive> template <typename Archive>
void serialize(Archive &archive) void serialize(Archive &archive)
@ -80,7 +80,7 @@ namespace deerith
static constexpr bool reliable = false; static constexpr bool reliable = false;
std::vector<id_t> entities_ids; std::vector<id_t> entities_ids;
std::vector<sync_variable_transport_t<glm::vec2>> positions_to_update; std::vector<sync_variable_transport_t<glm::vec3>> positions_to_update;
template <typename Archive> template <typename Archive>
void serialize(Archive &archive) void serialize(Archive &archive)

View File

@ -1,9 +1,13 @@
#pragma once #pragma once
#include <deerith/engine.h> #include <deerith/engine.h>
#include <deerith/world/voxels.h> #include <deerith/world/voxels.h>
#include <deerith/world/environment.h>
#include <cereal/types/vector.hpp> #include <cereal/types/vector.hpp>
#include <cereal/types/string.hpp> #include <cereal/types/string.hpp>
#include <cereal/types/array.hpp>
#include <memory>
// VOXEL SPECIFIC PACKETS 1xxx // VOXEL SPECIFIC PACKETS 1xxx
@ -24,4 +28,58 @@ namespace deerith
archive(voxel_types); archive(voxel_types);
} }
}; };
struct packet_surface_data_t
{
static constexpr uint16_t packet_id = 1002;
static constexpr bool reliable = true;
glm::ivec2 surface_id;
std::unique_ptr<surface_height_data_t> __surface_data;
template <typename Archive>
void save(Archive &archive) const
{
archive(surface_id);
archive(*__surface_data);
}
template <typename Archive>
void load(Archive &archive)
{
archive(surface_id);
__surface_data = std::make_unique<surface_height_data_t>();
archive(*__surface_data);
}
};
struct packet_cluster_data_t
{
static constexpr uint16_t packet_id = 1003;
static constexpr bool reliable = true;
glm::ivec2 surface_id;
size_t cluster_height_id;
std::unique_ptr<cluster_voxel_type_id_data_t> __cluster_data;
template <typename Archive>
void save(Archive &archive) const
{
archive(surface_id);
archive(cluster_height_id);
archive(*__cluster_data);
}
template <typename Archive>
void load(Archive &archive)
{
archive(surface_id);
archive(cluster_height_id);
__cluster_data = std::make_unique<cluster_voxel_type_id_data_t>();
archive(*__cluster_data);
}
};
} }

View File

@ -15,4 +15,17 @@ namespace cereal
{ {
archive(vec.x, vec.y, vec.z); archive(vec.x, vec.y, vec.z);
} }
template <class Archive>
void serialize(Archive &archive, glm::ivec3 &vec)
{
archive(vec.x, vec.y, vec.z);
}
template <class Archive>
void serialize(Archive &archive, glm::ivec2 &vec)
{
archive(vec.x, vec.y);
}
} }

View File

@ -16,14 +16,15 @@ namespace deerith
}; };
// struct for linking a entity to a client // struct for linking a entity to a client
struct component_player_sync_input_t struct component_client_sync_character_t
{ {
sync_variable_t<glm::vec2> move_input; sync_variable_t<glm::vec3> move_input;
sync_variable_t<glm::vec2> position; sync_variable_t<glm::vec3> position;
glm::vec2 player_look;
}; };
struct component_sync_coordinates_t struct component_sync_coordinates_t
{ {
sync_variable_t<glm::vec2> position; sync_variable_t<glm::vec3> position;
}; };
} }

View File

@ -1,16 +1,70 @@
#pragma once #pragma once
#include <deerith/engine.h>
#include <deerith/world/voxels.h> #include <deerith/world/voxels.h>
#include <glm/glm.hpp> #include <glm/glm.hpp>
namespace deerith namespace deerith
{ {
using voxel_coordinates_t = glm::ivec3; inline constexpr int CLUSTER_SIZE = 32;
using surface_coordinates_t = glm::ivec2; inline constexpr int MAX_CLUSTER_IN_SURFACE = 16;
inline constexpr int STARTING_CLUSTER_HEIGHT = -8;
// This sets the terrain layer for default comosition y > height -> 0; y <= height -> 1 inline constexpr float VOXEL_SIZE = 0.5f;
void set_surface_height(surface_coordinates_t surface_pos, int height);
void set_voxel(voxel_type_id_t voxel_id, voxel_coordinates_t coordinates);
voxel_type_id_t get_voxel_id(voxel_coordinates_t coordinates); using surface_height_t = int16_t;
const voxel_type_t &get_voxel(voxel_coordinates_t coordinates); using surface_height_data_t = std::array<std::array<surface_height_t, CLUSTER_SIZE>, CLUSTER_SIZE>;
using cluster_voxel_type_id_data_t = std::array<std::array<std::array<voxel_type_id_t, CLUSTER_SIZE>, CLUSTER_SIZE>, CLUSTER_SIZE>;
void set_surface_height(glm::ivec2 surface_pos, surface_height_t height);
void set_voxel(voxel_type_id_t voxel_id, glm::ivec3 coordinates);
voxel_type_id_t get_voxel_id(glm::ivec3 coordinates);
const voxel_type_t &get_voxel(glm::ivec3 coordinates);
void get_surface_height_raw_data(surface_height_data_t &data, glm::ivec2 surface_id);
void set_surface_height_raw_data(const surface_height_data_t &data, glm::ivec2 surface_id);
void get_cluster_voxel_type_id_raw_data(cluster_voxel_type_id_data_t &data, glm::ivec2 surface_id, size_t cluster_height_id);
void set_cluster_voxel_type_id_raw_data(const cluster_voxel_type_id_data_t &data, glm::ivec2 surface_id, size_t cluster_height_id);
cluster_voxel_type_id_data_t *get_cluster_voxel_type_id_raw_ponter(glm::ivec2 surface_id, size_t cluster_height_id);
int32_t get_cluster_last_tick_update(glm::ivec2 surface_id, size_t height_id);
}
// UTILS
namespace deerith
{
struct environment_settings_t
{
voxel_type_id_t default_air = 0;
voxel_type_id_t default_surface = 1;
surface_height_t default_height = 0;
};
struct surface_pos_hash_t
{
std::size_t operator()(const glm::ivec2 &id) const noexcept
{
const std::size_t h1 = std::hash<int>{}(id.x);
const std::size_t h2 = std::hash<int>{}(id.y);
return h1 ^ (h2 + 0x9e3779b9 + (h1 << 6) + (h1 >> 2));
}
};
struct world_pos_hash_t
{
std::size_t operator()(const glm::ivec3 &pos) const noexcept
{
const std::size_t h1 = std::hash<int>{}(pos.x);
const std::size_t h2 = std::hash<int>{}(pos.y);
const std::size_t h3 = std::hash<int>{}(pos.z);
std::size_t seed = h1;
seed ^= h2 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= h3 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
return seed;
}
};
} }

View File

@ -6,6 +6,8 @@
namespace deerith namespace deerith
{ {
uint32_t tick_id = 0; uint32_t tick_id = 0;
std::chrono::steady_clock::time_point __chrono_start;
} }
void deerith::set_tick(uint32_t v) void deerith::set_tick(uint32_t v)
@ -42,3 +44,13 @@ void deerith::wait_till_next_tick()
last_tick = clock::now(); last_tick = clock::now();
tick_id++; tick_id++;
} }
void deerith::start_chrono()
{
__chrono_start = std::chrono::steady_clock::now();
}
float deerith::get_chrono_ms()
{
return std::chrono::duration<float, std::milli>(std::chrono::steady_clock::now() - __chrono_start).count();
}

View File

@ -1,47 +1,47 @@
#include <deerith/world/environment.h> #include <deerith/world/environment.h>
#include <deerith/world/world_core.h>
#include <array> #include <array>
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <unordered_map>
#include <memory> #include <memory>
#include <vector> #include <vector>
#include <math.h> #include <math.h>
#define CLUSTER_SIZE 32
#define MAX_CLUSTER_IN_SURFACE 16
#define STARTING_CLUSTER_HEIGHT 8
namespace deerith namespace deerith
{ {
using surface_id_t = glm::ivec2;
using internal_voxel_id_t = glm::ivec3;
struct voxel_cluster_t struct voxel_cluster_t
{ {
voxel_type_id_t data[CLUSTER_SIZE][CLUSTER_SIZE][CLUSTER_SIZE] = {}; voxel_cluster_t() : last_update_tick_id(get_world_tick()) {}
uint32_t last_update_tick_id;
cluster_voxel_type_id_data_t data = {};
}; };
struct surface_t struct surface_t
{ {
surface_id_t surface_id; glm::ivec2 surface_id;
int layer_height[CLUSTER_SIZE][CLUSTER_SIZE] = {}; surface_height_data_t __layer_height = {};
std::unique_ptr<voxel_cluster_t> voxel_clusters[MAX_CLUSTER_IN_SURFACE] = {}; std::unique_ptr<voxel_cluster_t> voxel_clusters[MAX_CLUSTER_IN_SURFACE] = {};
}; };
std::vector<std::unique_ptr<surface_t>> surfaces; std::vector<std::unique_ptr<surface_t>> surfaces;
std::unordered_map<surface_id_t, size_t> surface_id_index_map; std::unordered_map<glm::ivec2, size_t, surface_pos_hash_t> surface_id_index_map;
voxel_type_id_t get_default_voxel(voxel_coordinates_t); voxel_type_id_t get_default_voxel(glm::ivec3);
surface_id_t get_surface_id(voxel_coordinates_t coords); glm::ivec2 get_surface_id(glm::ivec3 coords);
internal_voxel_id_t get_internal_voxel_coords(voxel_coordinates_t coords); glm::ivec2 get_surface_id(glm::ivec2 coords);
internal_voxel_id_t get_internal_voxel_coords(surface_coordinates_t coords, int height = 0); glm::ivec3 get_internal_voxel_coords(glm::ivec3 coords);
glm::ivec3 get_internal_voxel_coords(glm::ivec2 coords, int height = 0);
size_t get_voxel_cluster_height_id(int height); size_t get_voxel_cluster_height_id(int height);
surface_t *create_surface(surface_id_t); surface_t *create_surface(glm::ivec2);
voxel_cluster_t *create_cluster(glm::ivec2, size_t);
} }
deerith::surface_t *deerith::create_surface(surface_id_t surface_id) deerith::surface_t *deerith::create_surface(glm::ivec2 surface_id)
{ {
std::unique_ptr<surface_t> new_surface = std::make_unique<surface_t>(); std::unique_ptr<surface_t> new_surface = std::make_unique<surface_t>();
size_t surface_index = surfaces.size(); size_t surface_index = surfaces.size();
@ -52,7 +52,36 @@ deerith::surface_t *deerith::create_surface(surface_id_t surface_id)
return surfaces.back().get(); return surfaces.back().get();
} }
deerith::voxel_type_id_t get_default_voxel(deerith::voxel_coordinates_t coords) deerith::voxel_cluster_t *deerith::create_cluster(glm::ivec2 surface_id, size_t cluster_height_id)
{
surface_t *surface = nullptr;
if (surface_id_index_map.contains(surface_id))
{
size_t surface_index = surface_id_index_map[surface_id];
surface = surfaces[surface_index].get();
}
surface->voxel_clusters[cluster_height_id] = std::make_unique<voxel_cluster_t>();
voxel_cluster_t *cluster = surface->voxel_clusters[cluster_height_id].get();
for (int x = 0; x < CLUSTER_SIZE; x++)
{
for (int z = 0; z < CLUSTER_SIZE; z++)
{
int start_height = 0;
int end_height = surface->__layer_height[x][z] - ((int)cluster_height_id + STARTING_CLUSTER_HEIGHT) * CLUSTER_SIZE;
for (int y = start_height; y < end_height; y++)
{
cluster->data[x][y][z] = 1;
}
}
}
return cluster;
}
deerith::voxel_type_id_t deerith::get_default_voxel(glm::ivec3 coords)
{ {
if (coords.y > 0) if (coords.y > 0)
{ {
@ -78,10 +107,10 @@ size_t deerith::get_voxel_cluster_height_id(int height)
return cluster_height_id; return cluster_height_id;
} }
deerith::internal_voxel_id_t deerith::get_internal_voxel_coords(voxel_coordinates_t coords) glm::ivec3 deerith::get_internal_voxel_coords(glm::ivec3 coords)
{ {
// this will invert negatives coords but we don't mind // this will invert negatives coords but we don't mind
internal_voxel_id_t ic = {}; glm::ivec3 ic = {};
ic.x = std::abs(coords.x % (CLUSTER_SIZE)); ic.x = std::abs(coords.x % (CLUSTER_SIZE));
ic.y = std::abs(coords.y % (CLUSTER_SIZE)); ic.y = std::abs(coords.y % (CLUSTER_SIZE));
ic.z = std::abs(coords.z % (CLUSTER_SIZE)); ic.z = std::abs(coords.z % (CLUSTER_SIZE));
@ -89,10 +118,10 @@ deerith::internal_voxel_id_t deerith::get_internal_voxel_coords(voxel_coordinate
return ic; return ic;
} }
deerith::internal_voxel_id_t deerith::get_internal_voxel_coords(surface_coordinates_t coords, int height = 0) glm::ivec3 deerith::get_internal_voxel_coords(glm::ivec2 coords, int height)
{ {
// this will invert negatives coords but we don't mind // this will invert negatives coords but we don't mind
internal_voxel_id_t ic = {}; glm::ivec3 ic = {};
ic.x = std::abs(coords.x % (CLUSTER_SIZE)); ic.x = std::abs(coords.x % (CLUSTER_SIZE));
ic.y = std::abs(height % (CLUSTER_SIZE)); ic.y = std::abs(height % (CLUSTER_SIZE));
ic.z = std::abs(coords.y % (CLUSTER_SIZE)); ic.z = std::abs(coords.y % (CLUSTER_SIZE));
@ -100,18 +129,18 @@ deerith::internal_voxel_id_t deerith::get_internal_voxel_coords(surface_coordina
return ic; return ic;
} }
deerith::surface_id_t deerith::get_surface_id(voxel_coordinates_t coords) glm::ivec2 deerith::get_surface_id(glm::ivec3 coords)
{ {
surface_id_t surface_id = {}; glm::ivec2 surface_id = {};
surface_id.x = std::floor(static_cast<float>(coords.x) / static_cast<float>(CLUSTER_SIZE)); surface_id.x = std::floor(static_cast<float>(coords.x) / static_cast<float>(CLUSTER_SIZE));
surface_id.y = std::floor(static_cast<float>(coords.z) / static_cast<float>(CLUSTER_SIZE)); surface_id.y = std::floor(static_cast<float>(coords.z) / static_cast<float>(CLUSTER_SIZE));
return surface_id; return surface_id;
} }
deerith::surface_id_t deerith::get_surface_id(surface_coordinates_t coords) glm::ivec2 deerith::get_surface_id(glm::ivec2 coords)
{ {
surface_id_t surface_id = {}; glm::ivec2 surface_id = {};
surface_id.x = std::floor(static_cast<float>(coords.x) / static_cast<float>(CLUSTER_SIZE)); surface_id.x = std::floor(static_cast<float>(coords.x) / static_cast<float>(CLUSTER_SIZE));
surface_id.y = std::floor(static_cast<float>(coords.y) / static_cast<float>(CLUSTER_SIZE)); surface_id.y = std::floor(static_cast<float>(coords.y) / static_cast<float>(CLUSTER_SIZE));
@ -119,9 +148,9 @@ deerith::surface_id_t deerith::get_surface_id(surface_coordinates_t coords)
} }
// This sets the terrain layer for default comosition y > height -> 0; y <= height -> 1 // This sets the terrain layer for default comosition y > height -> 0; y <= height -> 1
void deerith::set_surface_height(surface_coordinates_t surface_pos, int height) void deerith::set_surface_height(glm::ivec2 surface_pos, surface_height_t height)
{ {
surface_id_t surface_id = get_surface_id(surface_pos); glm::ivec2 surface_id = get_surface_id(surface_pos);
surface_t *surface = nullptr; surface_t *surface = nullptr;
if (surface_id_index_map.contains(surface_id)) if (surface_id_index_map.contains(surface_id))
@ -135,13 +164,13 @@ void deerith::set_surface_height(surface_coordinates_t surface_pos, int height)
surface = create_surface(surface_id); surface = create_surface(surface_id);
} }
internal_voxel_id_t internal_voxel_id = get_internal_voxel_coords(surface_pos, height); glm::ivec3 internal_voxel_id = get_internal_voxel_coords(surface_pos, height);
surface->layer_height[internal_voxel_id.x][internal_voxel_id.z] = height; surface->__layer_height[internal_voxel_id.x][internal_voxel_id.z] = height;
} }
void deerith::set_voxel(voxel_type_id_t voxel_id, voxel_coordinates_t coordinates) void deerith::set_voxel(voxel_type_id_t voxel_id, glm::ivec3 coordinates)
{ {
surface_id_t surface_id = get_surface_id(coordinates); glm::ivec2 surface_id = get_surface_id(coordinates);
surface_t *surface = nullptr; surface_t *surface = nullptr;
if (surface_id_index_map.contains(surface_id)) if (surface_id_index_map.contains(surface_id))
@ -155,7 +184,7 @@ void deerith::set_voxel(voxel_type_id_t voxel_id, voxel_coordinates_t coordinate
surface = create_surface(surface_id); surface = create_surface(surface_id);
} }
internal_voxel_id_t internal_voxel_id = get_internal_voxel_coords(coordinates); glm::ivec3 internal_voxel_id = get_internal_voxel_coords(coordinates);
size_t cluster_height_id = get_voxel_cluster_height_id(coordinates.y); size_t cluster_height_id = get_voxel_cluster_height_id(coordinates.y);
if (cluster_height_id >= MAX_CLUSTER_IN_SURFACE) if (cluster_height_id >= MAX_CLUSTER_IN_SURFACE)
@ -167,16 +196,16 @@ void deerith::set_voxel(voxel_type_id_t voxel_id, voxel_coordinates_t coordinate
voxel_cluster_t *cluster = surface->voxel_clusters[cluster_height_id].get(); voxel_cluster_t *cluster = surface->voxel_clusters[cluster_height_id].get();
if (cluster == nullptr) if (cluster == nullptr)
{ {
surface->voxel_clusters[cluster_height_id] = std::make_unique<voxel_cluster_t>(); cluster = create_cluster(surface_id, cluster_height_id);
cluster = surface->voxel_clusters[cluster_height_id].get();
} }
cluster->last_update_tick_id = get_world_tick();
cluster->data[internal_voxel_id.x][internal_voxel_id.y][internal_voxel_id.z] = voxel_id; cluster->data[internal_voxel_id.x][internal_voxel_id.y][internal_voxel_id.z] = voxel_id;
} }
deerith::voxel_type_id_t deerith::get_voxel_id(voxel_coordinates_t coordinates) deerith::voxel_type_id_t deerith::get_voxel_id(glm::ivec3 coordinates)
{ {
surface_id_t surface_id = get_surface_id(coordinates); glm::ivec2 surface_id = get_surface_id(coordinates);
if (!surface_id_index_map.contains(surface_id)) if (!surface_id_index_map.contains(surface_id))
{ {
@ -197,11 +226,11 @@ deerith::voxel_type_id_t deerith::get_voxel_id(voxel_coordinates_t coordinates)
return get_default_voxel(coordinates); return get_default_voxel(coordinates);
} }
internal_voxel_id_t internal_voxel_id = get_internal_voxel_coords(coordinates); glm::ivec3 internal_voxel_id = get_internal_voxel_coords(coordinates);
voxel_cluster_t *cluster = surface->voxel_clusters[cluster_height_id].get(); voxel_cluster_t *cluster = surface->voxel_clusters[cluster_height_id].get();
if (cluster == nullptr) if (cluster == nullptr)
{ {
if (coordinates.y <= surface->layer_height[internal_voxel_id.x][internal_voxel_id.y]) if (coordinates.y <= surface->__layer_height[internal_voxel_id.x][internal_voxel_id.y])
{ {
return 1; return 1;
} }
@ -214,7 +243,161 @@ deerith::voxel_type_id_t deerith::get_voxel_id(voxel_coordinates_t coordinates)
return cluster->data[internal_voxel_id.x][internal_voxel_id.y][internal_voxel_id.z]; return cluster->data[internal_voxel_id.x][internal_voxel_id.y][internal_voxel_id.z];
} }
const deerith::voxel_type_t &deerith::get_voxel(voxel_coordinates_t coordinates) const deerith::voxel_type_t &deerith::get_voxel(glm::ivec3 coordinates)
{ {
return get_voxel_type(get_voxel_id(coordinates)); return get_voxel_type(get_voxel_id(coordinates));
} }
void deerith::get_surface_height_raw_data(surface_height_data_t &data, glm::ivec2 surface_pos)
{
glm::ivec2 surface_id = get_surface_id(surface_pos);
surface_t *surface = nullptr;
if (surface_id_index_map.contains(surface_id))
{
size_t surface_index = surface_id_index_map[surface_id];
surface = surfaces[surface_index].get();
}
if (surface == nullptr)
{
surface = create_surface(surface_id);
}
std::memcpy(data.data(), surface->__layer_height.data(), sizeof(data));
}
void deerith::set_surface_height_raw_data(const surface_height_data_t &data, glm::ivec2 surface_pos)
{
glm::ivec2 surface_id = get_surface_id(surface_pos);
surface_t *surface = nullptr;
if (surface_id_index_map.contains(surface_id))
{
size_t surface_index = surface_id_index_map[surface_id];
surface = surfaces[surface_index].get();
}
if (surface == nullptr)
{
surface = create_surface(surface_id);
}
std::memcpy(surface->__layer_height.data(), data.data(), sizeof(data));
}
int32_t deerith::get_cluster_last_tick_update(glm::ivec2 surface_id, size_t height_id)
{
if (!surface_id_index_map.contains(surface_id))
{
return -1;
}
size_t surface_index = surface_id_index_map[surface_id];
surface_t *surface = surfaces[surface_index].get();
if (surface == nullptr)
{
return -1;
}
if (height_id >= MAX_CLUSTER_IN_SURFACE)
{
return -1;
}
voxel_cluster_t *cluster = surface->voxel_clusters[height_id].get();
if (cluster == nullptr)
{
return -1;
}
return cluster->last_update_tick_id;
}
void deerith::get_cluster_voxel_type_id_raw_data(cluster_voxel_type_id_data_t &data, glm::ivec2 surface_id, size_t cluster_height_id)
{
if (cluster_height_id >= MAX_CLUSTER_IN_SURFACE)
{
deerith_warn("tried to read voxel data out of bounds");
return;
}
surface_t *surface = nullptr;
if (surface_id_index_map.contains(surface_id))
{
size_t surface_index = surface_id_index_map[surface_id];
surface = surfaces[surface_index].get();
}
if (surface == nullptr)
{
surface = create_surface(surface_id);
}
voxel_cluster_t *cluster = surface->voxel_clusters[cluster_height_id].get();
if (cluster == nullptr)
{
cluster = create_cluster(surface_id, cluster_height_id);
}
data = cluster->data;
}
void deerith::set_cluster_voxel_type_id_raw_data(const cluster_voxel_type_id_data_t &data, glm::ivec2 surface_id, size_t cluster_height_id)
{
if (cluster_height_id >= MAX_CLUSTER_IN_SURFACE)
{
deerith_warn("tried to write voxel data out of bounds");
return;
}
surface_t *surface = nullptr;
if (surface_id_index_map.contains(surface_id))
{
size_t surface_index = surface_id_index_map[surface_id];
surface = surfaces[surface_index].get();
}
if (surface == nullptr)
{
surface = create_surface(surface_id);
}
voxel_cluster_t *cluster = surface->voxel_clusters[cluster_height_id].get();
if (cluster == nullptr)
{
cluster = create_cluster(surface_id, cluster_height_id);
}
cluster->data = data;
cluster->last_update_tick_id = get_world_tick();
}
deerith::cluster_voxel_type_id_data_t *deerith::get_cluster_voxel_type_id_raw_ponter(glm::ivec2 surface_id, size_t cluster_height_id)
{
if (cluster_height_id >= MAX_CLUSTER_IN_SURFACE)
{
deerith_warn("tried to write voxel data out of bounds");
return nullptr;
}
surface_t *surface = nullptr;
if (surface_id_index_map.contains(surface_id))
{
size_t surface_index = surface_id_index_map[surface_id];
surface = surfaces[surface_index].get();
}
if (surface == nullptr)
{
return nullptr;
}
voxel_cluster_t *cluster = surface->voxel_clusters[cluster_height_id].get();
return &cluster->data;
}

View File

@ -1,14 +1,8 @@
#pragma once #pragma once
#include <enet/enet.h>
#include <vector>
namespace deerith namespace deerith
{ {
int init_network();
void shutdown_network();
bool init_server(int port); bool init_server(int port);
void flush_network_events(); void flush_network_events();
void load_base_protocols(); void load_base_protocols();
} }

View File

@ -4,17 +4,21 @@
namespace deerith namespace deerith
{ {
void update_players_characters(); // Client lifecycle
void client_connects(client_t *client); void client_connects(client_t *client);
void client_disconnects(client_t *client); void client_disconnects(client_t *client);
void send_entity_data(); // Entity management
void send_create_entity_to_all_clients(entity_t ent);
void send_create_entity_to_client(entity_t ent, client_t *client); void send_create_entity_to_client(entity_t ent, client_t *client);
void send_create_actual_entities_to_client(client_t *client); void send_create_entity_to_all_clients(entity_t ent);
void send_create_all_entities_to_client(client_t *client);
void send_voxel_data_to_client(client_t *client);
void send_delete_entity_to_all_clients(entity_t ent); void send_delete_entity_to_all_clients(entity_t ent);
// Player updates
void update_players_characters();
// Data synchronization
void send_entity_data();
void send_voxel_data_to_client(client_t *client);
void send_clients_environment_data();
} }

View File

@ -0,0 +1,7 @@
#pragma once
namespace deerith
{
int init_network();
void shutdown_network();
}

View File

@ -1,6 +1,6 @@
#include <deerith/engine.h> #include <deerith/engine.h>
#include <deerith/server/network/network_internals.h> #include <deerith/server/network.h>
namespace deerith namespace deerith
{ {

View File

@ -1,9 +1,13 @@
#include <deerith/core/log.h> #include <deerith/engine.h>
#include <deerith/network/client.h> #include <deerith/network/client.h>
#include <deerith/network/router.h> #include <deerith/network/router.h>
#include <deerith/network/packets.h> #include <deerith/network/packets.h>
#include <deerith/server/world.h> #include <deerith/server/world.h>
#include <deerith/server/network.h>
#include <deerith/server/internals/network.h>
#include <deerith/server/internals/world.h>
#include <enet/enet.h> #include <enet/enet.h>
@ -11,33 +15,15 @@
#include <vector> #include <vector>
#include <memory> #include <memory>
#include <deerith/server/network/network_internals.h>
#include <deerith/server/world/world_internals.h>
namespace deerith namespace deerith
{ {
ENetHost *server; ENetHost *server;
std::vector<std::unique_ptr<client_t>> clients; std::vector<std::unique_ptr<client_t>> clients;
void create_client(ENetPeer *peer); void create_client(ENetPeer *peer);
void delete_client(client_t *client); void delete_client(client_t *client);
} }
void deerith::delete_client(client_t *client)
{
auto it = std::find_if(
clients.begin(),
clients.end(),
[client](const std::unique_ptr<client_t> &ptr)
{ return ptr.get() == client; });
if (it != clients.end())
{
clients.erase(it);
}
}
bool deerith::init_server(int port) bool deerith::init_server(int port)
{ {
ENetAddress address = {0}; ENetAddress address = {0};
@ -112,3 +98,15 @@ void deerith::create_client(ENetPeer *peer)
clients.push_back(std::move(client)); clients.push_back(std::move(client));
client_connects((client_t *)peer->data); client_connects((client_t *)peer->data);
} }
void deerith::delete_client(client_t *client)
{
for (auto it = clients.begin(); it != clients.end(); ++it)
{
if (it->get() == client)
{
clients.erase(it);
return;
}
}
}

View File

@ -6,8 +6,8 @@
#include <deerith/server/world.h> #include <deerith/server/world.h>
#include <deerith/server/network/network_internals.h> #include <deerith/server/network.h>
#include <deerith/server/world/world_internals.h> #include <deerith/server/internals/world.h>
void deerith::client_connects(client_t *client) void deerith::client_connects(client_t *client)
{ {
@ -21,7 +21,7 @@ void deerith::client_connects(client_t *client)
// create entity player entity // create entity player entity
entity_t entity = create_entity(); entity_t entity = create_entity();
component_player_sync_input_t &position_sync = add_component<component_player_sync_input_t>(entity); component_client_sync_character_t &position_sync = add_component<component_client_sync_character_t>(entity);
packet_create_player_entity_t create_player_entity; packet_create_player_entity_t create_player_entity;
router_send_packet(create_player_entity, client); router_send_packet(create_player_entity, client);
@ -32,12 +32,12 @@ void deerith::client_connects(client_t *client)
send_create_entity_to_all_clients(entity); send_create_entity_to_all_clients(entity);
// we do this the last to avoid send_create_entity_to_all_clients send_create_actual_entities_to_client create the same entity for the player // we do this the last to avoid send_create_entity_to_all_clients send_create_all_entities_to_client create the same entity for the player
component_client_link_t &link = add_component<component_client_link_t>(entity); component_client_link_t &link = add_component<component_client_link_t>(entity);
client->entity_id = entity; client->entity_id = entity;
link.client = client; link.client = client;
send_create_actual_entities_to_client(client); send_create_all_entities_to_client(client);
} }
void deerith::client_disconnects(client_t *client) void deerith::client_disconnects(client_t *client)

View File

@ -1,18 +1,13 @@
#include <deerith/engine.h> #include <deerith/engine.h>
#include <deerith/world/components.h> #include <deerith/world/components.h>
#include <deerith/network/packets.h> #include <deerith/network/packets.h>
#include <deerith/network/router.h> #include <deerith/network/router.h>
#include <deerith/network/client.h> #include <deerith/network/client.h>
#include <deerith/server/world.h> #include <deerith/server/internals/world.h>
#include <deerith/server/internals/network.h>
#include <deerith/server/network/network_internals.h>
#include <deerith/server/world/world_internals.h>
namespace deerith
{
}
void deerith::load_base_protocols() void deerith::load_base_protocols()
{ {
router_add_packet_processor<packet_update_player_input_t>(); router_add_packet_processor<packet_update_player_input_t>();
@ -22,7 +17,7 @@ template <>
void deerith::process_packet(packet_update_player_input_t &packet, client_t *client) void deerith::process_packet(packet_update_player_input_t &packet, client_t *client)
{ {
entity_t entity = client->entity_id; entity_t entity = client->entity_id;
component_player_sync_input_t &sync_client = get_component<component_player_sync_input_t>(entity); component_client_sync_character_t &sync_client = get_component<component_client_sync_character_t>(entity);
packet.input_transport.recive(sync_client.move_input); packet.input_transport.recive(sync_client.move_input);
packet.position_transport.recive(sync_client.position); packet.position_transport.recive(sync_client.position);
@ -74,7 +69,7 @@ void deerith::send_delete_entity_to_all_clients(entity_t ent)
} }
} }
void deerith::send_create_actual_entities_to_client(client_t *client) void deerith::send_create_all_entities_to_client(client_t *client)
{ {
auto entities_view = get_entity_registry().view<component_network_id_t>(); auto entities_view = get_entity_registry().view<component_network_id_t>();

View File

@ -1,10 +1,23 @@
#include <deerith/server/world/world_internals.h> #include <deerith/server/internals/world.h>
#include <deerith/world/environment.h>
#include <deerith/network/packets_voxel.h> #include <deerith/network/packets_voxel.h>
#include <deerith/network/router.h> #include <deerith/network/router.h>
#include <unordered_map>
namespace deerith namespace deerith
{ {
struct component_client_environment_knowledge_t
{
std::unordered_map<glm::ivec2, bool, surface_pos_hash_t> surface_knowledge;
std::unordered_map<glm::ivec3, int32_t, world_pos_hash_t> cluster_knowledge;
};
void check_client_surface_knowledge(client_t *, component_client_environment_knowledge_t &knowledge, glm::ivec3 position);
bool check_client_cluster_knowledge(client_t *, component_client_environment_knowledge_t &knowledge, glm::ivec2 position);
void send_surface_info_to_client(client_t *, glm::ivec2);
void send_cluster_info_to_client(client_t *, glm::ivec2, size_t);
} }
void deerith::send_voxel_data_to_client(client_t *client) void deerith::send_voxel_data_to_client(client_t *client)
@ -15,3 +28,106 @@ void deerith::send_voxel_data_to_client(client_t *client)
router_send_packet(voxel_data_definition, client); router_send_packet(voxel_data_definition, client);
} }
void deerith::send_clients_environment_data()
{
// temp solution to assign this component to clients that don't have it
{
auto no_surface_knowledge_component_clients = get_entity_registry().view<component_client_link_t>(entt::exclude<component_client_environment_knowledge_t>);
for (auto [entity, client_link] : no_surface_knowledge_component_clients.each())
{
add_component<component_client_environment_knowledge_t>(entity);
}
}
auto update_surface_knowledge_to_clients = get_entity_registry().view<component_client_link_t, component_sync_coordinates_t, component_client_environment_knowledge_t>();
for (auto [entity, client_link, entity_position, surface_knowledge] : update_surface_knowledge_to_clients.each())
{
check_client_surface_knowledge(client_link.client, surface_knowledge, entity_position.position.read_value());
}
}
void deerith::check_client_surface_knowledge(client_t *client, component_client_environment_knowledge_t &knowledge, glm::ivec3 position)
{
const int surface_x = static_cast<int>(std::floor(position.x / CLUSTER_SIZE));
const int surface_z = static_cast<int>(std::floor(position.z / CLUSTER_SIZE));
const int SURFACE_RADIUS = 4;
for (int x = -SURFACE_RADIUS; x <= SURFACE_RADIUS; x++)
{
for (int z = -SURFACE_RADIUS; z <= SURFACE_RADIUS; z++)
{
glm::ivec2 surface_id = {surface_x + x, surface_z + z};
if (knowledge.surface_knowledge.contains(surface_id) && knowledge.surface_knowledge[surface_id] == true)
{
if (check_client_cluster_knowledge(client, knowledge, surface_id))
{
return;
}
}
if (!knowledge.surface_knowledge.contains(surface_id) || knowledge.surface_knowledge[surface_id] == false)
{
knowledge.surface_knowledge[surface_id] = true;
send_surface_info_to_client(client, surface_id);
return;
}
}
}
}
void deerith::send_surface_info_to_client(client_t *client, glm::ivec2 surface_id)
{
start_chrono();
packet_surface_data_t surface_data;
surface_data.surface_id = surface_id;
surface_data.__surface_data = std::make_unique<surface_height_data_t>();
get_surface_height_raw_data(*surface_data.__surface_data, surface_id);
router_send_packet(surface_data, client);
}
bool deerith::check_client_cluster_knowledge(client_t *client, component_client_environment_knowledge_t &knowledge, glm::ivec2 position)
{
for (int y = 0; y < MAX_CLUSTER_IN_SURFACE; y++)
{
int32_t cluster_last_update = get_cluster_last_tick_update(position, y);
if (cluster_last_update < 0)
{
continue;
}
glm::ivec3 cluster_pos = glm::ivec3(position.x, y, position.y);
int32_t actual_cluster_kknowledge = -1;
if (knowledge.cluster_knowledge.contains(cluster_pos))
{
actual_cluster_kknowledge = knowledge.cluster_knowledge[cluster_pos];
}
if (actual_cluster_kknowledge < cluster_last_update)
{
knowledge.cluster_knowledge[cluster_pos] = cluster_last_update;
send_cluster_info_to_client(client, position, y);
return true;
}
}
return false;
}
void deerith::send_cluster_info_to_client(client_t *client, glm::ivec2 surface_pos, size_t cluster_height_id)
{
start_chrono();
packet_cluster_data_t cluster_data;
cluster_data.surface_id = surface_pos;
cluster_data.cluster_height_id = cluster_height_id;
cluster_data.__cluster_data = std::make_unique<cluster_voxel_type_id_data_t>();
get_cluster_voxel_type_id_raw_data(*cluster_data.__cluster_data, surface_pos, cluster_height_id);
router_send_packet(cluster_data, client);
deerith_trace("sent cluster data to client in {}ms", get_chrono_ms());
}

View File

@ -1,37 +1,16 @@
#include <deerith/engine.h>
#include <deerith/server/world.h> #include <deerith/server/world.h>
#include <deerith/core/log.h>
#include <deerith/network/router.h>
#include <deerith/server/network/network_internals.h> #include <deerith/server/internals/world.h>
#include <deerith/server/world/world_internals.h> #include <deerith/server/internals/network.h>
#include <deerith/world/components.h>
#include <deerith/network/packets.h>
#include <csignal>
#include <atomic>
namespace deerith namespace deerith
{ {
int world_tick = 0; void server_loop();
void world_simulation();
std::atomic<bool> running = true;
void create_client(ENetPeer *peer);
void handle_signal(int signal);
}
void deerith::handle_signal(int signal)
{
if (signal == SIGTERM)
running = false;
} }
void deerith::run_world(int port) void deerith::run_world(int port)
{ {
std::signal(SIGTERM, handle_signal);
if (!init_server(port)) if (!init_server(port))
{ {
deerith_error("could not init server"); deerith_error("could not init server");
@ -39,13 +18,13 @@ void deerith::run_world(int port)
} }
deerith_trace("server init on port {}", port); deerith_trace("server init on port {}", port);
while (running) while (true)
{ {
world_simulation(); server_loop();
} }
} }
void deerith::world_simulation() void deerith::server_loop()
{ {
flush_network_events(); flush_network_events();
@ -54,6 +33,8 @@ void deerith::world_simulation()
if (get_world_tick() % 2 == 0) if (get_world_tick() % 2 == 0)
{ {
send_clients_environment_data();
send_entity_data(); send_entity_data();
} }

View File

@ -1,17 +1,16 @@
#include <deerith/server/world/world_internals.h> #include <deerith/server/internals/world.h>
#include <deerith/server/world.h>
#include <deerith/world/components.h> #include <deerith/world/components.h>
#include <deerith/network/packets.h> #include <deerith/network/packets.h>
#include <deerith/network/router.h> #include <deerith/network/router.h>
void deerith::update_players_characters() void deerith::update_players_characters()
{ {
auto view = get_entity_registry().view<component_player_sync_input_t, component_client_link_t, component_sync_coordinates_t>(); auto view = get_entity_registry().view<component_client_sync_character_t, component_client_link_t, component_sync_coordinates_t>();
for (auto [entity, position_input, client, sync_coords] : view.each()) for (auto [entity, position_input, client, sync_coords] : view.each())
{ {
glm::vec2 ps{}; glm::vec3 ps{};
if (position_input.position.read_synced(ps)) if (position_input.position.read_synced(ps))
{ {
sync_coords.position = ps; sync_coords.position = ps;
@ -32,7 +31,7 @@ void deerith::send_entity_data()
{ {
sync_entities_coordinates.entities_ids.push_back(network_id.network_id); sync_entities_coordinates.entities_ids.push_back(network_id.network_id);
sync_entities_coordinates.positions_to_update.push_back({}); sync_entities_coordinates.positions_to_update.push_back({});
sync_variable_transport_t<glm::vec2> &position_trasport = sync_entities_coordinates.positions_to_update.back(); sync_variable_transport_t<glm::vec3> &position_trasport = sync_entities_coordinates.positions_to_update.back();
position_trasport.load(sync_coords.position); position_trasport.load(sync_coords.position);
} }

View File

@ -0,0 +1,17 @@
#include "world.h"
#include <deerith/world/environment.h>
namespace deerith
{
}
void sandbox::build_world()
{
deerith::set_surface_height(glm::ivec2(2, 2), 5);
deerith::set_surface_height(glm::ivec2(2, 3), 7);
deerith::set_surface_height(glm::ivec2(2, 1), 6);
deerith::set_voxel(1, glm::vec3(2, 2, 2));
deerith::set_voxel(1, glm::vec3(3, 4, 1));
}

View File

@ -18,7 +18,7 @@ int main(int argc, const char **argv)
sandbox::define_voxel_materials(); sandbox::define_voxel_materials();
sandbox::define_voxels_types(); sandbox::define_voxels_types();
// sandbox::build_world(); sandbox::build_world();
#ifdef DEBUG #ifdef DEBUG
if (cmdl[{"-s", "--single"}] && !deerith::execute_client("../deerith_client/DeerithClient", port)) if (cmdl[{"-s", "--single"}] && !deerith::execute_client("../deerith_client/DeerithClient", port))