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 bug with HeightmapGenerator3D and standardize how air layer works #157

Merged
merged 2 commits into from
Aug 15, 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
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func _set_grid() -> void:
for x in range(settings.world_length):
max_height = maxi(
floor(settings.noise.get_noise_1d(x) * settings.height_intensity + settings.height_offset), max_height
)
) + 1

var area := Rect2i(
# starting point
Expand All @@ -102,10 +102,9 @@ func _set_grid_area(area: Rect2i) -> void:

var height = floor(settings.noise.get_noise_1d(x) * settings.height_intensity + settings.height_offset)
for y in range(area.position.y, area.end.y):
if y > -height and y <= -settings.min_height:
if y >= -height and y <= -settings.min_height:
grid.set_valuexy(x, y, settings.tile)

if y == -height and settings.air_layer:
elif y == -height - 1 and settings.air_layer:
grid.set_valuexy(x, y, null)


2 changes: 1 addition & 1 deletion addons/gaea/generators/3D/grid_3d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func erasexyz(x: int, y: int, z: int, layer: int) -> void:
## Returns [code]true[/code] if the cell at the given position has a non-existing neighbor. Doesn't include diagonals.
func has_empty_neighbor(pos: Vector3i, layer: int) -> bool:
for neighbor in NEIGHBORS:
if not has_cell(pos + neighbor, layer):
if not has_cell(pos + neighbor, layer) or get_value(pos + neighbor, layer) == null:
return true

return false
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func _set_grid() -> void:
max_height = maxi(
floor(settings.noise.get_noise_2d(x, z) * settings.height_intensity + settings.height_offset),
max_height
)
) + 1

var area := AABB(
# starting point
Expand Down Expand Up @@ -114,5 +114,5 @@ func _set_grid_area(area: AABB) -> void:
if y <= height and y >= settings.min_height:
grid.set_valuexyz(x, y, z, settings.tile)

if y == height and settings.air_layer:
elif y == height + 1 and settings.air_layer:
grid.set_valuexyz(x, y, z, null)
6 changes: 0 additions & 6 deletions addons/gaea/modifiers/modifier.gd
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ func apply(grid: GaeaGrid, generator: GaeaGenerator) -> void:
## Returns true if the [param tile_info] can be modified according
## to the filters.
func _passes_filter(grid: GaeaGrid, cell) -> bool:
if filter_type == FilterType.ONLY_EMPTY_TILES:
for layer in grid.get_layer_count():
if grid.get_value(cell, layer) != null:
return false
return true

if filter_type == FilterType.NONE:
return true

Expand Down
2 changes: 1 addition & 1 deletion addons/gaea/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="Gaea"
description="A procedural generation add-on for Godot 4.2.2"
author="BenjaTK"
version="1.1.0"
version="1.1.2"
script="plugin.gd"
4 changes: 3 additions & 1 deletion addons/gaea/renderers/2D/tilemap_gaea_renderer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ extends GaeaRenderer2D
@export var clear_tile_map_on_draw: 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
## Set this to [code]true[/code] if you have gaps between your terrains. Can cause problems.
@export var terrain_gap_fix: bool = false


func _ready() -> void:
Expand Down Expand Up @@ -64,7 +66,7 @@ func _draw_area(area: Rect2i) -> void:
for tile_info in terrains:
tile_map.set_cells_terrain_connect.call_deferred(
tile_info.tilemap_layer, terrains[tile_info],
tile_info.terrain_set, tile_info.terrain
tile_info.terrain_set, tile_info.terrain, !terrain_gap_fix
)

(func(): area_rendered.emit(area)).call_deferred()
Expand Down
2 changes: 1 addition & 1 deletion addons/gaea/renderers/3D/gridmap_gaea_renderer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func _draw_area(area: AABB) -> void:
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):
if generator.grid.has_cell(cell, layer) and generator.grid.get_value(cell, layer) != null:
has_cell = true
break

Expand Down