mirror of
https://github.com/libretro/RetroArch
synced 2025-04-01 04:20:27 +00:00
Refactor db_state code
This commit is contained in:
parent
07019909f3
commit
566eb771ba
@ -121,14 +121,15 @@ typedef struct nbio_handle
|
|||||||
|
|
||||||
typedef struct database_state_handle
|
typedef struct database_state_handle
|
||||||
{
|
{
|
||||||
|
struct string_list *list;
|
||||||
|
size_t list_index;
|
||||||
|
size_t entry_index;
|
||||||
|
uint32_t crc;
|
||||||
uint8_t *buf;
|
uint8_t *buf;
|
||||||
} database_state_handle_t;
|
} database_state_handle_t;
|
||||||
|
|
||||||
typedef struct db_handle
|
typedef struct db_handle
|
||||||
{
|
{
|
||||||
struct string_list *list;
|
|
||||||
size_t list_index;
|
|
||||||
size_t entry_index;
|
|
||||||
database_state_handle_t state;
|
database_state_handle_t state;
|
||||||
database_info_handle_t *handle;
|
database_info_handle_t *handle;
|
||||||
msg_queue_t *msg_queue;
|
msg_queue_t *msg_queue;
|
||||||
|
@ -70,21 +70,16 @@ static int database_info_iterate_playlist(
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
uint32_t crc, target_crc = 0;
|
|
||||||
int read_from = read_file(name, (void**)&db_state->buf, &ret);
|
int read_from = read_file(name, (void**)&db_state->buf, &ret);
|
||||||
|
|
||||||
(void)target_crc;
|
|
||||||
|
|
||||||
if (read_from != 1 || ret <= 0)
|
if (read_from != 1 || ret <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
||||||
#ifdef HAVE_ZLIB
|
#ifdef HAVE_ZLIB
|
||||||
crc = zlib_crc32_calculate(db_state->buf, ret);
|
db_state->crc = zlib_crc32_calculate(db_state->buf, ret);
|
||||||
|
RARCH_LOG("CRC32: 0x%x .\n", (unsigned)db_state->crc);
|
||||||
RARCH_LOG("CRC32: 0x%x .\n", (unsigned)crc);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -168,8 +163,9 @@ static void rarch_main_data_db_cleanup_state(void *data)
|
|||||||
|
|
||||||
void rarch_main_data_db_iterate(bool is_thread, void *data)
|
void rarch_main_data_db_iterate(bool is_thread, void *data)
|
||||||
{
|
{
|
||||||
data_runloop_t *runloop = (data_runloop_t*)data;
|
data_runloop_t *runloop = (data_runloop_t*)data;
|
||||||
database_info_handle_t *db = runloop ? runloop->db.handle : NULL;
|
database_info_handle_t *db = runloop ? runloop->db.handle : NULL;
|
||||||
|
database_state_handle_t *db_state = runloop ? &runloop->db.state : NULL;
|
||||||
const char *name = db ? db->list->elems[db->list_ptr].data : NULL;
|
const char *name = db ? db->list->elems[db->list_ptr].data : NULL;
|
||||||
|
|
||||||
if (!db || !runloop)
|
if (!db || !runloop)
|
||||||
@ -178,16 +174,14 @@ void rarch_main_data_db_iterate(bool is_thread, void *data)
|
|||||||
switch (db->status)
|
switch (db->status)
|
||||||
{
|
{
|
||||||
case DATABASE_STATUS_ITERATE_BEGIN:
|
case DATABASE_STATUS_ITERATE_BEGIN:
|
||||||
if (!runloop->db.list)
|
if (db_state && !db_state->list)
|
||||||
{
|
db_state->list = dir_list_new_special(NULL, DIR_LIST_DATABASES);
|
||||||
runloop->db.list = dir_list_new_special(NULL, DIR_LIST_DATABASES);
|
|
||||||
runloop->db.list_index = 0;
|
|
||||||
runloop->db.entry_index = 0;
|
|
||||||
}
|
|
||||||
db->status = DATABASE_STATUS_ITERATE_START;
|
db->status = DATABASE_STATUS_ITERATE_START;
|
||||||
break;
|
break;
|
||||||
case DATABASE_STATUS_ITERATE_START:
|
case DATABASE_STATUS_ITERATE_START:
|
||||||
rarch_main_data_db_cleanup_state(data);
|
rarch_main_data_db_cleanup_state(data);
|
||||||
|
db_state->list_index = 0;
|
||||||
|
db_state->entry_index = 0;
|
||||||
database_info_iterate_start(db, name);
|
database_info_iterate_start(db, name);
|
||||||
break;
|
break;
|
||||||
case DATABASE_STATUS_ITERATE:
|
case DATABASE_STATUS_ITERATE:
|
||||||
@ -206,9 +200,9 @@ void rarch_main_data_db_iterate(bool is_thread, void *data)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DATABASE_STATUS_FREE:
|
case DATABASE_STATUS_FREE:
|
||||||
if (runloop->db.list)
|
if (db_state->list)
|
||||||
dir_list_free(runloop->db.list);
|
dir_list_free(db_state->list);
|
||||||
runloop->db.list = NULL;
|
db_state->list = NULL;
|
||||||
rarch_main_data_db_cleanup_state(data);
|
rarch_main_data_db_cleanup_state(data);
|
||||||
database_info_free(db);
|
database_info_free(db);
|
||||||
if (runloop->db.handle)
|
if (runloop->db.handle)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user