diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2017-12-03 21:58:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-03 21:58:04 +0100 |
commit | 58930cf7ecd989bb42463ede923dea586901cba8 (patch) | |
tree | 4b227d357e52ba060b774e0c5e3ed55cf4845a58 /scene/2d | |
parent | 9b9fcb1977c2586fcba86405865a10ad81f8d2e6 (diff) | |
parent | af719a90a78687ac3d56367ef84696cc3b1c6434 (diff) |
Merge pull request #13431 from MarianoGnu/tileset
Several TileMap Fixes
Diffstat (limited to 'scene/2d')
-rw-r--r-- | scene/2d/tile_map.cpp | 24 | ||||
-rw-r--r-- | scene/2d/tile_map.h | 4 |
2 files changed, 18 insertions, 10 deletions
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index c7b656b5fc..c0d0a6e011 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -716,7 +716,7 @@ void TileMap::set_cell(int p_x, int p_y, int p_tile, bool p_flip_x, bool p_flip_ } else { ERR_FAIL_COND(!Q); // quadrant should exist... - if (E->get().id == p_tile && E->get().flip_h == p_flip_x && E->get().flip_v == p_flip_y && E->get().transpose == p_transpose) + if (E->get().id == p_tile && E->get().flip_h == p_flip_x && E->get().flip_v == p_flip_y && E->get().transpose == p_transpose && E->get().autotile_coord_x == (uint16_t)p_autotile_coord.x && E->get().autotile_coord_y == (uint16_t)p_autotile_coord.y) return; //nothing changed } @@ -741,7 +741,7 @@ int TileMap::get_cellv(const Vector2 &p_pos) const { void TileMap::make_bitmask_area_dirty(const Vector2 &p_pos) { for (int x = p_pos.x - 1; x <= p_pos.x + 1; x++) { - for (int y = p_pos.y - 1; x <= p_pos.y + 1; y++) { + for (int y = p_pos.y - 1; y <= p_pos.y + 1; y++) { PosKey p(x, y); if (dirty_bitmask.find(p) == NULL) { dirty_bitmask.push_back(p); @@ -810,6 +810,10 @@ void TileMap::update_cell_bitmask(int p_x, int p_y) { Vector2 coord = tile_set->autotile_get_subtile_for_bitmask(id, mask, this, Vector2(p_x, p_y)); E->get().autotile_coord_x = (int)coord.x; E->get().autotile_coord_y = (int)coord.y; + + PosKey qk(p_x / _get_quadrant_size(), p_y / _get_quadrant_size()); + Map<PosKey, Quadrant>::Element *Q = quadrant_map.find(qk); + _make_quadrant_dirty(Q); } else { E->get().autotile_coord_x = 0; E->get().autotile_coord_y = 0; @@ -870,28 +874,31 @@ bool TileMap::is_cell_transposed(int p_x, int p_y) const { return E->get().transpose; } -int TileMap::get_cell_autotile_coord_x(int p_x, int p_y) const { +void TileMap::set_cell_autotile_coord(int p_x, int p_y, const Vector2 &p_coord) { PosKey pk(p_x, p_y); const Map<PosKey, Cell>::Element *E = tile_map.find(pk); if (!E) - return 0; + return; - return E->get().autotile_coord_x; + Cell c = E->get(); + c.autotile_coord_x = p_coord.x; + c.autotile_coord_y = p_coord.y; + tile_map[pk] = c; } -int TileMap::get_cell_autotile_coord_y(int p_x, int p_y) const { +Vector2 TileMap::get_cell_autotile_coord(int p_x, int p_y) const { PosKey pk(p_x, p_y); const Map<PosKey, Cell>::Element *E = tile_map.find(pk); if (!E) - return 0; + return Vector2(); - return E->get().autotile_coord_y; + return Vector2(E->get().autotile_coord_x, E->get().autotile_coord_y); } void TileMap::_recreate_quadrants() { @@ -963,6 +970,7 @@ void TileMap::_set_tile_data(const PoolVector<int> &p_data) { int offset = (format == FORMAT_2_1_5) ? 3 : 2; + clear(); for (int i = 0; i < c; i += offset) { const uint8_t *ptr = (const uint8_t *)&r[i]; diff --git a/scene/2d/tile_map.h b/scene/2d/tile_map.h index a0ca2e6a35..8eecf48df2 100644 --- a/scene/2d/tile_map.h +++ b/scene/2d/tile_map.h @@ -241,8 +241,8 @@ public: bool is_cell_x_flipped(int p_x, int p_y) const; bool is_cell_y_flipped(int p_x, int p_y) const; bool is_cell_transposed(int p_x, int p_y) const; - int get_cell_autotile_coord_x(int p_x, int p_y) const; - int get_cell_autotile_coord_y(int p_x, int p_y) const; + void set_cell_autotile_coord(int p_x, int p_y, const Vector2 &p_coord); + Vector2 get_cell_autotile_coord(int p_x, int p_y) const; void set_cellv(const Vector2 &p_pos, int p_tile, bool p_flip_x = false, bool p_flip_y = false, bool p_transpose = false); int get_cellv(const Vector2 &p_pos) const; |