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