summaryrefslogtreecommitdiffstats
path: root/Tools/QtBiomeVisualiser/ChunkSource.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-10-30 12:22:15 +0100
committerMattes D <github@xoft.cz>2014-10-30 12:22:15 +0100
commit30db6d9852e7dc4ba5f7d4a9d783ae8a6d4c4f79 (patch)
tree574b3c572b0b06e1733f4854fd46ca20147ab575 /Tools/QtBiomeVisualiser/ChunkSource.cpp
parentMerge pull request #1575 from mc-server/1.8-Item (diff)
parentQtBiomeVisualiser: Generator uses all machine threads. (diff)
downloadcuberite-30db6d9852e7dc4ba5f7d4a9d783ae8a6d4c4f79.tar
cuberite-30db6d9852e7dc4ba5f7d4a9d783ae8a6d4c4f79.tar.gz
cuberite-30db6d9852e7dc4ba5f7d4a9d783ae8a6d4c4f79.tar.bz2
cuberite-30db6d9852e7dc4ba5f7d4a9d783ae8a6d4c4f79.tar.lz
cuberite-30db6d9852e7dc4ba5f7d4a9d783ae8a6d4c4f79.tar.xz
cuberite-30db6d9852e7dc4ba5f7d4a9d783ae8a6d4c4f79.tar.zst
cuberite-30db6d9852e7dc4ba5f7d4a9d783ae8a6d4c4f79.zip
Diffstat (limited to '')
-rw-r--r--Tools/QtBiomeVisualiser/ChunkSource.cpp57
1 files changed, 50 insertions, 7 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));
}