fix: tidy namespace Scenes::/Info:: PascalCase i locals UPPER_CASE

This commit is contained in:
2026-05-16 15:06:16 +02:00
parent ae89b252e2
commit ae359f4a1e
55 changed files with 303 additions and 303 deletions
+1 -1
View File
@@ -334,5 +334,5 @@ auto Jd8::fadeTickStep() -> bool {
// eliminats a Phase B.2: feien un bucle de 32 iteracions amb `Jd8::flip`
// entre cada una que només funcionava mentre l'entorn tenia fibers i
// `Jd8::flip` cedia el control al Director. Ara tot fade es fa tick a
// tick via `scenes::PaletteFade` (que encapsula `Jd8::fadeStartOut` /
// tick via `Scenes::PaletteFade` (que encapsula `Jd8::fadeStartOut` /
// `Jd8::fadeStartToPal` + `Jd8::fadeTickStep`).
+1 -1
View File
@@ -69,7 +69,7 @@ namespace Jd8 {
// (32 passos en total). El caller és responsable de fer el Flip entre
// passos si el vol veure animat. `fadeIsActive` permet saber si hi ha
// un fade en curs per a enllaçar-lo amb un altre subsistema.
// L'embolcall `scenes::PaletteFade` ho fa més idiomàtic per a escenes.
// L'embolcall `Scenes::PaletteFade` ho fa més idiomàtic per a escenes.
void fadeStartOut();
void fadeStartToPal(const Color* pal);
auto fadeTickStep() -> bool;
+7 -7
View File
@@ -33,9 +33,9 @@ void Jg::setUpdateTicks(Uint32 milliseconds) {
}
auto Jg::shouldUpdate() -> bool {
const Uint32 now = SDL_GetTicks();
if (now - update_time > update_ticks) {
update_time = now;
const Uint32 NOW = SDL_GetTicks();
if (NOW - update_time > update_ticks) {
update_time = NOW;
cycle_counter++;
return true;
}
@@ -50,8 +50,8 @@ auto Jg::getCycleCounter() -> Uint32 {
}
auto Jg::getDeltaMs() -> Uint32 {
const Uint32 now = SDL_GetTicks();
const Uint32 delta = now - last_delta_time;
last_delta_time = now;
return delta;
const Uint32 NOW = SDL_GetTicks();
const Uint32 DELTA = NOW - last_delta_time;
last_delta_time = NOW;
return DELTA;
}
+21 -21
View File
@@ -231,28 +231,28 @@ void Screen::present(Uint32* pixel_data) {
// no trencar la selecció de l'usuari.
Rendering::PostFXParams clean{};
shader_backend_->setPostFXParams(clean);
const auto prev_shader = shader_backend_->getActiveShader();
if (prev_shader != Rendering::ShaderType::POSTFX) {
const auto PREV_SHADER = shader_backend_->getActiveShader();
if (PREV_SHADER != Rendering::ShaderType::POSTFX) {
shader_backend_->setActiveShader(Rendering::ShaderType::POSTFX);
}
shader_backend_->uploadPixels(pixel_data, GAME_WIDTH, GAME_HEIGHT);
shader_backend_->render();
if (prev_shader != Rendering::ShaderType::POSTFX) {
shader_backend_->setActiveShader(prev_shader);
if (PREV_SHADER != Rendering::ShaderType::POSTFX) {
shader_backend_->setActiveShader(PREV_SHADER);
}
} else {
// Fallback SDL_Renderer. A mult=1, flux directe original: logical
// Fallback SDL_Renderer. A MULT=1, flux directe original: logical
// presentation (setada per applyFallbackPresentation) + scale mode de
// texture_ segons l'opció. A mult>1, la còpia intermèdia crea la
// texture_ segons l'opció. A MULT>1, la còpia intermèdia crea la
// font ampliada (NN via GPU), i es presenta via logical presentation
// a la mida de la font intermèdia.
SDL_UpdateTexture(texture_, nullptr, pixel_data, GAME_WIDTH * sizeof(Uint32));
const int mult = Options::video.internal_resolution;
if (mult > 1) {
const int MULT = Options::video.internal_resolution;
if (MULT > 1) {
ensureFallbackInternalTexture();
if (internal_texture_sdl_ != nullptr) {
// Còpia NN a la textura intermèdia (mult·game). Sampler NN
// Còpia NN a la textura intermèdia (MULT·game). Sampler NN
// per construcció: volem píxels grans i nets.
SDL_SetTextureScaleMode(texture_, SDL_SCALEMODE_NEAREST);
SDL_SetRenderTarget(renderer_, internal_texture_sdl_);
@@ -261,7 +261,7 @@ void Screen::present(Uint32* pixel_data) {
SDL_SetRenderTarget(renderer_, nullptr);
// Filtre global al pas final → finestra (via logical presentation
// que applyFallbackPresentation ja configura amb mida game·mult).
// que applyFallbackPresentation ja configura amb mida game·MULT).
SDL_ScaleMode final_scale = (Options::video.texture_filter == Options::TextureFilter::LINEAR)
? SDL_SCALEMODE_LINEAR
: SDL_SCALEMODE_NEAREST;
@@ -273,9 +273,9 @@ void Screen::present(Uint32* pixel_data) {
}
// Si la creació de la textura intermèdia ha fallat, caiem al path normal.
}
// mult=1 (o fallback-del-fallback): texture_ directament. El scale mode
// MULT=1 (o fallback-del-fallback): texture_ directament. El scale mode
// el manté applyFallbackPresentation — però el re-apliquem per si la
// ruta mult>1 el va sobreescriure anteriorment.
// ruta MULT>1 el va sobreescriure anteriorment.
SDL_ScaleMode direct_scale = (Options::video.texture_filter == Options::TextureFilter::LINEAR)
? SDL_SCALEMODE_LINEAR
: SDL_SCALEMODE_NEAREST;
@@ -632,16 +632,16 @@ void Screen::applyFallbackPresentation() {
}
// Amb resolució interna N > 1, la mida lògica creix proporcionalment
// perquè SDL scale des de 320·N × 200·N a la finestra — menys aggressive linear.
const int mult = Options::video.internal_resolution < 1 ? 1 : Options::video.internal_resolution;
SDL_SetRenderLogicalPresentation(renderer_, GAME_WIDTH * mult, GAME_HEIGHT * mult, mode);
const int MULT = Options::video.internal_resolution < 1 ? 1 : Options::video.internal_resolution;
SDL_SetRenderLogicalPresentation(renderer_, GAME_WIDTH * MULT, GAME_HEIGHT * MULT, mode);
}
void Screen::ensureFallbackInternalTexture() {
if (renderer_ == nullptr) {
return;
}
const int mult = Options::video.internal_resolution;
if (mult <= 1) {
const int MULT = Options::video.internal_resolution;
if (MULT <= 1) {
// No cal textura intermèdia — recicla si la teníem.
if (internal_texture_sdl_ != nullptr) {
SDL_DestroyTexture(internal_texture_sdl_);
@@ -650,7 +650,7 @@ void Screen::ensureFallbackInternalTexture() {
}
return;
}
if (internal_texture_sdl_ != nullptr && internal_texture_mult_ == mult) {
if (internal_texture_sdl_ != nullptr && internal_texture_mult_ == MULT) {
return;
}
@@ -661,15 +661,15 @@ void Screen::ensureFallbackInternalTexture() {
internal_texture_sdl_ = SDL_CreateTexture(renderer_,
SDL_PIXELFORMAT_ABGR8888,
SDL_TEXTUREACCESS_TARGET,
GAME_WIDTH * mult,
GAME_HEIGHT * mult);
GAME_WIDTH * MULT,
GAME_HEIGHT * MULT);
if (internal_texture_sdl_ == nullptr) {
std::cerr << "Screen: failed to create fallback internal texture (×" << mult << "): "
std::cerr << "Screen: failed to create fallback internal texture (×" << MULT << "): "
<< SDL_GetError() << '\n';
internal_texture_mult_ = 0;
return;
}
internal_texture_mult_ = mult;
internal_texture_mult_ = MULT;
}
void Screen::adjustWindowSize() {
@@ -906,8 +906,8 @@ namespace Rendering {
// ---- Calcular viewport (dimensions lògiques del canvas) ----
// Si 4:3 actiu, effective_height ja és 240 (la textura estirada)
const auto logical_w = static_cast<float>(game_width_);
const auto logical_h = static_cast<float>(effective_height);
const auto LOGICAL_W = static_cast<float>(game_width_);
const auto LOGICAL_H = static_cast<float>(effective_height);
float vx = 0.0F;
float vy = 0.0F;
@@ -916,8 +916,8 @@ namespace Rendering {
switch (scaling_mode_) {
case Options::ScalingMode::DISABLED:
// 1:1, sense escala (pot ser diminut en finestres grans)
vw = logical_w;
vh = logical_h;
vw = LOGICAL_W;
vh = LOGICAL_H;
break;
case Options::ScalingMode::STRETCH:
// Omple tota la finestra, escala no uniforme
@@ -925,23 +925,23 @@ namespace Rendering {
vh = static_cast<float>(sh);
break;
case Options::ScalingMode::LETTERBOX: {
const float SCALE = std::min(static_cast<float>(sw) / logical_w,
static_cast<float>(sh) / logical_h);
vw = logical_w * SCALE;
vh = logical_h * SCALE;
const float SCALE = std::min(static_cast<float>(sw) / LOGICAL_W,
static_cast<float>(sh) / LOGICAL_H);
vw = LOGICAL_W * SCALE;
vh = LOGICAL_H * SCALE;
break;
}
case Options::ScalingMode::OVERSCAN: {
const float SCALE = std::max(static_cast<float>(sw) / logical_w,
static_cast<float>(sh) / logical_h);
vw = logical_w * SCALE;
vh = logical_h * SCALE;
const float SCALE = std::max(static_cast<float>(sw) / LOGICAL_W,
static_cast<float>(sh) / LOGICAL_H);
vw = LOGICAL_W * SCALE;
vh = LOGICAL_H * SCALE;
break;
}
case Options::ScalingMode::INTEGER: {
const int SCALE = std::max(1, std::min(static_cast<int>(sw) / static_cast<int>(logical_w), static_cast<int>(sh) / static_cast<int>(logical_h)));
vw = logical_w * static_cast<float>(SCALE);
vh = logical_h * static_cast<float>(SCALE);
const int SCALE = std::max(1, std::min(static_cast<int>(sw) / static_cast<int>(LOGICAL_W), static_cast<int>(sh) / static_cast<int>(LOGICAL_H)));
vw = LOGICAL_W * static_cast<float>(SCALE);
vh = LOGICAL_H * static_cast<float>(SCALE);
break;
}
}
+3 -3
View File
@@ -108,8 +108,8 @@ namespace Resource {
return true;
}
const Uint64 start_ns = SDL_GetTicksNS();
const Uint64 budget_ns = static_cast<Uint64>(budget_ms) * 1'000'000ULL;
const Uint64 START_NS = SDL_GetTicksNS();
const Uint64 BUDGET_NS = static_cast<Uint64>(budget_ms) * 1'000'000ULL;
const auto* list = List::get();
while (stage_ != LoadStage::DONE) {
@@ -173,7 +173,7 @@ namespace Resource {
case LoadStage::DONE:
break;
}
if ((SDL_GetTicksNS() - start_ns) >= budget_ns) {
if ((SDL_GetTicksNS() - START_NS) >= BUDGET_NS) {
break;
}
}
+2 -2
View File
@@ -14,8 +14,8 @@ namespace ResourceHelper {
bool fallback_enabled_ = true;
auto readFromDisk(const std::string& relative_path) -> std::vector<uint8_t> {
const std::string full = std::string(Jf::getResourceFolder()) + relative_path;
std::ifstream file(full, std::ios::binary | std::ios::ate);
const std::string FULL = std::string(Jf::getResourceFolder()) + relative_path;
std::ifstream file(FULL, std::ios::binary | std::ios::ate);
if (!file) {
return {};
}
+33 -33
View File
@@ -37,42 +37,42 @@ std::unique_ptr<Director> Director::instance_;
Director::~Director() = default;
void Director::initGameContext() {
info::ctx.num_habitacio = Options::game.habitacio_inicial;
info::ctx.num_piramide = Options::game.piramide_inicial;
info::ctx.diners = Options::game.diners_inicial;
info::ctx.diamants = Options::game.diamants_inicial;
info::ctx.vida = Options::game.vides;
info::ctx.momies = 0;
info::ctx.nou_personatge = false;
info::ctx.pepe_activat = false;
Info::ctx.num_habitacio = Options::game.habitacio_inicial;
Info::ctx.num_piramide = Options::game.piramide_inicial;
Info::ctx.diners = Options::game.diners_inicial;
Info::ctx.diamants = Options::game.diamants_inicial;
Info::ctx.vida = Options::game.vides;
Info::ctx.momies = 0;
Info::ctx.nou_personatge = false;
Info::ctx.pepe_activat = false;
FILE* ini = fopen("trick.ini", "rb");
if (ini != nullptr) {
info::ctx.nou_personatge = true;
Info::ctx.nou_personatge = true;
fclose(ini);
}
}
auto Director::createNextScene() const -> std::unique_ptr<scenes::Scene> {
auto Director::createNextScene() const -> std::unique_ptr<Scenes::Scene> {
// Mentre el Resource::Cache no haja acabat de precarregar, executem
// el BootLoaderScene — pinta una barra de progrés i avança la
// càrrega per pressupost de temps. Quan acaba, retorna i tornem ací
// amb el cache plenament disponible per a la resta d'escenes.
if (Resource::Cache::get() != nullptr && !Resource::Cache::get()->isLoadDone()) {
return std::make_unique<scenes::BootLoaderScene>();
return std::make_unique<Scenes::BootLoaderScene>();
}
if (game_state_ == 0) {
// Gameplay. ModuleGame és una scenes::Scene des de la Phase A.
// Gameplay. ModuleGame és una Scenes::Scene des de la Phase A.
return std::make_unique<ModuleGame>();
}
// game_state_ == 1: dispatch al registry per num_piramide. Replica
// del redirect que el vell ModuleSequence::Go() feia: si el jugador
// arriba a la Secreta (6) sense prou diners, salta als slides de
// fracàs (7) abans de buscar l'escena al registry.
if (info::ctx.num_piramide == 6 && info::ctx.diners < 200) {
info::ctx.num_piramide = 7;
if (Info::ctx.num_piramide == 6 && Info::ctx.diners < 200) {
Info::ctx.num_piramide = 7;
}
return scenes::SceneRegistry::instance().tryCreate(info::ctx.num_piramide);
return Scenes::SceneRegistry::instance().tryCreate(Info::ctx.num_piramide);
}
void Director::init() {
@@ -80,34 +80,34 @@ void Director::init() {
Gamepad::init();
// Registre d'escenes. Cada entrada = un state_key (`num_piramide`)
// amb una factory de `scenes::Scene`. iterate() consulta aquest
// amb una factory de `Scenes::Scene`. iterate() consulta aquest
// registry per a tots els states de seqüència (game_state_ == 1); si
// una clau no apareix ací, Director surt ordenadament.
auto& registry = scenes::SceneRegistry::instance();
registry.registerScene(0, [] { return std::make_unique<scenes::MenuScene>(); });
registry.registerScene(100, [] { return std::make_unique<scenes::MortScene>(); });
auto& registry = Scenes::SceneRegistry::instance();
registry.registerScene(0, [] { return std::make_unique<Scenes::MenuScene>(); });
registry.registerScene(100, [] { return std::make_unique<Scenes::MortScene>(); });
// BannerScene cobreix les piràmides 2..5 (el vell doBanner decideix
// pel switch intern llegint info::ctx.num_piramide).
// pel switch intern llegint Info::ctx.num_piramide).
for (int p = 2; p <= 5; ++p) {
registry.registerScene(p, [] { return std::make_unique<scenes::BannerScene>(); });
registry.registerScene(p, [] { return std::make_unique<Scenes::BannerScene>(); });
}
// SlidesScene cobreix els dos states on el vell `doSlides` s'invocava:
// - num_piramide == 1: slides narratius inicials (entrada al joc)
// - num_piramide == 7: slides de fracàs (ve del redirect 6→7 quan
// l'usuari no té prou diners per a la Secreta)
registry.registerScene(1, [] { return std::make_unique<scenes::SlidesScene>(); });
registry.registerScene(7, [] { return std::make_unique<scenes::SlidesScene>(); });
registry.registerScene(6, [] { return std::make_unique<scenes::SecretaScene>(); });
registry.registerScene(8, [] { return std::make_unique<scenes::CreditsScene>(); });
registry.registerScene(1, [] { return std::make_unique<Scenes::SlidesScene>(); });
registry.registerScene(7, [] { return std::make_unique<Scenes::SlidesScene>(); });
registry.registerScene(6, [] { return std::make_unique<Scenes::SecretaScene>(); });
registry.registerScene(8, [] { return std::make_unique<Scenes::CreditsScene>(); });
// State 255 (intro): dues variants segons `Options::game.use_new_logo`.
// La factory tria a runtime — així es pot togglar des del menú sense
// re-registrar. Les dues escenes construeixen una IntroSpritesScene
// com a sub-escena per a la part d'animacions de sprites.
registry.registerScene(255, []() -> std::unique_ptr<scenes::Scene> {
registry.registerScene(255, []() -> std::unique_ptr<Scenes::Scene> {
if (Options::game.use_new_logo) {
return std::make_unique<scenes::IntroNewLogoScene>();
return std::make_unique<Scenes::IntroNewLogoScene>();
}
return std::make_unique<scenes::IntroScene>();
return std::make_unique<Scenes::IntroScene>();
});
}
@@ -149,12 +149,12 @@ auto Director::iterate() -> bool {
restart_requested_ = false;
Audio::get()->stopMusic();
Audio::get()->stopAllSounds();
// Reinicialitza info::ctx des d'Options (vides, diners, diamants...)
// Reinicialitza Info::ctx des d'Options (vides, diners, diamants...)
// en lloc de ctx.reset() pla que deixaria vida=0 → jugador mort.
initGameContext();
// Força l'intro independentment de `piramide_inicial` (que pot estar
// configurat a una piràmide intermèdia per a proves ràpides).
info::ctx.num_piramide = 255;
Info::ctx.num_piramide = 255;
current_scene_.reset();
game_state_ = 1; // 1 = dispatch via SceneRegistry per num_piramide
has_frame_ = false;
@@ -183,9 +183,9 @@ auto Director::iterate() -> bool {
Audio::update();
// Dispara els crèdits cinematogràfics la primera vegada que el joc
// arriba al menú del títol (info::ctx.num_piramide == 0).
// arriba al menú del títol (Info::ctx.num_piramide == 0).
static bool credits_triggered_ = false;
if (!credits_triggered_ && info::ctx.num_piramide == 0) {
if (!credits_triggered_ && Info::ctx.num_piramide == 0) {
if (Options::game.show_title_credits) {
Overlay::startCredits();
}
@@ -210,7 +210,7 @@ auto Director::iterate() -> bool {
}
// Si no hi ha escena activa, construeix la pròxima segons
// 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.
if (!current_scene_) {
if (game_state_ == -1 || Jg::quitting()) {
+6 -6
View File
@@ -10,7 +10,7 @@
// El Director és l'únic thread del runtime. Cada iterate() fa input →
// tick de l'escena actual → Jd8::flip → overlay → present → sleep al frame
// target. Totes les escenes (`scenes::Scene` i `ModuleGame`) són
// target. Totes les escenes (`Scenes::Scene` i `ModuleGame`) són
// tick-based i no bloquegen — no hi ha fibers, mutex ni condition_variable.
// Compatible amb SDL_AppIterate i amb el futur port a emscripten.
class Director {
@@ -36,7 +36,7 @@ class Director {
void requestQuit();
[[nodiscard]] auto isQuitRequested() const -> bool { return quit_requested_; }
// Demana un reinici "suau": para música i sons, reseteja info::ctx i
// Demana un reinici "suau": para música i sons, reseteja Info::ctx i
// torna a l'intro (state 255). Es processa al començament del pròxim
// iterate() per evitar manipular l'escena des d'una lambda del menú.
void requestRestart();
@@ -61,12 +61,12 @@ class Director {
void pollAllEvents(); // drenatge amb SDL_PollEvent, només per al bucle natiu
// Inicialitza info::ctx a partir de Options::game.* i comprova trick.ini.
// Inicialitza Info::ctx a partir de Options::game.* i comprova trick.ini.
// Es crida una sola vegada des d'iterate() a la primera invocació.
static void initGameContext();
// Construeix l'escena apropiada segons game_state_ i info::ctx.
// Construeix l'escena apropiada segons game_state_ i Info::ctx.
// Retorna nullptr si l'state actual no té escena registrada (bug).
[[nodiscard]] auto createNextScene() const -> std::unique_ptr<scenes::Scene>;
[[nodiscard]] auto createNextScene() const -> std::unique_ptr<Scenes::Scene>;
// Buffers persistents entre iteracions. Abans eren locals a run(),
// ara són membres perquè iterate() els pot reutilitzar sense tornar-los
@@ -77,7 +77,7 @@ class Director {
// Estat de l'escena actual. Abans vivia al stack del GameFiber; des
// de la Phase B.2 de la migració viu directament al Director.
std::unique_ptr<scenes::Scene> current_scene_;
std::unique_ptr<Scenes::Scene> current_scene_;
int game_state_{1}; // 0 = gameplay (ModuleGame), 1 = via SceneRegistry, -1 = quit
Uint32 last_tick_ms_{0};
bool context_initialized_{false};