From e3a2dc5a1391d8aaaa3fdb83e946838540a07e75 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 14 Sep 2014 01:32:00 +0200 Subject: Added new Qt-based biome visualiser. Compile with Qt 5.1+ --- Tools/QtBiomeVisualiser/ChunkSource.h | 60 +++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 Tools/QtBiomeVisualiser/ChunkSource.h (limited to 'Tools/QtBiomeVisualiser/ChunkSource.h') diff --git a/Tools/QtBiomeVisualiser/ChunkSource.h b/Tools/QtBiomeVisualiser/ChunkSource.h new file mode 100644 index 000000000..d6eb2e3cb --- /dev/null +++ b/Tools/QtBiomeVisualiser/ChunkSource.h @@ -0,0 +1,60 @@ +#pragma once +#include "Chunk.h" + + + + + +// fwd: +class cBiomeGen; + + + + + +/** Abstract interface for getting biome data for chunks. */ +class ChunkSource +{ +public: + virtual ~ChunkSource() {} + + /** Fills the a_DestChunk with the biomes for the specified coords. + It is expected to be thread-safe and re-entrant. Usually QThread::idealThreadCount() threads are used. */ + virtual void getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChunk) = 0; +}; + + + + + + +class BioGenSource : + public ChunkSource +{ +public: + /** Constructs a new BioGenSource based on the biome generator given. + Takes ownership of a_BiomeGen */ + BioGenSource(cBiomeGen * a_BiomeGen); + + virtual void getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChunk) override; + +protected: + std::shared_ptr m_BiomeGen; + QMutex m_Mtx; +}; + + + + +class AnvilSource : + public ChunkSource +{ +public: + // TODO + + virtual void getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChunk) override; +}; + + + + -- cgit v1.2.3 From d772bc032f12bceac2d974ad9165597edabe5b0a Mon Sep 17 00:00:00 2001 From: Mattes D Date: Mon, 15 Sep 2014 16:50:40 +0200 Subject: QtBiomeVisualiser: Added multithreading. For some reason this makes the UI less responsive. --- Tools/QtBiomeVisualiser/ChunkSource.h | 37 +++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'Tools/QtBiomeVisualiser/ChunkSource.h') diff --git a/Tools/QtBiomeVisualiser/ChunkSource.h b/Tools/QtBiomeVisualiser/ChunkSource.h index d6eb2e3cb..7bbdda276 100644 --- a/Tools/QtBiomeVisualiser/ChunkSource.h +++ b/Tools/QtBiomeVisualiser/ChunkSource.h @@ -1,4 +1,5 @@ #pragma once +#include #include "Chunk.h" @@ -7,6 +8,8 @@ // fwd: class cBiomeGen; +typedef std::shared_ptr cBiomeGenPtr; +class cIniFile; @@ -21,6 +24,9 @@ public: /** Fills the a_DestChunk with the biomes for the specified coords. It is expected to be thread-safe and re-entrant. Usually QThread::idealThreadCount() threads are used. */ virtual void getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChunk) = 0; + + /** Forces a fresh reload of the source. Useful mainly for the generator, whose underlying definition file may have been changed. */ + virtual void reload() = 0; }; @@ -32,15 +38,36 @@ class BioGenSource : public ChunkSource { public: - /** Constructs a new BioGenSource based on the biome generator given. - Takes ownership of a_BiomeGen */ - BioGenSource(cBiomeGen * a_BiomeGen); + /** Constructs a new BioGenSource based on the biome generator that is defined in the specified world.ini file. */ + BioGenSource(QString a_WorldIniPath); + // ChunkSource overrides: virtual void getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChunk) override; + virtual void reload(void) override; protected: - std::shared_ptr m_BiomeGen; + /** Path to the world.ini file from which the m_WorldIni is regenerated on reload requests. */ + QString m_WorldIniPath; + + /** Parsed contents of the world.ini file from which the biome generators are initialized. + Locked by m_Mtx to avoid multithreaded access. */ + std::unique_ptr m_WorldIni; + + /** List of cBiomeGen instances that are "free" - aren't doing any generating at this moment. + Locked by m_Mtx to avoid multithreaded access. */ + std::vector m_AvailableGens; + + /** Guards m_AvailableGens and m_WorldIni against multithreaded access. */ 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); }; @@ -52,7 +79,9 @@ class AnvilSource : public: // TODO + // ChunkSource overrides: virtual void getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChunk) override; + virtual void reload() override {} }; -- cgit v1.2.3 From 84947a22ad2c2ccb91733e171566433731eb0f48 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Mon, 15 Sep 2014 17:20:54 +0200 Subject: QtBiomeVisualiser: removed multithreading. It was slowing things down, the granularity is too fine. --- Tools/QtBiomeVisualiser/ChunkSource.h | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) (limited to 'Tools/QtBiomeVisualiser/ChunkSource.h') diff --git a/Tools/QtBiomeVisualiser/ChunkSource.h b/Tools/QtBiomeVisualiser/ChunkSource.h index 7bbdda276..a485e473a 100644 --- a/Tools/QtBiomeVisualiser/ChunkSource.h +++ b/Tools/QtBiomeVisualiser/ChunkSource.h @@ -49,25 +49,11 @@ protected: /** Path to the world.ini file from which the m_WorldIni is regenerated on reload requests. */ QString m_WorldIniPath; - /** Parsed contents of the world.ini file from which the biome generators are initialized. - Locked by m_Mtx to avoid multithreaded access. */ - std::unique_ptr m_WorldIni; + /** The generator used for generating biomes. */ + std::unique_ptr m_BiomeGen; - /** List of cBiomeGen instances that are "free" - aren't doing any generating at this moment. - Locked by m_Mtx to avoid multithreaded access. */ - std::vector m_AvailableGens; - - /** Guards m_AvailableGens and m_WorldIni against multithreaded access. */ + /** Guards m_BiomeGen against multithreaded access. */ 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); }; -- cgit v1.2.3