1
0
Fork 0

QtBiomeVisualiser: generator source is read from generator setup ini.

This commit is contained in:
madmaxoft 2014-09-22 18:33:18 +02:00
parent 10c5d50566
commit 583532e1b9
3 changed files with 13 additions and 16 deletions

View File

@ -142,8 +142,8 @@ static void biomesToImage(cChunkDef::BiomeMap & a_Biomes, Chunk::Image & a_Image
////////////////////////////////////////////////////////////////////////////////
// BioGenSource:
BioGenSource::BioGenSource(QString a_WorldIniPath) :
m_WorldIniPath(a_WorldIniPath),
BioGenSource::BioGenSource(cIniFilePtr a_IniFile) :
m_IniFile(a_IniFile),
m_Mtx(QMutex::Recursive)
{
reload();
@ -171,14 +171,10 @@ void BioGenSource::getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChu
void BioGenSource::reload()
{
cIniFile ini;
ini.ReadFile(m_WorldIniPath.toStdString());
int seed = ini.GetValueSetI("Seed", "Seed", 0);
int seed = m_IniFile->GetValueSetI("Seed", "Seed", 0);
bool unused = false;
QMutexLocker lock(&m_Mtx);
m_BiomeGen.reset(cBiomeGen::CreateBiomeGen(ini, seed, unused));
lock.unlock();
ini.WriteFile(m_WorldIniPath.toStdString());
m_BiomeGen.reset(cBiomeGen::CreateBiomeGen(*m_IniFile, seed, unused));
}

View File

@ -12,6 +12,7 @@
class cBiomeGen;
typedef std::shared_ptr<cBiomeGen> cBiomeGenPtr;
class cIniFile;
typedef std::shared_ptr<cIniFile> cIniFilePtr;
@ -41,15 +42,15 @@ class BioGenSource :
{
public:
/** Constructs a new BioGenSource based on the biome generator that is defined in the specified world.ini file. */
BioGenSource(QString a_WorldIniPath);
BioGenSource(cIniFilePtr a_IniFile);
// ChunkSource overrides:
virtual void getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChunk) override;
virtual void reload(void) override;
protected:
/** Path to the world.ini file from which the m_WorldIni is regenerated on reload requests. */
QString m_WorldIniPath;
/** The world.ini contents from which the generator is created and re-created on reload(). */
cIniFilePtr m_IniFile;
/** The generator used for generating biomes. */
std::unique_ptr<cBiomeGen> m_BiomeGen;

View File

@ -53,12 +53,12 @@ MainWindow::~MainWindow()
void MainWindow::newGenerator()
{
// TODO
// (Re-)open the generator setup dialog:
// (Re-)open the generator setup dialog with empty settings:
openGeneratorSetup("");
// TODO
// Set the chunk source:
m_BiomeView->setChunkSource(std::shared_ptr<BioGenSource>(new BioGenSource(m_GeneratorSetup->getIniFile())));
m_BiomeView->redraw();
}
@ -78,7 +78,7 @@ void MainWindow::openGenerator()
openGeneratorSetup(worldIni.toStdString());
// Set the chunk source:
m_BiomeView->setChunkSource(std::shared_ptr<BioGenSource>(new BioGenSource(worldIni)));
m_BiomeView->setChunkSource(std::shared_ptr<BioGenSource>(new BioGenSource(m_GeneratorSetup->getIniFile())));
m_BiomeView->redraw();
}