mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-06-17 14:06:42 -04:00
767ba3bb14
* 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>
222 lines
8.6 KiB
C++
222 lines
8.6 KiB
C++
#include "JSystem/JSystem.h" // IWYU pragma: keep
|
|
|
|
#include "JSystem/JParticle/JPADynamicsBlock.h"
|
|
#include "JSystem/JMath/JMATrigonometric.h"
|
|
#include "JSystem/JParticle/JPAEmitter.h"
|
|
|
|
void JPAVolumePoint(JPAEmitterWorkData* work) {
|
|
work->mVolumeCalcData.mVolumePos.zero();
|
|
work->mVolumeCalcData.mVelOmni.set(work->mpEmtr->get_r_zh(), work->mpEmtr->get_r_zh(),
|
|
work->mpEmtr->get_r_zh());
|
|
work->mVolumeCalcData.mVelAxis.set(work->mVolumeCalcData.mVelOmni.x, 0.0f,
|
|
work->mVolumeCalcData.mVelOmni.z);
|
|
}
|
|
|
|
void JPAVolumeLine(JPAEmitterWorkData* work) {
|
|
if (work->mpEmtr->checkFlag(JPADynFlag_FixedInterval)) {
|
|
work->mVolumeCalcData.mVolumePos.set(
|
|
0.0f, 0.0f,
|
|
work->mVolumeSize * ((work->mVolumeEmitIdx / (work->mEmitCount - 1.0f) - 0.5f)));
|
|
work->mVolumeEmitIdx++;
|
|
} else {
|
|
work->mVolumeCalcData.mVolumePos.set(0.0f, 0.0f,
|
|
work->mVolumeSize * work->mpEmtr->get_r_zh());
|
|
}
|
|
|
|
work->mVolumeCalcData.mVelOmni.set(0.0f, 0.0f,
|
|
work->mVolumeCalcData.mVolumePos.z * work->mGlobalScl.z);
|
|
work->mVolumeCalcData.mVelAxis.set(0.0f, 0.0f, work->mVolumeCalcData.mVolumePos.z);
|
|
}
|
|
|
|
// NONMATCHING regalloc. Could be issue with mul asm implementations
|
|
void JPAVolumeCircle(JPAEmitterWorkData* work) {
|
|
s16 theta;
|
|
f32 distance;
|
|
|
|
if (work->mpEmtr->checkFlag(JPADynFlag_FixedInterval)) {
|
|
theta = (s16)((work->mVolumeEmitIdx << 16) / work->mEmitCount);
|
|
theta = theta * work->mVolumeSweep;
|
|
work->mVolumeEmitIdx++;
|
|
} else {
|
|
theta = work->mVolumeSweep * work->mpEmtr->get_r_ss();
|
|
}
|
|
|
|
distance = work->mpEmtr->get_r_f();
|
|
if (work->mpEmtr->checkFlag(JPADynFlag_FixedDensity)) {
|
|
distance = 1.0f - (distance * distance);
|
|
}
|
|
|
|
distance = work->mVolumeSize * (work->mVolumeMinRad + distance * (1.0f - work->mVolumeMinRad));
|
|
work->mVolumeCalcData.mVolumePos.set(distance * JMASSin(theta), 0.0f,
|
|
distance * JMASCos(theta));
|
|
work->mVolumeCalcData.mVelOmni.mul(work->mVolumeCalcData.mVolumePos, work->mGlobalScl);
|
|
work->mVolumeCalcData.mVelAxis.set(work->mVolumeCalcData.mVolumePos.x, 0.0f,
|
|
work->mVolumeCalcData.mVolumePos.z);
|
|
}
|
|
|
|
void JPAVolumeCube(JPAEmitterWorkData* work) {
|
|
work->mVolumeCalcData.mVolumePos.set(work->mpEmtr->get_r_zh() * work->mVolumeSize,
|
|
work->mpEmtr->get_r_zh() * work->mVolumeSize,
|
|
work->mpEmtr->get_r_zh() * work->mVolumeSize);
|
|
work->mVolumeCalcData.mVelOmni.mul(work->mVolumeCalcData.mVolumePos, work->mGlobalScl);
|
|
work->mVolumeCalcData.mVelAxis.set(work->mVolumeCalcData.mVolumePos.x, 0.0f, work->mVolumeCalcData.mVolumePos.z);
|
|
}
|
|
|
|
static void JPAVolumeSphere(JPAEmitterWorkData* work) {
|
|
s16 phi, r28;
|
|
if (work->mpEmtr->checkFlag(JPADynFlag_FixedInterval)) {
|
|
phi = u16(work->mVolumeX * 0x8000 / (work->mDivNumber - 1) + 0x4000);
|
|
|
|
#if TARGET_PC
|
|
// Fix div by 0 error here
|
|
// TODO: maybe review a better way of handling div by 0 UB
|
|
r28 = 0x8000;
|
|
if (work->mVolumeAngleNum > 1) {
|
|
u16 r26 = u16(work->mVolumeAngleNum * 0x10000 / (work->mVolumeAngleMax - 1));
|
|
r28 += f32(r26) * work->mVolumeSweep + 0x8000;
|
|
}
|
|
#else
|
|
u16 r26 = u16(work->mVolumeAngleNum * 0x10000 / (work->mVolumeAngleMax - 1));
|
|
r28 = f32(r26) * work->mVolumeSweep + 0x8000;
|
|
#endif
|
|
|
|
work->mVolumeAngleNum++;
|
|
if (work->mVolumeAngleNum == work->mVolumeAngleMax) {
|
|
work->mVolumeAngleNum = 0;
|
|
work->mVolumeX++;
|
|
if (work->mVolumeX * 2 < work->mDivNumber) {
|
|
work->mVolumeAngleMax = work->mVolumeAngleMax != 1 ?
|
|
work->mVolumeAngleMax + 4 : work->mVolumeAngleMax + 3;
|
|
} else {
|
|
work->mVolumeAngleMax = work->mVolumeAngleMax != 4 ? work->mVolumeAngleMax - 4 : 1;
|
|
}
|
|
}
|
|
} else {
|
|
phi = work->mpEmtr->get_r_ss() >> 1;
|
|
r28 = work->mVolumeSweep * work->mpEmtr->get_r_ss();
|
|
}
|
|
|
|
f32 f31 = work->mpEmtr->get_r_f();
|
|
if (work->mpEmtr->checkFlag(JPADynFlag_FixedDensity)) {
|
|
f31 = 1.0f - f31 * f31 * f31;
|
|
}
|
|
f31 = work->mVolumeSize * (work->mVolumeMinRad + f31 * (1.0f - work->mVolumeMinRad));
|
|
work->mVolumeCalcData.mVolumePos.set(f31 * JMASCos(phi) * JMASSin(r28), -f31 * JMASSin(phi),
|
|
f31 * JMASCos(phi) * JMASCos(r28));
|
|
work->mVolumeCalcData.mVelOmni.mul(work->mVolumeCalcData.mVolumePos, work->mGlobalScl);
|
|
work->mVolumeCalcData.mVelAxis.set(work->mVolumeCalcData.mVolumePos.x, 0.0f,
|
|
work->mVolumeCalcData.mVolumePos.z);
|
|
}
|
|
|
|
static void JPAVolumeCylinder(JPAEmitterWorkData* work) {
|
|
s16 r30 = work->mVolumeSweep * work->mpEmtr->get_r_ss();
|
|
f32 f31 = work->mpEmtr->get_r_f();
|
|
if (work->mpEmtr->checkFlag(JPADynFlag_FixedDensity)) {
|
|
f31 = 1.0f - f31 * f31;
|
|
}
|
|
f31 = work->mVolumeSize * (work->mVolumeMinRad + f31 * (1.0f - work->mVolumeMinRad));
|
|
work->mVolumeCalcData.mVolumePos.set(
|
|
f31 * JMASSin(r30), work->mVolumeSize * work->mpEmtr->get_r_zp(), f31 * JMASCos(r30));
|
|
work->mVolumeCalcData.mVelOmni.mul(work->mVolumeCalcData.mVolumePos, work->mGlobalScl);
|
|
work->mVolumeCalcData.mVelAxis.set(work->mVolumeCalcData.mVolumePos.x, 0.0f,
|
|
work->mVolumeCalcData.mVolumePos.z);
|
|
}
|
|
|
|
static void JPAVolumeTorus(JPAEmitterWorkData* work) {
|
|
s16 theta = work->mVolumeSweep * work->mpEmtr->get_r_ss();
|
|
s16 phi = work->mpEmtr->get_r_ss();
|
|
f32 rad = work->mVolumeSize * work->mVolumeMinRad;
|
|
work->mVolumeCalcData.mVelAxis.set(rad * JMASSin(theta) * JMASCos(phi), rad * JMASSin(phi),
|
|
rad * JMASCos(theta) * JMASCos(phi));
|
|
work->mVolumeCalcData.mVolumePos.set(
|
|
work->mVolumeCalcData.mVelAxis.x + work->mVolumeSize * JMASSin(theta),
|
|
work->mVolumeCalcData.mVelAxis.y,
|
|
work->mVolumeCalcData.mVelAxis.z + work->mVolumeSize * JMASCos(theta));
|
|
work->mVolumeCalcData.mVelOmni.mul(work->mVolumeCalcData.mVolumePos, work->mGlobalScl);
|
|
}
|
|
|
|
JPADynamicsBlock::JPADynamicsBlock(u8 const* data) {
|
|
mpData = (const JPADynamicsBlockData*)data;
|
|
init();
|
|
}
|
|
|
|
enum {
|
|
VOL_Cube = 0x00,
|
|
VOL_Sphere = 0x01,
|
|
VOL_Cylinder = 0x02,
|
|
VOL_Torus = 0x03,
|
|
VOL_Point = 0x04,
|
|
VOL_Circle = 0x05,
|
|
VOL_Line = 0x06,
|
|
};
|
|
|
|
void JPADynamicsBlock::init() {
|
|
switch (getVolumeType()) {
|
|
case VOL_Cube:
|
|
mpCalcVolumeFunc = &JPAVolumeCube;
|
|
break;
|
|
case VOL_Sphere:
|
|
mpCalcVolumeFunc = &JPAVolumeSphere;
|
|
break;
|
|
case VOL_Cylinder:
|
|
mpCalcVolumeFunc = &JPAVolumeCylinder;
|
|
break;
|
|
case VOL_Torus:
|
|
mpCalcVolumeFunc = &JPAVolumeTorus;
|
|
break;
|
|
case VOL_Point:
|
|
mpCalcVolumeFunc = &JPAVolumePoint;
|
|
break;
|
|
case VOL_Circle:
|
|
mpCalcVolumeFunc = &JPAVolumeCircle;
|
|
break;
|
|
case VOL_Line:
|
|
mpCalcVolumeFunc = &JPAVolumeLine;
|
|
break;
|
|
}
|
|
}
|
|
|
|
void JPADynamicsBlock::create(JPAEmitterWorkData* work) {
|
|
if (work->mpEmtr->checkStatus(JPAEmtrStts_RateStepEmit)) {
|
|
s32 emitCount = 0;
|
|
|
|
if (work->mpEmtr->checkFlag(JPADynFlag_FixedInterval)) {
|
|
emitCount = getVolumeType() == VOL_Sphere ? 4 * getDivNumber() * getDivNumber() + 2 : getDivNumber();
|
|
|
|
work->mVolumeEmitIdx = 0;
|
|
} else {
|
|
f32 newPtclCount =
|
|
work->mpEmtr->mRate * (getRateRndm() * work->mpEmtr->get_r_zp() + 1.0f);
|
|
emitCount = work->mpEmtr->mEmitCount += newPtclCount;
|
|
work->mpEmtr->mEmitCount -= emitCount;
|
|
|
|
if (work->mpEmtr->checkStatus(JPAEmtrStts_FirstEmit) && 0.0f < newPtclCount &&
|
|
newPtclCount < 1.0f)
|
|
emitCount = 1;
|
|
}
|
|
|
|
work->mEmitCount = emitCount;
|
|
if (work->mpEmtr->checkStatus(JPAEmtrStts_StopEmit)) {
|
|
emitCount = 0;
|
|
}
|
|
|
|
JPABaseParticle* ptcl = NULL;
|
|
s32 createCount = emitCount;
|
|
while (createCount > 0) {
|
|
ptcl = work->mpEmtr->createParticle();
|
|
if (ptcl == NULL)
|
|
break;
|
|
createCount--;
|
|
}
|
|
}
|
|
|
|
if (++work->mpEmtr->mRateStepTimer >= (work->mpEmtr->mRateStep + 1)) {
|
|
work->mpEmtr->mRateStepTimer -= work->mpEmtr->mRateStep + 1;
|
|
work->mpEmtr->setStatus(JPAEmtrStts_RateStepEmit);
|
|
} else {
|
|
work->mpEmtr->clearStatus(JPAEmtrStts_RateStepEmit);
|
|
}
|
|
|
|
work->mpEmtr->clearStatus(JPAEmtrStts_FirstEmit);
|
|
}
|