diff --git a/src/decomp/audio/effects.c b/src/decomp/audio/effects.c index bd243f3..cb96059 100644 --- a/src/decomp/audio/effects.c +++ b/src/decomp/audio/effects.c @@ -63,21 +63,16 @@ seqChannel->changes.as_u8=0; #else static void sequence_channel_process_sound(struct SequenceChannel *seqChannel) { - f32 channelVolume; - f32 panLayerWeight; - f32 panFromChannel; - s32 i; - - channelVolume = seqChannel->volume * seqChannel->volumeScale * seqChannel->seqPlayer->fadeVolume; + f32 channelVolume = seqChannel->volume * seqChannel->volumeScale * seqChannel->seqPlayer->fadeVolume; if (seqChannel->seqPlayer->muted && (seqChannel->muteBehavior & MUTE_BEHAVIOR_SOFTEN) != 0) { channelVolume *= seqChannel->seqPlayer->muteVolumeScale; } - panFromChannel = seqChannel->pan * seqChannel->panChannelWeight; - panLayerWeight = US_FLOAT(1.0) - seqChannel->panChannelWeight; + f32 panFromChannel = seqChannel->pan * seqChannel->panChannelWeight; + f32 panLayerWeight = US_FLOAT(1.0) - seqChannel->panChannelWeight; - for (i = 0; i < 4; i++) + for (s32 i = 0; i < 4; i++) { struct SequenceChannelLayer *layer = seqChannel->layers[i]; if (layer != NULL && layer->enabled && layer->note != NULL) @@ -92,8 +87,6 @@ static void sequence_channel_process_sound(struct SequenceChannel *seqChannel) void sequence_player_process_sound(struct SequencePlayer *seqPlayer) { - s32 i; - if (seqPlayer->fadeRemainingFrames != 0) { seqPlayer->fadeVolume += seqPlayer->fadeVelocity; @@ -145,7 +138,7 @@ void sequence_player_process_sound(struct SequencePlayer *seqPlayer) #endif // Process channels - for (i = 0; i < CHANNELS_MAX; i++) + for (s32 i = 0; i < CHANNELS_MAX; i++) { if (IS_SEQUENCE_CHANNEL_VALID(seqPlayer->channels[i]) == TRUE && seqPlayer->channels[i]->enabled == TRUE) @@ -205,10 +198,9 @@ s16 get_vibrato_pitch_change(struct VibratoState *vib) #else s8 get_vibrato_pitch_change(struct VibratoState *vib) { - s32 index; vib->time += vib->rate; - index = vib->time >> 10 & 0x3F; + s32 index = vib->time >> 10 & 0x3F; switch (index & 0x30) { @@ -233,8 +225,6 @@ s8 get_vibrato_pitch_change(struct VibratoState *vib) f32 get_vibrato_freq_scale(struct VibratoState *vib) { - s32 pitchChange; - f32 extent; f32 result; if (vib->delay != 0) @@ -291,8 +281,8 @@ f32 get_vibrato_freq_scale(struct VibratoState *vib) return 1.0f; } - pitchChange = get_vibrato_pitch_change(vib); - extent = (f32)vib->extent / US_FLOAT(4096.0); + s32 pitchChange = get_vibrato_pitch_change(vib); + f32 extent = (f32)vib->extent / US_FLOAT(4096.0); #if defined(VERSION_EU) || defined(VERSION_SH) result = US_FLOAT(1.0) + extent * (gPitchBendFrequencyScale[pitchChange + 128] - US_FLOAT(1.0)); diff --git a/src/decomp/audio/external.c b/src/decomp/audio/external.c index f872d51..34ff1fc 100644 --- a/src/decomp/audio/external.c +++ b/src/decomp/audio/external.c @@ -864,15 +864,11 @@ void create_next_audio_buffer(s16 *samples, u32 num_samples) */ static void process_sound_request(u32 bits, f32 *pos) { - u8 bank; - u8 soundIndex; u8 counter = 0; - u8 soundId; - f32 dist; const f32 one = 1.0f; - bank = (bits & SOUNDARGS_MASK_BANK) >> SOUNDARGS_SHIFT_BANK; - soundId = (bits & SOUNDARGS_MASK_SOUNDID) >> SOUNDARGS_SHIFT_SOUNDID; + u8 bank = (bits & SOUNDARGS_MASK_BANK) >> SOUNDARGS_SHIFT_BANK; + u8 soundId = (bits & SOUNDARGS_MASK_SOUNDID) >> SOUNDARGS_SHIFT_SOUNDID; if (soundId >= sNumSoundsPerBank[bank] || sSoundBankDisabled[bank]) { @@ -880,7 +876,7 @@ static void process_sound_request(u32 bits, f32 *pos) return; } - soundIndex = sSoundBanks[bank][0].next; + u8 soundIndex = sSoundBanks[bank][0].next; while (soundIndex != 0xff && soundIndex != 0) { //DEBUG_PRINT("process_sound_request: soundIndex %d\n", soundIndex); @@ -938,7 +934,7 @@ static void process_sound_request(u32 bits, f32 *pos) // Allocate from free list soundIndex = sSoundBankFreeListFront[bank]; - dist = sqrtf(pos[0] * pos[0] + pos[1] * pos[1] + pos[2] * pos[2]) * one; + f32 dist = sqrtf(pos[0] * pos[0] + pos[1] * pos[1] + pos[2] * pos[2]) * one; sSoundBanks[bank][soundIndex].x = &pos[0]; sSoundBanks[bank][soundIndex].y = &pos[1]; sSoundBanks[bank][soundIndex].z = &pos[2]; @@ -965,11 +961,9 @@ static void process_sound_request(u32 bits, f32 *pos) */ static void process_all_sound_requests(void) { - struct Sound *sound; - while (sSoundRequestCount != sNumProcessedSoundRequests) { - sound = &sSoundRequests[sNumProcessedSoundRequests]; + struct Sound *sound = &sSoundRequests[sNumProcessedSoundRequests]; process_sound_request(sound->soundBits, sound->position); sNumProcessedSoundRequests++; //DEBUG_PRINT("processed sounds: %d\n", sNumProcessedSoundRequests); @@ -1019,11 +1013,7 @@ static void update_background_music_after_sound(u8 bank, u8 soundIndex) */ static void select_current_sounds(u8 bank) { - u32 isDiscreteAndStatus; - u8 latestSoundIndex; u8 i; - u8 j; - u8 soundIndex; u32 liveSoundPriorities[16] = { 0x10000000, 0x10000000, 0x10000000, 0x10000000, 0x10000000, 0x10000000, 0x10000000, 0x10000000, @@ -1039,15 +1029,14 @@ static void select_current_sounds(u8 bank) 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; u8 numSoundsInBank = 0; - u8 requestedPriority; // // Delete stale sounds and prioritize remaining sounds into the liveSound arrays // - soundIndex = sSoundBanks[bank][0].next; + u8 soundIndex = sSoundBanks[bank][0].next; while (soundIndex != 0xff) { - latestSoundIndex = soundIndex; + u8 latestSoundIndex = soundIndex; // If a discrete sound goes 10 frames without being played (because it is too low // priority), then mark it for deletion @@ -1093,8 +1082,8 @@ static void select_current_sounds(u8 bank) + *sSoundBanks[bank][soundIndex].z * *sSoundBanks[bank][soundIndex].z) * 1; - requestedPriority = (sSoundBanks[bank][soundIndex].soundBits & SOUNDARGS_MASK_PRIORITY) - >> SOUNDARGS_SHIFT_PRIORITY; + u8 requestedPriority = (sSoundBanks[bank][soundIndex].soundBits & SOUNDARGS_MASK_PRIORITY) + >> SOUNDARGS_SHIFT_PRIORITY; // Recompute priority, possibly based on the sound's source position relative to the // camera. @@ -1127,7 +1116,7 @@ static void select_current_sounds(u8 bank) if (liveSoundPriorities[i] >= sSoundBanks[bank][soundIndex].priority) { // Shift remaining sounds to the right - for (j = sMaxChannelsForSoundBank[bank] - 1; j > i; j--) + for (u8 j = sMaxChannelsForSoundBank[bank] - 1; j > i; j--) { liveSoundPriorities[j] = liveSoundPriorities[j - 1]; liveSoundIndices[j] = liveSoundIndices[j - 1]; @@ -1185,8 +1174,8 @@ static void select_current_sounds(u8 bank) } // If the sound is discrete and is playing, then delete it - isDiscreteAndStatus = sSoundBanks[bank][sCurrentSound[bank][i]].soundBits - & (SOUND_DISCRETE | SOUNDARGS_MASK_STATUS); + u32 isDiscreteAndStatus = sSoundBanks[bank][sCurrentSound[bank][i]].soundBits + & (SOUND_DISCRETE | SOUNDARGS_MASK_STATUS); if (isDiscreteAndStatus >= (SOUND_DISCRETE | SOUND_STATUS_PLAYING) && sSoundBanks[bank][sCurrentSound[bank][i]].soundStatus != SOUND_STATUS_STOPPED) { @@ -1259,17 +1248,15 @@ static void select_current_sounds(u8 bank) */ static f32 get_sound_pan(f32 x, f32 z) { - f32 absX; - f32 absZ; f32 pan; - absX = x < 0 ? -x : x; + f32 absX = x < 0 ? -x : x; if (absX > AUDIO_MAX_DISTANCE) { absX = AUDIO_MAX_DISTANCE; } - absZ = z < 0 ? -z : z; + f32 absZ = z < 0 ? -z : z; if (absZ > AUDIO_MAX_DISTANCE) { absZ = AUDIO_MAX_DISTANCE; @@ -1476,9 +1463,7 @@ void audio_signal_game_loop_tick(void) void update_game_sound(void) { u8 soundStatus; - u8 i; u8 soundId; - u8 bank; u8 channelIndex = 0; u8 soundIndex; #if defined(VERSION_JP) || defined(VERSION_US) @@ -1493,11 +1478,11 @@ void update_game_sound(void) return; } - for (bank = 0; bank < SOUND_BANK_COUNT; bank++) + for (u8 bank = 0; bank < SOUND_BANK_COUNT; bank++) { select_current_sounds(bank); - for (i = 0; i < MAX_CHANNELS_PER_SOUND_BANK; i++) + for (u8 i = 0; i < MAX_CHANNELS_PER_SOUND_BANK; i++) { soundIndex = sCurrentSound[bank][i]; @@ -1890,7 +1875,6 @@ void update_game_sound(void) void seq_player_play_sequence(u8 player, u8 seqId, u16 arg2) { u8 targetVolume; - u8 i; if (player == SEQ_PLAYER_LEVEL) { @@ -1900,7 +1884,7 @@ void seq_player_play_sequence(u8 player, u8 seqId, u16 arg2) sMusicDynamicDelay = 2; } - for (i = 0; i < CHANNELS_MAX; i++) + for (u8 i = 0; i < CHANNELS_MAX; i++) { D_80360928[player][i].remainingFrames = 0; } @@ -1968,8 +1952,7 @@ void seq_player_fade_out(u8 player, u16 fadeDuration) */ void fade_volume_scale(u8 player, u8 targetScale, u16 fadeDuration) { - u8 i; - for (i = 0; i < CHANNELS_MAX; i++) + for (u8 i = 0; i < CHANNELS_MAX; i++) { fade_channel_volume_scale(player, i, targetScale, fadeDuration); } @@ -1980,11 +1963,9 @@ void fade_volume_scale(u8 player, u8 targetScale, u16 fadeDuration) */ static void fade_channel_volume_scale(u8 player, u8 channelIndex, u8 targetScale, u16 fadeDuration) { - struct ChannelVolumeScaleFade *temp; - if (gSequencePlayers[player].channels[channelIndex] != &gSequenceChannelNone) { - temp = &D_80360928[player][channelIndex]; + struct ChannelVolumeScaleFade *temp = &D_80360928[player][channelIndex]; temp->remainingFrames = fadeDuration; temp->velocity = (targetScale / US_FLOAT(127.0) - gSequencePlayers[player].channels[channelIndex]->volumeScale) @@ -1999,10 +1980,8 @@ static void fade_channel_volume_scale(u8 player, u8 channelIndex, u8 targetScale */ static void func_8031F96C(u8 player) { - u8 i; - // Loop over channels - for (i = 0; i < CHANNELS_MAX; i++) + for (u8 i = 0; i < CHANNELS_MAX; i++) { if (gSequencePlayers[player].channels[i] != &gSequenceChannelNone && D_80360928[player][i].remainingFrames != 0) @@ -2037,18 +2016,12 @@ static void func_8031F96C(u8 player) */ void process_level_music_dynamics(void) { - u32 conditionBits; u16 tempBits; UNUSED u16 pad; - u8 musicDynIndex; - u8 condIndex; - u8 i; - u8 j; s16 conditionValues[8]; u8 conditionTypes[8]; s16 dur1; s16 dur2; - u16 bit; func_8031F96C(0); func_8031F96C(2); @@ -2067,14 +2040,14 @@ void process_level_music_dynamics(void) return; } - conditionBits = sLevelDynamics[gCurrLevelNum][1] & 0xff00; - musicDynIndex = (u8)sLevelDynamics[gCurrLevelNum][1] & 0xff; - i = 2; + u32 conditionBits = sLevelDynamics[gCurrLevelNum][1] & 0xff00; + u8 musicDynIndex = (u8)sLevelDynamics[gCurrLevelNum][1] & 0xff; + u8 i = 2; while (conditionBits & 0xff00) { - j = 0; - condIndex = 0; - bit = 0x8000; + u8 j = 0; + u8 condIndex = 0; + u16 bit = 0x8000; while (j < 8) { if (conditionBits & bit) @@ -2163,14 +2136,12 @@ void process_level_music_dynamics(void) void unused_8031FED0(u8 player, u32 bits, s8 arg2) { - u8 i; - if (arg2 < 0) { arg2 = -arg2; } - for (i = 0; i < CHANNELS_MAX; i++) + for (u8 i = 0; i < CHANNELS_MAX; i++) { if (gSequencePlayers[player].channels[i] != &gSequenceChannelNone) { @@ -2311,9 +2282,7 @@ static u8 begin_background_music_fade(u16 fadeDuration) */ void set_audio_muted(u8 muted) { - u8 i; - - for (i = 0; i < SEQUENCE_PLAYERS; i++) + for (u8 i = 0; i < SEQUENCE_PLAYERS; i++) { #if defined(VERSION_EU) || defined(VERSION_SH) if (muted) @@ -2402,10 +2371,9 @@ void sound_init(void) // (unused) void get_currently_playing_sound(u8 bank, u8 *numPlayingSounds, u8 *numSoundsInBank, u8 *soundId) { - u8 i; u8 count = 0; - for (i = 0; i < sMaxChannelsForSoundBank[bank]; i++) + for (u8 i = 0; i < sMaxChannelsForSoundBank[bank]; i++) { if (sCurrentSound[bank][i] != 0xff) { @@ -2458,12 +2426,9 @@ void stop_sound(u32 soundBits, f32 *pos) */ void stop_sounds_from_source(f32 *pos) { - u8 bank; - u8 soundIndex; - - for (bank = 0; bank < SOUND_BANK_COUNT; bank++) + for (u8 bank = 0; bank < SOUND_BANK_COUNT; bank++) { - soundIndex = sSoundBanks[bank][0].next; + u8 soundIndex = sSoundBanks[bank][0].next; while (soundIndex != 0xff) { if (sSoundBanks[bank][soundIndex].x == pos) @@ -2510,9 +2475,7 @@ void stop_sounds_in_continuous_banks(void) */ void sound_banks_disable(UNUSED u8 player, u16 bankMask) { - u8 i; - - for (i = 0; i < SOUND_BANK_COUNT; i++) + for (u8 i = 0; i < SOUND_BANK_COUNT; i++) { if (bankMask & 1) { @@ -2527,9 +2490,7 @@ void sound_banks_disable(UNUSED u8 player, u16 bankMask) */ static void disable_all_sequence_players(void) { - u8 i; - - for (i = 0; i < SEQUENCE_PLAYERS; i++) + for (u8 i = 0; i < SEQUENCE_PLAYERS; i++) { sequence_player_disable(&gSequencePlayers[i]); } @@ -2540,9 +2501,7 @@ static void disable_all_sequence_players(void) */ void sound_banks_enable(UNUSED u8 player, u16 bankMask) { - u8 i; - - for (i = 0; i < SOUND_BANK_COUNT; i++) + for (u8 i = 0; i < SOUND_BANK_COUNT; i++) { if (bankMask & 1) { @@ -2658,7 +2617,6 @@ void play_music(u8 player, u16 seqArgs, u16 fadeTimer) */ void stop_background_music(u16 seqId) { - u8 foundIndex; u8 i; if (sBackgroundMusicQueueSize == 0) @@ -2668,7 +2626,7 @@ void stop_background_music(u16 seqId) // If sequence is not found, remove an empty queue item (the next empty // queue slot). - foundIndex = sBackgroundMusicQueueSize; + u8 foundIndex = sBackgroundMusicQueueSize; // Search for the sequence. for (i = 0; i < sBackgroundMusicQueueSize; i++) @@ -2829,8 +2787,6 @@ void func_80321080(u16 fadeTimer) */ void func_803210D4(u16 fadeDuration) { - u8 i; - if (sHasStartedFadeOut) { return; @@ -2854,7 +2810,7 @@ void func_803210D4(u16 fadeDuration) #endif } - for (i = 0; i < SOUND_BANK_COUNT; i++) + for (u8 i = 0; i < SOUND_BANK_COUNT; i++) { if (i != SOUND_BANK_MENU) { diff --git a/src/decomp/audio/heap.c b/src/decomp/audio/heap.c index 9475bd3..f1a8bc1 100644 --- a/src/decomp/audio/heap.c +++ b/src/decomp/audio/heap.c @@ -236,9 +236,7 @@ void reset_bank_and_seq_load_status(void) void discard_bank(s32 bankId) { - s32 i; - - for (i = 0; i < gMaxSimultaneousNotes; i++) + for (s32 i = 0; i < gMaxSimultaneousNotes; i++) { struct Note *note = &gNotes[i]; @@ -271,9 +269,7 @@ void discard_bank(s32 bankId) void discard_sequence(s32 seqId) { - s32 i; - - for (i = 0; i < SEQUENCE_PLAYERS; i++) + for (s32 i = 0; i < SEQUENCE_PLAYERS; i++) { if (gSequencePlayers[i].enabled && gSequencePlayers[i].seqId == seqId) { @@ -289,15 +285,13 @@ void discard_sequence(s32 seqId) void *soundAlloc(struct SoundAllocPool *pool, u32 size) { u8 *start; - s32 last; - s32 i; if (pool->cur + ALIGN16(size) <= pool->size + pool->start) { start = pool->cur; pool->cur += ALIGN16(size); - last = pool->cur - start - 1; - for (i = 0; i <= last; i++) + s32 last = pool->cur - start - 1; + for (s32 i = 0; i <= last; i++) { start[i] = 0; } @@ -993,9 +987,8 @@ void *get_bank_or_seq_inner(s32 poolIdx, s32 arg1, s32 bankId) #ifndef VERSION_SH void *get_bank_or_seq(struct SoundMultiPool *arg0, s32 arg1, s32 id) { - u32 i; UNUSED - void *ret; + void *ret; struct TemporaryPool *temporary = &arg0->temporary; if (arg1 == 0) @@ -1017,7 +1010,7 @@ void *get_bank_or_seq(struct SoundMultiPool *arg0, s32 arg1, s32 id) else { struct PersistentPool *persistent = &arg0->persistent; - for (i = 0; i < persistent->numEntries; i++) + for (u32 i = 0; i < persistent->numEntries; i++) { if (id == persistent->entries[i].id) { @@ -1302,8 +1295,7 @@ void audio_reset_session(void) #if defined(VERSION_JP) || defined(VERSION_US) s8 updatesPerFrame; s32 reverbWindowSize; - s32 k; - #endif +#endif s32 i; s32 j; s32 persistentMem; @@ -1379,7 +1371,7 @@ void audio_reset_session(void) for (j = 0; j < NUMAIBUFFERS; j++) { - for (k = 0; k < (s32)(AIBUFFER_LEN / sizeof(s16)); k++) + for (s32 k = 0; k < (s32)(AIBUFFER_LEN / sizeof(s16)); k++) { gAiBuffers[j][k] = 0; } diff --git a/src/decomp/audio/load.c b/src/decomp/audio/load.c index 1466f79..5b1136e 100644 --- a/src/decomp/audio/load.c +++ b/src/decomp/audio/load.c @@ -228,16 +228,13 @@ void *dma_sample_data(uintptr_t devAddr, u32 size, s32 arg2, u8 *dmaIndexRef) { s32 hasDma = FALSE; struct SharedDma *dma; - uintptr_t dmaDevAddr; - u32 transfer; - u32 i; u32 dmaIndex; ssize_t bufferPos; UNUSED u32 pad; if (arg2 != 0 || *dmaIndexRef >= sSampleDmaListSize1) { - for (i = sSampleDmaListSize1; i < gSampleDmaNumListItems; i++) + for (u32 i = sSampleDmaListSize1; i < gSampleDmaNumListItems; i++) { #if defined(VERSION_EU) dma = &sSampleDmas[i]; @@ -329,8 +326,8 @@ void *dma_sample_data(uintptr_t devAddr, u32 size, s32 arg2, u8 *dmaIndexRef) hasDma = TRUE; } - transfer = dma->bufSize; - dmaDevAddr = devAddr & ~0xF; + u32 transfer = dma->bufSize; + uintptr_t dmaDevAddr = devAddr & ~0xF; dma->ttl = 2; dma->source = dmaDevAddr; dma->sizeUnused = transfer; @@ -461,7 +458,6 @@ UNUSED static #endif void patch_sound(UNUSED struct AudioBankSound *sound, UNUSED u8 *memBase, UNUSED u8 *offsetBase) { - struct AudioBankSample *sample; void *patched; UNUSED u8 *mem; // unused on US @@ -469,7 +465,7 @@ void patch_sound(UNUSED struct AudioBankSound *sound, UNUSED u8 *memBase, UNUSED if (sound->sample != NULL) { - sample = sound->sample = PATCH(sound->sample, memBase); + struct AudioBankSample *sample = sound->sample = PATCH(sound->sample, memBase); if (sample->loaded == 0) { sample->sampleAddr = PATCH(sample->sampleAddr, offsetBase); @@ -537,7 +533,6 @@ void patch_audio_bank(struct AudioBank *mem, u8 *offset, u32 numInstruments, u32 struct Instrument **itInstrs; struct Instrument **end; struct AudioBank *temp; - u32 i; void *patched; struct Drum *drum; struct Drum **drums; @@ -561,7 +556,7 @@ void patch_audio_bank(struct AudioBank *mem, u8 *offset, u32 numInstruments, u32 { mem->drums = (void *)((uintptr_t)drums + (uintptr_t)mem); if (numDrums > 0) //! unneeded when -sopt is enabled - for (i = 0; i < numDrums; i++) + for (u32 i = 0; i < numDrums; i++) { #else numDrums2 = numDrums; @@ -603,9 +598,8 @@ void patch_audio_bank(struct AudioBank *mem, u8 *offset, u32 numInstruments, u32 if (numInstruments > 0) { //! Doesn't affect EU, but required for US/JP - struct Instrument **tempInst; itInstrs = temp->instruments; - tempInst = temp->instruments; + struct Instrument **tempInst = temp->instruments; end = numInstruments + tempInst; #if defined(VERSION_JP) || defined(VERSION_US) @@ -656,22 +650,18 @@ struct AudioBank *bank_load_immediate(s32 bankId, s32 arg1) UNUSED u32 pad1[4]; u32 buf[4]; - u32 numInstruments, numDrums; - struct AudioBank *ret; - u8 *ctlData; - s32 alloc; // (This is broken if the length is 1 (mod 16), but that never happens -- // it's always divisible by 4.) DEBUG_PRINT("- getting alloc"); - alloc = gAlCtlHeader->seqArray[bankId].len + 0xf; + s32 alloc = gAlCtlHeader->seqArray[bankId].len + 0xf; DEBUG_PRINT("- aligning"); alloc = ALIGN16(alloc); alloc -= 0x10; DEBUG_PRINT("- getting ctl data for bank %d", bankId); - ctlData = gAlCtlHeader->seqArray[bankId].offset; + u8 *ctlData = gAlCtlHeader->seqArray[bankId].offset; DEBUG_PRINT("- alloc bank or seq"); - ret = alloc_bank_or_seq(&gBankLoadedPool, 1, alloc, arg1, bankId); + struct AudioBank *ret = alloc_bank_or_seq(&gBankLoadedPool, 1, alloc, arg1, bankId); if (ret == NULL) { return NULL; @@ -681,8 +671,8 @@ struct AudioBank *bank_load_immediate(s32 bankId, s32 arg1) DEBUG_PRINT("- ctlData: %x", ctlData); audio_dma_copy_immediate((uintptr_t)ctlData, buf, 0x10); DEBUG_PRINT("- getting nums"); - numInstruments = buf[0]; - numDrums = buf[1]; + 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"); @@ -757,14 +747,10 @@ struct AudioBank *bank_load_async(s32 bankId, s32 arg1, struct SequencePlayer *s void *sequence_dma_immediate(s32 seqId, s32 arg1) { - s32 seqLength; - void *ptr; - u8 *seqData; - - seqLength = gSeqFileHeader->seqArray[seqId].len + 0xf; + s32 seqLength = gSeqFileHeader->seqArray[seqId].len + 0xf; seqLength = ALIGN16(seqLength); - seqData = gSeqFileHeader->seqArray[seqId].offset; - ptr = alloc_bank_or_seq(&gSeqLoadedPool, 1, seqLength, arg1, seqId); + u8 *seqData = gSeqFileHeader->seqArray[seqId].offset; + void *ptr = alloc_bank_or_seq(&gSeqLoadedPool, 1, seqLength, arg1, seqId); if (ptr == NULL) { return NULL; @@ -777,16 +763,11 @@ void *sequence_dma_immediate(s32 seqId, s32 arg1) void *sequence_dma_async(s32 seqId, s32 arg1, struct SequencePlayer *seqPlayer) { - s32 seqLength; - void *ptr; - u8 *seqData; - OSMesgQueue *mesgQueue; - eu_stubbed_printf_1("Seq %d Loading Start\n", seqId); - seqLength = gSeqFileHeader->seqArray[seqId].len + 0xf; + s32 seqLength = gSeqFileHeader->seqArray[seqId].len + 0xf; seqLength = ALIGN16(seqLength); - seqData = gSeqFileHeader->seqArray[seqId].offset; - ptr = alloc_bank_or_seq(&gSeqLoadedPool, 1, seqLength, arg1, seqId); + u8 *seqData = gSeqFileHeader->seqArray[seqId].offset; + void *ptr = alloc_bank_or_seq(&gSeqLoadedPool, 1, seqLength, arg1, seqId); if (ptr == NULL) { eu_stubbed_printf_0("Heap Overflow Error\n"); @@ -805,7 +786,7 @@ void *sequence_dma_async(s32 seqId, s32 arg1, struct SequencePlayer *seqPlayer) else { audio_dma_copy_immediate((uintptr_t)seqData, ptr, 0x40); - mesgQueue = &seqPlayer->seqDmaMesgQueue; + OSMesgQueue *mesgQueue = &seqPlayer->seqDmaMesgQueue; osCreateMesgQueue(mesgQueue, &seqPlayer->seqDmaMesg, 1); #if defined(VERSION_JP) || defined(VERSION_US) seqPlayer->seqDmaMesg = NULL; @@ -873,11 +854,10 @@ struct AudioBank *load_banks_immediate(s32 seqId, u8 *outDefaultBank) DEBUG_PRINT("load_banks_immediate()"); void *ret; u32 bankId; - u16 offset; u8 i; DEBUG_PRINT("- getting offset"); - offset = ((u16 *)gAlBankSets)[seqId]; + u16 offset = ((u16 *)gAlBankSets)[seqId]; #ifdef VERSION_EU for (i = gAlBankSets[offset++]; i != 0; i--) { @@ -977,7 +957,6 @@ void load_sequence(u32 player, u32 seqId, s32 loadAsync) void load_sequence_internal(u32 player, u32 seqId, s32 loadAsync) { - void *sequenceData; struct SequencePlayer *seqPlayer = &gSequencePlayers[player]; UNUSED u32 padding[2]; @@ -1022,7 +1001,7 @@ void load_sequence_internal(u32 player, u32 seqId, s32 loadAsync) eu_stubbed_printf_0("Seq Loading Start\n"); seqPlayer->seqId = seqId; - sequenceData = get_bank_or_seq(&gSeqLoadedPool, 2, seqId); + void *sequenceData = get_bank_or_seq(&gSeqLoadedPool, 2, seqId); if (sequenceData == NULL) { if (seqPlayer->seqDmaInProgress) @@ -1061,18 +1040,16 @@ void audio_init() DEBUG_PRINT("audio_init()"); UNUSED s8 pad[32]; u8 buf[0x10]; - s32 i, j, UNUSED k; - UNUSED s32 lim1; // lim1 unused in EU - s32 lim2, UNUSED lim3; - UNUSED u32 size; + s32 i, UNUSED k; + // lim1 unused in EU + s32 UNUSED lim3; UNUSED u64 *ptr64; - void *data; UNUSED s32 pad2; gAudioLoadLock = AUDIO_LOCK_UNINITIALIZED; DEBUG_PRINT("- setting values in unused"); - lim1 = gUnusedCount80333EE8; + s32 lim1 = gUnusedCount80333EE8; for (i = 0; i < lim1; i++) { gUnused80226E58[i] = 0; @@ -1080,7 +1057,7 @@ void audio_init() } DEBUG_PRINT("- clearing audio heap"); - lim2 = gAudioHeapSize; + s32 lim2 = gAudioHeapSize; for (i = 0; i <= lim2 / 8 - 1; i++) { ((u64 *)gAudioHeap)[i] = 0; @@ -1113,7 +1090,7 @@ void audio_init() { gAiBuffers[i] = soundAlloc(&gAudioInitPool, AIBUFFER_LEN); - for (j = 0; j < (s32)(AIBUFFER_LEN / sizeof(s16)); j++) + for (s32 j = 0; j < (s32)(AIBUFFER_LEN / sizeof(s16)); j++) { gAiBuffers[i][j] = 0; } @@ -1128,10 +1105,10 @@ void audio_init() // Load headers for sounds and sequences gSeqFileHeader = (ALSeqFile *)buf; - data = gMusicData; + void *data = gMusicData; audio_dma_copy_immediate((uintptr_t)data, gSeqFileHeader, 0x10); gSequenceCount = gSeqFileHeader->seqCount; - size = ALIGN16(gSequenceCount * sizeof(ALSeqData) + 4); + u32 size = ALIGN16(gSequenceCount * sizeof(ALSeqData) + 4); gSeqFileHeader = soundAlloc(&gAudioInitPool, size); audio_dma_copy_immediate((uintptr_t)data, gSeqFileHeader, size); alSeqFileNew(gSeqFileHeader, data); diff --git a/src/decomp/audio/playback.c b/src/decomp/audio/playback.c index 312d1f9..a7ace09 100644 --- a/src/decomp/audio/playback.c +++ b/src/decomp/audio/playback.c @@ -400,7 +400,6 @@ void process_notes(void) #if defined(VERSION_JP) || defined(VERSION_US) struct AudioListItem *it; #endif - s32 i; // Macro versions of audio_list_push_front and audio_list_remove. // Should ideally be changed to use copt. @@ -414,7 +413,7 @@ void process_notes(void) ? it \ : (it->prev->next = it->next, it->next->prev = it->prev, it->prev = NULL, it)) - for (i = 0; i < gMaxSimultaneousNotes; i++) + for (s32 i = 0; i < gMaxSimultaneousNotes; i++) { note = &gNotes[i]; #if defined(VERSION_EU) || defined(VERSION_SH) @@ -980,8 +979,6 @@ void build_synthetic_wave(struct Note *note, struct SequenceChannelLayer *seqLay s32 j; s32 pos; s32 stepSize; - s32 offset; - u8 lim; u8 origSampleCount = note->sampleCount; if (seqLayer->freqScale < US_FLOAT(1.0)) @@ -1023,9 +1020,9 @@ void build_synthetic_wave(struct Note *note, struct SequenceChannelLayer *seqLay } // Repeat sample - for (offset = note->sampleCount; offset < 0x40; offset += note->sampleCount) + for (s32 offset = note->sampleCount; offset < 0x40; offset += note->sampleCount) { - lim = note->sampleCount; + u8 lim = note->sampleCount; if (offset < 0 || offset > 0) { for (j = 0; j < lim; j++) @@ -1098,10 +1095,8 @@ void init_note_lists(struct NotePool *pool) void init_note_free_list(void) { - s32 i; - init_note_lists(&gNoteFreeLists); - for (i = 0; i < gMaxSimultaneousNotes; i++) + for (s32 i = 0; i < gMaxSimultaneousNotes; i++) { gNotes[i].listItem.u.value = &gNotes[i]; gNotes[i].listItem.prev = NULL; @@ -1111,13 +1106,12 @@ void init_note_free_list(void) void note_pool_clear(struct NotePool *pool) { - s32 i; struct AudioListItem *source; struct AudioListItem *cur; struct AudioListItem *dest; UNUSED s32 j; // unused in EU - for (i = 0; i < 4; i++) + for (s32 i = 0; i < 4; i++) { switch (i) { @@ -1180,7 +1174,6 @@ void note_pool_fill(struct NotePool *pool, s32 count) { s32 i; s32 j; - struct Note *note; struct AudioListItem *source; struct AudioListItem *dest; @@ -1219,7 +1212,7 @@ void note_pool_fill(struct NotePool *pool, s32 count) while (j < count) { - note = audio_list_pop_back(source); + struct Note *note = audio_list_pop_back(source); if (note == NULL) { break; @@ -1593,16 +1586,12 @@ null_return: seqLayer->status = SOUND_LOAD_STATUS_NOT_LOADED; #if defined(VERSION_JP) || defined(VERSION_US) void reclaim_notes(void) { - struct Note *note; - s32 i; - s32 cond; - - for (i = 0; i < gMaxSimultaneousNotes; i++) + for (s32 i = 0; i < gMaxSimultaneousNotes; i++) { - note = &gNotes[i]; + struct Note *note = &gNotes[i]; if (note->parentLayer != NO_LAYER) { - cond = FALSE; + s32 cond = FALSE; if (!note->parentLayer->enabled && note->priority >= NOTE_PRIORITY_MIN) { cond = TRUE; @@ -1645,12 +1634,9 @@ void reclaim_notes(void) void note_init_all(void) { - struct Note *note; - s32 i; - - for (i = 0; i < gMaxSimultaneousNotes; i++) + for (s32 i = 0; i < gMaxSimultaneousNotes; i++) { - note = &gNotes[i]; + struct Note *note = &gNotes[i]; #if defined(VERSION_EU) || defined(VERSION_SH) note->noteSubEu = gZeroNoteSub; #else diff --git a/src/decomp/audio/seqplayer.c b/src/decomp/audio/seqplayer.c index be112f9..93ecf2b 100644 --- a/src/decomp/audio/seqplayer.c +++ b/src/decomp/audio/seqplayer.c @@ -33,8 +33,6 @@ u8 get_instrument( void sequence_channel_init(struct SequenceChannel *seqChannel) { - s32 i; - seqChannel->enabled = FALSE; seqChannel->finished = FALSE; seqChannel->stopScript = FALSE; @@ -91,7 +89,7 @@ void sequence_channel_init(struct SequenceChannel *seqChannel) seqChannel->freqScale = 1.0f; #endif - for (i = 0; i < 8; i++) + for (s32 i = 0; i < 8; i++) { seqChannel->soundScriptIO[i] = -1; } @@ -200,8 +198,7 @@ void seq_channel_layer_free(struct SequenceChannel *seqChannel, s32 layerIndex) void sequence_channel_disable(struct SequenceChannel *seqChannel) { - s32 i; - for (i = 0; i < LAYERS_MAX; i++) + for (s32 i = 0; i < LAYERS_MAX; i++) { seq_channel_layer_free(seqChannel, i); } @@ -213,8 +210,7 @@ void sequence_channel_disable(struct SequenceChannel *seqChannel) struct SequenceChannel *allocate_sequence_channel(void) { - s32 i; - for (i = 0; i < ARRAY_COUNT(gSequenceChannels); i++) + for (s32 i = 0; i < ARRAY_COUNT(gSequenceChannels); i++) { if (gSequenceChannels[i].seqPlayer == NULL) { @@ -230,14 +226,11 @@ struct SequenceChannel *allocate_sequence_channel(void) void sequence_player_init_channels(struct SequencePlayer *seqPlayer, u16 channelBits) { - struct SequenceChannel *seqChannel; - s32 i; - - for (i = 0; i < CHANNELS_MAX; i++) + for (s32 i = 0; i < CHANNELS_MAX; i++) { if (channelBits & 1) { - seqChannel = seqPlayer->channels[i]; + struct SequenceChannel *seqChannel = seqPlayer->channels[i]; if (IS_SEQUENCE_CHANNEL_VALID(seqChannel) == TRUE && seqChannel->seqPlayer == seqPlayer) { sequence_channel_disable(seqChannel); @@ -270,15 +263,12 @@ void sequence_player_init_channels(struct SequencePlayer *seqPlayer, u16 channel void sequence_player_disable_channels(struct SequencePlayer *seqPlayer, u16 channelBits) { - struct SequenceChannel *seqChannel; - s32 i; - eu_stubbed_printf_0("SUBTRACK DIM\n"); - for (i = 0; i < CHANNELS_MAX; i++) + for (s32 i = 0; i < CHANNELS_MAX; i++) { if (channelBits & 1) { - seqChannel = seqPlayer->channels[i]; + struct SequenceChannel *seqChannel = seqPlayer->channels[i]; if (IS_SEQUENCE_CHANNEL_VALID(seqChannel) == TRUE) { if (seqChannel->seqPlayer == seqPlayer) @@ -307,7 +297,6 @@ void sequence_player_disable_channels(struct SequencePlayer *seqPlayer, u16 chan void sequence_channel_enable(struct SequencePlayer *seqPlayer, u8 channelIndex, void *script) { struct SequenceChannel *seqChannel = seqPlayer->channels[channelIndex]; - s32 i; if (IS_SEQUENCE_CHANNEL_VALID(seqChannel) == FALSE) { #ifdef VERSION_EU @@ -337,7 +326,7 @@ void sequence_channel_enable(struct SequencePlayer *seqPlayer, u8 channelIndex, seqChannel->scriptState.depth = 0; seqChannel->scriptState.pc = script; seqChannel->delay = 0; - for (i = 0; i < LAYERS_MAX; i++) + for (s32 i = 0; i < LAYERS_MAX; i++) { if (seqChannel->layers[i] != NULL) { @@ -439,14 +428,12 @@ void *audio_list_pop_back(struct AudioListItem *list) void init_layer_freelist(void) { - s32 i; - gLayerFreeList.prev = &gLayerFreeList; gLayerFreeList.next = &gLayerFreeList; gLayerFreeList.u.count = 0; gLayerFreeList.pool = NULL; - for (i = 0; i < ARRAY_COUNT(gSequenceLayers); i++) + for (s32 i = 0; i < ARRAY_COUNT(gSequenceLayers); i++) { #if defined(VERSION_EU) || defined(VERSION_SH) gSequenceLayers[i].listItem.u.value = &gSequenceLayers[i]; @@ -1673,9 +1660,6 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) { DEBUG_PRINT("sequence_channel_process_script()"); - struct M64ScriptState *state; - struct SequencePlayer *seqPlayer; - u8 cmd; s8 temp; u8 loBits; u16 sp5A; @@ -1701,7 +1685,7 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) return; } - seqPlayer = seqChannel->seqPlayer; + struct SequencePlayer *seqPlayer = seqChannel->seqPlayer; if (seqPlayer->muted && (seqChannel->muteBehavior & MUTE_BEHAVIOR_STOP_SCRIPT) != 0) { return; @@ -1712,12 +1696,12 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) seqChannel->delay--; } - state = &seqChannel->scriptState; + struct M64ScriptState *state = &seqChannel->scriptState; if (seqChannel->delay == 0) { for (;;) { - cmd = m64_read_u8(state); + u8 cmd = m64_read_u8(state); DEBUG_PRINT("- handling command: %x", cmd); #if !defined(VERSION_EU) && !defined(VERSION_SH) @@ -2073,11 +2057,10 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) case 0xc7: // chan_writeseq; write to sequence data (!) { #if !defined(VERSION_EU) && !defined(VERSION_SH) - u8 *seqData; #endif cmd = m64_read_u8(state); sp5A = m64_read_s16(state); - seqData = seqPlayer->seqData + sp5A; + u8 *seqData = seqPlayer->seqData + sp5A; *seqData = (u8)value + cmd; } break; @@ -2489,7 +2472,6 @@ void sequence_player_process_sequence(struct SequencePlayer *seqPlayer) u8 loBits; u8 temp; s32 value; - s32 i; u16 u16v; u8 *seqData; struct M64ScriptState *state; @@ -3029,7 +3011,7 @@ void sequence_player_process_sequence(struct SequencePlayer *seqPlayer) } } - for (i = 0; i < CHANNELS_MAX; i++) + for (s32 i = 0; i < CHANNELS_MAX; i++) { #if defined(VERSION_EU) || defined(VERSION_SH) if (IS_SEQUENCE_CHANNEL_VALID(seqPlayer->channels[i]) == TRUE) @@ -3048,8 +3030,7 @@ void sequence_player_process_sequence(struct SequencePlayer *seqPlayer) // This runs 240 times per second. void process_sequences(UNUSED s32 iterationsRemaining) { - s32 i; - for (i = 0; i < SEQUENCE_PLAYERS; i++) + for (s32 i = 0; i < SEQUENCE_PLAYERS; i++) { if (gSequencePlayers[i].enabled == TRUE) { diff --git a/src/decomp/audio/synthesis.c b/src/decomp/audio/synthesis.c index f541030..57dd154 100644 --- a/src/decomp/audio/synthesis.c +++ b/src/decomp/audio/synthesis.c @@ -171,9 +171,6 @@ void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex) struct ReverbRingBufferItem *item; s32 srcPos; s32 dstPos; - s32 nSamples; - s32 numSamplesAfterDownsampling; - s32 excessiveSamples; if (gReverbDownsampleRate != 1) { if (gSynthesisReverb.framesLeftToIgnore == 0) @@ -202,7 +199,7 @@ void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex) } item = &gSynthesisReverb.items[gSynthesisReverb.curFrame][updateIndex]; - numSamplesAfterDownsampling = chunkLen / gReverbDownsampleRate; + s32 numSamplesAfterDownsampling = chunkLen / gReverbDownsampleRate; if (numSamplesAfterDownsampling + gSynthesisReverb.nextRingBufferPos - gSynthesisReverb.bufSizePerChannel < 0) { // There is space in the ring buffer before it wraps around @@ -214,9 +211,8 @@ void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex) else { // Ring buffer wrapped around - excessiveSamples = - numSamplesAfterDownsampling + gSynthesisReverb.nextRingBufferPos - gSynthesisReverb.bufSizePerChannel; - nSamples = numSamplesAfterDownsampling - excessiveSamples; + s32 excessiveSamples = numSamplesAfterDownsampling + gSynthesisReverb.nextRingBufferPos - gSynthesisReverb.bufSizePerChannel; + s32 nSamples = numSamplesAfterDownsampling - excessiveSamples; item->lengthA = nSamples * 2; item->lengthB = excessiveSamples * 2; item->startPos = gSynthesisReverb.nextRingBufferPos; @@ -368,14 +364,12 @@ u64 *synthesis_execute(u64 *cmdBuf, s32 *writtenCmds, s16 *aiBuf, s32 bufLen) { DEBUG_PRINT("synthesis_execute()"); s32 chunkLen; - s32 i; u32 *aiBufPtr = (u32 *)aiBuf; u64 *cmd = cmdBuf + 1; - s32 v0; aSegment(cmdBuf, 0, 0); - for (i = gAudioUpdatesPerFrame; i > 0; i--) + for (s32 i = gAudioUpdatesPerFrame; i > 0; i--) { if (i == 1) { @@ -384,7 +378,7 @@ u64 *synthesis_execute(u64 *cmdBuf, s32 *writtenCmds, s16 *aiBuf, s32 bufLen) } else { - v0 = bufLen / i; + s32 v0 = bufLen / i; // chunkLen = v0 rounded to nearest multiple of 8 chunkLen = v0 - (v0 & 7); @@ -592,17 +586,14 @@ u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateI DEBUG_PRINT("synthesis_do_one_audio_update()"); UNUSED s32 pad1[1]; - s16 ra; - s16 t4; UNUSED s32 pad[2]; - struct ReverbRingBufferItem *v1; UNUSED s32 pad2[1]; s16 temp; DEBUG_PRINT("- curFrame: %d", gSynthesisReverb.curFrame); DEBUG_PRINT("- updateIndex: %d", updateIndex); - v1 = &gSynthesisReverb.items[gSynthesisReverb.curFrame][updateIndex]; + struct ReverbRingBufferItem *v1 = &gSynthesisReverb.items[gSynthesisReverb.curFrame][updateIndex]; DEBUG_PRINT("- v1: %x", v1); if (gSynthesisReverb.useReverb == 0) @@ -649,8 +640,8 @@ u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateI // Same as above but upsample the previously downsampled samples used for reverb first temp = 0; //! jesus christ - t4 = (v1->startPos & 7) * 2; - ra = ALIGN(v1->lengthA + t4, 4); + 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) @@ -1126,16 +1117,14 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) u64 *load_wave_samples(u64 *cmd, struct Note *note, s32 nSamplesToLoad) { - s32 a3; - s32 i; aSetBuffer(cmd++, /*flags*/ 0, /*dmemin*/ DMEM_ADDR_UNCOMPRESSED_NOTE, /*dmemout*/ 0, /*count*/ sizeof(note->synthesisBuffers->samples)); aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->samples)); note->samplePosInt &= note->sampleCount - 1; - a3 = 64 - note->samplePosInt; + s32 a3 = 64 - note->samplePosInt; if (a3 < nSamplesToLoad) { - for (i = 0; i <= (nSamplesToLoad - a3 + 63) / 64 - 1; i++) + for (s32 i = 0; i <= (nSamplesToLoad - a3 + 63) / 64 - 1; i++) { aDMEMMove(cmd++, /*dmemin*/ DMEM_ADDR_UNCOMPRESSED_NOTE, /*dmemout*/ DMEM_ADDR_UNCOMPRESSED_NOTE + (1 + i) * sizeof(note->synthesisBuffers->samples), /*count*/ sizeof(note->synthesisBuffers->samples)); } @@ -1522,10 +1511,8 @@ void note_set_vel_pan_reverb(struct Note *note, f32 velocity, f32 pan, u8 reverb } else if (note->stereoHeadsetEffects && gSoundMode == SOUND_MODE_STEREO) { - u8 strongLeft; - u8 strongRight; - strongLeft = FALSE; - strongRight = FALSE; + u8 strongLeft = FALSE; + u8 strongRight = FALSE; note->headsetPanLeft = 0; note->headsetPanRight = 0; note->usesHeadsetPanEffects = FALSE; diff --git a/src/decomp/engine/geo_layout.c b/src/decomp/engine/geo_layout.c index 75f3bf4..2e0eedc 100644 --- a/src/decomp/engine/geo_layout.c +++ b/src/decomp/engine/geo_layout.c @@ -214,9 +214,6 @@ void geo_layout_cmd_update_node_flags(void) */ void geo_layout_cmd_node_root(void) { - s32 i; - struct GraphNodeRoot *graphNode; - s16 x = cur_geo_cmd_s16(0x04); s16 y = cur_geo_cmd_s16(0x06); s16 width = cur_geo_cmd_s16(0x08); @@ -227,7 +224,7 @@ void geo_layout_cmd_node_root(void) // cmd+0x02 = 0x00: Mario face, 0x0A: all other levels gGeoNumViews = cur_geo_cmd_s16(0x02) + 2; - graphNode = init_graph_node_root(gGraphNodePool, NULL, 0, x, y, width, height); + struct GraphNodeRoot *graphNode = init_graph_node_root(gGraphNodePool, NULL, 0, x, y, width, height); // gGeoViews is unused in libsm64 gGeoViews = NULL; // alloc_only_pool_alloc(gGraphNodePool, gGeoNumViews * sizeof(struct GraphNode *)); @@ -235,7 +232,7 @@ void geo_layout_cmd_node_root(void) graphNode->views = gGeoViews; graphNode->numViews = gGeoNumViews; - for (i = 0; i < gGeoNumViews; i++) + for (s32 i = 0; i < gGeoNumViews; i++) { gGeoViews[i] = NULL; } @@ -251,10 +248,9 @@ void geo_layout_cmd_node_root(void) */ void geo_layout_cmd_node_ortho_projection(void) { - struct GraphNodeOrthoProjection *graphNode; f32 scale = (f32)cur_geo_cmd_s16(0x02) / 100.0f; - graphNode = init_graph_node_ortho_projection(gGraphNodePool, NULL, scale); + struct GraphNodeOrthoProjection *graphNode = init_graph_node_ortho_projection(gGraphNodePool, NULL, scale); register_scene_graph_node(&graphNode->node); @@ -271,7 +267,6 @@ void geo_layout_cmd_node_ortho_projection(void) */ void geo_layout_cmd_node_perspective(void) { - struct GraphNodePerspective *graphNode; GraphNodeFunc frustumFunc = NULL; s16 fov = cur_geo_cmd_s16(0x02); s16 near = cur_geo_cmd_s16(0x04); @@ -284,7 +279,7 @@ void geo_layout_cmd_node_perspective(void) gGeoLayoutCommand += 4 << CMD_SIZE_SHIFT; } - graphNode = init_graph_node_perspective(gGraphNodePool, NULL, fov, near, far, frustumFunc, 0); + struct GraphNodePerspective *graphNode = init_graph_node_perspective(gGraphNodePool, NULL, fov, near, far, frustumFunc, 0); register_scene_graph_node(&graphNode->fnNode.node); @@ -297,9 +292,7 @@ void geo_layout_cmd_node_perspective(void) */ void geo_layout_cmd_node_start(void) { - struct GraphNodeStart *graphNode; - - graphNode = init_graph_node_start(gGraphNodePool, NULL); + struct GraphNodeStart *graphNode = init_graph_node_start(gGraphNodePool, NULL); register_scene_graph_node(&graphNode->node); @@ -318,9 +311,7 @@ void geo_layout_cmd_nop3(void) */ void geo_layout_cmd_node_master_list(void) { - struct GraphNodeMasterList *graphNode; - - graphNode = init_graph_node_master_list(gGraphNodePool, NULL, cur_geo_cmd_u8(0x01)); + struct GraphNodeMasterList *graphNode = init_graph_node_master_list(gGraphNodePool, NULL, cur_geo_cmd_u8(0x01)); register_scene_graph_node(&graphNode->node); @@ -335,11 +326,10 @@ void geo_layout_cmd_node_master_list(void) */ void geo_layout_cmd_node_level_of_detail(void) { - struct GraphNodeLevelOfDetail *graphNode; s16 minDistance = cur_geo_cmd_s16(0x04); s16 maxDistance = cur_geo_cmd_s16(0x06); - graphNode = init_graph_node_render_range(gGraphNodePool, NULL, minDistance, maxDistance); + struct GraphNodeLevelOfDetail *graphNode = init_graph_node_render_range(gGraphNodePool, NULL, minDistance, maxDistance); register_scene_graph_node(&graphNode->node); @@ -356,14 +346,11 @@ void geo_layout_cmd_node_level_of_detail(void) */ void geo_layout_cmd_node_switch_case(void) { - struct GraphNodeSwitchCase *graphNode; - - graphNode = - init_graph_node_switch_case(gGraphNodePool, NULL, - cur_geo_cmd_s16(0x02), // case which is initially selected - 0, - cur_geo_cmd_ptr(0x04), // case update function - 0); + struct GraphNodeSwitchCase *graphNode = init_graph_node_switch_case(gGraphNodePool, NULL, + cur_geo_cmd_s16(0x02), // case which is initially selected + 0, + cur_geo_cmd_ptr(0x04), // case update function + 0); register_scene_graph_node(&graphNode->fnNode.node); @@ -383,7 +370,6 @@ void geo_layout_cmd_node_switch_case(void) */ void geo_layout_cmd_node_camera(void) { - struct GraphNodeCamera *graphNode; s16 *cmdPos = (s16 *)&gGeoLayoutCommand[4]; Vec3f pos, focus; @@ -391,8 +377,8 @@ void geo_layout_cmd_node_camera(void) cmdPos = read_vec3s_to_vec3f(pos, cmdPos); cmdPos = read_vec3s_to_vec3f(focus, cmdPos); - graphNode = init_graph_node_camera(gGraphNodePool, NULL, pos, focus, - cur_geo_cmd_ptr(0x10), cur_geo_cmd_s16(0x02)); + struct GraphNodeCamera *graphNode = init_graph_node_camera(gGraphNodePool, NULL, pos, focus, + cur_geo_cmd_ptr(0x10), cur_geo_cmd_s16(0x02)); register_scene_graph_node(&graphNode->fnNode.node); @@ -437,8 +423,6 @@ void geo_layout_cmd_node_camera(void) */ void geo_layout_cmd_node_translation_rotation(void) { - struct GraphNodeTranslationRotation *graphNode; - Vec3s translation, rotation; void *displayList = NULL; @@ -475,8 +459,8 @@ void geo_layout_cmd_node_translation_rotation(void) cmdPos += 2 << CMD_SIZE_SHIFT; } - graphNode = init_graph_node_translation_rotation(gGraphNodePool, NULL, drawingLayer, displayList, - translation, rotation); + struct GraphNodeTranslationRotation *graphNode = init_graph_node_translation_rotation(gGraphNodePool, NULL, drawingLayer, displayList, + translation, rotation); register_scene_graph_node(&graphNode->node); gGeoLayoutCommand = (u8 *)cmdPos; @@ -494,8 +478,6 @@ void geo_layout_cmd_node_translation_rotation(void) */ void geo_layout_cmd_node_translation(void) { - struct GraphNodeTranslation *graphNode; - Vec3s translation; s16 drawingLayer = 0; @@ -512,8 +494,7 @@ void geo_layout_cmd_node_translation(void) cmdPos += 2 << CMD_SIZE_SHIFT; } - graphNode = - init_graph_node_translation(gGraphNodePool, NULL, drawingLayer, displayList, translation); + struct GraphNodeTranslation *graphNode = init_graph_node_translation(gGraphNodePool, NULL, drawingLayer, displayList, translation); register_scene_graph_node(&graphNode->node); @@ -532,8 +513,6 @@ void geo_layout_cmd_node_translation(void) */ void geo_layout_cmd_node_rotation(void) { - struct GraphNodeRotation *graphNode; - Vec3s sp2c; s16 drawingLayer = 0; @@ -550,7 +529,7 @@ void geo_layout_cmd_node_rotation(void) cmdPos += 2 << CMD_SIZE_SHIFT; } - graphNode = init_graph_node_rotation(gGraphNodePool, NULL, drawingLayer, displayList, sp2c); + struct GraphNodeRotation *graphNode = init_graph_node_rotation(gGraphNodePool, NULL, drawingLayer, displayList, sp2c); register_scene_graph_node(&graphNode->node); @@ -567,8 +546,6 @@ void geo_layout_cmd_node_rotation(void) */ void geo_layout_cmd_node_scale(void) { - struct GraphNodeScale *graphNode; - s16 drawingLayer = 0; s16 params = cur_geo_cmd_u8(0x01); f32 scale = cur_geo_cmd_u32(0x04) / 65536.0f; @@ -581,7 +558,7 @@ void geo_layout_cmd_node_scale(void) gGeoLayoutCommand += 4 << CMD_SIZE_SHIFT; } - graphNode = init_graph_node_scale(gGraphNodePool, NULL, drawingLayer, displayList, scale); + struct GraphNodeScale *graphNode = init_graph_node_scale(gGraphNodePool, NULL, drawingLayer, displayList, scale); register_scene_graph_node(&graphNode->node); @@ -604,7 +581,6 @@ void geo_layout_cmd_nop2(void) */ void geo_layout_cmd_node_animated_part(void) { - struct GraphNodeAnimatedPart *graphNode; Vec3s translation; s32 drawingLayer = cur_geo_cmd_u8(0x01); void *displayList = cur_geo_cmd_ptr(0x08); @@ -612,8 +588,7 @@ void geo_layout_cmd_node_animated_part(void) read_vec3s(translation, &cmdPos[1]); - graphNode = - init_graph_node_animated_part(gGraphNodePool, NULL, drawingLayer, displayList, translation); + struct GraphNodeAnimatedPart *graphNode = init_graph_node_animated_part(gGraphNodePool, NULL, drawingLayer, displayList, translation); register_scene_graph_node(&graphNode->node); @@ -632,7 +607,6 @@ void geo_layout_cmd_node_animated_part(void) */ void geo_layout_cmd_node_billboard(void) { - struct GraphNodeBillboard *graphNode; Vec3s translation; s16 drawingLayer = 0; s16 params = cur_geo_cmd_u8(0x01); @@ -648,7 +622,7 @@ void geo_layout_cmd_node_billboard(void) cmdPos += 2 << CMD_SIZE_SHIFT; } - graphNode = init_graph_node_billboard(gGraphNodePool, NULL, drawingLayer, displayList, translation); + struct GraphNodeBillboard *graphNode = init_graph_node_billboard(gGraphNodePool, NULL, drawingLayer, displayList, translation); register_scene_graph_node(&graphNode->node); @@ -662,11 +636,10 @@ void geo_layout_cmd_node_billboard(void) */ void geo_layout_cmd_node_display_list(void) { - struct GraphNodeDisplayList *graphNode; s32 drawingLayer = cur_geo_cmd_u8(0x01); void *displayList = cur_geo_cmd_ptr(0x04); - graphNode = init_graph_node_display_list(gGraphNodePool, NULL, drawingLayer, displayList); + struct GraphNodeDisplayList *graphNode = init_graph_node_display_list(gGraphNodePool, NULL, drawingLayer, displayList); register_scene_graph_node(&graphNode->node); @@ -681,12 +654,11 @@ void geo_layout_cmd_node_display_list(void) */ void geo_layout_cmd_node_shadow(void) { - struct GraphNodeShadow *graphNode; u8 shadowType = cur_geo_cmd_s16(0x02); u8 shadowSolidity = cur_geo_cmd_s16(0x04); s16 shadowScale = cur_geo_cmd_s16(0x06); - graphNode = init_graph_node_shadow(gGraphNodePool, NULL, shadowScale, shadowSolidity, shadowType); + struct GraphNodeShadow *graphNode = init_graph_node_shadow(gGraphNodePool, NULL, shadowScale, shadowSolidity, shadowType); register_scene_graph_node(&graphNode->node); @@ -696,9 +668,7 @@ void geo_layout_cmd_node_shadow(void) // 0x17: Create scene graph node that manages the group of all object nodes void geo_layout_cmd_node_object_parent(void) { - struct GraphNodeObjectParent *graphNode; - - graphNode = init_graph_node_object_parent(gGraphNodePool, NULL, &gObjParentGraphNode); + struct GraphNodeObjectParent *graphNode = init_graph_node_object_parent(gGraphNodePool, NULL, &gObjParentGraphNode); register_scene_graph_node(&graphNode->node); @@ -712,11 +682,9 @@ void geo_layout_cmd_node_object_parent(void) */ void geo_layout_cmd_node_generated(void) { - struct GraphNodeGenerated *graphNode; - - graphNode = init_graph_node_generated(gGraphNodePool, NULL, - cur_geo_cmd_ptr(0x04), // asm function - cur_geo_cmd_s16(0x02)); // parameter + struct GraphNodeGenerated *graphNode = init_graph_node_generated(gGraphNodePool, NULL, + cur_geo_cmd_ptr(0x04), // asm function + cur_geo_cmd_s16(0x02)); // parameter register_scene_graph_node(&graphNode->fnNode.node); @@ -730,9 +698,7 @@ void geo_layout_cmd_node_generated(void) */ void geo_layout_cmd_node_background(void) { - struct GraphNodeBackground *graphNode; - - graphNode = init_graph_node_background( + struct GraphNodeBackground *graphNode = init_graph_node_background( gGraphNodePool, NULL, cur_geo_cmd_s16(0x02), // background ID, or RGBA5551 color if asm function is null cur_geo_cmd_ptr(0x04), // asm function @@ -756,7 +722,6 @@ void geo_layout_cmd_nop(void) */ void geo_layout_cmd_copy_view(void) { - struct GraphNodeObjectParent *graphNode; struct GraphNode *node = NULL; s16 index = cur_geo_cmd_s16(0x02); @@ -774,7 +739,7 @@ void geo_layout_cmd_copy_view(void) } } - graphNode = init_graph_node_object_parent(gGraphNodePool, NULL, node); + struct GraphNodeObjectParent *graphNode = init_graph_node_object_parent(gGraphNodePool, NULL, node); register_scene_graph_node(&graphNode->node); @@ -791,12 +756,11 @@ void geo_layout_cmd_copy_view(void) */ void geo_layout_cmd_node_held_obj(void) { - struct GraphNodeHeldObject *graphNode; Vec3s offset; read_vec3s(offset, (s16 *)&gGeoLayoutCommand[0x02]); - graphNode = init_graph_node_held_object( + struct GraphNodeHeldObject *graphNode = init_graph_node_held_object( gGraphNodePool, NULL, NULL, offset, cur_geo_cmd_ptr(0x08), cur_geo_cmd_u8(0x01)); register_scene_graph_node(&graphNode->fnNode.node); @@ -811,8 +775,7 @@ void geo_layout_cmd_node_held_obj(void) */ void geo_layout_cmd_node_culling_radius(void) { - struct GraphNodeCullingRadius *graphNode; - graphNode = init_graph_node_culling_radius(gGraphNodePool, NULL, cur_geo_cmd_s16(0x02)); + struct GraphNodeCullingRadius *graphNode = init_graph_node_culling_radius(gGraphNodePool, NULL, cur_geo_cmd_s16(0x02)); register_scene_graph_node(&graphNode->node); gGeoLayoutCommand += 0x04 << CMD_SIZE_SHIFT; } diff --git a/src/decomp/engine/graph_node.c b/src/decomp/engine/graph_node.c index 0ece64b..580db8f 100644 --- a/src/decomp/engine/graph_node.c +++ b/src/decomp/engine/graph_node.c @@ -618,13 +618,10 @@ struct GraphNodeHeldObject *init_graph_node_held_object( */ struct GraphNode *geo_add_child(struct GraphNode *parent, struct GraphNode *childNode) { - struct GraphNode *parentFirstChild; - struct GraphNode *parentLastChild; - if (childNode != NULL) { childNode->parent = parent; - parentFirstChild = parent->children; + struct GraphNode *parentFirstChild = parent->children; if (parentFirstChild == NULL) { @@ -634,7 +631,7 @@ struct GraphNode *geo_add_child(struct GraphNode *parent, struct GraphNode *chil } else { - parentLastChild = parentFirstChild->prev; + struct GraphNode *parentLastChild = parentFirstChild->prev; childNode->prev = parentLastChild; childNode->next = parentFirstChild; parentFirstChild->prev = childNode; @@ -653,11 +650,8 @@ struct GraphNode *geo_add_child(struct GraphNode *parent, struct GraphNode *chil */ struct GraphNode *geo_remove_child(struct GraphNode *graphNode) { - struct GraphNode *parent; - struct GraphNode **firstChild; - - parent = graphNode->parent; - firstChild = &parent->children; + struct GraphNode *parent = graphNode->parent; + struct GraphNode **firstChild = &parent->children; // Remove link with siblings graphNode->prev->next = graphNode->next; @@ -688,12 +682,8 @@ struct GraphNode *geo_remove_child(struct GraphNode *graphNode) */ struct GraphNode *geo_make_first_child(struct GraphNode *newFirstChild) { - struct GraphNode *lastSibling; - struct GraphNode *parent; - struct GraphNode **firstChild; - - parent = newFirstChild->parent; - firstChild = &parent->children; + struct GraphNode *parent = newFirstChild->parent; + struct GraphNode **firstChild = &parent->children; if (*firstChild != newFirstChild) { @@ -701,7 +691,7 @@ struct GraphNode *geo_make_first_child(struct GraphNode *newFirstChild) { newFirstChild->prev->next = newFirstChild->next; newFirstChild->next->prev = newFirstChild->prev; - lastSibling = (*firstChild)->prev; + struct GraphNode *lastSibling = (*firstChild)->prev; newFirstChild->prev = lastSibling; newFirstChild->next = *firstChild; (*firstChild)->prev = newFirstChild; @@ -720,14 +710,12 @@ struct GraphNode *geo_make_first_child(struct GraphNode *newFirstChild) void geo_call_global_function_nodes_helper(struct GraphNode *graphNode, s32 callContext) { struct GraphNode **globalPtr; - struct GraphNode *curNode; - struct FnGraphNode *asFnNode; - curNode = graphNode; + struct GraphNode *curNode = graphNode; do { - asFnNode = (struct FnGraphNode *)curNode; + struct FnGraphNode *asFnNode = (struct FnGraphNode *)curNode; if (curNode->type & GRAPH_NODE_TYPE_FUNCTIONAL) { @@ -922,9 +910,8 @@ s32 retrieve_animation_index(s32 frame, u16 **attributes) s16 geo_update_animation_frame(struct AnimInfo *obj, s32 *accelAssist) { s32 result; - struct Animation *anim; - anim = obj->curAnim; + struct Animation *anim = obj->curAnim; if (obj->animTimer == gAreaUpdateCounter || anim->flags & ANIM_FLAG_2) { @@ -1003,15 +990,13 @@ void geo_retreive_animation_translation(struct GraphNodeObject *obj, Vec3f posit { struct Animation *animation = obj->animInfo.curAnim; u16 *attribute; - s16 *values; - s16 frame; if (animation != NULL) { attribute = segmented_to_virtual(animation->index); - values = segmented_to_virtual(animation->values); + s16 *values = segmented_to_virtual(animation->values); - frame = obj->animInfo.animFrame; + s16 frame = obj->animInfo.animFrame; if (frame < 0) { diff --git a/src/decomp/engine/graph_node_manager.c b/src/decomp/engine/graph_node_manager.c index de458f2..829fb77 100644 --- a/src/decomp/engine/graph_node_manager.c +++ b/src/decomp/engine/graph_node_manager.c @@ -8,12 +8,11 @@ #if IS_64_BIT static s16 next_s16_in_geo_script(s16 **src) { - s16 ret; if (((uintptr_t) * src & 7) == 4) { *src += 2; // skip 32 bits } - ret = *(*src)++; + s16 ret = *(*src)++; if (((uintptr_t) * src & 7) == 4) { *src += 2; // skip 32 bits diff --git a/src/decomp/engine/guMtxF2L.c b/src/decomp/engine/guMtxF2L.c index a635df7..770e676 100644 --- a/src/decomp/engine/guMtxF2L.c +++ b/src/decomp/engine/guMtxF2L.c @@ -60,10 +60,9 @@ void guMtxL2F(float mf[4][4], Mtx *m) void guMtxIdentF(float mf[4][4]) { - int r, c; - for (r = 0; r < 4; r++) + for (int r = 0; r < 4; r++) { - for (c = 0; c < 4; c++) + for (int c = 0; c < 4; c++) { if (r == c) { diff --git a/src/decomp/engine/math_util.c b/src/decomp/engine/math_util.c index 1532813..35a6004 100644 --- a/src/decomp/engine/math_util.c +++ b/src/decomp/engine/math_util.c @@ -1591,11 +1591,10 @@ void *vec3f_normalize(Vec3f dest) /// Copy matrix 'src' to 'dest' void mtxf_copy(Mat4 dest, Mat4 src) { - register s32 i; register u32 *d = (u32 *)dest; register u32 *s = (u32 *)src; - for (i = 0; i < 16; i++) + for (register s32 i = 0; i < 16; i++) { *d++ = *s++; } @@ -1636,42 +1635,29 @@ void mtxf_translate(Mat4 dest, Vec3f b) */ void mtxf_lookat(Mat4 mtx, Vec3f from, Vec3f to, s16 roll) { - register f32 invLength; - f32 dx; - f32 dz; - f32 xColY; - f32 yColY; - f32 zColY; - f32 xColZ; - f32 yColZ; - f32 zColZ; - f32 xColX; - f32 yColX; - f32 zColX; + f32 dx = to[0] - from[0]; + f32 dz = to[2] - from[2]; - dx = to[0] - from[0]; - dz = to[2] - from[2]; - - invLength = -1.0 / sqrtf(dx * dx + dz * dz); + register f32 invLength = -1.0 / sqrtf(dx * dx + dz * dz); dx *= invLength; dz *= invLength; - yColY = coss(roll); - xColY = sins(roll) * dz; - zColY = -sins(roll) * dx; + f32 yColY = coss(roll); + f32 xColY = sins(roll) * dz; + f32 zColY = -sins(roll) * dx; - xColZ = to[0] - from[0]; - yColZ = to[1] - from[1]; - zColZ = to[2] - from[2]; + f32 xColZ = to[0] - from[0]; + f32 yColZ = to[1] - from[1]; + f32 zColZ = to[2] - from[2]; invLength = -1.0 / sqrtf(xColZ * xColZ + yColZ * yColZ + zColZ * zColZ); xColZ *= invLength; yColZ *= invLength; zColZ *= invLength; - xColX = yColY * zColZ - zColY * yColZ; - yColX = zColY * xColZ - xColY * zColZ; - zColX = xColY * yColZ - yColY * xColZ; + f32 xColX = yColY * zColZ - zColY * yColZ; + f32 yColX = zColY * xColZ - xColY * zColZ; + f32 zColX = xColY * yColZ - yColY * xColZ; invLength = 1.0 / sqrtf(xColX * xColX + yColX * yColX + zColX * zColX); @@ -1872,7 +1858,6 @@ void mtxf_align_terrain_triangle(Mat4 mtx, Vec3f pos, s16 yaw, f32 radius) Vec3f xColumn; Vec3f yColumn; Vec3f zColumn; - f32 avgY; f32 minY = -radius * 3; point0[0] = pos[0] + radius * sins(yaw + 0x2AAA); @@ -1901,7 +1886,7 @@ void mtxf_align_terrain_triangle(Mat4 mtx, Vec3f pos, s16 yaw, f32 radius) point2[1] = pos[1]; } - avgY = (point0[1] + point1[1] + point2[1]) / 3; + f32 avgY = (point0[1] + point1[1] + point2[1]) / 3; vec3f_set(forward, sins(yaw), 0, coss(yaw)); find_vector_perpendicular_to_plane(yColumn, point0, point1, point2); @@ -1943,14 +1928,11 @@ void mtxf_align_terrain_triangle(Mat4 mtx, Vec3f pos, s16 yaw, f32 radius) void mtxf_mul(Mat4 dest, Mat4 a, Mat4 b) { Mat4 temp; - register f32 entry0; - register f32 entry1; - register f32 entry2; // column 0 - entry0 = a[0][0]; - entry1 = a[0][1]; - entry2 = a[0][2]; + register f32 entry0 = a[0][0]; + register f32 entry1 = a[0][1]; + register f32 entry2 = a[0][2]; temp[0][0] = entry0 * b[0][0] + entry1 * b[1][0] + entry2 * b[2][0]; temp[0][1] = entry0 * b[0][1] + entry1 * b[1][1] + entry2 * b[2][1]; temp[0][2] = entry0 * b[0][2] + entry1 * b[1][2] + entry2 * b[2][2]; @@ -1990,9 +1972,7 @@ void mtxf_mul(Mat4 dest, Mat4 a, Mat4 b) */ void mtxf_scale_vec3f(Mat4 dest, Mat4 mtx, Vec3f s) { - register s32 i; - - for (i = 0; i < 4; i++) + for (register s32 i = 0; i < 4; i++) { dest[0][i] = mtx[0][i] * s[0]; dest[1][i] = mtx[1][i] * s[1]; @@ -2363,12 +2343,11 @@ void anim_spline_init(Vec4s *keyFrames) s32 anim_spline_poll(Vec3f result) { Vec4f weights; - s32 i; s32 hasEnded = FALSE; vec3f_copy(result, gVec3fZero); spline_get_weights(weights, gSplineKeyframeFraction, gSplineState); - for (i = 0; i < 4; i++) + for (s32 i = 0; i < 4; i++) { result[0] += weights[i] * gSplineKeyframe[i][1]; result[1] += weights[i] * gSplineKeyframe[i][2]; @@ -2412,8 +2391,7 @@ s32 anim_spline_poll(Vec3f result) */ void linear_mtxf_mul_vec3f(Mat4 m, Vec3f dst, Vec3f v) { - s32 i; - for (i = 0; i < 3; i++) + for (s32 i = 0; i < 3; i++) { dst[i] = m[0][i] * v[0] + m[1][i] * v[1] + m[2][i] * v[2]; } @@ -2429,8 +2407,7 @@ void linear_mtxf_mul_vec3f(Mat4 m, Vec3f dst, Vec3f v) */ void linear_mtxf_transpose_mul_vec3f(Mat4 m, Vec3f dst, Vec3f v) { - s32 i; - for (i = 0; i < 3; i++) + for (s32 i = 0; i < 3; i++) { dst[i] = m[i][0] * v[0] + m[i][1] * v[1] + m[i][2] * v[2]; } diff --git a/src/decomp/engine/surface_collision.c b/src/decomp/engine/surface_collision.c index 8424c8c..2b98d2e 100644 --- a/src/decomp/engine/surface_collision.c +++ b/src/decomp/engine/surface_collision.c @@ -10,8 +10,6 @@ */ static struct SM64SurfaceCollisionData *find_ceil_from_list(f32 x, f32 y, f32 z, f32 *pheight) { - register struct SM64SurfaceCollisionData *surf; - register f32 x1, z1, x2, z2, x3, z3; struct SM64SurfaceCollisionData *ceil = NULL; ceil = NULL; @@ -22,7 +20,7 @@ static struct SM64SurfaceCollisionData *find_ceil_from_list(f32 x, f32 y, f32 z, uint32_t surfCount = loaded_surface_iter_group_size(i); for (int j = 0; j < surfCount; ++j) { - surf = loaded_surface_iter_get_at_index(i, j); + register struct SM64SurfaceCollisionData *surf = loaded_surface_iter_get_at_index(i, j); // libsm64: Weed out surfaces whose triangles are actually line segs. TODO do this at surface load time if (!surf->isValid) continue; @@ -30,10 +28,10 @@ static struct SM64SurfaceCollisionData *find_ceil_from_list(f32 x, f32 y, f32 z, // Do the check normally done in add_surface_to_cell if (surf->normal.y >= -0.01f) continue; - x1 = surf->vertex1[0]; - z1 = surf->vertex1[2]; - z2 = surf->vertex2[2]; - x2 = surf->vertex2[0]; + register f32 x1 = surf->vertex1[0]; + register f32 z1 = surf->vertex1[2]; + register f32 z2 = surf->vertex2[2]; + register f32 x2 = surf->vertex2[0]; // Checking if point is in bounds of the triangle laterally. if ((z1 - z) * (x2 - x1) - (x1 - x) * (z2 - z1) > 0) @@ -42,8 +40,8 @@ static struct SM64SurfaceCollisionData *find_ceil_from_list(f32 x, f32 y, f32 z, } // Slight optimization by checking these later. - x3 = surf->vertex3[0]; - z3 = surf->vertex3[2]; + register f32 x3 = surf->vertex3[0]; + register f32 z3 = surf->vertex3[2]; if ((z2 - z) * (x3 - x2) - (x2 - x) * (z3 - z2) > 0) { continue; @@ -58,7 +56,6 @@ static struct SM64SurfaceCollisionData *find_ceil_from_list(f32 x, f32 y, f32 z, f32 ny = surf->normal.y; f32 nz = surf->normal.z; f32 oo = surf->originOffset; - f32 height; // If a wall, ignore it. Likely a remnant, should never occur. if (ny == 0.0f) @@ -67,7 +64,7 @@ static struct SM64SurfaceCollisionData *find_ceil_from_list(f32 x, f32 y, f32 z, } // Find the ceil height at the specific point. - height = -(x * nx + nz * z + oo) / ny; + f32 height = -(x * nx + nz * z + oo) / ny; // Checks for ceiling interaction with a 78 unit buffer. //! (Exposed Ceilings) Because any point above a ceiling counts @@ -94,11 +91,6 @@ static struct SM64SurfaceCollisionData *find_ceil_from_list(f32 x, f32 y, f32 z, */ static struct SM64SurfaceCollisionData *find_floor_from_list(f32 x, f32 y, f32 z, f32 *pheight) { - register struct SM64SurfaceCollisionData *surf; - register f32 x1, z1, x2, z2, x3, z3; - f32 nx, ny, nz; - f32 oo; - f32 height; struct SM64SurfaceCollisionData *floor = NULL; uint32_t groupCount = loaded_surface_iter_group_count(); @@ -107,7 +99,7 @@ static struct SM64SurfaceCollisionData *find_floor_from_list(f32 x, f32 y, f32 z uint32_t surfCount = loaded_surface_iter_group_size(i); for (int j = 0; j < surfCount; ++j) { - surf = loaded_surface_iter_get_at_index(i, j); + register struct SM64SurfaceCollisionData *surf = loaded_surface_iter_get_at_index(i, j); // libsm64: Weed out surfaces whose triangles are actually line segs. TODO do this at surface load time if (!surf->isValid) continue; @@ -115,10 +107,10 @@ static struct SM64SurfaceCollisionData *find_floor_from_list(f32 x, f32 y, f32 z // Do the check normally done in add_surface_to_cell if (surf->normal.y <= 0.01f) continue; - x1 = surf->vertex1[0]; - z1 = surf->vertex1[2]; - x2 = surf->vertex2[0]; - z2 = surf->vertex2[2]; + register f32 x1 = surf->vertex1[0]; + register f32 z1 = surf->vertex1[2]; + register f32 x2 = surf->vertex2[0]; + register f32 z2 = surf->vertex2[2]; // Check that the point is within the triangle bounds. if ((z1 - z) * (x2 - x1) - (x1 - x) * (z2 - z1) < 0) @@ -127,8 +119,8 @@ static struct SM64SurfaceCollisionData *find_floor_from_list(f32 x, f32 y, f32 z } // To slightly save on computation time, set this later. - x3 = surf->vertex3[0]; - z3 = surf->vertex3[2]; + register f32 x3 = surf->vertex3[0]; + register f32 z3 = surf->vertex3[2]; if ((z2 - z) * (x3 - x2) - (x2 - x) * (z3 - z2) < 0) { @@ -139,10 +131,10 @@ static struct SM64SurfaceCollisionData *find_floor_from_list(f32 x, f32 y, f32 z continue; } - nx = surf->normal.x; - ny = surf->normal.y; - nz = surf->normal.z; - oo = surf->originOffset; + f32 nx = surf->normal.x; + f32 ny = surf->normal.y; + f32 nz = surf->normal.z; + f32 oo = surf->originOffset; // If a wall, ignore it. Likely a remnant, should never occur. if (ny == 0.0f) @@ -151,7 +143,7 @@ static struct SM64SurfaceCollisionData *find_floor_from_list(f32 x, f32 y, f32 z } // Find the height of the floor at a given location. - height = -(x * nx + nz * z + oo) / ny; + f32 height = -(x * nx + nz * z + oo) / ny; // Checks for floor interaction with a 78 unit buffer. if (y - (height + -78.0f) < 0.0f) { @@ -170,13 +162,10 @@ static struct SM64SurfaceCollisionData *find_floor_from_list(f32 x, f32 y, f32 z static s32 find_wall_collisions_from_list(struct SM64WallCollisionData *data) { - register struct SM64SurfaceCollisionData *surf; - register f32 offset; register f32 radius = data->radius; register f32 x = data->x; register f32 y = data->y + data->offsetY; register f32 z = data->z; - register f32 px, pz; register f32 w1, w2, w3; register f32 y1, y2, y3; s32 numCols = 0; @@ -193,7 +182,7 @@ static s32 find_wall_collisions_from_list(struct SM64WallCollisionData *data) uint32_t surfCount = loaded_surface_iter_group_size(i); for (int j = 0; j < surfCount; ++j) { - surf = loaded_surface_iter_get_at_index(i, j); + register struct SM64SurfaceCollisionData *surf = loaded_surface_iter_get_at_index(i, j); // libsm64: Weed out surfaces whose triangles are actually line segs. TODO do this at surface load time if (!surf->isValid) continue; @@ -212,15 +201,15 @@ static s32 find_wall_collisions_from_list(struct SM64WallCollisionData *data) continue; } - offset = surf->normal.x * x + surf->normal.y * y + surf->normal.z * z + surf->originOffset; + register f32 offset = surf->normal.x * x + surf->normal.y * y + surf->normal.z * z + surf->originOffset; if (offset < -radius || offset > radius) { continue; } - px = x; - pz = z; + register f32 px = x; + register f32 pz = z; //! (Quantum Tunneling) Due to issues with the vertices walls choose and // the fact they are floating point, certain floating point positions diff --git a/src/decomp/game/behavior_actions.c b/src/decomp/game/behavior_actions.c index 34425ef..7f88c9d 100644 --- a/src/decomp/game/behavior_actions.c +++ b/src/decomp/game/behavior_actions.c @@ -7,11 +7,10 @@ Gfx *geo_move_mario_part_from_parent(s32 run, UNUSED struct GraphNode *node, Mat4 mtx) { Mat4 sp20; - struct Object *sp1C; if (run == TRUE) { - sp1C = (struct Object *)gCurGraphNodeObject; + struct Object *sp1C = (struct Object *)gCurGraphNodeObject; if (sp1C == gMarioObject && sp1C->prevObj != NULL) { create_transformation_from_matrices(sp20, mtx, *gCurGraphNodeCamera->matrixPtr); diff --git a/src/decomp/game/interaction.c b/src/decomp/game/interaction.c index cdd1aa2..10bcdc5 100644 --- a/src/decomp/game/interaction.c +++ b/src/decomp/game/interaction.c @@ -446,12 +446,9 @@ u32 able_to_grab_object(struct MarioState *m, UNUSED struct Object *o) struct Object *mario_get_collided_object(struct MarioState *m, u32 interactType) { - s32 i; - struct Object *object; - - for (i = 0; i < m->marioObj->numCollidedObjs; i++) + for (s32 i = 0; i < m->marioObj->numCollidedObjs; i++) { - object = m->marioObj->collidedObjs[i]; + struct Object *object = m->marioObj->collidedObjs[i]; if (object->oInteractType == interactType) { @@ -502,10 +499,6 @@ u32 bully_knock_back_mario(struct MarioState *mario) { struct BullyCollisionData marioData; struct BullyCollisionData bullyData; - s16 newMarioYaw; - s16 newBullyYaw; - s16 marioDYaw; - UNUSED s16 bullyDYaw; u32 bonkAction = 0; @@ -531,11 +524,11 @@ u32 bully_knock_back_mario(struct MarioState *mario) transfer_bully_speed(&bullyData, &marioData); } - newMarioYaw = atan2s(marioData.velZ, marioData.velX); - newBullyYaw = atan2s(bullyData.velZ, bullyData.velX); + s16 newMarioYaw = atan2s(marioData.velZ, marioData.velX); + s16 newBullyYaw = atan2s(bullyData.velZ, bullyData.velX); - marioDYaw = newMarioYaw - mario->faceAngle[1]; - bullyDYaw = newBullyYaw - bully->oMoveAngleYaw; + s16 marioDYaw = newMarioYaw - mario->faceAngle[1]; + s16 bullyDYaw = newBullyYaw - bully->oMoveAngleYaw; mario->faceAngle[1] = newMarioYaw; mario->forwardVel = sqrtf(marioData.velX * marioData.velX + marioData.velZ * marioData.velZ); @@ -814,15 +807,13 @@ u32 take_damage_from_interact_object(struct MarioState *m) u32 take_damage_and_knock_back(struct MarioState *m, struct Object *o) { - u32 damage; - 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; - damage = take_damage_from_interact_object(m); + u32 damage = take_damage_from_interact_object(m); if (o->oInteractionSubtype & INT_SUBTYPE_BIG_KNOCKBACK) { @@ -880,8 +871,6 @@ u32 check_object_grab_mario(struct MarioState *m, UNUSED u32 interactType, struc u32 mario_can_talk(struct MarioState *m, u32 arg) { - s16 val6; - if ((m->action & ACT_FLAG_IDLE) != 0x00000000) { return TRUE; @@ -894,7 +883,7 @@ u32 mario_can_talk(struct MarioState *m, u32 arg) return TRUE; } - val6 = m->marioObj->header.gfx.animInfo.animID; + s16 val6 = m->marioObj->header.gfx.animInfo.animID; if (val6 == 0x0080 || val6 == 0x007F || val6 == 0x006C) { diff --git a/src/decomp/game/mario.c b/src/decomp/game/mario.c index 8b2c37c..edfb94c 100644 --- a/src/decomp/game/mario.c +++ b/src/decomp/game/mario.c @@ -228,9 +228,6 @@ s32 is_anim_past_frame(struct MarioState *m, s16 animFrame) */ s16 find_mario_anim_flags_and_translation(struct Object *obj, s32 yaw, Vec3s translation) { - f32 dx; - f32 dz; - struct Animation *curAnim = (void *)obj->header.gfx.animInfo.curAnim; s16 animFrame = geo_update_animation_frame(&obj->header.gfx.animInfo, NULL); u16 *animIndex = segmented_to_virtual(curAnim->index); @@ -239,9 +236,9 @@ s16 find_mario_anim_flags_and_translation(struct Object *obj, s32 yaw, Vec3s tra f32 s = sins(yaw); f32 c = coss(yaw); - dx = *(animValues + retrieve_animation_index(animFrame, &animIndex)) / 4.0f; + f32 dx = *(animValues + retrieve_animation_index(animFrame, &animIndex)) / 4.0f; translation[1] = *(animValues + retrieve_animation_index(animFrame, &animIndex)) / 4.0f; - dz = *(animValues + retrieve_animation_index(animFrame, &animIndex)) / 4.0f; + f32 dz = *(animValues + retrieve_animation_index(animFrame, &animIndex)) / 4.0f; translation[0] = dx * c + dz * s; translation[2] = -dx * s + dz * c; @@ -255,9 +252,8 @@ s16 find_mario_anim_flags_and_translation(struct Object *obj, s32 yaw, Vec3s tra void update_mario_pos_for_anim(struct MarioState *m) { Vec3s translation; - s16 flags; - flags = find_mario_anim_flags_and_translation(m->marioObj, m->faceAngle[1], translation); + s16 flags = find_mario_anim_flags_and_translation(m->marioObj, m->faceAngle[1], translation); if (flags & (ANIM_FLAG_HOR_TRANS | ANIM_FLAG_6)) { @@ -360,8 +356,7 @@ void play_sound_and_spawn_particles(struct MarioState *m, u32 soundBits, u32 wav } } - if (m->flags & MARIO_METAL_CAP || soundBits == SOUND_ACTION_UNSTUCK_FROM_GROUND - || soundBits == SOUND_MARIO_PUNCH_HOO) + if (m->flags & MARIO_METAL_CAP || soundBits == SOUND_ACTION_UNSTUCK_FROM_GROUND || soundBits == SOUND_MARIO_PUNCH_HOO) { play_sound(soundBits, m->marioObj->header.gfx.cameraToObject); } @@ -554,11 +549,10 @@ u32 mario_get_terrain_sound_addend(struct MarioState *m) { s16 floorSoundType; s32 ret = SOUND_TERRAIN_DEFAULT << 16; - s32 floorType; if (m->floor != NULL) { - floorType = m->floor->type; + s32 floorType = m->floor->type; s16 terrainType = m->curTerrain; if (gCurrLevelNum != LEVEL_LLL && m->floorHeight < m->waterLevel - 10) @@ -790,12 +784,11 @@ s32 mario_floor_is_steep(struct MarioState *m) f32 find_floor_height_relative_polar(struct MarioState *m, s16 angleFromMario, f32 distFromMario) { struct SM64SurfaceCollisionData *floor; - f32 floorY; f32 y = sins(m->faceAngle[1] + angleFromMario) * distFromMario; f32 x = coss(m->faceAngle[1] + angleFromMario) * distFromMario; - floorY = find_floor(m->pos[0] + y, m->pos[1] + 100.0f, m->pos[2] + x, &floor); + f32 floorY = find_floor(m->pos[0] + y, m->pos[1] + 100.0f, m->pos[2] + x, &floor); return floorY; } @@ -806,20 +799,18 @@ f32 find_floor_height_relative_polar(struct MarioState *m, s16 angleFromMario, f s16 find_floor_slope(struct MarioState *m, s16 yawOffset) { struct SM64SurfaceCollisionData *floor; - f32 forwardFloorY, backwardFloorY; - f32 forwardYDelta, backwardYDelta; s16 result; f32 x = sins(m->faceAngle[1] + yawOffset) * 5.0f; f32 z = coss(m->faceAngle[1] + yawOffset) * 5.0f; - forwardFloorY = find_floor(m->pos[0] + x, m->pos[1] + 100.0f, m->pos[2] + z, &floor); - backwardFloorY = find_floor(m->pos[0] - x, m->pos[1] + 100.0f, m->pos[2] - z, &floor); + f32 forwardFloorY = find_floor(m->pos[0] + x, m->pos[1] + 100.0f, m->pos[2] + z, &floor); + f32 backwardFloorY = find_floor(m->pos[0] - x, m->pos[1] + 100.0f, m->pos[2] - z, &floor); //! If Mario is near OOB, these floorY's can sometimes be -11000. // This will cause these to be off and give improper slopes. - forwardYDelta = forwardFloorY - m->pos[1]; - backwardYDelta = m->pos[1] - backwardFloorY; + f32 forwardYDelta = forwardFloorY - m->pos[1]; + f32 backwardYDelta = m->pos[1] - backwardFloorY; if (forwardYDelta * forwardYDelta < backwardYDelta * backwardYDelta) { @@ -1441,14 +1432,11 @@ void squish_mario_model(struct MarioState *m) */ void debug_print_speed_action_normal(struct MarioState *m) { - f32 steepness; - f32 floor_nY; - if (gShowDebugText) { - steepness = sqrtf( + f32 steepness = sqrtf( m->floor->normal.x * m->floor->normal.x + m->floor->normal.z * m->floor->normal.z); - floor_nY = m->floor->normal.y; + f32 floor_nY = m->floor->normal.y; print_text_fmt_int(210, 88, "ANG %d", atan2s(floor_nY, steepness) * 180.0f / 32768.0f); @@ -1546,7 +1534,6 @@ void update_mario_joystick_inputs(struct MarioState *m) void update_mario_geometry_inputs(struct MarioState *m) { //f32 gasLevel; - f32 ceilToFloorDist; f32_find_wall_collision(&m->pos[0], &m->pos[1], &m->pos[2], 60.0f, 50.0f); f32_find_wall_collision(&m->pos[0], &m->pos[1], &m->pos[2], 30.0f, 24.0f); @@ -1582,10 +1569,9 @@ void update_mario_geometry_inputs(struct MarioState *m) m->input |= INPUT_ABOVE_SLIDE; } - if (m->floor->flags & SURFACE_FLAG_DYNAMIC - || (m->ceil && m->ceil->flags & SURFACE_FLAG_DYNAMIC)) + if (m->floor->flags & SURFACE_FLAG_DYNAMIC || (m->ceil && m->ceil->flags & SURFACE_FLAG_DYNAMIC)) { - ceilToFloorDist = m->ceilHeight - m->floorHeight; + f32 ceilToFloorDist = m->ceilHeight - m->floorHeight; if (0.0f <= ceilToFloorDist && ceilToFloorDist <= 150.0f) { @@ -1673,13 +1659,10 @@ void update_mario_inputs(struct MarioState *m) */ void set_submerged_cam_preset_and_spawn_bubbles(struct MarioState *m) { - f32 heightBelowWater; - s16 camPreset; - if ((m->action & ACT_GROUP_MASK) == ACT_GROUP_SUBMERGED) { - heightBelowWater = (f32)(m->waterLevel - 80) - m->pos[1]; - camPreset = m->area->camera->mode; + f32 heightBelowWater = (f32)(m->waterLevel - 80) - m->pos[1]; + s16 camPreset = m->area->camera->mode; if (m->action & ACT_FLAG_METAL_WATER) { @@ -1719,8 +1702,6 @@ void set_submerged_cam_preset_and_spawn_bubbles(struct MarioState *m) */ void update_mario_health(struct MarioState *m) { - s32 terrainIsSnow; - if (m->health >= 0x100) { // When already healing or hurting Mario, Mario's HP is not changed any more here. @@ -1737,7 +1718,7 @@ void update_mario_health(struct MarioState *m) { if (m->action & ACT_FLAG_SWIMMING && !(m->action & ACT_FLAG_INTANGIBLE)) { - terrainIsSnow = m->floor != NULL && m->curTerrain == TERRAIN_SNOW; + s32 terrainIsSnow = m->floor != NULL && m->curTerrain == TERRAIN_SNOW; // When Mario is near the water surface, recover health (unless in snow), // when in snow terrains lose 3 health. @@ -1855,11 +1836,10 @@ u64 sCapFlickerFrames = 0x4444449249255555; u32 update_and_return_cap_flags(struct MarioState *m) { u32 flags = m->flags; - u32 action; if (m->capTimer > 0) { - action = m->action; + u32 action = m->action; if (m->capTimer <= 60 || (action != ACT_READING_AUTOMATIC_DIALOG && action != ACT_READING_NPC_DIALOG diff --git a/src/decomp/game/mario_actions_airborne.c b/src/decomp/game/mario_actions_airborne.c index fb2040e..9e7a884 100644 --- a/src/decomp/game/mario_actions_airborne.c +++ b/src/decomp/game/mario_actions_airborne.c @@ -78,10 +78,9 @@ s32 lava_boost_on_wall(struct MarioState *m) s32 check_fall_damage(struct MarioState *m, u32 hardFallAction) { - f32 fallHeight; f32 damageHeight; - fallHeight = m->peakHeight - m->pos[1]; + f32 fallHeight = m->peakHeight - m->pos[1]; #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wtype-limits" @@ -177,20 +176,16 @@ s32 check_fall_damage_or_get_stuck(struct MarioState *m, u32 hardFallAction) s32 check_horizontal_wind(struct MarioState *m) { - struct SM64SurfaceCollisionData *floor; - f32 speed; - s16 pushAngle; - - floor = m->floor; + struct SM64SurfaceCollisionData *floor = m->floor; if (floor->type == SURFACE_HORIZONTAL_WIND) { - pushAngle = floor->force << 8; + s16 pushAngle = floor->force << 8; m->slideVelX += 1.2f * sins(pushAngle); m->slideVelZ += 1.2f * coss(pushAngle); - speed = sqrtf(m->slideVelX * m->slideVelX + m->slideVelZ * m->slideVelZ); + f32 speed = sqrtf(m->slideVelX * m->slideVelX + m->slideVelZ * m->slideVelZ); if (speed > 48.0f) { @@ -251,19 +246,16 @@ void update_air_with_turn(struct MarioState *m) void update_air_without_turn(struct MarioState *m) { f32 sidewaysSpeed = 0.0f; - f32 dragThreshold; - s16 intendedDYaw; - f32 intendedMag; if (!check_horizontal_wind(m)) { - dragThreshold = m->action == ACT_LONG_JUMP ? 48.0f : 32.0f; + f32 dragThreshold = m->action == ACT_LONG_JUMP ? 48.0f : 32.0f; m->forwardVel = approach_f32(m->forwardVel, 0.0f, 0.35f, 0.35f); if (m->input & INPUT_NONZERO_ANALOG) { - intendedDYaw = m->intendedYaw - m->faceAngle[1]; - intendedMag = m->intendedMag / 32.0f; + s16 intendedDYaw = m->intendedYaw - m->faceAngle[1]; + f32 intendedMag = m->intendedMag / 32.0f; m->forwardVel += intendedMag * coss(intendedDYaw) * 1.5f; sidewaysSpeed = intendedMag * sins(intendedDYaw) * 10.0f; @@ -292,13 +284,10 @@ void update_air_without_turn(struct MarioState *m) void update_lava_boost_or_twirling(struct MarioState *m) { - s16 intendedDYaw; - f32 intendedMag; - if (m->input & INPUT_NONZERO_ANALOG) { - intendedDYaw = m->intendedYaw - m->faceAngle[1]; - intendedMag = m->intendedMag / 32.0f; + s16 intendedDYaw = m->intendedYaw - m->faceAngle[1]; + f32 intendedMag = m->intendedMag / 32.0f; m->forwardVel += coss(intendedDYaw) * intendedMag; m->faceAngle[1] += sins(intendedDYaw) * intendedMag * 1024.0f; @@ -451,11 +440,9 @@ void update_flying(struct MarioState *m) u32 common_air_action_step(struct MarioState *m, u32 landAction, s32 animation, u32 stepArg) { - u32 stepResult; - update_air_without_turn(m); - stepResult = perform_air_step(m, stepArg); + u32 stepResult = perform_air_step(m, stepArg); switch (stepResult) { case AIR_STEP_NONE: @@ -1091,16 +1078,13 @@ s32 act_steep_jump(struct MarioState *m) s32 act_ground_pound(struct MarioState *m) { - u32 stepResult; - f32 yOffset; - play_sound_if_no_flag(m, SOUND_ACTION_THROW, MARIO_ACTION_SOUND_PLAYED); if (m->actionState == 0) { if (m->actionTimer < 10) { - yOffset = 20 - 2 * m->actionTimer; + f32 yOffset = 20 - 2 * m->actionTimer; if (m->pos[1] + yOffset + 160.0f < m->ceilHeight) { m->pos[1] += yOffset; @@ -1131,7 +1115,7 @@ s32 act_ground_pound(struct MarioState *m) { set_mario_animation(m, MARIO_ANIM_GROUND_POUND); - stepResult = perform_air_step(m, 0); + u32 stepResult = perform_air_step(m, 0); if (stepResult == AIR_STEP_LANDED) { if (should_get_stuck_in_ground(m)) @@ -1303,11 +1287,9 @@ u32 common_air_knockback_step( struct MarioState *m, u32 landAction, u32 hardFallAction, s32 animation, f32 speed) { - u32 stepResult; - mario_set_forward_vel(m, speed); - stepResult = perform_air_step(m, 0); + u32 stepResult = perform_air_step(m, 0); switch (stepResult) { case AIR_STEP_NONE: @@ -1446,8 +1428,6 @@ s32 act_thrown_backward(struct MarioState *m) s32 act_thrown_forward(struct MarioState *m) { - s16 pitch; - u32 landAction; if (m->actionArg != 0) { @@ -1463,7 +1443,7 @@ s32 act_thrown_forward(struct MarioState *m) if (common_air_knockback_step(m, landAction, ACT_HARD_FORWARD_GROUND_KB, 0x002D, m->forwardVel) == AIR_STEP_NONE) { - pitch = atan2s(m->forwardVel, -m->vel[1]); + s16 pitch = atan2s(m->forwardVel, -m->vel[1]); if (pitch > 0x1800) { pitch = 0x1800; @@ -1943,8 +1923,6 @@ s32 act_slide_kick(struct MarioState *m) s32 act_jump_kick(struct MarioState *m) { - s32 animFrame; - if (m->actionState == 0) { play_sound_if_no_flag(m, SOUND_MARIO_PUNCH_HOO, MARIO_ACTION_SOUND_PLAYED); @@ -1953,7 +1931,7 @@ s32 act_jump_kick(struct MarioState *m) m->actionState = 1; } - animFrame = m->marioObj->header.gfx.animInfo.animFrame; + s32 animFrame = m->marioObj->header.gfx.animInfo.animFrame; if (animFrame == 0) { m->marioBodyState->punchState = 2 << 6 | 6; diff --git a/src/decomp/game/mario_actions_automatic.c b/src/decomp/game/mario_actions_automatic.c index 3a52024..4897b83 100644 --- a/src/decomp/game/mario_actions_automatic.c +++ b/src/decomp/game/mario_actions_automatic.c @@ -70,9 +70,6 @@ s32 set_pole_position(struct MarioState *m, f32 offsetY) UNUSED s32 unused3; struct SM64SurfaceCollisionData *floor; struct SM64SurfaceCollisionData *ceil; - f32 floorHeight; - f32 ceilHeight; - s32 collided; s32 result = POLE_NONE; f32 poleTop = m->usedObj->hitboxHeight - 100.0f; struct Object *marioObj = m->marioObj; @@ -86,17 +83,17 @@ s32 set_pole_position(struct MarioState *m, f32 offsetY) m->pos[2] = m->usedObj->oPosZ; m->pos[1] = m->usedObj->oPosY + marioObj->oMarioPolePos + offsetY; - collided = f32_find_wall_collision(&m->pos[0], &m->pos[1], &m->pos[2], 60.0f, 50.0f); + s32 collided = f32_find_wall_collision(&m->pos[0], &m->pos[1], &m->pos[2], 60.0f, 50.0f); collided |= f32_find_wall_collision(&m->pos[0], &m->pos[1], &m->pos[2], 30.0f, 24.0f); - ceilHeight = vec3f_find_ceil(m->pos, m->pos[1], &ceil); + f32 ceilHeight = vec3f_find_ceil(m->pos, m->pos[1], &ceil); if (m->pos[1] > ceilHeight - 160.0f) { m->pos[1] = ceilHeight - 160.0f; marioObj->oMarioPolePos = m->pos[1] - m->usedObj->oPosY; } - floorHeight = find_floor(m->pos[0], m->pos[1], m->pos[2], &floor); + f32 floorHeight = find_floor(m->pos[0], m->pos[1], m->pos[2], &floor); if (m->pos[1] < floorHeight) { m->pos[1] = floorHeight; @@ -360,13 +357,10 @@ s32 perform_hanging_step(struct MarioState *m, Vec3f nextPos) UNUSED s32 unused; struct SM64SurfaceCollisionData *ceil; struct SM64SurfaceCollisionData *floor; - f32 ceilHeight; - f32 floorHeight; - f32 ceilOffset; m->wall = resolve_and_return_wall_collisions(nextPos, 50.0f, 50.0f); - floorHeight = find_floor(nextPos[0], nextPos[1], nextPos[2], &floor); - ceilHeight = vec3f_find_ceil(nextPos, floorHeight, &ceil); + f32 floorHeight = find_floor(nextPos[0], nextPos[1], nextPos[2], &floor); + f32 ceilHeight = vec3f_find_ceil(nextPos, floorHeight, &ceil); if (floor == NULL) { @@ -385,7 +379,7 @@ s32 perform_hanging_step(struct MarioState *m, Vec3f nextPos) return HANG_LEFT_CEIL; } - ceilOffset = ceilHeight - (nextPos[1] + 160.0f); + f32 ceilOffset = ceilHeight - (nextPos[1] + 160.0f); if (ceilOffset < -30.0f) { return HANG_HIT_CEIL_OR_OOB; @@ -408,7 +402,6 @@ s32 perform_hanging_step(struct MarioState *m, Vec3f nextPos) s32 update_hang_moving(struct MarioState *m) { - s32 stepResult; Vec3f nextPos; f32 maxSpeed = 4.0f; @@ -433,7 +426,7 @@ s32 update_hang_moving(struct MarioState *m) nextPos[2] = m->pos[2] - m->ceil->normal.y * m->vel[2]; nextPos[1] = m->pos[1]; - stepResult = perform_hanging_step(m, nextPos); + s32 stepResult = perform_hanging_step(m, nextPos); vec3f_copy(m->marioObj->header.gfx.pos, m->pos); vec3s_set(m->marioObj->header.gfx.angle, 0, m->faceAngle[1], 0); @@ -583,7 +576,6 @@ s32 act_hang_moving(struct MarioState *m) s32 let_go_of_ledge(struct MarioState *m) { - f32 floorHeight; struct SM64SurfaceCollisionData *floor; m->vel[1] = 0.0f; @@ -591,7 +583,7 @@ s32 let_go_of_ledge(struct MarioState *m) m->pos[0] -= 60.0f * sins(m->faceAngle[1]); m->pos[2] -= 60.0f * coss(m->faceAngle[1]); - floorHeight = find_floor(m->pos[0], m->pos[1], m->pos[2], &floor); + f32 floorHeight = find_floor(m->pos[0], m->pos[1], m->pos[2], &floor); if (floorHeight < m->pos[1] - 100.0f) { m->pos[1] -= 100.0f; @@ -906,9 +898,6 @@ s32 act_tornado_twirling(struct MarioState *m) { struct SM64SurfaceCollisionData *floor; Vec3f nextPos; - f32 sinAngleVel; - f32 cosAngleVel; - f32 floorHeight; struct Object *marioObj = m->marioObj; struct Object *usedObj = m->usedObj; s16 prevTwirlYaw = m->twirlYaw; @@ -946,8 +935,8 @@ s32 act_tornado_twirling(struct MarioState *m) m->twirlYaw += m->angleVel[1]; - sinAngleVel = sins(marioObj->oMarioTornadoYawVel); - cosAngleVel = coss(marioObj->oMarioTornadoYawVel); + f32 sinAngleVel = sins(marioObj->oMarioTornadoYawVel); + f32 cosAngleVel = coss(marioObj->oMarioTornadoYawVel); nextPos[0] = usedObj->oPosX + dx * cosAngleVel + dz * sinAngleVel; nextPos[2] = usedObj->oPosZ - dx * sinAngleVel + dz * cosAngleVel; @@ -955,7 +944,7 @@ s32 act_tornado_twirling(struct MarioState *m) f32_find_wall_collision(&nextPos[0], &nextPos[1], &nextPos[2], 60.0f, 50.0f); - floorHeight = find_floor(nextPos[0], nextPos[1], nextPos[2], &floor); + f32 floorHeight = find_floor(nextPos[0], nextPos[1], nextPos[2], &floor); if (floor != NULL) { m->floor = floor; diff --git a/src/decomp/game/mario_actions_cutscene.c b/src/decomp/game/mario_actions_cutscene.c index 53dccc8..55dc1b0 100644 --- a/src/decomp/game/mario_actions_cutscene.c +++ b/src/decomp/game/mario_actions_cutscene.c @@ -429,7 +429,6 @@ s32 set_mario_npc_dialog(s32 actionArg) s32 act_reading_npc_dialog(struct MarioState *m) { s32 headTurnAmount = 0; - s16 angleToNPC; if (m->actionArg == 2) { @@ -443,7 +442,7 @@ s32 act_reading_npc_dialog(struct MarioState *m) if (m->actionState < 8) { // turn to NPC - angleToNPC = mario_obj_angle_to_object(m, m->usedObj); + s16 angleToNPC = mario_obj_angle_to_object(m, m->usedObj); m->faceAngle[1] = angleToNPC - approach_s32((angleToNPC - m->faceAngle[1]) << 16 >> 16, 0, 2048, 2048); // turn head to npc @@ -609,13 +608,11 @@ s32 act_debug_free_move(struct MarioState *m) struct Controller *gPlayer1Controller = &gController; struct SM64SurfaceCollisionData *surf; - f32 floorHeight; Vec3f pos; - f32 speed; u32 action; // integer immediates, generates convert instructions for some reason - speed = gPlayer1Controller->buttonDown & B_BUTTON ? 4 : 1; + f32 speed = gPlayer1Controller->buttonDown & B_BUTTON ? 4 : 1; if (gPlayer1Controller->buttonDown & L_TRIG) { speed = 0.01f; @@ -641,7 +638,7 @@ s32 act_debug_free_move(struct MarioState *m) resolve_and_return_wall_collisions(pos, 60.0f, 50.0f); - floorHeight = find_floor(pos[0], pos[1], pos[2], &surf); + f32 floorHeight = find_floor(pos[0], pos[1], pos[2], &surf); if (surf != NULL) { if (pos[1] < floorHeight) @@ -875,10 +872,9 @@ s32 act_eaten_by_bubba(struct MarioState *m) // set the new action s32 launch_mario_until_land(struct MarioState *m, s32 endAction, s32 animation, f32 forwardVel) { - s32 airStepLanded; mario_set_forward_vel(m, forwardVel); set_mario_animation(m, animation); - airStepLanded = perform_air_step(m, 0) == AIR_STEP_LANDED; + s32 airStepLanded = perform_air_step(m, 0) == AIR_STEP_LANDED; if (airStepLanded) { set_mario_action(m, endAction, 0); @@ -973,16 +969,12 @@ s32 act_unlocking_star_door(struct MarioState *m) s32 act_entering_star_door(struct MarioState *m) { - f32 targetDX; - f32 targetDZ; - s16 targetAngle; - if (m->actionTimer++ == 0) { m->interactObj->oInteractStatus = 0x00010000; // ~30 degrees / 1/12 rot - targetAngle = m->usedObj->oMoveAngleYaw + 0x1555; + s16 targetAngle = m->usedObj->oMoveAngleYaw + 0x1555; if (m->actionArg & 2) { targetAngle += 0x5556; // ~120 degrees / 1/3 rot (total 150d / 5/12) @@ -991,8 +983,8 @@ s32 act_entering_star_door(struct MarioState *m) // targetDX and targetDZ are the offsets to add to Mario's position to // have Mario stand 150 units in front of the door - targetDX = m->usedObj->oPosX + 150.0f * sins(targetAngle) - m->pos[0]; - targetDZ = m->usedObj->oPosZ + 150.0f * coss(targetAngle) - m->pos[2]; + f32 targetDX = m->usedObj->oPosX + 150.0f * sins(targetAngle) - m->pos[0]; + f32 targetDZ = m->usedObj->oPosZ + 150.0f * coss(targetAngle) - m->pos[2]; m->marioObj->oMarioReadingSignDPosX = targetDX / 20.0f; m->marioObj->oMarioReadingSignDPosZ = targetDZ / 20.0f; @@ -1453,15 +1445,11 @@ s32 act_spawn_no_spin_landing(struct MarioState *m) s32 act_bbh_enter_spin(struct MarioState *m) { f32 floorDist; - f32 scale; - f32 cageDX; - f32 cageDZ; - f32 cageDist; f32 forwardVel; - cageDX = m->usedObj->oPosX - m->pos[0]; - cageDZ = m->usedObj->oPosZ - m->pos[2]; - cageDist = sqrtf(cageDX * cageDX + cageDZ * cageDZ); + f32 cageDX = m->usedObj->oPosX - m->pos[0]; + f32 cageDZ = m->usedObj->oPosZ - m->pos[2]; + f32 cageDist = sqrtf(cageDX * cageDX + cageDZ * cageDZ); if (cageDist > 20.0f) { @@ -1534,7 +1522,7 @@ s32 act_bbh_enter_spin(struct MarioState *m) if (m->actionTimer >= 11) { m->actionTimer -= 6; - scale = m->actionTimer / 100.0f; + f32 scale = m->actionTimer / 100.0f; vec3f_set(m->marioObj->header.gfx.scale, scale, scale, scale); } break; @@ -1550,19 +1538,15 @@ s32 act_bbh_enter_spin(struct MarioState *m) s32 act_bbh_enter_jump(struct MarioState *m) { - f32 cageDX; - f32 cageDZ; - f32 cageDist; - play_mario_action_sound( m, m->flags & MARIO_METAL_CAP ? SOUND_ACTION_METAL_JUMP : SOUND_ACTION_TERRAIN_JUMP, 1); play_mario_jump_sound(m); if (m->actionState == 0) { - cageDX = m->usedObj->oPosX - m->pos[0]; - cageDZ = m->usedObj->oPosZ - m->pos[2]; - cageDist = sqrtf(cageDX * cageDX + cageDZ * cageDZ); + f32 cageDX = m->usedObj->oPosX - m->pos[0]; + f32 cageDZ = m->usedObj->oPosZ - m->pos[2]; + f32 cageDist = sqrtf(cageDX * cageDX + cageDZ * cageDZ); m->vel[1] = 60.0f; m->faceAngle[1] = atan2s(cageDZ, cageDX); @@ -1697,7 +1681,6 @@ s32 act_shocked(struct MarioState *m) s32 act_squished(struct MarioState *m) { UNUSED s32 pad; - f32 squishAmount; f32 spaceUnderCeil; s16 surfAngle; s32 underSteepSurf = FALSE; // seems to be responsible for setting velocity? @@ -1721,7 +1704,7 @@ s32 act_squished(struct MarioState *m) if (spaceUnderCeil >= 10.1f) { // Mario becomes a pancake - squishAmount = spaceUnderCeil / 160.0f; + f32 squishAmount = spaceUnderCeil / 160.0f; vec3f_set(m->marioObj->header.gfx.scale, 2.0f - squishAmount, squishAmount, 2.0f - squishAmount); } @@ -2101,7 +2084,6 @@ static void jumbo_star_cutscene_falling(struct MarioState *m) static s32 jumbo_star_cutscene_taking_off(struct MarioState *m) { struct Object *marioObj = m->marioObj; - s32 animFrame; if (m->actionState == 0) { @@ -2116,7 +2098,7 @@ static s32 jumbo_star_cutscene_taking_off(struct MarioState *m) } else { - animFrame = set_mario_animation(m, MARIO_ANIM_FINAL_BOWSER_WING_CAP_TAKE_OFF); + s32 animFrame = set_mario_animation(m, MARIO_ANIM_FINAL_BOWSER_WING_CAP_TAKE_OFF); if (animFrame == 3 || animFrame == 28 || animFrame == 60) { play_sound_and_spawn_particles(m, SOUND_ACTION_TERRAIN_JUMP, 1); @@ -2165,11 +2147,6 @@ static s32 jumbo_star_cutscene_flying(struct MarioState *m) Vec3f targetPos; UNUSED struct Object *marioObj = m->marioObj; - f32 targetDX; - f32 targetDY; - f32 targetDZ; - f32 targetHyp; - s16 targetAngle; switch (m->actionState) { @@ -2187,11 +2164,11 @@ static s32 jumbo_star_cutscene_flying(struct MarioState *m) } else { - targetDX = targetPos[0] - m->pos[0]; - targetDY = targetPos[1] - m->pos[1]; - targetDZ = targetPos[2] - m->pos[2]; - targetHyp = sqrtf(targetDX * targetDX + targetDZ * targetDZ); - targetAngle = atan2s(targetDZ, targetDX); + f32 targetDX = targetPos[0] - m->pos[0]; + f32 targetDY = targetPos[1] - m->pos[1]; + f32 targetDZ = targetPos[2] - m->pos[2]; + f32 targetHyp = sqrtf(targetDX * targetDX + targetDZ * targetDZ); + s16 targetAngle = atan2s(targetDZ, targetDX); vec3f_copy(m->pos, targetPos); m->marioObj->header.gfx.angle[0] = -atan2s(targetHyp, targetDY); diff --git a/src/decomp/game/mario_actions_moving.c b/src/decomp/game/mario_actions_moving.c index ec085e4..77e41a1 100644 --- a/src/decomp/game/mario_actions_moving.c +++ b/src/decomp/game/mario_actions_moving.c @@ -121,10 +121,6 @@ void check_ledge_climb_down(struct MarioState *m) { struct SM64WallCollisionData wallCols; struct SM64SurfaceCollisionData *floor; - f32 floorHeight; - struct SM64SurfaceCollisionData *wall; - s16 wallAngle; - s16 wallDYaw; if (m->forwardVel < 10.0f) { @@ -136,12 +132,12 @@ void check_ledge_climb_down(struct MarioState *m) if (find_wall_collisions(&wallCols) != 0) { - floorHeight = find_floor(wallCols.x, wallCols.y, wallCols.z, &floor); + f32 floorHeight = find_floor(wallCols.x, wallCols.y, wallCols.z, &floor); if (floor != NULL && wallCols.y - floorHeight > 160.0f) { - wall = wallCols.walls[wallCols.numWalls - 1]; - wallAngle = atan2s(wall->normal.z, wall->normal.x); - wallDYaw = wallAngle - m->faceAngle[1]; + struct SM64SurfaceCollisionData *wall = wallCols.walls[wallCols.numWalls - 1]; + s16 wallAngle = atan2s(wall->normal.z, wall->normal.x); + s16 wallDYaw = wallAngle - m->faceAngle[1]; if (wallDYaw > -0x4000 && wallDYaw < 0x4000) { @@ -193,9 +189,6 @@ s32 set_triple_jump_action(struct MarioState *m, UNUSED u32 action, UNUSED u32 a void update_sliding_angle(struct MarioState *m, f32 accel, f32 lossFactor) { - s32 newFacingDYaw; - s16 facingDYaw; - struct SM64SurfaceCollisionData *floor = m->floor; s16 slopeAngle = atan2s(floor->normal.z, floor->normal.x); f32 steepness = sqrtf(floor->normal.x * floor->normal.x + floor->normal.z * floor->normal.z); @@ -209,8 +202,8 @@ void update_sliding_angle(struct MarioState *m, f32 accel, f32 lossFactor) m->slideYaw = atan2s(m->slideVelZ, m->slideVelX); - facingDYaw = m->faceAngle[1] - m->slideYaw; - newFacingDYaw = facingDYaw; + s16 facingDYaw = m->faceAngle[1] - m->slideYaw; + s32 newFacingDYaw = facingDYaw; //! -0x4000 not handled - can slide down a slope while facing perpendicular to it if (newFacingDYaw > 0 && newFacingDYaw <= 0x4000) @@ -269,8 +262,6 @@ s32 update_sliding(struct MarioState *m, f32 stopSpeed) { f32 lossFactor; f32 accel; - f32 oldSpeed; - f32 newSpeed; s32 stopped = FALSE; @@ -307,7 +298,7 @@ s32 update_sliding(struct MarioState *m, f32 stopSpeed) break; } - oldSpeed = sqrtf(m->slideVelX * m->slideVelX + m->slideVelZ * m->slideVelZ); + f32 oldSpeed = sqrtf(m->slideVelX * m->slideVelX + m->slideVelZ * m->slideVelZ); //! This is attempting to use trig derivatives to rotate Mario's speed. // It is slightly off/asymmetric since it uses the new X speed, but the old @@ -315,7 +306,7 @@ s32 update_sliding(struct MarioState *m, f32 stopSpeed) m->slideVelX += m->slideVelZ * (m->intendedMag / 32.0f) * sideward * 0.05f; m->slideVelZ -= m->slideVelX * (m->intendedMag / 32.0f) * sideward * 0.05f; - newSpeed = sqrtf(m->slideVelX * m->slideVelX + m->slideVelZ * m->slideVelZ); + f32 newSpeed = sqrtf(m->slideVelX * m->slideVelX + m->slideVelZ * m->slideVelZ); if (oldSpeed > 0.0f && newSpeed > 0.0f) { @@ -414,7 +405,6 @@ s32 apply_landing_accel(struct MarioState *m, f32 frictionFactor) void update_shell_speed(struct MarioState *m) { f32 maxTargetSpeed; - f32 targetSpeed; if (m->floorHeight < m->waterLevel) { @@ -432,7 +422,7 @@ void update_shell_speed(struct MarioState *m) maxTargetSpeed = 64.0f; } - targetSpeed = m->intendedMag * 2.0f; + f32 targetSpeed = m->intendedMag * 2.0f; if (targetSpeed > maxTargetSpeed) { targetSpeed = maxTargetSpeed; @@ -516,7 +506,6 @@ s32 update_decelerating_speed(struct MarioState *m) void update_walking_speed(struct MarioState *m) { f32 maxTargetSpeed; - f32 targetSpeed; if (m->floor != NULL && m->floor->type == SURFACE_SLOW) { @@ -527,7 +516,7 @@ void update_walking_speed(struct MarioState *m) maxTargetSpeed = 32.0f; } - targetSpeed = m->intendedMag < maxTargetSpeed ? m->intendedMag : maxTargetSpeed; + f32 targetSpeed = m->intendedMag < maxTargetSpeed ? m->intendedMag : maxTargetSpeed; if (m->quicksandDepth > 10.0f) { @@ -622,9 +611,8 @@ void anim_and_audio_for_walk(struct MarioState *m) struct Object *marioObj = m->marioObj; s32 val0C = TRUE; s16 targetPitch = 0; - f32 val04; - val04 = m->intendedMag > m->forwardVel ? m->intendedMag : m->forwardVel; + f32 val04 = m->intendedMag > m->forwardVel ? m->intendedMag : m->forwardVel; if (val04 < 4.0f) { @@ -735,9 +723,8 @@ void anim_and_audio_for_hold_walk(struct MarioState *m) { s32 val0C; s32 val08 = TRUE; - f32 val04; - val04 = m->intendedMag > m->forwardVel ? m->intendedMag : m->forwardVel; + f32 val04 = m->intendedMag > m->forwardVel ? m->intendedMag : m->forwardVel; if (val04 < 2.0f) { @@ -867,17 +854,14 @@ void tilt_body_walking(struct MarioState *m, s16 startYaw) UNUSED struct Object *marioObj = m->marioObj; s16 animID = m->marioObj->header.gfx.animInfo.animID; - s16 dYaw; - s16 val02; - s16 val00; if (animID == MARIO_ANIM_WALKING || animID == MARIO_ANIM_RUNNING) { - dYaw = m->faceAngle[1] - startYaw; + s16 dYaw = m->faceAngle[1] - startYaw; //! (Speed Crash) These casts can cause a crash if (dYaw * forwardVel / 12) or //! (forwardVel * 170) exceed or equal 2^31. - val02 = -(s16)(dYaw * m->forwardVel / 12.0f); - val00 = (s16)(m->forwardVel * 170.0f); + s16 val02 = -(s16)(dYaw * m->forwardVel / 12.0f); + s16 val00 = (s16)(m->forwardVel * 170.0f); if (val02 > 0x1555) { @@ -1514,8 +1498,6 @@ s32 act_riding_shell_ground(struct MarioState *m) s32 act_crawling(struct MarioState *m) { - s32 val04; - if (should_begin_sliding(m)) { return set_mario_action(m, ACT_BEGIN_SLIDING, 0); @@ -1568,7 +1550,7 @@ s32 act_crawling(struct MarioState *m) break; } - val04 = (s32)(m->intendedMag * 2.0f * 0x10000); + s32 val04 = (s32)(m->intendedMag * 2.0f * 0x10000); set_mario_anim_with_accel(m, MARIO_ANIM_CRAWLING, val04); play_step_sound(m, 26, 79); return FALSE; @@ -1741,23 +1723,19 @@ s32 act_butt_slide(struct MarioState *m) s32 act_hold_butt_slide(struct MarioState *m) { - s32 cancel; - if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) { return drop_and_set_mario_action(m, ACT_BUTT_SLIDE, 0); } - cancel = common_slide_action_with_jump(m, ACT_HOLD_BUTT_SLIDE_STOP, ACT_HOLD_JUMP, ACT_HOLD_BUTT_SLIDE_AIR, - MARIO_ANIM_SLIDING_ON_BOTTOM_WITH_LIGHT_OBJ); + s32 cancel = common_slide_action_with_jump(m, ACT_HOLD_BUTT_SLIDE_STOP, ACT_HOLD_JUMP, ACT_HOLD_BUTT_SLIDE_AIR, + MARIO_ANIM_SLIDING_ON_BOTTOM_WITH_LIGHT_OBJ); tilt_body_butt_slide(m); return cancel; } s32 act_crouch_slide(struct MarioState *m) { - s32 cancel; - if (m->input & INPUT_ABOVE_SLIDE) { return set_mario_action(m, ACT_BUTT_SLIDE, 0); @@ -1797,8 +1775,8 @@ s32 act_crouch_slide(struct MarioState *m) return set_mario_action(m, ACT_BRAKING, 0); } - cancel = common_slide_action_with_jump(m, ACT_CROUCHING, ACT_JUMP, ACT_FREEFALL, - MARIO_ANIM_START_CROUCHING); + s32 cancel = common_slide_action_with_jump(m, ACT_CROUCHING, ACT_JUMP, ACT_FREEFALL, + MARIO_ANIM_START_CROUCHING); return cancel; } @@ -1872,14 +1850,12 @@ s32 act_stomach_slide(struct MarioState *m) s32 act_hold_stomach_slide(struct MarioState *m) { - s32 cancel; - if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) { return drop_and_set_mario_action(m, ACT_STOMACH_SLIDE, 0); } - cancel = stomach_slide_action(m, ACT_DIVE_PICKING_UP, ACT_HOLD_FREEFALL, MARIO_ANIM_SLIDE_DIVE); + s32 cancel = stomach_slide_action(m, ACT_DIVE_PICKING_UP, ACT_HOLD_FREEFALL, MARIO_ANIM_SLIDE_DIVE); return cancel; } @@ -1920,8 +1896,6 @@ s32 act_dive_slide(struct MarioState *m) s32 common_ground_knockback_action(struct MarioState *m, s32 animation, s32 arg2, s32 arg3, s32 arg4) { - s32 animFrame; - if (arg3) { play_mario_heavy_landing_sound_once(m, SOUND_ACTION_TERRAIN_BODY_HIT_GROUND); @@ -1949,7 +1923,7 @@ s32 common_ground_knockback_action(struct MarioState *m, s32 animation, s32 arg2 m->forwardVel = -32.0f; } - animFrame = set_mario_animation(m, animation); + s32 animFrame = set_mario_animation(m, animation); if (animFrame < arg2) { apply_landing_accel(m, 0.9f); @@ -2066,12 +2040,10 @@ s32 act_ground_bonk(struct MarioState *m) s32 act_death_exit_land(struct MarioState *m) { - s32 animFrame; - apply_landing_accel(m, 0.9f); play_mario_heavy_landing_sound_once(m, SOUND_ACTION_TERRAIN_BODY_HIT_GROUND); - animFrame = set_mario_animation(m, MARIO_ANIM_FALL_OVER_BACKWARDS); + s32 animFrame = set_mario_animation(m, MARIO_ANIM_FALL_OVER_BACKWARDS); if (animFrame == 54) { @@ -2092,8 +2064,6 @@ s32 act_death_exit_land(struct MarioState *m) u32 common_landing_action(struct MarioState *m, s16 animation, u32 airAction) { - u32 stepResult; - if (m->input & INPUT_NONZERO_ANALOG) { apply_landing_accel(m, 0.98f); @@ -2107,7 +2077,7 @@ u32 common_landing_action(struct MarioState *m, s16 animation, u32 airAction) m->vel[1] = 0.0f; } - stepResult = perform_ground_step(m); + u32 stepResult = perform_ground_step(m); switch (stepResult) { case GROUND_STEP_LEFT_GROUND: diff --git a/src/decomp/game/mario_actions_stationary.c b/src/decomp/game/mario_actions_stationary.c index 9ce206a..c04e0f6 100644 --- a/src/decomp/game/mario_actions_stationary.c +++ b/src/decomp/game/mario_actions_stationary.c @@ -502,15 +502,13 @@ s32 act_shivering(struct MarioState *m) s32 act_coughing(struct MarioState *m) { - s32 animFrame; - if (check_common_idle_cancels(m)) { return TRUE; } stationary_ground_step(m); - animFrame = set_mario_animation(m, MARIO_ANIM_COUGHING); + s32 animFrame = set_mario_animation(m, MARIO_ANIM_COUGHING); if (animFrame == 25 || animFrame == 35) { play_sound(SOUND_MARIO_COUGHING3, m->marioObj->header.gfx.cameraToObject); @@ -964,9 +962,6 @@ s32 act_stop_crawling(struct MarioState *m) s32 act_shockwave_bounce(struct MarioState *m) { - s16 sp1E; - f32 sp18; - if (m->marioObj->oInteractStatus & INT_STATUS_HIT_BY_SHOCKWAVE) { #ifdef VERSION_SH @@ -991,8 +986,8 @@ s32 act_shockwave_bounce(struct MarioState *m) return set_mario_action(m, ACT_IDLE, 0); } - sp1E = (m->actionTimer % 16) << 12; - sp18 = (f32)(6 - m->actionTimer / 8) * 8.0f + 4.0f; + s16 sp1E = (m->actionTimer % 16) << 12; + f32 sp18 = (f32)(6 - m->actionTimer / 8) * 8.0f + 4.0f; mario_set_forward_vel(m, 0); vec3f_set(m->vel, 0.0f, 0.0f, 0.0f); if (sins(sp1E) >= 0.0f) diff --git a/src/decomp/game/mario_actions_submerged.c b/src/decomp/game/mario_actions_submerged.c index 424245a..15f0350 100644 --- a/src/decomp/game/mario_actions_submerged.c +++ b/src/decomp/game/mario_actions_submerged.c @@ -95,15 +95,12 @@ static f32 get_buoyancy(struct MarioState *m) static u32 perform_water_full_step(struct MarioState *m, Vec3f nextPos) { - struct SM64SurfaceCollisionData *wall; struct SM64SurfaceCollisionData *ceil; struct SM64SurfaceCollisionData *floor; - f32 ceilHeight; - f32 floorHeight; - wall = resolve_and_return_wall_collisions(nextPos, 10.0f, 110.0f); - floorHeight = find_floor(nextPos[0], nextPos[1], nextPos[2], &floor); - ceilHeight = vec3f_find_ceil(nextPos, floorHeight, &ceil); + struct SM64SurfaceCollisionData *wall = resolve_and_return_wall_collisions(nextPos, 10.0f, 110.0f); + f32 floorHeight = find_floor(nextPos[0], nextPos[1], nextPos[2], &floor); + f32 ceilHeight = vec3f_find_ceil(nextPos, floorHeight, &ceil); if (floor == NULL) { @@ -155,7 +152,6 @@ static u32 perform_water_full_step(struct MarioState *m, Vec3f nextPos) static void apply_water_current(struct MarioState *m, Vec3f step) { - s32 i; f32 whirlpoolRadius = 2000.0f; if (m->floor->type == SURFACE_FLOWING_WATER) @@ -167,7 +163,7 @@ static void apply_water_current(struct MarioState *m, Vec3f step) step[2] += currentSpeed * coss(currentAngle); } - for (i = 0; i < 2; i++) + for (s32 i = 0; i < 2; i++) { struct Whirlpool *whirlpool = gCurrentArea->whirlpools[i]; if (whirlpool != NULL) @@ -212,7 +208,6 @@ static void apply_water_current(struct MarioState *m, Vec3f step) static u32 perform_water_step(struct MarioState *m) { UNUSED u32 unused; - u32 stepResult; Vec3f nextPos; Vec3f step; struct Object *marioObj = m->marioObj; @@ -234,7 +229,7 @@ static u32 perform_water_step(struct MarioState *m) m->vel[1] = 0.0f; } - stepResult = perform_water_full_step(m, nextPos); + u32 stepResult = perform_water_full_step(m, nextPos); vec3f_copy(marioObj->header.gfx.pos, m->pos); vec3s_set(marioObj->header.gfx.angle, -m->faceAngle[0], m->faceAngle[1], m->faceAngle[2]); @@ -1162,7 +1157,6 @@ static s32 act_water_death(struct MarioState *m) static s32 act_water_plunge(struct MarioState *m) { - u32 stepResult; s32 stateFlags = m->heldObj != NULL; f32 endVSpeed; @@ -1188,7 +1182,7 @@ static s32 act_water_plunge(struct MarioState *m) stationary_slow_down(m); - stepResult = perform_water_step(m); + u32 stepResult = perform_water_step(m); if (m->actionState == 0) { @@ -1262,8 +1256,6 @@ static s32 act_water_plunge(struct MarioState *m) static s32 act_caught_in_whirlpool(struct MarioState *m) { - f32 sinAngleChange; - f32 cosAngleChange; f32 newDistance; s16 angleChange; @@ -1301,8 +1293,8 @@ static s32 act_caught_in_whirlpool(struct MarioState *m) m->vel[1] = -640.0f / (newDistance + 16.0f); - sinAngleChange = sins(angleChange); - cosAngleChange = coss(angleChange); + f32 sinAngleChange = sins(angleChange); + f32 cosAngleChange = coss(angleChange); if (distance < 1.0f) { diff --git a/src/decomp/game/mario_misc.c b/src/decomp/game/mario_misc.c index d350380..8a25563 100644 --- a/src/decomp/game/mario_misc.c +++ b/src/decomp/game/mario_misc.c @@ -351,12 +351,11 @@ Gfx *geo_mirror_mario_set_alpha(s32 callContext, struct GraphNode *node, UNUSED Gfx *gfx = NULL; struct GraphNodeGenerated *asGenerated = (struct GraphNodeGenerated *)node; struct MarioBodyState *bodyState = &gBodyStates[asGenerated->parameter]; - s16 alpha; UNUSED u8 unused2[4]; if (callContext == GEO_CONTEXT_RENDER) { - alpha = bodyState->modelState & 0x100 ? bodyState->modelState & 0xFF : 255; + s16 alpha = bodyState->modelState & 0x100 ? bodyState->modelState & 0xFF : 255; gfx = make_gfx_mario_alpha(asGenerated, alpha); } return gfx; @@ -387,13 +386,12 @@ Gfx *geo_switch_mario_eyes(s32 callContext, struct GraphNode *node, UNUSED Mat4 { struct GraphNodeSwitchCase *switchCase = (struct GraphNodeSwitchCase *)node; struct MarioBodyState *bodyState = &gBodyStates[switchCase->numCases]; - s16 blinkFrame; if (callContext == GEO_CONTEXT_RENDER) { if (bodyState->eyeState == 0) { - blinkFrame = (switchCase->numCases * 32 + gAreaUpdateCounter) >> 1 & 0x1F; + s16 blinkFrame = (switchCase->numCases * 32 + gAreaUpdateCounter) >> 1 & 0x1F; if (blinkFrame < 7) { switchCase->selectedCase = gMarioBlinkAnimation[blinkFrame]; diff --git a/src/decomp/game/mario_step.c b/src/decomp/game/mario_step.c index 0b9163b..b94081f 100644 --- a/src/decomp/game/mario_step.c +++ b/src/decomp/game/mario_step.c @@ -271,13 +271,12 @@ void stop_and_set_height_to_floor(struct MarioState *m) s32 stationary_ground_step(struct MarioState *m) { - u32 takeStep; struct Object *marioObj = m->marioObj; u32 stepResult = GROUND_STEP_NONE; mario_set_forward_vel(m, 0.0f); - takeStep = mario_update_moving_sand(m); + u32 takeStep = mario_update_moving_sand(m); takeStep |= mario_update_windy_ground(m); if (takeStep) { @@ -297,23 +296,17 @@ s32 stationary_ground_step(struct MarioState *m) static s32 perform_ground_quarter_step(struct MarioState *m, Vec3f nextPos) { - UNUSED - struct SM64SurfaceCollisionData *lowerWall; - struct SM64SurfaceCollisionData *upperWall; struct SM64SurfaceCollisionData *ceil; struct SM64SurfaceCollisionData *floor; - f32 ceilHeight; - f32 floorHeight; - f32 waterLevel; - lowerWall = resolve_and_return_wall_collisions(nextPos, 30.0f, 24.0f); - upperWall = resolve_and_return_wall_collisions(nextPos, 60.0f, 50.0f); + struct SM64SurfaceCollisionData *lowerWall = resolve_and_return_wall_collisions(nextPos, 30.0f, 24.0f); + struct SM64SurfaceCollisionData *upperWall = resolve_and_return_wall_collisions(nextPos, 60.0f, 50.0f); - floorHeight = find_floor(nextPos[0], nextPos[1], nextPos[2], &floor); - ceilHeight = vec3f_find_ceil(nextPos, floorHeight, &ceil); + f32 floorHeight = find_floor(nextPos[0], nextPos[1], nextPos[2], &floor); + f32 ceilHeight = vec3f_find_ceil(nextPos, floorHeight, &ceil); //waterLevel = find_water_level(nextPos[0], nextPos[2]); - waterLevel = m->waterLevel; + f32 waterLevel = m->waterLevel; m->wall = upperWall; @@ -372,11 +365,10 @@ static s32 perform_ground_quarter_step(struct MarioState *m, Vec3f nextPos) s32 perform_ground_step(struct MarioState *m) { - s32 i; u32 stepResult; Vec3f intendedPos; - for (i = 0; i < 4; i++) + for (s32 i = 0; i < 4; i++) { intendedPos[0] = m->pos[0] + m->floor->normal.y * (m->vel[0] / 4.0f); intendedPos[2] = m->pos[2] + m->floor->normal.y * (m->vel[2] / 4.0f); @@ -404,16 +396,14 @@ u32 check_ledge_grab(struct MarioState *m, struct SM64SurfaceCollisionData *wall { struct SM64SurfaceCollisionData *ledgeFloor; Vec3f ledgePos; - f32 displacementX; - f32 displacementZ; if (m->vel[1] > 0) { return FALSE; } - displacementX = nextPos[0] - intendedPos[0]; - displacementZ = nextPos[2] - intendedPos[2]; + f32 displacementX = nextPos[0] - intendedPos[0]; + f32 displacementZ = nextPos[2] - intendedPos[2]; // Only ledge grab if the wall displaced Mario in the opposite direction of // his velocity. @@ -446,26 +436,20 @@ u32 check_ledge_grab(struct MarioState *m, struct SM64SurfaceCollisionData *wall s32 perform_air_quarter_step(struct MarioState *m, Vec3f intendedPos, u32 stepArg) { - s16 wallDYaw; Vec3f nextPos; - struct SM64SurfaceCollisionData *upperWall; - struct SM64SurfaceCollisionData *lowerWall; struct SM64SurfaceCollisionData *ceil; struct SM64SurfaceCollisionData *floor; - f32 ceilHeight; - f32 floorHeight; - f32 waterLevel; vec3f_copy(nextPos, intendedPos); - upperWall = resolve_and_return_wall_collisions(nextPos, 150.0f, 50.0f); - lowerWall = resolve_and_return_wall_collisions(nextPos, 30.0f, 50.0f); + struct SM64SurfaceCollisionData *upperWall = resolve_and_return_wall_collisions(nextPos, 150.0f, 50.0f); + struct SM64SurfaceCollisionData *lowerWall = resolve_and_return_wall_collisions(nextPos, 30.0f, 50.0f); - floorHeight = find_floor(nextPos[0], nextPos[1], nextPos[2], &floor); - ceilHeight = vec3f_find_ceil(nextPos, floorHeight, &ceil); + f32 floorHeight = find_floor(nextPos[0], nextPos[1], nextPos[2], &floor); + f32 ceilHeight = vec3f_find_ceil(nextPos, floorHeight, &ceil); //waterLevel = find_water_level(nextPos[0], nextPos[2]); - waterLevel = m->waterLevel; + f32 waterLevel = m->waterLevel; m->wall = NULL; @@ -558,7 +542,7 @@ s32 perform_air_quarter_step(struct MarioState *m, Vec3f intendedPos, u32 stepAr if (upperWall != NULL || lowerWall != NULL) { m->wall = upperWall != NULL ? upperWall : lowerWall; - wallDYaw = atan2s(m->wall->normal.z, m->wall->normal.x) - m->faceAngle[1]; + s16 wallDYaw = atan2s(m->wall->normal.z, m->wall->normal.x) - m->faceAngle[1]; if (m->wall->type == SURFACE_BURNING) { @@ -577,7 +561,6 @@ s32 perform_air_quarter_step(struct MarioState *m, Vec3f intendedPos, u32 stepAr void apply_twirl_gravity(struct MarioState *m) { - f32 terminalVelocity; f32 heaviness = 1.0f; if (m->angleVel[1] > 1024) @@ -585,7 +568,7 @@ void apply_twirl_gravity(struct MarioState *m) heaviness = 1024.0f / m->angleVel[1]; } - terminalVelocity = -75.0f * heaviness; + f32 terminalVelocity = -75.0f * heaviness; m->vel[1] -= 4.0f * heaviness; if (m->vel[1] < terminalVelocity) @@ -691,11 +674,10 @@ void apply_gravity(struct MarioState *m) void apply_vertical_wind(struct MarioState *m) { f32 maxVelY; - f32 offsetY; if (m->action != ACT_GROUND_POUND) { - offsetY = m->pos[1] - -1500.0f; + f32 offsetY = m->pos[1] - -1500.0f; if (m->floor->type == SURFACE_VERTICAL_WIND && -3000.0f < offsetY && offsetY < 2000.0f) { @@ -726,19 +708,17 @@ void apply_vertical_wind(struct MarioState *m) s32 perform_air_step(struct MarioState *m, u32 stepArg) { Vec3f intendedPos; - s32 i; - s32 quarterStepResult; s32 stepResult = AIR_STEP_NONE; m->wall = NULL; - for (i = 0; i < 4; i++) + for (s32 i = 0; i < 4; i++) { intendedPos[0] = m->pos[0] + m->vel[0] / 4.0f; intendedPos[1] = m->pos[1] + m->vel[1] / 4.0f; intendedPos[2] = m->pos[2] + m->vel[2] / 4.0f; - quarterStepResult = perform_air_quarter_step(m, intendedPos, stepArg); + s32 quarterStepResult = perform_air_quarter_step(m, intendedPos, stepArg); //! On one qf, hit OOB/ceil/wall to store the 2 return value, and continue // getting 0s until your last qf. Graze a wall on your last qf, and it will diff --git a/src/decomp/game/object_stuff.c b/src/decomp/game/object_stuff.c index d46e088..8cad461 100644 --- a/src/decomp/game/object_stuff.c +++ b/src/decomp/game/object_stuff.c @@ -13,8 +13,7 @@ static Vec3s gVec3sZero = {0, 0, 0}; static struct Object *try_allocate_object(void) { - struct ObjectNode *nextObj; - nextObj = (struct ObjectNode *)malloc(sizeof(struct Object)); + struct ObjectNode *nextObj = (struct ObjectNode *)malloc(sizeof(struct Object)); nextObj->prev = NULL; nextObj->next = NULL; return (struct Object *)nextObj; @@ -22,7 +21,6 @@ static struct Object *try_allocate_object(void) static struct Object *allocate_object(void) { - s32 i; struct Object *obj = try_allocate_object(); // Initialize object fields @@ -33,7 +31,7 @@ static struct Object *allocate_object(void) obj->collidedObjInteractTypes = 0; obj->numCollidedObjs = 0; - for (i = 0; i < 0x50; i++) + for (s32 i = 0; i < 0x50; i++) { #ifdef _WIN32 obj->rawData.asS32[i] = 0; @@ -89,8 +87,7 @@ static struct Object *allocate_object(void) static struct Object *create_object(void) { - struct Object *obj; - obj = allocate_object(); + struct Object *obj = allocate_object(); obj->curBhvCommand = NULL; obj->behavior = NULL; return obj; @@ -115,9 +112,7 @@ static void geo_obj_init(struct GraphNodeObject *graphNode, void *sharedChild, V static struct Object *spawn_object_at_origin(void) { - struct Object *obj; - obj = create_object(); - + struct Object *obj = create_object(); obj->parentObj = NULL; obj->header.gfx.areaIndex = 0; obj->header.gfx.activeAreaIndex = 0; @@ -194,11 +189,9 @@ void bhv_mario_update(void) void create_transformation_from_matrices(Mat4 a0, Mat4 a1, Mat4 a2) { - f32 spC, sp8, sp4; - - spC = a2[3][0] * a2[0][0] + a2[3][1] * a2[0][1] + a2[3][2] * a2[0][2]; - sp8 = a2[3][0] * a2[1][0] + a2[3][1] * a2[1][1] + a2[3][2] * a2[1][2]; - sp4 = a2[3][0] * a2[2][0] + a2[3][1] * a2[2][1] + a2[3][2] * a2[2][2]; + f32 spC = a2[3][0] * a2[0][0] + a2[3][1] * a2[0][1] + a2[3][2] * a2[0][2]; + f32 sp8 = a2[3][0] * a2[1][0] + a2[3][1] * a2[1][1] + a2[3][2] * a2[1][2]; + f32 sp4 = a2[3][0] * a2[2][0] + a2[3][1] * a2[2][1] + a2[3][2] * a2[2][2]; a0[0][0] = a1[0][0] * a2[0][0] + a1[0][1] * a2[0][1] + a1[0][2] * a2[0][2]; a0[0][1] = a1[0][0] * a2[1][0] + a1[0][1] * a2[1][1] + a1[0][2] * a2[1][2]; diff --git a/src/decomp/game/platform_displacement.c b/src/decomp/game/platform_displacement.c index e3a5300..8c6906f 100644 --- a/src/decomp/game/platform_displacement.c +++ b/src/decomp/game/platform_displacement.c @@ -98,9 +98,6 @@ void apply_platform_displacement(u32 isMario, struct SM64SurfaceObjectTransform Vec3f relativeOffset; Vec3f newObjectOffset; Vec3s rotation; - UNUSED s16 unused1; - UNUSED s16 unused2; - UNUSED s16 unused3; f32 displaceMatrix[4][4]; rotation[0] = platform->aAngleVelPitch; @@ -121,9 +118,9 @@ void apply_platform_displacement(u32 isMario, struct SM64SurfaceObjectTransform if (rotation[0] != 0 || rotation[1] != 0 || rotation[2] != 0) { - unused1 = rotation[0]; - unused2 = rotation[2]; - unused3 = platform->aFaceAngleYaw; + s16 unused1 = rotation[0]; + s16 unused2 = rotation[2]; + s16 unused3 = platform->aFaceAngleYaw; if (isMario) { diff --git a/src/decomp/game/rendering_graph_node.c b/src/decomp/game/rendering_graph_node.c index 11d29f2..052ce48 100644 --- a/src/decomp/game/rendering_graph_node.c +++ b/src/decomp/game/rendering_graph_node.c @@ -170,7 +170,6 @@ LookAt lookAt; static void geo_process_master_list_sub(struct GraphNodeMasterList *node) { struct DisplayListNode *currList; - s32 i; s32 enableZBuffer = (node->node.flags & GRAPH_RENDER_Z_BUFFER) != 0; // struct RenderModeContainer *modeList = &renderModeTable_1Cycle[enableZBuffer]; // struct RenderModeContainer *mode2List = &renderModeTable_2Cycle[enableZBuffer]; @@ -193,7 +192,7 @@ static void geo_process_master_list_sub(struct GraphNodeMasterList *node) // Mario ends up in the second master list for some reason. // The first item in the list is the projection matrix that is uninitialized, so just skip it. int xx = FALSE; - for (i = 1; i < GFX_NUM_MASTER_LISTS; i++) + for (s32 i = 1; i < GFX_NUM_MASTER_LISTS; i++) { if ((currList = node->listHeads[i]) != NULL) { @@ -256,13 +255,12 @@ static void geo_append_display_list(void *displayList, s16 layer) */ static void geo_process_master_list(struct GraphNodeMasterList *node) { - s32 i; UNUSED s32 sp1C; if (gCurGraphNodeMasterList == NULL && node->node.children != NULL) { gCurGraphNodeMasterList = node; - for (i = 0; i < GFX_NUM_MASTER_LISTS; i++) + for (s32 i = 0; i < GFX_NUM_MASTER_LISTS; i++) { node->listHeads[i] = NULL; } @@ -364,13 +362,12 @@ static void geo_process_level_of_detail(struct GraphNodeLevelOfDetail *node) static void geo_process_switch(struct GraphNodeSwitchCase *node) { struct GraphNode *selectedChild = node->fnNode.node.children; - s32 i; if (node->fnNode.func != NULL) { node->fnNode.func(GEO_CONTEXT_RENDER, &node->fnNode.node, gMatStack[gMatStackIndex]); } - for (i = 0; selectedChild != NULL && node->selectedCase > i; i++) + for (s32 i = 0; selectedChild != NULL && node->selectedCase > i; i++) { selectedChild = selectedChild->next; } @@ -879,23 +876,21 @@ static void geo_process_shadow(struct GraphNodeShadow *node) static s32 obj_is_in_view(struct GraphNodeObject *node, Mat4 matrix) { s16 cullingRadius; - s16 halfFov; // half of the fov in in-game angle units instead of degrees - struct GraphNode *geo; - f32 hScreenEdge; + // half of the fov in in-game angle units instead of degrees if (node->node.flags & GRAPH_RENDER_INVISIBLE) { return FALSE; } - geo = node->sharedChild; + struct GraphNode *geo = node->sharedChild; // ! @bug The aspect ratio is not accounted for. When the fov value is 45, // the horizontal effective fov is actually 60 degrees, so you can see objects // visibly pop in or out at the edge of the screen. - halfFov = (gCurGraphNodeCamFrustum->fov / 2.0f + 1.0f) * 32768.0f / 180.0f + 0.5f; + s16 halfFov = (gCurGraphNodeCamFrustum->fov / 2.0f + 1.0f) * 32768.0f / 180.0f + 0.5f; - hScreenEdge = -matrix[3][2] * sins(halfFov) / coss(halfFov); + f32 hScreenEdge = -matrix[3][2] * sins(halfFov) / coss(halfFov); // -matrix[3][2] is the depth, which gets multiplied by tan(halfFov) to get // the amount of units between the center of the screen and the horizontal edge // given the distance from the object to the camera. @@ -1274,10 +1269,8 @@ void geo_process_root_hack_single_node(struct GraphNode *node) display_list_pool_reset(); - Mtx *initialMatrix; - gDisplayListHeap = alloc_only_pool_init(); - initialMatrix = alloc_display_list(sizeof(*initialMatrix)); + Mtx *initialMatrix = alloc_display_list(sizeof(*initialMatrix)); gMatStackIndex = 0; gCurAnimType = 0; diff --git a/src/decomp/pc/alBnkfNew.c b/src/decomp/pc/alBnkfNew.c index 0f58358..ad401ab 100644 --- a/src/decomp/pc/alBnkfNew.c +++ b/src/decomp/pc/alBnkfNew.c @@ -5,8 +5,7 @@ void alSeqFileNew(ALSeqFile *f, u8 *base) { - int i; - for (i = 0; i < f->seqCount; i++) + for (int i = 0; i < f->seqCount; i++) { PATCH(f->seqArray[i].offset, base, u8 *); } @@ -14,11 +13,6 @@ void alSeqFileNew(ALSeqFile *f, u8 *base) static void _bnkfPatchBank(ALInstrument *inst, ALBankFile *f, u8 *table) { - int i; - ALSound *sound; - ALWaveTable *wavetable; - u8 *table2; - if (inst->flags) { return; @@ -26,22 +20,22 @@ static void _bnkfPatchBank(ALInstrument *inst, ALBankFile *f, u8 *table) inst->flags = 1; - for (i = 0; i < inst->soundCount; i++) + for (int i = 0; i < inst->soundCount; i++) { PATCH(inst->soundArray[i], f, ALSound *); - sound = inst->soundArray[i]; + ALSound *sound = inst->soundArray[i]; if (sound->flags) { continue; } - table2 = table; + u8 *table2 = table; sound->flags = 1; PATCH(sound->envelope, f, ALEnvelope *); PATCH(sound->keyMap, f, ALKeyMap *); PATCH(sound->wavetable, f, ALWaveTable *); - wavetable = sound->wavetable; + ALWaveTable *wavetable = sound->wavetable; if (wavetable->flags) { continue; @@ -75,16 +69,13 @@ static void unused(void) void alBnkfNew(ALBankFile *f, u8 *table) { - ALBank *bank; - int i; - int j; unused(); if (f->revision != AL_BANK_VERSION) { return; } - for (i = 0; i < f->bankCount; i++) + for (int i = 0; i < f->bankCount; i++) { PATCH(f->bankArray[i], f, ALBank *); if (f->bankArray[i] == NULL) @@ -92,7 +83,7 @@ void alBnkfNew(ALBankFile *f, u8 *table) continue; } - bank = f->bankArray[i]; + ALBank *bank = f->bankArray[i]; if (bank->flags == 0) { bank->flags = 1; @@ -101,7 +92,7 @@ void alBnkfNew(ALBankFile *f, u8 *table) PATCH(bank->percussion, f, ALInstrument *); _bnkfPatchBank(bank->percussion, f, table); } - for (j = 0; j < bank->instCount; j++) + for (int j = 0; j < bank->instCount; j++) { PATCH(bank->instArray[j], f, ALInstrument *); if (bank->instArray[j] != NULL) diff --git a/src/decomp/pc/mixer.c b/src/decomp/pc/mixer.c index b453b87..a08897c 100644 --- a/src/decomp/pc/mixer.c +++ b/src/decomp/pc/mixer.c @@ -474,7 +474,7 @@ void aADPCMdecImpl(uint8_t flags, ADPCM_STATE state) int16_t ins[8]; int16_t prev1 = out[-1]; int16_t prev2 = out[-2]; - int j, k; + int j; for (j = 0; j < 4; j++) { ins[j * 2] = (((*in >> 4) << 28) >> 28) << shift; @@ -483,7 +483,7 @@ void aADPCMdecImpl(uint8_t flags, ADPCM_STATE state) for (j = 0; j < 8; j++) { int32_t acc = tbl[0][j] * prev2 + tbl[1][j] * prev1 + (ins[j] << 11); - for (k = 0; k < j; k++) + for (int k = 0; k < j; k++) { acc += tbl[1][(j - k - 1)] * ins[k]; } @@ -931,7 +931,7 @@ void aEnvMixerImpl(uint8_t flags, ENVMIX_STATE state) int32_t step_diff[2]; int32_t vols[2][8]; - int c, i; + int i; if (flags & A_INIT) { @@ -964,7 +964,7 @@ void aEnvMixerImpl(uint8_t flags, ENVMIX_STATE state) do { - for (c = 0; c < 2; c++) + for (int c = 0; c < 2; c++) { for (i = 0; i < 8; i++) { diff --git a/src/decomp/tools/libmio0.c b/src/decomp/tools/libmio0.c index f46913e..f03958f 100644 --- a/src/decomp/tools/libmio0.c +++ b/src/decomp/tools/libmio0.c @@ -78,9 +78,7 @@ static int find_longest(const unsigned char *buf, int start_offset, int max_sear { int best_length = 0; int best_offset = 0; - int cur_length; - int search_len; - int farthest, off, i; + int i; int lb_idx; const unsigned char first = buf[start_offset]; lookback *lb = &lkbk[first]; @@ -93,7 +91,7 @@ static int find_longest(const unsigned char *buf, int start_offset, int max_sear // +cur_length // check at most the past 4096 values - farthest = MAX(start_offset - 4096, 0); + int farthest = MAX(start_offset - 4096, 0); // find starting index for (lb_idx = lb->start; lb_idx < lb->count && lb->indexes[lb_idx] < farthest; lb_idx++) { @@ -101,9 +99,9 @@ static int find_longest(const unsigned char *buf, int start_offset, int max_sear lb->start = lb_idx; for (; lb_idx < lb->count && lb->indexes[lb_idx] < start_offset; lb_idx++) { - off = lb->indexes[lb_idx]; + int off = lb->indexes[lb_idx]; // check at most requested max or up until start - search_len = MIN(max_search, start_offset - off); + int search_len = MIN(max_search, start_offset - off); for (i = 0; i < search_len; i++) { if (buf[start_offset + i] != buf[off + i]) @@ -111,7 +109,7 @@ static int find_longest(const unsigned char *buf, int start_offset, int max_sear break; } } - cur_length = i; + int cur_length = i; // if matched up until start, continue matching in already matched parts if (cur_length == search_len) { @@ -167,10 +165,9 @@ int mio0_decode(const unsigned char *in, unsigned char *out, unsigned int *end) int bit_idx = 0; int comp_idx = 0; int uncomp_idx = 0; - int valid; // extract header - valid = mio0_decode_header(in, &head); + int valid = mio0_decode_header(in, &head); // verify MIO0 header if (!valid) { @@ -190,14 +187,11 @@ int mio0_decode(const unsigned char *in, unsigned char *out, unsigned int *end) else { // 0 - read compressed data - int idx; - int length; - int i; const unsigned char *vals = &in[head.comp_offset + comp_idx]; comp_idx += 2; - length = ((vals[0] & 0xF0) >> 4) + 3; - idx = ((vals[0] & 0x0F) << 8) + vals[1] + 1; - for (i = 0; i < length; i++) + int length = ((vals[0] & 0xF0) >> 4) + 3; + int idx = ((vals[0] & 0x0F) << 8) + vals[1] + 1; + for (int i = 0; i < length; i++) { out[bytes_written] = out[bytes_written - idx]; bytes_written++; @@ -216,26 +210,18 @@ int mio0_decode(const unsigned char *in, unsigned char *out, unsigned int *end) int mio0_encode(const unsigned char *in, unsigned int length, unsigned char *out) { - unsigned char *bit_buf; - unsigned char *comp_buf; - unsigned char *uncomp_buf; - unsigned int bit_length; - unsigned int comp_offset; - unsigned int uncomp_offset; unsigned int bytes_proc = 0; - int bytes_written; int bit_idx = 0; int comp_idx = 0; int uncomp_idx = 0; - lookback *lookbacks; // initialize lookback buffer - lookbacks = lookback_init(); + lookback *lookbacks = lookback_init(); // allocate some temporary buffers worst case size - bit_buf = malloc((length + 7) / 8); // 1-bit/byte - comp_buf = malloc(length); // 16-bits/2bytes - uncomp_buf = malloc(length); // all uncompressed + unsigned char *bit_buf = malloc((length + 7) / 8); // 1-bit/byte + unsigned char *comp_buf = malloc(length); // 16-bits/2bytes + unsigned char *uncomp_buf = malloc(length); // all uncompressed memset(bit_buf, 0, (length + 7) / 8); // encode data @@ -297,11 +283,11 @@ int mio0_encode(const unsigned char *in, unsigned int length, unsigned char *out // compute final sizes and offsets // +7 so int division accounts for all bits - bit_length = (bit_idx + 7) / 8; + unsigned int bit_length = (bit_idx + 7) / 8; // compressed data after control bits and aligned to 4-byte boundary - comp_offset = ALIGN(MIO0_HEADER_LENGTH + bit_length, 4); - uncomp_offset = comp_offset + comp_idx; - bytes_written = uncomp_offset + uncomp_idx; + unsigned int comp_offset = ALIGN(MIO0_HEADER_LENGTH + bit_length, 4); + unsigned int uncomp_offset = comp_offset + comp_idx; + int bytes_written = uncomp_offset + uncomp_idx; // output header memcpy(out, "MIO0", 4); @@ -340,18 +326,15 @@ static FILE *mio0_open_out_file(const char *out_file) int mio0_decode_file(const char *in_file, unsigned long offset, const char *out_file) { mio0_header_t head; - FILE *in; FILE *out; unsigned char *in_buf = NULL; unsigned char *out_buf = NULL; - long file_size; int ret_val = 0; - size_t bytes_read; int bytes_decoded; int bytes_written; int valid; - in = fopen(in_file, "rb"); + FILE *in = fopen(in_file, "rb"); if (in == NULL) { return 1; @@ -359,12 +342,12 @@ int mio0_decode_file(const char *in_file, unsigned long offset, const char *out_ // allocate buffer to read from offset to end of file fseek(in, 0, SEEK_END); - file_size = ftell(in); + long file_size = ftell(in); in_buf = malloc(file_size - offset); fseek(in, offset, SEEK_SET); // read bytes - bytes_read = fread(in_buf, 1, file_size - offset, in); + size_t bytes_read = fread(in_buf, 1, file_size - offset, in); if (bytes_read != file_size - offset) { ret_val = 2; @@ -423,17 +406,14 @@ free_all: if (out_buf) int mio0_encode_file(const char *in_file, const char *out_file) { - FILE *in; FILE *out; unsigned char *in_buf = NULL; unsigned char *out_buf = NULL; - size_t file_size; - size_t bytes_read; int bytes_encoded; int bytes_written; int ret_val = 0; - in = fopen(in_file, "rb"); + FILE *in = fopen(in_file, "rb"); if (in == NULL) { return 1; @@ -441,12 +421,12 @@ int mio0_encode_file(const char *in_file, const char *out_file) // allocate buffer to read entire contents of files fseek(in, 0, SEEK_END); - file_size = ftell(in); + size_t file_size = ftell(in); fseek(in, 0, SEEK_SET); in_buf = malloc(file_size); // read bytes - bytes_read = fread(in_buf, 1, file_size, in); + size_t bytes_read = fread(in_buf, 1, file_size, in); if (bytes_read != file_size) { ret_val = 2; diff --git a/src/decomp/tools/n64graphics.c b/src/decomp/tools/n64graphics.c index 6ba36d1..362abc1 100644 --- a/src/decomp/tools/n64graphics.c +++ b/src/decomp/tools/n64graphics.c @@ -42,9 +42,8 @@ typedef struct rgba *raw2rgba(const uint8_t *raw, int width, int height, int depth) { rgba *img; - int img_size; - img_size = width * height * sizeof(*img); + int img_size = width * height * sizeof(*img); img = malloc(img_size); if (!img) { @@ -79,9 +78,8 @@ rgba *raw2rgba(const uint8_t *raw, int width, int height, int depth) ia *raw2ia(const uint8_t *raw, int width, int height, int depth) { ia *img; - int img_size; - img_size = width * height * sizeof(*img); + int img_size = width * height * sizeof(*img); img = malloc(img_size); if (!img) { @@ -108,8 +106,7 @@ ia *raw2ia(const uint8_t *raw, int width, int height, int depth) case 4: for (int i = 0; i < width * height; i++) { - uint8_t bits; - bits = raw[i / 2]; + uint8_t bits = raw[i / 2]; if (i % 2) { bits &= 0xF; @@ -125,10 +122,8 @@ ia *raw2ia(const uint8_t *raw, int width, int height, int depth) case 1: for (int i = 0; i < width * height; i++) { - uint8_t bits; - uint8_t mask; - bits = raw[i / 8]; - mask = 1 << (7 - i % 8); // MSb->LSb + uint8_t bits = raw[i / 8]; + uint8_t mask = 1 << (7 - i % 8); // MSb->LSb bits = bits & mask ? 0xFF : 0x00; img[i].intensity = bits; img[i].alpha = bits; @@ -145,9 +140,8 @@ ia *raw2ia(const uint8_t *raw, int width, int height, int depth) ia *raw2i(const uint8_t *raw, int width, int height, int depth) { ia *img = NULL; - int img_size; - img_size = width * height * sizeof(*img); + int img_size = width * height * sizeof(*img); img = malloc(img_size); if (!img) { @@ -167,8 +161,7 @@ ia *raw2i(const uint8_t *raw, int width, int height, int depth) case 4: for (int i = 0; i < width * height; i++) { - uint8_t bits; - bits = raw[i / 2]; + uint8_t bits = raw[i / 2]; if (i % 2) { bits &= 0xF; @@ -195,12 +188,9 @@ ia *raw2i(const uint8_t *raw, int width, int height, int depth) // convert CI raw data and palette to raw data (either RGBA16 or IA16) uint8_t *ci2raw(const uint8_t *rawci, const uint8_t *palette, int width, int height, int ci_depth) { - uint8_t *raw; - int raw_size; - // first convert to raw RGBA - raw_size = sizeof(uint16_t) * width * height; - raw = malloc(raw_size); + int raw_size = sizeof(uint16_t) * width * height; + uint8_t *raw = malloc(raw_size); if (!raw) { ERROR("Error allocating %u bytes\n", raw_size); @@ -239,11 +229,10 @@ int rgba2raw(uint8_t *raw, const rgba *img, int width, int height, int depth) { for (int i = 0; i < width * height; i++) { - uint8_t r, g, b, a; - r = SCALE_8_5(img[i].red); - g = SCALE_8_5(img[i].green); - b = SCALE_8_5(img[i].blue); - a = img[i].alpha ? 0x1 : 0x0; + uint8_t r = SCALE_8_5(img[i].red); + uint8_t g = SCALE_8_5(img[i].green); + uint8_t b = SCALE_8_5(img[i].blue); + uint8_t a = img[i].alpha ? 0x1 : 0x0; raw[i * 2] = r << 3 | g >> 2; raw[i * 2 + 1] = (g & 0x3) << 6 | b << 1 | a; } @@ -438,7 +427,6 @@ rgba *png2rgba(const char *png_filename, int *width, int *height) int w = 0; int h = 0; int channels = 0; - int img_size; stbi_uc *data = stbi_load(png_filename, &w, &h, &channels, STBI_default); if (!data || w <= 0 || h <= 0) @@ -448,7 +436,7 @@ rgba *png2rgba(const char *png_filename, int *width, int *height) } INFO("Read \"%s\" %dx%d channels: %d\n", png_filename, w, h, channels); - img_size = w * h * sizeof(*img); + int img_size = w * h * sizeof(*img); img = malloc(img_size); if (!img) { @@ -511,7 +499,6 @@ ia *png2ia(const char *png_filename, int *width, int *height) ia *img = NULL; int w = 0, h = 0; int channels = 0; - int img_size; stbi_uc *data = stbi_load(png_filename, &w, &h, &channels, STBI_default); if (!data || w <= 0 || h <= 0) @@ -521,7 +508,7 @@ ia *png2ia(const char *png_filename, int *width, int *height) } INFO("Read \"%s\" %dx%d channels: %d\n", png_filename, w, h, channels); - img_size = w * h * sizeof(*img); + int img_size = w * h * sizeof(*img); img = malloc(img_size); if (!img) { @@ -595,8 +582,7 @@ static int pal_find_color(const palette_t *pal, uint16_t val) // returns palette index entered or -1 if palette full static int pal_add_color(palette_t *pal, uint16_t val) { - int idx; - idx = pal_find_color(pal, val); + int idx = pal_find_color(pal, val); if (idx < 0) { if (pal->used == pal->max) diff --git a/src/decomp/tools/stb/stb_image.h b/src/decomp/tools/stb/stb_image.h index b64d361..8516d22 100644 --- a/src/decomp/tools/stb/stb_image.h +++ b/src/decomp/tools/stb/stb_image.h @@ -1056,14 +1056,12 @@ static void *stbi__load_main(stbi__context *s, int *x, int *y, int *comp, int re static stbi_uc *stbi__convert_16_to_8(stbi__uint16 *orig, int w, int h, int channels) { - int i; int img_len = w * h * channels; - stbi_uc *reduced; - reduced = (stbi_uc *)stbi__malloc(img_len); + stbi_uc *reduced = (stbi_uc *)stbi__malloc(img_len); if (reduced == NULL) return stbi__errpuc("outofmem", "Out of memory"); - for (i = 0; i < img_len; ++i) + for (int i = 0; i < img_len; ++i) reduced[i] = (stbi_uc)(orig[i] >> 8 & 0xFF); // top half of each byte is sufficient approx of 16->8 bit scaling STBI_FREE(orig); @@ -1072,14 +1070,12 @@ static stbi_uc *stbi__convert_16_to_8(stbi__uint16 *orig, int w, int h, int chan static stbi__uint16 *stbi__convert_8_to_16(stbi_uc *orig, int w, int h, int channels) { - int i; int img_len = w * h * channels; - stbi__uint16 *enlarged; - enlarged = (stbi__uint16 *)stbi__malloc(img_len * 2); + stbi__uint16 *enlarged = (stbi__uint16 *)stbi__malloc(img_len * 2); if (enlarged == NULL) return (stbi__uint16 *)stbi__errpuc("outofmem", "Out of memory"); - for (i = 0; i < img_len; ++i) + for (int i = 0; i < img_len; ++i) enlarged[i] = (stbi__uint16)((orig[i] << 8) + orig[i]); // replicate to high and low byte, maps 0->0, 255->0xffff STBI_FREE(orig); @@ -1088,12 +1084,11 @@ static stbi__uint16 *stbi__convert_8_to_16(stbi_uc *orig, int w, int h, int chan static void stbi__vertical_flip(void *image, int w, int h, int bytes_per_pixel) { - int row; size_t bytes_per_row = (size_t)w * bytes_per_pixel; stbi_uc temp[2048]; stbi_uc *bytes = image; - for (row = 0; row < h >> 1; row++) + for (int row = 0; row < h >> 1; row++) { stbi_uc *row0 = bytes + row * bytes_per_row; stbi_uc *row1 = bytes + (h - row - 1) * bytes_per_row; @@ -1114,11 +1109,10 @@ static void stbi__vertical_flip(void *image, int w, int h, int bytes_per_pixel) static void stbi__vertical_flip_slices(void *image, int w, int h, int z, int bytes_per_pixel) { - int slice; int slice_size = w * h * bytes_per_pixel; stbi_uc *bytes = image; - for (slice = 0; slice < z; ++slice) + for (int slice = 0; slice < z; ++slice) { stbi__vertical_flip(bytes, w, h, bytes_per_pixel); bytes += slice_size; @@ -1210,19 +1204,17 @@ static FILE *stbi__fopen(char const *filename, char const *mode) STBIDEF stbi_uc *stbi_load(char const *filename, int *x, int *y, int *comp, int req_comp) { FILE *f = stbi__fopen(filename, "rb"); - unsigned char *result; if (!f) return stbi__errpuc("can't fopen", "Unable to open file"); - result = stbi_load_from_file(f, x, y, comp, req_comp); + unsigned char *result = stbi_load_from_file(f, x, y, comp, req_comp); fclose(f); return result; } STBIDEF stbi_uc *stbi_load_from_file(FILE *f, int *x, int *y, int *comp, int req_comp) { - unsigned char *result; stbi__context s; stbi__start_file(&s, f); - result = stbi__load_and_postprocess_8bit(&s, x, y, comp, req_comp); + unsigned char *result = stbi__load_and_postprocess_8bit(&s, x, y, comp, req_comp); if (result) { // need to 'unget' all the characters in the IO buffer @@ -1233,10 +1225,9 @@ STBIDEF stbi_uc *stbi_load_from_file(FILE *f, int *x, int *y, int *comp, int req STBIDEF stbi__uint16 *stbi_load_from_file_16(FILE *f, int *x, int *y, int *comp, int req_comp) { - stbi__uint16 *result; stbi__context s; stbi__start_file(&s, f); - result = stbi__load_and_postprocess_16bit(&s, x, y, comp, req_comp); + stbi__uint16 *result = stbi__load_and_postprocess_16bit(&s, x, y, comp, req_comp); if (result) { // need to 'unget' all the characters in the IO buffer @@ -1248,9 +1239,8 @@ STBIDEF stbi__uint16 *stbi_load_from_file_16(FILE *f, int *x, int *y, int *comp, STBIDEF stbi_us *stbi_load_16(char const *filename, int *x, int *y, int *comp, int req_comp) { FILE *f = stbi__fopen(filename, "rb"); - stbi__uint16 *result; if (!f) return (stbi_us *)stbi__errpuc("can't fopen", "Unable to open file"); - result = stbi_load_from_file_16(f, x, y, comp, req_comp); + stbi__uint16 *result = stbi_load_from_file_16(f, x, y, comp, req_comp); fclose(f); return result; } @@ -1289,11 +1279,10 @@ STBIDEF stbi_uc *stbi_load_from_callbacks(stbi_io_callbacks const *clbk, void *u #ifndef STBI_NO_GIF STBIDEF stbi_uc *stbi_load_gif_from_memory(stbi_uc const *buffer, int len, int **delays, int *x, int *y, int *z, int *comp, int req_comp) { - unsigned char *result; stbi__context s; stbi__start_mem(&s, buffer, len); - result = (unsigned char *)stbi__load_gif_main(&s, delays, x, y, z, comp, req_comp); + unsigned char *result = (unsigned char *)stbi__load_gif_main(&s, delays, x, y, z, comp, req_comp); if (stbi__vertically_flip_on_load) { stbi__vertical_flip_slices(result, *x, *y, *z, *comp); @@ -1512,12 +1501,10 @@ static int stbi__getn(stbi__context *s, stbi_uc *buffer, int n) int blen = (int)(s->img_buffer_end - s->img_buffer); if (blen < n) { - int res, count; - memcpy(buffer, s->img_buffer, blen); - count = s->io.read(s->io_user_data, (char *)buffer + blen, n - blen); - res = count == n - blen; + int count = s->io.read(s->io_user_data, (char *)buffer + blen, n - blen); + int res = count == n - blen; s->img_buffer = s->img_buffer_end; return res; } @@ -1584,20 +1571,19 @@ static stbi_uc stbi__compute_y(int r, int g, int b) static unsigned char *stbi__convert_format(unsigned char *data, int img_n, int req_comp, unsigned int x, unsigned int y) { - int i, j; - unsigned char *good; + int i; if (req_comp == img_n) return data; STBI_ASSERT(req_comp >= 1 && req_comp <= 4); - good = (unsigned char *)stbi__malloc_mad3(req_comp, x, y, 0); + unsigned char *good = (unsigned char *)stbi__malloc_mad3(req_comp, x, y, 0); if (good == NULL) { STBI_FREE(data); return stbi__errpuc("outofmem", "Out of memory"); } - for (j = 0; j < (int)y; ++j) + for (int j = 0; j < (int)y; ++j) { unsigned char *src = data + j * x * img_n; unsigned char *dest = good + j * x * req_comp; @@ -1685,20 +1671,19 @@ static stbi__uint16 stbi__compute_y_16(int r, int g, int b) static stbi__uint16 *stbi__convert_format16(stbi__uint16 *data, int img_n, int req_comp, unsigned int x, unsigned int y) { - int i, j; - stbi__uint16 *good; + int i; if (req_comp == img_n) return data; STBI_ASSERT(req_comp >= 1 && req_comp <= 4); - good = (stbi__uint16 *)stbi__malloc(req_comp * x * y * 2); + stbi__uint16 *good = (stbi__uint16 *)stbi__malloc(req_comp * x * y * 2); if (good == NULL) { STBI_FREE(data); return (stbi__uint16 *)stbi__errpuc("outofmem", "Out of memory"); } - for (j = 0; j < (int)y; ++j) + for (int j = 0; j < (int)y; ++j) { stbi__uint16 *src = data + j * x * img_n; stbi__uint16 *dest = good + j * x * req_comp; @@ -1941,7 +1926,6 @@ typedef struct static int stbi__build_huffman(stbi__huffman *h, int *count) { int i, j, k = 0; - unsigned int code; // build size list for each symbol (from JPEG spec) for (i = 0; i < 16; ++i) for (j = 0; j < count[i]; ++j) @@ -1949,7 +1933,7 @@ static int stbi__build_huffman(stbi__huffman *h, int *count) h->size[k] = 0; // compute actual symbols (from jpeg spec) - code = 0; + unsigned int code = 0; k = 0; for (j = 1; j <= 16; ++j) { @@ -1989,8 +1973,7 @@ static int stbi__build_huffman(stbi__huffman *h, int *count) // one go. static void stbi__build_fast_ac(stbi__int16 *fast_ac, stbi__huffman *h) { - int i; - for (i = 0; i < 1 << FAST_BITS; ++i) + for (int i = 0; i < 1 << FAST_BITS; ++i) { stbi_uc fast = h->fast[i]; fast_ac[i] = 0; @@ -2043,15 +2026,12 @@ static const stbi__uint32 stbi__bmask[17] = {0, 1, 3, 7, 15, 31, 63, 127, 255, 5 // decode a jpeg huffman value from the bitstream stbi_inline static int stbi__jpeg_huff_decode(stbi__jpeg *j, stbi__huffman *h) { - unsigned int temp; - int c, k; - if (j->code_bits < 16) stbi__grow_buffer_unsafe(j); // look at the top FAST_BITS and determine what symbol ID it is, // if the code is <= FAST_BITS - c = j->code_buffer >> (32 - FAST_BITS) & (1 << FAST_BITS) - 1; - k = h->fast[c]; + int c = j->code_buffer >> (32 - FAST_BITS) & (1 << FAST_BITS) - 1; + int k = h->fast[c]; if (k < 255) { int s = h->size[k]; @@ -2068,7 +2048,7 @@ stbi_inline static int stbi__jpeg_huff_decode(stbi__jpeg *j, stbi__huffman *h) // end; in other words, regardless of the number of bits, it // wants to be compared against something shifted to have 16; // that way we don't need to shift inside the loop. - temp = j->code_buffer >> 16; + unsigned int temp = j->code_buffer >> 16; for (k = FAST_BITS + 1; ; ++k) if (temp < h->maxcode[k]) break; @@ -2099,12 +2079,10 @@ static const int stbi__jbias[16] = {0, -1, -3, -7, -15, -31, -63, -127, -255, -5 // always extends everything it receives. stbi_inline static int stbi__extend_receive(stbi__jpeg *j, int n) { - unsigned int k; - int sgn; if (j->code_bits < n) stbi__grow_buffer_unsafe(j); - sgn = (stbi__int32)j->code_buffer >> 31; // sign bit is always in MSB - k = stbi_lrot(j->code_buffer, n); + int sgn = (stbi__int32)j->code_buffer >> 31; // sign bit is always in MSB + unsigned int k = stbi_lrot(j->code_buffer, n); STBI_ASSERT(n >= 0 && n < (int)(sizeof(stbi__bmask) / sizeof(*stbi__bmask))); j->code_buffer = k & ~stbi__bmask[n]; k &= stbi__bmask[n]; @@ -2115,9 +2093,8 @@ stbi_inline static int stbi__extend_receive(stbi__jpeg *j, int n) // get some unsigned bits stbi_inline static int stbi__jpeg_get_bits(stbi__jpeg *j, int n) { - unsigned int k; if (j->code_bits < n) stbi__grow_buffer_unsafe(j); - k = stbi_lrot(j->code_buffer, n); + unsigned int k = stbi_lrot(j->code_buffer, n); j->code_buffer = k & ~stbi__bmask[n]; k &= stbi__bmask[n]; j->code_bits -= n; @@ -2126,9 +2103,8 @@ stbi_inline static int stbi__jpeg_get_bits(stbi__jpeg *j, int n) stbi_inline static int stbi__jpeg_get_bit(stbi__jpeg *j) { - unsigned int k; if (j->code_bits < 1) stbi__grow_buffer_unsafe(j); - k = j->code_buffer; + unsigned int k = j->code_buffer; j->code_buffer <<= 1; --j->code_bits; return k & 0x80000000; @@ -2154,30 +2130,27 @@ static const stbi_uc stbi__jpeg_dezigzag[64 + 15] = // decode one 64-entry block-- static int stbi__jpeg_decode_block(stbi__jpeg *j, short data[64], stbi__huffman *hdc, stbi__huffman *hac, stbi__int16 *fac, int b, stbi__uint16 *dequant) { - int diff, dc, k; - int t; - if (j->code_bits < 16) stbi__grow_buffer_unsafe(j); - t = stbi__jpeg_huff_decode(j, hdc); + int t = stbi__jpeg_huff_decode(j, hdc); if (t < 0) return stbi__err("bad huffman code", "Corrupt JPEG"); // 0 all the ac values now so we can do it 32-bits at a time memset(data, 0, 64 * sizeof(data[0])); - diff = t ? stbi__extend_receive(j, t) : 0; - dc = j->img_comp[b].dc_pred + diff; + int diff = t ? stbi__extend_receive(j, t) : 0; + int dc = j->img_comp[b].dc_pred + diff; j->img_comp[b].dc_pred = dc; data[0] = (short)(dc * dequant[0]); // decode AC components, see JPEG spec - k = 1; + int k = 1; do { unsigned int zig; - int c, r, s; + int s; if (j->code_bits < 16) stbi__grow_buffer_unsafe(j); - c = j->code_buffer >> (32 - FAST_BITS) & (1 << FAST_BITS) - 1; - r = fac[c]; + int c = j->code_buffer >> (32 - FAST_BITS) & (1 << FAST_BITS) - 1; + int r = fac[c]; if (r) { // fast-AC path k += r >> 4 & 15; // run @@ -2214,8 +2187,6 @@ static int stbi__jpeg_decode_block(stbi__jpeg *j, short data[64], stbi__huffman static int stbi__jpeg_decode_block_prog_dc(stbi__jpeg *j, short data[64], stbi__huffman *hdc, int b) { - int diff, dc; - int t; if (j->spec_end != 0) return stbi__err("can't merge dc and ac", "Corrupt JPEG"); if (j->code_bits < 16) stbi__grow_buffer_unsafe(j); @@ -2224,10 +2195,10 @@ static int stbi__jpeg_decode_block_prog_dc(stbi__jpeg *j, short data[64], stbi__ { // first scan for DC coefficient, must be first memset(data, 0, 64 * sizeof(data[0])); // 0 all the ac values now - t = stbi__jpeg_huff_decode(j, hdc); - diff = t ? stbi__extend_receive(j, t) : 0; + int t = stbi__jpeg_huff_decode(j, hdc); + int diff = t ? stbi__extend_receive(j, t) : 0; - dc = j->img_comp[b].dc_pred + diff; + int dc = j->img_comp[b].dc_pred + diff; j->img_comp[b].dc_pred = dc; data[0] = (short)(dc << j->succ_low); } @@ -2261,10 +2232,10 @@ static int stbi__jpeg_decode_block_prog_ac(stbi__jpeg *j, short data[64], stbi__ do { unsigned int zig; - int c, r, s; + int s; if (j->code_bits < 16) stbi__grow_buffer_unsafe(j); - c = j->code_buffer >> (32 - FAST_BITS) & (1 << FAST_BITS) - 1; - r = fac[c]; + int c = j->code_buffer >> (32 - FAST_BITS) & (1 << FAST_BITS) - 1; + int r = fac[c]; if (r) { // fast-AC path k += r >> 4 & 15; // run @@ -2330,11 +2301,10 @@ static int stbi__jpeg_decode_block_prog_ac(stbi__jpeg *j, short data[64], stbi__ k = j->spec_start; do { - int r, s; int rs = stbi__jpeg_huff_decode(j, hac); // @OPTIMIZE see if we can use the fast path here, advance-by-r is so slow, eh if (rs < 0) return stbi__err("bad huffman code", "Corrupt JPEG"); - s = rs & 15; - r = rs >> 4; + int s = rs & 15; + int r = rs >> 4; if (s == 0) { if (r < 15) @@ -2962,7 +2932,6 @@ static int stbi__parse_entropy_coded_data(stbi__jpeg *z) { if (z->scan_n == 1) { - int i, j; STBI_SIMD_ALIGN(short, data[64]); int n = z->order[0]; // non-interleaved data, we just need to process one block at a time, @@ -2971,9 +2940,9 @@ static int stbi__parse_entropy_coded_data(stbi__jpeg *z) // component has, independent of interleaved MCU blocking and such int w = (z->img_comp[n].x + 7) >> 3; int h = (z->img_comp[n].y + 7) >> 3; - for (j = 0; j < h; ++j) + for (int j = 0; j < h; ++j) { - for (i = 0; i < w; ++i) + for (int i = 0; i < w; ++i) { int ha = z->img_comp[n].ha; if (!stbi__jpeg_decode_block(z, data, z->huff_dc + z->img_comp[n].hd, z->huff_ac + ha, z->fast_ac[ha], n, z->dequant[z->img_comp[n].tq])) return 0; @@ -2993,21 +2962,20 @@ static int stbi__parse_entropy_coded_data(stbi__jpeg *z) } else { // interleaved - int i, j, k, x, y; STBI_SIMD_ALIGN(short, data[64]); - for (j = 0; j < z->img_mcu_y; ++j) + for (int j = 0; j < z->img_mcu_y; ++j) { - for (i = 0; i < z->img_mcu_x; ++i) + for (int i = 0; i < z->img_mcu_x; ++i) { // scan an interleaved mcu... process scan_n components in order - for (k = 0; k < z->scan_n; ++k) + for (int k = 0; k < z->scan_n; ++k) { int n = z->order[k]; // scan out an mcu's worth of this component; that's just determined // by the basic H and V specified for the component - for (y = 0; y < z->img_comp[n].v; ++y) + for (int y = 0; y < z->img_comp[n].v; ++y) { - for (x = 0; x < z->img_comp[n].h; ++x) + for (int x = 0; x < z->img_comp[n].h; ++x) { int x2 = (i * z->img_comp[n].h + x) * 8; int y2 = (j * z->img_comp[n].v + y) * 8; @@ -3034,7 +3002,6 @@ static int stbi__parse_entropy_coded_data(stbi__jpeg *z) { if (z->scan_n == 1) { - int i, j; int n = z->order[0]; // non-interleaved data, we just need to process one block at a time, // in trivial scanline order @@ -3042,9 +3009,9 @@ static int stbi__parse_entropy_coded_data(stbi__jpeg *z) // component has, independent of interleaved MCU blocking and such int w = (z->img_comp[n].x + 7) >> 3; int h = (z->img_comp[n].y + 7) >> 3; - for (j = 0; j < h; ++j) + for (int j = 0; j < h; ++j) { - for (i = 0; i < w; ++i) + for (int i = 0; i < w; ++i) { short *data = z->img_comp[n].coeff + 64 * (i + j * z->img_comp[n].coeff_w); if (z->spec_start == 0) @@ -3071,20 +3038,19 @@ static int stbi__parse_entropy_coded_data(stbi__jpeg *z) } else { // interleaved - int i, j, k, x, y; - for (j = 0; j < z->img_mcu_y; ++j) + for (int j = 0; j < z->img_mcu_y; ++j) { - for (i = 0; i < z->img_mcu_x; ++i) + for (int i = 0; i < z->img_mcu_x; ++i) { // scan an interleaved mcu... process scan_n components in order - for (k = 0; k < z->scan_n; ++k) + for (int k = 0; k < z->scan_n; ++k) { int n = z->order[k]; // scan out an mcu's worth of this component; that's just determined // by the basic H and V specified for the component - for (y = 0; y < z->img_comp[n].v; ++y) + for (int y = 0; y < z->img_comp[n].v; ++y) { - for (x = 0; x < z->img_comp[n].h; ++x) + for (int x = 0; x < z->img_comp[n].h; ++x) { int x2 = i * z->img_comp[n].h + x; int y2 = j * z->img_comp[n].v + y; @@ -3111,8 +3077,7 @@ static int stbi__parse_entropy_coded_data(stbi__jpeg *z) static void stbi__jpeg_dequantize(short *data, stbi__uint16 *dequant) { - int i; - for (i = 0; i < 64; ++i) + for (int i = 0; i < 64; ++i) data[i] *= dequant[i]; } @@ -3121,14 +3086,13 @@ static void stbi__jpeg_finish(stbi__jpeg *z) if (z->progressive) { // dequantize and idct the data - int i, j, n; - for (n = 0; n < z->s->img_n; ++n) + for (int n = 0; n < z->s->img_n; ++n) { int w = (z->img_comp[n].x + 7) >> 3; int h = (z->img_comp[n].y + 7) >> 3; - for (j = 0; j < h; ++j) + for (int j = 0; j < h; ++j) { - for (i = 0; i < w; ++i) + for (int i = 0; i < w; ++i) { short *data = z->img_comp[n].coeff + 64 * (i + j * z->img_comp[n].coeff_w); stbi__jpeg_dequantize(data, z->dequant[z->img_comp[n].tq]); @@ -3158,11 +3122,11 @@ static int stbi__process_marker(stbi__jpeg *z, int m) { int q = stbi__get8(z->s); int p = q >> 4, sixteen = p != 0; - int t = q & 15, i; + int t = q & 15; if (p != 0 && p != 1) return stbi__err("bad DQT type", "Corrupt JPEG"); if (t > 3) return stbi__err("bad DQT table", "Corrupt JPEG"); - for (i = 0; i < 64; ++i) + for (int i = 0; i < 64; ++i) z->dequant[t][stbi__jpeg_dezigzag[i]] = (stbi__uint16)(sixteen ? stbi__get16be(z->s) : stbi__get8(z->s)); L -= sixteen ? 129 : 65; } @@ -3220,8 +3184,7 @@ static int stbi__process_marker(stbi__jpeg *z, int m) { // JFIF APP0 segment static const unsigned char tag[5] = {'J', 'F', 'I', 'F', '\0'}; int ok = 1; - int i; - for (i = 0; i < 5; ++i) + for (int i = 0; i < 5; ++i) if (stbi__get8(z->s) != tag[i]) ok = 0; L -= 5; @@ -3232,8 +3195,7 @@ static int stbi__process_marker(stbi__jpeg *z, int m) { // Adobe APP14 segment static const unsigned char tag[6] = {'A', 'd', 'o', 'b', 'e', '\0'}; int ok = 1; - int i; - for (i = 0; i < 6; ++i) + for (int i = 0; i < 6; ++i) if (stbi__get8(z->s) != tag[i]) ok = 0; L -= 6; @@ -3257,12 +3219,11 @@ static int stbi__process_marker(stbi__jpeg *z, int m) // after we see SOS static int stbi__process_scan_header(stbi__jpeg *z) { - int i; int Ls = stbi__get16be(z->s); z->scan_n = stbi__get8(z->s); if (z->scan_n < 1 || z->scan_n > 4 || z->scan_n > z->s->img_n) return stbi__err("bad SOS component count", "Corrupt JPEG"); if (Ls != 6 + 2 * z->scan_n) return stbi__err("bad SOS len", "Corrupt JPEG"); - for (i = 0; i < z->scan_n; ++i) + for (int i = 0; i < z->scan_n; ++i) { int id = stbi__get8(z->s), which; int q = stbi__get8(z->s); @@ -3278,10 +3239,9 @@ static int stbi__process_scan_header(stbi__jpeg *z) } { - int aa; z->spec_start = stbi__get8(z->s); z->spec_end = stbi__get8(z->s); // should be 63, but might be 0 - aa = stbi__get8(z->s); + int aa = stbi__get8(z->s); z->succ_high = aa >> 4; z->succ_low = aa & 15; if (z->progressive) @@ -3302,8 +3262,7 @@ static int stbi__process_scan_header(stbi__jpeg *z) static int stbi__free_jpeg_components(stbi__jpeg *z, int ncomp, int why) { - int i; - for (i = 0; i < ncomp; ++i) + for (int i = 0; i < ncomp; ++i) { if (z->img_comp[i].raw_data) { @@ -3329,16 +3288,16 @@ static int stbi__free_jpeg_components(stbi__jpeg *z, int ncomp, int why) static int stbi__process_frame_header(stbi__jpeg *z, int scan) { stbi__context *s = z->s; - int Lf, p, i, q, h_max = 1, v_max = 1, c; - Lf = stbi__get16be(s); + int i, h_max = 1, v_max = 1; + int Lf = stbi__get16be(s); if (Lf < 11) return stbi__err("bad SOF len", "Corrupt JPEG"); // JPEG - p = stbi__get8(s); + int p = stbi__get8(s); if (p != 8) return stbi__err("only 8-bit", "JPEG format not supported: 8-bit only"); // JPEG baseline s->img_y = stbi__get16be(s); if (s->img_y == 0) return stbi__err("no header height", "JPEG format not supported: delayed height"); // Legal, but we don't handle it--but neither does IJG s->img_x = stbi__get16be(s); if (s->img_x == 0) return stbi__err("0 width", "Corrupt JPEG"); // JPEG requires - c = stbi__get8(s); + int c = stbi__get8(s); if (c != 3 && c != 1 && c != 4) return stbi__err("bad component count", "Corrupt JPEG"); s->img_n = c; for (i = 0; i < c; ++i) @@ -3356,7 +3315,7 @@ static int stbi__process_frame_header(stbi__jpeg *z, int scan) z->img_comp[i].id = stbi__get8(s); if (s->img_n == 3 && z->img_comp[i].id == rgb[i]) ++z->rgb; - q = stbi__get8(s); + int q = stbi__get8(s); z->img_comp[i].h = q >> 4; if (!z->img_comp[i].h || z->img_comp[i].h > 4) return stbi__err("bad H", "Corrupt JPEG"); z->img_comp[i].v = q & 15; @@ -3432,11 +3391,10 @@ static int stbi__process_frame_header(stbi__jpeg *z, int scan) static int stbi__decode_jpeg_header(stbi__jpeg *z, int scan) { - int m; z->jfif = 0; z->app14_color_transform = -1; // valid values are 0,1,2 z->marker = STBI__MARKER_none; // initialize cached marker to empty - m = stbi__get_marker(z); + int m = stbi__get_marker(z); if (!stbi__SOI(m)) return stbi__err("no SOI", "Corrupt JPEG"); if (scan == STBI__SCAN_type) return 1; m = stbi__get_marker(z); @@ -3527,9 +3485,8 @@ static stbi_uc *resample_row_1(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, static stbi_uc *stbi__resample_row_v_2(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs) { // need to generate two samples vertically for every one in input - int i; STBI_NOTUSED(hs); - for (i = 0; i < w; ++i) + for (int i = 0; i < w; ++i) out[i] = stbi__div4(3 * in_near[i] + in_far[i] + 2); return out; } @@ -3569,18 +3526,17 @@ static stbi_uc *stbi__resample_row_h_2(stbi_uc *out, stbi_uc *in_near, stbi_uc * static stbi_uc *stbi__resample_row_hv_2(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs) { // need to generate 2x2 samples for every one in input - int i, t0, t1; if (w == 1) { out[0] = out[1] = stbi__div4(3 * in_near[0] + in_far[0] + 2); return out; } - t1 = 3 * in_near[0] + in_far[0]; + int t1 = 3 * in_near[0] + in_far[0]; out[0] = stbi__div4(t1 + 2); - for (i = 1; i < w; ++i) + for (int i = 1; i < w; ++i) { - t0 = t1; + int t0 = t1; t1 = 3 * in_near[i] + in_far[i]; out[i * 2 - 1] = stbi__div16(3 * t0 + t1 + 8); out[i * 2] = stbi__div16(3 * t1 + t0 + 8); @@ -3596,7 +3552,7 @@ static stbi_uc *stbi__resample_row_hv_2(stbi_uc *out, stbi_uc *in_near, stbi_uc static stbi_uc *stbi__resample_row_hv_2_simd(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs) { // need to generate 2x2 samples for every one in input - int i = 0, t0, t1; + int i = 0; if (w == 1) { @@ -3604,7 +3560,7 @@ static stbi_uc *stbi__resample_row_hv_2_simd(stbi_uc *out, stbi_uc *in_near, stb return out; } - t1 = 3 * in_near[0] + in_far[0]; + int t1 = 3 * in_near[0] + in_far[0]; // process groups of 8 pixels for as long as we can. // note we can't handle the last pixel in a row in this loop // because we need to handle the filter boundary conditions. @@ -3693,7 +3649,7 @@ static stbi_uc *stbi__resample_row_hv_2_simd(stbi_uc *out, stbi_uc *in_near, stb t1 = 3 * in_near[i + 7] + in_far[i + 7]; } - t0 = t1; + int t0 = t1; t1 = 3 * in_near[i] + in_far[i]; out[i * 2] = stbi__div16(3*t1+ t0+ 8); @@ -3715,10 +3671,9 @@ static stbi_uc *stbi__resample_row_hv_2_simd(stbi_uc *out, stbi_uc *in_near, stb static stbi_uc *stbi__resample_row_generic(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs) { // resample with nearest-neighbor - int i, j; STBI_NOTUSED(in_far); - for (i = 0; i < w; ++i) - for (j = 0; j < hs; ++j) + for (int i = 0; i < w; ++i) + for (int j = 0; j < hs; ++j) out[i * hs + j] = in_near[i]; return out; } @@ -3729,16 +3684,14 @@ static stbi_uc *stbi__resample_row_generic(stbi_uc *out, stbi_uc *in_near, stbi_ static void stbi__YCbCr_to_RGB_row(stbi_uc *out, const stbi_uc *y, const stbi_uc *pcb, const stbi_uc *pcr, int count, int step) { - int i; - for (i = 0; i < count; ++i) + for (int i = 0; i < count; ++i) { int y_fixed = (y[i] << 20) + (1 << 19); // rounding - int r, g, b; int cr = pcr[i] - 128; int cb = pcb[i] - 128; - r = y_fixed + cr * stbi__float2fixed(1.40200f); - g = y_fixed + cr * -stbi__float2fixed(0.71414f) + (cb * -stbi__float2fixed(0.34414f) & 0xffff0000); - b = y_fixed + cb * stbi__float2fixed(1.77200f); + int r = y_fixed + cr * stbi__float2fixed(1.40200f); + int g = y_fixed + cr * -stbi__float2fixed(0.71414f) + (cb * -stbi__float2fixed(0.34414f) & 0xffff0000); + int b = y_fixed + cb * stbi__float2fixed(1.77200f); r >>= 20; g >>= 20; b >>= 20; @@ -3884,12 +3837,11 @@ static void stbi__YCbCr_to_RGB_simd(stbi_uc *out, stbi_uc const *y, stbi_uc cons for (; i < count; ++i) { int y_fixed = (y[i] << 20) + (1 << 19); // rounding - int r, g, b; int cr = pcr[i] - 128; int cb = pcb[i] - 128; - r = y_fixed + cr * stbi__float2fixed(1.40200f); - g = y_fixed + cr * -stbi__float2fixed(0.71414f) + (cb * -stbi__float2fixed(0.34414f) & 0xffff0000); - b = y_fixed + cb * stbi__float2fixed(1.77200f); + int r = y_fixed + cr * stbi__float2fixed(1.40200f); + int g = y_fixed + cr * -stbi__float2fixed(0.71414f) + (cb * -stbi__float2fixed(0.34414f) & 0xffff0000); + int b = y_fixed + cb * stbi__float2fixed(1.77200f); r >>= 20; g >>= 20; b >>= 20; @@ -3965,7 +3917,7 @@ static stbi_uc stbi__blinn_8x8(stbi_uc x, stbi_uc y) static stbi_uc *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, int *comp, int req_comp) { - int n, decode_n, is_rgb; + int decode_n; z->s->img_n = 0; // make stbi__cleanup_jpeg safe // validate req_comp @@ -3979,9 +3931,9 @@ static stbi_uc *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, int *comp } // determine actual number of components to generate - n = req_comp ? req_comp : z->s->img_n >= 3 ? 3 : 1; + int n = req_comp ? req_comp : z->s->img_n >= 3 ? 3 : 1; - is_rgb = z->s->img_n == 3 && (z->rgb == 3 || (z->app14_color_transform == 0 && !z->jfif)); + int is_rgb = z->s->img_n == 3 && (z->rgb == 3 || (z->app14_color_transform == 0 && !z->jfif)); if (z->s->img_n == 3 && n < 3 && !is_rgb) decode_n = 1; @@ -3991,8 +3943,7 @@ static stbi_uc *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, int *comp // resample and color-convert { int k; - unsigned int i, j; - stbi_uc *output; + unsigned int i; stbi_uc *coutput[4]; stbi__resample res_comp[4]; @@ -4025,7 +3976,7 @@ static stbi_uc *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, int *comp } // can't error after this so, this is safe - output = (stbi_uc *)stbi__malloc_mad3(n, z->s->img_x, z->s->img_y, 1); + stbi_uc *output = (stbi_uc *)stbi__malloc_mad3(n, z->s->img_x, z->s->img_y, 1); if (!output) { stbi__cleanup_jpeg(z); @@ -4033,7 +3984,7 @@ static stbi_uc *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, int *comp } // now go ahead and resample - for (j = 0; j < z->s->img_y; ++j) + for (unsigned int j = 0; j < z->s->img_y; ++j) { stbi_uc *out = output + n * z->s->img_x * j; for (k = 0; k < decode_n; ++k) @@ -4170,23 +4121,21 @@ static stbi_uc *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, int *comp static void *stbi__jpeg_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri) { - unsigned char *result; stbi__jpeg *j = stbi__malloc(sizeof(stbi__jpeg)); STBI_NOTUSED(ri); j->s = s; stbi__setup_jpeg(j); - result = load_jpeg_image(j, x, y, comp, req_comp); + unsigned char *result = load_jpeg_image(j, x, y, comp, req_comp); STBI_FREE(j); return result; } static int stbi__jpeg_test(stbi__context *s) { - int r; stbi__jpeg *j = stbi__malloc(sizeof(stbi__jpeg)); j->s = s; stbi__setup_jpeg(j); - r = stbi__decode_jpeg_header(j, STBI__SCAN_type); + int r = stbi__decode_jpeg_header(j, STBI__SCAN_type); stbi__rewind(s); STBI_FREE(j); return r; @@ -4207,10 +4156,9 @@ static int stbi__jpeg_info_raw(stbi__jpeg *j, int *x, int *y, int *comp) static int stbi__jpeg_info(stbi__context *s, int *x, int *y, int *comp) { - int result; stbi__jpeg *j = stbi__malloc(sizeof(stbi__jpeg)); j->s = s; - result = stbi__jpeg_info_raw(j, x, y, comp); + int result = stbi__jpeg_info_raw(j, x, y, comp); STBI_FREE(j); return result; } @@ -4261,7 +4209,7 @@ stbi_inline static int stbi__bit_reverse(int v, int bits) static int stbi__zbuild_huffman(stbi__zhuffman *z, const stbi_uc *sizelist, int num) { int i, k = 0; - int code, next_code[16], sizes[17]; + int next_code[16], sizes[17]; // DEFLATE spec for generating codes memset(sizes, 0, sizeof(sizes)); @@ -4272,7 +4220,7 @@ static int stbi__zbuild_huffman(stbi__zhuffman *z, const stbi_uc *sizelist, int for (i = 1; i < 16; ++i) if (sizes[i] > 1 << i) return stbi__err("bad sizes", "Corrupt PNG"); - code = 0; + int code = 0; for (i = 1; i < 16; ++i) { next_code[i] = code; @@ -4349,9 +4297,8 @@ static void stbi__fill_bits(stbi__zbuf *z) stbi_inline static unsigned int stbi__zreceive(stbi__zbuf *z, int n) { - unsigned int k; if (z->num_bits < n) stbi__fill_bits(z); - k = z->code_buffer & (1 << n) - 1; + unsigned int k = z->code_buffer & (1 << n) - 1; z->code_buffer >>= n; z->num_bits -= n; return k; @@ -4359,16 +4306,16 @@ stbi_inline static unsigned int stbi__zreceive(stbi__zbuf *z, int n) static int stbi__zhuffman_decode_slowpath(stbi__zbuf *a, stbi__zhuffman *z) { - int b, s, k; + int s; // not resolved by fast table, so compute it the slow way // use jpeg approach, which requires MSbits at top - k = stbi__bit_reverse(a->code_buffer, 16); + int k = stbi__bit_reverse(a->code_buffer, 16); for (s = STBI__ZFAST_BITS + 1; ; ++s) if (k < z->maxcode[s]) break; if (s == 16) return -1; // invalid code! // code size is s, so: - b = (k >> (16 - s)) - z->firstcode[s] + z->firstsymbol[s]; + int b = (k >> (16 - s)) - z->firstcode[s] + z->firstsymbol[s]; STBI_ASSERT(z->size[b] == s); a->code_buffer >>= s; a->num_bits -= s; @@ -4377,12 +4324,11 @@ static int stbi__zhuffman_decode_slowpath(stbi__zbuf *a, stbi__zhuffman *z) stbi_inline static int stbi__zhuffman_decode(stbi__zbuf *a, stbi__zhuffman *z) { - int b, s; if (a->num_bits < 16) stbi__fill_bits(a); - b = z->fast[a->code_buffer & STBI__ZFAST_MASK]; + int b = z->fast[a->code_buffer & STBI__ZFAST_MASK]; if (b) { - s = b >> 9; + int s = b >> 9; a->code_buffer >>= s; a->num_bits -= s; return b & 511; @@ -4392,15 +4338,14 @@ stbi_inline static int stbi__zhuffman_decode(stbi__zbuf *a, stbi__zhuffman *z) static int stbi__zexpand(stbi__zbuf *z, char *zout, int n) // need to make room for n bytes { - char *q; - int cur, limit, old_limit; + int old_limit; z->zout = zout; if (!z->z_expandable) return stbi__err("output buffer limit", "Corrupt PNG"); - cur = (int)(z->zout - z->zout_start); - limit = old_limit = (int)(z->zout_end - z->zout_start); + int cur = (int)(z->zout - z->zout_start); + int limit = old_limit = (int)(z->zout_end - z->zout_start); while (cur + n > limit) limit *= 2; - q = (char *)STBI_REALLOC_SIZED(z->zout_start, old_limit, limit); + char *q = (char *)STBI_REALLOC_SIZED(z->zout_start, old_limit, limit); STBI_NOTUSED(old_limit); if (q == NULL) return stbi__err("outofmem", "Out of memory"); z->zout_start = q; @@ -4444,19 +4389,17 @@ static int stbi__parse_huffman_block(stbi__zbuf *a) } else { - stbi_uc *p; - int len, dist; if (z == 256) { a->zout = zout; return 1; } z -= 257; - len = stbi__zlength_base[z]; + int len = stbi__zlength_base[z]; if (stbi__zlength_extra[z]) len += stbi__zreceive(a, stbi__zlength_extra[z]); z = stbi__zhuffman_decode(a, &a->z_distance); if (z < 0) return stbi__err("bad huffman code", "Corrupt PNG"); - dist = stbi__zdist_base[z]; + int dist = stbi__zdist_base[z]; if (stbi__zdist_extra[z]) dist += stbi__zreceive(a, stbi__zdist_extra[z]); if (zout - a->zout_start < dist) return stbi__err("bad dist", "Corrupt PNG"); if (zout + len > a->zout_end) @@ -4464,7 +4407,7 @@ static int stbi__parse_huffman_block(stbi__zbuf *a) if (!stbi__zexpand(a, zout, len)) return 0; zout = a->zout; } - p = (stbi_uc *)(zout - dist); + stbi_uc *p = (stbi_uc *)(zout - dist); if (dist == 1) { // run of one byte; common in images. stbi_uc v = *p; @@ -4484,7 +4427,6 @@ static int stbi__compute_huffman_codes(stbi__zbuf *a) stbi__zhuffman z_codelength; stbi_uc lencodes[286 + 32 + 137]; //padding for maximum single op stbi_uc codelength_sizes[19]; - int i, n; int hlit = stbi__zreceive(a, 5) + 257; int hdist = stbi__zreceive(a, 5) + 1; @@ -4492,14 +4434,14 @@ static int stbi__compute_huffman_codes(stbi__zbuf *a) int ntot = hlit + hdist; memset(codelength_sizes, 0, sizeof(codelength_sizes)); - for (i = 0; i < hclen; ++i) + for (int i = 0; i < hclen; ++i) { int s = stbi__zreceive(a, 3); codelength_sizes[length_dezigzag[i]] = (stbi_uc)s; } if (!stbi__zbuild_huffman(&z_codelength, codelength_sizes, 19)) return 0; - n = 0; + int n = 0; while (n < ntot) { int c = stbi__zhuffman_decode(a, &z_codelength); @@ -4536,11 +4478,10 @@ static int stbi__compute_huffman_codes(stbi__zbuf *a) static int stbi__parse_uncompressed_block(stbi__zbuf *a) { stbi_uc header[4]; - int len, nlen, k; if (a->num_bits & 7) stbi__zreceive(a, a->num_bits & 7); // discard // drain the bit-packed data into header - k = 0; + int k = 0; while (a->num_bits > 0) { header[k++] = (stbi_uc)(a->code_buffer & 255); // suppress MSVC run-time check @@ -4551,8 +4492,8 @@ static int stbi__parse_uncompressed_block(stbi__zbuf *a) // now fill header the normal way while (k < 4) header[k++] = stbi__zget8(a); - len = header[1] * 256 + header[0]; - nlen = header[3] * 256 + header[2]; + int len = header[1] * 256 + header[0]; + int nlen = header[3] * 256 + header[2]; if (nlen != (len ^ 0xffff)) return stbi__err("zlib corrupt", "Corrupt PNG"); if (a->zbuffer + len > a->zbuffer_end) return stbi__err("read past buffer", "Corrupt PNG"); if (a->zout + len > a->zout_end) @@ -4607,7 +4548,7 @@ Init algorithm: static int stbi__parse_zlib(stbi__zbuf *a, int parse_header) { - int final, type; + int final; if (parse_header) if (!stbi__parse_zlib_header(a)) return 0; a->num_bits = 0; @@ -4615,7 +4556,7 @@ static int stbi__parse_zlib(stbi__zbuf *a, int parse_header) do { final = stbi__zreceive(a, 1); - type = stbi__zreceive(a, 2); + int type = stbi__zreceive(a, 2); if (type == 0) { if (!stbi__parse_uncompressed_block(a)) return 0; @@ -4766,8 +4707,7 @@ static stbi__pngchunk stbi__get_chunk_header(stbi__context *s) static int stbi__check_png_header(stbi__context *s) { static const stbi_uc png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10}; - int i; - for (i = 0; i < 8; ++i) + for (int i = 0; i < 8; ++i) if (stbi__get8(s) != png_sig[i]) return stbi__err("bad png sig", "Not a PNG"); return 1; } @@ -5135,23 +5075,20 @@ static int stbi__create_png_image(stbi__png *a, stbi_uc *image_data, stbi__uint3 { int bytes = depth == 16 ? 2 : 1; int out_bytes = out_n * bytes; - stbi_uc *final; - int p; if (!interlaced) return stbi__create_png_image_raw(a, image_data, image_data_len, out_n, a->s->img_x, a->s->img_y, depth, color); // de-interlacing - final = (stbi_uc *)stbi__malloc_mad3(a->s->img_x, a->s->img_y, out_bytes, 0); - for (p = 0; p < 7; ++p) + stbi_uc *final = (stbi_uc *)stbi__malloc_mad3(a->s->img_x, a->s->img_y, out_bytes, 0); + for (int p = 0; p < 7; ++p) { int xorig[] = {0, 4, 0, 2, 0, 1, 0}; int yorig[] = {0, 0, 4, 0, 2, 0, 1}; int xspc[] = {8, 8, 4, 4, 2, 2, 1}; int yspc[] = {8, 8, 8, 4, 4, 2, 2}; - int i, j, x, y; // pass1_x[4] = 0, pass1_x[5] = 1, pass1_x[12] = 1 - x = (a->s->img_x - xorig[p] + xspc[p] - 1) / xspc[p]; - y = (a->s->img_y - yorig[p] + yspc[p] - 1) / yspc[p]; + int x = (a->s->img_x - xorig[p] + xspc[p] - 1) / xspc[p]; + int y = (a->s->img_y - yorig[p] + yspc[p] - 1) / yspc[p]; if (x && y) { stbi__uint32 img_len = (((a->s->img_n * x * depth + 7) >> 3) + 1) * y; @@ -5160,9 +5097,9 @@ static int stbi__create_png_image(stbi__png *a, stbi_uc *image_data, stbi__uint3 STBI_FREE(final); return 0; } - for (j = 0; j < y; ++j) + for (int j = 0; j < y; ++j) { - for (i = 0; i < x; ++i) + for (int i = 0; i < x; ++i) { int out_y = j * yspc[p] + yorig[p]; int out_x = i * xspc[p] + xorig[p]; @@ -5243,13 +5180,13 @@ static int stbi__compute_transparency16(stbi__png *z, stbi__uint16 tc[3], int ou static int stbi__expand_png_palette(stbi__png *a, stbi_uc *palette, int len, int pal_img_n) { stbi__uint32 i, pixel_count = a->s->img_x * a->s->img_y; - stbi_uc *p, *temp_out, *orig = a->out; + stbi_uc *orig = a->out; - p = (stbi_uc *)stbi__malloc_mad2(pixel_count, pal_img_n, 0); + stbi_uc *p = (stbi_uc *)stbi__malloc_mad2(pixel_count, pal_img_n, 0); if (p == NULL) return stbi__err("outofmem", "Out of memory"); // between here and free(out) below, exitting would leak - temp_out = p; + stbi_uc *temp_out = p; if (pal_img_n == 3) { @@ -5380,7 +5317,6 @@ static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp) break; case STBI__PNG_TYPE('I', 'H', 'D', 'R'): { - int comp, filter; if (!first) return stbi__err("multiple IHDR", "Corrupt PNG"); first = 0; if (c.length != 13) return stbi__err("bad IHDR len", "Corrupt PNG"); @@ -5395,9 +5331,9 @@ static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp) if (color == 3 && z->depth == 16) return stbi__err("bad ctype", "Corrupt PNG"); if (color == 3) pal_img_n = 3; else if (color & 1) return stbi__err("bad ctype", "Corrupt PNG"); - comp = stbi__get8(s); + int comp = stbi__get8(s); if (comp) return stbi__err("bad comp method", "Corrupt PNG"); - filter = stbi__get8(s); + int filter = stbi__get8(s); if (filter) return stbi__err("bad filter method", "Corrupt PNG"); interlace = stbi__get8(s); if (interlace > 1) return stbi__err("bad interlace method", "Corrupt PNG"); @@ -5482,12 +5418,11 @@ static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp) if (ioff + c.length > idata_limit) { stbi__uint32 idata_limit_old = idata_limit; - stbi_uc *p; if (idata_limit == 0) idata_limit = c.length > 4096 ? c.length : 4096; while (ioff + c.length > idata_limit) idata_limit *= 2; STBI_NOTUSED(idata_limit_old); - p = (stbi_uc *)STBI_REALLOC_SIZED(z->idata, idata_limit_old, idata_limit); + stbi_uc *p = (stbi_uc *)STBI_REALLOC_SIZED(z->idata, idata_limit_old, idata_limit); if (p == NULL) return stbi__err("outofmem", "Out of memory"); z->idata = p; } @@ -5498,12 +5433,12 @@ static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp) case STBI__PNG_TYPE('I', 'E', 'N', 'D'): { - stbi__uint32 raw_len, bpl; + stbi__uint32 raw_len; if (first) return stbi__err("first not IHDR", "Corrupt PNG"); if (scan != STBI__SCAN_load) return 1; if (z->idata == NULL) return stbi__err("no IDAT", "Corrupt PNG"); // initial guess for decoded data size to avoid unnecessary reallocs - bpl = (s->img_x * z->depth + 7) / 8; // bytes per line, per component + stbi__uint32 bpl = (s->img_x * z->depth + 7) / 8; // bytes per line, per component raw_len = bpl * s->img_y * s->img_n /* pixels */ + s->img_y /* filter mode per row */; z->expanded = (stbi_uc *)stbi_zlib_decode_malloc_guesssize_headerflag((char *)z->idata, ioff, raw_len, (int *)&raw_len, !is_iphone); if (z->expanded == NULL) return 0; // zlib should set error @@ -5613,8 +5548,7 @@ static void *stbi__png_load(stbi__context *s, int *x, int *y, int *comp, int req static int stbi__png_test(stbi__context *s) { - int r; - r = stbi__check_png_header(s); + int r = stbi__check_png_header(s); stbi__rewind(s); return r; } @@ -5659,16 +5593,14 @@ static int stbi__png_is16(stbi__context *s) #ifndef STBI_NO_BMP static int stbi__bmp_test_raw(stbi__context *s) { - int r; - int sz; if (stbi__get8(s) != 'B') return 0; if (stbi__get8(s) != 'M') return 0; stbi__get32le(s); // discard filesize stbi__get16le(s); // discard reserved stbi__get16le(s); // discard reserved stbi__get32le(s); // discard data offset - sz = stbi__get32le(s); - r = sz == 12 || sz == 40 || sz == 56 || sz == 108 || sz == 124; + int sz = stbi__get32le(s); + int r = sz == 12 || sz == 40 || sz == 56 || sz == 108 || sz == 124; return r; } @@ -5811,7 +5743,6 @@ static void *stbi__bmp_parse_header(stbi__context *s, stbi__bmp_data *info) } else { - int i; if (hsz != 108 && hsz != 124) return stbi__errpuc("bad BMP", "bad BMP"); info->mr = stbi__get32le(s); @@ -5819,7 +5750,7 @@ static void *stbi__bmp_parse_header(stbi__context *s, stbi__bmp_data *info) info->mb = stbi__get32le(s); info->ma = stbi__get32le(s); stbi__get32le(s); // discard color space - for (i = 0; i < 12; ++i) + for (int i = 0; i < 12; ++i) stbi__get32le(s); // discard color space parameters if (hsz == 124) { @@ -6440,12 +6371,12 @@ static int stbi__psd_test(stbi__context *s) static int stbi__psd_decode_rle(stbi__context *s, stbi_uc *p, int pixelCount) { - int count, nleft, len; + int nleft; - count = 0; + int count = 0; while ((nleft = pixelCount - count) > 0) { - len = stbi__get8(s); + int len = stbi__get8(s); if (len == 128) { // No-op. @@ -6465,12 +6396,11 @@ static int stbi__psd_decode_rle(stbi__context *s, stbi_uc *p, int pixelCount) } else if (len > 128) { - stbi_uc val; // Next -len+1 bytes in the dest are replicated from next source byte. // (Interpret len as a negative 8-bit int.) len = 257 - len; if (len > nleft) return 0; // corrupt data - val = stbi__get8(s); + stbi_uc val = stbi__get8(s); count += len; while (len) { @@ -6486,11 +6416,7 @@ static int stbi__psd_decode_rle(stbi__context *s, stbi_uc *p, int pixelCount) static void *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri, int bpc) { - int pixelCount; - int channelCount, compression; int channel, i; - int bitdepth; - int w, h; stbi_uc *out; STBI_NOTUSED(ri); @@ -6506,16 +6432,16 @@ static void *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int req stbi__skip(s, 6); // Read the number of channels (R, G, B, A, etc). - channelCount = stbi__get16be(s); + int channelCount = stbi__get16be(s); if (channelCount < 0 || channelCount > 16) return stbi__errpuc("wrong channel count", "Unsupported number of channels in PSD image"); // Read the rows and columns of the image. - h = stbi__get32be(s); - w = stbi__get32be(s); + int h = stbi__get32be(s); + int w = stbi__get32be(s); // Make sure the depth is 8 bits. - bitdepth = stbi__get16be(s); + int bitdepth = stbi__get16be(s); if (bitdepth != 8 && bitdepth != 16) return stbi__errpuc("unsupported bit depth", "PSD bit depth is not 8 or 16 bit"); @@ -6545,7 +6471,7 @@ static void *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int req // Known values: // 0: no compression // 1: RLE compressed - compression = stbi__get16be(s); + int compression = stbi__get16be(s); if (compression > 1) return stbi__errpuc("bad compression", "PSD has an unknown compression format"); @@ -6564,7 +6490,7 @@ static void *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int req out = (stbi_uc *)stbi__malloc(4 * w * h); if (!out) return stbi__errpuc("outofmem", "Out of memory"); - pixelCount = w * h; + int pixelCount = w * h; // Initialize the data to zero. //memset( out, 0, pixelCount * 4 ); @@ -6587,9 +6513,7 @@ static void *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int req // Read the RLE data by channel. for (channel = 0; channel < 4; channel++) { - stbi_uc *p; - - p = out + channel; + stbi_uc *p = out + channel; if (channel >= channelCount) { // Fill this channel with default data. @@ -6724,8 +6648,7 @@ static void *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int req #ifndef STBI_NO_PIC static int stbi__pic_is4(stbi__context *s, const char *str) { - int i; - for (i = 0; i < 4; ++i) + for (int i = 0; i < 4; ++i) if (stbi__get8(s) != (stbi_uc)str[i]) return 0; @@ -6734,12 +6657,10 @@ static int stbi__pic_is4(stbi__context *s, const char *str) static int stbi__pic_test_core(stbi__context *s) { - int i; - if (!stbi__pic_is4(s, "\x53\x80\xF6\x34")) return 0; - for (i = 0; i < 84; ++i) + for (int i = 0; i < 84; ++i) stbi__get8(s); if (!stbi__pic_is4(s, "PICT")) @@ -6755,9 +6676,9 @@ typedef struct static stbi_uc *stbi__readval(stbi__context *s, int channel, stbi_uc *dest) { - int mask = 0x80, i; + int mask = 0x80; - for (i = 0; i < 4; ++i, mask >>= 1) + for (int i = 0; i < 4; ++i, mask >>= 1) { if (channel & mask) { @@ -6771,28 +6692,26 @@ static stbi_uc *stbi__readval(stbi__context *s, int channel, stbi_uc *dest) static void stbi__copyval(int channel, stbi_uc *dest, const stbi_uc *src) { - int mask = 0x80, i; + int mask = 0x80; - for (i = 0; i < 4; ++i, mask >>= 1) + for (int i = 0; i < 4; ++i, mask >>= 1) if (channel & mask) dest[i] = src[i]; } static stbi_uc *stbi__pic_load_core(stbi__context *s, int width, int height, int *comp, stbi_uc *result) { - int act_comp = 0, num_packets = 0, y, chained; + int act_comp = 0, num_packets = 0, chained; stbi__pic_packet packets[10]; // this will (should...) cater for even some bizarre stuff like having data // for the same channel in multiple packets. do { - stbi__pic_packet *packet; - if (num_packets == sizeof(packets) / sizeof(packets[0])) return stbi__errpuc("bad format", "too many packets"); - packet = &packets[num_packets++]; + stbi__pic_packet *packet = &packets[num_packets++]; chained = stbi__get8(s); packet->size = stbi__get8(s); @@ -6808,11 +6727,9 @@ static stbi_uc *stbi__pic_load_core(stbi__context *s, int width, int height, int *comp = act_comp & 0x10 ? 4 : 3; // has alpha channel? - for (y = 0; y < height; ++y) + for (int y = 0; y < height; ++y) { - int packet_idx; - - for (packet_idx = 0; packet_idx < num_packets; ++packet_idx) + for (int packet_idx = 0; packet_idx < num_packets; ++packet_idx) { stbi__pic_packet *packet = &packets[packet_idx]; stbi_uc *dest = result + y * width * 4; @@ -6824,9 +6741,8 @@ static stbi_uc *stbi__pic_load_core(stbi__context *s, int width, int height, int case 0: { //uncompressed - int x; - for (x = 0; x < width; ++x, dest += 4) + for (int x = 0; x < width; ++x, dest += 4) if (!stbi__readval(s, packet->channel, dest)) return 0; break; @@ -6834,13 +6750,13 @@ static stbi_uc *stbi__pic_load_core(stbi__context *s, int width, int height, int case 1: //Pure RLE { - int left = width, i; + int left = width; while (left > 0) { - stbi_uc count, value[4]; + stbi_uc value[4]; - count = stbi__get8(s); + stbi_uc count = stbi__get8(s); if (stbi__at_eof(s)) return stbi__errpuc("bad file", "file too short (pure read count)"); if (count > left) @@ -6848,7 +6764,7 @@ static stbi_uc *stbi__pic_load_core(stbi__context *s, int width, int height, int if (!stbi__readval(s, packet->channel, value)) return 0; - for (i = 0; i < count; ++i, dest += 4) + for (int i = 0; i < count; ++i, dest += 4) stbi__copyval(packet->channel, dest, value); left -= count; } @@ -6902,17 +6818,16 @@ static stbi_uc *stbi__pic_load_core(stbi__context *s, int width, int height, int static void *stbi__pic_load(stbi__context *s, int *px, int *py, int *comp, int req_comp, stbi__result_info *ri) { - stbi_uc *result; - int i, x, y, internal_comp; + int internal_comp; STBI_NOTUSED(ri); if (!comp) comp = &internal_comp; - for (i = 0; i < 92; ++i) + for (int i = 0; i < 92; ++i) stbi__get8(s); - x = stbi__get16be(s); - y = stbi__get16be(s); + int x = stbi__get16be(s); + int y = stbi__get16be(s); if (stbi__at_eof(s)) return stbi__errpuc("bad file", "file too short (pic header)"); if (!stbi__mad3sizes_valid(x, y, 4, 0)) return stbi__errpuc("too large", "PIC image too large to decode"); @@ -6921,7 +6836,7 @@ static void *stbi__pic_load(stbi__context *s, int *px, int *py, int *comp, int r stbi__get16be(s); //skip `pad' // intermediate buffer is RGBA - result = (stbi_uc *)stbi__malloc_mad3(x, y, 4, 0); + stbi_uc *result = (stbi_uc *)stbi__malloc_mad3(x, y, 4, 0); memset(result, 0xff, x * y * 4); if (!stbi__pic_load_core(s, x, y, comp, result)) @@ -6978,9 +6893,8 @@ typedef struct static int stbi__gif_test_raw(stbi__context *s) { - int sz; if (stbi__get8(s) != 'G' || stbi__get8(s) != 'I' || stbi__get8(s) != 'F' || stbi__get8(s) != '8') return 0; - sz = stbi__get8(s); + int sz = stbi__get8(s); if (sz != '9' && sz != '7') return 0; if (stbi__get8(s) != 'a') return 0; return 1; @@ -6995,8 +6909,7 @@ static int stbi__gif_test(stbi__context *s) static void stbi__gif_parse_colortable(stbi__context *s, stbi_uc pal[256][4], int num_entries, int transp) { - int i; - for (i = 0; i < num_entries; ++i) + for (int i = 0; i < num_entries; ++i) { pal[i][2] = stbi__get8(s); pal[i][1] = stbi__get8(s); @@ -7007,11 +6920,10 @@ static void stbi__gif_parse_colortable(stbi__context *s, stbi_uc pal[256][4], in static int stbi__gif_header(stbi__context *s, stbi__gif *g, int *comp, int is_info) { - stbi_uc version; if (stbi__get8(s) != 'G' || stbi__get8(s) != 'I' || stbi__get8(s) != 'F' || stbi__get8(s) != '8') return stbi__err("not GIF", "Corrupt GIF"); - version = stbi__get8(s); + stbi_uc version = stbi__get8(s); if (version != '7' && version != '9') return stbi__err("not GIF", "Corrupt GIF"); if (stbi__get8(s) != 'a') return stbi__err("not GIF", "Corrupt GIF"); @@ -7050,9 +6962,6 @@ static int stbi__gif_info_raw(stbi__context *s, int *x, int *y, int *comp) static void stbi__out_gif_code(stbi__gif *g, stbi__uint16 code) { - stbi_uc *p, *c; - int idx; - // recurse to decode the prefixes, since the linked-list is backwards, // and working backwards through an interleaved image would be nasty if (g->codes[code].prefix >= 0) @@ -7060,11 +6969,11 @@ static void stbi__out_gif_code(stbi__gif *g, stbi__uint16 code) if (g->cur_y >= g->max_y) return; - idx = g->cur_x + g->cur_y; - p = &g->out[idx]; + int idx = g->cur_x + g->cur_y; + stbi_uc *p = &g->out[idx]; g->history[idx / 4] = 1; - c = &g->color_table[g->codes[code].suffix * 4]; + stbi_uc *c = &g->color_table[g->codes[code].suffix * 4]; if (c[3] > 128) { // don't render transparent pixels; p[0] = c[2]; @@ -7090,21 +6999,15 @@ static void stbi__out_gif_code(stbi__gif *g, stbi__uint16 code) static stbi_uc *stbi__process_gif_raster(stbi__context *s, stbi__gif *g) { - stbi_uc lzw_cs; - stbi__int32 len, init_code; - stbi__uint32 first; - stbi__int32 codesize, codemask, avail, oldcode, bits, valid_bits, clear; - stbi__gif_lzw *p; - - lzw_cs = stbi__get8(s); + stbi_uc lzw_cs = stbi__get8(s); if (lzw_cs > 12) return NULL; - clear = 1 << lzw_cs; - first = 1; - codesize = lzw_cs + 1; - codemask = (1 << codesize) - 1; - bits = 0; - valid_bits = 0; - for (init_code = 0; init_code < clear; init_code++) + stbi__int32 clear = 1 << lzw_cs; + stbi__uint32 first = 1; + stbi__int32 codesize = lzw_cs + 1; + stbi__int32 codemask = (1 << codesize) - 1; + stbi__int32 bits = 0; + stbi__int32 valid_bits = 0; + for (stbi__int32 init_code = 0; init_code < clear; init_code++) { g->codes[init_code].prefix = -1; g->codes[init_code].first = (stbi_uc)init_code; @@ -7112,10 +7015,10 @@ static stbi_uc *stbi__process_gif_raster(stbi__context *s, stbi__gif *g) } // support no starting clear code - avail = clear + 2; - oldcode = -1; + stbi__int32 avail = clear + 2; + stbi__int32 oldcode = -1; - len = 0; + stbi__int32 len = 0; for (;;) { if (valid_bits < codesize) @@ -7160,7 +7063,7 @@ static stbi_uc *stbi__process_gif_raster(stbi__context *s, stbi__gif *g) if (oldcode >= 0) { - p = &g->codes[avail++]; + stbi__gif_lzw *p = &g->codes[avail++]; if (avail > 8192) { return stbi__errpuc("too many codes", "Corrupt GIF"); @@ -7195,13 +7098,11 @@ static stbi_uc *stbi__process_gif_raster(stbi__context *s, stbi__gif *g) // two back is the image from two frames ago, used for a very specific disposal format static stbi_uc *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, int req_comp, stbi_uc *two_back) { - int dispose; - int first_frame; int pi; int pcount; // on first frame, any non-written pixels get the background colour (non-transparent) - first_frame = 0; + int first_frame = 0; if (g->out == 0) { if (!stbi__gif_header(s, g, comp, 0)) return 0; // stbi__g_failure_reason set by stbi__gif_header @@ -7221,7 +7122,7 @@ static stbi_uc *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, i else { // second frame - how do we dispoase of the previous one? - dispose = (g->eflags & 0x1C) >> 2; + int dispose = (g->eflags & 0x1C) >> 2; pcount = g->w * g->h; if (dispose == 3 && two_back == 0) @@ -7272,13 +7173,10 @@ static stbi_uc *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, i { case 0x2C: /* Image Descriptor */ { - stbi__int32 x, y, w, h; - stbi_uc *o; - - x = stbi__get16le(s); - y = stbi__get16le(s); - w = stbi__get16le(s); - h = stbi__get16le(s); + stbi__int32 x = stbi__get16le(s); + stbi__int32 y = stbi__get16le(s); + stbi__int32 w = stbi__get16le(s); + stbi__int32 h = stbi__get16le(s); if (x + w > g->w || y + h > g->h) return stbi__errpuc("bad Image Descriptor", "Corrupt GIF"); @@ -7315,7 +7213,7 @@ static stbi_uc *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, i else return stbi__errpuc("missing color table", "Corrupt GIF"); - o = stbi__process_gif_raster(s, g); + stbi_uc *o = stbi__process_gif_raster(s, g); if (o == NULL) return NULL; // if this was the first frame, @@ -7399,7 +7297,6 @@ static void *stbi__load_gif_main(stbi__context *s, int **delays, int *x, int *y, stbi_uc *out = 0; stbi_uc *two_back = 0; stbi__gif g; - int stride; memset(&g, 0, sizeof(g)); if (delays) { @@ -7416,7 +7313,7 @@ static void *stbi__load_gif_main(stbi__context *s, int **delays, int *x, int *y, *x = g.w; *y = g.h; ++layers; - stride = g.w * g.h * 4; + int stride = g.w * g.h * 4; if (out) { @@ -7794,11 +7691,10 @@ static int stbi__hdr_info(stbi__context *s, int *x, int *y, int *comp) #ifndef STBI_NO_BMP static int stbi__bmp_info(stbi__context *s, int *x, int *y, int *comp) { - void *p; stbi__bmp_data info; info.all_a = 255; - p = stbi__bmp_parse_header(s, &info); + void *p = stbi__bmp_parse_header(s, &info); stbi__rewind(s); if (p == NULL) return 0; @@ -7812,7 +7708,7 @@ static int stbi__bmp_info(stbi__context *s, int *x, int *y, int *comp) #ifndef STBI_NO_PSD static int stbi__psd_info(stbi__context *s, int *x, int *y, int *comp) { - int channelCount, dummy, depth; + int dummy; if (!x) x = &dummy; if (!y) y = &dummy; if (!comp) comp = &dummy; @@ -7827,7 +7723,7 @@ static int stbi__psd_info(stbi__context *s, int *x, int *y, int *comp) return 0; } stbi__skip(s, 6); - channelCount = stbi__get16be(s); + int channelCount = stbi__get16be(s); if (channelCount < 0 || channelCount > 16) { stbi__rewind(s); @@ -7835,7 +7731,7 @@ static int stbi__psd_info(stbi__context *s, int *x, int *y, int *comp) } *y = stbi__get32be(s); *x = stbi__get32be(s); - depth = stbi__get16be(s); + int depth = stbi__get16be(s); if (depth != 8 && depth != 16) { stbi__rewind(s); @@ -7852,7 +7748,6 @@ static int stbi__psd_info(stbi__context *s, int *x, int *y, int *comp) static int stbi__psd_is16(stbi__context *s) { - int channelCount, depth; if (stbi__get32be(s) != 0x38425053) { stbi__rewind(s); @@ -7864,7 +7759,7 @@ static int stbi__psd_is16(stbi__context *s) return 0; } stbi__skip(s, 6); - channelCount = stbi__get16be(s); + int channelCount = stbi__get16be(s); if (channelCount < 0 || channelCount > 16) { stbi__rewind(s); @@ -7872,7 +7767,7 @@ static int stbi__psd_is16(stbi__context *s) } (void)stbi__get32be(s); (void)stbi__get32be(s); - depth = stbi__get16be(s); + int depth = stbi__get16be(s); if (depth != 16) { stbi__rewind(s); @@ -7917,12 +7812,10 @@ static int stbi__pic_info(stbi__context *s, int *x, int *y, int *comp) do { - stbi__pic_packet *packet; - if (num_packets == sizeof(packets) / sizeof(packets[0])) return 0; - packet = &packets[num_packets++]; + stbi__pic_packet *packet = &packets[num_packets++]; chained = stbi__get8(s); packet->size = stbi__get8(s); packet->type = stbi__get8(s); @@ -7964,9 +7857,8 @@ static int stbi__pic_info(stbi__context *s, int *x, int *y, int *comp) static int stbi__pnm_test(stbi__context *s) { - char p, t; - p = (char)stbi__get8(s); - t = (char)stbi__get8(s); + char p = (char)stbi__get8(s); + char t = (char)stbi__get8(s); if (p != 'P' || (t != '5' && t != '6')) { stbi__rewind(s); @@ -7977,7 +7869,6 @@ static int stbi__pnm_test(stbi__context *s) static void *stbi__pnm_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri) { - stbi_uc *out; STBI_NOTUSED(ri); if (!stbi__pnm_info(s, (int *)&s->img_x, (int *)&s->img_y, &s->img_n)) @@ -7990,7 +7881,7 @@ static void *stbi__pnm_load(stbi__context *s, int *x, int *y, int *comp, int req if (!stbi__mad3sizes_valid(s->img_n, s->img_x, s->img_y, 0)) return stbi__errpuc("too large", "PNM too large"); - out = (stbi_uc *)stbi__malloc_mad3(s->img_n, s->img_x, s->img_y, 0); + stbi_uc *out = (stbi_uc *)stbi__malloc_mad3(s->img_n, s->img_x, s->img_y, 0); if (!out) return stbi__errpuc("outofmem", "Out of memory"); stbi__getn(s, out, s->img_n * s->img_x * s->img_y); @@ -8042,8 +7933,8 @@ static int stbi__pnm_getinteger(stbi__context *s, char *c) static int stbi__pnm_info(stbi__context *s, int *x, int *y, int *comp) { - int maxv, dummy; - char c, p, t; + int dummy; + char c; if (!x) x = &dummy; if (!y) y = &dummy; @@ -8052,8 +7943,8 @@ static int stbi__pnm_info(stbi__context *s, int *x, int *y, int *comp) stbi__rewind(s); // Get identifier - p = (char)stbi__get8(s); - t = (char)stbi__get8(s); + char p = (char)stbi__get8(s); + char t = (char)stbi__get8(s); if (p != 'P' || (t != '5' && t != '6')) { stbi__rewind(s); @@ -8071,7 +7962,7 @@ static int stbi__pnm_info(stbi__context *s, int *x, int *y, int *comp) *y = stbi__pnm_getinteger(s, &c); // read height stbi__pnm_skip_whitespace(s, &c); - maxv = stbi__pnm_getinteger(s, &c); // read max value + int maxv = stbi__pnm_getinteger(s, &c); // read max value if (maxv > 255) return stbi__err("max value > 255", "PPM image not 8-bit"); @@ -8139,20 +8030,18 @@ static int stbi__is_16_main(stbi__context *s) STBIDEF int stbi_info(char const *filename, int *x, int *y, int *comp) { FILE *f = stbi__fopen(filename, "rb"); - int result; if (!f) return stbi__err("can't fopen", "Unable to open file"); - result = stbi_info_from_file(f, x, y, comp); + int result = stbi_info_from_file(f, x, y, comp); fclose(f); return result; } STBIDEF int stbi_info_from_file(FILE *f, int *x, int *y, int *comp) { - int r; stbi__context s; long pos = ftell(f); stbi__start_file(&s, f); - r = stbi__info_main(&s, x, y, comp); + int r = stbi__info_main(&s, x, y, comp); fseek(f, pos, SEEK_SET); return r; } @@ -8160,20 +8049,18 @@ STBIDEF int stbi_info_from_file(FILE *f, int *x, int *y, int *comp) STBIDEF int stbi_is_16_bit(char const *filename) { FILE *f = stbi__fopen(filename, "rb"); - int result; if (!f) return stbi__err("can't fopen", "Unable to open file"); - result = stbi_is_16_bit_from_file(f); + int result = stbi_is_16_bit_from_file(f); fclose(f); return result; } STBIDEF int stbi_is_16_bit_from_file(FILE *f) { - int r; stbi__context s; long pos = ftell(f); stbi__start_file(&s, f); - r = stbi__is_16_main(&s); + int r = stbi__is_16_main(&s); fseek(f, pos, SEEK_SET); return r; } diff --git a/src/decomp/tools/stb/stb_image_write.h b/src/decomp/tools/stb/stb_image_write.h index 5a06824..1ede43f 100644 --- a/src/decomp/tools/stb/stb_image_write.h +++ b/src/decomp/tools/stb/stb_image_write.h @@ -370,7 +370,6 @@ static void stbiw__write3(stbi__write_context *s, unsigned char a, unsigned char static void stbiw__write_pixel(stbi__write_context *s, int rgb_dir, int comp, int write_alpha, int expand_mono, unsigned char *d) { unsigned char bg[3] = {255, 0, 255}, px[3]; - int k; if (write_alpha < 0) s->func(s->context, &d[comp - 1], 1); @@ -388,7 +387,7 @@ static void stbiw__write_pixel(stbi__write_context *s, int rgb_dir, int comp, in if (!write_alpha) { // composite against pink background - for (k = 0; k < 3; ++k) + for (int k = 0; k < 3; ++k) px[k] = bg[k] + (d[k] - bg[k]) * d[3] / 255; stbiw__write3(s, px[1 - rgb_dir], px[1], px[1 + rgb_dir]); break; @@ -405,7 +404,7 @@ static void stbiw__write_pixel(stbi__write_context *s, int rgb_dir, int comp, in static void stbiw__write_pixels(stbi__write_context *s, int rgb_dir, int vdir, int x, int y, int comp, void *data, int write_alpha, int scanline_pad, int expand_mono) { stbiw_uint32 zero = 0; - int i, j, j_end; + int j, j_end; if (y <= 0) return; @@ -420,7 +419,7 @@ static void stbiw__write_pixels(stbi__write_context *s, int rgb_dir, int vdir, i for (; j != j_end; j += vdir) { - for (i = 0; i < x; ++i) + for (int i = 0; i < x; ++i) { unsigned char *d = (unsigned char *)data + (j * x + i) * comp; stbiw__write_pixel(s, rgb_dir, comp, write_alpha, expand_mono, d); @@ -493,7 +492,7 @@ static int stbi_write_tga_core(stbi__write_context *s, int x, int y, int comp, v } else { - int i, j, k; + int j, k; int jend, jdir; stbiw__writef(s, "111 221 2222 11", 0, 0, format + 8, 0, 0, 0, 0, 0, x, y, (colorbytes + has_alpha) * 8, has_alpha * 8); @@ -515,7 +514,7 @@ static int stbi_write_tga_core(stbi__write_context *s, int x, int y, int comp, v unsigned char *row = (unsigned char *)data + j * x * comp; int len; - for (i = 0; i < x; i += len) + for (int i = 0; i < x; i += len) { unsigned char *begin = row + i * comp; int diff = 1; @@ -676,7 +675,6 @@ void stbiw__write_hdr_scanline(stbi__write_context *s, int width, int ncomp, uns } else { - int c, r; /* encode into scratch buffer */ for (x = 0; x < width; x++) { @@ -702,7 +700,7 @@ void stbiw__write_hdr_scanline(stbi__write_context *s, int width, int ncomp, uns s->func(s->context, scanlineheader, 4); /* RLE each component separately */ - for (c = 0; c < 4; c++) + for (int c = 0; c < 4; c++) { unsigned char *comp = &scratch[width * c]; @@ -710,7 +708,7 @@ void stbiw__write_hdr_scanline(stbi__write_context *s, int width, int ncomp, uns while (x < width) { // find first run - r = x; + int r = x; while (r + 2 < width) { if (comp[r] == comp[r + 1] && comp[r] == comp[r + 2]) @@ -755,7 +753,7 @@ static int stbi_write_hdr_core(stbi__write_context *s, int x, int y, int comp, f { // Each component is stored separately. Allocate scratch space for full output scanline. unsigned char *scratch = STBIW_MALLOC(x * 4); - int i, len; + int len; char buffer[128]; char header[] = "#?RADIANCE\n# Written by stb_image_write.h\nFORMAT=32-bit_rle_rgbe\n"; s->func(s->context, header, sizeof(header) - 1); @@ -767,7 +765,7 @@ len= sprintf(buffer, "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x #endif s->func (s->context, buffer, len); - for(i=0; i> 8 ^ crc_table[buffer[i] ^ crc & 0xff]; return ~crc; } @@ -1148,9 +1145,7 @@ unsigned char *stbi_write_png_to_mem(unsigned char *pixels, int stride_bytes, in int force_filter = stbi_write_force_png_filter; int ctype[5] = {-1, 0, 4, 2, 6}; unsigned char sig[8] = {137, 80, 78, 71, 13, 10, 26, 10}; - unsigned char *out, *o, *filt, *zlib; - signed char *line_buffer; - int j, zlen; + int zlen; if (stride_bytes == 0) stride_bytes = x * n; @@ -1160,15 +1155,15 @@ unsigned char *stbi_write_png_to_mem(unsigned char *pixels, int stride_bytes, in force_filter = -1; } - filt = (unsigned char *)STBIW_MALLOC((x * n + 1) * y); + unsigned char *filt = (unsigned char *)STBIW_MALLOC((x * n + 1) * y); if (!filt) return 0; - line_buffer = (signed char *)STBIW_MALLOC(x * n); + signed char *line_buffer = (signed char *)STBIW_MALLOC(x * n); if (!line_buffer) { STBIW_FREE(filt); return 0; } - for (j = 0; j < y; ++j) + for (int j = 0; j < y; ++j) { int filter_type; if (force_filter > -1) @@ -1178,14 +1173,14 @@ unsigned char *stbi_write_png_to_mem(unsigned char *pixels, int stride_bytes, in } else { // Estimate the best filter by running through all of them: - int best_filter = 0, best_filter_val = 0x7fffffff, est, i; + int best_filter = 0, best_filter_val = 0x7fffffff; for (filter_type = 0; filter_type < 5; filter_type++) { stbiw__encode_png_line(pixels, stride_bytes, x, y, j, n, filter_type, line_buffer); // Estimate the entropy of the line using this filter; the less, the better. - est = 0; - for (i = 0; i < x * n; ++i) + int est = 0; + for (int i = 0; i < x * n; ++i) { est += abs(line_buffer[i]); } @@ -1206,16 +1201,16 @@ unsigned char *stbi_write_png_to_mem(unsigned char *pixels, int stride_bytes, in STBIW_MEMMOVE(filt + j * (x * n + 1) + 1, line_buffer, x * n); } STBIW_FREE(line_buffer); - zlib = stbi_zlib_compress(filt, y * (x * n + 1), &zlen, stbi_write_png_compression_level); + unsigned char *zlib = stbi_zlib_compress(filt, y * (x * n + 1), &zlen, stbi_write_png_compression_level); STBIW_FREE(filt); if (!zlib) return 0; // each tag requires 12 bytes of overhead - out = (unsigned char *)STBIW_MALLOC(8 + 12 + 13 + 12 + zlen + 12); + unsigned char *out = (unsigned char *)STBIW_MALLOC(8 + 12 + 13 + 12 + zlen + 12); if (!out) return 0; *out_len = 8 + 12 + 13 + 12 + zlen + 12; - o = out; + unsigned char *o = out; STBIW_MEMMOVE(o, sig, 8); o += 8; stbiw__wp32(o, 13); // header length @@ -1313,7 +1308,6 @@ static void stbiw__jpg_writeBits(stbi__write_context *s, int *bitBufP, int *bitC static void stbiw__jpg_DCT(float *d0p, float *d1p, float *d2p, float *d3p, float *d4p, float *d5p, float *d6p, float *d7p) { float d0 = *d0p, d1 = *d1p, d2 = *d2p, d3 = *d3p, d4 = *d4p, d5 = *d5p, d6 = *d6p, d7 = *d7p; - float z1, z2, z3, z4, z5, z11, z13; float tmp0 = d0 + d7; float tmp7 = d0 - d7; @@ -1333,7 +1327,7 @@ static void stbiw__jpg_DCT(float *d0p, float *d1p, float *d2p, float *d3p, float d0 = tmp10 + tmp11; // phase 3 d4 = tmp10 - tmp11; - z1 = (tmp12 + tmp13) * 0.707106781f; // c4 + float z1 = (tmp12 + tmp13) * 0.707106781f; // c4 d2 = tmp13 + z1; // phase 5 d6 = tmp13 - z1; @@ -1343,13 +1337,13 @@ static void stbiw__jpg_DCT(float *d0p, float *d1p, float *d2p, float *d3p, float tmp12 = tmp6 + tmp7; // The rotator is modified from fig 4-8 to avoid extra negations. - z5 = (tmp10 - tmp12) * 0.382683433f; // c6 - z2 = tmp10 * 0.541196100f + z5; // c2-c6 - z4 = tmp12 * 1.306562965f + z5; // c2+c6 - z3 = tmp11 * 0.707106781f; // c4 + float z5 = (tmp10 - tmp12) * 0.382683433f; // c6 + float z2 = tmp10 * 0.541196100f + z5; // c2-c6 + float z4 = tmp12 * 1.306562965f + z5; // c2+c6 + float z3 = tmp11 * 0.707106781f; // c4 - z11 = tmp7 + z3; // phase 5 - z13 = tmp7 - z3; + float z11 = tmp7 + z3; // phase 5 + float z13 = tmp7 - z3; *d5p = z13 + z2; // phase 6 *d3p = z13 - z2; @@ -1378,7 +1372,7 @@ static int stbiw__jpg_processDU(stbi__write_context *s, int *bitBuf, int *bitCnt { const unsigned short EOB[2] = {HTAC[0x00][0], HTAC[0x00][1]}; const unsigned short M16zeroes[2] = {HTAC[0xF0][0], HTAC[0xF0][1]}; - int dataOff, i, diff, end0pos; + int dataOff, i; int DU[64]; // DCT rows @@ -1401,7 +1395,7 @@ static int stbiw__jpg_processDU(stbi__write_context *s, int *bitBuf, int *bitCnt } // Encode DC - diff = DU[0] - DC; + int diff = DU[0] - DC; if (diff == 0) { stbiw__jpg_writeBits(s, bitBuf, bitCnt, HTDC[0]); @@ -1414,7 +1408,7 @@ static int stbiw__jpg_processDU(stbi__write_context *s, int *bitBuf, int *bitCnt stbiw__jpg_writeBits(s, bitBuf, bitCnt, bits); } // Encode ACs - end0pos = 63; + int end0pos = 63; for (; end0pos > 0 && DU[end0pos] == 0; --end0pos) { } @@ -1427,17 +1421,15 @@ static int stbiw__jpg_processDU(stbi__write_context *s, int *bitBuf, int *bitCnt for (i = 1; i <= end0pos; ++i) { int startpos = i; - int nrzeroes; unsigned short bits[2]; for (; DU[i] == 0 && i <= end0pos; ++i) { } - nrzeroes = i - startpos; + int nrzeroes = i - startpos; if (nrzeroes >= 16) { int lng = nrzeroes >> 4; - int nrmarker; - for (nrmarker = 1; nrmarker <= lng; ++nrmarker) + for (int nrmarker = 1; nrmarker <= lng; ++nrmarker) stbiw__jpg_writeBits(s, bitBuf, bitCnt, M16zeroes); nrzeroes &= 15; } @@ -1531,7 +1523,7 @@ static int stbi_write_jpg_core(stbi__write_context *s, int width, int height, in 1.0f * 2.828427125f, 0.785694958f * 2.828427125f, 0.541196100f * 2.828427125f, 0.275899379f * 2.828427125f }; - int row, col, i, k; + int row, col, k; float fdtbl_Y[64], fdtbl_UV[64]; unsigned char YTable[64], UVTable[64]; @@ -1544,11 +1536,11 @@ static int stbi_write_jpg_core(stbi__write_context *s, int width, int height, in quality = quality < 1 ? 1 : quality > 100 ? 100 : quality; quality = quality < 50 ? 5000 / quality : 200 - quality * 2; - for (i = 0; i < 64; ++i) + for (int i = 0; i < 64; ++i) { - int uvti, yti = (YQT[i] * quality + 50) / 100; + int yti = (YQT[i] * quality + 50) / 100; YTable[stbiw__jpg_ZigZag[i]] = (unsigned char)(yti < 1 ? 1 : yti > 255 ? 255 : yti); - uvti = (UVQT[i] * quality + 50) / 100; + int uvti = (UVQT[i] * quality + 50) / 100; UVTable[stbiw__jpg_ZigZag[i]] = (unsigned char)(uvti < 1 ? 1 : uvti > 255 ? 255 : uvti); } @@ -1596,10 +1588,10 @@ static int stbi_write_jpg_core(stbi__write_context *s, int width, int height, in int bitBuf = 0, bitCnt = 0; // comp == 2 is grey+alpha (alpha is ignored) int ofsG = comp > 2 ? 1 : 0, ofsB = comp > 2 ? 2 : 0; - int x, y, pos; - for (y = 0; y < height; y += 8) + int pos; + for (int y = 0; y < height; y += 8) { - for (x = 0; x < width; x += 8) + for (int x = 0; x < width; x += 8) { float YDU[64], UDU[64], VDU[64]; for (row = y, pos = 0; row < y + 8; ++row) @@ -1607,7 +1599,6 @@ static int stbi_write_jpg_core(stbi__write_context *s, int width, int height, in for (col = x; col < x + 8; ++col, ++pos) { int p = (stbi__flip_vertically_on_write ? height - 1 - row : row) * width * comp + col * comp; - float r, g, b; if (row >= height) { p -= width * comp * (row + 1 - height); @@ -1617,9 +1608,9 @@ static int stbi_write_jpg_core(stbi__write_context *s, int width, int height, in p -= comp * (col + 1 - width); } - r = imageData[p + 0]; - g = imageData[p + ofsG]; - b = imageData[p + ofsB]; + float r = imageData[p + 0]; + float g = imageData[p + ofsG]; + float b = imageData[p + ofsB]; YDU[pos] = +0.29900f * r + 0.58700f * g + 0.11400f * b - 128; UDU[pos] = -0.16874f * r - 0.33126f * g + 0.50000f * b; VDU[pos] = +0.50000f * r - 0.41869f * g - 0.08131f * b; diff --git a/src/decomp/tools/utils.c b/src/decomp/tools/utils.c index 8c35e5b..31e8940 100644 --- a/src/decomp/tools/utils.c +++ b/src/decomp/tools/utils.c @@ -55,8 +55,7 @@ int is_power2(unsigned int val) void fprint_hex(FILE *fp, const unsigned char *buf, int length) { - int i; - for (i = 0; i < length; i++) + for (int i = 0; i < length; i++) { fprint_byte(fp, buf[i]); fputc(' ', fp); @@ -65,8 +64,7 @@ void fprint_hex(FILE *fp, const unsigned char *buf, int length) void fprint_hex_source(FILE *fp, const unsigned char *buf, int length) { - int i; - for (i = 0; i < length; i++) + for (int i = 0; i < length; i++) { if (i > 0) fputs(", ", fp); fputs("0x", fp); @@ -81,11 +79,9 @@ void print_hex(const unsigned char *buf, int length) void swap_bytes(unsigned char *data, long length) { - long i; - unsigned char tmp; - for (i = 0; i < length; i += 2) + for (long i = 0; i < length; i += 2) { - tmp = data[i]; + unsigned char tmp = data[i]; data[i] = data[i + 1]; data[i + 1] = tmp; } @@ -93,11 +89,9 @@ void swap_bytes(unsigned char *data, long length) void reverse_endian(unsigned char *data, long length) { - long i; - unsigned char tmp; - for (i = 0; i < length; i += 4) + for (long i = 0; i < length; i += 4) { - tmp = data[i]; + unsigned char tmp = data[i]; data[i] = data[i + 3]; data[i + 3] = tmp; tmp = data[i + 1]; @@ -120,9 +114,8 @@ long filesize(const char *filename) void touch_file(const char *filename) { - int fd; //fd = open(filename, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, 0666); - fd = open(filename, O_WRONLY | O_CREAT, 0666); + int fd = open(filename, O_WRONLY | O_CREAT, 0666); if (fd >= 0) { utime(filename, NULL); @@ -132,11 +125,8 @@ void touch_file(const char *filename) long read_file(const char *file_name, unsigned char **data) { - FILE *in; unsigned char *in_buf = NULL; - long file_size; - long bytes_read; - in = fopen(file_name, "rb"); + FILE *in = fopen(file_name, "rb"); if (in == NULL) { return -1; @@ -144,7 +134,7 @@ long read_file(const char *file_name, unsigned char **data) // allocate buffer to read from offset to end of file fseek(in, 0, SEEK_END); - file_size = ftell(in); + long file_size = ftell(in); // sanity check if (file_size > 256 * MB) @@ -156,7 +146,7 @@ long read_file(const char *file_name, unsigned char **data) fseek(in, 0, SEEK_SET); // read bytes - bytes_read = fread(in_buf, 1, file_size, in); + long bytes_read = fread(in_buf, 1, file_size, in); if (bytes_read != file_size) { return -3; @@ -169,16 +159,14 @@ long read_file(const char *file_name, unsigned char **data) long write_file(const char *file_name, unsigned char *data, long length) { - FILE *out; - long bytes_written; // open output file - out = fopen(file_name, "wb"); + FILE *out = fopen(file_name, "wb"); if (out == NULL) { perror(file_name); return -1; } - bytes_written = fwrite(data, 1, length, out); + long bytes_written = fwrite(data, 1, length, out); fclose(out); return bytes_written; } @@ -186,10 +174,9 @@ long write_file(const char *file_name, unsigned char *data, long length) void generate_filename(const char *in_name, char *out_name, char *extension) { char tmp_name[FILENAME_MAX]; - int len; int i; strcpy(tmp_name, in_name); - len = strlen(tmp_name); + int len = strlen(tmp_name); for (i = len - 1; i > 0; i--) { if (tmp_name[i] == '.') @@ -230,14 +217,12 @@ void make_dir(const char *dir_name) long copy_file(const char *src_name, const char *dst_name) { unsigned char *buf; - long bytes_written; - long bytes_read; - bytes_read = read_file(src_name, &buf); + long bytes_read = read_file(src_name, &buf); if (bytes_read > 0) { - bytes_written = write_file(dst_name, buf, bytes_read); + long bytes_written = write_file(dst_name, buf, bytes_read); if (bytes_written != bytes_read) { bytes_read = -1; @@ -250,23 +235,19 @@ long copy_file(const char *src_name, const char *dst_name) void dir_list_ext(const char *dir, const char *extension, dir_list *list) { - char *pool; - char *pool_ptr; struct dirent *entry; - DIR *dfd; - int idx; - dfd = opendir(dir); + DIR *dfd = opendir(dir); if (dfd == NULL) { ERROR("Can't open '%s'\n", dir); exit(1); } - pool = malloc(FILENAME_MAX * MAX_DIR_FILES); - pool_ptr = pool; + char *pool = malloc(FILENAME_MAX * MAX_DIR_FILES); + char *pool_ptr = pool; - idx = 0; + int idx = 0; while ((entry = readdir(dfd)) != NULL && idx < MAX_DIR_FILES) { if (!extension || str_ends_with(entry->d_name, extension)) diff --git a/src/libsm64.h b/src/libsm64.h index 59af8a7..b9c8e0d 100644 --- a/src/libsm64.h +++ b/src/libsm64.h @@ -32,6 +32,7 @@ struct SM64Surface int16_t type; int16_t force; uint16_t terrain; + int8_t flags; float vertices[3][3]; // world-space coordinates }; diff --git a/src/load_surfaces.c b/src/load_surfaces.c index 4409c2b..8e24c71 100644 --- a/src/load_surfaces.c +++ b/src/load_surfaces.c @@ -69,9 +69,9 @@ static void update_transform(struct SM64SurfaceObjectTransform *out, const struc * Returns whether a surface has exertion/moves Mario * based on the surface type. */ -static s32 surface_has_force(s16 surfaceType) +static bool surface_has_force(s16 surfaceType) { - s32 hasForce = FALSE; + bool hasForce = false; switch (surfaceType) { @@ -82,7 +82,7 @@ static s32 surface_has_force(s16 surfaceType) case SURFACE_MOVING_QUICKSAND: case SURFACE_HORIZONTAL_WIND: case SURFACE_INSTANT_MOVING_QUICKSAND: - hasForce = TRUE; + hasForce = true; break; default: @@ -93,21 +93,17 @@ static s32 surface_has_force(s16 surfaceType) static void engine_surface_from_lib_surface(struct SM64SurfaceCollisionData *surface, const struct SM64Surface *libSurf, struct SM64SurfaceObjectTransform *transform) { - int16_t type = libSurf->type; - int16_t force = libSurf->force; - f32 x1 = libSurf->vertices[0][0]; - f32 y1 = libSurf->vertices[0][1]; - f32 z1 = libSurf->vertices[0][2]; - f32 x2 = libSurf->vertices[1][0]; - f32 y2 = libSurf->vertices[1][1]; - f32 z2 = libSurf->vertices[1][2]; - f32 x3 = libSurf->vertices[2][0]; - f32 y3 = libSurf->vertices[2][1]; - f32 z3 = libSurf->vertices[2][2]; + f32 x1 = libSurf->vertices[0][0]; // v1.x + f32 y1 = libSurf->vertices[0][1]; // v1.y + f32 z1 = libSurf->vertices[0][2]; // v1.z - f32 maxY, minY; - f32 nx, ny, nz; - f32 mag; + f32 x2 = libSurf->vertices[1][0]; // v2.x + f32 y2 = libSurf->vertices[1][1]; // v2.y + f32 z2 = libSurf->vertices[1][2]; // v2.z + + f32 x3 = libSurf->vertices[2][0]; // v3.x + f32 y3 = libSurf->vertices[2][1]; // v3.y + f32 z3 = libSurf->vertices[2][2]; // v3.z if (transform != NULL) { @@ -127,9 +123,11 @@ static void engine_surface_from_lib_surface(struct SM64SurfaceCollisionData *sur x1 = v1[0]; y1 = v1[1]; z1 = v1[2]; + x2 = v2[0]; y2 = v2[1]; z2 = v2[2]; + x3 = v3[0]; y3 = v3[1]; z3 = v3[2]; @@ -142,13 +140,13 @@ static void engine_surface_from_lib_surface(struct SM64SurfaceCollisionData *sur } // (v2 - v1) x (v3 - v2) - nx = (y2 - y1) * (z3 - z2) - (z2 - z1) * (y3 - y2); - ny = (z2 - z1) * (x3 - x2) - (x2 - x1) * (z3 - z2); - nz = (x2 - x1) * (y3 - y2) - (y2 - y1) * (x3 - x2); - mag = sqrtf(nx * nx + ny * ny + nz * nz); + f32 nx = (y2 - y1) * (z3 - z2) - (z2 - z1) * (y3 - y2); + f32 ny = (z2 - z1) * (x3 - x2) - (x2 - x1) * (z3 - z2); + f32 nz = (x2 - x1) * (y3 - y2) - (y2 - y1) * (x3 - x2); + f32 mag = sqrtf(nx * nx + ny * ny + nz * nz); // Could have used min_3 and max_3 for this... - minY = y1; + f32 minY = y1; if (y2 < minY) { minY = y2; @@ -158,7 +156,7 @@ static void engine_surface_from_lib_surface(struct SM64SurfaceCollisionData *sur minY = y3; } - maxY = y1; + f32 maxY = y1; if (y2 > maxY) { maxY = y2; @@ -204,17 +202,17 @@ static void engine_surface_from_lib_surface(struct SM64SurfaceCollisionData *sur surface->lowerY = minY - 5; surface->upperY = maxY + 5; - s16 hasForce = surface_has_force(type); - s16 flags = 0; // surf_has_no_cam_collision(type); + int16_t type = libSurf->type; + // s16 flags = 0; // surf_has_no_cam_collision(type); surface->room = 0; surface->type = type; - surface->flags = (s8)flags; + surface->flags = libSurf->flags; surface->terrain = libSurf->terrain; - if (hasForce) + if (surface_has_force(type)) { - surface->force = force; + surface->force = libSurf->force; } else { diff --git a/test/cglm.h b/test/cglm.h index 34a37c4..ed32993 100644 --- a/test/cglm.h +++ b/test/cglm.h @@ -73,9 +73,7 @@ static float glm_vec3_norm(vec3 v) static void glm_vec3_normalize(vec3 v) { - float norm; - - norm = glm_vec3_norm(v); + float norm = glm_vec3_norm(v); if (norm == 0.0f) { @@ -107,12 +105,10 @@ static void glm_perspective( float farVal, mat4 dest) { - float f, fn; - glm_mat4_zero(dest); - f = 1.0f / tanf(fovy * 0.5f); - fn = 1.0f / (nearVal - farVal); + float f = 1.0f / tanf(fovy * 0.5f); + float fn = 1.0f / (nearVal - farVal); dest[0][0] = f / aspect; dest[1][1] = f; diff --git a/test/gl33core/gl33core_renderer.c b/test/gl33core/gl33core_renderer.c index a413907..1a68cae 100644 --- a/test/gl33core/gl33core_renderer.c +++ b/test/gl33core/gl33core_renderer.c @@ -238,7 +238,6 @@ static GLuint shader_compile(const char *shaderContents, size_t shaderContentsLe static GLuint shader_load(const char *shaderContents) { - GLuint result; GLuint vert = shader_compile(shaderContents, strlen(shaderContents), GL_VERTEX_SHADER); GLuint frag = shader_compile(shaderContents, strlen(shaderContents), GL_FRAGMENT_SHADER); @@ -249,7 +248,7 @@ static GLuint shader_load(const char *shaderContents) glLinkProgram(ref); glDetachShader(ref, vert); glDetachShader(ref, frag); - result = ref; + GLuint result = ref; return result; }