|
|
@ -3,9 +3,10 @@ |
|
|
|
#include "dbc.hpp" |
|
|
|
#include "dbc.hpp" |
|
|
|
#include <fmt/core.h> |
|
|
|
#include <fmt/core.h> |
|
|
|
#include "config.hpp" |
|
|
|
#include "config.hpp" |
|
|
|
|
|
|
|
#include <filesystem> |
|
|
|
|
|
|
|
|
|
|
|
using namespace components; |
|
|
|
using namespace components; |
|
|
|
|
|
|
|
using namespace fmt; |
|
|
|
|
|
|
|
|
|
|
|
template<typename CompT> |
|
|
|
template<typename CompT> |
|
|
|
inline void extract(DinkyECS::World &world, std::map<DinkyECS::Entity, CompT> &into) { |
|
|
|
inline void extract(DinkyECS::World &world, std::map<DinkyECS::Entity, CompT> &into) { |
|
|
@ -15,7 +16,7 @@ inline void extract(DinkyECS::World &world, std::map<DinkyECS::Entity, CompT> &i |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void save::to_file(std::string path, DinkyECS::World &world) { |
|
|
|
void save::to_file(fs::path path, DinkyECS::World &world) { |
|
|
|
SaveData save_data; |
|
|
|
SaveData save_data; |
|
|
|
tser::BinaryArchive archive; |
|
|
|
tser::BinaryArchive archive; |
|
|
|
|
|
|
|
|
|
|
@ -40,22 +41,22 @@ inline void inject(DinkyECS::World &world, std::map<DinkyECS::Entity, CompT> &ou |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void save::from_file(std::string path, DinkyECS::World &world_out) { |
|
|
|
void save::from_file(fs::path path, DinkyECS::World &world_out) { |
|
|
|
tser::BinaryArchive archive(0); |
|
|
|
tser::BinaryArchive archive(0); |
|
|
|
|
|
|
|
dbc::check(fs::exists(path), format("save file does not exist {}", path.string())); |
|
|
|
|
|
|
|
auto size = fs::file_size(path); |
|
|
|
|
|
|
|
|
|
|
|
if(std::ifstream in_file{path, std::ios::binary | std::ios::ate}) { |
|
|
|
if(std::ifstream in_file{path, std::ios::binary}) { |
|
|
|
auto size = in_file.tellg(); |
|
|
|
|
|
|
|
std::string in_data(size, '\0'); |
|
|
|
std::string in_data(size, '\0'); |
|
|
|
in_file.seekg(0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(in_file.read(&in_data[0], size)) { |
|
|
|
if(in_file.read(&in_data[0], size)) { |
|
|
|
std::string_view in_view(in_data); |
|
|
|
std::string_view in_view(in_data); |
|
|
|
archive.initialize(in_view); |
|
|
|
archive.initialize(in_view); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
dbc::sentinel(fmt::format("wrong size or error reading {}", path)); |
|
|
|
dbc::sentinel(format("wrong size or error reading {}", path.string())); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
dbc::sentinel(fmt::format("failed to load file {}", path)); |
|
|
|
dbc::sentinel(format("failed to load file {}", path.string())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
auto save_data = archive.load<SaveData>(); |
|
|
|
auto save_data = archive.load<SaveData>(); |
|
|
|