commit 4a6d425b
Made the whole replay info serializable
Changed files
| M | source/code/BlockGame.cpp before |
| M | source/code/BlockGame.hpp before |
diff --git a/source/code/BlockGame.cpp b/source/code/BlockGame.cpp
index b993d89..72d7635 100644
--- a/source/code/BlockGame.cpp
+++ b/source/code/BlockGame.cpp
@@ -35,6 +35,7 @@ http://blockattack.net
#include "puzzlehandler.hpp"
#include "stageclearhandler.hpp"
#include <sstream>
+#include <deque>
using std::string;
using std::stringstream;
@@ -211,6 +212,8 @@ bool BlockGame::GetIsWinner() const {
void BlockGame::NewGame(const BlockGameStartInfo& s) {
+ replayInfo.startInfo = s;
+ replayInfo.actions.clear();
this->recordStats = s.recordStats;
if (s.AI) {
recordStats = false;
@@ -1779,6 +1782,7 @@ void BlockGame::UpdateInternal(unsigned int newtick) {
}
void BlockGame::DoAction (const BlockGameAction& action) {
+ replayInfo.actions.push_back(action);
if (action.action == BlockGameAction::Action::UPDATE) {
UpdateInternal(action.tick);
}
diff --git a/source/code/BlockGame.hpp b/source/code/BlockGame.hpp
index 7e9a309..b778c56 100644
--- a/source/code/BlockGame.hpp
+++ b/source/code/BlockGame.hpp
@@ -26,6 +26,10 @@ http://www.blockattack.net
#include "stats.h"
#include "common.h"
+#include <deque>
+#include "cereal/cereal.hpp"
+#include "cereal/types/deque.hpp"
+#include "cereal/types/string.hpp"
#define NUMBEROFCHAINS 100
#define BLOCKWAIT 100000
@@ -65,6 +69,13 @@ struct BlockGameStartInfo {
int startBlocks = -1;
int handicap = 0;
int gameSpeed = 0;
+ template <class Archive>
+ void serialize( Archive & ar )
+ {
+ ar( CEREAL_NVP(ticks), CEREAL_NVP(timeTrial), CEREAL_NVP(stageClear), CEREAL_NVP(puzzleMode), CEREAL_NVP(singlePuzzle),
+ CEREAL_NVP(level), CEREAL_NVP(AI), CEREAL_NVP(recordStats), CEREAL_NVP(vsMode), CEREAL_NVP(vsAI),
+ CEREAL_NVP(startBlocks), CEREAL_NVP(handicap), CEREAL_NVP(gameSpeed) );
+ }
};
struct GarbageStruct {
@@ -76,6 +87,11 @@ struct GarbageStruct {
width = w;
height = h;
}
+ template <class Archive>
+ void serialize( Archive & ar )
+ {
+ ar( CEREAL_NVP(greyGarbage), CEREAL_NVP(width), CEREAL_NVP(height) );
+ }
};
struct BlockGameAction {
@@ -86,6 +102,21 @@ struct BlockGameAction {
int x = 0;
int y = 0;
std::vector<GarbageStruct> garbage;
+ template <class Archive>
+ void serialize( Archive & ar )
+ {
+ ar( CEREAL_NVP(action), CEREAL_NVP(tick), CEREAL_NVP(way), CEREAL_NVP(x), CEREAL_NVP(y), CEREAL_NVP(garbage) );
+ }
+};
+
+struct BlockGameInfo {
+ BlockGameStartInfo startInfo;
+ std::deque<BlockGameAction> actions;
+ template <class Archive>
+ void serialize( Archive & ar )
+ {
+ ar( CEREAL_NVP(startInfo), CEREAL_NVP(actions) );
+ }
};
////////////////////////////////////////////////////////////////////////////////
@@ -115,6 +146,8 @@ private:
unsigned int nextRandomNumber = 0;
int Level = 0; //Only used in stageClear and puzzle (not implemented)
+ BlockGameInfo replayInfo;
+
int rand2();
int firstUnusedChain();
@@ -217,6 +250,9 @@ public:
int getLevel() const;
bool GetAIenabled() const;
bool IsNearDeath() const;
+ const BlockGameInfo& GetBlockGameInfo() {
+ return replayInfo;
+ }
private:
void NewGame(unsigned int ticks);
//Test if LineNr is an empty line, returns false otherwise.