fix: tidy director/jdraw8/jinput/jfile (locals UPPER_CASE, file_*→Jf::)

This commit is contained in:
2026-05-16 14:57:07 +02:00
parent 35cdd88cbb
commit ae89b252e2
8 changed files with 72 additions and 68 deletions
+16 -16
View File
@@ -117,9 +117,9 @@ void Jd8::setScreenPalette(Jd8::Palette palette) {
} }
void Jd8::fillSquare(int ini, int height, Uint8 color) { void Jd8::fillSquare(int ini, int height, Uint8 color) {
const int offset = ini * 320; const int OFFSET = ini * 320;
const int size = height * 320; const int SIZE = height * 320;
memset(&screen[offset], color, size); memset(&screen[OFFSET], color, SIZE);
} }
void Jd8::fillRect(int x, int y, int w, int h, Uint8 color) { void Jd8::fillRect(int x, int y, int w, int h, Uint8 color) {
@@ -265,25 +265,25 @@ void Jd8::setPaletteColor(Uint8 index, Uint8 r, Uint8 g, Uint8 b) {
namespace { namespace {
enum class FadeType : std::uint8_t { enum class FadeType : std::uint8_t {
None = 0, NONE = 0,
Out, OUT,
ToPal, TO_PAL,
}; };
constexpr int FADE_STEPS = 32; constexpr int FADE_STEPS = 32;
FadeType fade_type = FadeType::None; FadeType fade_type = FadeType::NONE;
Color fade_target[256]; Color fade_target[256];
int fade_step = 0; int fade_step = 0;
void apply_fade_step() { void applyFadeStep() {
if (fade_type == FadeType::Out) { if (fade_type == FadeType::OUT) {
for (int i = 0; i < 256; i++) { for (int i = 0; i < 256; i++) {
main_palette[i].r = main_palette[i].r >= 8 ? main_palette[i].r - 8 : 0; main_palette[i].r = main_palette[i].r >= 8 ? main_palette[i].r - 8 : 0;
main_palette[i].g = main_palette[i].g >= 8 ? main_palette[i].g - 8 : 0; main_palette[i].g = main_palette[i].g >= 8 ? main_palette[i].g - 8 : 0;
main_palette[i].b = main_palette[i].b >= 8 ? main_palette[i].b - 8 : 0; main_palette[i].b = main_palette[i].b >= 8 ? main_palette[i].b - 8 : 0;
} }
} else if (fade_type == FadeType::ToPal) { } else if (fade_type == FadeType::TO_PAL) {
for (int i = 0; i < 256; i++) { for (int i = 0; i < 256; i++) {
main_palette[i].r = main_palette[i].r <= int(fade_target[i].r) - 8 main_palette[i].r = main_palette[i].r <= int(fade_target[i].r) - 8
? main_palette[i].r + 8 ? main_palette[i].r + 8
@@ -301,30 +301,30 @@ namespace {
} // namespace } // namespace
void Jd8::fadeStartOut() { void Jd8::fadeStartOut() {
fade_type = FadeType::Out; fade_type = FadeType::OUT;
fade_step = 0; fade_step = 0;
} }
void Jd8::fadeStartToPal(const Color* pal) { void Jd8::fadeStartToPal(const Color* pal) {
fade_type = FadeType::ToPal; fade_type = FadeType::TO_PAL;
memcpy(fade_target, pal, sizeof(Color) * 256); memcpy(fade_target, pal, sizeof(Color) * 256);
fade_step = 0; fade_step = 0;
} }
auto Jd8::fadeIsActive() -> bool { auto Jd8::fadeIsActive() -> bool {
return fade_type != FadeType::None; return fade_type != FadeType::NONE;
} }
auto Jd8::fadeTickStep() -> bool { auto Jd8::fadeTickStep() -> bool {
if (fade_type == FadeType::None) { if (fade_type == FadeType::NONE) {
return true; return true;
} }
apply_fade_step(); applyFadeStep();
fade_step++; fade_step++;
if (fade_step >= FADE_STEPS) { if (fade_step >= FADE_STEPS) {
fade_type = FadeType::None; fade_type = FadeType::NONE;
return true; return true;
} }
return false; return false;
+6 -6
View File
@@ -55,17 +55,17 @@ namespace {
} // namespace } // namespace
void file_setresourcefolder(const char* str) { void Jf::setResourceFolder(const char* str) {
resource_folder = str; resource_folder = str;
} }
auto file_getresourcefolder() -> const char* { auto Jf::getResourceFolder() -> const char* {
return resource_folder.c_str(); return resource_folder.c_str();
} }
// Crea la carpeta del sistema on guardar les dades. // Crea la carpeta del sistema on guardar les dades.
// Accepta rutes amb subdirectoris (ex: "jailgames/aee") i crea tota la jerarquia. // Accepta rutes amb subdirectoris (ex: "jailgames/aee") i crea tota la jerarquia.
void file_setconfigfolder(const char* foldername) { void Jf::setConfigFolder(const char* foldername) {
#ifdef _WIN32 #ifdef _WIN32
const char* base = getenv("APPDATA"); const char* base = getenv("APPDATA");
if (!base) base = "C:/"; if (!base) base = "C:/";
@@ -102,13 +102,13 @@ void file_setconfigfolder(const char* foldername) {
// volàtil al navegador de totes formes: ignorem l'error i continuem. // volàtil al navegador de totes formes: ignorem l'error i continuem.
} }
auto file_getconfigfolder() -> const char* { auto Jf::getConfigFolder() -> const char* {
thread_local std::string folder_; thread_local std::string folder_;
folder_ = config_folder + "/"; folder_ = config_folder + "/";
return folder_.c_str(); return folder_.c_str();
} }
auto file_getconfigvalue(const char* key) -> const char* { auto Jf::getConfigValue(const char* key) -> const char* {
if (config.empty()) { if (config.empty()) {
loadConfigValues(); loadConfigValues();
} }
@@ -121,7 +121,7 @@ auto file_getconfigvalue(const char* key) -> const char* {
return nullptr; return nullptr;
} }
void file_setconfigvalue(const char* key, const char* value) { void Jf::setConfigValue(const char* key, const char* value) {
if (config.empty()) { if (config.empty()) {
loadConfigValues(); loadConfigValues();
} }
+10 -6
View File
@@ -1,10 +1,14 @@
#pragma once #pragma once
void file_setconfigfolder(const char* foldername); namespace Jf {
auto file_getconfigfolder() -> const char*;
void file_setresourcefolder(const char* str); void setConfigFolder(const char* foldername);
auto file_getresourcefolder() -> const char*; auto getConfigFolder() -> const char*;
auto file_getconfigvalue(const char* key) -> const char*; void setResourceFolder(const char* str);
void file_setconfigvalue(const char* key, const char* value); auto getResourceFolder() -> const char*;
auto getConfigValue(const char* key) -> const char*;
void setConfigValue(const char* key, const char* value);
} // namespace Jf
+15 -15
View File
@@ -30,7 +30,7 @@ namespace {
Uint8 virtual_keystates[static_cast<size_t>(Ji::VirtualSource::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 scancodeToAscii(Uint8 scancode) -> Uint8 {
if (scancode >= SDL_SCANCODE_A && scancode <= SDL_SCANCODE_Z) { if (scancode >= SDL_SCANCODE_A && scancode <= SDL_SCANCODE_Z) {
return static_cast<Uint8>('a' + (scancode - SDL_SCANCODE_A)); return static_cast<Uint8>('a' + (scancode - SDL_SCANCODE_A));
} }
@@ -51,11 +51,11 @@ 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;
} }
const auto src_idx = static_cast<size_t>(source); const auto SRC_IDX = static_cast<size_t>(source);
if (src_idx >= static_cast<size_t>(VirtualSource::COUNT)) { if (SRC_IDX >= static_cast<size_t>(VirtualSource::COUNT)) {
return; return;
} }
virtual_keystates[src_idx][scancode] = pressed ? 1 : 0; virtual_keystates[SRC_IDX][scancode] = pressed ? 1 : 0;
} }
void Ji::moveCheats(Uint8 scancode) { void Ji::moveCheats(Uint8 scancode) {
@@ -63,7 +63,7 @@ void Ji::moveCheats(Uint8 scancode) {
cheat[1] = cheat[2]; cheat[1] = cheat[2];
cheat[2] = cheat[3]; cheat[2] = cheat[3];
cheat[3] = cheat[4]; cheat[3] = cheat[4];
cheat[4] = scancode_to_ascii(scancode); cheat[4] = scancodeToAscii(scancode);
} }
void Ji::update() { void Ji::update() {
@@ -73,15 +73,15 @@ void Ji::update() {
keystates = SDL_GetKeyboardState(nullptr); keystates = SDL_GetKeyboardState(nullptr);
} }
const Uint64 now = SDL_GetTicks(); const Uint64 NOW = SDL_GetTicks();
if (last_update_tick == 0) { if (last_update_tick == 0) {
last_update_tick = now; last_update_tick = NOW;
} }
const auto delta_ms = static_cast<float>(now - last_update_tick); const auto DELTA_MS = static_cast<float>(NOW - last_update_tick);
last_update_tick = now; last_update_tick = NOW;
if (wait_ms > 0.0F) { if (wait_ms > 0.0F) {
wait_ms -= delta_ms; wait_ms -= DELTA_MS;
wait_ms = std::max(wait_ms, 0.0F); wait_ms = std::max(wait_ms, 0.0F);
} }
@@ -111,15 +111,15 @@ auto Ji::keyPressed(int key) -> bool {
} }
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;
} }
// Compara contra els últims `len` caràcters del buffer. El buffer té // 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. // mida fixa 5 i acumula sempre el darrer tecle a la posició 4.
const size_t offset = sizeof(cheat) - len; const size_t OFFSET = sizeof(cheat) - LEN;
for (size_t i = 0; i < len; i++) { for (size_t i = 0; i < LEN; i++) {
if (cheat[offset + i] != static_cast<Uint8>(cheat_code[i])) { if (cheat[OFFSET + i] != static_cast<Uint8>(cheat_code[i])) {
return false; return false;
} }
} }
+1 -1
View File
@@ -14,7 +14,7 @@ namespace ResourceHelper {
bool fallback_enabled_ = true; bool fallback_enabled_ = true;
auto readFromDisk(const std::string& relative_path) -> std::vector<uint8_t> { auto readFromDisk(const std::string& relative_path) -> std::vector<uint8_t> {
const std::string full = std::string(file_getresourcefolder()) + relative_path; const std::string full = std::string(Jf::getResourceFolder()) + relative_path;
std::ifstream file(full, std::ios::binary | std::ios::ate); std::ifstream file(full, std::ios::binary | std::ios::ate);
if (!file) { if (!file) {
return {}; return {};
+1 -1
View File
@@ -5,7 +5,7 @@
#include <vector> #include <vector>
// API d'alt nivell per a llegir recursos. Prova primer el pack (si està // API d'alt nivell per a llegir recursos. Prova primer el pack (si està
// carregat), després cau al fitxer solt dins `file_getresourcefolder()` // carregat), després cau al fitxer solt dins `Jf::getResourceFolder()`
// si el fallback està activat. // si el fallback està activat.
namespace ResourceHelper { namespace ResourceHelper {
+16 -16
View File
@@ -170,7 +170,7 @@ auto Director::iterate() -> bool {
constexpr Uint32 FRAME_MS_VSYNC = 16; // ~60 FPS amb VSync constexpr Uint32 FRAME_MS_VSYNC = 16; // ~60 FPS amb VSync
constexpr Uint32 FRAME_MS_NO_VSYNC = 4; // ~250 FPS sense VSync (límit superior) constexpr Uint32 FRAME_MS_NO_VSYNC = 4; // ~250 FPS sense VSync (límit superior)
const Uint32 frame_start = SDL_GetTicks(); const Uint32 FRAME_START = SDL_GetTicks();
Gamepad::update(); Gamepad::update();
KeyRemap::update(); KeyRemap::update();
@@ -184,12 +184,12 @@ auto Director::iterate() -> bool {
// Dispara els crèdits cinematogràfics la primera vegada que el joc // 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; 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) { if (Options::game.show_title_credits) {
Overlay::startCredits(); Overlay::startCredits();
} }
credits_triggered = true; credits_triggered_ = true;
} }
// Si l'overlay ja no bloqueja ESC (timeout), desbloquegem // Si l'overlay ja no bloqueja ESC (timeout), desbloquegem
@@ -225,12 +225,12 @@ auto Director::iterate() -> bool {
} }
// 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;
current_scene_->tick(delta_ms); current_scene_->tick(DELTA_MS);
// Converteix `screen` indexat → `pixel_data` ARGB amb la paleta // Converteix `screen` indexat → `pixel_data` ARGB amb la paleta
// actual. Jd8::flip ja no fa yield (Phase B.2 eliminà els fibers); // actual. Jd8::flip ja no fa yield (Phase B.2 eliminà els fibers);
@@ -250,10 +250,10 @@ auto Director::iterate() -> bool {
// Nota: quan el runtime posseïx el main loop (SDL_AppIterate / // Nota: quan el runtime posseïx el main loop (SDL_AppIterate /
// emscripten), aquest SDL_Delay no és ideal. Fase 7 afegirà un mode // emscripten), aquest SDL_Delay no és ideal. Fase 7 afegirà un mode
// que es basa en el timing intern de SDL en lloc del delay explícit. // que es basa en el timing intern de SDL en lloc del delay explícit.
const Uint32 target_ms = Options::video.vsync ? FRAME_MS_VSYNC : FRAME_MS_NO_VSYNC; const Uint32 TARGET_MS = Options::video.vsync ? FRAME_MS_VSYNC : FRAME_MS_NO_VSYNC;
const Uint32 elapsed = SDL_GetTicks() - frame_start; const Uint32 ELAPSED = SDL_GetTicks() - FRAME_START;
if (elapsed < target_ms) { if (ELAPSED < TARGET_MS) {
SDL_Delay(target_ms - elapsed); SDL_Delay(TARGET_MS - ELAPSED);
} }
return true; return true;
@@ -386,10 +386,10 @@ void Director::handleEvent(const SDL_Event& event) {
// KeyConfig::isGuiKey cobreix totes les tecles GUI a la vegada, // KeyConfig::isGuiKey cobreix totes les tecles GUI a la vegada,
// incloent pause_toggle i menu_toggle (defensa en profunditat: // incloent pause_toggle i menu_toggle (defensa en profunditat:
// aquestes ja s'haurien hagut de menjar al swallow d'amunt). // aquestes ja s'haurien hagut de menjar al swallow d'amunt).
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);
+7 -7
View File
@@ -30,7 +30,7 @@ auto SDL_AppInit(void** /*appstate*/, int /*argc*/, char* /*argv*/[]) -> SDL_App
srand(unsigned(time(nullptr))); srand(unsigned(time(nullptr)));
// Crea la carpeta de configuració i carrega les opcions // Crea la carpeta de configuració i carrega les opcions
file_setconfigfolder("jailgames/aee"); Jf::setConfigFolder("jailgames/aee");
// Ruta absoluta a data/ basada en la ubicació de l'executable. // Ruta absoluta a data/ basada en la ubicació de l'executable.
// SDL_GetBasePath() detecta automàticament si estem dins d'un .app bundle // SDL_GetBasePath() detecta automàticament si estem dins d'un .app bundle
@@ -39,7 +39,7 @@ auto SDL_AppInit(void** /*appstate*/, int /*argc*/, char* /*argv*/[]) -> SDL_App
std::string resource_pack_path; std::string resource_pack_path;
if (base_path != nullptr) { if (base_path != nullptr) {
const std::string data_path = std::string(base_path) + "data/"; const std::string data_path = std::string(base_path) + "data/";
file_setresourcefolder(data_path.c_str()); Jf::setResourceFolder(data_path.c_str());
resource_pack_path = std::string(base_path) + "resources.pack"; resource_pack_path = std::string(base_path) + "resources.pack";
} else { } else {
resource_pack_path = "resources.pack"; resource_pack_path = "resources.pack";
@@ -57,17 +57,17 @@ auto SDL_AppInit(void** /*appstate*/, int /*argc*/, char* /*argv*/[]) -> SDL_App
return SDL_APP_FAILURE; return SDL_APP_FAILURE;
} }
Options::setConfigFile(std::string(file_getconfigfolder()) + "config.yaml"); Options::setConfigFile(std::string(Jf::getConfigFolder()) + "config.yaml");
Options::loadFromFile(); Options::loadFromFile();
// KeyConfig: defaults des de data/input/keys.yaml + overrides de l'usuari // KeyConfig: defaults des de data/input/keys.yaml + overrides de l'usuari
KeyConfig::init("input/keys.yaml", KeyConfig::init("input/keys.yaml",
std::string(file_getconfigfolder()) + "keys.yaml"); std::string(Jf::getConfigFolder()) + "keys.yaml");
#ifndef NDEBUG #ifndef NDEBUG
// debug.yaml: estat inicial de gameplay per a tests ràpids, // debug.yaml: estat inicial de gameplay per a tests ràpids,
// només en builds de debug. // només en builds de debug.
Options::setDebugFile(std::string(file_getconfigfolder()) + "debug.yaml"); Options::setDebugFile(std::string(Jf::getConfigFolder()) + "debug.yaml");
Options::loadDebugFromFile(); Options::loadDebugFromFile();
#endif #endif
@@ -84,9 +84,9 @@ auto SDL_AppInit(void** /*appstate*/, int /*argc*/, char* /*argv*/[]) -> SDL_App
Locale::load("locale/ca.yaml"); Locale::load("locale/ca.yaml");
// Carrega presets de shaders // Carrega presets de shaders
Options::setPostFXFile(std::string(file_getconfigfolder()) + "postfx.yaml"); Options::setPostFXFile(std::string(Jf::getConfigFolder()) + "postfx.yaml");
Options::loadPostFXFromFile(); Options::loadPostFXFromFile();
Options::setCrtPiFile(std::string(file_getconfigfolder()) + "crtpi.yaml"); Options::setCrtPiFile(std::string(Jf::getConfigFolder()) + "crtpi.yaml");
Options::loadCrtPiFromFile(); Options::loadCrtPiFromFile();
Jg::init(); Jg::init();