From 66ef05c765a7e66ec3d77cd1a1eaff4f03b28688 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 20 Sep 2014 18:41:21 +0200 Subject: QtBiomeVisualiser: Added support for loading Anvil worlds. --- Tools/QtBiomeVisualiser/ChunkSource.cpp | 241 ++++++++++++++++++++++++++ Tools/QtBiomeVisualiser/ChunkSource.h | 34 +++- Tools/QtBiomeVisualiser/MainWindow.cpp | 12 +- Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro | 38 +++- 4 files changed, 320 insertions(+), 5 deletions(-) (limited to 'Tools/QtBiomeVisualiser') diff --git a/Tools/QtBiomeVisualiser/ChunkSource.cpp b/Tools/QtBiomeVisualiser/ChunkSource.cpp index 2235816bc..54da2afe5 100644 --- a/Tools/QtBiomeVisualiser/ChunkSource.cpp +++ b/Tools/QtBiomeVisualiser/ChunkSource.cpp @@ -3,6 +3,8 @@ #include #include "Generating/BioGen.h" #include "inifile/iniFile.h" +#include "StringCompression.h" +#include "WorldStorage/FastNBT.h" @@ -182,3 +184,242 @@ void BioGenSource::reload() + +//////////////////////////////////////////////////////////////////////////////// +// AnvilSource::AnvilFile + +class AnvilSource::AnvilFile +{ +public: + /** Coordinates of the region file. */ + int m_RegionX, m_RegionZ; + + /** True iff the file contains proper data. */ + bool m_IsValid; + + + + /** Creates a new instance with the specified region coords. Reads the file header. */ + AnvilFile(int a_RegionX, int a_RegionZ, const AString & a_WorldPath) : + m_RegionX(a_RegionX), + m_RegionZ(a_RegionZ), + m_IsValid(false) + { + readFile(Printf("%s/r.%d.%d.mca", a_WorldPath.c_str(), a_RegionX, a_RegionZ)); + } + + + + /** Returns the compressed data of the specified chunk. + Returns an empty string when chunk not present. */ + AString getChunkData(int a_ChunkX, int a_ChunkZ) + { + if (!m_IsValid) + { + return ""; + } + + // Translate to local coords: + int RelChunkX = a_ChunkX - m_RegionX * 32; + int RelChunkZ = a_ChunkZ - m_RegionZ * 32; + ASSERT((RelChunkX >= 0) && (RelChunkX < 32)); + ASSERT((RelChunkZ >= 0) && (RelChunkZ < 32)); + + // Get the chunk data location: + UInt32 chunkOffset = m_Header[RelChunkX + 32 * RelChunkZ] >> 8; + UInt32 numChunkSectors = m_Header[RelChunkX + 32 * RelChunkZ] & 0xff; + if ((chunkOffset < 2) || (numChunkSectors == 0)) + { + return ""; + } + + // Get the real data size: + const char * chunkData = m_FileData.data() + chunkOffset * 4096; + UInt32 chunkSize = GetBEInt(chunkData); + if ((chunkSize < 2) || (chunkSize / 4096 > numChunkSectors)) + { + // Bad data, bail out + return ""; + } + + // Check the compression method: + if (chunkData[4] != 2) + { + // Chunk is in an unknown compression + return ""; + } + chunkSize--; + + // Read the chunk data: + return m_FileData.substr(chunkOffset * 4096 + 5, chunkSize); + } + +protected: + AString m_FileData; + UInt32 m_Header[2048]; + + + /** Reads the whole specified file contents and parses the header. */ + void readFile(const AString & a_FileName) + { + // Read the entire file: + m_FileData = cFile::ReadWholeFile(a_FileName); + if (m_FileData.size() < sizeof(m_Header)) + { + return; + } + + // Parse the header - change endianness: + const char * hdr = m_FileData.data(); + for (size_t i = 0; i < ARRAYCOUNT(m_Header); i++) + { + m_Header[i] = GetBEInt(hdr + 4 * i); + } + m_IsValid = true; + } +}; + + + + + +//////////////////////////////////////////////////////////////////////////////// +// AnvilSource: + +AnvilSource::AnvilSource(QString a_WorldRegionFolder) : + m_WorldRegionFolder(a_WorldRegionFolder) +{ +} + + + + + +void AnvilSource::getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChunk) +{ + // Load the compressed data: + AString compressedChunkData = getCompressedChunkData(a_ChunkX, a_ChunkZ); + if (compressedChunkData.empty()) + { + return; + } + + // Uncompress the chunk data: + AString uncompressed; + int res = InflateString(compressedChunkData.data(), compressedChunkData.size(), uncompressed); + if (res != Z_OK) + { + return; + } + + // Parse the NBT data: + cParsedNBT nbt(uncompressed.data(), uncompressed.size()); + if (!nbt.IsValid()) + { + return; + } + + // Get the biomes out of the NBT: + int Level = nbt.FindChildByName(0, "Level"); + if (Level < 0) + { + return; + } + cChunkDef::BiomeMap biomeMap; + int mcsBiomes = nbt.FindChildByName(Level, "MCSBiomes"); + if ((mcsBiomes >= 0) && (nbt.GetDataLength(mcsBiomes) == sizeof(biomeMap))) + { + // Convert the biomes from BigEndian to platform native numbers: + const char * beBiomes = nbt.GetData(mcsBiomes); + for (size_t i = 0; i < ARRAYCOUNT(biomeMap); i++) + { + biomeMap[i] = (EMCSBiome)GetBEInt(beBiomes + 4 * i); + } + // Render the biomes: + Chunk::Image img; + biomesToImage(biomeMap, img); + a_DestChunk->setImage(img); + return; + } + + // MCS biomes not found, load Vanilla biomes instead: + int biomes = nbt.FindChildByName(Level, "Biomes"); + if ((biomes < 0) || (nbt.GetDataLength(biomes) != ARRAYCOUNT(biomeMap))) + { + return; + } + // Convert the biomes from Vanilla to EMCSBiome: + const char * vanillaBiomes = nbt.GetData(biomes); + for (size_t i = 0; i < ARRAYCOUNT(biomeMap); i++) + { + biomeMap[i] = EMCSBiome(vanillaBiomes[i]); + } + // Render the biomes: + Chunk::Image img; + biomesToImage(biomeMap, img); + a_DestChunk->setImage(img); +} + + + + + +void AnvilSource::reload() +{ + // Remove all files from the cache: + QMutexLocker lock(&m_Mtx); + m_Files.clear(); +} + + + + + +void AnvilSource::chunkToRegion(int a_ChunkX, int a_ChunkZ, int & a_RegionX, int & a_RegionZ) +{ + a_RegionX = a_ChunkX >> 5; + a_RegionZ = a_ChunkZ >> 5; +} + + + + + +AString AnvilSource::getCompressedChunkData(int a_ChunkX, int a_ChunkZ) +{ + return getAnvilFile(a_ChunkX, a_ChunkZ)->getChunkData(a_ChunkX, a_ChunkZ); +} + + + + + +AnvilSource::AnvilFilePtr AnvilSource::getAnvilFile(int a_ChunkX, int a_ChunkZ) +{ + int RegionX, RegionZ; + chunkToRegion(a_ChunkX, a_ChunkZ, RegionX, RegionZ); + + // Search the cache for the file: + QMutexLocker lock(&m_Mtx); + for (auto itr = m_Files.cbegin(), end = m_Files.cend(); itr != end; ++itr) + { + if (((*itr)->m_RegionX == RegionX) && ((*itr)->m_RegionZ == RegionZ)) + { + // Found the file in the cache, move it to front and return it: + AnvilFilePtr file(*itr); + m_Files.erase(itr); + m_Files.push_front(file); + return file; + } + } + + // File not in cache, create it: + AnvilFilePtr file(new AnvilFile(RegionX, RegionZ, m_WorldRegionFolder.toStdString())); + m_Files.push_front(file); + return file; +} + + + + + diff --git a/Tools/QtBiomeVisualiser/ChunkSource.h b/Tools/QtBiomeVisualiser/ChunkSource.h index 868e4a144..a5612da01 100644 --- a/Tools/QtBiomeVisualiser/ChunkSource.h +++ b/Tools/QtBiomeVisualiser/ChunkSource.h @@ -1,4 +1,5 @@ #pragma once +#include "Globals.h" #include #include #include "Chunk.h" @@ -64,11 +65,40 @@ class AnvilSource : public ChunkSource { public: - // TODO + /** Constructs a new AnvilSource based on the world path. */ + AnvilSource(QString a_WorldRegionFolder); // ChunkSource overrides: virtual void getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChunk) override; - virtual void reload() override {} + virtual void reload() override; + +protected: + class AnvilFile; + typedef std::shared_ptr 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 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); + }; diff --git a/Tools/QtBiomeVisualiser/MainWindow.cpp b/Tools/QtBiomeVisualiser/MainWindow.cpp index 65d0ccf5e..b6db806f9 100644 --- a/Tools/QtBiomeVisualiser/MainWindow.cpp +++ b/Tools/QtBiomeVisualiser/MainWindow.cpp @@ -39,6 +39,10 @@ MainWindow::~MainWindow() void MainWindow::generate() { QString worldIni = QFileDialog::getOpenFileName(this, tr("Open world.ini"), QString(), tr("world.ini (world.ini)")); + if (worldIni.isEmpty()) + { + return; + } m_BiomeView->setChunkSource(std::shared_ptr(new BioGenSource(worldIni))); m_BiomeView->redraw(); } @@ -49,7 +53,13 @@ void MainWindow::generate() void MainWindow::open() { - // TODO + QString regionFolder = QFileDialog::getExistingDirectory(this, tr("Select the region folder"), QString()); + if (regionFolder.isEmpty()) + { + return; + } + m_BiomeView->setChunkSource(std::shared_ptr(new AnvilSource(regionFolder))); + m_BiomeView->redraw(); } diff --git a/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro b/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro index e6b65e628..283e180f8 100644 --- a/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro +++ b/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro @@ -29,7 +29,24 @@ SOURCES += main.cpp\ ChunkCache.cpp \ Chunk.cpp \ ChunkSource.cpp \ - ChunkLoader.cpp + ChunkLoader.cpp \ + ../../src/StringCompression.cpp \ + ../../src/WorldStorage/FastNBT.cpp \ + ../../lib/zlib/adler32.c \ + ../../lib/zlib/compress.c \ + ../../lib/zlib/crc32.c \ + ../../lib/zlib/deflate.c \ + ../../lib/zlib/gzclose.c \ + ../../lib/zlib/gzlib.c \ + ../../lib/zlib/gzread.c \ + ../../lib/zlib/gzwrite.c \ + ../../lib/zlib/infback.c \ + ../../lib/zlib/inffast.c \ + ../../lib/zlib/inflate.c \ + ../../lib/zlib/inftrees.c \ + ../../lib/zlib/trees.c \ + ../../lib/zlib/uncompr.c \ + ../../lib/zlib/zutil.c HEADERS += MainWindow.h \ Globals.h \ @@ -48,7 +65,20 @@ HEADERS += MainWindow.h \ ChunkCache.h \ Chunk.h \ ChunkSource.h \ - ChunkLoader.h + ChunkLoader.h \ + ../../src/StringCompression.h \ + ../../src/WorldStorage/FastNBT.h \ + ../../lib/zlib/crc32.h \ + ../../lib/zlib/deflate.h \ + ../../lib/zlib/gzguts.h \ + ../../lib/zlib/inffast.h \ + ../../lib/zlib/inffixed.h \ + ../../lib/zlib/inflate.h \ + ../../lib/zlib/inftrees.h \ + ../../lib/zlib/trees.h \ + ../../lib/zlib/zconf.h \ + ../../lib/zlib/zlib.h \ + ../../lib/zlib/zutil.h INCLUDEPATH += $$_PRO_FILE_PWD_ \ $$_PRO_FILE_PWD_/../../src \ @@ -57,4 +87,8 @@ INCLUDEPATH += $$_PRO_FILE_PWD_ \ CONFIG += C++11 +OTHER_FILES += \ + ../../lib/zlib/example.c.txt \ + ../../lib/zlib/minigzip.c.txt + -- cgit v1.2.3 From 14123c6d1653b79b6c58e7766dc97e5d06bf1fc9 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 20 Sep 2014 23:03:13 +0200 Subject: QtBiomeVisualiser: Added list of vanilla worlds. --- Tools/QtBiomeVisualiser/MainWindow.cpp | 132 +++++++++++++++++++++++++++++++-- Tools/QtBiomeVisualiser/MainWindow.h | 20 +++++ 2 files changed, 145 insertions(+), 7 deletions(-) (limited to 'Tools/QtBiomeVisualiser') diff --git a/Tools/QtBiomeVisualiser/MainWindow.cpp b/Tools/QtBiomeVisualiser/MainWindow.cpp index b6db806f9..c56cf8bc2 100644 --- a/Tools/QtBiomeVisualiser/MainWindow.cpp +++ b/Tools/QtBiomeVisualiser/MainWindow.cpp @@ -5,9 +5,13 @@ #include #include #include +#include +#include #include "inifile/iniFile.h" #include "ChunkSource.h" #include "Generating/BioGen.h" +#include "StringCompression.h" +#include "WorldStorage/FastNBT.h" @@ -16,6 +20,8 @@ MainWindow::MainWindow(QWidget * parent) : QMainWindow(parent) { + initMinecraftPath(); + m_BiomeView = new BiomeView(this); setCentralWidget(m_BiomeView); @@ -66,8 +72,41 @@ void MainWindow::open() +void MainWindow::openVanillaWorld() +{ + QAction * action = qobject_cast(sender()); + if (action == nullptr) + { + return; + } + m_BiomeView->setChunkSource(std::shared_ptr(new AnvilSource(action->data().toString()))); + m_BiomeView->redraw(); +} + + + + + +void MainWindow::initMinecraftPath() +{ + #ifdef Q_OS_MAC + m_MinecraftPath = QDir::homePath() + QDir::toNativeSeparators("/Library/Application Support/minecraft"); + #elif defined Q_OS_WIN32 + QSettings ini(QSettings::IniFormat, QSettings::UserScope, ".minecraft", "minecraft1"); + m_MinecraftPath = QFileInfo(ini.fileName()).absolutePath(); + #else + m_MinecraftPath = QDir::homePath() + QDir::toNativeSeparators("/.minecraft"); + #endif +} + + + + + void MainWindow::createActions() { + createWorldActions(); + m_actGen = new QAction(tr("&Generate..."), this); m_actGen->setShortcut(tr("Ctrl+N")); m_actGen->setStatusTip(tr("Open a generator INI file and display the generated biomes")); @@ -93,15 +132,94 @@ void MainWindow::createActions() +void MainWindow::createWorldActions() +{ + QDir mc(m_MinecraftPath); + if (!mc.cd("saves")) + { + return; + } + + QDirIterator it(mc); + int key = 1; + while (it.hasNext()) + { + it.next(); + if (!it.fileInfo().isDir()) + { + continue; + } + QString name = getWorldName(it.filePath().toStdString()); + if (name.isEmpty()) + { + continue; + } + QAction * w = new QAction(this); + w->setText(name); + w->setData(it.filePath() + "/region"); + if (key < 10) + { + w->setShortcut("Ctrl+" + QString::number(key)); + key++; + } + connect(w, SIGNAL(triggered()), this, SLOT(openVanillaWorld())); + m_WorldActions.append(w); + } +} + + + + + void MainWindow::createMenus() { - QMenu * mFile = menuBar()->addMenu(tr("&World")); - mFile->addAction(m_actGen); - mFile->addAction(m_actOpen); - mFile->addSeparator(); - mFile->addAction(m_actReload); - mFile->addSeparator(); - mFile->addAction(m_actExit); + QMenu * file = menuBar()->addMenu(tr("&Map")); + file->addAction(m_actGen); + file->addSeparator(); + QMenu * worlds = file->addMenu(tr("Open existing")); + worlds->addActions(m_WorldActions); + if (m_WorldActions.empty()) + { + worlds->setEnabled(false); + } + file->addAction(m_actOpen); + file->addSeparator(); + file->addAction(m_actReload); + file->addSeparator(); + file->addAction(m_actExit); +} + + + + + +QString MainWindow::getWorldName(const AString & a_Path) +{ + AString levelData = cFile::ReadWholeFile(a_Path + "/level.dat"); + if (levelData.empty()) + { + // No such file / no data + return QString(); + } + + AString uncompressed; + if (UncompressStringGZIP(levelData.data(), levelData.size(), uncompressed) != Z_OK) + { + return QString(); + } + cParsedNBT nbt(uncompressed.data(), uncompressed.size()); + if (!nbt.IsValid()) + { + return QString(); + } + AString name = nbt.GetName(1); + OutputDebugStringA(name.c_str()); + int levelNameTag = nbt.FindTagByPath(nbt.GetRoot(), "Data\\LevelName"); + if ((levelNameTag <= 0) || (nbt.GetType(levelNameTag) != TAG_String)) + { + return QString(); + } + return QString::fromStdString(nbt.GetString(levelNameTag)); } diff --git a/Tools/QtBiomeVisualiser/MainWindow.h b/Tools/QtBiomeVisualiser/MainWindow.h index b37bf4120..997d7a5d2 100644 --- a/Tools/QtBiomeVisualiser/MainWindow.h +++ b/Tools/QtBiomeVisualiser/MainWindow.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include "BiomeView.h" @@ -25,6 +26,9 @@ private slots: /** Opens an existing world and displays the loaded biomes. */ void open(); + /** Opens a vanilla world that is specified by the calling action. */ + void openVanillaWorld(); + protected: // Actions: QAction * m_actGen; @@ -32,12 +36,28 @@ protected: QAction * m_actReload; QAction * m_actExit; + /** List of actions that open the specific vanilla world. */ + QList m_WorldActions; + + /** Path to the vanilla folder. */ + QString m_MinecraftPath; + + + /** Initializes the m_MinecraftPath based on the proper MC path */ + void initMinecraftPath(); /** Creates the actions that the UI supports. */ void createActions(); + /** Creates the actions that open a specific vanilla world. Iterates over the minecraft saves folder. */ + void createWorldActions(); + /** Creates the menu bar and connects its events. */ void createMenus(); + + /** Returns the name of the vanilla world in the specified path. + Reads the level.dat file for the name. Returns an empty string on failure. */ + QString getWorldName(const AString & a_Path); }; -- cgit v1.2.3 From dda66ea6efaa1ae3305dae97a9ab9bdb4254cf46 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 21 Sep 2014 22:58:09 +0200 Subject: QtBiomeVisualiser: Added the base for INI editting. --- Tools/QtBiomeVisualiser/GeneratorSetupDlg.cpp | 125 ++++++++++++++++++++++++++ Tools/QtBiomeVisualiser/GeneratorSetupDlg.h | 53 +++++++++++ Tools/QtBiomeVisualiser/MainWindow.cpp | 77 +++++++++++++--- Tools/QtBiomeVisualiser/MainWindow.h | 25 ++++-- Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro | 6 +- 5 files changed, 266 insertions(+), 20 deletions(-) create mode 100644 Tools/QtBiomeVisualiser/GeneratorSetupDlg.cpp create mode 100644 Tools/QtBiomeVisualiser/GeneratorSetupDlg.h (limited to 'Tools/QtBiomeVisualiser') diff --git a/Tools/QtBiomeVisualiser/GeneratorSetupDlg.cpp b/Tools/QtBiomeVisualiser/GeneratorSetupDlg.cpp new file mode 100644 index 000000000..e6037fa9b --- /dev/null +++ b/Tools/QtBiomeVisualiser/GeneratorSetupDlg.cpp @@ -0,0 +1,125 @@ +#include "Globals.h" +#include "GeneratorSetupDlg.h" +#include +#include +#include "Generating/BioGen.h" +#include "inifile/iniFile.h" + + + + + +static const QString s_GeneratorNames[] = +{ + QString("Checkerboard"), + QString("Constant"), + QString("DistortedVoronoi"), + QString("MultiStepMap"), + QString("TwoLevel"), + QString("Voronoi"), +}; + + + + + +GeneratorSetupDlg::GeneratorSetupDlg(const AString & a_IniFileName, QWidget * a_Parent) : + super(a_Parent), + m_IniFile(new cIniFile()) +{ + // The generator name is in a separate form layout at the top, always present: + m_cbGenerator = new QComboBox(); + m_cbGenerator->setMinimumWidth(300); + for (size_t i = 0; i < ARRAYCOUNT(s_GeneratorNames); i++) + { + m_cbGenerator->addItem(s_GeneratorNames[i]); + } + QFormLayout * nameLayout = new QFormLayout(); + nameLayout->addRow(new QLabel(tr("Generator")), m_cbGenerator); + + // The rest of the controls are in a dynamically created form layout: + m_FormLayout = new QFormLayout(); + + // The main layout joins these two vertically: + m_MainLayout = new QVBoxLayout(); + m_MainLayout->addLayout(nameLayout); + m_MainLayout->addLayout(m_FormLayout); + setLayout(m_MainLayout); + + // Load the INI file, if specified, otherwise set defaults: + if (!a_IniFileName.empty() && m_IniFile->ReadFile(a_IniFileName)) + { + m_cbGenerator->setCurrentText(QString::fromStdString(m_IniFile->GetValue("Generator", "BiomeGen"))); + } + else + { + m_IniFile->SetValue("Generator", "Generator", "Composable"); + m_IniFile->SetValue("Generator", "BiomeGen", m_cbGenerator->currentText().toStdString()); + bool dummy; + delete cBiomeGen::CreateBiomeGen(*m_IniFile, m_Seed, dummy); + } + updateFromIni(); + + // Connect the combo change even only after the data has been loaded: + connect(m_cbGenerator, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(generatorChanged(QString))); +} + + + + + +void GeneratorSetupDlg::generatorChanged(const QString & a_NewName) +{ + // Clear the current contents of the form layout by assigning it to a stack temporary: + { + m_MainLayout->takeAt(1); + QWidget().setLayout(m_FormLayout); + } + + // Re-create the layout: + m_FormLayout = new QFormLayout(); + m_MainLayout->addLayout(m_FormLayout); + + // Recreate the INI file: + m_IniFile->Clear(); + m_IniFile->SetValue("Generator", "Generator", "Composable"); + m_IniFile->SetValue("Generator", "BiomeGen", a_NewName.toStdString()); + + // Create a dummy biome gen from the INI file, this will create the defaults in the INI file: + bool dummy; + delete cBiomeGen::CreateBiomeGen(*m_IniFile, m_Seed, dummy); + + // Read all values from the INI file and put them into the form layout: + updateFromIni(); +} + + + + + +void GeneratorSetupDlg::updateFromIni() +{ + int keyID = m_IniFile->FindKey("Generator"); + if (keyID <= -1) + { + return; + } + int numItems = m_IniFile->GetNumValues(keyID); + for (int i = 0; i < numItems; i++) + { + AString itemName = m_IniFile->GetValueName(keyID, i); + AString itemValue = m_IniFile->GetValue(keyID, i); + if ((itemName == "Generator") || (itemName == "BiomeGen")) + { + // These special cases are not to be added + continue; + } + QLineEdit * edit = new QLineEdit(); + edit->setText(QString::fromStdString(itemValue)); + m_FormLayout->addRow(new QLabel(QString::fromStdString(itemName)), edit); + } // for i - INI values[] +} + + + + diff --git a/Tools/QtBiomeVisualiser/GeneratorSetupDlg.h b/Tools/QtBiomeVisualiser/GeneratorSetupDlg.h new file mode 100644 index 000000000..d7070e331 --- /dev/null +++ b/Tools/QtBiomeVisualiser/GeneratorSetupDlg.h @@ -0,0 +1,53 @@ +#pragma once + +#include +#include +#include +#include +#include + + + + + +class cIniFile; + + + + + +class GeneratorSetupDlg : + public QDialog +{ + typedef QDialog super; + + Q_OBJECT + +public: + /** Creates the dialog and loads the contents of the INI file, if not empty. */ + explicit GeneratorSetupDlg(const std::string & a_IniFileName, QWidget * parent = nullptr); + +signals: + +public slots: + /** Called when the user selects a different generator from the top combobox. + Re-creates m_IniFile and updates the form layout. */ + void generatorChanged(const QString & a_NewName); + +protected: + QComboBox * m_cbGenerator; + QVBoxLayout * m_MainLayout; + QFormLayout * m_FormLayout; + + std::unique_ptr m_IniFile; + + int m_Seed; + + + /** Updates the form layout with the values from m_IniFile. */ + void updateFromIni(); +}; + + + + diff --git a/Tools/QtBiomeVisualiser/MainWindow.cpp b/Tools/QtBiomeVisualiser/MainWindow.cpp index c56cf8bc2..d2c1ae2c1 100644 --- a/Tools/QtBiomeVisualiser/MainWindow.cpp +++ b/Tools/QtBiomeVisualiser/MainWindow.cpp @@ -12,6 +12,7 @@ #include "Generating/BioGen.h" #include "StringCompression.h" #include "WorldStorage/FastNBT.h" +#include "GeneratorSetupDlg.h" @@ -42,13 +43,37 @@ MainWindow::~MainWindow() -void MainWindow::generate() +void MainWindow::newGenerator() { + // TODO + + // (Re-)open the generator setup dialog: + m_GeneratorSetupDlg.reset(new GeneratorSetupDlg("")); + m_GeneratorSetupDlg->show(); + m_GeneratorSetupDlg->raise(); + + // TODO +} + + + + + +void MainWindow::openGenerator() +{ + // Let the user specify the world.ini file: QString worldIni = QFileDialog::getOpenFileName(this, tr("Open world.ini"), QString(), tr("world.ini (world.ini)")); if (worldIni.isEmpty()) { return; } + + // (Re-)open the generator setup dialog: + m_GeneratorSetupDlg.reset(new GeneratorSetupDlg(worldIni.toStdString())); + m_GeneratorSetupDlg->show(); + m_GeneratorSetupDlg->raise(); + + // Set the chunk source: m_BiomeView->setChunkSource(std::shared_ptr(new BioGenSource(worldIni))); m_BiomeView->redraw(); } @@ -57,13 +82,23 @@ void MainWindow::generate() -void MainWindow::open() +void MainWindow::openWorld() { + // Let the user specify the world: QString regionFolder = QFileDialog::getExistingDirectory(this, tr("Select the region folder"), QString()); if (regionFolder.isEmpty()) { return; } + + // Remove the generator setup dialog, if open: + if (m_GeneratorSetupDlg.get() != nullptr) + { + m_GeneratorSetupDlg->hide(); + m_GeneratorSetupDlg.reset(nullptr); + } + + // Set the chunk source: m_BiomeView->setChunkSource(std::shared_ptr(new AnvilSource(regionFolder))); m_BiomeView->redraw(); } @@ -74,11 +109,21 @@ void MainWindow::open() void MainWindow::openVanillaWorld() { + // The world is stored in the sender action's data, retrieve it: QAction * action = qobject_cast(sender()); if (action == nullptr) { return; } + + // Remove the generator setup dialog, if open: + if (m_GeneratorSetupDlg.get() != nullptr) + { + m_GeneratorSetupDlg->hide(); + m_GeneratorSetupDlg.reset(nullptr); + } + + // Set the chunk source: m_BiomeView->setChunkSource(std::shared_ptr(new AnvilSource(action->data().toString()))); m_BiomeView->redraw(); } @@ -107,19 +152,24 @@ void MainWindow::createActions() { createWorldActions(); - m_actGen = new QAction(tr("&Generate..."), this); - m_actGen->setShortcut(tr("Ctrl+N")); - m_actGen->setStatusTip(tr("Open a generator INI file and display the generated biomes")); - connect(m_actGen, SIGNAL(triggered()), this, SLOT(generate())); + m_actNewGen = new QAction(tr("&New generator"), this); + m_actNewGen->setShortcut(tr("Ctrl+N")); + m_actNewGen->setStatusTip(tr("Open a generator INI file and display the generated biomes")); + connect(m_actNewGen, SIGNAL(triggered()), this, SLOT(newGenerator())); + + m_actOpenGen = new QAction(tr("&Open generator..."), this); + m_actOpenGen->setShortcut(tr("Ctrl+G")); + m_actOpenGen->setStatusTip(tr("Open a generator INI file and display the generated biomes")); + connect(m_actOpenGen, SIGNAL(triggered()), this, SLOT(openGenerator())); - m_actOpen = new QAction(tr("&Open world..."), this); - m_actOpen->setShortcut(tr("Ctrl+O")); - m_actOpen->setStatusTip(tr("Open an existing world and display its biomes")); - connect(m_actOpen, SIGNAL(triggered()), this, SLOT(open())); + m_actOpenWorld = new QAction(tr("&Open world..."), this); + m_actOpenWorld->setShortcut(tr("Ctrl+O")); + m_actOpenWorld->setStatusTip(tr("Open an existing world and display its biomes")); + connect(m_actOpenWorld, SIGNAL(triggered()), this, SLOT(openWorld())); m_actReload = new QAction(tr("&Reload"), this); m_actReload->setShortcut(tr("F5")); - m_actReload->setStatusTip(tr("Open an existing world and display its biomes")); + m_actReload->setStatusTip(tr("Clear the view cache and force a reload of all the data")); connect(m_actReload, SIGNAL(triggered()), m_BiomeView, SLOT(reload())); m_actExit = new QAction(tr("E&xit"), this); @@ -174,7 +224,8 @@ void MainWindow::createWorldActions() void MainWindow::createMenus() { QMenu * file = menuBar()->addMenu(tr("&Map")); - file->addAction(m_actGen); + file->addAction(m_actNewGen); + file->addAction(m_actOpenGen); file->addSeparator(); QMenu * worlds = file->addMenu(tr("Open existing")); worlds->addActions(m_WorldActions); @@ -182,7 +233,7 @@ void MainWindow::createMenus() { worlds->setEnabled(false); } - file->addAction(m_actOpen); + file->addAction(m_actOpenWorld); file->addSeparator(); file->addAction(m_actReload); file->addSeparator(); diff --git a/Tools/QtBiomeVisualiser/MainWindow.h b/Tools/QtBiomeVisualiser/MainWindow.h index 997d7a5d2..840e01b0f 100644 --- a/Tools/QtBiomeVisualiser/MainWindow.h +++ b/Tools/QtBiomeVisualiser/MainWindow.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include "BiomeView.h" @@ -8,6 +9,13 @@ +// fwd: +class GeneratorSetupDlg; + + + + + class MainWindow : public QMainWindow { @@ -16,23 +24,27 @@ class MainWindow : BiomeView * m_BiomeView; public: - MainWindow(QWidget *parent = 0); + MainWindow(QWidget * parent = nullptr); ~MainWindow(); private slots: + /** Creates a generator definition from scratch, lets user modify generator params in realtime. */ + void newGenerator(); + /** Opens a generator definition and generates the biomes based on that. */ - void generate(); + void openGenerator(); /** Opens an existing world and displays the loaded biomes. */ - void open(); + void openWorld(); /** Opens a vanilla world that is specified by the calling action. */ void openVanillaWorld(); protected: // Actions: - QAction * m_actGen; - QAction * m_actOpen; + QAction * m_actNewGen; + QAction * m_actOpenGen; + QAction * m_actOpenWorld; QAction * m_actReload; QAction * m_actExit; @@ -42,6 +54,9 @@ protected: /** Path to the vanilla folder. */ QString m_MinecraftPath; + /** The dialog for setting up the generator. */ + std::unique_ptr m_GeneratorSetupDlg; + /** Initializes the m_MinecraftPath based on the proper MC path */ void initMinecraftPath(); diff --git a/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro b/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro index 283e180f8..7171562bb 100644 --- a/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro +++ b/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro @@ -46,7 +46,8 @@ SOURCES += main.cpp\ ../../lib/zlib/inftrees.c \ ../../lib/zlib/trees.c \ ../../lib/zlib/uncompr.c \ - ../../lib/zlib/zutil.c + ../../lib/zlib/zutil.c \ + GeneratorSetupDlg.cpp HEADERS += MainWindow.h \ Globals.h \ @@ -78,7 +79,8 @@ HEADERS += MainWindow.h \ ../../lib/zlib/trees.h \ ../../lib/zlib/zconf.h \ ../../lib/zlib/zlib.h \ - ../../lib/zlib/zutil.h + ../../lib/zlib/zutil.h \ + GeneratorSetupDlg.h INCLUDEPATH += $$_PRO_FILE_PWD_ \ $$_PRO_FILE_PWD_/../../src \ -- cgit v1.2.3 From 10c5d5056691f0a03798c7e9439138126da30b8a Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 22 Sep 2014 18:26:35 +0200 Subject: QtBiomeVisualiser: Moved the generator setup into a side-pane. --- Tools/QtBiomeVisualiser/GeneratorSetup.cpp | 135 ++++++++++++++++++++++++++ Tools/QtBiomeVisualiser/GeneratorSetup.h | 57 +++++++++++ Tools/QtBiomeVisualiser/GeneratorSetupDlg.cpp | 125 ------------------------ Tools/QtBiomeVisualiser/GeneratorSetupDlg.h | 53 ---------- Tools/QtBiomeVisualiser/MainWindow.cpp | 69 +++++++++---- Tools/QtBiomeVisualiser/MainWindow.h | 24 ++++- Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro | 4 +- 7 files changed, 262 insertions(+), 205 deletions(-) create mode 100644 Tools/QtBiomeVisualiser/GeneratorSetup.cpp create mode 100644 Tools/QtBiomeVisualiser/GeneratorSetup.h delete mode 100644 Tools/QtBiomeVisualiser/GeneratorSetupDlg.cpp delete mode 100644 Tools/QtBiomeVisualiser/GeneratorSetupDlg.h (limited to 'Tools/QtBiomeVisualiser') diff --git a/Tools/QtBiomeVisualiser/GeneratorSetup.cpp b/Tools/QtBiomeVisualiser/GeneratorSetup.cpp new file mode 100644 index 000000000..d512d2b90 --- /dev/null +++ b/Tools/QtBiomeVisualiser/GeneratorSetup.cpp @@ -0,0 +1,135 @@ +#include "Globals.h" +#include "GeneratorSetup.h" +#include +#include +#include "Generating/BioGen.h" +#include "inifile/iniFile.h" + + + + + +static const QString s_GeneratorNames[] = +{ + QString("Checkerboard"), + QString("Constant"), + QString("DistortedVoronoi"), + QString("MultiStepMap"), + QString("TwoLevel"), + QString("Voronoi"), +}; + + + + + +GeneratorSetup::GeneratorSetup(const AString & a_IniFileName, QWidget * a_Parent) : + super(a_Parent), + m_IniFile(new cIniFile()) +{ + // The generator name is in a separate form layout at the top, always present: + m_cbGenerator = new QComboBox(); + m_cbGenerator->setMinimumWidth(120); + for (size_t i = 0; i < ARRAYCOUNT(s_GeneratorNames); i++) + { + m_cbGenerator->addItem(s_GeneratorNames[i]); + } + QFormLayout * nameLayout = new QFormLayout(); + nameLayout->addRow(new QLabel(tr("Generator")), m_cbGenerator); + + // The rest of the controls are in a dynamically created form layout: + m_FormLayout = new QFormLayout(); + + // The main layout joins these two vertically: + m_MainLayout = new QVBoxLayout(); + m_MainLayout->addLayout(nameLayout); + m_MainLayout->addLayout(m_FormLayout); + m_MainLayout->addStretch(); + setLayout(m_MainLayout); + + // Load the INI file, if specified, otherwise set defaults: + if (!a_IniFileName.empty() && m_IniFile->ReadFile(a_IniFileName)) + { + m_cbGenerator->setCurrentText(QString::fromStdString(m_IniFile->GetValue("Generator", "BiomeGen"))); + } + else + { + m_IniFile->SetValue("Generator", "Generator", "Composable"); + m_IniFile->SetValue("Generator", "BiomeGen", m_cbGenerator->currentText().toStdString()); + bool dummy; + delete cBiomeGen::CreateBiomeGen(*m_IniFile, m_Seed, dummy); + } + updateFromIni(); + + // Connect the combo change even only after the data has been loaded: + connect(m_cbGenerator, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(generatorChanged(QString))); +} + + + + + +void GeneratorSetup::generatorChanged(const QString & a_NewName) +{ + // Clear the current contents of the form layout by assigning it to a stack temporary: + { + m_MainLayout->takeAt(1); + QWidget().setLayout(m_FormLayout); + } + + // Re-create the layout: + m_FormLayout = new QFormLayout(); + m_MainLayout->insertLayout(1, m_FormLayout); + + // Recreate the INI file: + m_IniFile->Clear(); + m_IniFile->SetValue("Generator", "Generator", "Composable"); + m_IniFile->SetValue("Generator", "BiomeGen", a_NewName.toStdString()); + + // Create a dummy biome gen from the INI file, this will create the defaults in the INI file: + bool dummy; + delete cBiomeGen::CreateBiomeGen(*m_IniFile, m_Seed, dummy); + + // Read all values from the INI file and put them into the form layout: + updateFromIni(); +} + + + + + +void GeneratorSetup::updateFromIni() +{ + int keyID = m_IniFile->FindKey("Generator"); + if (keyID <= -1) + { + return; + } + int numItems = m_IniFile->GetNumValues(keyID); + AString generatorName = m_IniFile->GetValue("Generator", "BiomeGen"); + size_t generatorNameLen = generatorName.length(); + for (int i = 0; i < numItems; i++) + { + AString itemName = m_IniFile->GetValueName(keyID, i); + AString itemValue = m_IniFile->GetValue(keyID, i); + if ((itemName == "Generator") || (itemName == "BiomeGen")) + { + // These special cases are not to be added + continue; + } + + // Remove the generator name prefix from the item name, for clarity purposes: + if (NoCaseCompare(itemName.substr(0, generatorNameLen), generatorName) == 0) + { + itemName.erase(0, generatorNameLen); + } + + QLineEdit * edit = new QLineEdit(); + edit->setText(QString::fromStdString(itemValue)); + m_FormLayout->addRow(new QLabel(QString::fromStdString(itemName)), edit); + } // for i - INI values[] +} + + + + diff --git a/Tools/QtBiomeVisualiser/GeneratorSetup.h b/Tools/QtBiomeVisualiser/GeneratorSetup.h new file mode 100644 index 000000000..0594e1998 --- /dev/null +++ b/Tools/QtBiomeVisualiser/GeneratorSetup.h @@ -0,0 +1,57 @@ +#pragma once + +#include +#include +#include +#include +#include + + + + + +class cIniFile; +typedef std::shared_ptr cIniFilePtr; + + + + + +class GeneratorSetup : + public QWidget +{ + typedef QWidget super; + + Q_OBJECT + +public: + /** Creates the widget and loads the contents of the INI file, if not empty. */ + explicit GeneratorSetup(const std::string & a_IniFileName, QWidget * parent = nullptr); + + /** Returns the cIniFile instance that is being edited by this widget. */ + cIniFilePtr getIniFile() { return m_IniFile; } + +signals: + +public slots: + /** Called when the user selects a different generator from the top combobox. + Re-creates m_IniFile and updates the form layout. */ + void generatorChanged(const QString & a_NewName); + +protected: + QComboBox * m_cbGenerator; + QVBoxLayout * m_MainLayout; + QFormLayout * m_FormLayout; + + cIniFilePtr m_IniFile; + + int m_Seed; + + + /** Updates the form layout with the values from m_IniFile. */ + void updateFromIni(); +}; + + + + diff --git a/Tools/QtBiomeVisualiser/GeneratorSetupDlg.cpp b/Tools/QtBiomeVisualiser/GeneratorSetupDlg.cpp deleted file mode 100644 index e6037fa9b..000000000 --- a/Tools/QtBiomeVisualiser/GeneratorSetupDlg.cpp +++ /dev/null @@ -1,125 +0,0 @@ -#include "Globals.h" -#include "GeneratorSetupDlg.h" -#include -#include -#include "Generating/BioGen.h" -#include "inifile/iniFile.h" - - - - - -static const QString s_GeneratorNames[] = -{ - QString("Checkerboard"), - QString("Constant"), - QString("DistortedVoronoi"), - QString("MultiStepMap"), - QString("TwoLevel"), - QString("Voronoi"), -}; - - - - - -GeneratorSetupDlg::GeneratorSetupDlg(const AString & a_IniFileName, QWidget * a_Parent) : - super(a_Parent), - m_IniFile(new cIniFile()) -{ - // The generator name is in a separate form layout at the top, always present: - m_cbGenerator = new QComboBox(); - m_cbGenerator->setMinimumWidth(300); - for (size_t i = 0; i < ARRAYCOUNT(s_GeneratorNames); i++) - { - m_cbGenerator->addItem(s_GeneratorNames[i]); - } - QFormLayout * nameLayout = new QFormLayout(); - nameLayout->addRow(new QLabel(tr("Generator")), m_cbGenerator); - - // The rest of the controls are in a dynamically created form layout: - m_FormLayout = new QFormLayout(); - - // The main layout joins these two vertically: - m_MainLayout = new QVBoxLayout(); - m_MainLayout->addLayout(nameLayout); - m_MainLayout->addLayout(m_FormLayout); - setLayout(m_MainLayout); - - // Load the INI file, if specified, otherwise set defaults: - if (!a_IniFileName.empty() && m_IniFile->ReadFile(a_IniFileName)) - { - m_cbGenerator->setCurrentText(QString::fromStdString(m_IniFile->GetValue("Generator", "BiomeGen"))); - } - else - { - m_IniFile->SetValue("Generator", "Generator", "Composable"); - m_IniFile->SetValue("Generator", "BiomeGen", m_cbGenerator->currentText().toStdString()); - bool dummy; - delete cBiomeGen::CreateBiomeGen(*m_IniFile, m_Seed, dummy); - } - updateFromIni(); - - // Connect the combo change even only after the data has been loaded: - connect(m_cbGenerator, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(generatorChanged(QString))); -} - - - - - -void GeneratorSetupDlg::generatorChanged(const QString & a_NewName) -{ - // Clear the current contents of the form layout by assigning it to a stack temporary: - { - m_MainLayout->takeAt(1); - QWidget().setLayout(m_FormLayout); - } - - // Re-create the layout: - m_FormLayout = new QFormLayout(); - m_MainLayout->addLayout(m_FormLayout); - - // Recreate the INI file: - m_IniFile->Clear(); - m_IniFile->SetValue("Generator", "Generator", "Composable"); - m_IniFile->SetValue("Generator", "BiomeGen", a_NewName.toStdString()); - - // Create a dummy biome gen from the INI file, this will create the defaults in the INI file: - bool dummy; - delete cBiomeGen::CreateBiomeGen(*m_IniFile, m_Seed, dummy); - - // Read all values from the INI file and put them into the form layout: - updateFromIni(); -} - - - - - -void GeneratorSetupDlg::updateFromIni() -{ - int keyID = m_IniFile->FindKey("Generator"); - if (keyID <= -1) - { - return; - } - int numItems = m_IniFile->GetNumValues(keyID); - for (int i = 0; i < numItems; i++) - { - AString itemName = m_IniFile->GetValueName(keyID, i); - AString itemValue = m_IniFile->GetValue(keyID, i); - if ((itemName == "Generator") || (itemName == "BiomeGen")) - { - // These special cases are not to be added - continue; - } - QLineEdit * edit = new QLineEdit(); - edit->setText(QString::fromStdString(itemValue)); - m_FormLayout->addRow(new QLabel(QString::fromStdString(itemName)), edit); - } // for i - INI values[] -} - - - - diff --git a/Tools/QtBiomeVisualiser/GeneratorSetupDlg.h b/Tools/QtBiomeVisualiser/GeneratorSetupDlg.h deleted file mode 100644 index d7070e331..000000000 --- a/Tools/QtBiomeVisualiser/GeneratorSetupDlg.h +++ /dev/null @@ -1,53 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - - - - - -class cIniFile; - - - - - -class GeneratorSetupDlg : - public QDialog -{ - typedef QDialog super; - - Q_OBJECT - -public: - /** Creates the dialog and loads the contents of the INI file, if not empty. */ - explicit GeneratorSetupDlg(const std::string & a_IniFileName, QWidget * parent = nullptr); - -signals: - -public slots: - /** Called when the user selects a different generator from the top combobox. - Re-creates m_IniFile and updates the form layout. */ - void generatorChanged(const QString & a_NewName); - -protected: - QComboBox * m_cbGenerator; - QVBoxLayout * m_MainLayout; - QFormLayout * m_FormLayout; - - std::unique_ptr m_IniFile; - - int m_Seed; - - - /** Updates the form layout with the values from m_IniFile. */ - void updateFromIni(); -}; - - - - diff --git a/Tools/QtBiomeVisualiser/MainWindow.cpp b/Tools/QtBiomeVisualiser/MainWindow.cpp index d2c1ae2c1..f9915901d 100644 --- a/Tools/QtBiomeVisualiser/MainWindow.cpp +++ b/Tools/QtBiomeVisualiser/MainWindow.cpp @@ -12,19 +12,27 @@ #include "Generating/BioGen.h" #include "StringCompression.h" #include "WorldStorage/FastNBT.h" -#include "GeneratorSetupDlg.h" +#include "GeneratorSetup.h" MainWindow::MainWindow(QWidget * parent) : - QMainWindow(parent) + QMainWindow(parent), + m_GeneratorSetup(nullptr), + m_LineSeparator(nullptr) { initMinecraftPath(); - m_BiomeView = new BiomeView(this); - setCentralWidget(m_BiomeView); + m_BiomeView = new BiomeView(); + m_MainLayout = new QHBoxLayout(); + m_MainLayout->addWidget(m_BiomeView); + m_MainLayout->setMenuBar(menuBar()); + m_MainLayout->setMargin(0); + QWidget * central = new QWidget(); + central->setLayout(m_MainLayout); + setCentralWidget(central); createActions(); createMenus(); @@ -48,9 +56,7 @@ void MainWindow::newGenerator() // TODO // (Re-)open the generator setup dialog: - m_GeneratorSetupDlg.reset(new GeneratorSetupDlg("")); - m_GeneratorSetupDlg->show(); - m_GeneratorSetupDlg->raise(); + openGeneratorSetup(""); // TODO } @@ -69,9 +75,7 @@ void MainWindow::openGenerator() } // (Re-)open the generator setup dialog: - m_GeneratorSetupDlg.reset(new GeneratorSetupDlg(worldIni.toStdString())); - m_GeneratorSetupDlg->show(); - m_GeneratorSetupDlg->raise(); + openGeneratorSetup(worldIni.toStdString()); // Set the chunk source: m_BiomeView->setChunkSource(std::shared_ptr(new BioGenSource(worldIni))); @@ -92,11 +96,7 @@ void MainWindow::openWorld() } // Remove the generator setup dialog, if open: - if (m_GeneratorSetupDlg.get() != nullptr) - { - m_GeneratorSetupDlg->hide(); - m_GeneratorSetupDlg.reset(nullptr); - } + closeGeneratorSetup(); // Set the chunk source: m_BiomeView->setChunkSource(std::shared_ptr(new AnvilSource(regionFolder))); @@ -117,11 +117,7 @@ void MainWindow::openVanillaWorld() } // Remove the generator setup dialog, if open: - if (m_GeneratorSetupDlg.get() != nullptr) - { - m_GeneratorSetupDlg->hide(); - m_GeneratorSetupDlg.reset(nullptr); - } + closeGeneratorSetup(); // Set the chunk source: m_BiomeView->setChunkSource(std::shared_ptr(new AnvilSource(action->data().toString()))); @@ -276,3 +272,36 @@ QString MainWindow::getWorldName(const AString & a_Path) + +void MainWindow::openGeneratorSetup(const AString & a_IniFileName) +{ + // Close any previous editor: + closeGeneratorSetup(); + + // Open up a new editor: + m_GeneratorSetup = new GeneratorSetup(a_IniFileName); + m_LineSeparator = new QWidget(); + m_LineSeparator->setFixedWidth(2); + m_LineSeparator->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); + m_LineSeparator->setStyleSheet(QString("background-color: #c0c0c0;")); + m_MainLayout->addWidget(m_LineSeparator); + m_MainLayout->addWidget(m_GeneratorSetup); +} + + + + + +void MainWindow::closeGeneratorSetup() +{ + delete m_MainLayout->takeAt(2); + delete m_MainLayout->takeAt(1); + delete m_GeneratorSetup; + delete m_LineSeparator; + m_GeneratorSetup = nullptr; + m_LineSeparator = nullptr; +} + + + + diff --git a/Tools/QtBiomeVisualiser/MainWindow.h b/Tools/QtBiomeVisualiser/MainWindow.h index 840e01b0f..6490a937f 100644 --- a/Tools/QtBiomeVisualiser/MainWindow.h +++ b/Tools/QtBiomeVisualiser/MainWindow.h @@ -3,6 +3,7 @@ #include #include #include +#include #include "BiomeView.h" @@ -10,7 +11,7 @@ // fwd: -class GeneratorSetupDlg; +class GeneratorSetup; @@ -21,8 +22,6 @@ class MainWindow : { Q_OBJECT - BiomeView * m_BiomeView; - public: MainWindow(QWidget * parent = nullptr); ~MainWindow(); @@ -54,8 +53,17 @@ protected: /** Path to the vanilla folder. */ QString m_MinecraftPath; - /** The dialog for setting up the generator. */ - std::unique_ptr m_GeneratorSetupDlg; + /** The pane for setting up the generator, available when visualising a generator. */ + GeneratorSetup * m_GeneratorSetup; + + /** The main biome display widget. */ + BiomeView * m_BiomeView; + + /** The layout for the window. */ + QHBoxLayout * m_MainLayout; + + /** The separator line between biome view and generator setup. */ + QWidget * m_LineSeparator; /** Initializes the m_MinecraftPath based on the proper MC path */ @@ -73,6 +81,12 @@ protected: /** Returns the name of the vanilla world in the specified path. Reads the level.dat file for the name. Returns an empty string on failure. */ QString getWorldName(const AString & a_Path); + + /** Opens the generator setup pane, if not already open, and loads the specified INI file to it. */ + void openGeneratorSetup(const AString & a_IniFileName); + + /** Closes and destroys the generator setup pane, if there is one. */ + void closeGeneratorSetup(); }; diff --git a/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro b/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro index 7171562bb..2ed1be719 100644 --- a/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro +++ b/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro @@ -47,7 +47,7 @@ SOURCES += main.cpp\ ../../lib/zlib/trees.c \ ../../lib/zlib/uncompr.c \ ../../lib/zlib/zutil.c \ - GeneratorSetupDlg.cpp + GeneratorSetup.cpp HEADERS += MainWindow.h \ Globals.h \ @@ -80,7 +80,7 @@ HEADERS += MainWindow.h \ ../../lib/zlib/zconf.h \ ../../lib/zlib/zlib.h \ ../../lib/zlib/zutil.h \ - GeneratorSetupDlg.h + GeneratorSetup.h INCLUDEPATH += $$_PRO_FILE_PWD_ \ $$_PRO_FILE_PWD_/../../src \ -- cgit v1.2.3 From 583532e1b927e1b9af9782e35c7f2d089e997254 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 22 Sep 2014 18:33:18 +0200 Subject: QtBiomeVisualiser: generator source is read from generator setup ini. --- Tools/QtBiomeVisualiser/ChunkSource.cpp | 12 ++++-------- Tools/QtBiomeVisualiser/ChunkSource.h | 7 ++++--- Tools/QtBiomeVisualiser/MainWindow.cpp | 10 +++++----- 3 files changed, 13 insertions(+), 16 deletions(-) (limited to 'Tools/QtBiomeVisualiser') diff --git a/Tools/QtBiomeVisualiser/ChunkSource.cpp b/Tools/QtBiomeVisualiser/ChunkSource.cpp index 54da2afe5..d8cecbaa4 100644 --- a/Tools/QtBiomeVisualiser/ChunkSource.cpp +++ b/Tools/QtBiomeVisualiser/ChunkSource.cpp @@ -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)); } diff --git a/Tools/QtBiomeVisualiser/ChunkSource.h b/Tools/QtBiomeVisualiser/ChunkSource.h index a5612da01..05e8ac5de 100644 --- a/Tools/QtBiomeVisualiser/ChunkSource.h +++ b/Tools/QtBiomeVisualiser/ChunkSource.h @@ -12,6 +12,7 @@ class cBiomeGen; typedef std::shared_ptr cBiomeGenPtr; class cIniFile; +typedef std::shared_ptr 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 m_BiomeGen; diff --git a/Tools/QtBiomeVisualiser/MainWindow.cpp b/Tools/QtBiomeVisualiser/MainWindow.cpp index f9915901d..c55d85082 100644 --- a/Tools/QtBiomeVisualiser/MainWindow.cpp +++ b/Tools/QtBiomeVisualiser/MainWindow.cpp @@ -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(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(new BioGenSource(worldIni))); + m_BiomeView->setChunkSource(std::shared_ptr(new BioGenSource(m_GeneratorSetup->getIniFile()))); m_BiomeView->redraw(); } -- cgit v1.2.3 From 83588fb0aad5c8597df783792c946c27327f1a40 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 22 Sep 2014 21:51:59 +0200 Subject: QtBiomeVisualiser: Implemented live-update for the generator setup. --- Tools/QtBiomeVisualiser/ChunkSource.cpp | 2 +- Tools/QtBiomeVisualiser/GeneratorSetup.cpp | 44 +++++++++++++++++++++------ Tools/QtBiomeVisualiser/GeneratorSetup.h | 7 +++++ Tools/QtBiomeVisualiser/MainWindow.cpp | 9 ++++-- Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro | 4 +-- 5 files changed, 49 insertions(+), 17 deletions(-) (limited to 'Tools/QtBiomeVisualiser') diff --git a/Tools/QtBiomeVisualiser/ChunkSource.cpp b/Tools/QtBiomeVisualiser/ChunkSource.cpp index d8cecbaa4..f7174b624 100644 --- a/Tools/QtBiomeVisualiser/ChunkSource.cpp +++ b/Tools/QtBiomeVisualiser/ChunkSource.cpp @@ -171,7 +171,7 @@ void BioGenSource::getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChu void BioGenSource::reload() { - int seed = m_IniFile->GetValueSetI("Seed", "Seed", 0); + int seed = m_IniFile->GetValueSetI("Generator", "Seed", 0); bool unused = false; QMutexLocker lock(&m_Mtx); m_BiomeGen.reset(cBiomeGen::CreateBiomeGen(*m_IniFile, seed, unused)); diff --git a/Tools/QtBiomeVisualiser/GeneratorSetup.cpp b/Tools/QtBiomeVisualiser/GeneratorSetup.cpp index d512d2b90..239965409 100644 --- a/Tools/QtBiomeVisualiser/GeneratorSetup.cpp +++ b/Tools/QtBiomeVisualiser/GeneratorSetup.cpp @@ -27,22 +27,27 @@ GeneratorSetup::GeneratorSetup(const AString & a_IniFileName, QWidget * a_Parent super(a_Parent), m_IniFile(new cIniFile()) { - // The generator name is in a separate form layout at the top, always present: + // The seed and generator name is in a separate form layout at the top, always present: + m_eSeed = new QLineEdit(); + m_eSeed->setValidator(new QIntValidator()); + m_eSeed->setText("0"); + m_eSeed->setProperty("INI.ItemName", QVariant("Seed")); m_cbGenerator = new QComboBox(); m_cbGenerator->setMinimumWidth(120); for (size_t i = 0; i < ARRAYCOUNT(s_GeneratorNames); i++) { m_cbGenerator->addItem(s_GeneratorNames[i]); } - QFormLayout * nameLayout = new QFormLayout(); - nameLayout->addRow(new QLabel(tr("Generator")), m_cbGenerator); + QFormLayout * baseLayout = new QFormLayout(); + baseLayout->addRow(new QLabel(tr("Seed")), m_eSeed); + baseLayout->addRow(new QLabel(tr("Generator")), m_cbGenerator); // The rest of the controls are in a dynamically created form layout: m_FormLayout = new QFormLayout(); // The main layout joins these two vertically: m_MainLayout = new QVBoxLayout(); - m_MainLayout->addLayout(nameLayout); + m_MainLayout->addLayout(baseLayout); m_MainLayout->addLayout(m_FormLayout); m_MainLayout->addStretch(); setLayout(m_MainLayout); @@ -51,18 +56,20 @@ GeneratorSetup::GeneratorSetup(const AString & a_IniFileName, QWidget * a_Parent if (!a_IniFileName.empty() && m_IniFile->ReadFile(a_IniFileName)) { m_cbGenerator->setCurrentText(QString::fromStdString(m_IniFile->GetValue("Generator", "BiomeGen"))); + m_eSeed->setText(QString::number(m_IniFile->GetValueI("Generator", "Seed"))); } else { m_IniFile->SetValue("Generator", "Generator", "Composable"); m_IniFile->SetValue("Generator", "BiomeGen", m_cbGenerator->currentText().toStdString()); bool dummy; - delete cBiomeGen::CreateBiomeGen(*m_IniFile, m_Seed, dummy); + delete cBiomeGen::CreateBiomeGen(*m_IniFile, 0, dummy); } updateFromIni(); - // Connect the combo change even only after the data has been loaded: - connect(m_cbGenerator, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(generatorChanged(QString))); + // Connect the change events only after the data has been loaded: + connect(m_cbGenerator, SIGNAL(currentIndexChanged(QString)), this, SLOT(generatorChanged(QString))); + connect(m_eSeed, SIGNAL(textChanged(QString)), this, SLOT(editChanged(QString))); } @@ -92,6 +99,20 @@ void GeneratorSetup::generatorChanged(const QString & a_NewName) // Read all values from the INI file and put them into the form layout: updateFromIni(); + + // Notify of the changes: + emit generatorUpdated(); +} + + + + + +void GeneratorSetup::editChanged(const QString & a_NewValue) +{ + QString itemName = sender()->property("INI.ItemName").toString(); + m_IniFile->SetValue("Generator", itemName.toStdString(), a_NewValue.toStdString()); + emit generatorUpdated(); } @@ -111,12 +132,16 @@ void GeneratorSetup::updateFromIni() for (int i = 0; i < numItems; i++) { AString itemName = m_IniFile->GetValueName(keyID, i); - AString itemValue = m_IniFile->GetValue(keyID, i); if ((itemName == "Generator") || (itemName == "BiomeGen")) { // These special cases are not to be added continue; } + AString itemValue = m_IniFile->GetValue(keyID, i); + + QLineEdit * edit = new QLineEdit(); + edit->setText(QString::fromStdString(itemValue)); + edit->setProperty("INI.ItemName", QVariant(QString::fromStdString(itemName))); // Remove the generator name prefix from the item name, for clarity purposes: if (NoCaseCompare(itemName.substr(0, generatorNameLen), generatorName) == 0) @@ -124,8 +149,7 @@ void GeneratorSetup::updateFromIni() itemName.erase(0, generatorNameLen); } - QLineEdit * edit = new QLineEdit(); - edit->setText(QString::fromStdString(itemValue)); + connect(edit, SIGNAL(textChanged(QString)), this, SLOT(editChanged(QString))); m_FormLayout->addRow(new QLabel(QString::fromStdString(itemName)), edit); } // for i - INI values[] } diff --git a/Tools/QtBiomeVisualiser/GeneratorSetup.h b/Tools/QtBiomeVisualiser/GeneratorSetup.h index 0594e1998..e72d3abbc 100644 --- a/Tools/QtBiomeVisualiser/GeneratorSetup.h +++ b/Tools/QtBiomeVisualiser/GeneratorSetup.h @@ -32,14 +32,21 @@ public: cIniFilePtr getIniFile() { return m_IniFile; } signals: + /** Emitted when the generator parameters have changed. */ + void generatorUpdated(); public slots: /** Called when the user selects a different generator from the top combobox. Re-creates m_IniFile and updates the form layout. */ void generatorChanged(const QString & a_NewName); +protected slots: + /** Called when any of the edit widgets are changed. */ + void editChanged(const QString & a_NewValue); + protected: QComboBox * m_cbGenerator; + QLineEdit * m_eSeed; QVBoxLayout * m_MainLayout; QFormLayout * m_FormLayout; diff --git a/Tools/QtBiomeVisualiser/MainWindow.cpp b/Tools/QtBiomeVisualiser/MainWindow.cpp index c55d85082..a2cfa7794 100644 --- a/Tools/QtBiomeVisualiser/MainWindow.cpp +++ b/Tools/QtBiomeVisualiser/MainWindow.cpp @@ -27,7 +27,7 @@ MainWindow::MainWindow(QWidget * parent) : m_BiomeView = new BiomeView(); m_MainLayout = new QHBoxLayout(); - m_MainLayout->addWidget(m_BiomeView); + m_MainLayout->addWidget(m_BiomeView, 1); m_MainLayout->setMenuBar(menuBar()); m_MainLayout->setMargin(0); QWidget * central = new QWidget(); @@ -57,7 +57,8 @@ void MainWindow::newGenerator() openGeneratorSetup(""); // Set the chunk source: - m_BiomeView->setChunkSource(std::shared_ptr(new BioGenSource(m_GeneratorSetup->getIniFile()))); + cIniFilePtr iniFile = m_GeneratorSetup->getIniFile(); + m_BiomeView->setChunkSource(std::shared_ptr(new BioGenSource(iniFile))); m_BiomeView->redraw(); } @@ -260,7 +261,6 @@ QString MainWindow::getWorldName(const AString & a_Path) return QString(); } AString name = nbt.GetName(1); - OutputDebugStringA(name.c_str()); int levelNameTag = nbt.FindTagByPath(nbt.GetRoot(), "Data\\LevelName"); if ((levelNameTag <= 0) || (nbt.GetType(levelNameTag) != TAG_String)) { @@ -286,6 +286,9 @@ void MainWindow::openGeneratorSetup(const AString & a_IniFileName) m_LineSeparator->setStyleSheet(QString("background-color: #c0c0c0;")); m_MainLayout->addWidget(m_LineSeparator); m_MainLayout->addWidget(m_GeneratorSetup); + + // Connect the signals from the setup pane: + connect(m_GeneratorSetup, SIGNAL(generatorUpdated()), m_BiomeView, SLOT(reload())); } diff --git a/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro b/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro index 2ed1be719..4275f73eb 100644 --- a/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro +++ b/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro @@ -89,8 +89,6 @@ INCLUDEPATH += $$_PRO_FILE_PWD_ \ CONFIG += C++11 -OTHER_FILES += \ - ../../lib/zlib/example.c.txt \ - ../../lib/zlib/minigzip.c.txt +OTHER_FILES += -- cgit v1.2.3 From de163f013416dc6a55f04eba5b23a7f8a9002c74 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 23 Sep 2014 12:39:09 +0200 Subject: QtBiomeVisualiser: Fixed confusion about Globals.h. --- Tools/QtBiomeVisualiser/ChunkSource.cpp | 6 +++--- Tools/QtBiomeVisualiser/GeneratorSetup.cpp | 2 +- Tools/QtBiomeVisualiser/Globals.h | 24 ++++++++++++------------ Tools/QtBiomeVisualiser/MainWindow.cpp | 6 +++--- Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro | 4 ++-- 5 files changed, 21 insertions(+), 21 deletions(-) (limited to 'Tools/QtBiomeVisualiser') diff --git a/Tools/QtBiomeVisualiser/ChunkSource.cpp b/Tools/QtBiomeVisualiser/ChunkSource.cpp index f7174b624..28d184615 100644 --- a/Tools/QtBiomeVisualiser/ChunkSource.cpp +++ b/Tools/QtBiomeVisualiser/ChunkSource.cpp @@ -1,10 +1,10 @@ #include "Globals.h" #include "ChunkSource.h" #include -#include "Generating/BioGen.h" +#include "src/Generating/BioGen.h" #include "inifile/iniFile.h" -#include "StringCompression.h" -#include "WorldStorage/FastNBT.h" +#include "src/StringCompression.h" +#include "src/WorldStorage/FastNBT.h" diff --git a/Tools/QtBiomeVisualiser/GeneratorSetup.cpp b/Tools/QtBiomeVisualiser/GeneratorSetup.cpp index 239965409..f5412404c 100644 --- a/Tools/QtBiomeVisualiser/GeneratorSetup.cpp +++ b/Tools/QtBiomeVisualiser/GeneratorSetup.cpp @@ -2,7 +2,7 @@ #include "GeneratorSetup.h" #include #include -#include "Generating/BioGen.h" +#include "src/Generating/BioGen.h" #include "inifile/iniFile.h" diff --git a/Tools/QtBiomeVisualiser/Globals.h b/Tools/QtBiomeVisualiser/Globals.h index d3c7f0675..8d2e913b7 100644 --- a/Tools/QtBiomeVisualiser/Globals.h +++ b/Tools/QtBiomeVisualiser/Globals.h @@ -238,14 +238,14 @@ template class SizeChecker; #ifndef TEST_GLOBALS // Common headers (part 1, without macros): - #include "StringUtils.h" - #include "OSSupport/Sleep.h" - #include "OSSupport/CriticalSection.h" - #include "OSSupport/Semaphore.h" - #include "OSSupport/Event.h" - #include "OSSupport/Thread.h" - #include "OSSupport/File.h" - #include "Logger.h" + #include "src/StringUtils.h" + #include "src/OSSupport/Sleep.h" + #include "src/OSSupport/CriticalSection.h" + #include "src/OSSupport/Semaphore.h" + #include "src/OSSupport/Event.h" + #include "src/OSSupport/Thread.h" + #include "src/OSSupport/File.h" + #include "src/Logger.h" #else // Logging functions void inline LOGERROR(const char* a_Format, ...) FORMATSTRING(1, 2); @@ -375,10 +375,10 @@ T Clamp(T a_Value, T a_Min, T a_Max) // Common headers (part 2, with macros): -#include "ChunkDef.h" -#include "BiomeDef.h" -#include "BlockID.h" -#include "BlockInfo.h" +#include "src/ChunkDef.h" +#include "src/BiomeDef.h" +#include "src/BlockID.h" +#include "src/BlockInfo.h" diff --git a/Tools/QtBiomeVisualiser/MainWindow.cpp b/Tools/QtBiomeVisualiser/MainWindow.cpp index a2cfa7794..eb45690c1 100644 --- a/Tools/QtBiomeVisualiser/MainWindow.cpp +++ b/Tools/QtBiomeVisualiser/MainWindow.cpp @@ -9,9 +9,9 @@ #include #include "inifile/iniFile.h" #include "ChunkSource.h" -#include "Generating/BioGen.h" -#include "StringCompression.h" -#include "WorldStorage/FastNBT.h" +#include "src/Generating/BioGen.h" +#include "src/StringCompression.h" +#include "src/WorldStorage/FastNBT.h" #include "GeneratorSetup.h" diff --git a/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro b/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro index 4275f73eb..d6630bd34 100644 --- a/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro +++ b/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro @@ -83,8 +83,8 @@ HEADERS += MainWindow.h \ GeneratorSetup.h INCLUDEPATH += $$_PRO_FILE_PWD_ \ - $$_PRO_FILE_PWD_/../../src \ - $$_PRO_FILE_PWD_/../../lib + $$_PRO_FILE_PWD_/../../lib \ + $$_PRO_FILE_PWD_/../../ CONFIG += C++11 -- cgit v1.2.3 From 34b83656b3dc0da7deb69851f6b8239e492d2862 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 24 Sep 2014 11:21:59 +0200 Subject: QtBiomeVisualiser: Fixed MSVC path-crossing. MSVC would occasionally compile the wrong CPP file - the same name, but wrong path. --- Tools/QtBiomeVisualiser/BiomeView.cpp | 2 +- Tools/QtBiomeVisualiser/Chunk.cpp | 36 ------------------------ Tools/QtBiomeVisualiser/Chunk.h | 40 --------------------------- Tools/QtBiomeVisualiser/ChunkSource.cpp | 2 +- Tools/QtBiomeVisualiser/ChunkSource.h | 2 +- Tools/QtBiomeVisualiser/QtBiomeVisualiser.cpp | 20 ++++++++++++++ Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro | 16 +++++++---- Tools/QtBiomeVisualiser/QtChunk.cpp | 35 +++++++++++++++++++++++ Tools/QtBiomeVisualiser/QtChunk.h | 40 +++++++++++++++++++++++++++ Tools/QtBiomeVisualiser/main.cpp | 20 -------------- 10 files changed, 109 insertions(+), 104 deletions(-) delete mode 100644 Tools/QtBiomeVisualiser/Chunk.cpp delete mode 100644 Tools/QtBiomeVisualiser/Chunk.h create mode 100644 Tools/QtBiomeVisualiser/QtBiomeVisualiser.cpp create mode 100644 Tools/QtBiomeVisualiser/QtChunk.cpp create mode 100644 Tools/QtBiomeVisualiser/QtChunk.h delete mode 100644 Tools/QtBiomeVisualiser/main.cpp (limited to 'Tools/QtBiomeVisualiser') diff --git a/Tools/QtBiomeVisualiser/BiomeView.cpp b/Tools/QtBiomeVisualiser/BiomeView.cpp index bbaccb369..ce5a870cd 100644 --- a/Tools/QtBiomeVisualiser/BiomeView.cpp +++ b/Tools/QtBiomeVisualiser/BiomeView.cpp @@ -1,6 +1,6 @@ #include "Globals.h" #include "BiomeView.h" -#include "Chunk.h" +#include "QtChunk.h" #include #include diff --git a/Tools/QtBiomeVisualiser/Chunk.cpp b/Tools/QtBiomeVisualiser/Chunk.cpp deleted file mode 100644 index d3419af9c..000000000 --- a/Tools/QtBiomeVisualiser/Chunk.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "Globals.h" -#include "Globals.h" -#include "Chunk.h" - - - - - -Chunk::Chunk() : - m_IsValid(false) -{ -} - - - - - -const uchar * Chunk::getImage(void) const -{ - ASSERT(m_IsValid); - return m_Image; -} - - - - - -void Chunk::setImage(const Image & a_Image) -{ - memcpy(m_Image, a_Image, sizeof(a_Image)); - m_IsValid = true; -} - - - - diff --git a/Tools/QtBiomeVisualiser/Chunk.h b/Tools/QtBiomeVisualiser/Chunk.h deleted file mode 100644 index 03e7bd1b3..000000000 --- a/Tools/QtBiomeVisualiser/Chunk.h +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -#include - - - - - -class Chunk -{ -public: - /** The type used for storing image data for a chunk. */ - typedef uchar Image[16 * 16 * 4]; - - - Chunk(void); - - /** Returns true iff the chunk data is valid - loaded or generated. */ - bool isValid(void) const { return m_IsValid; } - - /** Returns the image of the chunk's biomes. Assumes that the chunk is valid. */ - const uchar * getImage(void) const; - - /** Sets the image data for this chunk. */ - void setImage(const Image & a_Image); - -protected: - /** Flag that specifies if the chunk data is valid - loaded or generated. */ - bool m_IsValid; - - /** Cached rendered image of this chunk's biomes. Updated in render(). */ - Image m_Image; -}; - -typedef std::shared_ptr ChunkPtr; - - - - - diff --git a/Tools/QtBiomeVisualiser/ChunkSource.cpp b/Tools/QtBiomeVisualiser/ChunkSource.cpp index 28d184615..bebf89a0a 100644 --- a/Tools/QtBiomeVisualiser/ChunkSource.cpp +++ b/Tools/QtBiomeVisualiser/ChunkSource.cpp @@ -2,9 +2,9 @@ #include "ChunkSource.h" #include #include "src/Generating/BioGen.h" -#include "inifile/iniFile.h" #include "src/StringCompression.h" #include "src/WorldStorage/FastNBT.h" +#include "inifile/iniFile.h" diff --git a/Tools/QtBiomeVisualiser/ChunkSource.h b/Tools/QtBiomeVisualiser/ChunkSource.h index 05e8ac5de..7bd1865ff 100644 --- a/Tools/QtBiomeVisualiser/ChunkSource.h +++ b/Tools/QtBiomeVisualiser/ChunkSource.h @@ -2,7 +2,7 @@ #include "Globals.h" #include #include -#include "Chunk.h" +#include "QtChunk.h" diff --git a/Tools/QtBiomeVisualiser/QtBiomeVisualiser.cpp b/Tools/QtBiomeVisualiser/QtBiomeVisualiser.cpp new file mode 100644 index 000000000..f41cdcfb2 --- /dev/null +++ b/Tools/QtBiomeVisualiser/QtBiomeVisualiser.cpp @@ -0,0 +1,20 @@ +#include "Globals.h" +#include "MainWindow.h" +#include + + + + + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + + return a.exec(); +} + + + + diff --git a/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro b/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro index d6630bd34..9e5d1303c 100644 --- a/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro +++ b/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro @@ -12,7 +12,7 @@ TARGET = QtBiomeVisualiser TEMPLATE = app -SOURCES += main.cpp\ +SOURCES +=\ MainWindow.cpp \ BiomeView.cpp \ ../../src/Generating/BioGen.cpp \ @@ -27,7 +27,6 @@ SOURCES += main.cpp\ ../../src/OSSupport/IsThread.cpp \ ../../src/BiomeDef.cpp \ ChunkCache.cpp \ - Chunk.cpp \ ChunkSource.cpp \ ChunkLoader.cpp \ ../../src/StringCompression.cpp \ @@ -47,7 +46,9 @@ SOURCES += main.cpp\ ../../lib/zlib/trees.c \ ../../lib/zlib/uncompr.c \ ../../lib/zlib/zutil.c \ - GeneratorSetup.cpp + GeneratorSetup.cpp \ + QtBiomeVisualiser.cpp \ + QtChunk.cpp HEADERS += MainWindow.h \ Globals.h \ @@ -64,7 +65,6 @@ HEADERS += MainWindow.h \ ../../src/OSSupport/IsThread.h \ ../../src/BiomeDef.h \ ChunkCache.h \ - Chunk.h \ ChunkSource.h \ ChunkLoader.h \ ../../src/StringCompression.h \ @@ -80,13 +80,19 @@ HEADERS += MainWindow.h \ ../../lib/zlib/zconf.h \ ../../lib/zlib/zlib.h \ ../../lib/zlib/zutil.h \ - GeneratorSetup.h + GeneratorSetup.h \ + QtChunk.h INCLUDEPATH += $$_PRO_FILE_PWD_ \ $$_PRO_FILE_PWD_/../../lib \ + $$_PRO_FILE_PWD_/../../lib/jsoncpp/include \ + $$_PRO_FILE_PWD_/../../lib/polarssl/include \ + $$_PRO_FILE_PWD_/../../lib/sqlite \ + $$_PRO_FILE_PWD_/../../lib/SQLiteCpp/include \ $$_PRO_FILE_PWD_/../../ + CONFIG += C++11 OTHER_FILES += diff --git a/Tools/QtBiomeVisualiser/QtChunk.cpp b/Tools/QtBiomeVisualiser/QtChunk.cpp new file mode 100644 index 000000000..80109b2f8 --- /dev/null +++ b/Tools/QtBiomeVisualiser/QtChunk.cpp @@ -0,0 +1,35 @@ +#include "Globals.h" +#include "QtChunk.h" + + + + + +Chunk::Chunk() : + m_IsValid(false) +{ +} + + + + + +const uchar * Chunk::getImage(void) const +{ + ASSERT(m_IsValid); + return m_Image; +} + + + + + +void Chunk::setImage(const Image & a_Image) +{ + memcpy(m_Image, a_Image, sizeof(a_Image)); + m_IsValid = true; +} + + + + diff --git a/Tools/QtBiomeVisualiser/QtChunk.h b/Tools/QtBiomeVisualiser/QtChunk.h new file mode 100644 index 000000000..03e7bd1b3 --- /dev/null +++ b/Tools/QtBiomeVisualiser/QtChunk.h @@ -0,0 +1,40 @@ +#pragma once + +#include + + + + + +class Chunk +{ +public: + /** The type used for storing image data for a chunk. */ + typedef uchar Image[16 * 16 * 4]; + + + Chunk(void); + + /** Returns true iff the chunk data is valid - loaded or generated. */ + bool isValid(void) const { return m_IsValid; } + + /** Returns the image of the chunk's biomes. Assumes that the chunk is valid. */ + const uchar * getImage(void) const; + + /** Sets the image data for this chunk. */ + void setImage(const Image & a_Image); + +protected: + /** Flag that specifies if the chunk data is valid - loaded or generated. */ + bool m_IsValid; + + /** Cached rendered image of this chunk's biomes. Updated in render(). */ + Image m_Image; +}; + +typedef std::shared_ptr ChunkPtr; + + + + + diff --git a/Tools/QtBiomeVisualiser/main.cpp b/Tools/QtBiomeVisualiser/main.cpp deleted file mode 100644 index f41cdcfb2..000000000 --- a/Tools/QtBiomeVisualiser/main.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "Globals.h" -#include "MainWindow.h" -#include - - - - - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - MainWindow w; - w.show(); - - return a.exec(); -} - - - - -- cgit v1.2.3