2014-09-13 19:32:00 -04:00
|
|
|
#pragma once
|
2014-09-20 12:41:21 -04:00
|
|
|
#include "Globals.h"
|
2014-09-15 10:50:40 -04:00
|
|
|
#include <QString>
|
2014-09-18 04:24:52 -04:00
|
|
|
#include <QMutex>
|
2014-09-24 05:21:59 -04:00
|
|
|
#include "QtChunk.h"
|
2014-09-13 19:32:00 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// fwd:
|
|
|
|
class cBiomeGen;
|
2014-09-15 10:50:40 -04:00
|
|
|
typedef std::shared_ptr<cBiomeGen> cBiomeGenPtr;
|
|
|
|
class cIniFile;
|
2014-09-22 12:33:18 -04:00
|
|
|
typedef std::shared_ptr<cIniFile> cIniFilePtr;
|
2014-09-13 19:32:00 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Abstract interface for getting biome data for chunks. */
|
|
|
|
class ChunkSource
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~ChunkSource() {}
|
|
|
|
|
|
|
|
/** 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;
|
2014-09-15 10:50:40 -04:00
|
|
|
|
|
|
|
/** Forces a fresh reload of the source. Useful mainly for the generator, whose underlying definition file may have been changed. */
|
|
|
|
virtual void reload() = 0;
|
2014-09-13 19:32:00 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BioGenSource :
|
|
|
|
public ChunkSource
|
|
|
|
{
|
|
|
|
public:
|
2014-09-15 10:50:40 -04:00
|
|
|
/** Constructs a new BioGenSource based on the biome generator that is defined in the specified world.ini file. */
|
2014-09-22 12:33:18 -04:00
|
|
|
BioGenSource(cIniFilePtr a_IniFile);
|
2014-09-13 19:32:00 -04:00
|
|
|
|
2014-09-15 10:50:40 -04:00
|
|
|
// ChunkSource overrides:
|
2014-09-13 19:32:00 -04:00
|
|
|
virtual void getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChunk) override;
|
2014-09-15 10:50:40 -04:00
|
|
|
virtual void reload(void) override;
|
2014-09-13 19:32:00 -04:00
|
|
|
|
|
|
|
protected:
|
2014-09-22 12:33:18 -04:00
|
|
|
/** The world.ini contents from which the generator is created and re-created on reload(). */
|
|
|
|
cIniFilePtr m_IniFile;
|
2014-09-15 10:50:40 -04:00
|
|
|
|
2014-09-15 11:20:54 -04:00
|
|
|
/** The generator used for generating biomes. */
|
|
|
|
std::unique_ptr<cBiomeGen> m_BiomeGen;
|
2014-09-15 10:50:40 -04:00
|
|
|
|
2014-09-15 11:20:54 -04:00
|
|
|
/** Guards m_BiomeGen against multithreaded access. */
|
2014-09-13 19:32:00 -04:00
|
|
|
QMutex m_Mtx;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AnvilSource :
|
|
|
|
public ChunkSource
|
|
|
|
{
|
|
|
|
public:
|
2014-09-20 12:41:21 -04:00
|
|
|
/** Constructs a new AnvilSource based on the world path. */
|
|
|
|
AnvilSource(QString a_WorldRegionFolder);
|
2014-09-13 19:32:00 -04:00
|
|
|
|
2014-09-15 10:50:40 -04:00
|
|
|
// ChunkSource overrides:
|
2014-09-13 19:32:00 -04:00
|
|
|
virtual void getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChunk) override;
|
2014-09-20 12:41:21 -04:00
|
|
|
virtual void reload() override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
class AnvilFile;
|
|
|
|
typedef std::shared_ptr<AnvilFile> AnvilFilePtr;
|
|
|
|
|
|
|
|
|
|
|
|
/** Folder where the individual Anvil Region files are located. */
|
|
|
|
QString m_WorldRegionFolder;
|
|
|
|
|
|
|
|
/** List of currently loaded files. Acts as a cache so that a file is not opened and closed over and over again.
|
|
|
|
Protected against multithreaded access by m_Mtx. */
|
|
|
|
std::list<AnvilFilePtr> m_Files;
|
|
|
|
|
|
|
|
/** Guards m_Files agains multithreaded access. */
|
|
|
|
QMutex m_Mtx;
|
|
|
|
|
|
|
|
|
|
|
|
/** Converts chunk coords to region coords. */
|
|
|
|
void chunkToRegion(int a_ChunkX, int a_ChunkZ, int & a_RegionX, int & a_RegionZ);
|
|
|
|
|
|
|
|
/** Returns the compressed data of the specified chunk.
|
|
|
|
Returns an empty string if the chunk is not available. */
|
|
|
|
AString getCompressedChunkData(int a_ChunkX, int a_ChunkZ);
|
|
|
|
|
|
|
|
/** Returns the file object that contains the specified chunk.
|
|
|
|
The file is taken from the cache if available there, otherwise it is created anew. */
|
|
|
|
AnvilFilePtr getAnvilFile(int a_ChunkX, int a_ChunkZ);
|
|
|
|
|
2014-09-13 19:32:00 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|