Systems::render_map now holds the logic to render the map, and it's working well enough to use for displaying.

This commit is contained in:
Zed A. Shaw 2025-07-15 11:39:05 -04:00
parent 0d1eacdc5c
commit dca38397e7
3 changed files with 45 additions and 40 deletions

View file

@ -565,3 +565,35 @@ bool System::inventory_occupied(GameLevel& level, Entity container_id, const std
auto& inventory = level.world->get<inventory::Model>(container_id);
return inventory.has(name);
}
void System::render_map(Matrix& tiles, EntityGrid& entity_map, sf::RenderTexture& render) {
sf::Vector2i size{MAP_TILE_DIM,MAP_TILE_DIM};
unsigned int width = matrix::width(tiles);
unsigned int height = matrix::height(tiles);
sf::Vector2u dim{width * size.x, height * size.y};
auto render_size = render.getSize();
if(render_size.x != width || render_size.y != height) {
bool worked = render.resize(dim);
dbc::check(worked, "Failed to resize map render target.");
}
render.clear({0,0,0,0});
for(matrix::each_row it{tiles}; it.next();) {
wchar_t display = tiles[it.y][it.x];
if(display == L' ') continue; // skip for now
auto& sprite = textures::get_map_sprite(display);
sprite.setPosition({float(it.x * size.x), float(it.y * size.y)});
render.draw(sprite);
}
for(auto [point, display] : entity_map) {
auto& sprite = textures::get_map_sprite(display);
sprite.setPosition({float(point.x * size.x), float(point.y * size.y)});
render.draw(sprite);
}
render.display();
}