refactor: JI_* a Ji:: i JG_* a Jg::
This commit is contained in:
@@ -171,10 +171,10 @@ namespace Gamepad {
|
||||
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);
|
||||
JI_SetVirtualKey(SDL_SCANCODE_LEFT, JI_VSRC_GAMEPAD, false);
|
||||
JI_SetVirtualKey(SDL_SCANCODE_RIGHT, JI_VSRC_GAMEPAD, false);
|
||||
Ji::setVirtualKey(SDL_SCANCODE_UP, Ji::VirtualSource::GAMEPAD, false);
|
||||
Ji::setVirtualKey(SDL_SCANCODE_DOWN, Ji::VirtualSource::GAMEPAD, false);
|
||||
Ji::setVirtualKey(SDL_SCANCODE_LEFT, Ji::VirtualSource::GAMEPAD, false);
|
||||
Ji::setVirtualKey(SDL_SCANCODE_RIGHT, Ji::VirtualSource::GAMEPAD, false);
|
||||
notifyDisconnected(saved_name);
|
||||
}
|
||||
}
|
||||
@@ -259,17 +259,17 @@ namespace Gamepad {
|
||||
}
|
||||
|
||||
// Assegura que el joc no rep tecles de moviment mentre el menú està obert
|
||||
JI_SetVirtualKey(SDL_SCANCODE_UP, JI_VSRC_GAMEPAD, false);
|
||||
JI_SetVirtualKey(SDL_SCANCODE_DOWN, JI_VSRC_GAMEPAD, false);
|
||||
JI_SetVirtualKey(SDL_SCANCODE_LEFT, JI_VSRC_GAMEPAD, false);
|
||||
JI_SetVirtualKey(SDL_SCANCODE_RIGHT, JI_VSRC_GAMEPAD, false);
|
||||
Ji::setVirtualKey(SDL_SCANCODE_UP, Ji::VirtualSource::GAMEPAD, false);
|
||||
Ji::setVirtualKey(SDL_SCANCODE_DOWN, Ji::VirtualSource::GAMEPAD, false);
|
||||
Ji::setVirtualKey(SDL_SCANCODE_LEFT, Ji::VirtualSource::GAMEPAD, false);
|
||||
Ji::setVirtualKey(SDL_SCANCODE_RIGHT, Ji::VirtualSource::GAMEPAD, false);
|
||||
} else {
|
||||
// Moviment al joc — level-triggered (polling)
|
||||
JI_SetVirtualKey(SDL_SCANCODE_UP, JI_VSRC_GAMEPAD, up);
|
||||
JI_SetVirtualKey(SDL_SCANCODE_DOWN, JI_VSRC_GAMEPAD, dn);
|
||||
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)
|
||||
Ji::setVirtualKey(SDL_SCANCODE_UP, Ji::VirtualSource::GAMEPAD, up);
|
||||
Ji::setVirtualKey(SDL_SCANCODE_DOWN, Ji::VirtualSource::GAMEPAD, dn);
|
||||
Ji::setVirtualKey(SDL_SCANCODE_LEFT, Ji::VirtualSource::GAMEPAD, lt);
|
||||
Ji::setVirtualKey(SDL_SCANCODE_RIGHT, Ji::VirtualSource::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)) {
|
||||
pushKey(SDL_SCANCODE_RETURN);
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace GlobalInputs {
|
||||
bool consumed = false;
|
||||
|
||||
// F1 — Reduir zoom
|
||||
bool dec_zoom = JI_KeyPressed(KeyConfig::scancode("dec_zoom"));
|
||||
bool dec_zoom = Ji::keyPressed(KeyConfig::scancode("dec_zoom"));
|
||||
if (dec_zoom && !dec_zoom_prev) {
|
||||
Screen::get()->decZoom();
|
||||
char msg[32];
|
||||
@@ -40,7 +40,7 @@ namespace GlobalInputs {
|
||||
dec_zoom_prev = dec_zoom;
|
||||
|
||||
// F2 — Augmentar zoom
|
||||
bool inc_zoom = JI_KeyPressed(KeyConfig::scancode("inc_zoom"));
|
||||
bool inc_zoom = Ji::keyPressed(KeyConfig::scancode("inc_zoom"));
|
||||
if (inc_zoom && !inc_zoom_prev) {
|
||||
Screen::get()->incZoom();
|
||||
char msg[32];
|
||||
@@ -53,7 +53,7 @@ namespace GlobalInputs {
|
||||
inc_zoom_prev = inc_zoom;
|
||||
|
||||
// F3 — Toggle pantalla completa
|
||||
bool fullscreen = JI_KeyPressed(KeyConfig::scancode("fullscreen"));
|
||||
bool fullscreen = Ji::keyPressed(KeyConfig::scancode("fullscreen"));
|
||||
if (fullscreen && !fullscreen_prev) {
|
||||
Screen::get()->toggleFullscreen();
|
||||
Overlay::showNotification(Screen::get()->isFullscreen() ? Locale::get("notifications.fullscreen") : Locale::get("notifications.windowed"));
|
||||
@@ -64,7 +64,7 @@ namespace GlobalInputs {
|
||||
fullscreen_prev = fullscreen;
|
||||
|
||||
// F4 — Toggle shaders
|
||||
bool shader = JI_KeyPressed(KeyConfig::scancode("toggle_shader"));
|
||||
bool shader = Ji::keyPressed(KeyConfig::scancode("toggle_shader"));
|
||||
if (shader && !shader_prev) {
|
||||
Screen::get()->toggleShaders();
|
||||
Overlay::showNotification(Options::video.shader_enabled ? Locale::get("notifications.shader_on") : Locale::get("notifications.shader_off"));
|
||||
@@ -75,7 +75,7 @@ namespace GlobalInputs {
|
||||
shader_prev = shader;
|
||||
|
||||
// F5 — Toggle aspect ratio 4:3
|
||||
bool aspect = JI_KeyPressed(KeyConfig::scancode("toggle_aspect_ratio"));
|
||||
bool aspect = Ji::keyPressed(KeyConfig::scancode("toggle_aspect_ratio"));
|
||||
if (aspect && !aspect_prev) {
|
||||
Screen::get()->toggleAspectRatio();
|
||||
Overlay::showNotification(Options::video.aspect_ratio_4_3 ? Locale::get("notifications.aspect_43") : Locale::get("notifications.aspect_square"));
|
||||
@@ -86,7 +86,7 @@ namespace GlobalInputs {
|
||||
aspect_prev = aspect;
|
||||
|
||||
// F6 — Toggle supersampling
|
||||
bool ss = JI_KeyPressed(KeyConfig::scancode("toggle_supersampling"));
|
||||
bool ss = Ji::keyPressed(KeyConfig::scancode("toggle_supersampling"));
|
||||
if (ss && !ss_prev) {
|
||||
if (Screen::get()->toggleSupersampling()) {
|
||||
Overlay::showNotification(Options::video.supersampling ? Locale::get("notifications.ss_on") : Locale::get("notifications.ss_off"));
|
||||
@@ -98,7 +98,7 @@ namespace GlobalInputs {
|
||||
ss_prev = ss;
|
||||
|
||||
// F7 — Canviar tipus de shader (PostFX ↔ CrtPi)
|
||||
bool next_shader = JI_KeyPressed(KeyConfig::scancode("next_shader"));
|
||||
bool next_shader = Ji::keyPressed(KeyConfig::scancode("next_shader"));
|
||||
if (next_shader && !next_shader_prev) {
|
||||
if (Screen::get()->nextShaderType()) {
|
||||
char msg[64];
|
||||
@@ -112,7 +112,7 @@ namespace GlobalInputs {
|
||||
next_shader_prev = next_shader;
|
||||
|
||||
// F8 — Pròxim preset del shader actiu
|
||||
bool next_preset = JI_KeyPressed(KeyConfig::scancode("next_shader_preset"));
|
||||
bool next_preset = Ji::keyPressed(KeyConfig::scancode("next_shader_preset"));
|
||||
if (next_preset && !next_preset_prev) {
|
||||
if (Screen::get()->nextPreset()) {
|
||||
char msg[64];
|
||||
@@ -126,7 +126,7 @@ namespace GlobalInputs {
|
||||
next_preset_prev = next_preset;
|
||||
|
||||
// F9 — Cicla filtre de textura (NEAREST ↔ LINEAR), sempre aplicat
|
||||
bool texture_filter = JI_KeyPressed(KeyConfig::scancode("cycle_texture_filter"));
|
||||
bool texture_filter = Ji::keyPressed(KeyConfig::scancode("cycle_texture_filter"));
|
||||
if (texture_filter && !texture_filter_prev) {
|
||||
Screen::get()->cycleTextureFilter(+1);
|
||||
Overlay::showNotification(Options::video.texture_filter == Options::TextureFilter::LINEAR
|
||||
@@ -139,7 +139,7 @@ namespace GlobalInputs {
|
||||
texture_filter_prev = texture_filter;
|
||||
|
||||
// F10 — Toggle render info (FPS, driver, shader)
|
||||
bool render_info = JI_KeyPressed(KeyConfig::scancode("toggle_render_info"));
|
||||
bool render_info = Ji::keyPressed(KeyConfig::scancode("toggle_render_info"));
|
||||
if (render_info && !render_info_prev) {
|
||||
Overlay::toggleRenderInfo();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
namespace GlobalInputs {
|
||||
// Comprovar una vegada per frame, després de JI_Update()
|
||||
// Comprovar una vegada per frame, després de Ji::update()
|
||||
// Retorna true si ha consumit alguna tecla (per suprimir-la de la capa de joc)
|
||||
auto handle() -> bool;
|
||||
} // namespace GlobalInputs
|
||||
|
||||
@@ -9,10 +9,10 @@ namespace KeyRemap {
|
||||
|
||||
static void mirror(SDL_Scancode custom, SDL_Scancode standard, const bool* ks) {
|
||||
if (custom == standard || custom == SDL_SCANCODE_UNKNOWN) {
|
||||
JI_SetVirtualKey(standard, JI_VSRC_REMAP, false);
|
||||
Ji::setVirtualKey(standard, Ji::VirtualSource::REMAP, false);
|
||||
return;
|
||||
}
|
||||
JI_SetVirtualKey(standard, JI_VSRC_REMAP, ks[custom]);
|
||||
Ji::setVirtualKey(standard, Ji::VirtualSource::REMAP, ks[custom]);
|
||||
}
|
||||
|
||||
void update() {
|
||||
|
||||
+12
-12
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace {
|
||||
|
||||
bool quitting = false;
|
||||
bool is_quitting = false;
|
||||
Uint32 update_ticks = 0;
|
||||
Uint32 update_time = 0;
|
||||
Uint32 cycle_counter = 0;
|
||||
@@ -10,29 +10,29 @@ namespace {
|
||||
|
||||
} // namespace
|
||||
|
||||
void JG_Init() {
|
||||
void Jg::init() {
|
||||
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
|
||||
update_time = SDL_GetTicks();
|
||||
last_delta_time = update_time;
|
||||
}
|
||||
|
||||
void JG_Finalize() {
|
||||
void Jg::finalize() {
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
void JG_QuitSignal() {
|
||||
quitting = true;
|
||||
void Jg::quitSignal() {
|
||||
is_quitting = true;
|
||||
}
|
||||
|
||||
auto JG_Quitting() -> bool {
|
||||
return quitting;
|
||||
auto Jg::quitting() -> bool {
|
||||
return is_quitting;
|
||||
}
|
||||
|
||||
void JG_SetUpdateTicks(Uint32 milliseconds) {
|
||||
void Jg::setUpdateTicks(Uint32 milliseconds) {
|
||||
update_ticks = milliseconds;
|
||||
}
|
||||
|
||||
auto JG_ShouldUpdate() -> bool {
|
||||
auto Jg::shouldUpdate() -> bool {
|
||||
const Uint32 now = SDL_GetTicks();
|
||||
if (now - update_time > update_ticks) {
|
||||
update_time = now;
|
||||
@@ -40,16 +40,16 @@ auto JG_ShouldUpdate() -> bool {
|
||||
return true;
|
||||
}
|
||||
// No toca update — retornem false sense més. Des de Phase B.2 ja no
|
||||
// hi ha fibers: cap caller fa spin-waits (`while (!JG_ShouldUpdate())`)
|
||||
// hi ha fibers: cap caller fa spin-waits (`while (!Jg::shouldUpdate())`)
|
||||
// i el Director pren el control del main loop frame a frame.
|
||||
return false;
|
||||
}
|
||||
|
||||
auto JG_GetCycleCounter() -> Uint32 {
|
||||
auto Jg::getCycleCounter() -> Uint32 {
|
||||
return cycle_counter;
|
||||
}
|
||||
|
||||
auto JG_GetDeltaMs() -> Uint32 {
|
||||
auto Jg::getDeltaMs() -> Uint32 {
|
||||
const Uint32 now = SDL_GetTicks();
|
||||
const Uint32 delta = now - last_delta_time;
|
||||
last_delta_time = now;
|
||||
|
||||
+24
-20
@@ -1,20 +1,24 @@
|
||||
#pragma once
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
void JG_Init();
|
||||
|
||||
void JG_Finalize();
|
||||
|
||||
void JG_QuitSignal();
|
||||
|
||||
auto JG_Quitting() -> bool;
|
||||
|
||||
void JG_SetUpdateTicks(Uint32 milliseconds);
|
||||
|
||||
auto JG_ShouldUpdate() -> bool;
|
||||
|
||||
auto JG_GetCycleCounter() -> Uint32;
|
||||
|
||||
// Temps transcorregut (en ms) des de l'última crida a JG_GetDeltaMs.
|
||||
// Helper per a la migració progressiva a time-based (Fase 4+).
|
||||
auto JG_GetDeltaMs() -> Uint32;
|
||||
#pragma once
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
namespace Jg {
|
||||
|
||||
void init();
|
||||
|
||||
void finalize();
|
||||
|
||||
void quitSignal();
|
||||
|
||||
auto quitting() -> bool;
|
||||
|
||||
void setUpdateTicks(Uint32 milliseconds);
|
||||
|
||||
auto shouldUpdate() -> bool;
|
||||
|
||||
auto getCycleCounter() -> Uint32;
|
||||
|
||||
// Temps transcorregut (en ms) des de l'última crida a Jg::getDeltaMs.
|
||||
// Helper per a la migració progressiva a time-based (Fase 4+).
|
||||
auto getDeltaMs() -> Uint32;
|
||||
|
||||
} // namespace Jg
|
||||
|
||||
+14
-13
@@ -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;
|
||||
}
|
||||
|
||||
+36
-27
@@ -1,27 +1,36 @@
|
||||
#pragma once
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
void JI_DisableKeyboard(Uint32 time);
|
||||
|
||||
// Bloqueja tot l'input cap al joc (JI_KeyPressed retorna false per a tot)
|
||||
void JI_SetInputBlocked(bool blocked);
|
||||
|
||||
// Estableix l'estat d'una tecla virtual. Múltiples fonts (gamepad, remap)
|
||||
// s'agrupen per OR. JI_KeyPressed retorna true si el teclat real O qualsevol
|
||||
// font virtual està premuda.
|
||||
enum JI_VirtualSource : std::uint8_t {
|
||||
JI_VSRC_GAMEPAD = 0,
|
||||
JI_VSRC_REMAP = 1,
|
||||
JI_VSRC_COUNT = 2
|
||||
};
|
||||
void JI_SetVirtualKey(int scancode, int source, bool pressed);
|
||||
|
||||
void JI_Update();
|
||||
|
||||
auto JI_KeyPressed(int key) -> bool;
|
||||
|
||||
auto JI_CheatActivated(const char* cheat_code) -> bool;
|
||||
|
||||
auto JI_AnyKey() -> bool;
|
||||
#pragma once
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace Ji {
|
||||
|
||||
void disableKeyboard(Uint32 time);
|
||||
|
||||
// Bloqueja tot l'input cap al joc (Ji::keyPressed retorna false per a tot)
|
||||
void setInputBlocked(bool blocked);
|
||||
|
||||
// Estableix l'estat d'una tecla virtual. Múltiples fonts (gamepad, remap)
|
||||
// s'agrupen per OR. Ji::keyPressed retorna true si el teclat real O qualsevol
|
||||
// font virtual està premuda.
|
||||
enum class VirtualSource : std::uint8_t {
|
||||
GAMEPAD = 0,
|
||||
REMAP = 1,
|
||||
COUNT = 2
|
||||
};
|
||||
void setVirtualKey(int scancode, VirtualSource source, bool pressed);
|
||||
|
||||
void update();
|
||||
|
||||
// Avança el buffer rotatori de cheats afegint `scancode` per detectar
|
||||
// seqüències com "reviu", "alone", "obert". Usat pel Director quan rep
|
||||
// un KEY_DOWN; el joc no l'ha de cridar directament.
|
||||
void moveCheats(Uint8 scancode);
|
||||
|
||||
auto keyPressed(int key) -> bool;
|
||||
|
||||
auto cheatActivated(const char* cheat_code) -> bool;
|
||||
|
||||
auto anyKey() -> bool;
|
||||
|
||||
} // namespace Ji
|
||||
|
||||
@@ -32,9 +32,6 @@
|
||||
#include "game/scenes/secreta_scene.hpp"
|
||||
#include "game/scenes/slides_scene.hpp"
|
||||
|
||||
// Cheats del joc original — declarats a jinput.cpp
|
||||
extern void JI_moveCheats(Uint8 new_key);
|
||||
|
||||
std::unique_ptr<Director> Director::instance_;
|
||||
|
||||
Director::~Director() = default;
|
||||
@@ -141,7 +138,7 @@ void Director::setup() {
|
||||
|
||||
auto Director::iterate() -> bool {
|
||||
if (quit_requested_) {
|
||||
JG_QuitSignal();
|
||||
Jg::quitSignal();
|
||||
current_scene_.reset(); // destrueix l'escena actual ordenadament
|
||||
return false;
|
||||
}
|
||||
@@ -162,7 +159,7 @@ auto Director::iterate() -> bool {
|
||||
game_state_ = 1; // 1 = dispatch via SceneRegistry per num_piramide
|
||||
has_frame_ = false;
|
||||
Menu::close();
|
||||
JI_SetInputBlocked(false); // el menú ho havia bloquejat — cal desfer-ho
|
||||
Ji::setInputBlocked(false); // el menú ho havia bloquejat — cal desfer-ho
|
||||
}
|
||||
|
||||
if (!context_initialized_) {
|
||||
@@ -207,7 +204,7 @@ auto Director::iterate() -> bool {
|
||||
// Transicions: si l'escena actual ha acabat (o s'ha senyalat
|
||||
// quit), llegim el seu next state i la destruïm per crear la
|
||||
// següent a continuació.
|
||||
if (current_scene_ && (current_scene_->done() || JG_Quitting())) {
|
||||
if (current_scene_ && (current_scene_->done() || Jg::quitting())) {
|
||||
game_state_ = current_scene_->nextState();
|
||||
current_scene_.reset();
|
||||
}
|
||||
@@ -216,7 +213,7 @@ auto Director::iterate() -> bool {
|
||||
// game_state_ i info::ctx. Si és impossible (game_state_ == -1,
|
||||
// quit, o state no registrat), eixim del loop.
|
||||
if (!current_scene_) {
|
||||
if (game_state_ == -1 || JG_Quitting()) {
|
||||
if (game_state_ == -1 || Jg::quitting()) {
|
||||
return false;
|
||||
}
|
||||
current_scene_ = createNextScene();
|
||||
@@ -227,9 +224,9 @@ auto Director::iterate() -> bool {
|
||||
last_tick_ms_ = SDL_GetTicks();
|
||||
}
|
||||
|
||||
// Tick de l'escena. JI_Update refresca key_pressed/any_key; el
|
||||
// Tick de l'escena. Ji::update refresca key_pressed/any_key; el
|
||||
// delta_ms és el temps real transcorregut des de l'últim tick.
|
||||
JI_Update();
|
||||
Ji::update();
|
||||
const Uint32 now = SDL_GetTicks();
|
||||
const int delta_ms = static_cast<int>(now - last_tick_ms_);
|
||||
last_tick_ms_ = now;
|
||||
@@ -266,7 +263,7 @@ void Director::teardown() {
|
||||
// Senyal de quit i descàrrega ordenada de l'escena en curs. Els
|
||||
// destructors de cada escena són no-bloquejants — ja no fan fades
|
||||
// bloquejants. La resta de cleanup la gestiona `destroy()`.
|
||||
JG_QuitSignal();
|
||||
Jg::quitSignal();
|
||||
current_scene_.reset();
|
||||
}
|
||||
|
||||
@@ -290,7 +287,7 @@ void Director::pollAllEvents() {
|
||||
|
||||
void Director::handleEvent(const SDL_Event& event) {
|
||||
if (event.type == SDL_EVENT_QUIT) {
|
||||
JG_QuitSignal();
|
||||
Jg::quitSignal();
|
||||
requestQuit();
|
||||
}
|
||||
// Hot-plug de gamepad (a Emscripten els dispositius web entren com
|
||||
@@ -325,7 +322,7 @@ void Director::handleEvent(const SDL_Event& event) {
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && !event.key.repeat &&
|
||||
event.key.scancode == KeyConfig::scancode("menu_toggle")) {
|
||||
Menu::toggle();
|
||||
JI_SetInputBlocked(Menu::isOpen());
|
||||
Ji::setInputBlocked(Menu::isOpen());
|
||||
menu_keys_held_[event.key.scancode] = true;
|
||||
return;
|
||||
}
|
||||
@@ -333,14 +330,14 @@ void Director::handleEvent(const SDL_Event& event) {
|
||||
if (Menu::isOpen() && event.type == SDL_EVENT_KEY_DOWN && !event.key.repeat) {
|
||||
if (event.key.scancode == SDL_SCANCODE_ESCAPE) {
|
||||
Menu::close();
|
||||
JI_SetInputBlocked(false);
|
||||
Ji::setInputBlocked(false);
|
||||
// Empassa l'ESC fins al release perquè el joc no la veja per polling
|
||||
esc_swallow_until_release_ = true;
|
||||
} else {
|
||||
Menu::handleKey(event.key.scancode);
|
||||
// El menú pot haver-se tancat (p.ex. Backspace al nivell arrel)
|
||||
if (!Menu::isOpen()) {
|
||||
JI_SetInputBlocked(false);
|
||||
Ji::setInputBlocked(false);
|
||||
}
|
||||
}
|
||||
menu_keys_held_[event.key.scancode] = true;
|
||||
@@ -372,7 +369,7 @@ void Director::handleEvent(const SDL_Event& event) {
|
||||
// Segona pulsació: senyal d'eixida al joc
|
||||
esc_blocked_ = false;
|
||||
key_pressed_ = true;
|
||||
JG_QuitSignal();
|
||||
Jg::quitSignal();
|
||||
// Si estem en pausa, la desactivem: el fiber del joc està
|
||||
// congelat i necessita ser reprès per veure la senyal de
|
||||
// quit i poder tornar de forma natural.
|
||||
@@ -392,7 +389,7 @@ void Director::handleEvent(const SDL_Event& event) {
|
||||
const auto sc = event.key.scancode;
|
||||
if (!KeyConfig::isGuiKey(sc)) {
|
||||
key_pressed_ = true;
|
||||
JI_moveCheats(sc);
|
||||
Ji::moveCheats(sc);
|
||||
}
|
||||
}
|
||||
Mouse::handleEvent(event);
|
||||
@@ -400,7 +397,7 @@ void Director::handleEvent(const SDL_Event& event) {
|
||||
|
||||
void Director::requestQuit() {
|
||||
quit_requested_ = true;
|
||||
JG_QuitSignal();
|
||||
Jg::quitSignal();
|
||||
}
|
||||
|
||||
void Director::requestRestart() {
|
||||
|
||||
@@ -41,7 +41,7 @@ class Director {
|
||||
// iterate() per evitar manipular l'escena des d'una lambda del menú.
|
||||
void requestRestart();
|
||||
|
||||
// Consumeix el flag de "tecla polsada" (com l'antic JI_AnyKey)
|
||||
// Consumeix el flag de "tecla polsada" (com l'antic Ji::anyKey)
|
||||
auto consumeKeyPressed() -> bool;
|
||||
|
||||
// Indica si ESC està bloquejada (el joc no l'ha de veure)
|
||||
@@ -88,9 +88,9 @@ class Director {
|
||||
std::atomic<bool> esc_blocked_{false};
|
||||
std::atomic<bool> paused_{false};
|
||||
// Quan el menú tanca amb ESC, empassem-nos l'ESC fins que l'usuari la deixe anar,
|
||||
// per no fer eixir el joc al proper poll de JI_KeyPressed.
|
||||
// per no fer eixir el joc al proper poll de Ji::keyPressed.
|
||||
std::atomic<bool> esc_swallow_until_release_{false};
|
||||
// Tecles consumides pel menú (KEY_DOWN): el KEY_UP associat cal empassar-lo
|
||||
// per evitar que el joc (JI_AnyKey / JI_moveCheats) les veja quan el menú tanca.
|
||||
// per evitar que el joc (Ji::anyKey / Ji::moveCheats) les veja quan el menú tanca.
|
||||
bool menu_keys_held_[SDL_SCANCODE_COUNT]{};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user