From 5e831256ef838e0238a6fd5eaf3b3e39791c6d77 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Sat, 2 Jun 2012 13:21:59 +0000 Subject: Added a cBioGenCache object for caching generated biomes git-svn-id: http://mc-server.googlecode.com/svn/trunk@537 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cChunkGenerator.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'source/cChunkGenerator.cpp') diff --git a/source/cChunkGenerator.cpp b/source/cChunkGenerator.cpp index 5aa50c20a..1687e0e13 100644 --- a/source/cChunkGenerator.cpp +++ b/source/cChunkGenerator.cpp @@ -111,6 +111,7 @@ void cChunkGenerator::InitBiomeGen(cIniFile & a_IniFile) BiomeGenName = "constant"; } + bool CacheOffByDefault = false; if (NoCaseCompare(BiomeGenName, "constant") == 0) { AString Biome = a_IniFile.GetValue("Generator", "ConstantBiome", "Plains"); @@ -121,12 +122,14 @@ void cChunkGenerator::InitBiomeGen(cIniFile & a_IniFile) b = biPlains; } m_BiomeGen = new cBioGenConstant(b); + CacheOffByDefault = true; // we're generating faster than a cache would retrieve data :) } else if (NoCaseCompare(BiomeGenName, "checkerboard") == 0) { int BiomeSize = a_IniFile.GetValueI("Generator", "CheckerboardBiomeSize", 64); AString Biomes = a_IniFile.GetValue("Generator", "CheckerBoardBiomes", ""); m_BiomeGen = new cBioGenCheckerboard(BiomeSize, Biomes); + CacheOffByDefault = true; // we're (probably) generating faster than a cache would retrieve data } else if (NoCaseCompare(BiomeGenName, "voronoi") == 0) { @@ -144,6 +147,21 @@ void cChunkGenerator::InitBiomeGen(cIniFile & a_IniFile) AString Biomes = a_IniFile.GetValue("Generator", "DistortedVoronoiBiomes", ""); m_BiomeGen = new cBioGenDistortedVoronoi(m_Seed, CellSize, Biomes); } + + // Add a cache, if requested: + int CacheSize = a_IniFile.GetValueI("Generator", "BiomeGenCacheSize", CacheOffByDefault ? 0 : 64); + if (CacheSize > 0) + { + if (CacheSize < 4) + { + LOGWARNING("Biomegen cache size set too low, would hurt performance instead of helping. Increasing from %d to %d", + CacheSize, 4 + ); + CacheSize = 4; + } + LOGINFO("Using a cache for biomegen of size %d.", CacheSize); + m_BiomeGen = new cBioGenCache(m_BiomeGen, CacheSize); + } } -- cgit v1.2.3