Refactored out the tilemap since it was mostly doing nothing useful.

This commit is contained in:
Zed A. Shaw 2025-05-25 11:39:43 -04:00
parent ea9f6bf383
commit 3a745d492a
15 changed files with 40 additions and 187 deletions

View file

@ -35,12 +35,21 @@ namespace textures {
void load_tiles() {
Config assets("assets/tiles.json");
auto &tiles = assets.json();
TMGR.surfaces.resize(tiles.size());
for(auto &el : tiles.items()) {
auto &config = el.value();
TMGR.surfaces.emplace_back(load_image(config["texture"]));
const std::string& texture_fname = config["texture"];
size_t surface_i = config["id"];
if(surface_i >= tiles.size()) {
TMGR.surfaces.resize(surface_i + 1);
}
TMGR.surfaces[surface_i] = load_image(texture_fname);
wchar_t tid = config["display"];
int surface_i = TMGR.surfaces.size() - 1;
fmt::println("texture {} has surface_i={}", texture_fname, surface_i);
TMGR.char_to_texture[tid] = surface_i;
}
}
@ -72,7 +81,6 @@ namespace textures {
sf::Image texture;
bool good = texture.loadFromFile(filename);
dbc::check(good, fmt::format("failed to load {}", filename));
fmt::println("texture size={}", sizeof(texture));
return texture;
}
@ -80,17 +88,6 @@ namespace textures {
return (const uint32_t *)TMGR.surfaces[num].getPixelsPtr();
}
matrix::Matrix convert_char_to_texture(matrix::Matrix &tile_ids) {
auto result = matrix::make(matrix::width(tile_ids), matrix::height(tile_ids));
for(matrix::each_cell it(tile_ids); it.next();) {
wchar_t tid = tile_ids[it.y][it.x];
result[it.y][it.x] = TMGR.char_to_texture.at(tid);
}
return result;
}
const uint32_t* get_floor() {
return (const uint32_t *)TMGR.floor.getPixelsPtr();
}