From 7090de541ad2143a60000f4ccaf70cd69a1d0973 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Thu, 13 Feb 2020 17:26:11 +0100 Subject: [PATCH] - Merge runahead/mylist.c into retroarch.c - General cleanups --- Makefile.common | 1 - gfx/display_servers/dispserv_android.c | 36 +----- griffin/griffin.c | 4 - retroarch.c | 145 +++++++++++++++++++-- runahead/mylist.c | 167 ------------------------- runahead/mylist.h | 40 ------ 6 files changed, 141 insertions(+), 252 deletions(-) delete mode 100644 runahead/mylist.c delete mode 100644 runahead/mylist.h diff --git a/Makefile.common b/Makefile.common index 1222bef126..535cfd9d4b 100644 --- a/Makefile.common +++ b/Makefile.common @@ -282,7 +282,6 @@ endif ifeq ($(HAVE_RUNAHEAD), 1) DEFINES += -DHAVE_RUNAHEAD - OBJ += runahead/mylist.o endif ifeq ($(HAVE_CC_RESAMPLER), 1) diff --git a/gfx/display_servers/dispserv_android.c b/gfx/display_servers/dispserv_android.c index a77861347a..4b4072d1ba 100644 --- a/gfx/display_servers/dispserv_android.c +++ b/gfx/display_servers/dispserv_android.c @@ -19,30 +19,11 @@ #include "../video_display_server.h" #include "../../frontend/drivers/platform_unix.h" -static void* android_display_server_init(void) -{ - return NULL; -} - -static void android_display_server_destroy(void *data) -{ - (void)data; -} - -static bool android_display_server_set_window_opacity(void *data, unsigned opacity) -{ - (void)data; - (void)opacity; - return true; -} - -static bool android_display_server_set_window_progress(void *data, int progress, bool finished) -{ - (void)data; - (void)progress; - (void)finished; - return true; -} +static void* android_display_server_init(void) { return NULL; } +static void android_display_server_destroy(void *data) { } +static bool android_display_server_set_window_opacity(void *data, unsigned opacity) { return true; } +static bool android_display_server_set_window_progress(void *data, int progress, bool finished) { return true; } +static uint32_t android_display_server_get_flags(void *data) { return 0; } static void android_display_server_set_screen_orientation(enum rotation rotation) { @@ -56,13 +37,6 @@ static void android_display_server_set_screen_orientation(enum rotation rotation g_android->setScreenOrientation, rotation); } -static uint32_t android_display_server_get_flags(void *data) -{ - uint32_t flags = 0; - - return flags; -} - const video_display_server_t dispserv_android = { android_display_server_init, android_display_server_destroy, diff --git a/griffin/griffin.c b/griffin/griffin.c index f4cc840c64..f22cf24390 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -1379,10 +1379,6 @@ MENU #include "../libretro-common/net/net_http_parse.c" #endif -#ifdef HAVE_RUNAHEAD -#include "../runahead/mylist.c" -#endif - /*============================================================ DEPENDENCIES ============================================================ */ diff --git a/retroarch.c b/retroarch.c index c2966d6028..75138a9c75 100644 --- a/retroarch.c +++ b/retroarch.c @@ -223,10 +223,6 @@ #include "retroarch.h" -#ifdef HAVE_RUNAHEAD -#include "runahead/mylist.h" -#endif - #ifdef HAVE_ACCESSIBILITY #include "accessibility.h" #endif @@ -3239,6 +3235,18 @@ static bool request_fast_savestate = false; static bool hard_disable_audio = false; /* Save State List for Run Ahead */ +typedef void *(*constructor_t)(void); +typedef void (*destructor_t )(void*); + +typedef struct MyList_t +{ + void **data; + int capacity; + int size; + constructor_t constructor; + destructor_t destructor; +} MyList; + static MyList *runahead_save_state_list = NULL; static MyList *input_state_list = NULL; @@ -23690,14 +23698,133 @@ bool driver_ctl(enum driver_ctl_state state, void *data) /* RUNAHEAD */ #ifdef HAVE_RUNAHEAD +static void mylist_resize(MyList *list, int new_size, bool run_constructor) +{ + int i; + int new_capacity; + int old_size; + void *element = NULL; + if (new_size < 0) + new_size = 0; + if (!list) + return; + new_capacity = new_size; + old_size = list->size; + + if (new_size == old_size) + return; + + if (new_size > list->capacity) + { + if (new_capacity < list->capacity * 2) + new_capacity = list->capacity * 2; + + /* try to realloc */ + list->data = (void**)realloc( + (void*)list->data, new_capacity * sizeof(void*)); + + for (i = list->capacity; i < new_capacity; i++) + list->data[i] = NULL; + + list->capacity = new_capacity; + } + + if (new_size <= list->size) + { + for (i = new_size; i < list->size; i++) + { + element = list->data[i]; + + if (element) + { + list->destructor(element); + list->data[i] = NULL; + } + } + } + else + { + for (i = list->size; i < new_size; i++) + { + list->data[i] = NULL; + if (run_constructor) + list->data[i] = list->constructor(); + } + } + + list->size = new_size; +} + +static void *mylist_add_element(MyList *list) +{ + int old_size; + + if (!list) + return NULL; + + old_size = list->size; + mylist_resize(list, old_size + 1, true); + return list->data[old_size]; +} + +static void mylist_destroy(MyList **list_p) +{ + MyList *list = NULL; + if (!list_p) + return; + + list = *list_p; + + if (list) + { + mylist_resize(list, 0, false); + free(list->data); + free(list); + *list_p = NULL; + } +} + + +static void mylist_create(MyList **list_p, int initial_capacity, + constructor_t constructor, destructor_t destructor) +{ + MyList *list = NULL; + + if (!list_p) + return; + + if (initial_capacity < 0) + initial_capacity = 0; + + list = *list_p; + if (list) + mylist_destroy(list_p); + + list = (MyList*)malloc(sizeof(MyList)); + *list_p = list; + list->size = 0; + list->constructor = constructor; + list->destructor = destructor; + + if (initial_capacity > 0) + { + list->data = (void**)calloc(initial_capacity, sizeof(void*)); + list->capacity = initial_capacity; + } + else + { + list->data = NULL; + list->capacity = 0; + } +} static void *input_list_element_constructor(void) { - void *ptr = calloc(1, sizeof(input_list_element)); - input_list_element *element = (input_list_element*)ptr; + void *ptr = calloc(1, sizeof(input_list_element)); + input_list_element *element = (input_list_element*)ptr; - element->state_size = 256; - element->state = (int16_t*)calloc( + element->state_size = 256; + element->state = (int16_t*)calloc( element->state_size, sizeof(int16_t)); return ptr; @@ -24028,7 +24155,7 @@ static bool runahead_create(void) static bool runahead_save_state(void) { retro_ctx_serialize_info_t *serialize_info; - bool okay = false; + bool okay = false; if (!runahead_save_state_list) return false; diff --git a/runahead/mylist.c b/runahead/mylist.c deleted file mode 100644 index 20bfd91b0d..0000000000 --- a/runahead/mylist.c +++ /dev/null @@ -1,167 +0,0 @@ -#include -#include - -#include "mylist.h" - -void mylist_resize(MyList *list, int new_size, bool run_constructor) -{ - int new_capacity; - int old_size; - int i; - void *element = NULL; - if (new_size < 0) - new_size = 0; - if (!list) - return; - new_capacity = new_size; - old_size = list->size; - - if (new_size == old_size) - return; - - if (new_size > list->capacity) - { - if (new_capacity < list->capacity * 2) - new_capacity = list->capacity * 2; - - /* try to realloc */ - list->data = (void**)realloc( - (void*)list->data, new_capacity * sizeof(void*)); - - for (i = list->capacity; i < new_capacity; i++) - list->data[i] = NULL; - - list->capacity = new_capacity; - } - - if (new_size <= list->size) - { - for (i = new_size; i < list->size; i++) - { - element = list->data[i]; - - if (element) - { - list->destructor(element); - list->data[i] = NULL; - } - } - } - else - { - for (i = list->size; i < new_size; i++) - { - if (run_constructor) - list->data[i] = list->constructor(); - else - list->data[i] = NULL; - } - } - - list->size = new_size; -} - -void *mylist_add_element(MyList *list) -{ - int old_size; - - if (!list) - return NULL; - - old_size = list->size; - mylist_resize(list, old_size + 1, true); - return list->data[old_size]; -} - -void mylist_create(MyList **list_p, int initial_capacity, - constructor_t constructor, destructor_t destructor) -{ - MyList *list = NULL; - - if (!list_p) - return; - - if (initial_capacity < 0) - initial_capacity = 0; - - list = *list_p; - if (list) - mylist_destroy(list_p); - - list = (MyList*)malloc(sizeof(MyList)); - *list_p = list; - list->size = 0; - list->constructor = constructor; - list->destructor = destructor; - - if (initial_capacity > 0) - { - list->data = (void**)calloc(initial_capacity, sizeof(void*)); - list->capacity = initial_capacity; - } - else - { - list->data = NULL; - list->capacity = 0; - } -} - -void mylist_destroy(MyList **list_p) -{ - MyList *list = NULL; - if (!list_p) - return; - - list = *list_p; - - if (list) - { - mylist_resize(list, 0, false); - free(list->data); - free(list); - *list_p = NULL; - } -} - -void mylist_assign(MyList *list, int index, void *value) -{ - void *old_element = NULL; - - if (index < 0 || index >= list->size) - return; - - old_element = list->data[index]; - list->destructor(old_element); - list->data[index] = value; -} - -void mylist_remove_at(MyList *list, int index) -{ - int i; - - if (index < 0 || index >= list->size) - return; - - mylist_assign(list, index, NULL); - - for (i = index + 1; i < list->size; i++) - list->data[i - 1] = list->data[i]; - - list->size--; - list->data[list->size] = NULL; -} - -void mylist_pop_front(MyList *list) -{ - mylist_remove_at(list, 0); -} - -void mylist_push_back(MyList *list, void *value) -{ - int old_size; - if (!list) - return; - old_size = list->size; - mylist_resize(list, old_size + 1, false); - list->data[old_size] = value; -} diff --git a/runahead/mylist.h b/runahead/mylist.h deleted file mode 100644 index cdc03efab0..0000000000 --- a/runahead/mylist.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef __MYLIST_H__ -#define __MYLIST_H__ - -#include -#include -#include -#include - -RETRO_BEGIN_DECLS - -typedef void *(*constructor_t)(void); -typedef void (*destructor_t )(void*); - -typedef struct MyList_t -{ - void **data; - int capacity; - int size; - constructor_t constructor; - destructor_t destructor; -} MyList; - -void *mylist_add_element(MyList *list); - -void mylist_resize(MyList *list, int newSize, bool run_constructor); - -void mylist_create(MyList **list_p, int initial_capacity, - constructor_t constructor, destructor_t destructor); - -void mylist_destroy(MyList **list_p); - -void mylist_assign(MyList *list, int index, void *value); - -void mylist_remove_at(MyList *list, int index); - -void mylist_pop_front(MyList *list); - -RETRO_END_DECLS - -#endif