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
+13 -13
View File
@@ -171,10 +171,10 @@ namespace Gamepad {
pad = nullptr; pad = nullptr;
pad_id = 0; pad_id = 0;
// Neteja qualsevol tecla virtual que poguera estar premuda // Neteja qualsevol tecla virtual que poguera estar premuda
JI_SetVirtualKey(SDL_SCANCODE_UP, JI_VSRC_GAMEPAD, false); Ji::setVirtualKey(SDL_SCANCODE_UP, Ji::VirtualSource::GAMEPAD, false);
JI_SetVirtualKey(SDL_SCANCODE_DOWN, JI_VSRC_GAMEPAD, false); Ji::setVirtualKey(SDL_SCANCODE_DOWN, Ji::VirtualSource::GAMEPAD, false);
JI_SetVirtualKey(SDL_SCANCODE_LEFT, JI_VSRC_GAMEPAD, false); Ji::setVirtualKey(SDL_SCANCODE_LEFT, Ji::VirtualSource::GAMEPAD, false);
JI_SetVirtualKey(SDL_SCANCODE_RIGHT, JI_VSRC_GAMEPAD, false); Ji::setVirtualKey(SDL_SCANCODE_RIGHT, Ji::VirtualSource::GAMEPAD, false);
notifyDisconnected(saved_name); notifyDisconnected(saved_name);
} }
} }
@@ -259,17 +259,17 @@ namespace Gamepad {
} }
// Assegura que el joc no rep tecles de moviment mentre el menú està obert // 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_UP, Ji::VirtualSource::GAMEPAD, false);
JI_SetVirtualKey(SDL_SCANCODE_DOWN, JI_VSRC_GAMEPAD, false); Ji::setVirtualKey(SDL_SCANCODE_DOWN, Ji::VirtualSource::GAMEPAD, false);
JI_SetVirtualKey(SDL_SCANCODE_LEFT, JI_VSRC_GAMEPAD, false); Ji::setVirtualKey(SDL_SCANCODE_LEFT, Ji::VirtualSource::GAMEPAD, false);
JI_SetVirtualKey(SDL_SCANCODE_RIGHT, JI_VSRC_GAMEPAD, false); Ji::setVirtualKey(SDL_SCANCODE_RIGHT, Ji::VirtualSource::GAMEPAD, false);
} else { } else {
// Moviment al joc — level-triggered (polling) // Moviment al joc — level-triggered (polling)
JI_SetVirtualKey(SDL_SCANCODE_UP, JI_VSRC_GAMEPAD, up); Ji::setVirtualKey(SDL_SCANCODE_UP, Ji::VirtualSource::GAMEPAD, up);
JI_SetVirtualKey(SDL_SCANCODE_DOWN, JI_VSRC_GAMEPAD, dn); Ji::setVirtualKey(SDL_SCANCODE_DOWN, Ji::VirtualSource::GAMEPAD, dn);
JI_SetVirtualKey(SDL_SCANCODE_LEFT, JI_VSRC_GAMEPAD, lt); Ji::setVirtualKey(SDL_SCANCODE_LEFT, Ji::VirtualSource::GAMEPAD, lt);
JI_SetVirtualKey(SDL_SCANCODE_RIGHT, JI_VSRC_GAMEPAD, rt); Ji::setVirtualKey(SDL_SCANCODE_RIGHT, Ji::VirtualSource::GAMEPAD, rt);
// Qualsevol dels 4 botons frontals avança escenes (JI_AnyKey via Enter sintètic) // Qualsevol dels 4 botons frontals avança escenes (Ji::anyKey via Enter sintètic)
if ((south && !prev_south) || (east && !prev_east) || if ((south && !prev_south) || (east && !prev_east) ||
(west && !prev_west) || (north && !prev_north)) { (west && !prev_west) || (north && !prev_north)) {
pushKey(SDL_SCANCODE_RETURN); pushKey(SDL_SCANCODE_RETURN);
+10 -10
View File
@@ -27,7 +27,7 @@ namespace GlobalInputs {
bool consumed = false; bool consumed = false;
// F1 — Reduir zoom // 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) { if (dec_zoom && !dec_zoom_prev) {
Screen::get()->decZoom(); Screen::get()->decZoom();
char msg[32]; char msg[32];
@@ -40,7 +40,7 @@ namespace GlobalInputs {
dec_zoom_prev = dec_zoom; dec_zoom_prev = dec_zoom;
// F2 — Augmentar 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) { if (inc_zoom && !inc_zoom_prev) {
Screen::get()->incZoom(); Screen::get()->incZoom();
char msg[32]; char msg[32];
@@ -53,7 +53,7 @@ namespace GlobalInputs {
inc_zoom_prev = inc_zoom; inc_zoom_prev = inc_zoom;
// F3 — Toggle pantalla completa // F3 — Toggle pantalla completa
bool fullscreen = JI_KeyPressed(KeyConfig::scancode("fullscreen")); bool fullscreen = Ji::keyPressed(KeyConfig::scancode("fullscreen"));
if (fullscreen && !fullscreen_prev) { if (fullscreen && !fullscreen_prev) {
Screen::get()->toggleFullscreen(); Screen::get()->toggleFullscreen();
Overlay::showNotification(Screen::get()->isFullscreen() ? Locale::get("notifications.fullscreen") : Locale::get("notifications.windowed")); Overlay::showNotification(Screen::get()->isFullscreen() ? Locale::get("notifications.fullscreen") : Locale::get("notifications.windowed"));
@@ -64,7 +64,7 @@ namespace GlobalInputs {
fullscreen_prev = fullscreen; fullscreen_prev = fullscreen;
// F4 — Toggle shaders // F4 — Toggle shaders
bool shader = JI_KeyPressed(KeyConfig::scancode("toggle_shader")); bool shader = Ji::keyPressed(KeyConfig::scancode("toggle_shader"));
if (shader && !shader_prev) { if (shader && !shader_prev) {
Screen::get()->toggleShaders(); Screen::get()->toggleShaders();
Overlay::showNotification(Options::video.shader_enabled ? Locale::get("notifications.shader_on") : Locale::get("notifications.shader_off")); 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; shader_prev = shader;
// F5 — Toggle aspect ratio 4:3 // 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) { if (aspect && !aspect_prev) {
Screen::get()->toggleAspectRatio(); Screen::get()->toggleAspectRatio();
Overlay::showNotification(Options::video.aspect_ratio_4_3 ? Locale::get("notifications.aspect_43") : Locale::get("notifications.aspect_square")); 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; aspect_prev = aspect;
// F6 — Toggle supersampling // F6 — Toggle supersampling
bool ss = JI_KeyPressed(KeyConfig::scancode("toggle_supersampling")); bool ss = Ji::keyPressed(KeyConfig::scancode("toggle_supersampling"));
if (ss && !ss_prev) { if (ss && !ss_prev) {
if (Screen::get()->toggleSupersampling()) { if (Screen::get()->toggleSupersampling()) {
Overlay::showNotification(Options::video.supersampling ? Locale::get("notifications.ss_on") : Locale::get("notifications.ss_off")); Overlay::showNotification(Options::video.supersampling ? Locale::get("notifications.ss_on") : Locale::get("notifications.ss_off"));
@@ -98,7 +98,7 @@ namespace GlobalInputs {
ss_prev = ss; ss_prev = ss;
// F7 — Canviar tipus de shader (PostFX ↔ CrtPi) // 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 (next_shader && !next_shader_prev) {
if (Screen::get()->nextShaderType()) { if (Screen::get()->nextShaderType()) {
char msg[64]; char msg[64];
@@ -112,7 +112,7 @@ namespace GlobalInputs {
next_shader_prev = next_shader; next_shader_prev = next_shader;
// F8 — Pròxim preset del shader actiu // 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 (next_preset && !next_preset_prev) {
if (Screen::get()->nextPreset()) { if (Screen::get()->nextPreset()) {
char msg[64]; char msg[64];
@@ -126,7 +126,7 @@ namespace GlobalInputs {
next_preset_prev = next_preset; next_preset_prev = next_preset;
// F9 — Cicla filtre de textura (NEAREST ↔ LINEAR), sempre aplicat // 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) { if (texture_filter && !texture_filter_prev) {
Screen::get()->cycleTextureFilter(+1); Screen::get()->cycleTextureFilter(+1);
Overlay::showNotification(Options::video.texture_filter == Options::TextureFilter::LINEAR Overlay::showNotification(Options::video.texture_filter == Options::TextureFilter::LINEAR
@@ -139,7 +139,7 @@ namespace GlobalInputs {
texture_filter_prev = texture_filter; texture_filter_prev = texture_filter;
// F10 — Toggle render info (FPS, driver, shader) // 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) { if (render_info && !render_info_prev) {
Overlay::toggleRenderInfo(); Overlay::toggleRenderInfo();
} }
+1 -1
View File
@@ -1,7 +1,7 @@
#pragma once #pragma once
namespace GlobalInputs { 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) // Retorna true si ha consumit alguna tecla (per suprimir-la de la capa de joc)
auto handle() -> bool; auto handle() -> bool;
} // namespace GlobalInputs } // namespace GlobalInputs
+2 -2
View File
@@ -9,10 +9,10 @@ namespace KeyRemap {
static void mirror(SDL_Scancode custom, SDL_Scancode standard, const bool* ks) { static void mirror(SDL_Scancode custom, SDL_Scancode standard, const bool* ks) {
if (custom == standard || custom == SDL_SCANCODE_UNKNOWN) { if (custom == standard || custom == SDL_SCANCODE_UNKNOWN) {
JI_SetVirtualKey(standard, JI_VSRC_REMAP, false); Ji::setVirtualKey(standard, Ji::VirtualSource::REMAP, false);
return; return;
} }
JI_SetVirtualKey(standard, JI_VSRC_REMAP, ks[custom]); Ji::setVirtualKey(standard, Ji::VirtualSource::REMAP, ks[custom]);
} }
void update() { void update() {
+12 -12
View File
@@ -2,7 +2,7 @@
namespace { namespace {
bool quitting = false; bool is_quitting = false;
Uint32 update_ticks = 0; Uint32 update_ticks = 0;
Uint32 update_time = 0; Uint32 update_time = 0;
Uint32 cycle_counter = 0; Uint32 cycle_counter = 0;
@@ -10,29 +10,29 @@ namespace {
} // namespace } // namespace
void JG_Init() { void Jg::init() {
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO); SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
update_time = SDL_GetTicks(); update_time = SDL_GetTicks();
last_delta_time = update_time; last_delta_time = update_time;
} }
void JG_Finalize() { void Jg::finalize() {
SDL_Quit(); SDL_Quit();
} }
void JG_QuitSignal() { void Jg::quitSignal() {
quitting = true; is_quitting = true;
} }
auto JG_Quitting() -> bool { auto Jg::quitting() -> bool {
return quitting; return is_quitting;
} }
void JG_SetUpdateTicks(Uint32 milliseconds) { void Jg::setUpdateTicks(Uint32 milliseconds) {
update_ticks = milliseconds; update_ticks = milliseconds;
} }
auto JG_ShouldUpdate() -> bool { auto Jg::shouldUpdate() -> bool {
const Uint32 now = SDL_GetTicks(); const Uint32 now = SDL_GetTicks();
if (now - update_time > update_ticks) { if (now - update_time > update_ticks) {
update_time = now; update_time = now;
@@ -40,16 +40,16 @@ auto JG_ShouldUpdate() -> bool {
return true; return true;
} }
// No toca update — retornem false sense més. Des de Phase B.2 ja no // 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. // i el Director pren el control del main loop frame a frame.
return false; return false;
} }
auto JG_GetCycleCounter() -> Uint32 { auto Jg::getCycleCounter() -> Uint32 {
return cycle_counter; return cycle_counter;
} }
auto JG_GetDeltaMs() -> Uint32 { auto Jg::getDeltaMs() -> Uint32 {
const Uint32 now = SDL_GetTicks(); const Uint32 now = SDL_GetTicks();
const Uint32 delta = now - last_delta_time; const Uint32 delta = now - last_delta_time;
last_delta_time = now; last_delta_time = now;
+24 -20
View File
@@ -1,20 +1,24 @@
#pragma once #pragma once
#include <SDL3/SDL.h> #include <SDL3/SDL.h>
void JG_Init(); namespace Jg {
void JG_Finalize(); void init();
void JG_QuitSignal(); void finalize();
auto JG_Quitting() -> bool; void quitSignal();
void JG_SetUpdateTicks(Uint32 milliseconds); auto quitting() -> bool;
auto JG_ShouldUpdate() -> bool; void setUpdateTicks(Uint32 milliseconds);
auto JG_GetCycleCounter() -> Uint32; auto shouldUpdate() -> bool;
// Temps transcorregut (en ms) des de l'última crida a JG_GetDeltaMs. auto getCycleCounter() -> Uint32;
// Helper per a la migració progressiva a time-based (Fase 4+).
auto JG_GetDeltaMs() -> 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
View File
@@ -17,18 +17,18 @@ namespace {
bool key_pressed = false; 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 // retornen false. Utilitzat per a evitar que pulsacions fortuïtes
// saltin cinemàtiques al començament. // 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 // 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. // hagen de passar-lo explícitament. Es reinicia a la primera crida.
Uint64 last_update_tick = 0; Uint64 last_update_tick = 0;
bool input_blocked = false; 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 { auto scancode_to_ascii(Uint8 scancode) -> Uint8 {
if (scancode >= SDL_SCANCODE_A && scancode <= SDL_SCANCODE_Z) { if (scancode >= SDL_SCANCODE_A && scancode <= SDL_SCANCODE_Z) {
@@ -39,25 +39,26 @@ namespace {
} // namespace } // namespace
void JI_DisableKeyboard(Uint32 time) { void Ji::disableKeyboard(Uint32 time) {
wait_ms = static_cast<float>(time); wait_ms = static_cast<float>(time);
} }
void JI_SetInputBlocked(bool blocked) { void Ji::setInputBlocked(bool blocked) {
input_blocked = 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) { if (scancode < 0 || scancode >= SDL_SCANCODE_COUNT) {
return; 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; 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[0] = cheat[1];
cheat[1] = cheat[2]; cheat[1] = cheat[2];
cheat[2] = cheat[3]; cheat[2] = cheat[3];
@@ -65,7 +66,7 @@ void JI_moveCheats(Uint8 scancode) {
cheat[4] = scancode_to_ascii(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 director ha processat tots els events. Ací només refresquem
// el snapshot del teclat i consumim el flag de tecla polsada. // el snapshot del teclat i consumim el flag de tecla polsada.
if (keystates == nullptr) { if (keystates == nullptr) {
@@ -88,7 +89,7 @@ void JI_Update() {
key_pressed = Director::get()->consumeKeyPressed(); key_pressed = Director::get()->consumeKeyPressed();
} }
auto JI_KeyPressed(int key) -> bool { auto Ji::keyPressed(int key) -> bool {
if (wait_ms > 0.0F || keystates == nullptr) { if (wait_ms > 0.0F || keystates == nullptr) {
return false; 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; }); 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); const size_t len = std::strlen(cheat_code);
if (len > sizeof(cheat)) { if (len > sizeof(cheat)) {
return false; return false;
@@ -125,6 +126,6 @@ auto JI_CheatActivated(const char* cheat_code) -> bool {
return true; return true;
} }
auto JI_AnyKey() -> bool { auto Ji::anyKey() -> bool {
return wait_ms > 0.0F ? false : key_pressed; return wait_ms > 0.0F ? false : key_pressed;
} }
+36 -27
View File
@@ -1,27 +1,36 @@
#pragma once #pragma once
#include <SDL3/SDL.h> #include <SDL3/SDL.h>
#include <cstdint> #include <cstdint>
void JI_DisableKeyboard(Uint32 time); namespace Ji {
// Bloqueja tot l'input cap al joc (JI_KeyPressed retorna false per a tot) void disableKeyboard(Uint32 time);
void JI_SetInputBlocked(bool blocked);
// Bloqueja tot l'input cap al joc (Ji::keyPressed retorna false per a tot)
// Estableix l'estat d'una tecla virtual. Múltiples fonts (gamepad, remap) void setInputBlocked(bool blocked);
// s'agrupen per OR. JI_KeyPressed retorna true si el teclat real O qualsevol
// font virtual està premuda. // Estableix l'estat d'una tecla virtual. Múltiples fonts (gamepad, remap)
enum JI_VirtualSource : std::uint8_t { // s'agrupen per OR. Ji::keyPressed retorna true si el teclat real O qualsevol
JI_VSRC_GAMEPAD = 0, // font virtual està premuda.
JI_VSRC_REMAP = 1, enum class VirtualSource : std::uint8_t {
JI_VSRC_COUNT = 2 GAMEPAD = 0,
}; REMAP = 1,
void JI_SetVirtualKey(int scancode, int source, bool pressed); COUNT = 2
};
void JI_Update(); void setVirtualKey(int scancode, VirtualSource source, bool pressed);
auto JI_KeyPressed(int key) -> bool; void update();
auto JI_CheatActivated(const char* cheat_code) -> bool; // Avança el buffer rotatori de cheats afegint `scancode` per detectar
// seqüències com "reviu", "alone", "obert". Usat pel Director quan rep
auto JI_AnyKey() -> bool; // 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
+14 -17
View File
@@ -32,9 +32,6 @@
#include "game/scenes/secreta_scene.hpp" #include "game/scenes/secreta_scene.hpp"
#include "game/scenes/slides_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_; std::unique_ptr<Director> Director::instance_;
Director::~Director() = default; Director::~Director() = default;
@@ -141,7 +138,7 @@ void Director::setup() {
auto Director::iterate() -> bool { auto Director::iterate() -> bool {
if (quit_requested_) { if (quit_requested_) {
JG_QuitSignal(); Jg::quitSignal();
current_scene_.reset(); // destrueix l'escena actual ordenadament current_scene_.reset(); // destrueix l'escena actual ordenadament
return false; return false;
} }
@@ -162,7 +159,7 @@ auto Director::iterate() -> bool {
game_state_ = 1; // 1 = dispatch via SceneRegistry per num_piramide game_state_ = 1; // 1 = dispatch via SceneRegistry per num_piramide
has_frame_ = false; has_frame_ = false;
Menu::close(); 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_) { if (!context_initialized_) {
@@ -207,7 +204,7 @@ auto Director::iterate() -> bool {
// Transicions: si l'escena actual ha acabat (o s'ha senyalat // Transicions: si l'escena actual ha acabat (o s'ha senyalat
// quit), llegim el seu next state i la destruïm per crear la // quit), llegim el seu next state i la destruïm per crear la
// següent a continuació. // 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(); game_state_ = current_scene_->nextState();
current_scene_.reset(); current_scene_.reset();
} }
@@ -216,7 +213,7 @@ auto Director::iterate() -> bool {
// game_state_ i info::ctx. Si és impossible (game_state_ == -1, // game_state_ i info::ctx. Si és impossible (game_state_ == -1,
// quit, o state no registrat), eixim del loop. // quit, o state no registrat), eixim del loop.
if (!current_scene_) { if (!current_scene_) {
if (game_state_ == -1 || JG_Quitting()) { if (game_state_ == -1 || Jg::quitting()) {
return false; return false;
} }
current_scene_ = createNextScene(); current_scene_ = createNextScene();
@@ -227,9 +224,9 @@ auto Director::iterate() -> bool {
last_tick_ms_ = SDL_GetTicks(); 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. // delta_ms és el temps real transcorregut des de l'últim tick.
JI_Update(); Ji::update();
const Uint32 now = SDL_GetTicks(); const Uint32 now = SDL_GetTicks();
const int delta_ms = static_cast<int>(now - last_tick_ms_); const int delta_ms = static_cast<int>(now - last_tick_ms_);
last_tick_ms_ = now; last_tick_ms_ = now;
@@ -266,7 +263,7 @@ void Director::teardown() {
// Senyal de quit i descàrrega ordenada de l'escena en curs. Els // 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 // destructors de cada escena són no-bloquejants — ja no fan fades
// bloquejants. La resta de cleanup la gestiona `destroy()`. // bloquejants. La resta de cleanup la gestiona `destroy()`.
JG_QuitSignal(); Jg::quitSignal();
current_scene_.reset(); current_scene_.reset();
} }
@@ -290,7 +287,7 @@ void Director::pollAllEvents() {
void Director::handleEvent(const SDL_Event& event) { void Director::handleEvent(const SDL_Event& event) {
if (event.type == SDL_EVENT_QUIT) { if (event.type == SDL_EVENT_QUIT) {
JG_QuitSignal(); Jg::quitSignal();
requestQuit(); requestQuit();
} }
// Hot-plug de gamepad (a Emscripten els dispositius web entren com // 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 && if (event.type == SDL_EVENT_KEY_DOWN && !event.key.repeat &&
event.key.scancode == KeyConfig::scancode("menu_toggle")) { event.key.scancode == KeyConfig::scancode("menu_toggle")) {
Menu::toggle(); Menu::toggle();
JI_SetInputBlocked(Menu::isOpen()); Ji::setInputBlocked(Menu::isOpen());
menu_keys_held_[event.key.scancode] = true; menu_keys_held_[event.key.scancode] = true;
return; 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 (Menu::isOpen() && event.type == SDL_EVENT_KEY_DOWN && !event.key.repeat) {
if (event.key.scancode == SDL_SCANCODE_ESCAPE) { if (event.key.scancode == SDL_SCANCODE_ESCAPE) {
Menu::close(); Menu::close();
JI_SetInputBlocked(false); Ji::setInputBlocked(false);
// Empassa l'ESC fins al release perquè el joc no la veja per polling // Empassa l'ESC fins al release perquè el joc no la veja per polling
esc_swallow_until_release_ = true; esc_swallow_until_release_ = true;
} else { } else {
Menu::handleKey(event.key.scancode); Menu::handleKey(event.key.scancode);
// El menú pot haver-se tancat (p.ex. Backspace al nivell arrel) // El menú pot haver-se tancat (p.ex. Backspace al nivell arrel)
if (!Menu::isOpen()) { if (!Menu::isOpen()) {
JI_SetInputBlocked(false); Ji::setInputBlocked(false);
} }
} }
menu_keys_held_[event.key.scancode] = true; 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 // Segona pulsació: senyal d'eixida al joc
esc_blocked_ = false; esc_blocked_ = false;
key_pressed_ = true; key_pressed_ = true;
JG_QuitSignal(); Jg::quitSignal();
// Si estem en pausa, la desactivem: el fiber del joc està // Si estem en pausa, la desactivem: el fiber del joc està
// congelat i necessita ser reprès per veure la senyal de // congelat i necessita ser reprès per veure la senyal de
// quit i poder tornar de forma natural. // quit i poder tornar de forma natural.
@@ -392,7 +389,7 @@ void Director::handleEvent(const SDL_Event& event) {
const auto sc = event.key.scancode; const auto sc = event.key.scancode;
if (!KeyConfig::isGuiKey(sc)) { if (!KeyConfig::isGuiKey(sc)) {
key_pressed_ = true; key_pressed_ = true;
JI_moveCheats(sc); Ji::moveCheats(sc);
} }
} }
Mouse::handleEvent(event); Mouse::handleEvent(event);
@@ -400,7 +397,7 @@ void Director::handleEvent(const SDL_Event& event) {
void Director::requestQuit() { void Director::requestQuit() {
quit_requested_ = true; quit_requested_ = true;
JG_QuitSignal(); Jg::quitSignal();
} }
void Director::requestRestart() { void Director::requestRestart() {
+3 -3
View File
@@ -41,7 +41,7 @@ class Director {
// iterate() per evitar manipular l'escena des d'una lambda del menú. // iterate() per evitar manipular l'escena des d'una lambda del menú.
void requestRestart(); 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; auto consumeKeyPressed() -> bool;
// Indica si ESC està bloquejada (el joc no l'ha de veure) // 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> esc_blocked_{false};
std::atomic<bool> paused_{false}; std::atomic<bool> paused_{false};
// Quan el menú tanca amb ESC, empassem-nos l'ESC fins que l'usuari la deixe anar, // 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}; std::atomic<bool> esc_swallow_until_release_{false};
// Tecles consumides pel menú (KEY_DOWN): el KEY_UP associat cal empassar-lo // 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]{}; bool menu_keys_held_[SDL_SCANCODE_COUNT]{};
}; };
+1 -1
View File
@@ -38,7 +38,7 @@ void Bola::update() {
} }
// Augmentem el frame // Augmentem el frame
if (JG_GetCycleCounter() % this->cycles_per_frame == 0) { if (Jg::getCycleCounter() % this->cycles_per_frame == 0) {
this->cur_frame++; this->cur_frame++;
if (this->cur_frame == entitat.animacions[this->o].frames.size()) { if (this->cur_frame == entitat.animacions[this->o].frames.size()) {
this->cur_frame = 0; this->cur_frame = 0;
+1 -1
View File
@@ -32,7 +32,7 @@ Engendro::Engendro(Jd8::Surface gfx, Uint16 x, Uint16 y)
auto Engendro::update() -> bool { auto Engendro::update() -> bool {
bool mort = false; bool mort = false;
if (JG_GetCycleCounter() % this->cycles_per_frame == 0) { if (Jg::getCycleCounter() % this->cycles_per_frame == 0) {
this->cur_frame++; this->cur_frame++;
if (this->cur_frame == entitat.animacions[this->o].frames.size()) { if (this->cur_frame == entitat.animacions[this->o].frames.size()) {
this->cur_frame = 0; this->cur_frame = 0;
+2 -2
View File
@@ -72,13 +72,13 @@ void Mapa::update() {
} }
if (this->porta_oberta && sam->x == 150 && sam->y == 30) { if (this->porta_oberta && sam->x == 150 && sam->y == 30) {
if (JI_KeyPressed(SDL_SCANCODE_UP)) { if (Ji::keyPressed(SDL_SCANCODE_UP)) {
this->sam->o = 4; this->sam->o = 4;
this->sam->y -= 15; this->sam->y -= 15;
} }
} }
if (JG_GetCycleCounter() % 8 == 0) { if (Jg::getCycleCounter() % 8 == 0) {
this->frame_torxes++; this->frame_torxes++;
this->frame_torxes = this->frame_torxes % 4; this->frame_torxes = this->frame_torxes % 4;
} }
+9 -9
View File
@@ -9,7 +9,7 @@
ModuleGame::ModuleGame() { ModuleGame::ModuleGame() {
this->gfx_ = Jd8::loadSurface(info::ctx.pepe_activat ? "gfx/frames2.gif" : "gfx/frames.gif"); this->gfx_ = Jd8::loadSurface(info::ctx.pepe_activat ? "gfx/frames2.gif" : "gfx/frames.gif");
JG_SetUpdateTicks(10); Jg::setUpdateTicks(10);
this->sam_ = std::make_unique<Prota>(this->gfx_); this->sam_ = std::make_unique<Prota>(this->gfx_);
this->mapa_ = std::make_unique<Mapa>(this->gfx_, this->sam_.get()); this->mapa_ = std::make_unique<Mapa>(this->gfx_, this->sam_.get());
@@ -92,7 +92,7 @@ void ModuleGame::tick(int delta_ms) {
} }
auto ModuleGame::nextState() const -> int { auto ModuleGame::nextState() const -> int {
if (JG_Quitting()) { if (Jg::quitting()) {
return -1; return -1;
} }
if (info::ctx.num_habitacio == 1 || if (info::ctx.num_habitacio == 1 ||
@@ -133,8 +133,8 @@ void ModuleGame::draw() {
} }
void ModuleGame::update() { void ModuleGame::update() {
if (JG_ShouldUpdate()) { if (Jg::shouldUpdate()) {
JI_Update(); Ji::update();
this->final_ = this->sam_->update(); this->final_ = this->sam_->update();
const auto erased = std::erase_if(this->momies_, [](auto& m) { return m->update(); }); const auto erased = std::erase_if(this->momies_, [](auto& m) { return m->update(); });
@@ -148,14 +148,14 @@ void ModuleGame::update() {
info::ctx.momies++; info::ctx.momies++;
} }
if (JI_CheatActivated("reviu")) { if (Ji::cheatActivated("reviu")) {
info::ctx.vida = 5; info::ctx.vida = 5;
} }
if (JI_CheatActivated("alone")) { if (Ji::cheatActivated("alone")) {
this->momies_.clear(); this->momies_.clear();
info::ctx.momies = 0; info::ctx.momies = 0;
} }
if (JI_CheatActivated("obert")) { if (Ji::cheatActivated("obert")) {
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
this->mapa_->tombes[i].costat[0] = true; this->mapa_->tombes[i].costat[0] = true;
this->mapa_->tombes[i].costat[1] = true; this->mapa_->tombes[i].costat[1] = true;
@@ -165,8 +165,8 @@ void ModuleGame::update() {
} }
} }
if (JI_KeyPressed(SDL_SCANCODE_ESCAPE)) { if (Ji::keyPressed(SDL_SCANCODE_ESCAPE)) {
JG_QuitSignal(); Jg::quitSignal();
} }
} }
} }
+3 -3
View File
@@ -16,14 +16,14 @@
// Escena de gameplay pur. Reemplaça el vell `Go()` bloquejant amb // Escena de gameplay pur. Reemplaça el vell `Go()` bloquejant amb
// l'interfície `scenes::Scene` tick-based: `onEnter()` arranca la // l'interfície `scenes::Scene` tick-based: `onEnter()` arranca la
// música i un fade-in, el `tick()` avança un frame (Draw + Update // música i un fade-in, el `tick()` avança un frame (Draw + Update
// gated per JG_ShouldUpdate), i quan la partida acaba fa un fade-out // gated per Jg::shouldUpdate), i quan la partida acaba fa un fade-out
// abans de retornar el next state. // abans de retornar el next state.
// //
// Tres fases internes: // Tres fases internes:
// 1. FADING_IN — fade-in 32 passos mentre el render segueix viu. // 1. FADING_IN — fade-in 32 passos mentre el render segueix viu.
// 2. Playing — gameplay normal; `final_` es setja quan el prota mor // 2. Playing — gameplay normal; `final_` es setja quan el prota mor
// o canvia de sala. `Update()` només avança cada 10 ms // o canvia de sala. `Update()` només avança cada 10 ms
// via `JG_ShouldUpdate` (ticker fix del jail). // via `Jg::shouldUpdate` (ticker fix del jail).
// 3. FADING_OUT — fade-out 32 passos mantenint l'últim frame visible // 3. FADING_OUT — fade-out 32 passos mantenint l'últim frame visible
// (substituïx el `JD8_FadeOut` bloquejant que feia el // (substituïx el `JD8_FadeOut` bloquejant que feia el
// destructor legacy). // destructor legacy).
@@ -51,7 +51,7 @@ class ModuleGame : public scenes::Scene {
}; };
void draw(); // render a `screen`; no crida Jd8::flip (ho fa el caller) void draw(); // render a `screen`; no crida Jd8::flip (ho fa el caller)
void update(); // gated per JG_ShouldUpdate void update(); // gated per Jg::shouldUpdate
void iniciarMomies(); void iniciarMomies();
void applyFinalTransitions() const; // muta info::ctx quan final_ passa a !=0 void applyFinalTransitions() const; // muta info::ctx quan final_ passa a !=0
+3 -3
View File
@@ -74,7 +74,7 @@ void Momia::draw() {
Sprite::draw(); Sprite::draw();
if (info::ctx.num_piramide == 4) { if (info::ctx.num_piramide == 4) {
if ((JG_GetCycleCounter() % 40) < 20) { if ((Jg::getCycleCounter() % 40) < 20) {
Jd8::blitCK(this->x, this->y, this->gfx, 220, 80, 15, 15, 255); Jd8::blitCK(this->x, this->y, this->gfx, 220, 80, 15, 15, 255);
} else { } else {
Jd8::blitCK(this->x, this->y, this->gfx, 235, 80, 15, 15, 255); Jd8::blitCK(this->x, this->y, this->gfx, 235, 80, 15, 15, 255);
@@ -93,7 +93,7 @@ auto Momia::update() -> bool {
return morta; return morta;
} }
if (this->sam->o < 4 && (this->dimoni || info::ctx.num_piramide == 5 || JG_GetCycleCounter() % 2 == 0)) { if (this->sam->o < 4 && (this->dimoni || info::ctx.num_piramide == 5 || Jg::getCycleCounter() % 2 == 0)) {
if ((this->x - 20) % 65 == 0 && (this->y - 30) % 35 == 0) { if ((this->x - 20) % 65 == 0 && (this->y - 30) % 35 == 0) {
if (this->dimoni) { if (this->dimoni) {
if (rand() % 2 == 0) { if (rand() % 2 == 0) {
@@ -147,7 +147,7 @@ auto Momia::update() -> bool {
break; break;
} }
if (JG_GetCycleCounter() % this->cycles_per_frame == 0) { if (Jg::getCycleCounter() % this->cycles_per_frame == 0) {
this->cur_frame++; this->cur_frame++;
if (this->cur_frame == entitat.animacions[this->o].frames.size()) { if (this->cur_frame == entitat.animacions[this->o].frames.size()) {
this->cur_frame = 0; this->cur_frame = 0;
+7 -7
View File
@@ -91,7 +91,7 @@ void Prota::draw() {
Sprite::draw(); Sprite::draw();
if (info::ctx.num_piramide == 4 && this->o != 4) { if (info::ctx.num_piramide == 4 && this->o != 4) {
if ((JG_GetCycleCounter() % 40) < 20) { if ((Jg::getCycleCounter() % 40) < 20) {
Jd8::blitCK(this->x, this->y, this->gfx, 220, 80, 15, 15, 255); Jd8::blitCK(this->x, this->y, this->gfx, 220, 80, 15, 15, 255);
} else { } else {
Jd8::blitCK(this->x, this->y, this->gfx, 235, 80, 15, 15, 255); Jd8::blitCK(this->x, this->y, this->gfx, 235, 80, 15, 15, 255);
@@ -104,25 +104,25 @@ auto Prota::update() -> Uint8 {
if (this->o < 4) { if (this->o < 4) {
Uint8 dir = 4; Uint8 dir = 4;
if (JI_KeyPressed(SDL_SCANCODE_DOWN)) { if (Ji::keyPressed(SDL_SCANCODE_DOWN)) {
if ((this->x - 20) % 65 == 0) { if ((this->x - 20) % 65 == 0) {
this->o = 0; this->o = 0;
} }
dir = this->o; dir = this->o;
} }
if (JI_KeyPressed(SDL_SCANCODE_UP)) { if (Ji::keyPressed(SDL_SCANCODE_UP)) {
if ((this->x - 20) % 65 == 0) { if ((this->x - 20) % 65 == 0) {
this->o = 1; this->o = 1;
} }
dir = this->o; dir = this->o;
} }
if (JI_KeyPressed(SDL_SCANCODE_RIGHT)) { if (Ji::keyPressed(SDL_SCANCODE_RIGHT)) {
if ((this->y - 30) % 35 == 0) { if ((this->y - 30) % 35 == 0) {
this->o = 2; this->o = 2;
} }
dir = this->o; dir = this->o;
} }
if (JI_KeyPressed(SDL_SCANCODE_LEFT)) { if (Ji::keyPressed(SDL_SCANCODE_LEFT)) {
if ((this->y - 30) % 35 == 0) { if ((this->y - 30) % 35 == 0) {
this->o = 3; this->o = 3;
} }
@@ -161,7 +161,7 @@ auto Prota::update() -> Uint8 {
if (this->frame_pejades == 15) { if (this->frame_pejades == 15) {
this->frame_pejades = 0; this->frame_pejades = 0;
} }
if (JG_GetCycleCounter() % this->cycles_per_frame == 0) { if (Jg::getCycleCounter() % this->cycles_per_frame == 0) {
this->cur_frame++; this->cur_frame++;
if (this->cur_frame == entitat.animacions[this->o].frames.size()) { if (this->cur_frame == entitat.animacions[this->o].frames.size()) {
this->cur_frame = 0; this->cur_frame = 0;
@@ -170,7 +170,7 @@ auto Prota::update() -> Uint8 {
} }
eixir = 0U; eixir = 0U;
} else { } else {
if (JG_GetCycleCounter() % this->cycles_per_frame == 0) { if (Jg::getCycleCounter() % this->cycles_per_frame == 0) {
this->cur_frame++; this->cur_frame++;
if (this->cur_frame == entitat.animacions[this->o].frames.size()) { if (this->cur_frame == entitat.animacions[this->o].frames.size()) {
if (this->o == 4) { if (this->o == 4) {
+1 -1
View File
@@ -48,7 +48,7 @@ namespace scenes {
break; break;
case Phase::Showing: case Phase::Showing:
if (JI_AnyKey()) { if (Ji::anyKey()) {
remaining_ms_ = 0; remaining_ms_ = 0;
} else { } else {
remaining_ms_ -= delta_ms; remaining_ms_ -= delta_ms;
+3 -3
View File
@@ -29,7 +29,7 @@ namespace {
}; };
constexpr int CONTADOR_MAX = 3100; // ~62 s de crèdits a 20 ms/tick constexpr int CONTADOR_MAX = 3100; // ~62 s de crèdits a 20 ms/tick
constexpr int TICK_MS = 20; // JG_SetUpdateTicks heretat del doSlides previ constexpr int TICK_MS = 20; // Jg::setUpdateTicks heretat del doSlides previ
constexpr int BG_INDEX = 255; constexpr int BG_INDEX = 255;
} // namespace } // namespace
@@ -111,7 +111,7 @@ namespace scenes {
switch (phase_) { switch (phase_) {
case Phase::Rolling: { case Phase::Rolling: {
// Avancem el contador en passos discrets de 20 ms, igual // Avancem el contador en passos discrets de 20 ms, igual
// que feia JG_ShouldUpdate(20) al vell doCredits. // que feia Jg::shouldUpdate(20) al vell doCredits.
contador_acc_ms_ += delta_ms; contador_acc_ms_ += delta_ms;
while (contador_acc_ms_ >= TICK_MS) { while (contador_acc_ms_ >= TICK_MS) {
contador_acc_ms_ -= TICK_MS; contador_acc_ms_ -= TICK_MS;
@@ -121,7 +121,7 @@ namespace scenes {
coche_.tick(delta_ms); coche_.tick(delta_ms);
render(); render();
if (JI_AnyKey() || contador_ >= CONTADOR_MAX) { if (Ji::anyKey() || contador_ >= CONTADOR_MAX) {
writeTrickIni(); writeTrickIni();
fade_.startFadeOut(); fade_.startFadeOut();
phase_ = Phase::FadingOut; phase_ = Phase::FadingOut;
+1 -1
View File
@@ -137,7 +137,7 @@ namespace scenes {
// TOTA la intro (inclou saltar la fase de sprites). Durant Sprites // TOTA la intro (inclou saltar la fase de sprites). Durant Sprites
// deixem que la sub-escena gestione el seu propi skip (que a més // deixem que la sub-escena gestione el seu propi skip (que a més
// respecta la fase "final" no skippable de la variant 0). // respecta la fase "final" no skippable de la variant 0).
if (phase_ != Phase::Sprites && phase_ != Phase::Done && JI_AnyKey()) { if (phase_ != Phase::Sprites && phase_ != Phase::Done && Ji::anyKey()) {
info::ctx.num_piramide = 0; info::ctx.num_piramide = 0;
phase_ = Phase::Done; phase_ = Phase::Done;
return; return;
+2 -2
View File
@@ -7,7 +7,7 @@
namespace { namespace {
// Timings idèntics als del vell `doIntro()`: el JG_SetUpdateTicks(1000) // Timings idèntics als del vell `doIntro()`: el Jg::setUpdateTicks(1000)
// inicial, (100) per a les 3 primeres lletres (J, A, I), (200) per a // inicial, (100) per a les 3 primeres lletres (J, A, I), (200) per a
// "JAIL" i el seu clear, (100) per a les 4 lletres centrals // "JAIL" i el seu clear, (100) per a les 4 lletres centrals
// (G, A, M, E) i (200) per a la resta fins al cicle de paleta. // (G, A, M, E) i (200) per a la resta fins al cicle de paleta.
@@ -152,7 +152,7 @@ namespace scenes {
// (inclou saltar la fase de sprites). Durant Sprites deixem que // (inclou saltar la fase de sprites). Durant Sprites deixem que
// la sub-escena gestione el seu propi skip internament, que a més // la sub-escena gestione el seu propi skip internament, que a més
// respecta la fase "final" no skippable de la variant 0. // respecta la fase "final" no skippable de la variant 0.
if (phase_ != Phase::Sprites && phase_ != Phase::Done && JI_AnyKey()) { if (phase_ != Phase::Sprites && phase_ != Phase::Done && Ji::anyKey()) {
info::ctx.num_piramide = 0; info::ctx.num_piramide = 0;
phase_ = Phase::Done; phase_ = Phase::Done;
return; return;
+2 -2
View File
@@ -9,7 +9,7 @@
namespace { namespace {
// Duració d'un pas. El vell doIntroSprites feia JG_SetUpdateTicks(20); // Duració d'un pas. El vell doIntroSprites feia Jg::setUpdateTicks(20);
// cada iteració del seu for (i) consumia un tick de 20 ms. // cada iteració del seu for (i) consumia un tick de 20 ms.
constexpr int TICK_MS = 20; constexpr int TICK_MS = 20;
@@ -346,7 +346,7 @@ namespace scenes {
// Skip per tecla. Durant la fase marcada com a no skippable (només // Skip per tecla. Durant la fase marcada com a no skippable (només
// v0Final al vell codi) s'ignora — preserva la semàntica del vell // v0Final al vell codi) s'ignora — preserva la semàntica del vell
// bucle final de la variant 0 que no cridava wait_frame_or_skip. // bucle final de la variant 0 que no cridava wait_frame_or_skip.
if (phases[phase_].skippable && JI_AnyKey()) { if (phases[phase_].skippable && Ji::anyKey()) {
done_ = true; done_ = true;
return; return;
} }
+3 -3
View File
@@ -98,9 +98,9 @@ namespace scenes {
// Qualsevol tecla tanca el menú. Llegim 'P' explícitament abans // Qualsevol tecla tanca el menú. Llegim 'P' explícitament abans
// de reiniciar el flag de input perquè `info::ctx.pepe_activat` // de reiniciar el flag de input perquè `info::ctx.pepe_activat`
// reflecteixca si l'usuari estava polsant P al moment d'eixir. // reflecteixca si l'usuari estava polsant P al moment d'eixir.
if (JI_AnyKey() || JI_KeyPressed(SDL_SCANCODE_P)) { if (Ji::anyKey() || Ji::keyPressed(SDL_SCANCODE_P)) {
info::ctx.pepe_activat = JI_KeyPressed(SDL_SCANCODE_P); info::ctx.pepe_activat = Ji::keyPressed(SDL_SCANCODE_P);
JI_DisableKeyboard(60); Ji::disableKeyboard(60);
info::ctx.num_piramide = 1; info::ctx.num_piramide = 1;
fade_.startFadeOut(); fade_.startFadeOut();
phase_ = Phase::FadingOut; phase_ = Phase::FadingOut;
+2 -2
View File
@@ -11,7 +11,7 @@ namespace scenes {
void MortScene::onEnter() { void MortScene::onEnter() {
playMusic("music/mort.ogg"); playMusic("music/mort.ogg");
JI_DisableKeyboard(60); Ji::disableKeyboard(60);
info::ctx.vida = 5; info::ctx.vida = 5;
gfx_ = SurfaceHandle("gfx/gameover.gif"); gfx_ = SurfaceHandle("gfx/gameover.gif");
@@ -38,7 +38,7 @@ namespace scenes {
break; break;
case Phase::Showing: case Phase::Showing:
if (JI_AnyKey()) { if (Ji::anyKey()) {
remaining_ms_ = 0; remaining_ms_ = 0;
} else { } else {
remaining_ms_ -= delta_ms; remaining_ms_ -= delta_ms;
+2 -2
View File
@@ -12,7 +12,7 @@
namespace { namespace {
constexpr int TICK_MS = 20; // JG_SetUpdateTicks(20) del vell doSecreta constexpr int TICK_MS = 20; // Jg::setUpdateTicks(20) del vell doSecreta
// Durades per fase, derivades dels contador-thresholds del vell: // Durades per fase, derivades dels contador-thresholds del vell:
// tomba1 scroll: 127 passos (contador 1→128) × 20ms // tomba1 scroll: 127 passos (contador 1→128) × 20ms
@@ -85,7 +85,7 @@ namespace scenes {
// Skip per tecla (després del fade inicial, no mentre). Salta // Skip per tecla (després del fade inicial, no mentre). Salta
// directament al FinalFadeOut. Mateix patró que el vell, on // directament al FinalFadeOut. Mateix patró que el vell, on
// qualsevol tecla sortia del loop. // qualsevol tecla sortia del loop.
if (!skip_triggered_ && phase_ != Phase::InitialFadeOut && JI_AnyKey()) { if (!skip_triggered_ && phase_ != Phase::InitialFadeOut && Ji::anyKey()) {
skip_triggered_ = true; skip_triggered_ = true;
beginFinalFade(); beginFinalFade();
} }
+1 -1
View File
@@ -103,7 +103,7 @@ namespace scenes {
// Skip: qualsevol tecla salta directament al fade final. Per fidelitat // Skip: qualsevol tecla salta directament al fade final. Per fidelitat
// al vell doSlides, el skip NO atura la música explícitament — només // al vell doSlides, el skip NO atura la música explícitament — només
// el final natural crida Ja::fadeOutMusic (beginFinalFade() distingeix). // el final natural crida Ja::fadeOutMusic (beginFinalFade() distingeix).
if (!skip_triggered_ && JI_AnyKey()) { if (!skip_triggered_ && Ji::anyKey()) {
skip_triggered_ = true; skip_triggered_ = true;
if (num_piramide_at_start_ != 7) { if (num_piramide_at_start_ != 7) {
Audio::get()->fadeOutMusic(250); Audio::get()->fadeOutMusic(250);
+2 -2
View File
@@ -89,7 +89,7 @@ auto SDL_AppInit(void** /*appstate*/, int /*argc*/, char* /*argv*/[]) -> SDL_App
Options::setCrtPiFile(std::string(file_getconfigfolder()) + "crtpi.yaml"); Options::setCrtPiFile(std::string(file_getconfigfolder()) + "crtpi.yaml");
Options::loadCrtPiFromFile(); Options::loadCrtPiFromFile();
JG_Init(); Jg::init();
Screen::init(); Screen::init();
Jd8::init(); Jd8::init();
Audio::init(); // crida internament Ja::init i aplica Options::audio Audio::init(); // crida internament Ja::init i aplica Options::audio
@@ -149,6 +149,6 @@ void SDL_AppQuit(void* /*appstate*/, SDL_AppResult /*result*/) {
Audio::destroy(); // el destructor del singleton crida Ja::quit Audio::destroy(); // el destructor del singleton crida Ja::quit
Jd8::quit(); Jd8::quit();
Screen::destroy(); Screen::destroy();
JG_Finalize(); Jg::finalize();
ResourceHelper::shutdownResourceSystem(); ResourceHelper::shutdownResourceSystem();
} }