diff options
Diffstat (limited to 'src/code')
| -rw-r--r-- | src/code/audio/audio_heap.c | 2 | ||||
| -rw-r--r-- | src/code/audio/audio_load.c | 2 | ||||
| -rw-r--r-- | src/code/audio/audio_playback.c | 987 | ||||
| -rw-r--r-- | src/code/audio/audio_seqplayer.c | 6 | ||||
| -rw-r--r-- | src/code/graph.c | 1 | ||||
| -rw-r--r-- | src/code/sys_ucode.c | 7 | ||||
| -rw-r--r-- | src/code/z_actor.c | 11 | ||||
| -rw-r--r-- | src/code/z_bgcheck.c | 11 | ||||
| -rw-r--r-- | src/code/z_eff_blure.c | 5 | ||||
| -rw-r--r-- | src/code/z_eff_shield_particle.c | 5 | ||||
| -rw-r--r-- | src/code/z_eff_spark.c | 5 | ||||
| -rw-r--r-- | src/code/z_eff_tire_mark.c | 6 | ||||
| -rw-r--r-- | src/code/z_en_item00.c | 51 | ||||
| -rw-r--r-- | src/code/z_jpeg.c | 7 | ||||
| -rw-r--r-- | src/code/z_lights.c | 5 | ||||
| -rw-r--r-- | src/code/z_quake.c | 315 | ||||
| -rw-r--r-- | src/code/z_view.c | 130 |
17 files changed, 1272 insertions, 284 deletions
diff --git a/src/code/audio/audio_heap.c b/src/code/audio/audio_heap.c index 7c43ef0f1..b3d83c1f9 100644 --- a/src/code/audio/audio_heap.c +++ b/src/code/audio/audio_heap.c @@ -18,7 +18,7 @@ #pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_8018B578.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_8018B5D0.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/AudioHeap_AllocDmaMemory.s") #pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_8018B608.s") diff --git a/src/code/audio/audio_load.c b/src/code/audio/audio_load.c index 15e54b3c5..497f9d47a 100644 --- a/src/code/audio/audio_load.c +++ b/src/code/audio/audio_load.c @@ -8,7 +8,7 @@ #pragma GLOBAL_ASM("asm/non_matchings/code/audio_load/func_8018EF88.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_load/func_8018F220.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/audio_load/AudioLoad_IsFontLoadComplete.s") #pragma GLOBAL_ASM("asm/non_matchings/code/audio_load/func_8018F298.s") diff --git a/src/code/audio/audio_playback.c b/src/code/audio/audio_playback.c index ec8dd86b8..78161943c 100644 --- a/src/code/audio/audio_playback.c +++ b/src/code/audio/audio_playback.c @@ -1,63 +1,988 @@ #include "global.h" -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_playback/func_80194930.s") +void AudioPlayback_NoteSetResamplingRate(NoteSubEu* noteSubEu, f32 resamplingRateInput); +void AudioPlayback_AudioListPushFront(AudioListItem* list, AudioListItem* item); +void AudioPlayback_NoteInitForLayer(Note* note, SequenceLayer* layer); -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_playback/func_80194DB0.s") +void AudioPlayback_InitNoteSub(Note* note, NoteSubEu* sub, NoteSubAttributes* attrs) { + f32 volRight, volLeft; + s32 smallPanIndex; + u64 pad; + u8 strongLeft; + u8 strongRight; + f32 vel; + u8 pan; + u8 reverbVol; + StereoData stereoData; + s32 stereoHeadsetEffects = note->playbackState.stereoHeadsetEffects; -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_playback/func_80194E60.s") + vel = attrs->velocity; + pan = attrs->pan; + reverbVol = attrs->reverbVol; + stereoData = attrs->stereo.s; -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_playback/func_80194F20.s") + sub->bitField0 = note->noteSubEu.bitField0; + sub->bitField1 = note->noteSubEu.bitField1; + sub->sound.samples = note->noteSubEu.sound.samples; + sub->unk_06 = note->noteSubEu.unk_06; -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_playback/func_80194F84.s") + AudioPlayback_NoteSetResamplingRate(sub, attrs->frequency); -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_playback/func_801954CC.s") + pan &= 0x7F; -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_playback/func_80195508.s") + sub->bitField0.stereoStrongRight = false; + sub->bitField0.stereoStrongLeft = false; + sub->bitField0.stereoHeadsetEffects = stereoData.stereoHeadsetEffects; + sub->bitField0.usesHeadsetPanEffects = stereoData.usesHeadsetPanEffects; + if (stereoHeadsetEffects && gAudioContext.soundMode == AUDIO_MODE_HEADSET) { + smallPanIndex = pan >> 1; + if (smallPanIndex > 0x3F) { + smallPanIndex = 0x3F; + } -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_playback/func_801955DC.s") + sub->headsetPanLeft = gHeadsetPanQuantization[smallPanIndex]; + sub->headsetPanRight = gHeadsetPanQuantization[0x3F - smallPanIndex]; + sub->bitField1.usesHeadsetPanEffects2 = true; -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_playback/func_801956C0.s") + volLeft = gHeadsetPanVolume[pan]; + volRight = gHeadsetPanVolume[0x7F - pan]; + } else if (stereoHeadsetEffects && gAudioContext.soundMode == AUDIO_MODE_STEREO) { + strongLeft = strongRight = false; + sub->headsetPanRight = 0; + sub->headsetPanLeft = 0; + sub->bitField1.usesHeadsetPanEffects2 = false; -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_playback/func_801957B4.s") + volLeft = gStereoPanVolume[pan]; + volRight = gStereoPanVolume[0x7F - pan]; + if (pan < 0x20) { + strongLeft = true; + } else if (pan > 0x60) { + strongRight = true; + } -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_playback/func_801958F8.s") + sub->bitField0.stereoStrongRight = strongRight; + sub->bitField0.stereoStrongLeft = strongLeft; -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_playback/func_80195C40.s") + switch (stereoData.bit2) { + case 0: + break; + case 1: + sub->bitField0.stereoStrongRight = stereoData.strongRight; + sub->bitField0.stereoStrongLeft = stereoData.strongLeft; + break; + case 2: + sub->bitField0.stereoStrongRight = stereoData.strongRight | strongRight; + sub->bitField0.stereoStrongLeft = stereoData.strongLeft | strongLeft; + break; + case 3: + sub->bitField0.stereoStrongRight = stereoData.strongRight ^ strongRight; + sub->bitField0.stereoStrongLeft = stereoData.strongLeft ^ strongLeft; + break; + } -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_playback/func_80195C60.s") + } else if (gAudioContext.soundMode == AUDIO_MODE_MONO) { + sub->bitField0.stereoHeadsetEffects = false; + sub->bitField0.usesHeadsetPanEffects = false; + volLeft = 0.707f; // approx 1/sqrt(2) + volRight = 0.707f; + } else { + sub->bitField0.stereoStrongRight = stereoData.strongRight; + sub->bitField0.stereoStrongLeft = stereoData.strongLeft; + volLeft = gDefaultPanVolume[pan]; + volRight = gDefaultPanVolume[0x7F - pan]; + } -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_playback/func_80195C80.s") + vel = 0.0f > vel ? 0.0f : vel; + vel = 1.0f < vel ? 1.0f : vel; -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_playback/func_80195D84.s") + sub->targetVolLeft = (s32)((vel * volLeft) * (0x1000 - 0.001f)); + sub->targetVolRight = (s32)((vel * volRight) * (0x1000 - 0.001f)); -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_playback/func_80195DDC.s") + sub->unk_2 = attrs->unk_1; + sub->filter = attrs->filter; + sub->unk_07 = attrs->unk_14; + sub->unk_0E = attrs->unk_16; + sub->reverbVol = reverbVol; + sub->unk_19 = attrs->unk_3; +} -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_playback/func_80195DEC.s") +void AudioPlayback_NoteSetResamplingRate(NoteSubEu* noteSubEu, f32 resamplingRateInput) { + f32 resamplingRate = 0.0f; -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_playback/func_80195E3C.s") + if (resamplingRateInput < 2.0f) { + noteSubEu->bitField1.hasTwoParts = false; + resamplingRate = CLAMP_MAX(resamplingRateInput, 1.99998f); -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_playback/func_80195EE0.s") + } else { + noteSubEu->bitField1.hasTwoParts = true; + if (resamplingRateInput > 3.99996f) { + resamplingRate = 1.99998f; + } else { + resamplingRate = resamplingRateInput * 0.5f; + } + } + noteSubEu->resamplingRateFixedPoint = (s32)(resamplingRate * 32768.0f); +} -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_playback/func_80196040.s") +void AudioPlayback_NoteInit(Note* note) { + if (note->playbackState.parentLayer->adsr.releaseRate == 0) { + AudioEffects_AdsrInit(¬e->playbackState.adsr, note->playbackState.parentLayer->channel->adsr.envelope, + ¬e->playbackState.adsrVolScaleUnused); + } else { + AudioEffects_AdsrInit(¬e->playbackState.adsr, note->playbackState.parentLayer->adsr.envelope, + ¬e->playbackState.adsrVolScaleUnused); + } -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_playback/func_8019617C.s") + note->playbackState.unk_04 = 0; + note->playbackState.adsr.action.s.state = ADSR_STATE_INITIAL; + note->noteSubEu = gDefaultNoteSub; +} -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_playback/func_801961BC.s") +void AudioPlayback_NoteDisable(Note* note) { + if (note->noteSubEu.bitField0.needsInit == true) { + note->noteSubEu.bitField0.needsInit = false; + } + note->playbackState.priority = 0; + note->noteSubEu.bitField0.enabled = false; + note->playbackState.unk_04 = 0; + note->noteSubEu.bitField0.finished = false; + note->playbackState.parentLayer = NO_LAYER; + note->playbackState.prevParentLayer = NO_LAYER; + note->playbackState.adsr.action.s.state = ADSR_STATE_DISABLED; + note->playbackState.adsr.current = 0; +} -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_playback/func_801961E8.s") +void AudioPlayback_ProcessNotes(void) { + s32 pad; + s32 unk_04; + NoteAttributes* attrs; + NoteSubEu* noteSubEu2; + NoteSubEu* noteSubEu; + Note* note; + NotePlaybackState* playbackState; + NoteSubAttributes subAttrs; + u8 bookOffset; + f32 scale; + s32 i; -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_playback/func_80196268.s") + for (i = 0; i < gAudioContext.numNotes; i++) { + note = &gAudioContext.notes[i]; + noteSubEu2 = &gAudioContext.noteSubsEu[gAudioContext.noteSubEuOffset + i]; + playbackState = ¬e->playbackState; + if (playbackState->parentLayer != NO_LAYER) { + if ((u32)playbackState->parentLayer < 0x7FFFFFFF) { + continue; + } -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_playback/func_801963E8.s") + if (note != playbackState->parentLayer->note && playbackState->unk_04 == 0) { + playbackState->adsr.action.s.release = true; + playbackState->adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; + playbackState->priority = 1; + playbackState->unk_04 = 2; + goto out; + } else if (!playbackState->parentLayer->enabled && playbackState->unk_04 == 0 && + playbackState->priority >= 1) { + // do nothing + } else if (playbackState->parentLayer->channel->seqPlayer == NULL) { + AudioSeq_SequenceChannelDisable(playbackState->parentLayer->channel); + playbackState->priority = 1; + playbackState->unk_04 = 1; + continue; + } else if (playbackState->parentLayer->channel->seqPlayer->muted && + (playbackState->parentLayer->channel->muteBehavior & 0x40)) { + // do nothing + } else { + goto out; + } -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_playback/func_8019641C.s") + AudioPlayback_SeqLayerNoteRelease(playbackState->parentLayer); + AudioPlayback_AudioListRemove(¬e->listItem); + AudioPlayback_AudioListPushFront(¬e->listItem.pool->decaying, ¬e->listItem); + playbackState->priority = 1; + playbackState->unk_04 = 2; + } else if (playbackState->unk_04 == 0 && playbackState->priority >= 1) { + continue; + } -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_playback/func_80196448.s") + out: + if (playbackState->priority != 0) { + if (1) {} + noteSubEu = ¬e->noteSubEu; + if (playbackState->unk_04 >= 1 || noteSubEu->bitField0.finished) { + if (playbackState->adsr.action.s.state == ADSR_STATE_DISABLED || noteSubEu->bitField0.finished) { + if (playbackState->wantedParentLayer != NO_LAYER) { + AudioPlayback_NoteDisable(note); + if (playbackState->wantedParentLayer->channel != NULL) { + AudioPlayback_NoteInitForLayer(note, playbackState->wantedParentLayer); + AudioEffects_NoteVibratoInit(note); + AudioEffects_NotePortamentoInit(note); + AudioPlayback_AudioListRemove(¬e->listItem); + AudioSeq_AudioListPushBack(¬e->listItem.pool->active, ¬e->listItem); + playbackState->wantedParentLayer = NO_LAYER; + // don't skip + } else { + AudioPlayback_NoteDisable(note); + AudioPlayback_AudioListRemove(¬e->listItem); + AudioSeq_AudioListPushBack(¬e->listItem.pool->disabled, ¬e->listItem); + playbackState->wantedParentLayer = NO_LAYER; + goto skip; + } + } else { + if (playbackState->parentLayer != NO_LAYER) { + playbackState->parentLayer->bit1 = true; + } + AudioPlayback_NoteDisable(note); + AudioPlayback_AudioListRemove(¬e->listItem); + AudioSeq_AudioListPushBack(¬e->listItem.pool->disabled, ¬e->listItem); + continue; + } + } + } else if (playbackState->adsr.action.s.state == ADSR_STATE_DISABLED) { + if (playbackState->parentLayer != NO_LAYER) { + playbackState->parentLayer->bit1 = true; + } + AudioPlayback_NoteDisable(note); + AudioPlayback_AudioListRemove(¬e->listItem); + AudioSeq_AudioListPushBack(¬e->listItem.pool->disabled, ¬e->listItem); + continue; + } -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_playback/func_80196494.s") + scale = AudioEffects_AdsrUpdate(&playbackState->adsr); + AudioEffects_NoteVibratoUpdate(note); + unk_04 = playbackState->unk_04; + attrs = &playbackState->attributes; + if (unk_04 == 1 || unk_04 == 2) { + subAttrs.frequency = attrs->freqScale; + subAttrs.velocity = attrs->velocity; + subAttrs.pan = attrs->pan; + subAttrs.reverbVol = attrs->reverb; + subAttrs.stereo = attrs->stereo; + subAttrs.unk_1 = attrs->unk_1; + subAttrs.filter = attrs->filter; + subAttrs.unk_14 = attrs->unk_4; + subAttrs.unk_16 = attrs->unk_6; + subAttrs.unk_3 = attrs->unk_3; + bookOffset = noteSubEu->bitField1.bookOffset; + } else { + SequenceLayer* layer = playbackState->parentLayer; + SequenceChannel* channel = playbackState->parentLayer->channel; -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_playback/func_801964F8.s") + subAttrs.frequency = layer->noteFreqScale; + subAttrs.velocity = layer->noteVelocity; + subAttrs.pan = layer->notePan; -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_playback/func_801965F0.s") + if (layer->unk_08 == 0x80) { + subAttrs.unk_3 = channel->unk_10; + } else { + subAttrs.unk_3 = layer->unk_08; + } -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_playback/func_801968C4.s") + if (layer->stereo.s.bit2 == 0) { + subAttrs.stereo = channel->stereo; + } else { + subAttrs.stereo = layer->stereo; + } + + if (layer->unk_0A.s.bit_2 == 1) { + subAttrs.reverbVol = channel->reverb; + } else { + subAttrs.reverbVol = layer->unk_09; + } + + if (layer->unk_0A.s.bit_9 == 1) { + subAttrs.unk_1 = channel->unk_0C; + } else { + subAttrs.unk_1 = 0; + if (1) {} + } + + subAttrs.filter = channel->filter; + subAttrs.unk_14 = channel->unk_0F; + subAttrs.unk_16 = channel->unk_20; + bookOffset = channel->bookOffset & 0x7; + + if (channel->seqPlayer->muted && (channel->muteBehavior & 8)) { + subAttrs.frequency = 0.0f; + subAttrs.velocity = 0.0f; + } + } + + subAttrs.frequency *= playbackState->vibratoFreqScale * playbackState->portamentoFreqScale; + subAttrs.frequency *= gAudioContext.audioBufferParameters.resampleRate; + subAttrs.velocity *= scale; + AudioPlayback_InitNoteSub(note, noteSubEu2, &subAttrs); + noteSubEu->bitField1.bookOffset = bookOffset; + skip:; + } + } +} + +SoundFontSound* AudioPlayback_InstrumentGetSound(Instrument* instrument, s32 semitone) { + SoundFontSound* sound; + + if (semitone < instrument->normalRangeLo) { + sound = &instrument->lowNotesSound; + } else if (semitone <= instrument->normalRangeHi) { + sound = &instrument->normalNotesSound; + } else { + sound = &instrument->highNotesSound; + } + return sound; +} + +Instrument* AudioPlayback_GetInstrumentInner(s32 fontId, s32 instId) { + Instrument* inst; + + if (fontId == 0xFF) { + return NULL; + } + + if (!AudioLoad_IsFontLoadComplete(fontId)) { + gAudioContext.audioErrorFlags = fontId + 0x10000000; + return NULL; + } + + if (instId >= gAudioContext.soundFonts[fontId].numInstruments) { + gAudioContext.audioErrorFlags = ((fontId << 8) + instId) + 0x3000000; + return NULL; + } + + inst = gAudioContext.soundFonts[fontId].instruments[instId]; + if (inst == NULL) { + gAudioContext.audioErrorFlags = ((fontId << 8) + instId) + 0x1000000; + return inst; + } + + return inst; +} + +Drum* AudioPlayback_GetDrum(s32 fontId, s32 drumId) { + Drum* drum; + + if (fontId == 0xFF) { + return NULL; + } + + if (!AudioLoad_IsFontLoadComplete(fontId)) { + gAudioContext.audioErrorFlags = fontId + 0x10000000; + return NULL; + } + + if (drumId >= gAudioContext.soundFonts[fontId].numDrums) { + gAudioContext.audioErrorFlags = ((fontId << 8) + drumId) + 0x4000000; + return NULL; + } + if ((u32)gAudioContext.soundFonts[fontId].drums < 0x80000000) { + return NULL; + } + drum = gAudioContext.soundFonts[fontId].drums[drumId]; + + if (drum == NULL) { + gAudioContext.audioErrorFlags = ((fontId << 8) + drumId) + 0x5000000; + } + + return drum; +} + +SoundFontSound* AudioPlayback_GetSfx(s32 fontId, s32 sfxId) { + SoundFontSound* sfx; + + if (fontId == 0xFF) { + return NULL; + } + + if (!AudioLoad_IsFontLoadComplete(fontId)) { + gAudioContext.audioErrorFlags = fontId + 0x10000000; + return NULL; + } + + if (sfxId >= gAudioContext.soundFonts[fontId].numSfx) { + gAudioContext.audioErrorFlags = ((fontId << 8) + sfxId) + 0x4000000; + return NULL; + } + + if ((u32)gAudioContext.soundFonts[fontId].soundEffects < 0x80000000) { + return NULL; + } + + sfx = &gAudioContext.soundFonts[fontId].soundEffects[sfxId]; + + if (sfx == NULL) { + gAudioContext.audioErrorFlags = ((fontId << 8) + sfxId) + 0x5000000; + } + + if (sfx->sample == NULL) { + return NULL; + } + + return sfx; +} + +s32 AudioPlayback_SetFontInstrument(s32 instrumentType, s32 fontId, s32 index, void* value) { + if (fontId == 0xFF) { + return -1; + } + + if (!AudioLoad_IsFontLoadComplete(fontId)) { + return -2; + } + + switch (instrumentType) { + case 0: + if (index >= gAudioContext.soundFonts[fontId].numDrums) { + return -3; + } + gAudioContext.soundFonts[fontId].drums[index] = value; + break; + + case 1: + if (index >= gAudioContext.soundFonts[fontId].numSfx) { + return -3; + } + gAudioContext.soundFonts[fontId].soundEffects[index] = *(SoundFontSound*)value; + break; + + default: + if (index >= gAudioContext.soundFonts[fontId].numInstruments) { + return -3; + } + gAudioContext.soundFonts[fontId].instruments[index] = value; + break; + } + + return 0; +} + +void AudioPlayback_SeqLayerDecayRelease(SequenceLayer* layer, s32 target) { + Note* note; + NoteAttributes* attrs; + SequenceChannel* chan; + s32 i; + + if (layer == NO_LAYER) { + return; + } + + layer->bit3 = false; + + if (layer->note == NULL) { + return; + } + + note = layer->note; + attrs = ¬e->playbackState.attributes; + + if (note->playbackState.wantedParentLayer == layer) { + note->playbackState.wantedParentLayer = NO_LAYER; + } + + if (note->playbackState.parentLayer != layer) { + if (note->playbackState.parentLayer == NO_LAYER && note->playbackState.wantedParentLayer == NO_LAYER && + note->playbackState.prevParentLayer == layer && target != ADSR_STATE_DECAY) { + note->playbackState.adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; + note->playbackState.adsr.action.s.release = true; + } + return; + } + + if (note->playbackState.adsr.action.s.state != ADSR_STATE_DECAY) { + attrs->freqScale = layer->noteFreqScale; + attrs->velocity = layer->noteVelocity; + attrs->pan = layer->notePan; + + if (layer->channel != NULL) { + chan = layer->channel; + + if (layer->unk_0A.s.bit_2 == 1) { + attrs->reverb = chan->reverb; + } else { + attrs->reverb = layer->unk_09; + } + + if (layer->unk_08 == 0x80) { + attrs->unk_3 = chan->unk_10; + } else { + attrs->unk_3 = layer->unk_08; + } + + if (layer->unk_0A.s.bit_9 == 1) { + attrs->unk_1 = chan->unk_0C; + } else { + attrs->unk_1 = 0; + } + + attrs->filter = chan->filter; + + if (attrs->filter != NULL) { + for (i = 0; i < 8; i++) { + attrs->filterBuf[i] = attrs->filter[i]; + } + attrs->filter = attrs->filterBuf; + } + + attrs->unk_6 = chan->unk_20; + attrs->unk_4 = chan->unk_0F; + if (chan->seqPlayer->muted && (chan->muteBehavior & 8)) { + note->noteSubEu.bitField0.finished = true; + } + + if (layer->stereo.asByte == 0) { + attrs->stereo = chan->stereo; + } else { + attrs->stereo = layer->stereo; + } + note->playbackState.priority = chan->someOtherPriority; + } else { + attrs->stereo = layer->stereo; + note->playbackState.priority = 1; + } + + note->playbackState.prevParentLayer = note->playbackState.parentLayer; + note->playbackState.parentLayer = NO_LAYER; + if (target == ADSR_STATE_RELEASE) { + note->playbackState.adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; + note->playbackState.adsr.action.s.release = true; + note->playbackState.unk_04 = 2; + } else { + note->playbackState.unk_04 = 1; + note->playbackState.adsr.action.s.decay = true; + if (layer->adsr.releaseRate == 0) { + note->playbackState.adsr.fadeOutVel = gAudioContext.unk_3520[layer->channel->adsr.releaseRate]; + } else { + note->playbackState.adsr.fadeOutVel = gAudioContext.unk_3520[layer->adsr.releaseRate]; + } + note->playbackState.adsr.sustain = + ((f32)(s32)(layer->channel->adsr.sustain) * note->playbackState.adsr.current) / 256.0f; + } + } + + if (target == ADSR_STATE_DECAY) { + AudioPlayback_AudioListRemove(¬e->listItem); + AudioPlayback_AudioListPushFront(¬e->listItem.pool->decaying, ¬e->listItem); + } +} + +void AudioPlayback_SeqLayerNoteDecay(SequenceLayer* layer) { + AudioPlayback_SeqLayerDecayRelease(layer, ADSR_STATE_DECAY); +} + +void AudioPlayback_SeqLayerNoteRelease(SequenceLayer* layer) { + AudioPlayback_SeqLayerDecayRelease(layer, ADSR_STATE_RELEASE); +} + +s32 AudioPlayback_BuildSyntheticWave(Note* note, SequenceLayer* layer, s32 waveId) { + f32 freqScale; + f32 ratio; + u8 sampleCountIndex; + + if (waveId < 128) { + waveId = 128; + } + + freqScale = layer->freqScale; + if (layer->portamento.mode != 0 && 0.0f < layer->portamento.extent) { + freqScale *= (layer->portamento.extent + 1.0f); + } + if (freqScale < 0.99999f) { + sampleCountIndex = 0; + ratio = 1.0465f; + } else if (freqScale < 1.99999f) { + sampleCountIndex = 1; + ratio = 0.52325f; + } else if (freqScale < 3.99999f) { + sampleCountIndex = 2; + ratio = 0.26263f; + } else { + sampleCountIndex = 3; + ratio = 0.13081f; + } + layer->freqScale *= ratio; + note->playbackState.waveId = waveId; + note->playbackState.sampleCountIndex = sampleCountIndex; + + note->noteSubEu.sound.samples = &gWaveSamples[waveId - 128][sampleCountIndex * 64]; + + return sampleCountIndex; +} + +void AudioPlayback_InitSyntheticWave(Note* note, SequenceLayer* layer) { + s32 sampleCountIndex; + s32 waveSampleCountIndex; + s32 waveId = layer->instOrWave; + + if (waveId == 0xFF) { + waveId = layer->channel->instOrWave; + } + + sampleCountIndex = note->playbackState.sampleCountIndex; + waveSampleCountIndex = AudioPlayback_BuildSyntheticWave(note, layer, waveId); + + if (waveSampleCountIndex != sampleCountIndex) { + note->noteSubEu.unk_06 = waveSampleCountIndex * 4 + sampleCountIndex; + } +} + +void AudioPlayback_InitNoteList(AudioListItem* list) { + list->prev = list; + list->next = list; + list->u.count = 0; +} + +void AudioPlayback_InitNoteLists(NotePool* pool) { + AudioPlayback_InitNoteList(&pool->disabled); + AudioPlayback_InitNoteList(&pool->decaying); + AudioPlayback_InitNoteList(&pool->releasing); + AudioPlayback_InitNoteList(&pool->active); + pool->disabled.pool = pool; + pool->decaying.pool = pool; + pool->releasing.pool = pool; + pool->active.pool = pool; +} + +void AudioPlayback_InitNoteFreeList(void) { + s32 i; + + AudioPlayback_InitNoteLists(&gAudioContext.noteFreeLists); + for (i = 0; i < gAudioContext.numNotes; i++) { + gAudioContext.notes[i].listItem.u.value = &gAudioContext.notes[i]; + gAudioContext.notes[i].listItem.prev = NULL; + AudioSeq_AudioListPushBack(&gAudioContext.noteFreeLists.disabled, &gAudioContext.notes[i].listItem); + } +} + +void AudioPlayback_NotePoolClear(NotePool* pool) { + s32 i; + AudioListItem* source; + AudioListItem* cur; + AudioListItem* dest; + + for (i = 0; i < 4; i++) { + switch (i) { + case 0: + source = &pool->disabled; + dest = &gAudioContext.noteFreeLists.disabled; + break; + + case 1: + source = &pool->decaying; + dest = &gAudioContext.noteFreeLists.decaying; + break; + + case 2: + source = &pool->releasing; + dest = &gAudioContext.noteFreeLists.releasing; + break; + + case 3: + source = &pool->active; + dest = &gAudioContext.noteFreeLists.active; + break; + } + + for (;;) { + cur = source->next; + if (cur == source || cur == NULL) { + break; + } + AudioPlayback_AudioListRemove(cur); + AudioSeq_AudioListPushBack(dest, cur); + } + } +} + +void AudioPlayback_NotePoolFill(NotePool* pool, s32 count) { + s32 i; + s32 j; + Note* note; + AudioListItem* source; + AudioListItem* dest; + + AudioPlayback_NotePoolClear(pool); + + for (i = 0, j = 0; j < count; i++) { + if (i == 4) { + return; + } + + switch (i) { + case 0: + source = &gAudioContext.noteFreeLists.disabled; + dest = &pool->disabled; + break; + + case 1: + source = &gAudioContext.noteFreeLists.decaying; + dest = &pool->decaying; + break; + + case 2: + source = &gAudioContext.noteFreeLists.releasing; + dest = &pool->releasing; + break; + + case 3: + source = &gAudioContext.noteFreeLists.active; + dest = &pool->active; + break; + } + + while (j < count) { + note = AudioSeq_AudioListPopBack(source); + if (note == NULL) { + break; + } + AudioSeq_AudioListPushBack(dest, ¬e->listItem); + j++; + } + } +} + +void AudioPlayback_AudioListPushFront(AudioListItem* list, AudioListItem* item) { + // add 'item' to the front of the list given by 'list', if it's not in any list + if (item->prev == NULL) { + item->prev = list; + item->next = list->next; + list->next->prev = item; + list->next = item; + list->u.count++; + item->pool = list->pool; + } +} + +void AudioPlayback_AudioListRemove(AudioListItem* item) { + // remove 'item' from the list it's in, if any + if (item->prev != NULL) { + item->prev->next = item->next; + item->next->prev = item->prev; + item->prev = NULL; + } +} + +Note* AudioPlayback_FindNodeWithPrioLessThan(AudioListItem* list, s32 limit) { + AudioListItem* cur = list->next; + AudioListItem* best; + + if (cur == list) { + return NULL; + } + + for (best = cur; cur != list; cur = cur->next) { + if (((Note*)best->u.value)->playbackState.priority >= ((Note*)cur->u.value)->playbackState.priority) { + best = cur; + } + } + + if (best == NULL) { + return NULL; + } + + if (limit <= ((Note*)best->u.value)->playbackState.priority) { + return NULL; + } + + return best->u.value; +} + +void AudioPlayback_NoteInitForLayer(Note* note, SequenceLayer* layer) { + s32 pad[3]; + s16 instId; + SequenceChannel* channel = layer->channel; + NotePlaybackState* playbackState = ¬e->playbackState; + NoteSubEu* noteSubEu = ¬e->noteSubEu; + + playbackState->prevParentLayer = NO_LAYER; + playbackState->parentLayer = layer; + playbackState->priority = channel->notePriority; + layer->notePropertiesNeedInit = true; + layer->bit3 = true; + layer->note = note; + channel->noteUnused = note; + channel->layerUnused = layer; + layer->noteVelocity = 0.0f; + AudioPlayback_NoteInit(note); + instId = layer->instOrWave; + + if (instId == 0xFF) { + instId = channel->instOrWave; + } + noteSubEu->sound.soundFontSound = layer->sound; + + if (instId >= 0x80 && instId < 0xC0) { + noteSubEu->bitField1.isSyntheticWave = true; + } else { + noteSubEu->bitField1.isSyntheticWave = false; + } + + if (noteSubEu->bitField1.isSyntheticWave) { + AudioPlayback_BuildSyntheticWave(note, layer, instId); + } else if (channel->unk_DC == 1) { + playbackState->unk_84 = noteSubEu->sound.soundFontSound->sample->loop->start; + } else { + playbackState->unk_84 = channel->unk_DC; + if (playbackState->unk_84 >= noteSubEu->sound.soundFontSound->sample->loop->end) { + playbackState->unk_84 = 0; + } + } + + playbackState->fontId = channel->fontId; + playbackState->stereoHeadsetEffects = channel->stereoHeadsetEffects; + noteSubEu->bitField1.reverbIndex = channel->reverbIndex & 3; +} + +void func_801963E8(Note* note, SequenceLayer* layer) { + // similar to Audio_NoteReleaseAndTakeOwnership, hard to say what the difference is + AudioPlayback_SeqLayerNoteRelease(note->playbackState.parentLayer); + note->playbackState.wantedParentLayer = layer; +} + +void AudioPlayback_NoteReleaseAndTakeOwnership(Note* note, SequenceLayer* layer) { + note->playbackState.wantedParentLayer = layer; + note->playbackState.priority = layer->channel->notePriority; + + note->playbackState.adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; + note->playbackState.adsr.action.s.release = true; +} + +Note* AudioPlayback_AllocNoteFromDisabled(NotePool* pool, SequenceLayer* layer) { + Note* note = AudioSeq_AudioListPopBack(&pool->disabled); + if (note != NULL) { + AudioPlayback_NoteInitForLayer(note, layer); + AudioPlayback_AudioListPushFront(&pool->active, ¬e->listItem); + } + return note; +} + +Note* AudioPlayback_AllocNoteFromDecaying(NotePool* pool, SequenceLayer* layer) { + Note* note = AudioPlayback_FindNodeWithPrioLessThan(&pool->decaying, layer->channel->notePriority); + + if (note != NULL) { + AudioPlayback_NoteReleaseAndTakeOwnership(note, layer); + AudioPlayback_AudioListRemove(¬e->listItem); + AudioSeq_AudioListPushBack(&pool->releasing, ¬e->listItem); + } + return note; +} + +Note* AudioPlayback_AllocNoteFromActive(NotePool* pool, SequenceLayer* layer) { + Note* rNote; + Note* aNote; + s32 rPriority; + s32 aPriority; + + rPriority = aPriority = 0x10; + rNote = AudioPlayback_FindNodeWithPrioLessThan(&pool->releasing, layer->channel->notePriority); + + if (rNote != NULL) { + rPriority = rNote->playbackState.priority; + } + + aNote = AudioPlayback_FindNodeWithPrioLessThan(&pool->active, layer->channel->notePriority); + + if (aNote != NULL) { + aPriority = aNote->playbackState.priority; + } + + if (rNote == NULL && aNote == NULL) { + return NULL; + } + + if (aPriority < rPriority) { + AudioPlayback_AudioListRemove(&aNote->listItem); + func_801963E8(aNote, layer); + AudioSeq_AudioListPushBack(&pool->releasing, &aNote->listItem); + aNote->playbackState.priority = layer->channel->notePriority; + return aNote; + } + rNote->playbackState.wantedParentLayer = layer; + rNote->playbackState.priority = layer->channel->notePriority; + return rNote; +} + +Note* AudioPlayback_AllocNote(SequenceLayer* layer) { + Note* note; + u32 policy = layer->channel->noteAllocPolicy; + + if (policy & 1) { + note = layer->note; + if (note != NULL && note->playbackState.prevParentLayer == layer && + note->playbackState.wantedParentLayer == NO_LAYER) { + AudioPlayback_NoteReleaseAndTakeOwnership(note, layer); + AudioPlayback_AudioListRemove(¬e->listItem); + AudioSeq_AudioListPushBack(¬e->listItem.pool->releasing, ¬e->listItem); + return note; + } + } + + if (policy & 2) { + if (!(note = AudioPlayback_AllocNoteFromDisabled(&layer->channel->notePool, layer)) && + !(note = AudioPlayback_AllocNoteFromDecaying(&layer->channel->notePool, layer)) && + !(note = AudioPlayback_AllocNoteFromActive(&layer->channel->notePool, layer))) { + goto null_return; + } + return note; + } + + if (policy & 4) { + if (!(note = AudioPlayback_AllocNoteFromDisabled(&layer->channel->notePool, layer)) && + !(note = AudioPlayback_AllocNoteFromDisabled(&layer->channel->seqPlayer->notePool, layer)) && + !(note = AudioPlayback_AllocNoteFromDecaying(&layer->channel->notePool, layer)) && + !(note = AudioPlayback_AllocNoteFromDecaying(&layer->channel->seqPlayer->notePool, layer)) && + !(note = AudioPlayback_AllocNoteFromActive(&layer->channel->notePool, layer)) && + !(note = AudioPlayback_AllocNoteFromActive(&layer->channel->seqPlayer->notePool, layer))) { + goto null_return; + } + return note; + } + + if (policy & 8) { + if (!(note = AudioPlayback_AllocNoteFromDisabled(&gAudioContext.noteFreeLists, layer)) && + !(note = AudioPlayback_AllocNoteFromDecaying(&gAudioContext.noteFreeLists, layer)) && + !(note = AudioPlayback_AllocNoteFromActive(&gAudioContext.noteFreeLists, layer))) { + goto null_return; + } + return note; + } + + if (!(note = AudioPlayback_AllocNoteFromDisabled(&layer->channel->notePool, layer)) && + !(note = AudioPlayback_AllocNoteFromDisabled(&layer->channel->seqPlayer->notePool, layer)) && + !(note = AudioPlayback_AllocNoteFromDisabled(&gAudioContext.noteFreeLists, layer)) && + !(note = AudioPlayback_AllocNoteFromDecaying(&layer->channel->notePool, layer)) && + !(note = AudioPlayback_AllocNoteFromDecaying(&layer->channel->seqPlayer->notePool, layer)) && + !(note = AudioPlayback_AllocNoteFromDecaying(&gAudioContext.noteFreeLists, layer)) && + !(note = AudioPlayback_AllocNoteFromActive(&layer->channel->notePool, layer)) && + !(note = AudioPlayback_AllocNoteFromActive(&layer->channel->seqPlayer->notePool, layer)) && + !(note = AudioPlayback_AllocNoteFromActive(&gAudioContext.noteFreeLists, layer))) { + goto null_return; + } + return note; + +null_return: + layer->bit3 = true; + return NULL; +} + +void AudioPlayback_NoteInitAll(void) { + Note* note; + s32 i; + + for (i = 0; i < gAudioContext.numNotes; i++) { + note = &gAudioContext.notes[i]; + note->noteSubEu = gZeroNoteSub; + note->playbackState.priority = 0; + note->playbackState.unk_04 = 0; + note->playbackState.parentLayer = NO_LAYER; + note->playbackState.wantedParentLayer = NO_LAYER; + note->playbackState.prevParentLayer = NO_LAYER; + note->playbackState.waveId = 0; + note->playbackState.attributes.velocity = 0.0f; + note->playbackState.adsrVolScaleUnused = 0; + note->playbackState.adsr.action.asByte = 0; + note->playbackState.vibratoState.active = false; + note->playbackState.portamento.cur = 0; + note->playbackState.portamento.speed = 0; + note->playbackState.stereoHeadsetEffects = false; + note->playbackState.unk_84 = 0; + note->synthesisState.synthesisBuffers = AudioHeap_AllocDmaMemory(&gAudioContext.notesAndBuffersPool, 0x2E0); + note->playbackState.attributes.filterBuf = AudioHeap_AllocDmaMemory(&gAudioContext.notesAndBuffersPool, 0x10); + } +} diff --git a/src/code/audio/audio_seqplayer.c b/src/code/audio/audio_seqplayer.c index ec4375796..56d8ac951 100644 --- a/src/code/audio/audio_seqplayer.c +++ b/src/code/audio/audio_seqplayer.c @@ -12,7 +12,7 @@ #pragma GLOBAL_ASM("asm/non_matchings/code/audio_seqplayer/func_80197A54.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_seqplayer/func_80197AA4.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/audio_seqplayer/AudioSeq_SequenceChannelDisable.s") #pragma GLOBAL_ASM("asm/non_matchings/code/audio_seqplayer/func_80197B14.s") @@ -24,9 +24,9 @@ #pragma GLOBAL_ASM("asm/non_matchings/code/audio_seqplayer/AudioSeq_SequencePlayerDisable.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_seqplayer/func_80197E08.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/audio_seqplayer/AudioSeq_AudioListPushBack.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/audio_seqplayer/func_80197E48.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/audio_seqplayer/AudioSeq_AudioListPopBack.s") #pragma GLOBAL_ASM("asm/non_matchings/code/audio_seqplayer/func_80197E88.s") diff --git a/src/code/graph.c b/src/code/graph.c index 8059d1f63..04ab72057 100644 --- a/src/code/graph.c +++ b/src/code/graph.c @@ -1,4 +1,3 @@ -#include "prevent_bss_reordering.h" #include "global.h" #include "system_malloc.h" #include "overlays/gamestates/ovl_daytelop/z_daytelop.h" diff --git a/src/code/sys_ucode.c b/src/code/sys_ucode.c index 9bde9e6df..f9433eab2 100644 --- a/src/code/sys_ucode.c +++ b/src/code/sys_ucode.c @@ -7,8 +7,11 @@ extern u64 rspbootTextStart[]; extern u64 rspbootTextEnd[]; -u64* initialgspUcodeText = gspF3DEX2_NoN_fifoTextStart; -u64* initialgspUcodeData = gspF3DEX2_NoN_fifoDataStart; +extern u64 gspF3DZEX2_NoN_PosLight_fifoTextStart[]; +extern u64 gspF3DZEX2_NoN_PosLight_fifoDataStart[]; + +u64* initialgspUcodeText = gspF3DZEX2_NoN_PosLight_fifoTextStart; +u64* initialgspUcodeData = gspF3DZEX2_NoN_PosLight_fifoDataStart; u64* SysUcode_GetUCodeBoot(void) { return rspbootTextStart; diff --git a/src/code/z_actor.c b/src/code/z_actor.c index 998063534..f41fb43df 100644 --- a/src/code/z_actor.c +++ b/src/code/z_actor.c @@ -320,13 +320,12 @@ void func_800B4AEC(GlobalContext* globalCtx, Actor* actor, f32 y) { void func_800B4B50(Actor* actor, Lights* mapper, GlobalContext* globalCtx) { f32 spEC; f32 temp_f12; - f32 temp_f20; f32 shadowScaleZ; f32 temp_f22; f32 temp_f24; f32 temp_f8; - MtxF sp94; s32 lightNum; + MtxF sp94; s32 numLights; s8 phi_v1; u8 temp_v0; @@ -342,7 +341,8 @@ void func_800B4B50(Actor* actor, Lights* mapper, GlobalContext* globalCtx) { spEC = actor->world.pos.y - actor->floorHeight; if (spEC > 20.0f) { - temp_f20 = actor->shape.shadowScale; + f32 temp_f20 = actor->shape.shadowScale; + temp_v0 = actor->shape.shadowAlpha; actor->shape.shadowScale *= 0.3f; temp_f12 = (spEC - 20.0f) * 0.02f; @@ -350,7 +350,6 @@ void func_800B4B50(Actor* actor, Lights* mapper, GlobalContext* globalCtx) { ActorShadow_DrawCircle(actor, mapper, globalCtx); actor->shape.shadowScale = temp_f20; actor->shape.shadowAlpha = temp_v0; - dummy_label_111649:; } else if (spEC >= -1.0f) { numLights = mapper->numLights - 2; @@ -377,8 +376,8 @@ void func_800B4B50(Actor* actor, Lights* mapper, GlobalContext* globalCtx) { for (j = 0; j < 2; j++, phi_s0++) { if (phi_s0->l.dir[1] > 0) { - lightNum = (ABS_ALT(phi_s0->l.dir[1]) * (phi_s0->l.col[0] + phi_s0->l.col[1] + phi_s0->l.col[2])) - - (lightNumMax * ((void)0, 8)); + lightNum = ((phi_s0->l.col[0] + phi_s0->l.col[1] + phi_s0->l.col[2]) * ABS_ALT(phi_s0->l.dir[1])) - + (8 * lightNumMax); if (lightNum > 0) { ActorShadow_DrawFoot(globalCtx, phi_s0, &sp94, lightNum, temp_f22, temp_f24, shadowScaleZ); } diff --git a/src/code/z_bgcheck.c b/src/code/z_bgcheck.c index 850d5234b..7fa1b755b 100644 --- a/src/code/z_bgcheck.c +++ b/src/code/z_bgcheck.c @@ -4321,17 +4321,18 @@ s32 SurfaceType_IsIgnoredByProjectiles(CollisionContext* colCtx, CollisionPoly* } /** - * CollisionPoly is conveyor enabled - * Returns true if `poly` is a conveyor surface, else false + * SurfaceType Get Conveyor Surface Type + * Return type 0 (CONVEYOR_WATER) if 'poly' is a surface that will only move player underwater + * Return type 1 (CONVEYOR_FLOOR) if `poly` is a surface that must be stood on to move player */ -s32 SurfaceType_IsConveyor(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { +s32 SurfaceType_GetConveyorType(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { u32 flags; if (BgCheck_GetCollisionHeader(colCtx, bgId) == NULL) { - return true; + return CONVEYOR_FLOOR; } if (poly == NULL) { - return false; + return CONVEYOR_WATER; } flags = poly->flags_vIB & 0x2000; return !!flags; diff --git a/src/code/z_eff_blure.c b/src/code/z_eff_blure.c index 887534366..b17799aff 100644 --- a/src/code/z_eff_blure.c +++ b/src/code/z_eff_blure.c @@ -1,4 +1,5 @@ #include "global.h" +#include "objects/gameplay_keep/gameplay_keep.h" void EffectBlure_AddVertex(EffectBlure* this, Vec3f* p1, Vec3f* p2) { EffectBlureElement* elem; @@ -720,8 +721,8 @@ void EffectBlure_SetupSimpleAlt(GraphicsContext* gfxCtx, EffectBlure* this, Vtx* gDPSetTextureLUT(POLY_XLU_DISP++, G_TT_NONE); gSPTexture(POLY_XLU_DISP++, 0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_ON); - gDPLoadTextureBlock(POLY_XLU_DISP++, D_04014570, G_IM_FMT_I, G_IM_SIZ_8b, 64, 32, 0, G_TX_NOMIRROR | G_TX_CLAMP, - G_TX_NOMIRROR | G_TX_WRAP, 6, 5, G_TX_NOLOD, G_TX_NOLOD); + gDPLoadTextureBlock(POLY_XLU_DISP++, gameplay_keep_Tex_014570, G_IM_FMT_I, G_IM_SIZ_8b, 64, 32, 0, + G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_WRAP, 6, 5, G_TX_NOLOD, G_TX_NOLOD); gDPSetCombineLERP(POLY_XLU_DISP++, TEXEL0, PRIMITIVE, PRIM_LOD_FRAC, TEXEL0, TEXEL0, 0, PRIMITIVE, 0, PRIMITIVE, ENVIRONMENT, COMBINED, ENVIRONMENT, 0, 0, 0, COMBINED); diff --git a/src/code/z_eff_shield_particle.c b/src/code/z_eff_shield_particle.c index 05669d63a..112f7fe73 100644 --- a/src/code/z_eff_shield_particle.c +++ b/src/code/z_eff_shield_particle.c @@ -2,6 +2,7 @@ #include "vt.h" #include "assets/code/eff_shield_particle/eff_shield_particle.c" +#include "objects/gameplay_keep/gameplay_keep.h" void EffectShieldParticle_Init(void* thisx, void* initParamsx) { EffectShieldParticle* this = (EffectShieldParticle*)thisx; @@ -154,8 +155,8 @@ void EffectShieldParticle_Draw(void* thisx, GraphicsContext* gfxCtx) { gDPPipeSync(POLY_XLU_DISP++); gSPTexture(POLY_XLU_DISP++, 0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_ON); - gDPLoadTextureBlock(POLY_XLU_DISP++, D_04054F20, G_IM_FMT_I, G_IM_SIZ_8b, 32, 32, 0, G_TX_NOMIRROR | G_TX_WRAP, - G_TX_NOMIRROR | G_TX_WRAP, 5, 5, G_TX_NOLOD, G_TX_NOLOD); + gDPLoadTextureBlock(POLY_XLU_DISP++, gameplay_keep_Tex_054F20, G_IM_FMT_I, G_IM_SIZ_8b, 32, 32, 0, + G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, 5, 5, G_TX_NOLOD, G_TX_NOLOD); gDPSetCombineLERP(POLY_XLU_DISP++, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, PRIMITIVE, 0, TEXEL0, 0, 0, 0, 0, COMBINED, 0, 0, 0, COMBINED); diff --git a/src/code/z_eff_spark.c b/src/code/z_eff_spark.c index 27ed1443d..697c55398 100644 --- a/src/code/z_eff_spark.c +++ b/src/code/z_eff_spark.c @@ -1,4 +1,5 @@ #include "global.h" +#include "objects/gameplay_keep/gameplay_keep.h" void EffectSpark_Init(void* thisx, void* initParamsx) { EffectSpark* this = (EffectSpark*)thisx; @@ -152,8 +153,8 @@ void EffectSpark_Draw(void* thisx, GraphicsContext* gfxCtx) { gDPPipeSync(POLY_XLU_DISP++); gSPTexture(POLY_XLU_DISP++, 0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_ON); - gDPLoadTextureBlock(POLY_XLU_DISP++, D_04054F20, G_IM_FMT_I, G_IM_SIZ_8b, 32, 32, 0, G_TX_NOMIRROR | G_TX_WRAP, - G_TX_NOMIRROR | G_TX_WRAP, 5, 5, G_TX_NOLOD, G_TX_NOLOD); + gDPLoadTextureBlock(POLY_XLU_DISP++, gameplay_keep_Tex_054F20, G_IM_FMT_I, G_IM_SIZ_8b, 32, 32, 0, + G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, 5, 5, G_TX_NOLOD, G_TX_NOLOD); gDPSetCombineMode(POLY_XLU_DISP++, G_CC_SHADEDECALA, G_CC_PASS2); gDPSetRenderMode(POLY_XLU_DISP++, G_RM_PASS, G_RM_ZB_CLD_SURF2); diff --git a/src/code/z_eff_tire_mark.c b/src/code/z_eff_tire_mark.c index 517ee5251..532e8e2fb 100644 --- a/src/code/z_eff_tire_mark.c +++ b/src/code/z_eff_tire_mark.c @@ -1,4 +1,5 @@ #include "global.h" +#include "objects/gameplay_keep/gameplay_keep.h" void func_800AE930(CollisionContext* colCtx, EffectTireMark* this, Vec3f* pos, f32 arg3, s16 arg4, CollisionPoly* colPoly, s32 arg6) { @@ -233,7 +234,7 @@ void EffectTireMark_Draw(void* thisx, GraphicsContext* gfxCtx) { POLY_OPA_DISP = Gfx_CallSetupDL(POLY_OPA_DISP++, 0x2C); gDPSetRenderMode(POLY_OPA_DISP++, G_RM_PASS, G_RM_ZB_CLD_SURF2); - gDPLoadTextureBlock(POLY_OPA_DISP++, D_04014570, G_IM_FMT_I, G_IM_SIZ_8b, 64, 32, 0, + gDPLoadTextureBlock(POLY_OPA_DISP++, gameplay_keep_Tex_014570, G_IM_FMT_I, G_IM_SIZ_8b, 64, 32, 0, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_WRAP, 6, 5, G_TX_NOLOD, G_TX_NOLOD); gDPSetCombineLERP(POLY_OPA_DISP++, 0, 0, 0, PRIMITIVE, TEXEL0, 0, PRIMITIVE, 0, 0, 0, 0, COMBINED, 0, 0, 0, @@ -255,11 +256,12 @@ void EffectTireMark_Draw(void* thisx, GraphicsContext* gfxCtx) { if ((elem - 1)->flags & 1) { if (!(elem->flags & 1)) { + s32 requiredScopeTemp; + vtx[i * 2 + 0].v.tc[0] = 0; vtx[i * 2 + 0].v.tc[1] = 0; vtx[i * 2 + 1].v.tc[0] = 0; vtx[i * 2 + 1].v.tc[1] = 1024; - dummy_label:; } else if ((i >= 2) && !((elem - 2)->flags & 1)) { vtx[i * 2 - 2].v.tc[0] = 0; vtx[i * 2 - 2].v.tc[1] = 0; diff --git a/src/code/z_en_item00.c b/src/code/z_en_item00.c index 3c174215f..7100aec71 100644 --- a/src/code/z_en_item00.c +++ b/src/code/z_en_item00.c @@ -1,4 +1,6 @@ #include "global.h" +#include "objects/gameplay_keep/gameplay_keep.h" +#include "objects/object_gi_hearts/object_gi_hearts.h" #define FLAGS 0x00000000 @@ -693,12 +695,12 @@ void EnItem00_Draw(Actor* thisx, GlobalContext* globalCtx) { } } -UNK_PTR D_801ADF30[5] = { - &D_04061FC0, // Green rupee - &D_04061FE0, // Blue rupee - &D_04062000, // Red rupee - &D_04062040, // Orange rupee - &D_04062020 // Purple rupee +TexturePtr D_801ADF30[] = { + gameplay_keep_Tex_061FC0, // Green rupee + gameplay_keep_Tex_061FE0, // Blue rupee + gameplay_keep_Tex_062000, // Red rupee + gameplay_keep_Tex_062040, // Orange rupee + gameplay_keep_Tex_062020 // Purple rupee }; void EnItem00_DrawRupee(EnItem00* this, GlobalContext* globalCtx) { @@ -720,24 +722,24 @@ void EnItem00_DrawRupee(EnItem00* this, GlobalContext* globalCtx) { gSPSegment(POLY_OPA_DISP++, 0x08, Lib_SegmentedToVirtual(D_801ADF30[iconNb])); - gSPDisplayList(POLY_OPA_DISP++, &D_040622C0); // TODO symbol + gSPDisplayList(POLY_OPA_DISP++, gameplay_keep_DL_0622C0); // TODO symbol CLOSE_DISPS(globalCtx->state.gfxCtx); } -UNK_PTR D_801ADF44[12] = { - &D_0405E6F0, // Heart (Not used) - &D_0405CEF0, // Bombs (A), Bombs (0) - &D_0405BEF0, // Arrows (10) - &D_0405B6F0, // Arrows (30) - &D_0405C6F0, // Arrows (40), Arrows (50) - &D_0405CEF0, // Bombs (B) - &D_040607C0, // Nuts (1), Nuts (10) - &D_04060FC0, // Sticks (1) - &D_040617C0, // Magic (Large) - &D_0405FFC0, // Magic (Small) +TexturePtr D_801ADF44[12] = { + gameplay_keep_Tex_05E6F0, // Heart (Not used) + gameplay_keep_Tex_05CEF0, // Bombs (A), Bombs (0) + gameplay_keep_Tex_05BEF0, // Arrows (10) + gameplay_keep_Tex_05B6F0, // Arrows (30) + gameplay_keep_Tex_05C6F0, // Arrows (40), Arrows (50) + gameplay_keep_Tex_05CEF0, // Bombs (B) + gameplay_keep_Tex_0607C0, // Nuts (1), Nuts (10) + gameplay_keep_Tex_060FC0, // Sticks (1) + gameplay_keep_Tex_0617C0, // Magic (Large) + gameplay_keep_Tex_05FFC0, // Magic (Small) NULL, - &D_0405F7C0 // Small Key + gameplay_keep_Tex_05F7C0 // Small Key }; void EnItem00_DrawSprite(EnItem00* this, GlobalContext* globalCtx) { @@ -764,14 +766,11 @@ void EnItem00_DrawSprite(EnItem00* this, GlobalContext* globalCtx) { gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx), G_MTX_MODELVIEW | G_MTX_LOAD); - gSPDisplayList(POLY_OPA_DISP++, D_0405F6F0); + gSPDisplayList(POLY_OPA_DISP++, gameplay_keep_DL_05F6F0); CLOSE_DISPS(globalCtx->state.gfxCtx); } -extern Gfx D_06001290[]; -extern Gfx D_06001470[]; - void EnItem00_DrawHeartContainer(EnItem00* actor, GlobalContext* globalCtx) { s32 pad; s32 pad2; @@ -784,8 +783,8 @@ void EnItem00_DrawHeartContainer(EnItem00* actor, GlobalContext* globalCtx) { gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx), G_MTX_MODELVIEW | G_MTX_LOAD); - gSPDisplayList(POLY_XLU_DISP++, D_06001290); - gSPDisplayList(POLY_XLU_DISP++, D_06001470); + gSPDisplayList(POLY_XLU_DISP++, object_gi_hearts_DL_001290); + gSPDisplayList(POLY_XLU_DISP++, object_gi_hearts_DL_001470); CLOSE_DISPS(globalCtx->state.gfxCtx); } @@ -801,7 +800,7 @@ void EnItem00_DrawHeartPiece(EnItem00* this, GlobalContext* globalCtx) { gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx), G_MTX_MODELVIEW | G_MTX_LOAD); - gSPDisplayList(POLY_XLU_DISP++, D_0405AAB0); + gSPDisplayList(POLY_XLU_DISP++, gameplay_keep_DL_05AAB0); CLOSE_DISPS(globalCtx->state.gfxCtx); } diff --git a/src/code/z_jpeg.c b/src/code/z_jpeg.c index c611ab1f8..7b9254ccd 100644 --- a/src/code/z_jpeg.c +++ b/src/code/z_jpeg.c @@ -16,6 +16,9 @@ #define MARKER_COM 0xFE #define MARKER_EOI 0xD9 +extern u64 njpgdspMainTextStart[]; +extern u64 njpgdspMainDataStart[]; + /** * Configures and schedules a JPEG decoder task and waits for it to finish. */ @@ -25,9 +28,9 @@ void Jpeg_ScheduleDecoderTask(JpegContext* jpegCtx) { 0, // flags NULL, // ucode_boot 0, // ucode_boot_size - gJpegUCode, // ucode + njpgdspMainTextStart, // ucode 0x1000, // ucode_size - gJpegUCodeData, // ucode_data + njpgdspMainDataStart, // ucode_data 0x800, // ucode_data_size NULL, // dram_stack 0, // dram_stack_size diff --git a/src/code/z_lights.c b/src/code/z_lights.c index fae6af51e..858a7186e 100644 --- a/src/code/z_lights.c +++ b/src/code/z_lights.c @@ -1,4 +1,5 @@ #include "global.h" +#include "objects/gameplay_keep/gameplay_keep.h" void Lights_PointSetInfo(LightInfo* info, s16 x, s16 y, s16 z, u8 r, u8 g, u8 b, s16 radius, s32 type) { info->type = type; @@ -418,7 +419,7 @@ void Lights_DrawGlow(GlobalContext* globalCtx) { gDPSetCombineLERP(dl++, 0, 0, 0, PRIMITIVE, TEXEL0, 0, PRIMITIVE, 0, 0, 0, 0, PRIMITIVE, TEXEL0, 0, PRIMITIVE, 0); - gSPDisplayList(dl++, D_04029CB0); + gSPDisplayList(dl++, gameplay_keep_DL_029CB0); do { if (light->info->type == LIGHT_POINT_GLOW) { @@ -434,7 +435,7 @@ void Lights_DrawGlow(GlobalContext* globalCtx) { gSPMatrix(dl++, Matrix_NewMtx(globalCtx->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - gSPDisplayList(dl++, D_04029CF0); + gSPDisplayList(dl++, gameplay_keep_DL_029CF0); } } diff --git a/src/code/z_quake.c b/src/code/z_quake.c index e699ff086..d38746bf4 100644 --- a/src/code/z_quake.c +++ b/src/code/z_quake.c @@ -1,7 +1,7 @@ #include "global.h" QuakeRequest sQuakeRequest[4]; -Quake2Context sQuake2Context; +DistortionContext sDistortionContext; static s16 sIsQuakeInitialized = true; static s16 sQuakeRequestCount = 0; @@ -382,58 +382,62 @@ s16 Quake_Calc(Camera* camera, QuakeCamCalc* camData) { return ret; } -void Quake2_Init(GlobalContext* globalCtx) { - sQuake2Context.globalCtx = globalCtx; - View_ClearQuake(&globalCtx->view); - sQuake2Context.type = 0; - sQuake2Context.countdown = 0; - sQuake2Context.state = QUAKE2_INACTIVE; +void Distortion_Init(GlobalContext* globalCtx) { + sDistortionContext.globalCtx = globalCtx; + View_ClearDistortion(&globalCtx->view); + sDistortionContext.type = 0; + sDistortionContext.countdown = 0; + sDistortionContext.state = DISTORTION_INACTIVE; } -void Quake2_SetCountdown(s16 countdown) { - sQuake2Context.countdown = countdown; - sQuake2Context.state = QUAKE2_SETUP; +void Distortion_SetCountdown(s16 countdown) { + sDistortionContext.countdown = countdown; + sDistortionContext.state = DISTORTION_SETUP; } -s16 Quake2_GetCountdown(void) { - return sQuake2Context.countdown; +s16 Distortion_GetCountdown(void) { + return sDistortionContext.countdown; } -s16 Quake2_GetType(void) { - return sQuake2Context.type; +s16 Distortion_GetType(void) { + return sDistortionContext.type; } -void Quake2_SetType(s32 type) { - if (sQuake2Context.type < type) { - sQuake2Context.type = type; +void Distortion_SetType(s32 type) { + if (sDistortionContext.type < type) { + sDistortionContext.type = type; } } -void Quake2_ClearType(s32 type) { - if (sQuake2Context.type == type) { - sQuake2Context.type = 0; +void Distortion_ClearType(s32 type) { + if (sDistortionContext.type == type) { + sDistortionContext.type = 0; } } -s32 Quake2_GetFloorQuake(Player* player) { - if (!SurfaceType_IsConveyor(&sQuake2Context.globalCtx->colCtx, player->actor.floorPoly, player->actor.floorBgId)) { - return SurfaceType_GetConveyorSpeed(&sQuake2Context.globalCtx->colCtx, player->actor.floorPoly, +/** + * Checks that the bg surface is an underwater conveyor type and if so, returns the conveyor speed + */ +s32 Distortion_GetUnderwaterCurrentSpeed(Player* player) { + if (SurfaceType_GetConveyorType(&sDistortionContext.globalCtx->colCtx, player->actor.floorPoly, + player->actor.floorBgId) == CONVEYOR_WATER) { + return SurfaceType_GetConveyorSpeed(&sDistortionContext.globalCtx->colCtx, player->actor.floorPoly, player->actor.floorBgId); } return 0; } -void Quake2_Update(void) { - static s16 angle1 = 0x3F0; - static s16 angle2 = 0x156; +void Distortion_Update(void) { + static s16 depthPhase = 0x3F0; + static s16 screenPlanePhase = 0x156; static s16 countdownMax = 1; f32 xyScaleFactor; f32 zScaleFactor; f32 speedScaleFactor; f32 countdownRatio; f32 waterYScaleFactor; - f32 angle1Speed; - f32 angle2Speed; + f32 depthPhaseStep; + f32 screenPlanePhaseStep; f32 rotX; f32 rotY; f32 rotZ; @@ -442,181 +446,210 @@ void Quake2_Update(void) { f32 zScale; f32 speed; Player* player; - GlobalContext* globalCtx = sQuake2Context.globalCtx; + GlobalContext* globalCtx = sDistortionContext.globalCtx; PosRot playerPosRot; Camera* camera = GET_ACTIVE_CAM(globalCtx); f32 speedRatio = CLAMP_MAX(camera->speedRatio, 1.0f); - if (sQuake2Context.type != 0) { - if (sQuake2Context.type & 0x800) { - sQuake2Context.countdown = 2; - angle1 = 0x3F0; - angle2 = 0x156; - angle1Speed = 0.0f; - angle2Speed = 170.0f; + if (sDistortionContext.type != 0) { + if (sDistortionContext.type & 0x800) { + sDistortionContext.countdown = 2; + depthPhase = 0x3F0; + screenPlanePhase = 0x156; + + depthPhaseStep = 0.0f; + screenPlanePhaseStep = 170.0f; + rotX = 0.0f; rotY = 0.0f; rotZ = 0.0f; + xScale = -0.01f; yScale = 0.01f; zScale = 0.0f; + speed = 0.6f; - xyScaleFactor = zScaleFactor = sQuake2Context.countdown / 60.0f; + xyScaleFactor = zScaleFactor = sDistortionContext.countdown / 60.0f; speedScaleFactor = 1.0f; - } else if (sQuake2Context.type & 0x400) { - if (sQuake2Context.state == QUAKE2_SETUP) { - countdownMax = sQuake2Context.countdown; - angle1 = 0x3F0; - angle2 = 0x156; + } else if (sDistortionContext.type & 0x400) { + if (sDistortionContext.state == DISTORTION_SETUP) { + countdownMax = sDistortionContext.countdown; + depthPhase = 0x3F0; + screenPlanePhase = 0x156; } - angle1Speed = 0.0f; - angle2Speed = 50.0f / countdownMax; + depthPhaseStep = 0.0f; + screenPlanePhaseStep = 50.0f / countdownMax; + rotX = 0.0f; rotY = 0.0f; rotZ = 0.0f; + xScale = 0.01f; yScale = 100.0f; zScale = 0.0f; + speed = 0.4f; - xyScaleFactor = zScaleFactor = ((f32)countdownMax - sQuake2Context.countdown) / (f32)countdownMax; + xyScaleFactor = zScaleFactor = ((f32)countdownMax - sDistortionContext.countdown) / (f32)countdownMax; speedScaleFactor = 0.5f; - } else if (sQuake2Context.type & 0x200) { - if (sQuake2Context.state == QUAKE2_SETUP) { - countdownMax = sQuake2Context.countdown; - angle1 = 0x1FC; - angle2 = 0x156; + } else if (sDistortionContext.type & 0x200) { + if (sDistortionContext.state == DISTORTION_SETUP) { + countdownMax = sDistortionContext.countdown; + depthPhase = 0x1FC; + screenPlanePhase = 0x156; } - angle1Speed = -5.0f; - angle2Speed = 5.0f; + depthPhaseStep = -5.0f; + screenPlanePhaseStep = 5.0f; + rotX = 0.0f; rotY = 0.0f; rotZ = 2.0f; + xScale = 0.3f; yScale = 0.3f; zScale = 0.0f; + speed = 0.1f; - xyScaleFactor = zScaleFactor = ((f32)countdownMax - sQuake2Context.countdown) / (f32)countdownMax; + xyScaleFactor = zScaleFactor = ((f32)countdownMax - sDistortionContext.countdown) / (f32)countdownMax; speedScaleFactor = 1.0f; - } else if (sQuake2Context.type & 0x100) { - if (sQuake2Context.state == QUAKE2_SETUP) { - countdownMax = sQuake2Context.countdown; - angle1 = 0x2710; - angle2 = 0x3E8; + } else if (sDistortionContext.type & 0x100) { + if (sDistortionContext.state == DISTORTION_SETUP) { + countdownMax = sDistortionContext.countdown; + depthPhase = 0x2710; + screenPlanePhase = 0x3E8; } - angle1Speed = 0.0f; - angle2Speed = 150.0f; + depthPhaseStep = 0.0f; + screenPlanePhaseStep = 150.0f; + rotX = 0; rotY = 0; rotZ = 0.2f; + xScale = 0.025f; yScale = 0.02f; zScale = 0.01f; + speed = 1.5f; - if (sQuake2Context.countdown < 5) { - xyScaleFactor = zScaleFactor = ((f32)countdownMax - sQuake2Context.countdown) / (f32)countdownMax; + if (sDistortionContext.countdown < 5) { + xyScaleFactor = zScaleFactor = ((f32)countdownMax - sDistortionContext.countdown) / (f32)countdownMax; } else { xyScaleFactor = zScaleFactor = 0.0f; } speedScaleFactor = 1.0f; - } else if (sQuake2Context.type & 0x80) { - if (sQuake2Context.state == QUAKE2_SETUP) { - countdownMax = sQuake2Context.countdown; - angle1 = 0x4B0; - angle2 = 0x7D0; + } else if (sDistortionContext.type & 0x80) { + if (sDistortionContext.state == DISTORTION_SETUP) { + countdownMax = sDistortionContext.countdown; + depthPhase = 0x4B0; + screenPlanePhase = 0x7D0; } - angle1Speed = 0.0f; - angle2Speed = 150.0f; + depthPhaseStep = 0.0f; + screenPlanePhaseStep = 150.0f; + rotX = 0; rotY = 0; rotZ = 0; + xScale = 0.03f; yScale = 0.02f; zScale = 0.01f; + speed = 1.5f; - xyScaleFactor = zScaleFactor = sQuake2Context.countdown / (f32)countdownMax; + xyScaleFactor = zScaleFactor = sDistortionContext.countdown / (f32)countdownMax; speedScaleFactor = 1.0f; - } else if (sQuake2Context.type & 0x40) { - if (sQuake2Context.state == QUAKE2_SETUP) { - countdownMax = sQuake2Context.countdown; - angle1 = 0x9C4; - angle2 = 0xBB8; + } else if (sDistortionContext.type & 0x40) { + if (sDistortionContext.state == DISTORTION_SETUP) { + countdownMax = sDistortionContext.countdown; + depthPhase = 0x9C4; + screenPlanePhase = 0xBB8; } - angle1Speed = 0.0f; - angle2Speed = 150.0f; + depthPhaseStep = 0.0f; + screenPlanePhaseStep = 150.0f; + rotX = 0; rotY = 0; rotZ = 0; + xScale = 0.03f; yScale = 0.03f; zScale = 0.01f; + speed = 1.3f; - if (sQuake2Context.countdown < 4) { - xyScaleFactor = zScaleFactor = sQuake2Context.countdown / (f32)countdownMax; + if (sDistortionContext.countdown < 4) { + xyScaleFactor = zScaleFactor = sDistortionContext.countdown / (f32)countdownMax; } else { xyScaleFactor = zScaleFactor = 0.0f; } speedScaleFactor = 1.0f; - } else if (sQuake2Context.type & 0x20) { - sQuake2Context.countdown = 2; - if (sQuake2Context.state == QUAKE2_SETUP) { - angle1 = 0x9C4; - angle2 = 0xBB8; + } else if (sDistortionContext.type & 0x20) { + sDistortionContext.countdown = 2; + if (sDistortionContext.state == DISTORTION_SETUP) { + depthPhase = 0x9C4; + screenPlanePhase = 0xBB8; } - angle1 += 0xB1; - angle2 -= 0x2B; - angle1Speed = -107.0f; - angle2Speed = 158.0f; + depthPhase += 0xB1; + screenPlanePhase -= 0x2B; + + depthPhaseStep = -107.0f; + screenPlanePhaseStep = 158.0f; + rotX = 0.2f; rotY = 1.7f; rotZ = -2.9f; + xScale = -0.6f; yScale = -0.7f; zScale = 0.6f; + speed = 0.2f; zScaleFactor = 1.0f; xyScaleFactor = 1.0f; speedScaleFactor = 1.0f; - } else if (sQuake2Context.type & 0x10) { - if (sQuake2Context.state == QUAKE2_SETUP) { - countdownMax = sQuake2Context.countdown; - angle1 = 0x760; - angle2 = 0x1BC; + } else if (sDistortionContext.type & 0x10) { + if (sDistortionContext.state == DISTORTION_SETUP) { + countdownMax = sDistortionContext.countdown; + depthPhase = 0x760; + screenPlanePhase = 0x1BC; } - angle1Speed = 248.0f; - angle2Speed = -90.0f; + depthPhaseStep = 248.0f; + screenPlanePhaseStep = -90.0f; + rotX = 0.0f; rotY = 0.0f; rotZ = 0.0f; + xScale = -0.4f; yScale = 0.4f; zScale = 0.2f; + speed = 0.25f; - countdownRatio = sQuake2Context.countdown / (f32)countdownMax; + countdownRatio = sDistortionContext.countdown / (f32)countdownMax; zScaleFactor = xyScaleFactor = countdownRatio; speedScaleFactor = 1.0f; - } else if (sQuake2Context.type & 8) { - angle1 = 0x3F0; - angle2 = 0x156; - sQuake2Context.countdown = 2; + } else if (sDistortionContext.type & 8) { + depthPhase = 0x3F0; + screenPlanePhase = 0x156; + + sDistortionContext.countdown = 2; player = GET_PLAYER(globalCtx); if (&player->actor != NULL) { Actor_GetWorldPosShapeRot(&playerPosRot, &player->actor); } - angle1Speed = 359.2f; - angle2Speed = -18.5f; + depthPhaseStep = 359.2f; + screenPlanePhaseStep = -18.5f; + rotX = 0.0f; rotY = 0.0f; rotZ = 0.3f; - switch (Quake2_GetFloorQuake(player)) { + + switch (Distortion_GetUnderwaterCurrentSpeed(player)) { case 3: xScale = -0.06f; yScale = 0.1f; @@ -650,17 +683,20 @@ void Quake2_Update(void) { } zScaleFactor = -xyScaleFactor; speedScaleFactor = 1.0f; - } else if (sQuake2Context.type & 4) { - angle1 = 0x3F0; - angle2 = 0x156; - sQuake2Context.countdown = 2; + } else if (sDistortionContext.type & 4) { + depthPhase = 0x3F0; + screenPlanePhase = 0x156; + + sDistortionContext.countdown = 2; player = GET_PLAYER(globalCtx); - angle1Speed = 359.2f; - angle2Speed = -18.5f; + + depthPhaseStep = 359.2f; + screenPlanePhaseStep = -18.5f; + rotX = 0.0f; rotY = 0.0f; rotZ = 0.0f; - switch (Quake2_GetFloorQuake(player)) { + switch (Distortion_GetUnderwaterCurrentSpeed(player)) { case 3: xScale = 0.12f; yScale = 0.12f; @@ -695,18 +731,23 @@ void Quake2_Update(void) { xyScaleFactor = speedScaleFactor = (waterYScaleFactor * 0.15f) + 0.35f + (speedRatio * 0.4f); zScaleFactor = 0.9f - xyScaleFactor; - } else if (sQuake2Context.type & 1) { - angle1 = 0x3F0; - angle2 = 0x156; - sQuake2Context.countdown = 2; - angle1Speed = 0.0f; - angle2Speed = 150.0f; + } else if (sDistortionContext.type & 1) { + // Gives a small mirage-like appearance + depthPhase = 0x3F0; + screenPlanePhase = 0x156; + + sDistortionContext.countdown = 2; + depthPhaseStep = 0.0f; + screenPlanePhaseStep = 150.0f; + rotX = 0.0f; rotY = 0.0f; rotZ = 0.0f; + xScale = -0.01f; yScale = 0.01f; zScale = 0.01f; + speed = 0.6f; speedScaleFactor = 1.0f; zScaleFactor = 1.0f; @@ -715,26 +756,32 @@ void Quake2_Update(void) { return; } - angle1 += DEGF_TO_BINANG(angle1Speed); - angle2 += DEGF_TO_BINANG(angle2Speed); - View_SetQuakeRotation(&sQuake2Context.globalCtx->view, Math_CosS(angle1) * (DEGF_TO_RADF(rotX) * xyScaleFactor), - Math_SinS(angle1) * (DEGF_TO_RADF(rotY) * xyScaleFactor), - Math_SinS(angle2) * (DEGF_TO_RADF(rotZ) * zScaleFactor)); - View_SetQuakeScale(&sQuake2Context.globalCtx->view, (Math_SinS(angle2) * (xScale * xyScaleFactor)) + 1.0f, - (Math_CosS(angle2) * (yScale * xyScaleFactor)) + 1.0f, - (Math_CosS(angle1) * (zScale * zScaleFactor)) + 1.0f); - View_SetQuakeSpeed(&sQuake2Context.globalCtx->view, speed * speedScaleFactor); - sQuake2Context.state = QUAKE2_ACTIVE; - } else if (sQuake2Context.state != QUAKE2_INACTIVE) { - View_ClearQuake(&globalCtx->view); - sQuake2Context.state = QUAKE2_INACTIVE; - sQuake2Context.countdown = 0; + depthPhase += DEGF_TO_BINANG(depthPhaseStep); + screenPlanePhase += DEGF_TO_BINANG(screenPlanePhaseStep); + + View_SetDistortionDirRot(&sDistortionContext.globalCtx->view, + Math_CosS(depthPhase) * (DEGF_TO_RADF(rotX) * xyScaleFactor), + Math_SinS(depthPhase) * (DEGF_TO_RADF(rotY) * xyScaleFactor), + Math_SinS(screenPlanePhase) * (DEGF_TO_RADF(rotZ) * zScaleFactor)); + View_SetDistortionScale(&sDistortionContext.globalCtx->view, + (Math_SinS(screenPlanePhase) * (xScale * xyScaleFactor)) + 1.0f, + (Math_CosS(screenPlanePhase) * (yScale * xyScaleFactor)) + 1.0f, + (Math_CosS(depthPhase) * (zScale * zScaleFactor)) + 1.0f); + View_SetDistortionSpeed(&sDistortionContext.globalCtx->view, speed * speedScaleFactor); + + sDistortionContext.state = DISTORTION_ACTIVE; + + } else if (sDistortionContext.state != DISTORTION_INACTIVE) { + View_ClearDistortion(&globalCtx->view); + + sDistortionContext.state = DISTORTION_INACTIVE; + sDistortionContext.countdown = 0; } - if (sQuake2Context.countdown != 0) { - sQuake2Context.countdown--; - if (sQuake2Context.countdown == 0) { - sQuake2Context.type = 0; + if (sDistortionContext.countdown != 0) { + sDistortionContext.countdown--; + if (sDistortionContext.countdown == 0) { + sDistortionContext.type = 0; } } } diff --git a/src/code/z_view.c b/src/code/z_view.c index da2e3593b..d11a18201 100644 --- a/src/code/z_view.c +++ b/src/code/z_view.c @@ -43,7 +43,7 @@ void View_Init(View* view, GraphicsContext* gfxCtx) { view->zFar = 12800.0f; view->eye.z = -1.0f; - View_InitCameraQuake(view); + View_InitDistortion(view); } void View_SetViewOrientation(View* view, Vec3f* eye, Vec3f* at, Vec3f* up) { @@ -187,87 +187,93 @@ void View_SetScissorForLetterbox(View* view) { CLOSE_DISPS(view->gfxCtx); } -s32 View_SetQuakeRotation(View* view, f32 x, f32 y, f32 z) { - view->quakeRot.x = x; - view->quakeRot.y = y; - view->quakeRot.z = z; +s32 View_SetDistortionDirRot(View* view, f32 dirRotX, f32 dirRotY, f32 dirRotZ) { + view->distortionDirRot.x = dirRotX; + view->distortionDirRot.y = dirRotY; + view->distortionDirRot.z = dirRotZ; return 1; } -s32 View_SetQuakeScale(View* view, f32 x, f32 y, f32 z) { - view->quakeScale.x = x; - view->quakeScale.y = y; - view->quakeScale.z = z; +s32 View_SetDistortionScale(View* view, f32 scaleX, f32 scaleY, f32 scaleZ) { + view->distortionScale.x = scaleX; + view->distortionScale.y = scaleY; + view->distortionScale.z = scaleZ; return 1; } -s32 View_SetQuakeSpeed(View* view, f32 speed) { - view->quakeSpeed = speed; +s32 View_SetDistortionSpeed(View* view, f32 speed) { + view->distortionSpeed = speed; return 1; } -s32 View_InitCameraQuake(View* view) { - view->quakeRot.x = 0.0f; - view->quakeRot.y = 0.0f; - view->quakeRot.z = 0.0f; - view->quakeScale.x = 1.0f; - view->quakeScale.y = 1.0f; - view->quakeScale.z = 1.0f; - view->currQuakeRot = view->quakeRot; - view->currQuakeScale = view->quakeScale; - view->quakeSpeed = 0.0f; +s32 View_InitDistortion(View* view) { + view->distortionDirRot.x = 0.0f; + view->distortionDirRot.y = 0.0f; + view->distortionDirRot.z = 0.0f; + view->distortionScale.x = 1.0f; + view->distortionScale.y = 1.0f; + view->distortionScale.z = 1.0f; + view->curDistortionDirRot = view->distortionDirRot; + view->curDistortionScale = view->distortionScale; + view->distortionSpeed = 0.0f; return 1; } -s32 View_ClearQuake(View* view) { - view->quakeRot.x = 0.0f; - view->quakeRot.y = 0.0f; - view->quakeRot.z = 0.0f; - view->quakeScale.x = 1.0f; - view->quakeScale.y = 1.0f; - view->quakeScale.z = 1.0f; - view->quakeSpeed = 1.0f; +s32 View_ClearDistortion(View* view) { + view->distortionDirRot.x = 0.0f; + view->distortionDirRot.y = 0.0f; + view->distortionDirRot.z = 0.0f; + view->distortionScale.x = 1.0f; + view->distortionScale.y = 1.0f; + view->distortionScale.z = 1.0f; + view->distortionSpeed = 1.0f; return 1; } -s32 View_SetQuake(View* view, Vec3f rot, Vec3f scale, f32 speed) { - view->quakeRot = rot; - view->quakeScale = scale; - view->quakeSpeed = speed; +s32 View_SetDistortion(View* view, Vec3f dirRot, Vec3f scale, f32 speed) { + view->distortionDirRot = dirRot; + view->distortionScale = scale; + view->distortionSpeed = speed; return 1; } -s32 View_StepQuake(View* view, Mtx* matrix) { - MtxF mf; +s32 View_StepDistortion(View* view, Mtx* projectionMtx) { + MtxF projectionMtxF; - if (view->quakeSpeed == 0.0f) { - return 0; - } else if (view->quakeSpeed == 1.0f) { - view->currQuakeRot = view->quakeRot; - view->currQuakeScale = view->quakeScale; - view->quakeSpeed = 0.0f; + if (view->distortionSpeed == 0.0f) { + return false; + } else if (view->distortionSpeed == 1.0f) { + view->curDistortionDirRot = view->distortionDirRot; + view->curDistortionScale = view->distortionScale; + view->distortionSpeed = 0.0f; } else { - view->currQuakeRot.x += ((view->quakeRot.x - view->currQuakeRot.x) * view->quakeSpeed); - view->currQuakeRot.y += ((view->quakeRot.y - view->currQuakeRot.y) * view->quakeSpeed); - view->currQuakeRot.z += ((view->quakeRot.z - view->currQuakeRot.z) * view->quakeSpeed); - - view->currQuakeScale.x += ((view->quakeScale.x - view->currQuakeScale.x) * view->quakeSpeed); - view->currQuakeScale.y += ((view->quakeScale.y - view->currQuakeScale.y) * view->quakeSpeed); - view->currQuakeScale.z += ((view->quakeScale.z - view->currQuakeScale.z) * view->quakeSpeed); + view->curDistortionDirRot.x = + F32_LERPIMP(view->curDistortionDirRot.x, view->distortionDirRot.x, view->distortionSpeed); + view->curDistortionDirRot.y = + F32_LERPIMP(view->curDistortionDirRot.y, view->distortionDirRot.y, view->distortionSpeed); + view->curDistortionDirRot.z = + F32_LERPIMP(view->curDistortionDirRot.z, view->distortionDirRot.z, view->distortionSpeed); + + view->curDistortionScale.x = + F32_LERPIMP(view->curDistortionScale.x, view->distortionScale.x, view->distortionSpeed); + view->curDistortionScale.y = + F32_LERPIMP(view->curDistortionScale.y, view->distortionScale.y, view->distortionSpeed); + view->curDistortionScale.z = + F32_LERPIMP(view->curDistortionScale.z, view->distortionScale.z, view->distortionSpeed); } - Matrix_FromRSPMatrix(matrix, &mf); - Matrix_SetCurrentState(&mf); - Matrix_RotateStateAroundXAxis(view->currQuakeRot.x); - Matrix_InsertYRotation_f(view->currQuakeRot.y, MTXMODE_APPLY); - Matrix_InsertZRotation_f(view->currQuakeRot.z, MTXMODE_APPLY); - Matrix_Scale(view->currQuakeScale.x, view->currQuakeScale.y, view->currQuakeScale.z, MTXMODE_APPLY); - Matrix_InsertZRotation_f(-view->currQuakeRot.z, MTXMODE_APPLY); - Matrix_InsertYRotation_f(-view->currQuakeRot.y, MTXMODE_APPLY); - Matrix_RotateStateAroundXAxis(-view->currQuakeRot.x); - Matrix_ToMtx(matrix); - - return 1; + Matrix_FromRSPMatrix(projectionMtx, &projectionMtxF); + Matrix_SetCurrentState(&projectionMtxF); + Matrix_RotateStateAroundXAxis(view->curDistortionDirRot.x); + Matrix_InsertYRotation_f(view->curDistortionDirRot.y, MTXMODE_APPLY); + Matrix_InsertZRotation_f(view->curDistortionDirRot.z, MTXMODE_APPLY); + Matrix_Scale(view->curDistortionScale.x, view->curDistortionScale.y, view->curDistortionScale.z, MTXMODE_APPLY); + Matrix_InsertZRotation_f(-view->curDistortionDirRot.z, MTXMODE_APPLY); + Matrix_InsertYRotation_f(-view->curDistortionDirRot.y, MTXMODE_APPLY); + Matrix_RotateStateAroundXAxis(-view->curDistortionDirRot.x); + Matrix_ToMtx(projectionMtx); + + return true; } void View_RenderView(View* view, s32 uParm2) { @@ -309,8 +315,8 @@ s32 View_RenderToPerspectiveMatrix(View* view) { guPerspective(projection, &view->normal, view->fovy, aspect, view->zNear, view->zFar, view->scale); view->projection = *projection; - //! @bug: This cast of `projection` is invalid - View_StepQuake(view, (Mtx*)projection); + + View_StepDistortion(view, projection); gSPPerspNormalize(POLY_OPA_DISP++, view->normal); gSPMatrix(POLY_OPA_DISP++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION); |
