added serialization of IKeysMap with cereal
This commit is contained in:
parent
7705034bf9
commit
90e20da7f6
@ -8,6 +8,7 @@
|
||||
#include <SFML/Window.hpp>
|
||||
|
||||
#include <cereal/archives/json.hpp>
|
||||
#include <cereal/types/vector.hpp>
|
||||
#include <cassert>
|
||||
|
||||
#include <unordered_map>
|
||||
@ -55,13 +56,7 @@ struct Action
|
||||
template <class Archive>
|
||||
void serialize(Archive & archive)
|
||||
{
|
||||
archive(action,source,controller_id);
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
void load(Archive & archive)
|
||||
{
|
||||
archive >> action >> source >> controller_id;
|
||||
archive(CEREAL_NVP(action),CEREAL_NVP(source),CEREAL_NVP(controller_id));
|
||||
}
|
||||
};
|
||||
|
||||
@ -72,6 +67,11 @@ struct Binding// : public Serializable
|
||||
int type;
|
||||
Binding& operator=(const Binding newBinding);
|
||||
|
||||
template <class Archive>
|
||||
void serialize(Archive & archive)
|
||||
{
|
||||
archive(CEREAL_NVP(action),CEREAL_NVP(key),CEREAL_NVP(type));
|
||||
}
|
||||
};
|
||||
|
||||
class IKeysMap
|
||||
@ -83,6 +83,13 @@ public:
|
||||
std::vector<Binding>& data(){return keys;}
|
||||
protected:
|
||||
std::vector<Binding> keys;
|
||||
|
||||
friend class cereal::access;
|
||||
template <class Archive>
|
||||
void serialize(Archive & archive)
|
||||
{
|
||||
archive(CEREAL_NVP(keys));
|
||||
}
|
||||
};
|
||||
|
||||
class Context {
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include <SFML/Window.hpp>
|
||||
#include "input.h"
|
||||
#include <imgui/imgui.h>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -37,8 +38,13 @@ int main()
|
||||
myInput.addContext(context);
|
||||
myInput.setCurrentContext("test");
|
||||
|
||||
std::ifstream is("data.json");
|
||||
// std::ofstream os("data.json");
|
||||
// cereal::JSONInputArchive input(is);
|
||||
cereal::JSONOutputArchive output(std::cout);
|
||||
|
||||
output(myInput.getKeysMap());
|
||||
/*
|
||||
while(!myInput.isCloseRequested())
|
||||
{
|
||||
myInput.updateEvents();
|
||||
@ -56,7 +62,7 @@ int main()
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
/* IKeysMap* keymap = new IKeysMap("test", 1);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user