Transform to server only program
This commit is contained in:
parent
0f4d7a721d
commit
28289b5d56
@ -1,52 +1,37 @@
|
|||||||
find_package(glfw3 REQUIRED)
|
find_package(glfw3 CONFIG REQUIRED)
|
||||||
find_package(OpenGL REQUIRED)
|
find_package(OpenGL REQUIRED)
|
||||||
|
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
pkg_check_modules(IMGUI REQUIRED imgui)
|
|
||||||
|
|
||||||
|
pkg_check_modules(IMGUI REQUIRED IMPORTED_TARGET imgui)
|
||||||
|
|
||||||
add_library(DeerithClient)
|
file(GLOB_RECURSE DEERITH_SOURCES
|
||||||
|
|
||||||
file(GLOB_RECURSE deerith_SOURCES
|
|
||||||
CONFIGURE_DEPENDS
|
CONFIGURE_DEPENDS
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp
|
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp"
|
||||||
)
|
)
|
||||||
|
|
||||||
target_sources(DeerithClient
|
add_executable(DeerithClient
|
||||||
PRIVATE
|
${DEERITH_SOURCES}
|
||||||
${deerith_SOURCES}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(DeerithClient
|
target_include_directories(DeerithClient
|
||||||
PRIVATE
|
PRIVATE
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
"${CMAKE_CURRENT_SOURCE_DIR}/src"
|
||||||
PUBLIC
|
"${CMAKE_CURRENT_SOURCE_DIR}/include"
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
|
||||||
${IMGUI_INCLUDE_DIRS}
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(DeerithClient
|
|
||||||
PRIVATE
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(DeerithClient
|
target_link_libraries(DeerithClient
|
||||||
PUBLIC
|
PRIVATE
|
||||||
DeerithCore
|
DeerithCore
|
||||||
OpenGL::GL
|
OpenGL::GL
|
||||||
glfw
|
glfw
|
||||||
${IMGUI_LIBRARIES}
|
PkgConfig::IMGUI
|
||||||
)
|
)
|
||||||
|
|
||||||
add_custom_target(DeerithClientShaders ALL
|
add_custom_target(DeerithClientShaders ALL
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders
|
"${CMAKE_CURRENT_SOURCE_DIR}/shaders"
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/shaders
|
"${CMAKE_CURRENT_BINARY_DIR}/shaders"
|
||||||
)
|
COMMENT "Copying DeerithClient shaders"
|
||||||
|
|
||||||
target_compile_definitions(DeerithClient
|
|
||||||
PUBLIC
|
|
||||||
DEERITH_CLIENT
|
|
||||||
)
|
)
|
||||||
|
|
||||||
add_dependencies(DeerithClient DeerithClientShaders)
|
add_dependencies(DeerithClient DeerithClientShaders)
|
||||||
@ -28,6 +28,7 @@ namespace deerith
|
|||||||
|
|
||||||
void bind() const;
|
void bind() const;
|
||||||
void draw() const;
|
void draw() const;
|
||||||
|
void draw_lines() const;
|
||||||
|
|
||||||
~mesh_3d_t();
|
~mesh_3d_t();
|
||||||
|
|
||||||
@ -37,5 +38,6 @@ namespace deerith
|
|||||||
unsigned int ebo;
|
unsigned int ebo;
|
||||||
|
|
||||||
size_t index_count;
|
size_t index_count;
|
||||||
|
size_t vertex_count;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -13,4 +13,5 @@ namespace deerith
|
|||||||
|
|
||||||
shader_t *get_lit_shader();
|
shader_t *get_lit_shader();
|
||||||
mesh_3d_t *get_cube_mesh();
|
mesh_3d_t *get_cube_mesh();
|
||||||
|
mesh_3d_t *get_grid_mesh();
|
||||||
}
|
}
|
||||||
@ -1,6 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "glm/glm.hpp"
|
#include "glm/glm.hpp"
|
||||||
|
|
||||||
|
#define GRID_SIZE 21
|
||||||
|
|
||||||
namespace deerith
|
namespace deerith
|
||||||
{
|
{
|
||||||
void init_primitives();
|
void init_primitives();
|
||||||
@ -1,12 +1,7 @@
|
|||||||
#include <deerith/engine.h>
|
#include <deerith/engine.h>
|
||||||
#include <deerith/core/log.h>
|
#include <deerith/core/log.h>
|
||||||
|
|
||||||
#include "network/network_internals.h"
|
#include <deerith/network/network_internals.h>
|
||||||
|
|
||||||
namespace deerith
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void deerith::init_engine()
|
void deerith::init_engine()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -67,10 +67,10 @@ void deerith::mesh_2d_t::draw() const
|
|||||||
|
|
||||||
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,
|
||||||
const unsigned int *indices,
|
const unsigned int *indices,
|
||||||
std::size_t index_count)
|
std::size_t _index_count)
|
||||||
: index_count(index_count)
|
: index_count(_index_count), vertex_count(_vertex_count)
|
||||||
{
|
{
|
||||||
glGenVertexArrays(1, &vao);
|
glGenVertexArrays(1, &vao);
|
||||||
glGenBuffers(1, &vbo);
|
glGenBuffers(1, &vbo);
|
||||||
@ -121,10 +121,15 @@ void deerith::mesh_3d_t::bind() const
|
|||||||
void deerith::mesh_3d_t::draw() const
|
void deerith::mesh_3d_t::draw() const
|
||||||
{
|
{
|
||||||
glBindVertexArray(vao);
|
glBindVertexArray(vao);
|
||||||
|
|
||||||
glDrawElements(
|
glDrawElements(
|
||||||
GL_TRIANGLES,
|
GL_TRIANGLES,
|
||||||
static_cast<GLsizei>(index_count),
|
static_cast<GLsizei>(index_count),
|
||||||
GL_UNSIGNED_INT,
|
GL_UNSIGNED_INT,
|
||||||
nullptr);
|
nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void deerith::mesh_3d_t::draw_lines() const
|
||||||
|
{
|
||||||
|
glBindVertexArray(vao);
|
||||||
|
glDrawArrays(GL_LINES, 0, vertex_count);
|
||||||
|
}
|
||||||
@ -1,7 +1,7 @@
|
|||||||
#include "primitive_internals.h"
|
#include <deerith/graphics/primitive_internals.h>
|
||||||
#include "deerith/graphics/primitive.h"
|
#include <deerith/graphics/primitive.h>
|
||||||
#include <deerith/graphics/shader.h>
|
#include <deerith/graphics/shader.h>
|
||||||
#include "deerith/graphics/mesh.h"
|
#include <deerith/graphics/mesh.h>
|
||||||
#include <deerith/engine.h>
|
#include <deerith/engine.h>
|
||||||
|
|
||||||
#include "glm/glm.hpp"
|
#include "glm/glm.hpp"
|
||||||
@ -12,6 +12,7 @@
|
|||||||
#include <glm/gtc/type_ptr.hpp>
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
|
|
||||||
#include <glad/gl.h>
|
#include <glad/gl.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace deerith
|
namespace deerith
|
||||||
{
|
{
|
||||||
@ -20,7 +21,27 @@ namespace deerith
|
|||||||
|
|
||||||
std::unique_ptr<shader_t> lit_shader;
|
std::unique_ptr<shader_t> lit_shader;
|
||||||
std::unique_ptr<mesh_3d_t> cube_mesh;
|
std::unique_ptr<mesh_3d_t> cube_mesh;
|
||||||
|
std::unique_ptr<mesh_3d_t> grid_mesh;
|
||||||
|
|
||||||
|
void create_grid_mesh();
|
||||||
|
}
|
||||||
|
|
||||||
|
void deerith::create_grid_mesh()
|
||||||
|
{
|
||||||
|
const size_t vertex_count = GRID_SIZE * 4;
|
||||||
|
std::vector<glm::vec3> grid_vertices; // size will GRID_SIZE * 4
|
||||||
|
for (int i = 0; i < GRID_SIZE; i++)
|
||||||
|
{
|
||||||
|
float relative_position = static_cast<float>(i) / static_cast<float>(GRID_SIZE - 1);
|
||||||
|
float absolute_position = (relative_position * 2.0f - 1.0f) * static_cast<float>(GRID_SIZE);
|
||||||
|
grid_vertices.push_back(glm::vec3(absolute_position, 0, -GRID_SIZE));
|
||||||
|
grid_vertices.push_back(glm::vec3(absolute_position, 0, GRID_SIZE));
|
||||||
|
|
||||||
|
grid_vertices.push_back(glm::vec3(-GRID_SIZE, 0, absolute_position));
|
||||||
|
grid_vertices.push_back(glm::vec3(GRID_SIZE, 0, absolute_position));
|
||||||
|
}
|
||||||
|
|
||||||
|
grid_mesh = std::make_unique<mesh_3d_t>(&grid_vertices[0], vertex_count, nullptr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void deerith::init_primitives()
|
void deerith::init_primitives()
|
||||||
@ -35,6 +56,8 @@ void deerith::init_primitives()
|
|||||||
"../deerith_engine_client/shaders/lit.frag.glsl");
|
"../deerith_engine_client/shaders/lit.frag.glsl");
|
||||||
|
|
||||||
cube_mesh = std::make_unique<mesh_3d_t>(cube_vertices, 8, cube_indices, 36); // 6 faces * 2 * 3
|
cube_mesh = std::make_unique<mesh_3d_t>(cube_vertices, 8, cube_indices, 36); // 6 faces * 2 * 3
|
||||||
|
|
||||||
|
create_grid_mesh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void deerith::shutdown_primitives()
|
void deerith::shutdown_primitives()
|
||||||
@ -47,6 +70,8 @@ void deerith::shutdown_primitives()
|
|||||||
lit_shader.reset();
|
lit_shader.reset();
|
||||||
cube_mesh.release();
|
cube_mesh.release();
|
||||||
cube_mesh.reset();
|
cube_mesh.reset();
|
||||||
|
grid_mesh.release();
|
||||||
|
grid_mesh.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void deerith::set_primitive_viewspace(glm::vec2 start_viewspace, glm::vec2 end_viewspace)
|
void deerith::set_primitive_viewspace(glm::vec2 start_viewspace, glm::vec2 end_viewspace)
|
||||||
@ -98,3 +123,8 @@ deerith::mesh_3d_t *deerith::get_cube_mesh()
|
|||||||
{
|
{
|
||||||
return cube_mesh.get();
|
return cube_mesh.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deerith::mesh_3d_t *deerith::get_grid_mesh()
|
||||||
|
{
|
||||||
|
return grid_mesh.get();
|
||||||
|
}
|
||||||
@ -1,6 +1,6 @@
|
|||||||
#include "deerith/graphics/window.h"
|
#include "deerith/graphics/window.h"
|
||||||
#include "primitive_internals.h"
|
#include <deerith/graphics/primitive_internals.h>
|
||||||
#include "../network/network_internals.h"
|
#include <deerith/network/network_internals.h>
|
||||||
#include <deerith/world.h>
|
#include <deerith/world.h>
|
||||||
|
|
||||||
#include <glad/gl.h>
|
#include <glad/gl.h>
|
||||||
@ -68,8 +68,8 @@ int deerith::init_window()
|
|||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
glDisable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glDisable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
|
|
||||||
init_primitives();
|
init_primitives();
|
||||||
init_imgui();
|
init_imgui();
|
||||||
@ -125,6 +125,7 @@ void deerith::finish_window_display()
|
|||||||
|
|
||||||
glClearColor(0.1f, 0.1f, 0.15f, 1.0f);
|
glClearColor(0.1f, 0.1f, 0.15f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void deerith::shutdown_window()
|
void deerith::shutdown_window()
|
||||||
|
|||||||
@ -3,23 +3,18 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#include <args/argh.h>
|
#include <args/argh.h>
|
||||||
|
|
||||||
#ifdef DEERITH_CLIENT
|
|
||||||
#include <deerith/graphics/window.h>
|
#include <deerith/graphics/window.h>
|
||||||
#endif
|
|
||||||
|
|
||||||
int main(int argc, const char **argv)
|
int main(int argc, const char **argv)
|
||||||
{
|
{
|
||||||
deerith::init_engine();
|
deerith::init_engine();
|
||||||
auto cmdl = argh::parser(argc, argv);
|
auto cmdl = argh::parser(argc, argv);
|
||||||
|
|
||||||
|
// set up world
|
||||||
int port = 8080;
|
int port = 8080;
|
||||||
cmdl("port", 8080) >> port;
|
cmdl("port", 8080) >> port;
|
||||||
#ifdef DEERITH_SERVER
|
|
||||||
deerith::run_world(8080);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef DEERITH_CLIENT
|
if (cmdl[{"-s", "--single"}] && !deerith::execute_client("../sandbox/SandboxServer", port))
|
||||||
if (cmdl[{"-s", "--single"}] && !deerith::execute_server("./SandboxServer", port))
|
|
||||||
{
|
{
|
||||||
deerith_error("could not start server");
|
deerith_error("could not start server");
|
||||||
deerith::shutdown_engine();
|
deerith::shutdown_engine();
|
||||||
@ -41,7 +36,6 @@ int main(int argc, const char **argv)
|
|||||||
|
|
||||||
deerith::shutdown_window();
|
deerith::shutdown_window();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
deerith::shutdown_executing_servers();
|
deerith::shutdown_executing_servers();
|
||||||
deerith::shutdown_engine();
|
deerith::shutdown_engine();
|
||||||
@ -6,7 +6,7 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "network_internals.h"
|
#include <deerith/network/network_internals.h>
|
||||||
|
|
||||||
namespace deerith
|
namespace deerith
|
||||||
{
|
{
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
#include <deerith/network/packets.h>
|
#include <deerith/network/packets.h>
|
||||||
#include <deerith/world/components.h>
|
#include <deerith/world/components.h>
|
||||||
|
|
||||||
#include "world/world_internals.h"
|
#include <deerith/world/world_internals.h>
|
||||||
|
|
||||||
namespace deerith
|
namespace deerith
|
||||||
{
|
{
|
||||||
|
|||||||
@ -4,8 +4,8 @@
|
|||||||
#include <deerith/world/components.h>
|
#include <deerith/world/components.h>
|
||||||
#include <deerith/world.h>
|
#include <deerith/world.h>
|
||||||
|
|
||||||
#include "world/world_internals.h"
|
#include <deerith/world/world_internals.h>
|
||||||
#include "network/network_internals.h"
|
#include <deerith/network/network_internals.h>
|
||||||
|
|
||||||
void deerith::setup_base_protocols()
|
void deerith::setup_base_protocols()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
#include <deerith/engine.h>
|
#include <deerith/engine.h>
|
||||||
#include <deerith/world.h>
|
#include <deerith/world.h>
|
||||||
|
|
||||||
#include "network/network_internals.h"
|
#include <deerith/network/network_internals.h>
|
||||||
#include "world/world_internals.h"
|
#include <deerith/world/world_internals.h>
|
||||||
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|||||||
@ -13,23 +13,29 @@ void deerith::render_world()
|
|||||||
{
|
{
|
||||||
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.position = glm::vec3(0, 3, -10);
|
||||||
|
set_camera_to_shader(camera, get_lit_shader());
|
||||||
|
|
||||||
|
get_lit_shader()->use();
|
||||||
|
get_lit_shader()->set_vec4("u_color", glm::vec4(0.8f, 0.8f, 0.8f, 1));
|
||||||
|
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();
|
||||||
|
|
||||||
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_player_sync_input_t>);
|
||||||
for (auto [entity, sync_coords] : entities_view.each())
|
for (auto [entity, sync_coords] : entities_view.each())
|
||||||
{
|
{
|
||||||
glm::vec2 chords;
|
glm::vec2 chords;
|
||||||
if (sync_coords.position.read_synced(chords))
|
if (sync_coords.position.read_synced(chords))
|
||||||
{
|
{
|
||||||
camera_t camera;
|
|
||||||
camera.position = glm::vec3(0, 0, -10);
|
|
||||||
|
|
||||||
glm::vec3 position = glm::vec3(chords.x, 0, chords.y);
|
glm::vec3 position = glm::vec3(chords.x, 0, chords.y);
|
||||||
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);
|
||||||
|
|
||||||
set_camera_to_shader(camera, get_lit_shader());
|
get_lit_shader()->set_vec4("u_color", glm::vec4(1, 0.4f, 0.6f, 1));
|
||||||
set_transform_to_shader(position, rotation, scale, get_lit_shader());
|
set_transform_to_shader(position, rotation, scale, get_lit_shader());
|
||||||
|
|
||||||
get_lit_shader()->set_vec4("u_color", glm::vec4(1, 0.4f, 0.6f, 1));
|
|
||||||
get_lit_shader()->use();
|
get_lit_shader()->use();
|
||||||
get_cube_mesh()->draw();
|
get_cube_mesh()->draw();
|
||||||
}
|
}
|
||||||
@ -40,16 +46,12 @@ void deerith::render_world()
|
|||||||
for (auto [entity, sync_coords, client_sync_coords] : self_view.each())
|
for (auto [entity, sync_coords, client_sync_coords] : self_view.each())
|
||||||
{
|
{
|
||||||
|
|
||||||
camera_t camera;
|
|
||||||
camera.position = glm::vec3(0, 0, -10);
|
|
||||||
|
|
||||||
get_lit_shader()->set_vec4("u_color", glm::vec4(0.8f, 0.8f, 0.8f, 1));
|
|
||||||
glm::vec2 user_pos = client_sync_coords.position.read_value();
|
glm::vec2 user_pos = client_sync_coords.position.read_value();
|
||||||
glm::vec3 position = glm::vec3(user_pos.x, 0, user_pos.y);
|
glm::vec3 position = glm::vec3(user_pos.x, 0, user_pos.y);
|
||||||
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);
|
||||||
|
|
||||||
set_camera_to_shader(camera, get_lit_shader());
|
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();
|
||||||
|
|||||||
@ -14,6 +14,6 @@ namespace deerith
|
|||||||
void init_engine();
|
void init_engine();
|
||||||
void shutdown_engine();
|
void shutdown_engine();
|
||||||
|
|
||||||
bool execute_server(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();
|
||||||
}
|
}
|
||||||
19
deerith_engine_core/include/deerith/world/voxels.h
Normal file
19
deerith_engine_core/include/deerith/world/voxels.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <deerith/engine.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace deerith
|
||||||
|
{
|
||||||
|
using voxel_type_id_t = uint16_t;
|
||||||
|
|
||||||
|
struct voxel_type_t
|
||||||
|
{
|
||||||
|
std::string id;
|
||||||
|
bool is_air = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
voxel_type_id_t register_voxel_type(const voxel_type_t &type);
|
||||||
|
voxel_type_id_t get_voxel_type_id(const std::string &name);
|
||||||
|
const voxel_type_t &get_voxel_type(voxel_type_id_t id);
|
||||||
|
}
|
||||||
@ -12,13 +12,13 @@ namespace deerith
|
|||||||
std::vector<pid_t> executing_servers;
|
std::vector<pid_t> executing_servers;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool deerith::execute_server(const char *server_executable_path, int port)
|
bool deerith::execute_client(const char *client_executable_path, int port)
|
||||||
{
|
{
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
|
|
||||||
if (pid < 0)
|
if (pid < 0)
|
||||||
{
|
{
|
||||||
deerith_error("execute_server fatal error");
|
deerith_error("execute_client fatal error");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,13 +30,13 @@ bool deerith::execute_server(const char *server_executable_path, int port)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
execl(server_executable_path,
|
execl(client_executable_path,
|
||||||
server_executable_path,
|
client_executable_path,
|
||||||
"-p",
|
"-p",
|
||||||
"8080",
|
"8080",
|
||||||
nullptr);
|
nullptr);
|
||||||
|
|
||||||
deerith_error("Fatal error executing server");
|
deerith_error("fatal error executing client");
|
||||||
_exit(1);
|
_exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
28
deerith_engine_core/src/voxels.cpp
Normal file
28
deerith_engine_core/src/voxels.cpp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#include <deerith/world/voxels.h>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
namespace deerith
|
||||||
|
{
|
||||||
|
std::vector<voxel_type_t> voxel_type_array;
|
||||||
|
std::unordered_map<std::string, voxel_type_id_t> voxel_type_name_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
deerith::voxel_type_id_t deerith::register_voxel_type(const voxel_type_t &type)
|
||||||
|
{
|
||||||
|
voxel_type_array.push_back(type);
|
||||||
|
return voxel_type_array.size() - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const deerith::voxel_type_t &deerith::get_voxel_type(deerith::voxel_type_id_t id)
|
||||||
|
{
|
||||||
|
deerith_assert(id >= 0 && id < voxel_type_array.size(), "invalid get_voxel_type id");
|
||||||
|
return voxel_type_array[id];
|
||||||
|
}
|
||||||
|
|
||||||
|
deerith::voxel_type_id_t deerith::get_voxel_type_id(const std::string &name)
|
||||||
|
{
|
||||||
|
deerith_assert(voxel_type_name_id.contains(name), "invalid get_voxel_type_id name");
|
||||||
|
return voxel_type_name_id[name];
|
||||||
|
}
|
||||||
@ -1,13 +1,13 @@
|
|||||||
add_library(DeerithServer)
|
add_library(DeerithServer)
|
||||||
|
|
||||||
file(GLOB_RECURSE deerith_SOURCES
|
file(GLOB_RECURSE DEERITH_SOURCES
|
||||||
CONFIGURE_DEPENDS
|
CONFIGURE_DEPENDS
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_sources(DeerithServer
|
target_sources(DeerithServer
|
||||||
PRIVATE
|
PRIVATE
|
||||||
${deerith_SOURCES}
|
${DEERITH_SOURCES}
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(DeerithServer
|
target_include_directories(DeerithServer
|
||||||
@ -21,8 +21,3 @@ target_link_libraries(DeerithServer
|
|||||||
PUBLIC
|
PUBLIC
|
||||||
DeerithCore
|
DeerithCore
|
||||||
)
|
)
|
||||||
|
|
||||||
target_compile_definitions(DeerithServer
|
|
||||||
PUBLIC
|
|
||||||
DEERITH_SERVER
|
|
||||||
)
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
#include <deerith/engine.h>
|
#include <deerith/engine.h>
|
||||||
|
|
||||||
#include "network/network_internals.h"
|
#include <deerith/network/network_internals.h>
|
||||||
|
|
||||||
namespace deerith
|
namespace deerith
|
||||||
{
|
{
|
||||||
|
|||||||
@ -11,8 +11,8 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "network_internals.h"
|
#include <deerith/network/network_internals.h>
|
||||||
#include "world/world_internals.h"
|
#include <deerith/world/world_internals.h>
|
||||||
|
|
||||||
namespace deerith
|
namespace deerith
|
||||||
{
|
{
|
||||||
|
|||||||
@ -5,8 +5,8 @@
|
|||||||
#include <deerith/network/router.h>
|
#include <deerith/network/router.h>
|
||||||
#include <deerith/network/client.h>
|
#include <deerith/network/client.h>
|
||||||
|
|
||||||
#include "network/network_internals.h"
|
#include <deerith/network/network_internals.h>
|
||||||
#include "world/world_internals.h"
|
#include <deerith/world/world_internals.h>
|
||||||
|
|
||||||
namespace deerith
|
namespace deerith
|
||||||
{
|
{
|
||||||
|
|||||||
@ -2,8 +2,8 @@
|
|||||||
#include <deerith/core/log.h>
|
#include <deerith/core/log.h>
|
||||||
#include <deerith/network/router.h>
|
#include <deerith/network/router.h>
|
||||||
|
|
||||||
#include "network/network_internals.h"
|
#include <deerith/network/network_internals.h>
|
||||||
#include "world/world_internals.h"
|
#include <deerith/world/world_internals.h>
|
||||||
|
|
||||||
#include <deerith/world/components.h>
|
#include <deerith/world/components.h>
|
||||||
#include <deerith/network/packets.h>
|
#include <deerith/network/packets.h>
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#include "world/world_internals.h"
|
#include <deerith/world/world_internals.h>
|
||||||
|
|
||||||
#include <deerith/world.h>
|
#include <deerith/world.h>
|
||||||
#include <deerith/world/components.h>
|
#include <deerith/world/components.h>
|
||||||
|
|||||||
@ -1,44 +1,22 @@
|
|||||||
file(GLOB_RECURSE SANDBOX_COMMON
|
file(GLOB_RECURSE SANDBOX_RECURSE
|
||||||
CONFIGURE_DEPENDS
|
CONFIGURE_DEPENDS
|
||||||
src/runtime/*.cpp
|
src/*.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
file(GLOB_RECURSE SANDBOX_CLIENT
|
add_executable(Sandbox
|
||||||
CONFIGURE_DEPENDS
|
${SANDBOX_RECURSE}
|
||||||
src/client/*.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
file(GLOB_RECURSE SANDBOX_SERVER
|
target_include_directories(Sandbox
|
||||||
CONFIGURE_DEPENDS
|
|
||||||
src/server/*.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
add_executable(SandboxClient
|
|
||||||
${SANDBOX_COMMON}
|
|
||||||
${SANDBOX_CLIENT}
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(SandboxClient
|
|
||||||
PRIVATE
|
|
||||||
DeerithClient
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(SandboxClient
|
|
||||||
PRIVATE
|
PRIVATE
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(SandboxServer
|
target_link_libraries(Sandbox
|
||||||
${SANDBOX_COMMON}
|
|
||||||
${SANDBOX_SERVER}
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(SandboxServer
|
|
||||||
PRIVATE
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(SandboxServer
|
|
||||||
PRIVATE
|
PRIVATE
|
||||||
DeerithServer
|
DeerithServer
|
||||||
)
|
)
|
||||||
|
|
||||||
|
target_compile_definitions(Sandbox PRIVATE
|
||||||
|
$<$<CONFIG:Debug>:DEBUG>
|
||||||
|
)
|
||||||
27
sandbox/src/main.cpp
Normal file
27
sandbox/src/main.cpp
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#include <deerith/engine.h>
|
||||||
|
#include <deerith/world.h>
|
||||||
|
#include <thread>
|
||||||
|
#include <args/argh.h>
|
||||||
|
|
||||||
|
int main(int argc, const char **argv)
|
||||||
|
{
|
||||||
|
deerith::init_engine();
|
||||||
|
auto cmdl = argh::parser(argc, argv);
|
||||||
|
|
||||||
|
int port = 8080;
|
||||||
|
cmdl("port", 8080) >> port;
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
if (cmdl[{"-s", "--single"}] && !deerith::execute_client("../deerith_engine_client/DeerithClient", port))
|
||||||
|
{
|
||||||
|
deerith_error("could not start server");
|
||||||
|
deerith::shutdown_engine();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
deerith::run_world(8080);
|
||||||
|
|
||||||
|
deerith::shutdown_executing_servers();
|
||||||
|
deerith::shutdown_engine();
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user