This commit is contained in:
SimoneN64
2024-01-19 00:59:47 +01:00
parent 7f1bef6037
commit 042fd05338
10 changed files with 67 additions and 25 deletions

View File

@@ -1,6 +1,7 @@
#include <Core.hpp>
#include <Scheduler.hpp>
#include <ParallelRDPWrapper.hpp>
#include <SDL2/SDL.h>
namespace n64 {
u32 extraCycles = 0;
@@ -16,15 +17,16 @@ u32 PopStalledCycles() {
}
Core::Core() {
SDL_Init(SDL_INIT_EVERYTHING);
if(SDL_GameControllerAddMappingsFromFile("resources/gamecontrollerdb.txt") < 0) {
Util::warn("Failed to load game controller DB");
}
cpu = std::make_unique<Interpreter>();
LoadParallelRDP(cpu->mem.GetRDRAM());
}
void Core::Stop() {
render = false;
pause = true;
romLoaded = false;
cpu->Reset();
@@ -54,6 +56,7 @@ void Core::LoadROM(const std::string& rom_) {
cpu->mem.LoadSRAM(cpu->mem.saveType, rom);
PIF::ExecutePIF(cpu->mem, cpu->regs);
pause = false;
render = true;
}
void Core::Run(float volumeL, float volumeR) {

View File

@@ -22,7 +22,7 @@ struct Core {
u32 breakpoint = 0;
bool pause = true;
bool render = true;
bool render = false;
u32 cycles = 0;
bool romLoaded = false;
std::string rom;

View File

@@ -1,11 +1,23 @@
#include <ParallelRDPWrapper.hpp>
#include <EmuThread.hpp>
#include <RenderWidget.hpp>
EmuThread::EmuThread(QObject* parent_object) noexcept : QThread(parent_object) {}
EmuThread::EmuThread(std::unique_ptr<QtInstanceFactory>&& instance, std::unique_ptr<Vulkan::WSIPlatform>&& wsiPlatform, std::unique_ptr<ParallelRdpWindowInfo>&& windowInfo, QObject* parent_object) noexcept
: QThread(parent_object), instance(std::move(instance)), wsiPlatform(std::move(wsiPlatform)), windowInfo(std::move(windowInfo)) {}
[[noreturn]] void EmuThread::run() noexcept {
LoadWSIPlatform(instance.get(), std::move(wsiPlatform), std::move(windowInfo));
LoadParallelRDP(core.cpu->mem.GetRDRAM());
while (true) {
if (!core.pause) {
core.Run(0.5, 0.5);
if(core.render) {
UpdateScreenParallelRdp(core, core.cpu->mem.mmio.vi);
}
} else {
if(core.render) {
UpdateScreenParallelRdpNoGame(core);
}
}
}
}

View File

@@ -2,12 +2,20 @@
#include <QThread>
#include <Core.hpp>
struct QtInstanceFactory;
struct ParallelRdpWindowInfo;
namespace Vulkan {
struct WSIPlatform;
}
class EmuThread : public QThread
{
Q_OBJECT
std::unique_ptr<QtInstanceFactory> instance;
std::unique_ptr<Vulkan::WSIPlatform> wsiPlatform;
std::unique_ptr<ParallelRdpWindowInfo> windowInfo;
public:
explicit EmuThread(QObject* parent_object) noexcept;
explicit EmuThread(std::unique_ptr<QtInstanceFactory>&& instance, std::unique_ptr<Vulkan::WSIPlatform>&& wsiPlatform, std::unique_ptr<ParallelRdpWindowInfo>&& windowInfo, QObject* parent_object) noexcept;
[[noreturn]] void run() noexcept override;

View File

@@ -1,8 +1,16 @@
#include <KaizenQt.hpp>
#include <QMessageBox>
#include <QApplication>
#include <SDL2/SDL.h>
KaizenQt::KaizenQt() noexcept {
mainWindow = new MainWindowController();
emuThread = new EmuThread(
std::move(mainWindow->view.vulkanWidget->instance),
std::move(mainWindow->view.vulkanWidget->wsiPlatform),
std::move(mainWindow->view.vulkanWidget->windowInfo),
mainWindow);
KaizenQt::KaizenQt() noexcept : mainWindow(new MainWindowController), emuThread(new EmuThread(mainWindow)) {
ConnectMainWindowSignalsToSlots();
mainWindow->show();
@@ -19,6 +27,6 @@ void KaizenQt::ConnectMainWindowSignalsToSlots() noexcept {
}
void KaizenQt::LoadROM(const QString& file_name) noexcept {
emuThread->core.LoadROM(file_name.toStdString());
emuThread->start();
emuThread->core.LoadROM(file_name.toStdString());
}

View File

@@ -2,7 +2,7 @@
#include <QMessageBox>
#include <MainWindow.hpp>
MainWindowController::MainWindowController() noexcept : vulkanWidget(new RenderWidget(this)) {
MainWindowController::MainWindowController() noexcept {
view.setupUi(this);
ConnectSignalsToSlots();
}

View File

@@ -11,11 +11,10 @@ class MainWindowController : public QMainWindow
public:
MainWindowController() noexcept;
Ui::MainWindow view;
private:
void ConnectSignalsToSlots() noexcept;
Ui::MainWindow view;
RenderWidget *vulkanWidget;
bool textPauseToggle = false;
Q_SIGNALS:

View File

@@ -19,11 +19,10 @@ RenderWidget::RenderWidget(QWidget* parent) : QWidget(parent) {
Util::panic("Could not initialize Vulkan ICD");
}
windowHandle()->setVulkanInstance(&instance.get_qvkinstance());
instance = std::make_unique<QtInstanceFactory>();
windowHandle()->setVulkanInstance(&instance->qVkInstance);
windowHandle()->create();
wsiPlatform = std::make_unique<QtWSIPlatform>(windowHandle());
windowInfo = std::make_unique<QtParallelRdpWindowInfo>(windowHandle());
LoadWSIPlatform(&instance, std::move(wsiPlatform), std::move(windowInfo));
}

View File

@@ -4,10 +4,11 @@
#include <QWidget>
#include <QWindow>
#include <QVulkanInstance>
#include <QVulkanWindow>
struct QtInstanceFactory : Vulkan::InstanceFactory {
VkInstance create_instance(const VkInstanceCreateInfo *info) override {
instance.setApiVersion({1,3,0});
qVkInstance.setApiVersion({1,3,0});
QByteArrayList exts;
for(int i = 0; i < info->enabledExtensionCount; i++) {
exts.push_back(QByteArray::fromStdString(info->ppEnabledExtensionNames[i]));
@@ -16,17 +17,15 @@ struct QtInstanceFactory : Vulkan::InstanceFactory {
for(int i = 0; i < info->enabledLayerCount; i++) {
layers.push_back(QByteArray::fromStdString(info->ppEnabledLayerNames[i]));
}
instance.setExtensions(exts);
instance.setLayers(layers);
instance.setApiVersion({1,3,0});
instance.create();
qVkInstance.setExtensions(exts);
qVkInstance.setLayers(layers);
qVkInstance.setApiVersion({1,3,0});
qVkInstance.create();
return instance.vkInstance();
return qVkInstance.vkInstance();
}
QVulkanInstance& get_qvkinstance() { return instance; }
private:
QVulkanInstance instance;
QVulkanInstance qVkInstance;
};
class QtParallelRdpWindowInfo : public ParallelRdpWindowInfo {
@@ -58,6 +57,8 @@ public:
return QVulkanInstance::surfaceForWindow(window);
}
void destroy_surface(VkInstance instance, VkSurfaceKHR surface) override { }
uint32_t get_surface_width() override {
return 640;
}
@@ -70,7 +71,9 @@ public:
return true;
}
void poll_input() override { }
void poll_input() override {
SDL_PumpEvents();
}
void event_frame_tick(double frame, double elapsed) override { }
@@ -93,8 +96,8 @@ public:
[[nodiscard]] QPaintEngine* paintEngine() const override {
return nullptr;
}
private:
std::unique_ptr<ParallelRdpWindowInfo> windowInfo;
std::unique_ptr<Vulkan::WSIPlatform> wsiPlatform;
QtInstanceFactory instance;
std::unique_ptr<QtInstanceFactory> instance;
};

View File

@@ -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>RenderWidget</class>
<extends>QWidget</extends>
<header>RenderWidget.hpp</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>