summaryrefslogtreecommitdiffstats
path: root/scene/2d/tile_map.cpp
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2020-05-14 13:23:58 +0200
committerRémi Verschelde <rverschelde@gmail.com>2020-05-14 16:54:55 +0200
commit0be6d925dc3c6413bce7a3ccb49631b8e4a6e67a (patch)
treea27e497da7104dd0a64f98a04fa3067668735e91 /scene/2d/tile_map.cpp
parent710b34b70227becdc652b4ae027fe0ac47409642 (diff)
downloadredot-engine-0be6d925dc3c6413bce7a3ccb49631b8e4a6e67a.tar.gz
Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks
Which means that reduz' beloved style which we all became used to will now be changed automatically to remove the first empty line. This makes us lean closer to 1TBS (the one true brace style) instead of hybridating it with some Allman-inspired spacing. There's still the case of braces around single-statement blocks that needs to be addressed (but clang-format can't help with that, but clang-tidy may if we agree about it). Part of #33027.
Diffstat (limited to 'scene/2d/tile_map.cpp')
-rw-r--r--scene/2d/tile_map.cpp142
1 files changed, 0 insertions, 142 deletions
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp
index 869f290f97..fa66a2af22 100644
--- a/scene/2d/tile_map.cpp
+++ b/scene/2d/tile_map.cpp
@@ -39,7 +39,6 @@
#include "servers/physics_server_2d.h"
int TileMap::_get_quadrant_size() const {
-
if (use_y_sort)
return 1;
else
@@ -47,14 +46,10 @@ int TileMap::_get_quadrant_size() const {
}
void TileMap::_notification(int p_what) {
-
switch (p_what) {
-
case NOTIFICATION_ENTER_TREE: {
-
Node2D *c = this;
while (c) {
-
navigation = Object::cast_to<Navigation2D>(c);
if (navigation) {
break;
@@ -79,14 +74,11 @@ void TileMap::_notification(int p_what) {
} break;
case NOTIFICATION_EXIT_TREE: {
-
_update_quadrant_space(RID());
for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
-
Quadrant &q = E->get();
if (navigation) {
for (Map<PosKey, Quadrant::NavPoly>::Element *F = q.navpoly_ids.front(); F; F = F->next()) {
-
NavigationServer2D::get_singleton()->region_set_map(F->get().region, RID());
}
q.navpoly_ids.clear();
@@ -109,13 +101,11 @@ void TileMap::_notification(int p_what) {
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
-
//move stuff
_update_quadrant_transform();
} break;
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
-
if (use_parent) {
_recreate_quadrants();
}
@@ -125,10 +115,8 @@ void TileMap::_notification(int p_what) {
}
void TileMap::_update_quadrant_space(const RID &p_space) {
-
if (!use_parent) {
for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
-
Quadrant &q = E->get();
PhysicsServer2D::get_singleton()->body_set_space(q.body, p_space);
}
@@ -136,7 +124,6 @@ void TileMap::_update_quadrant_space(const RID &p_space) {
}
void TileMap::_update_quadrant_transform() {
-
if (!is_inside_tree())
return;
@@ -151,7 +138,6 @@ void TileMap::_update_quadrant_transform() {
nav_rel = get_relative_transform_to_parent(navigation);
for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
-
Quadrant &q = E->get();
Transform2D xform;
xform.set_origin(q.pos);
@@ -163,7 +149,6 @@ void TileMap::_update_quadrant_transform() {
if (navigation) {
for (Map<PosKey, Quadrant::NavPoly>::Element *F = q.navpoly_ids.front(); F; F = F->next()) {
-
NavigationServer2D::get_singleton()->region_set_transform(F->get().region, nav_rel * F->get().xform);
}
}
@@ -175,7 +160,6 @@ void TileMap::_update_quadrant_transform() {
}
void TileMap::set_tileset(const Ref<TileSet> &p_tileset) {
-
if (tile_set.is_valid()) {
tile_set->disconnect("changed", callable_mp(this, &TileMap::_recreate_quadrants));
tile_set->remove_change_receptor(this);
@@ -196,12 +180,10 @@ void TileMap::set_tileset(const Ref<TileSet> &p_tileset) {
}
Ref<TileSet> TileMap::get_tileset() const {
-
return tile_set;
}
void TileMap::set_cell_size(Size2 p_size) {
-
ERR_FAIL_COND(p_size.x < 1 || p_size.y < 1);
_clear_quadrants();
@@ -211,12 +193,10 @@ void TileMap::set_cell_size(Size2 p_size) {
}
Size2 TileMap::get_cell_size() const {
-
return cell_size;
}
void TileMap::set_quadrant_size(int p_size) {
-
ERR_FAIL_COND_MSG(p_size < 1, "Quadrant size cannot be smaller than 1.");
_clear_quadrants();
@@ -226,17 +206,14 @@ void TileMap::set_quadrant_size(int p_size) {
}
int TileMap::get_quadrant_size() const {
-
return quadrant_size;
}
void TileMap::_fix_cell_transform(Transform2D &xform, const Cell &p_cell, const Vector2 &p_offset, const Size2 &p_sc) {
-
Size2 s = p_sc;
Vector2 offset = p_offset;
if (compatibility_mode && !centered_textures) {
-
if (tile_origin == TILE_ORIGIN_BOTTOM_LEFT) {
offset.y += cell_size.y;
} else if (tile_origin == TILE_ORIGIN_CENTER) {
@@ -326,7 +303,6 @@ void TileMap::_add_shape(int &shape_idx, const Quadrant &p_q, const Ref<Shape2D>
}
void TileMap::update_dirty_quadrants() {
-
if (!pending_update)
return;
if (!is_inside_tree() || !tile_set.is_valid()) {
@@ -358,11 +334,9 @@ void TileMap::update_dirty_quadrants() {
}
while (dirty_quadrant_list.first()) {
-
Quadrant &q = *dirty_quadrant_list.first()->self();
for (List<RID>::Element *E = q.canvas_items.front(); E; E = E->next()) {
-
vs->free(E->get());
}
@@ -377,7 +351,6 @@ void TileMap::update_dirty_quadrants() {
if (navigation) {
for (Map<PosKey, Quadrant::NavPoly>::Element *E = q.navpoly_ids.front(); E; E = E->next()) {
-
NavigationServer2D::get_singleton()->region_set_map(E->get().region, RID());
}
q.navpoly_ids.clear();
@@ -393,7 +366,6 @@ void TileMap::update_dirty_quadrants() {
RID prev_debug_canvas_item;
for (int i = 0; i < q.cells.size(); i++) {
-
Map<PosKey, Cell>::Element *E = tile_map.find(q.cells[i]);
Cell &c = E->get();
//moment of truth
@@ -420,7 +392,6 @@ void TileMap::update_dirty_quadrants() {
RID debug_canvas_item;
if (prev_canvas_item == RID() || prev_material != mat || prev_z_index != z_index) {
-
canvas_item = vs->canvas_item_create();
if (mat.is_valid())
vs->canvas_item_set_material(canvas_item, mat->get_rid());
@@ -435,7 +406,6 @@ void TileMap::update_dirty_quadrants() {
q.canvas_items.push_back(canvas_item);
if (debug_shapes) {
-
debug_canvas_item = vs->canvas_item_create();
vs->canvas_item_set_parent(debug_canvas_item, canvas_item);
vs->canvas_item_set_z_as_relative_to_parent(debug_canvas_item, false);
@@ -509,7 +479,6 @@ void TileMap::update_dirty_quadrants() {
rect.position += tile_ofs;
} else if (tile_origin == TILE_ORIGIN_BOTTOM_LEFT) {
-
rect.position += tile_ofs;
if (c.transpose) {
@@ -525,7 +494,6 @@ void TileMap::update_dirty_quadrants() {
}
} else if (tile_origin == TILE_ORIGIN_CENTER) {
-
rect.position += tile_ofs;
if (c.flip_h)
@@ -651,10 +619,8 @@ void TileMap::update_dirty_quadrants() {
Vector<int> polygon = navpoly->get_polygon(j);
for (int k = 2; k < polygon.size(); k++) {
-
int kofs[3] = { 0, k - 1, k };
for (int l = 0; l < 3; l++) {
-
int idx = polygon[kofs[l]];
ERR_FAIL_INDEX(idx, vsize);
indices.push_back(idx);
@@ -704,13 +670,10 @@ void TileMap::update_dirty_quadrants() {
pending_update = false;
if (quadrant_order_dirty) {
-
int index = -(int64_t)0x80000000; //always must be drawn below children
for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
-
Quadrant &q = E->get();
for (List<RID>::Element *F = q.canvas_items.front(); F; F = F->next()) {
-
RS::get_singleton()->canvas_item_set_draw_index(F->get(), index++);
}
}
@@ -722,7 +685,6 @@ void TileMap::update_dirty_quadrants() {
}
void TileMap::_recompute_rect_cache() {
-
#ifdef DEBUG_ENABLED
if (!rect_cache_dirty)
@@ -730,7 +692,6 @@ void TileMap::_recompute_rect_cache() {
Rect2 r_total;
for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
-
Rect2 r;
r.position = _map_to_world(E->key().x * _get_quadrant_size(), E->key().y * _get_quadrant_size());
r.expand_to(_map_to_world(E->key().x * _get_quadrant_size() + _get_quadrant_size(), E->key().y * _get_quadrant_size()));
@@ -751,7 +712,6 @@ void TileMap::_recompute_rect_cache() {
}
Map<TileMap::PosKey, TileMap::Quadrant>::Element *TileMap::_create_quadrant(const PosKey &p_qk) {
-
Transform2D xform;
//xform.set_origin(Point2(p_qk.x,p_qk.y)*cell_size*quadrant_size);
Quadrant q;
@@ -794,7 +754,6 @@ Map<TileMap::PosKey, TileMap::Quadrant>::Element *TileMap::_create_quadrant(cons
}
void TileMap::_erase_quadrant(Map<PosKey, Quadrant>::Element *Q) {
-
Quadrant &q = Q->get();
if (!use_parent) {
PhysicsServer2D::get_singleton()->free(q.body);
@@ -803,7 +762,6 @@ void TileMap::_erase_quadrant(Map<PosKey, Quadrant>::Element *Q) {
}
for (List<RID>::Element *E = q.canvas_items.front(); E; E = E->next()) {
-
RenderingServer::get_singleton()->free(E->get());
}
q.canvas_items.clear();
@@ -812,7 +770,6 @@ void TileMap::_erase_quadrant(Map<PosKey, Quadrant>::Element *Q) {
if (navigation) {
for (Map<PosKey, Quadrant::NavPoly>::Element *E = q.navpoly_ids.front(); E; E = E->next()) {
-
NavigationServer2D::get_singleton()->region_set_map(E->get().region, RID());
}
q.navpoly_ids.clear();
@@ -828,7 +785,6 @@ void TileMap::_erase_quadrant(Map<PosKey, Quadrant>::Element *Q) {
}
void TileMap::_make_quadrant_dirty(Map<PosKey, Quadrant>::Element *Q, bool update) {
-
Quadrant &q = Q->get();
if (!q.dirty_list.in_list())
dirty_quadrant_list.add(&q.dirty_list);
@@ -845,12 +801,10 @@ void TileMap::_make_quadrant_dirty(Map<PosKey, Quadrant>::Element *Q, bool updat
}
void TileMap::set_cellv(const Vector2 &p_pos, int p_tile, bool p_flip_x, bool p_flip_y, bool p_transpose) {
-
set_cell(p_pos.x, p_pos.y, p_tile, p_flip_x, p_flip_y, p_transpose);
}
void TileMap::_set_celld(const Vector2 &p_pos, const Dictionary &p_data) {
-
Variant v_pos_x = p_pos.x, v_pos_y = p_pos.y, v_tile = p_data["id"], v_flip_h = p_data["flip_h"], v_flip_v = p_data["flip_y"], v_transpose = p_data["transpose"], v_autotile_coord = p_data["auto_coord"];
const Variant *args[7] = { &v_pos_x, &v_pos_y, &v_tile, &v_flip_h, &v_flip_v, &v_transpose, &v_autotile_coord };
Callable::CallError ce;
@@ -858,7 +812,6 @@ void TileMap::_set_celld(const Vector2 &p_pos, const Dictionary &p_data) {
}
void TileMap::set_cell(int p_x, int p_y, int p_tile, bool p_flip_x, bool p_flip_y, bool p_transpose, Vector2 p_autotile_coord) {
-
PosKey pk(p_x, p_y);
Map<PosKey, Cell>::Element *E = tile_map.find(pk);
@@ -912,12 +865,10 @@ void TileMap::set_cell(int p_x, int p_y, int p_tile, bool p_flip_x, bool p_flip_
}
int TileMap::get_cellv(const Vector2 &p_pos) const {
-
return get_cell(p_pos.x, p_pos.y);
}
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; y <= p_pos.y + 1; y++) {
PosKey p(x, y);
@@ -929,7 +880,6 @@ void TileMap::make_bitmask_area_dirty(const Vector2 &p_pos) {
}
void TileMap::update_bitmask_area(const Vector2 &p_pos) {
-
for (int x = p_pos.x - 1; x <= p_pos.x + 1; x++) {
for (int y = p_pos.y - 1; y <= p_pos.y + 1; y++) {
update_cell_bitmask(x, y);
@@ -938,7 +888,6 @@ void TileMap::update_bitmask_area(const Vector2 &p_pos) {
}
void TileMap::update_bitmask_region(const Vector2 &p_start, const Vector2 &p_end) {
-
if ((p_end.x < p_start.x || p_end.y < p_start.y) || (p_end.x == p_start.x && p_end.y == p_start.y)) {
Array a = get_used_cells();
for (int i = 0; i < a.size(); i++) {
@@ -955,7 +904,6 @@ void TileMap::update_bitmask_region(const Vector2 &p_start, const Vector2 &p_end
}
void TileMap::update_cell_bitmask(int p_x, int p_y) {
-
ERR_FAIL_COND_MSG(tile_set.is_null(), "Cannot update cell bitmask if Tileset is not open.");
PosKey p(p_x, p_y);
Map<PosKey, Cell>::Element *E = tile_map.find(p);
@@ -1027,11 +975,9 @@ void TileMap::update_cell_bitmask(int p_x, int p_y) {
_make_quadrant_dirty(Q);
} else if (tile_set->tile_get_tile_mode(id) == TileSet::SINGLE_TILE) {
-
E->get().autotile_coord_x = 0;
E->get().autotile_coord_y = 0;
} else if (tile_set->tile_get_tile_mode(id) == TileSet::ATLAS_TILE) {
-
if (tile_set->autotile_get_bitmask(id, Vector2(p_x, p_y)) == TileSet::BIND_CENTER) {
Vector2 coord = tile_set->atlastile_get_subtile_by_priority(id, this, Vector2(p_x, p_y));
@@ -1043,7 +989,6 @@ void TileMap::update_cell_bitmask(int p_x, int p_y) {
}
void TileMap::update_dirty_bitmask() {
-
while (dirty_bitmask.size() > 0) {
update_cell_bitmask(dirty_bitmask[0].x, dirty_bitmask[0].y);
dirty_bitmask.pop_front();
@@ -1051,10 +996,8 @@ void TileMap::update_dirty_bitmask() {
}
void TileMap::fix_invalid_tiles() {
-
ERR_FAIL_COND_MSG(tile_set.is_null(), "Cannot fix invalid tiles if Tileset is not open.");
for (Map<PosKey, Cell>::Element *E = tile_map.front(); E; E = E->next()) {
-
if (!tile_set->has_tile(get_cell(E->key().x, E->key().y))) {
set_cell(E->key().x, E->key().y, INVALID_CELL);
}
@@ -1062,7 +1005,6 @@ void TileMap::fix_invalid_tiles() {
}
int TileMap::get_cell(int p_x, int p_y) const {
-
PosKey pk(p_x, p_y);
const Map<PosKey, Cell>::Element *E = tile_map.find(pk);
@@ -1073,7 +1015,6 @@ int TileMap::get_cell(int p_x, int p_y) const {
return E->get().id;
}
bool TileMap::is_cell_x_flipped(int p_x, int p_y) const {
-
PosKey pk(p_x, p_y);
const Map<PosKey, Cell>::Element *E = tile_map.find(pk);
@@ -1084,7 +1025,6 @@ bool TileMap::is_cell_x_flipped(int p_x, int p_y) const {
return E->get().flip_h;
}
bool TileMap::is_cell_y_flipped(int p_x, int p_y) const {
-
PosKey pk(p_x, p_y);
const Map<PosKey, Cell>::Element *E = tile_map.find(pk);
@@ -1095,7 +1035,6 @@ bool TileMap::is_cell_y_flipped(int p_x, int p_y) const {
return E->get().flip_v;
}
bool TileMap::is_cell_transposed(int p_x, int p_y) const {
-
PosKey pk(p_x, p_y);
const Map<PosKey, Cell>::Element *E = tile_map.find(pk);
@@ -1107,7 +1046,6 @@ bool TileMap::is_cell_transposed(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);
@@ -1130,7 +1068,6 @@ void TileMap::set_cell_autotile_coord(int p_x, int p_y, const Vector2 &p_coord)
}
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);
@@ -1142,11 +1079,9 @@ Vector2 TileMap::get_cell_autotile_coord(int p_x, int p_y) const {
}
void TileMap::_recreate_quadrants() {
-
_clear_quadrants();
for (Map<PosKey, Cell>::Element *E = tile_map.front(); E; E = E->next()) {
-
PosKey qk = PosKey(E->key().x, E->key().y).to_quadrant(_get_quadrant_size());
Map<PosKey, Quadrant>::Element *Q = quadrant_map.find(qk);
@@ -1162,50 +1097,41 @@ void TileMap::_recreate_quadrants() {
}
void TileMap::_clear_quadrants() {
-
while (quadrant_map.size()) {
_erase_quadrant(quadrant_map.front());
}
}
void TileMap::set_material(const Ref<Material> &p_material) {
-
CanvasItem::set_material(p_material);
_update_all_items_material_state();
}
void TileMap::set_use_parent_material(bool p_use_parent_material) {
-
CanvasItem::set_use_parent_material(p_use_parent_material);
_update_all_items_material_state();
}
void TileMap::_update_all_items_material_state() {
-
for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
-
Quadrant &q = E->get();
for (List<RID>::Element *F = q.canvas_items.front(); F; F = F->next()) {
-
_update_item_material_state(F->get());
}
}
}
void TileMap::_update_item_material_state(const RID &p_canvas_item) {
-
RS::get_singleton()->canvas_item_set_use_parent_material(p_canvas_item, get_use_parent_material() || get_material().is_valid());
}
void TileMap::clear() {
-
_clear_quadrants();
tile_map.clear();
used_size_cache_dirty = true;
}
void TileMap::_set_tile_data(const Vector<int> &p_data) {
-
ERR_FAIL_COND(format > FORMAT_2);
int c = p_data.size();
@@ -1215,7 +1141,6 @@ void TileMap::_set_tile_data(const Vector<int> &p_data) {
clear();
for (int i = 0; i < c; i += offset) {
-
const uint8_t *ptr = (const uint8_t *)&r[i];
uint8_t local[12];
for (int j = 0; j < ((format == FORMAT_2) ? 12 : 8); j++)
@@ -1253,7 +1178,6 @@ void TileMap::_set_tile_data(const Vector<int> &p_data) {
}
Vector<int> TileMap::_get_tile_data() const {
-
Vector<int> data;
data.resize(tile_map.size() * 3);
int *w = data.ptrw();
@@ -1293,11 +1217,9 @@ Rect2 TileMap::_edit_get_rect() const {
#endif
void TileMap::set_collision_layer(uint32_t p_layer) {
-
collision_layer = p_layer;
if (!use_parent) {
for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
-
Quadrant &q = E->get();
PhysicsServer2D::get_singleton()->body_set_collision_layer(q.body, collision_layer);
}
@@ -1305,11 +1227,9 @@ void TileMap::set_collision_layer(uint32_t p_layer) {
}
void TileMap::set_collision_mask(uint32_t p_mask) {
-
collision_mask = p_mask;
if (!use_parent) {
for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
-
Quadrant &q = E->get();
PhysicsServer2D::get_singleton()->body_set_collision_mask(q.body, collision_mask);
}
@@ -1317,7 +1237,6 @@ void TileMap::set_collision_mask(uint32_t p_mask) {
}
void TileMap::set_collision_layer_bit(int p_bit, bool p_value) {
-
uint32_t layer = get_collision_layer();
if (p_value)
layer |= 1 << p_bit;
@@ -1327,7 +1246,6 @@ void TileMap::set_collision_layer_bit(int p_bit, bool p_value) {
}
void TileMap::set_collision_mask_bit(int p_bit, bool p_value) {
-
uint32_t mask = get_collision_mask();
if (p_value)
mask |= 1 << p_bit;
@@ -1337,24 +1255,20 @@ void TileMap::set_collision_mask_bit(int p_bit, bool p_value) {
}
bool TileMap::get_collision_use_kinematic() const {
-
return use_kinematic;
}
void TileMap::set_collision_use_kinematic(bool p_use_kinematic) {
-
_clear_quadrants();
use_kinematic = p_use_kinematic;
_recreate_quadrants();
}
bool TileMap::get_collision_use_parent() const {
-
return use_parent;
}
void TileMap::set_collision_use_parent(bool p_use_parent) {
-
if (use_parent == p_use_parent)
return;
@@ -1375,11 +1289,9 @@ void TileMap::set_collision_use_parent(bool p_use_parent) {
}
void TileMap::set_collision_friction(float p_friction) {
-
friction = p_friction;
if (!use_parent) {
for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
-
Quadrant &q = E->get();
PhysicsServer2D::get_singleton()->body_set_param(q.body, PhysicsServer2D::BODY_PARAM_FRICTION, p_friction);
}
@@ -1387,48 +1299,39 @@ void TileMap::set_collision_friction(float p_friction) {
}
float TileMap::get_collision_friction() const {
-
return friction;
}
void TileMap::set_collision_bounce(float p_bounce) {
-
bounce = p_bounce;
if (!use_parent) {
for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
-
Quadrant &q = E->get();
PhysicsServer2D::get_singleton()->body_set_param(q.body, PhysicsServer2D::BODY_PARAM_BOUNCE, p_bounce);
}
}
}
float TileMap::get_collision_bounce() const {
-
return bounce;
}
uint32_t TileMap::get_collision_layer() const {
-
return collision_layer;
}
uint32_t TileMap::get_collision_mask() const {
-
return collision_mask;
}
bool TileMap::get_collision_layer_bit(int p_bit) const {
-
return get_collision_layer() & (1 << p_bit);
}
bool TileMap::get_collision_mask_bit(int p_bit) const {
-
return get_collision_mask() & (1 << p_bit);
}
void TileMap::set_mode(Mode p_mode) {
-
_clear_quadrants();
mode = p_mode;
_recreate_quadrants();
@@ -1440,7 +1343,6 @@ TileMap::Mode TileMap::get_mode() const {
}
void TileMap::set_half_offset(HalfOffset p_half_offset) {
-
_clear_quadrants();
half_offset = p_half_offset;
_recreate_quadrants();
@@ -1448,7 +1350,6 @@ void TileMap::set_half_offset(HalfOffset p_half_offset) {
}
void TileMap::set_tile_origin(TileOrigin p_tile_origin) {
-
_clear_quadrants();
tile_origin = p_tile_origin;
_recreate_quadrants();
@@ -1456,25 +1357,19 @@ void TileMap::set_tile_origin(TileOrigin p_tile_origin) {
}
TileMap::TileOrigin TileMap::get_tile_origin() const {
-
return tile_origin;
}
Vector2 TileMap::get_cell_draw_offset() const {
-
switch (mode) {
-
case MODE_SQUARE: {
-
return Vector2();
} break;
case MODE_ISOMETRIC: {
-
return Vector2(-cell_size.x * 0.5, 0);
} break;
case MODE_CUSTOM: {
-
Vector2 min;
min.x = MIN(custom_transform[0].x, min.x);
min.y = MIN(custom_transform[0].y, min.y);
@@ -1492,18 +1387,14 @@ TileMap::HalfOffset TileMap::get_half_offset() const {
}
Transform2D TileMap::get_cell_transform() const {
-
switch (mode) {
-
case MODE_SQUARE: {
-
Transform2D m;
m[0] *= cell_size.x;
m[1] *= cell_size.y;
return m;
} break;
case MODE_ISOMETRIC: {
-
//isometric only makes sense when y is positive in both x and y vectors, otherwise
//the drawing of tiles will overlap
Transform2D m;
@@ -1513,7 +1404,6 @@ Transform2D TileMap::get_cell_transform() const {
} break;
case MODE_CUSTOM: {
-
return custom_transform;
} break;
}
@@ -1522,7 +1412,6 @@ Transform2D TileMap::get_cell_transform() const {
}
void TileMap::set_custom_transform(const Transform2D &p_xform) {
-
_clear_quadrants();
custom_transform = p_xform;
_recreate_quadrants();
@@ -1530,20 +1419,16 @@ void TileMap::set_custom_transform(const Transform2D &p_xform) {
}
Transform2D TileMap::get_custom_transform() const {
-
return custom_transform;
}
Vector2 TileMap::_map_to_world(int p_x, int p_y, bool p_ignore_ofs) const {
-
Vector2 ret = get_cell_transform().xform(Vector2(p_x, p_y));
if (!p_ignore_ofs) {
switch (half_offset) {
-
case HALF_OFFSET_X:
case HALF_OFFSET_NEGATIVE_X: {
if (ABS(p_y) & 1) {
-
ret += get_cell_transform()[0] * (half_offset == HALF_OFFSET_X ? 0.5 : -0.5);
}
} break;
@@ -1562,7 +1447,6 @@ Vector2 TileMap::_map_to_world(int p_x, int p_y, bool p_ignore_ofs) const {
}
bool TileMap::_set(const StringName &p_name, const Variant &p_value) {
-
if (p_name == "format") {
if (p_value.get_type() == Variant::INT) {
format = (DataFormat)(p_value.operator int64_t()); // Set format used for loading
@@ -1579,7 +1463,6 @@ bool TileMap::_set(const StringName &p_name, const Variant &p_value) {
}
bool TileMap::_get(const StringName &p_name, Variant &r_ret) const {
-
if (p_name == "format") {
r_ret = FORMAT_2; // When saving, always save highest format
return true;
@@ -1591,7 +1474,6 @@ bool TileMap::_get(const StringName &p_name, Variant &r_ret) const {
}
void TileMap::_get_property_list(List<PropertyInfo> *p_list) const {
-
PropertyInfo p(Variant::INT, "format", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL);
p_list->push_back(p);
@@ -1606,16 +1488,13 @@ void TileMap::_validate_property(PropertyInfo &property) const {
}
Vector2 TileMap::map_to_world(const Vector2 &p_pos, bool p_ignore_ofs) const {
-
return _map_to_world(p_pos.x, p_pos.y, p_ignore_ofs);
}
Vector2 TileMap::world_to_map(const Vector2 &p_pos) const {
-
Vector2 ret = get_cell_transform().affine_inverse().xform(p_pos);
switch (half_offset) {
-
case HALF_OFFSET_X: {
if (int(floor(ret.y)) & 1) {
ret.x -= 0.5;
@@ -1650,7 +1529,6 @@ Vector2 TileMap::world_to_map(const Vector2 &p_pos) const {
}
void TileMap::set_y_sort_enabled(bool p_enable) {
-
_clear_quadrants();
use_y_sort = p_enable;
RS::get_singleton()->canvas_item_set_sort_children_by_y(get_canvas_item(), use_y_sort);
@@ -1659,12 +1537,10 @@ void TileMap::set_y_sort_enabled(bool p_enable) {
}
bool TileMap::is_y_sort_enabled() const {
-
return use_y_sort;
}
void TileMap::set_compatibility_mode(bool p_enable) {
-
_clear_quadrants();
compatibility_mode = p_enable;
_recreate_quadrants();
@@ -1672,12 +1548,10 @@ void TileMap::set_compatibility_mode(bool p_enable) {
}
bool TileMap::is_compatibility_mode_enabled() const {
-
return compatibility_mode;
}
void TileMap::set_centered_textures(bool p_enable) {
-
_clear_quadrants();
centered_textures = p_enable;
_recreate_quadrants();
@@ -1685,17 +1559,14 @@ void TileMap::set_centered_textures(bool p_enable) {
}
bool TileMap::is_centered_textures_enabled() const {
-
return centered_textures;
}
TypedArray<Vector2i> TileMap::get_used_cells() const {
-
TypedArray<Vector2i> a;
a.resize(tile_map.size());
int i = 0;
for (Map<PosKey, Cell>::Element *E = tile_map.front(); E; E = E->next()) {
-
Vector2i p(E->key().x, E->key().y);
a[i++] = p;
}
@@ -1704,10 +1575,8 @@ TypedArray<Vector2i> TileMap::get_used_cells() const {
}
TypedArray<Vector2i> TileMap::get_used_cells_by_index(int p_id) const {
-
TypedArray<Vector2i> a;
for (Map<PosKey, Cell>::Element *E = tile_map.front(); E; E = E->next()) {
-
if (E->value().id == p_id) {
Vector2i p(E->key().x, E->key().y);
a.push_back(p);
@@ -1739,10 +1608,8 @@ Rect2 TileMap::get_used_rect() { // Not const because of cache
}
void TileMap::set_occluder_light_mask(int p_mask) {
-
occluder_light_mask = p_mask;
for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
-
for (Map<PosKey, Quadrant::Occluder>::Element *F = E->get().occluder_instances.front(); F; F = F->next()) {
RenderingServer::get_singleton()->canvas_light_occluder_set_light_mask(F->get().id, occluder_light_mask);
}
@@ -1750,15 +1617,12 @@ void TileMap::set_occluder_light_mask(int p_mask) {
}
int TileMap::get_occluder_light_mask() const {
-
return occluder_light_mask;
}
void TileMap::set_light_mask(int p_light_mask) {
-
CanvasItem::set_light_mask(p_light_mask);
for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
-
for (List<RID>::Element *F = E->get().canvas_items.front(); F; F = F->next()) {
RenderingServer::get_singleton()->canvas_item_set_light_mask(F->get(), get_light_mask());
}
@@ -1766,7 +1630,6 @@ void TileMap::set_light_mask(int p_light_mask) {
}
void TileMap::set_clip_uv(bool p_enable) {
-
if (clip_uv == p_enable)
return;
@@ -1776,12 +1639,10 @@ void TileMap::set_clip_uv(bool p_enable) {
}
bool TileMap::get_clip_uv() const {
-
return clip_uv;
}
String TileMap::get_configuration_warning() const {
-
String warning = Node2D::get_configuration_warning();
if (use_parent && !collision_parent) {
@@ -1795,7 +1656,6 @@ String TileMap::get_configuration_warning() const {
}
void TileMap::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_tileset", "tileset"), &TileMap::set_tileset);
ClassDB::bind_method(D_METHOD("get_tileset"), &TileMap::get_tileset);
@@ -1942,7 +1802,6 @@ void TileMap::_changed_callback(Object *p_changed, const char *p_prop) {
}
TileMap::TileMap() {
-
rect_cache_dirty = true;
used_size_cache_dirty = true;
pending_update = false;
@@ -1974,7 +1833,6 @@ TileMap::TileMap() {
}
TileMap::~TileMap() {
-
if (tile_set.is_valid())
tile_set->remove_change_receptor(this);