fix: tidy modulegame (enums UPPER_CASE, draw/update camelBack, membres _)

This commit is contained in:
2026-05-16 14:40:18 +02:00
parent 1e00f5c3a4
commit 9d30dd538c
2 changed files with 55 additions and 55 deletions
+39 -39
View File
@@ -8,28 +8,28 @@
#include "core/jail/jinput.hpp"
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);
this->sam = std::make_unique<Prota>(this->gfx);
this->mapa = std::make_unique<Mapa>(this->gfx, this->sam.get());
this->marcador = std::make_unique<Marcador>(this->gfx, this->sam.get());
this->sam_ = std::make_unique<Prota>(this->gfx_);
this->mapa_ = std::make_unique<Mapa>(this->gfx_, this->sam_.get());
this->marcador_ = std::make_unique<Marcador>(this->gfx_, this->sam_.get());
if (info::ctx.num_piramide == 2) {
this->bola = std::make_unique<Bola>(this->gfx, this->sam.get());
this->bola_ = std::make_unique<Bola>(this->gfx_, this->sam_.get());
}
this->iniciarMomies();
}
ModuleGame::~ModuleGame() {
Jd8::freeSurface(this->gfx);
Jd8::freeSurface(this->gfx_);
}
void ModuleGame::onEnter() {
// Primera Draw per omplir `screen` amb el contingut del gameplay
// abans que el fade-in arranque. Si no, les primeres iteracions del
// fade interpolarien cap a una paleta amb pantalla buida.
this->Draw();
this->draw();
// Audio::playMusic ja és idempotent: si la pista actual coincideix amb la
// demanada, no fa res. Per això podem cridar-lo cada onEnter sense
@@ -48,32 +48,32 @@ void ModuleGame::onEnter() {
// 32) per cada tick; durant aquesta fase el gameplay no corre,
// només Draw+fade. Substituïx la crida bloquejant `JD8_FadeToPal`.
fade_.startFadeTo(Jd8::loadPalette(info::ctx.pepe_activat ? "gfx/frames2.gif" : "gfx/frames.gif"));
phase_ = Phase::FadingIn;
phase_ = Phase::FADING_IN;
}
void ModuleGame::tick(int delta_ms) {
switch (phase_) {
case Phase::FadingIn:
case Phase::FADING_IN:
// No redibuixem durant el fade: el `screen` ja va ser omplit
// per la Draw() d'onEnter. Només el Jd8::flip del caller muta
// pixel_data segons la paleta que avança pas a pas.
fade_.tick(delta_ms);
if (fade_.done()) {
phase_ = Phase::Playing;
phase_ = Phase::PLAYING;
}
break;
case Phase::Playing:
this->Draw();
this->Update();
case Phase::PLAYING:
this->draw();
this->update();
if (this->final_ != 0) {
this->applyFinalTransitions();
fade_.startFadeOut();
phase_ = Phase::FadingOut;
phase_ = Phase::FADING_OUT;
}
break;
case Phase::FadingOut:
case Phase::FADING_OUT:
// No redibuixem: el `screen` té l'últim frame pintat per la
// fase Playing (just abans que Update() setegés `final_`).
// El vell `JD8_FadeOut` feia exactament això — flips amb
@@ -82,11 +82,11 @@ void ModuleGame::tick(int delta_ms) {
// "tornant" davant la porta després d'haver eixit).
fade_.tick(delta_ms);
if (fade_.done()) {
phase_ = Phase::Done;
phase_ = Phase::DONE;
}
break;
case Phase::Done:
case Phase::DONE:
break;
}
}
@@ -118,33 +118,33 @@ void ModuleGame::applyFinalTransitions() const {
}
}
void ModuleGame::Draw() {
void ModuleGame::draw() {
// No crida Jd8::flip — el caller (mini-loop del fiber, o Director a
// Phase B.2) ho fa després de cada tick.
this->mapa->draw();
this->marcador->draw();
this->sam->draw();
for (auto& m : this->momies) {
this->mapa_->draw();
this->marcador_->draw();
this->sam_->draw();
for (auto& m : this->momies_) {
m->draw();
}
if (this->bola) {
this->bola->draw();
if (this->bola_) {
this->bola_->draw();
}
}
void ModuleGame::Update() {
void ModuleGame::update() {
if (JG_ShouldUpdate()) {
JI_Update();
this->final_ = this->sam->update();
const auto erased = std::erase_if(this->momies, [](auto& m) { return m->update(); });
this->final_ = this->sam_->update();
const auto erased = std::erase_if(this->momies_, [](auto& m) { return m->update(); });
info::ctx.momies -= static_cast<int>(erased);
if (this->bola) {
this->bola->update();
if (this->bola_) {
this->bola_->update();
}
this->mapa->update();
if (this->mapa->novaMomia()) {
this->momies.emplace_back(std::make_unique<Momia>(this->gfx, true, 0, 0, this->sam.get()));
this->mapa_->update();
if (this->mapa_->novaMomia()) {
this->momies_.emplace_back(std::make_unique<Momia>(this->gfx_, true, 0, 0, this->sam_.get()));
info::ctx.momies++;
}
@@ -152,16 +152,16 @@ void ModuleGame::Update() {
info::ctx.vida = 5;
}
if (JI_CheatActivated("alone")) {
this->momies.clear();
this->momies_.clear();
info::ctx.momies = 0;
}
if (JI_CheatActivated("obert")) {
for (int i = 0; i < 16; i++) {
this->mapa->tombes[i].costat[0] = true;
this->mapa->tombes[i].costat[1] = true;
this->mapa->tombes[i].costat[2] = true;
this->mapa->tombes[i].costat[3] = true;
this->mapa->comprovaCaixa(i);
this->mapa_->tombes[i].costat[0] = true;
this->mapa_->tombes[i].costat[1] = true;
this->mapa_->tombes[i].costat[2] = true;
this->mapa_->tombes[i].costat[3] = true;
this->mapa_->comprovaCaixa(i);
}
}
@@ -185,7 +185,7 @@ void ModuleGame::iniciarMomies() {
int y = 170;
bool dimonis = info::ctx.num_piramide == 6;
for (int i = 0; i < info::ctx.momies; i++) {
this->momies.emplace_back(std::make_unique<Momia>(this->gfx, dimonis, x, y, this->sam.get()));
this->momies_.emplace_back(std::make_unique<Momia>(this->gfx_, dimonis, x, y, this->sam_.get()));
x += 65;
if (x == 345) {
x = 20;
+16 -16
View File
@@ -20,11 +20,11 @@
// abans de retornar el next state.
//
// Tres fases internes:
// 1. FadingIn — 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
// o canvia de sala. `Update()` només avança cada 10 ms
// via `JG_ShouldUpdate` (ticker fix del jail).
// 3. FadingOut — 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
// destructor legacy).
class ModuleGame : public scenes::Scene {
@@ -39,31 +39,31 @@ class ModuleGame : public scenes::Scene {
void onEnter() override;
void tick(int delta_ms) override;
[[nodiscard]] auto done() const -> bool override { return phase_ == Phase::Done; }
[[nodiscard]] auto done() const -> bool override { return phase_ == Phase::DONE; }
[[nodiscard]] auto nextState() const -> int override;
private:
enum class Phase : std::uint8_t {
FadingIn,
Playing,
FadingOut,
Done,
FADING_IN,
PLAYING,
FADING_OUT,
DONE,
};
void Draw(); // render a `screen`; no crida Jd8::flip (ho fa el caller)
void Update(); // gated per JG_ShouldUpdate
void draw(); // render a `screen`; no crida Jd8::flip (ho fa el caller)
void update(); // gated per JG_ShouldUpdate
void iniciarMomies();
void applyFinalTransitions() const; // muta info::ctx quan final_ passa a !=0
Phase phase_{Phase::FadingIn};
Phase phase_{Phase::FADING_IN};
scenes::PaletteFade fade_;
Uint8 final_{0};
Jd8::Surface gfx{nullptr};
Jd8::Surface gfx_{nullptr};
std::unique_ptr<Mapa> mapa;
std::unique_ptr<Prota> sam;
std::unique_ptr<Marcador> marcador;
std::vector<std::unique_ptr<Momia>> momies;
std::unique_ptr<Bola> bola;
std::unique_ptr<Mapa> mapa_;
std::unique_ptr<Prota> sam_;
std::unique_ptr<Marcador> marcador_;
std::vector<std::unique_ptr<Momia>> momies_;
std::unique_ptr<Bola> bola_;
};