tile_set.h 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  1. /**************************************************************************/
  2. /* tile_set.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef TILE_SET_H
  31. #define TILE_SET_H
  32. #include "core/io/resource.h"
  33. #include "core/object/object.h"
  34. #include "core/templates/local_vector.h"
  35. #include "core/templates/rb_set.h"
  36. #include "scene/2d/light_occluder_2d.h"
  37. #include "scene/main/canvas_item.h"
  38. #include "scene/resources/2d/convex_polygon_shape_2d.h"
  39. #include "scene/resources/2d/navigation_polygon.h"
  40. #include "scene/resources/image_texture.h"
  41. #include "scene/resources/packed_scene.h"
  42. #include "scene/resources/physics_material.h"
  43. #ifndef DISABLE_DEPRECATED
  44. #include "scene/resources/shader.h"
  45. #endif
  46. class TileMap;
  47. class TileSetSource;
  48. class TileSetAtlasSource;
  49. class TileData;
  50. // Forward-declare the plugins.
  51. class TileSetPlugin;
  52. class TileSetPluginAtlasRendering;
  53. class TileSetPluginAtlasPhysics;
  54. class TileSetPluginAtlasNavigation;
  55. union TileMapCell {
  56. struct {
  57. int16_t source_id;
  58. int16_t coord_x;
  59. int16_t coord_y;
  60. int16_t alternative_tile;
  61. };
  62. uint64_t _u64t;
  63. static uint32_t hash(const TileMapCell &p_hash) {
  64. return hash_one_uint64(p_hash._u64t);
  65. }
  66. TileMapCell(int p_source_id = -1, Vector2i p_atlas_coords = Vector2i(-1, -1), int p_alternative_tile = -1) { // default are INVALID_SOURCE, INVALID_ATLAS_COORDS, INVALID_TILE_ALTERNATIVE
  67. source_id = p_source_id;
  68. set_atlas_coords(p_atlas_coords);
  69. alternative_tile = p_alternative_tile;
  70. }
  71. Vector2i get_atlas_coords() const {
  72. return Vector2i(coord_x, coord_y);
  73. }
  74. void set_atlas_coords(const Vector2i &r_coords) {
  75. coord_x = r_coords.x;
  76. coord_y = r_coords.y;
  77. }
  78. bool operator<(const TileMapCell &p_other) const {
  79. if (source_id == p_other.source_id) {
  80. if (coord_x == p_other.coord_x) {
  81. if (coord_y == p_other.coord_y) {
  82. return alternative_tile < p_other.alternative_tile;
  83. } else {
  84. return coord_y < p_other.coord_y;
  85. }
  86. } else {
  87. return coord_x < p_other.coord_x;
  88. }
  89. } else {
  90. return source_id < p_other.source_id;
  91. }
  92. }
  93. bool operator!=(const TileMapCell &p_other) const {
  94. return !(source_id == p_other.source_id && coord_x == p_other.coord_x && coord_y == p_other.coord_y && alternative_tile == p_other.alternative_tile);
  95. }
  96. bool operator==(const TileMapCell &p_other) const {
  97. return source_id == p_other.source_id && coord_x == p_other.coord_x && coord_y == p_other.coord_y && alternative_tile == p_other.alternative_tile;
  98. }
  99. };
  100. class TileMapPattern : public Resource {
  101. GDCLASS(TileMapPattern, Resource);
  102. Size2i size;
  103. HashMap<Vector2i, TileMapCell> pattern;
  104. void _set_tile_data(const Vector<int> &p_data);
  105. Vector<int> _get_tile_data() const;
  106. protected:
  107. bool _set(const StringName &p_name, const Variant &p_value);
  108. bool _get(const StringName &p_name, Variant &r_ret) const;
  109. void _get_property_list(List<PropertyInfo> *p_list) const;
  110. static void _bind_methods();
  111. public:
  112. void set_cell(const Vector2i &p_coords, int p_source_id, const Vector2i p_atlas_coords, int p_alternative_tile = 0);
  113. bool has_cell(const Vector2i &p_coords) const;
  114. void remove_cell(const Vector2i &p_coords, bool p_update_size = true);
  115. int get_cell_source_id(const Vector2i &p_coords) const;
  116. Vector2i get_cell_atlas_coords(const Vector2i &p_coords) const;
  117. int get_cell_alternative_tile(const Vector2i &p_coords) const;
  118. const HashMap<Vector2i, TileMapCell> &get_pattern() const { return pattern; }
  119. TypedArray<Vector2i> get_used_cells() const;
  120. Size2i get_size() const;
  121. void set_size(const Size2i &p_size);
  122. bool is_empty() const;
  123. void clear();
  124. };
  125. class TileSet : public Resource {
  126. GDCLASS(TileSet, Resource);
  127. #ifndef DISABLE_DEPRECATED
  128. private:
  129. struct CompatibilityShapeData {
  130. Vector2i autotile_coords;
  131. bool one_way;
  132. float one_way_margin;
  133. Ref<Shape2D> shape;
  134. Transform2D transform;
  135. };
  136. struct CompatibilityTileData {
  137. String name;
  138. Ref<Texture2D> texture;
  139. Vector2 tex_offset;
  140. Ref<Material> material;
  141. Rect2 region;
  142. int tile_mode = 0;
  143. Color modulate = Color(1, 1, 1);
  144. // Atlas or autotiles data
  145. int autotile_bitmask_mode = 0;
  146. Vector2 autotile_icon_coordinate;
  147. Size2i autotile_tile_size = Size2i(16, 16);
  148. int autotile_spacing = 0;
  149. HashMap<Vector2i, int> autotile_bitmask_flags;
  150. HashMap<Vector2i, Ref<OccluderPolygon2D>> autotile_occluder_map;
  151. HashMap<Vector2i, Ref<NavigationPolygon>> autotile_navpoly_map;
  152. HashMap<Vector2i, int> autotile_priority_map;
  153. HashMap<Vector2i, int> autotile_z_index_map;
  154. Vector<CompatibilityShapeData> shapes;
  155. Ref<OccluderPolygon2D> occluder;
  156. Vector2 occluder_offset;
  157. Ref<NavigationPolygon> navigation;
  158. Vector2 navigation_offset;
  159. int z_index = 0;
  160. };
  161. enum CompatibilityTileMode {
  162. COMPATIBILITY_TILE_MODE_SINGLE_TILE = 0,
  163. COMPATIBILITY_TILE_MODE_AUTO_TILE,
  164. COMPATIBILITY_TILE_MODE_ATLAS_TILE,
  165. };
  166. HashMap<int, CompatibilityTileData *> compatibility_data;
  167. HashMap<int, int> compatibility_tilemap_mapping_tile_modes;
  168. HashMap<int, RBMap<Array, Array>> compatibility_tilemap_mapping;
  169. HashMap<Vector2i, int> compatibility_size_count;
  170. void _compatibility_conversion();
  171. public:
  172. // Format of output array [source_id, atlas_coords, alternative]
  173. Array compatibility_tilemap_map(int p_tile_id, Vector2i p_coords, bool p_flip_h, bool p_flip_v, bool p_transpose);
  174. #endif // DISABLE_DEPRECATED
  175. public:
  176. static const int INVALID_SOURCE; // -1;
  177. enum CellNeighbor {
  178. CELL_NEIGHBOR_RIGHT_SIDE = 0,
  179. CELL_NEIGHBOR_RIGHT_CORNER,
  180. CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE,
  181. CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER,
  182. CELL_NEIGHBOR_BOTTOM_SIDE,
  183. CELL_NEIGHBOR_BOTTOM_CORNER,
  184. CELL_NEIGHBOR_BOTTOM_LEFT_SIDE,
  185. CELL_NEIGHBOR_BOTTOM_LEFT_CORNER,
  186. CELL_NEIGHBOR_LEFT_SIDE,
  187. CELL_NEIGHBOR_LEFT_CORNER,
  188. CELL_NEIGHBOR_TOP_LEFT_SIDE,
  189. CELL_NEIGHBOR_TOP_LEFT_CORNER,
  190. CELL_NEIGHBOR_TOP_SIDE,
  191. CELL_NEIGHBOR_TOP_CORNER,
  192. CELL_NEIGHBOR_TOP_RIGHT_SIDE,
  193. CELL_NEIGHBOR_TOP_RIGHT_CORNER,
  194. CELL_NEIGHBOR_MAX,
  195. };
  196. static const char *CELL_NEIGHBOR_ENUM_TO_TEXT[];
  197. enum TerrainMode {
  198. TERRAIN_MODE_MATCH_CORNERS_AND_SIDES = 0,
  199. TERRAIN_MODE_MATCH_CORNERS,
  200. TERRAIN_MODE_MATCH_SIDES,
  201. };
  202. enum TileShape {
  203. TILE_SHAPE_SQUARE,
  204. TILE_SHAPE_ISOMETRIC,
  205. TILE_SHAPE_HALF_OFFSET_SQUARE,
  206. TILE_SHAPE_HEXAGON,
  207. };
  208. enum TileLayout {
  209. TILE_LAYOUT_STACKED,
  210. TILE_LAYOUT_STACKED_OFFSET,
  211. TILE_LAYOUT_STAIRS_RIGHT,
  212. TILE_LAYOUT_STAIRS_DOWN,
  213. TILE_LAYOUT_DIAMOND_RIGHT,
  214. TILE_LAYOUT_DIAMOND_DOWN,
  215. };
  216. enum TileOffsetAxis {
  217. TILE_OFFSET_AXIS_HORIZONTAL,
  218. TILE_OFFSET_AXIS_VERTICAL,
  219. };
  220. struct PackedSceneSource {
  221. Ref<PackedScene> scene;
  222. Vector2 offset;
  223. };
  224. class TerrainsPattern {
  225. bool valid = false;
  226. int terrain = -1;
  227. int bits[TileSet::CELL_NEIGHBOR_MAX] = {};
  228. bool is_valid_bit[TileSet::CELL_NEIGHBOR_MAX] = {};
  229. int not_empty_terrains_count = 0;
  230. public:
  231. bool is_valid() const;
  232. bool is_erase_pattern() const;
  233. bool operator<(const TerrainsPattern &p_terrains_pattern) const;
  234. bool operator==(const TerrainsPattern &p_terrains_pattern) const;
  235. bool operator!=(const TerrainsPattern &p_terrains_pattern) const {
  236. return !operator==(p_terrains_pattern);
  237. }
  238. void set_terrain(int p_terrain);
  239. int get_terrain() const;
  240. void set_terrain_peering_bit(TileSet::CellNeighbor p_peering_bit, int p_terrain);
  241. int get_terrain_peering_bit(TileSet::CellNeighbor p_peering_bit) const;
  242. void from_array(Array p_terrains);
  243. Array as_array() const;
  244. TerrainsPattern(const TileSet *p_tile_set, int p_terrain_set);
  245. TerrainsPattern() {}
  246. };
  247. protected:
  248. bool _set(const StringName &p_name, const Variant &p_value);
  249. bool _get(const StringName &p_name, Variant &r_ret) const;
  250. void _get_property_list(List<PropertyInfo> *p_list) const;
  251. void _validate_property(PropertyInfo &p_property) const;
  252. #ifdef TOOLS_ENABLED
  253. virtual uint32_t hash_edited_version_for_preview() const override { return 0; } // Not using preview, so disable it for performance.
  254. #endif
  255. private:
  256. // --- TileSet data ---
  257. // Basic shape and layout.
  258. TileShape tile_shape = TILE_SHAPE_SQUARE;
  259. TileLayout tile_layout = TILE_LAYOUT_STACKED;
  260. TileOffsetAxis tile_offset_axis = TILE_OFFSET_AXIS_HORIZONTAL;
  261. Size2i tile_size = Size2i(16, 16); //Size2(64, 64);
  262. // Rendering.
  263. bool uv_clipping = false;
  264. struct OcclusionLayer {
  265. uint32_t light_mask = 1;
  266. bool sdf_collision = false;
  267. };
  268. Vector<OcclusionLayer> occlusion_layers;
  269. Ref<ArrayMesh> tile_lines_mesh;
  270. Ref<ArrayMesh> tile_filled_mesh;
  271. mutable bool tile_meshes_dirty = true;
  272. // Physics
  273. struct PhysicsLayer {
  274. uint32_t collision_layer = 1;
  275. uint32_t collision_mask = 1;
  276. real_t collision_priority = 1.0;
  277. Ref<PhysicsMaterial> physics_material;
  278. };
  279. Vector<PhysicsLayer> physics_layers;
  280. // Terrains
  281. struct Terrain {
  282. String name;
  283. Color color;
  284. };
  285. struct TerrainSet {
  286. TerrainMode mode = TERRAIN_MODE_MATCH_CORNERS_AND_SIDES;
  287. Vector<Terrain> terrains;
  288. };
  289. Vector<TerrainSet> terrain_sets;
  290. HashMap<TerrainMode, Ref<ArrayMesh>> terrain_meshes;
  291. HashMap<TerrainMode, HashMap<CellNeighbor, Ref<ArrayMesh>>> terrain_peering_bits_meshes;
  292. bool terrain_bits_meshes_dirty = true;
  293. LocalVector<RBMap<TileSet::TerrainsPattern, RBSet<TileMapCell>>> per_terrain_pattern_tiles; // Cached data.
  294. bool terrains_cache_dirty = true;
  295. void _update_terrains_cache();
  296. // Navigation
  297. struct NavigationLayer {
  298. uint32_t layers = 1;
  299. };
  300. Vector<NavigationLayer> navigation_layers;
  301. // CustomData
  302. struct CustomDataLayer {
  303. String name;
  304. Variant::Type type = Variant::NIL;
  305. };
  306. Vector<CustomDataLayer> custom_data_layers;
  307. HashMap<String, int> custom_data_layers_by_name;
  308. // Per Atlas source data.
  309. HashMap<int, Ref<TileSetSource>> sources;
  310. Vector<int> source_ids;
  311. int next_source_id = 0;
  312. // ---------------------
  313. LocalVector<Ref<TileMapPattern>> patterns;
  314. void _compute_next_source_id();
  315. void _source_changed();
  316. // Tile proxies
  317. RBMap<int, int> source_level_proxies;
  318. RBMap<Array, Array> coords_level_proxies;
  319. RBMap<Array, Array> alternative_level_proxies;
  320. // Helpers
  321. Vector<Point2> _get_square_terrain_polygon(Vector2i p_size);
  322. Vector<Point2> _get_square_corner_or_side_terrain_peering_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit);
  323. Vector<Point2> _get_square_corner_terrain_peering_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit);
  324. Vector<Point2> _get_square_side_terrain_peering_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit);
  325. Vector<Point2> _get_isometric_terrain_polygon(Vector2i p_size);
  326. Vector<Point2> _get_isometric_corner_or_side_terrain_peering_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit);
  327. Vector<Point2> _get_isometric_corner_terrain_peering_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit);
  328. Vector<Point2> _get_isometric_side_terrain_peering_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit);
  329. Vector<Point2> _get_half_offset_terrain_polygon(Vector2i p_size, float p_overlap, TileSet::TileOffsetAxis p_offset_axis);
  330. Vector<Point2> _get_half_offset_corner_or_side_terrain_peering_bit_polygon(Vector2i p_size, float p_overlap, TileSet::TileOffsetAxis p_offset_axis, TileSet::CellNeighbor p_bit);
  331. Vector<Point2> _get_half_offset_corner_terrain_peering_bit_polygon(Vector2i p_size, float p_overlap, TileSet::TileOffsetAxis p_offset_axis, TileSet::CellNeighbor p_bit);
  332. Vector<Point2> _get_half_offset_side_terrain_peering_bit_polygon(Vector2i p_size, float p_overlap, TileSet::TileOffsetAxis p_offset_axis, TileSet::CellNeighbor p_bit);
  333. protected:
  334. static void _bind_methods();
  335. public:
  336. // --- Plugins ---
  337. Vector<TileSetPlugin *> get_tile_set_atlas_plugins() const;
  338. // --- Accessors for TileSet data ---
  339. // -- Shape and layout --
  340. void set_tile_shape(TileShape p_shape);
  341. TileShape get_tile_shape() const;
  342. void set_tile_layout(TileLayout p_layout);
  343. TileLayout get_tile_layout() const;
  344. void set_tile_offset_axis(TileOffsetAxis p_alignment);
  345. TileOffsetAxis get_tile_offset_axis() const;
  346. void set_tile_size(Size2i p_size);
  347. Size2i get_tile_size() const;
  348. // -- Sources management --
  349. int get_next_source_id() const;
  350. int get_source_count() const;
  351. int get_source_id(int p_index) const;
  352. int add_source(Ref<TileSetSource> p_tile_set_source, int p_source_id_override = -1);
  353. void set_source_id(int p_source_id, int p_new_id);
  354. void remove_source(int p_source_id);
  355. void remove_source_ptr(TileSetSource *p_tile_set_source); // Not exposed
  356. bool has_source(int p_source_id) const;
  357. Ref<TileSetSource> get_source(int p_source_id) const;
  358. // Rendering
  359. void set_uv_clipping(bool p_uv_clipping);
  360. bool is_uv_clipping() const;
  361. int get_occlusion_layers_count() const;
  362. void add_occlusion_layer(int p_index = -1);
  363. void move_occlusion_layer(int p_from_index, int p_to_pos);
  364. void remove_occlusion_layer(int p_index);
  365. void set_occlusion_layer_light_mask(int p_layer_index, int p_light_mask);
  366. int get_occlusion_layer_light_mask(int p_layer_index) const;
  367. void set_occlusion_layer_sdf_collision(int p_layer_index, bool p_sdf_collision);
  368. bool get_occlusion_layer_sdf_collision(int p_layer_index) const;
  369. // Physics
  370. int get_physics_layers_count() const;
  371. void add_physics_layer(int p_index = -1);
  372. void move_physics_layer(int p_from_index, int p_to_pos);
  373. void remove_physics_layer(int p_index);
  374. void set_physics_layer_collision_layer(int p_layer_index, uint32_t p_layer);
  375. uint32_t get_physics_layer_collision_layer(int p_layer_index) const;
  376. void set_physics_layer_collision_mask(int p_layer_index, uint32_t p_mask);
  377. uint32_t get_physics_layer_collision_mask(int p_layer_index) const;
  378. void set_physics_layer_collision_priority(int p_layer_index, real_t p_priority);
  379. real_t get_physics_layer_collision_priority(int p_layer_index) const;
  380. void set_physics_layer_physics_material(int p_layer_index, Ref<PhysicsMaterial> p_physics_material);
  381. Ref<PhysicsMaterial> get_physics_layer_physics_material(int p_layer_index) const;
  382. // Terrain sets
  383. int get_terrain_sets_count() const;
  384. void add_terrain_set(int p_index = -1);
  385. void move_terrain_set(int p_from_index, int p_to_pos);
  386. void remove_terrain_set(int p_index);
  387. void set_terrain_set_mode(int p_terrain_set, TerrainMode p_terrain_mode);
  388. TerrainMode get_terrain_set_mode(int p_terrain_set) const;
  389. // Terrains
  390. int get_terrains_count(int p_terrain_set) const;
  391. void add_terrain(int p_terrain_set, int p_index = -1);
  392. void move_terrain(int p_terrain_set, int p_from_index, int p_to_pos);
  393. void remove_terrain(int p_terrain_set, int p_index);
  394. void set_terrain_name(int p_terrain_set, int p_terrain_index, String p_name);
  395. String get_terrain_name(int p_terrain_set, int p_terrain_index) const;
  396. void set_terrain_color(int p_terrain_set, int p_terrain_index, Color p_color);
  397. Color get_terrain_color(int p_terrain_set, int p_terrain_index) const;
  398. bool is_valid_terrain_peering_bit_for_mode(TileSet::TerrainMode p_terrain_mode, TileSet::CellNeighbor p_peering_bit) const;
  399. bool is_valid_terrain_peering_bit(int p_terrain_set, TileSet::CellNeighbor p_peering_bit) const;
  400. // Navigation
  401. int get_navigation_layers_count() const;
  402. void add_navigation_layer(int p_index = -1);
  403. void move_navigation_layer(int p_from_index, int p_to_pos);
  404. void remove_navigation_layer(int p_index);
  405. void set_navigation_layer_layers(int p_layer_index, uint32_t p_layers);
  406. uint32_t get_navigation_layer_layers(int p_layer_index) const;
  407. void set_navigation_layer_layer_value(int p_layer_index, int p_layer_number, bool p_value);
  408. bool get_navigation_layer_layer_value(int p_layer_index, int p_layer_number) const;
  409. // Custom data
  410. int get_custom_data_layers_count() const;
  411. void add_custom_data_layer(int p_index = -1);
  412. void move_custom_data_layer(int p_from_index, int p_to_pos);
  413. void remove_custom_data_layer(int p_index);
  414. int get_custom_data_layer_by_name(String p_value) const;
  415. void set_custom_data_layer_name(int p_layer_id, String p_value);
  416. String get_custom_data_layer_name(int p_layer_id) const;
  417. void set_custom_data_layer_type(int p_layer_id, Variant::Type p_value);
  418. Variant::Type get_custom_data_layer_type(int p_layer_id) const;
  419. // Tiles proxies.
  420. void set_source_level_tile_proxy(int p_source_from, int p_source_to);
  421. int get_source_level_tile_proxy(int p_source_from);
  422. bool has_source_level_tile_proxy(int p_source_from);
  423. void remove_source_level_tile_proxy(int p_source_from);
  424. void set_coords_level_tile_proxy(int p_source_from, Vector2i p_coords_from, int p_source_to, Vector2i p_coords_to);
  425. Array get_coords_level_tile_proxy(int p_source_from, Vector2i p_coords_from);
  426. bool has_coords_level_tile_proxy(int p_source_from, Vector2i p_coords_from);
  427. void remove_coords_level_tile_proxy(int p_source_from, Vector2i p_coords_from);
  428. void set_alternative_level_tile_proxy(int p_source_from, Vector2i p_coords_from, int p_alternative_from, int p_source_to, Vector2i p_coords_to, int p_alternative_to);
  429. Array get_alternative_level_tile_proxy(int p_source_from, Vector2i p_coords_from, int p_alternative_from);
  430. bool has_alternative_level_tile_proxy(int p_source_from, Vector2i p_coords_from, int p_alternative_from);
  431. void remove_alternative_level_tile_proxy(int p_source_from, Vector2i p_coords_from, int p_alternative_from);
  432. Array get_source_level_tile_proxies() const;
  433. Array get_coords_level_tile_proxies() const;
  434. Array get_alternative_level_tile_proxies() const;
  435. Array map_tile_proxy(int p_source_from, Vector2i p_coords_from, int p_alternative_from) const;
  436. void cleanup_invalid_tile_proxies();
  437. void clear_tile_proxies();
  438. // Patterns.
  439. int add_pattern(Ref<TileMapPattern> p_pattern, int p_index = -1);
  440. Ref<TileMapPattern> get_pattern(int p_index);
  441. void remove_pattern(int p_index);
  442. int get_patterns_count();
  443. // Terrains.
  444. RBSet<TerrainsPattern> get_terrains_pattern_set(int p_terrain_set);
  445. RBSet<TileMapCell> get_tiles_for_terrains_pattern(int p_terrain_set, TerrainsPattern p_terrain_tile_pattern);
  446. TileMapCell get_random_tile_from_terrains_pattern(int p_terrain_set, TerrainsPattern p_terrain_tile_pattern);
  447. // Helpers
  448. Vector<Vector2> get_tile_shape_polygon() const;
  449. void draw_tile_shape(CanvasItem *p_canvas_item, Transform2D p_transform, Color p_color, bool p_filled = false, Ref<Texture2D> p_texture = Ref<Texture2D>()) const;
  450. // Used by TileMap/TileMapLayer
  451. Vector2 map_to_local(const Vector2i &p_pos) const;
  452. Vector2i local_to_map(const Vector2 &p_pos) const;
  453. bool is_existing_neighbor(TileSet::CellNeighbor p_cell_neighbor) const;
  454. Vector2i get_neighbor_cell(const Vector2i &p_coords, TileSet::CellNeighbor p_cell_neighbor) const;
  455. TypedArray<Vector2i> get_surrounding_cells(const Vector2i &p_coords) const;
  456. Vector2i map_pattern(const Vector2i &p_position_in_tilemap, const Vector2i &p_coords_in_pattern, Ref<TileMapPattern> p_pattern) const;
  457. void draw_cells_outline(CanvasItem *p_canvas_item, const RBSet<Vector2i> &p_cells, Color p_color, Transform2D p_transform = Transform2D()) const;
  458. Vector<Point2> get_terrain_polygon(int p_terrain_set);
  459. Vector<Point2> get_terrain_peering_bit_polygon(int p_terrain_set, TileSet::CellNeighbor p_bit);
  460. void draw_terrains(CanvasItem *p_canvas_item, Transform2D p_transform, const TileData *p_tile_data);
  461. Vector<Vector<Ref<Texture2D>>> generate_terrains_icons(Size2i p_size);
  462. // Resource management
  463. virtual void reset_state() override;
  464. // Helpers.
  465. static Vector2i transform_coords_layout(const Vector2i &p_coords, TileSet::TileOffsetAxis p_offset_axis, TileSet::TileLayout p_from_layout, TileSet::TileLayout p_to_layout);
  466. TileSet();
  467. ~TileSet();
  468. };
  469. class TileSetSource : public Resource {
  470. GDCLASS(TileSetSource, Resource);
  471. protected:
  472. const TileSet *tile_set = nullptr;
  473. static void _bind_methods();
  474. public:
  475. static const Vector2i INVALID_ATLAS_COORDS; // Vector2i(-1, -1);
  476. static const int INVALID_TILE_ALTERNATIVE; // -1;
  477. // Not exposed.
  478. virtual void set_tile_set(const TileSet *p_tile_set);
  479. TileSet *get_tile_set() const;
  480. virtual void notify_tile_data_properties_should_change() {}
  481. virtual void add_occlusion_layer(int p_index) {}
  482. virtual void move_occlusion_layer(int p_from_index, int p_to_pos) {}
  483. virtual void remove_occlusion_layer(int p_index) {}
  484. virtual void add_physics_layer(int p_index) {}
  485. virtual void move_physics_layer(int p_from_index, int p_to_pos) {}
  486. virtual void remove_physics_layer(int p_index) {}
  487. virtual void add_terrain_set(int p_index) {}
  488. virtual void move_terrain_set(int p_from_index, int p_to_pos) {}
  489. virtual void remove_terrain_set(int p_index) {}
  490. virtual void add_terrain(int p_terrain_set, int p_index) {}
  491. virtual void move_terrain(int p_terrain_set, int p_from_index, int p_to_pos) {}
  492. virtual void remove_terrain(int p_terrain_set, int p_index) {}
  493. virtual void add_navigation_layer(int p_index) {}
  494. virtual void move_navigation_layer(int p_from_index, int p_to_pos) {}
  495. virtual void remove_navigation_layer(int p_index) {}
  496. virtual void add_custom_data_layer(int p_index) {}
  497. virtual void move_custom_data_layer(int p_from_index, int p_to_pos) {}
  498. virtual void remove_custom_data_layer(int p_index) {}
  499. virtual void reset_state() override;
  500. // Tiles.
  501. virtual int get_tiles_count() const = 0;
  502. virtual Vector2i get_tile_id(int tile_index) const = 0;
  503. virtual bool has_tile(Vector2i p_atlas_coords) const = 0;
  504. // Alternative tiles.
  505. virtual int get_alternative_tiles_count(const Vector2i p_atlas_coords) const = 0;
  506. virtual int get_alternative_tile_id(const Vector2i p_atlas_coords, int p_index) const = 0;
  507. virtual bool has_alternative_tile(const Vector2i p_atlas_coords, int p_alternative_tile) const = 0;
  508. };
  509. class TileSetAtlasSource : public TileSetSource {
  510. GDCLASS(TileSetAtlasSource, TileSetSource);
  511. public:
  512. enum TileAnimationMode {
  513. TILE_ANIMATION_MODE_DEFAULT,
  514. TILE_ANIMATION_MODE_RANDOM_START_TIMES,
  515. TILE_ANIMATION_MODE_MAX,
  516. };
  517. enum TransformBits {
  518. TRANSFORM_FLIP_H = 1 << 12,
  519. TRANSFORM_FLIP_V = 1 << 13,
  520. TRANSFORM_TRANSPOSE = 1 << 14,
  521. };
  522. static const int16_t UNTRANSFORM_MASK = ~(TileSetAtlasSource::TRANSFORM_FLIP_H + TileSetAtlasSource::TRANSFORM_FLIP_V + TileSetAtlasSource::TRANSFORM_TRANSPOSE);
  523. private:
  524. struct TileAlternativesData {
  525. Vector2i size_in_atlas = Vector2i(1, 1);
  526. Vector2i texture_offset;
  527. // Animation
  528. int animation_columns = 0;
  529. Vector2i animation_separation;
  530. real_t animation_speed = 1.0;
  531. TileSetAtlasSource::TileAnimationMode animation_mode = TILE_ANIMATION_MODE_DEFAULT;
  532. LocalVector<real_t> animation_frames_durations;
  533. // Alternatives
  534. HashMap<int, TileData *> alternatives;
  535. Vector<int> alternatives_ids;
  536. int next_alternative_id = 1;
  537. };
  538. bool initializing = true;
  539. Ref<Texture2D> texture;
  540. Vector2i margins;
  541. Vector2i separation;
  542. Size2i texture_region_size = Size2i(16, 16);
  543. HashMap<Vector2i, TileAlternativesData> tiles;
  544. Vector<Vector2i> tiles_ids;
  545. HashMap<Vector2i, Vector2i> _coords_mapping_cache; // Maps any coordinate to the including tile
  546. TileData *_get_atlas_tile_data(Vector2i p_atlas_coords, int p_alternative_tile);
  547. const TileData *_get_atlas_tile_data(Vector2i p_atlas_coords, int p_alternative_tile) const;
  548. void _compute_next_alternative_id(const Vector2i p_atlas_coords);
  549. void _clear_coords_mapping_cache(Vector2i p_atlas_coords);
  550. void _create_coords_mapping_cache(Vector2i p_atlas_coords);
  551. bool use_texture_padding = true;
  552. Ref<CanvasTexture> padded_texture;
  553. bool padded_texture_needs_update = false;
  554. void _queue_update_padded_texture();
  555. Ref<ImageTexture> _create_padded_image_texture(const Ref<Texture2D> &p_source);
  556. void _update_padded_texture();
  557. void _try_emit_changed();
  558. protected:
  559. bool _set(const StringName &p_name, const Variant &p_value);
  560. bool _get(const StringName &p_name, Variant &r_ret) const;
  561. void _get_property_list(List<PropertyInfo> *p_list) const;
  562. void _notification(int p_notification);
  563. static void _bind_methods();
  564. public:
  565. // Not exposed.
  566. virtual void set_tile_set(const TileSet *p_tile_set) override;
  567. const TileSet *get_tile_set() const;
  568. virtual void notify_tile_data_properties_should_change() override;
  569. virtual void add_occlusion_layer(int p_index) override;
  570. virtual void move_occlusion_layer(int p_from_index, int p_to_pos) override;
  571. virtual void remove_occlusion_layer(int p_index) override;
  572. virtual void add_physics_layer(int p_index) override;
  573. virtual void move_physics_layer(int p_from_index, int p_to_pos) override;
  574. virtual void remove_physics_layer(int p_index) override;
  575. virtual void add_terrain_set(int p_index) override;
  576. virtual void move_terrain_set(int p_from_index, int p_to_pos) override;
  577. virtual void remove_terrain_set(int p_index) override;
  578. virtual void add_terrain(int p_terrain_set, int p_index) override;
  579. virtual void move_terrain(int p_terrain_set, int p_from_index, int p_to_pos) override;
  580. virtual void remove_terrain(int p_terrain_set, int p_index) override;
  581. virtual void add_navigation_layer(int p_index) override;
  582. virtual void move_navigation_layer(int p_from_index, int p_to_pos) override;
  583. virtual void remove_navigation_layer(int p_index) override;
  584. virtual void add_custom_data_layer(int p_index) override;
  585. virtual void move_custom_data_layer(int p_from_index, int p_to_pos) override;
  586. virtual void remove_custom_data_layer(int p_index) override;
  587. virtual void reset_state() override;
  588. // Base properties.
  589. void set_texture(Ref<Texture2D> p_texture);
  590. Ref<Texture2D> get_texture() const;
  591. void set_margins(Vector2i p_margins);
  592. Vector2i get_margins() const;
  593. void set_separation(Vector2i p_separation);
  594. Vector2i get_separation() const;
  595. void set_texture_region_size(Vector2i p_tile_size);
  596. Vector2i get_texture_region_size() const;
  597. // Padding.
  598. void set_use_texture_padding(bool p_use_padding);
  599. bool get_use_texture_padding() const;
  600. // Base tiles.
  601. void create_tile(const Vector2i p_atlas_coords, const Vector2i p_size = Vector2i(1, 1));
  602. void remove_tile(Vector2i p_atlas_coords);
  603. virtual bool has_tile(Vector2i p_atlas_coords) const override;
  604. void move_tile_in_atlas(Vector2i p_atlas_coords, Vector2i p_new_atlas_coords = INVALID_ATLAS_COORDS, Vector2i p_new_size = Vector2i(-1, -1));
  605. Vector2i get_tile_size_in_atlas(Vector2i p_atlas_coords) const;
  606. virtual int get_tiles_count() const override;
  607. virtual Vector2i get_tile_id(int p_index) const override;
  608. bool has_room_for_tile(Vector2i p_atlas_coords, Vector2i p_size, int p_animation_columns, Vector2i p_animation_separation, int p_frames_count, Vector2i p_ignored_tile = INVALID_ATLAS_COORDS) const;
  609. PackedVector2Array get_tiles_to_be_removed_on_change(Ref<Texture2D> p_texture, Vector2i p_margins, Vector2i p_separation, Vector2i p_texture_region_size);
  610. Vector2i get_tile_at_coords(Vector2i p_atlas_coords) const;
  611. bool has_tiles_outside_texture() const;
  612. Vector<Vector2i> get_tiles_outside_texture() const;
  613. void clear_tiles_outside_texture();
  614. // Animation.
  615. void set_tile_animation_columns(const Vector2i p_atlas_coords, int p_frame_columns);
  616. int get_tile_animation_columns(const Vector2i p_atlas_coords) const;
  617. void set_tile_animation_separation(const Vector2i p_atlas_coords, const Vector2i p_separation);
  618. Vector2i get_tile_animation_separation(const Vector2i p_atlas_coords) const;
  619. void set_tile_animation_speed(const Vector2i p_atlas_coords, real_t p_speed);
  620. real_t get_tile_animation_speed(const Vector2i p_atlas_coords) const;
  621. void set_tile_animation_mode(const Vector2i p_atlas_coords, const TileSetAtlasSource::TileAnimationMode p_mode);
  622. TileSetAtlasSource::TileAnimationMode get_tile_animation_mode(const Vector2i p_atlas_coords) const;
  623. void set_tile_animation_frames_count(const Vector2i p_atlas_coords, int p_frames_count);
  624. int get_tile_animation_frames_count(const Vector2i p_atlas_coords) const;
  625. void set_tile_animation_frame_duration(const Vector2i p_atlas_coords, int p_frame_index, real_t p_duration);
  626. real_t get_tile_animation_frame_duration(const Vector2i p_atlas_coords, int p_frame_index) const;
  627. real_t get_tile_animation_total_duration(const Vector2i p_atlas_coords) const;
  628. // Alternative tiles.
  629. int create_alternative_tile(const Vector2i p_atlas_coords, int p_alternative_id_override = -1);
  630. void remove_alternative_tile(const Vector2i p_atlas_coords, int p_alternative_tile);
  631. void set_alternative_tile_id(const Vector2i p_atlas_coords, int p_alternative_tile, int p_new_id);
  632. virtual bool has_alternative_tile(const Vector2i p_atlas_coords, int p_alternative_tile) const override;
  633. int get_next_alternative_tile_id(const Vector2i p_atlas_coords) const;
  634. virtual int get_alternative_tiles_count(const Vector2i p_atlas_coords) const override;
  635. virtual int get_alternative_tile_id(const Vector2i p_atlas_coords, int p_index) const override;
  636. // Get data associated to a tile.
  637. TileData *get_tile_data(const Vector2i p_atlas_coords, int p_alternative_tile) const;
  638. // Helpers.
  639. Vector2i get_atlas_grid_size() const;
  640. Rect2i get_tile_texture_region(Vector2i p_atlas_coords, int p_frame = 0) const;
  641. bool is_position_in_tile_texture_region(const Vector2i p_atlas_coords, int p_alternative_tile, Vector2 p_position) const;
  642. bool is_rect_in_tile_texture_region(const Vector2i p_atlas_coords, int p_alternative_tile, Rect2 p_rect) const;
  643. static int alternative_no_transform(int p_alternative_id);
  644. // Getters for texture and tile region (padded or not)
  645. Ref<Texture2D> get_runtime_texture() const;
  646. Rect2i get_runtime_tile_texture_region(Vector2i p_atlas_coords, int p_frame = 0) const;
  647. ~TileSetAtlasSource();
  648. };
  649. class TileSetScenesCollectionSource : public TileSetSource {
  650. GDCLASS(TileSetScenesCollectionSource, TileSetSource);
  651. private:
  652. struct SceneData {
  653. Ref<PackedScene> scene;
  654. bool display_placeholder = false;
  655. };
  656. Vector<int> scenes_ids;
  657. HashMap<int, SceneData> scenes;
  658. int next_scene_id = 1;
  659. bool initializing = true;
  660. void _compute_next_alternative_id();
  661. void _try_emit_changed();
  662. protected:
  663. bool _set(const StringName &p_name, const Variant &p_value);
  664. bool _get(const StringName &p_name, Variant &r_ret) const;
  665. void _get_property_list(List<PropertyInfo> *p_list) const;
  666. void _notification(int p_notification);
  667. static void _bind_methods();
  668. public:
  669. // Tiles.
  670. int get_tiles_count() const override;
  671. Vector2i get_tile_id(int p_tile_index) const override;
  672. bool has_tile(Vector2i p_atlas_coords) const override;
  673. // Alternative tiles.
  674. int get_alternative_tiles_count(const Vector2i p_atlas_coords) const override;
  675. int get_alternative_tile_id(const Vector2i p_atlas_coords, int p_index) const override;
  676. bool has_alternative_tile(const Vector2i p_atlas_coords, int p_alternative_tile) const override;
  677. // Scenes accessors. Lot are similar to "Alternative tiles".
  678. int get_scene_tiles_count() { return get_alternative_tiles_count(Vector2i()); }
  679. int get_scene_tile_id(int p_index) { return get_alternative_tile_id(Vector2i(), p_index); }
  680. bool has_scene_tile_id(int p_id) { return has_alternative_tile(Vector2i(), p_id); }
  681. int create_scene_tile(Ref<PackedScene> p_packed_scene = Ref<PackedScene>(), int p_id_override = -1);
  682. void set_scene_tile_id(int p_id, int p_new_id);
  683. void set_scene_tile_scene(int p_id, Ref<PackedScene> p_packed_scene);
  684. Ref<PackedScene> get_scene_tile_scene(int p_id) const;
  685. void set_scene_tile_display_placeholder(int p_id, bool p_packed_scene);
  686. bool get_scene_tile_display_placeholder(int p_id) const;
  687. void remove_scene_tile(int p_id);
  688. int get_next_scene_tile_id() const;
  689. };
  690. class TileData : public Object {
  691. GDCLASS(TileData, Object);
  692. private:
  693. const TileSet *tile_set = nullptr;
  694. bool allow_transform = true;
  695. // Rendering
  696. bool flip_h = false;
  697. bool flip_v = false;
  698. bool transpose = false;
  699. Vector2i texture_origin;
  700. Ref<Material> material;
  701. Color modulate = Color(1.0, 1.0, 1.0, 1.0);
  702. int z_index = 0;
  703. int y_sort_origin = 0;
  704. struct OcclusionLayerTileData {
  705. struct PolygonOccluderTileData {
  706. Ref<OccluderPolygon2D> occluder_polygon;
  707. mutable HashMap<int, Ref<OccluderPolygon2D>> transformed_polygon_occluders;
  708. };
  709. Vector<PolygonOccluderTileData> polygons;
  710. };
  711. Vector<OcclusionLayerTileData> occluders;
  712. // Physics
  713. struct PhysicsLayerTileData {
  714. struct PolygonShapeTileData {
  715. LocalVector<Vector2> polygon;
  716. LocalVector<Ref<ConvexPolygonShape2D>> shapes;
  717. mutable HashMap<int, LocalVector<Ref<ConvexPolygonShape2D>>> transformed_shapes;
  718. bool one_way = false;
  719. float one_way_margin = 1.0;
  720. };
  721. Vector2 linear_velocity;
  722. double angular_velocity = 0.0;
  723. Vector<PolygonShapeTileData> polygons;
  724. };
  725. Vector<PhysicsLayerTileData> physics;
  726. // TODO add support for areas.
  727. // Terrain
  728. int terrain_set = -1;
  729. int terrain = -1;
  730. int terrain_peering_bits[16] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
  731. // Navigation
  732. struct NavigationLayerTileData {
  733. Ref<NavigationPolygon> navigation_polygon;
  734. mutable HashMap<int, Ref<NavigationPolygon>> transformed_navigation_polygon;
  735. };
  736. Vector<NavigationLayerTileData> navigation;
  737. // Misc
  738. double probability = 1.0;
  739. // Custom data
  740. Vector<Variant> custom_data;
  741. protected:
  742. bool _set(const StringName &p_name, const Variant &p_value);
  743. bool _get(const StringName &p_name, Variant &r_ret) const;
  744. void _get_property_list(List<PropertyInfo> *p_list) const;
  745. static void _bind_methods();
  746. #ifndef DISABLE_DEPRECATED
  747. Ref<NavigationPolygon> _get_navigation_polygon_bind_compat_84660(int p_layer_id) const;
  748. Ref<OccluderPolygon2D> _get_occluder_bind_compat_84660(int p_layer_id) const;
  749. static void _bind_compatibility_methods();
  750. #endif
  751. public:
  752. // Not exposed.
  753. void set_tile_set(const TileSet *p_tile_set);
  754. void notify_tile_data_properties_should_change();
  755. void add_occlusion_layer(int p_index);
  756. void move_occlusion_layer(int p_from_index, int p_to_pos);
  757. void remove_occlusion_layer(int p_index);
  758. void add_physics_layer(int p_index);
  759. void move_physics_layer(int p_from_index, int p_to_pos);
  760. void remove_physics_layer(int p_index);
  761. void add_terrain_set(int p_index);
  762. void move_terrain_set(int p_from_index, int p_to_pos);
  763. void remove_terrain_set(int p_index);
  764. void add_terrain(int p_terrain_set, int p_index);
  765. void move_terrain(int p_terrain_set, int p_from_index, int p_to_pos);
  766. void remove_terrain(int p_terrain_set, int p_index);
  767. void add_navigation_layer(int p_index);
  768. void move_navigation_layer(int p_from_index, int p_to_pos);
  769. void remove_navigation_layer(int p_index);
  770. void add_custom_data_layer(int p_index);
  771. void move_custom_data_layer(int p_from_index, int p_to_pos);
  772. void remove_custom_data_layer(int p_index);
  773. void set_allow_transform(bool p_allow_transform);
  774. bool is_allowing_transform() const;
  775. // To duplicate a TileData object, needed for runtiume update.
  776. TileData *duplicate();
  777. // Rendering
  778. void set_flip_h(bool p_flip_h);
  779. bool get_flip_h() const;
  780. void set_flip_v(bool p_flip_v);
  781. bool get_flip_v() const;
  782. void set_transpose(bool p_transpose);
  783. bool get_transpose() const;
  784. void set_texture_origin(Vector2i p_texture_origin);
  785. Vector2i get_texture_origin() const;
  786. void set_material(Ref<Material> p_material);
  787. Ref<Material> get_material() const;
  788. void set_modulate(Color p_modulate);
  789. Color get_modulate() const;
  790. void set_z_index(int p_z_index);
  791. int get_z_index() const;
  792. void set_y_sort_origin(int p_y_sort_origin);
  793. int get_y_sort_origin() const;
  794. #ifndef DISABLE_DEPRECATED
  795. void set_occluder(int p_layer_id, Ref<OccluderPolygon2D> p_occluder_polygon);
  796. Ref<OccluderPolygon2D> get_occluder(int p_layer_id, bool p_flip_h = false, bool p_flip_v = false, bool p_transpose = false) const;
  797. #endif // DISABLE_DEPRECATED
  798. void set_occluder_polygons_count(int p_layer_id, int p_polygons_count);
  799. int get_occluder_polygons_count(int p_layer_id) const;
  800. void add_occluder_polygon(int p_layer_id);
  801. void remove_occluder_polygon(int p_layer_id, int p_polygon_index);
  802. void set_occluder_polygon(int p_layer_id, int p_polygon_index, const Ref<OccluderPolygon2D> &p_occluder_polygon);
  803. Ref<OccluderPolygon2D> get_occluder_polygon(int p_layer_id, int p_polygon_index, bool p_flip_h = false, bool p_flip_v = false, bool p_transpose = false) const;
  804. // Physics
  805. void set_constant_linear_velocity(int p_layer_id, const Vector2 &p_velocity);
  806. Vector2 get_constant_linear_velocity(int p_layer_id) const;
  807. void set_constant_angular_velocity(int p_layer_id, real_t p_velocity);
  808. real_t get_constant_angular_velocity(int p_layer_id) const;
  809. void set_collision_polygons_count(int p_layer_id, int p_shapes_count);
  810. int get_collision_polygons_count(int p_layer_id) const;
  811. void add_collision_polygon(int p_layer_id);
  812. void remove_collision_polygon(int p_layer_id, int p_polygon_index);
  813. void set_collision_polygon_points(int p_layer_id, int p_polygon_index, Vector<Vector2> p_polygon);
  814. Vector<Vector2> get_collision_polygon_points(int p_layer_id, int p_polygon_index) const;
  815. void set_collision_polygon_one_way(int p_layer_id, int p_polygon_index, bool p_one_way);
  816. bool is_collision_polygon_one_way(int p_layer_id, int p_polygon_index) const;
  817. void set_collision_polygon_one_way_margin(int p_layer_id, int p_polygon_index, float p_one_way_margin);
  818. float get_collision_polygon_one_way_margin(int p_layer_id, int p_polygon_index) const;
  819. int get_collision_polygon_shapes_count(int p_layer_id, int p_polygon_index) const;
  820. Ref<ConvexPolygonShape2D> get_collision_polygon_shape(int p_layer_id, int p_polygon_index, int shape_index, bool p_flip_h = false, bool p_flip_v = false, bool p_transpose = false) const;
  821. // Terrain
  822. void set_terrain_set(int p_terrain_id);
  823. int get_terrain_set() const;
  824. void set_terrain(int p_terrain_id);
  825. int get_terrain() const;
  826. void set_terrain_peering_bit(TileSet::CellNeighbor p_peering_bit, int p_terrain_id);
  827. int get_terrain_peering_bit(TileSet::CellNeighbor p_peering_bit) const;
  828. bool is_valid_terrain_peering_bit(TileSet::CellNeighbor p_peering_bit) const;
  829. TileSet::TerrainsPattern get_terrains_pattern() const; // Not exposed.
  830. // Navigation
  831. void set_navigation_polygon(int p_layer_id, Ref<NavigationPolygon> p_navigation_polygon);
  832. Ref<NavigationPolygon> get_navigation_polygon(int p_layer_id, bool p_flip_h = false, bool p_flip_v = false, bool p_transpose = false) const;
  833. // Misc
  834. void set_probability(float p_probability);
  835. float get_probability() const;
  836. // Custom data.
  837. void set_custom_data(String p_layer_name, Variant p_value);
  838. Variant get_custom_data(String p_layer_name) const;
  839. void set_custom_data_by_layer_id(int p_layer_id, Variant p_value);
  840. Variant get_custom_data_by_layer_id(int p_layer_id) const;
  841. // Polygons.
  842. static PackedVector2Array get_transformed_vertices(const PackedVector2Array &p_vertices, bool p_flip_h, bool p_flip_v, bool p_transpose);
  843. };
  844. VARIANT_ENUM_CAST(TileSet::CellNeighbor);
  845. VARIANT_ENUM_CAST(TileSet::TerrainMode);
  846. VARIANT_ENUM_CAST(TileSet::TileShape);
  847. VARIANT_ENUM_CAST(TileSet::TileLayout);
  848. VARIANT_ENUM_CAST(TileSet::TileOffsetAxis);
  849. VARIANT_ENUM_CAST(TileSetAtlasSource::TileAnimationMode);
  850. #endif // TILE_SET_H