Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic actor params getters #1359

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 29 additions & 3 deletions include/z64actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,6 @@ typedef enum {
/* 0xFF */ NAVI_ENEMY_NONE = 0xFF
} NaviEnemy;

#define TRANSITION_ACTOR_PARAMS_INDEX_SHIFT 10
#define GET_TRANSITION_ACTOR_INDEX(actor) ((u16)(actor)->params >> TRANSITION_ACTOR_PARAMS_INDEX_SHIFT)

// EnDoor and DoorKiller share openAnim and playerIsOpening
// Due to alignment, a substruct cannot be used in the structs of these actors.
#define DOOR_ACTOR_BASE \
Expand Down Expand Up @@ -640,4 +637,33 @@ typedef struct {
/* 0x24 */ char unk_24[0x4];
} NpcInteractInfo; // size = 0x28

// Converts a number of bits to a bitmask, helper for params macros
// e.g. 3 becomes 0b111 (7)
#define NBITS_TO_MASK(n) \
((1 << (n)) - 1)

// Extracts the `n`-bit value at position `s` in `p`, shifts then masks
// Unsigned variant, no possibility of sign extension
#define PARAMS_GET_U(p, s, n) \
(((p) >> (s)) & NBITS_TO_MASK(n))

// Extracts the `n`-bit value at position `s` in `p`, masks then shifts
// Signed variant, possibility of sign extension
#define PARAMS_GET_S(p, s, n) \
(((p) & (NBITS_TO_MASK(n) << (s))) >> (s))

// Extracts all bits past position `s` in `p`
#define PARAMS_GET_NOMASK(p, s) \
((p) >> (s))

// Extracts the `n`-bit value at position `s` in `p` without shifting it from its current position
#define PARAMS_GET_NOSHIFT(p, s, n) \
((p) & (NBITS_TO_MASK(n) << (s)))

// Generates a bitmask for bit position `s` of length `n`
#define PARAMS_MAKE_MASK(s, n) PARAMS_GET_NOSHIFT(~0, s, n)

#define TRANSITION_ACTOR_PARAMS_INDEX_SHIFT 10
#define GET_TRANSITION_ACTOR_INDEX(actor) PARAMS_GET_NOMASK((u16)(actor)->params, 10)

#endif
3 changes: 1 addition & 2 deletions src/code/z_collision_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -2807,8 +2807,7 @@ void CollisionCheck_OC_JntSphVsJntSph(PlayState* play, CollisionCheckContext* co
continue;
}
if (Math3D_SphVsSphOverlap(&leftJntSphElem->dim.worldSphere, &rightJntSphElem->dim.worldSphere,
&overlapSize) ==
true) {
&overlapSize) == true) {
Vec3f leftPos;
Vec3f rightPos;

Expand Down
2 changes: 1 addition & 1 deletion src/code/z_en_a_keep.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void EnAObj_Init(Actor* thisx, PlayState* play) {
EnAObj* this = (EnAObj*)thisx;
f32 shadowScale = 6.0f;

this->textId = (thisx->params >> 8) & 0xFF;
this->textId = PARAMS_GET_U(thisx->params, 8, 8);
thisx->params &= 0xFF;

switch (thisx->params) {
Expand Down
4 changes: 2 additions & 2 deletions src/code/z_en_item00.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ void EnItem00_Init(Actor* thisx, PlayState* play) {
f32 yOffset = 980.0f;
f32 shadowScale = 6.0f;
s32 getItemId = GI_NONE;
s16 spawnParam8000 = this->actor.params & 0x8000;
s16 spawnParam8000 = PARAMS_GET_NOSHIFT(this->actor.params, 15, 1);
s32 pad1;

this->collectibleFlag = (this->actor.params & 0x3F00) >> 8;
this->collectibleFlag = PARAMS_GET_S(this->actor.params, 8, 6);

this->actor.params &= 0xFF;

Expand Down
2 changes: 1 addition & 1 deletion src/code/z_play.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ void Play_Init(GameState* thisx) {
Camera_InitDataUsingPlayer(&this->mainCamera, player);
Camera_RequestMode(&this->mainCamera, CAM_MODE_NORMAL);

playerStartBgCamIndex = player->actor.params & 0xFF;
playerStartBgCamIndex = PARAMS_GET_U(player->actor.params, 0, 8);
if (playerStartBgCamIndex != 0xFF) {
PRINTF("player has start camera ID (" VT_FGCOL(BLUE) "%d" VT_RST ")\n", playerStartBgCamIndex);
Camera_RequestBgCam(&this->mainCamera, playerStartBgCamIndex);
Expand Down
2 changes: 1 addition & 1 deletion src/code/z_room.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ RoomShapeImageMultiBgEntry* Room_GetImageMultiBgEntry(RoomShapeImageMulti* roomS
}

player = GET_PLAYER(play);
player->actor.params = (player->actor.params & 0xFF00) | bgCamIndex;
player->actor.params = PARAMS_GET_NOSHIFT(player->actor.params, 8, 8) | bgCamIndex;

bgEntry = SEGMENTED_TO_VIRTUAL(roomShapeImageMulti->backgrounds);
for (i = 0; i < roomShapeImageMulti->numBackgrounds; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void BgBdanObjects_Init(Actor* thisx, PlayState* play) {

Actor_ProcessInitChain(&this->dyna.actor, sInitChain);
DynaPolyActor_Init(&this->dyna, DYNA_TRANSFORM_POS);
this->var.switchFlag = (thisx->params >> 8) & 0x3F;
this->var.switchFlag = PARAMS_GET_U(thisx->params, 8, 6);
thisx->params &= 0xFF;
if (thisx->params == JABU_OBJECTS_TYPE_WATERBOX_HEIGHT_CHANGER) {
thisx->flags |= ACTOR_FLAG_4 | ACTOR_FLAG_5;
Expand Down
39 changes: 20 additions & 19 deletions src/overlays/actors/ovl_Bg_Bdan_Switch/z_bg_bdan_switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void func_8086D0EC(BgBdanSwitch* this) {
this->unk_1CC += 0xFA0;
}

switch (this->dyna.actor.params & 0xFF) {
switch (PARAMS_GET_U(this->dyna.actor.params, 0, 8)) {
case BLUE:
case YELLOW_HEAVY:
case YELLOW:
Expand All @@ -139,7 +139,7 @@ void BgBdanSwitch_Init(Actor* thisx, PlayState* play) {
s16 type;
s32 flag;

type = this->dyna.actor.params & 0xFF;
type = PARAMS_GET_U(this->dyna.actor.params, 0, 8);
Actor_ProcessInitChain(&this->dyna.actor, sInitChain);
if (type == YELLOW_TALL_1 || type == YELLOW_TALL_2) {
this->dyna.actor.scale.z = 0.05f;
Expand All @@ -165,7 +165,7 @@ void BgBdanSwitch_Init(Actor* thisx, PlayState* play) {
break;
}

flag = Flags_GetSwitch(play, (this->dyna.actor.params >> 8) & 0x3F);
flag = Flags_GetSwitch(play, PARAMS_GET_U(this->dyna.actor.params, 8, 6));

switch (type) {
case BLUE:
Expand Down Expand Up @@ -202,7 +202,7 @@ void BgBdanSwitch_Init(Actor* thisx, PlayState* play) {
void BgBdanSwitch_Destroy(Actor* thisx, PlayState* play) {
BgBdanSwitch* this = (BgBdanSwitch*)thisx;

switch (this->dyna.actor.params & 0xFF) {
switch (PARAMS_GET_U(this->dyna.actor.params, 0, 8)) {
case BLUE:
case YELLOW_HEAVY:
case YELLOW:
Expand All @@ -219,9 +219,9 @@ void func_8086D4B4(BgBdanSwitch* this, PlayState* play) {
s32 pad;
s32 type;

if (!Flags_GetSwitch(play, (this->dyna.actor.params >> 8) & 0x3F)) {
type = this->dyna.actor.params & 0xFF;
Flags_SetSwitch(play, (this->dyna.actor.params >> 8) & 0x3F);
if (!Flags_GetSwitch(play, PARAMS_GET_U(this->dyna.actor.params, 8, 6))) {
type = PARAMS_GET_U(this->dyna.actor.params, 0, 8);
Flags_SetSwitch(play, PARAMS_GET_U(this->dyna.actor.params, 8, 6));
if (type == BLUE || type == YELLOW_TALL_2) {
OnePointCutscene_AttentionSetSfx(play, &this->dyna.actor, NA_SE_SY_TRE_BOX_APPEAR);
} else {
Expand All @@ -231,9 +231,9 @@ void func_8086D4B4(BgBdanSwitch* this, PlayState* play) {
}

void func_8086D548(BgBdanSwitch* this, PlayState* play) {
if (Flags_GetSwitch(play, (this->dyna.actor.params >> 8) & 0x3F)) {
Flags_UnsetSwitch(play, (this->dyna.actor.params >> 8) & 0x3F);
if ((this->dyna.actor.params & 0xFF) == YELLOW_TALL_2) {
if (Flags_GetSwitch(play, PARAMS_GET_U(this->dyna.actor.params, 8, 6))) {
Flags_UnsetSwitch(play, PARAMS_GET_U(this->dyna.actor.params, 8, 6));
if (PARAMS_GET_U(this->dyna.actor.params, 0, 8) == YELLOW_TALL_2) {
OnePointCutscene_AttentionSetSfx(play, &this->dyna.actor, NA_SE_SY_TRE_BOX_APPEAR);
}
}
Expand All @@ -245,7 +245,7 @@ void func_8086D5C4(BgBdanSwitch* this) {
}

void func_8086D5E0(BgBdanSwitch* this, PlayState* play) {
switch (this->dyna.actor.params & 0xFF) {
switch (PARAMS_GET_U(this->dyna.actor.params, 0, 8)) {
case BLUE:
if (func_800435B4(&this->dyna)) {
func_8086D67C(this);
Expand Down Expand Up @@ -284,7 +284,7 @@ void func_8086D730(BgBdanSwitch* this) {
}

void func_8086D754(BgBdanSwitch* this, PlayState* play) {
switch (this->dyna.actor.params & 0xFF) {
switch (PARAMS_GET_U(this->dyna.actor.params, 0, 8)) {
case BLUE:
if (!func_800435B4(&this->dyna)) {
if (this->unk_1D8 <= 0) {
Expand All @@ -296,7 +296,7 @@ void func_8086D754(BgBdanSwitch* this, PlayState* play) {
}
break;
case YELLOW:
if (!Flags_GetSwitch(play, (this->dyna.actor.params >> 8) & 0x3F)) {
if (!Flags_GetSwitch(play, PARAMS_GET_U(this->dyna.actor.params, 8, 6))) {
func_8086D7FC(this);
}
break;
Expand Down Expand Up @@ -406,7 +406,7 @@ void func_8086DB4C(BgBdanSwitch* this) {
}

void func_8086DB68(BgBdanSwitch* this, PlayState* play) {
switch (this->dyna.actor.params & 0xFF) {
switch (PARAMS_GET_U(this->dyna.actor.params, 0, 8)) {
default:
return;
case YELLOW_TALL_1:
Expand Down Expand Up @@ -447,9 +447,9 @@ void func_8086DCCC(BgBdanSwitch* this) {
}

void func_8086DCE8(BgBdanSwitch* this, PlayState* play) {
switch (this->dyna.actor.params & 0xFF) {
switch (PARAMS_GET_U(this->dyna.actor.params, 0, 8)) {
case YELLOW_TALL_1:
if (!Flags_GetSwitch(play, (this->dyna.actor.params >> 8) & 0x3F)) {
if (!Flags_GetSwitch(play, PARAMS_GET_U(this->dyna.actor.params, 8, 6))) {
func_8086DDA8(this);
}
break;
Expand All @@ -469,7 +469,8 @@ void func_8086DDA8(BgBdanSwitch* this) {
}

void func_8086DDC0(BgBdanSwitch* this, PlayState* play) {
if ((((this->dyna.actor.params & 0xFF) != YELLOW_TALL_2) || (func_8005B198() == this->dyna.actor.category)) ||
if (((PARAMS_GET_U(this->dyna.actor.params, 0, 8) != YELLOW_TALL_2) ||
(func_8005B198() == this->dyna.actor.category)) ||
(this->unk_1DA <= 0)) {
this->unk_1C8 += 0.3f;
if (this->unk_1C8 >= 2.0f) {
Expand All @@ -489,7 +490,7 @@ void BgBdanSwitch_Update(Actor* thisx, PlayState* play) {
}
this->actionFunc(this, play);
func_8086D0EC(this);
type = this->dyna.actor.params & 0xFF;
type = PARAMS_GET_U(this->dyna.actor.params, 0, 8);
if (type != 3 && type != 4) {
this->unk_1D8--;
} else {
Expand All @@ -515,7 +516,7 @@ void func_8086DF58(BgBdanSwitch* this, PlayState* play, Gfx* dlist) {
void BgBdanSwitch_Draw(Actor* thisx, PlayState* play) {
BgBdanSwitch* this = (BgBdanSwitch*)thisx;

switch (this->dyna.actor.params & 0xFF) {
switch (PARAMS_GET_U(this->dyna.actor.params, 0, 8)) {
case YELLOW_HEAVY:
case YELLOW:
func_8086DF58(this, play, gJabuYellowFloorSwitchDL);
Expand Down
1 change: 0 additions & 1 deletion src/overlays/actors/ovl_Bg_Bdan_Switch/z_bg_bdan_switch.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "ultra64.h"
#include "global.h"

// BgBdanSwitch.actor.params & 0xFF
typedef enum {
/* 0x00 */ BLUE,
/* 0x01 */ YELLOW_HEAVY,
Expand Down
6 changes: 3 additions & 3 deletions src/overlays/actors/ovl_Bg_Bombwall/z_bg_bombwall.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void BgBombwall_Init(Actor* thisx, PlayState* play) {
Actor_ProcessInitChain(&this->dyna.actor, sInitChain);
Actor_SetScale(&this->dyna.actor, 0.1f);

if (Flags_GetSwitch(play, this->dyna.actor.params & 0x3F)) {
if (Flags_GetSwitch(play, PARAMS_GET_U(this->dyna.actor.params, 0, 6))) {
func_8086EE94(this, play);
} else {
BgBombwall_InitDynapoly(this, play);
Expand Down Expand Up @@ -213,7 +213,7 @@ void func_8086ED70(BgBombwall* this, PlayState* play) {
if (this->collider.base.acFlags & AC_HIT) {
this->collider.base.acFlags &= ~AC_HIT;
func_8086EDFC(this, play);
Flags_SetSwitch(play, this->dyna.actor.params & 0x3F);
Flags_SetSwitch(play, PARAMS_GET_U(this->dyna.actor.params, 0, 6));
} else if (this->dyna.actor.xzDistToPlayer < 600.0f) {
CollisionCheck_SetAC(play, &play->colChkCtx, &this->collider.base);
}
Expand All @@ -232,7 +232,7 @@ void func_8086EE40(BgBombwall* this, PlayState* play) {
} else {
func_8086EE94(this, play);

if (((this->dyna.actor.params >> 0xF) & 1) != 0) {
if (PARAMS_GET_U(this->dyna.actor.params, 15, 1) != 0) {
Sfx_PlaySfxCentered(NA_SE_SY_CORRECT_CHIME);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/overlays/actors/ovl_Bg_Breakwall/z_bg_breakwall.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void BgBreakwall_SetupAction(BgBreakwall* this, BgBreakwallActionFunc actionFunc
void BgBreakwall_Init(Actor* thisx, PlayState* play) {
BgBreakwall* this = (BgBreakwall*)thisx;
s32 pad;
s32 wallType = ((this->dyna.actor.params >> 13) & 3) & 0xFF;
s32 wallType = (u8)PARAMS_GET_U(this->dyna.actor.params, 13, 2);

Actor_ProcessInitChain(&this->dyna.actor, sInitChain);
DynaPolyActor_Init(&this->dyna, 0);
Expand All @@ -91,7 +91,7 @@ void BgBreakwall_Init(Actor* thisx, PlayState* play) {
}

if (this->bombableWallDList != NULL) {
if (Flags_GetSwitch(play, this->dyna.actor.params & 0x3F)) {
if (Flags_GetSwitch(play, PARAMS_GET_U(this->dyna.actor.params, 0, 6))) {
Actor_Kill(&this->dyna.actor);
return;
}
Expand Down Expand Up @@ -203,7 +203,7 @@ Actor* BgBreakwall_SpawnFragments(PlayState* play, BgBreakwall* this, Vec3f* pos
void BgBreakwall_WaitForObject(BgBreakwall* this, PlayState* play) {
if (Object_IsLoaded(&play->objectCtx, this->requiredObjectSlot)) {
CollisionHeader* colHeader = NULL;
s32 wallType = ((this->dyna.actor.params >> 13) & 3) & 0xFF;
s32 wallType = (u8)PARAMS_GET_U(this->dyna.actor.params, 13, 2);

this->dyna.actor.objectSlot = this->requiredObjectSlot;
Actor_SetObjectDependency(play, &this->dyna.actor);
Expand All @@ -227,7 +227,7 @@ void BgBreakwall_WaitForObject(BgBreakwall* this, PlayState* play) {
void BgBreakwall_Wait(BgBreakwall* this, PlayState* play) {
if (this->collider.base.acFlags & AC_HIT) {
Vec3f effectPos;
s32 wallType = ((this->dyna.actor.params >> 13) & 3) & 0xFF;
s32 wallType = (u8)PARAMS_GET_U(this->dyna.actor.params, 13, 2);

DynaPoly_DeleteBgActor(play, &play->colCtx.dyna, this->dyna.bgId);
effectPos.y = effectPos.z = effectPos.x = 0.0f;
Expand All @@ -240,7 +240,7 @@ void BgBreakwall_Wait(BgBreakwall* this, PlayState* play) {
}

BgBreakwall_SpawnFragments(play, this, &effectPos, 0.0f, 6.4f, 5.0f, 1, 2.0f);
Flags_SetSwitch(play, this->dyna.actor.params & 0x3F);
Flags_SetSwitch(play, PARAMS_GET_U(this->dyna.actor.params, 0, 6));

if (wallType == BWALL_KD_FLOOR) {
Actor_PlaySfx(&this->dyna.actor, NA_SE_EV_EXPLOSION);
Expand Down
8 changes: 4 additions & 4 deletions src/overlays/actors/ovl_Bg_Dodoago/z_bg_dodoago.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void BgDodoago_Init(Actor* thisx, PlayState* play) {
this->dyna.bgId = DynaPoly_SetBgActor(play, &play->colCtx.dyna, &this->dyna.actor, colHeader);
ActorShape_Init(&this->dyna.actor.shape, 0.0f, NULL, 0.0f);

if (Flags_GetSwitch(play, this->dyna.actor.params & 0x3F)) {
if (Flags_GetSwitch(play, PARAMS_GET_U(this->dyna.actor.params, 0, 6))) {
BgDodoago_SetupAction(this, BgDodoago_DoNothing);
this->dyna.actor.shape.rot.x = 0x1333;
play->roomCtx.unk_74[BGDODOAGO_EYE_LEFT] = play->roomCtx.unk_74[BGDODOAGO_EYE_RIGHT] = 255;
Expand Down Expand Up @@ -156,7 +156,7 @@ void BgDodoago_WaitExplosives(BgDodoago* this, PlayState* play) {

if (((play->roomCtx.unk_74[BGDODOAGO_EYE_LEFT] == 255) && (this->state == BGDODOAGO_EYE_RIGHT)) ||
((play->roomCtx.unk_74[BGDODOAGO_EYE_RIGHT] == 255) && (this->state == BGDODOAGO_EYE_LEFT))) {
Flags_SetSwitch(play, this->dyna.actor.params & 0x3F);
Flags_SetSwitch(play, PARAMS_GET_U(this->dyna.actor.params, 0, 6));
this->state = 0;
Audio_PlaySfxGeneral(NA_SE_SY_CORRECT_CHIME, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale,
&gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb);
Expand Down Expand Up @@ -296,9 +296,9 @@ void BgDodoago_Update(Actor* thisx, PlayState* play) {
}
} else {
sTimer++;
Flags_GetSwitch(play, this->dyna.actor.params & 0x3F);
Flags_GetSwitch(play, PARAMS_GET_U(this->dyna.actor.params, 0, 6));
if (!sDisableBombCatcher && sTimer > 140) {
if (Flags_GetSwitch(play, this->dyna.actor.params & 0x3F)) {
if (Flags_GetSwitch(play, PARAMS_GET_U(this->dyna.actor.params, 0, 6))) {
// this prevents clearing the actor's parent pointer, effectively disabling the bomb catcher
sDisableBombCatcher++;
} else {
Expand Down