diff options
author | npwoods <npwoods@alumni.carnegiemellon.edu> | 2017-05-05 02:17:49 -0400 |
---|---|---|
committer | Vas Crabb <cuavas@users.noreply.github.com> | 2017-05-05 16:17:49 +1000 |
commit | 536990e77b49ccc50ef275bfbf1018cc29c16154 (patch) | |
tree | 86e160cca07995479cd87506732c178b3728e58a /src/frontend/mame/ui | |
parent | cce3369cdeec54494c6d4dc4a781cbba64d027bd (diff) |
Overhaul to how MAME handles options (#2260)
This is an overhaul to how MAME handles options to provide a better foundation for what MAME is already doing in practice. Previously, core_options was designed to provide an input/output facility for reading options from the command line and INI files. However, the current needs (image/slot/get_default_card_software calculus and MewUI) go way beyond that.
Broadly, this PR makes the following changes:
* core_options now has an extensibility mechanism, so one can register options that behave dramatically differently
* With that foundation, emu_options now encapsulates all of the funky image/slot/get_default_card_software calculus that were previously handled by static methods in mameopts.cpp. Changes to emu_options should not automatically cascade in such a way so that it stays in a consistent state
* emu_options no longer provides direct access to the slot_options/image_options maps; there are simpler API functions that control these capabilities
* Many core_options functions that expose internal data structures (e.g. - priority) that were only really needed because of previous (now obsolete) techniques have been removed.
* core_options is now exception based (rather than dumping text to an std::string). The burden is on the caller to catch these, and discern between warnings and errors as needed.
Obviously this is a risky change; that's why this is being submitted at the start of the dev cycle.
Diffstat (limited to 'src/frontend/mame/ui')
-rw-r--r-- | src/frontend/mame/ui/custui.cpp | 38 | ||||
-rw-r--r-- | src/frontend/mame/ui/dirmenu.cpp | 15 | ||||
-rw-r--r-- | src/frontend/mame/ui/info.cpp | 3 | ||||
-rw-r--r-- | src/frontend/mame/ui/miscmenu.cpp | 28 | ||||
-rw-r--r-- | src/frontend/mame/ui/selgame.cpp | 14 | ||||
-rw-r--r-- | src/frontend/mame/ui/selsoft.cpp | 26 | ||||
-rw-r--r-- | src/frontend/mame/ui/slotopt.cpp | 9 | ||||
-rw-r--r-- | src/frontend/mame/ui/sndmenu.cpp | 10 | ||||
-rw-r--r-- | src/frontend/mame/ui/submenu.cpp | 26 | ||||
-rw-r--r-- | src/frontend/mame/ui/submenu.h | 2 | ||||
-rw-r--r-- | src/frontend/mame/ui/ui.cpp | 35 |
11 files changed, 88 insertions, 118 deletions
diff --git a/src/frontend/mame/ui/custui.cpp b/src/frontend/mame/ui/custui.cpp index 17a5c22539b..438840f0fc0 100644 --- a/src/frontend/mame/ui/custui.cpp +++ b/src/frontend/mame/ui/custui.cpp @@ -64,12 +64,10 @@ menu_custom_ui::menu_custom_ui(mame_ui_manager &mui, render_container &container menu_custom_ui::~menu_custom_ui() { - std::string error_string; - ui().options().set_value(OPTION_HIDE_PANELS, ui_globals::panels_status, OPTION_PRIORITY_CMDLINE, error_string); + ui().options().set_value(OPTION_HIDE_PANELS, ui_globals::panels_status, OPTION_PRIORITY_CMDLINE); if (!m_lang.empty()) { - machine().options().set_value(OPTION_LANGUAGE, m_lang[m_currlang].c_str(), OPTION_PRIORITY_CMDLINE, error_string); - machine().options().mark_changed(OPTION_LANGUAGE); + machine().options().set_value(OPTION_LANGUAGE, m_lang[m_currlang].c_str(), OPTION_PRIORITY_CMDLINE); load_translation(machine().options()); } ui_globals::reset = true; @@ -215,22 +213,10 @@ menu_font_ui::menu_font_ui(mame_ui_manager &mui, render_container &container) : m_info_size = moptions.infos_size(); m_font_size = moptions.font_rows(); - - for (ui_options::entry &f_entry : moptions) - { - const char *entry_name = f_entry.name(); - if (entry_name && strlen(entry_name) && !strcmp(OPTION_INFOS_SIZE, f_entry.name())) - { - m_info_max = atof(f_entry.maximum()); - m_info_min = atof(f_entry.minimum()); - } - else if (entry_name && strlen(entry_name) && !strcmp(OPTION_FONT_ROWS, f_entry.name())) - { - m_font_max = atof(f_entry.maximum()); - m_font_min = atof(f_entry.minimum()); - } - } - + m_info_max = atof(moptions.get_entry(OPTION_INFOS_SIZE)->maximum()); + m_info_min = atof(moptions.get_entry(OPTION_INFOS_SIZE)->minimum()); + m_font_max = atof(moptions.get_entry(OPTION_FONT_ROWS)->maximum()); + m_font_max = atof(moptions.get_entry(OPTION_FONT_ROWS)->minimum()); } //------------------------------------------------- @@ -264,11 +250,9 @@ menu_font_ui::~menu_font_ui() name.insert(0, "[B]"); } #endif - machine().options().set_value(OPTION_UI_FONT, name.c_str(), OPTION_PRIORITY_CMDLINE, error_string); - machine().options().mark_changed(OPTION_UI_FONT); - - moptions.set_value(OPTION_INFOS_SIZE, m_info_size, OPTION_PRIORITY_CMDLINE, error_string); - moptions.set_value(OPTION_FONT_ROWS, m_font_size, OPTION_PRIORITY_CMDLINE, error_string); + machine().options().set_value(OPTION_UI_FONT, name, OPTION_PRIORITY_CMDLINE); + moptions.set_value(OPTION_INFOS_SIZE, m_info_size, OPTION_PRIORITY_CMDLINE); + moptions.set_value(OPTION_FONT_ROWS, m_font_size, OPTION_PRIORITY_CMDLINE); } //------------------------------------------------- @@ -463,11 +447,11 @@ menu_colors_ui::menu_colors_ui(mame_ui_manager &mui, render_container &container menu_colors_ui::~menu_colors_ui() { - std::string error_string, dec_color; + std::string dec_color; for (int index = 1; index < MUI_RESTORE; index++) { dec_color = string_format("%x", (uint32_t)m_color_table[index].color); - ui().options().set_value(m_color_table[index].option, dec_color.c_str(), OPTION_PRIORITY_CMDLINE, error_string); + ui().options().set_value(m_color_table[index].option, dec_color.c_str(), OPTION_PRIORITY_CMDLINE); } } diff --git a/src/frontend/mame/ui/dirmenu.cpp b/src/frontend/mame/ui/dirmenu.cpp index 1ef39925bfd..2d0200ef099 100644 --- a/src/frontend/mame/ui/dirmenu.cpp +++ b/src/frontend/mame/ui/dirmenu.cpp @@ -352,11 +352,10 @@ void menu_add_change_folder::handle() if (m_change) { if (ui().options().exists(s_folders[m_ref].option)) - ui().options().set_value(s_folders[m_ref].option, m_current_path.c_str(), OPTION_PRIORITY_CMDLINE, error_string); + ui().options().set_value(s_folders[m_ref].option, m_current_path.c_str(), OPTION_PRIORITY_CMDLINE); else if (strcmp(machine().options().value(s_folders[m_ref].option), m_current_path.c_str()) != 0) { - machine().options().set_value(s_folders[m_ref].option, m_current_path.c_str(), OPTION_PRIORITY_CMDLINE, error_string); - machine().options().mark_changed(s_folders[m_ref].option); + machine().options().set_value(s_folders[m_ref].option, m_current_path.c_str(), OPTION_PRIORITY_CMDLINE); } } else @@ -371,11 +370,10 @@ void menu_add_change_folder::handle() } if (ui().options().exists(s_folders[m_ref].option)) - ui().options().set_value(s_folders[m_ref].option, tmppath.c_str(), OPTION_PRIORITY_CMDLINE, error_string); + ui().options().set_value(s_folders[m_ref].option, tmppath.c_str(), OPTION_PRIORITY_CMDLINE); else if (strcmp(machine().options().value(s_folders[m_ref].option), tmppath.c_str()) != 0) { - machine().options().set_value(s_folders[m_ref].option, tmppath.c_str(), OPTION_PRIORITY_CMDLINE, error_string); - machine().options().mark_changed(s_folders[m_ref].option); + machine().options().set_value(s_folders[m_ref].option, tmppath.c_str(), OPTION_PRIORITY_CMDLINE); } } @@ -592,11 +590,10 @@ void menu_remove_folder::handle() } if (ui().options().exists(s_folders[m_ref].option)) - ui().options().set_value(s_folders[m_ref].option, tmppath.c_str(), OPTION_PRIORITY_CMDLINE, error_string); + ui().options().set_value(s_folders[m_ref].option, tmppath.c_str(), OPTION_PRIORITY_CMDLINE); else if (strcmp(machine().options().value(s_folders[m_ref].option),tmppath.c_str())!=0) { - machine().options().set_value(s_folders[m_ref].option, tmppath.c_str(), OPTION_PRIORITY_CMDLINE, error_string); - machine().options().mark_changed(s_folders[m_ref].option); + machine().options().set_value(s_folders[m_ref].option, tmppath.c_str(), OPTION_PRIORITY_CMDLINE); } reset_parent(reset_options::REMEMBER_REF); diff --git a/src/frontend/mame/ui/info.cpp b/src/frontend/mame/ui/info.cpp index 8101faad3c6..ab0e6d85cd3 100644 --- a/src/frontend/mame/ui/info.cpp +++ b/src/frontend/mame/ui/info.cpp @@ -326,8 +326,7 @@ std::string machine_info::mandatory_images() { if (image.must_be_loaded()) { - auto iter = m_machine.options().image_options().find(image.instance_name()); - if (iter == m_machine.options().image_options().end() || iter->second.empty()) + if (m_machine.options().image_option(image.instance_name()).value().empty()) { if (is_first) is_first = false; diff --git a/src/frontend/mame/ui/miscmenu.cpp b/src/frontend/mame/ui/miscmenu.cpp index 3ec2bf78cd3..66201951a91 100644 --- a/src/frontend/mame/ui/miscmenu.cpp +++ b/src/frontend/mame/ui/miscmenu.cpp @@ -127,12 +127,10 @@ void menu_bios_selection::handle() if (val>cnt) val=1; dev->set_system_bios(val); if (strcmp(dev->tag(),":")==0) { - std::string error; - machine().options().set_value("bios", val-1, OPTION_PRIORITY_CMDLINE, error); - assert(error.empty()); + machine().options().set_value("bios", val-1, OPTION_PRIORITY_CMDLINE); } else { const char *slot_option_name = dev->owner()->tag() + 1; - machine().options().slot_options()[slot_option_name].set_bios(string_format("%d", val - 1)); + machine().options().slot_option(slot_option_name).set_bios(string_format("%d", val - 1)); } reset(reset_options::REMEMBER_REF); } @@ -675,15 +673,14 @@ void menu_export::populate(float &customtop, float &custombottom) menu_machine_configure::menu_machine_configure(mame_ui_manager &mui, render_container &container, const game_driver *prev, float _x0, float _y0) : menu(mui, container) , m_drv(prev) - , m_opts(mui.machine().options()) , x0(_x0) , y0(_y0) , m_curbios(0) , m_fav_reset(false) { // parse the INI file - std::string error; - mame_options::parse_standard_inis(m_opts,error, m_drv); + std::ostringstream error; + mame_options::parse_standard_inis(m_opts, error, m_drv); setup_bios(); } @@ -754,9 +751,7 @@ void menu_machine_configure::handle() else if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT) { (menu_event->iptkey == IPT_UI_LEFT) ? --m_curbios : ++m_curbios; - std::string error; - m_opts.set_value(OPTION_BIOS, m_bios[m_curbios].second, OPTION_PRIORITY_CMDLINE, error); - m_opts.mark_changed(OPTION_BIOS); + m_opts.set_value(OPTION_BIOS, m_bios[m_curbios].second, OPTION_PRIORITY_CMDLINE); reset(reset_options::REMEMBER_POSITION); } } @@ -918,8 +913,7 @@ void menu_plugins_configure::handle() if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT || menu_event->iptkey == IPT_UI_SELECT) { int oldval = plugins.int_value((const char*)menu_event->itemref); - std::string error_string; - plugins.set_value((const char*)menu_event->itemref, oldval == 1 ? 0 : 1, OPTION_PRIORITY_CMDLINE, error_string); + plugins.set_value((const char*)menu_event->itemref, oldval == 1 ? 0 : 1, OPTION_PRIORITY_CMDLINE); changed = true; } } @@ -935,13 +929,13 @@ void menu_plugins_configure::populate(float &customtop, float &custombottom) { plugin_options& plugins = mame_machine_manager::instance()->plugins(); - for (auto &curentry : plugins) + for (auto &curentry : plugins.entries()) { - if (!curentry.is_header()) + if (curentry->type() != OPTION_HEADER) { - auto enabled = std::string(curentry.value()) == "1"; - item_append(curentry.description(), enabled ? _("On") : _("Off"), - enabled ? FLAG_RIGHT_ARROW : FLAG_LEFT_ARROW, (void *)(uintptr_t)curentry.name()); + auto enabled = !strcmp(curentry->value(), "1"); + item_append(curentry->description(), enabled ? _("On") : _("Off"), + enabled ? FLAG_RIGHT_ARROW : FLAG_LEFT_ARROW, (void *)(uintptr_t)curentry->name().c_str()); } } item_append(menu_item_type::SEPARATOR); diff --git a/src/frontend/mame/ui/selgame.cpp b/src/frontend/mame/ui/selgame.cpp index e2628f63a9b..04d1c2b2350 100644 --- a/src/frontend/mame/ui/selgame.cpp +++ b/src/frontend/mame/ui/selgame.cpp @@ -116,8 +116,7 @@ menu_select_game::menu_select_game(mame_ui_manager &mui, render_container &conta if (!moptions.remember_last()) reselect_last::reset(); - mui.machine().options().set_value(OPTION_SNAPNAME, "%g/%i", OPTION_PRIORITY_CMDLINE, error_string); - mui.machine().options().set_value(OPTION_SOFTWARENAME, "", OPTION_PRIORITY_CMDLINE, error_string); + mui.machine().options().set_value(OPTION_SNAPNAME, "%g/%i", OPTION_PRIORITY_CMDLINE); ui_globals::curimage_view = FIRST_VIEW; ui_globals::curdats_view = 0; @@ -155,9 +154,9 @@ menu_select_game::~menu_select_game() filter.append(",").append(c_year::ui[c_year::actual]); ui_options &mopt = ui().options(); - mopt.set_value(OPTION_LAST_USED_FILTER, filter.c_str(), OPTION_PRIORITY_CMDLINE, error_string); - mopt.set_value(OPTION_LAST_USED_MACHINE, last_driver.c_str(), OPTION_PRIORITY_CMDLINE, error_string); - mopt.set_value(OPTION_HIDE_PANELS, ui_globals::panels_status, OPTION_PRIORITY_CMDLINE, error_string); + mopt.set_value(OPTION_LAST_USED_FILTER, filter.c_str(), OPTION_PRIORITY_CMDLINE); + mopt.set_value(OPTION_LAST_USED_MACHINE, last_driver.c_str(), OPTION_PRIORITY_CMDLINE); + mopt.set_value(OPTION_HIDE_PANELS, ui_globals::panels_status, OPTION_PRIORITY_CMDLINE); ui().save_ui_options(); } @@ -930,11 +929,10 @@ void menu_select_game::inkey_select_favorite(const event *menu_event) return; } - std::string error_string; std::string string_list = std::string(ui_swinfo->listname).append(":").append(ui_swinfo->shortname).append(":").append(ui_swinfo->part).append(":").append(ui_swinfo->instance); - mopt.set_value(OPTION_SOFTWARENAME, string_list.c_str(), OPTION_PRIORITY_CMDLINE, error_string); + mopt.set_value(OPTION_SOFTWARENAME, string_list.c_str(), OPTION_PRIORITY_CMDLINE); std::string snap_list = std::string(ui_swinfo->listname).append(PATH_SEPARATOR).append(ui_swinfo->shortname); - mopt.set_value(OPTION_SNAPNAME, snap_list.c_str(), OPTION_PRIORITY_CMDLINE, error_string); + mopt.set_value(OPTION_SNAPNAME, snap_list.c_str(), OPTION_PRIORITY_CMDLINE); reselect_last::driver = drv.driver().name; reselect_last::software = ui_swinfo->shortname; reselect_last::swlist = ui_swinfo->listname; diff --git a/src/frontend/mame/ui/selsoft.cpp b/src/frontend/mame/ui/selsoft.cpp index b5eeb36b204..23107e4d992 100644 --- a/src/frontend/mame/ui/selsoft.cpp +++ b/src/frontend/mame/ui/selsoft.cpp @@ -144,9 +144,6 @@ menu_select_software::menu_select_software(mame_ui_manager &mui, render_containe ui_globals::switch_image = true; ui_globals::cur_sw_dats_view = 0; ui_globals::cur_sw_dats_total = 1; - - std::string error_string; - mui.machine().options().set_value(OPTION_SOFTWARENAME, "", OPTION_PRIORITY_CMDLINE, error_string); } //------------------------------------------------- @@ -718,11 +715,10 @@ void menu_select_software::inkey_select(const event *menu_event) return; } - std::string error_string; - std::string string_list = std::string(ui_swinfo->listname).append(":").append(ui_swinfo->shortname).append(":").append(ui_swinfo->part).append(":").append(ui_swinfo->instance); - machine().options().set_value(OPTION_SOFTWARENAME, string_list.c_str(), OPTION_PRIORITY_CMDLINE, error_string); + machine().options().set_system_name(m_driver->name); + machine().options().set_value(OPTION_SOFTWARENAME, ui_swinfo->shortname, OPTION_PRIORITY_CMDLINE); std::string snap_list = std::string(ui_swinfo->listname).append(PATH_SEPARATOR).append(ui_swinfo->shortname); - machine().options().set_value(OPTION_SNAPNAME, snap_list.c_str(), OPTION_PRIORITY_CMDLINE, error_string); + machine().options().set_value(OPTION_SNAPNAME, snap_list.c_str(), OPTION_PRIORITY_CMDLINE); reselect_last::driver = drivlist.driver().name; reselect_last::software = ui_swinfo->shortname; reselect_last::swlist = ui_swinfo->listname; @@ -1288,9 +1284,8 @@ void software_parts::handle() { if ((void*)&elem == menu_event->itemref) { - std::string error_string; std::string string_list = std::string(m_uiinfo->listname).append(":").append(m_uiinfo->shortname).append(":").append(elem.first).append(":").append(m_uiinfo->instance); - machine().options().set_value(OPTION_SOFTWARENAME, string_list.c_str(), OPTION_PRIORITY_CMDLINE, error_string); + machine().options().set_value(OPTION_SOFTWARENAME, string_list.c_str(), OPTION_PRIORITY_CMDLINE); reselect_last::driver = m_uiinfo->driver->name; reselect_last::software = m_uiinfo->shortname; @@ -1298,7 +1293,7 @@ void software_parts::handle() reselect_last::set(true); std::string snap_list = std::string(m_uiinfo->listname).append("/").append(m_uiinfo->shortname); - machine().options().set_value(OPTION_SNAPNAME, snap_list.c_str(), OPTION_PRIORITY_CMDLINE, error_string); + machine().options().set_value(OPTION_SNAPNAME, snap_list.c_str(), OPTION_PRIORITY_CMDLINE); mame_machine_manager::instance()->schedule_new_driver(*m_uiinfo->driver); machine().schedule_hard_reset(); @@ -1400,8 +1395,7 @@ void bios_selection::handle() reselect_last::set(true); } - std::string error; - moptions.set_value(OPTION_BIOS, elem.second, OPTION_PRIORITY_CMDLINE, error); + moptions.set_value(OPTION_BIOS, elem.second, OPTION_PRIORITY_CMDLINE); mame_machine_manager::instance()->schedule_new_driver(*s_driver); machine().schedule_hard_reset(); stack_reset(); @@ -1409,8 +1403,7 @@ void bios_selection::handle() else { ui_software_info *ui_swinfo = (ui_software_info *)m_driver; - std::string error; - machine().options().set_value(OPTION_BIOS, elem.second, OPTION_PRIORITY_CMDLINE, error); + machine().options().set_value(OPTION_BIOS, elem.second, OPTION_PRIORITY_CMDLINE); driver_enumerator drivlist(machine().options(), *ui_swinfo->driver); drivlist.next(); software_list_device *swlist = software_list_device::find_by_name(*drivlist.config(), ui_swinfo->listname.c_str()); @@ -1431,11 +1424,10 @@ void bios_selection::handle() menu::stack_push<software_parts>(ui(), container(), parts, ui_swinfo); return; } - std::string error_string; std::string string_list = std::string(ui_swinfo->listname).append(":").append(ui_swinfo->shortname).append(":").append(ui_swinfo->part).append(":").append(ui_swinfo->instance); - moptions.set_value(OPTION_SOFTWARENAME, string_list.c_str(), OPTION_PRIORITY_CMDLINE, error_string); + moptions.set_value(OPTION_SOFTWARENAME, string_list.c_str(), OPTION_PRIORITY_CMDLINE); std::string snap_list = std::string(ui_swinfo->listname).append(PATH_SEPARATOR).append(ui_swinfo->shortname); - moptions.set_value(OPTION_SNAPNAME, snap_list.c_str(), OPTION_PRIORITY_CMDLINE, error_string); + moptions.set_value(OPTION_SNAPNAME, snap_list.c_str(), OPTION_PRIORITY_CMDLINE); reselect_last::driver = drivlist.driver().name; reselect_last::software = ui_swinfo->shortname; reselect_last::swlist = ui_swinfo->listname; diff --git a/src/frontend/mame/ui/slotopt.cpp b/src/frontend/mame/ui/slotopt.cpp index 42ec9e1a896..8434a667899 100644 --- a/src/frontend/mame/ui/slotopt.cpp +++ b/src/frontend/mame/ui/slotopt.cpp @@ -27,9 +27,9 @@ device_slot_option *menu_slot_devices::slot_get_current_option(device_slot_inter std::string current; const char *slot_option_name = slot.device().tag() + 1; - if (!slot.fixed() && machine().options().slot_options().count(slot_option_name) > 0) + if (!slot.fixed()) { - current = machine().options().slot_options()[slot_option_name].value(); + current = machine().options().slot_option(slot_option_name).value(); } else { @@ -140,9 +140,7 @@ const char *menu_slot_devices::slot_get_option(device_slot_interface &slot, int void menu_slot_devices::set_slot_device(device_slot_interface &slot, const char *val) { - std::string error; - machine().options().set_value(slot.device().tag()+1, val, OPTION_PRIORITY_CMDLINE, error); - assert(error.empty()); + machine().options().set_value(slot.device().tag()+1, val, OPTION_PRIORITY_CMDLINE); } /*------------------------------------------------- @@ -200,7 +198,6 @@ void menu_slot_devices::handle() { if ((uintptr_t)menu_event->itemref == 1 && menu_event->iptkey == IPT_UI_SELECT) { - mame_options::add_slot_options(machine().options()); machine().schedule_hard_reset(); } else if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT) diff --git a/src/frontend/mame/ui/sndmenu.cpp b/src/frontend/mame/ui/sndmenu.cpp index 0a0d1c019ed..f2304b529ea 100644 --- a/src/frontend/mame/ui/sndmenu.cpp +++ b/src/frontend/mame/ui/sndmenu.cpp @@ -45,23 +45,19 @@ menu_sound_options::menu_sound_options(mame_ui_manager &mui, render_container &c menu_sound_options::~menu_sound_options() { - std::string error_string; emu_options &moptions = machine().options(); if (strcmp(moptions.value(OSDOPTION_SOUND),m_sound ? OSDOPTVAL_AUTO : OSDOPTVAL_NONE)!=0) { - moptions.set_value(OSDOPTION_SOUND, m_sound ? OSDOPTVAL_AUTO : OSDOPTVAL_NONE, OPTION_PRIORITY_CMDLINE, error_string); - machine().options().mark_changed(OSDOPTION_SOUND); + moptions.set_value(OSDOPTION_SOUND, m_sound ? OSDOPTVAL_AUTO : OSDOPTVAL_NONE, OPTION_PRIORITY_CMDLINE); } if (moptions.int_value(OPTION_SAMPLERATE)!=m_sound_rate[m_cur_rates]) { - moptions.set_value(OPTION_SAMPLERATE, m_sound_rate[m_cur_rates], OPTION_PRIORITY_CMDLINE, error_string); - machine().options().mark_changed(OPTION_SAMPLERATE); + moptions.set_value(OPTION_SAMPLERATE, m_sound_rate[m_cur_rates], OPTION_PRIORITY_CMDLINE); } if (moptions.bool_value(OPTION_SAMPLES)!=m_samples) { - moptions.set_value(OPTION_SAMPLES, m_samples, OPTION_PRIORITY_CMDLINE, error_string); - machine().options().mark_changed(OPTION_SAMPLES); + moptions.set_value(OPTION_SAMPLES, m_samples, OPTION_PRIORITY_CMDLINE); } } diff --git a/src/frontend/mame/ui/submenu.cpp b/src/frontend/mame/ui/submenu.cpp index 5a8cb83cd8b..ab18a5a5a95 100644 --- a/src/frontend/mame/ui/submenu.cpp +++ b/src/frontend/mame/ui/submenu.cpp @@ -240,8 +240,7 @@ void submenu::handle() { case OPTION_BOOLEAN: changed = true; - sm_option.options->set_value(sm_option.name, !strcmp(sm_option.entry->value(),"1") ? "0" : "1", OPTION_PRIORITY_CMDLINE, error_string); - sm_option.entry->mark_changed(); + sm_option.options->set_value(sm_option.name, !strcmp(sm_option.entry->value(),"1") ? "0" : "1", OPTION_PRIORITY_CMDLINE); break; case OPTION_INTEGER: if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT) @@ -249,8 +248,7 @@ void submenu::handle() changed = true; int i_cur = atoi(sm_option.entry->value()); (menu_event->iptkey == IPT_UI_LEFT) ? i_cur-- : i_cur++; - sm_option.options->set_value(sm_option.name, i_cur, OPTION_PRIORITY_CMDLINE, error_string); - sm_option.entry->mark_changed(); + sm_option.options->set_value(sm_option.name, i_cur, OPTION_PRIORITY_CMDLINE); } break; case OPTION_FLOAT: @@ -260,17 +258,19 @@ void submenu::handle() f_cur = atof(sm_option.entry->value()); if (sm_option.entry->has_range()) { - f_step = atof(sm_option.entry->minimum()); + const char *minimum = sm_option.entry->minimum(); + const char *maximum = sm_option.entry->maximum(); + f_step = atof(minimum); if (f_step <= 0.0f) { - int pmin = getprecisionchr(sm_option.entry->minimum()); - int pmax = getprecisionchr(sm_option.entry->maximum()); + int pmin = getprecisionchr(minimum); + int pmax = getprecisionchr(maximum); tmptxt = '1' + std::string((pmin > pmax) ? pmin : pmax, '0'); f_step = 1 / atof(tmptxt.c_str()); } } else { - int precision = getprecisionchr(sm_option.entry->default_value()); + int precision = getprecisionchr(sm_option.entry->default_value().c_str()); tmptxt = '1' + std::string(precision, '0'); f_step = 1 / atof(tmptxt.c_str()); } @@ -279,8 +279,7 @@ void submenu::handle() else f_cur += f_step; tmptxt = string_format("%g", f_cur); - sm_option.options->set_value(sm_option.name, tmptxt.c_str(), OPTION_PRIORITY_CMDLINE, error_string); - sm_option.entry->mark_changed(); + sm_option.options->set_value(sm_option.name, tmptxt.c_str(), OPTION_PRIORITY_CMDLINE); } break; case OPTION_STRING: @@ -293,10 +292,11 @@ void submenu::handle() v_cur = sm_option.value[--cur_value]; else v_cur = sm_option.value[++cur_value]; - sm_option.options->set_value(sm_option.name, v_cur.c_str(), OPTION_PRIORITY_CMDLINE, error_string); - sm_option.entry->mark_changed(); + sm_option.options->set_value(sm_option.name, v_cur.c_str(), OPTION_PRIORITY_CMDLINE); } break; + default: + break; } break; default: @@ -391,7 +391,7 @@ void submenu::populate(float &customtop, float &custombottom) break; case OPTION_STRING: { - std::string const v_cur(sm_option->entry->value()); + std::string v_cur(sm_option->entry->value()); int const cur_value = std::distance(sm_option->value.begin(), std::find(sm_option->value.begin(), sm_option->value.end(), v_cur)); arrow_flags = get_arrow_flags(0, int(unsigned(sm_option->value.size() - 1)), cur_value); item_append(_(sm_option->description), diff --git a/src/frontend/mame/ui/submenu.h b/src/frontend/mame/ui/submenu.h index acaf28d90e4..f17b6fe53ff 100644 --- a/src/frontend/mame/ui/submenu.h +++ b/src/frontend/mame/ui/submenu.h @@ -48,7 +48,7 @@ public: option_type type; const char *description; const char *name; - core_options::entry *entry; + core_options::entry::shared_ptr entry; core_options *options; std::vector<std::string> value; }; diff --git a/src/frontend/mame/ui/ui.cpp b/src/frontend/mame/ui/ui.cpp index cf4ea2c9cc5..fc080835893 100644 --- a/src/frontend/mame/ui/ui.cpp +++ b/src/frontend/mame/ui/ui.cpp @@ -2228,14 +2228,18 @@ void mame_ui_manager::popup_time_string(int seconds, std::string message) void mame_ui_manager::load_ui_options() { // parse the file - std::string error; // attempt to open the output file emu_file file(machine().options().ini_path(), OPEN_FLAG_READ); if (file.open("ui.ini") == osd_file::error::NONE) { - bool result = options().parse_ini_file((util::core_file&)file, OPTION_PRIORITY_MAME_INI, OPTION_PRIORITY_DRIVER_INI, error); - if (!result) + try + { + options().parse_ini_file((util::core_file&)file, OPTION_PRIORITY_MAME_INI, true); + } + catch (options_exception &) + { osd_printf_error("**Error loading ui.ini**"); + } } } @@ -2266,28 +2270,37 @@ void mame_ui_manager::save_main_option() { // parse the file std::string error; - emu_options options(machine().options()); // This way we make sure that all OSD parts are in - std::string error_string; + emu_options options(true); // This way we make sure that all OSD parts are in + + options.copy_from(machine().options()); // attempt to open the main ini file { emu_file file(machine().options().ini_path(), OPEN_FLAG_READ); if (file.open(emulator_info::get_configname(), ".ini") == osd_file::error::NONE) { - bool result = options.parse_ini_file((util::core_file&)file, OPTION_PRIORITY_MAME_INI, OPTION_PRIORITY_DRIVER_INI, error); - if (!result) + try + { + options.parse_ini_file((util::core_file&)file, OPTION_PRIORITY_MAME_INI, true); + } + catch(options_error_exception &ex) { - osd_printf_error("**Error loading %s.ini**", emulator_info::get_configname()); + osd_printf_error("**Error loading %s.ini**: %s\n", emulator_info::get_configname(), ex.message().c_str()); return; } + catch (options_exception &) + { + // ignore other exceptions + } } } - for (emu_options::entry &f_entry : machine().options()) + for (const auto &f_entry : machine().options().entries()) { - if (f_entry.is_changed()) + const char *value = f_entry->value(); + if (value && strcmp(value, options.value(f_entry->name().c_str()))) { - options.set_value(f_entry.name(), f_entry.value(), OPTION_PRIORITY_CMDLINE, error_string); + options.set_value(f_entry->name(), *f_entry->value(), OPTION_PRIORITY_CMDLINE); } } |