From f4f2fc7c3d76eb3dc5a91c5eefb36c10597d6cb7 Mon Sep 17 00:00:00 2001 From: peterbell10 Date: Fri, 25 Aug 2017 13:43:18 +0100 Subject: Add cUUID class (#3871) --- src/WorldStorage/NBTChunkSerializer.cpp | 11 ++++++----- src/WorldStorage/WSSAnvil.cpp | 35 +++++++++++++++------------------ src/WorldStorage/WSSAnvil.h | 5 +++-- 3 files changed, 25 insertions(+), 26 deletions(-) (limited to 'src/WorldStorage') diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 8c60aac0d..73c633e1a 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -7,6 +7,7 @@ #include "EnchantmentSerializer.h" #include "../ItemGrid.h" #include "../StringCompression.h" +#include "../UUID.h" #include "FastNBT.h" #include "../BlockEntities/BeaconEntity.h" @@ -382,7 +383,7 @@ void cNBTChunkSerializer::AddMobHeadEntity(cMobHeadEntity * a_MobHead) // The new Block Entity format for a Mob Head. See: https://minecraft.gamepedia.com/Head#Block_entity m_Writer.BeginCompound("Owner"); - m_Writer.AddString("Id", a_MobHead->GetOwnerUUID()); + m_Writer.AddString("Id", a_MobHead->GetOwnerUUID().ToShortString()); m_Writer.AddString("Name", a_MobHead->GetOwnerName()); m_Writer.BeginCompound("Properties"); m_Writer.BeginList("textures", TAG_Compound); @@ -679,9 +680,9 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster) { m_Writer.AddString("Owner", Wolf->GetOwnerName()); } - if (!Wolf->GetOwnerUUID().empty()) + if (!Wolf->GetOwnerUUID().IsNil()) { - m_Writer.AddString("OwnerUUID", Wolf->GetOwnerUUID()); + m_Writer.AddString("OwnerUUID", Wolf->GetOwnerUUID().ToShortString()); } m_Writer.AddByte("Sitting", Wolf->IsSitting() ? 1 : 0); m_Writer.AddByte("Angry", Wolf->IsAngry() ? 1 : 0); @@ -709,9 +710,9 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster) { m_Writer.AddString("Owner", Ocelot->GetOwnerName()); } - if (!Ocelot->GetOwnerUUID().empty()) + if (!Ocelot->GetOwnerUUID().IsNil()) { - m_Writer.AddString("OwnerUUID", Ocelot->GetOwnerUUID()); + m_Writer.AddString("OwnerUUID", Ocelot->GetOwnerUUID().ToShortString()); } m_Writer.AddByte("Sitting", Ocelot->IsSitting() ? 1 : 0); m_Writer.AddInt ("CatType", Ocelot->GetOcelotType()); diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 7aa3eb0cd..bbbffb07f 100755 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1398,12 +1398,13 @@ cBlockEntity * cWSSAnvil::LoadMobHeadFromNBT(const cParsedNBT & a_NBT, int a_Tag int ownerLine = a_NBT.FindChildByName(a_TagIdx, "Owner"); if (ownerLine >= 0) { - AString OwnerName, OwnerUUID, OwnerTexture, OwnerTextureSignature; + AString OwnerName, OwnerTexture, OwnerTextureSignature; + cUUID OwnerUUID; currentLine = a_NBT.FindChildByName(ownerLine, "Id"); if (currentLine >= 0) { - OwnerUUID = a_NBT.GetString(currentLine); + OwnerUUID.FromString(a_NBT.GetString(currentLine)); } currentLine = a_NBT.FindChildByName(ownerLine, "Name"); @@ -2526,7 +2527,7 @@ void cWSSAnvil::LoadOcelotFromNBT(cEntityList & a_Entities, const cParsedNBT & a } auto OwnerInfo = LoadEntityOwner(a_NBT, a_TagIdx); - if (!OwnerInfo.first.empty() && !OwnerInfo.second.empty()) + if (!OwnerInfo.first.empty() && !OwnerInfo.second.IsNil()) { Monster->SetOwner(OwnerInfo.first, OwnerInfo.second); Monster->SetIsTame(true); @@ -2927,7 +2928,7 @@ void cWSSAnvil::LoadWolfFromNBT(cEntityList & a_Entities, const cParsedNBT & a_N } auto OwnerInfo = LoadEntityOwner(a_NBT, a_TagIdx); - if (!OwnerInfo.first.empty() && !OwnerInfo.second.empty()) + if (!OwnerInfo.first.empty() && !OwnerInfo.second.IsNil()) { Monster->SetOwner(OwnerInfo.first, OwnerInfo.second); Monster->SetIsTame(true); @@ -3064,43 +3065,39 @@ void cWSSAnvil::LoadPigZombieFromNBT(cEntityList & a_Entities, const cParsedNBT -std::pair cWSSAnvil::LoadEntityOwner(const cParsedNBT & a_NBT, int a_TagIdx) +std::pair cWSSAnvil::LoadEntityOwner(const cParsedNBT & a_NBT, int a_TagIdx) { // Load the owner information. OwnerUUID or Owner may be specified, possibly both: - AString OwnerUUID, OwnerName; + AString OwnerName; + cUUID OwnerUUID; int OwnerUUIDIdx = a_NBT.FindChildByName(a_TagIdx, "OwnerUUID"); if (OwnerUUIDIdx > 0) { - OwnerUUID = a_NBT.GetString(OwnerUUIDIdx); + OwnerUUID.FromString(a_NBT.GetString(OwnerUUIDIdx)); } int OwnerIdx = a_NBT.FindChildByName(a_TagIdx, "Owner"); if (OwnerIdx > 0) { OwnerName = a_NBT.GetString(OwnerIdx); } - if (OwnerName.empty() && OwnerUUID.empty()) + if (OwnerName.empty() && OwnerUUID.IsNil()) { // There is no owner, bail out: - return std::pair(); + return {}; } // Convert name to UUID, if needed: - if (OwnerUUID.empty()) + if (OwnerUUID.IsNil()) { // This entity has only playername stored (pre-1.7.6), look up the UUID // The lookup is blocking, but we're running in a separate thread, so it's ok OwnerUUID = cRoot::Get()->GetMojangAPI().GetUUIDFromPlayerName(OwnerName); - if (OwnerUUID.empty()) + if (OwnerUUID.IsNil()) { // Not a known player, un-tame the entity by bailing out - return std::pair(); + return {}; } } - else - { - // Normalize the UUID: - OwnerUUID = cMojangAPI::MakeUUIDShort(OwnerUUID); - } // Convert UUID to name, if needed: if (OwnerName.empty()) @@ -3110,11 +3107,11 @@ std::pair cWSSAnvil::LoadEntityOwner(const cParsedNBT & a_NBT, if (OwnerName.empty()) { // Not a known player, un-tame the entity by bailing out - return std::pair(); + return {}; } } - return std::make_pair(OwnerName, OwnerUUID); + return { OwnerName, OwnerUUID }; } diff --git a/src/WorldStorage/WSSAnvil.h b/src/WorldStorage/WSSAnvil.h index a53d8d8c4..0f32d1a2e 100755 --- a/src/WorldStorage/WSSAnvil.h +++ b/src/WorldStorage/WSSAnvil.h @@ -20,6 +20,7 @@ class cItemGrid; class cMonster; class cProjectileEntity; class cHangingEntity; +class cUUID; @@ -230,8 +231,8 @@ protected: void LoadPigZombieFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx); /** Loads the owner name and UUID from the entity at the specified NBT tag. - Returns a pair of {name, uuid}. If the entity is not owned, both are empty strings. */ - std::pair LoadEntityOwner(const cParsedNBT & a_NBT, int a_TagIdx); + Returns a pair of {name, uuid}. If the entity is not owned, name is an empty string and uuid is nil. */ + std::pair LoadEntityOwner(const cParsedNBT & a_NBT, int a_TagIdx); /** Loads entity common data from the NBT compound; returns true if successful */ bool LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIdx); -- cgit v1.2.3 From 447d929da18b656227c77d9c00958bcf52afeeb2 Mon Sep 17 00:00:00 2001 From: peterbell10 Date: Sun, 20 Aug 2017 23:23:23 +0100 Subject: Implement anvil chunk sparsing --- src/WorldStorage/NBTChunkSerializer.cpp | 6 +++--- src/WorldStorage/NBTChunkSerializer.h | 13 +++++-------- src/WorldStorage/WSSAnvil.cpp | 32 +++++++++++++++++--------------- 3 files changed, 25 insertions(+), 26 deletions(-) (limited to 'src/WorldStorage') diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 73c633e1a..1e8543648 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -68,11 +68,11 @@ void cNBTChunkSerializer::Finish(void) m_Writer.EndList(); } - // If light not valid, reset it to all zeroes: + // If light not valid, reset it to defaults: if (!m_IsLightValid) { - memset(m_BlockLight, 0, sizeof(m_BlockLight)); - memset(m_BlockSkyLight, 0, sizeof(m_BlockSkyLight)); + m_Data.FillBlockLight(0x00); + m_Data.FillSkyLight(0x0f); } // Check if "Entity" and "TileEntities" lists exists. MCEdit requires this. diff --git a/src/WorldStorage/NBTChunkSerializer.h b/src/WorldStorage/NBTChunkSerializer.h index 3637ea655..50d98a518 100644 --- a/src/WorldStorage/NBTChunkSerializer.h +++ b/src/WorldStorage/NBTChunkSerializer.h @@ -1,4 +1,4 @@ - + // NBTChunkSerializer.h // Declares the cNBTChunkSerializer class that is used for saving individual chunks into NBT format used by Anvil @@ -55,7 +55,7 @@ class cPainting; class cNBTChunkSerializer : - public cChunkDataSeparateCollector + public cChunkDataCopyCollector { public: cChunkDef::BiomeMap m_Biomes; @@ -69,15 +69,12 @@ public: /** Close NBT tags that we've opened */ void Finish(void); - bool IsLightValid(void) const {return m_IsLightValid; } + bool IsLightValid(void) const { return m_IsLightValid; } protected: - /* From cChunkDataSeparateCollector we inherit: - - m_BlockTypes[] - - m_BlockMetas[] - - m_BlockLight[] - - m_BlockSkyLight[] */ + /* From cChunkDataCopyCollector we inherit: + - cChunkData m_Data */ cFastNBTWriter & m_Writer; diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index bbbffb07f..a3251481f 100755 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -515,23 +515,25 @@ bool cWSSAnvil::SaveChunkToNBT(const cChunkCoords & a_Chunk, cFastNBTWriter & a_ // Save blockdata: a_Writer.BeginList("Sections", TAG_Compound); - size_t SliceSizeBlock = cChunkDef::Width * cChunkDef::Width * 16; - size_t SliceSizeNibble = SliceSizeBlock / 2; - const char * BlockTypes = reinterpret_cast(Serializer.m_BlockTypes); - const char * BlockMetas = reinterpret_cast(Serializer.m_BlockMetas); - #ifdef DEBUG_SKYLIGHT - const char * BlockLight = reinterpret_cast(Serializer.m_BlockSkyLight); - #else - const char * BlockLight = reinterpret_cast(Serializer.m_BlockLight); - #endif - const char * BlockSkyLight = reinterpret_cast(Serializer.m_BlockSkyLight); - for (int Y = 0; Y < 16; Y++) + for (size_t Y = 0; Y != cChunkData::NumSections; ++Y) { + auto Section = Serializer.m_Data.GetSection(Y); + if (Section == nullptr) + { + continue; + } + a_Writer.BeginCompound(""); - a_Writer.AddByteArray("Blocks", BlockTypes + static_cast(Y) * SliceSizeBlock, SliceSizeBlock); - a_Writer.AddByteArray("Data", BlockMetas + static_cast(Y) * SliceSizeNibble, SliceSizeNibble); - a_Writer.AddByteArray("SkyLight", BlockSkyLight + static_cast(Y) * SliceSizeNibble, SliceSizeNibble); - a_Writer.AddByteArray("BlockLight", BlockLight + static_cast(Y) * SliceSizeNibble, SliceSizeNibble); + a_Writer.AddByteArray("Blocks", reinterpret_cast(Section->m_BlockTypes), ARRAYCOUNT(Section->m_BlockTypes)); + a_Writer.AddByteArray("Data", reinterpret_cast(Section->m_BlockMetas), ARRAYCOUNT(Section->m_BlockMetas)); + + #ifdef DEBUG_SKYLIGHT + a_Writer.AddByteArray("BlockLight", reinterpret_cast(Section->m_BlockSkyLight), ARRAYCOUNT(Section->m_BlockSkyLight)); + #else + a_Writer.AddByteArray("BlockLight", reinterpret_cast(Section->m_BlockLight), ARRAYCOUNT(Section->m_BlockLight)); + #endif + + a_Writer.AddByteArray("SkyLight", reinterpret_cast(Section->m_BlockSkyLight), ARRAYCOUNT(Section->m_BlockSkyLight)); a_Writer.AddByte("Y", static_cast(Y)); a_Writer.EndCompound(); } -- cgit v1.2.3