summaryrefslogtreecommitdiffstats
path: root/Tools/QtBiomeVisualiser/RegionCache.h
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-10-28 22:07:09 +0100
committerMattes D <github@xoft.cz>2014-10-28 22:07:09 +0100
commit2f0abb73c94eb896c956ceb0375d2e72065d95d5 (patch)
tree2cf8a72a9aaf59fa218f5978045412a47662d52b /Tools/QtBiomeVisualiser/RegionCache.h
parentForgotten m_SendChunksMediumPriority.empty() check. (diff)
parentQtBiomeVisualiser: Reduced memory usage. (diff)
downloadcuberite-2f0abb73c94eb896c956ceb0375d2e72065d95d5.tar
cuberite-2f0abb73c94eb896c956ceb0375d2e72065d95d5.tar.gz
cuberite-2f0abb73c94eb896c956ceb0375d2e72065d95d5.tar.bz2
cuberite-2f0abb73c94eb896c956ceb0375d2e72065d95d5.tar.lz
cuberite-2f0abb73c94eb896c956ceb0375d2e72065d95d5.tar.xz
cuberite-2f0abb73c94eb896c956ceb0375d2e72065d95d5.tar.zst
cuberite-2f0abb73c94eb896c956ceb0375d2e72065d95d5.zip
Diffstat (limited to 'Tools/QtBiomeVisualiser/RegionCache.h')
-rw-r--r--Tools/QtBiomeVisualiser/RegionCache.h73
1 files changed, 73 insertions, 0 deletions
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 <QObject>
+#include <QCache>
+#include <QMutex>
+#include <memory>
+
+
+
+
+
+// fwd:
+class Region;
+typedef std::shared_ptr<Region> 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<ChunkSource> 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<quint32, RegionPtr> m_Cache;
+
+ /** Locks the cache against multithreaded access */
+ QMutex m_Mtx;
+
+ /** The source used to get the biome data. */
+ std::shared_ptr<ChunkSource> 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);
+};
+
+
+
+
+