Skip to content

Commit

Permalink
3rdParty: ifdef plugin code in rt64
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosalie241 committed May 27, 2024
1 parent 550c6ca commit 5c21ee1
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 68 deletions.
25 changes: 17 additions & 8 deletions Source/3rdParty/rt64/src/hle/rt64_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
# include "res/bluenoise/LDR_64_64_64_RGB1.h"
#endif

#if RT64_BUILD_PLUGIN
# include "api/rt64_api_common.h"
#endif

//#define TEST_RENDER_INTERFACE
//#define LOG_DISPLAY_LISTS

Expand Down Expand Up @@ -142,7 +146,13 @@ namespace RT64 {
RenderInterfaceTest(renderInterface.get());
# endif

#if 0 // TODO: fix later....
# ifdef RT64_BUILD_PLUGIN
const bool isPJ64 = (RT64::API.apiType == RT64::APIType::Project64);
if (!isPJ64) {
appWindow = std::make_unique<ApplicationWindow>();
}
else {
# endif
// Create the application window.
const char *windowTitle = "RT64";
appWindow = std::make_unique<ApplicationWindow>();
Expand All @@ -152,10 +162,11 @@ namespace RT64 {
else {
appWindow->setup(windowTitle, this);
}

# ifdef RT64_BUILD_PLUGIN
}
# endif
// Detect refresh rate from the display the window is located at.
appWindow->detectRefreshRate();
#endif

// Create the render device for the window
device = renderInterface->createDevice();
Expand All @@ -180,7 +191,7 @@ namespace RT64 {
textureComputeWorker = std::make_unique<RenderWorker>(device.get(), "Texture Compute", RenderCommandListType::COMPUTE);
workloadGraphicsWorker = std::make_unique<RenderWorker>(device.get(), "Workload Graphics", RenderCommandListType::DIRECT);
presentGraphicsWorker = std::make_unique<RenderWorker>(device.get(), "Present Graphics", RenderCommandListType::DIRECT);
swapChain = presentGraphicsWorker->commandQueue->createSwapChain(RenderWindow{}, 2, RenderFormat::B8G8R8A8_UNORM);
swapChain = presentGraphicsWorker->commandQueue->createSwapChain(appWindow->windowHandle, 2, RenderFormat::B8G8R8A8_UNORM);

// Detect if the application should use HDR framebuffers or not.
bool usesHDR;
Expand Down Expand Up @@ -268,7 +279,7 @@ namespace RT64 {
workloadQueue->setup(workloadExt);

PresentQueue::External presentExt;
presentExt.appWindow = nullptr;
presentExt.appWindow = appWindow.get();
presentExt.device = device.get();
presentExt.swapChain = swapChain.get();
presentExt.presentGraphicsWorker = presentGraphicsWorker.get();
Expand All @@ -280,7 +291,7 @@ namespace RT64 {
// Configure the state to use all the created components.
State::External stateExt;
stateExt.app = this;
stateExt.appWindow = nullptr;
stateExt.appWindow = appWindow.get();
stateExt.interpreter = interpreter.get();
stateExt.device = device.get();
stateExt.swapChain = swapChain.get();
Expand Down Expand Up @@ -559,8 +570,6 @@ namespace RT64 {
}

void Application::setFullScreen(bool fullscreen) {
#if 0
appWindow->setFullScreen(fullscreen);
#endif
}
};
2 changes: 0 additions & 2 deletions Source/3rdParty/rt64/src/hle/rt64_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ namespace RT64 {
UserPaths userPaths;
std::unique_ptr<Interpreter> interpreter;
std::unique_ptr<State> state;
#if 0 // TODO: uncomment later
std::unique_ptr<ApplicationWindow> appWindow;
#endif
std::unique_ptr<RenderDevice> device;
std::unique_ptr<RenderSwapChain> swapChain;
std::unique_ptr<RenderWorker> framebufferGraphicsWorker;
Expand Down
51 changes: 40 additions & 11 deletions Source/3rdParty/rt64/src/hle/rt64_application_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@
#if defined(_WIN32)
# include <Windows.h>
# include <ShellScalingAPI.h>
#elif defined(__linux__)
#elif defined(__linux__) && !defined(RT64_BUILD_PLUGIN)
# define Status int
# include <X11/extensions/Xrandr.h>
#endif

#if RT64_BUILD_PLUGIN
# include "api/rt64_api_common.h"
#endif

#include "common/rt64_common.h"

namespace RT64 {
Expand Down Expand Up @@ -54,6 +58,12 @@ namespace RT64 {
windowHandle = window;

# ifdef _WIN32
# ifdef RT64_BUILD_PLUGIN
const bool isPJ64 = (RT64::API.apiType == RT64::APIType::Project64);
if (!isPJ64) {
return;
}
# endif
if (listener->usesWindowMessageFilter()) {
assert(HookedApplicationWindow == nullptr);
assert(threadId != 0);
Expand All @@ -74,6 +84,12 @@ namespace RT64 {
} bounds {};

# if defined(_WIN32)
# ifdef RT64_BUILD_PLUGIN
const bool isPJ64 = (RT64::API.apiType == RT64::APIType::Project64);
if (!isPJ64) {
return;
}
# endif
SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);

RECT rect;
Expand All @@ -87,9 +103,9 @@ namespace RT64 {
bounds.top = rect.top;
bounds.width = rect.right - rect.left;
bounds.height = rect.bottom - rect.top;
# elif defined(__ANDROID__)
# elif defined(__ANDROID__) && !defined(RT64_BUILD_PLUGIN)
static_assert(false && "Android unimplemented");
# elif defined(__linux__) || defined(__APPLE__)
# elif defined(__linux__) || defined(__APPLE__) && !defined(RT64_BUILD_PLUGIN)
if (SDL_VideoInit(nullptr) != 0) {
printf("Failed to init SDL2 video: %s\n", SDL_GetError());
assert(false && "Failed to init SDL2 video");
Expand All @@ -105,12 +121,12 @@ namespace RT64 {
bounds.top = (dm.h - Height) / 2;
bounds.width = Width;
bounds.height = Height;
# else
# elif !defined(RT64_BUILD_PLUGIN)
static_assert(false && "Unimplemented");
# endif

// Create window.
#ifdef RT64_SDL_WINDOW
#if defined RT64_SDL_WINDOW && !defined(RT64_BUILD_PLUGIN)
SDL_Window *sdlWindow = SDL_CreateWindow(windowTitle, bounds.left, bounds.top, bounds.width, bounds.height, SDL_WINDOW_RESIZABLE);
SDL_SysWMinfo wmInfo;
assert(sdlWindow && "Failed to open window with SDL");
Expand All @@ -129,7 +145,7 @@ namespace RT64 {
static_assert(false && "Unimplemented");
# endif
usingSdl = true;
#else
#elif !defined(RT64_BUILD_PLUGIN)
static_assert(false && "Unimplemented");
#endif

Expand All @@ -149,6 +165,13 @@ namespace RT64 {
return;
}

# ifdef RT64_BUILD_PLUGIN
const bool isPJ64 = (RT64::API.apiType == RT64::APIType::Project64);
if (!isPJ64) {
return;
}
# endif

# ifdef _WIN32
if (newFullScreen) {
// Save if window is maximized or not
Expand Down Expand Up @@ -205,6 +228,12 @@ namespace RT64 {

void ApplicationWindow::makeResizable() {
# ifdef _WIN32
# ifdef RT64_BUILD_PLUGIN
const bool isPJ64 = (RT64::API.apiType == RT64::APIType::Project64);
if (!isPJ64) {
return;
}
# endif
LONG_PTR lStyle = GetWindowLongPtr(windowHandle, GWL_STYLE);
windowMenu = GetMenu(windowHandle);
lStyle |= WS_THICKFRAME | WS_MAXIMIZEBOX;
Expand All @@ -213,7 +242,11 @@ namespace RT64 {
}

void ApplicationWindow::detectRefreshRate() {
# if defined(_WIN32)
# if defined(RT64_BUILD_PLUGIN)
// TODO: add vidext func to mupen64plus for this....
refreshRate = 60;
return;
# elif defined(_WIN32)
HMONITOR monitor = MonitorFromWindow(windowHandle, MONITOR_DEFAULTTONEAREST);
MONITORINFOEX info = {};
info.cbSize = sizeof(info);
Expand All @@ -238,10 +271,6 @@ namespace RT64 {
refreshRate++;
}
# elif defined(__linux__)
// TODO: add vidext func....
refreshRate = 60;
return;

// Sourced from: https://stackoverflow.com/a/66865623
XRRScreenResources *screenResources = XRRGetScreenResources(windowHandle.display, windowHandle.window);
if (screenResources == nullptr) {
Expand Down
2 changes: 1 addition & 1 deletion Source/3rdParty/rt64/src/hle/rt64_present_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ namespace RT64 {
}

if (needsResize || ext.appWindow->detectWindowMoved()) {
// ext.appWindow->detectRefreshRate();
ext.appWindow->detectRefreshRate();
ext.sharedResources->setSwapChainRate(std::min(60u, displayTimingRate));
}

Expand Down
Loading

0 comments on commit 5c21ee1

Please sign in to comment.