bool input_manager::code_check_axis(input_device_item &item, input_code code) { // if we've already reported this one, don't bother if (item.memory() == INVALID_AXIS_VALUE) return false; // ignore min/max for lightguns // so the selection will not be affected by a gun going out of range int32_t curval = code_value(code); if (code.device_class() == DEVICE_CLASS_LIGHTGUN && (code.item_id() == ITEM_ID_XAXIS || code.item_id() == ITEM_ID_YAXIS) && (curval == INPUT_ABSOLUTE_MAX || curval == INPUT_ABSOLUTE_MIN)) return false; // compute the diff against memory int32_t diff = curval - item.memory(); if (diff < 0) diff = -diff; // for absolute axes, look for 25% of maximum if (item.itemclass() == ITEM_CLASS_ABSOLUTE && diff > (INPUT_ABSOLUTE_MAX - INPUT_ABSOLUTE_MIN) / 4) { item.set_memory(INVALID_AXIS_VALUE); return true; } // for relative axes, look for ~20 pixels movement if (item.itemclass() == ITEM_CLASS_RELATIVE && diff > 20 * INPUT_RELATIVE_PER_PIXEL) { item.set_memory(INVALID_AXIS_VALUE); return true; } return false; }
int keyboard_trans_table::vkey_for_mame_code(input_code code) const { // only works for keyboard switches if (code.device_class() == DEVICE_CLASS_KEYBOARD && code.item_class() == ITEM_CLASS_SWITCH) { input_item_id id = code.item_id(); int tablenum; // scan the table for a match for (tablenum = 0; tablenum < m_table_size; tablenum++) if (m_table[tablenum].mame_key == id) return m_table[tablenum].virtual_key; } return 0; }
std::string input_manager::code_to_token(input_code code) const { // determine the devclass part const char *devclass = (*devclass_token_table)[code.device_class()]; // determine the devindex part; keyboard 0 doesn't show an index std::string devindex = string_format("%d", code.device_index() + 1); if (code.device_class() == DEVICE_CLASS_KEYBOARD && code.device_index() == 0) devindex.clear(); // determine the itemid part; look up in the table if we don't have a token input_device_item *item = item_from_code(code); const char *devcode = (item != nullptr) ? item->token() : "UNKNOWN"; // determine the modifier part const char *modifier = (*modifier_token_table)[code.item_modifier()]; // determine the itemclass part; if we match the native class, we don't include this const char *itemclass = ""; if (item == nullptr || item->itemclass() != code.item_class()) itemclass = (*itemclass_token_table)[code.item_class()]; // concatenate the strings std::string str(devclass); if (!devindex.empty()) str.append("_").append(devindex); if (devcode[0] != 0) str.append("_").append(devcode); if (modifier != nullptr) str.append("_").append(modifier); if (itemclass[0] != 0) str.append("_").append(itemclass); return str; }
std::string input_manager::code_name(input_code code) const { // if nothing there, return an empty string input_device_item *item = item_from_code(code); if (item == nullptr) return std::string(); // determine the devclass part const char *devclass = (*devclass_string_table)[code.device_class()]; // determine the devindex part std::string devindex = string_format("%d", code.device_index() + 1); // if we're unifying all devices, don't display a number if (!m_class[code.device_class()]->multi()) devindex.clear(); // keyboard 0 doesn't show a class or index if it is the only one input_device_class device_class = item->device().devclass(); if (device_class == DEVICE_CLASS_KEYBOARD && m_class[device_class]->maxindex() == 0) { devclass = ""; devindex.clear(); } // devcode part comes from the item name const char *devcode = item->name(); // determine the modifier part const char *modifier = (*modifier_string_table)[code.item_modifier()]; // devcode is redundant with joystick switch left/right/up/down if (device_class == DEVICE_CLASS_JOYSTICK && code.item_class() == ITEM_CLASS_SWITCH) if (code.item_modifier() >= ITEM_MODIFIER_LEFT && code.item_modifier() <= ITEM_MODIFIER_DOWN) devcode = ""; // concatenate the strings std::string str(devclass); if (!devindex.empty()) str.append(" ").append(devindex); if (devcode[0] != 0) str.append(" ").append(devcode); if (modifier != nullptr) str.append(" ").append(modifier); // delete any leading spaces strtrimspace(str); return str; }
int32_t input_manager::code_value(input_code code) { g_profiler.start(PROFILER_INPUT); int32_t result = 0; // dummy loop to allow clean early exits do { // return 0 for any invalid devices input_device *device = device_from_code(code); if (device == nullptr) break; // also return 0 if the device class is disabled input_class &devclass = *m_class[code.device_class()]; if (!devclass.enabled()) break; // if this is not a multi device, only return data for item 0 and iterate over all int startindex = code.device_index(); int stopindex = startindex; if (!devclass.multi()) { if (startindex != 0) break; stopindex = devclass.maxindex(); } // iterate over all device indices input_item_class targetclass = code.item_class(); for (int curindex = startindex; curindex <= stopindex; curindex++) { // lookup the item for the appropriate index code.set_device_index(curindex); input_device_item *item = item_from_code(code); if (item == nullptr) continue; // process items according to their native type switch (targetclass) { case ITEM_CLASS_ABSOLUTE: if (result == 0) result = item->read_as_absolute(code.item_modifier()); break; case ITEM_CLASS_RELATIVE: result += item->read_as_relative(code.item_modifier()); break; case ITEM_CLASS_SWITCH: result |= item->read_as_switch(code.item_modifier()); break; default: break; } } } while (0); // stop the profiler before exiting g_profiler.stop(); return result; }