Skip to content

Commit

Permalink
player cleanup and fixed horse archery third person camera #179
Browse files Browse the repository at this point in the history
  • Loading branch information
blawar committed Mar 1, 2022
1 parent ee96556 commit 52011c3
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 33 deletions.
4 changes: 2 additions & 2 deletions include/def/z_skelanime.h
Expand Up @@ -14,8 +14,8 @@ struct Vec3f;
void AnimationContext_DisableQueue(GlobalContext* globalCtx);
void AnimationContext_Reset(AnimationContext* animationCtx);
void AnimationContext_SetCopyAll(GlobalContext* globalCtx, s32 vecCount, Vec3s* dst, Vec3s* src);
void AnimationContext_SetCopyFalse(GlobalContext* globalCtx, s32 vecCount, Vec3s* dst, Vec3s* src, u8* copyFlag);
void AnimationContext_SetCopyTrue(GlobalContext* globalCtx, s32 vecCount, Vec3s* dst, Vec3s* src, u8* copyFlag);
void AnimationContext_SetCopyFalse(GlobalContext* globalCtx, s32 vecCount, Vec3s* dst, Vec3s* src, const u8* copyFlag);
void AnimationContext_SetCopyTrue(GlobalContext* globalCtx, s32 vecCount, Vec3s* dst, Vec3s* src, const u8* copyFlag);
void AnimationContext_SetInterp(GlobalContext* globalCtx, s32 vecCount, Vec3s* base, Vec3s* mod, f32 weight);
void AnimationContext_SetLoadFrame(GlobalContext* globalCtx, LinkAnimationHeader* animation, s32 frame, s32 limbCount, Vec3s* frameTable);
void AnimationContext_SetMoveActor(GlobalContext* globalCtx, Actor* actor, SkelAnime* skelAnime, f32 arg3);
Expand Down
4 changes: 2 additions & 2 deletions include/z64animation.h
Expand Up @@ -157,15 +157,15 @@ struct AnimEntryCopyTrue {
/* 0x001 */ u8 vecCount;
/* 0x004 */ Vec3s* dst;
/* 0x008 */ Vec3s* src;
/* 0x00C */ u8* copyFlag;
/* 0x00C */ const u8* copyFlag;
}; // size = 0x10

struct AnimEntryCopyFalse {
/* 0x000 */ u8 queueFlag;
/* 0x001 */ u8 vecCount;
/* 0x004 */ Vec3s* dst;
/* 0x008 */ Vec3s* src;
/* 0x00C */ u8* copyFlag;
/* 0x00C */ const u8* copyFlag;
}; // size = 0x10

struct AnimEntryMoveActor {
Expand Down
2 changes: 1 addition & 1 deletion src/code/z_actor.cpp
Expand Up @@ -1010,7 +1010,7 @@ f32 Player_GetHeight(Player* player) {
f32 func_8002DCE4(Player* player) {
if (player->stateFlags1 & PLAYER_STATE_HORSE_MOUNTED) {//When mounted on a horse
return 8.0f;
} else if (player->stateFlags1 & 0x8000000) {//When swimming
} else if (player->stateFlags1 & PLAYER_STATE_SWIMMING) {//When swimming
return (R_RUN_SPEED_LIMIT / 100.0f) * 0.6f;
} else {
return R_RUN_SPEED_LIMIT / 100.0f;
Expand Down
2 changes: 1 addition & 1 deletion src/code/z_camera.cpp
Expand Up @@ -548,7 +548,7 @@ s32 Camera_GetWaterBoxDataIdx(Camera* camera, f32* waterY) {
return -1;
}

if (!(camera->player->stateFlags1 & 0x8000000)) {
if (!(camera->player->stateFlags1 & PLAYER_STATE_SWIMMING)) {
// player is not swimming
*waterY = BGCHECK_Y_MIN;
return -1;
Expand Down
6 changes: 6 additions & 0 deletions src/code/z_camera_data.cpp
Expand Up @@ -19,9 +19,15 @@ typedef struct {
union {
u32 unk_00;
struct {
#ifdef LITTLE_ENDIAN
u32 validModes : 30;
u32 unk_bit1 : 1;
u32 unk_bit0 : 1;
#else
u32 unk_bit0 : 1;
u32 unk_bit1 : 1;
u32 validModes : 30;
#endif
};
};
CameraMode* cameraModes;
Expand Down
2 changes: 2 additions & 0 deletions src/code/z_kaleido_scope_call.cpp
Expand Up @@ -8,6 +8,7 @@
#include "def/z_kaleido_scope_call.h"
#include "def/z_kaleido_setup.h"

void Player_Reset();
void (*sKaleidoScopeUpdateFunc)(GlobalContext* globalCtx);
void (*sKaleidoScopeDrawFunc)(GlobalContext* globalCtx);
f32 gBossMarkScale;
Expand Down Expand Up @@ -37,6 +38,7 @@ void KaleidoScopeCall_LoadPlayer() {
osSyncPrintf(VT_RST);

KaleidoManager_LoadOvl(playerActorOvl);
Player_Reset();
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/code/z_player_lib.cpp
Expand Up @@ -325,7 +325,7 @@ void Player_SetBootData(GlobalContext* globalCtx, Player* pthis) {
currentBoots = PLAYER_BOOTS_NORMAL_CHILD;
}
} else if (currentBoots == PLAYER_BOOTS_IRON) {
if (pthis->stateFlags1 & 0x8000000) {//Swimming?
if (pthis->stateFlags1 & PLAYER_STATE_SWIMMING) {//Swimming?
currentBoots = PLAYER_BOOTS_IRON_UNDERWATER;
}
REG(27) = 500;
Expand Down Expand Up @@ -648,7 +648,7 @@ s32 func_8008F2F8(GlobalContext* globalCtx) {
} else if ((pthis->unk_840 > 80) &&
((pthis->currentBoots == PLAYER_BOOTS_IRON) || (pthis->unk_840 >= 300))) { // Deep underwater
var = ((pthis->currentBoots == PLAYER_BOOTS_IRON) && (pthis->actor.bgCheckFlags & 1)) ? 1 : 3;
} else if (pthis->stateFlags1 & 0x8000000) { // Swimming
} else if (pthis->stateFlags1 & PLAYER_STATE_SWIMMING) { // Swimming
var = 2;
} else {
return 0;
Expand Down Expand Up @@ -958,7 +958,7 @@ s32 func_80090014(GlobalContext* globalCtx, s32 limbIndex, Gfx** dList, Vec3f* p
} else if ((D_80160014 == 6) && (pthis->stateFlags1 & 0x2000000)) {
dLists = &D_80125E08[gSaveContext.linkAge];
D_80160014 = 0;
} else if ((pthis->leftHandType == 0) && (pthis->actor.speedXZ > 2.0f) && !(pthis->stateFlags1 & 0x8000000)) {
} else if ((pthis->leftHandType == 0) && (pthis->actor.speedXZ > 2.0f) && !(pthis->stateFlags1 & PLAYER_STATE_SWIMMING)) {
dLists = &D_80125E18[gSaveContext.linkAge];
D_80160014 = 1;
}
Expand All @@ -969,7 +969,7 @@ s32 func_80090014(GlobalContext* globalCtx, s32 limbIndex, Gfx** dList, Vec3f* p

if (D_80160018 == 10) {
dLists += pthis->currentShield * 4;
} else if ((pthis->rightHandType == 8) && (pthis->actor.speedXZ > 2.0f) && !(pthis->stateFlags1 & 0x8000000)) {
} else if ((pthis->rightHandType == 8) && (pthis->actor.speedXZ > 2.0f) && !(pthis->stateFlags1 & PLAYER_STATE_SWIMMING)) {
dLists = &D_80125E58[gSaveContext.linkAge];
D_80160018 = 9;
}
Expand Down
8 changes: 4 additions & 4 deletions src/code/z_skelanime.cpp
Expand Up @@ -906,7 +906,7 @@ void AnimationContext_SetInterp(GlobalContext* globalCtx, s32 vecCount, Vec3s* b
/**
* Requests copying vectors from src frame table to dst frame table whose copy flag is true
*/
void AnimationContext_SetCopyTrue(GlobalContext* globalCtx, s32 vecCount, Vec3s* dst, Vec3s* src, u8* copyFlag) {
void AnimationContext_SetCopyTrue(GlobalContext* globalCtx, s32 vecCount, Vec3s* dst, Vec3s* src, const u8* copyFlag) {
AnimationEntry* entry = AnimationContext_AddEntry(&globalCtx->animationCtx, ANIMENTRY_COPYTRUE);

if (entry != NULL) {
Expand All @@ -921,7 +921,7 @@ void AnimationContext_SetCopyTrue(GlobalContext* globalCtx, s32 vecCount, Vec3s*
/**
* Requests copying vectors from src frame table to dst frame table whose copy flag is false
*/
void AnimationContext_SetCopyFalse(GlobalContext* globalCtx, s32 vecCount, Vec3s* dst, Vec3s* src, u8* copyFlag) {
void AnimationContext_SetCopyFalse(GlobalContext* globalCtx, s32 vecCount, Vec3s* dst, Vec3s* src, const u8* copyFlag) {
AnimationEntry* entry = AnimationContext_AddEntry(&globalCtx->animationCtx, ANIMENTRY_COPYFALSE);

if (entry != NULL) {
Expand Down Expand Up @@ -990,7 +990,7 @@ void AnimationContext_CopyTrue(GlobalContext* globalCtx, AnimationEntryData* dat
if (!(entry->queueFlag & sDisableAnimQueueFlags)) {
Vec3s* dst = entry->dst;
Vec3s* src = entry->src;
u8* copyFlag = entry->copyFlag;
const u8* copyFlag = entry->copyFlag;
s32 i;

for (i = 0; i < entry->vecCount; i++, dst++, src++) {
Expand All @@ -1010,7 +1010,7 @@ void AnimationContext_CopyFalse(GlobalContext* globalCtx, AnimationEntryData* da
if (!(entry->queueFlag & sDisableAnimQueueFlags)) {
Vec3s* dst = entry->dst;
Vec3s* src = entry->src;
u8* copyFlag = entry->copyFlag;
const u8* copyFlag = entry->copyFlag;
s32 i;

for (i = 0; i < entry->vecCount; i++, dst++, src++) {
Expand Down
64 changes: 46 additions & 18 deletions src/overlays/actors/ovl_player_actor/z_player.cpp
Expand Up @@ -321,9 +321,9 @@ static Input* sControlInput;

// .data

static u8 D_80853410[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
static const u8 D_80853410[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };

static PlayerAgeProperties sAgeProperties[] = {
static const PlayerAgeProperties sAgeProperties[] = {
{
56.0f,
90.0f,
Expand Down Expand Up @@ -448,14 +448,14 @@ static s16 D_80853610 = 0;
static s32 D_80853614 = 0;
static s32 D_80853618 = 0;

static u16 D_8085361C[] = {
static const u16 D_8085361C[] = {
NA_SE_VO_LI_SWEAT,
NA_SE_VO_LI_SNEEZE,
NA_SE_VO_LI_RELAX,
NA_SE_VO_LI_FALL_L,
};

static GetItemEntry sGetItemTable[] = {
static const GetItemEntry sGetItemTable[] = {
GET_ITEM(ITEM_BOMBS_5, OBJECT_GI_BOMB_1, GID_BOMB, 0x32, 0x59, CHEST_ANIM_SHORT),
GET_ITEM(ITEM_NUTS_5, OBJECT_GI_NUTS, GID_NUTS, 0x34, 0x0C, CHEST_ANIM_SHORT),
GET_ITEM(ITEM_BOMBCHU, OBJECT_GI_BOMB_2, GID_BOMBCHU, 0x33, 0x80, CHEST_ANIM_SHORT),
Expand Down Expand Up @@ -882,17 +882,17 @@ static struct_80832924 D_80853E4C[] = {
{ NA_SE_VO_LI_RELAX, -0x2014 },
};

static struct_80832924* D_80853E50[] = {
static const struct_80832924* D_80853E50[] = {
D_80853DEC, D_80853DF0, D_80853DF4, D_80853DF8, D_80853DFC, D_80853E10,
D_80853E28, D_80853E34, D_80853E44, D_80853E4C, NULL,
};

static u8 D_80853E7C[] = {
static const u8 D_80853E7C[] = {
0, 0, 1, 1, 2, 2, 2, 2, 10, 10, 10, 10, 10, 10, 3, 3, 4, 4, 8, 8, 5, 5, 6, 6, 7, 7, 9, 9, 0,
};

// Used to map item IDs to action params
static s8 sItemActionParams[] = {
static const s8 sItemActionParams[] = {
PLAYER_AP_STICK,
PLAYER_AP_NUT,
PLAYER_AP_BOMB,
Expand Down Expand Up @@ -1259,7 +1259,7 @@ void func_80832698(Player* pthis, u16 sfxId) {
}

void func_808326F0(Player* pthis) {
u16* entry = &D_8085361C[0];
const u16* entry = &D_8085361C[0];
s32 i;

for (i = 0; i < 4; i++) {
Expand Down Expand Up @@ -1325,7 +1325,7 @@ void func_808328EC(Player* pthis, u16 sfxId) {
pthis->stateFlags2 |= 8;
}

void func_80832924(Player* pthis, struct_80832924* entry) {
static void func_80832924(Player* pthis, const struct_80832924* entry) {
s32 data;
s32 flags;
u32 cont;
Expand Down Expand Up @@ -1529,15 +1529,15 @@ void func_8083328C(GlobalContext* globalCtx, Player* pthis, LinkAnimationHeader*
}

s32 Player_IsSwimmingWithoutIronBoots(Player* pthis) {
return (pthis->stateFlags1 & 0x8000000) && (pthis->currentBoots != PLAYER_BOOTS_IRON);
return (pthis->stateFlags1 & PLAYER_STATE_SWIMMING) && (pthis->currentBoots != PLAYER_BOOTS_IRON);
}

s32 func_808332E4(Player* pthis) {
return (pthis->stateFlags1 & 0x1000000);
}

void func_808332F4(Player* pthis, GlobalContext* globalCtx) {
GetItemEntry* giEntry = &sGetItemTable[pthis->getItemId - 1];
const GetItemEntry* giEntry = &sGetItemTable[pthis->getItemId - 1];

pthis->unk_862 = ABS(giEntry->gi);
}
Expand Down Expand Up @@ -4658,7 +4658,7 @@ static LinkAnimationHeader* D_80854548[] = {
s32 func_8083B040(Player* pthis, GlobalContext* globalCtx) {
s32 sp2C;
s32 sp28;
GetItemEntry* giEntry;
const GetItemEntry* giEntry;
Actor* targetActor;

if ((pthis->unk_6AD != 0) &&
Expand Down Expand Up @@ -5822,7 +5822,7 @@ static s32 D_80854598[] = {
0xFFDB0871, 0xF8310000, 0x00940470, 0xF3980000, 0xFFB504A9, 0x0C9F0000, 0x08010402,
};

void func_8083E4C4(GlobalContext* globalCtx, Player* pthis, GetItemEntry* giEntry) {
static void func_8083E4C4(GlobalContext* globalCtx, Player* pthis, const GetItemEntry* giEntry) {
s32 sp1C = giEntry->field & 0x1F;

if (!(giEntry->field & 0x80)) {
Expand All @@ -5849,7 +5849,7 @@ s32 func_8083E5A8(Player* pthis, GlobalContext* globalCtx) {
}

if (pthis->getItemId < GI_MAX) {
GetItemEntry* giEntry = &sGetItemTable[pthis->getItemId - 1];
const GetItemEntry* giEntry = &sGetItemTable[pthis->getItemId - 1];

if ((interactedActor != &pthis->actor) && !iREG(67)) {
interactedActor->parent = &pthis->actor;
Expand Down Expand Up @@ -5878,7 +5878,7 @@ s32 func_8083E5A8(Player* pthis, GlobalContext* globalCtx) {
} else if (CHECK_BTN_ALL(sControlInput->press.button, BTN_A) && !(pthis->stateFlags1 & 0x800) &&
!(pthis->stateFlags2 & 0x400)) {
if (pthis->getItemId != GI_NONE) {
GetItemEntry* giEntry = &sGetItemTable[-pthis->getItemId - 1];
const GetItemEntry* giEntry = &sGetItemTable[-pthis->getItemId - 1];
EnBox* chest = (EnBox*)interactedActor;

if (giEntry->itemId != ITEM_NONE) {
Expand Down Expand Up @@ -11743,7 +11743,7 @@ void func_8084DFAC(GlobalContext* globalCtx, Player* pthis) {
}

s32 func_8084DFF4(GlobalContext* globalCtx, Player* pthis) {
GetItemEntry* giEntry;
const GetItemEntry* giEntry;
s32 temp1;
s32 temp2;

Expand Down Expand Up @@ -12216,7 +12216,7 @@ void func_8084F104(Player* pthis, GlobalContext* globalCtx) {

func_80853148(globalCtx, targetActor);
} else {
GetItemEntry* giEntry = &sGetItemTable[D_80854528[pthis->exchangeItemId - 1] - 1];
const GetItemEntry* giEntry = &sGetItemTable[D_80854528[pthis->exchangeItemId - 1] - 1];

if (pthis->itemActionParam >= PLAYER_AP_LETTER_ZELDA) {
if (giEntry->gi >= 0) {
Expand Down Expand Up @@ -14118,4 +14118,32 @@ void func_80853148(GlobalContext* globalCtx, Actor* actor) {
pthis->naviActor->flags |= ACTOR_FLAG_8;
func_80835EA4(globalCtx, 0xB);
}
}
}

void Player_Reset()
{
D_80858AA0 = 0;
D_80858AA4 = 0;
D_80858AA8 = {0, 0, 0};
sControlInput = nullptr;

D_808535D0 = false;
D_808535D4 = 0.0f;
D_808535D8 = 0;
D_808535DC = 0;
D_808535E0 = 0;
D_808535E4 = 0;
D_808535E8 = 1.0f;
D_808535EC = 1.0f;
D_808535F0 = 0;
D_808535F4 = 0;
D_808535F8 = 0;
D_808535FC = 0;
D_80853600 = 0.0f;
D_80853604 = 0;
D_80853608 = 0;
D_8085360C = 0;
D_80853610 = 0;
D_80853614 = 0;
D_80853618 = 0;
}
2 changes: 1 addition & 1 deletion src/overlays/actors/ovl_player_actor/z_player.h
Expand Up @@ -183,7 +183,7 @@ struct Player {
/* 0x066C */ s32 unk_66C;
/* 0x0670 */ s32 swordEffectIndex;
/* 0x0674 */ PlayerFunc674 func_674;
/* 0x0678 */ PlayerAgeProperties* ageProperties;
/* 0x0678 */ const PlayerAgeProperties* ageProperties;
/* 0x067C */ u32 stateFlags1;//0x8000000 when swimming, 0x800000 when mounted on a horse
/* 0x0680 */ u32 stateFlags2;
/* 0x0684 */ Actor* unk_684;
Expand Down

0 comments on commit 52011c3

Please sign in to comment.