Refactor ensure_tile method.
@@ -73,16 +73,12 @@ class OpenGLTilesetAlias::impl : public TilesetObserver {
auto prepare_alias(const TCOD_Console& console) -> uint32_t
{
for (int i = 0; i < console.w * console.h; ++i) {
- int codepoint = console.tiles[i].ch;
- if (codepoint >= static_cast<int>(local_map_.size())
- || local_map_.at(codepoint) < 0) {
- if (ensure_tile(codepoint) == -1) {
+ if (ensure_tile(console.tiles[i].ch) == -1) {
// The texture alias was replaced by a bigger one.
i = -1; // Need to start over from the beginning.
continue;
}
}
- }
return gltexture_;
}
auto get_tile_position(int codepoint) const -> std::array<int, 2>
@@ -156,6 +152,9 @@ class OpenGLTilesetAlias::impl : public TilesetObserver {
if (codepoint >= static_cast<int>(local_map_.size())) {
local_map_.resize(codepoint + 1, -1);
}
+ if (local_map_.at(codepoint) >= 0) {
+ return 0; // Tile already assigned.
+ }
if (next_alias_index_ == capacity()) {
// Replace the current texture with a larger one.
texture_size_ *= 2;
