Skip to content

Commit

Permalink
Added rotation options OFF+FLIP (flipped vertical for handheld portra…
Browse files Browse the repository at this point in the history
…it mode with pad at the bottom) and OFF+CAB.MODE (non-rotated controls for arcade cabs and vertical monitors). Fixed FIT 4/3 option so it works even with rotation, and removed unneeded FIT 3/4 option
  • Loading branch information
rsn8887 committed Feb 7, 2017
1 parent 6bd3133 commit bf922c7
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 80 deletions.
28 changes: 22 additions & 6 deletions pfba/deps/libcross2d/src/3ds/ctr_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ int CTRInput::GetButton(int player) {
return -1;
}

Input::Player *CTRInput::Update(bool rotate) {
Input::Player *CTRInput::Update(int rotate) {

for (int i = 0; i < PLAYER_COUNT; i++) {
players[i].state = 0;
Expand All @@ -82,7 +82,7 @@ Input::Player *CTRInput::Update(bool rotate) {
return players;
}

void CTRInput::process_buttons(Input::Player &player, bool rotate) {
void CTRInput::process_buttons(Input::Player &player, int rotate) {

if (!player.enabled) {
return;
Expand All @@ -98,13 +98,29 @@ void CTRInput::process_buttons(Input::Player &player, bool rotate) {

if (held & BIT(mapping)) {
if (rotate && key_id[i] == Input::Key::KEY_UP) {
player.state |= Input::Key::KEY_RIGHT;
if (rotate == 1) {
player.state |= Input::Key::KEY_RIGHT;
} else if (rotate == 3) {
player.state |= Input::Key::KEY_LEFT;
}
} else if (rotate && key_id[i] == Input::Key::KEY_DOWN) {
player.state |= Input::Key::KEY_LEFT;
if (rotate == 1) {
player.state |= Input::Key::KEY_LEFT;
} else if (rotate == 3) {
player.state |= Input::Key::KEY_RIGHT;
}
} else if (rotate && key_id[i] == Input::Key::KEY_LEFT) {
player.state |= Input::Key::KEY_UP;
if (rotate == 1) {
player.state |= Input::Key::KEY_UP;
} else if (rotate == 3) {
player.state |= Input::Key::KEY_DOWN;
}
} else if (rotate && key_id[i] == Input::Key::KEY_RIGHT) {
player.state |= Input::Key::KEY_DOWN;
if (rotate == 1) {
player.state |= Input::Key::KEY_DOWN;
} else if (rotate == 3) {
player.state |= Input::Key::KEY_UP;
}
} else {
player.state |= key_id[i];
}
Expand Down
4 changes: 2 additions & 2 deletions pfba/deps/libcross2d/src/3ds/ctr_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class CTRInput : Input {
CTRInput();
virtual ~CTRInput();

virtual Player *Update(bool rotate = false);
virtual Player *Update(int rotate = 0);
virtual int GetButton(int player);

private:
virtual void process_buttons(Input::Player &player, bool rotate = false);
virtual void process_buttons(Input::Player &player, int rotate = 0);

};

Expand Down
94 changes: 72 additions & 22 deletions pfba/deps/libcross2d/src/sdl2/sdl2_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ int SDL2Input::GetButton(int player) {
return -1;
}

Input::Player *SDL2Input::Update(bool rotate) {
Input::Player *SDL2Input::Update(int rotate) {

for (int i = 0; i < PLAYER_COUNT; i++) {
players[i].state = 0;
Expand Down Expand Up @@ -116,7 +116,7 @@ Input::Player *SDL2Input::Update(bool rotate) {
return players;
}

void SDL2Input::process_axis(Input::Player &player, bool rotate) {
void SDL2Input::process_axis(Input::Player &player, int rotate) {

if (!player.enabled || !player.data) {
return;
Expand All @@ -126,22 +126,22 @@ void SDL2Input::process_axis(Input::Player &player, bool rotate) {
SDL_JoystickGetAxis((SDL_Joystick *) player.data, player.axis_rx)};

if (x[0] > player.dead_zone || x[1] > player.dead_zone) {
player.state |= rotate ? Input::Key::KEY_DOWN : Input::Key::KEY_RIGHT;
player.state |= (rotate == 1) ? Input::Key::KEY_DOWN : (rotate == 3) ? Input::Key::KEY_UP : Input::Key::KEY_RIGHT;
} else if (x[0] < -player.dead_zone || x[1] < -player.dead_zone) {
player.state |= rotate ? Input::Key::KEY_UP : Input::Key::KEY_LEFT;
player.state |= (rotate == 1) ? Input::Key::KEY_UP : (rotate == 3) ? Input::Key::KEY_DOWN : Input::Key::KEY_LEFT;
}

int y[2] = {SDL_JoystickGetAxis((SDL_Joystick *) player.data, player.axis_ly),
SDL_JoystickGetAxis((SDL_Joystick *) player.data, player.axis_ry)};

if (y[0] > player.dead_zone || y[1] > player.dead_zone) {
player.state |= rotate ? Input::Key::KEY_LEFT : Input::Key::KEY_DOWN;
player.state |= (rotate == 1) ? Input::Key::KEY_LEFT : (rotate == 3) ? Input::Key::KEY_RIGHT : Input::Key::KEY_DOWN;
} else if (y[0] < -player.dead_zone || y[1] < -player.dead_zone) {
player.state |= rotate ? Input::Key::KEY_RIGHT : Input::Key::KEY_UP;
player.state |= (rotate == 1) ? Input::Key::KEY_RIGHT : (rotate == 3) ? Input::Key::KEY_LEFT : Input::Key::KEY_UP;
}
}

void SDL2Input::process_hat(Input::Player &player, bool rotate) {
void SDL2Input::process_hat(Input::Player &player, int rotate) {

if (!player.enabled || !player.data) {
return;
Expand All @@ -152,26 +152,26 @@ void SDL2Input::process_hat(Input::Player &player, bool rotate) {
if (value == SDL_HAT_UP
|| value == SDL_HAT_LEFTUP
|| value == SDL_HAT_RIGHTUP) {
player.state |= rotate ? Input::Key::KEY_RIGHT : Input::Key::KEY_UP;
player.state |= (rotate == 1) ? Input::Key::KEY_RIGHT : (rotate == 3) ? Input::Key::KEY_LEFT : Input::Key::KEY_UP;
}
if (value == SDL_HAT_DOWN
|| value == SDL_HAT_LEFTDOWN
|| value == SDL_HAT_RIGHTDOWN) {
player.state |= rotate ? Input::Key::KEY_LEFT : Input::Key::KEY_DOWN;
player.state |= (rotate == 1) ? Input::Key::KEY_LEFT : (rotate == 3) ? Input::Key::KEY_RIGHT : Input::Key::KEY_DOWN;
}
if (value == SDL_HAT_LEFT
|| value == SDL_HAT_LEFTDOWN
|| value == SDL_HAT_LEFTUP) {
player.state |= rotate ? Input::Key::KEY_UP : Input::Key::KEY_LEFT;
player.state |= (rotate == 1) ? Input::Key::KEY_UP : (rotate == 3) ? Input::Key::KEY_DOWN : Input::Key::KEY_LEFT;
}
if (value == SDL_HAT_RIGHT
|| value == SDL_HAT_RIGHTDOWN
|| value == SDL_HAT_RIGHTUP) {
player.state |= rotate ? Input::Key::KEY_DOWN : Input::Key::KEY_RIGHT;
player.state |= (rotate == 1) ? Input::Key::KEY_DOWN : (rotate == 3) ? Input::Key::KEY_UP : Input::Key::KEY_RIGHT;
}
}

void SDL2Input::process_buttons(Input::Player &player, bool rotate) {
void SDL2Input::process_buttons(Input::Player &player, int rotate) {

if (!player.enabled || !player.data) {
return;
Expand All @@ -183,7 +183,7 @@ void SDL2Input::process_buttons(Input::Player &player, bool rotate) {

#ifdef __PSP2__
// rotate buttons on ps vita to play in portrait mode
if (rotate) {
if (rotate == 1) {
switch (mapping) {
case 2: // PSP2_CROSS (SDL-Vita)
mapping = 1; // PSP2_CIRCLE (SDL-Vita)
Expand All @@ -200,39 +200,89 @@ void SDL2Input::process_buttons(Input::Player &player, bool rotate) {
default:
break;
}
} else if (rotate == 3) {
switch (mapping) {
case 2: // PSP2_CROSS (SDL-Vita)
mapping = 3; // PSP2_SQUARE (SDL-Vita)
break;
case 3: // PSP2_SQUARE (SDL-Vita)
mapping = 0; // PSP2_TRIANGLE (SDL-Vita)
break;
case 0: // PSP2_TRIANGLE (SDL-Vita)
mapping = 1; // PSP2_CIRCLE (SDL-Vita)
break;
case 1: // PSP2_CIRCLE (SDL-Vita)
mapping = 2; // PSP2_CROSS (SDL-Vita)
break;
default:
break;
}
}

#endif

if (SDL_JoystickGetButton((SDL_Joystick *) player.data, mapping)) {
if (rotate && key_id[i] == Input::Key::KEY_UP) {
player.state |= Input::Key::KEY_RIGHT;
if (rotate == 1) {
player.state |= Input::Key::KEY_RIGHT;
} else if (rotate == 3) {
player.state |= Input::Key::KEY_LEFT;
}
} else if (rotate && key_id[i] == Input::Key::KEY_DOWN) {
player.state |= Input::Key::KEY_LEFT;
if (rotate == 1) {
player.state |= Input::Key::KEY_LEFT;
} else if (rotate == 3) {
player.state |= Input::Key::KEY_RIGHT;
}
} else if (rotate && key_id[i] == Input::Key::KEY_LEFT) {
player.state |= Input::Key::KEY_UP;
if (rotate == 1) {
player.state |= Input::Key::KEY_UP;
} else if (rotate == 3) {
player.state |= Input::Key::KEY_DOWN;
}
} else if (rotate && key_id[i] == Input::Key::KEY_RIGHT) {
player.state |= Input::Key::KEY_DOWN;
if (rotate == 1) {
player.state |= Input::Key::KEY_DOWN;
} else if (rotate == 3) {
player.state |= Input::Key::KEY_UP;
}
} else {
player.state |= key_id[i];
}
}
}
}

void SDL2Input::process_keyboard(Input::Player &player, bool rotate) {
void SDL2Input::process_keyboard(Input::Player &player, int rotate) {

const Uint8 *keys = SDL_GetKeyboardState(NULL);

for (int i = 0; i < KEY_COUNT; i++) {
if (keys[keyboard.mapping[i]]) {
if (rotate && key_id[i] == Input::Key::KEY_UP) {
player.state |= Input::Key::KEY_RIGHT;
if (rotate == 1) {
player.state |= Input::Key::KEY_RIGHT;
} else if (rotate == 3) {
player.state |= Input::Key::KEY_LEFT;
}
} else if (rotate && key_id[i] == Input::Key::KEY_DOWN) {
player.state |= Input::Key::KEY_LEFT;
if (rotate == 1) {
player.state |= Input::Key::KEY_LEFT;
} else if (rotate == 3) {
player.state |= Input::Key::KEY_RIGHT;
}
} else if (rotate && key_id[i] == Input::Key::KEY_LEFT) {
player.state |= Input::Key::KEY_UP;
if (rotate == 1) {
player.state |= Input::Key::KEY_UP;
} else if (rotate == 3) {
player.state |= Input::Key::KEY_DOWN;
}
} else if (rotate && key_id[i] == Input::Key::KEY_RIGHT) {
player.state |= Input::Key::KEY_DOWN;
if (rotate == 1) {
player.state |= Input::Key::KEY_DOWN;
} else if (rotate == 3) {
player.state |= Input::Key::KEY_UP;
}
} else {
player.state |= key_id[i];
}
Expand Down
10 changes: 5 additions & 5 deletions pfba/deps/libcross2d/src/sdl2/sdl2_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ class SDL2Input : Input {
SDL2Input();
virtual ~SDL2Input();

virtual Player *Update(bool rotate = false);
virtual Player *Update(int rotate = 0);
virtual int GetButton(int player);

private:
virtual void process_axis(Input::Player& player, bool rotate = false);
virtual void process_hat(Input::Player& player, bool rotate = false);
virtual void process_buttons(Input::Player &player, bool rotate = false);
virtual void process_keyboard(Input::Player& player, bool rotate = false);
virtual void process_axis(Input::Player& player, int rotate = 0);
virtual void process_hat(Input::Player& player, int rotate = 0);
virtual void process_buttons(Input::Player &player, int rotate = 0);
virtual void process_keyboard(Input::Player& player, int rotate = 0);

};

Expand Down
50 changes: 33 additions & 17 deletions pfba/deps/libcross2d/src/sfml/sfml_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ int SFMLInput::GetButton(int player) {
return -1;
}

Input::Player *SFMLInput::Update(bool rotate) {
Input::Player *SFMLInput::Update(int rotate) {

for (int i = 0; i < PLAYER_COUNT; i++) {
players[i].state = 0;
Expand Down Expand Up @@ -125,7 +125,7 @@ Input::Player *SFMLInput::Update(bool rotate) {
return players;
}

void SFMLInput::process_axis(Input::Player &player, bool rotate) {
void SFMLInput::process_axis(Input::Player &player, int rotate) {

if (!player.enabled) {
return;
Expand All @@ -135,24 +135,24 @@ void SFMLInput::process_axis(Input::Player &player, bool rotate) {
if (sf::Joystick::hasAxis(player.id, sf::Joystick::X)) {
int x = (int) sf::Joystick::getAxisPosition(player.id, sf::Joystick::X) * 320;
if (x > player.dead_zone) {
player.state |= rotate ? Input::Key::KEY_DOWN : Input::Key::KEY_RIGHT;
player.state |= (rotate == 1) ? Input::Key::KEY_DOWN : (rotate == 3) ? Input::Key::KEY_UP : Input::Key::KEY_RIGHT;
} else if (x < -player.dead_zone) {
player.state |= rotate ? Input::Key::KEY_UP : Input::Key::KEY_LEFT;
player.state |= (rotate == 1) ? Input::Key::KEY_UP : (rotate == 3) ? Input::Key::KEY_DOWN : Input::Key::KEY_LEFT;
}
}

// Y AXIS
if (sf::Joystick::hasAxis(player.id, sf::Joystick::Y)) {
int y = (int) sf::Joystick::getAxisPosition(player.id, sf::Joystick::Y) * 320;
if (y > player.dead_zone) {
player.state |= rotate ? Input::Key::KEY_LEFT : Input::Key::KEY_DOWN;
player.state |= (rotate == 1) ? Input::Key::KEY_LEFT : (rotate == 3) ? Input::Key::KEY_RIGHT : Input::Key::KEY_DOWN;
} else if (y < -player.dead_zone) {
player.state |= rotate ? Input::Key::KEY_RIGHT : Input::Key::KEY_UP;
player.state |= (rotate == 1) ? Input::Key::KEY_RIGHT : (rotate == 3) ? Input::Key::KEY_LEFT : Input::Key::KEY_UP;
}
}
}

void SFMLInput::process_hat(Input::Player &player, bool rotate) {
void SFMLInput::process_hat(Input::Player &player, int rotate) {

if (!player.enabled) {
return;
Expand All @@ -162,25 +162,25 @@ void SFMLInput::process_hat(Input::Player &player, bool rotate) {
if (sf::Joystick::hasAxis(player.id, sf::Joystick::PovX)) {
int x = (int) sf::Joystick::getAxisPosition(player.id, sf::Joystick::PovX) * 320;
if (x > player.dead_zone) {
player.state |= rotate ? Input::Key::KEY_DOWN : Input::Key::KEY_RIGHT;
player.state |= (rotate == 1) ? Input::Key::KEY_DOWN : (rotate == 3) ? Input::Key::KEY_UP : Input::Key::KEY_RIGHT;
} else if (x < -player.dead_zone) {
player.state |= rotate ? Input::Key::KEY_UP : Input::Key::KEY_LEFT;
player.state |= (rotate == 1) ? Input::Key::KEY_UP : (rotate == 3) ? Input::Key::KEY_DOWN : Input::Key::KEY_LEFT;
}
}

// Y AXIS
if (sf::Joystick::hasAxis(player.id, sf::Joystick::PovY)) {
int y = (int) sf::Joystick::getAxisPosition(player.id, sf::Joystick::PovY) * 320;
if (y > player.dead_zone) {
player.state |= rotate ? Input::Key::KEY_LEFT : Input::Key::KEY_DOWN;
player.state |= (rotate == 1) ? Input::Key::KEY_LEFT : (rotate == 3) ? Input::Key::KEY_RIGHT : Input::Key::KEY_DOWN;
} else if (y < -player.dead_zone) {
player.state |= rotate ? Input::Key::KEY_RIGHT : Input::Key::KEY_UP;
player.state |= (rotate == 1) ? Input::Key::KEY_RIGHT : (rotate == 3) ? Input::Key::KEY_LEFT : Input::Key::KEY_UP;
}
}

}

void SFMLInput::process_buttons(Input::Player &player, bool rotate) {
void SFMLInput::process_buttons(Input::Player &player, int rotate) {

if (!player.enabled) {
return;
Expand All @@ -194,21 +194,37 @@ void SFMLInput::process_buttons(Input::Player &player, bool rotate) {

if (sf::Joystick::isButtonPressed(player.id, mapping)) {
if (rotate && key_id[i] == Input::Key::KEY_UP) {
player.state |= Input::Key::KEY_RIGHT;
if (rotate == 1) {
player.state |= Input::Key::KEY_RIGHT;
} else if (rotate == 3) {
player.state |= Input::Key::KEY_LEFT;
}
} else if (rotate && key_id[i] == Input::Key::KEY_DOWN) {
player.state |= Input::Key::KEY_LEFT;
if (rotate == 1) {
player.state |= Input::Key::KEY_LEFT;
} else if (rotate == 3) {
player.state |= Input::Key::KEY_RIGHT;
}
} else if (rotate && key_id[i] == Input::Key::KEY_LEFT) {
player.state |= Input::Key::KEY_UP;
if (rotate == 1) {
player.state |= Input::Key::KEY_UP;
} else if (rotate == 3) {
player.state |= Input::Key::KEY_DOWN;
}
} else if (rotate && key_id[i] == Input::Key::KEY_RIGHT) {
player.state |= Input::Key::KEY_DOWN;
if (rotate == 1) {
player.state |= Input::Key::KEY_DOWN;
} else if (rotate == 3) {
player.state |= Input::Key::KEY_UP;
}
} else {
player.state |= key_id[i];
}
}
}
}

void SFMLInput::process_keyboard(Input::Player &player, bool rotate) {
void SFMLInput::process_keyboard(Input::Player &player, int rotate) {

for (int i = 0; i < KEY_COUNT; i++) {
sf::Keyboard::Key key((sf::Keyboard::Key) keyboard.mapping[i]);
Expand Down
Loading

0 comments on commit bf922c7

Please sign in to comment.