minor logging and settings improvements

This commit is contained in:
Dennis Eichhorn 2024-11-11 05:13:28 +01:00
parent e9e8213145
commit 713822687e
7 changed files with 46 additions and 34 deletions

View File

@ -39,7 +39,7 @@ void audio_fill_buffer(AudioSetting* setting, uint32 to_fill, Audio* sound, int1
buffer1_size /= setting->sample_size;
buffer2_size /= setting->sample_size;
uint32 sample_count = sound->size / sound->sample_size;
f32 volume_scale = (f32) setting->volume / 100.0f;
f32 volume_scale = setting->volume * setting->volume;
const int16* data = (int16*) sound->data;
uint32 sample_index = setting->sample_index;

View File

@ -33,8 +33,8 @@ struct AudioSetting {
// how often has the audio_play been called (required for xaudio)
uint32 sample_output;
// 0 - 100
int16 volume;
// 0.0 - 1.0
f32 volume;
// max buffer content/size
uint32 buffer_size;

View File

@ -352,7 +352,7 @@ f32 text_calculate_dimensions_height(
f32 text_calculate_dimensions_width(
f32 width,
const Font* __restrict font, const char* __restrict text, f32 scale, int32 length
const Font* __restrict font, const char* __restrict text, bool is_ascii, f32 scale, int32 length
) {
f32 x = 0;
f32 offset_x = 0;
@ -362,7 +362,7 @@ f32 text_calculate_dimensions_width(
// @todo remember to restrict to width/height if value > 0 -> force width to remain below certain value
for (int i = 0; i < length; ++i) {
int32 character = utf8_get_char_at(text, i);
int32 character = is_ascii ? text[i] : utf8_get_char_at(text, i);
if (character == '\n') {
x = OMS_MAX(x, offset_x);
@ -401,7 +401,7 @@ f32 text_calculate_dimensions_width(
void text_calculate_dimensions(
f32* __restrict width, f32* __restrict height,
const Font* __restrict font, const char* __restrict text, f32 scale, int32 length
const Font* __restrict font, const char* __restrict text, bool is_ascii, f32 scale, int32 length
) {
f32 x = 0;
f32 y = font->line_height * scale;
@ -413,7 +413,7 @@ void text_calculate_dimensions(
// @todo remember to restrict to width/height if value > 0 -> force width to remain below certain value
for (int i = 0; i < length; ++i) {
int32 character = utf8_get_char_at(text, i);
int32 character = is_ascii ? text[i] : utf8_get_char_at(text, i);
if (character == '\n') {
x = OMS_MAX(x, offset_x);
@ -459,14 +459,15 @@ f32 vertex_text_create(
const Font* __restrict font, const char* __restrict text, f32 size, uint32 color_index = 0
) {
int32 length = utf8_strlen(text);
bool is_ascii = strlen(text) == length;
float scale = size / font->size;
// If we do a different alignment we need to pre-calculate the width and height
if (align_h != 0 || align_v != 0) {
if (align_h != 0 && align_v != 0) {
text_calculate_dimensions(&width, &height, font, text, scale, length);
text_calculate_dimensions(&width, &height, font, text, is_ascii, scale, length);
} else if (align_h != 0) {
width = text_calculate_dimensions_width(width, font, text, scale, length);
width = text_calculate_dimensions_width(width, font, text, is_ascii, scale, length);
} else {
height = text_calculate_dimensions_height(height, font, text, scale, length);
}
@ -488,7 +489,7 @@ f32 vertex_text_create(
f32 offset_x = x;
for (int i = 0; i < length; ++i) {
int32 character = utf8_get_char_at(text, i);
int32 character = is_ascii ? text[i] : utf8_get_char_at(text, i);
if (character == '\n') {
y += font->line_height * scale;
offset_x = x;
@ -593,6 +594,7 @@ f32 ui_text_create(
UIAttribute* color_index = ui_attribute_from_group(element_group, UI_ATTRIBUTE_TYPE_FONT_COLOR);
int32 length = utf8_strlen(text->value_str);
bool is_ascii = strlen(text->value_str) == length;
float scale = size->value_float / theme->font.size;
// If we do a different alignment we need to pre-calculate the width and height
@ -601,9 +603,9 @@ f32 ui_text_create(
f32 tmp_height = height->value_int;
if (align_h != NULL && align_v != NULL) {
text_calculate_dimensions(&tmp_width, &tmp_height, &theme->font, text->value_str, scale, length);
text_calculate_dimensions(&tmp_width, &tmp_height, &theme->font, text->value_str, is_ascii, scale, length);
} else if (align_h != NULL) {
tmp_width = text_calculate_dimensions_width(tmp_width, &theme->font, text->value_str, scale, length);
tmp_width = text_calculate_dimensions_width(tmp_width, &theme->font, text->value_str, is_ascii, scale, length);
} else {
tmp_height = text_calculate_dimensions_height(tmp_height, &theme->font, text->value_str, scale, length);
}
@ -627,7 +629,7 @@ f32 ui_text_create(
f32 offset_x = x->value_int;
f32 offset_y = y->value_int;
for (int i = 0; i < length; ++i) {
int32 character = utf8_get_char_at(text->value_str, i);
int32 character = is_ascii ? text->value_str[i] : utf8_get_char_at(text->value_str, i);
if (character == '\n') {
offset_y += theme->font.line_height * scale;

View File

@ -64,6 +64,12 @@ void update_timing_stat_end_continued(uint32 stat, const char* function)
debug_container->perf_stats[stat].old_tick_count = new_tick_count;
}
inline
void update_timing_stat_reset(uint32 stat)
{
debug_container->perf_stats[stat].function = NULL;
}
inline
void reset_counter(int32 id)
{
@ -71,9 +77,9 @@ void reset_counter(int32 id)
}
inline
void log_increment(int32 id)
void log_increment(int32 id, int32 by = 1)
{
++debug_container->counter[id];
debug_container->counter[id] += by;
}
inline

View File

@ -55,7 +55,7 @@ struct LogMemory {
void log_to_file();
void log(const char* str, bool should_log, bool save, const char* file, const char* function, int32 line);
void log(const char* format, LogDataType data_type, void* data, bool should_log, bool save, const char* file, const char* function, int32 line);
void log_increment(int32);
void log_increment(int32, int32);
void log_counter(int32, int32);
#if (LOG_LEVEL == 0)
@ -64,6 +64,7 @@ void log_counter(int32, int32);
#define LOG_FORMAT(format, data_type, data, should_log, save) ((void) 0)
#define LOG_TO_FILE() ((void) 0)
#define LOG_INCREMENT(a) ((void) 0)
#define LOG_INCREMENT_BY(a, b) ((void) 0)
#define LOG_COUNTER(a, b) ((void) 0)
#define RESET_COUNTER(a) ((void) 0)
#else
@ -71,6 +72,7 @@ void log_counter(int32, int32);
#define LOG_FORMAT(format, data_type, data, should_log, save) log((format), (data_type), (data), (should_log), (save), __FILE__, __func__, __LINE__)
#define LOG_TO_FILE() log_to_file()
#define LOG_INCREMENT(a) log_increment((a))
#define LOG_INCREMENT_BY(a, b) log_increment((a), (b))
#define LOG_COUNTER(a, b) log_counter((a), (b))
#define RESET_COUNTER(a) reset_counter((a))
#endif

View File

@ -35,18 +35,24 @@ struct TimingStat {
// These are only needed if we need to delay the overwrite by 1 frame (e.g. ui update)
void update_timing_stat_start(uint32, const char*);
void update_timing_stat_end(uint32, const char*);
void update_timing_stat_end_continued(uint32, const char*);
#define UPDATE_TIMING_STAT_START(stat) update_timing_stat_start(stat, __func__)
#define UPDATE_TIMING_STAT_END(stat) update_timing_stat_end(stat, __func__)
#define UPDATE_TIMING_STAT_CONTINUE(stat) update_timing_stat_start(stat, __func__)
#define UPDATE_TIMING_STAT_END_CONTINUED(stat) update_timing_stat_end(stat, __func__)
void update_timing_stat_end(uint32, const char*);
#define UPDATE_TIMING_STAT_END(stat) update_timing_stat_end(stat, __func__)
void update_timing_stat_end_continued(uint32, const char*);
#define UPDATE_TIMING_STAT_END_CONTINUED(stat) update_timing_stat_end_continued(stat, __func__)
void update_timing_stat_reset(uint32);
#define UPDATE_TIMING_STAT_RESET(stat) update_timing_stat_reset(stat)
#else
#define UPDATE_TIMING_STAT(stat) ((void) 0)
#define UPDATE_TIMING_STAT_START(stat) ((void) 0)
#define UPDATE_TIMING_STAT_END(stat) ((void) 0)
#define UPDATE_TIMING_STAT_CONTINUE(stat) ((void) 0)
#define UPDATE_TIMING_STAT_END_CONTINUED(stat) ((void) 0)
#define UPDATE_TIMING_STAT_RESET(stat) ((void) 0)
#endif
#endif

View File

@ -123,8 +123,6 @@ struct CSettings {
byte gpu_gamma;
f32 gpu_fov;
int8 gpu_sync;
AntiAliasingType gpu_aa_type;
int8 gpu_aa_samples;
byte gpu_render_distance_terrain = 10;
byte gpu_render_distance_terrain_secondary = 10;
@ -175,8 +173,8 @@ struct CSettings {
byte gpu_reflection_blur = SETTING_TYPE_DISABLED;
byte gpu_motion_blur = SETTING_TYPE_DISABLED;
byte gpu_blur = SETTING_TYPE_DISABLED;
byte gpu_anti_aliasing = SETTING_TYPE_DISABLED;
byte gpu_anti_aliasing_detail = 0;
AntiAliasingType gpu_anti_aliasing;
int8 gpu_anti_aliasing_detail = 0;
byte gpu_sharpening = SETTING_TYPE_DISABLED;
byte gpu_ambient_occlusion = SETTING_TYPE_DISABLED;
byte gpu_color_deficiency;
@ -190,11 +188,11 @@ struct CSettings {
bool gpu_vignetting = true;
bool gpu_light_shafts = true;
byte audio_volume_master = 128;
byte audio_volume_game = 128;
byte audio_volume_environment = 128;
byte audio_volume_music = 128;
byte audio_volume_speech = 128;
f32 audio_volume_master;
f32 audio_volume_game;
f32 audio_volume_environment;
f32 audio_volume_music;
f32 audio_volume_speech;
uint16 game_window1_dim[2];
uint16 game_window1_pos[2];
@ -263,7 +261,6 @@ struct CSettings {
bool game_minimap_show_quest = false;
bool game_minimap_show_dungeons = false;
bool game_minimap_show_names = false;
bool game_show_clock = false;
bool game_map_show_merchants = false;
bool game_map_show_quest = false;
@ -419,7 +416,9 @@ void load_settings(CSettings* __restrict client_settings, char* data)
if (strncmp(name, "_ambient_occlusion", sizeof("_ambient_occlusion") - 1) == 0) {
} else if (strncmp(name, "_animation_quality", sizeof("_animation_quality") - 1) == 0) {
} else if (strncmp(name, "_anti_aliasing_detail", sizeof("_anti_aliasing_detail") - 1) == 0) {
client_settings->gpu_anti_aliasing_detail = (int8) atoi(pos);
} else if (strncmp(name, "_anti_aliasing", sizeof("_anti_aliasing") - 1) == 0) {
client_settings->gpu_anti_aliasing = (AntiAliasingType) atoi(pos);
} else if (strncmp(name, "_api", sizeof("_api") - 1) == 0) {
} else if (strncmp(name, "_aspect_ratio", sizeof("_aspect_ratio") - 1) == 0) {
client_settings->gpu_aspect_ratio = (f32) atof(pos);
@ -476,10 +475,6 @@ void load_settings(CSettings* __restrict client_settings, char* data)
} else if (strncmp(name, "_sharpening", sizeof("_sharpening") - 1) == 0) {
} else if (strncmp(name, "_sync", sizeof("_sync") - 1) == 0) {
client_settings->gpu_sync = (int8) atoi(pos);
} else if (strncmp(name, "_aa_type", sizeof("_aa_type") - 1) == 0) {
client_settings->gpu_aa_type = (AntiAliasingType) atoi(pos);
} else if (strncmp(name, "_aa_samples", sizeof("_aa_samples") - 1) == 0) {
client_settings->gpu_aa_samples = (int8) atoi(pos);
} else if (strncmp(name, "_terrain_quality", sizeof("_terrain_quality") - 1) == 0) {
} else if (strncmp(name, "_texture_quality", sizeof("_texture_quality") - 1) == 0) {
} else if (strncmp(name, "_type", sizeof("_type") - 1) == 0) {
@ -696,6 +691,7 @@ void load_settings(CSettings* __restrict client_settings, char* data)
if (strncmp(name, "_volume_environment", sizeof("_volume_environment") - 1) == 0) {
} else if (strncmp(name, "_volume_game", sizeof("_volume_game") - 1) == 0) {
} else if (strncmp(name, "_volume_master", sizeof("_volume_master") - 1) == 0) {
client_settings->audio_volume_master = (f32) atof(pos);
} else if (strncmp(name, "_volume_music", sizeof("_volume_music") - 1) == 0) {
} else if (strncmp(name, "_volume_speech", sizeof("_volume_speech") - 1) == 0) {
}