refactoring noggitApplication

This commit is contained in:
Alister
2021-12-16 19:27:13 +00:00
parent 660181b9e1
commit f7efd6db5a
15 changed files with 122 additions and 147 deletions

View File

@@ -26,7 +26,7 @@ DBCFile::DBCFile(const std::string& _filename)
void DBCFile::open()
{
BlizzardArchive::ClientFile f (filename, NOGGIT_APP->clientData());
BlizzardArchive::ClientFile f (filename, Noggit::Application::Noggit::instance()->clientData());
if (f.isEof())
{

View File

@@ -90,7 +90,7 @@ void LiquidTextureManager::upload()
unsigned n_frames = 30;
for (int j = 0; j < N_FRAMES; ++j)
{
if (!NOGGIT_APP->clientData()->exists(filename + std::to_string((j + 1)) + ".blp"))
if (!Noggit::Application::Noggit::instance()->clientData()->exists(filename + std::to_string((j + 1)) + ".blp"))
{
n_frames = j;
break;

View File

@@ -106,7 +106,7 @@ void MapTile::finishLoading()
if (finished)
return;
BlizzardArchive::ClientFile theFile(_file_key, NOGGIT_APP->clientData());
BlizzardArchive::ClientFile theFile(_file_key, Noggit::Application::Noggit::instance()->clientData());
Log << "Opening tile " << index.x << ", " << index.z << " (\"" << _file_key.stringRepr() << "\") from " << (theFile.isExternal() ? "disk" : "MPQ") << "." << std::endl;
@@ -1290,7 +1290,7 @@ void MapTile::saveTile(World* world)
{
BlizzardArchive::ClientFile f(_file_key.filepath(), NOGGIT_APP->clientData());
BlizzardArchive::ClientFile f(_file_key.filepath(), Noggit::Application::Noggit::instance()->clientData());
f.setBuffer(lADTFile.data);
f.save();
}

View File

@@ -31,7 +31,7 @@ Model::Model(const std::string& filename, Noggit::NoggitRenderContext context)
void Model::finishLoading()
{
BlizzardArchive::ClientFile f(_file_key.filepath(), NOGGIT_APP->clientData());
BlizzardArchive::ClientFile f(_file_key.filepath(), Noggit::Application::Noggit::instance()->clientData());
if (f.isEof() || !f.getSize())
{
@@ -284,7 +284,7 @@ void Model::initCommon(const BlizzardArchive::ClientFile& f)
// indices - allocate space, too
std::string lodname = _file_key.filepath().substr(0, _file_key.filepath().length() - 3);
lodname.append("00.skin");
BlizzardArchive::ClientFile g(lodname, NOGGIT_APP->clientData());
BlizzardArchive::ClientFile g(lodname, Noggit::Application::Noggit::instance()->clientData());
if (g.isEof()) {
LogError << "loading skinfile " << lodname << std::endl;
g.close();
@@ -1101,10 +1101,10 @@ void Model::initAnimated(const BlizzardArchive::ClientFile& f)
std::string lodname = _file_key.filepath().substr(0, _file_key.filepath().length() - 3);
std::stringstream tempname;
tempname << lodname << anim.animID << "-" << anim.subAnimID << ".anim";
if (NOGGIT_APP->clientData()->exists(tempname.str()))
if (Noggit::Application::Noggit::instance()->clientData()->exists(tempname.str()))
{
animation_files.push_back(std::make_unique<BlizzardArchive::ClientFile>(tempname.str(),
NOGGIT_APP->clientData()));
Noggit::Application::Noggit::instance()->clientData()));
}
}
}

View File

@@ -396,7 +396,7 @@ blp_texture::blp_texture(BlizzardArchive::Listfile::FileKey const& file_key, Nog
void blp_texture::finishLoading()
{
bool exists = NOGGIT_APP->clientData()->exists( _file_key.filepath());
bool exists = Noggit::Application::Noggit::instance()->clientData()->exists( _file_key.filepath());
if (!exists)
{
LogError << "file not found: '" << _file_key.stringRepr() << "'" << std::endl;
@@ -410,7 +410,7 @@ void blp_texture::finishLoading()
_is_tileset = true;
spec_filename = _file_key.filepath().substr(0, _file_key.filepath().find_last_of(".")) + "_s.blp";
has_specular = NOGGIT_APP->clientData()->exists(spec_filename);
has_specular = Noggit::Application::Noggit::instance()->clientData()->exists(spec_filename);
if (has_specular)
{
@@ -420,7 +420,7 @@ void blp_texture::finishLoading()
BlizzardArchive::ClientFile f(
exists ? (has_specular ? spec_filename : _file_key.filepath()) : "textures/shanecube.blp"
, NOGGIT_APP->clientData());
, Noggit::Application::Noggit::instance()->clientData());
if (f.isEof())
{
finished = true;

View File

@@ -28,7 +28,7 @@ WMO::WMO(BlizzardArchive::Listfile::FileKey const& file_key, Noggit::NoggitRende
void WMO::finishLoading ()
{
BlizzardArchive::ClientFile f(_file_key.filepath(), NOGGIT_APP->clientData());
BlizzardArchive::ClientFile f(_file_key.filepath(), Noggit::Application::Noggit::instance()->clientData());
if (f.isEof()) {
LogError << "Error loading WMO \"" << _file_key.stringRepr() << "\"." << std::endl;
return;
@@ -180,7 +180,7 @@ void WMO::finishLoading ()
if (path.length())
{
if (NOGGIT_APP->clientData()->exists(path))
if (Noggit::Application::Noggit::instance()->clientData()->exists(path))
{
skybox = scoped_model_reference(path, _context);
}
@@ -922,7 +922,7 @@ void WMOGroup::load()
std::string fname = wmo->file_key().filepath();
fname.insert (fname.find (".wmo"), curNum.str ());
BlizzardArchive::ClientFile f(fname, NOGGIT_APP->clientData());
BlizzardArchive::ClientFile f(fname, Noggit::Application::Noggit::instance()->clientData());
if (f.isEof()) {
LogError << "Error loading WMO \"" << fname << "\"." << std::endl;
return;

View File

@@ -70,13 +70,13 @@ bool World::IsEditableWorld(int pMapId)
std::stringstream ssfilename;
ssfilename << "World\\Maps\\" << lMapName << "\\" << lMapName << ".wdt";
if (!NOGGIT_APP->clientData()->exists(ssfilename.str()))
if (!Noggit::Application::Noggit::instance()->clientData()->exists(ssfilename.str()))
{
Log << "World " << pMapId << ": " << lMapName << " has no WDT file!" << std::endl;
return false;
}
BlizzardArchive::ClientFile mf(ssfilename.str(), NOGGIT_APP->clientData());
BlizzardArchive::ClientFile mf(ssfilename.str(), Noggit::Application::Noggit::instance()->clientData());
//sometimes, wdts don't open, so ignore them...
if (mf.isEof())

View File

@@ -39,24 +39,6 @@ namespace Noggit::application
LogError << "std::terminate: " << reason << std::endl;
}
struct application_with_exception_printer_on_notify : QApplication
{
using QApplication::QApplication;
virtual bool notify(QObject* object, QEvent* event) override
{
try
{
return QApplication::notify(object, event);
}
catch (...)
{
std::terminate();
}
}
};
}
int main(int argc, char *argv[])
@@ -71,8 +53,9 @@ int main(int argc, char *argv[])
qapp.setApplicationName ("Noggit");
qapp.setOrganizationName ("Noggit");
auto noggit = Noggit::Application::Noggit::instance(argc, argv);
noggit->start();
auto noggit = Noggit::Application::Noggit::instance();
noggit->Initalize(argc, argv);
noggit->Start();
return qapp.exec();
}

View File

@@ -5,103 +5,105 @@
namespace Noggit::Application
{
Noggit::Noggit(int argc, char* argv[])
Noggit::Noggit()
: fullscreen(false)
, doAntiAliasing(true)
{
InitLogging();
assert(argc >= 1); (void)argc;
Noggit::initPath(argv);
Log << "Noggit Studio - " << STRPRODUCTVER << std::endl;
QSettings settings;
doAntiAliasing = settings.value("antialiasing", false).toBool();
fullscreen = settings.value("fullscreen", false).toBool();
srand(::time(nullptr));
QDir path(settings.value("project/game_path").toString());
wowpath = path.absolutePath().toStdString();
Log << "Game path: " << wowpath << std::endl;
project_path = settings.value("project/path", path.absolutePath()).toString().toStdString();
settings.setValue("project/path", QString::fromStdString(project_path));
Log << "Project path: " << project_path << std::endl;
settings.setValue("project/game_path", path.absolutePath());
settings.setValue("project/path", QString::fromStdString(project_path));
if (!QGLFormat::hasOpenGL())
{
throw std::runtime_error("Your system does not support OpenGL. Sorry, this application can't run without it.");
}
QSurfaceFormat format;
format.setRenderableType(QSurfaceFormat::OpenGL);
format.setVersion(4, 1);
format.setProfile(QSurfaceFormat::CoreProfile);
//format.setOption(QSurfaceFormat::ResetNotification, true);
format.setSwapBehavior(QSurfaceFormat::TripleBuffer);
format.setSwapInterval(0);
format.setRenderableType(QSurfaceFormat::OpenGL);
format.setDepthBufferSize(16);
format.setSamples(0);
if (doAntiAliasing)
{
format.setSamples(4);
}
QSurfaceFormat::setDefaultFormat(format);
QOpenGLContext context;
context.create();
QOffscreenSurface surface;
surface.create();
context.makeCurrent(&surface);
OpenGL::context::scoped_setter const _(::gl, &context);
LogDebug << "GL: Version: " << gl.getString(GL_VERSION) << std::endl;
LogDebug << "GL: Vendor: " << gl.getString(GL_VENDOR) << std::endl;
LogDebug << "GL: Renderer: " << gl.getString(GL_RENDERER) << std::endl;
}
void Noggit::initPath(char* argv[])
void Noggit::Initalize(int argc, char* argv[])
{
try
{
std::filesystem::path startupPath(argv[0]);
startupPath.remove_filename();
InitLogging();
assert(argc >= 1);
(void)argc;
if (startupPath.is_relative())
{
std::filesystem::current_path(std::filesystem::current_path() / startupPath);
}
else
{
std::filesystem::current_path(startupPath);
}
}
catch (const std::filesystem::filesystem_error& ex)
{
LogError << ex.what() << std::endl;
}
try
{
std::filesystem::path startupPath(argv[0]);
startupPath.remove_filename();
if (startupPath.is_relative())
{
std::filesystem::current_path(std::filesystem::current_path() / startupPath);
}
else
{
std::filesystem::current_path(startupPath);
}
}
catch (const std::filesystem::filesystem_error& ex)
{
LogError << ex.what() << std::endl;
}
Log << "Noggit Studio - " << STRPRODUCTVER << std::endl;
QSettings settings;
doAntiAliasing = settings.value("antialiasing", false).toBool();
fullscreen = settings.value("fullscreen", false).toBool();
srand(::time(nullptr));
QDir path(settings.value("project/game_path").toString());
wowpath = path.absolutePath().toStdString();
Log << "Game path: " << wowpath << std::endl;
project_path = settings.value("project/path", path.absolutePath()).toString().toStdString();
settings.setValue("project/path", QString::fromStdString(project_path));
Log << "Project path: " << project_path << std::endl;
settings.setValue("project/game_path", path.absolutePath());
settings.setValue("project/path", QString::fromStdString(project_path));
if (!QGLFormat::hasOpenGL())
{
throw std::runtime_error(
"Your system does not support OpenGL. Sorry, this application can't run without it.");
}
QSurfaceFormat format;
format.setRenderableType(QSurfaceFormat::OpenGL);
format.setVersion(4, 1);
format.setProfile(QSurfaceFormat::CoreProfile);
//format.setOption(QSurfaceFormat::ResetNotification, true);
format.setSwapBehavior(QSurfaceFormat::TripleBuffer);
format.setSwapInterval(0);
format.setRenderableType(QSurfaceFormat::OpenGL);
format.setDepthBufferSize(16);
format.setSamples(0);
if (doAntiAliasing)
{
format.setSamples(4);
}
QSurfaceFormat::setDefaultFormat(format);
QOpenGLContext context;
context.create();
QOffscreenSurface surface;
surface.create();
context.makeCurrent(&surface);
OpenGL::context::scoped_setter const _(::gl, &context);
LogDebug << "GL: Version: " << gl.getString(GL_VERSION) << std::endl;
LogDebug << "GL: Vendor: " << gl.getString(GL_VENDOR) << std::endl;
LogDebug << "GL: Renderer: " << gl.getString(GL_RENDERER) << std::endl;
}
void Noggit::start()
void Noggit::Start()
{
_client_data = std::make_unique<BlizzardArchive::ClientData>(wowpath.string(), BlizzardArchive::ClientVersion::WOTLK, BlizzardArchive::Locale::AUTO, project_path);
OpenDBs();
main_window = std::make_unique<::Noggit::Ui::main_window>();
main_window = std::make_unique<Ui::main_window>();
if (fullscreen)
{

View File

@@ -8,11 +8,6 @@
#include <ClientData.hpp>
#include <noggit/ui/main_window.hpp>
#include <noggit/application/NoggitApplication.hpp>
#include <noggit/DBC.h>
#include <noggit/Log.h>
#include <noggit/ui/main_window.hpp>
#include <opengl/context.hpp>
#include <util/exception_to_string.hpp>
#include <memory>
#include <string>
#include <string_view>
@@ -24,7 +19,6 @@
#include <QtWidgets/QFileDialog>
#include <QtWidgets/QMessageBox>
#include <QSplashScreen>
#include <codecvt>
#include <string>
#include <revision.h>
@@ -33,22 +27,20 @@ namespace Noggit::Application {
class Noggit
{
public:
static Noggit* instance(int argc, char* argv[])
static Noggit* instance()
{
static Noggit inst{ argc, argv };
static Noggit inst{};
return &inst;
}
BlizzardArchive::ClientData* clientData() { return _client_data.get(); };
void start();
void Start();
void Initalize(int argc, char* argv[]);
private:
Noggit(int argc, char* argv[]);
Noggit();
static void initPath(char* argv[]);
std::unique_ptr<::Noggit::Ui::main_window> main_window;
std::unique_ptr<Ui::main_window> main_window;
std::unique_ptr<BlizzardArchive::ClientData> _client_data;
std::filesystem::path wowpath;
@@ -60,6 +52,4 @@ namespace Noggit::Application {
}
#define NOGGIT_APP Noggit::Application::Noggit::instance(0, nullptr)
#endif //NOGGIT_APPLICATION_HPP

View File

@@ -96,13 +96,13 @@ map_horizon::map_horizon(const std::string& basename, const MapIndex * const ind
filename << "World\\Maps\\" << basename << "\\" << basename << ".wdl";
_filename = filename.str();
if (!NOGGIT_APP->clientData()->exists(_filename))
if (!Application::Noggit::instance()->clientData()->exists(_filename))
{
LogError << "file \"World\\Maps\\" << basename << "\\" << basename << ".wdl\" does not exist." << std::endl;
return;
}
BlizzardArchive::ClientFile wdl_file (_filename, NOGGIT_APP->clientData());
BlizzardArchive::ClientFile wdl_file (_filename, Application::Noggit::instance()->clientData());
uint32_t fourcc;
uint32_t size;

View File

@@ -67,7 +67,7 @@ MapIndex::MapIndex (const std::string &pBasename, int map_id, World* world,
std::stringstream filename;
filename << "World\\Maps\\" << basename << "\\" << basename << ".wdt";
BlizzardArchive::ClientFile theFile(filename.str(), NOGGIT_APP->clientData());
BlizzardArchive::ClientFile theFile(filename.str(), Noggit::Application::Noggit::instance()->clientData());
uint32_t fourcc;
uint32_t size;
@@ -252,7 +252,7 @@ void MapIndex::save()
// }
}
BlizzardArchive::ClientFile f(filename.str(), NOGGIT_APP->clientData());
BlizzardArchive::ClientFile f(filename.str(), Noggit::Application::Noggit::instance()->clientData());
f.setBuffer(wdtFile.data);
f.save();
f.close();
@@ -362,7 +362,7 @@ MapTile* MapIndex::loadTile(const tile_index& tile, bool reloading)
std::stringstream filename;
filename << "World\\Maps\\" << basename << "\\" << basename << "_" << tile.x << "_" << tile.z << ".adt";
if (!NOGGIT_APP->clientData()->exists(filename.str()))
if (!Noggit::Application::Noggit::instance()->clientData()->exists(filename.str()))
{
LogError << "The requested tile \"" << filename.str() << "\" does not exist! Oo" << std::endl;
return nullptr;
@@ -603,7 +603,7 @@ uint32_t MapIndex::getHighestGUIDFromFile(const std::string& pFilename) const
{
uint32_t highGUID = 0;
BlizzardArchive::ClientFile theFile(pFilename, NOGGIT_APP->clientData());
BlizzardArchive::ClientFile theFile(pFilename, Noggit::Application::Noggit::instance()->clientData());
if (theFile.isEof())
{
return highGUID;
@@ -718,7 +718,7 @@ uid_fix_status MapIndex::fixUIDs (World* world, bool cancel_on_model_loading_err
std::stringstream filename;
filename << "World\\Maps\\" << basename << "\\" << basename << "_" << x << "_" << z << ".adt";
BlizzardArchive::ClientFile file(filename.str(), NOGGIT_APP->clientData());
BlizzardArchive::ClientFile file(filename.str(), Noggit::Application::Noggit::instance()->clientData());
if (file.isEof())
{
@@ -1049,14 +1049,14 @@ void MapIndex::loadMaxUID()
void MapIndex::loadMinimapMD5translate()
{
if (!NOGGIT_APP->clientData()->exists("textures/minimap/md5translate.trs"))
if (!Noggit::Application::Noggit::instance()->clientData()->exists("textures/minimap/md5translate.trs"))
{
LogError << "md5translate.trs was not found. "
"Noggit will generate a new one in the project directory on minimap save." << std::endl;
return;
}
BlizzardArchive::ClientFile md5trs_file("textures/minimap/md5translate.trs", NOGGIT_APP->clientData());
BlizzardArchive::ClientFile md5trs_file("textures/minimap/md5translate.trs", Noggit::Application::Noggit::instance()->clientData());
size_t size = md5trs_file.getSize();
void* buffer_raw = std::malloc(size);

View File

@@ -622,7 +622,7 @@ namespace Noggit
void object_editor::copy(std::string const& filename)
{
if (!NOGGIT_APP->clientData()->exists(filename))
if (!Noggit::Application::Noggit::instance()->clientData()->exists(filename))
{
QMessageBox::warning
( nullptr

View File

@@ -66,7 +66,7 @@ namespace Noggit
std::vector<std::string> tilesets;
std::unordered_set<std::string> tilesets_with_specular_variant;
for (auto const& entry_pair : NOGGIT_APP->clientData()->listfile()->pathToFileDataIDMap())
for (auto const& entry_pair : Application::Noggit::instance()->clientData()->listfile()->pathToFileDataIDMap())
{
std::string const& filepath = entry_pair.first;

View File

@@ -292,7 +292,7 @@ void AssetBrowserWidget::recurseDirectory(Model::TreeManager& tree_mgr, const QS
void AssetBrowserWidget::updateModelData()
{
Model::TreeManager tree_mgr = Model::TreeManager(_model);
for (auto& key_pair : NOGGIT_APP->clientData()->listfile()->pathToFileDataIDMap())
for (auto& key_pair : Noggit::Application::Noggit::instance()->clientData()->listfile()->pathToFileDataIDMap())
{
std::string const& filename = key_pair.first;