Merge pull request #13114 from libretro/move-widgetstate

Better compartmentalize state - better distinction between runloop and retroarch files
This commit is contained in:
Autechre 2021-10-13 18:43:23 +02:00 committed by GitHub
commit 78b861a8e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 588 additions and 560 deletions

118
command.c
View File

@ -46,6 +46,7 @@
#include "audio/audio_driver.h"
#include "command.h"
#include "core_info.h"
#include "cheat_manager.h"
#include "content.h"
#include "dynamic.h"
@ -693,6 +694,123 @@ uint8_t *command_memory_get_pointer(
*max_bytes = 0;
return NULL;
}
bool command_get_status(command_t *cmd, const char* arg)
{
char reply[4096] = {0};
bool contentless = false;
bool is_inited = false;
runloop_state_t *runloop_st = runloop_state_get_ptr();
content_get_status(&contentless, &is_inited);
if (!is_inited)
strcpy_literal(reply, "GET_STATUS CONTENTLESS");
else
{
/* add some content info */
const char *status = "PLAYING";
const char *content_name = path_basename(path_get(RARCH_PATH_BASENAME)); /* filename only without ext */
int content_crc32 = content_get_crc();
const char* system_id = NULL;
core_info_t *core_info = NULL;
core_info_get_current_core(&core_info);
if (runloop_st->paused)
status = "PAUSED";
if (core_info)
system_id = core_info->system_id;
if (!system_id)
system_id = runloop_st->system.info.library_name;
snprintf(reply, sizeof(reply), "GET_STATUS %s %s,%s,crc32=%x\n", status, system_id, content_name, content_crc32);
}
cmd->replier(cmd, reply, strlen(reply));
return true;
}
bool command_read_memory(command_t *cmd, const char *arg)
{
unsigned i;
char* reply = NULL;
char* reply_at = NULL;
const uint8_t* data = NULL;
unsigned int nbytes = 0;
unsigned int alloc_size = 0;
unsigned int address = -1;
size_t len = 0;
unsigned int max_bytes = 0;
runloop_state_t *runloop_st = runloop_state_get_ptr();
const rarch_system_info_t* system = &runloop_st->system;
if (sscanf(arg, "%x %u", &address, &nbytes) != 2)
return false;
/* Ensure large enough to return all requested bytes or an error message */
alloc_size = 64 + nbytes * 3;
reply = (char*)malloc(alloc_size);
reply_at = reply + snprintf(reply, alloc_size - 1, "READ_CORE_MEMORY %x", address);
data = command_memory_get_pointer(system, address, &max_bytes, 0, reply_at, alloc_size - strlen(reply));
if (data)
{
if (nbytes > max_bytes)
nbytes = max_bytes;
for (i = 0; i < nbytes; i++)
snprintf(reply_at + 3 * i, 4, " %02X", data[i]);
reply_at[3 * nbytes] = '\n';
len = reply_at + 3 * nbytes + 1 - reply;
}
else
len = strlen(reply);
cmd->replier(cmd, reply, len);
free(reply);
return true;
}
bool command_write_memory(command_t *cmd, const char *arg)
{
unsigned int address = (unsigned int)strtoul(arg, (char**)&arg, 16);
unsigned int max_bytes = 0;
char reply[128] = "";
runloop_state_t *runloop_st = runloop_state_get_ptr();
const rarch_system_info_t
*system = &runloop_st->system;
char *reply_at = reply + snprintf(reply, sizeof(reply) - 1, "WRITE_CORE_MEMORY %x", address);
uint8_t *data = command_memory_get_pointer(system, address, &max_bytes, 1, reply_at, sizeof(reply) - strlen(reply) - 1);
if (data)
{
uint8_t* start = data;
while (*arg && max_bytes > 0)
{
--max_bytes;
*data = strtoul(arg, (char**)&arg, 16);
data++;
}
snprintf(reply_at, sizeof(reply) - strlen(reply) - 1,
" %u\n", (unsigned)(data - start));
#ifdef HAVE_CHEEVOS
if (rcheevos_hardcore_active())
{
RARCH_LOG("Achievements hardcore mode disabled by WRITE_CORE_MEMORY\n");
rcheevos_pause_hardcore();
}
#endif
}
cmd->replier(cmd, reply, strlen(reply));
return true;
}
#endif
void command_event_set_volume(

View File

@ -408,7 +408,7 @@ static void gfx_widgets_unfold_end(void *userdata)
dispgfx_widget_t *p_dispwidget = &dispwidget_st;
unfold->unfolding = false;
p_dispwidget->widgets_moving = false;
p_dispwidget->moving = false;
}
static void gfx_widgets_move_end(void *userdata)
@ -434,7 +434,7 @@ static void gfx_widgets_move_end(void *userdata)
unfold->unfolding = true;
}
else
p_dispwidget->widgets_moving = false;
p_dispwidget->moving = false;
}
static void gfx_widgets_msg_queue_expired(void *userdata)
@ -481,7 +481,7 @@ static void gfx_widgets_msg_queue_move(dispgfx_widget_t *p_dispwidget)
gfx_animation_push(&entry);
p_dispwidget->widgets_moving = true;
p_dispwidget->moving = true;
}
}
@ -525,7 +525,7 @@ static void gfx_widgets_msg_queue_free(
if (msg->msg_new)
free(msg->msg_new);
p_dispwidget->widgets_moving = false;
p_dispwidget->moving = false;
}
static void gfx_widgets_msg_queue_kill_end(void *userdata)
@ -566,7 +566,7 @@ static void gfx_widgets_msg_queue_kill(
if (!msg)
return;
p_dispwidget->widgets_moving = true;
p_dispwidget->moving = true;
msg->dying = true;
p_dispwidget->msg_queue_kill = idx;
@ -962,7 +962,7 @@ void gfx_widgets_iterate(
/* Consume one message if available */
if ((FIFO_READ_AVAIL_NONPTR(p_dispwidget->msg_queue) > 0)
&& !p_dispwidget->widgets_moving
&& !p_dispwidget->moving
&& (p_dispwidget->current_msgs_size < ARRAY_SIZE(p_dispwidget->current_msgs)))
{
disp_widget_msg_t *msg_widget = NULL;
@ -1032,7 +1032,7 @@ void gfx_widgets_iterate(
if (!msg_widget->expiration_timer_started)
gfx_widgets_start_msg_expiration_timer(msg_widget, TASK_FINISHED_DURATION);
if (msg_widget->expired && !p_dispwidget->widgets_moving)
if (msg_widget->expired && !p_dispwidget->moving)
{
gfx_widgets_msg_queue_kill(p_dispwidget,
(unsigned)i);
@ -1753,7 +1753,7 @@ static void gfx_widgets_free(dispgfx_widget_t *p_dispwidget)
{
size_t i;
p_dispwidget->widgets_inited = false;
p_dispwidget->inited = false;
for (i = 0; i < ARRAY_SIZE(widgets); i++)
{
@ -1996,7 +1996,7 @@ bool gfx_widgets_init(
p_dispwidget->msg_queue_bg[14] = HEX_B(color);
p_dispwidget->msg_queue_bg[15] = 1.0f;
if (!p_dispwidget->widgets_inited)
if (!p_dispwidget->inited)
{
size_t i;
@ -2021,7 +2021,7 @@ bool gfx_widgets_init(
p_dispwidget->current_msgs_lock = slock_new();
#endif
p_dispwidget->widgets_inited = true;
p_dispwidget->inited = true;
}
gfx_widgets_context_reset(
@ -2174,3 +2174,12 @@ dispgfx_widget_t *dispwidget_get_ptr(void)
{
return &dispwidget_st;
}
bool gfx_widgets_ready(void)
{
#ifdef HAVE_GFX_WIDGETS
return dispwidget_st.active;
#else
return false;
#endif
}

View File

@ -225,8 +225,10 @@ typedef struct dispgfx_widget
/* There can only be one message animation at a time to
* avoid confusing users */
bool widgets_moving;
bool widgets_inited;
bool moving;
bool inited;
bool active;
bool persisting;
bool msg_queue_has_icons;
} dispgfx_widget_t;
@ -371,6 +373,8 @@ bool gfx_widget_start_load_content_animation(void);
* enable_menu_widgets to true for that driver */
void gfx_widgets_frame(void *data);
bool gfx_widgets_ready(void);
dispgfx_widget_t *dispwidget_get_ptr(void);
extern const gfx_widget_t gfx_widget_screenshot;

View File

@ -102,6 +102,9 @@
#include "../frontend/frontend_driver.h"
#include "../ui/ui_companion_driver.h"
#include "../gfx/video_display_server.h"
#ifdef HAVE_GFX_WIDGETS
#include "../gfx/gfx_widgets.h"
#endif
#include "../config.features.h"
#include "../version_git.h"
#include "../list_special.h"

View File

@ -6710,3 +6710,156 @@ int menu_input_post_iterate(
return menu_input_pointer_post_iterate(p_disp,
current_time, cbs, &entry, action);
}
void menu_driver_toggle(
void *curr_video_data,
void *video_driver_data,
menu_handle_t *menu,
menu_input_t *menu_input,
settings_t *settings,
bool menu_driver_alive,
bool overlay_alive,
retro_keyboard_event_t *key_event,
retro_keyboard_event_t *frontend_key_event,
bool on)
{
/* TODO/FIXME - retroarch_main_quit calls menu_driver_toggle -
* we might have to redesign this to avoid EXXC_BAD_ACCESS errors
* on OSX - for now we work around this by checking if the settings
* struct is NULL
*/
video_driver_t *current_video = (video_driver_t*)curr_video_data;
bool pause_libretro = false;
#ifdef HAVE_AUDIOMIXER
bool audio_enable_menu = false;
#if 0
bool audio_enable_menu_bgm = false;
#endif
#endif
runloop_state_t *runloop_st = runloop_state_get_ptr();
bool runloop_shutdown_initiated = runloop_st->shutdown_initiated;
#ifdef HAVE_OVERLAY
bool input_overlay_hide_in_menu = false;
bool input_overlay_enable = false;
#endif
bool video_adaptive_vsync = false;
bool video_swap_interval = false;
if (settings)
{
pause_libretro = settings->bools.menu_pause_libretro;
#ifdef HAVE_AUDIOMIXER
audio_enable_menu = settings->bools.audio_enable_menu;
#if 0
audio_enable_menu_bgm = settings->bools.audio_enable_menu_bgm ;
#endif
#endif
#ifdef HAVE_OVERLAY
input_overlay_hide_in_menu = settings->bools.input_overlay_hide_in_menu;
input_overlay_enable = settings->bools.input_overlay_enable;
#endif
video_adaptive_vsync = settings->bools.video_adaptive_vsync;
video_swap_interval = settings->uints.video_swap_interval;
}
if (on)
{
#ifdef HAVE_LAKKA
set_cpu_scaling_signal(CPUSCALING_EVENT_FOCUS_MENU);
#endif
#ifdef HAVE_OVERLAY
/* If an overlay was displayed before the toggle
* and overlays are disabled in menu, need to
* inhibit 'select' input */
if (input_overlay_hide_in_menu)
{
if (input_overlay_enable && overlay_alive)
{
/* Inhibits pointer 'select' and 'cancel' actions
* (until the next time 'select'/'cancel' are released) */
menu_input->select_inhibit= true;
menu_input->cancel_inhibit= true;
}
}
#endif
}
else
{
#ifdef HAVE_LAKKA
set_cpu_scaling_signal(CPUSCALING_EVENT_FOCUS_CORE);
#endif
#ifdef HAVE_OVERLAY
/* Inhibits pointer 'select' and 'cancel' actions
* (until the next time 'select'/'cancel' are released) */
menu_input->select_inhibit = false;
menu_input->cancel_inhibit = false;
#endif
}
if (menu_driver_alive)
{
bool refresh = false;
#ifdef WIIU
/* Enable burn-in protection menu is running */
IMEnableDim();
#endif
menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh);
/* Menu should always run with vsync on. */
if (current_video->set_nonblock_state)
current_video->set_nonblock_state(
video_driver_data,
false,
video_driver_test_all_flags(GFX_CTX_FLAGS_ADAPTIVE_VSYNC) &&
video_adaptive_vsync,
video_swap_interval
);
/* Stop all rumbling before entering the menu. */
command_event(CMD_EVENT_RUMBLE_STOP, NULL);
if (pause_libretro && !audio_enable_menu)
command_event(CMD_EVENT_AUDIO_STOP, NULL);
#if 0
if (audio_enable_menu && audio_enable_menu_bgm)
audio_driver_mixer_play_menu_sound_looped(AUDIO_MIXER_SYSTEM_SLOT_BGM);
#endif
/* Override keyboard callback to redirect to menu instead.
* We'll use this later for something ... */
if (key_event && frontend_key_event)
{
*frontend_key_event = *key_event;
*key_event = menu_input_key_event;
runloop_st->frame_time_last= 0;
}
}
else
{
#ifdef WIIU
/* Disable burn-in protection while core is running; this is needed
* because HID inputs don't count for the purpose of Wii U
* power-saving. */
IMDisableDim();
#endif
if (!runloop_shutdown_initiated)
driver_set_nonblock_state();
if (pause_libretro && !audio_enable_menu)
command_event(CMD_EVENT_AUDIO_START, NULL);
#if 0
if (audio_enable_menu && audio_enable_menu_bgm)
audio_driver_mixer_stop_stream(AUDIO_MIXER_SYSTEM_SLOT_BGM);
#endif
/* Restore libretro keyboard callback. */
if (key_event && frontend_key_event)
*key_event = *frontend_key_event;
}
}

View File

@ -897,6 +897,21 @@ int menu_input_post_iterate(
unsigned action,
retro_time_t current_time);
/* Gets called when we want to toggle the menu.
* If the menu is already running, it will be turned off.
* If the menu is off, then the menu will be started.
*/
void menu_driver_toggle(
void *curr_video_data,
void *video_driver_data,
menu_handle_t *menu,
menu_input_t *menu_input,
settings_t *settings,
bool menu_driver_alive,
bool overlay_alive,
retro_keyboard_event_t *key_event,
retro_keyboard_event_t *frontend_key_event,
bool on);
extern const menu_ctx_driver_t *menu_ctx_drivers[];

File diff suppressed because it is too large Load Diff

View File

@ -230,8 +230,6 @@ extern camera_driver_t camera_avfoundation;
**/
const char* config_get_camera_driver_options(void);
bool gfx_widgets_ready(void);
unsigned int retroarch_get_rotation(void);
void retroarch_init_task_queue(void);

View File

@ -549,8 +549,6 @@ typedef struct discord_state discord_state_t;
struct rarch_state
{
retro_time_t frame_limit_minimum_time;
retro_time_t frame_limit_last_time;
retro_time_t libretro_core_runtime_last;
retro_time_t libretro_core_runtime_usec;
struct global g_extern; /* retro_time_t alignment */
@ -736,10 +734,6 @@ struct rarch_state
char current_savestate_dir[PATH_MAX_LENGTH];
char dir_savestate[PATH_MAX_LENGTH];
#ifdef HAVE_GFX_WIDGETS
bool widgets_active;
bool widgets_persisting;
#endif
#ifdef HAVE_NETWORKING
/* Only used before init_netplay */
bool netplay_enabled;

View File

@ -36,9 +36,6 @@ static void deinit_netplay(struct rarch_state *p_rarch);
static void retroarch_deinit_drivers(struct rarch_state *p_rarch,
struct retro_callbacks *cbs);
static core_option_manager_t *retroarch_init_core_variables(
settings_t *settings,
const struct retro_variable *vars);
#ifdef HAVE_RUNAHEAD
#if defined(HAVE_DYNAMIC) || defined(HAVE_DYLIB)
static bool secondary_core_create(struct rarch_state *p_rarch,

View File

@ -86,6 +86,8 @@ typedef struct core_options_callbacks
struct runloop
{
retro_time_t frame_limit_minimum_time;
retro_time_t frame_limit_last_time;
retro_usec_t frame_time_last; /* int64_t alignment */
msg_queue_t msg_queue; /* ptr alignment */
@ -140,14 +142,6 @@ struct runloop
typedef struct runloop runloop_state_t;
#ifdef HAVE_THREADS
#define RUNLOOP_MSG_QUEUE_LOCK(runloop) slock_lock(runloop.msg_queue_lock)
#define RUNLOOP_MSG_QUEUE_UNLOCK(runloop) slock_unlock(runloop.msg_queue_lock)
#else
#define RUNLOOP_MSG_QUEUE_LOCK(p_runloop)
#define RUNLOOP_MSG_QUEUE_UNLOCK(p_runloop)
#endif
/* Time to exit out of the main loop?
* Reasons for exiting:
* a) Shutdown environment callback was invoked.