Skip to content

Commit

Permalink
Refactor initial baking
Browse files Browse the repository at this point in the history
  • Loading branch information
Scony committed Jan 14, 2024
1 parent 166bd2a commit 764aadb
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 21 deletions.
11 changes: 9 additions & 2 deletions source/match/AirNavigation.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@ func _ready():
_reference_mesh.global_transform.origin.y = Constants.Match.Air.Y


func rebake(map):
find_child("ReferenceMesh").mesh = map.find_child("Terrain").mesh
func bake(map):
assert(
_navigation_region.navigation_mesh.get_polygon_count() == 0,
"bake() should be called exactly once - during runtime"
)
var plane_mesh = PlaneMesh.new()
plane_mesh.size = map.size
plane_mesh.center_offset = Vector3(map.size.x, 0, map.size.y) / 2.0
_reference_mesh.mesh = plane_mesh
_navigation_region.bake_navigation_mesh(false)


Expand Down
2 changes: 1 addition & 1 deletion source/match/Match.gd
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func _setup_subsystems_dependent_on_map():
_terrain.update_shape(map.find_child("Terrain").mesh)
fog_of_war.resize(map.size)
_recalculate_camera_bounding_planes(map.size)
navigation.rebake(map)
navigation.setup(map)


func _recalculate_camera_bounding_planes(map_size: Vector2):
Expand Down
7 changes: 1 addition & 6 deletions source/match/Match.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=45 format=3 uid="uid://camns8fqod8d4"]
[gd_scene load_steps=44 format=3 uid="uid://camns8fqod8d4"]

[ext_resource type="Script" path="res://source/match/Match.gd" id="1_1555u"]
[ext_resource type="Script" path="res://source/match/IsometricCamera3D.gd" id="1_qb2ry"]
Expand Down Expand Up @@ -83,10 +83,6 @@ shader_parameter/world_visibility_texture = SubResource("ViewportTexture_7yqgo")
flip_faces = true
size = Vector2(2, 2)

[sub_resource type="PlaneMesh" id="PlaneMesh_g1mtu"]
size = Vector2(50, 50)
center_offset = Vector3(25, 0, 25)

[sub_resource type="NavigationMesh" id="NavigationMesh_8emvl"]
geometry_source_geometry_mode = 2
geometry_source_group_name = &"air_navigation_input"
Expand Down Expand Up @@ -224,7 +220,6 @@ script = ExtResource("16_ravsv")
[node name="ReferenceMesh" type="MeshInstance3D" parent="Navigation/Air" groups=["air_navigation_input"]]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.5, 0)
visible = false
mesh = SubResource("PlaneMesh_g1mtu")

[node name="NavigationRegion3D" type="NavigationRegion3D" parent="Navigation/Air"]
navigation_mesh = SubResource("NavigationMesh_8emvl")
Expand Down
14 changes: 4 additions & 10 deletions source/match/Navigation.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,13 @@ func get_navigation_map_rid_by_domain(domain):
}[domain]


func rebake(map):
air.rebake(map)
terrain.rebake()
_clear_static_obstacles()
func setup(map):
assert(_static_obstacles.is_empty())
air.bake(map)
terrain.bake()
_setup_static_obstacles()


func _clear_static_obstacles():
for static_obstacle in _static_obstacles:
NavigationServer3D.free_rid(static_obstacle)
_static_obstacles = []


func _setup_static_obstacles():
if not _static_obstacles.is_empty():
return
Expand Down
6 changes: 5 additions & 1 deletion source/match/TerrainNavigation.gd
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ func _process(_delta):
_navigation_region.bake_navigation_mesh(true)


func rebake():
func bake():
assert(
_navigation_region.navigation_mesh.get_polygon_count() == 0,
"bake() should be called exactly once - during runtime"
)
_navigation_region.bake_navigation_mesh(false)


Expand Down
1 change: 0 additions & 1 deletion tests/manual/TestNonQuadraticMap.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
script = ExtResource("3_eliam")
color = Color(0.4, 0.694118, 1, 1)
controller = 1
spawn_index = -1
spawn_index_offset = 0

[sub_resource type="Resource" id="Resource_qgn77"]
Expand Down

0 comments on commit 764aadb

Please sign in to comment.