Code gardening

- Review formatting
 - Improve readability for some functions result return
 - Minimize early returns
 - Align LoadFileData() to UnloadFileData()
This commit is contained in:
Ray 2024-04-20 13:53:13 +02:00
parent 2754c80596
commit 29ce13b777
6 changed files with 160 additions and 80 deletions

View file

@ -752,7 +752,7 @@ Wave LoadWave(const char *fileName)
// Loading wave from memory data
if (fileData != NULL) wave = LoadWaveFromMemory(GetFileExtension(fileName), fileData, dataSize);
RL_FREE(fileData);
UnloadFileData(fileData);
return wave;
}
@ -870,11 +870,15 @@ Wave LoadWaveFromMemory(const char *fileType, const unsigned char *fileData, int
// Checks if wave data is ready
bool IsWaveReady(Wave wave)
{
return ((wave.data != NULL) && // Validate wave data available
(wave.frameCount > 0) && // Validate frame count
(wave.sampleRate > 0) && // Validate sample rate is supported
(wave.sampleSize > 0) && // Validate sample size is supported
(wave.channels > 0)); // Validate number of channels supported
bool result = false;
if ((wave.data != NULL) && // Validate wave data available
(wave.frameCount > 0) && // Validate frame count
(wave.sampleRate > 0) && // Validate sample rate is supported
(wave.sampleSize > 0) && // Validate sample size is supported
(wave.channels > 0)) result = true; // Validate number of channels supported
return result;
}
// Load sound from file
@ -967,11 +971,15 @@ Sound LoadSoundAlias(Sound source)
// Checks if a sound is ready
bool IsSoundReady(Sound sound)
{
return ((sound.frameCount > 0) && // Validate frame count
(sound.stream.buffer != NULL) && // Validate stream buffer
(sound.stream.sampleRate > 0) && // Validate sample rate is supported
(sound.stream.sampleSize > 0) && // Validate sample size is supported
(sound.stream.channels > 0)); // Validate number of channels supported
bool result = false;
if ((sound.frameCount > 0) && // Validate frame count
(sound.stream.buffer != NULL) && // Validate stream buffer
(sound.stream.sampleRate > 0) && // Validate sample rate is supported
(sound.stream.sampleSize > 0) && // Validate sample size is supported
(sound.stream.channels > 0)) result = true; // Validate number of channels supported
return result;
}
// Unload wave data
@ -1163,7 +1171,11 @@ void StopSound(Sound sound)
// Check if a sound is playing
bool IsSoundPlaying(Sound sound)
{
return IsAudioBufferPlaying(sound.stream.buffer);
bool result = false;
if (IsAudioBufferPlaying(sound.stream.buffer)) result = true;
return result;
}
// Set volume for a sound