From 0da645e7e63f1c76de2dbee56574c3e2753ed467 Mon Sep 17 00:00:00 2001 From: Archez Date: Sun, 28 Apr 2024 20:12:19 -0400 Subject: [PATCH] Fix actor inits happening too early (#248) --- mm/src/code/z_scene.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/mm/src/code/z_scene.c b/mm/src/code/z_scene.c index caf78f9e4..e74852dc2 100644 --- a/mm/src/code/z_scene.c +++ b/mm/src/code/z_scene.c @@ -35,6 +35,9 @@ s32 Object_SpawnPersistent(ObjectContext* objectCtx, s16 id) { return objectCtx->numEntries - 1; } +// 2S2H [Port] Track when objects are first loaded for a scene +static u8 sObjectFirstUpdateSkippedForScene = false; + void Object_InitContext(GameState* gameState, ObjectContext* objectCtx) { PlayState* play = (PlayState*)gameState; s32 pad; @@ -66,6 +69,8 @@ void Object_InitContext(GameState* gameState, ObjectContext* objectCtx) { objectCtx->mainKeepSlot = Object_SpawnPersistent(objectCtx, GAMEPLAY_KEEP); gSegments[4] = OS_K0_TO_PHYSICAL(objectCtx->slots[objectCtx->mainKeepSlot].segment); + + sObjectFirstUpdateSkippedForScene = false; } void Object_UpdateEntries(ObjectContext* objectCtx) { @@ -74,18 +79,25 @@ void Object_UpdateEntries(ObjectContext* objectCtx) { RomFile* objectFile; size_t size; + // 2S2H [Port] Skip the first object load after scene init so that actors have their init delayed by one frame + // This seems to mostly if not nearly resolve actors that depend on console DMA requests ending later + if (!sObjectFirstUpdateSkippedForScene) { + sObjectFirstUpdateSkippedForScene = true; + return; + } + for (i = 0; i < objectCtx->numEntries; i++) { if (entry->id < 0) { s32 id = -entry->id; - // #region 2S2H [Port] We don't care to load the object from DMA, consider it already loaded + // 2S2H [Port] We don't care to load the object from DMA, consider it already loaded // There is a weird case handled below that accounts for RomFiles with a size of 0, but according // to object_table.h there is only one instance of this, along with a bunch of placeholder entries // so we _should_ be fine. Famous last words. entry->id = id; } - entry++; + entry++; } }