From e4d43881795c30f32647df9bfdf534236e84f082 Mon Sep 17 00:00:00 2001 From: KiritoDv Date: Fri, 27 Dec 2024 17:46:16 -0600 Subject: [PATCH] Moved port cvars out of display update --- src/engine/fox_beam.c | 5 - src/engine/fox_display.c | 150 +++---------------------- src/port/Engine.cpp | 12 +- src/port/hooks/impl/EventSystem.h | 11 +- src/port/hooks/list/EngineEvent.h | 6 + src/port/hooks/list/PlayerShotEvent.h | 10 -- src/port/mods/PortEnhancements.c | 155 ++++++++++++++++++++++++++ src/port/mods/PortEnhancements.h | 12 ++ 8 files changed, 195 insertions(+), 166 deletions(-) create mode 100644 src/port/hooks/list/EngineEvent.h delete mode 100644 src/port/hooks/list/PlayerShotEvent.h create mode 100644 src/port/mods/PortEnhancements.c create mode 100644 src/port/mods/PortEnhancements.h diff --git a/src/engine/fox_beam.c b/src/engine/fox_beam.c index 4f1a9af0..9be6fc18 100644 --- a/src/engine/fox_beam.c +++ b/src/engine/fox_beam.c @@ -5,7 +5,6 @@ #include "assets/ast_great_fox.h" #include "assets/ast_versus.h" #include "port/interpolation/FrameInterpolation.h" -#include "port/hooks/Events.h" Vec3f sShotViewPos; @@ -663,10 +662,6 @@ void PlayerShot_ApplyDamageToActor(PlayerShot* shot, Actor* actor, s32 hitIndex) Vec3f sp44 = { 0.0f, 0.0f, -100.0f }; Vec3f sp38; - PlayerShotEvent* event = malloc(sizeof(PlayerShotEvent)); - EventSystem_CallEvent(EVENT_PLAYER_SHOT, event); - free(event); - actor->dmgType = DMG_BEAM; actor->dmgPart = hitIndex - 1; actor->timer_0C2 = 2; diff --git a/src/engine/fox_display.c b/src/engine/fox_display.c index 786f2970..f5bbc57d 100644 --- a/src/engine/fox_display.c +++ b/src/engine/fox_display.c @@ -1,3 +1,4 @@ +#include #include "global.h" #include "mods/hit64.c" #include "assets/ast_arwing.h" @@ -6,6 +7,7 @@ #include "assets/ast_versus.h" #include "assets/ast_sector_z.h" #include "port/interpolation/FrameInterpolation.h" +#include "port/hooks/list/EngineEvent.h" // f32 path1 = 0.0f; // f32 path2 = 0.0f; @@ -1780,6 +1782,10 @@ void Display_Update(void) { } #endif + // @port: @event: Start DISPLAY_UPDATE_EVENT_PRE + IEvent* event = malloc(sizeof(IEvent)); + EventSystem_CallEvent(DISPLAY_UPDATE_EVENT_PRE, event); + Matrix_Push(&gGfxMatrix); if ((gCurrentLevel == LEVEL_AQUAS) && (gPlayer[0].state == PLAYERSTATE_ACTIVE)) { Math_SmoothStepToF(&gCamDistortion, 0.01f, 0.2f, 0.002f, 0.0f); @@ -2011,143 +2017,13 @@ void Display_Update(void) { sPlayersVisible[gPlayerNum] = false; Matrix_Pop(&gGfxMatrix); -#if DEBUG_BOSS_KILLER == 1 - KillBoss(); -#endif + // @port: @event: End DISPLAY_UPDATE_EVENT_PRE + free(event); - if (CVarGetInteger("gDebugSpeedControl", 0) == 1) { - Player* player = gPlayer; - static s32 prevSpeed; - static bool debugFreeze = false; + // @port: @event: Start DISPLAY_UPDATE_EVENT_POST + event = malloc(sizeof(IEvent)); + EventSystem_CallEvent(DISPLAY_UPDATE_EVENT_POST, event); - if (gControllerPress[0].button & L_JPAD) { - player->baseSpeed -= 50; - } else if (gControllerPress[0].button & R_JPAD) { - player->baseSpeed += 50; - } - - if ((!debugFreeze) && (gControllerPress[0].button & D_JPAD)) { - prevSpeed = player->baseSpeed; - player->baseSpeed = 0; - debugFreeze = true; - } else if ((debugFreeze) && (gControllerPress[0].button & D_JPAD)) { - player->baseSpeed = prevSpeed; - debugFreeze = false; - } - } - - if (CVarGetInteger("gDebugJumpToMap", 0) == 1) { - Player* pl = &gPlayer[0]; - - if ((gGameState != GSTATE_PLAY) || (gPlayState <= PLAY_INIT)) { - return; - } - - if ((gControllerHold[0].button & Z_TRIG) && (gControllerHold[0].button & R_TRIG) && - (gControllerPress[0].button & U_CBUTTONS)) { - gFillScreenAlphaTarget = 255; - gFillScreenRed = gFillScreenGreen = gFillScreenBlue = 0; - gFillScreenAlphaStep = 8; - gShowLevelClearStatusScreen = false; - pl->state = PLAYERSTATE_NEXT; - pl->csTimer = 0; - gFadeoutType = 4; - } - } - - if (CVarGetInteger("gDebugWarpZone", 0) == 1) { - if ((gGameState != GSTATE_PLAY) || (gPlayState <= PLAY_INIT)) { - return; - } - if (gControllerPress[0].button & L_TRIG) { - if ((gCurrentLevel != LEVEL_SECTOR_X) && (gCurrentLevel != LEVEL_METEO)) { - return; - } - if (gCurrentLevel == LEVEL_SECTOR_X) { - gRingPassCount++; - gPlayer[0].state = PLAYERSTATE_ENTER_WARP_ZONE; - gPlayer[0].csState = 0; - gSceneSetup = 1; - AUDIO_PLAY_SFX(NA_SE_WARP_HOLE, gDefaultSfxSource, 0); - gMissionStatus = MISSION_WARP; - gLeveLClearStatus[gCurrentLevel] = 1; - } else { - gPlayer[0].state = PLAYERSTATE_ENTER_WARP_ZONE; - gPlayer[0].csState = 0; - AUDIO_PLAY_SFX(NA_SE_WARP_HOLE, gDefaultSfxSource, 0); - gMissionStatus = MISSION_WARP; - gLeveLClearStatus[gCurrentLevel] = 1; - } - } - } - - if (CVarGetInteger("gDebugNoCollision", 0) == 1) { - if ((gGameState != GSTATE_PLAY) || (gPlayState <= PLAY_INIT)) { - return; - } - gPlayer->mercyTimer = 1000; - } - - if (CVarGetInteger("gDebugLevelComplete", 0) == 1) { - Player* pl = &gPlayer[0]; - if ((gGameState != GSTATE_PLAY) || (gPlayState <= PLAY_INIT)) { - return; - } - - if (gControllerPress[0].button & L_TRIG) { - pl->state = PLAYERSTATE_LEVEL_COMPLETE; - gMissionStatus = MISSION_ACCOMPLISHED; - } - } - - if (CVarGetInteger("gDebugJumpToAllRange", 0) == 1) { - Player* pl2 = &gPlayer[0]; - - if ((gLevelMode != LEVELMODE_ALL_RANGE) && (gControllerPress[0].button & L_TRIG)) { - pl2->state = PLAYERSTATE_START_360; - } - } - - // Cheats start here - - if (CVarGetInteger("gInfiniteLives", 0) == 1) { - if ((gGameState != GSTATE_PLAY) || (gPlayState <= PLAY_INIT)) { - return; - } - gLifeCount[0] = 9; - } - - if (CVarGetInteger("gInfiniteBombs", 0) == 1) { - if ((gGameState != GSTATE_PLAY) || (gPlayState <= PLAY_INIT)) { - return; - } - gBombCount[0] = 9; - } - - if (CVarGetInteger("gHyperLaser", 0) == 1) { - if ((gGameState != GSTATE_PLAY) || (gPlayState <= PLAY_INIT)) { - return; - } - gLaserStrength[0] = 2; - } - - if (CVarGetInteger("gScoreEditor", 0) == 1) { - if ((gGameState != GSTATE_PLAY) || (gPlayState <= PLAY_INIT)) { - return; - } - gHitCount = CVarGetInteger("gScoreEditValue", 1); - - } - Hit64_Main(); - // ground testing -#if 0 - RCP_SetupDL(&gMasterDisp, SETUPDL_83); - gDPSetPrimColor(gMasterDisp++, 0, 0, 255, 255, 0, 255); - Graphics_DisplaySmallText(10, 210, 1.0f, 1.0f, "STICK_X:"); - Graphics_DisplaySmallNumber(60, 210, (int) ABS(gInputPress->stick_x)); - Graphics_DisplaySmallText(10, 220, 1.0f, 1.0f, "STICK_Y:"); - Graphics_DisplaySmallNumber(60, 220, (int) ABS(gInputPress->stick_y)); - if (gInputPress->stick_x < 0) Graphics_DisplaySmallText(110, 210, 1.0f, 1.0f, "NEG:"); - if (gInputPress->stick_y < 0) Graphics_DisplaySmallText(110, 220, 1.0f, 1.0f, "NEG:"); -#endif + // @port: @event: End DISPLAY_UPDATE_EVENT_PRE + free(event); } diff --git a/src/port/Engine.cpp b/src/port/Engine.cpp index 2acdd9f9..6e40a442 100644 --- a/src/port/Engine.cpp +++ b/src/port/Engine.cpp @@ -37,9 +37,7 @@ #include #include "audio/GameAudio.h" #include "port/patches/DisplayListPatch.h" - -#include "port/hooks/impl/EventSystem.h" -#include "port/hooks/Events.h" +#include "port/mods/PortEnhancements.h" #include #include @@ -188,15 +186,11 @@ void GameEngine::Create() { #if defined(__SWITCH__) || defined(__WIIU__) CVarRegisterInteger("gControlNav", 1); // always enable controller nav on switch/wii u #endif - - EventSystem::Instance->RegisterListener(EVENT_PLAYER_SHOT, EVENT_PRIORITY_NORMAL, [](IEvent* event) { - auto pse = (PlayerShotEvent*) event; - SPDLOG_INFO("Player shot event fired for actor {}", pse->actorId); - }); - + PortEnhancements_Init(); } void GameEngine::Destroy() { + PortEnhancements_Exit(); AudioExit(); free(MemoryPool.memory); } diff --git a/src/port/hooks/impl/EventSystem.h b/src/port/hooks/impl/EventSystem.h index 3e6cf29b..1489c182 100644 --- a/src/port/hooks/impl/EventSystem.h +++ b/src/port/hooks/impl/EventSystem.h @@ -1,13 +1,14 @@ #pragma once #include +#include +#include typedef uint16_t EventID; typedef enum EventType { EVENT_TYPE_PRE, - EVENT_TYPE_NORMAL, - EVENT_TYPE_POST, + EVENT_TYPE_POST } EventType; typedef enum EventPriority { @@ -22,9 +23,9 @@ typedef struct IEvent { typedef void (*EventCallback)(IEvent*); -// ID Type -// 00000000000000 00 -#define EVENT_ID(id, type) ((id << 2) | type) +// ID Type +// 000000000000000 0 +#define EVENT_ID(id, type) ((id << 1) | type) #ifdef __cplusplus #include diff --git a/src/port/hooks/list/EngineEvent.h b/src/port/hooks/list/EngineEvent.h new file mode 100644 index 00000000..fb2ed47e --- /dev/null +++ b/src/port/hooks/list/EngineEvent.h @@ -0,0 +1,6 @@ +#pragma once + +#include "port/hooks/impl/EventSystem.h" + +#define DISPLAY_UPDATE_EVENT_PRE EVENT_ID(1, EVENT_TYPE_PRE) +#define DISPLAY_UPDATE_EVENT_POST EVENT_ID(2, EVENT_TYPE_POST) \ No newline at end of file diff --git a/src/port/hooks/list/PlayerShotEvent.h b/src/port/hooks/list/PlayerShotEvent.h deleted file mode 100644 index 8a495861..00000000 --- a/src/port/hooks/list/PlayerShotEvent.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -#include "port/hooks/impl/EventSystem.h" - -typedef struct { - IEvent event; - int actorId; -} PlayerShotEvent; - -#define EVENT_PLAYER_SHOT EVENT_ID(1, EVENT_TYPE_NORMAL) \ No newline at end of file diff --git a/src/port/mods/PortEnhancements.c b/src/port/mods/PortEnhancements.c new file mode 100644 index 00000000..6175e027 --- /dev/null +++ b/src/port/mods/PortEnhancements.c @@ -0,0 +1,155 @@ +#include "PortEnhancements.h" +#include "port/hooks/list/EngineEvent.h" +#include "global.h" +#include "hit64.h" + +void OnDisplayUpdatePre(IEvent* event) { +#if DEBUG_BOSS_KILLER == 1 + KillBoss(); +#endif + + if (CVarGetInteger("gDebugSpeedControl", 0) == 1) { + Player* player = gPlayer; + static s32 prevSpeed; + static bool debugFreeze = false; + + if (gControllerPress[0].button & L_JPAD) { + player->baseSpeed -= 50; + } else if (gControllerPress[0].button & R_JPAD) { + player->baseSpeed += 50; + } + + if ((!debugFreeze) && (gControllerPress[0].button & D_JPAD)) { + prevSpeed = player->baseSpeed; + player->baseSpeed = 0; + debugFreeze = true; + } else if ((debugFreeze) && (gControllerPress[0].button & D_JPAD)) { + player->baseSpeed = prevSpeed; + debugFreeze = false; + } + } + + if (CVarGetInteger("gDebugJumpToMap", 0) == 1) { + Player* pl = &gPlayer[0]; + + if ((gGameState != GSTATE_PLAY) || (gPlayState <= PLAY_INIT)) { + return; + } + + if ((gControllerHold[0].button & Z_TRIG) && (gControllerHold[0].button & R_TRIG) && + (gControllerPress[0].button & U_CBUTTONS)) { + gFillScreenAlphaTarget = 255; + gFillScreenRed = gFillScreenGreen = gFillScreenBlue = 0; + gFillScreenAlphaStep = 8; + gShowLevelClearStatusScreen = false; + pl->state = PLAYERSTATE_NEXT; + pl->csTimer = 0; + gFadeoutType = 4; + } + } + + if (CVarGetInteger("gDebugWarpZone", 0) == 1) { + if ((gGameState != GSTATE_PLAY) || (gPlayState <= PLAY_INIT)) { + return; + } + if (gControllerPress[0].button & L_TRIG) { + if ((gCurrentLevel != LEVEL_SECTOR_X) && (gCurrentLevel != LEVEL_METEO)) { + return; + } + if (gCurrentLevel == LEVEL_SECTOR_X) { + gRingPassCount++; + gPlayer[0].state = PLAYERSTATE_ENTER_WARP_ZONE; + gPlayer[0].csState = 0; + gSceneSetup = 1; + AUDIO_PLAY_SFX(NA_SE_WARP_HOLE, gDefaultSfxSource, 0); + gMissionStatus = MISSION_WARP; + gLeveLClearStatus[gCurrentLevel] = 1; + } else { + gPlayer[0].state = PLAYERSTATE_ENTER_WARP_ZONE; + gPlayer[0].csState = 0; + AUDIO_PLAY_SFX(NA_SE_WARP_HOLE, gDefaultSfxSource, 0); + gMissionStatus = MISSION_WARP; + gLeveLClearStatus[gCurrentLevel] = 1; + } + } + } + + if (CVarGetInteger("gDebugNoCollision", 0) == 1) { + if ((gGameState != GSTATE_PLAY) || (gPlayState <= PLAY_INIT)) { + return; + } + gPlayer->mercyTimer = 1000; + } + + if (CVarGetInteger("gDebugLevelComplete", 0) == 1) { + Player* pl = &gPlayer[0]; + if ((gGameState != GSTATE_PLAY) || (gPlayState <= PLAY_INIT)) { + return; + } + + if (gControllerPress[0].button & L_TRIG) { + pl->state = PLAYERSTATE_LEVEL_COMPLETE; + gMissionStatus = MISSION_ACCOMPLISHED; + } + } + + if (CVarGetInteger("gDebugJumpToAllRange", 0) == 1) { + Player* pl2 = &gPlayer[0]; + + if ((gLevelMode != LEVELMODE_ALL_RANGE) && (gControllerPress[0].button & L_TRIG)) { + pl2->state = PLAYERSTATE_START_360; + } + } + + // Cheats start here + + if (CVarGetInteger("gInfiniteLives", 0) == 1) { + if ((gGameState != GSTATE_PLAY) || (gPlayState <= PLAY_INIT)) { + return; + } + gLifeCount[0] = 9; + } + + if (CVarGetInteger("gInfiniteBombs", 0) == 1) { + if ((gGameState != GSTATE_PLAY) || (gPlayState <= PLAY_INIT)) { + return; + } + gBombCount[0] = 9; + } + + if (CVarGetInteger("gHyperLaser", 0) == 1) { + if ((gGameState != GSTATE_PLAY) || (gPlayState <= PLAY_INIT)) { + return; + } + gLaserStrength[0] = LASERS_HYPER; + } + + if (CVarGetInteger("gScoreEditor", 0) == 1) { + if ((gGameState != GSTATE_PLAY) || (gPlayState <= PLAY_INIT)) { + return; + } + gHitCount = CVarGetInteger("gScoreEditValue", 1); + + } + Hit64_Main(); + // ground testing +#if 0 + RCP_SetupDL(&gMasterDisp, SETUPDL_83); + gDPSetPrimColor(gMasterDisp++, 0, 0, 255, 255, 0, 255); + Graphics_DisplaySmallText(10, 210, 1.0f, 1.0f, "STICK_X:"); + Graphics_DisplaySmallNumber(60, 210, (int) ABS(gInputPress->stick_x)); + Graphics_DisplaySmallText(10, 220, 1.0f, 1.0f, "STICK_Y:"); + Graphics_DisplaySmallNumber(60, 220, (int) ABS(gInputPress->stick_y)); + if (gInputPress->stick_x < 0) Graphics_DisplaySmallText(110, 210, 1.0f, 1.0f, "NEG:"); + if (gInputPress->stick_y < 0) Graphics_DisplaySmallText(110, 220, 1.0f, 1.0f, "NEG:"); +#endif +} + +void PortEnhancements_Init() { + // Register event listeners + EventSystem_RegisterListener(DISPLAY_UPDATE_EVENT_PRE, EVENT_PRIORITY_NORMAL, OnDisplayUpdatePre); +} + +void PortEnhancements_Exit() { + // TODO: Unregister event listeners +} \ No newline at end of file diff --git a/src/port/mods/PortEnhancements.h b/src/port/mods/PortEnhancements.h new file mode 100644 index 00000000..6cdc6aaf --- /dev/null +++ b/src/port/mods/PortEnhancements.h @@ -0,0 +1,12 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +void PortEnhancements_Init(); +void PortEnhancements_Exit(); + +#ifdef __cplusplus +}; +#endif \ No newline at end of file