Basic initial work to replace Qt

This commit is contained in:
SimoZ64
2025-04-15 22:11:52 +02:00
parent 3ab403b8bd
commit a27ccf87d8
4 changed files with 34 additions and 63 deletions

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.2 FATAL_ERROR) cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
project( project(
cflags cflags

View File

@@ -1,6 +1,5 @@
#pragma once #pragma once
#include <Discord.hpp> #include <Discord.hpp>
#include <QThread>
#include <RenderWidget.hpp> #include <RenderWidget.hpp>
#include <SettingsWindow.hpp> #include <SettingsWindow.hpp>
#include <memory> #include <memory>
@@ -9,14 +8,13 @@ namespace n64 {
struct Core; struct Core;
} }
class EmuThread final : public QThread { class EmuThread final {
Q_OBJECT
RenderWidget &renderWidget; RenderWidget &renderWidget;
public: public:
explicit EmuThread(const std::shared_ptr<n64::Core> &, QLabel &, RenderWidget &, SettingsWindow &) noexcept; explicit EmuThread(const std::shared_ptr<n64::Core> &, RenderWidget &, SettingsWindow &) noexcept;
void run() noexcept override; void run() noexcept;
void TogglePause() const noexcept; void TogglePause() const noexcept;
void SetRender(bool v) const noexcept; void SetRender(bool v) const noexcept;
void Reset() const noexcept; void Reset() const noexcept;
@@ -24,5 +22,4 @@ public:
std::shared_ptr<n64::Core> core; std::shared_ptr<n64::Core> core;
SettingsWindow &settings; SettingsWindow &settings;
QLabel &fps;
}; };

View File

@@ -22,16 +22,11 @@ static CompositorCategory GetOSCompositorCategory() {
return CompositorCategory::Windows; return CompositorCategory::Windows;
} }
class KaizenQt : public QWidget { class KaizenQt {
Q_OBJECT
public: public:
KaizenQt() noexcept; KaizenQt() noexcept;
void LoadTAS(const QString &path) const noexcept; void LoadTAS(const std::string &path) const noexcept;
void LoadROM(const QString &path) const noexcept; void LoadROM(const std::string &path) const noexcept;
void dropEvent(QDropEvent *) override;
void dragEnterEvent(QDragEnterEvent *) override;
void keyPressEvent(QKeyEvent *) override;
void keyReleaseEvent(QKeyEvent *) override;
private: private:
void Quit() const noexcept; void Quit() const noexcept;

View File

@@ -1,70 +1,53 @@
#pragma once #pragma once
#undef signals #undef signals
#include <ParallelRDPWrapper.hpp> #include <ParallelRDPWrapper.hpp>
#include <QVulkanWindow> #include <SDL3/SDL.h>
#include <QWidget> #include <SDL3/SDL_vulkan.h>
#include <QWindow>
#include <SDL3/SDL_gamepad.h>
namespace n64 { namespace n64 {
struct Core; struct Core;
} }
struct QtInstanceFactory final : Vulkan::InstanceFactory { struct ImGuiInstanceFactory final : Vulkan::InstanceFactory {
VkInstance create_instance(const VkInstanceCreateInfo *info) override { VkInstance create_instance(const VkInstanceCreateInfo *info) override {
handle.setApiVersion({1, 3, 0});
QByteArrayList exts;
exts.resize(info->enabledExtensionCount);
for (int i = 0; i < info->enabledExtensionCount; i++) {
exts[i] = info->ppEnabledExtensionNames[i];
}
QByteArrayList layers;
layers.resize(info->enabledExtensionCount);
for (int i = 0; i < info->enabledLayerCount; i++) {
layers[i] = info->ppEnabledLayerNames[i];
}
handle.setExtensions(exts);
handle.setLayers(layers);
handle.setApiVersion({1, 3, 0});
handle.create();
return handle.vkInstance();
} }
QVulkanInstance handle; VkInstance instance;
}; };
class QtParallelRdpWindowInfo final : public ParallelRDP::WindowInfo { class ImGuiParallelRdpWindowInfo final : public ParallelRDP::WindowInfo {
public: public:
explicit QtParallelRdpWindowInfo(QWindow *window) : window(window) {} explicit ImGuiParallelRdpWindowInfo(SDL_Window *window) : window(window) {}
CoordinatePair get_window_size() override { CoordinatePair get_window_size() override {
return CoordinatePair{static_cast<float>(window->width()), static_cast<float>(window->height())}; int w,h;
SDL_GetWindowSizeInPixels(window.get(), &w, &h);
return CoordinatePair{static_cast<float>(w), static_cast<float>(h)};
} }
private: private:
std::shared_ptr<QWindow> window{}; std::shared_ptr<SDL_Window> window{};
}; };
class QtWSIPlatform final : public Vulkan::WSIPlatform { class ImGuiWSIPlatform final : public Vulkan::WSIPlatform {
public: public:
explicit QtWSIPlatform(const std::shared_ptr<n64::Core> &core, QWindow *window) : window(window), core(core) {} explicit ImGuiWSIPlatform(const std::shared_ptr<n64::Core> &core, SDL_Window *window) : window(window), core(core) {}
std::vector<const char *> get_instance_extensions() override { std::vector<const char *> get_instance_extensions() override {
auto vec = std::vector<const char *>(); auto vec = std::vector<const char *>();
const auto &extensions = window->vulkanInstance()->supportedExtensions(); u32 extCount;
vec.reserve(extensions.size()); const auto &extensions = SDL_Vulkan_GetInstanceExtensions(&extCount);
vec.reserve(extCount);
for (const auto &[name, _] : extensions) { for (u32 i = 0; i < extCount; i++) {
vec.emplace_back(name); vec.emplace_back(extensions[i]);
} }
return vec; return vec;
} }
VkSurfaceKHR create_surface(VkInstance, VkPhysicalDevice) override { VkSurfaceKHR create_surface(VkInstance instance, VkPhysicalDevice pDevice) override {
return QVulkanInstance::surfaceForWindow(window.get()); SDL_Vulkan_CreateSurface(window.get(), instance, nullptr, &surface);
return surface;
} }
void destroy_surface(VkInstance, VkSurfaceKHR) override {} void destroy_surface(VkInstance, VkSurfaceKHR) override {}
@@ -87,8 +70,8 @@ public:
VkApplicationInfo appInfo{.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, .apiVersion = VK_API_VERSION_1_3}; VkApplicationInfo appInfo{.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, .apiVersion = VK_API_VERSION_1_3};
std::shared_ptr<QWindow> window{}; std::shared_ptr<SDL_Window> window{};
VkSurfaceKHR surface;
private: private:
std::shared_ptr<n64::Core> core; std::shared_ptr<n64::Core> core;
SDL_Gamepad *gamepad{}; SDL_Gamepad *gamepad{};
@@ -96,16 +79,12 @@ private:
bool canPollEvents = true; bool canPollEvents = true;
}; };
class RenderWidget final : public QWidget { class RenderWidget final {
public: public:
[[nodiscard]] VkInstance instance() const { return qtVkInstanceFactory->handle.vkInstance(); } [[nodiscard]] VkInstance instance() const { return imGuiVkInstanceFactory->instance; }
explicit RenderWidget(const std::shared_ptr<n64::Core> &); explicit RenderWidget(const std::shared_ptr<n64::Core> &);
[[nodiscard]] QPaintEngine *paintEngine() const override { return nullptr; }
std::shared_ptr<ParallelRDP::WindowInfo> windowInfo; std::shared_ptr<ParallelRDP::WindowInfo> windowInfo;
std::shared_ptr<QtWSIPlatform> wsiPlatform; std::shared_ptr<ImGuiWSIPlatform> wsiPlatform;
std::shared_ptr<QtInstanceFactory> qtVkInstanceFactory; std::shared_ptr<ImGuiInstanceFactory> imGuiVkInstanceFactory;
Q_SIGNALS:
void Show() { show(); }
void Hide() { hide(); }
}; };