refactor: JI_* a Ji:: i JG_* a Jg::

This commit is contained in:
2026-05-16 14:43:16 +02:00
parent 9d30dd538c
commit bbcc10da81
27 changed files with 174 additions and 163 deletions
+14 -13
View File
@@ -17,18 +17,18 @@ namespace {
bool key_pressed = false;
// Temps restant en mil·lisegons durant el qual JI_KeyPressed/JI_AnyKey
// 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;
// Per a calcular el delta entre crides a JI_Update sense que els callers
// 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.
Uint64 last_update_tick = 0;
bool input_blocked = false;
Uint8 virtual_keystates[JI_VSRC_COUNT][SDL_SCANCODE_COUNT] = {{0}};
Uint8 virtual_keystates[static_cast<size_t>(Ji::VirtualSource::COUNT)][SDL_SCANCODE_COUNT] = {{0}};
auto scancode_to_ascii(Uint8 scancode) -> Uint8 {
if (scancode >= SDL_SCANCODE_A && scancode <= SDL_SCANCODE_Z) {
@@ -39,25 +39,26 @@ namespace {
} // namespace
void JI_DisableKeyboard(Uint32 time) {
void Ji::disableKeyboard(Uint32 time) {
wait_ms = static_cast<float>(time);
}
void JI_SetInputBlocked(bool blocked) {
void Ji::setInputBlocked(bool blocked) {
input_blocked = blocked;
}
void JI_SetVirtualKey(int scancode, int source, bool pressed) {
void Ji::setVirtualKey(int scancode, VirtualSource source, bool pressed) {
if (scancode < 0 || scancode >= SDL_SCANCODE_COUNT) {
return;
}
if (source < 0 || source >= JI_VSRC_COUNT) {
const auto src_idx = static_cast<size_t>(source);
if (src_idx >= static_cast<size_t>(VirtualSource::COUNT)) {
return;
}
virtual_keystates[source][scancode] = pressed ? 1 : 0;
virtual_keystates[src_idx][scancode] = pressed ? 1 : 0;
}
void JI_moveCheats(Uint8 scancode) {
void Ji::moveCheats(Uint8 scancode) {
cheat[0] = cheat[1];
cheat[1] = cheat[2];
cheat[2] = cheat[3];
@@ -65,7 +66,7 @@ void JI_moveCheats(Uint8 scancode) {
cheat[4] = scancode_to_ascii(scancode);
}
void JI_Update() {
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) {
@@ -88,7 +89,7 @@ void JI_Update() {
key_pressed = Director::get()->consumeKeyPressed();
}
auto JI_KeyPressed(int key) -> bool {
auto Ji::keyPressed(int key) -> bool {
if (wait_ms > 0.0F || keystates == nullptr) {
return false;
}
@@ -109,7 +110,7 @@ auto JI_KeyPressed(int key) -> bool {
return std::ranges::any_of(virtual_keystates, [key](const auto& vk) { return vk[key] != 0; });
}
auto JI_CheatActivated(const char* cheat_code) -> bool {
auto Ji::cheatActivated(const char* cheat_code) -> bool {
const size_t len = std::strlen(cheat_code);
if (len > sizeof(cheat)) {
return false;
@@ -125,6 +126,6 @@ auto JI_CheatActivated(const char* cheat_code) -> bool {
return true;
}
auto JI_AnyKey() -> bool {
auto Ji::anyKey() -> bool {
return wait_ms > 0.0F ? false : key_pressed;
}