diff options
Diffstat (limited to 'src/input.c')
| -rw-r--r-- | src/input.c | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/src/input.c b/src/input.c index e2c5298..faf4758 100644 --- a/src/input.c +++ b/src/input.c @@ -29,9 +29,38 @@ void pw_input_free(struct pw_input *input) { SDL_free(input); } +bool pw_input_reset(struct pw_input *input, struct pw_players *players) { + if (!input) { + return SDL_InvalidParamError("input"); + } + if (!players) { + return SDL_InvalidParamError("players"); + } + + bool connected[PW_PLAYERS_MAX]; + input->nplayers = pw_players_status(players, connected); + SDL_zeroa(input->players); + + return true; +} + static bool handle_connection(struct pw_input *input, struct pw_players *players) { - input->nplayers = pw_players_count(players); + size_t previous = input->nplayers; + + bool connected[PW_PLAYERS_MAX]; + input->nplayers = pw_players_status(players, connected); + for (size_t i = 0; i < SDL_arraysize(connected); ++i) { + input->players[i] *= (uint8_t)connected[i]; + } + + // We need to clear the button states of player 2 in case it was + // set because of the special POOM handling, and a new controller + // connected. + if (previous == 1 && input->nplayers > 1) { + input->players[1] = 0; + } + return players; } @@ -66,7 +95,7 @@ static bool handle_axis(struct pw_input *input, struct pw_players *players, // Some special POOM handling, which uses both player's inputs for controls. // This allows one player's directions be used for turning, and another for // strafing. - if (!i && pw_players_count(players) == 1) { + if (!i && input->nplayers == 1) { enum pw_button *p2 = &input->players[1]; switch (event->axis) { case SDL_GAMEPAD_AXIS_RIGHTX: |
