Compare commits
No commits in common. "699abc31915ab20aaed3865cdea57b8b8112c747" and "29b106d002e8c2f2696f4bbceefcc683d74fb375" have entirely different histories.
699abc3191
...
29b106d002
@ -28,8 +28,7 @@ sudo apt install \
|
|||||||
libglm-dev \
|
libglm-dev \
|
||||||
libspdlog-dev \
|
libspdlog-dev \
|
||||||
libfmt-dev \
|
libfmt-dev \
|
||||||
libgl1-mesa-dev \
|
libgl1-mesa-dev
|
||||||
libimgui-dev
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Building
|
## Building
|
||||||
|
|||||||
@ -37,9 +37,4 @@ add_custom_target(DeerithClientShaders ALL
|
|||||||
${CMAKE_CURRENT_BINARY_DIR}/shaders
|
${CMAKE_CURRENT_BINARY_DIR}/shaders
|
||||||
)
|
)
|
||||||
|
|
||||||
target_compile_definitions(DeerithClient
|
|
||||||
PUBLIC
|
|
||||||
DEERITH_CLIENT
|
|
||||||
)
|
|
||||||
|
|
||||||
add_dependencies(DeerithClient DeerithClientShaders)
|
add_dependencies(DeerithClient DeerithClientShaders)
|
||||||
1
deerith_engine_client/include/deerith/network/network.h
Normal file
1
deerith_engine_client/include/deerith/network/network.h
Normal file
@ -0,0 +1 @@
|
|||||||
|
#
|
||||||
@ -1,8 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
namespace deerith
|
|
||||||
{
|
|
||||||
void begin_connection_to_universe(const char *address, int port);
|
|
||||||
void shutdown_universe();
|
|
||||||
bool is_universe_running();
|
|
||||||
}
|
|
||||||
@ -1,63 +0,0 @@
|
|||||||
#include <deerith/core/log.h>
|
|
||||||
#include <enet/enet.h>
|
|
||||||
|
|
||||||
#include <deerith/core/log.h>
|
|
||||||
|
|
||||||
#include <thread>
|
|
||||||
|
|
||||||
#include "network_internals.h"
|
|
||||||
|
|
||||||
namespace deerith
|
|
||||||
{
|
|
||||||
ENetHost *client;
|
|
||||||
ENetPeer *client_peer;
|
|
||||||
}
|
|
||||||
|
|
||||||
void deerith::connect_to_server(const char *address, int port)
|
|
||||||
{
|
|
||||||
ENetAddress eaddress = {0};
|
|
||||||
eaddress.port = port;
|
|
||||||
|
|
||||||
int result = enet_address_set_host(&eaddress, address);
|
|
||||||
deerith_client_assert(result == 0, "connect_to_server invalid address");
|
|
||||||
|
|
||||||
client = enet_host_create(NULL, 1, 2, 0, 0);
|
|
||||||
deerith_client_assert(client, "connect_to_server failed to create host");
|
|
||||||
|
|
||||||
client_peer = enet_host_connect(client, &eaddress, 2, 0);
|
|
||||||
deerith_client_assert(client_peer, "enet_host_connect failed on connect_to_server");
|
|
||||||
}
|
|
||||||
|
|
||||||
int deerith::init_network()
|
|
||||||
{
|
|
||||||
if (enet_initialize() != 0)
|
|
||||||
{
|
|
||||||
deerith_client_error("An error occurred while initializing ENet.\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void deerith::shutdown_network()
|
|
||||||
{
|
|
||||||
enet_deinitialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool deerith::wait_till_connected_to_server()
|
|
||||||
{
|
|
||||||
ENetEvent event;
|
|
||||||
if (enet_host_service(client, &event, 5000) > 0 &&
|
|
||||||
event.type == ENET_EVENT_TYPE_CONNECT)
|
|
||||||
{
|
|
||||||
deerith_client_info("Connected to server");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
enet_peer_reset(client_peer);
|
|
||||||
deerith_client_error("Failed to connect to server");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
namespace deerith
|
|
||||||
{
|
|
||||||
int init_network();
|
|
||||||
void shutdown_network();
|
|
||||||
|
|
||||||
void connect_to_server(const char *address, int port);
|
|
||||||
bool wait_till_connected_to_server();
|
|
||||||
}
|
|
||||||
@ -1,60 +0,0 @@
|
|||||||
#include <deerith/universe/universe.h>
|
|
||||||
#include <deerith/core/log.h>
|
|
||||||
|
|
||||||
#include "../network/network_internals.h"
|
|
||||||
|
|
||||||
#include <thread>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace deerith
|
|
||||||
{
|
|
||||||
std::unique_ptr<std::thread> universe_thread = {};
|
|
||||||
std::atomic<bool> universe_running = false;
|
|
||||||
|
|
||||||
void universe_simulation();
|
|
||||||
}
|
|
||||||
|
|
||||||
void deerith::begin_connection_to_universe(const char *address, int port)
|
|
||||||
{
|
|
||||||
deerith_core_assert(!universe_running, "begin_connection_to_universe failed because there is a current running universe");
|
|
||||||
|
|
||||||
if (universe_thread && universe_thread->joinable())
|
|
||||||
universe_thread->join();
|
|
||||||
|
|
||||||
universe_thread.reset();
|
|
||||||
|
|
||||||
connect_to_server(address, port);
|
|
||||||
|
|
||||||
universe_running = true;
|
|
||||||
universe_thread = std::make_unique<std::thread>(universe_simulation);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool deerith::is_universe_running()
|
|
||||||
{
|
|
||||||
return universe_running;
|
|
||||||
}
|
|
||||||
|
|
||||||
void deerith::universe_simulation()
|
|
||||||
{
|
|
||||||
bool connected = wait_till_connected_to_server();
|
|
||||||
|
|
||||||
if (connected)
|
|
||||||
{
|
|
||||||
while (universe_running)
|
|
||||||
{
|
|
||||||
deerith_client_trace("another thread");
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
deerith_client_trace("Thread stop");
|
|
||||||
universe_running = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void deerith::shutdown_universe()
|
|
||||||
{
|
|
||||||
if (universe_thread && universe_thread->joinable())
|
|
||||||
universe_thread->join();
|
|
||||||
universe_running = false;
|
|
||||||
universe_thread.reset();
|
|
||||||
}
|
|
||||||
@ -1,7 +1,5 @@
|
|||||||
#include "deerith/graphics/window.h"
|
#include "deerith/graphics/window.h"
|
||||||
#include "primitive_internals.h"
|
#include "primitive_internals.h"
|
||||||
#include "../network/network_internals.h"
|
|
||||||
#include <deerith/universe/universe.h>
|
|
||||||
|
|
||||||
#include <glad/gl.h>
|
#include <glad/gl.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
@ -73,7 +71,6 @@ int deerith::init_window()
|
|||||||
|
|
||||||
init_primitives();
|
init_primitives();
|
||||||
init_imgui();
|
init_imgui();
|
||||||
init_network();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -131,8 +128,6 @@ void deerith::shutdown_window()
|
|||||||
ImGui::DestroyContext();
|
ImGui::DestroyContext();
|
||||||
|
|
||||||
shutdown_primitives();
|
shutdown_primitives();
|
||||||
shutdown_universe();
|
|
||||||
shutdown_network();
|
|
||||||
|
|
||||||
glfwDestroyWindow(window);
|
glfwDestroyWindow(window);
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
@ -1,18 +1,5 @@
|
|||||||
add_library(DeerithCore)
|
add_library(DeerithCore)
|
||||||
|
|
||||||
find_path(ENET_INCLUDE_DIR enet/enet.h)
|
|
||||||
find_library(ENET_LIBRARY enet)
|
|
||||||
|
|
||||||
include(FetchContent)
|
|
||||||
|
|
||||||
FetchContent_Declare(
|
|
||||||
EnTT
|
|
||||||
GIT_REPOSITORY https://github.com/skypjack/entt.git
|
|
||||||
GIT_TAG v3.16.0
|
|
||||||
)
|
|
||||||
|
|
||||||
FetchContent_MakeAvailable(EnTT)
|
|
||||||
|
|
||||||
find_package(spdlog REQUIRED)
|
find_package(spdlog REQUIRED)
|
||||||
find_package(fmt REQUIRED)
|
find_package(fmt REQUIRED)
|
||||||
find_package(glm REQUIRED)
|
find_package(glm REQUIRED)
|
||||||
@ -30,7 +17,6 @@ target_sources(DeerithCore
|
|||||||
target_include_directories(DeerithCore
|
target_include_directories(DeerithCore
|
||||||
PUBLIC
|
PUBLIC
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||||
${ENET_INCLUDE_DIR}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(DeerithCore
|
target_link_libraries(DeerithCore
|
||||||
@ -38,5 +24,4 @@ target_link_libraries(DeerithCore
|
|||||||
spdlog::spdlog
|
spdlog::spdlog
|
||||||
fmt::fmt
|
fmt::fmt
|
||||||
glm::glm
|
glm::glm
|
||||||
${ENET_LIBRARY}
|
|
||||||
)
|
)
|
||||||
@ -1,7 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
namespace deerith
|
|
||||||
{
|
|
||||||
void init_engine();
|
|
||||||
void shutdown_enigne();
|
|
||||||
}
|
|
||||||
@ -19,8 +19,3 @@ target_link_libraries(DeerithServer
|
|||||||
PUBLIC
|
PUBLIC
|
||||||
DeerithCore
|
DeerithCore
|
||||||
)
|
)
|
||||||
|
|
||||||
target_compile_definitions(DeerithServer
|
|
||||||
PUBLIC
|
|
||||||
DEERITH_SERVER
|
|
||||||
)
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
namespace deerith
|
|
||||||
{
|
|
||||||
void init_universe_serve(int port);
|
|
||||||
void shutdown_universe();
|
|
||||||
|
|
||||||
bool is_universe_running();
|
|
||||||
}
|
|
||||||
@ -1,63 +0,0 @@
|
|||||||
#include <deerith/core/log.h>
|
|
||||||
#include <enet/enet.h>
|
|
||||||
|
|
||||||
#include <deerith/core/log.h>
|
|
||||||
|
|
||||||
#include <thread>
|
|
||||||
|
|
||||||
#include "network_internals.h"
|
|
||||||
|
|
||||||
namespace deerith
|
|
||||||
{
|
|
||||||
ENetHost *client;
|
|
||||||
ENetPeer *client_peer;
|
|
||||||
}
|
|
||||||
|
|
||||||
void deerith::connect_to_server(const char *address, int port)
|
|
||||||
{
|
|
||||||
ENetAddress eaddress = {0};
|
|
||||||
eaddress.port = port;
|
|
||||||
|
|
||||||
int result = enet_address_set_host(&eaddress, address);
|
|
||||||
deerith_client_assert(result == 0, "connect_to_server invalid address");
|
|
||||||
|
|
||||||
client = enet_host_create(NULL, 1, 2, 0, 0);
|
|
||||||
deerith_client_assert(client, "connect_to_server failed to create host");
|
|
||||||
|
|
||||||
client_peer = enet_host_connect(client, &eaddress, 2, 0);
|
|
||||||
deerith_client_assert(client_peer, "enet_host_connect failed on connect_to_server");
|
|
||||||
}
|
|
||||||
|
|
||||||
int deerith::init_network()
|
|
||||||
{
|
|
||||||
if (enet_initialize() != 0)
|
|
||||||
{
|
|
||||||
deerith_client_error("An error occurred while initializing ENet.\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void deerith::shutdown_network()
|
|
||||||
{
|
|
||||||
enet_deinitialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool deerith::wait_till_connected_to_server()
|
|
||||||
{
|
|
||||||
ENetEvent event;
|
|
||||||
if (enet_host_service(client, &event, 5000) > 0 &&
|
|
||||||
event.type == ENET_EVENT_TYPE_CONNECT)
|
|
||||||
{
|
|
||||||
deerith_client_info("Connected to server");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
enet_peer_reset(client_peer);
|
|
||||||
deerith_client_error("Failed to connect to server");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
namespace deerith
|
|
||||||
{
|
|
||||||
int init_network();
|
|
||||||
void shutdown_network();
|
|
||||||
|
|
||||||
void init_server(int port);
|
|
||||||
}
|
|
||||||
@ -23,21 +23,11 @@ target_link_libraries(SandboxClient
|
|||||||
DeerithClient
|
DeerithClient
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(SandboxClient
|
|
||||||
PRIVATE
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
|
||||||
)
|
|
||||||
|
|
||||||
add_executable(SandboxServer
|
add_executable(SandboxServer
|
||||||
${SANDBOX_COMMON}
|
${SANDBOX_COMMON}
|
||||||
${SANDBOX_SERVER}
|
${SANDBOX_SERVER}
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(SandboxServer
|
|
||||||
PRIVATE
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(SandboxServer
|
target_link_libraries(SandboxServer
|
||||||
PRIVATE
|
PRIVATE
|
||||||
DeerithServer
|
DeerithServer
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
#include <deerith/graphics/primitive.h>
|
#include <deerith/graphics/primitive.h>
|
||||||
#include <deerith/graphics/input.h>
|
#include <deerith/graphics/input.h>
|
||||||
#include <deerith/core/core.h>
|
#include <deerith/core/core.h>
|
||||||
#include <deerith/universe/universe.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
@ -11,9 +10,6 @@
|
|||||||
|
|
||||||
glm::vec2 player_pos(5, 5);
|
glm::vec2 player_pos(5, 5);
|
||||||
|
|
||||||
char net_address[16] = "127.0.0.1";
|
|
||||||
int port = 8080;
|
|
||||||
|
|
||||||
float vel = 1;
|
float vel = 1;
|
||||||
|
|
||||||
int main(int args_count, const char **args)
|
int main(int args_count, const char **args)
|
||||||
@ -41,22 +37,8 @@ int main(int args_count, const char **args)
|
|||||||
{
|
{
|
||||||
ImGui::SliderFloat("Velocity", &vel, 0, 4);
|
ImGui::SliderFloat("Velocity", &vel, 0, 4);
|
||||||
|
|
||||||
if (deerith::is_universe_running())
|
|
||||||
{
|
|
||||||
ImGui::Text("Universe running");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ImGui::InputText("Net Address", net_address, 16);
|
|
||||||
ImGui::InputInt("Net port", &port);
|
|
||||||
|
|
||||||
if (ImGui::Button("Connect"))
|
|
||||||
{
|
|
||||||
deerith::begin_connection_to_universe(net_address, port);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
}
|
||||||
|
|
||||||
deerith::finish_window_display();
|
deerith::finish_window_display();
|
||||||
}
|
}
|
||||||
@ -1,3 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
void execute_window();
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
|
|
||||||
#include <deerith/core/core.h>
|
|
||||||
#include <deerith/core/log.h>
|
|
||||||
#include <deerith/engine.h>
|
|
||||||
|
|
||||||
#ifdef DEERITH_SERVER
|
|
||||||
#include <client/
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef DEERITH_CLIENT
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
deerith::init_deerith_core();
|
|
||||||
|
|
||||||
int init_result = deerith::init_window();
|
|
||||||
if (init_result != 0)
|
|
||||||
{
|
|
||||||
return init_result;
|
|
||||||
}
|
|
||||||
|
|
||||||
deerith::shutdown_enigne();
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user