[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"
void SceneSerializer::serialize(sf::Packet &packet, const Scene &scene) const {
// m_outputArchive.setPacket(packet);
m_outputArchive.setPacket(packet);
// scene.registry().snapshot().component<
// AnimationComponent,
// gk::DoubleBox,
// ItemStack,
// gk::Transformable,
// DrawableDef
// >(m_outputArchive);
scene.registry().snapshot().component<
AnimationComponent,
gk::DoubleBox,
ItemStack,
gk::Transformable,
DrawableDef
>(m_outputArchive);
}
void SceneSerializer::deserialize(sf::Packet &packet, Scene &scene) {
// m_inputArchive.setPacket(packet);
m_inputArchive.setPacket(packet);
// scene.registry().restore().component<
// AnimationComponent,
// gk::DoubleBox,
// ItemStack,
// gk::Transformable,
// DrawableDef
// >(m_inputArchive);
scene.registry().loader().component<
AnimationComponent,
gk::DoubleBox,
ItemStack,
gk::Transformable,
DrawableDef
>(m_inputArchive);
}
// void SceneSerializer::OutputArchive::operator()(Entity entity) {
// // gkDebug() << entity;
// // (*m_packet) << entity;
// }
//
// void SceneSerializer::InputArchive::operator()(Entity &entity) {
// // (*m_packet) >> entity;
// // gkDebug() << entity;
// }
void SceneSerializer::OutputArchive::operator()(entt::entity entity) {
// gkDebug() << "Entity:" << (u32)entity;
(*m_packet) << (u32)entity;
}
void SceneSerializer::OutputArchive::operator()(std::underlying_type_t<entt::entity> size) {
// gkDebug() << "Size:" << size;
(*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 SceneSerializer {
using Entity = entt::registry::entity_type;
public:
void serialize(sf::Packet &packet, const Scene &scene) const;
void deserialize(sf::Packet &packet, Scene &scene);
private:
// class OutputArchive {
// public:
// void operator()(Entity entity);
//
// template<typename T>
// void operator()(Entity entity, const T &value) {
// // gkDebug() << entity << (void *)&value << typeid(T).name();
// // (*m_packet) << entity << value;
// // 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:
// sf::Packet *m_packet = nullptr;
// };
//
// class InputArchive {
// public:
// void operator()(Entity &entity);
//
// template<typename T>
// void operator()(Entity &entity, T &value) {
// // (*m_packet) >> entity >> value;
// // gkDebug() << entity << (void *)&value << typeid(T).name();
// }
//
// void setPacket(sf::Packet &packet) { m_packet = &packet; }
//
// private:
// sf::Packet *m_packet = nullptr;
// };
//
// mutable OutputArchive m_outputArchive;
// mutable InputArchive m_inputArchive;
class OutputArchive {
public:
void operator()(entt::entity entity);
void operator()(std::underlying_type_t<entt::entity> size);
template<typename T>
void operator()(entt::entity entity, const T &value) {
// gkDebug() << (u32)entity << (void *)&value << typeid(T).name();
(*m_packet) << (u32)entity << value;
// 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:
sf::Packet *m_packet = nullptr;
};
class InputArchive {
public:
void operator()(entt::entity &entity);
void operator()(std::underlying_type_t<entt::entity> &size);
template<typename T>
void operator()(entt::entity &entity, T &value) {
u32 entityID;
(*m_packet) >> entityID >> value;
entity = (entt::entity)entityID;
// gkDebug() << (u32)entity << (void *)&value << typeid(T).name();
}
void setPacket(sf::Packet &packet) { m_packet = &packet; }
private:
sf::Packet *m_packet = nullptr;
};
mutable OutputArchive m_outputArchive;
mutable InputArchive m_inputArchive;
};
#endif // SCENESERIALIZER_HPP_