Mercurial > repos > blastem
changeset 1483:001120e91fed nuklear_ui
Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 25 Nov 2017 20:43:20 -0800 |
parents | 2d203bf73dbd |
children | d82af64c94d2 |
files | Makefile blastem.c blastem.h io.c nuklear_ui/blastem_nuklear.c nuklear_ui/blastem_nuklear.h render.h render_sdl.c |
diffstat | 8 files changed, 151 insertions(+), 92 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile Sat Nov 25 14:42:38 2017 -0800 +++ b/Makefile Sat Nov 25 20:43:20 2017 -0800 @@ -86,6 +86,7 @@ endif ifdef NOGL CFLAGS+= -DDISABLE_OPENGL +NONUKLEAR:=1 endif ifdef M68030 @@ -130,7 +131,13 @@ MAINOBJS=blastem.o system.o genesis.o debug.o gdb_remote.o vdp.o render_sdl.o ppm.o io.o romdb.o hash.o menu.o xband.o \ realtec.o i2c.o nor.o sega_mapper.o multi_game.o serialize.o $(TERMINAL) $(CONFIGOBJS) gst.o $(M68KOBJS) \ - $(TRANSOBJS) $(AUDIOOBJS) $(NUKLEAROBJS) paths.o saves.o + $(TRANSOBJS) $(AUDIOOBJS) paths.o saves.o + +ifdef NONUKLEAR +CFLAGS+= -DDISABLE_NUKLEAR +else +MAINOBJS+= $(NUKLEAROBJS) +endif ifeq ($(CPU),x86_64) CFLAGS+=-DX86_64 -m64
--- a/blastem.c Sat Nov 25 14:42:38 2017 -0800 +++ b/blastem.c Sat Nov 25 20:43:20 2017 -0800 @@ -24,7 +24,9 @@ #include "arena.h" #include "config.h" #include "menu.h" +#ifndef DISABLE_NUKLEAR #include "nuklear_ui/blastem_nuklear.h" +#endif #define BLASTEM_VERSION "0.5.2-pre" @@ -235,6 +237,55 @@ lock_on.size = load_rom(lock_on_path, &lock_on.buffer, NULL); } +static uint32_t opts = 0; +static uint8_t force_region = 0; +void init_system_with_media(char *path, system_type force_stype) +{ + if (game_system) { + game_system->persist_save(game_system); + //swap to game context arena and mark all allocated pages in it free + if (current_system == menu_system) { + current_system->arena = set_current_arena(game_system->arena); + } + mark_all_free(); + game_system->free_context(game_system); + } else if(current_system) { + //start a new arena and save old one in suspended system context + current_system->arena = start_new_arena(); + } + system_type stype = SYSTEM_UNKNOWN; + if (!(cart.size = load_rom(path, &cart.buffer, &stype))) { + fatal_error("Failed to open %s for reading\n", path); + } + free(cart.dir); + free(cart.name); + free(cart.extension); + cart.dir = path_dirname(path); + cart.name = basename_no_extension(path); + cart.extension = path_extension(path); + if (force_stype != SYSTEM_UNKNOWN) { + stype = force_stype; + } + if (stype == SYSTEM_UNKNOWN) { + stype = detect_system_type(&cart); + } + if (stype == SYSTEM_UNKNOWN) { + fatal_error("Failed to detect system type for %s\n", path); + } + rom_info info; + //allocate new system context + game_system = alloc_config_system(stype, &cart, opts, force_region, &info); + if (!game_system) { + fatal_error("Failed to configure emulated machine for %s\n", path); + } + if (menu_system) { + menu_system->next_context = game_system; + } + game_system->next_context = menu_system; + setup_saves(&cart, &info, game_system); + update_title(info.name); +} + int main(int argc, char ** argv) { set_exe_str(argv[0]); @@ -242,10 +293,8 @@ int width = -1; int height = -1; int debug = 0; - uint32_t opts = 0; int loaded = 0; system_type stype = SYSTEM_UNKNOWN, force_stype = SYSTEM_UNKNOWN; - uint8_t force_region = 0; char * romfname = NULL; char * statefile = NULL; debugger_type dtype = DEBUGGER_NATIVE; @@ -382,35 +431,6 @@ height = atoi(argv[i]); } } - uint8_t menu = !loaded; - if (!loaded) { - //load menu - romfname = tern_find_path(config, "ui\0rom\0", TVAL_PTR).ptrval; - if (!romfname) { - romfname = "menu.bin"; - } - if (is_absolute_path(romfname)) { - if (!(cart.size = load_rom(romfname, &cart.buffer, &stype))) { - fatal_error("Failed to open UI ROM %s for reading", romfname); - } - } else { - cart.buffer = (uint16_t *)read_bundled_file(romfname, &cart.size); - if (!cart.buffer) { - fatal_error("Failed to open UI ROM %s for reading", romfname); - } - uint32_t rom_size = nearest_pow2(cart.size); - if (rom_size > cart.size) { - cart.buffer = realloc(cart.buffer, rom_size); - cart.size = rom_size; - } - } - //force system detection, value on command line is only for games not the menu - stype = detect_system_type(&cart); - cart.dir = path_dirname(romfname); - cart.name = basename_no_extension(romfname); - cart.extension = path_extension(romfname); - loaded = 1; - } int def_width = 0, def_height = 0; char *config_width = tern_find_path(config, "video\0width\0", TVAL_PTR).ptrval; @@ -438,17 +458,39 @@ render_init(width, height, "BlastEm", fullscreen); render_set_drag_drop_handler(on_drag_drop); } - - if (stype == SYSTEM_UNKNOWN) { + + uint8_t menu = !loaded; + uint8_t use_nuklear = 0; +#ifndef DISABLE_NUKLEAR + use_nuklear = is_nuklear_available(); +#endif + if (!loaded && !use_nuklear) { + //load menu + romfname = tern_find_path(config, "ui\0rom\0", TVAL_PTR).ptrval; + if (!romfname) { + romfname = "menu.bin"; + } + if (is_absolute_path(romfname)) { + if (!(cart.size = load_rom(romfname, &cart.buffer, &stype))) { + fatal_error("Failed to open UI ROM %s for reading", romfname); + } + } else { + cart.buffer = (uint16_t *)read_bundled_file(romfname, &cart.size); + if (!cart.buffer) { + fatal_error("Failed to open UI ROM %s for reading", romfname); + } + uint32_t rom_size = nearest_pow2(cart.size); + if (rom_size > cart.size) { + cart.buffer = realloc(cart.buffer, rom_size); + cart.size = rom_size; + } + } + //force system detection, value on command line is only for games not the menu stype = detect_system_type(&cart); - } - if (stype == SYSTEM_UNKNOWN) { - fatal_error("Failed to detect system type for %s\n", romfname); - } - rom_info info; - current_system = alloc_config_system(stype, &cart, menu ? 0 : opts, force_region, &info); - if (!current_system) { - fatal_error("Failed to configure emulated machine for %s\n", romfname); + cart.dir = path_dirname(romfname); + cart.name = basename_no_extension(romfname); + cart.extension = path_extension(romfname); + loaded = 1; } char *state_format = tern_find_path(config, "ui\0state_format\0", TVAL_PTR).ptrval; if (state_format && !strcmp(state_format, "gst")) { @@ -456,16 +498,36 @@ } else if (state_format && strcmp(state_format, "native")) { warning("%s is not a valid value for the ui.state_format setting. Valid values are gst and native\n", state_format); } - setup_saves(&cart, &info, current_system); - update_title(info.name); - if (menu) { - menu_system = current_system; - } else { - game_system = current_system; + + if (loaded) { + if (stype == SYSTEM_UNKNOWN) { + stype = detect_system_type(&cart); + } + if (stype == SYSTEM_UNKNOWN) { + fatal_error("Failed to detect system type for %s\n", romfname); + } + rom_info info; + current_system = alloc_config_system(stype, &cart, menu ? 0 : opts, force_region, &info); + if (!current_system) { + fatal_error("Failed to configure emulated machine for %s\n", romfname); + } + + setup_saves(&cart, &info, current_system); + update_title(info.name); + if (menu) { + menu_system = current_system; + } else { + game_system = current_system; + } } - blastem_nuklear_init(game_system == current_system); - +#ifndef DISABLE_NUKLEAR + if (use_nuklear) { + blastem_nuklear_init(!menu); + current_system = game_system; + } +#endif + current_system->debugger_type = dtype; current_system->enter_debugger = start_in_debugger && menu == debug_target; current_system->start_context(current_system, menu ? NULL : statefile); @@ -477,45 +539,7 @@ if (current_system->next_rom) { char *next_rom = current_system->next_rom; current_system->next_rom = NULL; - if (game_system) { - game_system->persist_save(game_system); - //swap to game context arena and mark all allocated pages in it free - if (menu) { - current_system->arena = set_current_arena(game_system->arena); - } - mark_all_free(); - game_system->free_context(game_system); - } else { - //start a new arena and save old one in suspended genesis context - current_system->arena = start_new_arena(); - } - if (!(cart.size = load_rom(next_rom, &cart.buffer, &stype))) { - fatal_error("Failed to open %s for reading\n", next_rom); - } - free(cart.dir); - free(cart.name); - free(cart.extension); - cart.dir = path_dirname(next_rom); - cart.name = basename_no_extension(next_rom); - cart.extension = path_extension(next_rom); - stype = force_stype; - if (stype == SYSTEM_UNKNOWN) { - stype = detect_system_type(&cart); - } - if (stype == SYSTEM_UNKNOWN) { - fatal_error("Failed to detect system type for %s\n", next_rom); - } - //allocate new system context - game_system = alloc_config_system(stype, &cart, opts,force_region, &info); - if (!game_system) { - fatal_error("Failed to configure emulated machine for %s\n", next_rom); - } - if (menu_system) { - menu_system->next_context = game_system; - } - game_system->next_context = menu_system; - setup_saves(&cart, &info, game_system); - update_title(info.name); + init_system_with_media(next_rom, force_stype); free(next_rom); menu = 0; current_system = game_system;
--- a/blastem.h Sat Nov 25 14:42:38 2017 -0800 +++ b/blastem.h Sat Nov 25 20:43:20 2017 -0800 @@ -17,5 +17,6 @@ extern uint8_t use_native_states; void reload_media(void); void lockon_media(char *lock_on_path); +void init_system_with_media(char *path, system_type force_stype); #endif //BLASTEM_H_
--- a/io.c Sat Nov 25 14:42:38 2017 -0800 +++ b/io.c Sat Nov 25 20:43:20 2017 -0800 @@ -381,6 +381,9 @@ void handle_mousedown(int mouse, int button) { + if (!current_io) { + return; + } if (current_io->mouse_mode == MOUSE_CAPTURE && !current_io->mouse_captured) { current_io->mouse_captured = 1; render_relative_mouse(1); @@ -537,7 +540,7 @@ } case UI_EXIT: #ifndef DISABLE_NUKLEAR - if (is_nuklear_active) { + if (is_nuklear_active()) { show_pause_menu(); } else { #endif
--- a/nuklear_ui/blastem_nuklear.c Sat Nov 25 14:42:38 2017 -0800 +++ b/nuklear_ui/blastem_nuklear.c Sat Nov 25 20:43:20 2017 -0800 @@ -62,8 +62,13 @@ free_dir_list(entries, num_entries); entries = NULL; } else { - current_system->next_rom = full_path; - current_system->request_exit(current_system); + if (current_system) { + current_system->next_rom = full_path; + current_system->request_exit(current_system); + } else { + init_system_with_media(full_path, SYSTEM_UNKNOWN); + free(full_path); + } current_view = view_play; } } @@ -254,6 +259,19 @@ return active; } +uint8_t is_nuklear_available(void) +{ + if (!render_has_gl()) { + //currently no fallback if GL2 unavailable + return 0; + } + char *style = tern_find_path(config, "ui\0style\0", TVAL_PTR).ptrval; + if (!style) { + return 1; + } + return strcmp(style, "rom") != 0; +} + void blastem_nuklear_init(uint8_t file_loaded) { context = nk_sdl_init(render_get_window());
--- a/nuklear_ui/blastem_nuklear.h Sat Nov 25 14:42:38 2017 -0800 +++ b/nuklear_ui/blastem_nuklear.h Sat Nov 25 20:43:20 2017 -0800 @@ -14,5 +14,6 @@ void blastem_nuklear_init(uint8_t file_loaded); void show_pause_menu(void); uint8_t is_nuklear_active(void); +uint8_t is_nuklear_available(void); #endif //BLASTEM_NUKLEAR_H_