mirror of
https://github.com/izzy2lost/Ghostship.git
synced 2026-06-19 01:17:03 -07:00
Moved PortEnhancements to cpp among using ShipInit
This commit is contained in:
+21
-7
@@ -1,9 +1,17 @@
|
||||
#ifndef SM64_H
|
||||
#define SM64_H
|
||||
|
||||
// Global header for Super Mario 64
|
||||
|
||||
#include "types.h"
|
||||
#include <math.h>
|
||||
#include <PR/gu.h>
|
||||
#include <PR/ucode.h>
|
||||
#include "port/Engine.h"
|
||||
#include <libultra/os.h>
|
||||
|
||||
// Global header for Super Mario 64
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "config.h"
|
||||
#include "object_fields.h"
|
||||
#include "object_constants.h"
|
||||
@@ -13,12 +21,10 @@
|
||||
#include "mario_geo_switch_case_ids.h"
|
||||
#include "surface_terrains.h"
|
||||
#include "macros.h"
|
||||
#include <PR/gu.h>
|
||||
#include <PR/ucode.h>
|
||||
#include <libultra/os.h>
|
||||
#include <math.h>
|
||||
#include "port/Engine.h"
|
||||
#include "align_asset_macro.h"
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#define GAME_VERSION GameEngine_GetGameVersion()
|
||||
#define ROM_JP (GAME_VERSION == 0xE3DAA4E)
|
||||
@@ -501,6 +507,10 @@ extern void osMapTLB(int32_t a, uint32_t b, void* c, uint32_t d, uint32_t e, uin
|
||||
|
||||
// LUS
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void ResourceMgr_PatchGfxByName(const char* path, const char* patchName, GfxPatch* patches, int patchCount);
|
||||
void gSPSegmentLoadRes(void* value, int segNum, uintptr_t target);
|
||||
void gSPDisplayList(Gfx* pkt, Gfx* dl);
|
||||
@@ -508,6 +518,10 @@ void gSPDisplayListOffset(Gfx* pkt, Gfx* dl, int offset);
|
||||
void gSPVertex(Gfx* pkt, uintptr_t v, int n, int v0);
|
||||
void gSPInvalidateTexCache(Gfx* pkt, uintptr_t texAddr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
+6
-5
@@ -1,6 +1,7 @@
|
||||
#include "Engine.h"
|
||||
#include "ui/GhostshipGui.hpp"
|
||||
#include "GameExtractor.h"
|
||||
#include "ShipInit.hpp"
|
||||
#include "port/importer/AnimationFactory.h"
|
||||
#include "port/importer/AudioBankFactory.h"
|
||||
#include "port/importer/TrajectoryFactory.h"
|
||||
@@ -15,6 +16,7 @@
|
||||
#include "port/interpolation/FrameInterpolation.h"
|
||||
#include "audio/GameAudio.h"
|
||||
#include "texts_table.h"
|
||||
#include "port/ui/cvar_prefixes.h"
|
||||
#include "port/mods/PortEnhancements.h"
|
||||
#include "port/console/DevConsole.h"
|
||||
#include <fast/Fast3dWindow.h>
|
||||
@@ -327,18 +329,17 @@ void GameEngine::ScaleImGui() {
|
||||
void GameEngine::Create() {
|
||||
const auto instance = Instance = new GameEngine();
|
||||
GhostshipGui::SetupGuiElements();
|
||||
ShipInit::InitAll();
|
||||
instance->AudioInit();
|
||||
instance->LoadDictionary();
|
||||
instance->LoadPlayerAnims();
|
||||
#if defined(__SWITCH__) || defined(__WIIU__)
|
||||
CVarRegisterInteger("gControlNav", 1); // always enable controller nav on switch/wii u
|
||||
#endif
|
||||
PortEnhancements_Init();
|
||||
DevConsole_Init();
|
||||
}
|
||||
|
||||
void GameEngine::Destroy() {
|
||||
PortEnhancements_Exit();
|
||||
AudioExit();
|
||||
#ifdef __SWITCH__
|
||||
Ship::Switch::Exit();
|
||||
@@ -364,15 +365,15 @@ void GameEngine::StartFrame() const {
|
||||
|
||||
uint32_t GameEngine::GetInterpolationFPS() {
|
||||
if (Ship::Context::GetInstance()->GetWindow()->GetWindowBackend() == Ship::WindowBackend::FAST3D_DXGI_DX11) {
|
||||
return CVarGetInteger("gInterpolationFPS", 30);
|
||||
return CVarGetInteger(CVAR_SETTING("InterpolationFPS"), 30);
|
||||
}
|
||||
|
||||
if (CVarGetInteger("gMatchRefreshRate", 0)) {
|
||||
if (CVarGetInteger(CVAR_SETTING("MatchRefreshRate"), 0)) {
|
||||
return Ship::Context::GetInstance()->GetWindow()->GetCurrentRefreshRate();
|
||||
}
|
||||
|
||||
return std::min<uint32_t>(Ship::Context::GetInstance()->GetWindow()->GetCurrentRefreshRate(),
|
||||
CVarGetInteger("gInterpolationFPS", 30));
|
||||
CVarGetInteger(CVAR_SETTING("InterpolationFPS"), 30));
|
||||
}
|
||||
|
||||
// Audio
|
||||
|
||||
@@ -47,11 +47,11 @@ extern "C" EventID EventSystem_RegisterEvent() {
|
||||
return EventSystem::Instance->RegisterEvent();
|
||||
}
|
||||
|
||||
extern "C" size_t EventSystem_RegisterListener(EventID id, EventCallback callback, EventPriority priority) {
|
||||
extern "C" ListenerID EventSystem_RegisterListener(EventID id, EventCallback callback, EventPriority priority) {
|
||||
return EventSystem::Instance->RegisterListener(id, callback, priority);
|
||||
}
|
||||
|
||||
extern "C" void EventSystem_UnregisterListener(EventID ev, size_t id) {
|
||||
extern "C" void EventSystem_UnregisterListener(EventID ev, ListenerID id) {
|
||||
EventSystem::Instance->UnregisterListener(ev, id);
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ typedef struct {
|
||||
#define REGISTER_EVENT(eventType) \
|
||||
eventType##ID = EventSystem_RegisterEvent();
|
||||
|
||||
#define REGISTER_LISTENER(eventType, callback, priority) \
|
||||
#define REGISTER_LISTENER(eventType, priority, callback) \
|
||||
EventSystem_RegisterListener(eventType##ID, callback, priority);
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -81,9 +81,13 @@ private:
|
||||
std::unordered_map<EventID, std::vector<EventListener>> mEventListeners;
|
||||
EventID mInternalEventID = 0;
|
||||
};
|
||||
#else
|
||||
|
||||
extern "C" {
|
||||
#endif
|
||||
extern EventID EventSystem_RegisterEvent();
|
||||
extern ListenerID EventSystem_RegisterListener(EventID id, EventCallback callback, EventPriority priority);
|
||||
extern void EventSystem_UnregisterListener(EventID ev, ListenerID id);
|
||||
extern void EventSystem_CallEvent(EventID id, void* event);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +1,13 @@
|
||||
#include "PortEnhancements.h"
|
||||
|
||||
#define INIT_EVENT_IDS
|
||||
|
||||
#include "sm64.h"
|
||||
#include "game/level_update.h"
|
||||
|
||||
#define INIT_EVENT_IDS
|
||||
#include "port/hooks/Events.h"
|
||||
|
||||
#include "assets/bin/segment2.h"
|
||||
#include "port/ShipInit.hpp"
|
||||
|
||||
static const Mtx matrix_patch_identity = {
|
||||
{ { 1.0f, 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 1.0f, 0.0f }, { 0.0f, 0.0f, 0.0f, 1.0f } }
|
||||
@@ -17,33 +19,6 @@ static const Mtx matrix_patch_fullscreen = { { { 2.0f / SCREEN_WIDTH, 0.0f, 0.0f
|
||||
{ 0.0f, 0.0f, -1.0f, 0.0f },
|
||||
{ -1.0f, -1.0f, -1.0f, 1.0f } } };
|
||||
|
||||
void OnLivesChange(IEvent* event) {
|
||||
PlayerLivesChange* ev = (PlayerLivesChange*)event;
|
||||
if (CVarGetInteger("gCheats.InfiniteLives", 0) == 0 || ev->lives > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
event->cancelled = true;
|
||||
}
|
||||
|
||||
void OnHealthChange(IEvent* event) {
|
||||
PlayerHealthChange* ev = (PlayerHealthChange*)event;
|
||||
if (CVarGetInteger("gCheats.InfiniteHealth", 0) == 0 || ev->health > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
event->cancelled = true;
|
||||
}
|
||||
|
||||
void OnRenderPauseCourseOptions(IEvent* event) {
|
||||
if (CVarGetInteger("gCheats.PauseExitWhenever", 0) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
RenderPauseCourseOptions* ev = (RenderPauseCourseOptions*)event;
|
||||
*ev->render = true;
|
||||
}
|
||||
|
||||
void PatchSetupDList() {
|
||||
Gfx identity = gsSPMatrix(&matrix_patch_identity, G_MTX_PROJECTION | G_MTX_LOAD | G_MTX_NOPUSH);
|
||||
Gfx fullscreen = gsSPMatrix(&matrix_patch_fullscreen, G_MTX_PROJECTION | G_MTX_MUL | G_MTX_NOPUSH);
|
||||
@@ -75,9 +50,30 @@ void PortEnhancements_Init() {
|
||||
PatchSetupDList();
|
||||
|
||||
// Register event listeners
|
||||
REGISTER_LISTENER(PlayerHealthChange, OnHealthChange, EVENT_PRIORITY_NORMAL);
|
||||
REGISTER_LISTENER(PlayerLivesChange, OnLivesChange, EVENT_PRIORITY_NORMAL);
|
||||
REGISTER_LISTENER(RenderPauseCourseOptions, OnRenderPauseCourseOptions, EVENT_PRIORITY_NORMAL);
|
||||
REGISTER_LISTENER(PlayerHealthChange, EVENT_PRIORITY_NORMAL, [](IEvent* event) {
|
||||
PlayerHealthChange* ev = (PlayerHealthChange*)event;
|
||||
if (CVarGetInteger("gCheats.InfiniteHealth", 0) == 0 || ev->health > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
event->cancelled = true;
|
||||
});
|
||||
REGISTER_LISTENER(PlayerLivesChange, EVENT_PRIORITY_NORMAL, [](IEvent* event) {
|
||||
PlayerLivesChange* ev = (PlayerLivesChange*)event;
|
||||
if (CVarGetInteger("gCheats.InfiniteLives", 0) == 0 || ev->lives > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
event->cancelled = true;
|
||||
});
|
||||
REGISTER_LISTENER(RenderPauseCourseOptions, EVENT_PRIORITY_NORMAL, [](IEvent* event) {
|
||||
if (CVarGetInteger("gCheats.PauseExitWhenever", 0) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
RenderPauseCourseOptions* ev = (RenderPauseCourseOptions*)event;
|
||||
*ev->render = true;
|
||||
});
|
||||
}
|
||||
|
||||
void PortEnhancements_Register() {
|
||||
@@ -88,6 +84,4 @@ void PortEnhancements_Register() {
|
||||
REGISTER_EVENT(RenderPauseCourseOptions);
|
||||
}
|
||||
|
||||
void PortEnhancements_Exit() {
|
||||
// TODO: Unregister event listeners
|
||||
}
|
||||
static RegisterShipInitFunc initFunc(PortEnhancements_Init);
|
||||
@@ -227,8 +227,8 @@ void GhostshipMenu::AddMenuSettings() {
|
||||
.Max(8)
|
||||
.DefaultValue(1));
|
||||
#endif
|
||||
auto fps = CVarGetInteger(CVAR_SETTING("InterpolationFPS"), 20);
|
||||
const char* fpsFormat = fps == 20 ? "Original (%d)" : "%d";
|
||||
auto fps = CVarGetInteger(CVAR_SETTING("InterpolationFPS"), 30);
|
||||
const char* fpsFormat = fps == 30 ? "Original (%d)" : "%d";
|
||||
AddWidget(path, "Current FPS", WIDGET_CVAR_SLIDER_INT)
|
||||
.CVar(CVAR_SETTING("InterpolationFPS"))
|
||||
.RaceDisable(false)
|
||||
@@ -245,7 +245,7 @@ void GhostshipMenu::AddMenuSettings() {
|
||||
if (mGhostshipMenu->disabledMap.at(DISABLE_FOR_MATCH_REFRESH_RATE_ON).active)
|
||||
info.activeDisables.push_back(DISABLE_FOR_MATCH_REFRESH_RATE_ON);
|
||||
})
|
||||
.Options(IntSliderOptions().Tooltip(tooltip).Min(20).Max(maxFps).DefaultValue(20).Format(fpsFormat));
|
||||
.Options(IntSliderOptions().Tooltip(tooltip).Min(30).Max(maxFps).DefaultValue(30).Format(fpsFormat));
|
||||
AddWidget(path, "Match Refresh Rate", WIDGET_CVAR_CHECKBOX)
|
||||
.CVar(CVAR_SETTING("MatchRefreshRate"))
|
||||
.RaceDisable(false)
|
||||
|
||||
Reference in New Issue
Block a user