linter: varios
This commit is contained in:
@@ -409,8 +409,8 @@ void Credits::initPlayers() {
|
||||
|
||||
// Actualiza los rectangulos negros (time-based)
|
||||
void Credits::updateBlackRects(float delta_time) {
|
||||
if (!initialized_) return;
|
||||
if (delta_time < 0.0f) delta_time = 0.0f;
|
||||
if (!initialized_) { return; }
|
||||
delta_time = std::max(delta_time, 0.0F);
|
||||
|
||||
// Fase vertical: hasta que ambos rects verticales estén exactos en su target
|
||||
if (!vertical_done_) {
|
||||
@@ -420,15 +420,15 @@ void Credits::updateBlackRects(float delta_time) {
|
||||
|
||||
// top
|
||||
int prev_top_h = static_cast<int>(top_black_rect_.h);
|
||||
top_black_rect_.h = std::min(top_black_rect_.h + 1.0f,
|
||||
top_black_rect_.h = std::min(top_black_rect_.h + 1.0F,
|
||||
static_cast<float>(param.game.game_area.center_y - 1));
|
||||
int top_delta = static_cast<int>(top_black_rect_.h) - prev_top_h;
|
||||
|
||||
// bottom
|
||||
int prev_bottom_h = static_cast<int>(bottom_black_rect_.h);
|
||||
int prev_bottom_y = static_cast<int>(bottom_black_rect_.y);
|
||||
bottom_black_rect_.h = bottom_black_rect_.h + 1.0f;
|
||||
bottom_black_rect_.y = std::max(bottom_black_rect_.y - 1.0f,
|
||||
bottom_black_rect_.h = bottom_black_rect_.h + 1.0F;
|
||||
bottom_black_rect_.y = std::max(bottom_black_rect_.y - 1.0F,
|
||||
static_cast<float>(param.game.game_area.center_y + 1));
|
||||
int bottom_steps_by_h = static_cast<int>(bottom_black_rect_.h) - prev_bottom_h;
|
||||
int bottom_steps_by_y = prev_bottom_y - static_cast<int>(bottom_black_rect_.y);
|
||||
@@ -436,18 +436,18 @@ void Credits::updateBlackRects(float delta_time) {
|
||||
|
||||
int steps_done = top_delta + bottom_steps;
|
||||
if (steps_done > 0) {
|
||||
current_step_ = std::max(0.0f, current_step_ - static_cast<float>(steps_done));
|
||||
current_step_ = std::max(0.0F, current_step_ - static_cast<float>(steps_done));
|
||||
float vol_f = initial_volume_ * (current_step_ / static_cast<float>(total_steps_));
|
||||
int vol_i = static_cast<int>(std::clamp(vol_f, 0.0f, static_cast<float>(initial_volume_)));
|
||||
int vol_i = static_cast<int>(std::clamp(vol_f, 0.0F, static_cast<float>(initial_volume_)));
|
||||
Audio::get()->setMusicVolume(vol_i); // usa tu API de audio aquí
|
||||
}
|
||||
|
||||
// Si han alcanzado los objetivos, fijarlos exactamente y marcar done
|
||||
bool top_at_target = static_cast<int>(top_black_rect_.h) == param.game.game_area.center_y - 1;
|
||||
bool bottom_at_target = static_cast<int>(bottom_black_rect_.y) == param.game.game_area.center_y + 1;
|
||||
bool top_at_target = static_cast<int>(top_black_rect_.h) == param.game.game_area.center_y - 1.0F;
|
||||
bool bottom_at_target = static_cast<int>(bottom_black_rect_.y) == param.game.game_area.center_y + 1.0F;
|
||||
if (top_at_target && bottom_at_target) {
|
||||
top_black_rect_.h = static_cast<float>(param.game.game_area.center_y - 1);
|
||||
bottom_black_rect_.y = static_cast<float>(param.game.game_area.center_y + 1);
|
||||
top_black_rect_.h = param.game.game_area.center_y - 1.0F;
|
||||
bottom_black_rect_.y = param.game.game_area.center_y + 1.0F;
|
||||
vertical_done_ = true;
|
||||
}
|
||||
}
|
||||
@@ -480,8 +480,8 @@ void Credits::updateBlackRects(float delta_time) {
|
||||
bool left_at_target = static_cast<int>(left_black_rect_.w) == param.game.game_area.center_x;
|
||||
bool right_at_target = static_cast<int>(right_black_rect_.x) == param.game.game_area.center_x;
|
||||
if (left_at_target && right_at_target) {
|
||||
left_black_rect_.w = static_cast<float>(param.game.game_area.center_x);
|
||||
right_black_rect_.x = static_cast<float>(param.game.game_area.center_x);
|
||||
left_black_rect_.w = param.game.game_area.center_x;
|
||||
right_black_rect_.x = param.game.game_area.center_x;
|
||||
horizontal_done_ = true;
|
||||
}
|
||||
|
||||
@@ -504,13 +504,13 @@ void Credits::updateBlackRects(float delta_time) {
|
||||
// Actualiza el rectangulo del borde
|
||||
void Credits::updateBorderRect() {
|
||||
border_rect_.x = left_black_rect_.x + left_black_rect_.w;
|
||||
border_rect_.y = top_black_rect_.y + top_black_rect_.h - 1;
|
||||
border_rect_.y = top_black_rect_.y + top_black_rect_.h - 1.0F;
|
||||
|
||||
float raw_w = right_black_rect_.x - border_rect_.x;
|
||||
float raw_h = bottom_black_rect_.y - border_rect_.y + 1.0f;
|
||||
float raw_h = bottom_black_rect_.y - border_rect_.y + 1.0F;
|
||||
|
||||
border_rect_.w = std::max(0.0f, raw_w);
|
||||
border_rect_.h = std::max(0.0f, raw_h);
|
||||
border_rect_.w = std::max(0.0F, raw_w);
|
||||
border_rect_.h = std::max(0.0F, raw_h);
|
||||
}
|
||||
|
||||
// Actualiza el estado de fade (time-based)
|
||||
@@ -612,25 +612,25 @@ void Credits::renderPlayers() {
|
||||
void Credits::initVars() {
|
||||
// Inicialización segura de rects tal y como los mostraste
|
||||
top_black_rect_ = {
|
||||
play_area_.x,
|
||||
param.game.game_area.rect.y,
|
||||
play_area_.w,
|
||||
black_bars_size_};
|
||||
.x = play_area_.x,
|
||||
.y = param.game.game_area.rect.y,
|
||||
.w = play_area_.w,
|
||||
.h = black_bars_size_};
|
||||
bottom_black_rect_ = {
|
||||
play_area_.x,
|
||||
param.game.game_area.rect.h - black_bars_size_,
|
||||
play_area_.w,
|
||||
black_bars_size_};
|
||||
.x = play_area_.x,
|
||||
.y = param.game.game_area.rect.h - black_bars_size_,
|
||||
.w = play_area_.w,
|
||||
.h = black_bars_size_};
|
||||
left_black_rect_ = {
|
||||
play_area_.x,
|
||||
param.game.game_area.center_y - 1,
|
||||
0,
|
||||
2};
|
||||
.x = play_area_.x,
|
||||
.y = param.game.game_area.center_y - 1.0F,
|
||||
.w = 0.0F,
|
||||
.h = 2.0F};
|
||||
right_black_rect_ = {
|
||||
play_area_.x + play_area_.w,
|
||||
param.game.game_area.center_y - 1,
|
||||
0,
|
||||
2};
|
||||
.x = play_area_.x + play_area_.w,
|
||||
.y = param.game.game_area.center_y - 1.0F,
|
||||
.w = 0.0F,
|
||||
.h = 2.0F};
|
||||
|
||||
initialized_ = false;
|
||||
|
||||
@@ -659,10 +659,10 @@ void Credits::initVars() {
|
||||
|
||||
void Credits::startCredits() {
|
||||
// Guardar iniciales (enteros para contar "pasos" por píxel)
|
||||
init_top_h = static_cast<int>(top_black_rect_.h);
|
||||
init_bottom_y = static_cast<int>(bottom_black_rect_.y);
|
||||
init_left_w = static_cast<int>(left_black_rect_.w);
|
||||
init_right_x = static_cast<int>(right_black_rect_.x);
|
||||
init_top_h_ = static_cast<int>(top_black_rect_.h);
|
||||
init_bottom_y_ = static_cast<int>(bottom_black_rect_.y);
|
||||
init_left_w_ = static_cast<int>(left_black_rect_.w);
|
||||
init_right_x_ = static_cast<int>(right_black_rect_.x);
|
||||
|
||||
// Objetivos
|
||||
int top_target_h = param.game.game_area.center_y - 1;
|
||||
@@ -671,12 +671,12 @@ void Credits::startCredits() {
|
||||
int right_target_x = param.game.game_area.center_x;
|
||||
|
||||
// Pasos verticales
|
||||
int pasos_top = std::max(0, top_target_h - init_top_h);
|
||||
int pasos_bottom = std::max(0, init_bottom_y - bottom_target_y);
|
||||
int pasos_top = std::max(0, top_target_h - init_top_h_);
|
||||
int pasos_bottom = std::max(0, init_bottom_y_ - bottom_target_y);
|
||||
|
||||
// Pasos horizontales. right se mueve a velocidad HORIZONTAL_SPEED, contamos pasos como unidades de movimiento equivalentes
|
||||
int pasos_left = std::max(0, left_target_w - init_left_w);
|
||||
int dx_right = std::max(0, init_right_x - right_target_x);
|
||||
int pasos_left = std::max(0, left_target_w - init_left_w_);
|
||||
int dx_right = std::max(0, init_right_x_ - right_target_x);
|
||||
int pasos_right = (dx_right + (HORIZONTAL_SPEED - 1)) / HORIZONTAL_SPEED; // ceil
|
||||
|
||||
total_steps_ = pasos_top + pasos_bottom + pasos_left + pasos_right;
|
||||
@@ -685,20 +685,20 @@ void Credits::startCredits() {
|
||||
current_step_ = static_cast<float>(total_steps_);
|
||||
|
||||
// Reiniciar contadores y estado
|
||||
credits_state_.black_rect_accumulator = 0.0f;
|
||||
counter_pre_fade_ = 0.0f;
|
||||
credits_state_.black_rect_accumulator = 0.0F;
|
||||
counter_pre_fade_ = 0.0F;
|
||||
initialized_ = true;
|
||||
|
||||
// Asegurar volumen inicial consistente
|
||||
if (steps_ <= 0) steps_ = 1;
|
||||
float vol_f = initial_volume_ * (current_step_ / static_cast<float>(total_steps_));
|
||||
setVolume(static_cast<int>(std::clamp(vol_f, 0.0f, static_cast<float>(initial_volume_))));
|
||||
setVolume(static_cast<int>(std::clamp(vol_f, 0.0F, static_cast<float>(initial_volume_))));
|
||||
}
|
||||
|
||||
// Dibuja el rectángulo del borde si es visible
|
||||
void Credits::drawBorderRect() {
|
||||
// Umbral: cualquier valor menor que 1 píxel no se considera visible
|
||||
constexpr float VISIBLE_THRESHOLD = 1.0f;
|
||||
constexpr float VISIBLE_THRESHOLD = 1.0F;
|
||||
if (border_rect_.w < VISIBLE_THRESHOLD || border_rect_.h < VISIBLE_THRESHOLD) {
|
||||
return; // no dibujar
|
||||
}
|
||||
@@ -709,10 +709,10 @@ void Credits::drawBorderRect() {
|
||||
|
||||
// Convertir a enteros de forma conservadora para evitar líneas de 1px por redondeo extraño
|
||||
SDL_Rect r;
|
||||
r.x = static_cast<int>(std::floor(border_rect_.x + 0.5f));
|
||||
r.y = static_cast<int>(std::floor(border_rect_.y + 0.5f));
|
||||
r.w = static_cast<int>(std::max(0.0f, std::floor(border_rect_.w + 0.5f)));
|
||||
r.h = static_cast<int>(std::max(0.0f, std::floor(border_rect_.h + 0.5f)));
|
||||
r.x = static_cast<int>(std::floor(border_rect_.x + 0.5F));
|
||||
r.y = static_cast<int>(std::floor(border_rect_.y + 0.5F));
|
||||
r.w = static_cast<int>(std::max(0.0f, std::floor(border_rect_.w + 0.5F)));
|
||||
r.h = static_cast<int>(std::max(0.0f, std::floor(border_rect_.h + 0.5F)));
|
||||
|
||||
if (r.w > 0 && r.h > 0) {
|
||||
SDL_RenderRect(Screen::get()->getRenderer(), &border_rect_);
|
||||
|
||||
@@ -35,9 +35,9 @@ class Credits {
|
||||
// --- Constantes de clase (time-based) ---
|
||||
static constexpr int PLAY_AREA_HEIGHT = 200;
|
||||
static constexpr float FAST_FORWARD_MULTIPLIER = 6.0F;
|
||||
static constexpr float BLACK_RECT_INTERVAL_S = 4.0F / 60.0F; // ~0.0667s (cada 4 frames a 60fps)
|
||||
static constexpr float BLACK_RECT_INTERVAL_S = 4.0F / 60.0F; // ~0.0667s (cada 4 frames a 60fps)
|
||||
static constexpr int HORIZONTAL_SPEED = 2;
|
||||
static constexpr float MAX_TIME_AFTER_LOGO_S = 20.0F;
|
||||
static constexpr float MAX_TIME_AFTER_LOGO_S = 20.0F;
|
||||
static constexpr float PRE_FADE_DELAY_S = 8.0F;
|
||||
|
||||
// --- Objetos principales ---
|
||||
@@ -52,19 +52,19 @@ class Credits {
|
||||
SDL_Texture* canvas_; // Textura donde se dibuja todo
|
||||
|
||||
// --- Temporización (time-based puro) ---
|
||||
Uint64 last_time_ = 0; // Último tiempo registrado para deltaTime
|
||||
float elapsed_time_balloons_ = 0.0F; // Tiempo acumulado para lanzamiento de globos (segundos)
|
||||
float counter_pre_fade_ = 0.0F; // Tiempo antes de activar fundido final (segundos)
|
||||
float time_since_logo_positioned_ = 0.0F; // Tiempo desde que el logo llegó a su posición (segundos)
|
||||
Uint64 last_time_ = 0; // Último tiempo registrado para deltaTime
|
||||
float elapsed_time_balloons_ = 0.0F; // Tiempo acumulado para lanzamiento de globos (segundos)
|
||||
float counter_pre_fade_ = 0.0F; // Tiempo antes de activar fundido final (segundos)
|
||||
float time_since_logo_positioned_ = 0.0F; // Tiempo desde que el logo llegó a su posición (segundos)
|
||||
float current_step_ = 0.0F;
|
||||
int total_steps_ = 1;
|
||||
bool initialized_ = false;
|
||||
|
||||
// --- Guardar estados iniciales para cálculo de pasos ---
|
||||
int init_top_h = 0;
|
||||
int init_bottom_y = 0;
|
||||
int init_left_w = 0;
|
||||
int init_right_x = 0;
|
||||
int init_top_h_ = 0;
|
||||
int init_bottom_y_ = 0;
|
||||
int init_left_w_ = 0;
|
||||
int init_right_x_ = 0;
|
||||
|
||||
// --- Variables de estado ---
|
||||
bool fading_ = false; // Estado del fade final
|
||||
|
||||
@@ -370,7 +370,7 @@ void Game::updateGameStateGameOver(float delta_time) {
|
||||
}
|
||||
|
||||
if (fade_out_->hasEnded()) {
|
||||
Section::name = Section::Name::HI_SCORE_TABLE;
|
||||
Section::name = Section::Name::HI_SCORE_TABLE;
|
||||
Section::options = Section::Options::HI_SCORE_AFTER_PLAYING;
|
||||
}
|
||||
}
|
||||
@@ -1961,68 +1961,68 @@ void Game::handleGameOverEvents() {
|
||||
}
|
||||
}
|
||||
|
||||
// Construye (una vez) el drawList a partir del vector principal
|
||||
// drawList almacena punteros a los elementos y queda reservado
|
||||
void Game::buildPlayerDrawList(const Players& elements, Players& drawList) {
|
||||
drawList.clear();
|
||||
drawList.reserve(elements.size());
|
||||
for (const auto& e : elements) drawList.push_back(e); // copia el shared_ptr
|
||||
std::stable_sort(drawList.begin(), drawList.end(), [](const std::shared_ptr<Player>& a, const std::shared_ptr<Player>& b) {
|
||||
// Construye (una vez) el draw_list a partir del vector principal
|
||||
// draw_list almacena punteros a los elementos y queda reservado
|
||||
void Game::buildPlayerDrawList(const Players& elements, Players& draw_list) {
|
||||
draw_list.clear();
|
||||
draw_list.reserve(elements.size());
|
||||
for (const auto& e : elements) draw_list.push_back(e); // copia el shared_ptr
|
||||
std::stable_sort(draw_list.begin(), draw_list.end(), [](const std::shared_ptr<Player>& a, const std::shared_ptr<Player>& b) {
|
||||
return a->getZOrder() < b->getZOrder();
|
||||
});
|
||||
}
|
||||
|
||||
// Actualiza drawList tras cambios en los z_order. Implementación simple:
|
||||
// reordena drawList según los z_order actuales. Llamar cuando cambian z_order
|
||||
void Game::updatePlayerDrawList(const Players& elements, Players& drawList) {
|
||||
// Si drawList está vacío o su tamaño no coincide, reconstruirlo.
|
||||
if (drawList.size() != elements.size()) {
|
||||
buildPlayerDrawList(elements, drawList);
|
||||
// Actualiza draw_list tras cambios en los z_order. Implementación simple:
|
||||
// reordena draw_list según los z_order actuales. Llamar cuando cambian z_order
|
||||
void Game::updatePlayerDrawList(const Players& elements, Players& draw_list) {
|
||||
// Si draw_list está vacío o su tamaño no coincide, reconstruirlo.
|
||||
if (draw_list.size() != elements.size()) {
|
||||
buildPlayerDrawList(elements, draw_list);
|
||||
return;
|
||||
}
|
||||
// Dado que apuntan a los mismos elementos, basta ordenar por los z_order actuales.
|
||||
std::stable_sort(drawList.begin(), drawList.end(), [](const std::shared_ptr<Player>& a, const std::shared_ptr<Player>& b) {
|
||||
std::stable_sort(draw_list.begin(), draw_list.end(), [](const std::shared_ptr<Player>& a, const std::shared_ptr<Player>& b) {
|
||||
return a->getZOrder() < b->getZOrder();
|
||||
});
|
||||
}
|
||||
|
||||
// Dibuja en el orden definido por drawList
|
||||
void Game::renderPlayerDrawList(const Players& drawList) {
|
||||
for (const auto& e : drawList) e->render();
|
||||
// Dibuja en el orden definido por draw_list
|
||||
void Game::renderPlayerDrawList(const Players& draw_list) {
|
||||
for (const auto& e : draw_list) e->render();
|
||||
}
|
||||
|
||||
// Operaciones sobre z_order que mantienen la invariante y actualizan drawList.
|
||||
// Operaciones sobre z_order que mantienen la invariante y actualizan draw_list.
|
||||
auto Game::findPlayerIndex(const Players& elems, const std::shared_ptr<Player>& who) -> size_t {
|
||||
for (size_t i = 0; i < elems.size(); ++i)
|
||||
if (elems[i] == who) return static_cast<int>(i); // compara shared_ptr directamente
|
||||
return -1;
|
||||
}
|
||||
|
||||
void Game::sendPlayerToBack(Players& elements, const std::shared_ptr<Player>& who, Players& drawList) {
|
||||
void Game::sendPlayerToBack(Players& elements, const std::shared_ptr<Player>& who, Players& draw_list) {
|
||||
int idx = findPlayerIndex(elements, who);
|
||||
if (idx < 0) return; // no encontrado
|
||||
const int oldZ = elements[idx]->getZOrder();
|
||||
if (oldZ <= 0) return;
|
||||
const int OLD_Z = elements[idx]->getZOrder();
|
||||
if (OLD_Z <= 0) return;
|
||||
for (auto& p : elements) {
|
||||
int z = p->getZOrder();
|
||||
if (z < oldZ) p->setZOrder(z + 1);
|
||||
if (z < OLD_Z) { p->setZOrder(z + 1); }
|
||||
}
|
||||
elements[idx]->setZOrder(0);
|
||||
updatePlayerDrawList(elements, drawList);
|
||||
updatePlayerDrawList(elements, draw_list);
|
||||
}
|
||||
|
||||
void Game::bringPlayerToFront(Players& elements, const std::shared_ptr<Player>& who, Players& drawList) {
|
||||
void Game::bringPlayerToFront(Players& elements, const std::shared_ptr<Player>& who, Players& draw_list) {
|
||||
int idx = findPlayerIndex(elements, who);
|
||||
if (idx < 0) return; // no encontrado
|
||||
const int oldZ = elements[idx]->getZOrder();
|
||||
const int OLD_Z = elements[idx]->getZOrder();
|
||||
const int N = static_cast<int>(elements.size());
|
||||
if (oldZ >= N - 1) return;
|
||||
if (OLD_Z >= N - 1) return;
|
||||
for (auto& p : elements) {
|
||||
int z = p->getZOrder();
|
||||
if (z > oldZ) p->setZOrder(z - 1);
|
||||
if (z > OLD_Z) p->setZOrder(z - 1);
|
||||
}
|
||||
elements[idx]->setZOrder(N - 1);
|
||||
updatePlayerDrawList(elements, drawList);
|
||||
updatePlayerDrawList(elements, draw_list);
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
||||
@@ -336,12 +336,12 @@ class Game {
|
||||
void playSound(const std::string& name) const; // Reproduce un efecto de sonido específico
|
||||
|
||||
// --- Gestion y dibujado de jugadores en z-order ---
|
||||
void buildPlayerDrawList(const Players& elements, Players& drawList); // Construye el drawList a partir del vector principal
|
||||
void updatePlayerDrawList(const Players& elements, Players& drawList); // Actualiza drawList tras cambios en los z_order
|
||||
void renderPlayerDrawList(const Players& drawList); // Dibuja en el orden definido
|
||||
void buildPlayerDrawList(const Players& elements, Players& draw_list); // Construye el draw_list a partir del vector principal
|
||||
void updatePlayerDrawList(const Players& elements, Players& draw_list); // Actualiza draw_list tras cambios en los z_order
|
||||
void renderPlayerDrawList(const Players& draw_list); // Dibuja en el orden definido
|
||||
static auto findPlayerIndex(const Players& elems, const std::shared_ptr<Player>& who) -> size_t;
|
||||
void sendPlayerToBack(Players& elements, const std::shared_ptr<Player>& who, Players& drawList); // Envia al jugador al fondo de la pantalla
|
||||
void bringPlayerToFront(Players& elements, const std::shared_ptr<Player>& who, Players& drawList); // Envia al jugador al frente de la pantalla
|
||||
void sendPlayerToBack(Players& elements, const std::shared_ptr<Player>& who, Players& draw_list); // Envia al jugador al fondo de la pantalla
|
||||
void bringPlayerToFront(Players& elements, const std::shared_ptr<Player>& who, Players& draw_list); // Envia al jugador al frente de la pantalla
|
||||
|
||||
// --- Varios ---
|
||||
void onPauseStateChanged(bool is_paused);
|
||||
|
||||
Reference in New Issue
Block a user