summaryrefslogtreecommitdiffstats
path: root/Tools/QtBiomeVisualiser/ChunkCache.h
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2014-09-14 14:16:17 +0200
committerHowaner <franzi.moos@googlemail.com>2014-09-14 14:16:17 +0200
commit92e7e5c615efb591210ffd978afa012027f2c84f (patch)
tree1271b2281ab938f59f3f2d933a6c873fd3f633ba /Tools/QtBiomeVisualiser/ChunkCache.h
parent1.8: Updated scoreboard packets. (diff)
parentAdded new Qt-based biome visualiser. (diff)
downloadcuberite-92e7e5c615efb591210ffd978afa012027f2c84f.tar
cuberite-92e7e5c615efb591210ffd978afa012027f2c84f.tar.gz
cuberite-92e7e5c615efb591210ffd978afa012027f2c84f.tar.bz2
cuberite-92e7e5c615efb591210ffd978afa012027f2c84f.tar.lz
cuberite-92e7e5c615efb591210ffd978afa012027f2c84f.tar.xz
cuberite-92e7e5c615efb591210ffd978afa012027f2c84f.tar.zst
cuberite-92e7e5c615efb591210ffd978afa012027f2c84f.zip
Diffstat (limited to 'Tools/QtBiomeVisualiser/ChunkCache.h')
-rw-r--r--Tools/QtBiomeVisualiser/ChunkCache.h68
1 files changed, 68 insertions, 0 deletions
diff --git a/Tools/QtBiomeVisualiser/ChunkCache.h b/Tools/QtBiomeVisualiser/ChunkCache.h
new file mode 100644
index 000000000..0efa7fc39
--- /dev/null
+++ b/Tools/QtBiomeVisualiser/ChunkCache.h
@@ -0,0 +1,68 @@
+#pragma once
+
+#include <QObject>
+#include <QCache>
+#include <QMutex>
+
+
+
+
+
+class Chunk;
+typedef std::shared_ptr<Chunk> ChunkPtr;
+
+class ChunkSource;
+
+
+
+
+
+/** Caches chunk data for reuse */
+class ChunkCache :
+ public QObject
+{
+ typedef QObject super;
+ Q_OBJECT
+
+public:
+ explicit ChunkCache(QObject * parent = NULL);
+
+ /** Retrieves the specified chunk from the cache.
+ Only returns valid chunks; if the chunk is invalid, queues it for rendering and returns an empty ptr. */
+ ChunkPtr fetch(int a_ChunkX, int a_ChunkZ);
+
+ /** 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(void) const { return (m_ChunkSource.get() != nullptr); }
+
+signals:
+ void chunkAvailable(int a_ChunkX, int a_ChunkZ);
+
+protected slots:
+ void gotChunk(int a_ChunkX, int a_ChunkZ);
+
+protected:
+ /** The cache of the chunks */
+ QCache<quint32, ChunkPtr> m_Cache;
+
+ /** Locks te 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 getChunkHash(int a_ChunkX, int a_ChunkZ);
+
+ /** Queues the specified chunk for rendering by m_ChunkSource. */
+ void queueChunkRender(int a_ChunkX, int a_ChunkZ, ChunkPtr & a_Chunk);
+};
+
+
+
+
+