linter
This commit is contained in:
@@ -61,7 +61,7 @@ auto AssetIntegrated::loadFile(const std::string& filename) -> std::vector<uint8
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto AssetIntegrated::fileExists(const std::string& filename) const -> bool {
|
auto AssetIntegrated::fileExists(const std::string& filename) -> bool {
|
||||||
if (shouldUseResourcePack(filename) && resource_pack_enabled) {
|
if (shouldUseResourcePack(filename) && resource_pack_enabled) {
|
||||||
auto& loader = ResourceLoader::getInstance();
|
auto& loader = ResourceLoader::getInstance();
|
||||||
|
|
||||||
|
|||||||
@@ -13,10 +13,10 @@ class AssetIntegrated : public Asset {
|
|||||||
const std::string& resource_pack_path = "resources.pack");
|
const std::string& resource_pack_path = "resources.pack");
|
||||||
|
|
||||||
// Carga un archivo usando ResourceLoader como primera opción
|
// Carga un archivo usando ResourceLoader como primera opción
|
||||||
auto loadFile(const std::string& filename) -> std::vector<uint8_t>;
|
static auto loadFile(const std::string& filename) -> std::vector<uint8_t>;
|
||||||
|
|
||||||
// Verifica si un archivo existe (pack o filesystem)
|
// Verifica si un archivo existe (pack o filesystem)
|
||||||
auto fileExists(const std::string& filename) const -> bool;
|
static auto fileExists(const std::string& filename) -> bool;
|
||||||
|
|
||||||
// Obtiene la ruta completa para archivos del sistema/config
|
// Obtiene la ruta completa para archivos del sistema/config
|
||||||
static auto getSystemPath(const std::string& filename) -> std::string;
|
static auto getSystemPath(const std::string& filename) -> std::string;
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ void PathSprite::render() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Determina el tipo de centrado basado en el tipo de path
|
// Determina el tipo de centrado basado en el tipo de path
|
||||||
auto PathSprite::determineCenteringType(const Path& path, bool centered) const -> PathCentered {
|
auto PathSprite::determineCenteringType(const Path& path, bool centered) -> PathCentered {
|
||||||
if (!centered) {
|
if (!centered) {
|
||||||
return PathCentered::NONE;
|
return PathCentered::NONE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ class PathSprite : public Sprite {
|
|||||||
void goToNextPathOrDie(); // Cambia de recorrido o finaliza
|
void goToNextPathOrDie(); // Cambia de recorrido o finaliza
|
||||||
|
|
||||||
// --- Métodos auxiliares para addPath ---
|
// --- Métodos auxiliares para addPath ---
|
||||||
[[nodiscard]] auto determineCenteringType(const Path& path, bool centered) const -> PathCentered; // Determina el tipo de centrado
|
[[nodiscard]] static auto determineCenteringType(const Path& path, bool centered) -> PathCentered; // Determina el tipo de centrado
|
||||||
void centerPathOnX(Path& path, float offset); // Aplica centrado en el eje X
|
static void centerPathOnX(Path& path, float offset); // Aplica centrado en el eje X
|
||||||
void centerPathOnY(Path& path, float offset); // Aplica centrado en el eje Y
|
static void centerPathOnY(Path& path, float offset); // Aplica centrado en el eje Y
|
||||||
};
|
};
|
||||||
@@ -42,13 +42,13 @@ auto OpenGLShader::initGLExtensions() -> bool {
|
|||||||
glVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC)SDL_GL_GetProcAddress("glVertexAttribPointer");
|
glVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC)SDL_GL_GetProcAddress("glVertexAttribPointer");
|
||||||
glEnableVertexAttribArray = (PFNGLENABLEVERTEXATTRIBARRAYPROC)SDL_GL_GetProcAddress("glEnableVertexAttribArray");
|
glEnableVertexAttribArray = (PFNGLENABLEVERTEXATTRIBARRAYPROC)SDL_GL_GetProcAddress("glEnableVertexAttribArray");
|
||||||
|
|
||||||
return glCreateShader && glShaderSource && glCompileShader && glGetShaderiv &&
|
return (glCreateShader != nullptr) && (glShaderSource != nullptr) && (glCompileShader != nullptr) && (glGetShaderiv != nullptr) &&
|
||||||
glGetShaderInfoLog && glDeleteShader && glAttachShader && glCreateProgram &&
|
(glGetShaderInfoLog != nullptr) && (glDeleteShader != nullptr) && (glAttachShader != nullptr) && (glCreateProgram != nullptr) &&
|
||||||
glLinkProgram && glValidateProgram && glGetProgramiv && glGetProgramInfoLog &&
|
(glLinkProgram != nullptr) && (glValidateProgram != nullptr) && (glGetProgramiv != nullptr) && (glGetProgramInfoLog != nullptr) &&
|
||||||
glUseProgram && glDeleteProgram && glGetUniformLocation && glUniform2f &&
|
(glUseProgram != nullptr) && (glDeleteProgram != nullptr) && (glGetUniformLocation != nullptr) && (glUniform2f != nullptr) &&
|
||||||
glGenVertexArrays && glBindVertexArray && glDeleteVertexArrays &&
|
(glGenVertexArrays != nullptr) && (glBindVertexArray != nullptr) && (glDeleteVertexArrays != nullptr) &&
|
||||||
glGenBuffers && glBindBuffer && glBufferData && glDeleteBuffers &&
|
(glGenBuffers != nullptr) && (glBindBuffer != nullptr) && (glBufferData != nullptr) && (glDeleteBuffers != nullptr) &&
|
||||||
glVertexAttribPointer && glEnableVertexAttribArray;
|
(glVertexAttribPointer != nullptr) && (glEnableVertexAttribArray != nullptr);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -432,7 +432,7 @@ void Credits::updateBlackRects(float delta_time) {
|
|||||||
static_cast<float>(param.game.game_area.center_y + 1));
|
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_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);
|
int bottom_steps_by_y = prev_bottom_y - static_cast<int>(bottom_black_rect_.y);
|
||||||
int bottom_steps = std::max(0, std::max(bottom_steps_by_h, bottom_steps_by_y));
|
int bottom_steps = std::max({0, bottom_steps_by_h, bottom_steps_by_y});
|
||||||
|
|
||||||
int steps_done = top_delta + bottom_steps;
|
int steps_done = top_delta + bottom_steps;
|
||||||
if (steps_done > 0) {
|
if (steps_done > 0) {
|
||||||
@@ -460,20 +460,20 @@ void Credits::updateBlackRects(float delta_time) {
|
|||||||
if (!horizontal_done_) {
|
if (!horizontal_done_) {
|
||||||
int prev_left_w = static_cast<int>(left_black_rect_.w);
|
int prev_left_w = static_cast<int>(left_black_rect_.w);
|
||||||
left_black_rect_.w = std::min(left_black_rect_.w + static_cast<float>(HORIZONTAL_SPEED),
|
left_black_rect_.w = std::min(left_black_rect_.w + static_cast<float>(HORIZONTAL_SPEED),
|
||||||
static_cast<float>(param.game.game_area.center_x));
|
param.game.game_area.center_x);
|
||||||
int left_gain = static_cast<int>(left_black_rect_.w) - prev_left_w;
|
int left_gain = static_cast<int>(left_black_rect_.w) - prev_left_w;
|
||||||
|
|
||||||
int prev_right_x = static_cast<int>(right_black_rect_.x);
|
int prev_right_x = static_cast<int>(right_black_rect_.x);
|
||||||
right_black_rect_.w = right_black_rect_.w + static_cast<float>(HORIZONTAL_SPEED);
|
right_black_rect_.w = right_black_rect_.w + static_cast<float>(HORIZONTAL_SPEED);
|
||||||
right_black_rect_.x = std::max(right_black_rect_.x - static_cast<float>(HORIZONTAL_SPEED),
|
right_black_rect_.x = std::max(right_black_rect_.x - static_cast<float>(HORIZONTAL_SPEED),
|
||||||
static_cast<float>(param.game.game_area.center_x));
|
param.game.game_area.center_x);
|
||||||
int right_move = prev_right_x - static_cast<int>(right_black_rect_.x);
|
int right_move = prev_right_x - static_cast<int>(right_black_rect_.x);
|
||||||
|
|
||||||
int steps_done = left_gain + right_move;
|
int steps_done = left_gain + right_move;
|
||||||
if (steps_done > 0) {
|
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_));
|
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í
|
Audio::get()->setMusicVolume(vol_i); // usa tu API de audio aquí
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -495,7 +495,9 @@ void Credits::updateBlackRects(float delta_time) {
|
|||||||
|
|
||||||
// Usar segundos puros en lugar de frames equivalentes
|
// Usar segundos puros en lugar de frames equivalentes
|
||||||
if (counter_pre_fade_ >= PRE_FADE_DELAY_S) {
|
if (counter_pre_fade_ >= PRE_FADE_DELAY_S) {
|
||||||
if (fade_out_) fade_out_->activate();
|
if (fade_out_) {
|
||||||
|
fade_out_->activate();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
counter_pre_fade_ += delta_time;
|
counter_pre_fade_ += delta_time;
|
||||||
}
|
}
|
||||||
@@ -680,7 +682,9 @@ void Credits::startCredits() {
|
|||||||
int pasos_right = (dx_right + (HORIZONTAL_SPEED - 1)) / HORIZONTAL_SPEED; // ceil
|
int pasos_right = (dx_right + (HORIZONTAL_SPEED - 1)) / HORIZONTAL_SPEED; // ceil
|
||||||
|
|
||||||
total_steps_ = pasos_top + pasos_bottom + pasos_left + pasos_right;
|
total_steps_ = pasos_top + pasos_bottom + pasos_left + pasos_right;
|
||||||
if (total_steps_ <= 0) total_steps_ = 1;
|
if (total_steps_ <= 0) {
|
||||||
|
total_steps_ = 1;
|
||||||
|
}
|
||||||
|
|
||||||
current_step_ = static_cast<float>(total_steps_);
|
current_step_ = static_cast<float>(total_steps_);
|
||||||
|
|
||||||
@@ -690,7 +694,9 @@ void Credits::startCredits() {
|
|||||||
initialized_ = true;
|
initialized_ = true;
|
||||||
|
|
||||||
// Asegurar volumen inicial consistente
|
// Asegurar volumen inicial consistente
|
||||||
if (steps_ <= 0) steps_ = 1;
|
if (steps_ <= 0) {
|
||||||
|
steps_ = 1;
|
||||||
|
}
|
||||||
float vol_f = initial_volume_ * (current_step_ / static_cast<float>(total_steps_));
|
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_))));
|
||||||
}
|
}
|
||||||
@@ -711,8 +717,8 @@ void Credits::drawBorderRect() {
|
|||||||
SDL_Rect r;
|
SDL_Rect r;
|
||||||
r.x = static_cast<int>(std::floor(border_rect_.x + 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.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.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.h = static_cast<int>(std::max(0.0F, std::floor(border_rect_.h + 0.5F)));
|
||||||
|
|
||||||
if (r.w > 0 && r.h > 0) {
|
if (r.w > 0 && r.h > 0) {
|
||||||
SDL_RenderRect(Screen::get()->getRenderer(), &border_rect_);
|
SDL_RenderRect(Screen::get()->getRenderer(), &border_rect_);
|
||||||
|
|||||||
@@ -551,19 +551,18 @@ void Game::handleTabeHitEffects() {
|
|||||||
|
|
||||||
// Maneja la colisión entre bala y globos
|
// Maneja la colisión entre bala y globos
|
||||||
auto Game::checkBulletBalloonCollision(const std::shared_ptr<Bullet>& bullet) -> bool {
|
auto Game::checkBulletBalloonCollision(const std::shared_ptr<Bullet>& bullet) -> bool {
|
||||||
for (auto& balloon : balloon_manager_->getBalloons()) {
|
return std::ranges::any_of(balloon_manager_->getBalloons(), [this, &bullet](auto& balloon) {
|
||||||
if (!balloon->isEnabled() || balloon->isInvulnerable()) {
|
if (!balloon->isEnabled() || balloon->isInvulnerable()) {
|
||||||
continue;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!checkCollision(balloon->getCollider(), bullet->getCollider())) {
|
if (!checkCollision(balloon->getCollider(), bullet->getCollider())) {
|
||||||
continue;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
processBalloonHit(bullet, balloon);
|
processBalloonHit(bullet, balloon);
|
||||||
return true;
|
return true;
|
||||||
}
|
});
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Procesa el impacto en un globo
|
// Procesa el impacto en un globo
|
||||||
@@ -1966,8 +1965,10 @@ void Game::handleGameOverEvents() {
|
|||||||
void Game::buildPlayerDrawList(const Players& elements, Players& draw_list) {
|
void Game::buildPlayerDrawList(const Players& elements, Players& draw_list) {
|
||||||
draw_list.clear();
|
draw_list.clear();
|
||||||
draw_list.reserve(elements.size());
|
draw_list.reserve(elements.size());
|
||||||
for (const auto& e : elements) draw_list.push_back(e); // copia el shared_ptr
|
for (const auto& e : elements) {
|
||||||
std::stable_sort(draw_list.begin(), draw_list.end(), [](const std::shared_ptr<Player>& a, const std::shared_ptr<Player>& b) {
|
draw_list.push_back(e); // copia el shared_ptr
|
||||||
|
}
|
||||||
|
std::ranges::stable_sort(draw_list, [](const std::shared_ptr<Player>& a, const std::shared_ptr<Player>& b) {
|
||||||
return a->getZOrder() < b->getZOrder();
|
return a->getZOrder() < b->getZOrder();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1981,31 +1982,42 @@ void Game::updatePlayerDrawList(const Players& elements, Players& draw_list) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Dado que apuntan a los mismos elementos, basta ordenar por los z_order actuales.
|
// Dado que apuntan a los mismos elementos, basta ordenar por los z_order actuales.
|
||||||
std::stable_sort(draw_list.begin(), draw_list.end(), [](const std::shared_ptr<Player>& a, const std::shared_ptr<Player>& b) {
|
std::ranges::stable_sort(draw_list, [](const std::shared_ptr<Player>& a, const std::shared_ptr<Player>& b) {
|
||||||
return a->getZOrder() < b->getZOrder();
|
return a->getZOrder() < b->getZOrder();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dibuja en el orden definido por draw_list
|
// Dibuja en el orden definido por draw_list
|
||||||
void Game::renderPlayerDrawList(const Players& draw_list) {
|
void Game::renderPlayerDrawList(const Players& draw_list) {
|
||||||
for (const auto& e : draw_list) e->render();
|
for (const auto& e : draw_list) {
|
||||||
|
e->render();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Operaciones sobre z_order que mantienen la invariante y actualizan draw_list.
|
// 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 {
|
auto Game::findPlayerIndex(const Players& elems, const std::shared_ptr<Player>& who) -> size_t {
|
||||||
for (size_t i = 0; i < elems.size(); ++i)
|
for (size_t i = 0; i < elems.size(); ++i) {
|
||||||
if (elems[i] == who) return static_cast<int>(i); // compara shared_ptr directamente
|
if (elems[i] == who) {
|
||||||
|
return static_cast<int>(i); // compara shared_ptr directamente
|
||||||
|
}
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::sendPlayerToBack(Players& elements, const std::shared_ptr<Player>& who, Players& draw_list) {
|
void Game::sendPlayerToBack(Players& elements, const std::shared_ptr<Player>& who, Players& draw_list) {
|
||||||
int idx = findPlayerIndex(elements, who);
|
int idx = findPlayerIndex(elements, who);
|
||||||
if (idx < 0) return; // no encontrado
|
if (idx < 0) {
|
||||||
|
return; // no encontrado
|
||||||
|
}
|
||||||
const int OLD_Z = elements[idx]->getZOrder();
|
const int OLD_Z = elements[idx]->getZOrder();
|
||||||
if (OLD_Z <= 0) return;
|
if (OLD_Z <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (auto& p : elements) {
|
for (auto& p : elements) {
|
||||||
int z = p->getZOrder();
|
int z = p->getZOrder();
|
||||||
if (z < OLD_Z) { p->setZOrder(z + 1); }
|
if (z < OLD_Z) {
|
||||||
|
p->setZOrder(z + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
elements[idx]->setZOrder(0);
|
elements[idx]->setZOrder(0);
|
||||||
updatePlayerDrawList(elements, draw_list);
|
updatePlayerDrawList(elements, draw_list);
|
||||||
@@ -2013,13 +2025,19 @@ void Game::sendPlayerToBack(Players& elements, const std::shared_ptr<Player>& wh
|
|||||||
|
|
||||||
void Game::bringPlayerToFront(Players& elements, const std::shared_ptr<Player>& who, Players& draw_list) {
|
void Game::bringPlayerToFront(Players& elements, const std::shared_ptr<Player>& who, Players& draw_list) {
|
||||||
int idx = findPlayerIndex(elements, who);
|
int idx = findPlayerIndex(elements, who);
|
||||||
if (idx < 0) return; // no encontrado
|
if (idx < 0) {
|
||||||
|
return; // no encontrado
|
||||||
|
}
|
||||||
const int OLD_Z = elements[idx]->getZOrder();
|
const int OLD_Z = elements[idx]->getZOrder();
|
||||||
const int N = static_cast<int>(elements.size());
|
const int N = static_cast<int>(elements.size());
|
||||||
if (OLD_Z >= N - 1) return;
|
if (OLD_Z >= N - 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (auto& p : elements) {
|
for (auto& p : elements) {
|
||||||
int z = p->getZOrder();
|
int z = p->getZOrder();
|
||||||
if (z > OLD_Z) p->setZOrder(z - 1);
|
if (z > OLD_Z) {
|
||||||
|
p->setZOrder(z - 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
elements[idx]->setZOrder(N - 1);
|
elements[idx]->setZOrder(N - 1);
|
||||||
updatePlayerDrawList(elements, draw_list);
|
updatePlayerDrawList(elements, draw_list);
|
||||||
|
|||||||
@@ -336,9 +336,9 @@ class Game {
|
|||||||
void playSound(const std::string& name) const; // Reproduce un efecto de sonido específico
|
void playSound(const std::string& name) const; // Reproduce un efecto de sonido específico
|
||||||
|
|
||||||
// --- Gestion y dibujado de jugadores en z-order ---
|
// --- Gestion y dibujado de jugadores en z-order ---
|
||||||
void buildPlayerDrawList(const Players& elements, Players& draw_list); // Construye el draw_list a partir del vector principal
|
static 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 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 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;
|
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& draw_list); // Envia al jugador al fondo 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
|
void bringPlayerToFront(Players& elements, const std::shared_ptr<Player>& who, Players& draw_list); // Envia al jugador al frente de la pantalla
|
||||||
|
|||||||
Reference in New Issue
Block a user