Skip to content

Commit

Permalink
Merge pull request #127 from cullumi/threaded_chunk_loaders
Browse files Browse the repository at this point in the history
Thread-Safety for NoiseGenerator and Tile/Gridmaps
  • Loading branch information
BenjaTK authored Jun 21, 2024
2 parents cd5d25b + 7c0a74f commit d13fa0a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions addons/gaea/generators/2D/noise_generator/noise_generator.gd
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ func generate_chunk(chunk_position: Vector2i, starting_grid: GaeaGrid = null) ->
next_pass.generate_chunk(chunk_position, grid)
return

chunk_updated.emit(chunk_position)
chunk_generation_finished.emit(chunk_position)
(func (): chunk_updated.emit(chunk_position)).call_deferred() # Deferred for thread-safety.
(func (): chunk_generation_finished.emit(chunk_position)).call_deferred() # Deferred for thread-safety.


func _set_grid() -> void:
Expand Down
4 changes: 2 additions & 2 deletions addons/gaea/renderers/2D/tilemap_gaea_renderer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func _draw_area(area: Rect2i) -> void:

if erase_empty_tiles and not has_cell_in_position:
for l in range(tile_map.get_layers_count()):
tile_map.erase_cell.call_deferred(l, Vector2i(x, y))
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()):
Expand All @@ -48,7 +48,7 @@ func _draw_area(area: Rect2i) -> void:

match tile_info.type:
TilemapTileInfo.Type.SINGLE_CELL:
tile_map.set_cell.call_deferred(
tile_map.call_thread_safe("set_cell", # thread_safe paces these calls out when threaded.
tile_info.tilemap_layer, tile, tile_info.source_id,
tile_info.atlas_coord, tile_info.alternative_tile
)
Expand Down
4 changes: 2 additions & 2 deletions addons/gaea/renderers/3D/gridmap_gaea_renderer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func _draw_area(area: AABB) -> void:
for layer in range(generator.grid.get_layer_count()):
var cell := Vector3i(x, y, z)
if not generator.grid.has_cell(cell, layer):
grid_map.set_cell_item.call_deferred(cell, -1)
grid_map.call_thread_safe("set_cell_item", cell, -1) # thread_safe paces these calls out when threaded.
continue

if only_draw_visible_cells and not generator.grid.has_empty_neighbor(cell, layer):
Expand All @@ -32,7 +32,7 @@ func _draw_area(area: AABB) -> void:
if not (tile_info is GridmapTileInfo):
continue

grid_map.set_cell_item.call_deferred(cell, tile_info.index)
grid_map.call_thread_safe("set_cell_item", cell, tile_info.index) # thread_safe paces these calls out when threaded.

(func(): area_rendered.emit()).call_deferred()

Expand Down

0 comments on commit d13fa0a

Please sign in to comment.