From a361f9e01be85cf489956e2b8449958a489021bc Mon Sep 17 00:00:00 2001 From: Quentin Bazin Date: Sun, 5 Apr 2020 16:59:34 +0200 Subject: [PATCH] Working on entity serialization. --- README.md | 4 +- source/client/CMakeLists.txt | 4 +- source/client/scene/AnimationController.cpp | 7 +- .../scene/{Scene.cpp => ClientScene.cpp} | 20 ++++- .../scene/{Scene.hpp => ClientScene.hpp} | 15 ++-- source/client/scene/CollisionController.cpp | 5 +- source/client/scene/ItemDropFactory.cpp | 8 +- source/client/scene/RenderingController.cpp | 14 ++- source/client/world/ClientWorld.hpp | 6 +- source/common/network/NetworkUtils.cpp | 20 +++++ source/common/network/NetworkUtils.hpp | 31 +++++++ .../scene/AnimationComponent.hpp | 39 ++++++++- source/common/scene/DrawableComponent.hpp | 51 +++++++++++ source/common/scene/Scene.hpp | 47 ++++++++++ source/common/scene/SceneSerializer.cpp | 51 +++++++++++ source/common/scene/SceneSerializer.hpp | 87 +++++++++++++++++++ source/server/CMakeLists.txt | 4 +- 17 files changed, 377 insertions(+), 36 deletions(-) rename source/client/scene/{Scene.cpp => ClientScene.cpp} (79%) rename source/client/scene/{Scene.hpp => ClientScene.hpp} (87%) rename source/{client => common}/scene/AnimationComponent.hpp (64%) create mode 100644 source/common/scene/DrawableComponent.hpp create mode 100644 source/common/scene/Scene.hpp create mode 100644 source/common/scene/SceneSerializer.cpp create mode 100644 source/common/scene/SceneSerializer.hpp diff --git a/README.md b/README.md index d5885878..6ad6d64d 100644 --- a/README.md +++ b/README.md @@ -104,16 +104,16 @@ This list is non exhaustive. - Player model display (currently without rotation nor animation) - Dimensions (like the Nether or the Ender in Minecraft) ([#80](https://github.com/Unarelith/OpenMiner/pull/80)) - World loading/saving (using `/save ` and `/load ` commands, see [#26](https://github.com/Unarelith/OpenMiner/issues/26)) +- Texture pack system (partially implemented, see [#34](https://github.com/Unarelith/OpenMiner/issues/34)) +- Entities (block drops, mobs, etc...) ([#90](https://github.com/Unarelith/OpenMiner/pull/90)) ### Missing features -- Texture pack system ([#34](https://github.com/Unarelith/OpenMiner/issues/34)) - Fluid propagation ([#62](https://github.com/Unarelith/OpenMiner/issues/62)) - Day/night cycle with sun/moon display ([#73](https://github.com/Unarelith/OpenMiner/issues/73)) - Real worldgen (seed-based, cave tunnels) ([#79](https://github.com/Unarelith/OpenMiner/issues/79)) - Clouds ([#52](https://github.com/Unarelith/OpenMiner/pull/52)) - Particle system -- Entities (block drops, mobs, etc...) ## Screenshots diff --git a/source/client/CMakeLists.txt b/source/client/CMakeLists.txt index bc6d9889..474e73b4 100644 --- a/source/client/CMakeLists.txt +++ b/source/client/CMakeLists.txt @@ -49,6 +49,7 @@ endif () target_link_libraries(${PROJECT_NAME} ${CMAKE_PROJECT_NAME}_server_lib + ${CMAKE_PROJECT_NAME}_common ${GAMEKIT_LIBRARIES} ${OPENGL_LIBRARIES} ${SDL2_LIBRARIES} @@ -60,6 +61,5 @@ target_link_libraries(${PROJECT_NAME} ${LUA_LIBRARIES} sfml-system sfml-network - ${UNIX_LIBS} - ${CMAKE_PROJECT_NAME}_common) + ${UNIX_LIBS}) diff --git a/source/client/scene/AnimationController.cpp b/source/client/scene/AnimationController.cpp index 9fd11019..4ba58485 100644 --- a/source/client/scene/AnimationController.cpp +++ b/source/client/scene/AnimationController.cpp @@ -29,11 +29,10 @@ #include "InventoryCube.hpp" void AnimationController::update(entt::DefaultRegistry ®istry) { - // FIXME: This shouldn't use InventoryCube but a more generic class - registry.view().each([](auto, auto &cube, auto &animation) { + registry.view().each([](auto, auto &transformable, auto &animation) { for (auto &it : animation.list) { if (it.type == AnimationType::Rotation) - cube.rotate(it.rotation.angle, {it.rotation.axisX, it.rotation.axisY, it.rotation.axisZ}); + transformable.rotate(it.rotation.angle, {it.rotation.axisX, it.rotation.axisY, it.rotation.axisZ}); else if (it.type == AnimationType::Translation) { float dx = it.translation.dx; float dy = it.translation.dy; @@ -51,7 +50,7 @@ void AnimationController::update(entt::DefaultRegistry ®istry) { || it.translation.cz + it.translation.dz < it.translation.min) dz = (it.translation.loop) ? -dz : 0; - cube.move(dx, dy, dz); + transformable.move(dx, dy, dz); it.translation.cx += dx; it.translation.cy += dy; diff --git a/source/client/scene/Scene.cpp b/source/client/scene/ClientScene.cpp similarity index 79% rename from source/client/scene/Scene.cpp rename to source/client/scene/ClientScene.cpp index c6227d2a..2d3b1883 100644 --- a/source/client/scene/Scene.cpp +++ b/source/client/scene/ClientScene.cpp @@ -26,22 +26,34 @@ */ #include "AnimationController.hpp" #include "ClientPlayer.hpp" +#include "ClientScene.hpp" #include "CollisionController.hpp" -#include "Scene.hpp" #include "RenderingController.hpp" -Scene::Scene(ClientPlayer &player) : m_player(player) { +ClientScene::ClientScene(ClientPlayer &player) : m_player(player) { m_controllers.emplace_back(new AnimationController); m_controllers.emplace_back(new CollisionController(player)); m_controllers.emplace_back(new RenderingController); } -void Scene::update() { +void ClientScene::update() { for (auto &controller : m_controllers) controller->update(m_registry); + + static bool test = false; + if (!test && m_registry.alive() > 2) { + gkDebug() << "serializing..."; + sf::Packet packet; + serialize(packet); + gkDebug() << "deserializing..."; + deserialize(packet); + gkDebug() << "serializing..."; + serialize(packet); + test = true; + } } -void Scene::draw(gk::RenderTarget &target, gk::RenderStates states) const { +void ClientScene::draw(gk::RenderTarget &target, gk::RenderStates states) const { if (!m_camera) return; // Subtract the camera position - see comment in ClientWorld::draw() diff --git a/source/client/scene/Scene.hpp b/source/client/scene/ClientScene.hpp similarity index 87% rename from source/client/scene/Scene.hpp rename to source/client/scene/ClientScene.hpp index ddbf7d32..b4b4ebc1 100644 --- a/source/client/scene/Scene.hpp +++ b/source/client/scene/ClientScene.hpp @@ -24,8 +24,8 @@ * * ===================================================================================== */ -#ifndef SCENE_HPP_ -#define SCENE_HPP_ +#ifndef CLIENTSCENE_HPP_ +#define CLIENTSCENE_HPP_ #include #include @@ -36,19 +36,18 @@ #include #include "AbstractController.hpp" +#include "Scene.hpp" class ClientPlayer; -class Scene : public gk::Drawable { +class ClientScene : public Scene, public gk::Drawable { public: - Scene(ClientPlayer &player); + ClientScene(ClientPlayer &player); void update(); void setCamera(gk::Camera &camera) { m_camera = &camera; } - entt::DefaultRegistry ®istry() { return m_registry; } - private: void draw(gk::RenderTarget &target, gk::RenderStates states) const override; @@ -56,9 +55,7 @@ class Scene : public gk::Drawable { gk::Camera *m_camera = nullptr; - mutable entt::DefaultRegistry m_registry; - std::deque> m_controllers; }; -#endif // SCENE_HPP_ +#endif // CLIENTSCENE_HPP_ diff --git a/source/client/scene/CollisionController.cpp b/source/client/scene/CollisionController.cpp index 95cff89b..24d76bd9 100644 --- a/source/client/scene/CollisionController.cpp +++ b/source/client/scene/CollisionController.cpp @@ -30,9 +30,8 @@ #include "ItemStack.hpp" void CollisionController::update(entt::DefaultRegistry ®istry) { - // FIXME: This shouldn't use InventoryCube, but instead a callback stored in a CollisionComponent - registry.view().each([&](auto entity, auto &cube, auto &box, auto &itemStack) { - gk::DoubleBox hitbox = box + cube.getPosition(); + registry.view().each([&](auto entity, auto &transformable, auto &box, auto &itemStack) { + gk::DoubleBox hitbox = box + transformable.getPosition(); gk::DoubleBox playerHitbox = m_player.hitbox() + gk::Vector3d{m_player.x(), m_player.y(), m_player.z()}; if (hitbox.intersects(playerHitbox)) { m_player.inventory().addStack(itemStack.item().stringID(), itemStack.amount()); diff --git a/source/client/scene/ItemDropFactory.cpp b/source/client/scene/ItemDropFactory.cpp index 165e7b73..88a4cc97 100644 --- a/source/client/scene/ItemDropFactory.cpp +++ b/source/client/scene/ItemDropFactory.cpp @@ -25,6 +25,7 @@ * ===================================================================================== */ #include "AnimationComponent.hpp" +#include "DrawableComponent.hpp" #include "InventoryCube.hpp" #include "ItemDropFactory.hpp" #include "ItemStack.hpp" @@ -33,11 +34,14 @@ void ItemDropFactory::create(entt::DefaultRegistry ®istry, double x, double y, double z, const std::string &itemID, u16 amount) { auto entity = registry.create(); - InventoryCube &cube = registry.assign(entity, 0.25f, true); + auto &drawableComponent = registry.assign(entity); + auto &cube = drawableComponent.setDrawable(0.25f, true); cube.setOrigin(cube.size() / 2.f, cube.size() / 2.f, cube.size() / 2.f); - cube.setPosition(x + 0.5, y + 0.5, z + 0.5); cube.updateVertexBuffer(Registry::getInstance().getBlockFromStringID(itemID)); + auto &transformable = registry.assign(entity); + transformable.setPosition(x + 0.5, y + 0.5, z + 0.5); + auto &animationComponent = registry.assign(entity); animationComponent.addRotation(0.f, 0.f, 1.f, 0.5f); animationComponent.addTranslation(0.f, 0.f, -0.0005f, -0.2f, 0.f, true); diff --git a/source/client/scene/RenderingController.cpp b/source/client/scene/RenderingController.cpp index 28f99f2d..5bab875d 100644 --- a/source/client/scene/RenderingController.cpp +++ b/source/client/scene/RenderingController.cpp @@ -24,13 +24,21 @@ * * ===================================================================================== */ +#include "DrawableComponent.hpp" #include "InventoryCube.hpp" #include "RenderingController.hpp" +#include +#include + void RenderingController::draw(entt::DefaultRegistry ®istry, gk::RenderTarget &target, gk::RenderStates states) { - // FIXME: There's probably another way to do this - registry.view().each([&](auto, auto &cube) { - target.draw(cube, states); + registry.view().each([&](auto entity, auto &drawable, auto &transformable) { + if (gk::GameClock::getInstance().getTicks() % 100 < 12) + gkDebug() << "Drawing entity" << entity << "at" << transformable.getPosition(); + + gk::RenderStates drawStates = states; + drawStates.transform *= transformable.getTransform(); + drawable.draw(target, drawStates); }); } diff --git a/source/client/world/ClientWorld.hpp b/source/client/world/ClientWorld.hpp index 2eb729dc..24ec3890 100644 --- a/source/client/world/ClientWorld.hpp +++ b/source/client/world/ClientWorld.hpp @@ -33,8 +33,8 @@ #include #include "ClientChunk.hpp" +#include "ClientScene.hpp" #include "Network.hpp" -#include "Scene.hpp" #include "World.hpp" class ClientCommandHandler; @@ -62,7 +62,7 @@ class ClientWorld : public World, public gk::Drawable { Chunk *getChunk(int cx, int cy, int cz) const override; - Scene &scene() { return m_scene; } + ClientScene &scene() { return m_scene; } void setClient(ClientCommandHandler &client) { m_client = &client; } void setCamera(gk::Camera &camera) { m_camera = &camera; m_scene.setCamera(camera); } @@ -74,7 +74,7 @@ class ClientWorld : public World, public gk::Drawable { void draw(gk::RenderTarget &target, gk::RenderStates states) const override; - Scene m_scene; + ClientScene m_scene; ChunkMap m_chunks; diff --git a/source/common/network/NetworkUtils.cpp b/source/common/network/NetworkUtils.cpp index 0c9e9da4..9fa11a67 100644 --- a/source/common/network/NetworkUtils.cpp +++ b/source/common/network/NetworkUtils.cpp @@ -36,3 +36,23 @@ sf::Packet &operator>>(sf::Packet &packet, gk::Color &color) { return packet; } +sf::Packet &operator<<(sf::Packet &packet, const gk::Transformable &transformable) { + packet << transformable.getPosition() << transformable.getOrigin() << transformable.getScale() + << transformable.getRotation() << transformable.getRotationTransform().getMatrix(); + return packet; +} + +sf::Packet &operator>>(sf::Packet &packet, gk::Transformable &transformable) { + gk::Vector3f position, origin, scale; + float rotation; + packet >> position >> origin >> scale >> rotation + >> transformable.getRotationTransform().getMatrix(); + + transformable.setPosition(position); + transformable.setOrigin(origin); + transformable.setScale(scale); + transformable.setRotation(rotation); + + return packet; +} + diff --git a/source/common/network/NetworkUtils.hpp b/source/common/network/NetworkUtils.hpp index 1e833386..d73c1423 100644 --- a/source/common/network/NetworkUtils.hpp +++ b/source/common/network/NetworkUtils.hpp @@ -84,6 +84,29 @@ sf::Packet &operator>>(sf::Packet &packet, std::unordered_map &map) { return packet; } +//====================================================================================== +// glm::mat4 +//====================================================================================== +#include +#include + +template +sf::Packet &operator<<(sf::Packet &packet, const glm::tmat4x4 &matrix) { + for (int i = 0 ; i < 4 * 4 ; ++i) { + packet << matrix[i % 4][i / 4]; + } + return packet; +} + +template +sf::Packet &operator>>(sf::Packet &packet, glm::tmat4x4 &matrix) { + for (int i = 0 ; i < 4 * 4 ; ++i) { + packet >> matrix[i % 4][i / 4]; + } + return packet; +} + + //====================================================================================== // gk::Rect //====================================================================================== @@ -143,4 +166,12 @@ sf::Packet &operator>>(sf::Packet &packet, gk::Vector3 &vec) { sf::Packet &operator<<(sf::Packet &packet, const gk::Color &color); sf::Packet &operator>>(sf::Packet &packet, gk::Color &color); +//====================================================================================== +// gk::Transformable +//====================================================================================== +#include + +sf::Packet &operator<<(sf::Packet &packet, const gk::Transformable &transformable); +sf::Packet &operator>>(sf::Packet &packet, gk::Transformable &transformable); + #endif // NETWORKUTILS_HPP_ diff --git a/source/client/scene/AnimationComponent.hpp b/source/common/scene/AnimationComponent.hpp similarity index 64% rename from source/client/scene/AnimationComponent.hpp rename to source/common/scene/AnimationComponent.hpp index 5fcc9f54..96590bcd 100644 --- a/source/client/scene/AnimationComponent.hpp +++ b/source/common/scene/AnimationComponent.hpp @@ -29,12 +29,17 @@ #include +#include + +#include "ISerializable.hpp" +#include "NetworkUtils.hpp" + enum class AnimationType { Rotation, Translation, }; -struct AnimationData { +struct AnimationData : public ISerializable { AnimationType type; union { @@ -53,9 +58,36 @@ struct AnimationData { bool loop; } translation; }; + + void serialize(sf::Packet &packet) const override { + packet << u8(type); + if (type == AnimationType::Rotation) { + packet << rotation.axisX << rotation.axisY << rotation.axisZ << rotation.angle; + } + else if (type == AnimationType::Translation) { + packet << translation.dx << translation.dy << translation.dz + << translation.cx << translation.cy << translation.cz + << translation.min << translation.max << translation.loop; + } + } + + void deserialize(sf::Packet &packet) override { + u8 type; + packet >> type; + if (type == u8(AnimationType::Rotation)) { + packet >> rotation.axisX >> rotation.axisY >> rotation.axisZ >> rotation.angle; + } + else if (type == u8(AnimationType::Translation)) { + packet >> translation.dx >> translation.dy >> translation.dz + >> translation.cx >> translation.cy >> translation.cz + >> translation.min >> translation.max >> translation.loop; + } + + this->type = AnimationType(type); + } }; -struct AnimationComponent { +struct AnimationComponent : public ISerializable { void addRotation(float axisX, float axisY, float axisZ, float angle) { list.emplace_back(); AnimationData &data = list.back(); @@ -89,6 +121,9 @@ struct AnimationComponent { data.translation.loop = loop; } + void serialize(sf::Packet &packet) const override { packet << list; } + void deserialize(sf::Packet &packet) override { packet >> list; } + std::vector list; }; diff --git a/source/common/scene/DrawableComponent.hpp b/source/common/scene/DrawableComponent.hpp new file mode 100644 index 00000000..fbd8e43c --- /dev/null +++ b/source/common/scene/DrawableComponent.hpp @@ -0,0 +1,51 @@ +/* + * ===================================================================================== + * + * OpenMiner + * + * Copyright (C) 2018-2020 Unarelith, Quentin Bazin + * Copyright (C) 2019-2020 the OpenMiner contributors (see CONTRIBUTORS.md) + * + * This file is part of OpenMiner. + * + * OpenMiner is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * OpenMiner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with OpenMiner; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * ===================================================================================== + */ +#ifndef DRAWABLECOMPONENT_HPP_ +#define DRAWABLECOMPONENT_HPP_ + +#include + +#include + +class DrawableComponent { + public: + template + auto setDrawable(Args &&...args) -> typename std::enable_if::value, T &>::type { + m_drawable.reset(new T(std::forward(args)...)); + return *static_cast(m_drawable.get()); + } + + void draw(gk::RenderTarget &target, gk::RenderStates states) { + if (m_drawable) + target.draw(*m_drawable, states); + } + + private: + std::unique_ptr m_drawable; +}; + +#endif // DRAWABLECOMPONENT_HPP_ diff --git a/source/common/scene/Scene.hpp b/source/common/scene/Scene.hpp new file mode 100644 index 00000000..10124429 --- /dev/null +++ b/source/common/scene/Scene.hpp @@ -0,0 +1,47 @@ +/* + * ===================================================================================== + * + * OpenMiner + * + * Copyright (C) 2018-2020 Unarelith, Quentin Bazin + * Copyright (C) 2019-2020 the OpenMiner contributors (see CONTRIBUTORS.md) + * + * This file is part of OpenMiner. + * + * OpenMiner is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * OpenMiner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with OpenMiner; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * ===================================================================================== + */ +#ifndef SCENE_HPP_ +#define SCENE_HPP_ + +#include "ISerializable.hpp" +#include "SceneSerializer.hpp" + +class Scene : public ISerializable { + public: + void serialize(sf::Packet &packet) const override { m_serializer.serialize(packet); } + void deserialize(sf::Packet &packet) override { m_serializer.deserialize(packet); } + + entt::DefaultRegistry ®istry() { return m_registry; } + + protected: + mutable entt::DefaultRegistry m_registry; + + private: + SceneSerializer m_serializer{*this}; +}; + +#endif // SCENE_HPP_ diff --git a/source/common/scene/SceneSerializer.cpp b/source/common/scene/SceneSerializer.cpp new file mode 100644 index 00000000..c68a2a67 --- /dev/null +++ b/source/common/scene/SceneSerializer.cpp @@ -0,0 +1,51 @@ +/* + * ===================================================================================== + * + * OpenMiner + * + * Copyright (C) 2018-2020 Unarelith, Quentin Bazin + * Copyright (C) 2019-2020 the OpenMiner contributors (see CONTRIBUTORS.md) + * + * This file is part of OpenMiner. + * + * OpenMiner is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * OpenMiner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with OpenMiner; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * ===================================================================================== + */ +#include "AnimationComponent.hpp" +#include "ItemStack.hpp" +#include "Scene.hpp" +#include "SceneSerializer.hpp" + +void SceneSerializer::serialize(sf::Packet &packet) const { + m_outputArchive.setPacket(packet); + m_scene.registry().snapshot().component(m_outputArchive); +} + +void SceneSerializer::deserialize(sf::Packet &packet) { + m_inputArchive.setPacket(packet); + m_scene.registry().restore().component(m_inputArchive); +} + +void SceneSerializer::OutputArchive::operator()(Entity entity) { + gkDebug() << entity; + (*m_packet) << entity; +} + +void SceneSerializer::InputArchive::operator()(Entity &entity) { + (*m_packet) >> entity; + gkDebug() << entity; +} + diff --git a/source/common/scene/SceneSerializer.hpp b/source/common/scene/SceneSerializer.hpp new file mode 100644 index 00000000..9c85069e --- /dev/null +++ b/source/common/scene/SceneSerializer.hpp @@ -0,0 +1,87 @@ +/* + * ===================================================================================== + * + * OpenMiner + * + * Copyright (C) 2018-2020 Unarelith, Quentin Bazin + * Copyright (C) 2019-2020 the OpenMiner contributors (see CONTRIBUTORS.md) + * + * This file is part of OpenMiner. + * + * OpenMiner is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * OpenMiner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with OpenMiner; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * ===================================================================================== + */ +#ifndef SCENESERIALIZER_HPP_ +#define SCENESERIALIZER_HPP_ + +#include + +#include + +#include "ISerializable.hpp" +#include "NetworkUtils.hpp" + +class Scene; + +class SceneSerializer : public ISerializable { + using Entity = entt::DefaultRegistry::entity_type; + + public: + SceneSerializer(Scene &scene) : m_scene(scene) {} + + void serialize(sf::Packet &packet) const; + void deserialize(sf::Packet &packet); + + private: + class OutputArchive { + public: + void operator()(Entity entity); + + template + void operator()(Entity entity, const T &value) { + // gkDebug() << entity << value; + (*m_packet) << entity << value; + } + + void setPacket(sf::Packet &packet) { m_packet = &packet; } + + private: + sf::Packet *m_packet = nullptr; + }; + + class InputArchive { + public: + void operator()(Entity &entity); + + template + void operator()(Entity &entity, T &value) { + (*m_packet) >> entity >> value; + // gkDebug() << entity << value; + } + + void setPacket(sf::Packet &packet) { m_packet = &packet; } + + private: + sf::Packet *m_packet = nullptr; + }; + + Scene &m_scene; + + mutable OutputArchive m_outputArchive; + mutable InputArchive m_inputArchive; +}; + +#endif // SCENESERIALIZER_HPP_ diff --git a/source/server/CMakeLists.txt b/source/server/CMakeLists.txt index 42ea96b7..ab136739 100644 --- a/source/server/CMakeLists.txt +++ b/source/server/CMakeLists.txt @@ -66,6 +66,7 @@ target_link_libraries(${PROJECT_NAME}_lib sfml-system sfml-network) target_link_libraries(${PROJECT_NAME} ${PROJECT_NAME}_lib + ${CMAKE_PROJECT_NAME}_common ${GAMEKIT_LIBRARIES} ${OPENGL_LIBRARIES} ${SDL2_LIBRARIES} @@ -77,6 +78,5 @@ target_link_libraries(${PROJECT_NAME} ${LUA_LIBRARIES} sfml-system sfml-network - ${UNIX_LIBS} - ${CMAKE_PROJECT_NAME}_common) + ${UNIX_LIBS})