diff options
author | est31 <MTest31@outlook.com> | 2016-12-22 23:16:00 +0100 |
---|---|---|
committer | est31 <MTest31@outlook.com> | 2016-12-22 23:16:00 +0100 |
commit | 81d56b94919dceb7b2e51d70b21a7ca22f852bd5 (patch) | |
tree | 1e9ef1be1b3295a8673d6e4f0bdeb4c2d3a6015f /src/nodemetadata.cpp | |
parent | 8077612dcb48221281e726a60eb97bf73fde462b (diff) | |
parent | 231ac33d34dfaaddf292c5f31b1eae43eeefba2d (diff) | |
download | minetest-81d56b94919dceb7b2e51d70b21a7ca22f852bd5.tar.gz minetest-81d56b94919dceb7b2e51d70b21a7ca22f852bd5.tar.bz2 minetest-81d56b94919dceb7b2e51d70b21a7ca22f852bd5.zip |
Merge 0.4.15 changes into stable-0.4
0.4.15 release!
Diffstat (limited to 'src/nodemetadata.cpp')
-rw-r--r-- | src/nodemetadata.cpp | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/nodemetadata.cpp b/src/nodemetadata.cpp index 126889ecf..0801a028b 100644 --- a/src/nodemetadata.cpp +++ b/src/nodemetadata.cpp @@ -74,6 +74,11 @@ void NodeMetadata::clear() m_inventory->clear(); } +bool NodeMetadata::empty() const +{ + return m_stringvars.size() == 0 && m_inventory->getLists().size() == 0; +} + /* NodeMetadataList */ @@ -84,14 +89,13 @@ void NodeMetadataList::serialize(std::ostream &os) const Version 0 is a placeholder for "nothing to see here; go away." */ - if(m_data.empty()){ + u16 count = countNonEmpty(); + if (count == 0) { writeU8(os, 0); // version return; } writeU8(os, 1); // version - - u16 count = m_data.size(); writeU16(os, count); for(std::map<v3s16, NodeMetadata*>::const_iterator @@ -100,6 +104,8 @@ void NodeMetadataList::serialize(std::ostream &os) const { v3s16 p = i->first; NodeMetadata *data = i->second; + if (data->empty()) + continue; u16 p16 = p.Z * MAP_BLOCKSIZE * MAP_BLOCKSIZE + p.Y * MAP_BLOCKSIZE + p.X; writeU16(os, p16); @@ -200,6 +206,17 @@ void NodeMetadataList::clear() m_data.clear(); } +int NodeMetadataList::countNonEmpty() const +{ + int n = 0; + std::map<v3s16, NodeMetadata*>::const_iterator it; + for (it = m_data.begin(); it != m_data.end(); ++it) { + if (!it->second->empty()) + n++; + } + return n; +} + std::string NodeMetadata::getString(const std::string &name, unsigned short recursion) const { |