From f424a0ec60afe92b9c0a4d7f56e422cc5e921401 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 29 Sep 2014 21:20:58 +0200 Subject: QtBiomeVisualiser: Seed is read properly. --- Tools/QtBiomeVisualiser/ChunkSource.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Tools/QtBiomeVisualiser/ChunkSource.cpp') diff --git a/Tools/QtBiomeVisualiser/ChunkSource.cpp b/Tools/QtBiomeVisualiser/ChunkSource.cpp index bebf89a0a..2d180f00f 100644 --- a/Tools/QtBiomeVisualiser/ChunkSource.cpp +++ b/Tools/QtBiomeVisualiser/ChunkSource.cpp @@ -171,7 +171,7 @@ void BioGenSource::getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChu void BioGenSource::reload() { - int seed = m_IniFile->GetValueSetI("Generator", "Seed", 0); + int seed = m_IniFile->GetValueSetI("Seed", "Seed", 0); bool unused = false; QMutexLocker lock(&m_Mtx); m_BiomeGen.reset(cBiomeGen::CreateBiomeGen(*m_IniFile, seed, unused)); -- cgit v1.2.3 From 0aa1b5667e0ba97101f60343323c595cc7866c6d Mon Sep 17 00:00:00 2001 From: Mattes D Date: Fri, 3 Oct 2014 19:41:42 +0200 Subject: QtBiomeVisualiser: Added mouse hover info. --- Tools/QtBiomeVisualiser/ChunkSource.cpp | 143 +------------------------------- 1 file changed, 3 insertions(+), 140 deletions(-) (limited to 'Tools/QtBiomeVisualiser/ChunkSource.cpp') diff --git a/Tools/QtBiomeVisualiser/ChunkSource.cpp b/Tools/QtBiomeVisualiser/ChunkSource.cpp index 2d180f00f..e5cd7a75a 100644 --- a/Tools/QtBiomeVisualiser/ChunkSource.cpp +++ b/Tools/QtBiomeVisualiser/ChunkSource.cpp @@ -10,135 +10,6 @@ -/** Map for converting biome values to colors. Initialized from biomeColors[]. */ -static uchar biomeToColor[256 * 4]; - -/** Map for converting biome values to colors. Used to initialize biomeToColor[].*/ -static struct -{ - EMCSBiome m_Biome; - uchar m_Color[3]; -} biomeColors[] = -{ - { biOcean, { 0x00, 0x00, 0x70 }, }, - { biPlains, { 0x8d, 0xb3, 0x60 }, }, - { biDesert, { 0xfa, 0x94, 0x18 }, }, - { biExtremeHills, { 0x60, 0x60, 0x60 }, }, - { biForest, { 0x05, 0x66, 0x21 }, }, - { biTaiga, { 0x0b, 0x66, 0x59 }, }, - { biSwampland, { 0x2f, 0xff, 0xda }, }, - { biRiver, { 0x30, 0x30, 0xaf }, }, - { biHell, { 0x7f, 0x00, 0x00 }, }, - { biSky, { 0x00, 0x7f, 0xff }, }, - { biFrozenOcean, { 0xa0, 0xa0, 0xdf }, }, - { biFrozenRiver, { 0xa0, 0xa0, 0xff }, }, - { biIcePlains, { 0xff, 0xff, 0xff }, }, - { biIceMountains, { 0xa0, 0xa0, 0xa0 }, }, - { biMushroomIsland, { 0xff, 0x00, 0xff }, }, - { biMushroomShore, { 0xa0, 0x00, 0xff }, }, - { biBeach, { 0xfa, 0xde, 0x55 }, }, - { biDesertHills, { 0xd2, 0x5f, 0x12 }, }, - { biForestHills, { 0x22, 0x55, 0x1c }, }, - { biTaigaHills, { 0x16, 0x39, 0x33 }, }, - { biExtremeHillsEdge, { 0x7f, 0x8f, 0x7f }, }, - { biJungle, { 0x53, 0x7b, 0x09 }, }, - { biJungleHills, { 0x2c, 0x42, 0x05 }, }, - - { biJungleEdge, { 0x62, 0x8b, 0x17 }, }, - { biDeepOcean, { 0x00, 0x00, 0x30 }, }, - { biStoneBeach, { 0xa2, 0xa2, 0x84 }, }, - { biColdBeach, { 0xfa, 0xf0, 0xc0 }, }, - { biBirchForest, { 0x30, 0x74, 0x44 }, }, - { biBirchForestHills, { 0x1f, 0x5f, 0x32 }, }, - { biRoofedForest, { 0x40, 0x51, 0x1a }, }, - { biColdTaiga, { 0x31, 0x55, 0x4a }, }, - { biColdTaigaHills, { 0x59, 0x7d, 0x72 }, }, - { biMegaTaiga, { 0x59, 0x66, 0x51 }, }, - { biMegaTaigaHills, { 0x59, 0x66, 0x59 }, }, - { biExtremeHillsPlus, { 0x50, 0x70, 0x50 }, }, - { biSavanna, { 0xbd, 0xb2, 0x5f }, }, - { biSavannaPlateau, { 0xa7, 0x9d, 0x64 }, }, - { biMesa, { 0xd9, 0x45, 0x15 }, }, - { biMesaPlateauF, { 0xb0, 0x97, 0x65 }, }, - { biMesaPlateau, { 0xca, 0x8c, 0x65 }, }, - - // M variants: - { biSunflowerPlains, { 0xb5, 0xdb, 0x88 }, }, - { biDesertM, { 0xff, 0xbc, 0x40 }, }, - { biExtremeHillsM, { 0x88, 0x88, 0x88 }, }, - { biFlowerForest, { 0x2d, 0x8e, 0x49 }, }, - { biTaigaM, { 0x33, 0x8e, 0x81 }, }, - { biSwamplandM, { 0x07, 0xf9, 0xb2 }, }, - { biIcePlainsSpikes, { 0xb4, 0xdc, 0xdc }, }, - { biJungleM, { 0x7b, 0xa3, 0x31 }, }, - { biJungleEdgeM, { 0x62, 0x8b, 0x17 }, }, - { biBirchForestM, { 0x58, 0x9c, 0x6c }, }, - { biBirchForestHillsM, { 0x47, 0x87, 0x5a }, }, - { biRoofedForestM, { 0x68, 0x79, 0x42 }, }, - { biColdTaigaM, { 0x24, 0x3f, 0x36 }, }, - { biMegaSpruceTaiga, { 0x45, 0x4f, 0x3e }, }, - { biMegaSpruceTaigaHills, { 0x45, 0x4f, 0x4e }, }, - { biExtremeHillsPlusM, { 0x78, 0x98, 0x78 }, }, - { biSavannaM, { 0xe5, 0xda, 0x87 }, }, - { biSavannaPlateauM, { 0xa7, 0x9d, 0x74 }, }, - { biMesaBryce, { 0xff, 0x6d, 0x3d }, }, - { biMesaPlateauFM, { 0xd8, 0xbf, 0x8d }, }, - { biMesaPlateauM, { 0xf2, 0xb4, 0x8d }, }, -} ; - - - - - -static class BiomeColorsInitializer -{ -public: - BiomeColorsInitializer(void) - { - // Reset all colors to gray: - for (size_t i = 0; i < ARRAYCOUNT(biomeToColor); i++) - { - biomeToColor[i] = 0x7f; - } - - // Set known biomes to their colors: - for (size_t i = 0; i < ARRAYCOUNT(biomeColors); i++) - { - uchar * color = &biomeToColor[4 * biomeColors[i].m_Biome]; - color[0] = biomeColors[i].m_Color[2]; - color[1] = biomeColors[i].m_Color[1]; - color[2] = biomeColors[i].m_Color[0]; - color[3] = 0xff; - } - } -} biomeColorInitializer; - - - - - -/** Converts biomes in an array into the chunk image data. */ -static void biomesToImage(cChunkDef::BiomeMap & a_Biomes, Chunk::Image & a_Image) -{ - // Make sure the two arrays are of the same size, compile-time. - // Note that a_Image is actually 4 items per pixel, so the array is 4 times bigger: - static const char Check1[4 * ARRAYCOUNT(a_Biomes) - ARRAYCOUNT(a_Image) + 1] = {}; - static const char Check2[ARRAYCOUNT(a_Image) - 4 * ARRAYCOUNT(a_Biomes) + 1] = {}; - - // Convert the biomes into color: - for (size_t i = 0; i < ARRAYCOUNT(a_Biomes); i++) - { - a_Image[4 * i + 0] = biomeToColor[4 * a_Biomes[i] + 0]; - a_Image[4 * i + 1] = biomeToColor[4 * a_Biomes[i] + 1]; - a_Image[4 * i + 2] = biomeToColor[4 * a_Biomes[i] + 2]; - a_Image[4 * i + 3] = biomeToColor[4 * a_Biomes[i] + 3]; - } -} - - - - - //////////////////////////////////////////////////////////////////////////////// // BioGenSource: @@ -160,9 +31,7 @@ void BioGenSource::getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChu QMutexLocker lock(&m_Mtx); m_BiomeGen->GenBiomes(a_ChunkX, a_ChunkZ, biomes); } - Chunk::Image img; - biomesToImage(biomes, img); - a_DestChunk->setImage(img); + a_DestChunk->setBiomes(biomes); } @@ -331,10 +200,7 @@ void AnvilSource::getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChun { biomeMap[i] = (EMCSBiome)GetBEInt(beBiomes + 4 * i); } - // Render the biomes: - Chunk::Image img; - biomesToImage(biomeMap, img); - a_DestChunk->setImage(img); + a_DestChunk->setBiomes(biomeMap); return; } @@ -350,10 +216,7 @@ void AnvilSource::getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChun { biomeMap[i] = EMCSBiome(vanillaBiomes[i]); } - // Render the biomes: - Chunk::Image img; - biomesToImage(biomeMap, img); - a_DestChunk->setImage(img); + a_DestChunk->setBiomes(biomeMap); } -- cgit v1.2.3 From e0cfbc4d8526a1a1d3afa8fc0774358f4f18b7e2 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 19 Oct 2014 14:01:59 +0200 Subject: Generator: Rewritten to use SharedPtrs. --- Tools/QtBiomeVisualiser/ChunkSource.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Tools/QtBiomeVisualiser/ChunkSource.cpp') diff --git a/Tools/QtBiomeVisualiser/ChunkSource.cpp b/Tools/QtBiomeVisualiser/ChunkSource.cpp index e5cd7a75a..3e5216458 100644 --- a/Tools/QtBiomeVisualiser/ChunkSource.cpp +++ b/Tools/QtBiomeVisualiser/ChunkSource.cpp @@ -43,7 +43,7 @@ void BioGenSource::reload() int seed = m_IniFile->GetValueSetI("Seed", "Seed", 0); bool unused = false; QMutexLocker lock(&m_Mtx); - m_BiomeGen.reset(cBiomeGen::CreateBiomeGen(*m_IniFile, seed, unused)); + m_BiomeGen = cBiomeGen::CreateBiomeGen(*m_IniFile, seed, unused); } -- cgit v1.2.3 From 298be25413b9d2f48b1071385a52a55d37d86857 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Thu, 23 Oct 2014 15:29:02 +0200 Subject: QtBiomeVisualiser: Moved the IniFile lib. --- Tools/QtBiomeVisualiser/ChunkSource.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Tools/QtBiomeVisualiser/ChunkSource.cpp') diff --git a/Tools/QtBiomeVisualiser/ChunkSource.cpp b/Tools/QtBiomeVisualiser/ChunkSource.cpp index 3e5216458..c5cde1c3b 100644 --- a/Tools/QtBiomeVisualiser/ChunkSource.cpp +++ b/Tools/QtBiomeVisualiser/ChunkSource.cpp @@ -4,7 +4,7 @@ #include "src/Generating/BioGen.h" #include "src/StringCompression.h" #include "src/WorldStorage/FastNBT.h" -#include "inifile/iniFile.h" +#include "src/IniFile.h" -- cgit v1.2.3 From c53b7e5d38c24bce7ba55abf3060ffd012783086 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Mon, 27 Oct 2014 23:58:09 +0100 Subject: QtBiomeVisualiser: Switched caching to entire regions. This speeds up the rendering preparation for small zooms. --- Tools/QtBiomeVisualiser/ChunkSource.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'Tools/QtBiomeVisualiser/ChunkSource.cpp') diff --git a/Tools/QtBiomeVisualiser/ChunkSource.cpp b/Tools/QtBiomeVisualiser/ChunkSource.cpp index c5cde1c3b..c6d50b2e0 100644 --- a/Tools/QtBiomeVisualiser/ChunkSource.cpp +++ b/Tools/QtBiomeVisualiser/ChunkSource.cpp @@ -24,14 +24,14 @@ BioGenSource::BioGenSource(cIniFilePtr a_IniFile) : -void BioGenSource::getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChunk) +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); } - a_DestChunk->setBiomes(biomes); + a_DestChunk.setBiomes(biomes); } @@ -160,7 +160,7 @@ AnvilSource::AnvilSource(QString a_WorldRegionFolder) : -void AnvilSource::getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChunk) +void AnvilSource::getChunkBiomes(int a_ChunkX, int a_ChunkZ, Chunk & a_DestChunk) { // Load the compressed data: AString compressedChunkData = getCompressedChunkData(a_ChunkX, a_ChunkZ); @@ -200,7 +200,7 @@ void AnvilSource::getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChun { biomeMap[i] = (EMCSBiome)GetBEInt(beBiomes + 4 * i); } - a_DestChunk->setBiomes(biomeMap); + a_DestChunk.setBiomes(biomeMap); return; } @@ -216,7 +216,7 @@ void AnvilSource::getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChun { biomeMap[i] = EMCSBiome(vanillaBiomes[i]); } - a_DestChunk->setBiomes(biomeMap); + a_DestChunk.setBiomes(biomeMap); } -- cgit v1.2.3 From 53ff5c527c154348608f9ab9559bf67064c8ed2a Mon Sep 17 00:00:00 2001 From: Mattes D Date: Tue, 28 Oct 2014 11:23:54 +0100 Subject: QtBiomeVisualiser: Attempt at fixing Linux compilation. --- Tools/QtBiomeVisualiser/ChunkSource.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Tools/QtBiomeVisualiser/ChunkSource.cpp') diff --git a/Tools/QtBiomeVisualiser/ChunkSource.cpp b/Tools/QtBiomeVisualiser/ChunkSource.cpp index c6d50b2e0..d9660b886 100644 --- a/Tools/QtBiomeVisualiser/ChunkSource.cpp +++ b/Tools/QtBiomeVisualiser/ChunkSource.cpp @@ -260,7 +260,7 @@ AnvilSource::AnvilFilePtr AnvilSource::getAnvilFile(int a_ChunkX, int a_ChunkZ) // Search the cache for the file: QMutexLocker lock(&m_Mtx); - for (auto itr = m_Files.cbegin(), end = m_Files.cend(); itr != end; ++itr) + for (auto itr = m_Files.begin(), end = m_Files.end(); itr != end; ++itr) { if (((*itr)->m_RegionX == RegionX) && ((*itr)->m_RegionZ == RegionZ)) { -- cgit v1.2.3 From 4e0cef0ff6080b67e4740bd33ccf4a491a82fb52 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Wed, 29 Oct 2014 23:04:59 +0100 Subject: QtBiomeVisualiser: Generator uses all machine threads. The previous limit of 1 thread was lifted, now the generator source runs on all CPU threads available. --- Tools/QtBiomeVisualiser/ChunkSource.cpp | 57 +++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 7 deletions(-) (limited to 'Tools/QtBiomeVisualiser/ChunkSource.cpp') 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)); } -- cgit v1.2.3