summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/inputdev.cpp
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/inputdev.cpp
parentbb6d7bd43fb1f7611846fed7c10a9215b208c7fa (diff)
Move axis movement checking code down into input devices
Diffstat (limited to 'src/emu/inputdev.cpp')
-rw-r--r--src/emu/inputdev.cpp67
1 files changed, 67 insertions, 0 deletions
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;
+}