diff options
| author | 2016-09-20 12:19:58 -0700 | |
|---|---|---|
| committer | 2016-09-20 12:19:58 -0700 | |
| commit | 845b36dae268242ab4a103ceb39520efdfa89018 (patch) | |
| tree | eca831bad8973be7ba3f449f16185619088c50a3 /src/emu/input.cpp | |
| parent | 32ea8266a31080330a6fd84208997dc24b7368fc (diff) | |
Adding id() property to input_device
This change adds id() property to input_device, which represents the
unique device id. This allows the osd layer when creating a device to
pass a friendly display name along with a unique identifier.
Currently the device id is only used to map a physical controller device
to controller id, but can be used more generally in the future. For raw
input devices, we use the full raw input name as the device id. For all
other devices, we fall back to device name as the device id. The
"uniqueness" of the device id is not currently enforced in code.
Diffstat (limited to 'src/emu/input.cpp')
| -rw-r--r-- | src/emu/input.cpp | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/src/emu/input.cpp b/src/emu/input.cpp index 2a65ff4c688..4c8aad97307 100644 --- a/src/emu/input.cpp +++ b/src/emu/input.cpp @@ -794,9 +794,10 @@ void input_seq::replace(input_code oldcode, input_code newcode) // input_device - constructor //------------------------------------------------- -input_device::input_device(input_class &_class, int devindex, const char *name, void *internal) +input_device::input_device(input_class &_class, int devindex, const char *name, const char *id, void *internal) : m_class(_class), m_name(name), + m_id(id), m_devindex(devindex), m_maxitem(input_item_id(0)), m_internal(internal), @@ -942,19 +943,19 @@ void input_device::apply_steadykey() const } //------------------------------------------------- -// match_device_name - match device name via +// match_device_id - match device id via // substring search //------------------------------------------------- -bool input_device::match_device_name(const char *devicename) +bool input_device::match_device_id(const char *deviceid) { - std::string devicenameupper(devicename); - std::string nameupper(m_name); + std::string deviceidupper(deviceid); + std::string idupper(m_id); - strmakeupper(devicenameupper); - strmakeupper(nameupper); + strmakeupper(deviceidupper); + strmakeupper(idupper); - return std::string::npos == nameupper.find(devicenameupper) ? false : true; + return std::string::npos == idupper.find(deviceidupper) ? false : true; } @@ -983,7 +984,7 @@ input_class::input_class(input_manager &manager, input_device_class devclass, bo // add_device - add a new input device //------------------------------------------------- -input_device *input_class::add_device(const char *name, void *internal) +input_device *input_class::add_device(const char *name, const char *id, void *internal) { // find the next empty index int devindex; @@ -992,23 +993,28 @@ input_device *input_class::add_device(const char *name, void *internal) break; // call through - return add_device(devindex, name, internal); + return add_device(devindex, name, id, internal); } -input_device *input_class::add_device(int devindex, const char *name, void *internal) +input_device *input_class::add_device(int devindex, const char *name, const char *id, void *internal) { assert_always(machine().phase() == MACHINE_PHASE_INIT, "Can only call input_class::add_device at init time!"); assert(name != nullptr); + assert(id != nullptr); assert(devindex >= 0 && devindex < DEVICE_INDEX_MAXIMUM); assert(m_device[devindex] == nullptr); // allocate a new device - m_device[devindex] = std::make_unique<input_device>(*this, devindex, name, internal); + m_device[devindex] = std::make_unique<input_device>(*this, devindex, name, id, internal); // update the maximum index found m_maxindex = std::max(m_maxindex, devindex); - osd_printf_verbose("Input: Adding %s #%d: %s\n", (*devclass_string_table)[m_devclass], devindex, name); + if (0 == strlen(id)) + osd_printf_verbose("Input: Adding %s #%d: %s\n", (*devclass_string_table)[m_devclass], devindex, name); + else + osd_printf_verbose("Input: Adding %s #%d: %s (device id: %s)\n", (*devclass_string_table)[m_devclass], devindex, name, id); + return m_device[devindex].get(); } @@ -2111,7 +2117,7 @@ bool input_manager::map_device_to_controller(const devicemap_table_type *devicem for (devicemap_table_type::const_iterator it = devicemap_table->begin(); it != devicemap_table->end(); it++) { - const char *devicename = it->first.c_str(); + const char *deviceid = it->first.c_str(); const char *controllername = it->second.c_str(); // tokenize the controller name into device class and index (i.e. controller name should be of the form "GUNCODE_1") @@ -2151,11 +2157,12 @@ bool input_manager::map_device_to_controller(const devicemap_table_type *devicem for (int devnum = 0; devnum <= input_devclass->maxindex(); devnum++) { input_device *device = input_devclass->device(devnum); - if (device != nullptr && device->match_device_name(devicename)) + if (device != nullptr && device->match_device_id(deviceid)) { // remap devindex input_devclass->remap_device_index(device->devindex(), devindex); - osd_printf_verbose("Input: Remapped %s #%d: %s\n", (*devclass_string_table)[input_devclass->devclass()], devindex, device->name()); + osd_printf_verbose("Input: Remapped %s #%d: %s (device id: %s)\n", (*devclass_string_table)[input_devclass->devclass()], devindex, device->name(), device->id()); + break; } } |
