mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2024-12-23 08:38:52 -05:00
Cleans up Window class.
This commit is contained in:
parent
10ce3c88fb
commit
f9621dcc17
@ -138,8 +138,6 @@ set(Source_Files__Globals
|
||||
"LUSMacros.h"
|
||||
"Window.cpp"
|
||||
"Window.h"
|
||||
"WindowShim.cpp"
|
||||
"WindowShim.h"
|
||||
)
|
||||
source_group("Source Files\\Globals" FILES ${Source_Files__Globals})
|
||||
|
||||
|
@ -12,14 +12,23 @@
|
||||
#include "AudioPlayer.h"
|
||||
#include "Hooks.h"
|
||||
#include "UltraController.h"
|
||||
#include "Lib/Fast3D/gfx_pc.h"
|
||||
#include "Lib/Fast3D/gfx_sdl.h"
|
||||
#include "Lib/Fast3D/gfx_opengl.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include "Console.h"
|
||||
#include "ImGuiImpl.h"
|
||||
#include "PR/ultra64/gbi.h"
|
||||
#include "Lib/Fast3D/gfx_pc.h"
|
||||
#include "Lib/Fast3D/gfx_sdl.h"
|
||||
#include "Lib/Fast3D/gfx_dxgi.h"
|
||||
#include "Lib/Fast3D/gfx_glx.h"
|
||||
#include "Lib/Fast3D/gfx_opengl.h"
|
||||
#include "Lib/Fast3D/gfx_direct3d11.h"
|
||||
#include "Lib/Fast3D/gfx_direct3d12.h"
|
||||
#include "Lib/Fast3D/gfx_wiiu.h"
|
||||
#include "Lib/Fast3D/gfx_gx2.h"
|
||||
#include "Lib/Fast3D/gfx_window_manager_api.h"
|
||||
#include <string>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@ -206,13 +215,8 @@ extern "C" {
|
||||
}
|
||||
}
|
||||
|
||||
extern GfxWindowManagerAPI gfx_sdl;
|
||||
void SetWindowManager(GfxWindowManagerAPI** WmApi, GfxRenderingAPI** RenderingApi, const std::string& gfx_backend);
|
||||
|
||||
namespace Ship {
|
||||
|
||||
int32_t Window::lastScancode;
|
||||
|
||||
Window::Window(std::shared_ptr<GlobalCtx2> Context) : Context(Context), APlayer(nullptr), ControllerApi(nullptr) {
|
||||
WmApi = nullptr;
|
||||
RenderingApi = nullptr;
|
||||
@ -265,8 +269,8 @@ namespace Ship {
|
||||
}
|
||||
|
||||
dwMenubar = pConf->getBool("Window.Options", false);
|
||||
const std::string& gfx_backend = pConf->getString("Window.GfxBackend");
|
||||
SetWindowManager(&WmApi, &RenderingApi, gfx_backend);
|
||||
gfxBackend = pConf->getString("Window.GfxBackend");
|
||||
InitializeWindowManager();
|
||||
|
||||
gfx_init(WmApi, RenderingApi, GetContext()->GetName().c_str(), bIsFullscreen, dwWidth, dwHeight);
|
||||
WmApi->set_fullscreen_changed_callback(OnFullscreenChanged);
|
||||
@ -332,12 +336,7 @@ namespace Ship {
|
||||
GlobalCtx2::GetInstance()->GetWindow()->ToggleFullscreen();
|
||||
}
|
||||
|
||||
// OTRTODO: Rig with Kirito's console?
|
||||
//if (dwScancode == Ship::stoi(Conf["KEYBOARD SHORTCUTS"]["KEY_CONSOLE"])) {
|
||||
// ToggleConsole();
|
||||
//}
|
||||
|
||||
lastScancode = -1;
|
||||
GlobalCtx2::GetInstance()->GetWindow()->SetLastScancode(-1);
|
||||
|
||||
bool bIsProcessed = false;
|
||||
auto controlDeck = GlobalCtx2::GetInstance()->GetWindow()->GetControlDeck();
|
||||
@ -361,7 +360,7 @@ namespace Ship {
|
||||
}
|
||||
}
|
||||
|
||||
lastScancode = dwScancode;
|
||||
GlobalCtx2::GetInstance()->GetWindow()->SetLastScancode(dwScancode);
|
||||
|
||||
return bIsProcessed;
|
||||
}
|
||||
@ -405,6 +404,52 @@ namespace Ship {
|
||||
#endif
|
||||
}
|
||||
|
||||
void Window::InitializeWindowManager() {
|
||||
// First set default
|
||||
#ifdef ENABLE_OPENGL
|
||||
RenderingApi = &gfx_opengl_api;
|
||||
#if defined(__linux__) && defined(X11_SUPPORTED)
|
||||
// LINUX_TODO:
|
||||
// *WmApi = &gfx_glx;
|
||||
WmApi = &gfx_sdl;
|
||||
#else
|
||||
WmApi = &gfx_sdl;
|
||||
#endif
|
||||
#endif
|
||||
#ifdef ENABLE_DX12
|
||||
RenderingApi = &gfx_direct3d12_api;
|
||||
WmApi = &gfx_dxgi_api;
|
||||
#endif
|
||||
#ifdef ENABLE_DX11
|
||||
RenderingApi = &gfx_direct3d11_api;
|
||||
WmApi = &gfx_dxgi_api;
|
||||
#endif
|
||||
#ifdef __WIIU__
|
||||
RenderingApi = &gfx_gx2_api;
|
||||
WmApi = &gfx_wiiu;
|
||||
#endif
|
||||
|
||||
// Config can override
|
||||
#ifdef ENABLE_DX11
|
||||
if (gfxBackend == "dx11") {
|
||||
RenderingApi = &gfx_direct3d11_api;
|
||||
WmApi = &gfx_dxgi_api;
|
||||
}
|
||||
#endif
|
||||
#ifdef ENABLE_OPENGL
|
||||
if (gfxBackend == "sdl") {
|
||||
RenderingApi = &gfx_opengl_api;
|
||||
WmApi = &gfx_sdl;
|
||||
}
|
||||
#if defined(__linux__) && defined(X11_SUPPORTED)
|
||||
if (gfxBackend == "glx") {
|
||||
RenderingApi = &gfx_opengl_api;
|
||||
WmApi = &gfx_glx;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void Window::InitializeControlDeck() {
|
||||
ControllerApi = std::make_shared<ControlDeck>();
|
||||
}
|
||||
|
@ -2,11 +2,9 @@
|
||||
#include <memory>
|
||||
#include "PR/ultra64/gbi.h"
|
||||
#include "Lib/Fast3D/gfx_pc.h"
|
||||
#include "UltraController.h"
|
||||
#include "Controller.h"
|
||||
#include "GlobalCtx2.h"
|
||||
#include "ControlDeck.h"
|
||||
#include <string>
|
||||
|
||||
#include "Lib/Fast3D/gfx_window_manager_api.h"
|
||||
|
||||
@ -15,8 +13,6 @@ namespace Ship {
|
||||
|
||||
class Window {
|
||||
public:
|
||||
static int32_t lastScancode;
|
||||
|
||||
Window(std::shared_ptr<GlobalCtx2> Context);
|
||||
~Window();
|
||||
void CreateDefaults();
|
||||
@ -40,6 +36,8 @@ namespace Ship {
|
||||
std::shared_ptr<GlobalCtx2> GetContext() { return Context.lock(); }
|
||||
std::shared_ptr<AudioPlayer> GetAudioPlayer() { return APlayer; }
|
||||
const char* GetKeyName(int scancode) { return WmApi->get_key_name(scancode); }
|
||||
int32_t GetLastScancode() { return lastScancode; };
|
||||
void SetLastScancode(int32_t scanCode) { lastScancode = scanCode; };
|
||||
|
||||
protected:
|
||||
private:
|
||||
@ -47,12 +45,15 @@ namespace Ship {
|
||||
static bool KeyUp(int32_t dwScancode);
|
||||
static void AllKeysUp(void);
|
||||
static void OnFullscreenChanged(bool bIsNowFullscreen);
|
||||
|
||||
void InitializeControlDeck();
|
||||
void InitializeAudioPlayer();
|
||||
void InitializeWindowManager();
|
||||
|
||||
std::weak_ptr<GlobalCtx2> Context;
|
||||
std::shared_ptr<AudioPlayer> APlayer;
|
||||
std::shared_ptr<ControlDeck> ControllerApi;
|
||||
std::string gfxBackend;
|
||||
|
||||
GfxRenderingAPI* RenderingApi;
|
||||
GfxWindowManagerAPI* WmApi;
|
||||
@ -60,5 +61,6 @@ namespace Ship {
|
||||
uint32_t dwWidth;
|
||||
uint32_t dwHeight;
|
||||
uint32_t dwMenubar;
|
||||
int32_t lastScancode;
|
||||
};
|
||||
}
|
||||
|
@ -1,67 +0,0 @@
|
||||
#include "PR/ultra64/gbi.h"
|
||||
#include "Lib/Fast3D/gfx_pc.h"
|
||||
#include "Lib/Fast3D/gfx_sdl.h"
|
||||
#include "Lib/Fast3D/gfx_dxgi.h"
|
||||
#include "Lib/Fast3D/gfx_glx.h"
|
||||
#include "Lib/Fast3D/gfx_opengl.h"
|
||||
#include "Lib/Fast3D/gfx_direct3d11.h"
|
||||
#include "Lib/Fast3D/gfx_direct3d12.h"
|
||||
#include "Lib/Fast3D/gfx_wiiu.h"
|
||||
#include "Lib/Fast3D/gfx_gx2.h"
|
||||
#include "Lib/Fast3D/gfx_window_manager_api.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
/*
|
||||
* Begin shims for gfx_pc.cpp. Eventually, a file from SOH repo should be moved in here.
|
||||
*/
|
||||
|
||||
/*
|
||||
* End empty shims
|
||||
*/
|
||||
|
||||
void SetWindowManager(struct GfxWindowManagerAPI** WmApi, struct GfxRenderingAPI** RenderingApi, const std::string& gfx_backend) {
|
||||
// First set default
|
||||
#ifdef ENABLE_OPENGL
|
||||
*RenderingApi = &gfx_opengl_api;
|
||||
#if defined(__linux__) && defined(X11_SUPPORTED)
|
||||
// LINUX_TODO:
|
||||
// *WmApi = &gfx_glx;
|
||||
*WmApi = &gfx_sdl;
|
||||
#else
|
||||
*WmApi = &gfx_sdl;
|
||||
#endif
|
||||
#endif
|
||||
#ifdef ENABLE_DX12
|
||||
*RenderingApi = &gfx_direct3d12_api;
|
||||
*WmApi = &gfx_dxgi_api;
|
||||
#endif
|
||||
#ifdef ENABLE_DX11
|
||||
*RenderingApi = &gfx_direct3d11_api;
|
||||
*WmApi = &gfx_dxgi_api;
|
||||
#endif
|
||||
#ifdef __WIIU__
|
||||
*RenderingApi = &gfx_gx2_api;
|
||||
*WmApi = &gfx_wiiu;
|
||||
#endif
|
||||
|
||||
// Config can override
|
||||
#ifdef ENABLE_DX11
|
||||
if (gfx_backend == "dx11") {
|
||||
*RenderingApi = &gfx_direct3d11_api;
|
||||
*WmApi = &gfx_dxgi_api;
|
||||
}
|
||||
#endif
|
||||
#ifdef ENABLE_OPENGL
|
||||
if (gfx_backend == "sdl") {
|
||||
*RenderingApi = &gfx_opengl_api;
|
||||
*WmApi = &gfx_sdl;
|
||||
}
|
||||
#if defined(__linux__) && defined(X11_SUPPORTED)
|
||||
if (gfx_backend == "glx") {
|
||||
*RenderingApi = &gfx_opengl_api;
|
||||
*WmApi = &gfx_glx;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
@ -1 +0,0 @@
|
||||
#pragma once
|
@ -243,8 +243,8 @@ extern "C" void Graph_ProcessFrame(void (*run_one_game_iter)(void)) {
|
||||
extern "C" void Graph_StartFrame() {
|
||||
#ifndef __WIIU__
|
||||
// Why -1?
|
||||
int32_t dwScancode = OTRGlobals::Instance->context->GetWindow()->lastScancode;
|
||||
OTRGlobals::Instance->context->GetWindow()->lastScancode = -1;
|
||||
int32_t dwScancode = OTRGlobals::Instance->context->GetWindow()->GetLastScancode();
|
||||
OTRGlobals::Instance->context->GetWindow()->SetLastScancode(-1);
|
||||
|
||||
switch (dwScancode - 1) {
|
||||
case SDL_SCANCODE_F5: {
|
||||
@ -374,16 +374,6 @@ extern "C" uint16_t OTRGetPixelDepth(float x, float y) {
|
||||
return OTRGlobals::Instance->context->GetWindow()->GetPixelDepth(x, y);
|
||||
}
|
||||
|
||||
extern "C" int32_t OTRGetLastScancode()
|
||||
{
|
||||
return OTRGlobals::Instance->context->GetWindow()->lastScancode;
|
||||
}
|
||||
|
||||
extern "C" void OTRResetScancode()
|
||||
{
|
||||
OTRGlobals::Instance->context->GetWindow()->lastScancode = -1;
|
||||
}
|
||||
|
||||
extern "C" uint32_t ResourceMgr_GetGameVersion()
|
||||
{
|
||||
return OTRGlobals::Instance->context->GetResourceManager()->GetGameVersion();
|
||||
|
Loading…
Reference in New Issue
Block a user