Okokokokokokokok
This commit is contained in:
@@ -53,6 +53,8 @@ add_executable(kaizen-qt
|
||||
main.cpp
|
||||
KaizenQt.hpp
|
||||
KaizenQt.cpp
|
||||
RenderWidget.cpp
|
||||
RenderWidget.hpp
|
||||
EmuThread.hpp
|
||||
EmuThread.cpp
|
||||
mainwindow.ui
|
||||
|
||||
@@ -2,17 +2,13 @@
|
||||
#include <QMessageBox>
|
||||
#include <QApplication>
|
||||
|
||||
KaizenQt::KaizenQt() noexcept
|
||||
: mainWindow(new MainWindowController),
|
||||
emuThread(new EmuThread(mainWindow))
|
||||
{
|
||||
KaizenQt::KaizenQt() noexcept : mainWindow(new MainWindowController), emuThread(new EmuThread(mainWindow)) {
|
||||
ConnectMainWindowSignalsToSlots();
|
||||
|
||||
mainWindow->show();
|
||||
}
|
||||
|
||||
void KaizenQt::ConnectMainWindowSignalsToSlots() noexcept
|
||||
{
|
||||
void KaizenQt::ConnectMainWindowSignalsToSlots() noexcept {
|
||||
connect(mainWindow, &MainWindowController::OpenROM, this, &KaizenQt::LoadROM);
|
||||
connect(mainWindow, &MainWindowController::Exit, this, []() {
|
||||
QApplication::quit();
|
||||
@@ -22,8 +18,7 @@ void KaizenQt::ConnectMainWindowSignalsToSlots() noexcept
|
||||
connect(mainWindow, &MainWindowController::Pause, emuThread, &EmuThread::TogglePause);
|
||||
}
|
||||
|
||||
void KaizenQt::LoadROM(const QString& file_name) noexcept
|
||||
{
|
||||
void KaizenQt::LoadROM(const QString& file_name) noexcept {
|
||||
emuThread->core.LoadROM(file_name.toStdString());
|
||||
emuThread->start();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,26 @@
|
||||
#pragma once
|
||||
#include <MainWindow.hpp>
|
||||
#include <EmuThread.hpp>
|
||||
#include <MainWindow.hpp>
|
||||
|
||||
enum class CompositorCategory {
|
||||
Windows, MacOS, XCB, Wayland
|
||||
};
|
||||
|
||||
static inline CompositorCategory GetOSCompositorCategory() {
|
||||
const QString platform_name = QGuiApplication::platformName();
|
||||
if (platform_name == QStringLiteral("windows"))
|
||||
return CompositorCategory::Windows;
|
||||
else if (platform_name == QStringLiteral("xcb"))
|
||||
return CompositorCategory::XCB;
|
||||
else if (platform_name == QStringLiteral("wayland") ||
|
||||
platform_name == QStringLiteral("wayland-egl"))
|
||||
return CompositorCategory::Wayland;
|
||||
else if (platform_name == QStringLiteral("cocoa") || platform_name == QStringLiteral("ios"))
|
||||
return CompositorCategory::MacOS;
|
||||
|
||||
Util::error("Unknown Qt platform!");
|
||||
return CompositorCategory::Windows;
|
||||
}
|
||||
|
||||
class KaizenQt : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
#include <MainWindow.hpp>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <MainWindow.hpp>
|
||||
|
||||
MainWindowController::MainWindowController() noexcept
|
||||
{
|
||||
MainWindowController::MainWindowController() noexcept {
|
||||
view.setupUi(this);
|
||||
ConnectSignalsToSlots();
|
||||
}
|
||||
|
||||
void MainWindowController::ConnectSignalsToSlots() noexcept
|
||||
{
|
||||
void MainWindowController::ConnectSignalsToSlots() noexcept {
|
||||
connect(view.actionOpen, &QAction::triggered, this, [this]() {
|
||||
QString file_name = QFileDialog::getOpenFileName(this);
|
||||
|
||||
if (!file_name.isEmpty())
|
||||
{
|
||||
if (!file_name.isEmpty()) {
|
||||
view.actionPause->setEnabled(true);
|
||||
view.actionReset->setEnabled(true);
|
||||
view.actionStop->setEnabled(true);
|
||||
@@ -24,24 +21,24 @@ void MainWindowController::ConnectSignalsToSlots() noexcept
|
||||
|
||||
connect(view.actionExit, &QAction::triggered, this, [this]() {
|
||||
emit Exit();
|
||||
});
|
||||
});
|
||||
|
||||
connect(view.actionReset, &QAction::triggered, this, [this]() {
|
||||
emit Reset();
|
||||
});
|
||||
});
|
||||
|
||||
connect(view.actionStop, &QAction::triggered, this, [this]() {
|
||||
view.actionPause->setDisabled(true);
|
||||
view.actionReset->setDisabled(true);
|
||||
view.actionStop->setDisabled(true);
|
||||
emit Stop();
|
||||
});
|
||||
});
|
||||
|
||||
connect(view.actionPause, &QAction::triggered, this, [this]() {
|
||||
textPauseToggle = !textPauseToggle;
|
||||
view.actionPause->setText(textPauseToggle ? "Resume" : "Pause");
|
||||
emit Pause();
|
||||
});
|
||||
});
|
||||
|
||||
connect(view.actionAbout, &QAction::triggered, this, [this]() {
|
||||
QMessageBox::about(
|
||||
@@ -50,5 +47,5 @@ void MainWindowController::ConnectSignalsToSlots() noexcept
|
||||
"experience and great compatibility.\n"
|
||||
"sliice is licensed under the BSD 3-clause license.\n"
|
||||
"Nintendo 64 is a registered trademarks of Nintendo Co., Ltd."));
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include <QMainWindow>
|
||||
#include "ui_mainwindow.h"
|
||||
#include <QMainWindow>
|
||||
#include <QApplication>
|
||||
|
||||
class MainWindowController : public QMainWindow
|
||||
{
|
||||
@@ -15,7 +16,7 @@ private:
|
||||
Ui::MainWindow view;
|
||||
bool textPauseToggle = false;
|
||||
|
||||
signals:
|
||||
Q_SIGNALS:
|
||||
void OpenROM(const QString& rom_file);
|
||||
void Exit();
|
||||
void Reset();
|
||||
|
||||
31
src/frontend/RenderWidget.cpp
Normal file
31
src/frontend/RenderWidget.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <RenderWidget.hpp>
|
||||
#include <KaizenQt.hpp>
|
||||
|
||||
RenderWidget::RenderWidget(QWidget* parent) : QWidget(parent) {
|
||||
if (volkInitialize() != VK_SUCCESS) {
|
||||
Util::panic("Could not initialize Vulkan loader!");
|
||||
}
|
||||
|
||||
create();
|
||||
|
||||
setAttribute(Qt::WA_NativeWindow);
|
||||
setAttribute(Qt::WA_PaintOnScreen);
|
||||
if (GetOSCompositorCategory() == CompositorCategory::Wayland) {
|
||||
setAttribute(Qt::WA_DontCreateNativeAncestors);
|
||||
}
|
||||
|
||||
if (GetOSCompositorCategory() == CompositorCategory::MacOS) {
|
||||
windowHandle()->setSurfaceType(QWindow::MetalSurface);
|
||||
}
|
||||
else {
|
||||
windowHandle()->setSurfaceType(QWindow::VulkanSurface);
|
||||
}
|
||||
|
||||
instance.create();
|
||||
windowHandle()->setVulkanInstance(&instance);
|
||||
|
||||
wsiPlatform = new QtWSIPlatform(windowHandle());
|
||||
windowInfo = std::make_unique<QtParallelRdpWindowInfo>(windowHandle());
|
||||
|
||||
LoadWSIPlatform(wsiPlatform, std::move(windowInfo));
|
||||
}
|
||||
75
src/frontend/RenderWidget.hpp
Normal file
75
src/frontend/RenderWidget.hpp
Normal file
@@ -0,0 +1,75 @@
|
||||
#pragma once
|
||||
#undef signals
|
||||
#include <ParallelRDPWrapper.hpp>
|
||||
#include <QWidget>
|
||||
#include <QWindow>
|
||||
#include <QVulkanInstance>
|
||||
|
||||
class QtParallelRdpWindowInfo : public ParallelRdpWindowInfo {
|
||||
public:
|
||||
QtParallelRdpWindowInfo(QWindow* window) : window(window) {}
|
||||
CoordinatePair get_window_size() {
|
||||
CoordinatePair{ static_cast<float>(window->width()), static_cast<float>(window->height()) };
|
||||
}
|
||||
private:
|
||||
QWindow* window;
|
||||
};
|
||||
|
||||
class QtWSIPlatform final : public Vulkan::WSIPlatform {
|
||||
public:
|
||||
QtWSIPlatform(QWindow* window) : window(window) {}
|
||||
|
||||
std::vector<const char*> get_instance_extensions() override {
|
||||
auto vec = std::vector<const char*>();
|
||||
|
||||
for (const auto& ext : window->vulkanInstance()->extensions()) {
|
||||
vec.push_back(ext);
|
||||
}
|
||||
|
||||
return vec;
|
||||
}
|
||||
|
||||
VkSurfaceKHR create_surface(VkInstance, VkPhysicalDevice) override {
|
||||
return QVulkanInstance::surfaceForWindow(window);
|
||||
}
|
||||
|
||||
uint32_t get_surface_width() override {
|
||||
return 640;
|
||||
}
|
||||
|
||||
uint32_t get_surface_height() override {
|
||||
return 480;
|
||||
}
|
||||
|
||||
bool alive(Vulkan::WSI&) override {
|
||||
return true;
|
||||
}
|
||||
|
||||
void poll_input() override { }
|
||||
|
||||
void event_frame_tick(double frame, double elapsed) override { }
|
||||
|
||||
const VkApplicationInfo* get_application_info() override {
|
||||
return &appInfo;
|
||||
}
|
||||
|
||||
VkApplicationInfo appInfo{
|
||||
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
|
||||
.apiVersion = VK_API_VERSION_1_3
|
||||
};
|
||||
private:
|
||||
QWindow* window;
|
||||
};
|
||||
|
||||
class RenderWidget : public QWidget {
|
||||
public:
|
||||
explicit RenderWidget(QWidget* parent);
|
||||
|
||||
QPaintEngine* paintEngine() const override {
|
||||
return nullptr;
|
||||
}
|
||||
private:
|
||||
std::unique_ptr<ParallelRdpWindowInfo> windowInfo;
|
||||
QtWSIPlatform* wsiPlatform;
|
||||
QVulkanInstance instance;
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <KaizenQt.hpp>
|
||||
#include <QApplication>
|
||||
#include <QCommandLineParser>
|
||||
#include <QCommandLineOption>
|
||||
#include <KaizenQt.hpp>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
QApplication app(argc, argv);
|
||||
|
||||
@@ -30,6 +30,9 @@
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="RenderWidget" name="vulkanWidget"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
@@ -119,6 +122,13 @@
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>Renderer</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>RenderWidget.hpp</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
||||
Reference in New Issue
Block a user