From 9059b4962e89b60e87370abcb40f0cbbfa13b3e4 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 7 Jun 2020 00:05:41 +0200 Subject: [PATCH] Cleanups --- gfx/gfx_animation.c | 62 +++++++++++++++++++++------------------- gfx/gfx_display.c | 5 ++-- gfx/video_shader_parse.c | 18 ++++-------- 3 files changed, 40 insertions(+), 45 deletions(-) diff --git a/gfx/gfx_animation.c b/gfx/gfx_animation.c index 5f8ba512a6..b6080e9d99 100644 --- a/gfx/gfx_animation.c +++ b/gfx/gfx_animation.c @@ -85,10 +85,6 @@ static const float ticker_pixel_period = (1.0f / 60.0f) * 1000.0f; static const char ticker_spacer_default[] = TICKER_SPACER_DEFAULT; -/* TODO/FIXME - global that gets referenced outside, - * needs to be refactored */ -static gfx_animation_t anim; - /* Forward declarations */ static void gfx_animation_update_time_default( float *dst, @@ -100,6 +96,9 @@ static update_time_cb update_time_callback = gfx_animation_update_time_default; static gfx_animation_t *anim_get_ptr(void) { + /* TODO/FIXME - global that gets referenced outside, + * needs to be refactored */ + static gfx_animation_t anim; return &anim; } @@ -1062,6 +1061,7 @@ void gfx_animation_push_delayed( bool gfx_animation_push(gfx_animation_ctx_entry_t *entry) { struct tween t; + gfx_animation_t *p_anim = anim_get_ptr(); t.duration = entry->duration; t.running_since = 0; @@ -1191,17 +1191,17 @@ bool gfx_animation_push(gfx_animation_ctx_entry_t *entry) if (!t.easing || t.duration == 0 || t.initial_value == t.target_value) return false; - if (!anim.initialized) + if (!p_anim->initialized) { - da_init(anim.list); - da_init(anim.pending); - anim.initialized = true; + da_init(p_anim->list); + da_init(p_anim->pending); + p_anim->initialized = true; } - if (anim.in_update) - da_push(anim.pending, t); + if (p_anim->in_update) + da_push(p_anim->pending, t); else - da_push(anim.list, t); + da_push(p_anim->list, t); return true; } @@ -2240,24 +2240,25 @@ bool gfx_animation_is_active(void) bool gfx_animation_kill_by_tag(gfx_animation_ctx_tag *tag) { unsigned i; + gfx_animation_t *p_anim = anim_get_ptr(); if (!tag || *tag == (uintptr_t)-1) return false; - for (i = 0; i < da_count(anim.list); ++i) + for (i = 0; i < da_count(p_anim->list); ++i) { - struct tween *t = da_getptr(anim.list, i); + struct tween *t = da_getptr(p_anim->list, i); if (!t || t->tag != *tag) continue; - if (anim.in_update) + if (p_anim->in_update) { - t->deleted = true; - anim.pending_deletes = true; + t->deleted = true; + p_anim->pending_deletes = true; } else { - da_delete(anim.list, i); + da_delete(p_anim->list, i); --i; } } @@ -2267,12 +2268,13 @@ bool gfx_animation_kill_by_tag(gfx_animation_ctx_tag *tag) void gfx_animation_kill_by_subject(gfx_animation_ctx_subject_t *subject) { - unsigned i, j, killed = 0; - float **sub = (float**)subject->data; + unsigned i, j, killed = 0; + float **sub = (float**)subject->data; + gfx_animation_t *p_anim = anim_get_ptr(); - for (i = 0; i < da_count(anim.list) && killed < subject->count; ++i) + for (i = 0; i < da_count(p_anim->list) && killed < subject->count; ++i) { - struct tween *t = da_getptr(anim.list, i); + struct tween *t = da_getptr(p_anim->list, i); if (!t) continue; @@ -2281,14 +2283,14 @@ void gfx_animation_kill_by_subject(gfx_animation_ctx_subject_t *subject) if (t->subject != sub[j]) continue; - if (anim.in_update) + if (p_anim->in_update) { - t->deleted = true; - anim.pending_deletes = true; + t->deleted = true; + p_anim->pending_deletes = true; } else { - da_delete(anim.list, i); + da_delete(p_anim->list, i); --i; } @@ -2314,9 +2316,9 @@ bool gfx_animation_ctl(enum gfx_animation_ctl_state state, void *data) { size_t i; - for (i = 0; i < da_count(anim.list); i++) + for (i = 0; i < da_count(p_anim->list); i++) { - struct tween *t = da_getptr(anim.list, i); + struct tween *t = da_getptr(p_anim->list, i); if (!t) continue; @@ -2324,10 +2326,10 @@ bool gfx_animation_ctl(enum gfx_animation_ctl_state state, void *data) t->subject = NULL; } - da_free(anim.list); - da_free(anim.pending); + da_free(p_anim->list); + da_free(p_anim->pending); - memset(&anim, 0, sizeof(anim)); + memset(&p_anim, 0, sizeof(p_anim)); } p_anim->cur_time = 0; p_anim->old_time = 0; diff --git a/gfx/gfx_display.c b/gfx/gfx_display.c index 0729205fdc..d1151ce217 100644 --- a/gfx/gfx_display.c +++ b/gfx/gfx_display.c @@ -69,10 +69,11 @@ struct gfx_display typedef struct gfx_display gfx_display_t; -static gfx_display_t dispgfx; - static gfx_display_t *disp_get_ptr(void) { + /* TODO/FIXME - global that gets referenced outside, + * needs to be refactored */ + static gfx_display_t dispgfx; return &dispgfx; } diff --git a/gfx/video_shader_parse.c b/gfx/video_shader_parse.c index 9dd57908f6..c227bc1579 100644 --- a/gfx/video_shader_parse.c +++ b/gfx/video_shader_parse.c @@ -555,14 +555,14 @@ bool video_shader_resolve_parameters(config_file_t *conf, param->desc[63] = '\0'; if (ret == 5) - param->step = 0.1f * (param->maximum - param->minimum); + param->step = 0.1f * (param->maximum - param->minimum); - param->pass = i; + param->pass = i; RARCH_LOG("Found #pragma parameter %s (%s) %f %f %f %f in pass %d\n", param->desc, param->id, param->initial, param->minimum, param->maximum, param->step, param->pass); - param->current = param->initial; + param->current = param->initial; shader->num_parameters++; param++; @@ -624,8 +624,7 @@ bool video_shader_write_preset(const char *path, { /* write a reference preset */ char buf[STRLEN_CONST("#reference \"") + PATH_MAX_LENGTH + 1] = "#reference \""; - size_t len = STRLEN_CONST("#reference \""); - + size_t len = STRLEN_CONST("#reference \""); char *preset_ref = buf + len; strlcpy(clean_path, path, PATH_MAX_LENGTH); @@ -734,9 +733,7 @@ char *video_shader_read_reference_path(const char *path) p++; if (*p == '\"') - { *p = '\0'; - } else { /* if there's no second ", remove whitespace at the end */ @@ -763,10 +760,8 @@ char *video_shader_read_reference_path(const char *path) /* rebase relative reference path */ if (!path_is_absolute(ref_path)) - { fill_pathname_resolve_relative(reference, path, ref_path, PATH_MAX_LENGTH); - } else strlcpy(reference, ref_path, PATH_MAX_LENGTH); } @@ -889,10 +884,7 @@ bool video_shader_read_conf_preset(config_file_t *conf, string_list_free(file_list); } - if (!video_shader_parse_textures(conf, shader)) - return false; - - return true; + return video_shader_parse_textures(conf, shader); } /* CGP store */