Skip to content
Snippets Groups Projects
Commit 8b0537d6 authored by Joseph Walton-Rivers's avatar Joseph Walton-Rivers
Browse files

add controller name support

parent 5792db23
No related branches found
No related tags found
No related merge requests found
Pipeline #3040 failed
......@@ -292,7 +292,7 @@ int main(int argc, char* argv[]) {
auto& gamepads = inputs->gamepads;
ImGui::Begin("GamePad", &gamepadWindow);
for ( int i=0; i<16; i++ ) {
std::string title = "GamePad " + std::to_string(i);
std::string title = gamepads.name(i);
bool present = gamepads.present(i);
if ( ImGui::TreeNode(title.c_str()) ) {
......
......@@ -49,12 +49,13 @@ static void fggl_input_keyboard(GLFWwindow* window, int key, int scancode, int a
}
static void fggl_update_joystick(fggl::input::GamepadInput& input, int jid) {
//glfwGetJoystickName(jid);
bool isGamepad = glfwJoystickIsGamepad(jid);
if ( isGamepad ) {
if( !input.present(jid) ) {
std::string name = glfwGetJoystickName(jid);
input.setActive(jid, true);
input.name(jid, name);
}
GLFWgamepadstate state;
......
......@@ -108,6 +108,19 @@ namespace fggl::input {
return m_active[id];
}
inline void name(size_t id, const std::string& name) {
assert( id < MaxControllers );
m_names[id] = name;
}
inline std::string name(size_t id) const {
std::string name = m_names[id].empty() ? "gamepad "+std::to_string(id) : m_names[id];
if ( !present(id) ) {
return name + " (disconnected)";
}
return name;
}
inline float axis(size_t id, GamepadAxis axis) const {
if ( !present(id) ) {
return 0.0f;
......@@ -166,6 +179,7 @@ namespace fggl::input {
private:
std::bitset<MaxControllers> m_active;
std::array<std::string, MaxControllers> m_names;
std::array<GamepadState, MaxControllers> m_current;
std::array<GamepadState, MaxControllers> m_previous;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment