LUS Cleanup: Merge Window and GlobalCtx2 classes. (#1259)

* Merges GlobalCtx2 and Window classes.

* Includes condition variable in File.

* add mac specific include

* sstream to get past "implicit instantiation of undefined template" error

* switch/wiiu includes

* that file doesn't exist

* more wii u globalctx2 stuff

Co-authored-by: briaguya <briaguya@alice>
This commit is contained in:
Kenix3 2022-08-21 21:08:01 -04:00 committed by GitHub
commit 51e4485966
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
35 changed files with 349 additions and 419 deletions

View file

@ -1,7 +1,3 @@
#ifdef _MSC_VER
#define NOGDI
#endif
#include "debugconsole.h"
#include "../libultraship/ImGuiImpl.h"
#include "savestates.h"

View file

@ -6,9 +6,7 @@
#include "rando_main.hpp"
// #include <soh/Enhancements/randomizer.h>
#include <Cvar.h>
#define NOGDI
#define WIN32_LEAN_AND_MEAN
#include <GlobalCtx2.h>
#include <Window.h>
#include <PR/ultra64/types.h>
#define TICKS_PER_SEC 268123480.0
@ -21,7 +19,7 @@ void RandoMain::GenerateRando(std::unordered_map<RandomizerSettingKey, u8> cvarS
// std::string settingsFileName = "./randomizer/latest_settings.json";
// CVar_SetString("gLoadedPreset", settingsFileName.c_str());
std::string fileName = Ship::GlobalCtx2::GetPathRelativeToAppDirectory(GenerateRandomizer(cvarSettings).c_str());
std::string fileName = Ship::Window::GetPathRelativeToAppDirectory(GenerateRandomizer(cvarSettings).c_str());
CVar_SetString("gSpoilerLog", fileName.c_str());
CVar_Save();

View file

@ -26,9 +26,7 @@
#include <filesystem>
#include <variables.h>
#define NOGDI
#define WIN32_LEAN_AND_MEAN
#include "GlobalCtx2.h"
#include "Window.h"
using json = nlohmann::json;
@ -726,12 +724,12 @@ const char* SpoilerLog_Write(int language) {
//WriteShuffledEntrances(spoilerLog);
WriteAllLocations(language);
if (!std::filesystem::exists(Ship::GlobalCtx2::GetPathRelativeToAppDirectory("Randomizer"))) {
std::filesystem::create_directory(Ship::GlobalCtx2::GetPathRelativeToAppDirectory("Randomizer"));
if (!std::filesystem::exists(Ship::Window::GetPathRelativeToAppDirectory("Randomizer"))) {
std::filesystem::create_directory(Ship::Window::GetPathRelativeToAppDirectory("Randomizer"));
}
std::string jsonString = jsonData.dump(4);
std::ofstream jsonFile(Ship::GlobalCtx2::GetPathRelativeToAppDirectory(
std::ofstream jsonFile(Ship::Window::GetPathRelativeToAppDirectory(
(std::string("Randomizer/") + std::string(Settings::seed) + std::string(".json")).c_str()));
jsonFile << std::setw(4) << jsonString << std::endl;
jsonFile.close();

View file

@ -3,8 +3,8 @@
#include <iostream>
#include <algorithm>
#include <filesystem>
#include <locale>
#include "GlobalCtx2.h"
#include <fstream>
#include "ResourceMgr.h"
#include "DisplayList.h"
#include "PlayerAnimation.h"
@ -42,6 +42,9 @@
#include "Hooks.h"
#include <soh/Enhancements/custom-message/CustomMessageManager.h>
#include "Lib/Fast3D/gfx_pc.h"
#include "Lib/Fast3D/gfx_rendering_api.h"
#ifdef __APPLE__
#include <SDL_scancode.h>
#else
@ -63,10 +66,9 @@ SaveManager* SaveManager::Instance;
CustomMessageManager* CustomMessageManager::Instance;
OTRGlobals::OTRGlobals() {
context = Ship::GlobalCtx2::CreateInstance("Ship of Harkinian");
context = Ship::Window::CreateInstance("Ship of Harkinian");
gSaveStateMgr = std::make_shared<SaveStateMgr>();
gRandomizer = std::make_shared<Randomizer>();
context->GetWindow()->Init();
}
OTRGlobals::~OTRGlobals() {
@ -237,14 +239,14 @@ extern "C" uint64_t GetPerfCounter() {
// C->C++ Bridge
extern "C" void Graph_ProcessFrame(void (*run_one_game_iter)(void)) {
OTRGlobals::Instance->context->GetWindow()->MainLoop(run_one_game_iter);
OTRGlobals::Instance->context->MainLoop(run_one_game_iter);
}
extern "C" void Graph_StartFrame() {
#ifndef __WIIU__
// Why -1?
int32_t dwScancode = OTRGlobals::Instance->context->GetWindow()->GetLastScancode();
OTRGlobals::Instance->context->GetWindow()->SetLastScancode(-1);
int32_t dwScancode = OTRGlobals::Instance->context->GetLastScancode();
OTRGlobals::Instance->context->SetLastScancode(-1);
switch (dwScancode - 1) {
case SDL_SCANCODE_F5: {
@ -300,7 +302,14 @@ extern "C" void Graph_StartFrame() {
}
}
#endif
OTRGlobals::Instance->context->GetWindow()->StartFrame();
OTRGlobals::Instance->context->StartFrame();
}
void RunCommands(Gfx* Commands, const std::vector<std::unordered_map<Mtx*, MtxF>>& mtx_replacements) {
for (const auto& m : mtx_replacements) {
gfx_run(Commands, m);
gfx_end_frame();
}
}
// C->C++ Bridge
@ -341,12 +350,12 @@ extern "C" void Graph_ProcessGfxCommands(Gfx* commands) {
time -= fps;
OTRGlobals::Instance->context->GetWindow()->SetTargetFps(fps);
OTRGlobals::Instance->context->SetTargetFps(fps);
int threshold = CVar_GetS32("gExtraLatencyThreshold", 80);
OTRGlobals::Instance->context->GetWindow()->SetMaximumFrameLatency(threshold > 0 && target_fps >= threshold ? 2 : 1);
OTRGlobals::Instance->context->SetMaximumFrameLatency(threshold > 0 && target_fps >= threshold ? 2 : 1);
OTRGlobals::Instance->context->GetWindow()->RunCommands(commands, mtx_replacements);
RunCommands(commands, mtx_replacements);
last_fps = fps;
last_update_rate = R_UPDATE_RATE;
@ -359,19 +368,19 @@ extern "C" void Graph_ProcessGfxCommands(Gfx* commands) {
}
// OTRTODO: FIGURE OUT END FRAME POINT
/* if (OTRGlobals::Instance->context->GetWindow()->lastScancode != -1)
OTRGlobals::Instance->context->GetWindow()->lastScancode = -1;*/
/* if (OTRGlobals::Instance->context->lastScancode != -1)
OTRGlobals::Instance->context->lastScancode = -1;*/
}
float divisor_num = 0.0f;
extern "C" void OTRGetPixelDepthPrepare(float x, float y) {
OTRGlobals::Instance->context->GetWindow()->GetPixelDepthPrepare(x, y);
OTRGlobals::Instance->context->GetPixelDepthPrepare(x, y);
}
extern "C" uint16_t OTRGetPixelDepth(float x, float y) {
return OTRGlobals::Instance->context->GetWindow()->GetPixelDepth(x, y);
return OTRGlobals::Instance->context->GetPixelDepth(x, y);
}
extern "C" uint32_t ResourceMgr_GetGameVersion()
@ -1183,7 +1192,7 @@ extern "C" s32* ResourceMgr_LoadCSByName(const char* path)
}
std::filesystem::path GetSaveFile(std::shared_ptr<Mercury> Conf) {
const std::string fileName = Conf->getString("Game.SaveName", Ship::GlobalCtx2::GetPathRelativeToAppDirectory("oot_save.sav"));
const std::string fileName = Conf->getString("Game.SaveName", Ship::Window::GetPathRelativeToAppDirectory("oot_save.sav"));
std::filesystem::path saveFile = std::filesystem::absolute(fileName);
if (!exists(saveFile.parent_path())) {
@ -1314,15 +1323,15 @@ extern "C" void OTRGfxPrint(const char* str, void* printer, void (*printImpl)(vo
}
extern "C" uint32_t OTRGetCurrentWidth() {
return OTRGlobals::Instance->context->GetWindow()->GetCurrentWidth();
return OTRGlobals::Instance->context->GetCurrentWidth();
}
extern "C" uint32_t OTRGetCurrentHeight() {
return OTRGlobals::Instance->context->GetWindow()->GetCurrentHeight();
return OTRGlobals::Instance->context->GetCurrentHeight();
}
extern "C" void OTRControllerCallback(ControllerCallback* controller) {
auto controlDeck = Ship::GlobalCtx2::GetInstance()->GetWindow()->GetControlDeck();
auto controlDeck = Ship::Window::GetInstance()->GetControlDeck();
for (int i = 0; i < controlDeck->GetNumVirtualDevices(); ++i) {
auto physicalDevice = controlDeck->GetPhysicalDeviceFromVirtualSlot(i);
@ -1354,33 +1363,33 @@ extern "C" int16_t OTRGetRectDimensionFromRightEdge(float v) {
}
extern "C" bool AudioPlayer_Init(void) {
if (OTRGlobals::Instance->context->GetWindow()->GetAudioPlayer() != nullptr) {
return OTRGlobals::Instance->context->GetWindow()->GetAudioPlayer()->Init();
if (OTRGlobals::Instance->context->GetAudioPlayer() != nullptr) {
return OTRGlobals::Instance->context->GetAudioPlayer()->Init();
}
return false;
}
extern "C" int AudioPlayer_Buffered(void) {
if (OTRGlobals::Instance->context->GetWindow()->GetAudioPlayer() != nullptr) {
return OTRGlobals::Instance->context->GetWindow()->GetAudioPlayer()->Buffered();
if (OTRGlobals::Instance->context->GetAudioPlayer() != nullptr) {
return OTRGlobals::Instance->context->GetAudioPlayer()->Buffered();
}
}
extern "C" int AudioPlayer_GetDesiredBuffered(void) {
if (OTRGlobals::Instance->context->GetWindow()->GetAudioPlayer() != nullptr) {
return OTRGlobals::Instance->context->GetWindow()->GetAudioPlayer()->GetDesiredBuffered();
if (OTRGlobals::Instance->context->GetAudioPlayer() != nullptr) {
return OTRGlobals::Instance->context->GetAudioPlayer()->GetDesiredBuffered();
}
}
extern "C" void AudioPlayer_Play(const uint8_t* buf, uint32_t len) {
if (OTRGlobals::Instance->context->GetWindow()->GetAudioPlayer() != nullptr) {
OTRGlobals::Instance->context->GetWindow()->GetAudioPlayer()->Play(buf, len);
if (OTRGlobals::Instance->context->GetAudioPlayer() != nullptr) {
OTRGlobals::Instance->context->GetAudioPlayer()->Play(buf, len);
}
}
extern "C" int Controller_ShouldRumble(size_t i) {
auto controlDeck = Ship::GlobalCtx2::GetInstance()->GetWindow()->GetControlDeck();
auto controlDeck = Ship::Window::GetInstance()->GetControlDeck();
for (int i = 0; i < controlDeck->GetNumVirtualDevices(); ++i) {
auto physicalDevice = controlDeck->GetPhysicalDeviceFromVirtualSlot(i);

View file

@ -3,10 +3,10 @@
#pragma once
#include "GlobalCtx2.h"
#include "SaveManager.h"
#ifdef __cplusplus
#include "Window.h"
#include "Enhancements/savestates.h"
#include "Enhancements/randomizer/randomizer.h"
@ -17,7 +17,7 @@ class OTRGlobals
public:
static OTRGlobals* Instance;
std::shared_ptr<Ship::GlobalCtx2> context;
std::shared_ptr<Ship::Window> context;
std::shared_ptr<SaveStateMgr> gSaveStateMgr;
std::shared_ptr<Randomizer> gRandomizer;

View file

@ -16,7 +16,7 @@
extern "C" SaveContext gSaveContext;
std::filesystem::path SaveManager::GetFileName(int fileNum) {
const std::filesystem::path sSavePath(Ship::GlobalCtx2::GetPathRelativeToAppDirectory("Save"));
const std::filesystem::path sSavePath(Ship::Window::GetPathRelativeToAppDirectory("Save"));
return sSavePath / ("file" + std::to_string(fileNum + 1) + ".sav");
}
@ -133,10 +133,10 @@ void SaveManager::SaveRandomizer() {
}
void SaveManager::Init() {
const std::filesystem::path sSavePath(Ship::GlobalCtx2::GetPathRelativeToAppDirectory("Save"));
const std::filesystem::path sSavePath(Ship::Window::GetPathRelativeToAppDirectory("Save"));
const std::filesystem::path sGlobalPath = sSavePath / std::string("global.sav");
auto sOldSavePath = Ship::GlobalCtx2::GetPathRelativeToAppDirectory("oot_save.sav");
auto sOldBackupSavePath = Ship::GlobalCtx2::GetPathRelativeToAppDirectory("oot_save.bak");
auto sOldSavePath = Ship::Window::GetPathRelativeToAppDirectory("oot_save.sav");
auto sOldBackupSavePath = Ship::Window::GetPathRelativeToAppDirectory("oot_save.bak");
// If the save directory does not exist, create it
if (!std::filesystem::exists(sSavePath)) {

View file

@ -68,7 +68,7 @@ void OTRGameplay_InitScene(GlobalContext* globalCtx, s32 spawn) {
gSaveContext.worldMapArea = 0;
OTRScene_ExecuteCommands(globalCtx, globalCtx->sceneSegment);
Gameplay_InitEnvironment(globalCtx, globalCtx->skyboxId);
/* auto data = static_cast<Ship::Vertex*>(Ship::GlobalCtx2::GetInstance()
/* auto data = static_cast<Ship::Vertex*>(Ship::Window::GetInstance()
->GetResourceManager()
->LoadResource("object_link_child\\object_link_childVtx_01FE08")
.get());