mirror of
https://github.com/Zelda64Recomp/Zelda64Recomp
synced 2026-08-17 13:40:49 -04:00
Hooked up graphics option menu to RT64, updated RT64
This commit is contained in:
+103
-2
@@ -2,10 +2,80 @@
|
||||
#include <cstring>
|
||||
// #include <Windows.h>
|
||||
|
||||
#include "../ultramodern/ultramodern.hpp"
|
||||
#define HLSL_CPU
|
||||
#include "hle/rt64_application.h"
|
||||
#include "rt64_layer.h"
|
||||
#include "rt64_render_hooks.h"
|
||||
|
||||
typedef struct {
|
||||
// void* hWnd;
|
||||
// void* hStatusBar;
|
||||
|
||||
// int Reserved;
|
||||
|
||||
unsigned char* HEADER; /* This is the rom header (first 40h bytes of the rom) */
|
||||
unsigned char* RDRAM;
|
||||
unsigned char* DMEM;
|
||||
unsigned char* IMEM;
|
||||
|
||||
unsigned int* MI_INTR_REG;
|
||||
|
||||
unsigned int* DPC_START_REG;
|
||||
unsigned int* DPC_END_REG;
|
||||
unsigned int* DPC_CURRENT_REG;
|
||||
unsigned int* DPC_STATUS_REG;
|
||||
unsigned int* DPC_CLOCK_REG;
|
||||
unsigned int* DPC_BUFBUSY_REG;
|
||||
unsigned int* DPC_PIPEBUSY_REG;
|
||||
unsigned int* DPC_TMEM_REG;
|
||||
|
||||
unsigned int* VI_STATUS_REG;
|
||||
unsigned int* VI_ORIGIN_REG;
|
||||
unsigned int* VI_WIDTH_REG;
|
||||
unsigned int* VI_INTR_REG;
|
||||
unsigned int* VI_V_CURRENT_LINE_REG;
|
||||
unsigned int* VI_TIMING_REG;
|
||||
unsigned int* VI_V_SYNC_REG;
|
||||
unsigned int* VI_H_SYNC_REG;
|
||||
unsigned int* VI_LEAP_REG;
|
||||
unsigned int* VI_H_START_REG;
|
||||
unsigned int* VI_V_START_REG;
|
||||
unsigned int* VI_V_BURST_REG;
|
||||
unsigned int* VI_X_SCALE_REG;
|
||||
unsigned int* VI_Y_SCALE_REG;
|
||||
|
||||
void (*CheckInterrupts)(void);
|
||||
|
||||
unsigned int version;
|
||||
unsigned int* SP_STATUS_REG;
|
||||
const unsigned int* RDRAM_SIZE;
|
||||
} GFX_INFO;
|
||||
|
||||
#ifdef _WIN32
|
||||
#define DLLEXPORT extern "C" __declspec(dllexport)
|
||||
#define DLLIMPORT extern "C" __declspec(dllimport)
|
||||
#define CALL __cdecl
|
||||
#else
|
||||
#define DLLEXPORT extern "C" __attribute__((visibility("default")))
|
||||
#define DLLIMPORT extern "C"
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
extern "C" RT64::Application* InitiateGFXWindows(GFX_INFO Gfx_Info, HWND hwnd, DWORD threadId);
|
||||
#elif defined(__ANDROID__)
|
||||
static_assert(false && "Unimplemented");
|
||||
#elif defined(__linux__)
|
||||
extern "C" RT64::Application* InitiateGFXLinux(GFX_INFO Gfx_Info, Window window, Display *display);
|
||||
#else
|
||||
static_assert(false && "Unimplemented");
|
||||
#endif
|
||||
|
||||
DLLIMPORT void ProcessRDPList(void);
|
||||
DLLIMPORT void ProcessDList(void);
|
||||
DLLIMPORT void UpdateScreen(void);
|
||||
DLLIMPORT void ChangeWindow(void);
|
||||
DLLIMPORT void PluginShutdown(void);
|
||||
|
||||
static uint8_t DMEM[0x1000];
|
||||
static uint8_t IMEM[0x1000];
|
||||
|
||||
@@ -45,7 +115,7 @@ void dummy_check_interrupts() {
|
||||
|
||||
}
|
||||
|
||||
bool RT64Init(uint8_t* rom, uint8_t* rdram, ultramodern::WindowHandle window_handle) {
|
||||
RT64::Application* RT64Init(uint8_t* rom, uint8_t* rdram, ultramodern::WindowHandle window_handle) {
|
||||
set_rt64_hooks();
|
||||
// Dynamic loading
|
||||
//auto RT64 = LoadLibrary("RT64.dll");
|
||||
@@ -134,3 +204,34 @@ void RT64ChangeWindow() {
|
||||
void RT64Shutdown() {
|
||||
PluginShutdown();
|
||||
}
|
||||
|
||||
void RT64UpdateConfig(RT64::Application* application, const ultramodern::GraphicsConfig& old_config, const ultramodern::GraphicsConfig& new_config) {
|
||||
if (new_config.wm_option != old_config.wm_option) {
|
||||
application->setFullScreen(new_config.wm_option == ultramodern::WindowMode::Fullscreen);
|
||||
}
|
||||
|
||||
switch (new_config.res_option) {
|
||||
default:
|
||||
case ultramodern::Resolution::Auto:
|
||||
application->userConfig.resolution = RT64::UserConfiguration::Resolution::WindowIntegerScale;
|
||||
break;
|
||||
case ultramodern::Resolution::Original:
|
||||
application->userConfig.resolution = RT64::UserConfiguration::Resolution::Original;
|
||||
break;
|
||||
case ultramodern::Resolution::Original2x:
|
||||
application->userConfig.resolution = RT64::UserConfiguration::Resolution::Manual;
|
||||
application->userConfig.resolutionMultiplier = 2.0;
|
||||
break;
|
||||
}
|
||||
|
||||
application->userConfig.aspectRatio = new_config.ar_option;
|
||||
application->userConfig.antialiasing = new_config.msaa_option;
|
||||
application->userConfig.refreshRate = new_config.rr_option;
|
||||
application->userConfig.refreshRateTarget = new_config.rr_manual_value;
|
||||
|
||||
application->updateUserConfig(true);
|
||||
|
||||
if (new_config.msaa_option != old_config.msaa_option) {
|
||||
application->updateMultisampling();
|
||||
}
|
||||
}
|
||||
|
||||
+85
-1
@@ -2,6 +2,8 @@
|
||||
|
||||
#include "recomp_ui.h"
|
||||
#include "../../ultramodern/ultramodern.hpp"
|
||||
#include "../../ultramodern/config.hpp"
|
||||
#include "common/rt64_user_configuration.h"
|
||||
|
||||
#include "nfd.h"
|
||||
#include "RmlUi/Core.h"
|
||||
@@ -36,15 +38,97 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
NLOHMANN_JSON_SERIALIZE_ENUM(ultramodern::Resolution, {
|
||||
{ultramodern::Resolution::Original, "Original"},
|
||||
{ultramodern::Resolution::Original2x, "Original2x"},
|
||||
{ultramodern::Resolution::Auto, "Auto"},
|
||||
});
|
||||
|
||||
NLOHMANN_JSON_SERIALIZE_ENUM(ultramodern::WindowMode, {
|
||||
{ultramodern::WindowMode::Windowed, "Windowed"},
|
||||
{ultramodern::WindowMode::Fullscreen, "Fullscreen"}
|
||||
});
|
||||
|
||||
ultramodern::GraphicsConfig cur_options;
|
||||
ultramodern::GraphicsConfig new_options;
|
||||
Rml::DataModelHandle options_handle;
|
||||
|
||||
template <typename T>
|
||||
void get_option(const T& input, Rml::Variant& output) {
|
||||
std::string value = "";
|
||||
to_json(value, input);
|
||||
|
||||
if (value.empty()) {
|
||||
throw std::runtime_error("Invalid value :" + std::to_string(int(input)));
|
||||
}
|
||||
|
||||
output = value;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void set_option(T& output, const Rml::Variant& input) {
|
||||
T value = T::OptionCount;
|
||||
from_json(input.Get<std::string>(), value);
|
||||
|
||||
if (value == T::OptionCount) {
|
||||
throw std::runtime_error("Invalid value :" + input.Get<std::string>());
|
||||
}
|
||||
|
||||
output = value;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void bind_option(Rml::DataModelConstructor& constructor, const std::string& name, T* option) {
|
||||
constructor.BindFunc(name,
|
||||
[option](Rml::Variant& out) { get_option(*option, out); },
|
||||
[option](const Rml::Variant& in) { set_option(*option, in); options_handle.DirtyVariable("options_changed"); }
|
||||
);
|
||||
};
|
||||
|
||||
void recomp::make_ui_bindings(Rml::Context* context) {
|
||||
Rml::DataModelConstructor constructor = context->CreateDataModel("graphics_model");
|
||||
if (!constructor) {
|
||||
throw std::runtime_error("Failed to make RmlUi data model constructor");
|
||||
}
|
||||
|
||||
bind_option(constructor, "res_option", &new_options.res_option);
|
||||
bind_option(constructor, "wm_option", &new_options.wm_option);
|
||||
bind_option(constructor, "ar_option", &new_options.ar_option);
|
||||
bind_option(constructor, "msaa_option", &new_options.msaa_option);
|
||||
bind_option(constructor, "rr_option", &new_options.rr_option);
|
||||
constructor.BindFunc("rr_manual_value",
|
||||
[](Rml::Variant& out) {
|
||||
out = new_options.rr_manual_value;
|
||||
},
|
||||
[](const Rml::Variant& in) {
|
||||
new_options.rr_manual_value = in.Get<int>();
|
||||
options_handle.DirtyVariable("options_changed");
|
||||
});
|
||||
|
||||
constructor.BindFunc("options_changed",
|
||||
[](Rml::Variant& out) {
|
||||
out = (cur_options != new_options);
|
||||
});
|
||||
|
||||
options_handle = constructor.GetModelHandle();
|
||||
}
|
||||
|
||||
std::unique_ptr<Rml::EventListenerInstancer> recomp::make_event_listener_instancer() {
|
||||
std::unique_ptr<UiEventListenerInstancer> ret = std::make_unique<UiEventListenerInstancer>();
|
||||
|
||||
ret->register_event("start_game",
|
||||
[](Rml::Event& event) {
|
||||
ultramodern::start_game(0);
|
||||
set_current_menu(Menu::None);
|
||||
set_current_menu(Menu::Config);
|
||||
}
|
||||
);
|
||||
|
||||
ret->register_event("apply_options",
|
||||
[](Rml::Event& event) {
|
||||
cur_options = new_options;
|
||||
options_handle.DirtyVariable("options_changed");
|
||||
update_graphics_config(new_options);
|
||||
});
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
+20
-3
@@ -565,7 +565,7 @@ public:
|
||||
};
|
||||
|
||||
bool can_focus(Rml::Element* element) {
|
||||
return element->GetProperty(Rml::PropertyId::TabIndex)->Get<Rml::Style::TabIndex>() != Rml::Property(Rml::Style::TabIndex::None);
|
||||
return element->GetOwnerDocument() != nullptr && element->GetProperty(Rml::PropertyId::TabIndex)->Get<Rml::Style::TabIndex>() != Rml::Property(Rml::Style::TabIndex::None);
|
||||
}
|
||||
|
||||
Rml::Element* get_target(Rml::ElementDocument* document, Rml::Element* element) {
|
||||
@@ -660,7 +660,20 @@ struct {
|
||||
// Revert focus to the previous element if focused on anything without a tab index.
|
||||
// This should prevent the user from losing focus on something that has no navigation.
|
||||
if (focused && !can_focus(focused)) {
|
||||
prev_focused->Focus();
|
||||
// If the previously focused element is still accepting focus, return focus to it.
|
||||
if (prev_focused && can_focus(prev_focused)) {
|
||||
prev_focused->Focus();
|
||||
}
|
||||
// Otherwise, check if the currently focused element has a "nav-return" attribute and focus that attribute's value if so.
|
||||
else {
|
||||
Rml::Variant* nav_return = focused->GetAttribute("nav-return");
|
||||
if (nav_return && nav_return->GetType() == Rml::Variant::STRING) {
|
||||
Rml::Element* return_element = current_document->GetElementById(nav_return->Get<std::string>());
|
||||
if (return_element) {
|
||||
return_element->Focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
prev_focused = current_document->GetFocusLeafNode();
|
||||
@@ -693,6 +706,7 @@ void init_hook(RT64::RenderInterface* interface, RT64::RenderDevice* device) {
|
||||
SDL_GetWindowSizeInPixels(window, &width, &height);
|
||||
|
||||
UIContext.rml.context = Rml::CreateContext("main", Rml::Vector2i(width, height));
|
||||
recomp::make_ui_bindings(UIContext.rml.context);
|
||||
|
||||
Rml::Debugger::Initialise(UIContext.rml.context);
|
||||
|
||||
@@ -730,7 +744,7 @@ bool recomp::try_deque_event(SDL_Event& out) {
|
||||
return ui_event_queue.try_dequeue(out);
|
||||
}
|
||||
|
||||
std::atomic<recomp::Menu> open_menu = recomp::Menu::Config;//Launcher;
|
||||
std::atomic<recomp::Menu> open_menu = recomp::Menu::Launcher;
|
||||
|
||||
void draw_hook(RT64::RenderCommandList* command_list, RT64::RenderTexture* swap_chain_texture) {
|
||||
int num_keys;
|
||||
@@ -778,6 +792,9 @@ void draw_hook(RT64::RenderCommandList* command_list, RT64::RenderTexture* swap_
|
||||
int width, height;
|
||||
SDL_GetWindowSizeInPixels(window, &width, &height);
|
||||
|
||||
// Scale the UI based on the window size with 720 vertical resolution as the reference point.
|
||||
UIContext.rml.context->SetDensityIndependentPixelRatio(height / 720.0f);
|
||||
|
||||
UIContext.rml.render_interface->start(command_list, width, height);
|
||||
|
||||
static int prev_width = 0;
|
||||
|
||||
Reference in New Issue
Block a user