mirror of
https://github.com/holub/mame
synced 2025-05-02 04:31:01 +03:00
ioport: Transfer crosshair polling loop to render_crosshair
This commit is contained in:
parent
261b73f526
commit
35f708384d
@ -222,6 +222,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
|
// animate - update the crosshair state
|
||||||
//-------------------------------------------------
|
//-------------------------------------------------
|
||||||
@ -230,7 +274,7 @@ void render_crosshair::animate(u16 auto_time)
|
|||||||
{
|
{
|
||||||
// read all the port values
|
// read all the port values
|
||||||
if (m_used)
|
if (m_used)
|
||||||
m_machine.ioport().crosshair_position(m_player, m_x, m_y);
|
update_position();
|
||||||
|
|
||||||
// auto visibility
|
// auto visibility
|
||||||
if (m_mode == CROSSHAIR_VISIBILITY_AUTO)
|
if (m_mode == CROSSHAIR_VISIBILITY_AUTO)
|
||||||
|
@ -74,6 +74,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
// private helpers
|
// private helpers
|
||||||
void create_bitmap();
|
void create_bitmap();
|
||||||
|
void update_position();
|
||||||
|
|
||||||
// private state
|
// private state
|
||||||
running_machine & m_machine; // reference to our machine
|
running_machine & m_machine; // reference to our machine
|
||||||
|
@ -1193,17 +1193,17 @@ void ioport_field::frame_update(ioport_value &result)
|
|||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------
|
//-------------------------------------------------
|
||||||
// crosshair_position - compute the crosshair
|
// crosshair_read - compute the crosshair
|
||||||
// position
|
// 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
|
// apply the scale and offset
|
||||||
if (m_crosshair_scale < 0)
|
if (m_crosshair_scale < 0)
|
||||||
value = -(1.0 - value) * m_crosshair_scale;
|
value = -(1.0f - value) * m_crosshair_scale;
|
||||||
else
|
else
|
||||||
value *= m_crosshair_scale;
|
value *= m_crosshair_scale;
|
||||||
value += m_crosshair_offset;
|
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())
|
if (!m_crosshair_mapper.isnull())
|
||||||
value = m_crosshair_mapper(value);
|
value = m_crosshair_mapper(value);
|
||||||
|
|
||||||
// handle X axis
|
return value;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1965,30 +1943,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
|
// frame_update - core logic for per-frame input
|
||||||
// port updating
|
// port updating
|
||||||
|
@ -1059,8 +1059,9 @@ public:
|
|||||||
s32 delta() const noexcept { return m_delta; }
|
s32 delta() const noexcept { return m_delta; }
|
||||||
s32 centerdelta() const noexcept { return m_centerdelta; }
|
s32 centerdelta() const noexcept { return m_centerdelta; }
|
||||||
crosshair_axis_t crosshair_axis() const noexcept { return m_crosshair_axis; }
|
crosshair_axis_t crosshair_axis() const noexcept { return m_crosshair_axis; }
|
||||||
double crosshair_scale() const noexcept { return m_crosshair_scale; }
|
float crosshair_scale() const noexcept { return m_crosshair_scale; }
|
||||||
double crosshair_offset() const noexcept { return m_crosshair_offset; }
|
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; }
|
u16 full_turn_count() const noexcept { return m_full_turn_count; }
|
||||||
const ioport_value *remap_table() const noexcept { return m_remap_table; }
|
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; }
|
ioport_field_live &live() const { assert(m_live != nullptr); return *m_live; }
|
||||||
|
|
||||||
// setters
|
// setters
|
||||||
void set_crosshair_scale(double scale) { m_crosshair_scale = scale; }
|
void set_crosshair_scale(float scale) { m_crosshair_scale = scale; }
|
||||||
void set_crosshair_offset(double offset) { m_crosshair_offset = offset; }
|
void set_crosshair_offset(float offset) { m_crosshair_offset = offset; }
|
||||||
void set_player(u8 player) { m_player = player; }
|
void set_player(u8 player) { m_player = player; }
|
||||||
|
|
||||||
// derived getters
|
// derived getters
|
||||||
@ -1086,7 +1087,7 @@ public:
|
|||||||
void select_previous_setting();
|
void select_previous_setting();
|
||||||
bool has_next_setting() const;
|
bool has_next_setting() const;
|
||||||
void select_next_setting();
|
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 init_live_state(analog_field *analog);
|
||||||
void frame_update(ioport_value &result);
|
void frame_update(ioport_value &result);
|
||||||
void reduce_mask(ioport_value bits_to_remove) { m_mask &= ~bits_to_remove; }
|
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_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
|
s32 m_centerdelta; // delta to apply each frame no digital inputs are pressed
|
||||||
crosshair_axis_t m_crosshair_axis; // crosshair axis
|
crosshair_axis_t m_crosshair_axis; // crosshair axis
|
||||||
double m_crosshair_scale; // crosshair scale
|
float m_crosshair_scale; // crosshair scale
|
||||||
double m_crosshair_offset; // crosshair offset
|
float m_crosshair_offset; // crosshair offset
|
||||||
double m_crosshair_altaxis;// crosshair alternate axis value
|
float m_crosshair_altaxis;// crosshair alternate axis value
|
||||||
ioport_field_crossmap_delegate m_crosshair_mapper; // crosshair mapping function
|
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
|
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
|
const ioport_value * m_remap_table; // pointer to an array that remaps the port value
|
||||||
@ -1403,7 +1404,6 @@ public:
|
|||||||
// other helpers
|
// other helpers
|
||||||
digital_joystick &digjoystick(int player, int joysticknum);
|
digital_joystick &digjoystick(int player, int joysticknum);
|
||||||
int count_players() const noexcept;
|
int count_players() const noexcept;
|
||||||
bool crosshair_position(int player, float &x, float &y);
|
|
||||||
s32 frame_interpolate(s32 oldval, s32 newval);
|
s32 frame_interpolate(s32 oldval, s32 newval);
|
||||||
ioport_type token_to_input_type(const char *string, int &player) const;
|
ioport_type token_to_input_type(const char *string, int &player) const;
|
||||||
std::string input_type_to_token(ioport_type type, int player);
|
std::string input_type_to_token(ioport_type type, int player);
|
||||||
|
Loading…
Reference in New Issue
Block a user