(GX) initial in-game menu

This commit is contained in:
Toad King 2012-08-07 23:40:17 -04:00
parent a5f8651dcd
commit 54a5845321
4 changed files with 118 additions and 37 deletions

View File

@ -47,6 +47,7 @@ FILE * log_fp;
#endif
uint32_t menu_framebuf[320 * 240];
rgui_handle_t *rgui;
char app_dir[PATH_MAX];
struct retro_system_info wii_core_info;
@ -81,6 +82,8 @@ enum
GX_DEVICE_NAV_LAST
};
extern uint8_t _binary_console_font_bmp_start[];
static bool folder_cb(const char *directory, rgui_file_enum_cb_t file_cb,
void *userdata, void *ctx)
{
@ -128,19 +131,25 @@ static bool folder_cb(const char *directory, rgui_file_enum_cb_t file_cb,
return true;
}
static bool get_rom_path(rgui_handle_t *rgui)
static void menu_loop(void)
{
gx_video_t *gx = (gx_video_t*)driver.video_data;
uint16_t old_input_state = 0;
bool can_quit = false;
uint64_t old_input_state = 0;
bool first = true;
g_console.menu_enable = true;
if(g_console.ingame_menu_enable)
{
//TODO: fill in some stuff here to bring up ingame menu
}
gx->menu_render = true;
for (;;)
do
{
uint16_t input_state = 0;
uint64_t input_state = 0;
input_wii.poll(NULL);
@ -150,19 +159,30 @@ static bool get_rom_path(rgui_handle_t *rgui)
RETRO_DEVICE_JOYPAD, 0, i) ? (1 << i) : 0;
}
uint16_t trigger_state = input_state & ~old_input_state;
static const struct retro_keybind _quit_binds[] = {
{ 0, 0, (enum retro_key)0, (GX_CLASSIC_HOME), 0 },
{ 0, 0, (enum retro_key)0, (GX_WIIMOTE_HOME), 0 },
};
const struct retro_keybind *quit_binds[] = {
_quit_binds
};
input_state |= input_wii.input_state(NULL, quit_binds, false,
RETRO_DEVICE_JOYPAD, 0, 0) ? (GX_CLASSIC_HOME) : 0;
input_state |= input_wii.input_state(NULL, quit_binds, false,
RETRO_DEVICE_JOYPAD, 0, 1) ? (GX_WIIMOTE_HOME) : 0;
uint64_t trigger_state = input_state & ~old_input_state;
rgui_action_t action = RGUI_ACTION_NOOP;
// don't run anything first frame, only capture held inputs for old_input_state
if (!first)
{
if (trigger_state & (1 << GX_DEVICE_NAV_EXIT))
{
if (can_quit)
return false;
}
else
can_quit = true;
g_console.mode_switch = MODE_EXIT;
if (trigger_state & (1 << GX_DEVICE_NAV_B))
action = RGUI_ACTION_CANCEL;
@ -188,24 +208,58 @@ static bool get_rom_path(rgui_handle_t *rgui)
const char *ret = rgui_iterate(rgui, action);
(void)ret;
rarch_render_cached_frame();
if (ret)
old_input_state = input_state;
bool quit_key_pressed = ((trigger_state & GX_WIIMOTE_HOME) || (trigger_state & GX_CLASSIC_HOME)) ? true : false;
if(IS_TIMER_EXPIRED(gx))
{
g_console.initialize_rarch_enable = true;
strlcpy(g_console.rom_path, ret, sizeof(g_console.rom_path));
if (rarch_startup(NULL))
return true;
// if we want to force goto the emulation loop, skip this
if(g_console.mode_switch != MODE_EMULATION)
{
if(quit_key_pressed)
{
g_console.menu_enable = (quit_key_pressed && g_console.emulator_initialized) ? false : true;
g_console.mode_switch = g_console.menu_enable ? MODE_MENU : MODE_EMULATION;
}
}
}
old_input_state = input_state;
rarch_sleep(10);
}
// set a timer delay so that we don't instantly switch back to the menu when
// press and holding QUIT in the emulation loop (lasts for 30 frame ticks)
if(g_console.mode_switch == MODE_EMULATION)
{
SET_TIMER_EXPIRATION(gx, 30);
}
}while(g_console.menu_enable);
gx->menu_render = false;
g_console.ingame_menu_enable = false;
}
static void menu_init(void)
{
rgui = rgui_init("",
menu_framebuf, RGUI_WIDTH * sizeof(uint32_t),
_binary_console_font_bmp_start, folder_cb, NULL);
rgui_iterate(rgui, RGUI_ACTION_REFRESH);
g_console.mode_switch = MODE_MENU;
}
static void menu_free(void)
{
rgui_free(rgui);
}
int rarch_main(int argc, char **argv);
extern uint8_t _binary_console_font_bmp_start[];
static void get_environment_settings(void)
{
@ -269,19 +323,15 @@ int main(void)
input_wii.post_init();
rgui_handle_t *rgui = rgui_init("",
menu_framebuf, RGUI_WIDTH * sizeof(uint32_t),
_binary_console_font_bmp_start, folder_cb, NULL);
rgui_iterate(rgui, RGUI_ACTION_REFRESH);
menu_init();
int ret = 0;
while (get_rom_path(rgui) && ret == 0)
begin_loop:
if(g_console.mode_switch == MODE_EMULATION)
{
gx->menu_render = false;
bool repeat = false;
input_wii.poll(NULL);
audio_start_func();
do{
repeat = rarch_main_iterate();
@ -289,15 +339,25 @@ int main(void)
audio_stop_func();
}
else if(g_console.mode_switch == MODE_MENU)
{
menu_loop();
rarch_startup(default_paths.config_file);
}
else
goto begin_shutdown;
goto begin_loop;
begin_shutdown:
if(path_file_exists(default_paths.config_file))
rarch_config_save(default_paths.config_file);
if(g_console.emulator_initialized)
rarch_main_deinit();
video_wii.stop();
input_wii.free(NULL);
video_wii.stop();
menu_free();
#ifdef HAVE_FILE_LOGGER
fclose(log_fp);
@ -306,11 +366,9 @@ int main(void)
logger_shutdown();
#endif
rgui_free(rgui);
if(g_console.return_to_launcher)
rarch_console_exec(g_console.launch_app_on_exit);
return ret;
return 1;
}

View File

@ -420,10 +420,29 @@ static void wii_input_poll(void *data)
static bool wii_key_pressed(void *data, int key)
{
(void)data;
gx_video_t *gx = driver.video_data;
switch (key)
{
case RARCH_QUIT_KEY:
return pad_state[0] & (GX_CLASSIC_HOME | GX_WIIMOTE_HOME) ? true : false;
if(IS_TIMER_EXPIRED(gx))
{
uint64_t quit_pressed_classic = pad_state[0] & GX_CLASSIC_HOME;
uint64_t quit_pressed_wiimote = pad_state[0] & GX_WIIMOTE_HOME;
bool retval = false;
g_console.menu_enable = ((quit_pressed_classic || quit_pressed_wiimote) && IS_TIMER_EXPIRED(gx));
if(g_console.menu_enable)
{
g_console.mode_switch = MODE_MENU;
SET_TIMER_EXPIRATION(gx, 30);
retval = g_console.menu_enable;
}
retval = g_console.menu_enable;
return retval;
}
default:
return false;
}

View File

@ -1,5 +1,7 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
* Copyright (C) 2011-2012 - Daniel De Matteis
* Copyright (C) 2012 - Michael Lelli
*
* 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-
@ -25,7 +27,6 @@
void *g_framebuf[2];
unsigned g_current_framebuf;
unsigned g_filter;
bool g_vsync;
lwpq_t g_video_cond;
volatile bool g_draw_done;
@ -152,6 +153,8 @@ static void init_vtx(GXRModeObj *mode)
static void init_texture(unsigned width, unsigned height)
{
unsigned g_filter = g_settings.video.smooth ? GX_LINEAR : GX_NEAR;
GX_InitTexObj(&g_tex.obj, g_tex.data, width, height, GX_TF_RGB5A3, GX_CLAMP, GX_CLAMP, GX_FALSE);
GX_InitTexObjLOD(&g_tex.obj, g_filter, g_filter, 0, 0, 0, GX_TRUE, GX_FALSE, GX_ANISO_1);
GX_InitTexObj(&menu_tex.obj, menu_tex.data, 320, 240, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE);
@ -198,7 +201,6 @@ static void *wii_init(const video_info_t *video,
if (!gx)
return NULL;
g_filter = video->smooth ? GX_LINEAR : GX_NEAR;
g_vsync = video->vsync;
return gx;
@ -229,7 +231,6 @@ static void gx_start(void)
init_vtx(mode);
build_disp_list();
g_filter = true;
g_vsync = true;
}
@ -425,6 +426,8 @@ static bool wii_frame(void *data, const void *frame,
if(!frame && !menu_render)
return true;
gx->frame_count++;
while (g_vsync && !g_draw_done)
LWP_ThreadSleep(g_video_cond);

View File

@ -19,6 +19,7 @@
typedef struct gx_video
{
bool menu_render;
uint32_t frame_count;
uint32_t *menu_data;
} gx_video_t;