diff --git a/CMakeLists.txt b/CMakeLists.txt index 8224de93..a292e3df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,16 +102,16 @@ add_subdirectory(common) add_subdirectory(bspinfo) add_subdirectory(bsputil) add_subdirectory(light) - -if (ENABLE_LIGHTPREVIEW) - add_subdirectory(lightpreview) -endif () - add_subdirectory(qbsp) add_subdirectory(vis) option(DISABLE_TESTS "Disables Tests" OFF) option(DISABLE_DOCS "Disables Docs" OFF) +option(ENABLE_LIGHTPREVIEW "Enable light preview tool" OFF) + +if (ENABLE_LIGHTPREVIEW) + add_subdirectory(lightpreview) +endif () if(NOT DISABLE_TESTS) # just creates testmaps.hh with absolute path to the testmaps source directory. diff --git a/lightpreview/CMakeLists.txt b/lightpreview/CMakeLists.txt index 1cb7df55..356327b7 100644 --- a/lightpreview/CMakeLists.txt +++ b/lightpreview/CMakeLists.txt @@ -2,7 +2,6 @@ project (lightpreview CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTOUIC ON) find_package(Qt5Widgets) @@ -11,10 +10,29 @@ add_executable(lightpreview mainwindow.cpp mainwindow.h glview.cpp - glview.h - ${QBSP_SOURCES}) + glview.h) -target_link_libraries(lightpreview Qt5::Widgets) +find_package(embree 3.0 REQUIRED) +INCLUDE_DIRECTORIES(${EMBREE_INCLUDE_DIRS}) + +# HACK: Windows embree .dll's from https://github.com/embree/embree/releases ship with a tbb12.dll +# and we need to copy it from the embree/bin directory to our light.exe/testlight.exe dir in order for them to run +find_file(EMBREE_TBB_DLL tbb12.dll + "${EMBREE_ROOT_DIR}/bin" + NO_DEFAULT_PATH) +if (NOT EMBREE_TBB_DLL STREQUAL EMBREE_TBB_DLL-NOTFOUND) + message(STATUS "Found embree EMBREE_TBB_DLL: ${EMBREE_TBB_DLL}") +endif() + +target_link_libraries(lightpreview + Qt5::Widgets + libqbsp + liblight + libvis + common + TBB::tbb + TBB::tbbmalloc + fmt::fmt) # from: http://stackoverflow.com/questions/40564443/copying-qt-dlls-to-executable-directory-on-windows-using-cmake # Copy Qt DLL's to bin directory for debugging @@ -25,6 +43,17 @@ add_custom_command( COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ ) +# HACK: copy .dll dependencies +add_custom_command(TARGET lightpreview POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different "$" "$" + COMMAND ${CMAKE_COMMAND} -E copy_if_different "$" "$" + COMMAND ${CMAKE_COMMAND} -E copy_if_different "$" "$" + ) +if (NOT EMBREE_TBB_DLL STREQUAL EMBREE_TBB_DLL-NOTFOUND) + add_custom_command(TARGET lightpreview POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different "${EMBREE_TBB_DLL}" "$") +endif() + # Install Qt DLL's install(FILES $ DESTINATION bin) install(FILES $ DESTINATION bin) diff --git a/lightpreview/glview.cpp b/lightpreview/glview.cpp index 0075a312..f5659ff1 100644 --- a/lightpreview/glview.cpp +++ b/lightpreview/glview.cpp @@ -28,6 +28,8 @@ See file, 'COPYING', for details. #include #include +#include + GLView::GLView(QWidget *parent) : QOpenGLWidget(parent), m_keysPressed(0), @@ -236,3 +238,5 @@ void GLView::timerEvent(QTimerEvent *event) update(); // schedule a repaint } + +void GLView::renderBSP(const mbsp_t &bsp) { } \ No newline at end of file diff --git a/lightpreview/glview.h b/lightpreview/glview.h index f4d7f60c..324440ff 100644 --- a/lightpreview/glview.h +++ b/lightpreview/glview.h @@ -38,6 +38,8 @@ enum class keys_t : uint32_t left = 8 }; +struct mbsp_t; + class GLView : public QOpenGLWidget, protected QOpenGLFunctions { private: @@ -67,6 +69,8 @@ public: GLView(QWidget *parent = nullptr); ~GLView(); + void renderBSP(const mbsp_t &bsp); + protected: void initializeGL() override; void paintGL() override; diff --git a/lightpreview/lightpreview.pro b/lightpreview/lightpreview.pro deleted file mode 100644 index 9f8b0689..00000000 --- a/lightpreview/lightpreview.pro +++ /dev/null @@ -1,33 +0,0 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2017-03-20T13:10:04 -# -#------------------------------------------------- - -QT += core gui - -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets - -TARGET = lightpreview -TEMPLATE = app - -# The following define makes your compiler emit warnings if you use -# any feature of Qt which as been marked as deprecated (the exact warnings -# depend on your compiler). Please consult the documentation of the -# deprecated API in order to know how to port your code away from it. -DEFINES += QT_DEPRECATED_WARNINGS - -# You can also make your code fail to compile if you use deprecated APIs. -# In order to do so, uncomment the following line. -# You can also select to disable deprecated APIs only up to a certain version of Qt. -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 - - -SOURCES += main.cpp\ - mainwindow.cpp \ - glview.cpp - -HEADERS += mainwindow.h \ - glview.h - -FORMS += mainwindow.ui diff --git a/lightpreview/mainwindow.cpp b/lightpreview/mainwindow.cpp index 5797f063..3b745390 100644 --- a/lightpreview/mainwindow.cpp +++ b/lightpreview/mainwindow.cpp @@ -18,16 +18,130 @@ See file, 'COPYING', for details. */ #include "mainwindow.h" -#include "ui_mainwindow.h" + +#include +#include +#include + +#include +#include +#include +#include + +#include "glview.h" MainWindow::MainWindow(QWidget *parent) - : QMainWindow(parent), - ui(new Ui::MainWindow) + : QMainWindow(parent) { - ui->setupUi(this); + resize(640, 480); + glView = new GLView(); + this->setCentralWidget(glView); + + setAcceptDrops(true); } -MainWindow::~MainWindow() +MainWindow::~MainWindow() { } + +void MainWindow::dragEnterEvent(QDragEnterEvent *event) { - delete ui; + if (event->mimeData()->hasUrls()) + event->acceptProposedAction(); } + +void MainWindow::dropEvent(QDropEvent *event) +{ + auto urls = event->mimeData()->urls(); + if (!urls.empty()) { + const QUrl &url = urls[0]; + if (url.isLocalFile()) { + loadFile(url.toLocalFile()); + + event->acceptProposedAction(); + } + } +} + +void MainWindow::loadFile(const QString &file) +{ + qDebug() << "load " << file; + + if (m_watcher) { + delete m_watcher; + } + m_watcher = new QFileSystemWatcher(this); + + // start watching it + qDebug() << "adding path: " << m_watcher->addPath(file); + connect(m_watcher, &QFileSystemWatcher::fileChanged, this, + [](const QString &path) { qDebug() << "got change notif for " << path; }); + + loadFileInternal(file); +} + +std::filesystem::path MakeFSPath(const QString &string) +{ + return std::filesystem::path{string.toStdU16String()}; +} + +static bspdata_t QbspVisLight_Common(const std::filesystem::path &name, std::vector extra_qbsp_args, + std::vector extra_light_args, bool run_vis) +{ + auto bsp_path = name; + bsp_path.replace_extension(".bsp"); + + std::vector args{ + "", // the exe path, which we're ignoring in this case + }; + for (auto &extra : extra_qbsp_args) { + args.push_back(extra); + } + args.push_back(name.string()); + + // run qbsp + + InitQBSP(args); + ProcessFile(); + + // run vis + if (run_vis) { + std::vector vis_args{ + "", // the exe path, which we're ignoring in this case + }; + vis_args.push_back(name.string()); + vis_main(vis_args); + } + + // run light + { + std::vector light_args{ + "", // the exe path, which we're ignoring in this case + }; + for (auto &arg : extra_light_args) { + light_args.push_back(arg); + } + light_args.push_back(name.string()); + + light_main(light_args); + } + + // serialize obj + { + bspdata_t bspdata; + LoadBSPFile(bsp_path, &bspdata); + + ConvertBSPFormat(&bspdata, &bspver_generic); + + return std::move(bspdata); + } +} + +void MainWindow::loadFileInternal(const QString &file) +{ + qDebug() << "loadFileInternal " << file; + + auto d = QbspVisLight_Common(MakeFSPath(file), {}, {}, true); + + const auto &bsp = std::get(d.bsp); + + glView->renderBSP(bsp); +} \ No newline at end of file diff --git a/lightpreview/mainwindow.h b/lightpreview/mainwindow.h index 81cf2da9..776ca5ea 100644 --- a/lightpreview/mainwindow.h +++ b/lightpreview/mainwindow.h @@ -21,19 +21,29 @@ See file, 'COPYING', for details. #include -namespace Ui -{ -class MainWindow; -} +class GLView; +class QFileSystemWatcher; class MainWindow : public QMainWindow { Q_OBJECT +private: + QFileSystemWatcher *m_watcher = nullptr; + QString m_mapFile; + public: explicit MainWindow(QWidget *parent = nullptr); ~MainWindow(); +protected: + void dragEnterEvent(QDragEnterEvent *event) override; + void dropEvent(QDropEvent *event) override; + private: - Ui::MainWindow *ui; + void loadFile(const QString &file); + void loadFileInternal(const QString &file); + +private: + GLView *glView; }; diff --git a/lightpreview/mainwindow.ui b/lightpreview/mainwindow.ui deleted file mode 100644 index e4eb7000..00000000 --- a/lightpreview/mainwindow.ui +++ /dev/null @@ -1,80 +0,0 @@ - - - MainWindow - - - - 0 - 0 - 499 - 423 - - - - MainWindow - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - - - - 0 - 0 - 499 - 22 - - - - - File - - - - - - - - TopToolBarArea - - - false - - - - - - Open - - - Ctrl+O - - - - - - - GLView - QOpenGLWidget -
glview.h
-
-
- - -