clang-tidy
This commit is contained in:
@@ -908,11 +908,7 @@ auto Player::getProjection(Direction direction, float displacement) -> SDL_FRect
|
||||
|
||||
// Marca al jugador como muerto
|
||||
void Player::markAsDead() {
|
||||
if (Options::cheats.invincible == Options::Cheat::State::ENABLED) {
|
||||
is_alive_ = true; // No puede morir
|
||||
} else {
|
||||
is_alive_ = false; // Muere
|
||||
}
|
||||
is_alive_ = (Options::cheats.invincible == Options::Cheat::State::ENABLED);
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
||||
@@ -29,9 +29,9 @@ void CollisionMap::initializeSurfaces() {
|
||||
|
||||
// Devuelve el tipo de tile que hay en ese pixel
|
||||
auto CollisionMap::getTile(SDL_FPoint point) const -> Tile {
|
||||
const int row = static_cast<int>(point.y / TILE_SIZE);
|
||||
const int col = static_cast<int>(point.x / TILE_SIZE);
|
||||
const int POS = row * MAP_WIDTH + col;
|
||||
const int ROW = static_cast<int>(point.y / TILE_SIZE);
|
||||
const int COL = static_cast<int>(point.x / TILE_SIZE);
|
||||
const int POS = (ROW * MAP_WIDTH) + COL;
|
||||
return getTile(POS);
|
||||
}
|
||||
|
||||
|
||||
@@ -654,6 +654,13 @@ void setPostFXFile(const std::string& path) {
|
||||
postfx_file_path = path;
|
||||
}
|
||||
|
||||
// Helper: extrae un campo float de un nodo YAML si existe, ignorando errores de conversión
|
||||
static void parseFloatField(const fkyaml::node& node, const std::string& key, float& target) {
|
||||
if (node.contains(key)) {
|
||||
try { target = node[key].get_value<float>(); } catch (...) {}
|
||||
}
|
||||
}
|
||||
|
||||
// Carga los presets de PostFX desde el fichero
|
||||
auto loadPostFXFromFile() -> bool {
|
||||
postfx_presets.clear();
|
||||
@@ -675,47 +682,18 @@ auto loadPostFXFromFile() -> bool {
|
||||
|
||||
if (yaml.contains("presets")) {
|
||||
const auto& presets = yaml["presets"];
|
||||
for (size_t i = 0; i < presets.size(); ++i) {
|
||||
const auto& p = presets[i];
|
||||
for (const auto& p : presets) {
|
||||
PostFXPreset preset;
|
||||
if (p.contains("name")) {
|
||||
preset.name = p["name"].get_value<std::string>();
|
||||
}
|
||||
if (p.contains("vignette")) {
|
||||
try {
|
||||
preset.vignette = p["vignette"].get_value<float>();
|
||||
} catch (...) {}
|
||||
}
|
||||
if (p.contains("scanlines")) {
|
||||
try {
|
||||
preset.scanlines = p["scanlines"].get_value<float>();
|
||||
} catch (...) {}
|
||||
}
|
||||
if (p.contains("chroma")) {
|
||||
try {
|
||||
preset.chroma = p["chroma"].get_value<float>();
|
||||
} catch (...) {}
|
||||
}
|
||||
if (p.contains("mask")) {
|
||||
try {
|
||||
preset.mask = p["mask"].get_value<float>();
|
||||
} catch (...) {}
|
||||
}
|
||||
if (p.contains("gamma")) {
|
||||
try {
|
||||
preset.gamma = p["gamma"].get_value<float>();
|
||||
} catch (...) {}
|
||||
}
|
||||
if (p.contains("curvature")) {
|
||||
try {
|
||||
preset.curvature = p["curvature"].get_value<float>();
|
||||
} catch (...) {}
|
||||
}
|
||||
if (p.contains("bleeding")) {
|
||||
try {
|
||||
preset.bleeding = p["bleeding"].get_value<float>();
|
||||
} catch (...) {}
|
||||
}
|
||||
parseFloatField(p, "vignette", preset.vignette);
|
||||
parseFloatField(p, "scanlines", preset.scanlines);
|
||||
parseFloatField(p, "chroma", preset.chroma);
|
||||
parseFloatField(p, "mask", preset.mask);
|
||||
parseFloatField(p, "gamma", preset.gamma);
|
||||
parseFloatField(p, "curvature", preset.curvature);
|
||||
parseFloatField(p, "bleeding", preset.bleeding);
|
||||
postfx_presets.push_back(preset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,6 +111,17 @@ void Ending::transitionToState(State new_state) {
|
||||
}
|
||||
}
|
||||
|
||||
// Lógica de fade común a los estados SCENE_N
|
||||
void Ending::handleSceneFadeout(float scene_duration, float delta_time) {
|
||||
if (state_time_ >= scene_duration - FADEOUT_START_OFFSET) {
|
||||
fadeout_time_ += delta_time;
|
||||
if (!scene_cover_) {
|
||||
scene_cover_ = std::make_unique<PixelReveal>(Options::game.width, Options::game.height, COVER_PIXELS_PER_SECOND, STEP_DURATION, COVER_STEPS, true);
|
||||
}
|
||||
scene_cover_->update(fadeout_time_);
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza la máquina de estados
|
||||
void Ending::updateState(float delta_time) {
|
||||
state_time_ += delta_time;
|
||||
@@ -125,57 +136,27 @@ void Ending::updateState(float delta_time) {
|
||||
|
||||
case State::SCENE_0:
|
||||
checkChangeScene();
|
||||
if (state_time_ >= SCENE_0_DURATION - FADEOUT_START_OFFSET) {
|
||||
fadeout_time_ += delta_time;
|
||||
if (!scene_cover_) {
|
||||
scene_cover_ = std::make_unique<PixelReveal>(Options::game.width, Options::game.height, COVER_PIXELS_PER_SECOND, STEP_DURATION, COVER_STEPS, true);
|
||||
}
|
||||
scene_cover_->update(fadeout_time_);
|
||||
}
|
||||
handleSceneFadeout(SCENE_0_DURATION, delta_time);
|
||||
break;
|
||||
|
||||
case State::SCENE_1:
|
||||
checkChangeScene();
|
||||
if (state_time_ >= SCENE_1_DURATION - FADEOUT_START_OFFSET) {
|
||||
fadeout_time_ += delta_time;
|
||||
if (!scene_cover_) {
|
||||
scene_cover_ = std::make_unique<PixelReveal>(Options::game.width, Options::game.height, COVER_PIXELS_PER_SECOND, STEP_DURATION, COVER_STEPS, true);
|
||||
}
|
||||
scene_cover_->update(fadeout_time_);
|
||||
}
|
||||
handleSceneFadeout(SCENE_1_DURATION, delta_time);
|
||||
break;
|
||||
|
||||
case State::SCENE_2:
|
||||
checkChangeScene();
|
||||
if (state_time_ >= SCENE_2_DURATION - FADEOUT_START_OFFSET) {
|
||||
fadeout_time_ += delta_time;
|
||||
if (!scene_cover_) {
|
||||
scene_cover_ = std::make_unique<PixelReveal>(Options::game.width, Options::game.height, COVER_PIXELS_PER_SECOND, STEP_DURATION, COVER_STEPS, true);
|
||||
}
|
||||
scene_cover_->update(fadeout_time_);
|
||||
}
|
||||
handleSceneFadeout(SCENE_2_DURATION, delta_time);
|
||||
break;
|
||||
|
||||
case State::SCENE_3:
|
||||
checkChangeScene();
|
||||
if (state_time_ >= SCENE_3_DURATION - FADEOUT_START_OFFSET) {
|
||||
fadeout_time_ += delta_time;
|
||||
if (!scene_cover_) {
|
||||
scene_cover_ = std::make_unique<PixelReveal>(Options::game.width, Options::game.height, COVER_PIXELS_PER_SECOND, STEP_DURATION, COVER_STEPS, true);
|
||||
}
|
||||
scene_cover_->update(fadeout_time_);
|
||||
}
|
||||
handleSceneFadeout(SCENE_3_DURATION, delta_time);
|
||||
break;
|
||||
|
||||
case State::SCENE_4:
|
||||
checkChangeScene();
|
||||
if (state_time_ >= SCENE_4_DURATION - FADEOUT_START_OFFSET) {
|
||||
fadeout_time_ += delta_time;
|
||||
if (!scene_cover_) {
|
||||
scene_cover_ = std::make_unique<PixelReveal>(Options::game.width, Options::game.height, COVER_PIXELS_PER_SECOND, STEP_DURATION, COVER_STEPS, true);
|
||||
}
|
||||
scene_cover_->update(fadeout_time_);
|
||||
}
|
||||
handleSceneFadeout(SCENE_4_DURATION, delta_time);
|
||||
break;
|
||||
|
||||
case State::ENDING:
|
||||
|
||||
@@ -82,8 +82,9 @@ class Ending {
|
||||
void iniTexts(); // Inicializa los textos
|
||||
void iniPics(); // Inicializa las imágenes
|
||||
void iniScenes(); // Inicializa las escenas
|
||||
void updateState(float delta_time); // Actualiza la máquina de estados
|
||||
void transitionToState(State new_state); // Transición entre estados
|
||||
void updateState(float delta_time); // Actualiza la máquina de estados
|
||||
void handleSceneFadeout(float scene_duration, float delta_time); // Lógica de fade común a los estados SCENE_N
|
||||
void transitionToState(State new_state); // Transición entre estados
|
||||
void updateSpriteCovers(); // Actualiza las cortinillas de los elementos
|
||||
void checkChangeScene(); // Comprueba si se ha de cambiar de escena
|
||||
void updateMusicVolume() const; // Actualiza el volumen de la música
|
||||
|
||||
@@ -285,7 +285,7 @@ void Ending2::updateSprites(float delta) {
|
||||
|
||||
const float Y = sprite->getPosY();
|
||||
const float H = sprite->getHeight();
|
||||
const float CANVAS_H = static_cast<float>(Options::game.height);
|
||||
const auto CANVAS_H = Options::game.height;
|
||||
|
||||
// Checkpoint inferior: sprite entra per baix → generar de dalt a baix
|
||||
if (Y > static_cast<float>(ENTRY_EXIT_PADDING) && Y <= CANVAS_H - H - ENTRY_EXIT_PADDING && sprite->getProgress() >= 1.0F && sprite->isTransitionDone()) {
|
||||
@@ -306,7 +306,7 @@ void Ending2::updateTextSprites(float delta) {
|
||||
|
||||
const float Y = sprite->getPosY();
|
||||
const float H = sprite->getHeight();
|
||||
const float CANVAS_H = static_cast<float>(Options::game.height);
|
||||
const auto CANVAS_H = Options::game.height;
|
||||
|
||||
if (Y > static_cast<float>(ENTRY_EXIT_PADDING) && Y <= CANVAS_H - H - ENTRY_EXIT_PADDING && sprite->getProgress() >= 1.0F && sprite->isTransitionDone()) {
|
||||
sprite->startGenerate(TRANSITION_DURATION_MS, DissolveDirection::UP);
|
||||
@@ -325,7 +325,7 @@ void Ending2::updateTexts(float delta) {
|
||||
|
||||
const float Y = sprite->getPosY();
|
||||
const float H = sprite->getHeight();
|
||||
const float CANVAS_H = static_cast<float>(Options::game.height);
|
||||
const auto CANVAS_H = Options::game.height;
|
||||
|
||||
// Checkpoint inferior: text entra per baix → generar de dalt a baix
|
||||
if (Y > static_cast<float>(ENTRY_EXIT_PADDING) && Y <= CANVAS_H - H - ENTRY_EXIT_PADDING && sprite->getProgress() >= 1.0F && sprite->isTransitionDone()) {
|
||||
|
||||
@@ -366,6 +366,13 @@ void Game::renderPostFadeEnding() {
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
// Helper: alterna un cheat y muestra notificación con su estado
|
||||
static void toggleCheat(Options::Cheat::State& cheat, const std::string& label) {
|
||||
cheat = (cheat == Options::Cheat::State::ENABLED) ? Options::Cheat::State::DISABLED : Options::Cheat::State::ENABLED;
|
||||
const bool ENABLED = (cheat == Options::Cheat::State::ENABLED);
|
||||
Notifier::get()->show({label + (ENABLED ? " ENABLED" : " DISABLED")}, Notifier::Style::DEFAULT, -1, true);
|
||||
}
|
||||
|
||||
// Pasa la información de debug
|
||||
void Game::updateDebugInfo() {
|
||||
// Debug::get()->add("X = " + std::to_string(static_cast<int>(player_->x_)) + ", Y = " + std::to_string(static_cast<int>(player_->y_)));
|
||||
@@ -437,20 +444,17 @@ void Game::handleDebugEvents(const SDL_Event& event) {
|
||||
break;
|
||||
|
||||
case SDLK_1:
|
||||
Options::cheats.infinite_lives = Options::cheats.infinite_lives == Options::Cheat::State::ENABLED ? Options::Cheat::State::DISABLED : Options::Cheat::State::ENABLED;
|
||||
Notifier::get()->show({std::string("INFINITE LIVES ") + (Options::cheats.infinite_lives == Options::Cheat::State::ENABLED ? "ENABLED" : "DISABLED")}, Notifier::Style::DEFAULT, -1, true);
|
||||
toggleCheat(Options::cheats.infinite_lives, "INFINITE LIVES");
|
||||
player_->setColor();
|
||||
break;
|
||||
|
||||
case SDLK_2:
|
||||
Options::cheats.invincible = Options::cheats.invincible == Options::Cheat::State::ENABLED ? Options::Cheat::State::DISABLED : Options::Cheat::State::ENABLED;
|
||||
Notifier::get()->show({std::string("INVINCIBLE ") + (Options::cheats.invincible == Options::Cheat::State::ENABLED ? "ENABLED" : "DISABLED")}, Notifier::Style::DEFAULT, -1, true);
|
||||
toggleCheat(Options::cheats.invincible, "INVINCIBLE");
|
||||
player_->setColor();
|
||||
break;
|
||||
|
||||
case SDLK_3:
|
||||
Options::cheats.jail_is_open = Options::cheats.jail_is_open == Options::Cheat::State::ENABLED ? Options::Cheat::State::DISABLED : Options::Cheat::State::ENABLED;
|
||||
Notifier::get()->show({std::string("JAIL IS OPEN ") + (Options::cheats.jail_is_open == Options::Cheat::State::ENABLED ? "ENABLED" : "DISABLED")}, Notifier::Style::DEFAULT, -1, true);
|
||||
toggleCheat(Options::cheats.jail_is_open, "JAIL IS OPEN");
|
||||
break;
|
||||
|
||||
case SDLK_7:
|
||||
@@ -506,7 +510,7 @@ void Game::handleDebugMouseDrag(float delta_time) {
|
||||
// Calcular distancia al objetivo
|
||||
float dx = game_x - player_x;
|
||||
float dy = game_y - player_y;
|
||||
float distance = std::sqrt(dx * dx + dy * dy);
|
||||
float distance = std::sqrt((dx * dx) + (dy * dy));
|
||||
|
||||
// Constantes de velocidad con ease-in (aceleración progresiva)
|
||||
constexpr float DRAG_SPEED_MIN = 30.0F; // Velocidad inicial (pixels/segundo)
|
||||
@@ -517,13 +521,13 @@ void Game::handleDebugMouseDrag(float delta_time) {
|
||||
if (!debug_dragging_player_) {
|
||||
debug_drag_speed_ = DRAG_SPEED_MIN; // Iniciar con velocidad mínima
|
||||
}
|
||||
debug_drag_speed_ = std::min(DRAG_SPEED_MAX, debug_drag_speed_ + DRAG_ACCELERATION * delta_time);
|
||||
debug_drag_speed_ = std::min(DRAG_SPEED_MAX, debug_drag_speed_ + (DRAG_ACCELERATION * delta_time));
|
||||
|
||||
if (distance > 1.0F) {
|
||||
// Calcular el movimiento con la velocidad actual
|
||||
float move_factor = std::min(1.0F, debug_drag_speed_ * delta_time / distance);
|
||||
float new_x = player_x + dx * move_factor;
|
||||
float new_y = player_y + dy * move_factor;
|
||||
float new_x = player_x + (dx * move_factor);
|
||||
float new_y = player_y + (dy * move_factor);
|
||||
|
||||
// Mover el jugador hacia la posición del cursor
|
||||
player_->setDebugPosition(new_x, new_y);
|
||||
|
||||
@@ -66,10 +66,10 @@ class Game {
|
||||
void updateFadeToEnding(float delta_time); // Actualiza el juego en estado FADE_TO_ENDING
|
||||
void updatePostFadeEnding(float delta_time); // Actualiza el juego en estado POST_FADE_ENDING
|
||||
void renderPlaying(); // Renderiza el juego en estado PLAYING (directo a pantalla)
|
||||
void renderBlackScreen(); // Renderiza el juego en estado BLACK_SCREEN (pantalla negra)
|
||||
void renderGameOver(); // Renderiza el juego en estado GAME_OVER (pantalla negra)
|
||||
static void renderBlackScreen(); // Renderiza el juego en estado BLACK_SCREEN (pantalla negra)
|
||||
static void renderGameOver(); // Renderiza el juego en estado GAME_OVER (pantalla negra)
|
||||
void renderFadeToEnding(); // Renderiza el juego en estado FADE_TO_ENDING (via backbuffer)
|
||||
void renderPostFadeEnding(); // Renderiza el juego en estado POST_FADE_ENDING (pantalla negra)
|
||||
static void renderPostFadeEnding(); // Renderiza el juego en estado POST_FADE_ENDING (pantalla negra)
|
||||
auto changeRoom(const std::string& room_path) -> bool; // Cambia de habitación
|
||||
void handleInput(); // Comprueba el teclado
|
||||
void checkPlayerIsOnBorder(); // Comprueba si el jugador esta en el borde de la pantalla y actua
|
||||
|
||||
Reference in New Issue
Block a user