diff options
author | Mattes D <github@xoft.cz> | 2014-09-15 16:50:40 +0200 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2014-09-15 16:50:40 +0200 |
commit | d772bc032f12bceac2d974ad9165597edabe5b0a (patch) | |
tree | 609648207d15494012b08f95e38b2a156ec50c93 /Tools/QtBiomeVisualiser/ChunkSource.cpp | |
parent | QtBiomeVisualiser: Extended zoom down below 100%. (diff) | |
download | cuberite-d772bc032f12bceac2d974ad9165597edabe5b0a.tar cuberite-d772bc032f12bceac2d974ad9165597edabe5b0a.tar.gz cuberite-d772bc032f12bceac2d974ad9165597edabe5b0a.tar.bz2 cuberite-d772bc032f12bceac2d974ad9165597edabe5b0a.tar.lz cuberite-d772bc032f12bceac2d974ad9165597edabe5b0a.tar.xz cuberite-d772bc032f12bceac2d974ad9165597edabe5b0a.tar.zst cuberite-d772bc032f12bceac2d974ad9165597edabe5b0a.zip |
Diffstat (limited to 'Tools/QtBiomeVisualiser/ChunkSource.cpp')
-rw-r--r-- | Tools/QtBiomeVisualiser/ChunkSource.cpp | 74 |
1 files changed, 68 insertions, 6 deletions
diff --git a/Tools/QtBiomeVisualiser/ChunkSource.cpp b/Tools/QtBiomeVisualiser/ChunkSource.cpp index 44dcf1fa7..5658198f4 100644 --- a/Tools/QtBiomeVisualiser/ChunkSource.cpp +++ b/Tools/QtBiomeVisualiser/ChunkSource.cpp @@ -1,6 +1,8 @@ #include "Globals.h" #include "ChunkSource.h" +#include <QThread> #include "Generating/BioGen.h" +#include "inifile/iniFile.h" @@ -138,9 +140,12 @@ static void biomesToImage(cChunkDef::BiomeMap & a_Biomes, Chunk::Image & a_Image //////////////////////////////////////////////////////////////////////////////// // BioGenSource: -BioGenSource::BioGenSource(cBiomeGen * a_BiomeGen) : - m_BiomeGen(a_BiomeGen) +BioGenSource::BioGenSource(QString a_WorldIniPath) : + m_WorldIniPath(a_WorldIniPath), + m_WorldIni(new cIniFile), + m_Mtx(QMutex::Recursive) { + reload(); } @@ -149,11 +154,14 @@ BioGenSource::BioGenSource(cBiomeGen * a_BiomeGen) : void BioGenSource::getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChunk) { - // TODO: To make use of multicore machines, we need multiple copies of the biomegen - // Right now we have only one, so we can let only one thread use it (hence the mutex) - QMutexLocker lock(&m_Mtx); + cBiomeGenPtr biomeGen; + { + QMutexLocker lock(&m_Mtx); + biomeGen = getBiomeGen(); + } cChunkDef::BiomeMap biomes; - m_BiomeGen->GenBiomes(a_ChunkX, a_ChunkZ, biomes); + biomeGen->GenBiomes(a_ChunkX, a_ChunkZ, biomes); + releaseBiomeGen(biomeGen); Chunk::Image img; biomesToImage(biomes, img); a_DestChunk->setImage(img); @@ -162,3 +170,57 @@ void BioGenSource::getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChu + +void BioGenSource::reload() +{ + { + QMutexLocker lock(&m_Mtx); + if (!m_WorldIni->ReadFile(m_WorldIniPath.toStdString())) + { + return; + } + m_AvailableGens.clear(); + } +} + + + + +cBiomeGenPtr BioGenSource::getBiomeGen() +{ + QMutexLocker lock(&m_Mtx); + + // Return a generator from the cache, if available: + if (!m_AvailableGens.empty()) + { + cBiomeGenPtr res = m_AvailableGens.back(); + m_AvailableGens.pop_back(); + return res; + } + + // No generator in cache available, create a new one: + int seed = m_WorldIni->GetValueSetI("Seed", "Seed", 0); + bool unused = false; + return cBiomeGenPtr(cBiomeGen::CreateBiomeGen(*m_WorldIni, seed, unused)); +} + + + + + +void BioGenSource::releaseBiomeGen(cBiomeGenPtr a_BiomeGen) +{ + QMutexLocker lock(&m_Mtx); + m_AvailableGens.push_back(a_BiomeGen); + + // Trim the cache if there are too many gens: + int wantedNumGens = QThread::idealThreadCount(); + if (m_AvailableGens.size() > (size_t)(4 * wantedNumGens)) + { + m_AvailableGens.resize(wantedNumGens); + } +} + + + + |