fix: tidy gamepad/overlay/jfile (statics sense sufix, locals UPPER_CASE)

This commit is contained in:
2026-05-16 14:37:56 +02:00
parent 7789c1c217
commit 1e00f5c3a4
3 changed files with 191 additions and 191 deletions
+67 -67
View File
@@ -11,8 +11,8 @@
namespace Gamepad {
static SDL_Gamepad* pad_ = nullptr;
static SDL_JoystickID pad_id_ = 0;
static SDL_Gamepad* pad = nullptr;
static SDL_JoystickID pad_id = 0;
// Emscripten-only: SDL 3.4+ ja no casa el GUID dels mandos web (el gamepad.id
// de Chrome/Android no porta Vendor/Product, el parser extreu valors
@@ -54,9 +54,9 @@ namespace Gamepad {
// elimina espais finals i talla a 25 caràcters.
static auto prettyName(const char* raw) -> std::string {
std::string name = ((raw != nullptr) && (*raw != 0)) ? raw : "Gamepad";
const auto pos = name.find_first_of("([");
if (pos != std::string::npos) {
name.erase(pos);
const auto POS = name.find_first_of("([");
if (POS != std::string::npos) {
name.erase(POS);
}
while (!name.empty() && name.back() == ' ') {
name.pop_back();
@@ -74,16 +74,16 @@ namespace Gamepad {
static constexpr Sint16 STICK_DEADZONE = 12000;
// Estat previ per a detecció de flanc (edge-triggered)
static bool prev_up_ = false;
static bool prev_down_ = false;
static bool prev_left_ = false;
static bool prev_right_ = false;
static bool prev_south_ = false;
static bool prev_east_ = false;
static bool prev_west_ = false;
static bool prev_north_ = false;
static bool prev_start_ = false;
static bool prev_back_ = false;
static bool prev_up = false;
static bool prev_down = false;
static bool prev_left = false;
static bool prev_right = false;
static bool prev_south = false;
static bool prev_east = false;
static bool prev_west = false;
static bool prev_north = false;
static bool prev_start = false;
static bool prev_back = false;
static void notify(const std::string& name, const char* status_key) {
std::string msg = name.empty() ? "Gamepad" : name;
@@ -106,10 +106,10 @@ namespace Gamepad {
if (!SDL_IsGamepad(ids[i])) {
continue;
}
pad_ = SDL_OpenGamepad(ids[i]);
if (pad_ != nullptr) {
pad_id_ = ids[i];
SDL_Log("Gamepad connectat: %s", SDL_GetGamepadName(pad_));
pad = SDL_OpenGamepad(ids[i]);
if (pad != nullptr) {
pad_id = ids[i];
SDL_Log("Gamepad connectat: %s", SDL_GetGamepadName(pad));
break;
}
}
@@ -132,16 +132,16 @@ namespace Gamepad {
}
void destroy() {
if (pad_ != nullptr) {
SDL_CloseGamepad(pad_);
pad_ = nullptr;
pad_id_ = 0;
if (pad != nullptr) {
SDL_CloseGamepad(pad);
pad = nullptr;
pad_id = 0;
}
SDL_QuitSubSystem(SDL_INIT_GAMEPAD);
}
auto isConnected() -> bool {
return pad_ != nullptr;
return pad != nullptr;
}
void handleEvent(const SDL_Event& event) {
@@ -149,27 +149,27 @@ namespace Gamepad {
// GAMEPAD_ADDED) perquè SDL no reconeix el GUID. Escoltem els dos i
// injectem el mapping estàndard abans d'obrir el mando.
if (event.type == SDL_EVENT_GAMEPAD_ADDED || event.type == SDL_EVENT_JOYSTICK_ADDED) {
if (pad_ == nullptr) {
if (pad == nullptr) {
SDL_JoystickID jid = event.jdevice.which;
installWebStandardMapping(jid);
if (!SDL_IsGamepad(jid)) {
return;
}
pad_ = SDL_OpenGamepad(jid);
if (pad_ != nullptr) {
pad_id_ = jid;
std::string name = prettyName(SDL_GetGamepadName(pad_));
pad = SDL_OpenGamepad(jid);
if (pad != nullptr) {
pad_id = jid;
std::string name = prettyName(SDL_GetGamepadName(pad));
SDL_Log("Gamepad connectat: %s", name.c_str());
notifyConnected(name);
}
}
} else if (event.type == SDL_EVENT_GAMEPAD_REMOVED || event.type == SDL_EVENT_JOYSTICK_REMOVED) {
if ((pad_ != nullptr) && event.jdevice.which == pad_id_) {
std::string saved_name = prettyName(SDL_GetGamepadName(pad_));
if ((pad != nullptr) && event.jdevice.which == pad_id) {
std::string saved_name = prettyName(SDL_GetGamepadName(pad));
SDL_Log("Gamepad desconnectat: %s", saved_name.c_str());
SDL_CloseGamepad(pad_);
pad_ = nullptr;
pad_id_ = 0;
SDL_CloseGamepad(pad);
pad = nullptr;
pad_id = 0;
// Neteja qualsevol tecla virtual que poguera estar premuda
JI_SetVirtualKey(SDL_SCANCODE_UP, JI_VSRC_GAMEPAD, false);
JI_SetVirtualKey(SDL_SCANCODE_DOWN, JI_VSRC_GAMEPAD, false);
@@ -196,19 +196,19 @@ namespace Gamepad {
}
void update() {
if (pad_ == nullptr) {
if (pad == nullptr) {
return;
}
// D-pad
bool dup = SDL_GetGamepadButton(pad_, SDL_GAMEPAD_BUTTON_DPAD_UP);
bool ddn = SDL_GetGamepadButton(pad_, SDL_GAMEPAD_BUTTON_DPAD_DOWN);
bool dlt = SDL_GetGamepadButton(pad_, SDL_GAMEPAD_BUTTON_DPAD_LEFT);
bool drt = SDL_GetGamepadButton(pad_, SDL_GAMEPAD_BUTTON_DPAD_RIGHT);
bool dup = SDL_GetGamepadButton(pad, SDL_GAMEPAD_BUTTON_DPAD_UP);
bool ddn = SDL_GetGamepadButton(pad, SDL_GAMEPAD_BUTTON_DPAD_DOWN);
bool dlt = SDL_GetGamepadButton(pad, SDL_GAMEPAD_BUTTON_DPAD_LEFT);
bool drt = SDL_GetGamepadButton(pad, SDL_GAMEPAD_BUTTON_DPAD_RIGHT);
// Stick esquerre amb dead-zone
Sint16 lx = SDL_GetGamepadAxis(pad_, SDL_GAMEPAD_AXIS_LEFTX);
Sint16 ly = SDL_GetGamepadAxis(pad_, SDL_GAMEPAD_AXIS_LEFTY);
Sint16 lx = SDL_GetGamepadAxis(pad, SDL_GAMEPAD_AXIS_LEFTX);
Sint16 ly = SDL_GetGamepadAxis(pad, SDL_GAMEPAD_AXIS_LEFTY);
bool sup = ly < -STICK_DEADZONE;
bool sdn = ly > STICK_DEADZONE;
bool slt = lx < -STICK_DEADZONE;
@@ -220,41 +220,41 @@ namespace Gamepad {
bool rt = drt || srt;
// Botons frontals (layout SDL: SOUTH=A/Cross, EAST=B/Circle, WEST=X/Square, NORTH=Y/Triangle)
bool south = SDL_GetGamepadButton(pad_, SDL_GAMEPAD_BUTTON_SOUTH);
bool east = SDL_GetGamepadButton(pad_, SDL_GAMEPAD_BUTTON_EAST);
bool west = SDL_GetGamepadButton(pad_, SDL_GAMEPAD_BUTTON_WEST);
bool north = SDL_GetGamepadButton(pad_, SDL_GAMEPAD_BUTTON_NORTH);
bool start = SDL_GetGamepadButton(pad_, SDL_GAMEPAD_BUTTON_START);
bool back = SDL_GetGamepadButton(pad_, SDL_GAMEPAD_BUTTON_BACK);
bool south = SDL_GetGamepadButton(pad, SDL_GAMEPAD_BUTTON_SOUTH);
bool east = SDL_GetGamepadButton(pad, SDL_GAMEPAD_BUTTON_EAST);
bool west = SDL_GetGamepadButton(pad, SDL_GAMEPAD_BUTTON_WEST);
bool north = SDL_GetGamepadButton(pad, SDL_GAMEPAD_BUTTON_NORTH);
bool start = SDL_GetGamepadButton(pad, SDL_GAMEPAD_BUTTON_START);
bool back = SDL_GetGamepadButton(pad, SDL_GAMEPAD_BUTTON_BACK);
// Select (Back) → obre/tanca menú de servei (flanc)
if (back && !prev_back_) {
if (back && !prev_back) {
pushKey(KeyConfig::scancode("menu_toggle"));
}
// Start → pausa (flanc)
if (start && !prev_start_) {
if (start && !prev_start) {
pushKey(KeyConfig::scancode("pause_toggle"));
}
if (Menu::isOpen()) {
// Navegació del menú per flanc
if (up && !prev_up_) {
if (up && !prev_up) {
pushKey(SDL_SCANCODE_UP);
}
if (dn && !prev_down_) {
if (dn && !prev_down) {
pushKey(SDL_SCANCODE_DOWN);
}
if (lt && !prev_left_) {
if (lt && !prev_left) {
pushKey(SDL_SCANCODE_LEFT);
}
if (rt && !prev_right_) {
if (rt && !prev_right) {
pushKey(SDL_SCANCODE_RIGHT);
}
// EAST accepta, SOUTH cancela / endarrere
if (east && !prev_east_) {
if (east && !prev_east) {
pushKey(SDL_SCANCODE_RETURN);
}
if (south && !prev_south_) {
if (south && !prev_south) {
pushKey(SDL_SCANCODE_BACKSPACE);
}
@@ -270,22 +270,22 @@ namespace Gamepad {
JI_SetVirtualKey(SDL_SCANCODE_LEFT, JI_VSRC_GAMEPAD, lt);
JI_SetVirtualKey(SDL_SCANCODE_RIGHT, JI_VSRC_GAMEPAD, rt);
// Qualsevol dels 4 botons frontals avança escenes (JI_AnyKey via Enter sintètic)
if ((south && !prev_south_) || (east && !prev_east_) ||
(west && !prev_west_) || (north && !prev_north_)) {
if ((south && !prev_south) || (east && !prev_east) ||
(west && !prev_west) || (north && !prev_north)) {
pushKey(SDL_SCANCODE_RETURN);
}
}
prev_up_ = up;
prev_down_ = dn;
prev_left_ = lt;
prev_right_ = rt;
prev_south_ = south;
prev_east_ = east;
prev_west_ = west;
prev_north_ = north;
prev_start_ = start;
prev_back_ = back;
prev_up = up;
prev_down = dn;
prev_left = lt;
prev_right = rt;
prev_south = south;
prev_east = east;
prev_west = west;
prev_north = north;
prev_start = start;
prev_back = back;
}
} // namespace Gamepad