From 2a020e47f1c9167b933fab2662c827365d2f6b5d Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 14 Sep 2014 20:09:11 +0200 Subject: QtBiomeVisualiser: Removed build-specific variables. These should be set in the project configuration instead, passed directly to qmake. --- Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro | 3 --- 1 file changed, 3 deletions(-) (limited to 'Tools/QtBiomeVisualiser') diff --git a/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro b/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro index 0329d5607..0b42f076d 100644 --- a/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro +++ b/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro @@ -55,8 +55,5 @@ INCLUDEPATH += $$_PRO_FILE_PWD_ \ $$_PRO_FILE_PWD_/../../lib -CONFIG += STATIC - - -- cgit v1.2.3 From 69b46aeb27ecfbf87fec5945993a9a441cb89fc7 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 14 Sep 2014 22:05:10 +0200 Subject: QtBiomeVisualiser: Added mouse and keyboard view control. Mouse dragging or WASD pans view, mouse wheel or QE zooms. --- Tools/QtBiomeVisualiser/BiomeView.cpp | 113 +++++++++++++++++++++++++++++++++- Tools/QtBiomeVisualiser/BiomeView.h | 28 ++++++++- 2 files changed, 137 insertions(+), 4 deletions(-) (limited to 'Tools/QtBiomeVisualiser') diff --git a/Tools/QtBiomeVisualiser/BiomeView.cpp b/Tools/QtBiomeVisualiser/BiomeView.cpp index be01fd104..3d24ed126 100644 --- a/Tools/QtBiomeVisualiser/BiomeView.cpp +++ b/Tools/QtBiomeVisualiser/BiomeView.cpp @@ -33,6 +33,9 @@ BiomeView::BiomeView(QWidget * parent) : // Add a chunk-update callback mechanism: connect(&m_Cache, SIGNAL(chunkAvailable(int, int)), this, SLOT(chunkAvailable(int, int))); + + // Allow keyboard interaction: + setFocusPolicy(Qt::StrongFocus); } @@ -236,9 +239,117 @@ void BiomeView::paintEvent(QPaintEvent * a_Event) -void BiomeView::queueChunkRender(ChunkPtr a_Chunk) +void BiomeView::mousePressEvent(QMouseEvent * a_Event) +{ + m_LastX = a_Event->x(); + m_LastY = a_Event->y(); + m_IsMouseDragging = true; +} + + + + + +void BiomeView::mouseMoveEvent(QMouseEvent * a_Event) +{ + if (m_IsMouseDragging) + { + // The user is dragging the mouse, move the view around: + m_X += (m_LastX - a_Event->x()) / m_Zoom; + m_Z += (m_LastY - a_Event->y()) / m_Zoom; + m_LastX = a_Event->x(); + m_LastY = a_Event->y(); + redraw(); + return; + } + + // TODO: Update the status bar info for the biome currently pointed at +} + + + + + +void BiomeView::mouseReleaseEvent(QMouseEvent *) +{ + m_IsMouseDragging = false; +} + + + + + +void BiomeView::wheelEvent(QWheelEvent * a_Event) +{ + m_Zoom += floor(a_Event->delta() / 90.0); + m_Zoom = Clamp(m_Zoom, 1.0, 20.0); + redraw(); +} + + + + + +void BiomeView::keyPressEvent(QKeyEvent * a_Event) { + switch (a_Event->key()) + { + case Qt::Key_Up: + case Qt::Key_W: + { + m_Z -= 10.0 / m_Zoom; + redraw(); + break; + } + + case Qt::Key_Down: + case Qt::Key_S: + { + m_Z += 10.0 / m_Zoom; + redraw(); + break; + } + + case Qt::Key_Left: + case Qt::Key_A: + { + m_X -= 10.0 / m_Zoom; + redraw(); + break; + } + + case Qt::Key_Right: + case Qt::Key_D: + { + m_X += 10.0 / m_Zoom; + redraw(); + break; + } + + case Qt::Key_PageUp: + case Qt::Key_Q: + { + m_Zoom++; + if (m_Zoom > 20.0) + { + m_Zoom = 20.0; + } + redraw(); + break; + } + case Qt::Key_PageDown: + case Qt::Key_E: + { + m_Zoom--; + if (m_Zoom < 1.0) + { + m_Zoom = 1.0; + } + redraw(); + break; + } + } } diff --git a/Tools/QtBiomeVisualiser/BiomeView.h b/Tools/QtBiomeVisualiser/BiomeView.h index c54c66491..8aae43df0 100644 --- a/Tools/QtBiomeVisualiser/BiomeView.h +++ b/Tools/QtBiomeVisualiser/BiomeView.h @@ -35,10 +35,20 @@ public slots: protected: double m_X, m_Z; - int m_Zoom; + double m_Zoom; + + /** Cache for the loaded chunk data. */ ChunkCache m_Cache; + + /** The entire view's contents in an offscreen image. */ QImage m_Image; + /** Coords of the mouse for the previous position, used while dragging. */ + int m_LastX, m_LastY; + + /** Set to true when the user has a mouse button depressed, and is dragging the view. */ + bool m_IsMouseDragging; + /** Data used for rendering a chunk that hasn't been loaded yet */ uchar m_EmptyChunkImage[16 * 16 * 4]; @@ -55,8 +65,20 @@ protected: /** Paints the entire widget */ virtual void paintEvent(QPaintEvent *) override; - /** Queues the chunk for rendering. */ - void queueChunkRender(ChunkPtr a_Chunk); + /** Called when the user presses any mouse button. */ + virtual void mousePressEvent(QMouseEvent * a_Event); + + /** Called when the user moves the mouse. */ + virtual void mouseMoveEvent(QMouseEvent * a_Event); + + /** Called when the user releases a previously held mouse button. */ + virtual void mouseReleaseEvent(QMouseEvent * a_Event) override; + + /** Called when the user rotates the mouse wheel. */ + virtual void wheelEvent(QWheelEvent * a_Event) override; + + /** Called when the user presses a key. */ + virtual void keyPressEvent(QKeyEvent * a_Event) override; }; -- cgit v1.2.3 From ddf130f849f81670254ea2baf79fd06adcc0f302 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 14 Sep 2014 22:20:16 +0200 Subject: QtBiomeVisualiser: Extended zoom down below 100%. --- Tools/QtBiomeVisualiser/BiomeView.cpp | 87 ++++++++++++++++++++++++++++------- Tools/QtBiomeVisualiser/BiomeView.h | 9 ++++ 2 files changed, 80 insertions(+), 16 deletions(-) (limited to 'Tools/QtBiomeVisualiser') diff --git a/Tools/QtBiomeVisualiser/BiomeView.cpp b/Tools/QtBiomeVisualiser/BiomeView.cpp index 3d24ed126..671942440 100644 --- a/Tools/QtBiomeVisualiser/BiomeView.cpp +++ b/Tools/QtBiomeVisualiser/BiomeView.cpp @@ -8,11 +8,19 @@ +static const int DELTA_STEP = 120; // The normal per-notch wheel delta + + + + + BiomeView::BiomeView(QWidget * parent) : super(parent), m_X(0), m_Z(0), - m_Zoom(1) + m_Zoom(1), + m_IsMouseDragging(false), + m_MouseWheelDelta(0) { // Create the image used for undefined chunks: int offset = 0; @@ -281,9 +289,17 @@ void BiomeView::mouseReleaseEvent(QMouseEvent *) void BiomeView::wheelEvent(QWheelEvent * a_Event) { - m_Zoom += floor(a_Event->delta() / 90.0); - m_Zoom = Clamp(m_Zoom, 1.0, 20.0); - redraw(); + m_MouseWheelDelta += a_Event->delta(); + while (m_MouseWheelDelta >= DELTA_STEP) + { + increaseZoom(); + m_MouseWheelDelta -= DELTA_STEP; + } + while (m_MouseWheelDelta <= -DELTA_STEP) + { + decreaseZoom(); + m_MouseWheelDelta += DELTA_STEP; + } } @@ -329,24 +345,14 @@ void BiomeView::keyPressEvent(QKeyEvent * a_Event) case Qt::Key_PageUp: case Qt::Key_Q: { - m_Zoom++; - if (m_Zoom > 20.0) - { - m_Zoom = 20.0; - } - redraw(); + increaseZoom(); break; } case Qt::Key_PageDown: case Qt::Key_E: { - m_Zoom--; - if (m_Zoom < 1.0) - { - m_Zoom = 1.0; - } - redraw(); + decreaseZoom(); break; } } @@ -355,3 +361,52 @@ void BiomeView::keyPressEvent(QKeyEvent * a_Event) + +void BiomeView::decreaseZoom() +{ + if (m_Zoom > 1.001) + { + m_Zoom--; + if (m_Zoom < 1.0) + { + // Just crossed the 100%, fixate the 100% threshold: + m_Zoom = 1.0; + } + } + else if (m_Zoom > 0.01) + { + m_Zoom = m_Zoom / 2; + } + redraw(); +} + + + + + +void BiomeView::increaseZoom() +{ + if (m_Zoom > 0.99) + { + if (m_Zoom > 20.0) + { + // Zoom too large + return; + } + m_Zoom++; + } + else + { + m_Zoom = m_Zoom * 2; + if (m_Zoom > 1.0) + { + // Just crossed the 100%, fixate the 100% threshold: + m_Zoom = 1.0; + } + } + redraw(); +} + + + + diff --git a/Tools/QtBiomeVisualiser/BiomeView.h b/Tools/QtBiomeVisualiser/BiomeView.h index 8aae43df0..61bda45c2 100644 --- a/Tools/QtBiomeVisualiser/BiomeView.h +++ b/Tools/QtBiomeVisualiser/BiomeView.h @@ -49,6 +49,9 @@ protected: /** Set to true when the user has a mouse button depressed, and is dragging the view. */ bool m_IsMouseDragging; + /** Accumulator for the mouse wheel's delta. When the accumulator hits a threshold, the view zooms. */ + int m_MouseWheelDelta; + /** Data used for rendering a chunk that hasn't been loaded yet */ uchar m_EmptyChunkImage[16 * 16 * 4]; @@ -79,6 +82,12 @@ protected: /** Called when the user presses a key. */ virtual void keyPressEvent(QKeyEvent * a_Event) override; + + /** Decreases the zoom level and queues a redraw. */ + void decreaseZoom(); + + /** Increases the zoom level and queues a redraw. */ + void increaseZoom(); }; -- 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.cpp | 74 ++++++++++++++++++++++++++++++--- Tools/QtBiomeVisualiser/ChunkSource.h | 37 +++++++++++++++-- Tools/QtBiomeVisualiser/MainWindow.cpp | 14 +------ 3 files changed, 102 insertions(+), 23 deletions(-) (limited to 'Tools/QtBiomeVisualiser') diff --git a/Tools/QtBiomeVisualiser/ChunkSource.cpp b/Tools/QtBiomeVisualiser/ChunkSource.cpp index 44dcf1fa7..5658198f4 100644 --- a/Tools/QtBiomeVisualiser/ChunkSource.cpp +++ b/Tools/QtBiomeVisualiser/ChunkSource.cpp @@ -1,6 +1,8 @@ #include "Globals.h" #include "ChunkSource.h" +#include #include "Generating/BioGen.h" +#include "inifile/iniFile.h" @@ -138,9 +140,12 @@ static void biomesToImage(cChunkDef::BiomeMap & a_Biomes, Chunk::Image & a_Image //////////////////////////////////////////////////////////////////////////////// // BioGenSource: -BioGenSource::BioGenSource(cBiomeGen * a_BiomeGen) : - m_BiomeGen(a_BiomeGen) +BioGenSource::BioGenSource(QString a_WorldIniPath) : + m_WorldIniPath(a_WorldIniPath), + m_WorldIni(new cIniFile), + m_Mtx(QMutex::Recursive) { + reload(); } @@ -149,11 +154,14 @@ BioGenSource::BioGenSource(cBiomeGen * a_BiomeGen) : void BioGenSource::getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChunk) { - // TODO: To make use of multicore machines, we need multiple copies of the biomegen - // Right now we have only one, so we can let only one thread use it (hence the mutex) - QMutexLocker lock(&m_Mtx); + cBiomeGenPtr biomeGen; + { + QMutexLocker lock(&m_Mtx); + biomeGen = getBiomeGen(); + } cChunkDef::BiomeMap biomes; - m_BiomeGen->GenBiomes(a_ChunkX, a_ChunkZ, biomes); + biomeGen->GenBiomes(a_ChunkX, a_ChunkZ, biomes); + releaseBiomeGen(biomeGen); Chunk::Image img; biomesToImage(biomes, img); a_DestChunk->setImage(img); @@ -162,3 +170,57 @@ void BioGenSource::getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChu + +void BioGenSource::reload() +{ + { + QMutexLocker lock(&m_Mtx); + if (!m_WorldIni->ReadFile(m_WorldIniPath.toStdString())) + { + return; + } + m_AvailableGens.clear(); + } +} + + + + +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; + return cBiomeGenPtr(cBiomeGen::CreateBiomeGen(*m_WorldIni, seed, unused)); +} + + + + + +void BioGenSource::releaseBiomeGen(cBiomeGenPtr a_BiomeGen) +{ + QMutexLocker lock(&m_Mtx); + m_AvailableGens.push_back(a_BiomeGen); + + // 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); + } +} + + + + 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 {} }; diff --git a/Tools/QtBiomeVisualiser/MainWindow.cpp b/Tools/QtBiomeVisualiser/MainWindow.cpp index 8b98c0b0e..21fb1a0c0 100644 --- a/Tools/QtBiomeVisualiser/MainWindow.cpp +++ b/Tools/QtBiomeVisualiser/MainWindow.cpp @@ -39,19 +39,7 @@ MainWindow::~MainWindow() void MainWindow::generate() { QString worldIni = QFileDialog::getOpenFileName(this, tr("Open world.ini"), QString(), tr("world.ini (world.ini)")); - cIniFile ini; - if (!ini.ReadFile(worldIni.toStdString())) - { - return; - } - int seed = ini.GetValueSetI("Seed", "Seed", 0); - bool unused = false; - cBiomeGen * biomeGen = cBiomeGen::CreateBiomeGen(ini, seed, unused); - if (biomeGen == nullptr) - { - return; - } - m_BiomeView->setChunkSource(std::shared_ptr(new BioGenSource(biomeGen))); + m_BiomeView->setChunkSource(std::shared_ptr(new BioGenSource(worldIni))); m_BiomeView->redraw(); } -- 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.cpp | 55 +++++---------------------------- Tools/QtBiomeVisualiser/ChunkSource.h | 20 ++---------- 2 files changed, 10 insertions(+), 65 deletions(-) (limited to 'Tools/QtBiomeVisualiser') diff --git a/Tools/QtBiomeVisualiser/ChunkSource.cpp b/Tools/QtBiomeVisualiser/ChunkSource.cpp index 5658198f4..7da36c39b 100644 --- a/Tools/QtBiomeVisualiser/ChunkSource.cpp +++ b/Tools/QtBiomeVisualiser/ChunkSource.cpp @@ -142,7 +142,6 @@ static void biomesToImage(cChunkDef::BiomeMap & a_Biomes, Chunk::Image & a_Image BioGenSource::BioGenSource(QString a_WorldIniPath) : m_WorldIniPath(a_WorldIniPath), - m_WorldIni(new cIniFile), m_Mtx(QMutex::Recursive) { reload(); @@ -154,14 +153,11 @@ BioGenSource::BioGenSource(QString a_WorldIniPath) : void BioGenSource::getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChunk) { - cBiomeGenPtr biomeGen; + cChunkDef::BiomeMap biomes; { 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; biomesToImage(biomes, img); a_DestChunk->setImage(img); @@ -173,52 +169,15 @@ void BioGenSource::getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChu void BioGenSource::reload() { + cIniFile ini; + if (!ini.ReadFile(m_WorldIniPath.toStdString())) { - QMutexLocker lock(&m_Mtx); - if (!m_WorldIni->ReadFile(m_WorldIniPath.toStdString())) - { - return; - } - m_AvailableGens.clear(); - } -} - - - - -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; + return; } - - // No generator in cache available, create a new one: - int seed = m_WorldIni->GetValueSetI("Seed", "Seed", 0); + int seed = ini.GetValueSetI("Seed", "Seed", 0); bool unused = false; - return cBiomeGenPtr(cBiomeGen::CreateBiomeGen(*m_WorldIni, seed, unused)); -} - - - - - -void BioGenSource::releaseBiomeGen(cBiomeGenPtr a_BiomeGen) -{ QMutexLocker lock(&m_Mtx); - m_AvailableGens.push_back(a_BiomeGen); - - // 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); - } + m_BiomeGen.reset(cBiomeGen::CreateBiomeGen(ini, seed, unused)); } 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 From 21b70f17c264de4f7c216cfca580e8254df5cbee Mon Sep 17 00:00:00 2001 From: Mattes D Date: Mon, 15 Sep 2014 17:29:34 +0200 Subject: QtBiomeVisualiser: Added reloading. --- Tools/QtBiomeVisualiser/BiomeView.cpp | 15 +++++++++++++++ Tools/QtBiomeVisualiser/BiomeView.h | 3 +++ Tools/QtBiomeVisualiser/ChunkCache.cpp | 16 ++++++++++++++++ Tools/QtBiomeVisualiser/ChunkCache.h | 5 ++++- Tools/QtBiomeVisualiser/MainWindow.cpp | 13 ++++++++++--- Tools/QtBiomeVisualiser/MainWindow.h | 1 + 6 files changed, 49 insertions(+), 4 deletions(-) (limited to 'Tools/QtBiomeVisualiser') diff --git a/Tools/QtBiomeVisualiser/BiomeView.cpp b/Tools/QtBiomeVisualiser/BiomeView.cpp index 671942440..bbaccb369 100644 --- a/Tools/QtBiomeVisualiser/BiomeView.cpp +++ b/Tools/QtBiomeVisualiser/BiomeView.cpp @@ -131,6 +131,21 @@ void BiomeView::chunkAvailable(int a_ChunkX, int a_ChunkZ) +void BiomeView::reload() +{ + if (!hasData()) + { + return; + } + m_Cache.reload(); + + redraw(); +} + + + + + void BiomeView::drawChunk(int a_ChunkX, int a_ChunkZ) { if (!hasData()) diff --git a/Tools/QtBiomeVisualiser/BiomeView.h b/Tools/QtBiomeVisualiser/BiomeView.h index 61bda45c2..86af8bcaf 100644 --- a/Tools/QtBiomeVisualiser/BiomeView.h +++ b/Tools/QtBiomeVisualiser/BiomeView.h @@ -33,6 +33,9 @@ public slots: /** A specified chunk has become available, redraw it. */ void chunkAvailable(int a_ChunkX, int a_ChunkZ); + /** Reloads the current chunk source and redraws the entire workspace. */ + void reload(); + protected: double m_X, m_Z; double m_Zoom; diff --git a/Tools/QtBiomeVisualiser/ChunkCache.cpp b/Tools/QtBiomeVisualiser/ChunkCache.cpp index b2230def0..05c267d30 100644 --- a/Tools/QtBiomeVisualiser/ChunkCache.cpp +++ b/Tools/QtBiomeVisualiser/ChunkCache.cpp @@ -76,6 +76,22 @@ void ChunkCache::setChunkSource(std::shared_ptr a_ChunkSource) +void ChunkCache::reload() +{ + assert(m_ChunkSource.get() != nullptr); + + // Reload the chunk source: + m_ChunkSource->reload(); + + // Clear the cache: + QMutexLocker lock(&m_Mtx); + m_Cache.clear(); +} + + + + + void ChunkCache::gotChunk(int a_ChunkX, int a_ChunkZ) { emit chunkAvailable(a_ChunkX, a_ChunkZ); diff --git a/Tools/QtBiomeVisualiser/ChunkCache.h b/Tools/QtBiomeVisualiser/ChunkCache.h index 0efa7fc39..0134bc7af 100644 --- a/Tools/QtBiomeVisualiser/ChunkCache.h +++ b/Tools/QtBiomeVisualiser/ChunkCache.h @@ -36,7 +36,10 @@ public: void setChunkSource(std::shared_ptr a_ChunkSource); /** Returns true iff the chunk source has been initialized. */ - bool hasData(void) const { return (m_ChunkSource.get() != nullptr); } + bool hasData() const { return (m_ChunkSource.get() != nullptr); } + + /** Reloads the current chunk source. */ + void reload(); signals: void chunkAvailable(int a_ChunkX, int a_ChunkZ); diff --git a/Tools/QtBiomeVisualiser/MainWindow.cpp b/Tools/QtBiomeVisualiser/MainWindow.cpp index 21fb1a0c0..65d0ccf5e 100644 --- a/Tools/QtBiomeVisualiser/MainWindow.cpp +++ b/Tools/QtBiomeVisualiser/MainWindow.cpp @@ -16,11 +16,11 @@ MainWindow::MainWindow(QWidget * parent) : QMainWindow(parent) { - createActions(); - createMenus(); - m_BiomeView = new BiomeView(this); setCentralWidget(m_BiomeView); + + createActions(); + createMenus(); } @@ -68,6 +68,11 @@ void MainWindow::createActions() m_actOpen->setStatusTip(tr("Open an existing world and display its biomes")); connect(m_actOpen, SIGNAL(triggered()), this, SLOT(open())); + m_actReload = new QAction(tr("&Reload"), this); + m_actReload->setShortcut(tr("F5")); + m_actReload->setStatusTip(tr("Open an existing world and display its biomes")); + connect(m_actReload, SIGNAL(triggered()), m_BiomeView, SLOT(reload())); + m_actExit = new QAction(tr("E&xit"), this); m_actExit->setShortcut(tr("Alt+X")); m_actExit->setStatusTip(tr("Exit %1").arg(QApplication::instance()->applicationName())); @@ -84,6 +89,8 @@ void MainWindow::createMenus() mFile->addAction(m_actGen); mFile->addAction(m_actOpen); mFile->addSeparator(); + mFile->addAction(m_actReload); + mFile->addSeparator(); mFile->addAction(m_actExit); } diff --git a/Tools/QtBiomeVisualiser/MainWindow.h b/Tools/QtBiomeVisualiser/MainWindow.h index f6028aff1..b37bf4120 100644 --- a/Tools/QtBiomeVisualiser/MainWindow.h +++ b/Tools/QtBiomeVisualiser/MainWindow.h @@ -29,6 +29,7 @@ protected: // Actions: QAction * m_actGen; QAction * m_actOpen; + QAction * m_actReload; QAction * m_actExit; -- cgit v1.2.3 From 18743540bc5122a42d24148a273ce04717057ed3 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 15 Sep 2014 21:45:35 +0200 Subject: QtBiomeVisualiser: Fixed colors and read failures. --- Tools/QtBiomeVisualiser/ChunkSource.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'Tools/QtBiomeVisualiser') diff --git a/Tools/QtBiomeVisualiser/ChunkSource.cpp b/Tools/QtBiomeVisualiser/ChunkSource.cpp index 7da36c39b..9e0ea5751 100644 --- a/Tools/QtBiomeVisualiser/ChunkSource.cpp +++ b/Tools/QtBiomeVisualiser/ChunkSource.cpp @@ -103,9 +103,9 @@ public: for (size_t i = 0; i < ARRAYCOUNT(biomeColors); i++) { uchar * color = &biomeToColor[4 * biomeColors[i].m_Biome]; - color[0] = biomeColors[i].m_Color[0]; + color[0] = biomeColors[i].m_Color[2]; color[1] = biomeColors[i].m_Color[1]; - color[2] = biomeColors[i].m_Color[2]; + color[2] = biomeColors[i].m_Color[0]; color[3] = 0xff; } } @@ -170,14 +170,13 @@ void BioGenSource::getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChu void BioGenSource::reload() { cIniFile ini; - if (!ini.ReadFile(m_WorldIniPath.toStdString())) - { - return; - } + ini.ReadFile(m_WorldIniPath.toStdString()); int seed = ini.GetValueSetI("Seed", "Seed", 0); bool unused = false; QMutexLocker lock(&m_Mtx); m_BiomeGen.reset(cBiomeGen::CreateBiomeGen(ini, seed, unused)); + lock.unlock(); + ini.WriteFile(m_WorldIniPath.toStdString()); } -- cgit v1.2.3 From 98f4588ed3af39af0554687b84944f12c49e87db Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 18 Sep 2014 10:24:52 +0200 Subject: QtBiomeVisualiser: Fixed linux compilation. --- Tools/QtBiomeVisualiser/BiomeView.h | 1 + Tools/QtBiomeVisualiser/ChunkCache.h | 1 + Tools/QtBiomeVisualiser/ChunkLoader.h | 2 ++ Tools/QtBiomeVisualiser/ChunkSource.h | 1 + Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro | 1 + 5 files changed, 6 insertions(+) (limited to 'Tools/QtBiomeVisualiser') diff --git a/Tools/QtBiomeVisualiser/BiomeView.h b/Tools/QtBiomeVisualiser/BiomeView.h index 86af8bcaf..f0521571d 100644 --- a/Tools/QtBiomeVisualiser/BiomeView.h +++ b/Tools/QtBiomeVisualiser/BiomeView.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include "ChunkCache.h" #include "ChunkSource.h" diff --git a/Tools/QtBiomeVisualiser/ChunkCache.h b/Tools/QtBiomeVisualiser/ChunkCache.h index 0134bc7af..8d198f02f 100644 --- a/Tools/QtBiomeVisualiser/ChunkCache.h +++ b/Tools/QtBiomeVisualiser/ChunkCache.h @@ -3,6 +3,7 @@ #include #include #include +#include diff --git a/Tools/QtBiomeVisualiser/ChunkLoader.h b/Tools/QtBiomeVisualiser/ChunkLoader.h index 3565434b9..4d026a45e 100644 --- a/Tools/QtBiomeVisualiser/ChunkLoader.h +++ b/Tools/QtBiomeVisualiser/ChunkLoader.h @@ -1,6 +1,8 @@ #pragma once + #include #include +#include diff --git a/Tools/QtBiomeVisualiser/ChunkSource.h b/Tools/QtBiomeVisualiser/ChunkSource.h index a485e473a..868e4a144 100644 --- a/Tools/QtBiomeVisualiser/ChunkSource.h +++ b/Tools/QtBiomeVisualiser/ChunkSource.h @@ -1,5 +1,6 @@ #pragma once #include +#include #include "Chunk.h" diff --git a/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro b/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro index 0b42f076d..e6b65e628 100644 --- a/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro +++ b/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro @@ -55,5 +55,6 @@ INCLUDEPATH += $$_PRO_FILE_PWD_ \ $$_PRO_FILE_PWD_/../../lib +CONFIG += C++11 -- cgit v1.2.3 From 09c67bddf75a2ed244b274462305136da08b20f3 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 18 Sep 2014 10:26:28 +0200 Subject: QtBiomeVisualiser: More gcc fixes. --- Tools/QtBiomeVisualiser/ChunkSource.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Tools/QtBiomeVisualiser') diff --git a/Tools/QtBiomeVisualiser/ChunkSource.cpp b/Tools/QtBiomeVisualiser/ChunkSource.cpp index 9e0ea5751..2235816bc 100644 --- a/Tools/QtBiomeVisualiser/ChunkSource.cpp +++ b/Tools/QtBiomeVisualiser/ChunkSource.cpp @@ -120,8 +120,8 @@ 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]; + 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++) -- cgit v1.2.3