surface: hallazgo 1 — SurfaceData::width/height de float a int
Las dimensiones en píxeles son enteros por naturaleza. Convertidos los miembros y constructores a int, y ajustados getWidth()/getHeight() para devolver int. Eliminados los static_cast<int>(...->width/height) y static_cast<int>(surface->getWidth/getHeight()) redundantes que sólo existían para compensar el tipo erróneo. Los callers que inicializan SDL_FRect directamente con getWidth/getHeight requieren static_cast<float> explícito (sprite.cpp, animated_sprite.cpp, notifier.cpp, title.cpp) por las reglas de narrowing de list-init. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -39,9 +39,9 @@ void MiniMap::buildTileColorTable(const std::string& tileset_name) {
|
||||
auto tileset = Resource::Cache::get()->getSurface(tileset_name);
|
||||
if (!tileset) { return; }
|
||||
|
||||
tileset_width_ = static_cast<int>(tileset->getWidth()) / Tile::SIZE;
|
||||
tileset_width_ = tileset->getWidth() / Tile::SIZE;
|
||||
tileset_transparent_ = tileset->getTransparentColor();
|
||||
int tileset_height = static_cast<int>(tileset->getHeight()) / Tile::SIZE;
|
||||
int tileset_height = tileset->getHeight() / Tile::SIZE;
|
||||
int total_tiles = tileset_width_ * tileset_height;
|
||||
|
||||
tile_colors_.resize(total_tiles, 0);
|
||||
|
||||
@@ -26,8 +26,8 @@ void TilePicker::open(const std::string& tileset_name, int current_tile, int bg_
|
||||
|
||||
// Calcular dimensiones del tileset en tiles (teniendo en cuenta spacing de entrada)
|
||||
int src_cell = Tile::SIZE + spacing_in_;
|
||||
tileset_width_ = static_cast<int>(tileset_->getWidth()) / src_cell;
|
||||
tileset_height_ = static_cast<int>(tileset_->getHeight()) / src_cell;
|
||||
tileset_width_ = tileset_->getWidth() / src_cell;
|
||||
tileset_height_ = tileset_->getHeight() / src_cell;
|
||||
// Corregir si el último tile cabe sin spacing
|
||||
if (tileset_width_ == 0 && tileset_->getWidth() >= Tile::SIZE) { tileset_width_ = 1; }
|
||||
if (tileset_height_ == 0 && tileset_->getHeight() >= Tile::SIZE) { tileset_height_ = 1; }
|
||||
|
||||
@@ -502,7 +502,7 @@ void Title::createCheevosTexture() { // NOLINT(readability-convert-member-funct
|
||||
|
||||
// Crea el sprite para el listado de logros (usa la zona del menu)
|
||||
cheevos_sprite_ = std::make_unique<Sprite>(cheevos_surface_, (GameCanvas::WIDTH - cheevos_surface_->getWidth()) / 2, MENU_ZONE_Y, cheevos_surface_->getWidth(), cheevos_surface_->getHeight());
|
||||
cheevos_surface_view_ = {.x = 0, .y = 0, .w = cheevos_surface_->getWidth(), .h = CHEEVOS_TEXTURE_VIEW_HEIGHT};
|
||||
cheevos_surface_view_ = {.x = 0, .y = 0, .w = static_cast<float>(cheevos_surface_->getWidth()), .h = CHEEVOS_TEXTURE_VIEW_HEIGHT};
|
||||
cheevos_sprite_->setClip(cheevos_surface_view_);
|
||||
}
|
||||
|
||||
|
||||
@@ -225,7 +225,7 @@ void Notifier::show(std::vector<std::string> texts, const Style& style, int icon
|
||||
|
||||
else if (SHAPE == Shape::SQUARED) {
|
||||
n.surface->clear(style.bg_color);
|
||||
SDL_FRect squared_rect = {.x = 0, .y = 0, .w = n.surface->getWidth(), .h = n.surface->getHeight()};
|
||||
SDL_FRect squared_rect = {.x = 0, .y = 0, .w = static_cast<float>(n.surface->getWidth()), .h = static_cast<float>(n.surface->getHeight())};
|
||||
n.surface->drawRectBorder(&squared_rect, style.border_color);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user