Skip to content

Commit

Permalink
misc: adopt M_ prefix for private functions
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Sep 20, 2024
1 parent 39c2d55 commit cce71ee
Show file tree
Hide file tree
Showing 23 changed files with 520 additions and 565 deletions.
4 changes: 2 additions & 2 deletions src/benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include <SDL2/SDL_timer.h>

static void Benchmark_Log(
static void M_Log(
BENCHMARK *const b, const char *file, int32_t line, const char *func,
Uint64 current, const char *message)
{
Expand Down Expand Up @@ -49,7 +49,7 @@ void Benchmark_Tick_Impl(
const char *const func, const char *const message)
{
const Uint64 current = SDL_GetPerformanceCounter();
Benchmark_Log(b, file, line, func, current, message);
M_Log(b, file, line, func, current, message);
b->last = current;
}

Expand Down
42 changes: 20 additions & 22 deletions src/config/config_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@

#include <string.h>

static bool Config_ReadFromJSON(
static bool M_ReadFromJSON(
const char *json, void (*load)(struct json_object_s *root_obj));
static char *Config_WriteToJSON(void (*dump)(struct json_object_s *root_obj));
static char *M_WriteToJSON(void (*dump)(struct json_object_s *root_obj));
static const char *M_ResolveOptionName(const char *option_name);

static const char *ConfigFile_ResolveOptionName(const char *option_name);

static bool Config_ReadFromJSON(
static bool M_ReadFromJSON(
const char *cfg_data, void (*load)(struct json_object_s *root_obj))
{
bool result = false;
Expand Down Expand Up @@ -42,7 +41,7 @@ static bool Config_ReadFromJSON(
return result;
}

static char *Config_WriteToJSON(void (*dump)(struct json_object_s *root_obj))
static char *M_WriteToJSON(void (*dump)(struct json_object_s *root_obj))
{
struct json_object_s *root_obj = json_object_new();

Expand All @@ -56,7 +55,7 @@ static char *Config_WriteToJSON(void (*dump)(struct json_object_s *root_obj))
return data;
}

static const char *ConfigFile_ResolveOptionName(const char *option_name)
static const char *M_ResolveOptionName(const char *option_name)
{
const char *dot = strrchr(option_name, '.');
if (dot) {
Expand All @@ -73,9 +72,9 @@ bool ConfigFile_Read(

if (!File_Load(path, &cfg_data, NULL)) {
LOG_WARNING("'%s' not loaded - default settings will apply", path);
result = Config_ReadFromJSON("{}", load);
result = M_ReadFromJSON("{}", load);
} else {
result = Config_ReadFromJSON(cfg_data, load);
result = M_ReadFromJSON(cfg_data, load);
}

Memory_FreePointer(&cfg_data);
Expand All @@ -92,7 +91,7 @@ bool ConfigFile_Write(
return false;
}

char *data = Config_WriteToJSON(dump);
char *data = M_WriteToJSON(dump);
File_WriteData(fp, data, strlen(data));
File_Close(fp);
Memory_FreePointer(&data);
Expand All @@ -108,31 +107,31 @@ void ConfigFile_LoadOptions(
switch (opt->type) {
case COT_BOOL:
*(bool *)opt->target = json_object_get_bool(
root_obj, ConfigFile_ResolveOptionName(opt->name),
root_obj, M_ResolveOptionName(opt->name),
*(bool *)opt->default_value);
break;

case COT_INT32:
*(int32_t *)opt->target = json_object_get_int(
root_obj, ConfigFile_ResolveOptionName(opt->name),
root_obj, M_ResolveOptionName(opt->name),
*(int32_t *)opt->default_value);
break;

case COT_FLOAT:
*(float *)opt->target = json_object_get_double(
root_obj, ConfigFile_ResolveOptionName(opt->name),
root_obj, M_ResolveOptionName(opt->name),
*(float *)opt->default_value);
break;

case COT_DOUBLE:
*(double *)opt->target = json_object_get_double(
root_obj, ConfigFile_ResolveOptionName(opt->name),
root_obj, M_ResolveOptionName(opt->name),
*(double *)opt->default_value);
break;

case COT_ENUM:
*(int *)opt->target = ConfigFile_ReadEnum(
root_obj, ConfigFile_ResolveOptionName(opt->name),
root_obj, M_ResolveOptionName(opt->name),
*(int *)opt->default_value,
(const ENUM_STRING_MAP *)opt->param);
}
Expand All @@ -148,32 +147,31 @@ void ConfigFile_DumpOptions(
switch (opt->type) {
case COT_BOOL:
json_object_append_bool(
root_obj, ConfigFile_ResolveOptionName(opt->name),
*(bool *)opt->target);
root_obj, M_ResolveOptionName(opt->name), *(bool *)opt->target);
break;

case COT_INT32:
json_object_append_int(
root_obj, ConfigFile_ResolveOptionName(opt->name),
root_obj, M_ResolveOptionName(opt->name),
*(int32_t *)opt->target);
break;

case COT_FLOAT:
json_object_append_double(
root_obj, ConfigFile_ResolveOptionName(opt->name),
root_obj, M_ResolveOptionName(opt->name),
*(float *)opt->target);
break;

case COT_DOUBLE:
json_object_append_double(
root_obj, ConfigFile_ResolveOptionName(opt->name),
root_obj, M_ResolveOptionName(opt->name),
*(double *)opt->target);
break;

case COT_ENUM:
ConfigFile_WriteEnum(
root_obj, ConfigFile_ResolveOptionName(opt->name),
*(int *)opt->target, (const ENUM_STRING_MAP *)opt->param);
root_obj, M_ResolveOptionName(opt->name), *(int *)opt->target,
(const ENUM_STRING_MAP *)opt->param);
break;
}
opt++;
Expand Down
7 changes: 3 additions & 4 deletions src/engine/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ static size_t m_MixBufferCapacity = 0;
static float *m_MixBuffer = NULL;
static Uint8 m_Silence = 0;

static void Audio_MixerCallback(
void *userdata, Uint8 *stream_data, int32_t len);
static void M_MixerCallback(void *userdata, Uint8 *stream_data, int32_t len);

static void Audio_MixerCallback(void *userdata, Uint8 *stream_data, int32_t len)
static void M_MixerCallback(void *userdata, Uint8 *stream_data, int32_t len)
{
memset(m_MixBuffer, m_Silence, len);
Audio_Stream_Mix(m_MixBuffer, len);
Expand Down Expand Up @@ -46,7 +45,7 @@ bool Audio_Init(void)
desired.format = AUDIO_WORKING_FORMAT;
desired.channels = AUDIO_WORKING_CHANNELS;
desired.samples = AUDIO_SAMPLES;
desired.callback = Audio_MixerCallback;
desired.callback = M_MixerCallback;
desired.userdata = NULL;

SDL_AudioSpec delivered;
Expand Down
44 changes: 20 additions & 24 deletions src/engine/audio_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,37 +61,34 @@ static int32_t m_LoadedSamplesCount = 0;
static AUDIO_SAMPLE m_LoadedSamples[AUDIO_MAX_SAMPLES] = { 0 };
static AUDIO_SAMPLE_SOUND m_Samples[AUDIO_MAX_ACTIVE_SAMPLES] = { 0 };

static double Audio_Sample_DecibelToMultiplier(double db_gain);
static bool Audio_Sample_RecalculateChannelVolumes(int32_t sound_id);
static int32_t Audio_Sample_ReadAVBuffer(
void *opaque, uint8_t *dst, int32_t dst_size);
static int64_t Audio_Sample_SeekAVBuffer(
void *opaque, int64_t offset, int32_t whence);
static bool Audio_Sample_Convert(const int32_t sample_id);

static double Audio_Sample_DecibelToMultiplier(double db_gain)
static double M_DecibelToMultiplier(double db_gain);
static bool M_RecalculateChannelVolumes(int32_t sound_id);
static int32_t M_ReadAVBuffer(void *opaque, uint8_t *dst, int32_t dst_size);
static int64_t M_SeekAVBuffer(void *opaque, int64_t offset, int32_t whence);
static bool M_Convert(const int32_t sample_id);

static double M_DecibelToMultiplier(double db_gain)
{
return pow(2.0, db_gain / 600.0);
}

static bool Audio_Sample_RecalculateChannelVolumes(int32_t sound_id)
static bool M_RecalculateChannelVolumes(int32_t sound_id)
{
if (!g_AudioDeviceID || sound_id < 0
|| sound_id >= AUDIO_MAX_ACTIVE_SAMPLES) {
return false;
}

AUDIO_SAMPLE_SOUND *sound = &m_Samples[sound_id];
sound->volume_l = Audio_Sample_DecibelToMultiplier(
sound->volume_l = M_DecibelToMultiplier(
sound->volume - (sound->pan > 0 ? sound->pan : 0));
sound->volume_r = Audio_Sample_DecibelToMultiplier(
sound->volume_r = M_DecibelToMultiplier(
sound->volume + (sound->pan < 0 ? sound->pan : 0));

return true;
}

static int32_t Audio_Sample_ReadAVBuffer(
void *opaque, uint8_t *dst, int32_t dst_size)
static int32_t M_ReadAVBuffer(void *opaque, uint8_t *dst, int32_t dst_size)
{
assert(opaque != NULL);
assert(dst != NULL);
Expand All @@ -106,8 +103,7 @@ static int32_t Audio_Sample_ReadAVBuffer(
return read;
}

static int64_t Audio_Sample_SeekAVBuffer(
void *opaque, int64_t offset, int32_t whence)
static int64_t M_SeekAVBuffer(void *opaque, int64_t offset, int32_t whence)
{
assert(opaque != NULL);
AUDIO_AV_BUFFER *src = opaque;
Expand Down Expand Up @@ -140,7 +136,7 @@ static int64_t Audio_Sample_SeekAVBuffer(
return src->ptr - src->data;
}

static bool Audio_Sample_Convert(const int32_t sample_id)
static bool M_Convert(const int32_t sample_id)
{
assert(sample_id >= 0 && sample_id < m_LoadedSamplesCount);

Expand Down Expand Up @@ -201,8 +197,8 @@ static bool Audio_Sample_Convert(const int32_t sample_id)
};

av.avio_context = avio_alloc_context(
read_buffer, av.read_buffer_size, 0, &av_buf, Audio_Sample_ReadAVBuffer,
NULL, Audio_Sample_SeekAVBuffer);
read_buffer, av.read_buffer_size, 0, &av_buf, M_ReadAVBuffer, NULL,
M_SeekAVBuffer);

av.format_ctx = avformat_alloc_context();
av.format_ctx->pb = av.avio_context;
Expand Down Expand Up @@ -559,7 +555,7 @@ int32_t Audio_Sample_Play(
continue;
}

Audio_Sample_Convert(sample_id);
M_Convert(sample_id);

sound->is_used = true;
sound->is_playing = true;
Expand All @@ -570,7 +566,7 @@ int32_t Audio_Sample_Play(
sound->current_sample = 0.0f;
sound->sample = &m_LoadedSamples[sample_id];

Audio_Sample_RecalculateChannelVolumes(sound_id);
M_RecalculateChannelVolumes(sound_id);

result = sound_id;
break;
Expand Down Expand Up @@ -696,7 +692,7 @@ bool Audio_Sample_SetPan(int32_t sound_id, int32_t pan)

SDL_LockAudioDevice(g_AudioDeviceID);
m_Samples[sound_id].pan = pan;
Audio_Sample_RecalculateChannelVolumes(sound_id);
M_RecalculateChannelVolumes(sound_id);
SDL_UnlockAudioDevice(g_AudioDeviceID);

return true;
Expand All @@ -711,7 +707,7 @@ bool Audio_Sample_SetVolume(int32_t sound_id, int32_t volume)

SDL_LockAudioDevice(g_AudioDeviceID);
m_Samples[sound_id].volume = volume;
Audio_Sample_RecalculateChannelVolumes(sound_id);
M_RecalculateChannelVolumes(sound_id);
SDL_UnlockAudioDevice(g_AudioDeviceID);

return true;
Expand All @@ -726,7 +722,7 @@ bool Audio_Sample_SetPitch(int32_t sound_id, float pitch)

SDL_LockAudioDevice(g_AudioDeviceID);
m_Samples[sound_id].pitch = pitch;
Audio_Sample_RecalculateChannelVolumes(sound_id);
M_RecalculateChannelVolumes(sound_id);
SDL_UnlockAudioDevice(g_AudioDeviceID);

return true;
Expand Down
Loading

0 comments on commit cce71ee

Please sign in to comment.