diff options
author | Michael Pavone <pavone@retrodev.com> | 2017-11-25 20:43:20 -0800 |
---|---|---|
committer | Michael Pavone <pavone@retrodev.com> | 2017-11-25 20:43:20 -0800 |
commit | f4767bb05392fa4a04d72969fa35aa91b688c8cb (patch) | |
tree | 431e023a080a27d2c5602238cdc032bfab974f58 | |
parent | c6edea8bbaceda316375019344f4e7ffbf6da57e (diff) |
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
--HG--
branch : nuklear_ui
-rw-r--r-- | Makefile | 9 | ||||
-rw-r--r-- | blastem.c | 200 | ||||
-rw-r--r-- | blastem.h | 1 | ||||
-rw-r--r-- | io.c | 5 | ||||
-rw-r--r-- | nuklear_ui/blastem_nuklear.c | 22 | ||||
-rw-r--r-- | nuklear_ui/blastem_nuklear.h | 1 | ||||
-rw-r--r-- | render.h | 1 | ||||
-rwxr-xr-x | render_sdl.c | 4 |
8 files changed, 151 insertions, 92 deletions
@@ -86,6 +86,7 @@ LDFLAGS+= -Wl,--no-as-needed -lprofiler -Wl,--as-needed endif ifdef NOGL CFLAGS+= -DDISABLE_OPENGL +NONUKLEAR:=1 endif ifdef M68030 @@ -130,7 +131,13 @@ NUKLEAROBJS=nuklear_ui/font.o nuklear_ui/blastem_nuklear.o 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 @@ -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 @@ void lockon_media(char *lock_on_path) 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 main(int argc, char ** argv) 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 @@ int main(int argc, char ** argv) 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 @@ int main(int argc, char ** argv) 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 @@ int main(int argc, char ** argv) } 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 @@ int main(int argc, char ** argv) 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; @@ -17,5 +17,6 @@ extern char *save_filename; 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_ @@ -381,6 +381,9 @@ void handle_joydown(int joystick, int button) 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 @@ void handle_binding_up(keybinding * binding) } case UI_EXIT: #ifndef DISABLE_NUKLEAR - if (is_nuklear_active) { + if (is_nuklear_active()) { show_pause_menu(); } else { #endif diff --git a/nuklear_ui/blastem_nuklear.c b/nuklear_ui/blastem_nuklear.c index 4785de6..96f8a5d 100644 --- a/nuklear_ui/blastem_nuklear.c +++ b/nuklear_ui/blastem_nuklear.c @@ -62,8 +62,13 @@ void view_load(struct nk_context *context) 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 @@ uint8_t is_nuklear_active(void) 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()); diff --git a/nuklear_ui/blastem_nuklear.h b/nuklear_ui/blastem_nuklear.h index a7cf377..df61ee7 100644 --- a/nuklear_ui/blastem_nuklear.h +++ b/nuklear_ui/blastem_nuklear.h @@ -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_ @@ -105,6 +105,7 @@ uint32_t render_overscan_top(); uint32_t render_overscan_left(); uint32_t render_elapsed_ms(void); void render_sleep_ms(uint32_t delay); +uint8_t render_has_gl(void); #endif //RENDER_H_ diff --git a/render_sdl.c b/render_sdl.c index 4d33f72..583274e 100755 --- a/render_sdl.c +++ b/render_sdl.c @@ -1230,3 +1230,7 @@ void render_sleep_ms(uint32_t delay) return SDL_Delay(delay); } +uint8_t render_has_gl(void) +{ + return render_gl; +} |