Rename Window to GameWindow. Fix guest pointers.

This commit is contained in:
Dario 2024-12-16 13:46:53 -03:00
parent 1a9ce72762
commit 6d7103b818
17 changed files with 63 additions and 64 deletions

View file

@ -153,7 +153,7 @@ set(SWA_UI_CXX_SOURCES
"ui/options_menu_thumbnails.cpp"
"ui/options_menu.cpp"
"ui/sdl_listener.cpp"
"ui/window.cpp"
"ui/game_window.cpp"
)
set(SWA_INSTALL_CXX_SOURCES

View file

@ -1,7 +1,7 @@
#include <app.h>
#include <install/installer.h>
#include <kernel/function.h>
#include <ui/window.h>
#include <ui/game_window.h>
#include <patches/audio_patches.h>
#include <user/config.h>
#include <os/process.h>
@ -41,7 +41,7 @@ PPC_FUNC(sub_822C1130)
SDL_PumpEvents();
SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT);
Window::Update();
GameWindow::Update();
AudioPatches::Update(App::s_deltaTime);
__imp__sub_822C1130(ctx, base);

View file

@ -4,7 +4,7 @@
#include <kernel/memory.h>
#include <cpu/guest_stack_var.h>
#include <ui/installer_wizard.h>
#include <ui/window.h>
#include <ui/game_window.h>
#include <api/boost/smart_ptr/shared_ptr.h>
SWA_API void Game_PlaySound(const char* pName)
@ -31,5 +31,5 @@ SWA_API void Game_PlaySound(const char* pName)
SWA_API void Window_SetFullscreen(bool isEnabled)
{
Window::SetFullscreen(isEnabled);
GameWindow::SetFullscreen(isEnabled);
}

View file

@ -19,9 +19,7 @@
#elif defined(__ANDROID__)
#include "android/native_window.h"
#elif defined(__linux__)
#define Window X11Window
#include "X11/Xlib.h"
#undef Window
#undef None
#undef Status
#undef LockMask
@ -40,7 +38,7 @@ namespace plume {
#elif defined(__linux__)
struct RenderWindow {
Display* display;
X11Window* window;
Window* window;
bool operator==(const struct RenderWindow& rhs) const {
return display == rhs.display && window == rhs.window;
}

View file

@ -26,7 +26,7 @@
#include <ui/message_window.h>
#include <ui/options_menu.h>
#include <ui/sdl_listener.h>
#include <ui/window.h>
#include <ui/game_window.h>
#include <user/config.h>
#include <xxHashMap.h>
@ -1041,7 +1041,7 @@ static void ProcSetRenderState(const RenderCommand& cmd)
}
}
static const std::pair<GuestRenderState, void*> g_setRenderStateFunctions[] =
static const std::pair<GuestRenderState, PPCFunc*> g_setRenderStateFunctions[] =
{
{ D3DRS_ZENABLE, HostToGuestFunction<SetRenderState<D3DRS_ZENABLE>> },
{ D3DRS_ZWRITEENABLE, HostToGuestFunction<SetRenderState<D3DRS_ZWRITEENABLE>> },
@ -1096,11 +1096,13 @@ static std::unique_ptr<GuestShader> g_enhancedMotionBlurShader;
#endif
#ifdef _WIN32
static bool DetectWine()
{
HMODULE dllHandle = GetModuleHandle("ntdll.dll");
return dllHandle != nullptr && GetProcAddress(dllHandle, "wine_get_version") != nullptr;
}
#endif
static constexpr size_t TEXTURE_DESCRIPTOR_SIZE = 65536;
static constexpr size_t SAMPLER_DESCRIPTOR_SIZE = 1024;
@ -1163,7 +1165,7 @@ static void CreateImGuiBackend()
OptionsMenu::Init();
InstallerWizard::Init();
ImGui_ImplSDL2_InitForOther(Window::s_pWindow);
ImGui_ImplSDL2_InitForOther(GameWindow::s_pWindow);
#ifdef ENABLE_IM_FONT_ATLAS_SNAPSHOT
g_imFontTexture = LoadTexture(
@ -1313,7 +1315,7 @@ void Video::CreateHostDevice()
IMGUI_CHECKVERSION();
ImGui::CreateContext();
Window::Init();
GameWindow::Init();
#ifdef SWA_D3D12
g_vulkan = DetectWine() || Config::GraphicsAPI == EGraphicsAPI::Vulkan;
@ -1358,7 +1360,7 @@ void Video::CreateHostDevice()
break;
}
g_swapChain = g_queue->createSwapChain(Window::s_handle, bufferCount, BACKBUFFER_FORMAT);
g_swapChain = g_queue->createSwapChain(GameWindow::s_handle, bufferCount, BACKBUFFER_FORMAT);
g_swapChain->setVsyncEnabled(Config::VSync);
g_swapChainValid = !g_swapChain->needsResize();

View file

@ -2,7 +2,7 @@
#include <SDL.h>
#include <user/config.h>
#include <hid/hid_detail.h>
#include <ui/window.h>
#include <ui/game_window.h>
#include <kernel/xdm.h>
#define TRANSLATE_INPUT(S, X) SDL_GameControllerGetButton(controller, S) << FirstBitLow(X)
@ -66,7 +66,7 @@ public:
bool CanPoll()
{
return controller && (Window::s_isFocused || Config::AllowBackgroundInput);
return controller && (GameWindow::s_isFocused || Config::AllowBackgroundInput);
}
void PollAxis()

View file

@ -2,7 +2,7 @@
#include "xam.h"
#include "xdm.h"
#include <hid/hid.h>
#include <ui/window.h>
#include <ui/game_window.h>
#include <cpu/guest_thread.h>
#include <ranges>
#include <unordered_set>
@ -232,7 +232,6 @@ SWA_API uint32_t XamShowMessageBoxUI(uint32_t dwUserIndex, be<uint16_t>* wszTitl
TASKDIALOGCONFIG config{};
config.cbSize = sizeof(config);
// config.hwndParent = Window::s_hWnd;
config.pszWindowTitle = texts[0].c_str();
config.pszContent = texts[1].c_str();
config.cButtons = cButtons;
@ -406,7 +405,7 @@ SWA_API uint32_t XamInputGetState(uint32_t userIndex, uint32_t flags, XAMINPUT_S
uint32_t result = hid::GetState(userIndex, state);
if (Window::s_isFocused)
if (GameWindow::s_isFocused)
{
auto keyboardState = SDL_GetKeyboardState(NULL);

View file

@ -1,6 +1,6 @@
#include <cpu/guest_code.h>
#include <api/SWA.h>
#include <ui/window.h>
#include <ui/game_window.h>
#include <user/config.h>
constexpr float m_baseAspectRatio = 16.0f / 9.0f;
@ -8,7 +8,7 @@ constexpr float m_baseAspectRatio = 16.0f / 9.0f;
bool CameraAspectRatioMidAsmHook(PPCRegister& r31)
{
auto pCamera = (SWA::CCamera*)g_memory.Translate(r31.u32);
auto newAspectRatio = (float)Window::s_width / (float)Window::s_height;
auto newAspectRatio = (float)GameWindow::s_width / (float)GameWindow::s_height;
// Dynamically adjust horizontal aspect ratio to window dimensions.
pCamera->m_HorzAspectRatio = newAspectRatio;
@ -27,7 +27,7 @@ bool CameraBoostAspectRatioMidAsmHook(PPCRegister& r31, PPCRegister& f0, PPCRegi
{
auto pCamera = (SWA::CCamera*)g_memory.Translate(r31.u32);
if (Window::s_width < Window::s_height)
if (GameWindow::s_width < GameWindow::s_height)
{
pCamera->m_VertFieldOfView = pCamera->m_HorzFieldOfView + f10.f64;
}

View file

@ -1,6 +1,6 @@
#include <cpu/guest_code.h>
#include <api/SWA.h>
#include <ui/window.h>
#include <ui/game_window.h>
#include <user/config.h>
#include <app.h>

View file

@ -1,6 +1,6 @@
#include <cpu/guest_code.h>
#include <api/SWA.h>
#include <ui/window.h>
#include <ui/game_window.h>
#include <user/achievement_data.h>
#include <user/config.h>

View file

@ -1,6 +1,6 @@
#include <cpu/guest_code.h>
#include <api/SWA.h>
#include <ui/window.h>
#include <ui/game_window.h>
#include <ui/window_events.h>
#include <user/config.h>
#include <os/logger.h>
@ -126,7 +126,7 @@ PPC_FUNC(sub_823B49D8)
{
__imp__sub_823B49D8(ctx, base);
SDL_User_EvilSonic(Window::s_pWindow, true);
SDL_User_EvilSonic(GameWindow::s_pWindow, true);
}
// SWA::Player::CEvilSonicContext::Dtor
@ -135,5 +135,5 @@ PPC_FUNC(sub_823B4590)
{
__imp__sub_823B4590(ctx, base);
SDL_User_EvilSonic(Window::s_pWindow, false);
SDL_User_EvilSonic(GameWindow::s_pWindow, false);
}

View file

@ -1,7 +1,7 @@
#include <cpu/guest_code.h>
#include <user/config.h>
#include <api/SWA.h>
#include <ui/window.h>
#include <ui/game_window.h>
// TODO: to be removed.
constexpr float m_baseAspectRatio = 16.0f / 9.0f;
@ -12,7 +12,7 @@ void CSDAspectRatioMidAsmHook(PPCRegister& f1, PPCRegister& f2)
if (Config::UIScaleMode == EUIScaleMode::Stretch)
return;
auto newAspectRatio = (float)Window::s_width / (float)Window::s_height;
auto newAspectRatio = (float)GameWindow::s_width / (float)GameWindow::s_height;
if (newAspectRatio > m_baseAspectRatio)
{

View file

@ -1,4 +1,4 @@
#include "window.h"
#include "game_window.h"
#include "sdl_listener.h"
#include <user/config.h>
#include <SDL_syswm.h>
@ -31,10 +31,10 @@ int Window_OnSDLEvent(void*, SDL_Event* event)
if (!(event->key.keysym.mod & KMOD_ALT) || !m_isFullscreenKeyReleased)
break;
Config::Fullscreen = Window::SetFullscreen(!Window::IsFullscreen());
Config::Fullscreen = GameWindow::SetFullscreen(!GameWindow::IsFullscreen());
if (!Config::Fullscreen)
Config::WindowState = Window::SetMaximised(Config::WindowState == EWindowState::Maximised);
Config::WindowState = GameWindow::SetMaximised(Config::WindowState == EWindowState::Maximised);
// Block holding ALT+ENTER spamming window changes.
m_isFullscreenKeyReleased = false;
@ -44,17 +44,17 @@ int Window_OnSDLEvent(void*, SDL_Event* event)
// Restore original window dimensions on F2.
case SDLK_F2:
Config::Fullscreen = Window::SetFullscreen(false);
Window::SetDimensions(DEFAULT_WIDTH, DEFAULT_HEIGHT);
Config::Fullscreen = GameWindow::SetFullscreen(false);
GameWindow::SetDimensions(DEFAULT_WIDTH, DEFAULT_HEIGHT);
break;
// Recentre window on F3.
case SDLK_F3:
{
if (Window::IsFullscreen())
if (GameWindow::IsFullscreen())
break;
Window::SetDimensions(Window::s_width, Window::s_height);
GameWindow::SetDimensions(GameWindow::s_width, GameWindow::s_height);
break;
}
@ -79,16 +79,16 @@ int Window_OnSDLEvent(void*, SDL_Event* event)
switch (event->window.event)
{
case SDL_WINDOWEVENT_FOCUS_LOST:
Window::s_isFocused = false;
GameWindow::s_isFocused = false;
SDL_ShowCursor(SDL_ENABLE);
break;
case SDL_WINDOWEVENT_FOCUS_GAINED:
{
Window::s_isFocused = true;
GameWindow::s_isFocused = true;
if (Window::IsFullscreen())
SDL_ShowCursor(Window::s_isFullscreenCursorVisible ? SDL_ENABLE : SDL_DISABLE);
if (GameWindow::IsFullscreen())
SDL_ShowCursor(GameWindow::s_isFullscreenCursorVisible ? SDL_ENABLE : SDL_DISABLE);
break;
}
@ -103,14 +103,14 @@ int Window_OnSDLEvent(void*, SDL_Event* event)
case SDL_WINDOWEVENT_RESIZED:
m_isResizing = true;
Window::s_width = event->window.data1;
Window::s_height = event->window.data2;
Window::SetTitle(fmt::format("{} - [{}x{}]", Window::GetTitle(), Window::s_width, Window::s_height).c_str());
GameWindow::s_width = event->window.data1;
GameWindow::s_height = event->window.data2;
GameWindow::SetTitle(fmt::format("{} - [{}x{}]", GameWindow::GetTitle(), GameWindow::s_width, GameWindow::s_height).c_str());
break;
case SDL_WINDOWEVENT_MOVED:
Window::s_x = event->window.data1;
Window::s_y = event->window.data2;
GameWindow::s_x = event->window.data1;
GameWindow::s_y = event->window.data2;
break;
}
@ -119,13 +119,13 @@ int Window_OnSDLEvent(void*, SDL_Event* event)
case SDL_USER_EVILSONIC:
{
Window::s_isIconNight = event->user.code;
Window::SetIcon(Window::s_isIconNight);
GameWindow::s_isIconNight = event->user.code;
GameWindow::SetIcon(GameWindow::s_isIconNight);
break;
}
}
if (!Window::IsFullscreen())
if (!GameWindow::IsFullscreen())
{
if (event->type == SDL_CONTROLLERBUTTONDOWN || event->type == SDL_CONTROLLERBUTTONUP || event->type == SDL_CONTROLLERAXISMOTION)
{
@ -142,7 +142,7 @@ int Window_OnSDLEvent(void*, SDL_Event* event)
return 0;
}
void Window::Init()
void GameWindow::Init()
{
SDL_InitSubSystem(SDL_INIT_VIDEO);
SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE);
@ -194,14 +194,14 @@ void Window::Init()
SDL_ShowWindow(s_pWindow);
}
void Window::Update()
void GameWindow::Update()
{
if (!Window::IsFullscreen() && !Window::IsMaximised())
if (!GameWindow::IsFullscreen() && !GameWindow::IsMaximised())
{
Config::WindowX = Window::s_x;
Config::WindowY = Window::s_y;
Config::WindowWidth = Window::s_width;
Config::WindowHeight = Window::s_height;
Config::WindowX = GameWindow::s_x;
Config::WindowY = GameWindow::s_y;
Config::WindowWidth = GameWindow::s_width;
Config::WindowHeight = GameWindow::s_height;
}
if (m_isResizing)

View file

@ -15,7 +15,7 @@
#define DEFAULT_WIDTH 1280
#define DEFAULT_HEIGHT 720
class Window
class GameWindow
{
public:
static inline SDL_Window* s_pWindow;
@ -109,7 +109,7 @@ public:
{
SDL_SetWindowFullscreen(s_pWindow, 0);
SDL_ShowCursor(SDL_ENABLE);
SetIcon(Window::s_isIconNight);
SetIcon(GameWindow::s_isIconNight);
}
return isEnabled;

View file

@ -13,7 +13,7 @@
#include <ui/button_guide.h>
#include <ui/message_window.h>
#include <ui/sdl_listener.h>
#include <ui/window.h>
#include <ui/game_window.h>
#include <decompressor.h>
#include <res/images/installer/install_001.dds.h>
@ -1439,18 +1439,18 @@ bool InstallerWizard::Run(bool skipGame)
g_currentPage = g_firstPage;
}
Window::SetFullscreenCursorVisibility(true);
GameWindow::SetFullscreenCursorVisibility(true);
s_isVisible = true;
while (s_isVisible)
{
SDL_PumpEvents();
SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT);
Window::Update();
GameWindow::Update();
Video::HostPresent();
}
Window::SetFullscreenCursorVisibility(false);
GameWindow::SetFullscreenCursorVisibility(false);
NFD_Quit();
InstallerWizard::Shutdown();

View file

@ -1,7 +1,7 @@
#include "options_menu.h"
#include "options_menu_thumbnails.h"
#include "imgui_utils.h"
#include "window.h"
#include "game_window.h"
#include "exports.h"
#include <api/SWA/System/InputState.h>
@ -971,8 +971,8 @@ static void DrawInfoPanel()
auto resScale = round(*(float*)g_selectedItem->GetValue() * 1000) / 1000;
std::snprintf(buf, sizeof(buf), desc.c_str(),
(int)((float)Window::s_width * resScale),
(int)((float)Window::s_height * resScale));
(int)((float)GameWindow::s_width * resScale),
(int)((float)GameWindow::s_height * resScale));
desc = buf;
}

View file

@ -1,7 +1,7 @@
#pragma once
#include <SDL.h>
#include "ui/window.h"
#include "ui/game_window.h"
#define SDL_USER_EVILSONIC (SDL_USEREVENT + 1)