[SceneSerializer] Adapted to latest EnTT version.

This commit is contained in:
Quentin Bazin 2020-04-13 16:59:31 +02:00
parent 3989d679eb
commit 782e752058
2 changed files with 80 additions and 64 deletions

View File

@ -31,36 +31,48 @@
#include "SceneSerializer.hpp" #include "SceneSerializer.hpp"
void SceneSerializer::serialize(sf::Packet &packet, const Scene &scene) const { void SceneSerializer::serialize(sf::Packet &packet, const Scene &scene) const {
// m_outputArchive.setPacket(packet); m_outputArchive.setPacket(packet);
// scene.registry().snapshot().component< scene.registry().snapshot().component<
// AnimationComponent, AnimationComponent,
// gk::DoubleBox, gk::DoubleBox,
// ItemStack, ItemStack,
// gk::Transformable, gk::Transformable,
// DrawableDef DrawableDef
// >(m_outputArchive); >(m_outputArchive);
} }
void SceneSerializer::deserialize(sf::Packet &packet, Scene &scene) { void SceneSerializer::deserialize(sf::Packet &packet, Scene &scene) {
// m_inputArchive.setPacket(packet); m_inputArchive.setPacket(packet);
// scene.registry().restore().component< scene.registry().loader().component<
// AnimationComponent, AnimationComponent,
// gk::DoubleBox, gk::DoubleBox,
// ItemStack, ItemStack,
// gk::Transformable, gk::Transformable,
// DrawableDef DrawableDef
// >(m_inputArchive); >(m_inputArchive);
} }
// void SceneSerializer::OutputArchive::operator()(Entity entity) { void SceneSerializer::OutputArchive::operator()(entt::entity entity) {
// // gkDebug() << entity; // gkDebug() << "Entity:" << (u32)entity;
// // (*m_packet) << entity; (*m_packet) << (u32)entity;
// } }
//
// void SceneSerializer::InputArchive::operator()(Entity &entity) { void SceneSerializer::OutputArchive::operator()(std::underlying_type_t<entt::entity> size) {
// // (*m_packet) >> entity; // gkDebug() << "Size:" << size;
// // gkDebug() << entity; (*m_packet) << size;
// } }
void SceneSerializer::InputArchive::operator()(entt::entity &entity) {
u32 entityID;
(*m_packet) >> entityID;
entity = (entt::entity)entityID;
// gkDebug() << "Entity:" << (u32)entity;
}
void SceneSerializer::InputArchive::operator()(std::underlying_type_t<entt::entity> &size) {
// gkDebug() << "Size:" << size;
(*m_packet) >> size;
}

View File

@ -36,50 +36,54 @@
class Scene; class Scene;
class SceneSerializer { class SceneSerializer {
using Entity = entt::registry::entity_type;
public: public:
void serialize(sf::Packet &packet, const Scene &scene) const; void serialize(sf::Packet &packet, const Scene &scene) const;
void deserialize(sf::Packet &packet, Scene &scene); void deserialize(sf::Packet &packet, Scene &scene);
private: private:
// class OutputArchive { class OutputArchive {
// public: public:
// void operator()(Entity entity); void operator()(entt::entity entity);
// void operator()(std::underlying_type_t<entt::entity> size);
// template<typename T>
// void operator()(Entity entity, const T &value) { template<typename T>
// // gkDebug() << entity << (void *)&value << typeid(T).name(); void operator()(entt::entity entity, const T &value) {
// // (*m_packet) << entity << value; // gkDebug() << (u32)entity << (void *)&value << typeid(T).name();
// // FIXME: It should be possible to check the type here and to create (*m_packet) << (u32)entity << value;
// // a defintion struct to serialize for some of them
// // instead of sending the component // FIXME: It should be possible to check the type here and to create
// } // a defintion struct to serialize for some of them
// // instead of sending the component
// void setPacket(sf::Packet &packet) { m_packet = &packet; } }
//
// private: void setPacket(sf::Packet &packet) { m_packet = &packet; }
// sf::Packet *m_packet = nullptr;
// }; private:
// sf::Packet *m_packet = nullptr;
// class InputArchive { };
// public:
// void operator()(Entity &entity); class InputArchive {
// public:
// template<typename T> void operator()(entt::entity &entity);
// void operator()(Entity &entity, T &value) { void operator()(std::underlying_type_t<entt::entity> &size);
// // (*m_packet) >> entity >> value;
// // gkDebug() << entity << (void *)&value << typeid(T).name(); template<typename T>
// } void operator()(entt::entity &entity, T &value) {
// u32 entityID;
// void setPacket(sf::Packet &packet) { m_packet = &packet; } (*m_packet) >> entityID >> value;
// entity = (entt::entity)entityID;
// private:
// sf::Packet *m_packet = nullptr; // gkDebug() << (u32)entity << (void *)&value << typeid(T).name();
// }; }
//
// mutable OutputArchive m_outputArchive; void setPacket(sf::Packet &packet) { m_packet = &packet; }
// mutable InputArchive m_inputArchive;
private:
sf::Packet *m_packet = nullptr;
};
mutable OutputArchive m_outputArchive;
mutable InputArchive m_inputArchive;
}; };
#endif // SCENESERIALIZER_HPP_ #endif // SCENESERIALIZER_HPP_