diff options
author | 2016-06-11 01:53:58 +0200 | |
---|---|---|
committer | 2016-06-11 01:53:58 +0200 | |
commit | 2030b4f3e5819be4a9c73216c1e39f5edbf41b4a (patch) | |
tree | 5d4d042f3ef455f900ecc7a7b79b7bf42fc812e9 | |
parent | 1a8fbf3aba8ac9c4f8d71dd00c784c5a313e298c (diff) |
Fixed issue #941, crash in attempt to use "Configure Machine" from favorites filter.
Boot time reduced by ~15%.
-rw-r--r-- | src/frontend/mame/ui/custui.cpp | 4 | ||||
-rw-r--r-- | src/frontend/mame/ui/datfile.cpp | 13 | ||||
-rw-r--r-- | src/frontend/mame/ui/datfile.h | 2 | ||||
-rw-r--r-- | src/frontend/mame/ui/datmenu.cpp | 19 | ||||
-rw-r--r-- | src/frontend/mame/ui/inifile.h | 12 | ||||
-rw-r--r-- | src/frontend/mame/ui/selector.cpp | 1 | ||||
-rw-r--r-- | src/frontend/mame/ui/selgame.cpp | 31 | ||||
-rw-r--r-- | src/frontend/mame/ui/utils.cpp | 7 | ||||
-rw-r--r-- | src/frontend/mame/ui/utils.h | 1 |
9 files changed, 47 insertions, 43 deletions
diff --git a/src/frontend/mame/ui/custui.cpp b/src/frontend/mame/ui/custui.cpp index 5b10342f310..b54f6b024e1 100644 --- a/src/frontend/mame/ui/custui.cpp +++ b/src/frontend/mame/ui/custui.cpp @@ -35,14 +35,14 @@ menu_custom_ui::menu_custom_ui(mame_ui_manager &mui, render_container *container { // load languages file_enumerator path(mui.machine().options().language_path()); - const char *lang = mui.machine().options().language(); + auto lang = mui.machine().options().language(); const osd_directory_entry *dirent; int cnt = 0; while ((dirent = path.next()) != nullptr) if (dirent->type == ENTTYPE_DIR && strcmp(dirent->name, ".") != 0 && strcmp(dirent->name, "..") != 0) { auto name = std::string(dirent->name); - int i = strreplace(name, "_", " ("); + auto i = strreplace(name, "_", " ("); if (i > 0) name = name.append(")"); m_lang.push_back(name); if (strcmp(name.c_str(), lang) == 0) diff --git a/src/frontend/mame/ui/datfile.cpp b/src/frontend/mame/ui/datfile.cpp index 400e290ce01..d70ec38fb9e 100644 --- a/src/frontend/mame/ui/datfile.cpp +++ b/src/frontend/mame/ui/datfile.cpp @@ -209,8 +209,7 @@ void datfile_manager::load_data_info(const game_driver *drv, std::string &buffer { dataindex index_idx; drvindex driver_idx; - std::string tag; - std::string filename; + std::string tag, filename; switch (type) { @@ -269,7 +268,7 @@ void datfile_manager::load_data_info(const game_driver *drv, std::string &buffer //------------------------------------------------- void datfile_manager::load_data_text(const game_driver *drv, std::string &buffer, dataindex &idx, std::string &tag) { - dataindex::iterator itemsiter = idx.find(drv); + auto itemsiter = idx.find(drv); if (itemsiter == idx.end()) { auto cloneof = driver_list::non_bios_clone(*drv); @@ -312,7 +311,7 @@ void datfile_manager::load_data_text(const game_driver *drv, std::string &buffer void datfile_manager::load_driver_text(const game_driver *drv, std::string &buffer, drvindex &idx, std::string &tag) { std::string s(core_filename_extract_base(drv->source_file)); - drvindex::const_iterator index = idx.find(s); + auto index = idx.find(s); // if driver not found, return if (index == idx.end()) @@ -346,7 +345,6 @@ void datfile_manager::load_driver_text(const game_driver *drv, std::string &buff //------------------------------------------------- int datfile_manager::index_mame_mess_info(dataindex &index, drvindex &index_drv, int &drvcount) { - std::string name; size_t foundtag; auto t_mame = TAG_MAMEINFO_R.size(); auto t_mess = TAG_MESSINFO_R.size(); @@ -354,7 +352,7 @@ int datfile_manager::index_mame_mess_info(dataindex &index, drvindex &index_drv, auto t_info = TAG_INFO.size(); char rbuf[64 * 1024]; - std::string readbuf, xid; + std::string readbuf, xid, name; while (fgets(rbuf, 64 * 1024, fp) != nullptr) { readbuf = chartrimcarriage(rbuf); @@ -424,7 +422,9 @@ int datfile_manager::index_datafile(dataindex &index, int &swcount) m_sysinfo_rev = readbuf.substr(t_sysinfo + 1, found - t_sysinfo); } else if (m_story_rev.empty() && readbuf.compare(0, t_story, TAG_STORY_R) == 0) + { m_story_rev = readbuf.substr(t_story + 1); + } else if (readbuf.compare(0, t_info, TAG_INFO) == 0) { // search for game info @@ -558,6 +558,7 @@ void datfile_manager::command_sub_menu(const game_driver *drv, std::vector<std:: { m_menuidx.clear(); index_menuidx(drv, m_cmdidx, m_menuidx); + menuitems.reserve(m_menuidx.size()); for (auto & elem : m_menuidx) menuitems.push_back(elem.first); parseclose(); diff --git a/src/frontend/mame/ui/datfile.h b/src/frontend/mame/ui/datfile.h index f76c9c7720e..9e77c2383fe 100644 --- a/src/frontend/mame/ui/datfile.h +++ b/src/frontend/mame/ui/datfile.h @@ -81,7 +81,7 @@ private: int index_mame_mess_info(dataindex &index, drvindex &index_drv, int &drvcount); int index_datafile(dataindex &index, int &swcount); void index_menuidx(const game_driver *drv, dataindex &idx, drvindex &index); - drvindex::iterator m_itemsiter; + drvindex::const_iterator m_itemsiter; void load_data_text(const game_driver *drv, std::string &buffer, dataindex &idx, std::string &tag); void load_driver_text(const game_driver *drv, std::string &buffer, drvindex &idx, std::string &tag); diff --git a/src/frontend/mame/ui/datmenu.cpp b/src/frontend/mame/ui/datmenu.cpp index e53e8dc8ab8..a3a29b76116 100644 --- a/src/frontend/mame/ui/datmenu.cpp +++ b/src/frontend/mame/ui/datmenu.cpp @@ -171,7 +171,6 @@ void menu_dats_view::custom_render(void *selectedref, float top, float bottom, f ui().draw_outlined_box(container, x1, y1, x2, y2, UI_BACKGROUND_COLOR); // take off the borders - x2 -= UI_BOX_LR_BORDER; y1 += UI_BOX_TB_BORDER; // draw the text within it @@ -224,22 +223,20 @@ void menu_dats_view::custom_render(void *selectedref, float top, float bottom, f void menu_dats_view::get_data() { - std::vector<int> xstart; - std::vector<int> xend; + std::vector<int> xstart, xend; std::string buffer; - std::vector<std::string> m_item; if (m_items_list[m_actual].option == UI_COMMAND_LOAD) { + std::vector<std::string> m_item; mame_machine_manager::instance()->datfile().command_sub_menu(m_driver, m_item); if (!m_item.empty()) { - for (size_t x = 0; x < m_item.size(); ++x) + for (auto & e : m_item) { std::string t_buffer; - buffer.append(m_item[x]).append("\n"); - mame_machine_manager::instance()->datfile().load_command_info(t_buffer, m_item[x]); - if (!t_buffer.empty()) - buffer.append(t_buffer).append("\n"); + buffer.append(e).append("\n"); + mame_machine_manager::instance()->datfile().load_command_info(t_buffer, e); + if (!t_buffer.empty()) buffer.append(t_buffer).append("\n"); } convert_command_glyph(buffer); } @@ -247,7 +244,7 @@ void menu_dats_view::get_data() else mame_machine_manager::instance()->datfile().load_data_info(m_driver, buffer, m_items_list[m_actual].option); - int lines = ui().wrap_text(container, buffer.c_str(), 0.0f, 0.0f, 1.0f - (4.0f * UI_BOX_LR_BORDER), xstart, xend); + auto lines = ui().wrap_text(container, buffer.c_str(), 0.0f, 0.0f, 1.0f - (4.0f * UI_BOX_LR_BORDER), xstart, xend); for (int x = 0; x < lines; ++x) { std::string tempbuf(buffer.substr(xstart[x], xend[x] - xstart[x])); @@ -270,7 +267,7 @@ void menu_dats_view::get_data_sw() mame_machine_manager::instance()->datfile().load_software_info(m_swinfo->listname, buffer, m_swinfo->shortname, m_swinfo->parentname); } - int lines = ui().wrap_text(container, buffer.c_str(), 0.0f, 0.0f, 1.0f - (4.0f * UI_BOX_LR_BORDER), xstart, xend); + auto lines = ui().wrap_text(container, buffer.c_str(), 0.0f, 0.0f, 1.0f - (4.0f * UI_BOX_LR_BORDER), xstart, xend); for (int x = 0; x < lines; ++x) { std::string tempbuf(buffer.substr(xstart[x], xend[x] - xstart[x])); diff --git a/src/frontend/mame/ui/inifile.h b/src/frontend/mame/ui/inifile.h index 654241e6913..0658cf1f7db 100644 --- a/src/frontend/mame/ui/inifile.h +++ b/src/frontend/mame/ui/inifile.h @@ -29,10 +29,12 @@ public: // getters running_machine &machine() const { return m_machine; } - std::string get_file(int file = -1) { return ((file == -1) ? ini_index[c_file].first : ini_index[file].first); } - std::string get_category(int cat = -1) { return ((cat == -1) ? ini_index[c_file].second[c_cat].first : ini_index[c_file].second[cat].first); } + std::string get_file() { return ini_index[c_file].first; } + std::string get_file(int file) { return ini_index[file].first; } + std::string get_category(int cat) { return ini_index[c_file].second[cat].first; } + std::string get_category() { return ini_index[c_file].second[c_cat].first; } size_t total() { return ini_index.size(); } - size_t cat_total(int cat = -1) { return ((cat == -1) ? ini_index[c_file].second.size() : ini_index[cat].second.size()); } + size_t cat_total() { return ini_index[c_file].second.size(); } UINT16 &cur_file() { return c_file; } UINT16 &cur_cat() { return c_cat; } @@ -42,8 +44,8 @@ public: // setters void move_file(int d) { c_file += d; c_cat = 0; } void move_cat(int d) { c_cat += d; } - void set_cat(int i = -1) { (i == -1) ? c_cat = 0 : c_cat = i; } - void set_file(int i = -1) { (i == -1) ? c_file = 0 : c_file = i; } + void set_cat(int i) { c_cat = i; } + void set_file(int i) { c_file = i; } private: diff --git a/src/frontend/mame/ui/selector.cpp b/src/frontend/mame/ui/selector.cpp index a60bb6ce070..502dab9bbc8 100644 --- a/src/frontend/mame/ui/selector.cpp +++ b/src/frontend/mame/ui/selector.cpp @@ -235,7 +235,6 @@ void menu_selector::find_matches(const char *str) if (m_str_items[index] == "_skip_") continue; - // pick the best match between driver name and description int curpenalty = fuzzy_substring(str, m_str_items[index]); // insert into the sorted table of matches diff --git a/src/frontend/mame/ui/selgame.cpp b/src/frontend/mame/ui/selgame.cpp index d3976afa1d6..0d59c9e20d3 100644 --- a/src/frontend/mame/ui/selgame.cpp +++ b/src/frontend/mame/ui/selgame.cpp @@ -236,6 +236,11 @@ void menu_select_game::handle() // handle IPT_CUSTOM (mouse right click) if (!isfavorite()) menu::stack_push<menu_machine_configure>(ui(), container, (const game_driver *)m_prev_selected, menu_event->mouse.x0, menu_event->mouse.y0); + else + { + ui_software_info *sw = (ui_software_info *)m_prev_selected; + menu::stack_push<menu_machine_configure>(ui(), container, (const game_driver *)sw->driver, menu_event->mouse.x0, menu_event->mouse.y0); + } } else if (menu_event->iptkey == IPT_UI_LEFT) { @@ -664,11 +669,11 @@ void menu_select_game::build_available_list() // now check and include NONE_NEEDED for (int x = 0; x < m_total; ++x) { - const game_driver *driver = &driver_list::driver(x); + auto driver = &driver_list::driver(x); if (!m_included[x] && driver != &GAME_NAME(___empty)) { const rom_entry *rom = driver->rom; - bool noroms = true; + auto noroms = true; // check NO-DUMP for (; !ROMENTRY_ISEND(rom) && noroms == true; ++rom) @@ -685,8 +690,8 @@ void menu_select_game::build_available_list() int cx = driver_list::clone(*driver); if (cx != -1 && m_included[cx]) { - const game_driver *drv = &driver_list::driver(cx); - const rom_entry *parentrom = drv->rom; + auto drv = &driver_list::driver(cx); + auto parentrom = drv->rom; if ((rom = driver->rom) == parentrom) noroms = true; @@ -703,7 +708,7 @@ void menu_select_game::build_available_list() continue; UINT64 lenght = ROM_GETLENGTH(rom); - bool found = false; + auto found = false; for (parentrom = drv->rom; !ROMENTRY_ISEND(parentrom) && found == false; ++parentrom) { if (ROMENTRY_ISFILE(parentrom) && ROM_GETLENGTH(parentrom) == lenght) @@ -1028,8 +1033,7 @@ void menu_select_game::inkey_select(const event *menu_event) { if (m_prev_selected != nullptr) menu::stack_push<menu_machine_configure>(ui(), container, (const game_driver *)m_prev_selected); - else - return; + return; } // special case for configure plugins @@ -1093,18 +1097,16 @@ void menu_select_game::inkey_select_favorite(const event *menu_event) // special case for configure options if ((FPTR)ui_swinfo == CONF_OPTS) menu::stack_push<menu_game_options>(ui(), container); - /* special case for configure machine TODO + // special case for configure machine else if ((FPTR)ui_swinfo == CONF_MACHINE) { if (m_prev_selected != nullptr) { ui_software_info *swinfo = (ui_software_info *)m_prev_selected; - if (swinfo->startempty == 1) - menu::stack_push(ui(), container, swinfo->driver); + menu::stack_push<menu_machine_configure>(ui(), container, (const game_driver *)swinfo->driver); } - else - return; - } */ + return; + } // special case for configure plugins else if ((FPTR)ui_swinfo == CONF_PLUGINS) { @@ -1677,6 +1679,9 @@ void menu_select_game::init_sorted_list() c_year::set(driver->year); } + for (auto & e : c_mnfct::uimap) + c_mnfct::ui.emplace_back(e.first); + // sort manufacturers - years and driver std::stable_sort(c_mnfct::ui.begin(), c_mnfct::ui.end()); std::stable_sort(c_year::ui.begin(), c_year::ui.end()); diff --git a/src/frontend/mame/ui/utils.cpp b/src/frontend/mame/ui/utils.cpp index 18f694007dc..5ad21c6839c 100644 --- a/src/frontend/mame/ui/utils.cpp +++ b/src/frontend/mame/ui/utils.cpp @@ -21,6 +21,7 @@ std::vector<std::string> c_year::ui; // Manufacturers index UINT16 c_mnfct::actual = 0; std::vector<std::string> c_mnfct::ui; +std::unordered_map<std::string, int> c_mnfct::uimap; // Main filters UINT16 main_filters::actual = 0; @@ -95,6 +96,7 @@ int getprecisionchr(const char* s) std::vector<std::string> tokenize(const std::string &text, char sep) { std::vector<std::string> tokens; + tokens.reserve(64); std::size_t start = 0, end = 0; while ((end = text.find(sep, start)) != std::string::npos) { @@ -165,10 +167,7 @@ int fuzzy_substring(std::string s_needle, std::string s_haystack) void c_mnfct::set(const char *str) { std::string name = getname(str); - if (std::find(ui.begin(), ui.end(), name) != ui.end()) - return; - - ui.push_back(name); + uimap[name] = 0; } std::string c_mnfct::getname(const char *str) diff --git a/src/frontend/mame/ui/utils.h b/src/frontend/mame/ui/utils.h index f6aa15b8b10..8d3d2d0c085 100644 --- a/src/frontend/mame/ui/utils.h +++ b/src/frontend/mame/ui/utils.h @@ -185,6 +185,7 @@ struct c_mnfct static void set(const char *str); static std::string getname(const char *str); static std::vector<std::string> ui; + static std::unordered_map<std::string, int> uimap; static UINT16 actual; }; |