From cb905f5b8219f736a8a386ccd22ea8ce163706e2 Mon Sep 17 00:00:00 2001 From: Akiko Date: Thu, 10 Oct 2013 07:06:25 +0200 Subject: [PATCH] - kicked the Irrlicht idea (this is not going to work like I thought) - removed Irrlicht and ZLIB requirements from the makefiles (both handled by Qt5) - updated all missing language tags (English/German) - added DatWindow skeleton (will be a dat file viewer and later an editor) - added ObjectWindow skeleton (will be a 3d object viewer/editor for meshes, BSP and highfields) - added a small tool for BSP file viewing (just a "can I do it?" study) - added engine subpart, here all the mesh, highfield and BSP stuff will go - fixed some minor bugs (wrong connections, etc) - some code cleanups --- CMakeLists.txt | 14 +-- cmake_distclean.sh | 14 +-- cmake_modules/FindIrrlicht.cmake | 42 ------- editor/CMakeLists.txt | 24 ++-- editor/DatWindow.cxx | 64 +++++++++++ editor/DatWindow.hxx | 41 +++++++ editor/DatWindow.ui | 52 +++++++++ editor/MainWindow.cxx | 74 ++++++++++++- editor/MainWindow.hxx | 6 + editor/MainWindow.ui | 12 ++ editor/ObjectWindow.cxx | 71 ++++++++++++ editor/ObjectWindow.hxx | 41 +++++++ editor/ObjectWindow.ui | 87 +++++++++++++++ editor/i18n_english.ts | 141 +++++++++++++++--------- editor/i18n_french.ts | 138 ++++++++++++++++------- editor/i18n_german.ts | 141 +++++++++++++++--------- engine/CMakeLists.txt | 17 +++ engine/GLWidget.cxx | 87 +++++++++++++++ engine/GLWidget.hxx | 32 ++++++ tools/CMakeLists.txt | 21 ++-- tools/bsp_viewer.cxx | 231 +++++++++++++++++++++++++++++++++++++++ 21 files changed, 1122 insertions(+), 228 deletions(-) delete mode 100644 cmake_modules/FindIrrlicht.cmake create mode 100644 editor/DatWindow.cxx create mode 100644 editor/DatWindow.hxx create mode 100644 editor/DatWindow.ui create mode 100644 editor/ObjectWindow.cxx create mode 100644 editor/ObjectWindow.hxx create mode 100644 editor/ObjectWindow.ui create mode 100644 engine/CMakeLists.txt create mode 100644 engine/GLWidget.cxx create mode 100644 engine/GLWidget.hxx create mode 100644 tools/bsp_viewer.cxx diff --git a/CMakeLists.txt b/CMakeLists.txt index 772944d..56e198e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,14 +1,12 @@ cmake_minimum_required (VERSION 2.8.8) project (QTinns) -set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake_modules/") # needed packages -find_package (Qt5Core) -find_package (Qt5Widgets) -find_package (Qt5Network) -find_package (Qt5LinguistTools) -find_package (ZLIB REQUIRED) -find_package (Irrlicht REQUIRED) +find_package (Qt5Core REQUIRED) +find_package (Qt5Widgets REQUIRED) +find_package (Qt5Network REQUIRED) +find_package (Qt5OpenGL REQUIRED) +find_package (Qt5LinguistTools REQUIRED) # includes and outputs set (CMAKE_INCLUDE_CURRENT_DIR on) @@ -23,8 +21,8 @@ set (CMAKE_C_FLAGS "-std=c++11 -W -Wall -Wextra -Os") #add_subdirectory (analyzer) add_subdirectory (editor) +add_subdirectory (engine) add_subdirectory (filesystem) -#add_subdirectory (renderer) #add_subdirectory (server) add_subdirectory (tests) add_subdirectory (tools) diff --git a/cmake_distclean.sh b/cmake_distclean.sh index e67620c..94d3d59 100755 --- a/cmake_distclean.sh +++ b/cmake_distclean.sh @@ -21,6 +21,13 @@ rm -rf editor/cmake_install.cmake rm -rf editor/*.qrc.depends rm -rf editor/moc_*.* +rm -rf engine/CMakeCache.txt +rm -rf engine/CMakeFiles/ +rm -rf engine/Makefile +rm -rf engine/cmake_install.cmake +rm -rf engine/*.qrc.depends +rm -rf engine/moc_*.* + rm -rf filesystem/CMakeCache.txt rm -rf filesystem/CMakeFiles/ rm -rf filesystem/Makefile @@ -28,13 +35,6 @@ rm -rf filesystem/cmake_install.cmake rm -rf filesystem/*.qrc.depends rm -rf filesystem/moc_*.* -rm -rf renderer/CMakeCache.txt -rm -rf renderer/CMakeFiles/ -rm -rf renderer/Makefile -rm -rf renderer/cmake_install.cmake -rm -rf renderer/*.qrc.depends -rm -rf renderer/moc_*.* - rm -rf server/CMakeCache.txt rm -rf server/CMakeFiles/ rm -rf server/Makefile diff --git a/cmake_modules/FindIrrlicht.cmake b/cmake_modules/FindIrrlicht.cmake deleted file mode 100644 index d1cafb8..0000000 --- a/cmake_modules/FindIrrlicht.cmake +++ /dev/null @@ -1,42 +0,0 @@ -set (IRRLICHT_FOUND TRUE) - -find_path ( - IRRLICHT_INCLUDE_DIRS - NAMES - irrlicht.h - HINTS - ENV - IRRLICHT_ROOT - PATHS - /usr - /usr/local - PATH_SUFFIXES - include - irrlicht -) - -find_library ( - IRRLICHT_LIBRARY - Irrlicht - HINTS - ENV - IRRLICHT_ROOT - PATHS - /usr/lib - /usr/local/lib -) - -if (IRRLICHT_INCLUDE_DIRS AND EXISTS "${IRRLICHT_INCLUDE_DIRS}/IrrCompileConfig.h") - file (STRINGS "${IRRLICHT_INCLUDE_DIRS}/IrrCompileConfig.h" - verstr REGEX "^#define[ \t]+IRRLICHT_SDK_VERSION[ \t]+\".+\"" - ) - string (REGEX REPLACE "^#define[ \t]+IRRLICHT_SDK_VERSION[ \t]+\"([^\"]+)\".*" "\\1" - IRRLICHT_VERSION_STRING "${verstr}" - ) - unset (verstr) -endif () - -include (FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS (Irrlicht REQUIRED_VARS IRRLICHT_LIBRARY IRRLICHT_INCLUDE_DIRS VERSION_VAR IRRLICHT_VERSION_STRING) - -mark_as_advanced (IRRLICHT_INCLUDE_DIRS IRRLICHT_LIBRARIES) diff --git a/editor/CMakeLists.txt b/editor/CMakeLists.txt index fe3ac52..080a8c6 100644 --- a/editor/CMakeLists.txt +++ b/editor/CMakeLists.txt @@ -1,17 +1,19 @@ # Qt sources -set (E_SOURCES Main.cxx MainWindow.cxx ImageWindow.cxx TextWindow.cxx) -set (E_HEADERS MainWindow.hxx ImageWindow.hxx TextWindow.hxx) -set (E_UI_FILES MainWindow.ui ImageWindow.ui TextWindow.ui) -set (E_RES_FILES Resources.qrc) -set (E_TS_FILES i18n_english.ts i18n_french.ts i18n_german.ts) +set (ED_SOURCES Main.cxx MainWindow.cxx ImageWindow.cxx TextWindow.cxx DatWindow.cxx + ObjectWindow.cxx) +set (ED_HEADERS MainWindow.hxx ImageWindow.hxx TextWindow.hxx DatWindow.hxx ObjectWindow.hxx) +set (ED_UI_FILES MainWindow.ui ImageWindow.ui TextWindow.ui DatWindow.ui ObjectWindow.ui) +set (ED_RES_FILES Resources.qrc) +set (ED_TS_FILES i18n_english.ts i18n_french.ts i18n_german.ts) # wrappers -QT5_ADD_TRANSLATION (E_TS_SOURCES ${E_TS_FILES}) -QT5_WRAP_CPP (E_MOC_SOURCES ${E_HEADERS}) -QT5_WRAP_UI (E_UI_SOURCES ${E_UI_FILES}) -QT5_ADD_RESOURCES (E_RES_SOURCES ${E_RES_FILES}) +QT5_ADD_TRANSLATION (ED_TS_SOURCES ${ED_TS_FILES}) +QT5_WRAP_CPP (ED_MOC_SOURCES ${ED_HEADERS}) +QT5_WRAP_UI (ED_UI_SOURCES ${ED_UI_FILES}) +QT5_ADD_RESOURCES (ED_RES_SOURCES ${ED_RES_FILES}) # apps -add_executable (QTinNS_Editor ${E_SOURCES} ${E_MOC_SOURCES} ${E_UI_SOURCES} ${E_RES_SOURCES} ${E_TS_SOURCES}) +add_executable (QTinNS_Editor ${ED_SOURCES} ${ED_MOC_SOURCES} ${ED_UI_SOURCES} ${ED_RES_SOURCES} + ${ED_TS_SOURCES}) qt5_use_modules (QTinNS_Editor Core Widgets) -target_link_libraries (QTinNS_Editor Filesystem) +target_link_libraries (QTinNS_Editor Filesystem Engine) diff --git a/editor/DatWindow.cxx b/editor/DatWindow.cxx new file mode 100644 index 0000000..624c9f8 --- /dev/null +++ b/editor/DatWindow.cxx @@ -0,0 +1,64 @@ +#include "DatWindow.hxx" +#include "ui_DatWindow.h" + +// --- constructors and deconstructors --- + +DatWindow::DatWindow(QWidget *parent) +: QMainWindow(parent), _ui(new Ui::DatWindow), _num(0) +{ + _ui->setupUi(this); + + setupActions(); + setMode(Mode::Fresh); +} + +DatWindow::~DatWindow() +{ + delete _ui; +} + +// --- public slots --- + +void DatWindow::slotDatSave() +{ +} + +void DatWindow::slotDatDiscard() +{ +} + +void DatWindow::slotDatView(NCFile& entry, quint32 row) +{ +} + +// --- protected methods --- + +void DatWindow::changeEvent(QEvent *event) +{ + if (event->type() == QEvent::LanguageChange) + _ui->retranslateUi(this); + else + QMainWindow::changeEvent(event); +} + +void DatWindow::setMode(const Mode mode) +{ + switch (mode) + { + case Mode::Edited: + _ui->act_dat_save->setEnabled(true); + + break; + case Mode::Fresh: + default: + _ui->act_dat_save->setEnabled(false); + } +} + +void DatWindow::setupActions() +{ + connect(_ui->act_dat_save, SIGNAL(triggered()), + this, SLOT(slotDatSave())); + connect(_ui->act_dat_cancel, SIGNAL(triggered()), + this, SLOT(slotDatDiscard())); +} diff --git a/editor/DatWindow.hxx b/editor/DatWindow.hxx new file mode 100644 index 0000000..7a245dc --- /dev/null +++ b/editor/DatWindow.hxx @@ -0,0 +1,41 @@ +#pragma once + +#include +#include "filesystem/NCFile.hxx" + +namespace Ui +{ + class DatWindow; +} + +class DatWindow : public QMainWindow { + Q_OBJECT +signals: + void sigDatUpdate(NCFile& entry, quint32 row) const; + void sigDatIgnored() const; + +public: + enum class Mode : quint8 { + Fresh, + Edited + }; + + explicit DatWindow(QWidget *parent = 0); + virtual ~DatWindow(); + +public slots: + void slotDatSave(); + void slotDatDiscard(); + + void slotDatView(NCFile& entry, quint32 row); + +protected: + virtual void changeEvent(QEvent *event); + void setMode(const Mode mode = Mode::Fresh); + void setupActions(); + +private: + Ui::DatWindow *_ui; + NCFile _entry; + quint32 _num; +}; diff --git a/editor/DatWindow.ui b/editor/DatWindow.ui new file mode 100644 index 0000000..075d988 --- /dev/null +++ b/editor/DatWindow.ui @@ -0,0 +1,52 @@ + + + DatWindow + + + + 0 + 0 + 800 + 600 + + + + FRM-DAT + + + + + + + + + 0 + 0 + 800 + 22 + + + + + MM-DAT + + + + + + + + + + ME-DAT-SAVE + + + + + ME-DAT-CANCEL + + + + + + diff --git a/editor/MainWindow.cxx b/editor/MainWindow.cxx index df5aa50..a50fc06 100644 --- a/editor/MainWindow.cxx +++ b/editor/MainWindow.cxx @@ -13,6 +13,8 @@ #include "filesystem/NCFilesystem.hxx" #include "ImageWindow.hxx" #include "TextWindow.hxx" +#include "DatWindow.hxx" +#include "ObjectWindow.hxx" // --- internal typedefs --- @@ -33,8 +35,8 @@ const QString TableHeader("header size;position;compressed size;original size;na MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), _ui(new Ui::MainWindow), _translator(new QTranslator(this)), - _settings(new QSettings("LinuxAddicted", "QTinNS Editor", this)), _vfs(new NCFilesystem), - _img(new ImageWindow(this)), _txt(new TextWindow(this)), _def_status(new QLabel) + _settings(new QSettings("LinuxAddicted", "QTinNS Editor", this)), _vfs(new NCFilesystem), _img(new ImageWindow(this)), + _txt(new TextWindow(this)), _dat(new DatWindow(this)), _obj(new ObjectWindow(this)), _def_status(new QLabel) { _ui->setupUi(this); _ui->wid_table->setColumnCount(7); @@ -43,6 +45,8 @@ MainWindow::MainWindow(QWidget *parent) _ui->wid_stack->addWidget(_img); _ui->wid_stack->addWidget(_txt); + _ui->wid_stack->addWidget(_dat); + _ui->wid_stack->addWidget(_obj); _ui->wid_stack->setCurrentIndex(0); statusBar()->insertWidget(0, _def_status); @@ -77,15 +81,23 @@ MainWindow::~MainWindow() _settings->sync(); } - _img->setVisible(false); - _ui->wid_stack->removeWidget(_img); + statusBar()->removeWidget(_def_status); + + _obj->setVisible(false); + _ui->wid_stack->removeWidget(_obj); + + _dat->setVisible(false); + _ui->wid_stack->removeWidget(_dat); _txt->setVisible(false); _ui->wid_stack->removeWidget(_txt); - statusBar()->removeWidget(_def_status); + _img->setVisible(false); + _ui->wid_stack->removeWidget(_img); delete _def_status; + delete _obj; + delete _dat; delete _txt; delete _img; delete _vfs; @@ -231,6 +243,26 @@ void MainWindow::slotFileText() setMode(Mode::Blocked); } +void MainWindow::slotFileDat() +{ + QTW *table = _ui->wid_table; + NCFile entry = _vfs->fileGet(table->currentRow()); + + _dat->slotDatView(entry, table->currentRow()); + _ui->wid_stack->setCurrentWidget(_dat); + setMode(Mode::Blocked); +} + +void MainWindow::slotFileObject() +{ + QTW *table = _ui->wid_table; + NCFile entry = _vfs->fileGet(table->currentRow()); + + _obj->slotObjectView(entry, table->currentRow()); + _ui->wid_stack->setCurrentWidget(_obj); + setMode(Mode::Blocked); +} + void MainWindow::slotLangEnglish() { setLanguage(Language::English); @@ -313,6 +345,16 @@ void MainWindow::slotTableSelected() _ui->act_file_text->setEnabled(true); else _ui->act_file_image->setEnabled(false); + + if (text.contains(".dat", Qt::CaseInsensitive)) + _ui->act_file_dat->setEnabled(true); + else + _ui->act_file_dat->setEnabled(false); + + if (text.contains(".bsp", Qt::CaseInsensitive)) + _ui->act_file_object->setEnabled(true); + else + _ui->act_file_object->setEnabled(false); } void MainWindow::slotTableChange(qint32 row) @@ -708,6 +750,8 @@ void MainWindow::setMode(const Mode mode) _ui->act_file_conv_lin->setEnabled(false); _ui->act_file_image->setEnabled(false); _ui->act_file_text->setEnabled(false); + _ui->act_file_dat->setEnabled(false); + _ui->act_file_object->setEnabled(false); switch (mode) { @@ -799,6 +843,10 @@ void MainWindow::setupActions() this, SLOT(slotFileImage())); connect(_ui->act_file_text, SIGNAL(triggered()), this, SLOT(slotFileText())); + connect(_ui->act_file_dat, SIGNAL(triggered()), + this, SLOT(slotFileDat())); + connect(_ui->act_file_object, SIGNAL(triggered()), + this, SLOT(slotFileObject())); connect(_ui->act_lang_english, SIGNAL(triggered()), this, SLOT(slotLangEnglish())); @@ -844,10 +892,22 @@ void MainWindow::setupActions() // text viewer connections connect(_txt, SIGNAL(sigTextUpdate(NCFile&, quint32)), - this, SLOT(slotTableIgnored())); + this, SLOT(slotTableReplace(NCFile&, quint32))); connect(_txt, SIGNAL(sigTextIgnored()), this, SLOT(slotTableIgnored())); + // dat viewer connections + connect(_dat, SIGNAL(sigDatUpdate(NCFile&, quint32)), + this, SLOT(slotTableReplace(NCFile&, quint32))); + connect(_dat, SIGNAL(sigDatIgnored()), + this, SLOT(slotTableIgnored())); + + // object viewer connections + connect(_obj, SIGNAL(sigObjectUpdate(NCFile&, quint32)), + this, SLOT(slotTableReplace(NCFile&, quint32))); + connect(_obj, SIGNAL(sigObjectIgnored()), + this, SLOT(slotTableIgnored())); + // context menus for the QTableWidget ctx_sep1->setSeparator(true); ctx_sep2->setSeparator(true); @@ -868,4 +928,6 @@ void MainWindow::setupActions() table->addAction(ctx_sep4); table->addAction(_ui->act_file_image); table->addAction(_ui->act_file_text); + table->addAction(_ui->act_file_dat); + table->addAction(_ui->act_file_object); } diff --git a/editor/MainWindow.hxx b/editor/MainWindow.hxx index fae4d86..87ac81d 100644 --- a/editor/MainWindow.hxx +++ b/editor/MainWindow.hxx @@ -14,6 +14,8 @@ class NCFile; class NCFilesystem; class ImageWindow; class TextWindow; +class DatWindow; +class ObjectWindow; class MainWindow : public QMainWindow { Q_OBJECT @@ -56,6 +58,8 @@ public slots: void slotFileConvLin(); void slotFileImage(); void slotFileText(); + void slotFileDat(); + void slotFileObject(); void slotLangEnglish(); void slotLangFrench(); @@ -93,6 +97,8 @@ private: NCFilesystem *_vfs; ImageWindow *_img; TextWindow *_txt; + DatWindow *_dat; + ObjectWindow *_obj; QLabel *_def_status; QString _filename; }; diff --git a/editor/MainWindow.ui b/editor/MainWindow.ui index 4c86a90..2bd1d13 100644 --- a/editor/MainWindow.ui +++ b/editor/MainWindow.ui @@ -118,6 +118,8 @@ + + @@ -245,6 +247,16 @@ ME-FILE-TEXT + + + ME-FILE-DAT + + + + + ME-FILE-OBJECT + + diff --git a/editor/ObjectWindow.cxx b/editor/ObjectWindow.cxx new file mode 100644 index 0000000..7beec33 --- /dev/null +++ b/editor/ObjectWindow.cxx @@ -0,0 +1,71 @@ +#include "ObjectWindow.hxx" +#include "ui_ObjectWindow.h" + +// --- constructors and deconstructors --- + +ObjectWindow::ObjectWindow(QWidget *parent) +: QMainWindow(parent), _ui(new Ui::ObjectWindow), _num(0) +{ + _ui->setupUi(this); + + setupActions(); + setMode(Mode::Fresh); +} + +ObjectWindow::~ObjectWindow() +{ + delete _ui; +} + +// --- public slots --- + +void ObjectWindow::slotObjectSave() +{ +} + +void ObjectWindow::slotObjectDiscard() +{ + _entry = NCFile(); + _num = 0; + + emit sigObjectIgnored(); +} + +void ObjectWindow::slotObjectView(NCFile& entry, quint32 row) +{ + _entry = entry; + _num = row; +} + +// --- protected methods --- + +void ObjectWindow::changeEvent(QEvent *event) +{ + if (event->type() == QEvent::LanguageChange) + _ui->retranslateUi(this); + else + QMainWindow::changeEvent(event); +} + +void ObjectWindow::setMode(const Mode mode) +{ + switch (mode) + { + case Mode::Edited: + _ui->act_object_save->setEnabled(true); + + break; + + case Mode::Fresh: + default: + _ui->act_object_save->setEnabled(false); + } +} + +void ObjectWindow::setupActions() +{ + connect(_ui->act_object_save, SIGNAL(triggered()), + this, SLOT(slotObjectSave())); + connect(_ui->act_object_cancel, SIGNAL(triggered()), + this, SLOT(slotObjectDiscard())); +} diff --git a/editor/ObjectWindow.hxx b/editor/ObjectWindow.hxx new file mode 100644 index 0000000..aff7a7b --- /dev/null +++ b/editor/ObjectWindow.hxx @@ -0,0 +1,41 @@ +#pragma once + +#include +#include "filesystem/NCFile.hxx" + +namespace Ui +{ + class ObjectWindow; +} + +class ObjectWindow : public QMainWindow { + Q_OBJECT +signals: + void sigObjectUpdate(NCFile& entry, quint32 row) const; + void sigObjectIgnored(); + +public: + enum class Mode : quint8 { + Fresh, + Edited + }; + + explicit ObjectWindow(QWidget *parent = 0); + virtual ~ObjectWindow(); + +public slots: + void slotObjectSave(); + void slotObjectDiscard(); + + void slotObjectView(NCFile& entry, quint32 row); + +protected: + virtual void changeEvent(QEvent *event); + void setMode(const Mode mode = Mode::Fresh); + void setupActions(); + +private: + Ui::ObjectWindow *_ui; + NCFile _entry; + quint32 _num; +}; diff --git a/editor/ObjectWindow.ui b/editor/ObjectWindow.ui new file mode 100644 index 0000000..2a5bba1 --- /dev/null +++ b/editor/ObjectWindow.ui @@ -0,0 +1,87 @@ + + + ObjectWindow + + + + 0 + 0 + 800 + 600 + + + + FRM-OBJECT + + + + + + + + + + true + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;"> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> + + + + + + + + 0 + 0 + + + + + + + + + + 0 + 0 + 800 + 22 + + + + + MM-OBJECT + + + + + + + + + + ME-OBJECT-SAVE + + + + + ME-OBJECT-CANCEL + + + + + + GLWidget + QWidget +
engine/GLWidget.hxx
+ 1 +
+
+ + +
diff --git a/editor/i18n_english.ts b/editor/i18n_english.ts index 9cb1f64..a22b50c 100644 --- a/editor/i18n_english.ts +++ b/editor/i18n_english.ts @@ -1,12 +1,35 @@ + + DatWindow + + + FRM-DAT + QTinNS Editor - Dat Viewer + + + + MM-DAT + Dat + + + + ME-DAT-SAVE + Save dat changes + + + + ME-DAT-CANCEL + Discard dat changes + + ImageWindow FRM-IMAGE - QTinNS Editor Image Viewer + QTinNS Editor - Image Viewer @@ -72,220 +95,234 @@ File - + ME-APP-QUIT Quit - + ME-APP-NEW New virtual filesystem - + ME-APP-OPEN Open virtual filesystem ... - + ME-APP-SAVE Save virtual filesystem - + ME-APP-SAVEAS Save virtual filesystem as ... - + ME-ABOUT-APP About QTinNS Editor ... - + ME-ABOUT-QT About Qt framework ... - + ME-LANG-ENGLISH English - + ME-LANG-FRENCH French - + ME-LANG-GERMAN German - + ME-STYLE-DEFAULT System Default - + ME-STYLE-WINDOWS ME-STYLE-CDE Windows - + ME-STYLE-GTK ME-STYLE-CLEANLOOKS GTK+ - + ME-STYLE-FUSION ME-STYLE-PLASTIQUE Fusion - + ME-FILE-ADD Add file(s) ... - + ME-FILE-REPLACE Replace file ... - + ME-FILE-REMOVE Remove file ... - + ME-FILE-SAVE-PLAIN Save plain file as ... - + ME-FILE-SAVE-PAK Save PAK file as ... - + ME-FILE-SAVE-ZLIB Save ZLIB file as ... - + ME-FILE-CONV-WIN Convert UNIX path to Windows path - + ME-FILE-CONV-LIN Convert Windows path to UNIX path - + ME-FILE-IMAGE View image ... - + ME-FILE-TEXT View text ... - - + + ME-FILE-DAT + View dat ... + + + + ME-FILE-OBJECT + View 3D object ... + + + + DIA-OPEN-FILE Open files ... - - + + FLT-FILE-VFS DIA-SAVE-FILE Neocron VFS file (*.vfs *.pak) - + DIA-OPEN-VFS Open virtual filesystem ... - + DIA-SAVE-VFS Save virtual filesystem ... - - + + FLT-FILE-ANY File (*.*) - + DIA-SAVE-PLAIN Save file ... - + FLT-FILE-PLAIN File (*.*) - + DIA-SAVE-PAK Save PAK file ... - + FLT-FILE-PAK Neocron PAK file (*.pak) - + DIA-SAVE-ZLIB Save ZLIB file ... - + FLT-FILE-ZLIB ZLIB file (*.z) - + MSG-UPD-FILE Virtual filesystem - + MSG-UPD-WITH with - + MSG-UPD-ENTRIES entries - PictureWindow + ObjectWindow - FRM-IMAGE - QTinNS Editor Viewer + + FRM-OBJECT + QTinNS Editor - 3D Object Viewer - MM-IMAGE - Picture + + MM-OBJECT + 3D Object - ME-IMAGE-SAVE - Save changes + + ME-OBJECT-SAVE + Save 3D object changes - ME-IMAGE-CANCEL - Discard changes + + ME-OBJECT-CANCEL + Discard 3D object changes @@ -293,7 +330,7 @@ FRM-TEXT - QTinNS Editor Text Viewer + QTinNS Editor - Text Viewer diff --git a/editor/i18n_french.ts b/editor/i18n_french.ts index 487db01..cab46ff 100644 --- a/editor/i18n_french.ts +++ b/editor/i18n_french.ts @@ -1,6 +1,29 @@ + + DatWindow + + + FRM-DAT + + + + + MM-DAT + + + + + ME-DAT-SAVE + + + + + ME-DAT-CANCEL + + + ImageWindow @@ -72,203 +95,236 @@ - + ME-APP-QUIT - + ME-APP-NEW - + ME-APP-OPEN - + ME-APP-SAVE - + ME-APP-SAVEAS - + ME-ABOUT-APP - + ME-ABOUT-QT - + ME-LANG-ENGLISH - + ME-LANG-FRENCH - + ME-LANG-GERMAN - + ME-STYLE-DEFAULT - + ME-STYLE-WINDOWS ME-STYLE-CDE - + ME-STYLE-GTK ME-STYLE-CLEANLOOKS - + ME-STYLE-FUSION ME-STYLE-PLASTIQUE - + ME-FILE-ADD - + ME-FILE-REPLACE - + ME-FILE-REMOVE - + ME-FILE-SAVE-PLAIN - + ME-FILE-SAVE-PAK - + ME-FILE-SAVE-ZLIB - + ME-FILE-CONV-WIN - + ME-FILE-CONV-LIN - + ME-FILE-IMAGE - + ME-FILE-TEXT - - + + ME-FILE-DAT + + + + + ME-FILE-OBJECT + + + + + DIA-OPEN-FILE - - + + FLT-FILE-VFS DIA-SAVE-FILE - + DIA-OPEN-VFS - + DIA-SAVE-VFS - - + + FLT-FILE-ANY - + DIA-SAVE-PLAIN - + FLT-FILE-PLAIN - + DIA-SAVE-PAK - + FLT-FILE-PAK - + DIA-SAVE-ZLIB - + FLT-FILE-ZLIB - + MSG-UPD-FILE - + MSG-UPD-WITH - + MSG-UPD-ENTRIES + + ObjectWindow + + + FRM-OBJECT + + + + + MM-OBJECT + + + + + ME-OBJECT-SAVE + + + + + ME-OBJECT-CANCEL + + + TextWindow diff --git a/editor/i18n_german.ts b/editor/i18n_german.ts index 33b8481..a1fddc6 100644 --- a/editor/i18n_german.ts +++ b/editor/i18n_german.ts @@ -1,12 +1,35 @@ + + DatWindow + + + FRM-DAT + QTinNS Editor - Dat Viewer + + + + MM-DAT + Dat + + + + ME-DAT-SAVE + Speichere Dat Änderungen + + + + ME-DAT-CANCEL + Verwerfe Dat Änderungen + + ImageWindow FRM-IMAGE - QTinNS Editor Image Viewer + QTinNS Editor - Image Viewer @@ -72,220 +95,234 @@ Datei - + ME-APP-QUIT Beenden - + ME-APP-NEW Neues virtuelles Dateisystem - + ME-APP-OPEN Virtuelles Dateisystem öffnen ... - + ME-APP-SAVE Virtuelles Dateisystem speichern - + ME-APP-SAVEAS Virtuelles Dateisystem speichern als ... - + ME-ABOUT-APP Über QTinNS Editor ... - + ME-ABOUT-QT Über Qt Framework ... - + ME-LANG-ENGLISH Englisch - + ME-LANG-FRENCH Französisch - + ME-LANG-GERMAN Deutsch - + ME-STYLE-DEFAULT System Standard - + ME-STYLE-WINDOWS ME-STYLE-CDE Windows - + ME-STYLE-GTK ME-STYLE-CLEANLOOKS GTK+ - + ME-STYLE-FUSION ME-STYLE-PLASTIQUE Fusion - + ME-FILE-ADD Füge Datei(en) hinzu ... - + ME-FILE-REPLACE Ersetze Datei ... - + ME-FILE-REMOVE Entferne Datei ... - + ME-FILE-SAVE-PLAIN Speichere normale Datei als ... - + ME-FILE-SAVE-PAK Speichere PAK Datei als ... - + ME-FILE-SAVE-ZLIB Speichere ZLIB Datei als ... - + ME-FILE-CONV-WIN Konvertiere UNIX Pfad nach Windows - + ME-FILE-CONV-LIN Konvertiere Windows Pfad nach UNIX - + ME-FILE-IMAGE Bild anzeigen ... - + ME-FILE-TEXT Text anzeigen ... - - + + ME-FILE-DAT + Dat anzeigen ... + + + + ME-FILE-OBJECT + 3D Objekt anzeigen ... + + + + DIA-OPEN-FILE Datei öffnen ... - - + + FLT-FILE-VFS DIA-SAVE-FILE Neocron VFS Datei (*.vfs *.pak) - + DIA-OPEN-VFS Virtuelles Dateisystem öffnen ... - + DIA-SAVE-VFS Virtuelles Dateisystem speichern ... - - + + FLT-FILE-ANY Datei (*.*) - + DIA-SAVE-PLAIN Datei speichern ... - + FLT-FILE-PLAIN Datei (*.*) - + DIA-SAVE-PAK PAK Datei speichern ... - + FLT-FILE-PAK Neocron PAK Datei (*.pak) - + DIA-SAVE-ZLIB ZLIB Datei speichern ... - + FLT-FILE-ZLIB ZLIB Datei (*.z) - + MSG-UPD-FILE Virtuelles Dateisystem - + MSG-UPD-WITH mit - + MSG-UPD-ENTRIES Einträgen - PictureWindow + ObjectWindow - FRM-IMAGE - QTinNS Editor Viewer + + FRM-OBJECT + QTinNS Editor - 3D Object Viewer - MM-IMAGE - Bild + + MM-OBJECT + 3D Objekt - ME-IMAGE-SAVE - Speichere Änderungen + + ME-OBJECT-SAVE + Speichere 3D Objekt Änderungen - ME-IMAGE-CANCEL - Verwerfe Änderungen + + ME-OBJECT-CANCEL + Verwerfe 3D Objekt Änderungen @@ -293,7 +330,7 @@ FRM-TEXT - QTinNS Editor Text Viewer + QTinNS Editor - Text Viewer diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt new file mode 100644 index 0000000..8832147 --- /dev/null +++ b/engine/CMakeLists.txt @@ -0,0 +1,17 @@ +# Qt sources +set (EN_SOURCES GLWidget.cxx) +set (EN_HEADERS GLWidget.hxx) +set (EN_UI_FILES ) +set (EN_RES_FILES ) +set (EN_TS_FILES ) + +# wrappers +QT5_ADD_TRANSLATION (EN_TS_SOURCES ${EN_TS_FILES}) +QT5_WRAP_CPP (EN_MOC_SOURCES ${EN_HEADERS}) +QT5_WRAP_UI (EN_UI_SOURCES ${EN_UI_FILES}) +QT5_ADD_RESOURCES (EN_RES_SOURCES ${EN_RES_FILES}) + +# apps +add_library (Engine ${EN_SOURCES} ${EN_MOC_SOURCES} ${EN_UI_SOURCES} ${EN_RES_SOURCES} ${EN_TS_SOURCES}) +qt5_use_modules (Engine Core OpenGL) +target_link_libraries (Engine GL) diff --git a/engine/GLWidget.cxx b/engine/GLWidget.cxx new file mode 100644 index 0000000..0e1bb94 --- /dev/null +++ b/engine/GLWidget.cxx @@ -0,0 +1,87 @@ +#include +#include +#include "GLWidget.hxx" + +// --- constructors and deconstructors --- + +GLWidget::GLWidget(QWidget *parent, QGLWidget *shared) +: QGLWidget(parent, shared), _last_pos(0, 0), _rot_x(0.0), _rot_y(0.0), _rot_z(0.0) +{ +} + +GLWidget::~GLWidget() +{ +} + +// --- public slots --- + +void GLWidget::slotRotateDelta(qreal angle_x, qreal angle_y, qreal angle_z) +{ + _rot_x += angle_x; + _rot_y += angle_y; + _rot_z += angle_z; + updateGL(); +} + +// --- protected methods --- + +void GLWidget::initializeGL() +{ + glEnable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE);; +} + +void GLWidget::paintGL() +{ + qglClearColor(Qt::black); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glLoadIdentity(); + glTranslatef(0.0, 0.0, -10.0); + glRotatef(_rot_x / 16.0, 1.0, 0.0, 0.0); + glRotatef(_rot_y / 16.0, 0.0, 1.0, 0.0); + glRotatef(_rot_z / 16.0, 0.0, 0.0, 1.0); + + if (_vertices.count()) + { + glVertexPointer(3, GL_FLOAT, 0, _vertices.constData()); + glEnableClientState(GL_VERTEX_ARRAY); + + for (quint32 i = 0; i < _vertices.count(); ++i) + glDrawArrays(GL_TRIANGLE_FAN, i * 4, 4); + } +} + +void GLWidget::resizeGL(qint32 width, qint32 height) +{ + const qint32 side = qMin(width, height); + + glViewport((width - side) / 2, (height - side) / 2, side, side); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-0.5, 0.5, 0.5, -0.5, 4.0, 15.0); + glMatrixMode(GL_MODELVIEW); +} + +void GLWidget::mousePressEvent(QMouseEvent *event) +{ + _last_pos = event->pos(); +} + +void GLWidget::mouseMoveEvent(QMouseEvent *event) +{ + qint32 dx = event->x() - _last_pos.x(); + qint32 dy = event->y() - _last_pos.y(); + + if (event->buttons() & Qt::LeftButton) + slotRotateDelta(8 * dy, 8 * dx, 0); + else if (event->buttons() & Qt::RightButton) + slotRotateDelta(8 * dy, 0, 8 * dx); + else + _last_pos = event->pos(); +} + +void GLWidget::mouseReleaseEvent(QMouseEvent *event) +{ + emit sigClicked(); +} diff --git a/engine/GLWidget.hxx b/engine/GLWidget.hxx new file mode 100644 index 0000000..0ea0b8b --- /dev/null +++ b/engine/GLWidget.hxx @@ -0,0 +1,32 @@ +#pragma once + +#include + +class GLWidget : public QGLWidget { + Q_OBJECT +signals: + void sigClicked() const; + +public: + explicit GLWidget(QWidget *parent = 0, QGLWidget *shared = 0); + virtual ~GLWidget(); + +public slots: + void slotRotateDelta(qreal angle_x, qreal angle_y, qreal angle_z); + +protected: + virtual void initializeGL() override; + virtual void paintGL() override; + virtual void resizeGL(qint32 width, qint32 height) override; + + virtual void mousePressEvent(QMouseEvent *event) override; + virtual void mouseMoveEvent(QMouseEvent *event) override; + virtual void mouseReleaseEvent(QMouseEvent *event) override; + +private: + QPoint _last_pos; + qreal _rot_x; + qreal _rot_y; + qreal _rot_z; + QVector _vertices; +}; diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index e9d8be9..3b4821e 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,13 +1,16 @@ # apps -add_executable (vfs_tool vfs_tool.cxx) -qt5_use_modules (vfs_tool Core) -target_link_libraries (vfs_tool Filesystem) +add_executable (tool_bsp_viewer bsp_viewer.cxx) +target_link_libraries (tool_bsp_viewer GL glut GLU GLEW) -add_executable (dat_viewer dat_viewer.cxx) -qt5_use_modules (dat_viewer Core) +add_executable (tool_dat_viewer dat_viewer.cxx) +qt5_use_modules (tool_dat_viewer Core) -add_executable (zcompress zcompress.cxx) -qt5_use_modules (zcompress Core) +add_executable (tool_vfs vfs_tool.cxx) +qt5_use_modules (tool_vfs Core) +target_link_libraries (tool_vfs Filesystem) -add_executable (zdecompress zdecompress.cxx) -qt5_use_modules (zdecompress Core) +add_executable (tool_zcompress zcompress.cxx) +qt5_use_modules (tool_zcompress Core) + +add_executable (tool_zdecompress zdecompress.cxx) +qt5_use_modules (tool_zdecompress Core) diff --git a/tools/bsp_viewer.cxx b/tools/bsp_viewer.cxx new file mode 100644 index 0000000..4eeb168 --- /dev/null +++ b/tools/bsp_viewer.cxx @@ -0,0 +1,231 @@ +#include +#include +#include +#include +#include +#include + +namespace Data +{ + enum Type { + BSPHeader = 0, + Faces = 11, + VertexIndexes = 13, + Vertices = 14, + RGBVertices = 15, + TextureInfo = 17, + Textures = 18, + TextureData = 19, + Palettes = 23, + PaletteEntries = 256 + }; +} + +struct BSPHeader { + uint32_t magic; + uint32_t unknown; + uint32_t version; + uint16_t systime[8]; +}; + +struct Chunk { + uint32_t type; + uint32_t size; + uint32_t count; +}; + +struct Vertex { + float x, y, z; +}; + +struct Face { + uint32_t first; + uint32_t vertex_count; + uint32_t plane_count; + uint32_t plane_side; + uint32_t tex_info; + uint32_t lightmap_info; + uint32_t lightmap_width; + uint32_t lightmap_height; + uint8_t lightmap_types; +}; + +std::vector faces; +std::vector vertices; +std::vector rgb_vertices; +std::vector indexes; + +void display() +{ + glClearColor(0.1, 0.1, 0.1, 0.0); + glClear(GL_COLOR_BUFFER_BIT); + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + glLoadIdentity(); + + glTranslatef(0.0, 0.0, -200.0); + for (Face& face : faces) + { + glBegin(GL_TRIANGLE_FAN); + for (size_t j = 0; j < face.vertex_count; ++j) + { + Vertex& vert = vertices[indexes[face.first + j]]; + + glVertex3f(vert.x / 30.0, vert.y / 30.0, vert.z / 30.0); + } + glEnd(); + } + /*for (Vertex& vert : vertices) + { + glBegin(GL_POINTS); + glColor3f(1.0, 1.0, 1.0); + glVertex3f(vert.x / 10.0, vert.y / 10.0, vert.z / 10.0); + glEnd(); + }*/ + /*glBegin(GL_POINTS); + glColor3f(1.0, 1.0, 1.0); + glVertex3f(-496.0, -512.0, -233.0); + glVertex3f(-496.0, -512.0, -322.0); + glVertex3f(-496.0, -512.0, -452.0); + glVertex3f(-304.0, -512.0, -452.0); + glVertex3f(-304.0, -512.0, -357.0); + glVertex3f(-304.0, -512.0, -304.0); + glVertex3f(-304.0, -512.0, -233.0); + glEnd();*/ + + glutSwapBuffers(); +} + +void reshape(GLint w, GLint h) +{ + glViewport(0, 0, static_cast(w), static_cast(h)); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(90, static_cast(w) / static_cast(h), 1.0, 1000.0); + glMatrixMode(GL_MODELVIEW); +} + +int main(int argc, char **argv) +{ + std::string filename = "test.bsp"; + std::ifstream file; + struct BSPHeader header; + + if (argc == 2) + filename = argv[1]; + + if (!std::ifstream(filename)) + { + std::cerr << "ERROR: file not accessable" << std::endl; + return 1; + } + + file.open(filename); + if (file.is_open() && file.good()) + { + Chunk chunk; + size_t size = file.seekg(0, std::ios_base::end).tellg(); + + file.seekg(0, std::ios_base::beg); + + while (file.read(reinterpret_cast(&chunk), sizeof (chunk)) && (chunk.type != 0xffff)) + { + switch (chunk.type) + { + case Data::BSPHeader: + { + file.seekg(chunk.size * chunk.count, std::ios_base::cur); + + break; + } + case Data::Faces: + { + Face fac; + + for (size_t i = 0; i < chunk.count; ++i) + { + file.read(reinterpret_cast(&fac), chunk.size); + faces.push_back(fac); + } + + std::cout << "read " << chunk.count << " faces" << std::endl; + + break; + } + case Data::VertexIndexes: + { + uint32_t ind = 0; + + for (size_t i = 0; i < chunk.count; ++i) + { + file.read(reinterpret_cast(&ind), chunk.size); + indexes.push_back(ind); + } + + std::cout << "read " << chunk.count << " vertex indicies" << std::endl; + + break; + } + case Data::Vertices: + { + Vertex vert; + + for (size_t i = 0; i < chunk.count; ++i) + { + file.read(reinterpret_cast(&vert), chunk.size); + vertices.push_back(vert); + } + + std::cout << "read " << chunk.count << " vertices" << std::endl; + + break; + } + default: + { + std::cout << "dropped type " << chunk.type << " with size " << chunk.size * chunk.count << std::endl; + file.seekg(chunk.size * chunk.count, std::ios_base::cur); + + break; + } + } + } + + file.close(); + } + + //for (Vertex& vert : vertices) + // std::cout << "vertex " << vert.x << " " << vert.y << " " << vert.z << std::endl; + + //for (uint32_t& ind : indexes) + // std::cout << "index " << ind << std::endl; + + /*for (Face& face : faces) + { + std::cout << "Face: " << face.vertex_count << " (" << face.first << ") ->"; + for (size_t i = 0; i < face.vertex_count; ++i) + { + std::cout << " " << indexes[i + face.first]; + } + std::cout << std::endl; + std::cout << " "; + for (size_t i = 0; i < face.vertex_count; ++i) + { + Vertex& vert = vertices[indexes[i + face.first]]; + std::cout << " (" << vert.x << ", " << vert.y << ", " << vert.z << ")"; + } + std::cout << std::endl << std::endl; + }*/ + + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA); + glutInitWindowSize(800, 600); + glutInitWindowPosition(40, 40); + glutCreateWindow("NC BSP Test"); + + glutDisplayFunc(display); + glutReshapeFunc(reshape); + glutIdleFunc(display); + + glutMainLoop(); + + return 0; +} -- 2.15.1