diff --git a/CMakeLists.txt b/CMakeLists.txt index 7459337..2545480 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.20) -project(MyEngine +project(DeerithEngine VERSION 0.1 LANGUAGES CXX ) diff --git a/deerith_engine_client/src/network/base_protocol.cpp b/deerith_engine_client/src/network/base_protocol.cpp index ed1dc49..0c9c0d0 100644 --- a/deerith_engine_client/src/network/base_protocol.cpp +++ b/deerith_engine_client/src/network/base_protocol.cpp @@ -5,5 +5,5 @@ void deerith::setup_base_protocols() { - router_add_packet_processor(); + router_add_packet_processor(); } \ No newline at end of file diff --git a/deerith_engine_client/src/world/server_communication.cpp b/deerith_engine_client/src/world/server_communication.cpp new file mode 100644 index 0000000..fa839ea --- /dev/null +++ b/deerith_engine_client/src/world/server_communication.cpp @@ -0,0 +1,25 @@ +#include +#include +#include +#include +#include + +#include "world/world_internals.h" + +namespace deerith +{ +} + +template <> +void deerith::process_packet(deerith::sync_world_tick_packet_t &packet, client_t *client) +{ + deerith_trace("tick set to {}", packet.tick_id); + set_tick(packet.tick_id); +} + +template <> +void deerith::process_packet(deerith::create_player_entity_packet_t &packet, client_t *client) +{ + self_entity = create_entity(); + add_component(self_entity); +} \ No newline at end of file diff --git a/deerith_engine_client/src/world/universe_render.cpp b/deerith_engine_client/src/world/universe_render.cpp new file mode 100644 index 0000000..a9e95ab --- /dev/null +++ b/deerith_engine_client/src/world/universe_render.cpp @@ -0,0 +1,5 @@ +#include + +void deerith::render_world() +{ +} \ No newline at end of file diff --git a/deerith_engine_client/src/world/world.cpp b/deerith_engine_client/src/world/world.cpp index 48b96d9..a085132 100644 --- a/deerith_engine_client/src/world/world.cpp +++ b/deerith_engine_client/src/world/world.cpp @@ -1,8 +1,6 @@ #include #include -#include - #include "network/network_internals.h" #include "world/world_internals.h" @@ -14,7 +12,7 @@ namespace deerith std::unique_ptr world_thread; std::atomic world_running = false; - character_sync_interface_t character_sync_interface; + entity_t self_entity = entt::null; void world_simulation(); } @@ -55,7 +53,7 @@ void deerith::world_simulation() send_player_input(); } - wait_till_next_click(); + wait_till_next_tick(); } world_running = false; diff --git a/deerith_engine_client/src/world/world_internals.h b/deerith_engine_client/src/world/world_internals.h index 19a5a1a..aae1ad7 100644 --- a/deerith_engine_client/src/world/world_internals.h +++ b/deerith_engine_client/src/world/world_internals.h @@ -1,7 +1,10 @@ #pragma once +#include namespace deerith { + extern entity_t self_entity; + void process_player_input(); void send_player_input(); } diff --git a/deerith_engine_client/src/world/world_protocols.cpp b/deerith_engine_client/src/world/world_protocols.cpp deleted file mode 100644 index 2dafda8..0000000 --- a/deerith_engine_client/src/world/world_protocols.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include -#include - -namespace deerith -{ -} - -template <> -void deerith::process_packet(sync_world_tick_t &world_tick, client_t *client) -{ - deerith_trace("sync_world_tick_t tick set to {}", world_tick.tick_id); - set_tick(world_tick.tick_id); -} \ No newline at end of file diff --git a/deerith_engine_core/CMakeLists.txt b/deerith_engine_core/CMakeLists.txt index 4614558..0ac2bf1 100644 --- a/deerith_engine_core/CMakeLists.txt +++ b/deerith_engine_core/CMakeLists.txt @@ -38,5 +38,6 @@ target_link_libraries(DeerithCore spdlog::spdlog fmt::fmt glm::glm + EnTT::EnTT ${ENET_LIBRARY} ) \ No newline at end of file diff --git a/deerith_engine_core/include/deerith/network/client.h b/deerith_engine_core/include/deerith/network/client.h index eb02856..7723cdc 100644 --- a/deerith_engine_core/include/deerith/network/client.h +++ b/deerith_engine_core/include/deerith/network/client.h @@ -1,11 +1,17 @@ #pragma once #include +#include namespace deerith { + using entity_registry_t = entt::registry; + using entity_t = entt::entity; + struct client_t { - client_t(ENetPeer *_peer) : peer(_peer) {} ENetPeer *peer; + entity_t entity_id = entt::null; + + client_t(ENetPeer *_peer) : peer(_peer) {} }; } \ No newline at end of file diff --git a/deerith_engine_core/include/deerith/packets/sync_world_tick.h b/deerith_engine_core/include/deerith/network/packets.h similarity index 63% rename from deerith_engine_core/include/deerith/packets/sync_world_tick.h rename to deerith_engine_core/include/deerith/network/packets.h index 8667d08..5391317 100644 --- a/deerith_engine_core/include/deerith/packets/sync_world_tick.h +++ b/deerith_engine_core/include/deerith/network/packets.h @@ -3,7 +3,7 @@ namespace deerith { - struct sync_world_tick_t + struct sync_world_tick_packet_t { static constexpr uint16_t packet_id = 1; static constexpr bool reliable = true; @@ -16,4 +16,10 @@ namespace deerith archive(tick_id); } }; + + struct create_player_entity_packet_t + { + static constexpr uint16_t packet_id = 2; + static constexpr bool reliable = true; + }; } \ No newline at end of file diff --git a/deerith_engine_core/include/deerith/packets/sync_character_interface.h b/deerith_engine_core/include/deerith/packets/sync_character_interface.h deleted file mode 100644 index 6cad0b9..0000000 --- a/deerith_engine_core/include/deerith/packets/sync_character_interface.h +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once -#include -#include - -namespace deerith -{ - struct sync_character_interface_t - { - static constexpr uint16_t packet_id = 2; - static constexpr bool reliable = false; - - sync_variable_transport_t move_input_transport; - - void load(const character_sync_interface_t &ci) - { - move_input_transport.load(ci.move_input); - } - - void dipose(character_sync_interface_t &ci) - { - move_input_transport.load(ci.move_input); - } - - template - void serialize(Archive &archive) - { - archive(move_input_transport); - } - }; -} \ No newline at end of file diff --git a/deerith_engine_core/include/deerith/world/character_sync_interface.h b/deerith_engine_core/include/deerith/world/character_sync_interface.h deleted file mode 100644 index e11a1f5..0000000 --- a/deerith_engine_core/include/deerith/world/character_sync_interface.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once -#include - -namespace deerith -{ - struct character_sync_interface_t - { - sync_variable_t move_input; - sync_variable_t position; - }; -} \ No newline at end of file diff --git a/deerith_engine_core/include/deerith/world/entity.h b/deerith_engine_core/include/deerith/world/entity.h new file mode 100644 index 0000000..b66a437 --- /dev/null +++ b/deerith_engine_core/include/deerith/world/entity.h @@ -0,0 +1,19 @@ +#pragma once +#include +#include + +namespace deerith +{ + // struct for linking a entity to a client, mostly in the server + struct entity_link_to_client_t + { + client_t *client = nullptr; + }; + + // struct for linking a entity to a client + struct entity_sync_client_position_t + { + sync_variable_t move_input; + sync_variable_t position; + }; +} \ No newline at end of file diff --git a/deerith_engine_core/include/deerith/world/world_core.h b/deerith_engine_core/include/deerith/world/world_core.h index cb6f955..0af86fc 100644 --- a/deerith_engine_core/include/deerith/world/world_core.h +++ b/deerith_engine_core/include/deerith/world/world_core.h @@ -1,11 +1,29 @@ #pragma once #include +#include namespace deerith { + using entity_registry_t = entt::registry; + using entity_t = entt::entity; + uint32_t get_world_tick(); - void wait_till_next_click(); + void wait_till_next_tick(); void set_tick(uint32_t); + entity_registry_t &get_entity_registry_t(); + inline entity_t create_entity() { return get_entity_registry_t().create(); } + + template + T &add_component(entity_t ent) + { + return get_entity_registry_t().emplace(ent); + } + + template + T &get_component(entity_t ent) + { + return get_entity_registry_t().get(ent); + } } diff --git a/deerith_engine_core/src/internal.h b/deerith_engine_core/src/internal.h index df4702b..6e08029 100644 --- a/deerith_engine_core/src/internal.h +++ b/deerith_engine_core/src/internal.h @@ -6,4 +6,5 @@ namespace deerith void init_network(); void shutdown_network(); + } \ No newline at end of file diff --git a/deerith_engine_core/src/tick.cpp b/deerith_engine_core/src/tick.cpp index a674080..933ee31 100644 --- a/deerith_engine_core/src/tick.cpp +++ b/deerith_engine_core/src/tick.cpp @@ -18,7 +18,7 @@ uint32_t deerith::get_world_tick() return tick_id; } -void deerith::wait_till_next_click() +void deerith::wait_till_next_tick() { using clock = std::chrono::steady_clock; diff --git a/deerith_engine_core/src/world.cpp b/deerith_engine_core/src/world.cpp new file mode 100644 index 0000000..c305590 --- /dev/null +++ b/deerith_engine_core/src/world.cpp @@ -0,0 +1,11 @@ +#include + +namespace deerith +{ + entity_registry_t entity_registry; +} + +entt::registry &deerith::get_entity_registry_t() +{ + return entity_registry; +} diff --git a/deerith_engine_server/src/network/network.cpp b/deerith_engine_server/src/network/network.cpp index 772f636..fa6bb56 100644 --- a/deerith_engine_server/src/network/network.cpp +++ b/deerith_engine_server/src/network/network.cpp @@ -12,6 +12,7 @@ #include #include "network_internals.h" +#include "world/world_internals.h" namespace deerith { @@ -88,13 +89,9 @@ void deerith::create_client(ENetPeer *peer) enet_address_get_host_ip(&peer->address, enet_address, 31); deerith_trace("a new client has connected : {}", enet_address); - sync_world_tick_t sync_world_tick; - sync_world_tick.tick_id = get_world_tick(); - std::unique_ptr client = std::make_unique(peer); peer->data = client.get(); clients.push_back(std::move(client)); - - router_send_packet(sync_world_tick, (client_t *)peer->data); + client_connects((client_t *)peer->data); } \ No newline at end of file diff --git a/deerith_engine_server/src/network/network_internals.h b/deerith_engine_server/src/network/network_internals.h index 5722c1b..414efe5 100644 --- a/deerith_engine_server/src/network/network_internals.h +++ b/deerith_engine_server/src/network/network_internals.h @@ -11,5 +11,4 @@ namespace deerith void flush_network_events(); void load_base_protocols(); - } \ No newline at end of file diff --git a/deerith_engine_server/src/world.cpp b/deerith_engine_server/src/world.cpp index 352852e..6fba7de 100644 --- a/deerith_engine_server/src/world.cpp +++ b/deerith_engine_server/src/world.cpp @@ -1,7 +1,12 @@ #include - #include +#include + #include "network/network_internals.h" +#include "world/world_internals.h" + +#include +#include #include #include @@ -47,5 +52,23 @@ void deerith::world_simulation() // process movments - wait_till_next_click(); + wait_till_next_tick(); +} + +void deerith::client_connects(client_t *client) +{ + sync_world_tick_packet_t sync_world_tick; + sync_world_tick.tick_id = get_world_tick(); + + create_player_entity_packet_t create_player_entity; + + router_send_packet(sync_world_tick, client); + router_send_packet(create_player_entity, client); + + entity_t entity = create_entity(); + entity_link_to_client_t &link = add_component(entity); + entity_sync_client_position_t &position_sync = add_component(entity); + + link.client = client; + client->entity_id = entity; } diff --git a/deerith_engine_server/src/world/character_sync.cpp b/deerith_engine_server/src/world/character_sync.cpp index 774598f..e69de29 100644 --- a/deerith_engine_server/src/world/character_sync.cpp +++ b/deerith_engine_server/src/world/character_sync.cpp @@ -1,15 +0,0 @@ -#include - -#include -#include - -namespace deerith -{ - -} - -template <> -void deerith::process_packet(sync_character_interface_t &interface, client_t *client) -{ - deerith_trace("sync player input {} {}"); -} diff --git a/deerith_engine_server/src/world/player_communication.cpp b/deerith_engine_server/src/world/player_communication.cpp new file mode 100644 index 0000000..774598f --- /dev/null +++ b/deerith_engine_server/src/world/player_communication.cpp @@ -0,0 +1,15 @@ +#include + +#include +#include + +namespace deerith +{ + +} + +template <> +void deerith::process_packet(sync_character_interface_t &interface, client_t *client) +{ + deerith_trace("sync player input {} {}"); +} diff --git a/deerith_engine_server/src/world/world_internals.h b/deerith_engine_server/src/world/world_internals.h index 5b1d841..2e3eb97 100644 --- a/deerith_engine_server/src/world/world_internals.h +++ b/deerith_engine_server/src/world/world_internals.h @@ -1,6 +1,8 @@ #pragma once +#include namespace deerith { void update_players_characters(); + void client_connects(client_t *client); } \ No newline at end of file