diff --git a/src/FakeObject.c b/src/FakeObject.c index 34b8cda..b422ff8 100644 --- a/src/FakeObject.c +++ b/src/FakeObject.c @@ -1,7 +1,3 @@ -// -// Created by nepushiro on 5/29/26. -// - #include "FakeObject.h" #include @@ -11,57 +7,10 @@ #include "decomp/game/interaction.h" #include "decomp/game/object_stuff.h" #include "decomp/include/object_fields.h" -#include "libsm64.h" #include #include #include "decomp/shim.h" -#define o gCurrentObject - -struct Object *cur_obj_find_nearest_pole(void) -{ - struct Object *closestObj = NULL; - struct Object *obj; - f32 minDist = 0x20000; - - for (s32 i = 0; i < s_fakeobj_instance_pool.size; i++) - { - obj = s_fakeobj_instance_pool.objects[i]; - - if (obj == NULL) - continue; - - if (obj->activeFlags == ACTIVE_FLAG_DEACTIVATED) - continue; - - if (!(obj->oInteractType & INTERACT_POLE)) - continue; - - if (obj == o) - continue; - - f32 objDist = dist_between_objects(o, obj); - - if (objDist < minDist) - { - closestObj = obj; - minDist = objDist; - } - } - - return closestObj; -} - -f32 dist_between_objects(struct Object *obj1, struct Object *obj2) -{ - if (obj1 == NULL || obj2 == NULL) { return 0; } - f32 dx = obj1->oPosX - obj2->oPosX; - f32 dy = obj1->oPosY - obj2->oPosY; - f32 dz = obj1->oPosZ - obj2->oPosZ; - - return sqrtf(dx * dx + dy * dy + dz * dz); -} - void fake_object_init(struct FakeObject *fake, float x, float y, float z) { memset(fake, 0, sizeof(*fake)); diff --git a/src/FakeObject.h b/src/FakeObject.h index 254c843..f069e13 100644 --- a/src/FakeObject.h +++ b/src/FakeObject.h @@ -1,12 +1,6 @@ -// -// Created by nepushiro on 5/29/26. -// - #ifndef LIBSM64_FAKEOBJECT_H #define LIBSM64_FAKEOBJECT_H -#endif //LIBSM64_FAKEOBJECT_H - #include #include #include @@ -16,13 +10,12 @@ struct FakeObject struct Object object; }; -struct Object* cur_obj_find_nearest_pole(void); -f32 dist_between_objects(struct Object *obj1, struct Object *obj2); - void fake_object_init(struct FakeObject *fake, float x, float y, float z); void fake_object_sync_position(struct FakeObject *fake); bool fake_object_overlaps_mario(struct FakeObject *fake, struct MarioState *m); void fake_object_add_collision(struct FakeObject *fake, struct MarioState *m); void fake_object_apply_pole(struct FakeObject *fake); -void fake_object_set_preset(struct FakeObject *fake, uint32_t preset); \ No newline at end of file +void fake_object_set_preset(struct FakeObject *fake, uint32_t preset); + +#endif // LIBSM64_FAKEOBJECT_H \ No newline at end of file diff --git a/src/decomp/audio/external.c b/src/decomp/audio/external.c index 34ff1fc..ddb1be8 100644 --- a/src/decomp/audio/external.c +++ b/src/decomp/audio/external.c @@ -872,14 +872,12 @@ static void process_sound_request(u32 bits, f32 *pos) if (soundId >= sNumSoundsPerBank[bank] || sSoundBankDisabled[bank]) { - //DEBUG_PRINT("process_sound_request: invalid soundId %d\n", soundId); return; } u8 soundIndex = sSoundBanks[bank][0].next; while (soundIndex != 0xff && soundIndex != 0) { - //DEBUG_PRINT("process_sound_request: soundIndex %d\n", soundIndex); // If an existing sound from the same source exists in the bank, then we should either // interrupt that sound and replace it with the new sound, or we should drop the new sound. if (sSoundBanks[bank][soundIndex].x == pos) @@ -930,7 +928,6 @@ static void process_sound_request(u32 bits, f32 *pos) // If free list has more than one element remaining if (sSoundBanks[bank][sSoundBankFreeListFront[bank]].next != 0xff && soundIndex != 0) { - DEBUG_PRINT("process_sound_request2: soundIndex %d\n", soundIndex); // Allocate from free list soundIndex = sSoundBankFreeListFront[bank]; @@ -966,7 +963,6 @@ static void process_all_sound_requests(void) struct Sound *sound = &sSoundRequests[sNumProcessedSoundRequests]; process_sound_request(sound->soundBits, sound->position); sNumProcessedSoundRequests++; - //DEBUG_PRINT("processed sounds: %d\n", sNumProcessedSoundRequests); } } diff --git a/src/decomp/audio/load.c b/src/decomp/audio/load.c index 5b1136e..491d197 100644 --- a/src/decomp/audio/load.c +++ b/src/decomp/audio/load.c @@ -120,17 +120,10 @@ ALSeqFile *get_audio_file_header(s32 arg0); */ void audio_dma_copy_immediate(uintptr_t devAddr, void *vAddr, size_t nbytes) { - DEBUG_PRINT("audio_dma_copy_immediate()"); - DEBUG_PRINT("- dev addr: %x", devAddr); - DEBUG_PRINT("- vAddr: %x", vAddr); - DEBUG_PRINT("- # bytes: %d", nbytes); eu_stubbed_printf_3("Romcopy %x -> %x ,size %x\n", devAddr, vAddr, nbytes); - DEBUG_PRINT("- invalidate d cache"); osInvalDCache(vAddr, nbytes); - DEBUG_PRINT("- start dma"); osPiStartDma(&gAudioDmaIoMesg, OS_MESG_PRI_HIGH, OS_READ, devAddr, vAddr, nbytes, &gAudioDmaMesgQueue); - DEBUG_PRINT("- recv message"); osRecvMesg(&gAudioDmaMesgQueue, NULL, OS_MESG_BLOCK); eu_stubbed_printf_0("Romcopyend\n"); } @@ -646,43 +639,31 @@ void patch_audio_bank(struct AudioBank *mem, u8 *offset, u32 numInstruments, u32 struct AudioBank *bank_load_immediate(s32 bankId, s32 arg1) { - DEBUG_PRINT("bank_load_immediate()"); UNUSED u32 pad1[4]; u32 buf[4]; // (This is broken if the length is 1 (mod 16), but that never happens -- // it's always divisible by 4.) - DEBUG_PRINT("- getting alloc"); s32 alloc = gAlCtlHeader->seqArray[bankId].len + 0xf; - DEBUG_PRINT("- aligning"); alloc = ALIGN16(alloc); alloc -= 0x10; - DEBUG_PRINT("- getting ctl data for bank %d", bankId); u8 *ctlData = gAlCtlHeader->seqArray[bankId].offset; - DEBUG_PRINT("- alloc bank or seq"); struct AudioBank *ret = alloc_bank_or_seq(&gBankLoadedPool, 1, alloc, arg1, bankId); if (ret == NULL) { return NULL; } - DEBUG_PRINT("- copying dma immediate 1"); - DEBUG_PRINT("- ctlData: %x", ctlData); audio_dma_copy_immediate((uintptr_t)ctlData, buf, 0x10); - DEBUG_PRINT("- getting nums"); u32 numInstruments = buf[0]; u32 numDrums = buf[1]; - DEBUG_PRINT("- copying dma immediate 2"); audio_dma_copy_immediate((uintptr_t)(ctlData + 0x10), ret, alloc); - DEBUG_PRINT("- patching bank"); patch_audio_bank(ret, gAlTbl->seqArray[bankId].offset, numInstruments, numDrums); - DEBUG_PRINT("- setting ctl entries"); gCtlEntries[bankId].numInstruments = (u8)numInstruments; gCtlEntries[bankId].numDrums = (u8)numDrums; gCtlEntries[bankId].instruments = ret->instruments; gCtlEntries[bankId].drums = ret->drums; - DEBUG_PRINT("- setting load status"); gBankLoadStatus[bankId] = SOUND_LOAD_STATUS_COMPLETE; return ret; } @@ -851,12 +832,10 @@ u8 get_missing_bank(u32 seqId, s32 *nonNullCount, s32 *nullCount) struct AudioBank *load_banks_immediate(s32 seqId, u8 *outDefaultBank) { - DEBUG_PRINT("load_banks_immediate()"); void *ret; u32 bankId; u8 i; - DEBUG_PRINT("- getting offset"); u16 offset = ((u16 *)gAlBankSets)[seqId]; #ifdef VERSION_EU for (i = gAlBankSets[offset++]; i != 0; i--) @@ -864,21 +843,17 @@ struct AudioBank *load_banks_immediate(s32 seqId, u8 *outDefaultBank) bankId = gAlBankSets[offset++]; #else offset++; - DEBUG_PRINT("- looping through bank sets"); for (i = gAlBankSets[offset - 1]; i != 0; i--) { offset++; - DEBUG_PRINT("- getting bank id"); bankId = gAlBankSets[offset - 1]; #endif - DEBUG_PRINT("- checking if bank load is complete"); if (IS_BANK_LOAD_COMPLETE(bankId) == TRUE) { #ifdef VERSION_EU ret = get_bank_or_seq(&gBankLoadedPool, 2, bankId); #else - DEBUG_PRINT("- getting bank or seq"); ret = get_bank_or_seq(&gBankLoadedPool, 2, gAlBankSets[offset - 1]); #endif } @@ -889,7 +864,6 @@ struct AudioBank *load_banks_immediate(s32 seqId, u8 *outDefaultBank) if (ret == NULL) { - DEBUG_PRINT("- bank load immediate"); ret = bank_load_immediate(bankId, 2); } } @@ -899,7 +873,6 @@ struct AudioBank *load_banks_immediate(s32 seqId, u8 *outDefaultBank) void preload_sequence(u32 seqId, u8 preloadMask) { - DEBUG_PRINT("preload_sequence()"); void *sequenceData; u8 temp; @@ -911,25 +884,21 @@ void preload_sequence(u32 seqId, u8 preloadMask) gAudioLoadLock = AUDIO_LOCK_LOADING; if (preloadMask & PRELOAD_BANKS) { - DEBUG_PRINT("- load banks immediate"); load_banks_immediate(seqId, &temp); } if (preloadMask & PRELOAD_SEQUENCE) { // @bug should be IS_SEQ_LOAD_COMPLETE - DEBUG_PRINT("- checking if bank load immediate"); if (IS_BANK_LOAD_COMPLETE(seqId) == TRUE) { eu_stubbed_printf_1("SEQ %d ALREADY CACHED\n", seqId); - DEBUG_PRINT("- getting bank or seq"); sequenceData = get_bank_or_seq(&gSeqLoadedPool, 2, seqId); } else { sequenceData = NULL; } - DEBUG_PRINT("- checking dma immediate"); if (sequenceData == NULL && sequence_dma_immediate(seqId, 2) == NULL) { gAudioLoadLock = AUDIO_LOCK_NOT_LOADING; @@ -1037,7 +1006,6 @@ void load_sequence_internal(u32 player, u32 seqId, s32 loadAsync) // (void) must be omitted from parameters to fix stack with -framepointer void audio_init() { - DEBUG_PRINT("audio_init()"); UNUSED s8 pad[32]; u8 buf[0x10]; s32 i, UNUSED k; @@ -1048,7 +1016,6 @@ void audio_init() gAudioLoadLock = AUDIO_LOCK_UNINITIALIZED; - DEBUG_PRINT("- setting values in unused"); s32 lim1 = gUnusedCount80333EE8; for (i = 0; i < lim1; i++) { @@ -1056,7 +1023,6 @@ void audio_init() gUnused80226E98[i] = 0; } - DEBUG_PRINT("- clearing audio heap"); s32 lim2 = gAudioHeapSize; for (i = 0; i <= lim2 / 8 - 1; i++) { @@ -1114,39 +1080,22 @@ void audio_init() alSeqFileNew(gSeqFileHeader, data); // Load header for CTL (instrument metadata) - DEBUG_PRINT("- loading ctl header"); gAlCtlHeader = (ALSeqFile *)buf; data = gSoundDataADSR; - DEBUG_PRINT("- copying dma immediate"); audio_dma_copy_immediate((uintptr_t)data, gAlCtlHeader, 0x10); size = gAlCtlHeader->seqCount * sizeof(ALSeqData) + 4; - DEBUG_PRINT("- seq count: %d", gAlCtlHeader->seqCount); - DEBUG_PRINT("- size after read: %d", size); size = ALIGN16(size); - DEBUG_PRINT("- size after align: %d", size); gCtlEntries = soundAlloc(&gAudioInitPool, gAlCtlHeader->seqCount * sizeof(struct CtlEntry)); gAlCtlHeader = soundAlloc(&gAudioInitPool, size); - DEBUG_PRINT("@ copying data from sound data adsr to ctl header"); - DEBUG_PRINT("- data: %x", data); - DEBUG_PRINT("- ctl header: %x", gAlCtlHeader); - DEBUG_PRINT("- size: %d", size); audio_dma_copy_immediate((uintptr_t)data, gAlCtlHeader, size); - DEBUG_PRINT("- creating new seq file for ctl"); alSeqFileNew(gAlCtlHeader, data); // Load header for TBL (raw sound data) - DEBUG_PRINT("- loading tbl"); gAlTbl = (ALSeqFile *)buf; - DEBUG_PRINT("- copying dma"); audio_dma_copy_immediate((uintptr_t)data, gAlTbl, 0x10); - DEBUG_PRINT("- tbl seq count: %d", gAlTbl->seqCount); size = gAlTbl->seqCount * sizeof(ALSeqData) + 4; - DEBUG_PRINT("- size: %d", size); size = ALIGN16(size); - DEBUG_PRINT("- size after align: %d", size); gAlTbl = soundAlloc(&gAudioInitPool, size); - DEBUG_PRINT("- tbl alloc at %x", gAlTbl); - DEBUG_PRINT("- gSoundDataRaw at %x", gSoundDataRaw); audio_dma_copy_immediate((uintptr_t)gSoundDataRaw, gAlTbl, size); alSeqFileNew(gAlTbl, (u8 *)gSoundDataRaw); diff --git a/src/decomp/audio/seqplayer.c b/src/decomp/audio/seqplayer.c index 93ecf2b..bbad1a0 100644 --- a/src/decomp/audio/seqplayer.c +++ b/src/decomp/audio/seqplayer.c @@ -447,10 +447,7 @@ void init_layer_freelist(void) u8 m64_read_u8(struct M64ScriptState *state) { - DEBUG_PRINT("m64_read_u8()"); - DEBUG_PRINT("- state at %x", state); u8 *midiArg = state->pc++; - DEBUG_PRINT("- read u8 (%d) at (%x)", *midiArg, midiArg); return *midiArg; } @@ -1205,10 +1202,8 @@ s32 seq_channel_layer_process_script_part2(struct SequenceChannelLayer *layer) break; case 0xc6: // layer_setinstr - DEBUG_PRINT(" - cmd 0xc6, setinstr"); cmd = m64_read_u8(state); - DEBUG_PRINT(" - read %d from state", cmd); if (cmd >= 0x7f) { @@ -1552,8 +1547,6 @@ s32 seq_channel_layer_process_script_part3(struct SequenceChannelLayer *layer, s u8 get_instrument(struct SequenceChannel *seqChannel, u8 instId, struct Instrument **instOut, struct AdsrSettings *adsr) { - DEBUG_PRINT("@ get_instrument()"); - DEBUG_PRINT("- instrument id: %d", instId); struct Instrument *inst; #if defined(VERSION_EU) || defined(VERSION_SH) @@ -1619,9 +1612,6 @@ u8 get_instrument(struct SequenceChannel *seqChannel, u8 instId, struct Instrume void set_instrument(struct SequenceChannel *seqChannel, u8 instId) { - DEBUG_PRINT("@ set_instrument()"); - DEBUG_PRINT("- bank id: %d", seqChannel->bankId); - DEBUG_PRINT("- instrument id: %d", instId); if (instId >= 0x80) { @@ -1658,7 +1648,6 @@ void sequence_channel_set_volume(struct SequenceChannel *seqChannel, u8 volume) void sequence_channel_process_script(struct SequenceChannel *seqChannel) { - DEBUG_PRINT("sequence_channel_process_script()"); s8 temp; u8 loBits; @@ -1702,7 +1691,6 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) for (;;) { u8 cmd = m64_read_u8(state); - DEBUG_PRINT("- handling command: %x", cmd); #if !defined(VERSION_EU) && !defined(VERSION_SH) if (cmd == 0xff) // chan_end @@ -1895,10 +1883,8 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) #endif case 0xc1: // chan_setinstr ("set program"?) - DEBUG_PRINT(" - cmd 0xc1, setinstr"); u8 instrId = m64_read_u8(state); - DEBUG_PRINT(" - read %d from state", instrId); set_instrument(seqChannel, instrId); break; @@ -2030,12 +2016,9 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) break; case 0xc6: // chan_setbank; switch bank within set - DEBUG_PRINT(" - case 0xc6 - switch bank"); - DEBUG_PRINT(" - seq id %d", seqPlayer->seqId); cmd = m64_read_u8(state); - DEBUG_PRINT(" - backwards bank id %d", cmd); // Switch to the temp's (0-indexed) bank in this sequence's // bank set. Note that in the binary format (not in the JSON!) @@ -2362,8 +2345,6 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) #else case 0x80: // chan_ioreadval; read data from audio lib #endif - DEBUG_PRINT("- cmd 0x80, read data from audio lib"); - DEBUG_PRINT(" - reading index: %d", loBits); value = seqChannel->soundScriptIO[loBits]; if (loBits < 4) { @@ -2463,7 +2444,6 @@ out: void sequence_player_process_sequence(struct SequencePlayer *seqPlayer) { - DEBUG_PRINT("sequence_player_process_sequence()"); u8 cmd; #ifdef VERSION_SH diff --git a/src/decomp/audio/synthesis.c b/src/decomp/audio/synthesis.c index 57dd154..0c4c6dc 100644 --- a/src/decomp/audio/synthesis.c +++ b/src/decomp/audio/synthesis.c @@ -28,13 +28,9 @@ #define DMEM_ADDR_WET_RIGHT_CH 0x880 #define aSetLoadBufferPair(pkt, c, off) \ - DEBUG_PRINT("- (in set load buffer pair, set buffer 1) "); \ aSetBuffer(pkt, 0, c + DMEM_ADDR_WET_LEFT_CH, 0, DEFAULT_LEN_1CH - c); \ - DEBUG_PRINT("- (in set load buffer pair, load buffer 1) "); \ aLoadBuffer(pkt, VIRTUAL_TO_PHYSICAL2(gSynthesisReverb.ringBuffer.left + (off))); \ - DEBUG_PRINT("- (in set load buffer pair, set buffer 2) "); \ aSetBuffer(pkt, 0, c + DMEM_ADDR_WET_RIGHT_CH, 0, DEFAULT_LEN_1CH - c); \ - DEBUG_PRINT("- (in set load buffer pair, load buffer 2) "); \ aLoadBuffer(pkt, VIRTUAL_TO_PHYSICAL2(gSynthesisReverb.ringBuffer.right + (off))) #define aSetSaveBufferPair(pkt, c, d, off) \ @@ -362,7 +358,6 @@ aiBufPtr+= chunkLen; // bufLen will be divisible by 16 u64 *synthesis_execute(u64 *cmdBuf, s32 *writtenCmds, s16 *aiBuf, s32 bufLen) { - DEBUG_PRINT("synthesis_execute()"); s32 chunkLen; u32 *aiBufPtr = (u32 *)aiBuf; u64 *cmd = cmdBuf + 1; @@ -583,66 +578,51 @@ u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateI #else u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateIndex) { - DEBUG_PRINT("synthesis_do_one_audio_update()"); UNUSED s32 pad1[1]; UNUSED s32 pad[2]; UNUSED s32 pad2[1]; s16 temp; - DEBUG_PRINT("- curFrame: %d", gSynthesisReverb.curFrame); - DEBUG_PRINT("- updateIndex: %d", updateIndex); struct ReverbRingBufferItem *v1 = &gSynthesisReverb.items[gSynthesisReverb.curFrame][updateIndex]; - DEBUG_PRINT("- v1: %x", v1); if (gSynthesisReverb.useReverb == 0) { - DEBUG_PRINT("- w/o reverb"); aClearBuffer(cmd++, DMEM_ADDR_LEFT_CH, DEFAULT_LEN_2CH); cmd = synthesis_process_notes(aiBuf, bufLen, cmd); } else { - DEBUG_PRINT("- w/ reverb"); if (gReverbDownsampleRate == 1) { - DEBUG_PRINT("- w/ reverb downsample"); // Put the oldest samples in the ring buffer into the wet channels - DEBUG_PRINT("- set load buffer pair 1"); - DEBUG_PRINT("- startPos: %d", v1->startPos); aSetLoadBufferPair(cmd++, 0, v1->startPos); if (v1->lengthB != 0) { // Ring buffer wrapped - DEBUG_PRINT("- set load buffer pair 2"); aSetLoadBufferPair(cmd++, v1->lengthA, 0); temp = 0; } // Use the reverb sound as initial sound for this audio update - DEBUG_PRINT("- dmem move"); aDMEMMove(cmd++, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_LEFT_CH, DEFAULT_LEN_2CH); // (Hopefully) lower the volume of the wet channels. New reverb will later be mixed into // these channels. - DEBUG_PRINT("- set buffer"); aSetBuffer(cmd++, 0, 0, 0, DEFAULT_LEN_2CH); // 0x8000 here is -100% - DEBUG_PRINT("- mix"); aMix(cmd++, 0, /*gain*/ 0x8000 + gSynthesisReverb.reverbGain, /*in*/ DMEM_ADDR_WET_LEFT_CH, /*out*/ DMEM_ADDR_WET_LEFT_CH); } else { - DEBUG_PRINT("- w/o reverb downsample"); // Same as above but upsample the previously downsampled samples used for reverb first temp = 0; //! jesus christ s16 t4 = (v1->startPos & 7) * 2; s16 ra = ALIGN(v1->lengthA + t4, 4); - DEBUG_PRINT("- set load buffer pair"); aSetLoadBufferPair(cmd++, 0, v1->startPos - t4 / 2); if (v1->lengthB != 0) { @@ -654,19 +634,12 @@ u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateI //! useless assignment. ra = ra + temp; } - DEBUG_PRINT("- set buffer 1"); aSetBuffer(cmd++, 0, t4 + DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_LEFT_CH, bufLen << 1); - DEBUG_PRINT("- resample 1"); aResample(cmd++, gSynthesisReverb.resampleFlags, gSynthesisReverb.resampleRate, VIRTUAL_TO_PHYSICAL2(gSynthesisReverb.resampleStateLeft)); - DEBUG_PRINT("- set buffer 2"); aSetBuffer(cmd++, 0, t4 + DMEM_ADDR_WET_RIGHT_CH, DMEM_ADDR_RIGHT_CH, bufLen << 1); - DEBUG_PRINT("- resample 2"); aResample(cmd++, gSynthesisReverb.resampleFlags, gSynthesisReverb.resampleRate, VIRTUAL_TO_PHYSICAL2(gSynthesisReverb.resampleStateRight)); - DEBUG_PRINT("- set buffer 3"); aSetBuffer(cmd++, 0, 0, 0, DEFAULT_LEN_2CH); - DEBUG_PRINT("- mix"); aMix(cmd++, 0, /*gain*/ 0x8000 + gSynthesisReverb.reverbGain, /*in*/ DMEM_ADDR_LEFT_CH, /*out*/ DMEM_ADDR_LEFT_CH); - DEBUG_PRINT("- dmem move"); aDMEMMove(cmd++, DMEM_ADDR_LEFT_CH, DMEM_ADDR_WET_LEFT_CH, DEFAULT_LEN_2CH); } cmd = synthesis_process_notes(aiBuf, bufLen, cmd); @@ -700,7 +673,6 @@ u64 *synthesis_process_note(struct Note *note, struct NoteSubEu *noteSubEu, stru #else u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { - DEBUG_PRINT("synthesis_process_notes()"); s32 noteIndex; // sp174 struct Note *note; // s7 @@ -787,29 +759,22 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) for (noteIndex = 0; noteIndex < gMaxSimultaneousNotes; noteIndex++) { - DEBUG_PRINT("- for note index %d/%d", noteIndex, gMaxSimultaneousNotes); - DEBUG_PRINT("- getting note"); note = &gNotes[noteIndex]; //! This function requires note->enabled to be volatile, but it breaks other functions like note_enable. //! Casting to a struct with just the volatile bitfield works, but there may be a better way to match. - DEBUG_PRINT("- if note is enabled but not loaded"); if (((struct vNote *)note)->enabled && IS_BANK_LOAD_COMPLETE(note->bankId) == FALSE) { - DEBUG_PRINT("- note is enabled but not loaded"); gAudioErrorFlags = (note->bankId << 8) + noteIndex + 0x1000000; continue; } - DEBUG_PRINT("- if note is enabled"); if (((struct vNote *)note)->enabled) { - DEBUG_PRINT("$ note is enabled!"); flags = 0; - DEBUG_PRINT("- if note needs to be init"); if (note->needsInit == TRUE) { flags = A_INIT; @@ -817,7 +782,6 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) note->samplePosFrac = 0; } - DEBUG_PRINT("- if note frequency is less than 2"); if (note->frequency < US_FLOAT(2.0)) { nParts = 1; @@ -842,12 +806,10 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) samplesLenFixedPoint = note->samplePosFrac + resamplingRateFixedPoint * bufLen * 2; note->samplePosFrac = samplesLenFixedPoint & 0xFFFF; // 16-bit store, can't reuse - DEBUG_PRINT("- if note sound is null"); if (note->sound == NULL) { // A wave synthesis note (not ADPCM) - DEBUG_PRINT("- note is null, do wave synthesis"); cmd = load_wave_samples(cmd, note, samplesLenFixedPoint >> 0x10); noteSamplesDmemAddrBeforeResampling = DMEM_ADDR_UNCOMPRESSED_NOTE + note->samplePosInt * 2; note->samplePosInt += samplesLenFixedPoint >> 0x10; @@ -856,7 +818,6 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) else { // ADPCM note - DEBUG_PRINT("- @ handle adpcm note"); audioBookSample = note->sound->sample; @@ -866,7 +827,6 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) resampledTempLen = 0; for (curPart = 0; curPart < nParts; curPart++) { - DEBUG_PRINT("- for part %d", curPart); nAdpcmSamplesProcessed = 0; // s8 s5 = 0; // s4 @@ -888,7 +848,6 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) u32 nEntries; // v1 curLoadedBook = audioBookSample->book->book; nEntries = audioBookSample->book->order * audioBookSample->book->npredictors; - DEBUG_PRINT("- loading adpcm"); aLoadADPCM(cmd++, nEntries * 16, VIRTUAL_TO_PHYSICAL2(curLoadedBook)); } @@ -952,7 +911,6 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) a3 = 0; } - DEBUG_PRINT("- if not note restart"); if (note->restart != FALSE) { aSetLoop(cmd++, VIRTUAL_TO_PHYSICAL2(audioBookSample->loop->state)); @@ -1000,7 +958,6 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) } flags = 0; - DEBUG_PRINT("- if note finished"); if (noteFinished) { aClearBuffer(cmd++, DMEM_ADDR_UNCOMPRESSED_NOTE + s5, @@ -1011,7 +968,6 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) break; } - DEBUG_PRINT("- if restart"); if (restart) { note->restart = TRUE; @@ -1097,20 +1053,14 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) } } - DEBUG_PRINT("- done handling notes"); - DEBUG_PRINT("- setting buffer 1"); t9 = bufLen * 2; aSetBuffer(cmd++, 0, 0, DMEM_ADDR_TEMP, t9); - DEBUG_PRINT("- interleaving"); aInterleave(cmd++, DMEM_ADDR_LEFT_CH, DMEM_ADDR_RIGHT_CH); t9 *= 2; - DEBUG_PRINT("- setting buffer 2"); aSetBuffer(cmd++, 0, 0, DMEM_ADDR_TEMP, t9); - DEBUG_PRINT("- saving buffer"); aSaveBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(aiBuf)); - DEBUG_PRINT("- returning from process notes"); return cmd; } diff --git a/src/decomp/game/interaction.c b/src/decomp/game/interaction.c index 85d792e..2e6766d 100644 --- a/src/decomp/game/interaction.c +++ b/src/decomp/game/interaction.c @@ -72,31 +72,31 @@ static u32 interact_noop(struct MarioState *m, u32 interactType, struct Object * } void push_mario_out_of_object(struct MarioState *m, struct Object *o, f32 padding); + void reset_mario_pitch(struct MarioState *m); -static u32 interact_pole(struct MarioState *m, u32 interactType, struct Object *o) +u32 interact_pole(struct MarioState *m, UNUSED u32 interactType, struct Object *o) { + if (!m || !o) { return FALSE; } s32 actionId = m->action & ACT_ID_MASK; - if (actionId >= 0x080 && actionId < 0x0A0) { -#if defined(VERSION_SH) || defined(VERSION_CN) - f32 velConv = m->forwardVel; // conserve the velocity. - struct Object *marioObj = m->marioObj; - u32 lowSpeed; -#else - u32 lowSpeed = (m->forwardVel <= 10.0f); - struct Object *marioObj = m->marioObj; -#endif - if (!(m->prevAction & ACT_FLAG_ON_POLE) || m->usedObj != o) { -#if defined(VERSION_SH) || defined(VERSION_CN) - lowSpeed = (velConv <= 10.0f); -#endif + #ifdef VERSION_SH + f32 velConv = m->forwardVel; // conserve the velocity. + struct Object *marioObj = m->marioObj; u32 lowSpeed; + #else + u32 lowSpeed = (m->forwardVel <= 10.0f); + struct Object *marioObj = m->marioObj; + #endif mario_stop_riding_and_holding(m); + #ifdef VERSION_SH + lowSpeed = (velConv <= 10.0f); + #endif + m->interactObj = o; m->usedObj = o; m->vel[1] = 0.0f; @@ -111,15 +111,15 @@ static u32 interact_pole(struct MarioState *m, u32 interactType, struct Object * return set_mario_action(m, ACT_GRAB_POLE_SLOW, 0); } -#if defined(VERSION_SH) || defined(VERSION_CN) + //! @bug Using m->forwardVel here is assumed to be 0.0f due to the set from earlier. + // This is fixed in the Shindou version. + #ifdef VERSION_SH marioObj->oMarioPoleYawVel = (s32)(velConv * 0x100 + 0x1000); -#else + #else marioObj->oMarioPoleYawVel = (s32)(m->forwardVel * 0x100 + 0x1000); -#endif + #endif reset_mario_pitch(m); -#if ENABLE_RUMBLE queue_rumble_data(5, 80); -#endif return set_mario_action(m, ACT_GRAB_POLE_FAST, 0); } } @@ -127,51 +127,11 @@ static u32 interact_pole(struct MarioState *m, u32 interactType, struct Object * return FALSE; } -static struct InteractionHandler sInteractionHandlers[] = { - {INTERACT_COIN, interact_noop}, - {INTERACT_WATER_RING, interact_noop}, - {INTERACT_STAR_OR_KEY, interact_noop}, - {INTERACT_BBH_ENTRANCE, interact_noop}, - {INTERACT_WARP, interact_noop}, - {INTERACT_WARP_DOOR, interact_noop}, - {INTERACT_DOOR, interact_noop}, - {INTERACT_CANNON_BASE, interact_noop}, - {INTERACT_IGLOO_BARRIER, interact_noop}, - {INTERACT_TORNADO, interact_noop}, - {INTERACT_WHIRLPOOL, interact_noop}, - {INTERACT_STRONG_WIND, interact_noop}, - {INTERACT_FLAME, interact_noop}, - {INTERACT_SNUFIT_BULLET, interact_noop}, - {INTERACT_CLAM_OR_BUBBA, interact_noop}, - {INTERACT_BULLY, interact_noop}, - {INTERACT_SHOCK, interact_noop}, - {INTERACT_BOUNCE_TOP2, interact_noop}, - {INTERACT_MR_BLIZZARD, interact_noop}, - {INTERACT_HIT_FROM_BELOW, interact_noop}, - {INTERACT_BOUNCE_TOP, interact_noop}, - {INTERACT_DAMAGE, interact_noop}, - {INTERACT_POLE, interact_pole}, - {INTERACT_HOOT, interact_noop}, - {INTERACT_BREAKABLE, interact_noop}, - {INTERACT_KOOPA, interact_noop}, - {INTERACT_KOOPA_SHELL, interact_noop}, - {INTERACT_UNKNOWN_08, interact_noop}, - {INTERACT_CAP, interact_noop}, - {INTERACT_GRABBABLE, interact_noop}, - {INTERACT_TEXT, interact_noop}, -}; +static struct InteractionHandler sInteractionHandlers[] = {{INTERACT_COIN, interact_noop}, {INTERACT_WATER_RING, interact_noop}, {INTERACT_STAR_OR_KEY, interact_noop}, {INTERACT_BBH_ENTRANCE, interact_noop}, {INTERACT_WARP, interact_noop}, {INTERACT_WARP_DOOR, interact_noop}, {INTERACT_DOOR, interact_noop}, {INTERACT_CANNON_BASE, interact_noop}, {INTERACT_IGLOO_BARRIER, interact_noop}, {INTERACT_TORNADO, interact_noop}, {INTERACT_WHIRLPOOL, interact_noop}, {INTERACT_STRONG_WIND, interact_noop}, {INTERACT_FLAME, interact_noop}, {INTERACT_SNUFIT_BULLET, interact_noop}, {INTERACT_CLAM_OR_BUBBA, interact_noop}, {INTERACT_BULLY, interact_noop}, {INTERACT_SHOCK, interact_noop}, {INTERACT_BOUNCE_TOP2, interact_noop}, {INTERACT_MR_BLIZZARD, interact_noop}, {INTERACT_HIT_FROM_BELOW, interact_noop}, {INTERACT_BOUNCE_TOP, interact_noop}, {INTERACT_DAMAGE, interact_noop}, {INTERACT_POLE, interact_pole}, {INTERACT_HOOT, interact_noop}, {INTERACT_BREAKABLE, interact_noop}, {INTERACT_KOOPA, interact_noop}, {INTERACT_KOOPA_SHELL, interact_noop}, {INTERACT_UNKNOWN_08, interact_noop}, {INTERACT_CAP, interact_noop}, {INTERACT_GRABBABLE, interact_noop}, {INTERACT_TEXT, interact_noop},}; -static u32 sForwardKnockbackActions[][3] = { - {ACT_SOFT_FORWARD_GROUND_KB, ACT_FORWARD_GROUND_KB, ACT_HARD_FORWARD_GROUND_KB}, - {ACT_FORWARD_AIR_KB, ACT_FORWARD_AIR_KB, ACT_HARD_FORWARD_AIR_KB}, - {ACT_FORWARD_WATER_KB, ACT_FORWARD_WATER_KB, ACT_FORWARD_WATER_KB}, -}; +static u32 sForwardKnockbackActions[][3] = {{ACT_SOFT_FORWARD_GROUND_KB, ACT_FORWARD_GROUND_KB, ACT_HARD_FORWARD_GROUND_KB}, {ACT_FORWARD_AIR_KB, ACT_FORWARD_AIR_KB, ACT_HARD_FORWARD_AIR_KB}, {ACT_FORWARD_WATER_KB, ACT_FORWARD_WATER_KB, ACT_FORWARD_WATER_KB},}; -static u32 sBackwardKnockbackActions[][3] = { - {ACT_SOFT_BACKWARD_GROUND_KB, ACT_BACKWARD_GROUND_KB, ACT_HARD_BACKWARD_GROUND_KB}, - {ACT_BACKWARD_AIR_KB, ACT_BACKWARD_AIR_KB, ACT_HARD_BACKWARD_AIR_KB}, - {ACT_BACKWARD_WATER_KB, ACT_BACKWARD_WATER_KB, ACT_BACKWARD_WATER_KB}, -}; +static u32 sBackwardKnockbackActions[][3] = {{ACT_SOFT_BACKWARD_GROUND_KB, ACT_BACKWARD_GROUND_KB, ACT_HARD_BACKWARD_GROUND_KB}, {ACT_BACKWARD_AIR_KB, ACT_BACKWARD_AIR_KB, ACT_HARD_BACKWARD_AIR_KB}, {ACT_BACKWARD_WATER_KB, ACT_BACKWARD_WATER_KB, ACT_BACKWARD_WATER_KB},}; static u8 sDisplayingDoorText = FALSE; static u8 sJustTeleported = FALSE; @@ -540,8 +500,7 @@ u32 mario_check_object_grab(struct MarioState *m) if (!(m->action & ACT_FLAG_AIR)) { - set_mario_action( - m, m->action & ACT_FLAG_DIVING ? ACT_DIVE_PICKING_UP : ACT_PICKING_UP, 0); + set_mario_action(m, m->action & ACT_FLAG_DIVING ? ACT_DIVE_PICKING_UP : ACT_PICKING_UP, 0); } result = TRUE; @@ -566,11 +525,9 @@ u32 bully_knock_back_mario(struct MarioState *mario) f32 bullyToMarioRatio = bully->hitboxRadius * 3 / 53; f32 marioToBullyRatio = 53.0f / bully->hitboxRadius; - init_bully_collision_data(&marioData, mario->pos[0], mario->pos[2], mario->forwardVel, - mario->faceAngle[1], bullyToMarioRatio, 52.0f); + init_bully_collision_data(&marioData, mario->pos[0], mario->pos[2], mario->forwardVel, mario->faceAngle[1], bullyToMarioRatio, 52.0f); - init_bully_collision_data(&bullyData, bully->oPosX, bully->oPosZ, bully->oForwardVel, - bully->oMoveAngleYaw, marioToBullyRatio, bully->hitboxRadius + 2.0f); + init_bully_collision_data(&bullyData, bully->oPosX, bully->oPosZ, bully->oForwardVel, bully->oMoveAngleYaw, marioToBullyRatio, bully->hitboxRadius + 2.0f); if (mario->forwardVel != 0.0f) { @@ -864,8 +821,7 @@ u32 take_damage_from_interact_object(struct MarioState *m) u32 take_damage_and_knock_back(struct MarioState *m, struct Object *o) { - if (!sInvulnerable && !(m->flags & MARIO_VANISH_CAP) - && !(o->oInteractionSubtype & INT_SUBTYPE_DELAY_INVINCIBILITY)) + if (!sInvulnerable && !(m->flags & MARIO_VANISH_CAP) && !(o->oInteractionSubtype & INT_SUBTYPE_DELAY_INVINCIBILITY)) { o->oInteractStatus = INT_STATUS_INTERACTED | INT_STATUS_ATTACKED_MARIO; m->interactObj = o; diff --git a/src/decomp/game/mario_actions_automatic.c b/src/decomp/game/mario_actions_automatic.c index 81c4526..df5c795 100644 --- a/src/decomp/game/mario_actions_automatic.c +++ b/src/decomp/game/mario_actions_automatic.c @@ -22,6 +22,7 @@ #include "../include/mario_geo_switch_case_ids.h" #include "../../rumble.h" #include "../../FakeObject.h" +#include "../../libsm64.h" static Vec3f gVec3fZero = {0.0f, 0.0f, 0.0f}; @@ -75,14 +76,16 @@ void play_climbing_sounds(struct MarioState *m, s32 b) s32 set_pole_position(struct MarioState *m, f32 offsetY) { - if (!m) { return 0;} - if (m->usedObj == NULL) + if (!m->isLocal && m->usedObj == NULL) { - m->usedObj = cur_obj_find_nearest_pole(); + return POLE_NONE; } + // This is here so if somehow a pole despawns while you are on it. + // You will just drop from it. if (m->usedObj == NULL) { + // If Mario is no longer interacting with the pole, stop the pole holding action. set_mario_action(m, ACT_FREEFALL, 0); return POLE_FELL_OFF; } @@ -161,11 +164,7 @@ s32 set_pole_position(struct MarioState *m, f32 offsetY) s32 act_holding_pole(struct MarioState *m) { - if (!m) { return 0; } struct Object *marioObj = m->marioObj; - if (m->usedObj == NULL) { m->usedObj = cur_obj_find_nearest_pole(); } - if (m->usedObj == NULL) { return FALSE; } - f32 poleStickY = -m->controller->stickY; #ifdef VERSION_JP @@ -198,7 +197,12 @@ s32 act_holding_pole(struct MarioState *m) if (poleStickY > 16.0f) { - f32 poleTop = m->usedObj->hitboxHeight - 100.0f; + f32 poleTop = m->pos[1] + 1000; + + if (m->usedObj != NULL) + { + poleTop = m->usedObj->hitboxHeight - 100.0f; + } // const BehaviorScript *poleBehavior = virtual_to_segmented(0x13, m->usedObj->behavior); if (marioObj->oMarioPolePos < poleTop - 0.4f) @@ -253,8 +257,6 @@ s32 act_holding_pole(struct MarioState *m) s32 act_climbing_pole(struct MarioState *m) { - if (!m) { return 0; } - if (m->usedObj == NULL) { m->usedObj = cur_obj_find_nearest_pole(); } s32 sp24; struct Object *marioObj = m->marioObj; s16 cameraAngle = m->area->camera->yaw; @@ -298,8 +300,6 @@ s32 act_climbing_pole(struct MarioState *m) s32 act_grab_pole_slow(struct MarioState *m) { - if (!m) { return 0; } - if (m->usedObj == NULL) { m->usedObj = cur_obj_find_nearest_pole(); } play_sound_if_no_flag(m, SOUND_MARIO_WHOA, MARIO_MARIO_SOUND_PLAYED); if (set_pole_position(m, 0.0f) == POLE_NONE) @@ -317,8 +317,6 @@ s32 act_grab_pole_slow(struct MarioState *m) s32 act_grab_pole_fast(struct MarioState *m) { - if (!m) { return 0; } - if (m->usedObj == NULL) { m->usedObj = cur_obj_find_nearest_pole(); } struct Object *marioObj = m->marioObj; play_sound_if_no_flag(m, SOUND_MARIO_WHOA, MARIO_MARIO_SOUND_PLAYED); @@ -348,8 +346,6 @@ s32 act_grab_pole_fast(struct MarioState *m) s32 act_top_of_pole_transition(struct MarioState *m) { - if (!m) { return 0; } - if (m->usedObj == NULL) { m->usedObj = cur_obj_find_nearest_pole(); } struct Object *marioObj = m->marioObj; marioObj->oMarioPoleYawVel = 0; @@ -376,9 +372,7 @@ s32 act_top_of_pole_transition(struct MarioState *m) s32 act_top_of_pole(struct MarioState *m) { - if (!m) { return 0; } UNUSED struct Object *marioObj = m->marioObj; - if (m->usedObj == NULL) { m->usedObj = cur_obj_find_nearest_pole(); } f32 poleStickY = -m->controller->stickY; if (m->input & INPUT_A_PRESSED) @@ -937,8 +931,6 @@ s32 act_in_cannon(struct MarioState *m) s32 act_tornado_twirling(struct MarioState *m) { - if (!m) { return 0; } - if (m->usedObj == NULL) { return FALSE; } struct SM64SurfaceCollisionData *floor; Vec3f nextPos; struct Object *marioObj = m->marioObj; diff --git a/src/decomp/global_state.c b/src/decomp/global_state.c index 63e44dd..20fdeee 100644 --- a/src/decomp/global_state.c +++ b/src/decomp/global_state.c @@ -3,8 +3,6 @@ #include #include -#include "../obj_pool.h" - struct GlobalState *g_state = 0; struct GlobalState *global_state_create(void) @@ -23,6 +21,5 @@ void global_state_bind(struct GlobalState *state) void global_state_delete(struct GlobalState *state) { - obj_pool_free_all(&state->mgFakeObjects); free(state); } \ No newline at end of file diff --git a/src/decomp/global_state.h b/src/decomp/global_state.h index 3a97f87..5c252e9 100644 --- a/src/decomp/global_state.h +++ b/src/decomp/global_state.h @@ -42,7 +42,6 @@ struct GlobalState struct Area *mgCurrentArea; struct Object *mgCurrentObject; struct Object *mgMarioObject; - struct ObjPool mgFakeObjects; struct MarioAnimation mD_80339D10; struct MarioState mgMarioStateVal; }; diff --git a/src/decomp/include/PR/abi.h b/src/decomp/include/PR/abi.h index 57a765e..a616949 100644 --- a/src/decomp/include/PR/abi.h +++ b/src/decomp/include/PR/abi.h @@ -460,13 +460,9 @@ typedef short ENVMIX_STATE[40]; */ #define aLoadBuffer(pkt, s) \ { \ - DEBUG_PRINT("aLoadBuffer()"); \ - DEBUG_PRINT("- getting pkt"); \ Acmd *_a = (Acmd *)pkt; \ \ - DEBUG_PRINT("- setting first word"); \ _a->words.w0 = _SHIFTL(A_LOADBUFF, 24, 8); \ - DEBUG_PRINT("- setting second word"); \ _a->words.w1 = (uintptr_t)(s); \ } @@ -582,8 +578,6 @@ typedef short ENVMIX_STATE[40]; */ #define aSetBuffer(pkt, f, i, o, c) \ { \ - DEBUG_PRINT("aSetBuffer()"); \ - DEBUG_PRINT("- getting pkt"); \ Acmd *_a = (Acmd *)pkt; \ \ _a->words.w0 = (_SHIFTL(A_SETBUFF, 24, 8) | _SHIFTL(f, 16, 8) | \ diff --git a/src/decomp/pc/mixer.c b/src/decomp/pc/mixer.c index a08897c..704dc54 100644 --- a/src/decomp/pc/mixer.c +++ b/src/decomp/pc/mixer.c @@ -162,8 +162,6 @@ void aSaveBufferImpl(uint16_t source_addr, int16_t *dest_addr, uint16_t nbytes) #else void aLoadBufferImpl(const void *source_addr) { - DEBUG_PRINT("aLoadBufferImpl()"); - DEBUG_PRINT("- source_addr: %x", source_addr); memcpy(BUF_U8(rspa.in), source_addr, ROUND_UP_8(rspa.nbytes)); } diff --git a/src/libsm64.c b/src/libsm64.c index ac7c9e5..0e3ca73 100644 --- a/src/libsm64.c +++ b/src/libsm64.c @@ -1,3 +1,4 @@ +#include "decomp/game/interaction.h" #ifndef SM64_LIB_EXPORT #define SM64_LIB_EXPORT #endif @@ -55,6 +56,49 @@ struct MarioInstance struct ObjPool s_mario_instance_pool = {0, 0}; struct ObjPool s_fakeobj_instance_pool = {0, 0}; +f32 dist_between_objects(struct Object *obj1, struct Object *obj2) +{ + if (obj1 == NULL || obj2 == NULL) { return 0; } + f32 dx = obj1->oPosX - obj2->oPosX; + f32 dy = obj1->oPosY - obj2->oPosY; + f32 dz = obj1->oPosZ - obj2->oPosZ; + + return sqrtf(dx * dx + dy * dy + dz * dz); +} + +struct Object *get_closest_pole_object() +{ + struct Object *closestObj = NULL; + f32 minDist = 0x20000; + + for (int i = 0; i < s_fakeobj_instance_pool.size; i++) + { + struct Object *obj = &((struct FakeObject *)s_fakeobj_instance_pool.objects[i])->object; + if (obj == NULL || obj->activeFlags == ACTIVE_FLAG_DEACTIVATED || !(obj->oInteractType & INTERACT_POLE) || obj == gMarioObject) continue; + + DEBUG_PRINT( + "POOL: %d ptr=%p interact=%X active=%X pos=(%f,%f,%f)", + i, + obj, + obj->oInteractType, + obj->activeFlags, + obj->oPosX, + obj->oPosY, + obj->oPosZ + ); + + f32 objDist = dist_between_objects(gMarioObject, obj); + if (objDist < minDist) + { + closestObj = obj; + DEBUG_PRINT("Found pole object with ID %d at distance %f", i, objDist); + minDist = objDist; + } + } + + return closestObj; +} + static void update_button(bool on, u16 button) { gController.buttonPressed &= ~button; diff --git a/src/libsm64.h b/src/libsm64.h index b10fcef..4680b33 100644 --- a/src/libsm64.h +++ b/src/libsm64.h @@ -9,6 +9,7 @@ #include #include "obj_pool.h" +#include "decomp/include/types.h" #if defined(_WIN32) #ifdef SM64_LIB_EXPORT @@ -156,7 +157,9 @@ enum SM64_GEO_MAX_TRIANGLES = 1024, }; -extern struct ObjPool s_fakeobj_instance_pool; +extern f32 dist_between_objects(struct Object *obj1, struct Object *obj2); + +extern struct Object *get_closest_pole_object(); typedef void (*SM64RumbleCallbackFunctionPtr)(int32_t marioId, int16_t level, int16_t time); diff --git a/src/play_sound.c b/src/play_sound.c index 03f26dd..33f40c0 100644 --- a/src/play_sound.c +++ b/src/play_sound.c @@ -10,7 +10,6 @@ extern void play_sound(uint32_t soundBits, f32 *pos) { if (g_is_audio_initialized) { - DEBUG_PRINT("$ play_sound(%d) request %d; pos %f %f %f\n", soundBits, sSoundRequestCount, pos[0], pos[1], pos[2]); sSoundRequests[sSoundRequestCount].soundBits = soundBits; sSoundRequests[sSoundRequestCount].position = pos; sSoundRequestCount++;