Files
cuberite-2a/Tools/QtBiomeVisualiser/RegionCache.h
T

74 lines
1.5 KiB
C++
Raw Normal View History

2014-09-14 01:32:00 +02:00
#pragma once
#include <QObject>
#include <QCache>
#include <QMutex>
2014-09-18 10:24:52 +02:00
#include <memory>
2014-09-14 01:32:00 +02:00
// fwd:
class Region;
typedef std::shared_ptr<Region> RegionPtr;
2014-09-14 01:32:00 +02:00
class ChunkSource;
/** Caches regions' chunk data for reuse */
class RegionCache :
2014-09-14 01:32:00 +02:00
public QObject
{
typedef QObject super;
Q_OBJECT
public:
explicit RegionCache(QObject * parent = NULL);
2014-09-14 01:32:00 +02:00
/** 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);
2014-09-14 01:32:00 +02:00
/** 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. */
2014-09-15 17:29:34 +02:00
bool hasData() const { return (m_ChunkSource.get() != nullptr); }
/** Reloads the current chunk source. */
void reload();
2014-09-14 01:32:00 +02:00
signals:
void regionAvailable(int a_RegionX, int a_RegionZ);
2014-09-14 01:32:00 +02:00
protected slots:
void gotRegion(int a_RegionX, int a_RegionZ);
2014-09-14 01:32:00 +02:00
protected:
/** The cache of the chunks */
QCache<quint32, RegionPtr> m_Cache;
2014-09-14 01:32:00 +02:00
/** Locks the cache against multithreaded access */
2014-09-14 01:32:00 +02:00
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);
2014-09-14 01:32:00 +02:00
/** Queues the specified region for rendering by m_RegionSource. */
void queueRegionRender(int a_RegionX, int a_RegionZ, RegionPtr & a_Region);
2014-09-14 01:32:00 +02:00
};