aboutsummaryrefslogtreecommitdiffstats
path: root/src/engine.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine.cpp')
-rw-r--r--src/engine.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/engine.cpp b/src/engine.cpp
index 61d119a..e959f21 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -20,6 +20,7 @@
*/
#include "engine.hpp"
+#include "gamestate.hpp"
#include "gamerun.hpp"
#include "input.hpp"
#include "player.hpp"
@@ -30,6 +31,8 @@
#include "components/Position.hpp"
#include "components/Velocity.hpp"
+#include <fstream>
+
using namespace std::chrono_literals;
namespace cr = std::chrono;
typedef std::chrono::high_resolution_clock mc;
@@ -43,7 +46,12 @@ int Engine::init(void)
systems.add<ScriptSystem>();
systems.configure();
+ // Load game script and entity data
systems.system<ScriptSystem>()->init();
+ if (GameState::load("save.json", entities)) {
+ std::cout << "Loaded from save.json. Delete the file if you don't want "
+ "it." << std::endl;
+ }
return 0;
}
@@ -116,6 +124,9 @@ void Engine::run(void)
// Done, bring logic thread back
logicThread.join();
+
+ // Save the entities' data
+ GameState::save("save.json", entities);
}
bool Engine::shouldRun(void)