Fix delayed FPS collapse from dense imp collision recovery and repeated routing
This commit is contained in:
+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)
|
||||
|
||||
Reference in New Issue
Block a user