Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GridmapGaeaRenderer not working with layers #147

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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