]> git.localhorst.tv Git - blank.git/blobdiff - src/io/WorldSave.cpp
move common exceptions to app/error
[blank.git] / src / io / WorldSave.cpp
index 86532787653d1b24deef8baec749501eab3377ff..529d0d91a5784da2f1cf2cea55ae62a1fc87b75c 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "filesystem.hpp"
 #include "TokenStreamReader.hpp"
+#include "../app/error.hpp"
 
 #include <cctype>
 #include <cstring>
@@ -125,9 +126,9 @@ void WorldSave::Read(Player &player) const {
                in.ReadIdentifier(name);
                in.Skip(Token::EQUALS);
                if (name == "chunk") {
-                       in.ReadVec(state.chunk_pos);
+                       in.ReadVec(state.pos.chunk);
                } else if (name == "position") {
-                       in.ReadVec(state.block_pos);
+                       in.ReadVec(state.pos.block);
                } else if (name == "orientation") {
                        in.ReadQuat(state.orient);
                } else if (name == "pitch") {
@@ -144,6 +145,7 @@ void WorldSave::Read(Player &player) const {
                }
        }
        player.GetEntity().SetState(state);
+       player.Update(0);
 }
 
 void WorldSave::Write(const Player &player) const {
@@ -152,8 +154,8 @@ void WorldSave::Write(const Player &player) const {
        }
        const EntityState &state = player.GetEntity().GetState();
        ofstream out(PlayerPath(player));
-       out << "chunk = " << state.chunk_pos << ';' << endl;
-       out << "position = " << state.block_pos << ';' << endl;
+       out << "chunk = " << state.pos.chunk << ';' << endl;
+       out << "position = " << state.pos.block << ';' << endl;
        out << "orientation = " << state.orient << ';' << endl;
        out << "pitch = " << state.pitch << ';' << endl;
        out << "yaw = " << state.yaw << ';' << endl;
@@ -167,7 +169,7 @@ string WorldSave::PlayerPath(const Player &player) const {
 }
 
 
-bool WorldSave::Exists(const Chunk::Pos &pos) const noexcept {
+bool WorldSave::Exists(const ExactLocation::Coarse &pos) const noexcept {
        return is_file(ChunkPath(pos));
 }
 
@@ -183,6 +185,7 @@ void WorldSave::Read(Chunk &chunk) const {
        if (gzclose(file) != Z_OK) {
                throw runtime_error("failed to read chunk file");
        }
+       chunk.ScanActive();
        chunk.InvalidateMesh();
        chunk.ClearSave();
 }
@@ -194,7 +197,7 @@ void WorldSave::Write(Chunk &chunk) const {
                // check if it's because of a missing path component
                if (errno != ENOENT) {
                        // nope, fatal
-                       throw runtime_error(strerror(errno));
+                       throw SysError();
                }
                string dir_path(path);
                dir_path.erase(dir_path.find_last_of("\\/"));
@@ -217,7 +220,7 @@ void WorldSave::Write(Chunk &chunk) const {
 }
 
 
-const char *WorldSave::ChunkPath(const Chunk::Pos &pos) const {
+const char *WorldSave::ChunkPath(const ExactLocation::Coarse &pos) const {
        snprintf(chunk_buf.get(), chunk_bufsiz, chunk_path.c_str(), pos.x, pos.y, pos.z);
        return chunk_buf.get();
 }