mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-21 12:29:18 +02:00
build 191212. gamepad input configuration support, minor bug fixes
This commit is contained in:
@@ -16,7 +16,7 @@ class gamepad_input {
|
||||
|
||||
public:
|
||||
// constructors
|
||||
gamepad_input();
|
||||
gamepad_input() = default;
|
||||
|
||||
// methods
|
||||
// checks state of the controls and sends issued commands
|
||||
@@ -27,6 +27,7 @@ public:
|
||||
|
||||
private:
|
||||
// types
|
||||
/*
|
||||
enum gamepad_button {
|
||||
a,
|
||||
b,
|
||||
@@ -51,34 +52,43 @@ private:
|
||||
lefttrigger,
|
||||
righttrigger
|
||||
};
|
||||
enum class control_mode {
|
||||
entity = -1,
|
||||
vehicle_mastercontroller,
|
||||
vehicle_trainbrake,
|
||||
vehicle_secondarycontroller,
|
||||
vehicle_independentbrake
|
||||
*/
|
||||
enum class input_type {
|
||||
threestate, // two commands, mapped to positive and negative axis value respectively; press and release events on state change
|
||||
impulse, // one command; press event when set, release when cleared
|
||||
value, // one command; press event, axis value passed as specified param (stored as second 'user_command')
|
||||
value_invert // the passed value is additionally multiplied by -1
|
||||
};
|
||||
typedef std::vector<float> float_sequence;
|
||||
typedef std::vector<char> char_sequence;
|
||||
typedef std::vector< std::pair< user_command, user_command > > commandpair_sequence;
|
||||
|
||||
struct input_button {
|
||||
unsigned char state; // last polled state
|
||||
int mode; // associated control mode
|
||||
user_command binding; // associated command
|
||||
};
|
||||
|
||||
struct input_axis {
|
||||
float state; // last polled state
|
||||
float accumulator; // multipurpose helper variable
|
||||
std::unordered_map< int, std::tuple< input_type, user_command, user_command > > bindings; // associated commands for respective modes
|
||||
};
|
||||
|
||||
using inputbutton_sequence = std::vector<input_button>;
|
||||
using inputaxis_sequence = std::vector<input_axis>;
|
||||
// methods
|
||||
void on_button( gamepad_button const Button, int const Action );
|
||||
void process_axes( glm::vec2 Leftstick, glm::vec2 const &Rightstick, glm::vec2 const &Triggers );
|
||||
void process_mode( float const Value, std::uint16_t const Recipient );
|
||||
bool recall_bindings();
|
||||
void bind( std::vector< std::reference_wrapper<user_command> > &Targets, cParser &Input, std::unordered_map<std::string, user_command> const &Translator, std::string const Point );
|
||||
void on_button( int const Button, int const Action );
|
||||
void process_axes();
|
||||
|
||||
// members
|
||||
command_relay m_relay;
|
||||
float_sequence m_axes;
|
||||
char_sequence m_buttons;
|
||||
inputbutton_sequence m_inputbuttons;
|
||||
inputaxis_sequence m_inputaxes;
|
||||
int m_deviceid{ -1 };
|
||||
control_mode m_mode{ control_mode::entity };
|
||||
commandpair_sequence m_modecommands; // sets of commands issued depending on the active control mode
|
||||
int m_mode{ -1 }; // currently active control mode
|
||||
float m_deadzone{ 0.15f }; // TODO: allow to configure this
|
||||
glm::vec2 m_leftstick;
|
||||
glm::vec2 m_rightstick;
|
||||
glm::vec2 m_triggers;
|
||||
double m_modeaccumulator{ 0.0 }; // used to throttle command input rate for vehicle controls
|
||||
// double m_modeaccumulator{ 0.0 }; // used to throttle command input rate for vehicle controls
|
||||
std::unordered_map< user_command, std::tuple<double, double> > m_lastcommandparams; // cached parameters for last issued command of given type
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user