Skip to content

Commit

Permalink
Cleanup Vector3f
Browse files Browse the repository at this point in the history
  • Loading branch information
intns committed Jan 2, 2024
1 parent acab183 commit 84ef91e
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 41 deletions.
110 changes: 110 additions & 0 deletions asm/plugPikiKando/odoMeter.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
.include "macros.inc"
.section .text, "ax" # 0x80005560 - 0x80221F60
.global __ct__8OdoMeterFv
__ct__8OdoMeterFv:
/* 800CD804 000CA764 C0 02 96 48 */ lfs f0, lbl_803E9848@sda21(r2)
/* 800CD808 000CA768 D0 03 00 00 */ stfs f0, 0(r3)
/* 800CD80C 000CA76C D0 03 00 04 */ stfs f0, 4(r3)
/* 800CD810 000CA770 4E 80 00 20 */ blr

.global start__8OdoMeterFff
start__8OdoMeterFff:
/* 800CD814 000CA774 D0 23 00 0C */ stfs f1, 0xc(r3)
/* 800CD818 000CA778 D0 23 00 04 */ stfs f1, 4(r3)
/* 800CD81C 000CA77C D0 43 00 08 */ stfs f2, 8(r3)
/* 800CD820 000CA780 C0 02 96 48 */ lfs f0, lbl_803E9848@sda21(r2)
/* 800CD824 000CA784 D0 03 00 00 */ stfs f0, 0(r3)
/* 800CD828 000CA788 4E 80 00 20 */ blr

.global moving__8OdoMeterFR8Vector3fR8Vector3f
moving__8OdoMeterFR8Vector3fR8Vector3f:
/* 800CD82C 000CA78C 94 21 FF A0 */ stwu r1, -0x60(r1)
/* 800CD830 000CA790 C0 23 00 04 */ lfs f1, 4(r3)
/* 800CD834 000CA794 C0 02 96 48 */ lfs f0, lbl_803E9848@sda21(r2)
/* 800CD838 000CA798 FC 01 00 40 */ fcmpo cr0, f1, f0
/* 800CD83C 000CA79C 40 81 00 14 */ ble lbl_800CD850
/* 800CD840 000CA7A0 80 CD 2D EC */ lwz r6, gsys@sda21(r13)
/* 800CD844 000CA7A4 C0 06 02 8C */ lfs f0, 0x28c(r6)
/* 800CD848 000CA7A8 EC 01 00 28 */ fsubs f0, f1, f0
/* 800CD84C 000CA7AC D0 03 00 04 */ stfs f0, 4(r3)
lbl_800CD850:
/* 800CD850 000CA7B0 C0 23 00 00 */ lfs f1, 0(r3)
/* 800CD854 000CA7B4 C0 02 96 4C */ lfs f0, lbl_803E984C@sda21(r2)
/* 800CD858 000CA7B8 FC 01 00 40 */ fcmpo cr0, f1, f0
/* 800CD85C 000CA7BC 40 80 00 AC */ bge lbl_800CD908
/* 800CD860 000CA7C0 C0 64 00 04 */ lfs f3, 4(r4)
/* 800CD864 000CA7C4 C0 45 00 04 */ lfs f2, 4(r5)
/* 800CD868 000CA7C8 C0 24 00 00 */ lfs f1, 0(r4)
/* 800CD86C 000CA7CC C0 05 00 00 */ lfs f0, 0(r5)
/* 800CD870 000CA7D0 EC 63 10 28 */ fsubs f3, f3, f2
/* 800CD874 000CA7D4 C0 44 00 08 */ lfs f2, 8(r4)
/* 800CD878 000CA7D8 EC 81 00 28 */ fsubs f4, f1, f0
/* 800CD87C 000CA7DC C0 05 00 08 */ lfs f0, 8(r5)
/* 800CD880 000CA7E0 EC 23 00 F2 */ fmuls f1, f3, f3
/* 800CD884 000CA7E4 EC 62 00 28 */ fsubs f3, f2, f0
/* 800CD888 000CA7E8 C0 02 96 48 */ lfs f0, lbl_803E9848@sda21(r2)
/* 800CD88C 000CA7EC EC 44 01 32 */ fmuls f2, f4, f4
/* 800CD890 000CA7F0 EC 63 00 F2 */ fmuls f3, f3, f3
/* 800CD894 000CA7F4 EC 22 08 2A */ fadds f1, f2, f1
/* 800CD898 000CA7F8 EC 83 08 2A */ fadds f4, f3, f1
/* 800CD89C 000CA7FC FC 04 00 40 */ fcmpo cr0, f4, f0
/* 800CD8A0 000CA800 40 81 00 5C */ ble lbl_800CD8FC
/* 800CD8A4 000CA804 FC 20 20 34 */ frsqrte f1, f4
/* 800CD8A8 000CA808 C8 62 96 50 */ lfd f3, lbl_803E9850@sda21(r2)
/* 800CD8AC 000CA80C C8 42 96 58 */ lfd f2, lbl_803E9858@sda21(r2)
/* 800CD8B0 000CA810 FC 01 00 72 */ fmul f0, f1, f1
/* 800CD8B4 000CA814 FC 23 00 72 */ fmul f1, f3, f1
/* 800CD8B8 000CA818 FC 04 00 32 */ fmul f0, f4, f0
/* 800CD8BC 000CA81C FC 02 00 28 */ fsub f0, f2, f0
/* 800CD8C0 000CA820 FC 21 00 32 */ fmul f1, f1, f0
/* 800CD8C4 000CA824 FC 01 00 72 */ fmul f0, f1, f1
/* 800CD8C8 000CA828 FC 23 00 72 */ fmul f1, f3, f1
/* 800CD8CC 000CA82C FC 04 00 32 */ fmul f0, f4, f0
/* 800CD8D0 000CA830 FC 02 00 28 */ fsub f0, f2, f0
/* 800CD8D4 000CA834 FC 21 00 32 */ fmul f1, f1, f0
/* 800CD8D8 000CA838 FC 01 00 72 */ fmul f0, f1, f1
/* 800CD8DC 000CA83C FC 23 00 72 */ fmul f1, f3, f1
/* 800CD8E0 000CA840 FC 04 00 32 */ fmul f0, f4, f0
/* 800CD8E4 000CA844 FC 02 00 28 */ fsub f0, f2, f0
/* 800CD8E8 000CA848 FC 01 00 32 */ fmul f0, f1, f0
/* 800CD8EC 000CA84C FC 04 00 32 */ fmul f0, f4, f0
/* 800CD8F0 000CA850 FC 00 00 18 */ frsp f0, f0
/* 800CD8F4 000CA854 D0 01 00 38 */ stfs f0, 0x38(r1)
/* 800CD8F8 000CA858 C0 81 00 38 */ lfs f4, 0x38(r1)
lbl_800CD8FC:
/* 800CD8FC 000CA85C C0 03 00 00 */ lfs f0, 0(r3)
/* 800CD900 000CA860 EC 00 20 2A */ fadds f0, f0, f4
/* 800CD904 000CA864 D0 03 00 00 */ stfs f0, 0(r3)
lbl_800CD908:
/* 800CD908 000CA868 C0 03 00 04 */ lfs f0, 4(r3)
/* 800CD90C 000CA86C C0 42 96 48 */ lfs f2, lbl_803E9848@sda21(r2)
/* 800CD910 000CA870 FC 00 10 40 */ fcmpo cr0, f0, f2
/* 800CD914 000CA874 4C 40 13 82 */ cror 2, 0, 2
/* 800CD918 000CA878 40 82 00 2C */ bne lbl_800CD944
/* 800CD91C 000CA87C C0 23 00 00 */ lfs f1, 0(r3)
/* 800CD920 000CA880 C0 03 00 08 */ lfs f0, 8(r3)
/* 800CD924 000CA884 FC 01 00 40 */ fcmpo cr0, f1, f0
/* 800CD928 000CA888 40 80 00 10 */ bge lbl_800CD938
/* 800CD92C 000CA88C D0 43 00 00 */ stfs f2, 0(r3)
/* 800CD930 000CA890 38 60 00 00 */ li r3, 0
/* 800CD934 000CA894 48 00 00 14 */ b lbl_800CD948
lbl_800CD938:
/* 800CD938 000CA898 C0 03 00 0C */ lfs f0, 0xc(r3)
/* 800CD93C 000CA89C D0 03 00 04 */ stfs f0, 4(r3)
/* 800CD940 000CA8A0 D0 43 00 00 */ stfs f2, 0(r3)
lbl_800CD944:
/* 800CD944 000CA8A4 38 60 00 01 */ li r3, 1
lbl_800CD948:
/* 800CD948 000CA8A8 38 21 00 60 */ addi r1, r1, 0x60
/* 800CD94C 000CA8AC 4E 80 00 20 */ blr

.section .sdata2, "a" # 0x803E8200 - 0x803EC840
.balign 8
lbl_803E9848:
.float 0.0
lbl_803E984C:
.float 100.0
lbl_803E9850:
.double 0.5
lbl_803E9858:
.double 3.0
48 changes: 39 additions & 9 deletions include/Vector3f.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,50 @@
#define _VECTOR3F_H

#include "types.h"
#include "math.h"

struct Vector3f {
f32 x, y, z;
Vector3f() {};
Vector3f() { }
Vector3f(float const& x, float const& y, float const& z);
f32 getX() { return this->x; } // inline function call
f32 getY() { return this->y; } // inline function call
f32 getZ() { return this->z; } // inline function call
};

inline float vecdiffX(Vector3f& argA, Vector3f& argB) { return argA.getX() - argB.getX(); }
inline f32 distance(Vector3f& to)
{
Vector3f result;
result.sub2(to, *this);
return result.length();
}

inline void sub2(Vector3f& a, Vector3f& b)
{
f32 newZ = a.getZ() - b.getZ();
f32 newY = a.getY() - b.getY();
f32 newX = a.getX() - b.getX();
set(newX, newY, newZ);
}

inline void set(float const& pX, float const& pY, float const& pZ)
{
x = pX;
y = pY;
z = pZ;
}

inline f32 squaredLength() const { return x * x + y * y + z * z; }
inline f32 length() const { return sqrtf(squaredLength()); }

inline float vecdiffY(Vector3f& argA, Vector3f& argB) { return argA.getY() - argB.getY(); }
const f32 getX() const { return x; }
const f32 getY() const { return y; }
const f32 getZ() const { return z; }

f32 getX() { return x; }
f32 getY() { return y; }
f32 getZ() { return z; }

f32 x, y, z;
};

inline float vecdiffZ(Vector3f& argA, Vector3f& argB) { return argA.getZ() - argB.getZ(); }
inline float Vector3f_diffX(Vector3f& a, Vector3f& b) { return a.getX() - b.getX(); }
inline float Vector3f_diffY(Vector3f& a, Vector3f& b) { return a.getY() - b.getY(); }
inline float Vector3f_diffZ(Vector3f& a, Vector3f& b) { return a.getZ() - b.getZ(); }

#endif
28 changes: 15 additions & 13 deletions include/odoMeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,31 @@
#include "math.h"

struct OdoMeter { // TODO: figure out what these actually are
float A; // _00
float B; // _04
float C; // _08
float D; // _0C
float _00; // _00
float _04; // _04
float _08; // _08
float _0C; // _0C

OdoMeter();
void start(float argA, float argB);
bool moving(Vector3f& argA, Vector3f& argB);
inline void odoGsys(void) // made up for OdoMeter::moving

inline void unknown1()
{
if (B > 0.0f) {
B -= gsys->m_28C;
if (_04 > 0.0f) {
_04 -= gsys->m_28C;
}
}
inline bool odoRet(void) // made up for OdoMeter::moving

inline bool unknown2()
{
if (B <= 0.0f) {
if (A < C) {
A = 0.0f;
if (_04 <= 0.0f) {
if (_00 < _08) {
_00 = 0.0f;
return false;
}
B = D;
A = 0.0f;
_04 = _0C;
_00 = 0.0f;
}
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugPikiKando/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ KANDO_FILES:=\
$(BUILD_DIR)/asm/plugPikiKando/aiAction.o\
$(BUILD_DIR)/asm/plugPikiKando/pikiInf.o\
$(BUILD_DIR)/asm/plugPikiKando/piki.o\
$(BUILD_DIR)/src/plugPikiKando/odoMeter.o\
$(BUILD_DIR)/asm/plugPikiKando/odoMeter.o\
$(BUILD_DIR)/asm/plugPikiKando/pikidoKill.o\
$(BUILD_DIR)/asm/plugPikiKando/pikiMgr.o\
$(BUILD_DIR)/asm/plugPikiKando/pikiState.o\
Expand Down
37 changes: 19 additions & 18 deletions src/plugPikiKando/odoMeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ void _Print(char*, ...)
*/
OdoMeter::OdoMeter()
{
A = 0.0;
B = 0.0;
_00 = 0.0;
_04 = 0.0;
}

/*
Expand All @@ -40,30 +40,31 @@ OdoMeter::OdoMeter()
*/
void OdoMeter::start(float argA, float argB)
{
D = argA;
B = argA;
C = argB;
A = 0.0;
_0C = argA;
_04 = argA;
_08 = argB;
_00 = 0.0;
}

/*
* --INFO--
* Address: 800CD82C
* Size: 000124
* This function has some silly inlining.
* The following, while likely fake, matches the stack.
* TODO
*/
bool OdoMeter::moving(Vector3f& argA, Vector3f& argB)
{
float dummy[4]; // useless padding variable for stack allocation match
Vector3f vec;
odoGsys();
if (A < 100.0f) {
vec.y = vecdiffY(argA, argB);
vec.x = vecdiffX(argA, argB);
vec.z = vecdiffZ(argA, argB);
float newthing = sqrtf(vec.x * vec.x + vec.y * vec.y + vec.z * vec.z);
A += newthing;
float dummy[4]; // Match stack allocation

unknown1();

if (_00 < 100.0f) {
// THIS IS VECTOR3F::DISTANCE!!! WHAT THE FUUUUUUUUUU
Vector3f vec;
vec.sub2(argA, argB);
f32 distance = vec.length();
_00 += distance;
}
return odoRet();

return unknown2();
}

0 comments on commit 84ef91e

Please sign in to comment.