From 6ac70ff5dafae0729b7b3a9994e2da65de12c2e4 Mon Sep 17 00:00:00 2001 From: kleonc <9283098+kleonc@users.noreply.github.com> Date: Sun, 12 Mar 2023 12:53:46 +0100 Subject: TileMap Fix rendering odd-sized tiles (cherry picked from commit c49a7feae3418d0732369b203d0bc9e28723b9db) --- scene/2d/tile_map.cpp | 16 ++++++++-------- scene/2d/tile_map.h | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'scene/2d') diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index 11e59d9858..e602ab337d 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -854,7 +854,7 @@ void TileMap::_update_dirty_quadrants() { q->self()->local_to_map.clear(); for (const Vector2i &E : q->self()->cells) { Vector2i pk = E; - Vector2i pk_local_coords = map_to_local(pk); + Vector2 pk_local_coords = map_to_local(pk); q->self()->map_to_local[pk] = pk_local_coords; q->self()->local_to_map[pk_local_coords] = pk; } @@ -1056,7 +1056,7 @@ void TileMap::_rendering_notification(int p_what) { TileMapQuadrant &q = E_quadrant.value; // Update occluders transform. - for (const KeyValue &E_cell : q.local_to_map) { + for (const KeyValue &E_cell : q.local_to_map) { Transform2D xform; xform.set_origin(E_cell.key); for (const KeyValue &kv : q.occluders) { @@ -1214,7 +1214,7 @@ void TileMap::_rendering_update_dirty_quadrants(SelfList::List RID prev_ci; // Iterate over the cells of the quadrant. - for (const KeyValue &E_cell : q.local_to_map) { + for (const KeyValue &E_cell : q.local_to_map) { TileMapCell c = get_cell(q.layer, E_cell.value, true); TileSetSource *source; @@ -1312,13 +1312,13 @@ void TileMap::_rendering_update_dirty_quadrants(SelfList::List for (TileMapLayer &layer : layers) { // Sort the quadrants coords per local coordinates. - RBMap local_to_map; + RBMap local_to_map; for (const KeyValue &E : layer.quadrant_map) { local_to_map[map_to_local(E.key)] = E.key; } // Sort the quadrants. - for (const KeyValue &E : local_to_map) { + for (const KeyValue &E : local_to_map) { TileMapQuadrant &q = layer.quadrant_map[E.value]; for (const RID &ci : q.canvas_items) { RS::get_singleton()->canvas_item_set_draw_index(ci, index++); @@ -1400,7 +1400,7 @@ void TileMap::_rendering_draw_quadrant_debug(TileMapQuadrant *p_quadrant) { } } -void TileMap::draw_tile(RID p_canvas_item, const Vector2i &p_position, const Ref p_tile_set, int p_atlas_source_id, const Vector2i &p_atlas_coords, int p_alternative_tile, int p_frame, Color p_modulation, const TileData *p_tile_data_override) { +void TileMap::draw_tile(RID p_canvas_item, const Vector2 &p_position, const Ref p_tile_set, int p_atlas_source_id, const Vector2i &p_atlas_coords, int p_alternative_tile, int p_frame, Color p_modulation, const TileData *p_tile_data_override) { ERR_FAIL_COND(!p_tile_set.is_valid()); ERR_FAIL_COND(!p_tile_set->has_source(p_atlas_source_id)); ERR_FAIL_COND(!p_tile_set->get_source(p_atlas_source_id)->has_tile(p_atlas_coords)); @@ -1432,7 +1432,7 @@ void TileMap::draw_tile(RID p_canvas_item, const Vector2i &p_position, const Ref Color modulate = tile_data->get_modulate() * p_modulation; // Compute the offset. - Vector2i tile_offset = tile_data->get_texture_origin(); + Vector2 tile_offset = tile_data->get_texture_origin(); // Get destination rect. Rect2 dest_rect; @@ -3023,7 +3023,7 @@ void TileMap::_build_runtime_update_tile_data(SelfList::List &r while (q_list_element) { TileMapQuadrant &q = *q_list_element->self(); // Iterate over the cells of the quadrant. - for (const KeyValue &E_cell : q.local_to_map) { + for (const KeyValue &E_cell : q.local_to_map) { TileMapCell c = get_cell(q.layer, E_cell.value, true); TileSetSource *source; diff --git a/scene/2d/tile_map.h b/scene/2d/tile_map.h index e9c1cb0c11..1f3c672f17 100644 --- a/scene/2d/tile_map.h +++ b/scene/2d/tile_map.h @@ -39,7 +39,7 @@ class TileSetAtlasSource; struct TileMapQuadrant { struct CoordsWorldComparator { - _ALWAYS_INLINE_ bool operator()(const Vector2i &p_a, const Vector2i &p_b) const { + _ALWAYS_INLINE_ bool operator()(const Vector2 &p_a, const Vector2 &p_b) const { // We sort the cells by their local coords, as it is needed by rendering. if (p_a.y == p_b.y) { return p_a.x > p_b.x; @@ -60,8 +60,8 @@ struct TileMapQuadrant { RBSet cells; // We need those two maps to sort by local position for rendering // This is kind of workaround, it would be better to sort the cells directly in the "cells" set instead. - RBMap map_to_local; - RBMap local_to_map; + RBMap map_to_local; + RBMap local_to_map; // Debug. RID debug_canvas_item; @@ -311,7 +311,7 @@ public: void set_quadrant_size(int p_size); int get_quadrant_size() const; - static void draw_tile(RID p_canvas_item, const Vector2i &p_position, const Ref p_tile_set, int p_atlas_source_id, const Vector2i &p_atlas_coords, int p_alternative_tile, int p_frame = -1, Color p_modulation = Color(1.0, 1.0, 1.0, 1.0), const TileData *p_tile_data_override = nullptr); + static void draw_tile(RID p_canvas_item, const Vector2 &p_position, const Ref p_tile_set, int p_atlas_source_id, const Vector2i &p_atlas_coords, int p_alternative_tile, int p_frame = -1, Color p_modulation = Color(1.0, 1.0, 1.0, 1.0), const TileData *p_tile_data_override = nullptr); // Layers management. int get_layers_count() const; -- cgit v1.2.3