Fix delayed FPS collapse from dense imp collision recovery and repeated routing
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
# Iron maiden physics mesh
|
||||
|
||||
The visible Meshy model is unchanged. These three concave shapes retain the hollow
|
||||
body and the two separate moving doors, with small surface detail removed from
|
||||
physics using a 12 cm world-space vertex grid and duplicate-triangle removal.
|
||||
|
||||
| Part | Render triangles | Collision triangles |
|
||||
| --- | ---: | ---: |
|
||||
| Body | 63,260 | 2,308 |
|
||||
| Left door | 13,921 | 579 |
|
||||
| Right door | 13,895 | 592 |
|
||||
|
||||
Generated from the committed `iron_maiden.glb` with
|
||||
`tools/bake_maiden_collision.gd`. Run from the repository root:
|
||||
|
||||
```powershell
|
||||
& tools/godot/Godot_v4.3-stable_win64_console.exe --path Demon_v0.19 --script "$PWD/tools/bake_maiden_collision.gd"
|
||||
```
|
||||
|
||||
`iron_maiden.gd` attaches these shapes to the corresponding visible mesh nodes.
|
||||
`mesh_walking.gd` uses them in the playable room; door transforms move the shapes
|
||||
with their hinges. Background rooms use separate mesh-derived convex pieces to
|
||||
avoid costly triangle contact recovery for decorative imps.
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -168,11 +168,16 @@ func bake_repeated(root,locations):
|
||||
var n=queue.pop_back()
|
||||
for child in n.get_children():queue.append(child)
|
||||
if n is CollisionShape3D:
|
||||
# Bokeh rooms need solid silhouettes, not triangle-level ornament contact.
|
||||
# Convex pieces avoid expensive capsule recovery when an imp gets stuck.
|
||||
var collision=n.shape
|
||||
var source_mesh=n.get_parent().get_parent()
|
||||
if source_mesh is MeshInstance3D:collision=source_mesh.mesh.create_convex_shape(true,true)
|
||||
for location in locations:
|
||||
if absf(location.y)>.1 or absf(location.z)>20.1 or location.x< -22.1 or location.x>40.1:continue
|
||||
var body=StaticBody3D.new();body.collision_layer=2;body.collision_mask=0;g.add_child(body)
|
||||
var tr=n.global_transform;tr.origin+=location;body.transform=tr
|
||||
var shape=CollisionShape3D.new();shape.shape=n.shape;body.add_child(shape)
|
||||
var shape=CollisionShape3D.new();shape.shape=collision;body.add_child(shape)
|
||||
if not n is MeshInstance3D or not n.visible:continue
|
||||
var mm=MultiMesh.new();mm.transform_format=MultiMesh.TRANSFORM_3D;mm.mesh=n.mesh;mm.instance_count=locations.size()
|
||||
for i in range(locations.size()):
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
extends RefCounted
|
||||
# Meshy shell is split locally at the actual hinge plane, not from the open concept.
|
||||
const MODEL=preload("res://art/equipment/iron_maiden_v01/iron_maiden.glb")
|
||||
const COLLISIONS={
|
||||
"Body":preload("res://art/equipment/iron_maiden_v01/collision/body.tres"),
|
||||
"LeftDoorSurface":preload("res://art/equipment/iron_maiden_v01/collision/left_door_surface.tres"),
|
||||
"RightDoorSurface":preload("res://art/equipment/iron_maiden_v01/collision/right_door_surface.tres")}
|
||||
func build(g,d):
|
||||
var root=d.device
|
||||
var model=MODEL.instantiate();root.add_child(model)
|
||||
@@ -8,6 +12,7 @@ func build(g,d):
|
||||
d.door=model.find_child("LeftDoor",true,false)
|
||||
d.second_door=model.find_child("RightDoor",true,false)
|
||||
assert(d.door!=null and d.second_door!=null,"Iron maiden requires two independent hinge nodes")
|
||||
for name in COLLISIONS:model.find_child(name,true,false).set_meta("walk_collision_shape",COLLISIONS[name])
|
||||
preload("res://maiden_interior.gd").new().build(g,model,d.door,d.second_door)
|
||||
d.door.rotation.y=-1.8;d.second_door.rotation.y=1.8
|
||||
d.flame=g.ball(root,Vector3(0,.20,0),Vector3(1.15,.25,.85),Color("ff8735"))
|
||||
|
||||
@@ -6,6 +6,22 @@ func check(ok,label):
|
||||
func shot(g,name):
|
||||
await RenderingServer.frame_post_draw
|
||||
g.get_viewport().get_texture().get_image().save_png(capture_folder+"/"+name+".png")
|
||||
func collision_check(g,d):
|
||||
var subject=Node3D.new();g.add_child(subject)
|
||||
await g.get_tree().physics_frame;await g.get_tree().physics_frame
|
||||
subject.position=d.device.position+Vector3(0,.35,-3)
|
||||
g.workshop.mesh_walking.move_actor(subject,Vector3(0,0,5),.25,1.18)
|
||||
check(subject.position.z<d.device.position.z-.2,"simplified back shell blocks a swept capsule")
|
||||
subject.position=d.device.position+Vector3(0,.35,2.5)
|
||||
g.workshop.mesh_walking.move_actor(subject,Vector3(0,0,-2.5),.25,1.18)
|
||||
check(absf(subject.position.z-d.device.position.z)<.15,"open doors preserve the hollow entrance above the base")
|
||||
d.door.rotation.y=0;d.second_door.rotation.y=0
|
||||
await g.get_tree().physics_frame;await g.get_tree().physics_frame
|
||||
subject.position=d.device.position+Vector3(0,.35,2.5)
|
||||
g.workshop.mesh_walking.move_actor(subject,Vector3(0,0,-3),.25,1.18)
|
||||
check(subject.position.z>d.device.position.z+.2,"closed moving doors block entry")
|
||||
d.door.rotation.y=-1.8;d.second_door.rotation.y=1.8
|
||||
await g.get_tree().physics_frame;subject.queue_free()
|
||||
func run(g):
|
||||
await g.get_tree().create_timer(.3).timeout
|
||||
g.start_game();g.set_process(false);g.reset_shift();g.game_started=true;g.paused=false
|
||||
@@ -38,6 +54,7 @@ func run(g):
|
||||
check(outer.get_shader_parameter(map_name)==inner.get_shader_parameter(map_name),"inner and outer share original PBR "+map_name)
|
||||
g.camera.position=Vector3(5.8,3.5,3);g.camera.look_at(d.device.position+Vector3(0,1.5,0));g.camera.size=4.5
|
||||
await shot(g,"open")
|
||||
await collision_check(g,d)
|
||||
for k in range(19):
|
||||
d.door.rotation.y=-1.8+float(k)*.1;d.second_door.rotation.y=1.8-float(k)*.1
|
||||
check(d.door.transform.is_finite() and d.second_door.transform.is_finite(),"finite hinge sweep")
|
||||
|
||||
+23
-5
@@ -75,21 +75,30 @@ func burn(s):
|
||||
func update(dt):
|
||||
var profiling=g.get_meta("profile_life",false)
|
||||
var activity_us=0;var movement_us=0;var gait_us=0
|
||||
var worst={"total_us":0} if profiling else null
|
||||
activities.update_marks(dt)
|
||||
for imp in imps+neighbours:
|
||||
if profiling:imp["path_us"]=0;imp["collision_us"]=0
|
||||
var tick=Time.get_ticks_usec() if profiling else 0
|
||||
var busy=activities.update(imp,dt)
|
||||
if profiling:activity_us+=Time.get_ticks_usec()-tick;tick=Time.get_ticks_usec()
|
||||
var activity_cost=Time.get_ticks_usec()-tick if profiling else 0
|
||||
if profiling:activity_us+=activity_cost;tick=Time.get_ticks_usec()
|
||||
if not busy:
|
||||
imp.patrol_age+=dt
|
||||
if imp.root.position.distance_to(imp.patrol_target)<.25 or imp.patrol_age>9:
|
||||
imp.patrol_angle+=1.05;imp.patrol_age=0;imp.patrol_target=patrol_point(imp)
|
||||
if imp.has("origin"):move_neighbour(imp,imp.patrol_target,dt)
|
||||
else:move_imp(imp,imp.patrol_target,dt)
|
||||
if profiling:movement_us+=Time.get_ticks_usec()-tick;tick=Time.get_ticks_usec()
|
||||
var movement_cost=Time.get_ticks_usec()-tick if profiling else 0
|
||||
if profiling:
|
||||
movement_us+=movement_cost;tick=Time.get_ticks_usec()
|
||||
if activity_cost+movement_cost>worst.total_us:
|
||||
worst={"total_us":activity_cost+movement_cost,"number":imp.activity_number,"activity":imp.activity,
|
||||
"path_us":imp.path_us,"collision_us":imp.collision_us,"position":str(imp.root.position),
|
||||
"target":str(imp.get("activity_target",imp.patrol_target))}
|
||||
imp.gait.update(dt,busy and imp.activity_time>0)
|
||||
if profiling:gait_us+=Time.get_ticks_usec()-tick
|
||||
if profiling:g.set_meta("life_profile",Vector3(activity_us,movement_us,gait_us))
|
||||
if profiling:g.set_meta("life_profile",Vector3(activity_us,movement_us,gait_us));g.set_meta("life_worst",worst)
|
||||
for i in range(burns.size()-1,-1,-1):
|
||||
var b=burns[i];b.t+=dt
|
||||
for mat in b.materials:mat.set_shader_parameter("progress",b.t/1.7)
|
||||
@@ -109,7 +118,11 @@ func update(dt):
|
||||
|
||||
func move_imp(imp,target,dt):
|
||||
var w=g.workshop
|
||||
var destination=w.cell(w.free_floor(target))
|
||||
var profile_tick=Time.get_ticks_usec() if g.get_meta("profile_life",false) else 0
|
||||
if imp.get("requested_target")!=target or imp.revision!=w.revision:
|
||||
imp["requested_target"]=target
|
||||
imp["resolved_target"]=w.free_floor(target,.36)
|
||||
var destination=w.cell(imp.resolved_target)
|
||||
if imp.destination!=destination or imp.revision!=w.revision:
|
||||
imp.destination=destination;imp.revision=w.revision
|
||||
var start=w.cell(imp.root.position)
|
||||
@@ -117,7 +130,8 @@ func move_imp(imp,target,dt):
|
||||
imp.root.position=w.free_floor(imp.root.position);start=w.cell(imp.root.position);imp.velocity=Vector3.ZERO;imp.gait.reset()
|
||||
imp.path=w.nav.get_point_path(start,destination)
|
||||
if not imp.path.is_empty():imp.path.remove_at(0)
|
||||
var next=target
|
||||
if profile_tick>0:imp.path_us+=Time.get_ticks_usec()-profile_tick
|
||||
var next=imp.resolved_target
|
||||
if not imp.path.is_empty():next=Vector3(imp.path[0].x,0,imp.path[0].y)
|
||||
var step_dt=minf(dt,.05)
|
||||
var desired_velocity=(next-imp.root.position).normalized()*1.25
|
||||
@@ -134,7 +148,9 @@ func move_imp(imp,target,dt):
|
||||
desired_velocity+=(delta.normalized() if delta.length_squared()>.0001 else Vector3.RIGHT)*1.4*(1-delta.length()/.72)
|
||||
imp.velocity=imp.get("velocity",Vector3.ZERO).move_toward(desired_velocity.limit_length(1.35),step_dt*5)
|
||||
var before=imp.root.position;var desired=before+imp.velocity*step_dt
|
||||
if profile_tick>0:profile_tick=Time.get_ticks_usec()
|
||||
w.mesh_walking.move_actor(imp.root,desired-imp.root.position,.34,1.18)
|
||||
if profile_tick>0:imp.collision_us+=Time.get_ticks_usec()-profile_tick
|
||||
imp.root.position.x=clampf(imp.root.position.x,-7.1,w.walk_right());imp.root.position.z=clampf(imp.root.position.z,-4.8,5.6)
|
||||
face_motion(imp,imp.root.position-before,step_dt)
|
||||
if imp.root.position.distance_to(next)<.12 and not imp.path.is_empty():imp.path.remove_at(0)
|
||||
@@ -154,7 +170,9 @@ func move_neighbour(imp,target,dt):
|
||||
var desired=(target-imp.root.position).normalized()*1.15;desired.y=0
|
||||
imp.velocity=imp.velocity.move_toward(desired,dt*4)
|
||||
var before=imp.root.position
|
||||
var profile_tick=Time.get_ticks_usec() if g.get_meta("profile_life",false) else 0
|
||||
g.workshop.mesh_walking.move_actor(imp.root,imp.velocity*dt,.34,1.18)
|
||||
if profile_tick>0:imp.collision_us+=Time.get_ticks_usec()-profile_tick
|
||||
imp.root.position.x=clampf(imp.root.position.x,imp.origin.x-7.1,imp.origin.x+7.1)
|
||||
imp.root.position.z=clampf(imp.root.position.z,imp.origin.z-5.5,imp.origin.z+5.5)
|
||||
face_motion(imp,imp.root.position-before,dt)
|
||||
|
||||
+8
-2
@@ -88,7 +88,7 @@ func _ready():
|
||||
var args=OS.get_cmdline_user_args()
|
||||
test_mode="--test-iron-maiden" in args or "--test-intro" in args or "--test-room-decor" in args or "--test-camera-controls" in args or "--test-rubies" in args or "--test-runtime-burn" in args or "--test-single-punishment" in args or "--test-expansion" in args or "--test-imps" in args or "--test-flight-camera" in args or "--test-maintenance" in args or "--test-castle" in args or "--test-building" in args or "--test-workflow" in args or "--test-roster" in args or "--test-priority" in args or "--test-mesh" in args or "--test-economy" in args or "--test-posture" in args or "--test-gait" in args or "--test-visuals" in args or "--test-mode" in args or "--test-exit" in args or "--test-ui" in args or "--test-audio" in args or "--test-sentences" in args or "--test-hud" in args
|
||||
capture_mode="--capture-workflow" in args or "--capture-roster" in args or "--capture-economy" in args or "--capture-posture" in args or "--capture-gait" in args or "--capture" in args or "--capture-workshop" in args
|
||||
test_mode=test_mode or "--test-maiden-performance" in args
|
||||
test_mode=test_mode or "--test-maiden-performance" in args or "--test-performance-soak" in args
|
||||
if FileAccess.file_exists("res://build_info.json"):
|
||||
var stamp=JSON.parse_string(FileAccess.get_file_as_string("res://build_info.json"))
|
||||
if stamp is Dictionary: build_id=str(stamp.get("id",build_id))
|
||||
@@ -145,7 +145,8 @@ func _ready():
|
||||
say("Первый день. Последняя надежда на отпуск.")
|
||||
refresh_ui()
|
||||
if automatic: build_auto_arm()
|
||||
if "--test-maiden-performance" in args:call_deferred("run_maiden_performance_tests")
|
||||
if "--test-performance-soak" in args:call_deferred("run_performance_soak_tests")
|
||||
elif "--test-maiden-performance" in args:call_deferred("run_maiden_performance_tests")
|
||||
elif "--test-iron-maiden" in args:call_deferred("run_iron_maiden_tests")
|
||||
elif "--test-intro" in args:call_deferred("run_intro_tests")
|
||||
elif "--test-exit" in args: call_deferred("test_exit")
|
||||
@@ -577,7 +578,9 @@ func _process(delta):
|
||||
time+=dt
|
||||
for gear in moving_gears: gear.rotation.z+=dt*0.65
|
||||
if workshop:
|
||||
var profile_tick=Time.get_ticks_usec() if get_meta("profile_life",false) else 0
|
||||
workshop.update(dt)
|
||||
if profile_tick>0:set_meta("workshop_cpu_us",Time.get_ticks_usec()-profile_tick)
|
||||
return
|
||||
if paused or not game_started: return
|
||||
advance_spawns(dt)
|
||||
@@ -1022,3 +1025,6 @@ func run_iron_maiden_tests():
|
||||
|
||||
func run_maiden_performance_tests():
|
||||
await preload("res://maiden_performance_tests.gd").new().run(self)
|
||||
|
||||
func run_performance_soak_tests():
|
||||
await preload("res://performance_soak_tests.gd").new().run(self)
|
||||
|
||||
@@ -23,7 +23,9 @@ func build(root):
|
||||
if bounds.size.length()<.24:continue
|
||||
var body=StaticBody3D.new();body.name="MeshWalkingCollider";body.collision_layer=2;body.collision_mask=0
|
||||
mesh.add_child(body)
|
||||
var collider=CollisionShape3D.new();collider.shape=mesh.mesh.create_trimesh_shape();body.add_child(collider)
|
||||
var collider=CollisionShape3D.new()
|
||||
collider.shape=mesh.get_meta("walk_collision_shape") if mesh.has_meta("walk_collision_shape") else mesh.mesh.create_trimesh_shape()
|
||||
body.add_child(collider)
|
||||
collider.shape.backface_collision=true
|
||||
func rebuild(stations):
|
||||
outlines.clear()
|
||||
@@ -44,7 +46,12 @@ func blocked(point,radius=.32):
|
||||
if point.distance_to(Geometry2D.get_closest_point_to_segment(point,polygon[i],polygon[i+1]))<radius:return true
|
||||
return false
|
||||
func move_actor(node,motion,radius=.30,height=1.65):
|
||||
shape.radius=radius;shape.height=maxf(height,2*radius);shape_node.position.y=(.195 if height>1.4 else .10)+height/2
|
||||
if motion.length_squared()<.0000001:return
|
||||
if not is_equal_approx(shape.radius,radius):shape.radius=radius
|
||||
var capsule_height=maxf(height,2*radius)
|
||||
if not is_equal_approx(shape.height,capsule_height):shape.height=capsule_height
|
||||
var offset=(.195 if height>1.4 else .10)+height/2
|
||||
if not is_equal_approx(shape_node.position.y,offset):shape_node.position.y=offset
|
||||
probe.position=node.position;probe.force_update_transform()
|
||||
var remaining=motion
|
||||
for i in range(4):
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
extends RefCounted
|
||||
var failures=0
|
||||
func check(ok,label):
|
||||
if not ok:failures+=1;push_error("PERFORMANCE SOAK: "+label)
|
||||
func contact_probe(g):
|
||||
g.set_process(false)
|
||||
await g.get_tree().physics_frame;await g.get_tree().physics_frame
|
||||
var subject=Node3D.new();g.add_child(subject)
|
||||
for point in [Vector3(41.30359,0,-20.25188),Vector3(5.30359,0,-2.25188)]:
|
||||
var samples=[]
|
||||
for i in range(40):
|
||||
subject.position=point
|
||||
var start=Time.get_ticks_usec()
|
||||
g.workshop.mesh_walking.move_actor(subject,Vector3(-.03,0,.02),.34,1.18)
|
||||
samples.append(float(Time.get_ticks_usec()-start)/1000.0)
|
||||
samples.sort()
|
||||
print("SOAK_CONTACT ",point," median_ms=",samples[20]," p95_ms=",samples[38])
|
||||
check(samples[38]<8.0,"known dense-maiden collision hotspot stays below 8 ms")
|
||||
subject.queue_free();g.set_process(true)
|
||||
func run(g):
|
||||
await g.get_tree().create_timer(.3).timeout
|
||||
g.start_game();g.reset_shift();g.game_started=true;g.paused=false;g.menu.show_page("")
|
||||
DisplayServer.window_set_vsync_mode(DisplayServer.VSYNC_DISABLED);Engine.max_fps=0
|
||||
var w=g.workshop;w.unlock=5;g.coins=50000;g.essence=5000
|
||||
w.add_station(0,Vector3(0,0,-2));w.add_station(3,Vector3(4,0,-2));w.rebuild_nav()
|
||||
var mode="queue"
|
||||
for arg in OS.get_cmdline_user_args():
|
||||
if arg.begins_with("--soak-mode="):mode=arg.get_slice("=",1)
|
||||
if mode=="auto":
|
||||
w.add_station(1,Vector3(8,0,-2));w.add_station(2,Vector3(0,0,3))
|
||||
w.add_station(4,Vector3(4,0,3));w.add_station(5,Vector3(8,0,3));w.rebuild_nav()
|
||||
for i in range(3):w.add_helper()
|
||||
w.automation=true;g.development.xp=370
|
||||
g.player.position=Vector3(-3,0,2.5);g.avatar.reset_gait();g.camera.size=20
|
||||
await contact_probe(g)
|
||||
g.set_meta("profile_life",true)
|
||||
var start=Time.get_ticks_msec();var last=start;var times=[];var records=[]
|
||||
var life=Vector3.ZERO;var soul_us=0.0;var workshop_us=0.0
|
||||
var worst={"total_us":0}
|
||||
while Time.get_ticks_msec()-start<65000:
|
||||
g.set_meta("soul_cpu_us",0)
|
||||
var tick=Time.get_ticks_usec()
|
||||
await g.get_tree().process_frame;await RenderingServer.frame_post_draw
|
||||
times.append(float(Time.get_ticks_usec()-tick)/1000)
|
||||
life+=g.get_meta("life_profile",Vector3.ZERO)
|
||||
var imp=g.get_meta("life_worst",{})
|
||||
if imp.get("total_us",0)>worst.total_us:worst=imp
|
||||
soul_us+=g.get_meta("soul_cpu_us",0);workshop_us+=g.get_meta("workshop_cpu_us",0)
|
||||
if Time.get_ticks_msec()-last>=5000:
|
||||
var count=times.size();times.sort()
|
||||
var record={"seconds":(Time.get_ticks_msec()-start)/1000.0,"sim_time":g.time,"mode":mode,
|
||||
"median_ms":times[count/2],"p95_ms":times[int(count*.95)],"max_ms":times.back(),
|
||||
"soul_ms":soul_us/count/1000,"workshop_ms":workshop_us/count/1000,
|
||||
"imp_activity_ms":life.x/count/1000,"imp_movement_ms":life.y/count/1000,"imp_gait_ms":life.z/count/1000,
|
||||
"souls":g.souls.size(),"departures":w.losses.departures.size(),"burns":g.life.burns.size(),"done":g.done,
|
||||
"nodes":Performance.get_monitor(Performance.OBJECT_NODE_COUNT),"objects":Performance.get_monitor(Performance.OBJECT_COUNT),
|
||||
"video_mb":Performance.get_monitor(Performance.RENDER_VIDEO_MEM_USED)/1048576.0,
|
||||
"draws":Performance.get_monitor(Performance.RENDER_TOTAL_DRAW_CALLS_IN_FRAME),"worst_imp":worst}
|
||||
records.append(record);print("SOAK_PROFILE ",JSON.stringify(record))
|
||||
last=Time.get_ticks_msec();times.clear();life=Vector3.ZERO;soul_us=0.0;workshop_us=0.0
|
||||
worst={"total_us":0}
|
||||
check(w.queue_load()<=7 and w.losses.departures.size()<=2,"queue/departures remain bounded")
|
||||
for record in records:
|
||||
if record.seconds>=30:check(record.median_ms<records[0].median_ms*2.5+8,"no sustained late frame-time collapse")
|
||||
var capture_root="res://captures/performance-soak" if OS.has_feature("editor") else OS.get_executable_path().get_base_dir()+"/captures/performance-soak"
|
||||
DirAccess.make_dir_recursive_absolute(capture_root)
|
||||
var file=FileAccess.open(capture_root+"/"+mode+".json",FileAccess.WRITE)
|
||||
file.store_string(JSON.stringify(records,"\t"));file.close()
|
||||
print("PERFORMANCE SOAK ","PASSED" if failures==0 else "FAILED",": 65s of normal spawns, queue losses and real game frames; timings recorded")
|
||||
g.get_tree().quit(1 if failures else 0)
|
||||
@@ -145,6 +145,7 @@ func update_torture(dt,active):
|
||||
if cry.playing and cry.get_playback_position()>.48:cry.stop()
|
||||
|
||||
func _process(_delta):
|
||||
var profile_tick=Time.get_ticks_usec() if game and game.get_meta("profile_life",false) else 0
|
||||
if game:
|
||||
animator.speed_scale=0.0 if game.paused else 1.0
|
||||
if cry:
|
||||
@@ -162,6 +163,7 @@ func _process(_delta):
|
||||
turn("neck",Vector3.RIGHT,.06);turn("head",Vector3.RIGHT,-.08)
|
||||
relax_flight_arms()
|
||||
cloth.update(self,minf(_delta,.05))
|
||||
if profile_tick>0:game.set_meta("soul_cpu_us",game.get_meta("soul_cpu_us",0)+Time.get_ticks_usec()-profile_tick)
|
||||
|
||||
func restore_flight_pose():
|
||||
for i in range(flight_pose.size()):skeleton.set_bone_pose(i,flight_pose[i])
|
||||
|
||||
+11
-11
@@ -68,6 +68,7 @@ var buy_buttons=[]
|
||||
var bars=[]
|
||||
var notice_time=0.0
|
||||
var nav=AStarGrid2D.new()
|
||||
var free_floor_points=PackedVector3Array()
|
||||
var revision=0
|
||||
var mesh_walking=preload("res://mesh_walking.gd").new()
|
||||
|
||||
@@ -500,6 +501,7 @@ func cell(p):
|
||||
|
||||
func rebuild_nav():
|
||||
mesh_walking.rebuild(stations)
|
||||
free_floor_points.clear()
|
||||
nav.region=Rect2i(0,0,38+ceili(g.architecture.growth.extra_width(expansion_level)*2),22);nav.cell_size=Vector2(.5,.5);nav.offset=Vector2(-7.5,-5)
|
||||
nav.diagonal_mode=AStarGrid2D.DIAGONAL_MODE_ONLY_IF_NO_OBSTACLES;nav.update()
|
||||
for x in range(nav.region.size.x):
|
||||
@@ -507,6 +509,8 @@ func rebuild_nav():
|
||||
var p=Vector2(-7.5+x*.5,-5+z*.5)
|
||||
var blocked=mesh_walking.blocked(p) or p.x>walk_right()
|
||||
nav.set_point_solid(Vector2i(x,z),blocked)
|
||||
if not blocked and p.x>=-7.1 and p.x<=walk_right() and p.y>=-4.8 and p.y<=5.6:
|
||||
free_floor_points.append(Vector3(p.x,0,p.y))
|
||||
revision+=1
|
||||
|
||||
func accessible():
|
||||
@@ -1086,15 +1090,11 @@ func station_at_screen(point):
|
||||
if station_rect(stations[i]).has_point(Vector2(p.x,p.z)):return i
|
||||
return -1
|
||||
|
||||
func free_floor(position):
|
||||
func free_floor(position,radius=.24):
|
||||
var point=Vector2(position.x,position.z)
|
||||
if not mesh_walking.blocked(point,.24):return position
|
||||
var nearest=Vector3(-5.3,0,0);var best=INF
|
||||
for x in range(nav.region.size.x):
|
||||
for z in range(nav.region.size.y):
|
||||
if nav.is_point_solid(Vector2i(x,z)):continue
|
||||
var p=Vector3(-7.5+x*.5,0,-5+z*.5)
|
||||
if p.x< -7.1 or p.x>walk_right() or p.z< -4.8 or p.z>5.6:continue
|
||||
var distance=p.distance_squared_to(position)
|
||||
if distance<best:best=distance;nearest=p
|
||||
return nearest
|
||||
if not mesh_walking.blocked(point,radius):return position
|
||||
var candidates=Array(free_floor_points)
|
||||
candidates.sort_custom(func(a,b):return a.distance_squared_to(position)<b.distance_squared_to(position))
|
||||
for p in candidates:
|
||||
if not mesh_walking.blocked(Vector2(p.x,p.z),radius):return p
|
||||
return Vector3(-5.3,0,0)
|
||||
|
||||
Reference in New Issue
Block a user