diff options
author | Mattes D <github@xoft.cz> | 2014-10-30 12:50:55 +0100 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2014-10-30 12:50:55 +0100 |
commit | 93f33b7d4eda4c6010827dc2a6522c3da34619f8 (patch) | |
tree | 122df2ff1cd5bb1b24aaf903aec5fce19cf8207d | |
parent | Grown biomes: made biomes smaller, made beaches smaller. (diff) | |
parent | Merge pull request #1576 from mc-server/QtBiomeVisualiserThreadedGen (diff) | |
download | cuberite-93f33b7d4eda4c6010827dc2a6522c3da34619f8.tar cuberite-93f33b7d4eda4c6010827dc2a6522c3da34619f8.tar.gz cuberite-93f33b7d4eda4c6010827dc2a6522c3da34619f8.tar.bz2 cuberite-93f33b7d4eda4c6010827dc2a6522c3da34619f8.tar.lz cuberite-93f33b7d4eda4c6010827dc2a6522c3da34619f8.tar.xz cuberite-93f33b7d4eda4c6010827dc2a6522c3da34619f8.tar.zst cuberite-93f33b7d4eda4c6010827dc2a6522c3da34619f8.zip |
Diffstat (limited to '')
-rw-r--r-- | Tools/QtBiomeVisualiser/ChunkSource.cpp | 57 | ||||
-rw-r--r-- | Tools/QtBiomeVisualiser/ChunkSource.h | 24 | ||||
-rw-r--r-- | src/BlockID.cpp | 7 | ||||
-rw-r--r-- | src/WorldStorage/WSSAnvil.cpp | 21 |
4 files changed, 97 insertions, 12 deletions
diff --git a/Tools/QtBiomeVisualiser/ChunkSource.cpp b/Tools/QtBiomeVisualiser/ChunkSource.cpp index d9660b886..ea3346f04 100644 --- a/Tools/QtBiomeVisualiser/ChunkSource.cpp +++ b/Tools/QtBiomeVisualiser/ChunkSource.cpp @@ -27,10 +27,10 @@ BioGenSource::BioGenSource(cIniFilePtr a_IniFile) : void BioGenSource::getChunkBiomes(int a_ChunkX, int a_ChunkZ, Chunk & a_DestChunk) { cChunkDef::BiomeMap biomes; - { - QMutexLocker lock(&m_Mtx); - m_BiomeGen->GenBiomes(a_ChunkX, a_ChunkZ, biomes); - } + int tag; + cBiomeGenPtr biomeGen = getBiomeGen(tag); + biomeGen->GenBiomes(a_ChunkX, a_ChunkZ, biomes); + releaseBiomeGen(std::move(biomeGen), tag); a_DestChunk.setBiomes(biomes); } @@ -40,10 +40,53 @@ void BioGenSource::getChunkBiomes(int a_ChunkX, int a_ChunkZ, Chunk & a_DestChun void BioGenSource::reload() { - int seed = m_IniFile->GetValueSetI("Seed", "Seed", 0); - bool unused = false; QMutexLocker lock(&m_Mtx); - m_BiomeGen = cBiomeGen::CreateBiomeGen(*m_IniFile, seed, unused); + m_CurrentTag += 1; + m_BiomeGens.clear(); +} + + + + + +cBiomeGenPtr BioGenSource::getBiomeGen(int & a_Tag) +{ + QMutexLocker lock(&m_Mtx); + a_Tag = m_CurrentTag; + if (m_BiomeGens.empty()) + { + // Create a new biogen: + lock.unlock(); + int seed = m_IniFile->GetValueSetI("Seed", "Seed", 0); + bool unused; + cBiomeGenPtr res = cBiomeGen::CreateBiomeGen(*m_IniFile, seed, unused); + return res; + } + else + { + // Return an existing biogen: + cBiomeGenPtr res = m_BiomeGens.back(); + m_BiomeGens.pop_back(); + return res; + } +} + + + + + +void BioGenSource::releaseBiomeGen(cBiomeGenPtr && a_BiomeGen, int a_Tag) +{ + QMutexLocker lock(&m_Mtx); + + // If the tag differs, the source has been reloaded and this biogen is old, dispose: + if (a_Tag != m_CurrentTag) + { + return; + } + + // The tag is the same, put the biogen back to list: + m_BiomeGens.push_back(std::move(a_BiomeGen)); } diff --git a/Tools/QtBiomeVisualiser/ChunkSource.h b/Tools/QtBiomeVisualiser/ChunkSource.h index a6bc3849b..62f9b5626 100644 --- a/Tools/QtBiomeVisualiser/ChunkSource.h +++ b/Tools/QtBiomeVisualiser/ChunkSource.h @@ -53,10 +53,30 @@ protected: cIniFilePtr m_IniFile; /** The generator used for generating biomes. */ - cBiomeGenPtr m_BiomeGen; + std::vector<cBiomeGenPtr> m_BiomeGens; - /** Guards m_BiomeGen against multithreaded access. */ + /** Guards m_BiomeGens against multithreaded access. */ QMutex m_Mtx; + + /** Keeps track of the current settings of the biomegens. + Incremented by one each time reload() is called. Provides the means of releasing old biomegens that were + in use while reload() was being processed and thus couldn't be changed back then. releaseBiomeGen() does + the job of filtering the biogens before reusing them. */ + int m_CurrentTag; + + + /** Retrieves one cBiomeGenPtr from m_BiomeGens. + If there's no biogen available there, creates a new one based on the ini file. + When done with it, the caller should call releaseBiomeGen() to put the biogen back to m_BiomeGens. + a_Tag receives the value of m_CurrentTag from when the lock was held; it should be passed to + releaseBiomeGen() together with the biogen. */ + cBiomeGenPtr getBiomeGen(int & a_Tag); + + /** Marks the specified biogen as available for reuse (puts it back into m_BiomeGens). + a_Tag is the value of m_CurrentTag from the time when the biogen was retrieved; if it is different from + current m_CurrentTagValue, the biogen will be disposed of (because reload() has been called in the + meantime). */ + void releaseBiomeGen(cBiomeGenPtr && a_BiomeGen, int a_Tag); }; diff --git a/src/BlockID.cpp b/src/BlockID.cpp index c0f3193bb..c98e0cad1 100644 --- a/src/BlockID.cpp +++ b/src/BlockID.cpp @@ -217,7 +217,12 @@ BLOCKTYPE BlockStringToType(const AString & a_BlockTypeString) bool StringToItem(const AString & a_ItemTypeString, cItem & a_Item) { - return gsBlockIDMap.ResolveItem(TrimString(a_ItemTypeString), a_Item); + AString ItemName = TrimString(a_ItemTypeString); + if (ItemName.substr(0, 10) == "minecraft:") + { + ItemName = ItemName.substr(10); + } + return gsBlockIDMap.ResolveItem(ItemName, a_Item); } diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index af7551ee4..0c77b4d67 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -696,11 +696,28 @@ cBlockEntity * cWSSAnvil::LoadBlockEntityFromNBT(const cParsedNBT & a_NBT, int a bool cWSSAnvil::LoadItemFromNBT(cItem & a_Item, const cParsedNBT & a_NBT, int a_TagIdx) { int Type = a_NBT.FindChildByName(a_TagIdx, "id"); - if ((Type < 0) || (a_NBT.GetType(Type) != TAG_Short)) + if (Type <= 0) { return false; } - a_Item.m_ItemType = a_NBT.GetShort(Type); + + if (a_NBT.GetType(Type) == TAG_String) + { + if (!StringToItem(a_NBT.GetString(Type), a_Item)) + { + // Can't resolve item type + return false; + } + } + else if (a_NBT.GetType(Type) == TAG_Short) + { + a_Item.m_ItemType = a_NBT.GetShort(Type); + } + else + { + return false; + } + if (a_Item.m_ItemType < 0) { a_Item.Empty(); |