57 lines
1.6 KiB
C++
Executable File
57 lines
1.6 KiB
C++
Executable File
#pragma once
|
|
#include <cstdint>
|
|
#include <vector>
|
|
|
|
#include "DeerCore/Enviroment.h"
|
|
#include "EntitySerializationStruct.h"
|
|
|
|
namespace Deer {
|
|
struct EntityEnvironmentEntity {
|
|
EntityEnvironment& environment;
|
|
EntityEnvironmentEntity(EntityEnvironment& env) : environment(env) {}
|
|
};
|
|
|
|
template <class Archive>
|
|
void save(Archive& archive, const Deer::EntityEnvironment& environment) {
|
|
EntityEnvironmentEntity envEnt(const_cast<Deer::EntityEnvironment&>(environment));
|
|
archive(cereal::make_nvp("entities", envEnt));
|
|
}
|
|
|
|
template <class Archive>
|
|
void load(Archive& archive, Deer::EntityEnvironment& environment) {
|
|
EntityEnvironmentEntity envEnt(environment);
|
|
archive(cereal::make_nvp("entities", envEnt));
|
|
}
|
|
|
|
template <class Archive>
|
|
void save(Archive& archive, EntityEnvironmentEntity const& m_entities) {
|
|
archive(cereal::make_size_tag(static_cast<cereal::size_type>(
|
|
m_entities.environment.getEntityCount())));
|
|
|
|
for (uint16_t i = 0; i < m_entities.environment.getEntityCount(); i++) {
|
|
while (!m_entities.environment.entityExists(i)) {
|
|
i++;
|
|
}
|
|
|
|
EntitySerializationStruct serializationStruct;
|
|
serializationStruct.env =
|
|
const_cast<EntityEnvironment*>(&m_entities.environment);
|
|
serializationStruct.entityID = i;
|
|
|
|
archive(serializationStruct);
|
|
}
|
|
}
|
|
|
|
template <class Archive>
|
|
void load(Archive& archive, EntityEnvironmentEntity& m_entities) {
|
|
cereal::size_type size;
|
|
archive(cereal::make_size_tag(size));
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
EntitySerializationStruct serializationStruct;
|
|
serializationStruct.env = &m_entities.environment;
|
|
|
|
archive(serializationStruct);
|
|
}
|
|
}
|
|
} // namespace Deer
|