QtBiomeVisualiser: removed multithreading.
It was slowing things down, the granularity is too fine.
This commit is contained in:
parent
d772bc032f
commit
84947a22ad
@ -142,7 +142,6 @@ static void biomesToImage(cChunkDef::BiomeMap & a_Biomes, Chunk::Image & a_Image
|
|||||||
|
|
||||||
BioGenSource::BioGenSource(QString a_WorldIniPath) :
|
BioGenSource::BioGenSource(QString a_WorldIniPath) :
|
||||||
m_WorldIniPath(a_WorldIniPath),
|
m_WorldIniPath(a_WorldIniPath),
|
||||||
m_WorldIni(new cIniFile),
|
|
||||||
m_Mtx(QMutex::Recursive)
|
m_Mtx(QMutex::Recursive)
|
||||||
{
|
{
|
||||||
reload();
|
reload();
|
||||||
@ -154,14 +153,11 @@ BioGenSource::BioGenSource(QString a_WorldIniPath) :
|
|||||||
|
|
||||||
void BioGenSource::getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChunk)
|
void BioGenSource::getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChunk)
|
||||||
{
|
{
|
||||||
cBiomeGenPtr biomeGen;
|
cChunkDef::BiomeMap biomes;
|
||||||
{
|
{
|
||||||
QMutexLocker lock(&m_Mtx);
|
QMutexLocker lock(&m_Mtx);
|
||||||
biomeGen = getBiomeGen();
|
m_BiomeGen->GenBiomes(a_ChunkX, a_ChunkZ, biomes);
|
||||||
}
|
}
|
||||||
cChunkDef::BiomeMap biomes;
|
|
||||||
biomeGen->GenBiomes(a_ChunkX, a_ChunkZ, biomes);
|
|
||||||
releaseBiomeGen(biomeGen);
|
|
||||||
Chunk::Image img;
|
Chunk::Image img;
|
||||||
biomesToImage(biomes, img);
|
biomesToImage(biomes, img);
|
||||||
a_DestChunk->setImage(img);
|
a_DestChunk->setImage(img);
|
||||||
@ -173,52 +169,15 @@ void BioGenSource::getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChu
|
|||||||
|
|
||||||
void BioGenSource::reload()
|
void BioGenSource::reload()
|
||||||
{
|
{
|
||||||
|
cIniFile ini;
|
||||||
|
if (!ini.ReadFile(m_WorldIniPath.toStdString()))
|
||||||
{
|
{
|
||||||
QMutexLocker lock(&m_Mtx);
|
return;
|
||||||
if (!m_WorldIni->ReadFile(m_WorldIniPath.toStdString()))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_AvailableGens.clear();
|
|
||||||
}
|
}
|
||||||
}
|
int seed = ini.GetValueSetI("Seed", "Seed", 0);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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;
|
bool unused = false;
|
||||||
return cBiomeGenPtr(cBiomeGen::CreateBiomeGen(*m_WorldIni, seed, unused));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void BioGenSource::releaseBiomeGen(cBiomeGenPtr a_BiomeGen)
|
|
||||||
{
|
|
||||||
QMutexLocker lock(&m_Mtx);
|
QMutexLocker lock(&m_Mtx);
|
||||||
m_AvailableGens.push_back(a_BiomeGen);
|
m_BiomeGen.reset(cBiomeGen::CreateBiomeGen(ini, seed, unused));
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,25 +49,11 @@ protected:
|
|||||||
/** Path to the world.ini file from which the m_WorldIni is regenerated on reload requests. */
|
/** Path to the world.ini file from which the m_WorldIni is regenerated on reload requests. */
|
||||||
QString m_WorldIniPath;
|
QString m_WorldIniPath;
|
||||||
|
|
||||||
/** Parsed contents of the world.ini file from which the biome generators are initialized.
|
/** The generator used for generating biomes. */
|
||||||
Locked by m_Mtx to avoid multithreaded access. */
|
std::unique_ptr<cBiomeGen> m_BiomeGen;
|
||||||
std::unique_ptr<cIniFile> m_WorldIni;
|
|
||||||
|
|
||||||
/** List of cBiomeGen instances that are "free" - aren't doing any generating at this moment.
|
/** Guards m_BiomeGen against multithreaded access. */
|
||||||
Locked by m_Mtx to avoid multithreaded access. */
|
|
||||||
std::vector<cBiomeGenPtr> m_AvailableGens;
|
|
||||||
|
|
||||||
/** Guards m_AvailableGens and m_WorldIni against multithreaded access. */
|
|
||||||
QMutex m_Mtx;
|
QMutex m_Mtx;
|
||||||
|
|
||||||
|
|
||||||
/** Returns a cBiomeGen that can generate a new chunk's biomes.
|
|
||||||
Uses m_AvailableGens as a cache before creating a new generator. */
|
|
||||||
cBiomeGenPtr BioGenSource::getBiomeGen();
|
|
||||||
|
|
||||||
/** Puts the specified BiomeGen back to m_AvailableGens to make it available for next getBiomeGen() request.
|
|
||||||
Truncates m_AvailableGens if there are too many instances in there. */
|
|
||||||
void releaseBiomeGen(cBiomeGenPtr a_BiomeGen);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user