// register for save states /*------------------------------------------------- * register_save - register for save states * -------------------------------------------------*/ public void register_save() { assert(m_save_order.empty()); assert(m_save_data == null); // make space for the data m_save_order.clear(); m_save_order.reserve(m_itemtable.size()); m_save_data = new s32 [m_itemtable.size()]; //m_save_data = std::make_unique<s32 []>(m_itemtable.size()); // sort existing outputs by name and register for save foreach (var item in m_itemtable) { m_save_order.emplace_back(item.second()); } m_save_order.Sort((l, r) => { return(string.Compare(l.name(), r.name())); }); //std::sort(m_save_order.begin(), m_save_order.end(), [] (auto const &l, auto const &r) { return l.get().name() < r.get().name(); }); // register the reserved space for saving //throw new emu_unimplemented(); #if false machine().save().save_pointer(nullptr, "output", nullptr, 0, NAME(m_save_data), m_itemtable.size()); #endif if (OUTPUT_VERBOSE) { osd_printf_verbose("Registered {0} outputs for save states\n", m_itemtable.size()); } }
// toolbar protected override void inkey_export() { std.vector <game_driver> list = new std.vector <game_driver>(); if (m_populated_favorites) { // iterate over favorites mame_machine_manager.instance().favorite().apply((info) => { assert(info.driver != null); if (info.startempty != 0) { list.push_back(info.driver); } }); } else { list.reserve(m_displaylist.size()); foreach (ui_system_info info in m_displaylist) { list.emplace_back(info.driver); } } throw new emu_unimplemented(); #if false #endif }
// general helpers //void set_current(UInt32 index) { assert(index >= -1 && index <= s_driver_count); m_current = index; } //------------------------------------------------- // driver_sort_callback - compare two items in // an array of game_driver pointers //------------------------------------------------- public void find_approximate_matches(string string_, int count, out int [] results) { //#undef rand results = new int [count]; // if no name, pick random entries if (string_.empty()) { // seed the RNG first //srand(osd_ticks()); Random r = new Random((int)m_osdcore.osd_ticks()); // allocate a temporary list std.vector <int> templist = new std.vector <int>(m_filtered_count); int arrayindex = 0; for (int index = 0; index < (int)s_driver_count; index++) { if (m_included[index]) { templist[arrayindex++] = index; } } assert(arrayindex == (int)m_filtered_count); // shuffle for (int shufnum = 0; shufnum < (int)(4 * s_driver_count); shufnum++) { int item1 = r.Next() % (int)m_filtered_count; int item2 = r.Next() % (int)m_filtered_count; int temp = templist[item1]; templist[item1] = templist[item2]; templist[item2] = temp; } // copy out the first few entries for (int matchnum = 0; matchnum < count; matchnum++) { results[matchnum] = templist[matchnum % (int)m_filtered_count]; } } else { // allocate memory to track the penalty value std.vector <std.pair <double, int> > penalty = new std.vector <std.pair <double, int> >(); penalty.reserve((size_t)count); string search = ustr_from_utf8(normalize_unicode(string_, unicode_normalization_form.D, true)); string composed; string candidate; // scan the entire drivers array for (int index = 0; index < (int)s_driver_count; index++) { if (m_included[index]) { // cheat on the shortname as it's always lowercase ASCII game_driver drv = s_drivers_sorted[index]; size_t namelen = std.strlen(drv.name); //candidate.resize(namelen); candidate = drv.name; //std.copy_n(drv.name, namelen, candidate.begin()); double curpenalty = util.edit_distance(search, candidate); // if it's not a perfect match, try the description if (curpenalty != 0) { candidate = ustr_from_utf8(normalize_unicode(drv.type.fullname(), unicode_normalization_form.D, true)); double p = util.edit_distance(search, candidate); if (p < curpenalty) { curpenalty = p; } } // also check "<manufacturer> <description>" if (curpenalty != 0) { composed = drv.manufacturer; composed += ' '; composed += drv.type.fullname(); candidate = ustr_from_utf8(normalize_unicode(composed, unicode_normalization_form.D, true)); double p = util.edit_distance(search, candidate); if (p < curpenalty) { curpenalty = p; } } // insert into the sorted table of matches //var it = std.upper_bound(penalty.begin(), penalty.end(), std.make_pair(curpenalty, index)); int it; for (it = 0; it < penalty.Count; it++) { if (penalty[it].first > curpenalty) { break; } } if (penalty.Count != it) { if ((int)penalty.size() >= count) { penalty.resize((size_t)count - 1); } penalty.emplace(it, new std.pair <double, int>(curpenalty, index)); } else if ((int)penalty.size() < count) { penalty.emplace(it, new std.pair <double, int>(curpenalty, index)); } } } // copy to output and pad with -1 //std::fill( // std::transform( // penalty.begin(), // penalty.end(), // results, // [] (std::pair<double, int> const &x) { return x.second; }), // results + count, // -1); results = new int [penalty.Count]; for (int i = 0; i < results.Length; i++) { results[i] = penalty[i].second; } } }
//------------------------------------------------- // populate search list //------------------------------------------------- void populate_search() { // ensure search list is populated if (m_searchlist.empty()) { var sorted = m_persistent_data.sorted_list(); m_searchlist.reserve(sorted.size()); foreach (ui_system_info info in sorted) { m_searchlist.emplace_back(new std.pair <double, ui_system_info>(1.0, info)); } } // keep track of what we matched against string ucs_search = ustr_from_utf8(normalize_unicode(m_search, unicode_normalization_form.D, true)); //const std::u32string ucs_search(ustr_from_utf8(normalize_unicode(m_search, unicode_normalization_form::D, true))); // check available search data if (m_persistent_data.is_available(system_list.available.AVAIL_UCS_SHORTNAME)) { m_searched_fields |= (unsigned)system_list.available.AVAIL_UCS_SHORTNAME; } if (m_persistent_data.is_available(system_list.available.AVAIL_UCS_DESCRIPTION)) { m_searched_fields |= (unsigned)system_list.available.AVAIL_UCS_DESCRIPTION; } if (m_persistent_data.is_available(system_list.available.AVAIL_UCS_MANUF_DESC)) { m_searched_fields |= (unsigned)system_list.available.AVAIL_UCS_MANUF_DESC; } if (m_persistent_data.is_available(system_list.available.AVAIL_UCS_DFLT_DESC)) { m_searched_fields |= (unsigned)system_list.available.AVAIL_UCS_DFLT_DESC; } if (m_persistent_data.is_available(system_list.available.AVAIL_UCS_MANUF_DFLT_DESC)) { m_searched_fields |= (unsigned)system_list.available.AVAIL_UCS_MANUF_DFLT_DESC; } for (int i = 0; i < m_searchlist.Count; i++) //for (std::pair<double, std::reference_wrapper<ui_system_info const> > &info : m_searchlist) { var info = m_searchlist[i]; m_searchlist[i] = std.make_pair(1.0, info.second); ui_system_info sys = info.second; // match shortnames if ((m_searched_fields & (unsigned)system_list.available.AVAIL_UCS_SHORTNAME) != 0) { m_searchlist[i] = std.make_pair(util.edit_distance(ucs_search, sys.ucs_shortname), info.second); } // match reading if (info.first != 0 && !sys.ucs_reading_description.empty()) { m_searchlist[i] = std.make_pair(std.min(util.edit_distance(ucs_search, sys.ucs_reading_description), info.first), info.second); // match "<manufacturer> <reading>" if (info.first != 0) { m_searchlist[i] = std.make_pair(std.min(util.edit_distance(ucs_search, sys.ucs_manufacturer_reading_description), info.first), info.second); } } // match descriptions if (info.first != 0 && (m_searched_fields & (unsigned)system_list.available.AVAIL_UCS_DESCRIPTION) != 0) { m_searchlist[i] = std.make_pair(std.min(util.edit_distance(ucs_search, sys.ucs_description), info.first), info.second); } // match "<manufacturer> <description>" if (info.first != 0 && (m_searched_fields & (unsigned)system_list.available.AVAIL_UCS_MANUF_DESC) != 0) { m_searchlist[i] = std.make_pair(std.min(util.edit_distance(ucs_search, sys.ucs_manufacturer_description), info.first), info.second); } // match default description if (info.first != 0 && (m_searched_fields & (unsigned)system_list.available.AVAIL_UCS_DFLT_DESC) != 0 && !sys.ucs_default_description.empty()) { m_searchlist[i] = std.make_pair(std.min(util.edit_distance(ucs_search, sys.ucs_default_description), info.first), info.second); // match "<manufacturer> <default description>" if (info.first != 0 && (m_searched_fields & (unsigned)system_list.available.AVAIL_UCS_MANUF_DFLT_DESC) != 0) { m_searchlist[i] = std.make_pair(std.min(util.edit_distance(ucs_search, sys.ucs_manufacturer_default_description), info.first), info.second); } } } // sort according to edit distance //std::stable_sort( // m_searchlist.begin(), // m_searchlist.end()); // [] (auto const &lhs, auto const &rhs) { return lhs.first < rhs.first; }); m_searchlist.Sort((lhs, rhs) => { return(lhs.first.CompareTo(rhs.first)); }); }