tidy-fix automàtic (sense naming)
This commit is contained in:
+45
-22
@@ -1,5 +1,6 @@
|
||||
#include "core/jail/jinput.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
#include "core/system/director.hpp"
|
||||
@@ -19,7 +20,7 @@ namespace {
|
||||
// Temps restant en mil·lisegons durant el qual JI_KeyPressed/JI_AnyKey
|
||||
// retornen false. Utilitzat per a evitar que pulsacions fortuïtes
|
||||
// saltin cinemàtiques al començament.
|
||||
float wait_ms = 0.0f;
|
||||
float wait_ms = 0.0F;
|
||||
|
||||
// Per a calcular el delta entre crides a JI_Update sense que els callers
|
||||
// hagen de passar-lo explícitament. Es reinicia a la primera crida.
|
||||
@@ -29,7 +30,7 @@ namespace {
|
||||
|
||||
Uint8 virtual_keystates[JI_VSRC_COUNT][SDL_SCANCODE_COUNT] = {{0}};
|
||||
|
||||
Uint8 scancode_to_ascii(Uint8 scancode) {
|
||||
auto scancode_to_ascii(Uint8 scancode) -> Uint8 {
|
||||
if (scancode >= SDL_SCANCODE_A && scancode <= SDL_SCANCODE_Z) {
|
||||
return static_cast<Uint8>('a' + (scancode - SDL_SCANCODE_A));
|
||||
}
|
||||
@@ -47,8 +48,12 @@ void JI_SetInputBlocked(bool blocked) {
|
||||
}
|
||||
|
||||
void JI_SetVirtualKey(int scancode, int source, bool pressed) {
|
||||
if (scancode < 0 || scancode >= SDL_SCANCODE_COUNT) return;
|
||||
if (source < 0 || source >= JI_VSRC_COUNT) return;
|
||||
if (scancode < 0 || scancode >= SDL_SCANCODE_COUNT) {
|
||||
return;
|
||||
}
|
||||
if (source < 0 || source >= JI_VSRC_COUNT) {
|
||||
return;
|
||||
}
|
||||
virtual_keystates[source][scancode] = pressed ? 1 : 0;
|
||||
}
|
||||
|
||||
@@ -64,49 +69,67 @@ void JI_Update() {
|
||||
// El director ha processat tots els events. Ací només refresquem
|
||||
// el snapshot del teclat i consumim el flag de tecla polsada.
|
||||
if (keystates == nullptr) {
|
||||
keystates = SDL_GetKeyboardState(NULL);
|
||||
keystates = SDL_GetKeyboardState(nullptr);
|
||||
}
|
||||
|
||||
const Uint64 now = SDL_GetTicks();
|
||||
if (last_update_tick == 0) last_update_tick = now;
|
||||
const float delta_ms = static_cast<float>(now - last_update_tick);
|
||||
if (last_update_tick == 0) {
|
||||
last_update_tick = now;
|
||||
}
|
||||
const auto delta_ms = static_cast<float>(now - last_update_tick);
|
||||
last_update_tick = now;
|
||||
|
||||
if (wait_ms > 0.0f) {
|
||||
if (wait_ms > 0.0F) {
|
||||
wait_ms -= delta_ms;
|
||||
if (wait_ms < 0.0f) wait_ms = 0.0f;
|
||||
wait_ms = std::max(wait_ms, 0.0f);
|
||||
}
|
||||
|
||||
// Consumim el flag de "alguna tecla no-GUI polsada" del director
|
||||
key_pressed = Director::get()->consumeKeyPressed();
|
||||
}
|
||||
|
||||
bool JI_KeyPressed(int key) {
|
||||
if (wait_ms > 0.0f || keystates == nullptr) return false;
|
||||
auto JI_KeyPressed(int key) -> bool {
|
||||
if (wait_ms > 0.0F || keystates == nullptr) {
|
||||
return false;
|
||||
}
|
||||
// Input bloquejat (p.ex. menú flotant obert)
|
||||
if (input_blocked) return false;
|
||||
if (input_blocked) {
|
||||
return false;
|
||||
}
|
||||
// ESC bloquejada pel Director (primera pulsació mostra notificació)
|
||||
if (key == SDL_SCANCODE_ESCAPE && Director::get()->isEscBlocked()) return false;
|
||||
if (key < 0 || key >= SDL_SCANCODE_COUNT) return false;
|
||||
if (keystates[key] != 0) return true;
|
||||
for (int src = 0; src < JI_VSRC_COUNT; src++) {
|
||||
if (virtual_keystates[src][key] != 0) return true;
|
||||
if (key == SDL_SCANCODE_ESCAPE && Director::get()->isEscBlocked()) {
|
||||
return false;
|
||||
}
|
||||
if (key < 0 || key >= SDL_SCANCODE_COUNT) {
|
||||
return false;
|
||||
}
|
||||
if (static_cast<int>(keystates[key]) != 0) {
|
||||
return true;
|
||||
}
|
||||
for (auto& virtual_keystate : virtual_keystates) {
|
||||
if (virtual_keystate[key] != 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool JI_CheatActivated(const char* cheat_code) {
|
||||
auto JI_CheatActivated(const char* cheat_code) -> bool {
|
||||
const size_t len = std::strlen(cheat_code);
|
||||
if (len > sizeof(cheat)) return false;
|
||||
if (len > sizeof(cheat)) {
|
||||
return false;
|
||||
}
|
||||
// Compara contra els últims `len` caràcters del buffer. El buffer té
|
||||
// mida fixa 5 i acumula sempre el darrer tecle a la posició 4.
|
||||
const size_t offset = sizeof(cheat) - len;
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
if (cheat[offset + i] != static_cast<Uint8>(cheat_code[i])) return false;
|
||||
if (cheat[offset + i] != static_cast<Uint8>(cheat_code[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JI_AnyKey() {
|
||||
return wait_ms > 0.0f ? false : key_pressed;
|
||||
auto JI_AnyKey() -> bool {
|
||||
return wait_ms > 0.0F ? false : key_pressed;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user