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/RegionCache.h | 73 +++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Tools/QtBiomeVisualiser/RegionCache.h (limited to 'Tools/QtBiomeVisualiser/RegionCache.h') diff --git a/Tools/QtBiomeVisualiser/RegionCache.h b/Tools/QtBiomeVisualiser/RegionCache.h new file mode 100644 index 000000000..c343e4ba9 --- /dev/null +++ b/Tools/QtBiomeVisualiser/RegionCache.h @@ -0,0 +1,73 @@ +#pragma once + +#include +#include +#include +#include + + + + + +// fwd: +class Region; +typedef std::shared_ptr RegionPtr; + +class ChunkSource; + + + + + +/** Caches regions' chunk data for reuse */ +class RegionCache : + public QObject +{ + typedef QObject super; + Q_OBJECT + +public: + explicit RegionCache(QObject * parent = NULL); + + /** Retrieves the specified region from the cache. + Only returns valid regions; if the region is invalid, queues it for rendering and returns an empty ptr. */ + RegionPtr fetch(int a_RegionX, int a_RegionZ); + + /** Replaces the chunk source used by the biome view to get the chunk biome data. + The cache is then invalidated. */ + void setChunkSource(std::shared_ptr a_ChunkSource); + + /** Returns true iff the chunk source has been initialized. */ + bool hasData() const { return (m_ChunkSource.get() != nullptr); } + + /** Reloads the current chunk source. */ + void reload(); + +signals: + void regionAvailable(int a_RegionX, int a_RegionZ); + +protected slots: + void gotRegion(int a_RegionX, int a_RegionZ); + +protected: + /** The cache of the chunks */ + QCache m_Cache; + + /** Locks the cache against multithreaded access */ + QMutex m_Mtx; + + /** The source used to get the biome data. */ + std::shared_ptr m_ChunkSource; + + + /** Returns the hash used by the chunk in the cache */ + quint32 getRegionHash(int a_RegionX, int a_RegionZ); + + /** Queues the specified region for rendering by m_RegionSource. */ + void queueRegionRender(int a_RegionX, int a_RegionZ, RegionPtr & a_Region); +}; + + + + + -- cgit v1.2.3