Add SurfaceFlags, and more formatting :)
Build libsm64 / Build libsm64 for linux (push) Successful in 32s
Build libsm64 / Build libsm64 for web (push) Successful in 39s
Build libsm64 / Build libsm64 for windows (push) Successful in 25s

This commit is contained in:
2026-05-24 18:03:08 -05:00
parent d3ea4e5e99
commit bd3dd8f523
38 changed files with 716 additions and 1295 deletions
+36 -80
View File
@@ -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)
{