summaryrefslogtreecommitdiffstats
path: root/src/World
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2015-02-01 01:38:20 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2015-02-01 01:38:20 +0100
commita6a2a6281218688de7a74a9cd2a426aad3fe2da2 (patch)
treea8a40ab0978ebeff31321ae6d094a7ea605ee553 /src/World
parentcbe64618821a0ae9f1901ce1a4a3893d939fdc32 (diff)
downloadMinedMap-a6a2a6281218688de7a74a9cd2a426aad3fe2da2.tar
MinedMap-a6a2a6281218688de7a74a9cd2a426aad3fe2da2.zip
More convenient tag access
Diffstat (limited to 'src/World')
-rw-r--r--src/World/Chunk.cpp12
-rw-r--r--src/World/Chunk.hpp8
2 files changed, 9 insertions, 11 deletions
diff --git a/src/World/Chunk.cpp b/src/World/Chunk.cpp
index ccd0d87..f3a140d 100644
--- a/src/World/Chunk.cpp
+++ b/src/World/Chunk.cpp
@@ -36,7 +36,7 @@
namespace MinedMap {
namespace World {
-std::tuple<UniqueCPtr<uint8_t[]>, size_t> Chunk::inflateChunk(uint8_t *data, size_t len) {
+std::pair<UniqueCPtr<uint8_t[]>, size_t> Chunk::inflateChunk(uint8_t *data, size_t len) {
size_t outlen = 0;
uint8_t *output = nullptr;
@@ -67,7 +67,7 @@ std::tuple<UniqueCPtr<uint8_t[]>, size_t> Chunk::inflateChunk(uint8_t *data, siz
inflateEnd(&stream);
- return std::make_tuple(UniqueCPtr<uint8_t[]>(output), stream.total_out);
+ return std::make_pair(UniqueCPtr<uint8_t[]>(output), stream.total_out);
}
Chunk::Chunk(uint8_t *buffer, size_t buflen) {
@@ -89,12 +89,12 @@ Chunk::Chunk(uint8_t *buffer, size_t buflen) {
std::cerr << "Chunk has size " << size << " (" << len << " inflated)" << std::endl;
Buffer nbt(data.get(), len);
+ std::pair<std::string, std::shared_ptr<const NBT::Tag>> tag = NBT::Tag::readNamedTag(&nbt);
- std::pair<std::string, std::shared_ptr<NBT::Tag>> tag = NBT::Tag::readNamedTag(&nbt);
- if (tag.first != "")
- throw std::invalid_argument("non-empty root tag");
+ std::shared_ptr<const NBT::CompoundTag>::operator=(std::dynamic_pointer_cast<const NBT::CompoundTag>(tag.second));
- content = std::move(tag.second);
+ if (!(*this) || tag.first != "")
+ throw std::invalid_argument("invalid root tag");
}
}
diff --git a/src/World/Chunk.hpp b/src/World/Chunk.hpp
index eba4626..7c485eb 100644
--- a/src/World/Chunk.hpp
+++ b/src/World/Chunk.hpp
@@ -28,7 +28,7 @@
#include "../UniqueCPtr.hpp"
-#include "../NBT/Tag.hpp"
+#include "../NBT/CompoundTag.hpp"
#include <cstdint>
#include <tuple>
@@ -37,14 +37,12 @@
namespace MinedMap {
namespace World {
-class Chunk {
+class Chunk : public std::shared_ptr<const NBT::CompoundTag> {
public:
static const size_t SIZE = 16;
private:
- static std::tuple<UniqueCPtr<uint8_t[]>, size_t> inflateChunk(uint8_t *data, size_t len);
-
- std::shared_ptr<NBT::Tag> content;
+ static std::pair<UniqueCPtr<uint8_t[]>, size_t> inflateChunk(uint8_t *data, size_t len);
public:
Chunk(uint8_t *buffer, size_t buflen);