Skip to content

Commit

Permalink
Optimized tile selection rendering (#1571)
Browse files Browse the repository at this point in the history
Co-authored-by: Semphris <[email protected]>
  • Loading branch information
Semphriss and Semphris authored Nov 8, 2020
1 parent 1de4fbd commit 613771c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/editor/overlay_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,18 +939,24 @@ EditorOverlayWidget::draw_tile_tip(DrawingContext& context)
return;
}

if (m_editor.get_tiles()->empty())
return;

Vector screen_corner = context.get_cliprect().p2() +
m_editor.get_sector()->get_camera().get_translation();
Vector drawn_tile = m_hovered_tile;
auto tiles = m_editor.get_tiles();

for (drawn_tile.x = static_cast<float>(tiles->m_width) - 1.0f; drawn_tile.x >= 0.0f; drawn_tile.x--) {
for (drawn_tile.y = static_cast<float>(tiles->m_height) - 1.0f; drawn_tile.y >= 0.0f; drawn_tile.y--) {
Vector on_tile = m_hovered_tile + drawn_tile;

if (m_editor.get_tiles()->empty() ||
on_tile.x < 0 ||
if (on_tile.x < 0 ||
on_tile.y < 0 ||
on_tile.x >= static_cast<float>(tilemap->get_width()) ||
on_tile.y >= static_cast<float>(tilemap->get_height())) {
on_tile.y >= static_cast<float>(tilemap->get_height()) ||
on_tile.x >= ceilf(screen_corner.x / 32) ||
on_tile.y >= ceilf(screen_corner.y / 32)) {
continue;
}
uint32_t tile_id = tiles->pos(static_cast<int>(drawn_tile.x), static_cast<int>(drawn_tile.y));
Expand Down

0 comments on commit 613771c

Please sign in to comment.