summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu
diff options
context:
space:
mode:
author AJR <ajrhacker@users.noreply.github.com>2020-08-30 23:32:47 -0400
committer AJR <ajrhacker@users.noreply.github.com>2020-08-30 23:34:02 -0400
commit261b73f5264c210e36862463d93de93e9003deb6 (patch)
tree69057aaa59fd9d6443d386b24df0ca667456de07 /src/emu
parentbb6d7bd43fb1f7611846fed7c10a9215b208c7fa (diff)
Move axis movement checking code down into input devices
Diffstat (limited to 'src/emu')
-rw-r--r--src/emu/input.cpp60
-rw-r--r--src/emu/input.h8
-rw-r--r--src/emu/inputdev.cpp67
-rw-r--r--src/emu/inputdev.h17
4 files changed, 98 insertions, 54 deletions
diff --git a/src/emu/input.cpp b/src/emu/input.cpp
index 10d6f9f5664..36f6e3f5fe6 100644
--- a/src/emu/input.cpp
+++ b/src/emu/input.cpp
@@ -26,9 +26,6 @@
// CONSTANTS
//**************************************************************************
-// invalid memory value for axis polling
-const s32 INVALID_AXIS_VALUE = 0x7fffffff;
-
// additional expanded input codes for sequences
constexpr input_code input_seq::end_code;
constexpr input_code input_seq::default_code;
@@ -738,6 +735,11 @@ input_code input_manager::poll_switches()
{
// iterate over device classes and devices
for (input_device_class devclass = DEVICE_CLASS_FIRST_VALID; devclass <= DEVICE_CLASS_LAST_VALID; ++devclass)
+ {
+ // skip device class if disabled
+ if (!m_class[devclass]->enabled())
+ continue;
+
for (int devnum = 0; devnum <= m_class[devclass]->maxindex(); devnum++)
{
// fetch the device; ignore if nullptr
@@ -763,7 +765,7 @@ input_code input_manager::poll_switches()
}
// skip if there is not enough axis movement
- if (!code_check_axis(*item, code))
+ if (!item->check_axis(code.item_modifier()))
continue;
// otherwise, poll axes digitally
@@ -804,6 +806,7 @@ input_code input_manager::poll_switches()
}
}
}
+ }
// if nothing, return an invalid code
return INPUT_CODE_INVALID;
@@ -845,47 +848,6 @@ input_code input_manager::poll_keyboard_switches()
//-------------------------------------------------
-// code_check_axis - see if axis has moved far
-// enough to trigger a read when polling
-//-------------------------------------------------
-
-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
- s32 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
- s32 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;
-}
-
-
-//-------------------------------------------------
// poll_axes - poll for any input
//-------------------------------------------------
@@ -893,6 +855,11 @@ input_code input_manager::poll_axes()
{
// iterate over device classes and devices
for (input_device_class devclass = DEVICE_CLASS_FIRST_VALID; devclass <= DEVICE_CLASS_LAST_VALID; ++devclass)
+ {
+ // skip device class if disabled
+ if (!m_class[devclass]->enabled())
+ continue;
+
for (int devnum = 0; devnum <= m_class[devclass]->maxindex(); devnum++)
{
// fetch the device; ignore if nullptr
@@ -907,11 +874,12 @@ input_code input_manager::poll_axes()
if (item != nullptr && item->itemclass() != ITEM_CLASS_SWITCH)
{
input_code code = item->code();
- if (code_check_axis(*item, code))
+ if (item->check_axis(code.item_modifier()))
return code;
}
}
}
+ }
// if nothing, return an invalid code
return INPUT_CODE_INVALID;
diff --git a/src/emu/input.h b/src/emu/input.h
index 61f833cfa29..b92bd7ce71f 100644
--- a/src/emu/input.h
+++ b/src/emu/input.h
@@ -31,13 +31,6 @@
// CONSTANTS
//**************************************************************************
-// relative devices return ~512 units per onscreen pixel
-constexpr s32 INPUT_RELATIVE_PER_PIXEL = 512;
-
-// absolute devices return values between -65536 and +65536
-constexpr s32 INPUT_ABSOLUTE_MIN = -65536;
-constexpr s32 INPUT_ABSOLUTE_MAX = 65536;
-
// maximum number of axis/buttons/hats with ITEM_IDs for use by osd layer
constexpr int INPUT_MAX_AXIS = 8;
constexpr int INPUT_MAX_BUTTONS = 32;
@@ -543,7 +536,6 @@ public:
private:
// internal helpers
void reset_memory();
- bool code_check_axis(input_device_item &item, input_code code);
// internal state
running_machine & m_machine;
diff --git a/src/emu/inputdev.cpp b/src/emu/inputdev.cpp
index e29dfe39315..71bf44d8fb5 100644
--- a/src/emu/inputdev.cpp
+++ b/src/emu/inputdev.cpp
@@ -31,6 +31,7 @@ public:
virtual s32 read_as_switch(input_item_modifier modifier) override;
virtual s32 read_as_relative(input_item_modifier modifier) override;
virtual s32 read_as_absolute(input_item_modifier modifier) override;
+ virtual bool item_check_axis(input_item_modifier modifier) override;
// steadykey helper
bool steadykey_changed();
@@ -56,6 +57,7 @@ public:
virtual s32 read_as_switch(input_item_modifier modifier) override;
virtual s32 read_as_relative(input_item_modifier modifier) override;
virtual s32 read_as_absolute(input_item_modifier modifier) override;
+ virtual bool item_check_axis(input_item_modifier modifier) override;
};
@@ -72,6 +74,7 @@ public:
virtual s32 read_as_switch(input_item_modifier modifier) override;
virtual s32 read_as_relative(input_item_modifier modifier) override;
virtual s32 read_as_absolute(input_item_modifier modifier) override;
+ virtual bool item_check_axis(input_item_modifier modifier) override;
};
@@ -699,6 +702,26 @@ input_device_item::~input_device_item()
}
+//-------------------------------------------------
+// check_axis - see if axis has moved far enough
+// to trigger a read when polling
+//-------------------------------------------------
+
+bool input_device_item::check_axis(input_item_modifier modifier)
+{
+ // if we've already reported this one, don't bother
+ if (m_memory == INVALID_AXIS_VALUE)
+ return false;
+
+ if (item_check_axis(modifier))
+ {
+ m_memory = INVALID_AXIS_VALUE;
+ return true;
+ }
+
+ return false;
+}
+
//**************************************************************************
// INPUT DEVICE SWITCH ITEM
@@ -774,6 +797,17 @@ s32 input_device_switch_item::read_as_absolute(input_item_modifier modifier)
//-------------------------------------------------
+// item_check_axis - see if axis has moved far
+// enough to trigger a read when polling
+//-------------------------------------------------
+
+bool input_device_switch_item::item_check_axis(input_item_modifier modifier)
+{
+ return false;
+}
+
+
+//-------------------------------------------------
// steadykey_changed - update for steadykey
// behavior, returning true if the current state
// has changed since the last call
@@ -850,6 +884,20 @@ s32 input_device_relative_item::read_as_absolute(input_item_modifier modifier)
}
+//-------------------------------------------------
+// item_check_axis - see if axis has moved far
+// enough to trigger a read when polling
+//-------------------------------------------------
+
+bool input_device_relative_item::item_check_axis(input_item_modifier modifier)
+{
+ s32 curval = read_as_relative(modifier);
+
+ // for relative axes, look for ~20 pixels movement
+ return std::abs(curval - memory()) > 20 * INPUT_RELATIVE_PER_PIXEL;
+}
+
+
//**************************************************************************
// INPUT DEVICE ABSOLUTE ITEM
@@ -947,3 +995,22 @@ s32 input_device_absolute_item::read_as_absolute(input_item_modifier modifier)
result = std::max(-result, 0) * 2 + INPUT_ABSOLUTE_MIN;
return result;
}
+
+
+//-------------------------------------------------
+// item_check_axis - see if axis has moved far
+// enough to trigger a read when polling
+//-------------------------------------------------
+
+bool input_device_absolute_item::item_check_axis(input_item_modifier modifier)
+{
+ // ignore min/max for lightguns
+ // so the selection will not be affected by a gun going out of range
+ s32 curval = read_as_absolute(modifier);
+ if (m_device.devclass() == DEVICE_CLASS_LIGHTGUN &&
+ (curval == INPUT_ABSOLUTE_MAX || curval == INPUT_ABSOLUTE_MIN))
+ return false;
+
+ // for absolute axes, look for 25% of maximum
+ return (curval - memory()) > (INPUT_ABSOLUTE_MAX - INPUT_ABSOLUTE_MIN) / 4;
+}
diff --git a/src/emu/inputdev.h b/src/emu/inputdev.h
index f6f0027b325..ecae0532be0 100644
--- a/src/emu/inputdev.h
+++ b/src/emu/inputdev.h
@@ -15,6 +15,21 @@
//**************************************************************************
+// CONSTANTS
+//**************************************************************************
+
+// relative devices return ~512 units per onscreen pixel
+constexpr s32 INPUT_RELATIVE_PER_PIXEL = 512;
+
+// absolute devices return values between -65536 and +65536
+constexpr s32 INPUT_ABSOLUTE_MIN = -65536;
+constexpr s32 INPUT_ABSOLUTE_MAX = 65536;
+
+// invalid memory value for axis polling
+constexpr s32 INVALID_AXIS_VALUE = 0x7fffffff;
+
+
+//**************************************************************************
// TYPE DEFINITIONS
//**************************************************************************
@@ -95,11 +110,13 @@ public:
// helpers
s32 update_value();
void set_memory(s32 value) { m_memory = value; }
+ bool check_axis(input_item_modifier modifier);
// readers
virtual s32 read_as_switch(input_item_modifier modifier) = 0;
virtual s32 read_as_relative(input_item_modifier modifier) = 0;
virtual s32 read_as_absolute(input_item_modifier modifier) = 0;
+ virtual bool item_check_axis(input_item_modifier modifier) = 0;
protected:
// internal state