Files
dusklight/libs/JSystem/src/JMath/JMath.cpp
T
qwertyquerty 767ba3bb14 Ongoing gameplay dev (#49)
* launch.json cwd

* bodge to load gci for testing

* stub card stat

* gameplay bodges

* viewport, ub fixes

* add release with debug info cmake variant

* be fixes, sound stub

* viewport h

* d_msg_flow BE

* be fopAcM_createItemFromEnemyID

* update launch configuration to use iso

* more audio stubs

* Attempt to set viewport and get messages for brightness check

* skip opening scene again, fixed JMessage::TResourceContainer::TCResource::Do_destroy

* add guards for viewport changes

* moar endian swapping to get Link sitting in PROC_OPENING_SCENE and for dialogues

* BE d_msg_class i_data

* stub bgm start

* fix div by 0 error (for now)

* TEMP_BROKEN in d_menu_ring

* REQUIRES_GX_LINES

* properly stub renderingAmap::draw with REQUIRES_GX_LINES

* better stubbing outside of stubs

* fix event data getting swapped multiple times

* evil draw vp fix

* Stub log imgui

This redirects all spammy logs to an imgui window that is cleared per frame.

This fixes the serious performance dip of the logging, and makes the regular log readable.

* Oops move those optimization changes I accidentally committed behind a flag

DUSK_SELECTED_OPT

* gx_line macro in map

* fix audio stubbing

* switch to CARD API aurora impl

* remove kabufuda from link libs

* refactor imgui stuff and add input viewer

* merge stub log with refactor

* accidentally committed a metaforce header shh

* basic map loader

* ImGuiConsole: Add missing <thread> include

* you may now play as luigi (you may now load stages with bridges)

* bloom fix

* bloom leak fix

* cloud shadow fix

* add soft reset button to imgui menu

* if it broke dont not fix it

* i swear i committed this

* BE swap indMtx in JPAResource::setPTev

* wnark ct fix

* frsqrte implementation from kinoko

* Fix Clang compile error in JAISeq::prepare_getSeqData_

* Add endian conversions to dMsgFlow_c::getInitNodeIndex

This fixes a freeze when Fado tries to stop you from leaving the
starting area.

* Add RAII GXTexObj wrapper; fix almost all leaks

* Update aurora for indirect texturing

* Update aurora for CARD fix

* Fix Clang build

* More d_msg_flow endian fixes

Fixes softlock when trying to talk to Fado and possibly other NPCs.

* no frame limiter

* get pause menu working

* proper frame limiting

* particle pointer size fix

* improve map loader a bit

---------

Co-authored-by: Jasper St. Pierre <jstpierre@mecheye.net>
Co-authored-by: TakaRikka <takarikka@outlook.com>
Co-authored-by: CraftyBoss <talibabdulmaalik@gmail.com>
Co-authored-by: Luke Street <luke@street.dev>
Co-authored-by: Lurs <2795933+Lurs@users.noreply.github.com>
Co-authored-by: PJB3005 <pieterjan.briers+git@gmail.com>
Co-authored-by: tgsm <doodrabbit@hotmail.com>
Co-authored-by: Max Roncace <me@caseif.net>
Co-authored-by: Phillip Stephens <antidote.crk@gmail.com>
2026-03-12 04:01:03 -07:00

154 lines
4.5 KiB
C++

#include "JSystem/JSystem.h" // IWYU pragma: keep
#include "JSystem/JMath/JMath.h"
#include "JSystem/JMath/JMATrigonometric.h"
void JMAEulerToQuat(s16 x, s16 y, s16 z, Quaternion* quat) {
f32 cosX = JMASCos(x / 2);
f32 cosY = JMASCos(y / 2);
f32 cosZ = JMASCos(z / 2);
f32 sinX = JMASSin(x / 2);
f32 sinY = JMASSin(y / 2);
f32 sinZ = JMASSin(z / 2);
f32 cyz = cosY * cosZ;
f32 syz = sinY * sinZ;
quat->w = cosX * (cyz) + sinX * (syz);
quat->x = sinX * (cyz)-cosX * (syz);
quat->y = cosZ * (cosX * sinY) + sinZ * (sinX * cosY);
quat->z = sinZ * (cosX * cosY) - cosZ * (sinX * sinY);
}
void JMAQuatLerp(__REGISTER const Quaternion* p, __REGISTER const Quaternion* q, f32 t,
Quaternion* dst) {
__REGISTER f32 pxy, pzw, qxy, qzw;
__REGISTER f32 dp;
#ifdef __MWERKS__ // clang-format off
// compute dot product
asm {
psq_l pxy, 0(p), 0, 0
psq_l qxy, 0(q), 0, 0
ps_mul dp, pxy, qxy
psq_l pzw, 8(p), 0, 0
psq_l qzw, 8(q), 0, 0
ps_madd dp, pzw, qzw, dp
ps_sum0 dp, dp, dp, dp
}
#else // clang-format on
dp = p->x * q->x + p->y * q->y + p->z * q->z + p->w * q->w;
#endif
f32 local_78 = dp;
if (local_78 < 0.0) {
int unused;
dst->x = -t * (p->x + q->x) + p->x;
dst->y = -t * (p->y + q->y) + p->y;
dst->z = -t * (p->z + q->z) + p->z;
dst->w = -t * (p->w + q->w) + p->w;
} else {
dst->x = -t * (p->x - q->x) + p->x;
dst->y = -t * (p->y - q->y) + p->y;
dst->z = -t * (p->z - q->z) + p->z;
dst->w = -t * (p->w - q->w) + p->w;
}
}
void JMAFastVECNormalize(__REGISTER const Vec* src, __REGISTER Vec* dst) {
__REGISTER f32 vxy, rxy, vz, length;
#ifdef __MWERKS__ // clang-format off
asm {
psq_l vxy, 0(src), 0, 0
ps_mul rxy, vxy, vxy
lfs vz, src->z
ps_madd length, vz, vz, rxy
ps_sum0 length, length, rxy, rxy
frsqrte length, length
ps_muls0 vxy, vxy, length;
psq_st vxy, 0(dst), 0, 0
fmuls vz, vz, length
stfs vz, dst->z
}
#else
f32 mag = src->x * src->x + src->y * src->y + src->z * src->z;
length = 1.0f / sqrtf(mag);
dst->x = src->x * length;
dst->y = src->y * length;
dst->z = src->z * length;
#endif // clang-format on
OSPanic(__FILE__, __LINE__, "UNIMPLEMENTED");
}
void JMAVECScaleAdd(__REGISTER const Vec* vec1, __REGISTER const Vec* vec2, __REGISTER Vec* dst,
__REGISTER f32 scale) {
__REGISTER f32 v1xy;
__REGISTER f32 v2xy;
__REGISTER f32 rxy, v1z, v2z, rz;
#ifdef __MWERKS__ // clang-format off
asm {
psq_l v1xy, 0(vec1), 0, 0
psq_l v2xy, 0(vec2), 0, 0
ps_madds0 rxy, v1xy, scale, v2xy
psq_st rxy, 0(dst), 0, 0
psq_l v1z, 8(vec1), 1, 0
psq_l v2z, 8(vec2), 1, 0
ps_madds0 rz, v1z, scale, v2z
psq_st rz, 8(dst), 1, 0
}
#else
dst->x = vec1->x * scale + vec2->x;
dst->y = vec1->y * scale + vec2->y;
dst->z = vec1->z * scale + vec2->z;
#endif // clang-format on
}
void JMAMTXApplyScale(__REGISTER const Mtx src, __REGISTER Mtx dst, __REGISTER f32 xScale,
__REGISTER f32 yScale, __REGISTER f32 zScale) {
__REGISTER f32 scale = yScale;
__REGISTER f32 x, y, z;
__REGISTER f32 normal = 1.0f;
#ifdef __MWERKS__ // clang-format off
asm {
// scale first 2 components
ps_merge00 scale, xScale, scale
psq_l x, 0(src), 0, 0
psq_l y, 16(src), 0, 0
psq_l z, 32(src), 0, 0
ps_mul x, x, scale
ps_mul y, y, scale
ps_mul z, z, scale
psq_st x, 0(dst), 0, 0
psq_st y, 16(dst), 0, 0
psq_st z, 32(dst), 0, 0
// scale last 2 components
ps_merge00 scale, zScale, normal
psq_l x, 8(src), 0, 0
psq_l y, 24(src), 0, 0
psq_l z, 40(src), 0, 0
ps_mul x, x, scale
ps_mul y, y, scale
ps_mul z, z, scale
psq_st x, 8(dst), 0, 0
psq_st y, 24(dst), 0, 0
psq_st z, 40(dst), 0, 0
}
#else
dst[0][0] = src[0][0] * xScale;
dst[0][1] = src[0][1] * yScale;
dst[0][2] = src[0][2] * zScale;
dst[0][3] = src[0][3];
dst[1][0] = src[1][0] * xScale;
dst[1][1] = src[1][1] * yScale;
dst[1][2] = src[1][2] * zScale;
dst[1][3] = src[1][3];
dst[2][0] = src[2][0] * xScale;
dst[2][1] = src[2][1] * yScale;
dst[2][2] = src[2][2] * zScale;
dst[2][3] = src[2][3];
#endif // clang-format on
}