summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author AJR <ajrhacker@users.noreply.github.com>2020-08-30 23:34:27 -0400
committer AJR <ajrhacker@users.noreply.github.com>2020-08-30 23:34:27 -0400
commit35f708384dc57f32631c6745ec3f76eacda5df45 (patch)
tree951a363b382b610c2489c30f1965c0b790d1fc43
parent261b73f5264c210e36862463d93de93e9003deb6 (diff)
ioport: Transfer crosshair polling loop to render_crosshair
-rw-r--r--src/emu/crsshair.cpp46
-rw-r--r--src/emu/crsshair.h1
-rw-r--r--src/emu/ioport.cpp56
-rw-r--r--src/emu/ioport.h18
4 files changed, 60 insertions, 61 deletions
diff --git a/src/emu/crsshair.cpp b/src/emu/crsshair.cpp
index a39782bcd63..6145e668a23 100644
--- a/src/emu/crsshair.cpp
+++ b/src/emu/crsshair.cpp
@@ -223,6 +223,50 @@ void render_crosshair::create_bitmap()
//-------------------------------------------------
+// update_position - update the crosshair values
+// for the given player
+//-------------------------------------------------
+
+void render_crosshair::update_position()
+{
+ // read all the lightgun values
+ bool gotx = false, goty = false;
+ for (auto &port : m_machine.ioport().ports())
+ for (ioport_field &field : port.second->fields())
+ if (field.player() == m_player && field.crosshair_axis() != CROSSHAIR_AXIS_NONE && field.enabled())
+ {
+ // handle X axis
+ if (field.crosshair_axis() == CROSSHAIR_AXIS_X)
+ {
+ m_x = field.crosshair_read();
+ gotx = true;
+ if (field.crosshair_altaxis() != 0)
+ {
+ m_y = field.crosshair_altaxis();
+ goty = true;
+ }
+ }
+
+ // handle Y axis
+ else
+ {
+ m_y = field.crosshair_read();
+ goty = true;
+ if (field.crosshair_altaxis() != 0)
+ {
+ m_x = field.crosshair_altaxis();
+ gotx = true;
+ }
+ }
+
+ // if we got both, stop
+ if (gotx && goty)
+ return;
+ }
+}
+
+
+//-------------------------------------------------
// animate - update the crosshair state
//-------------------------------------------------
@@ -230,7 +274,7 @@ void render_crosshair::animate(u16 auto_time)
{
// read all the port values
if (m_used)
- m_machine.ioport().crosshair_position(m_player, m_x, m_y);
+ update_position();
// auto visibility
if (m_mode == CROSSHAIR_VISIBILITY_AUTO)
diff --git a/src/emu/crsshair.h b/src/emu/crsshair.h
index 05be9e08c30..c2fbbf97ea5 100644
--- a/src/emu/crsshair.h
+++ b/src/emu/crsshair.h
@@ -74,6 +74,7 @@ public:
private:
// private helpers
void create_bitmap();
+ void update_position();
// private state
running_machine & m_machine; // reference to our machine
diff --git a/src/emu/ioport.cpp b/src/emu/ioport.cpp
index cd8f49fe0d6..f406ee6420b 100644
--- a/src/emu/ioport.cpp
+++ b/src/emu/ioport.cpp
@@ -1193,17 +1193,17 @@ void ioport_field::frame_update(ioport_value &result)
//-------------------------------------------------
-// crosshair_position - compute the crosshair
+// crosshair_read - compute the crosshair
// position
//-------------------------------------------------
-void ioport_field::crosshair_position(float &x, float &y, bool &gotx, bool &goty)
+float ioport_field::crosshair_read()
{
- double value = m_live->analog->crosshair_read();
+ float value = m_live->analog->crosshair_read();
// apply the scale and offset
if (m_crosshair_scale < 0)
- value = -(1.0 - value) * m_crosshair_scale;
+ value = -(1.0f - value) * m_crosshair_scale;
else
value *= m_crosshair_scale;
value += m_crosshair_offset;
@@ -1212,29 +1212,7 @@ void ioport_field::crosshair_position(float &x, float &y, bool &gotx, bool &goty
if (!m_crosshair_mapper.isnull())
value = m_crosshair_mapper(value);
- // handle X axis
- if (m_crosshair_axis == CROSSHAIR_AXIS_X)
- {
- x = value;
- gotx = true;
- if (m_crosshair_altaxis != 0)
- {
- y = m_crosshair_altaxis;
- goty = true;
- }
- }
-
- // handle Y axis
- else
- {
- y = value;
- goty = true;
- if (m_crosshair_altaxis != 0)
- {
- x = m_crosshair_altaxis;
- gotx = true;
- }
- }
+ return value;
}
@@ -1966,30 +1944,6 @@ int ioport_manager::count_players() const noexcept
//-------------------------------------------------
-// crosshair_position - return the extracted
-// crosshair values for the given player
-//-------------------------------------------------
-
-bool ioport_manager::crosshair_position(int player, float &x, float &y)
-{
- // read all the lightgun values
- bool gotx = false, goty = false;
- for (auto &port : m_portlist)
- for (ioport_field &field : port.second->fields())
- if (field.player() == player && field.crosshair_axis() != CROSSHAIR_AXIS_NONE && field.enabled())
- {
- field.crosshair_position(x, y, gotx, goty);
-
- // if we got both, stop
- if (gotx && goty)
- break;
- }
-
- return (gotx && goty);
-}
-
-
-//-------------------------------------------------
// frame_update - core logic for per-frame input
// port updating
//-------------------------------------------------
diff --git a/src/emu/ioport.h b/src/emu/ioport.h
index f8b1e1baf3a..9df5e8f533a 100644
--- a/src/emu/ioport.h
+++ b/src/emu/ioport.h
@@ -1059,8 +1059,9 @@ public:
s32 delta() const noexcept { return m_delta; }
s32 centerdelta() const noexcept { return m_centerdelta; }
crosshair_axis_t crosshair_axis() const noexcept { return m_crosshair_axis; }
- double crosshair_scale() const noexcept { return m_crosshair_scale; }
- double crosshair_offset() const noexcept { return m_crosshair_offset; }
+ float crosshair_scale() const noexcept { return m_crosshair_scale; }
+ float crosshair_offset() const noexcept { return m_crosshair_offset; }
+ float crosshair_altaxis() const noexcept { return m_crosshair_altaxis; }
u16 full_turn_count() const noexcept { return m_full_turn_count; }
const ioport_value *remap_table() const noexcept { return m_remap_table; }
@@ -1070,8 +1071,8 @@ public:
ioport_field_live &live() const { assert(m_live != nullptr); return *m_live; }
// setters
- void set_crosshair_scale(double scale) { m_crosshair_scale = scale; }
- void set_crosshair_offset(double offset) { m_crosshair_offset = offset; }
+ void set_crosshair_scale(float scale) { m_crosshair_scale = scale; }
+ void set_crosshair_offset(float offset) { m_crosshair_offset = offset; }
void set_player(u8 player) { m_player = player; }
// derived getters
@@ -1086,7 +1087,7 @@ public:
void select_previous_setting();
bool has_next_setting() const;
void select_next_setting();
- void crosshair_position(float &x, float &y, bool &gotx, bool &goty);
+ float crosshair_read();
void init_live_state(analog_field *analog);
void frame_update(ioport_value &result);
void reduce_mask(ioport_value bits_to_remove) { m_mask &= ~bits_to_remove; }
@@ -1140,9 +1141,9 @@ private:
s32 m_delta; // delta to apply each frame a digital inc/dec key is pressed
s32 m_centerdelta; // delta to apply each frame no digital inputs are pressed
crosshair_axis_t m_crosshair_axis; // crosshair axis
- double m_crosshair_scale; // crosshair scale
- double m_crosshair_offset; // crosshair offset
- double m_crosshair_altaxis;// crosshair alternate axis value
+ float m_crosshair_scale; // crosshair scale
+ float m_crosshair_offset; // crosshair offset
+ float m_crosshair_altaxis;// crosshair alternate axis value
ioport_field_crossmap_delegate m_crosshair_mapper; // crosshair mapping function
u16 m_full_turn_count; // number of optical counts for 1 full turn of the original control
const ioport_value * m_remap_table; // pointer to an array that remaps the port value
@@ -1403,7 +1404,6 @@ public:
// other helpers
digital_joystick &digjoystick(int player, int joysticknum);
int count_players() const noexcept;
- bool crosshair_position(int player, float &x, float &y);
s32 frame_interpolate(s32 oldval, s32 newval);
ioport_type token_to_input_type(const char *string, int &player) const;
std::string input_type_to_token(ioport_type type, int player);