Skip to content

Commit

Permalink
Merge pull request #147 from BenjaTK/fixes
Browse files Browse the repository at this point in the history
Fix GridmapGaeaRenderer not working with layers
  • Loading branch information
BenjaTK authored Jul 26, 2024
2 parents 05db76d + b0c6191 commit 1ab0074
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
22 changes: 12 additions & 10 deletions addons/gaea/renderers/2D/tilemap_gaea_renderer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extends GaeaRenderer2D
tile_map = value
update_configuration_warnings()
@export var clear_tile_map_on_draw: bool = true
## Erases the cell when an empty tile is found. Recommended: true.
## Erases the cell when an empty tile is found in all layers. Recommended: [code]true[/code].
@export var erase_empty_tiles: bool = true


Expand All @@ -30,15 +30,17 @@ func _draw_area(area: Rect2i) -> void:
for x in range(area.position.x, area.end.x + 1):
for y in range(area.position.y, area.end.y + 1):
var tile_position := Vector2i(x, y)
var has_cell_in_position: bool = false
for layer in range(generator.grid.get_layer_count()):
if generator.grid.has_cell(tile_position, layer):
has_cell_in_position = true

if erase_empty_tiles and not has_cell_in_position:
for l in range(tile_map.get_layers_count()):
tile_map.call_thread_safe("erase_cell", l, Vector2i(x, y)) # thread_safe paces these calls out when threaded.
continue
if erase_empty_tiles:
var has_cell_in_position: bool = false
for layer in range(generator.grid.get_layer_count()):
if generator.grid.has_cell(tile_position, layer):
has_cell_in_position = true
break

if not has_cell_in_position:
for l in range(tile_map.get_layers_count()):
tile_map.call_thread_safe("erase_cell", l, Vector2i(x, y)) # thread_safe paces these calls out when threaded.
continue

for layer in range(generator.grid.get_layer_count()):
var tile = tile_position
Expand Down
17 changes: 14 additions & 3 deletions addons/gaea/renderers/3D/gridmap_gaea_renderer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ extends GaeaRenderer3D
@export var grid_map: GridMap
## Draws only cells with an empty neighbor.
@export var only_draw_visible_cells: bool = true
## Erases the cell when an empty tile is found in all layers. Recommended: [code]true[/code].
@export var erase_empty_tiles: bool = true



func _ready() -> void:
Expand All @@ -19,12 +22,20 @@ func _draw_area(area: AABB) -> void:
for x in range(area.position.x, area.end.x + 1):
for y in range(area.position.y, area.end.y + 1):
for z in range(area.position.z, area.end.z + 1):
for layer in range(generator.grid.get_layer_count()):
var cell := Vector3i(x, y, z)
if not generator.grid.has_cell(cell, layer):
var cell := Vector3i(x, y, z)

if erase_empty_tiles:
var has_cell: bool = false
for layer in range(generator.grid.get_layer_count()):
if generator.grid.has_cell(cell, layer):
has_cell = true
break

if not has_cell:
grid_map.call_thread_safe("set_cell_item", cell, -1) # thread_safe paces these calls out when threaded.
continue

for layer in range(generator.grid.get_layer_count()):
if only_draw_visible_cells and not generator.grid.has_empty_neighbor(cell, layer):
continue

Expand Down

0 comments on commit 1ab0074

Please sign in to comment.