Split up runahead into its own file(s) - runahead.c/runahead.h -

by Dwedit's request
This commit is contained in:
libretroadmin 2023-01-11 10:19:56 +01:00
parent ee6aa753c3
commit f0c8008bda
9 changed files with 1852 additions and 1770 deletions

View file

@ -430,6 +430,7 @@ endif
ifeq ($(HAVE_RUNAHEAD), 1)
DEFINES += -DHAVE_RUNAHEAD
OBJ += runahead.o
endif
ifeq ($(HAVE_CC_RESAMPLER), 1)

View file

@ -1236,6 +1236,9 @@ RETROARCH
============================================================ */
#include "../retroarch.c"
#include "../runloop.c"
#ifdef HAVE_RUNAHEAD
#include "../runahead.c"
#endif
#include "../command.c"
#include "../midi_driver.c"
#include "../location_driver.c"

View file

@ -8710,7 +8710,7 @@ static void runahead_change_handler(rarch_setting_t *setting)
{
/* Disable preemptive frames and inform user */
settings->bools.preemptive_frames_enable = false;
runloop_preempt_deinit();
preempt_deinit(runloop_state_get_ptr());
runloop_msg_queue_push(
msg_hash_to_str(MSG_PREEMPT_DISABLED), 1, 100, false,
NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);

View file

@ -8438,7 +8438,7 @@ void deinit_netplay(void)
#if HAVE_RUNAHEAD
/* Reinitialize preemptive frames if enabled */
runloop_preempt_init();
preempt_init(runloop_state_get_ptr());
#endif
}

View file

@ -2272,7 +2272,7 @@ bool command_event(enum event_command cmd, void *data)
/* Disable preemptive frames */
settings->bools.preemptive_frames_enable = false;
runloop_preempt_deinit();
preempt_deinit(runloop_st);
}
}
#endif
@ -2318,8 +2318,8 @@ bool command_event(enum event_command cmd, void *data)
break;
case CMD_EVENT_PREEMPT_UPDATE:
#if HAVE_RUNAHEAD
runloop_preempt_deinit();
runloop_preempt_init();
preempt_deinit(runloop_st);
preempt_init(runloop_st);
#endif
break;
case CMD_EVENT_PREEMPT_RESET_BUFFER:
@ -2411,9 +2411,9 @@ bool command_event(enum event_command cmd, void *data)
if (!runloop_st->secondary_lib_handle)
{
if (!secondary_core_ensure_exists(settings))
if (!secondary_core_ensure_exists(runloop_st, settings))
{
runloop_secondary_core_destroy();
runahead_secondary_core_destroy(runloop_st);
runloop_st->flags &=
~RUNLOOP_FLAG_RUNAHEAD_SECONDARY_CORE_AVAILABLE;
return false;
@ -3042,10 +3042,10 @@ bool command_event(enum event_command cmd, void *data)
* remain disabled until the user restarts
* RetroArch */
if (!(runloop_st->flags & RUNLOOP_FLAG_RUNAHEAD_AVAILABLE))
runloop_runahead_clear_variables(runloop_st);
runahead_clear_variables(runloop_st);
/* Deallocate preemptive frames */
runloop_preempt_deinit();
preempt_deinit(runloop_st);
#endif
if (hwr)
@ -3583,7 +3583,7 @@ bool command_event(enum event_command cmd, void *data)
}
#if HAVE_RUNAHEAD
/* Deinit preemptive frames; not compatible with netplay */
runloop_preempt_deinit();
preempt_deinit(runloop_st);
#endif
}
break;
@ -6248,7 +6248,7 @@ bool retroarch_main_init(int argc, char *argv[])
#ifdef HAVE_NETWORKING
if (!netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL))
#endif
runloop_preempt_init();
preempt_init(runloop_st);
#endif
return true;

1705
runahead.c Normal file

File diff suppressed because it is too large Load diff

96
runahead.h Normal file
View file

@ -0,0 +1,96 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2023 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __RUNAHEAD_H
#define __RUNAHEAD_H
#include <stdint.h>
#include <boolean.h>
#include <retro_common_api.h>
#include "core.h"
#define MAX_RUNAHEAD_FRAMES 12
typedef void *(*constructor_t)(void);
typedef void (*destructor_t )(void*);
typedef struct my_list_t
{
void **data;
constructor_t constructor;
destructor_t destructor;
int capacity;
int size;
} my_list;
typedef struct preemptive_frames_data
{
/* Savestate buffer */
void* buffer[MAX_RUNAHEAD_FRAMES];
size_t state_size;
/* Frame count since buffer init/reset */
uint64_t frame_count;
/* Mask of analog states requested */
uint32_t analog_mask[MAX_USERS];
/* Input states. Replays triggered on changes */
int16_t joypad_state[MAX_USERS];
int16_t analog_state[MAX_USERS][20];
int16_t ptrdev_state[MAX_USERS][4];
/* Pointing device requested */
uint8_t ptr_dev[MAX_USERS];
/* Buffer indexes for replays */
uint8_t start_ptr;
uint8_t replay_ptr;
/* Number of latency frames to remove */
uint8_t frames;
} preempt_t;
RETRO_BEGIN_DECLS
typedef bool(*runahead_load_state_function)(const void*, size_t);
void runahead_run(
void *data,
int runahead_count,
bool runahead_hide_warnings,
bool use_secondary);
void runahead_clear_variables(void *data);
void runahead_remember_controller_port_device(void *data,
long port, long device);
void runahead_clear_controller_port_map(void *data);
void runahead_set_load_content_info(
void *data,
const retro_ctx_load_content_info_t *ctx);
void runahead_secondary_core_destroy(void *data);
bool preempt_init(void *data);
void preempt_deinit(void *data);
void preempt_run(preempt_t *preempt, void *data);
RETRO_END_DECLS
#endif

1719
runloop.c

File diff suppressed because it is too large Load diff

View file

@ -41,6 +41,9 @@
#include "core_option_manager.h"
#include "performance_counters.h"
#include "state_manager.h"
#ifdef HAVE_RUNAHEAD
#include "runahead.h"
#endif
#include "tasks/tasks_internal.h"
/* Arbitrary twenty subsystems limit */
@ -158,51 +161,6 @@ typedef struct core_options_callbacks
retro_core_options_update_display_callback_t update_display;
} core_options_callbacks_t;
#ifdef HAVE_RUNAHEAD
#define MAX_RUNAHEAD_FRAMES 12
typedef bool(*runahead_load_state_function)(const void*, size_t);
typedef void *(*constructor_t)(void);
typedef void (*destructor_t )(void*);
typedef struct my_list_t
{
void **data;
constructor_t constructor;
destructor_t destructor;
int capacity;
int size;
} my_list;
typedef struct preemptive_frames_data
{
/* Savestate buffer */
void* buffer[MAX_RUNAHEAD_FRAMES];
size_t state_size;
/* Number of latency frames to remove */
uint8_t frames;
/* Buffer indexes for replays */
uint8_t start_ptr;
uint8_t replay_ptr;
/* Frame count since buffer init/reset */
uint64_t frame_count;
/* Input states. Replays triggered on changes */
int16_t joypad_state[MAX_USERS];
int16_t analog_state[MAX_USERS][20];
int16_t ptrdev_state[MAX_USERS][4];
/* Pointing device requested */
uint8_t ptr_dev[MAX_USERS];
/* Mask of analog states requested */
uint32_t analog_mask[MAX_USERS];
} preempt_t;
#endif
struct runloop
{
#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL)
@ -413,13 +371,6 @@ void runloop_runtime_log_deinit(
void runloop_event_deinit_core(void);
#ifdef HAVE_RUNAHEAD
void runloop_runahead_clear_variables(runloop_state_t *runloop_st);
bool runloop_preempt_init(void);
void runloop_preempt_deinit(void);
#endif
bool runloop_event_init_core(
settings_t *settings,
void *input_data,
@ -453,13 +404,11 @@ void runloop_task_msg_queue_push(
unsigned prio, unsigned duration,
bool flush);
bool secondary_core_ensure_exists(settings_t *settings);
bool secondary_core_ensure_exists(void *data, settings_t *settings);
void runloop_log_counters(
struct retro_perf_counter **counters, unsigned num);
void runloop_secondary_core_destroy(void);
void runloop_msg_queue_deinit(void);
void runloop_msg_queue_init(void);
@ -482,6 +431,23 @@ void runloop_path_set_special(char **argv, unsigned num_content);
void runloop_path_deinit_subsystem(void);
/**
* init_libretro_symbols:
* @type : Type of core to be loaded.
* If CORE_TYPE_DUMMY, will
* load dummy symbols.
*
* Setup libretro callback symbols.
*
* @return true on success, or false if symbols could not be loaded.
**/
bool runloop_init_libretro_symbols(
void *data,
enum rarch_core_type type,
struct retro_core_t *current_core,
const char *lib_path,
void *_lib_handle_p);
runloop_state_t *runloop_state_get_ptr(void);
RETRO_END_DECLS