Almost working save sytem but the data I store is totally wrong. I need to also save the entity IDs being used and map them to the components.

This commit is contained in:
Zed A. Shaw 2024-11-05 02:38:36 -05:00
parent babc190525
commit d113dba42f
15 changed files with 213 additions and 64 deletions

View file

@ -6,6 +6,7 @@
#include "dinkyecs.hpp"
#include "components.hpp"
using namespace fmt;
using std::string;
@ -61,47 +62,3 @@ TEST_CASE("can go into a world", "[config]") {
Config &cfg = world.get_the<Config>();
REQUIRE(cfg["types"]["NUMBER"] == 1234);
}
#include <optional>
#include <iostream>
#include "tser.hpp"
enum class Item : char {
RADAR = 'R',
TRAP = 'T',
ORE = 'O'
};
struct Pixel {
int x = 0;
int y = 0;
DEFINE_SERIALIZABLE(Pixel, x, y);
};
struct Robot {
Pixel point;
std::wstring name;
std::optional<Item> item;
DEFINE_SERIALIZABLE(Robot, point, name, item);
};
TEST_CASE("test using tser for serialization", "[config]") {
auto robot = Robot{ Pixel{3,4}, L"BIG NAME", Item::RADAR};
std::cout << robot << '\n';
tser::BinaryArchive archive;
archive.save(robot);
std::string_view archive_view = archive.get_buffer();
tser::BinaryArchive archive2(0);
archive2.initialize(archive_view);
auto loadedRobot = archive2.load<Robot>();
REQUIRE(loadedRobot.point.x == robot.point.x);
REQUIRE(loadedRobot.point.y == robot.point.y);
REQUIRE(loadedRobot.name == robot.name);
REQUIRE(loadedRobot.item == robot.item);
}