| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "scene/resources/2d/tile_set.h" |
| 34 |
|
| 35 |
#ifndef NAVIGATION_2D_DISABLED |
| 36 |
class NavigationMeshSourceGeometryData2D; |
| 37 |
#endif |
| 38 |
class TileSetAtlasSource; |
| 39 |
class TileMap; |
| 40 |
|
| 41 |
enum TileMapLayerDataFormat { |
| 42 |
TILE_MAP_LAYER_DATA_FORMAT_0 = 0, |
| 43 |
TILE_MAP_LAYER_DATA_FORMAT_MAX, |
| 44 |
}; |
| 45 |
|
| 46 |
class TerrainConstraint { |
| 47 |
private: |
| 48 |
Ref<TileSet> tile_set; |
| 49 |
Vector2i base_cell_coords; |
| 50 |
int bit = -1; |
| 51 |
int terrain = -1; |
| 52 |
|
| 53 |
int priority = 1; |
| 54 |
|
| 55 |
public: |
| 56 |
bool operator<(const TerrainConstraint &p_other) const { |
| 57 |
if (base_cell_coords == p_other.base_cell_coords) { |
| 58 |
return bit < p_other.bit; |
| 59 |
} |
| 60 |
return base_cell_coords < p_other.base_cell_coords; |
| 61 |
} |
| 62 |
|
| 63 |
String to_string() const { |
| 64 |
return vformat("Constraint {pos:%s, bit:%d, terrain:%d, priority:%d}", base_cell_coords, bit, terrain, priority); |
| 65 |
} |
| 66 |
|
| 67 |
Vector2i get_base_cell_coords() const { |
| 68 |
return base_cell_coords; |
| 69 |
} |
| 70 |
|
| 71 |
bool is_center_bit() const { |
| 72 |
return bit == 0; |
| 73 |
} |
| 74 |
|
| 75 |
HashMap<Vector2i, TileSet::CellNeighbor> get_overlapping_coords_and_peering_bits() const; |
| 76 |
|
| 77 |
void set_terrain(int p_terrain) { |
| 78 |
terrain = p_terrain; |
| 79 |
} |
| 80 |
|
| 81 |
int get_terrain() const { |
| 82 |
return terrain; |
| 83 |
} |
| 84 |
|
| 85 |
void set_priority(int p_priority) { |
| 86 |
priority = p_priority; |
| 87 |
} |
| 88 |
|
| 89 |
int get_priority() const { |
| 90 |
return priority; |
| 91 |
} |
| 92 |
|
| 93 |
TerrainConstraint(Ref<TileSet> p_tile_set, const Vector2i &p_position, int p_terrain); |
| 94 |
TerrainConstraint(Ref<TileSet> p_tile_set, const Vector2i &p_position, const TileSet::CellNeighbor &p_bit, int p_terrain); |
| 95 |
TerrainConstraint() {} |
| 96 |
}; |
| 97 |
|
| 98 |
#ifdef DEBUG_ENABLED |
| 99 |
class DebugQuadrant; |
| 100 |
#endif |
| 101 |
class RenderingQuadrant; |
| 102 |
class PhysicsQuadrant; |
| 103 |
|
| 104 |
struct CellData { |
| 105 |
Vector2i coords; |
| 106 |
TileMapCell cell; |
| 107 |
|
| 108 |
|
| 109 |
SelfList<CellData> debug_quadrant_list_element; |
| 110 |
|
| 111 |
|
| 112 |
Ref<RenderingQuadrant> rendering_quadrant; |
| 113 |
SelfList<CellData> rendering_quadrant_list_element; |
| 114 |
LocalVector<LocalVector<RID>> occluders; |
| 115 |
|
| 116 |
#ifndef PHYSICS_2D_DISABLED |
| 117 |
|
| 118 |
Ref<PhysicsQuadrant> physics_quadrant; |
| 119 |
SelfList<CellData> physics_quadrant_list_element; |
| 120 |
#endif |
| 121 |
|
| 122 |
|
| 123 |
LocalVector<RID> navigation_regions; |
| 124 |
|
| 125 |
|
| 126 |
String scene; |
| 127 |
|
| 128 |
|
| 129 |
TileData *runtime_tile_data_cache = nullptr; |
| 130 |
|
| 131 |
|
| 132 |
SelfList<CellData> dirty_list_element; |
| 133 |
|
| 134 |
bool operator<(const CellData &p_other) const { |
| 135 |
return coords < p_other.coords; |
| 136 |
} |
| 137 |
|
| 138 |
|
| 139 |
void operator=(const CellData &p_other) { |
| 140 |
coords = p_other.coords; |
| 141 |
cell = p_other.cell; |
| 142 |
occluders = p_other.occluders; |
| 143 |
navigation_regions = p_other.navigation_regions; |
| 144 |
scene = p_other.scene; |
| 145 |
runtime_tile_data_cache = p_other.runtime_tile_data_cache; |
| 146 |
} |
| 147 |
|
| 148 |
CellData(const CellData &p_other) : |
| 149 |
debug_quadrant_list_element(this), |
| 150 |
rendering_quadrant_list_element(this), |
| 151 |
#ifndef PHYSICS_2D_DISABLED |
| 152 |
physics_quadrant_list_element(this), |
| 153 |
#endif |
| 154 |
dirty_list_element(this) { |
| 155 |
coords = p_other.coords; |
| 156 |
cell = p_other.cell; |
| 157 |
occluders = p_other.occluders; |
| 158 |
navigation_regions = p_other.navigation_regions; |
| 159 |
scene = p_other.scene; |
| 160 |
runtime_tile_data_cache = p_other.runtime_tile_data_cache; |
| 161 |
} |
| 162 |
|
| 163 |
CellData() : |
| 164 |
debug_quadrant_list_element(this), |
| 165 |
rendering_quadrant_list_element(this), |
| 166 |
#ifndef PHYSICS_2D_DISABLED |
| 167 |
physics_quadrant_list_element(this), |
| 168 |
#endif |
| 169 |
dirty_list_element(this) { |
| 170 |
} |
| 171 |
}; |
| 172 |
|
| 173 |
|
| 174 |
struct CellDataYSortedXReversedComparator { |
| 175 |
_FORCE_INLINE_ bool operator()(const CellData &p_a, const CellData &p_b) const { |
| 176 |
return p_a.coords.x == p_b.coords.x ? (p_a.coords.y < p_b.coords.y) : (p_a.coords.x > p_b.coords.x); |
| 177 |
} |
| 178 |
}; |
| 179 |
|
| 180 |
#ifdef DEBUG_ENABLED |
| 181 |
class DebugQuadrant : public RefCounted { |
| 182 |
GDCLASS(DebugQuadrant, RefCounted); |
| 183 |
|
| 184 |
public: |
| 185 |
Vector2i quadrant_coords; |
| 186 |
SelfList<CellData>::List cells; |
| 187 |
RID canvas_item; |
| 188 |
|
| 189 |
RID physics_mesh; |
| 190 |
|
| 191 |
|
| 192 |
bool drawn_to = false; |
| 193 |
|
| 194 |
SelfList<DebugQuadrant> dirty_quadrant_list_element; |
| 195 |
|
| 196 |
DebugQuadrant() : |
| 197 |
dirty_quadrant_list_element(this) { |
| 198 |
} |
| 199 |
|
| 200 |
~DebugQuadrant() { |
| 201 |
cells.clear(); |
| 202 |
} |
| 203 |
}; |
| 204 |
#endif |
| 205 |
|
| 206 |
class RenderingQuadrant : public RefCounted { |
| 207 |
GDCLASS(RenderingQuadrant, RefCounted); |
| 208 |
|
| 209 |
public: |
| 210 |
struct CoordsWorldComparator { |
| 211 |
_ALWAYS_INLINE_ bool operator()(const Vector2 &p_a, const Vector2 &p_b) const { |
| 212 |
|
| 213 |
if (p_a.y == p_b.y) { |
| 214 |
return p_a.x > p_b.x; |
| 215 |
} else { |
| 216 |
return p_a.y < p_b.y; |
| 217 |
} |
| 218 |
} |
| 219 |
}; |
| 220 |
|
| 221 |
Vector2i quadrant_coords; |
| 222 |
SelfList<CellData>::List cells; |
| 223 |
List<RID> canvas_items; |
| 224 |
Vector2 canvas_items_position; |
| 225 |
|
| 226 |
SelfList<RenderingQuadrant> dirty_quadrant_list_element; |
| 227 |
|
| 228 |
RenderingQuadrant() : |
| 229 |
dirty_quadrant_list_element(this) { |
| 230 |
} |
| 231 |
|
| 232 |
~RenderingQuadrant() { |
| 233 |
cells.clear(); |
| 234 |
} |
| 235 |
}; |
| 236 |
|
| 237 |
#ifndef PHYSICS_2D_DISABLED |
| 238 |
class PhysicsQuadrant : public RefCounted { |
| 239 |
GDCLASS(PhysicsQuadrant, RefCounted); |
| 240 |
|
| 241 |
public: |
| 242 |
struct PhysicsBodyKey { |
| 243 |
int physics_layer = 0; |
| 244 |
Vector2 linear_velocity; |
| 245 |
real_t angular_velocity = 0.0; |
| 246 |
|
| 247 |
bool one_way_collision = false; |
| 248 |
real_t one_way_collision_margin = 0.0; |
| 249 |
|
| 250 |
int64_t y_origin = 0; |
| 251 |
|
| 252 |
bool operator<(const PhysicsBodyKey &p_other) const { |
| 253 |
if (physics_layer == p_other.physics_layer) { |
| 254 |
if (linear_velocity == p_other.linear_velocity) { |
| 255 |
if (angular_velocity == p_other.angular_velocity) { |
| 256 |
if (one_way_collision == p_other.one_way_collision) { |
| 257 |
if (one_way_collision && y_origin != p_other.y_origin) { |
| 258 |
return y_origin < p_other.y_origin; |
| 259 |
} |
| 260 |
return one_way_collision_margin < p_other.one_way_collision_margin; |
| 261 |
} |
| 262 |
return one_way_collision < p_other.one_way_collision; |
| 263 |
} |
| 264 |
return angular_velocity < p_other.angular_velocity; |
| 265 |
} |
| 266 |
return linear_velocity < p_other.linear_velocity; |
| 267 |
} |
| 268 |
return physics_layer < p_other.physics_layer; |
| 269 |
} |
| 270 |
|
| 271 |
bool operator!=(const PhysicsBodyKey &p_other) const { |
| 272 |
return !this->operator==(p_other); |
| 273 |
} |
| 274 |
bool operator==(const PhysicsBodyKey &p_other) const { |
| 275 |
return physics_layer == p_other.physics_layer && |
| 276 |
linear_velocity == p_other.linear_velocity && |
| 277 |
angular_velocity == p_other.angular_velocity && |
| 278 |
one_way_collision == p_other.one_way_collision && |
| 279 |
one_way_collision_margin == p_other.one_way_collision_margin && |
| 280 |
(!one_way_collision || y_origin == p_other.y_origin); |
| 281 |
} |
| 282 |
}; |
| 283 |
|
| 284 |
struct PhysicsBodyKeyHasher { |
| 285 |
static uint32_t hash(const PhysicsBodyKey &p_hash) { |
| 286 |
uint32_t h = hash_murmur3_one_32(p_hash.physics_layer); |
| 287 |
h = hash_murmur3_one_real(p_hash.linear_velocity.x); |
| 288 |
h = hash_murmur3_one_real(p_hash.linear_velocity.y, h); |
| 289 |
h = hash_murmur3_one_real(p_hash.angular_velocity, h); |
| 290 |
if (p_hash.one_way_collision) { |
| 291 |
h = hash_murmur3_one_32(p_hash.y_origin, h); |
| 292 |
} |
| 293 |
return h; |
| 294 |
} |
| 295 |
}; |
| 296 |
|
| 297 |
struct PhysicsBodyValue { |
| 298 |
RID body; |
| 299 |
Vector<Vector<Vector2>> polygons; |
| 300 |
}; |
| 301 |
|
| 302 |
struct CoordsWorldComparator { |
| 303 |
_ALWAYS_INLINE_ bool operator()(const Vector2 &p_a, const Vector2 &p_b) const { |
| 304 |
|
| 305 |
if (p_a.y == p_b.y) { |
| 306 |
return p_a.x > p_b.x; |
| 307 |
} else { |
| 308 |
return p_a.y < p_b.y; |
| 309 |
} |
| 310 |
} |
| 311 |
}; |
| 312 |
|
| 313 |
Vector2i quadrant_coords; |
| 314 |
SelfList<CellData>::List cells; |
| 315 |
|
| 316 |
HashMap<PhysicsBodyKey, PhysicsBodyValue, PhysicsBodyKeyHasher> bodies; |
| 317 |
LocalVector<Ref<ConvexPolygonShape2D>> shapes; |
| 318 |
|
| 319 |
SelfList<PhysicsQuadrant> dirty_quadrant_list_element; |
| 320 |
|
| 321 |
PhysicsQuadrant() : |
| 322 |
dirty_quadrant_list_element(this) { |
| 323 |
} |
| 324 |
|
| 325 |
~PhysicsQuadrant() { |
| 326 |
cells.clear(); |
| 327 |
} |
| 328 |
}; |
| 329 |
#endif |
| 330 |
|
| 331 |
class TileMapLayer : public Node2D { |
| 332 |
GDCLASS(TileMapLayer, Node2D); |
| 333 |
|
| 334 |
public: |
| 335 |
enum HighlightMode { |
| 336 |
HIGHLIGHT_MODE_DEFAULT, |
| 337 |
HIGHLIGHT_MODE_ABOVE, |
| 338 |
HIGHLIGHT_MODE_BELOW, |
| 339 |
}; |
| 340 |
|
| 341 |
enum DebugVisibilityMode { |
| 342 |
DEBUG_VISIBILITY_MODE_DEFAULT, |
| 343 |
DEBUG_VISIBILITY_MODE_FORCE_SHOW, |
| 344 |
DEBUG_VISIBILITY_MODE_FORCE_HIDE, |
| 345 |
}; |
| 346 |
|
| 347 |
enum DirtyFlags { |
| 348 |
DIRTY_FLAGS_LAYER_ENABLED = 0, |
| 349 |
|
| 350 |
DIRTY_FLAGS_LAYER_IN_TREE, |
| 351 |
DIRTY_FLAGS_LAYER_IN_CANVAS, |
| 352 |
DIRTY_FLAGS_LAYER_LOCAL_TRANSFORM, |
| 353 |
DIRTY_FLAGS_LAYER_VISIBILITY, |
| 354 |
DIRTY_FLAGS_LAYER_SELF_MODULATE, |
| 355 |
DIRTY_FLAGS_LAYER_Y_SORT_ENABLED, |
| 356 |
DIRTY_FLAGS_LAYER_Y_SORT_ORIGIN, |
| 357 |
DIRTY_FLAGS_LAYER_X_DRAW_ORDER_REVERSED, |
| 358 |
DIRTY_FLAGS_LAYER_Z_INDEX, |
| 359 |
DIRTY_FLAGS_LAYER_LIGHT_MASK, |
| 360 |
DIRTY_FLAGS_LAYER_TEXTURE_FILTER, |
| 361 |
DIRTY_FLAGS_LAYER_TEXTURE_REPEAT, |
| 362 |
DIRTY_FLAGS_LAYER_RENDERING_QUADRANT_SIZE, |
| 363 |
DIRTY_FLAGS_LAYER_COLLISION_ENABLED, |
| 364 |
DIRTY_FLAGS_LAYER_USE_KINEMATIC_BODIES, |
| 365 |
DIRTY_FLAGS_LAYER_PHYSICS_QUADRANT_SIZE, |
| 366 |
DIRTY_FLAGS_LAYER_COLLISION_VISIBILITY_MODE, |
| 367 |
DIRTY_FLAGS_LAYER_OCCLUSION_ENABLED, |
| 368 |
DIRTY_FLAGS_LAYER_NAVIGATION_ENABLED, |
| 369 |
DIRTY_FLAGS_LAYER_NAVIGATION_MAP, |
| 370 |
DIRTY_FLAGS_LAYER_NAVIGATION_VISIBILITY_MODE, |
| 371 |
DIRTY_FLAGS_LAYER_RUNTIME_UPDATE, |
| 372 |
DIRTY_FLAGS_LAYER_HIGHLIGHT_MODE, |
| 373 |
|
| 374 |
DIRTY_FLAGS_LAYER_INDEX_IN_TILE_MAP_NODE, |
| 375 |
|
| 376 |
DIRTY_FLAGS_LAYER_GROUP_SELECTED_LAYERS, |
| 377 |
DIRTY_FLAGS_LAYER_GROUP_HIGHLIGHT_SELECTED, |
| 378 |
|
| 379 |
DIRTY_FLAGS_TILE_SET, |
| 380 |
|
| 381 |
DIRTY_FLAGS_MAX, |
| 382 |
}; |
| 383 |
|
| 384 |
private: |
| 385 |
static constexpr float FP_ADJUST = 0.00001; |
| 386 |
|
| 387 |
|
| 388 |
HashMap<Vector2i, CellData> tile_map_layer_data; |
| 389 |
|
| 390 |
bool enabled = true; |
| 391 |
Ref<TileSet> tile_set; |
| 392 |
|
| 393 |
HighlightMode highlight_mode = HIGHLIGHT_MODE_DEFAULT; |
| 394 |
|
| 395 |
int y_sort_origin = 0; |
| 396 |
bool x_draw_order_reversed = false; |
| 397 |
int rendering_quadrant_size = 16; |
| 398 |
|
| 399 |
bool collision_enabled = true; |
| 400 |
bool use_kinematic_bodies = false; |
| 401 |
int physics_quadrant_size = 16; |
| 402 |
DebugVisibilityMode collision_visibility_mode = DEBUG_VISIBILITY_MODE_DEFAULT; |
| 403 |
|
| 404 |
bool occlusion_enabled = true; |
| 405 |
|
| 406 |
bool navigation_enabled = true; |
| 407 |
RID navigation_map_override; |
| 408 |
DebugVisibilityMode navigation_visibility_mode = DEBUG_VISIBILITY_MODE_DEFAULT; |
| 409 |
|
| 410 |
|
| 411 |
bool pending_update = false; |
| 412 |
|
| 413 |
|
| 414 |
TileMap *tile_map_node = nullptr; |
| 415 |
int layer_index_in_tile_map_node = -1; |
| 416 |
|
| 417 |
|
| 418 |
struct { |
| 419 |
bool flags[DIRTY_FLAGS_MAX] = { false }; |
| 420 |
SelfList<CellData>::List cell_list; |
| 421 |
} dirty; |
| 422 |
|
| 423 |
|
| 424 |
mutable Rect2 rect_cache; |
| 425 |
mutable bool rect_cache_dirty = true; |
| 426 |
mutable Rect2i used_rect_cache; |
| 427 |
mutable bool used_rect_cache_dirty = true; |
| 428 |
|
| 429 |
|
| 430 |
bool _runtime_update_tile_data_was_cleaned_up = false; |
| 431 |
void _build_runtime_update_tile_data(bool p_force_cleanup); |
| 432 |
void _build_runtime_update_tile_data_for_cell(CellData &r_cell_data, bool p_use_tilemap_for_runtime, bool p_auto_add_to_dirty_list = false); |
| 433 |
bool _runtime_update_needs_all_cells_cleaned_up = false; |
| 434 |
void _clear_runtime_update_tile_data(); |
| 435 |
void _clear_runtime_update_tile_data_for_cell(CellData &r_cell_data); |
| 436 |
void _update_cells_callback(bool p_force_cleanup); |
| 437 |
|
| 438 |
|
| 439 |
Vector2i _coords_to_quadrant_coords(const Vector2i &p_coords, const int p_quadrant_size) const; |
| 440 |
|
| 441 |
|
| 442 |
#ifdef DEBUG_ENABLED |
| 443 |
HashMap<Vector2i, Ref<DebugQuadrant>> debug_quadrant_map; |
| 444 |
bool _debug_was_cleaned_up = true; |
| 445 |
void _debug_update(bool p_force_cleanup); |
| 446 |
void _debug_quadrants_update_cell(CellData &r_cell_data); |
| 447 |
void _get_debug_quadrant_for_cell(const Vector2i &p_coords); |
| 448 |
#endif |
| 449 |
|
| 450 |
HashMap<Vector2i, Ref<RenderingQuadrant>> rendering_quadrant_map; |
| 451 |
bool _rendering_was_cleaned_up = true; |
| 452 |
bool _occlusion_was_cleaned_up = true; |
| 453 |
void _rendering_update(bool p_force_cleanup); |
| 454 |
void _rendering_notification(int p_what); |
| 455 |
Color _highlight_color(const Color &p_modulate) const; |
| 456 |
void _rendering_quadrants_update_cell(CellData &r_cell_data, SelfList<RenderingQuadrant>::List &r_dirty_rendering_quadrant_list); |
| 457 |
void _rendering_occluders_clear_cell(CellData &r_cell_data); |
| 458 |
void _rendering_occluders_update_cell(CellData &r_cell_data); |
| 459 |
#ifdef DEBUG_ENABLED |
| 460 |
void _rendering_draw_cell_debug(const RID &p_canvas_item, const Vector2 &p_quadrant_pos, const CellData &r_cell_data); |
| 461 |
#endif |
| 462 |
|
| 463 |
#ifndef PHYSICS_2D_DISABLED |
| 464 |
HashMap<Vector2i, Ref<PhysicsQuadrant>> physics_quadrant_map; |
| 465 |
HashMap<RID, Vector2i> bodies_coords; |
| 466 |
bool _physics_was_cleaned_up = true; |
| 467 |
void _physics_update(bool p_force_cleanup); |
| 468 |
void _physics_notification(int p_what); |
| 469 |
void _physics_quadrants_update_cell(CellData &r_cell_data, SelfList<PhysicsQuadrant>::List &r_dirty_physics_quadrant_list); |
| 470 |
void _physics_clear_cell(CellData &r_cell_data); |
| 471 |
void _physics_update_cell(CellData &r_cell_data); |
| 472 |
#ifdef DEBUG_ENABLED |
| 473 |
void _physics_draw_quadrant_debug(const RID &p_canvas_item, DebugQuadrant &r_debug_quadrant); |
| 474 |
#endif |
| 475 |
#endif |
| 476 |
|
| 477 |
#ifndef NAVIGATION_2D_DISABLED |
| 478 |
bool _navigation_was_cleaned_up = true; |
| 479 |
void _navigation_update(bool p_force_cleanup); |
| 480 |
void _navigation_notification(int p_what); |
| 481 |
void _navigation_clear_cell(CellData &r_cell_data); |
| 482 |
void _navigation_update_cell(CellData &r_cell_data); |
| 483 |
#ifdef DEBUG_ENABLED |
| 484 |
void _navigation_draw_cell_debug(const RID &p_canvas_item, const Vector2 &p_quadrant_pos, const CellData &r_cell_data); |
| 485 |
#endif |
| 486 |
#endif |
| 487 |
|
| 488 |
bool _scenes_was_cleaned_up = true; |
| 489 |
void _scenes_update(bool p_force_cleanup); |
| 490 |
void _scenes_clear_cell(CellData &r_cell_data); |
| 491 |
void _scenes_update_cell(CellData &r_cell_data); |
| 492 |
#ifdef DEBUG_ENABLED |
| 493 |
void _scenes_draw_cell_debug(const RID &p_canvas_item, const Vector2 &p_quadrant_pos, const CellData &r_cell_data); |
| 494 |
#endif |
| 495 |
void _set_scene_transform_with_alternative(Node2D *p_scene, const Vector2 &p_cell_position, const int p_alternative_id); |
| 496 |
|
| 497 |
|
| 498 |
TileSet::TerrainsPattern _get_best_terrain_pattern_for_constraints(int p_terrain_set, const Vector2i &p_position, const RBSet<TerrainConstraint> &p_constraints, TileSet::TerrainsPattern p_current_pattern) const; |
| 499 |
RBSet<TerrainConstraint> _get_terrain_constraints_from_added_pattern(const Vector2i &p_position, int p_terrain_set, TileSet::TerrainsPattern p_terrains_pattern) const; |
| 500 |
RBSet<TerrainConstraint> _get_terrain_constraints_from_painted_cells_list(const RBSet<Vector2i> &p_painted, int p_terrain_set, bool p_ignore_empty_terrains) const; |
| 501 |
|
| 502 |
void _tile_set_changed(); |
| 503 |
|
| 504 |
void _renamed(); |
| 505 |
void _update_notify_local_transform(); |
| 506 |
|
| 507 |
|
| 508 |
void _queue_internal_update(); |
| 509 |
void _deferred_internal_update(); |
| 510 |
void _internal_update(bool p_force_cleanup); |
| 511 |
|
| 512 |
virtual void _physics_interpolated_changed() override; |
| 513 |
|
| 514 |
protected: |
| 515 |
void _notification(int p_what); |
| 516 |
|
| 517 |
static void _bind_methods(); |
| 518 |
void _validate_property(PropertyInfo &p_property) const; |
| 519 |
|
| 520 |
virtual void _update_self_texture_filter(RS::CanvasItemTextureFilter p_texture_filter) override; |
| 521 |
virtual void _update_self_texture_repeat(RS::CanvasItemTextureRepeat p_texture_repeat) override; |
| 522 |
|
| 523 |
public: |
| 524 |
#ifdef TOOLS_ENABLED |
| 525 |
virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const override; |
| 526 |
#endif |
| 527 |
|
| 528 |
|
| 529 |
void set_as_tile_map_internal_node(int p_index); |
| 530 |
int get_index_in_tile_map() const { |
| 531 |
return layer_index_in_tile_map_node; |
| 532 |
} |
| 533 |
const HashMap<Vector2i, CellData> &get_tile_map_layer_data() const { |
| 534 |
return tile_map_layer_data; |
| 535 |
} |
| 536 |
|
| 537 |
|
| 538 |
Rect2 get_rect(bool &r_changed) const; |
| 539 |
|
| 540 |
|
| 541 |
HashMap<Vector2i, TileSet::TerrainsPattern> terrain_fill_constraints(const Vector<Vector2i> &p_to_replace, int p_terrain_set, const RBSet<TerrainConstraint> &p_constraints) const; |
| 542 |
HashMap<Vector2i, TileSet::TerrainsPattern> terrain_fill_connect(const Vector<Vector2i> &p_coords_array, int p_terrain_set, int p_terrain, bool p_ignore_empty_terrains = true) const; |
| 543 |
HashMap<Vector2i, TileSet::TerrainsPattern> terrain_fill_path(const Vector<Vector2i> &p_coords_array, int p_terrain_set, int p_terrain, bool p_ignore_empty_terrains = true) const; |
| 544 |
HashMap<Vector2i, TileSet::TerrainsPattern> terrain_fill_pattern(const Vector<Vector2i> &p_coords_array, int p_terrain_set, TileSet::TerrainsPattern p_terrains_pattern, bool p_ignore_empty_terrains = true) const; |
| 545 |
|
| 546 |
|
| 547 |
TileMapCell get_cell(const Vector2i &p_coords) const; |
| 548 |
|
| 549 |
static void compute_transformed_tile_dest_rect(Rect2 &r_dest_rect, bool &r_transpose, const Vector2 &p_position, const Vector2 &p_dest_rect_size, const TileData *p_tile_data, int p_alternative_tile); |
| 550 |
static void draw_tile(RID p_canvas_item, const Vector2 &p_position, const Ref<TileSet> p_tile_set, int p_atlas_source_id, const Vector2i &p_atlas_coords, int p_alternative_tile, int p_frame = -1, const TileData *p_tile_data_override = nullptr, real_t p_normalized_animation_offset = 0.0); |
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
void set_cell(const Vector2i &p_coords, int p_source_id = TileSet::INVALID_SOURCE, const Vector2i &p_atlas_coords = TileSetSource::INVALID_ATLAS_COORDS, int p_alternative_tile = 0); |
| 557 |
void erase_cell(const Vector2i &p_coords); |
| 558 |
void fix_invalid_tiles(); |
| 559 |
void clear(); |
| 560 |
|
| 561 |
int get_cell_source_id(const Vector2i &p_coords) const; |
| 562 |
Vector2i get_cell_atlas_coords(const Vector2i &p_coords) const; |
| 563 |
int get_cell_alternative_tile(const Vector2i &p_coords) const; |
| 564 |
TileData *get_cell_tile_data(const Vector2i &p_coords) const; |
| 565 |
|
| 566 |
TypedArray<Vector2i> get_used_cells() const; |
| 567 |
TypedArray<Vector2i> get_used_cells_by_id(int p_source_id = TileSet::INVALID_SOURCE, const Vector2i &p_atlas_coords = TileSetSource::INVALID_ATLAS_COORDS, int p_alternative_tile = TileSetSource::INVALID_TILE_ALTERNATIVE) const; |
| 568 |
Rect2i get_used_rect() const; |
| 569 |
|
| 570 |
bool is_cell_flipped_h(const Vector2i &p_coords) const; |
| 571 |
bool is_cell_flipped_v(const Vector2i &p_coords) const; |
| 572 |
bool is_cell_transposed(const Vector2i &p_coords) const; |
| 573 |
|
| 574 |
|
| 575 |
Ref<TileMapPattern> get_pattern(TypedArray<Vector2i> p_coords_array); |
| 576 |
void set_pattern(const Vector2i &p_position, const Ref<TileMapPattern> p_pattern); |
| 577 |
|
| 578 |
|
| 579 |
void set_cells_terrain_connect(TypedArray<Vector2i> p_cells, int p_terrain_set, int p_terrain, bool p_ignore_empty_terrains = true); |
| 580 |
void set_cells_terrain_path(TypedArray<Vector2i> p_path, int p_terrain_set, int p_terrain, bool p_ignore_empty_terrains = true); |
| 581 |
|
| 582 |
#ifndef PHYSICS_2D_DISABLED |
| 583 |
|
| 584 |
bool has_body_rid(RID p_physics_body) const; |
| 585 |
Vector2i get_coords_for_body_rid(RID p_physics_body) const; |
| 586 |
#endif |
| 587 |
|
| 588 |
|
| 589 |
void update_internals(); |
| 590 |
void notify_runtime_tile_data_update(); |
| 591 |
GDVIRTUAL1R(bool, _use_tile_data_runtime_update, Vector2i); |
| 592 |
GDVIRTUAL2(_tile_data_runtime_update, Vector2i, TileData *); |
| 593 |
GDVIRTUAL2(_update_cells, TypedArray<Vector2i>, bool); |
| 594 |
|
| 595 |
|
| 596 |
Vector2i map_pattern(const Vector2i &p_position_in_tilemap, const Vector2i &p_coords_in_pattern, Ref<TileMapPattern> p_pattern); |
| 597 |
TypedArray<Vector2i> get_surrounding_cells(const Vector2i &p_coords); |
| 598 |
Vector2i get_neighbor_cell(const Vector2i &p_coords, TileSet::CellNeighbor p_cell_neighbor) const; |
| 599 |
Vector2 map_to_local(const Vector2i &p_pos) const; |
| 600 |
Vector2i local_to_map(const Vector2 &p_pos) const; |
| 601 |
|
| 602 |
|
| 603 |
void set_tile_map_data_from_array(const Vector<uint8_t> &p_data); |
| 604 |
Vector<uint8_t> get_tile_map_data_as_array() const; |
| 605 |
|
| 606 |
void set_enabled(bool p_enabled); |
| 607 |
bool is_enabled() const; |
| 608 |
void set_tile_set(const Ref<TileSet> &p_tile_set); |
| 609 |
Ref<TileSet> get_tile_set() const; |
| 610 |
|
| 611 |
void set_highlight_mode(HighlightMode p_highlight_mode); |
| 612 |
HighlightMode get_highlight_mode() const; |
| 613 |
|
| 614 |
virtual void set_self_modulate(const Color &p_self_modulate) override; |
| 615 |
virtual void set_y_sort_enabled(bool p_y_sort_enabled) override; |
| 616 |
void set_y_sort_origin(int p_y_sort_origin); |
| 617 |
int get_y_sort_origin() const; |
| 618 |
void set_x_draw_order_reversed(bool p_x_draw_order_reversed); |
| 619 |
bool is_x_draw_order_reversed() const; |
| 620 |
virtual void set_z_index(int p_z_index) override; |
| 621 |
virtual void set_light_mask(int p_light_mask) override; |
| 622 |
void set_rendering_quadrant_size(int p_size); |
| 623 |
int get_rendering_quadrant_size() const; |
| 624 |
|
| 625 |
void set_collision_enabled(bool p_enabled); |
| 626 |
bool is_collision_enabled() const; |
| 627 |
void set_use_kinematic_bodies(bool p_use_kinematic_bodies); |
| 628 |
bool is_using_kinematic_bodies() const; |
| 629 |
void set_collision_visibility_mode(DebugVisibilityMode p_show_collision); |
| 630 |
DebugVisibilityMode get_collision_visibility_mode() const; |
| 631 |
void set_physics_quadrant_size(int p_size); |
| 632 |
int get_physics_quadrant_size() const; |
| 633 |
|
| 634 |
void set_occlusion_enabled(bool p_enabled); |
| 635 |
bool is_occlusion_enabled() const; |
| 636 |
|
| 637 |
void set_navigation_enabled(bool p_enabled); |
| 638 |
bool is_navigation_enabled() const; |
| 639 |
void set_navigation_map(RID p_map); |
| 640 |
RID get_navigation_map() const; |
| 641 |
void set_navigation_visibility_mode(DebugVisibilityMode p_show_navigation); |
| 642 |
DebugVisibilityMode get_navigation_visibility_mode() const; |
| 643 |
|
| 644 |
private: |
| 645 |
#ifndef NAVIGATION_2D_DISABLED |
| 646 |
static Callable _navmesh_source_geometry_parsing_callback; |
| 647 |
static RID _navmesh_source_geometry_parser; |
| 648 |
#endif |
| 649 |
|
| 650 |
public: |
| 651 |
#ifndef NAVIGATION_2D_DISABLED |
| 652 |
static void navmesh_parse_init(); |
| 653 |
static void navmesh_parse_source_geometry(const Ref<NavigationPolygon> &p_navigation_mesh, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry_data, Node *p_node); |
| 654 |
#endif |
| 655 |
|
| 656 |
TileMapLayer(); |
| 657 |
~TileMapLayer(); |
| 658 |
}; |
| 659 |
|
| 660 |
VARIANT_ENUM_CAST(TileMapLayer::DebugVisibilityMode); |