eliminar entrades legacy del fitxer de mapa

This commit is contained in:
2026-04-10 18:51:14 +02:00
parent 8ebf7894f2
commit 6743562292
20 changed files with 133 additions and 318 deletions

View File

@@ -1,44 +1,32 @@
#include "tilemap_renderer.hpp"
#include "core/rendering/screen.hpp"
#include "core/rendering/sprite/sprite.hpp"
#include "core/rendering/surface.hpp"
#ifdef _DEBUG
#include "core/resources/resource_cache.hpp" // Para Resource::Cache (collision.gif)
#include "core/system/debug.hpp"
#endif
TilemapRenderer::TilemapRenderer(std::vector<int> tile_map, int tile_set_width, std::shared_ptr<Surface> tileset_surface, Uint8 bg_color, int conveyor_belt_direction)
TilemapRenderer::TilemapRenderer(std::vector<int> tile_map, int tile_set_width, std::shared_ptr<Surface> tileset_surface, Uint8 bg_color)
: tile_map_(std::move(tile_map)),
tile_set_width_(tile_set_width),
tileset_surface_(std::move(tileset_surface)),
bg_color_(bg_color),
conveyor_belt_direction_(conveyor_belt_direction) {
bg_color_(bg_color) {
map_surface_ = std::make_shared<Surface>(PlayArea::WIDTH, PlayArea::HEIGHT);
}
void TilemapRenderer::initialize(const std::vector<int>& collision_tile_map) {
setAnimatedTiles(collision_tile_map);
fillMapTexture(collision_tile_map);
}
void TilemapRenderer::update(float delta_time) {
if (is_paused_) { return; }
time_accumulator_ += delta_time;
updateAnimatedTiles();
void TilemapRenderer::update(float /*delta_time*/) {
// De momento no hay tiles animados; el sistema de conveyor belts antiguo se
// eliminó. Cuando se reimplementen como tipos de tile concretos, irá aquí.
}
void TilemapRenderer::render() {
SDL_FRect dest = {.x = 0, .y = 0, .w = PlayArea::WIDTH, .h = PlayArea::HEIGHT};
map_surface_->render(nullptr, &dest);
#ifdef _DEBUG
if (!Debug::get()->isEnabled()) {
renderAnimatedTiles();
}
#else
renderAnimatedTiles();
#endif
}
#ifdef _DEBUG
@@ -62,13 +50,11 @@ void TilemapRenderer::setTile(int index, int tile_value) {
map_surface_->fillRect(&cell, bg_color_);
if (tile_value > -1) {
if (!isAnimatedTile(tile_value)) {
SDL_FRect clip = {.x = static_cast<float>((tile_value % tile_set_width_) * TILE_SIZE),
.y = static_cast<float>((tile_value / tile_set_width_) * TILE_SIZE),
.w = static_cast<float>(TILE_SIZE),
.h = static_cast<float>(TILE_SIZE)};
tileset_surface_->render(col * TILE_SIZE, row * TILE_SIZE, &clip);
}
SDL_FRect clip = {.x = static_cast<float>((tile_value % tile_set_width_) * TILE_SIZE),
.y = static_cast<float>((tile_value / tile_set_width_) * TILE_SIZE),
.w = static_cast<float>(TILE_SIZE),
.h = static_cast<float>(TILE_SIZE)};
tileset_surface_->render(col * TILE_SIZE, row * TILE_SIZE, &clip);
}
Screen::get()->setRendererSurface(previous_renderer);
@@ -106,20 +92,18 @@ void TilemapRenderer::fillMapTexture(const std::vector<int>& collision_tile_map)
for (int y = 0; y < MAP_HEIGHT; ++y) {
for (int x = 0; x < MAP_WIDTH; ++x) {
const int INDEX = (y * MAP_WIDTH) + x;
// Los tiles animados no se pintan en la textura estática
const bool HAS_TILE = tile_map_[INDEX] > -1;
if (!HAS_TILE) { continue; }
if (HAS_TILE && !isAnimatedTile(tile_map_[INDEX])) {
clip.x = (tile_map_[INDEX] % tile_set_width_) * TILE_SIZE;
clip.y = (tile_map_[INDEX] / tile_set_width_) * TILE_SIZE;
clip.x = (tile_map_[INDEX] % tile_set_width_) * TILE_SIZE;
clip.y = (tile_map_[INDEX] / tile_set_width_) * TILE_SIZE;
#ifdef _DEBUG
if (!Debug::get()->isEnabled()) {
tileset_surface_->render(x * TILE_SIZE, y * TILE_SIZE, &clip);
}
#else
if (!Debug::get()->isEnabled()) {
tileset_surface_->render(x * TILE_SIZE, y * TILE_SIZE, &clip);
#endif
}
#else
tileset_surface_->render(x * TILE_SIZE, y * TILE_SIZE, &clip);
#endif
}
}
@@ -131,50 +115,3 @@ void TilemapRenderer::fillMapTexture(const std::vector<int>& collision_tile_map)
#endif
Screen::get()->setRendererSurface(previous_renderer);
}
// Localiza tiles animados (conveyor belts) usando el collision_tile_map
void TilemapRenderer::setAnimatedTiles(const std::vector<int>& collision_tile_map) {
for (int i = 0; i < static_cast<int>(tile_map_.size()); ++i) {
// Un tile es animado si su valor en el collision tilemap es COLLISION_ANIMATED (6)
if (i < static_cast<int>(collision_tile_map.size()) && collision_tile_map[i] == COLLISION_ANIMATED) {
const int X = (i % MAP_WIDTH) * TILE_SIZE;
const int Y = (i / MAP_WIDTH) * TILE_SIZE;
const int XC = (tile_map_[i] % tile_set_width_) * TILE_SIZE;
const int YC = (tile_map_[i] / tile_set_width_) * TILE_SIZE;
AnimatedTile at;
at.sprite = std::make_shared<Sprite>(tileset_surface_, X, Y, TILE_SIZE, TILE_SIZE);
at.sprite->setClip(XC, YC, TILE_SIZE, TILE_SIZE);
at.x_orig = XC;
animated_tiles_.push_back(at);
}
}
}
void TilemapRenderer::updateAnimatedTiles() {
const int NUM_FRAMES = 4;
const int CURRENT_FRAME = static_cast<int>(time_accumulator_ / CONVEYOR_FRAME_DURATION) % NUM_FRAMES;
int offset = 0;
if (conveyor_belt_direction_ == -1) {
offset = CURRENT_FRAME * TILE_SIZE;
} else {
offset = (NUM_FRAMES - 1 - CURRENT_FRAME) * TILE_SIZE;
}
for (auto& a : animated_tiles_) {
SDL_FRect rect = a.sprite->getClip();
rect.x = a.x_orig + offset;
a.sprite->setClip(rect);
}
}
void TilemapRenderer::renderAnimatedTiles() {
for (const auto& a : animated_tiles_) {
a.sprite->render();
}
}
auto TilemapRenderer::isAnimatedTile(int tile_value) const -> bool {
return (tile_value >= ANIMATED_TILE_ROW * tile_set_width_) && (tile_value < (ANIMATED_TILE_ROW + 1) * tile_set_width_);
}