From 0f34468a775ffe5f4e95bea1dbb64cd763c224df Mon Sep 17 00:00:00 2001 From: Alex Bates Date: Sat, 15 Aug 2020 05:27:01 +0100 Subject: [PATCH] match GetAngleBetweenNPCs --- .../code_f8f60_len_1560/GetAngleBetweenNPCs.s | 49 ------------ include/common_structs.h | 78 ++++++++++--------- include/functions.h | 8 +- src/code_42e0_len_1f60.c | 2 +- src/code_e92d0_len_5da0.c | 8 +- src/code_f8f60_len_1560.c | 14 +++- src/code_fa4c0_len_3bf0.c | 6 +- 7 files changed, 68 insertions(+), 97 deletions(-) delete mode 100644 asm/nonmatchings/code_f8f60_len_1560/GetAngleBetweenNPCs.s diff --git a/asm/nonmatchings/code_f8f60_len_1560/GetAngleBetweenNPCs.s b/asm/nonmatchings/code_f8f60_len_1560/GetAngleBetweenNPCs.s deleted file mode 100644 index 29f7b7a346..0000000000 --- a/asm/nonmatchings/code_f8f60_len_1560/GetAngleBetweenNPCs.s +++ /dev/null @@ -1,49 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - - -glabel GetAngleBetweenNPCs -/* 0F90B8 802D4708 27BDFFD8 */ addiu $sp, $sp, -0x28 -/* 0F90BC 802D470C AFB20018 */ sw $s2, 0x18($sp) -/* 0F90C0 802D4710 0080902D */ daddu $s2, $a0, $zero -/* 0F90C4 802D4714 AFBF0020 */ sw $ra, 0x20($sp) -/* 0F90C8 802D4718 AFB3001C */ sw $s3, 0x1c($sp) -/* 0F90CC 802D471C AFB10014 */ sw $s1, 0x14($sp) -/* 0F90D0 802D4720 AFB00010 */ sw $s0, 0x10($sp) -/* 0F90D4 802D4724 8E50000C */ lw $s0, 0xc($s2) -/* 0F90D8 802D4728 8E050000 */ lw $a1, ($s0) -/* 0F90DC 802D472C 0C0B1EAF */ jal get_variable -/* 0F90E0 802D4730 26100004 */ addiu $s0, $s0, 4 -/* 0F90E4 802D4734 8E050000 */ lw $a1, ($s0) -/* 0F90E8 802D4738 26100004 */ addiu $s0, $s0, 4 -/* 0F90EC 802D473C 0240202D */ daddu $a0, $s2, $zero -/* 0F90F0 802D4740 0C0B1EAF */ jal get_variable -/* 0F90F4 802D4744 0040882D */ daddu $s1, $v0, $zero -/* 0F90F8 802D4748 0240202D */ daddu $a0, $s2, $zero -/* 0F90FC 802D474C 0220282D */ daddu $a1, $s1, $zero -/* 0F9100 802D4750 8E130000 */ lw $s3, ($s0) -/* 0F9104 802D4754 0C0B36B0 */ jal resolve_npc -/* 0F9108 802D4758 0040882D */ daddu $s1, $v0, $zero -/* 0F910C 802D475C 0240202D */ daddu $a0, $s2, $zero -/* 0F9110 802D4760 0220282D */ daddu $a1, $s1, $zero -/* 0F9114 802D4764 0C0B36B0 */ jal resolve_npc -/* 0F9118 802D4768 0040802D */ daddu $s0, $v0, $zero -/* 0F911C 802D476C 8C460038 */ lw $a2, 0x38($v0) -/* 0F9120 802D4770 C60C0038 */ lwc1 $f12, 0x38($s0) -/* 0F9124 802D4774 C60E0040 */ lwc1 $f14, 0x40($s0) -/* 0F9128 802D4778 0C00A720 */ jal atan2 -/* 0F912C 802D477C 8C470040 */ lw $a3, 0x40($v0) -/* 0F9130 802D4780 0240202D */ daddu $a0, $s2, $zero -/* 0F9134 802D4784 4600008D */ trunc.w.s $f2, $f0 -/* 0F9138 802D4788 44061000 */ mfc1 $a2, $f2 -/* 0F913C 802D478C 0C0B2026 */ jal set_variable -/* 0F9140 802D4790 0260282D */ daddu $a1, $s3, $zero -/* 0F9144 802D4794 8FBF0020 */ lw $ra, 0x20($sp) -/* 0F9148 802D4798 8FB3001C */ lw $s3, 0x1c($sp) -/* 0F914C 802D479C 8FB20018 */ lw $s2, 0x18($sp) -/* 0F9150 802D47A0 8FB10014 */ lw $s1, 0x14($sp) -/* 0F9154 802D47A4 8FB00010 */ lw $s0, 0x10($sp) -/* 0F9158 802D47A8 24020002 */ addiu $v0, $zero, 2 -/* 0F915C 802D47AC 03E00008 */ jr $ra -/* 0F9160 802D47B0 27BD0028 */ addiu $sp, $sp, 0x28 - diff --git a/include/common_structs.h b/include/common_structs.h index 686c170b72..8412b9e50d 100644 --- a/include/common_structs.h +++ b/include/common_structs.h @@ -4,6 +4,12 @@ #include "ultra64.h" #include "types.h" +typedef struct vec3f { + /* 0x00 */ f32 x; + /* 0x04 */ f32 y; + /* 0x08 */ f32 z; +} vec3f; // size = 0x0C + typedef struct matrix4f { /* 0x00 */ f32 mtx[4][4]; } matrix4f; // size = 0x40 @@ -18,7 +24,7 @@ typedef struct cam_pos_settings { /* 0x04 */ f32 boomLength; /* 0x08 */ f32 boomPitch; /* 0x0C */ f32 viewPitch; - /* 0x10 */ f32 position[3]; + /* 0x10 */ struct vec3f position; } cam_pos_settings; // size = 0x1C typedef struct partner_data { @@ -55,12 +61,12 @@ typedef struct npc { /* 0x024 */ char unk_24[4]; /* 0x028 */ u32 currentAnim; /* 0x02C */ char unk_2C[12]; - /* 0x038 */ f32 pos[3]; - /* 0x044 */ f32 rotation[3]; + /* 0x038 */ struct vec3f pos; + /* 0x044 */ struct vec3f rotation; /* 0x050 */ char unk_50[4]; - /* 0x054 */ f32 scale[3]; - /* 0x060 */ f32 moveToPos[3]; - /* 0x06C */ f32 colliderPos[3]; /* used during collision with player */ + /* 0x054 */ struct vec3f scale; + /* 0x060 */ struct vec3f moveToPos; + /* 0x06C */ struct vec3f colliderPos; /* used during collision with player */ /* 0x078 */ s32 shadowIndex; /* 0x07C */ f32 shadowScale; /* 0x080 */ char unk_80[8]; @@ -427,7 +433,7 @@ typedef struct camera { /* 0x03C */ f32 lookAt_eye[3]; /* 0x048 */ f32 lookAt_obj[3]; /* 0x054 */ char unk_54[12]; - /* 0x060 */ f32 targetPos[3]; + /* 0x060 */ struct vec3f targetPos; /* 0x06C */ f32 currentYaw; /* 0x070 */ char unk_70[4]; /* 0x074 */ f32 currentBoomYaw; @@ -454,13 +460,13 @@ typedef struct camera { /* 0x48C */ f32 linearInterpScale; /* 3.0? */ /* 0x490 */ f32 moveSpeed; /* 0x494 */ char unk_494[28]; - /* 0x4B0 */ f32 movePos[3]; + /* 0x4B0 */ struct vec3f movePos; /* 0x4BC */ char unk_4BC[28]; /* 0x4D8 */ s32 controllerType; /* 0x4DC */ f32 controllerBoomLen; /* 0x4E0 */ f32 controllerBoomPitch; - /* 0x4E4 */ f32 posA[3]; - /* 0x4F0 */ f32 posB[3]; + /* 0x4E4 */ struct vec3f posA; + /* 0x4F0 */ struct vec3f posB; /* 0x4FC */ f32 controllerViewPitch; /* 0x500 */ char unk_500[4]; /* 0x504 */ s16 boolTargetPlayer; @@ -737,7 +743,7 @@ typedef struct item_entity { /* 0x00 */ s32 flags; /* 0x04 */ s16 boundVar; /* see make_item_entity */ /* 0x06 */ char unk_06[2]; - /* 0x08 */ f32 position[3]; + /* 0x08 */ struct vec3f position; /* 0x14 */ struct item_entity_physics_data* physicsData; /* 0x18 */ s16 itemID; /* into item table, also worldIconID */ /* 0x1A */ u8 state; @@ -776,10 +782,10 @@ typedef struct sprite_component { /* 0x10 */ s32 loopCounter; /* 0x14 */ s32 currentRaster; /* 0x18 */ s32 currentPalette; - /* 0x1C */ f32 posOffset[3]; - /* 0x28 */ f32 compPos[3]; - /* 0x34 */ f32 rotation[3]; - /* 0x40 */ f32 scale[3]; + /* 0x1C */ struct vec3f posOffset; + /* 0x28 */ struct vec3f compPos; + /* 0x34 */ struct vec3f rotation; + /* 0x40 */ struct vec3f scale; /* 0x4C */ char unk_4C[4]; } sprite_component; // size = 0x50 @@ -856,7 +862,7 @@ typedef struct game_status { /* 0x08E */ s16 entryID; /* 0x090 */ char unk_90[4]; /* 0x094 */ f32 exitAngle; - /* 0x098 */ f32 playerPos[3]; + /* 0x098 */ struct vec3f playerPos; /* 0x0A4 */ f32 playerYaw; /* 0x0A8 */ char unk_A8[4]; /* 0x0AC */ s8 loadMenuState; @@ -898,8 +904,8 @@ typedef struct partner_anim_set { typedef struct shadow { /* 0x00 */ s32 flags; /* 0x04 */ char unk_04[12]; - /* 0x10 */ f32 position[3]; - /* 0x1C */ f32 scale[3]; + /* 0x10 */ struct vec3f position; + /* 0x1C */ struct vec3f scale; /* 0x28 */ char unk_28[80]; } shadow; // size = 0x78 @@ -959,13 +965,13 @@ typedef struct ActorPart { /* 0x10 */ struct actor_part_movement* movement; /* 0x14 */ s16 partOffset[3]; /* 0x1A */ s16 visualOffset[3]; - /* 0x20 */ f32 partOffsetFloat[3]; - /* 0x2C */ f32 absolutePosition[3]; - /* 0x38 */ f32 rotation[3]; + /* 0x20 */ struct vec3f partOffsetFloat; + /* 0x2C */ struct vec3f absolutePosition; + /* 0x38 */ struct vec3f rotation; /* 0x44 */ s16 rotationPivotOffset[3]; /* 0x4A */ char unk_4A[2]; /* 0x4C */ f32 scale[3]; - /* 0x58 */ f32 currentPos[3]; + /* 0x58 */ struct vec3f currentPos; /* 0x64 */ f32 yaw; /* 0x68 */ s16 unkOffset[2]; /* 0x6C */ s16 targetOffset[2]; @@ -1094,14 +1100,14 @@ typedef struct encounter { typedef struct player_path_element { /* 0x00 */ char unk_00[4]; - /* 0x04 */ f32 pos[3]; + /* 0x04 */ struct vec3f pos; } player_path_element; // size = 0x10 typedef struct animated_model { /* 0x00 */ s32 animModelID; - /* 0x04 */ f32 pos[3]; /* Created by retype action */ - /* 0x10 */ f32 rot[3]; - /* 0x1C */ f32 scale[3]; + /* 0x04 */ struct vec3f pos; /* Created by retype action */ + /* 0x10 */ struct vec3f rot; + /* 0x1C */ struct vec3f scale; /* 0x28 */ struct matrix4s* mtx; /* 0x2C */ char unk_2C[60]; /* 0x68 */ u32 currentAnimData; @@ -1134,9 +1140,9 @@ typedef struct Actor { /* 0x000 */ s32 flags; /* 0x004 */ char unk_04[4]; /* 0x008 */ struct StaticActorData* staticActorData; - /* 0x00C */ f32 moveCurrentPos[3]; - /* 0x018 */ f32 moveGoalPos[3]; - /* 0x024 */ f32 moveEndPos[3]; /* where other actors should target this one at. saved before partner switching */ + /* 0x00C */ struct vec3f moveCurrentPos; + /* 0x018 */ struct vec3f moveGoalPos; + /* 0x024 */ struct vec3f moveEndPos; /* where other actors should target this one at. saved before partner switching */ /* 0x030 */ char unk_30[24]; /* 0x048 */ f32 jumpAccel; /* 0x04C */ f32 moveSpeed; @@ -1154,9 +1160,9 @@ typedef struct Actor { /* 0x077 */ u8 jumpPartIndex; /* 0x078 */ char unk_78[16]; /* 0x088 */ s32 varTable[16]; - /* 0x0C8 */ f32 flyCurrentPos[3]; - /* 0x0D4 */ f32 flyGoalPos[3]; - /* 0x0E0 */ f32 flyTempPos[3]; /* used for start in fly functions, end in flyrun functions */ + /* 0x0C8 */ struct vec3f flyCurrentPos; + /* 0x0D4 */ struct vec3f flyGoalPos; + /* 0x0E0 */ struct vec3f flyTempPos; /* used for start in fly functions, end in flyrun functions */ /* 0x0EC */ char unk_EC[24]; /* 0x104 */ f32 flyJumpAccel; /* 0x108 */ f32 flySpeed; @@ -1171,8 +1177,8 @@ typedef struct Actor { /* 0x135 */ u8 footStepCounter; /* 0x136 */ u8 actorType; /* 0x137 */ char unk_137; - /* 0x138 */ f32 homePos[3]; - /* 0x144 */ f32 currentPos[3]; + /* 0x138 */ struct vec3f homePos; + /* 0x144 */ struct vec3f currentPos; /* 0x150 */ s16 otherPosheadOffset[3]; /* 0x156 */ s16 healthBarPosition[3]; /* 0x15C */ f32 rotation[3]; @@ -1333,8 +1339,8 @@ typedef struct player_status { /* 0x014 */ u8 enableCollisionOverlapsCheck; /* 0x015 */ u8 statusMenuCounterinputEnabledCounter; /* whether the C-up menu can appear */ /* 0x016 */ s16 lastGoodPosition[3]; - /* 0x01C */ f32 extraVelocity[3]; - /* 0x028 */ f32 position[3]; + /* 0x01C */ struct vec3f extraVelocity; + /* 0x028 */ struct vec3f position; /* 0x034 */ char unk_34[16]; /* 0x044 */ f32 decorationPos[2]; /* 0x04C */ char unk_4C[4]; diff --git a/include/functions.h b/include/functions.h index ca16a591cb..955a53438b 100644 --- a/include/functions.h +++ b/include/functions.h @@ -9,12 +9,14 @@ void osCleanupThread(void); void clone_model(u16 srcModelID, u16 newModelID); void update_collider_transform(s16 colliderID); -s32 get_variable(script_context* script, s32 pos); -f32 get_float_variable(script_context* script, s32 pos); -f32 set_float_variable(script_context* script, s32 dest, f32 value); +s32 get_variable(script_context* script, bytecode var); +void set_variable(script_context* script, bytecode var, s32 value); +f32 get_float_variable(script_context* script, bytecode var); +f32 set_float_variable(script_context* script, bytecode var, f32 value); void set_script_timescale(script_context* script, f32 timescale); f32 sin_deg(f32 x); f32 cos_deg(f32 x); +f32 atan2(f32 startX, f32 startZ, f32 endX, f32 endZ); s32 func_80055448(s32); s32 func_80055464(s32, s32); s32 func_800554A4(s32, s32); diff --git a/src/code_42e0_len_1f60.c b/src/code_42e0_len_1f60.c index a23149bc68..d04606d79d 100644 --- a/src/code_42e0_len_1f60.c +++ b/src/code_42e0_len_1f60.c @@ -52,7 +52,7 @@ INCLUDE_ASM(code_42e0_len_1f60, clamp_angle); INCLUDE_ASM(code_42e0_len_1f60, get_clamped_angle_diff); -INCLUDE_ASM(code_42e0_len_1f60, atan2); +f32 INCLUDE_ASM(code_42e0_len_1f60, atan2, f32 startX, f32 startZ, f32 endX, f32 endZ); INCLUDE_ASM(code_42e0_len_1f60, get_player_normal_yaw); diff --git a/src/code_e92d0_len_5da0.c b/src/code_e92d0_len_5da0.c index 36bdfa8ab9..cd039dcf2f 100644 --- a/src/code_e92d0_len_5da0.c +++ b/src/code_e92d0_len_5da0.c @@ -407,17 +407,17 @@ INCLUDE_ASM(code_e92d0_len_5da0, si_execute_next_command); INCLUDE_ASM(code_e92d0_len_5da0, si_handle_end); -s32 INCLUDE_ASM(code_e92d0_len_5da0, get_variable, script_context* script, s32 pos); +s32 INCLUDE_ASM(code_e92d0_len_5da0, get_variable, script_context* script, s32 var); INCLUDE_ASM(code_e92d0_len_5da0, get_variable_index); INCLUDE_ASM(code_e92d0_len_5da0, get_variable_index_alt); -INCLUDE_ASM(code_e92d0_len_5da0, set_variable); +s32 INCLUDE_ASM(code_e92d0_len_5da0, set_variable, script_context* script, s32 var, s32 value); -f32 INCLUDE_ASM(code_e92d0_len_5da0, get_float_variable, script_context* script, s32 pos); +f32 INCLUDE_ASM(code_e92d0_len_5da0, get_float_variable, script_context* script, s32 var); -f32 INCLUDE_ASM(code_e92d0_len_5da0, set_float_variable, script_context* script, s32 dest, f32 value); +f32 INCLUDE_ASM(code_e92d0_len_5da0, set_float_variable, script_context* script, s32 var, f32 value); INCLUDE_ASM(code_e92d0_len_5da0, si_goto_label); diff --git a/src/code_f8f60_len_1560.c b/src/code_f8f60_len_1560.c index ad9be97f43..7e1a4e99a8 100644 --- a/src/code_f8f60_len_1560.c +++ b/src/code_f8f60_len_1560.c @@ -42,7 +42,19 @@ s32 RandInt(script_context* script, s32 initialCall) { return 2; } -INCLUDE_ASM(code_f8f60_len_1560, GetAngleBetweenNPCs); +s32 GetAngleBetweenNPCs(script_context* script, s32 initialCall) { + bytecode* ptrReadPos = script->ptrReadPos; + + NPC aID = get_variable(script, *ptrReadPos++); + NPC bID = get_variable(script, *ptrReadPos++); + bytecode outVar = *ptrReadPos++; + + npc* a = resolve_npc(script, aID); + npc* b = resolve_npc(script, bID); + set_variable(script, outVar, atan2(a->pos.x, a->pos.z, b->pos.x, b->pos.z)); + + return 2; +} INCLUDE_ASM(code_f8f60_len_1560, GetAngleToNPC); diff --git a/src/code_fa4c0_len_3bf0.c b/src/code_fa4c0_len_3bf0.c index f66a4cbda5..d401358064 100644 --- a/src/code_fa4c0_len_3bf0.c +++ b/src/code_fa4c0_len_3bf0.c @@ -312,9 +312,9 @@ s32 SetItemPos(script_context* script, s32 initialCall) { z = get_variable(script, *ptrReadPos++); ptrItemEntity = (item_entity *) get_item_entity(itemEntityIndex); - ptrItemEntity->position[0] = x; - ptrItemEntity->position[1] = y; - ptrItemEntity->position[2] = z; + ptrItemEntity->position.x = x; + ptrItemEntity->position.y = y; + ptrItemEntity->position.z = z; return 2; }