slowly refactoring code

having a look through the code to figure out the best structure for projects
This commit is contained in:
Alister
2021-12-11 23:25:22 +00:00
parent cb32b9a8eb
commit ac56fd9e47
22 changed files with 333 additions and 289 deletions

View File

@@ -193,9 +193,15 @@ INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/${EXTERNAL_SOURCE_DIR}/blizzard-databas
INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/${EXTERNAL_SOURCE_DIR}/blizzard-archive-library/include")
INCLUDE_DIRECTORIES(${Qt5Gui_PRIVATE_INCLUDE_DIRS})
#Load noggit source files
collect_files(noggit_root_sources src/noggit FALSE "*.cpp" "")
collect_files(noggit_application_sources src/noggit/application FALSE "*.cpp" "")
collect_files(noggit_data_sources src/noggit/data FALSE "*.cpp" "")
collect_files(noggit_simulation_sources src/noggit/simulation FALSE "*.cpp" "")
collect_files(noggit_project_sources src/noggit/project FALSE "*.cpp" "")
collect_files(noggit_ui_sources src/noggit/ui FALSE "*.cpp" "")
collect_files(noggit_scripting_sources src/noggit/scripting TRUE "*.cpp" "")
collect_files(math_sources src/math FALSE "*.cpp" "")
collect_files(opengl_sources src/opengl FALSE "*.cpp" "")
@@ -215,8 +221,13 @@ collect_files(archive_sources src/external/blizzard-archive-library/src FALSE "*
SET(util_sources src/util/exception_to_string.cpp)
collect_files(noggit_root_headers src/noggit FALSE "*.h;*.hpp;*.inl" "")
collect_files(noggit_application_headers src/noggit/application FALSE "*.h;*.hpp" "")
collect_files(noggit_data_sources src/noggit/data FALSE "*.h;*.hpp" "")
collect_files(noggit_simulation_sources src/noggit/simulation FALSE "*.h;*.hpp" "")
collect_files(noggit_project_sources src/noggit/project FALSE "*.h;*.hpp" "")
collect_files(noggit_ui_headers src/noggit/ui FALSE "*.h;*.hpp" "")
collect_files(noggit_scripting_headers src/noggit/scripting TRUE "*.h;*.hpp" "")
collect_files(math_headers src/math FALSE "*.h;*.hpp" "")
collect_files(opengl_headers src/opengl FALSE "*.h;*.hpp" "")
collect_files(shaders src/glsl FALSE "*.glsl" "")
@@ -245,6 +256,14 @@ collect_files(ui_files src TRUE "*.ui" "")
qt5_wrap_ui(compiled_ui_files ${ui_files})
assign_source_group(
${noggit_application_sources}
${noggit_application_headers}
${noggit_simulation_sources}
${noggit_simulation_headers}
${noggit_data_sources}
${noggit_data_headers}
${noggit_project_sources}
${noggit_project_headers}
${noggit_root_sources}
${noggit_root_headers}
${noggit_ui_sources}
@@ -280,6 +299,14 @@ assign_source_group(
ADD_EXECUTABLE(noggit
WIN32
MACOSX_BUNDLE
${noggit_application_sources}
${noggit_application_headers}
${noggit_simulation_sources}
${noggit_simulation_headers}
${noggit_data_sources}
${noggit_data_headers}
${noggit_project_sources}
${noggit_project_headers}
${noggit_root_sources}
${noggit_ui_sources}
${noggit_scripting_sources}

View File

@@ -2,7 +2,7 @@
#include <noggit/DBCFile.h>
#include <noggit/Log.h>
#include <noggit/application.hpp>
#include <noggit/application/NoggitApplication.hpp>
#include <ClientFile.hpp>
#include <string>

View File

@@ -4,7 +4,7 @@
#include <opengl/context.inl>
#include <noggit/DBC.h>
#include <noggit/application.hpp>
#include <noggit/application/NoggitApplication.hpp>
#include <boost/format.hpp>
#include <glm/vec2.hpp>

View File

@@ -12,7 +12,7 @@
#include <noggit/alphamap.hpp>
#include <noggit/texture_set.hpp>
#include <noggit/ui/TexturingGUI.h>
#include <noggit/application.hpp>
#include <noggit/application/NoggitApplication.hpp>
#include <ClientFile.hpp>
#include <opengl/scoped.hpp>
#include <opengl/shader.hpp>

View File

@@ -10,7 +10,7 @@
#include <opengl/scoped.hpp>
#include <opengl/shader.hpp>
#include <external/tracy/Tracy.hpp>
#include <noggit/application.hpp>
#include <noggit/application/NoggitApplication.hpp>
#include <algorithm>
#include <cassert>

View File

@@ -1,7 +1,7 @@
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
#include <noggit/TextureManager.h>
#include <noggit/Log.h> // LogDebug
#include <noggit/application.hpp>
#include <noggit/application/NoggitApplication.hpp>
#include <ClientFile.hpp>
#include <QtCore/QString>

View File

@@ -8,7 +8,7 @@
#include <noggit/WMO.h>
#include <noggit/World.h>
#include <opengl/primitives.hpp>
#include <noggit/application.hpp>
#include <noggit/application/NoggitApplication.hpp>
#include <opengl/scoped.hpp>
#include <boost/algorithm/string.hpp>

View File

@@ -20,7 +20,7 @@
#include <noggit/tool_enums.hpp>
#include <noggit/ui/ObjectEditor.h>
#include <noggit/ui/TexturingGUI.h>
#include <noggit/application.hpp>
#include <noggit/application/NoggitApplication.hpp>
#include <opengl/scoped.hpp>
#include <opengl/shader.hpp>

View File

@@ -1,234 +0,0 @@
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
#include <noggit/application.hpp>
#include <noggit/AsyncLoader.h>
#include <noggit/DBC.h>
#include <noggit/Log.h>
#include <noggit/errorHandling.h>
#include <noggit/ui/main_window.hpp>
#include <opengl/context.hpp>
#include <util/exception_to_string.hpp>
#include <external/framelesshelper/framelesswindowsmanager.h>
#include <cstdlib>
#include <ctime>
#include <iterator>
#include <list>
#include <memory>
#include <string>
#include <string_view>
#include <vector>
#include <QtCore/QSettings>
#include <QtCore/QTimer>
#include <QtGui/QOffscreenSurface>
#include <QtOpenGL/QGLFormat>
#include <QtCore/QDir>
#include <QtWidgets/QApplication>
#include <QtWidgets/QFileDialog>
#include <QtWidgets/QLabel>
#include <QtWidgets/QMessageBox>
#include <QSplashScreen>
#include <QStyleFactory>
#include <codecvt>
#include <locale>
#include <string>
#include <type_traits>
#include "revision.h"
using namespace BlizzardArchive;
void Noggit::initPath(char *argv[])
{
try
{
boost::filesystem::path startupPath(argv[0]);
startupPath.remove_filename();
if (startupPath.is_relative())
{
boost::filesystem::current_path(boost::filesystem::current_path() / startupPath);
}
else
{
boost::filesystem::current_path(startupPath);
}
}
catch (const boost::filesystem::filesystem_error& ex)
{
LogError << ex.what() << std::endl;
}
}
Noggit::Noggit(int argc, char *argv[])
: 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::start()
{
_client_data = std::make_unique<ClientData>(wowpath.string(),
ClientVersion::WOTLK, Locale::AUTO, project_path);
OpenDBs();
main_window = std::make_unique<noggit::ui::main_window>();
if (fullscreen)
{
main_window->showFullScreen();
}
else
{
main_window->showMaximized();
}
}
namespace
{
void noggit_terminate_handler()
{
std::string const reason
{util::exception_to_string (std::current_exception())};
if (qApp)
{
QMessageBox::critical ( nullptr
, "std::terminate"
, QString::fromStdString (reason)
, QMessageBox::Close
, QMessageBox::Close
);
}
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();
}
}
};
}
/* I wonder if you would correctly guess the reason of this being here... */
template < typename Char >
requires (std::is_same_v<Char, wchar_t> || std::is_same_v<Char, char>)
auto convert
(
Char const* src,
std::string* dst
)
-> char const*
{
if constexpr(std::is_same_v<Char, char>)
{
*dst = src;
return dst->c_str();
}
std::string mbc(MB_CUR_MAX, '\0');
dst->clear();
while(*src)
{
std::wctomb(mbc.data(), *src++);
dst->append(mbc.c_str());
}
return dst->c_str();
}
int main(int argc, char *argv[])
{
noggit::RegisterErrorHandlers();
std::set_terminate (noggit_terminate_handler);
QApplication::setStyle(QStyleFactory::create("Fusion"));
//QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication qapp (argc, argv);
qapp.setApplicationName ("Noggit");
qapp.setOrganizationName ("Noggit");
auto noggit = Noggit::instance(argc, argv);
noggit->start();
return qapp.exec();
}

View File

@@ -1,42 +0,0 @@
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
#ifndef NOGGIT_APPLICATION_HPP
#define NOGGIT_APPLICATION_HPP
#include <memory>
#include <boost/filesystem.hpp>
#include <ClientData.hpp>
#include <noggit/ui/main_window.hpp>
class Noggit
{
public:
static Noggit* instance(int argc, char *argv[])
{
static Noggit inst{argc, argv};
return &inst;
}
BlizzardArchive::ClientData* clientData() { return _client_data.get(); };
void start();
private:
Noggit (int argc, char *argv[]);
static void initPath(char *argv[]);
std::unique_ptr<noggit::ui::main_window> main_window;
std::unique_ptr<BlizzardArchive::ClientData> _client_data;
boost::filesystem::path wowpath;
std::string project_path;
bool fullscreen;
bool doAntiAliasing;
};
#define NOGGIT_APP Noggit::instance(0, nullptr)
#endif //NOGGIT_APPLICATION_HPP

View File

@@ -0,0 +1,77 @@
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
#include <noggit/application/NoggitApplication.hpp>
#include <noggit/Log.h>
#include <noggit/errorHandling.h>
#include <noggit/ui/main_window.hpp>
#include <opengl/context.hpp>
#include <util/exception_to_string.hpp>
#include <external/framelesshelper/framelesswindowsmanager.h>
#include <string>
#include <string_view>
#include <QtCore/QSettings>
#include <QtCore/QDir>
#include <QtWidgets/QApplication>
#include <QtWidgets/QFileDialog>
#include <QtWidgets/QMessageBox>
#include <QSplashScreen>
#include <QStyleFactory>
#include <codecvt>
#include <string>
namespace
{
void noggit_terminate_handler()
{
std::string const reason{ util::exception_to_string(std::current_exception()) };
if (qApp)
{
QMessageBox::critical(nullptr
, "std::terminate"
, QString::fromStdString(reason)
, QMessageBox::Close
, QMessageBox::Close
);
}
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[])
{
noggit::RegisterErrorHandlers();
std::set_terminate(noggit_terminate_handler);
QApplication::setStyle(QStyleFactory::create("Fusion"));
//QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication qapp (argc, argv);
qapp.setApplicationName ("Noggit");
qapp.setOrganizationName ("Noggit");
auto noggit = noggit::application::Noggit::instance(argc, argv);
noggit->start();
return qapp.exec();
}

View File

@@ -0,0 +1,146 @@
#include <noggit/application/NoggitApplication.hpp>
namespace noggit {
namespace application {
Noggit::Noggit(int argc, char* argv[]) : 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[])
{
try
{
boost::filesystem::path startupPath(argv[0]);
startupPath.remove_filename();
if (startupPath.is_relative())
{
boost::filesystem::current_path(boost::filesystem::current_path() / startupPath);
}
else
{
boost::filesystem::current_path(startupPath);
}
}
catch (const boost::filesystem::filesystem_error& ex)
{
LogError << ex.what() << std::endl;
}
}
void Noggit::start()
{
//Load Selected Project information
//-Client Path, Client Version
//Check If Project Contains DBClientFiles
//IF not Extract DBClientFiles to project path
//
_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>();
if (fullscreen)
{
main_window->showFullScreen();
}
else
{
main_window->showMaximized();
}
}
}
}
/* I wonder if you would correctly guess the reason of this being here... */
template < typename Char >
requires (std::is_same_v<Char, wchar_t> || std::is_same_v<Char, char>)
auto convert
(
Char const* src,
std::string* dst
)
-> char const*
{
if constexpr (std::is_same_v<Char, char>)
{
*dst = src;
return dst->c_str();
}
std::string mbc(MB_CUR_MAX, '\0');
dst->clear();
while (*src)
{
std::wctomb(mbc.data(), *src++);
dst->append(mbc.c_str());
}
return dst->c_str();
}

View File

@@ -0,0 +1,67 @@
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
#ifndef NOGGIT_APPLICATION_HPP
#define NOGGIT_APPLICATION_HPP
#include <memory>
#include <boost/filesystem.hpp>
#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>
#include <QtCore/QSettings>
#include <QtGui/QOffscreenSurface>
#include <QtOpenGL/QGLFormat>
#include <QtCore/QDir>
#include <QtWidgets/QApplication>
#include <QtWidgets/QFileDialog>
#include <QtWidgets/QMessageBox>
#include <QSplashScreen>
#include <codecvt>
#include <string>
#include "revision.h"
namespace noggit {
namespace application {
class Noggit
{
public:
static Noggit* instance(int argc, char* argv[])
{
static Noggit inst{ argc, argv };
return &inst;
}
BlizzardArchive::ClientData* clientData() { return _client_data.get(); };
void start();
private:
Noggit(int argc, char* argv[]);
static void initPath(char* argv[]);
std::unique_ptr<noggit::ui::main_window> main_window;
std::unique_ptr<BlizzardArchive::ClientData> _client_data;
boost::filesystem::path wowpath;
std::string project_path;
bool fullscreen;
bool doAntiAliasing;
};
#define NOGGIT_APP noggit::application::Noggit::instance(0, nullptr)
}}
#endif //NOGGIT_APPLICATION_HPP

1
src/noggit/data/_Data.h Normal file
View File

@@ -0,0 +1 @@
//Folder to contain all of the data related files like WMO/ADT etc

View File

@@ -3,7 +3,7 @@
#include "map_horizon.h"
#include <noggit/Log.h>
#include <noggit/application.hpp>
#include <noggit/application/NoggitApplication.hpp>
#include <noggit/map_index.hpp>
#include <noggit/World.h>
#include <opengl/context.hpp>

View File

@@ -14,7 +14,7 @@
#endif
#include <noggit/map_index.hpp>
#include <noggit/uid_storage.hpp>
#include <noggit/application.hpp>
#include <noggit/application/NoggitApplication.hpp>
#include <ClientFile.hpp>
#include <QtCore/QSettings>

View File

@@ -0,0 +1 @@
//Folder to contain all of the project related files

View File

@@ -0,0 +1 @@
//Folder to contain all of the simulation related files

View File

@@ -1,7 +1,7 @@
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
#include <noggit/MapView.h>
#include <noggit/application.hpp>
#include <noggit/application/NoggitApplication.hpp>
#include <noggit/Misc.h>
#include <noggit/ModelInstance.h>
#include <noggit/WMOInstance.h> // WMOInstance

View File

@@ -14,7 +14,7 @@
#include <noggit/TextureManager.h> // TextureManager, Texture
#include <noggit/ui/TextureList.hpp>
#include <noggit/application.hpp>
#include <noggit/application/NoggitApplication.hpp>
#include <unordered_set>

View File

@@ -5,7 +5,7 @@
#include <noggit/ui/FramelessWindow.hpp>
#include <noggit/ui/font_noggit.hpp>
#include <noggit/MapView.h>
#include <noggit/application.hpp>
#include <noggit/application/NoggitApplication.hpp>
#include <QStandardItemModel>
#include <QItemSelectionModel>

View File

@@ -4,7 +4,7 @@
#include <noggit/Log.h>
#include <noggit/World.h>
#include <noggit/wmo_liquid.hpp>
#include <noggit/application.hpp>
#include <noggit/application/NoggitApplication.hpp>
#include <opengl/context.hpp>
#include <opengl/context.inl>
#include <opengl/shader.hpp>