Small refactor for servant update (#1727)

A small refactor renaming a global variable for when the cutscene has
control of the engine.
In servant, it short cuts the main update function so that your familiar
isn't doing stuff while a cutscene is running.
Also some flag cleanup.

I've figured out quite a bit with the functions and how they are called.
It looks like most of the functions in ServantDesc are actually update
functions called by using the entityId as an offset. I want to update to
make that more clear, but I want to isolate that into it's own PR and I
already had this refactor in flight.
This commit is contained in:
H.M. Burger 2024-10-04 22:52:23 -05:00 committed by GitHub
parent f647b0c26b
commit bc549c75e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
22 changed files with 61 additions and 47 deletions

View File

@ -39,7 +39,7 @@ segments:
- [0x448, .data, 448]
- [0x4A8, .data, 4A8]
- [0x608, .data, 608]
- [0x10AC, .rodata, 10E8] # func_80172120
- [0x10AC, .rodata, 10E8] # UpdateServantDefault
- [0x10C4, .rodata, 10E8] # func_80174038
- [0x10E8, c, 10E8]
- [0x45C4, c, 45E4]

View File

@ -39,7 +39,7 @@ segments:
- [0x448, .data, 448]
- [0x4A8, .data, 4A8]
- [0x608, .data, 608]
- [0x10AC, .rodata, 10E8] # func_80172120
- [0x10AC, .rodata, 10E8] # UpdateServantDefault
- [0x10C4, .rodata, 10E8] # ProcessSfxState
- [0x10E8, c]
- [0x45E4, c]

View File

@ -700,6 +700,7 @@ g_CastleFlags_0x62 = 0x8003BE4E;
g_CastleFlags_0x63 = 0x8003BE4F;
g_CurrentStream = 0x8003C100;
g_ClutIds = 0x8003C104;
g_CutsceneHasControl = 0x8003C704;
D_8003C708_unk2 = 0x8003C70A;
D_8003C708_unk4 = 0x8003C70C;
D_8003C708_zPriority = 0x8003C70E;

View File

@ -8,7 +8,7 @@ func_8017170C = 0x092e7db0;
func_801718A0 = 0x092e8088;
func_801719E0 = 0x092e8260;
ServantInit = 0x092e8a48;
func_80172120 = 0x092e8d18;
UpdateServantDefault = 0x092e8d18;
func_80172C30 = 0x092e9e50;
func_8017339C = 0x092EA930;
func_801733A4 = 0x092EA938;

View File

@ -722,6 +722,7 @@ g_CastleFlags_0x62 = 0x8003BE4E;
g_CastleFlags_0x63 = 0x8003BE4F;
g_CurrentStream = 0x8003C100;
g_ClutIds = 0x8003C104;
g_CutsceneHasControl = 0x8003C704;
D_8003C708_unk2 = 0x8003C70A;
D_8003C708_unk4 = 0x8003C70C;
D_8003C708_zPriority = 0x8003C70E;

View File

@ -15,7 +15,7 @@ D_psp_091CF3AC = 0x091CF3AC;
D_psp_091CF3DC = 0x091CF3DC;
g_api = 0x091CF738;
g_PrimBuf = 0x091CFAF8;
D_8003C704 = 0x091CE598;
g_CutsceneHasControl = 0x091CE598;
D_8003C708 = 0x091E1308;
g_Tilemap = 0x091E1628;
g_Entities = 0x091E1680;

View File

@ -1859,7 +1859,7 @@ extern s32 D_8003C0EC[4];
extern s32 D_8003C0F8;
extern s32 D_8003C100;
extern u16 g_ClutIds[]; // array of palette VRAM offsets
extern s32 D_8003C704;
extern s32 g_CutsceneHasControl;
extern FgLayer D_8003C708;
extern s16 D_8003C710;
extern s16 D_8003C712;

View File

@ -20,7 +20,7 @@ typedef enum {
typedef struct {
void (*Init)(InitializeMode mode);
void (*Update)(Entity* self);
PfnEntityUpdate Update;
void (*Unk08)(Entity* self);
void (*Unk0C)(/*?*/);
void (*Unk10)(/*?*/);
@ -106,6 +106,7 @@ extern ServantDesc D_8D1DC40;
void ServantInit(InitializeMode mode);
void UpdateServantDefault(Entity* self);
void ProcessEvent(Entity* self, bool resetEvent);
void DestroyEntity(Entity* entity);
void CreateEventEntity(Entity* entityParent, s32 entityId, s32 params);

View File

@ -84,7 +84,7 @@ void OVL_EXPORT(EntityCutscene)(Entity* self) {
g_CutsceneFlags = 0;
D_us_8019AF2C = 0;
g_SkipCutscene = 0;
D_8003C704 = 1;
g_CutsceneHasControl = 1;
self->primIndex = g_Dialogue.primIndex[2];
self->step++;
}
@ -557,7 +557,7 @@ void OVL_EXPORT(EntityCutscene)(Entity* self) {
case 7:
g_api.TimeAttackController(
TIMEATTACK_EVENT_FIRST_MARIA_MEET, TIMEATTACK_SET_RECORD);
D_8003C704 = 0;
g_CutsceneHasControl = 0;
g_Settings.D_8003CB04 |= 0x80;
DestroyEntity(self);
break;

View File

@ -860,7 +860,7 @@ loop_5:
D_801362C8 = 0;
g_DebugIsRecordingVideo = false;
g_DemoMode = Demo_None;
D_8003C704 = 0;
g_CutsceneHasControl = 0;
D_800973EC = 0;
D_800974A4 = 0;
g_CdStep = CdStep_None;

View File

@ -961,7 +961,7 @@ void func_800F2404(s32 arg0) {
g_unkGraphicsStruct.D_800973F8 = 0;
g_unkGraphicsStruct.D_800973FC = 0;
}
D_8003C704 = 0;
g_CutsceneHasControl = 0;
g_unkGraphicsStruct.pauseEnemies = 0;
g_unkGraphicsStruct.unk18 = 0;

View File

@ -96,7 +96,13 @@ void UpdatePlayerEntities(void) {
// Objects 00-CF
entity->pfnUpdate = g_DraEntityTbl[entity->entityId];
} else if (entity->entityId < 0xE0) {
// Objects D0-DF
/* Objects D0-DF
* This is setting the update function for your current servant.
* In the servant code, entityId is updated when the "mode" of
* the servant is changed like when the bat goes from "seek"
* mode to "attack" mode. These update functions start at
* entityId = 0xD1 entityId = 0xD0 would be the init code.
*/
entity->pfnUpdate =
((PfnEntityUpdate*)&D_80170000)[entity->entityId - 0xD0];
} else if (entity->entityId == 0xEF || entity->entityId == 0xFF ||

View File

@ -42,7 +42,7 @@ GpuBuffer* g_CurrentBuffer;
u32 g_GameEngineStep;
s32 D_8003C0F8;
s32 D_800973EC;
s32 D_8003C704;
s32 g_CutsceneHasControl;
s32 D_800973EC;
s32 D_8003C73C;
s32 g_MapCursorTimer;

View File

@ -3,7 +3,7 @@ void ProcessSfxState(Entity* entity) {
switch (entity->step) {
case 0:
entity->flags = FLAG_UNK_20000 | FLAG_KEEP_ALIVE_OFFCAMERA;
if (D_8003C704 != 0) {
if (g_CutsceneHasControl != 0) {
g_PlaySfxStep = 99;
DestroyEntity(entity);
return;

View File

@ -39,8 +39,6 @@ s32 g_IsServantDestroyed;
s32 D_80174D40;
s32 _unused[26];
void func_80171ED4(s32 arg0);
void func_80172120(Entity* self);
void func_80172C30(Entity* self);
void func_8017339C(void);
void func_801733A4(void);
@ -57,10 +55,12 @@ void func_80173C24(void);
void DestroyServantEntity(Entity* self);
ServantDesc g_ServantDesc = {
ServantInit, func_80172120, func_80172C30, func_8017339C,
func_801733A4, func_801733AC, func_801733B4, func_801733BC,
func_801733C4, func_801733CC, BatFamiliarBlueTrail, func_80173C0C,
func_80173C14, func_80173C1C, func_80173C24, DestroyServantEntity,
ServantInit, UpdateServantDefault, func_80172C30,
func_8017339C, func_801733A4, func_801733AC,
func_801733B4, func_801733BC, func_801733C4,
func_801733CC, BatFamiliarBlueTrail, func_80173C0C,
func_80173C14, func_80173C1C, func_80173C24,
DestroyServantEntity,
};
#endif
@ -210,7 +210,7 @@ bool func_80171434(s16 x, s16 y, s16* outX, s16* outY) {
void func_80171560(Entity* self) {}
// Only ever called by func_80172120 so that is the parent
// Only ever called by UpdateServantDefault so that is the parent
void CreateBlueTrailEntity(Entity* parent) {
Entity* entity;
s32 i;
@ -527,14 +527,14 @@ s16 GetTargetPositionWithDistanceBuffer(
s16 currentX, s16 targetX, s16 distanceBuffer);
#ifdef VERSION_PSP
INCLUDE_ASM("servant/tt_000/nonmatchings/10E8", func_80172120);
INCLUDE_ASM("servant/tt_000/nonmatchings/10E8", UpdateServantDefault);
#else
void func_80172120(Entity* self) {
void UpdateServantDefault(Entity* self) {
g_api.func_8011A3AC(self, 0, 0, &D_80174C30);
if (g_IsServantDestroyed != 0) {
self->zPriority = PLAYER.zPriority - 2;
}
if (D_8003C708.flags & 0x20) {
if (D_8003C708.flags & STAGE_INVERTEDCASTLE_FLAG) {
switch (ServantUnk0()) {
case 0:
D_80174B04 = 0x40;
@ -570,7 +570,7 @@ void func_80172120(Entity* self) {
self->step = 5;
break;
}
if (D_8003C708.flags & 0x20) {
if (D_8003C708.flags & STAGE_INVERTEDCASTLE_FLAG) {
if (PLAYER.posX.i.hi >= self->posX.i.hi) {
self->facingLeft = true;
} else {
@ -636,7 +636,7 @@ void func_80172120(Entity* self) {
}
self->posX.val += self->velocityX;
self->posY.val += self->velocityY;
if (D_8003C704) {
if (g_CutsceneHasControl) {
break;
}
D_80174B24 = D_80174AFC - self->posX.i.hi;

View File

@ -34,7 +34,6 @@ extern s16
s32 ServantUnk0();
void ProcessEvent(Entity* self, bool resetEvent);
void func_us_80171864(Entity* self);
void func_us_801720A4(Entity* self);
void func_us_801720AC(void);
void func_us_801720B4(void);
@ -50,10 +49,12 @@ void func_us_801728F4(void);
void func_us_801728FC(void);
void DestroyServantEntity(Entity* self);
ServantDesc g_ServantDesc = {
ServantInit, func_us_80171864, func_us_801720A4, func_us_801720AC,
func_us_801720B4, func_us_801720BC, func_us_801720C4, func_us_801720CC,
func_us_801720D4, func_us_801720DC, func_us_801720E4, func_us_8017246C,
func_us_801728EC, func_us_801728F4, func_us_801728FC, DestroyServantEntity};
ServantInit, UpdateServantDefault, func_us_801720A4,
func_us_801720AC, func_us_801720B4, func_us_801720BC,
func_us_801720C4, func_us_801720CC, func_us_801720D4,
func_us_801720DC, func_us_801720E4, func_us_8017246C,
func_us_801728EC, func_us_801728F4, func_us_801728FC,
DestroyServantEntity};
#include "../set_entity_animation.h"
@ -227,6 +228,10 @@ Entity* func_us_80171568(Entity* self, s32 entityId) {
if (!entity->entityId) {
DestroyEntity(entity);
/* This is interesting. By changing the entityId of the
* entity, this effectively changes the update function.
* The update function that is called is set
*/
#if defined(VERSION_PSP)
entity->entityId = entityId;
#else
@ -336,7 +341,7 @@ void ServantInit(InitializeMode mode) {
}
}
void func_us_80171864(Entity* self) {
void UpdateServantDefault(Entity* self) {
s32 temp_s4;
s32 temp_s3;
s32 temp_s2;
@ -349,7 +354,7 @@ void func_us_80171864(Entity* self) {
self->hitboxWidth = 0;
self->hitboxHeight = 0;
if (self->step < 2) {
if (D_8003C708.flags & 0x20) {
if (D_8003C708.flags & STAGE_INVERTEDCASTLE_FLAG) {
switch (ServantUnk0()) {
case 0:
D_us_801737D8 = 0x40;
@ -400,7 +405,7 @@ void func_us_80171864(Entity* self) {
self->ext.ghost.unk8C = 0;
break;
}
if (D_8003C708.flags & 0x20) {
if (D_8003C708.flags & STAGE_INVERTEDCASTLE_FLAG) {
if (PLAYER.posX.i.hi >= self->posX.i.hi)
self->facingLeft = 1;
else
@ -444,7 +449,7 @@ void func_us_80171864(Entity* self) {
UpdateEntityVelocityTowardsTarget(self, D_us_801737C4, D_us_801737C8);
self->posX.val += self->velocityX;
self->posY.val += self->velocityY;
if (D_8003C704 == 0) {
if (!g_CutsceneHasControl) {
// Note: this is an assignment, not an equality check
if (self->ext.ghost.unkA2 = func_us_80171284(self)) {
self->step++;
@ -460,7 +465,7 @@ void func_us_80171864(Entity* self) {
self->ext.ghost.unk8C = 0;
break;
}
if (D_8003C704) {
if (g_CutsceneHasControl) {
self->step = 1;
}
if (!CheckEntityValid(self->ext.ghost.unkA2)) {

View File

@ -179,7 +179,7 @@ void OVL_EXPORT(EntityCutscene)(Entity* self) {
}
if (SetCutsceneScript(OVL_EXPORT(cutscene_data))) {
self->flags |= FLAG_HAS_PRIMS | FLAG_UNK_2000;
D_8003C704 = 1;
g_CutsceneHasControl = 1;
g_CutsceneFlags = 0;
g_IsCutsceneDone = 0;
g_SkipCutscene = 0;
@ -608,7 +608,7 @@ void OVL_EXPORT(EntityCutscene)(Entity* self) {
g_CastleFlags[HG_CS_DONE] = 1;
g_api.TimeAttackController(
TIMEATTACK_EVENT_GET_HOLYGLASSES, TIMEATTACK_SET_RECORD);
D_8003C704 = 0;
g_CutsceneHasControl = 0;
g_Settings.D_8003CB04 |= 0x800;
break;
}

View File

@ -143,7 +143,7 @@ void OVL_EXPORT(EntityCutscene)(Entity* self) {
g_CutsceneFlags = 0;
g_IsCutsceneDone = 0;
g_SkipCutscene = 0;
D_8003C704 = 1;
g_CutsceneHasControl = 1;
self->primIndex = g_Dialogue.primIndex[2];
self->step++;
}
@ -576,7 +576,7 @@ void OVL_EXPORT(EntityCutscene)(Entity* self) {
} else {
g_Settings.D_8003CB04 |= 0x1000;
}
D_8003C704 = 0;
g_CutsceneHasControl = 0;
DestroyEntity(self);
break;
}

View File

@ -107,7 +107,7 @@ void OVL_EXPORT(EntityCutscene)(Entity* self) {
g_CutsceneFlags = 0;
g_IsCutsceneDone = 0;
g_SkipCutscene = 0;
D_8003C704 = 1;
g_CutsceneHasControl = 1;
self->primIndex = g_Dialogue.primIndex[2];
self->step++;
}
@ -533,7 +533,7 @@ void OVL_EXPORT(EntityCutscene)(Entity* self) {
g_CastleFlags[CASTLE_FLAG_53] = 1;
g_api.TimeAttackController(
TIMEATTACK_EVENT_MEET_DEATH, TIMEATTACK_SET_RECORD);
D_8003C704 = 0;
g_CutsceneHasControl = 0;
g_Settings.D_8003CB04 |= 4;
DestroyEntity(self);
break;

View File

@ -70,7 +70,7 @@ void OVL_EXPORT(EntityCutscene)(Entity* self) {
g_CutsceneFlags = 0;
g_IsCutsceneDone = 0;
g_SkipCutscene = 0;
D_8003C704 = 1;
g_CutsceneHasControl = 1;
self->primIndex = g_Dialogue.primIndex[2];
self->step++;
}
@ -497,7 +497,7 @@ void OVL_EXPORT(EntityCutscene)(Entity* self) {
case 7:
DestroyEntity(self);
g_CastleFlags[CASTLE_FLAG_133] = 1;
D_8003C704 = 0;
g_CutsceneHasControl = 0;
g_Settings.D_8003CB04 |= 0x100;
break;
}

View File

@ -157,7 +157,7 @@ void SEL_EntityCutscene(Entity* entity) {
case 0:
if (SetCutsceneScript(D_8018B304)) {
g_SkipCutscene = D_801D6B00 = D_801BC3E8 = 0;
D_8003C704 = 1;
g_CutsceneHasControl = 1;
entity->flags |= FLAG_HAS_PRIMS | FLAG_UNK_2000;
entity->primIndex = g_Dialogue.primIndex[2];
++entity->step;
@ -499,7 +499,7 @@ void SEL_EntityCutscene(Entity* entity) {
}
break;
case 7:
D_8003C704 = 0;
g_CutsceneHasControl = 0;
break;
}
}

View File

@ -118,7 +118,7 @@ void OVL_EXPORT(EntityCutscene)(Entity* self) {
g_CutsceneFlags = 0;
g_IsCutsceneDone = 0;
g_SkipCutscene = 0;
D_8003C704 = 1;
g_CutsceneHasControl = 1;
self->primIndex = g_Dialogue.primIndex[2];
self->step += 1;
if (g_DemoMode != Demo_None) {
@ -537,7 +537,7 @@ void OVL_EXPORT(EntityCutscene)(Entity* self) {
break;
case 7:
D_8003C704 = 0;
g_CutsceneHasControl = 0;
g_Settings.D_8003CB04 |= 1;
DestroyEntity(self);
break;