Merge pull request #1371 from DayBr3ak/master
issue381, multicache for cBioGen
This commit is contained in:
commit
b590eed42f
@ -208,6 +208,59 @@ void cBioGenCache::InitializeBiomeGen(cIniFile & a_IniFile)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// cBioGenMulticache:
|
||||||
|
|
||||||
|
cBioGenMulticache::cBioGenMulticache(cBiomeGen * a_BioGenToCache, size_t a_CacheSize, size_t a_CachesLength) :
|
||||||
|
m_CachesLength(a_CachesLength)
|
||||||
|
{
|
||||||
|
m_Caches.reserve(a_CachesLength);
|
||||||
|
for (size_t i = 0; i < a_CachesLength; i++)
|
||||||
|
{
|
||||||
|
m_Caches.push_back(new cBioGenCache(a_BioGenToCache, a_CacheSize));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
cBioGenMulticache::~cBioGenMulticache()
|
||||||
|
{
|
||||||
|
for (std::vector<cBiomeGen*>::iterator it = m_Caches.begin(); it != m_Caches.end(); it++)
|
||||||
|
{
|
||||||
|
delete *it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cBioGenMulticache::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap)
|
||||||
|
{
|
||||||
|
const size_t coefficient = 3;
|
||||||
|
const size_t cacheIdx = ((size_t)a_ChunkX + coefficient * (size_t)a_ChunkZ) % m_CachesLength;
|
||||||
|
|
||||||
|
m_Caches[cacheIdx]->GenBiomes(a_ChunkX, a_ChunkZ, a_BiomeMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cBioGenMulticache::InitializeBiomeGen(cIniFile & a_IniFile)
|
||||||
|
{
|
||||||
|
for (std::vector<cBiomeGen*>::iterator it = m_Caches.begin(); it != m_Caches.end(); it++)
|
||||||
|
{
|
||||||
|
cBiomeGen * tmp = *it;
|
||||||
|
tmp->InitializeBiomeGen(a_IniFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// cBiomeGenList:
|
// cBiomeGenList:
|
||||||
|
@ -80,6 +80,32 @@ protected:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class cBioGenMulticache :
|
||||||
|
public cBiomeGen
|
||||||
|
{
|
||||||
|
|
||||||
|
typedef cBiomeGen super;
|
||||||
|
|
||||||
|
public:
|
||||||
|
/*
|
||||||
|
a_CacheSize defines the size of each singular cache
|
||||||
|
a_CachesLength defines how many caches are used for the multicache
|
||||||
|
*/
|
||||||
|
cBioGenMulticache(cBiomeGen * a_BioGenToCache, size_t a_CacheSize, size_t a_CachesLength); // Doesn't take ownership of a_BioGenToCache
|
||||||
|
~cBioGenMulticache();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
size_t m_CachesLength;
|
||||||
|
std::vector<cBiomeGen*> m_Caches;
|
||||||
|
|
||||||
|
virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override;
|
||||||
|
virtual void InitializeBiomeGen(cIniFile & a_IniFile) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Base class for generators that use a list of available biomes. This class takes care of the list.
|
/// Base class for generators that use a list of available biomes. This class takes care of the list.
|
||||||
class cBiomeGenList :
|
class cBiomeGenList :
|
||||||
public cBiomeGen
|
public cBiomeGen
|
||||||
|
@ -230,6 +230,8 @@ void cComposableGenerator::InitBiomeGen(cIniFile & a_IniFile)
|
|||||||
|
|
||||||
// Add a cache, if requested:
|
// Add a cache, if requested:
|
||||||
int CacheSize = a_IniFile.GetValueSetI("Generator", "BiomeGenCacheSize", CacheOffByDefault ? 0 : 64);
|
int CacheSize = a_IniFile.GetValueSetI("Generator", "BiomeGenCacheSize", CacheOffByDefault ? 0 : 64);
|
||||||
|
int MultiCacheLength = a_IniFile.GetValueSetI("Generator", "BiomeGenMultiCacheLength", 4);
|
||||||
|
|
||||||
if (CacheSize > 0)
|
if (CacheSize > 0)
|
||||||
{
|
{
|
||||||
if (CacheSize < 4)
|
if (CacheSize < 4)
|
||||||
@ -241,7 +243,16 @@ void cComposableGenerator::InitBiomeGen(cIniFile & a_IniFile)
|
|||||||
}
|
}
|
||||||
LOGD("Using a cache for biomegen of size %d.", CacheSize);
|
LOGD("Using a cache for biomegen of size %d.", CacheSize);
|
||||||
m_UnderlyingBiomeGen = m_BiomeGen;
|
m_UnderlyingBiomeGen = m_BiomeGen;
|
||||||
m_BiomeGen = new cBioGenCache(m_UnderlyingBiomeGen, CacheSize);
|
if (MultiCacheLength > 0)
|
||||||
|
{
|
||||||
|
LOGD("Enabling multicache for biomegen of length %d.", MultiCacheLength);
|
||||||
|
m_BiomeGen = new cBioGenMulticache(m_UnderlyingBiomeGen, CacheSize, MultiCacheLength);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_BiomeGen = new cBioGenCache(m_UnderlyingBiomeGen, CacheSize);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user