mirror of
https://github.com/lobomfz/VIctory-xmem.git
synced 2026-12-06 05:48:38 +00:00
fix(loader): step down hold_z while waiting for ground collision
This commit is contained in:
@ -120,8 +120,22 @@ const SETTLE: Duration = Duration::from_secs(15);
|
||||
/// the experimental route, so normal traffic does not stop a run.
|
||||
const REACHED_M: f32 = 40.0;
|
||||
const LEG_LIMIT: Duration = Duration::from_secs(600);
|
||||
/// The longest the drive's start waits for the ground to stream in.
|
||||
/// The longest a route's start waits for the ground to stream in.
|
||||
const GROUND_WAIT: Duration = Duration::from_secs(60);
|
||||
/// Interval before stepping `hold_z` lower when cold collision has not loaded.
|
||||
const HOLD_STEP_INTERVAL: Duration = Duration::from_secs(5);
|
||||
|
||||
/// Steps the player's holding height closer to sea level when cold collision
|
||||
/// has not streamed in yet (`300 -> 150 -> 80 -> 45` m).
|
||||
fn next_hold_z(hold_z: f32) -> f32 {
|
||||
if hold_z > 160.0 {
|
||||
150.0
|
||||
} else if hold_z > 90.0 {
|
||||
80.0
|
||||
} else {
|
||||
45.0
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a drive leg has run past its limit without reaching its goal.
|
||||
fn leg_stalled(taken: Duration, dist: f32) -> bool {
|
||||
@ -757,13 +771,15 @@ enum Phase {
|
||||
Settle(Instant),
|
||||
/// The route's first steps.
|
||||
Setup,
|
||||
/// downtown: the player held at the corner until the ground loads.
|
||||
FlyGround(Instant),
|
||||
/// downtown: the player held at the corner until the ground loads
|
||||
/// (`(since, last_step, hold_z)`).
|
||||
FlyGround(Instant, Instant, f32),
|
||||
/// downtown: the Blista being made at the corner.
|
||||
FlySpawn(Spawning),
|
||||
Fly(Flight),
|
||||
/// drive: the player held high over the start until the ground loads.
|
||||
DriveGround(Instant),
|
||||
/// drive: the player held high over the start until the ground loads
|
||||
/// (`(since, last_step, hold_z)`).
|
||||
DriveGround(Instant, Instant, f32),
|
||||
/// drive: the Blista being made at the start (at the ground height given).
|
||||
DriveSpawn(Spawning, f32),
|
||||
Drive(Drive),
|
||||
@ -891,12 +907,17 @@ impl Driver {
|
||||
Phase::Settle(since) if since.elapsed() < SETTLE => Phase::Settle(since),
|
||||
Phase::Settle(_) => Phase::Setup,
|
||||
Phase::Setup => self.setup()?,
|
||||
Phase::FlyGround(since) => {
|
||||
Phase::FlyGround(since, mut stepped, mut hold_z) => {
|
||||
let (x, y) = bench::DOWNTOWN_CORNER;
|
||||
let v = vector(x, y, HOLD_Z - 200.0);
|
||||
let probe_z = (hold_z - 100.0).max(bench::DOWNTOWN_GROUND);
|
||||
let v = vector(x, y, probe_z);
|
||||
call(REQUEST_COLLISION_AT_COORD, &[v[0], v[1]])?;
|
||||
match ground_z(x, y)? {
|
||||
Some(z) => {
|
||||
tracing::info!(
|
||||
"bench route: downtown: ground loaded at ({x:.0}, {y:.0}, z={z:.1}) from hold_z={hold_z:.0} after {:.1} s",
|
||||
since.elapsed().as_secs_f32()
|
||||
);
|
||||
// The player beside the corner, the car on it.
|
||||
let me = player()?;
|
||||
teleport(me, x + 3.0, y, z + 1.0)?;
|
||||
@ -904,12 +925,30 @@ impl Driver {
|
||||
Phase::FlySpawn(spawn_blista(x, y, z + 0.5, 0.0)?)
|
||||
}
|
||||
None if since.elapsed() > GROUND_WAIT => {
|
||||
let pos = coords(player()?).ok();
|
||||
return Err(RouteError::Failed(format!(
|
||||
"the ground at the corner did not load in {} s",
|
||||
"the ground at the corner did not load in {} s (hold_z={hold_z:.0}, player={pos:?})",
|
||||
GROUND_WAIT.as_secs()
|
||||
)));
|
||||
}
|
||||
None => Phase::FlyGround(since),
|
||||
None => {
|
||||
if stepped.elapsed() >= HOLD_STEP_INTERVAL {
|
||||
let me = player()?;
|
||||
let pos = coords(me).ok();
|
||||
let next_z = next_hold_z(hold_z);
|
||||
tracing::info!(
|
||||
"bench route: downtown: ground not yet loaded after {:.0} s (player={pos:?}); lowering hold_z {hold_z:.0} -> {next_z:.0}",
|
||||
since.elapsed().as_secs_f32()
|
||||
);
|
||||
if (next_z - hold_z).abs() > 1.0 {
|
||||
hold_z = next_z;
|
||||
freeze(me, true)?;
|
||||
teleport(me, x, y, hold_z)?;
|
||||
}
|
||||
stepped = Instant::now();
|
||||
}
|
||||
Phase::FlyGround(since, stepped, hold_z)
|
||||
}
|
||||
}
|
||||
}
|
||||
Phase::FlySpawn(mut spawning) => {
|
||||
@ -928,12 +967,17 @@ impl Driver {
|
||||
flight.step()?;
|
||||
Phase::Fly(flight)
|
||||
}
|
||||
Phase::DriveGround(since) => {
|
||||
Phase::DriveGround(since, mut stepped, mut hold_z) => {
|
||||
let (x, y) = bench::DRIVE_WAYPOINTS[0];
|
||||
let v = vector(x, y, HOLD_Z - 200.0);
|
||||
let probe_z = (hold_z - 100.0).max(bench::DOWNTOWN_GROUND);
|
||||
let v = vector(x, y, probe_z);
|
||||
call(REQUEST_COLLISION_AT_COORD, &[v[0], v[1]])?;
|
||||
match ground_z(x, y)? {
|
||||
Some(z) => {
|
||||
tracing::info!(
|
||||
"bench route: drive: ground loaded at ({x:.0}, {y:.0}, z={z:.1}) from hold_z={hold_z:.0} after {:.1} s",
|
||||
since.elapsed().as_secs_f32()
|
||||
);
|
||||
// The player beside the start, the car on it.
|
||||
let me = player()?;
|
||||
teleport(me, x + 3.0, y, z + 1.0)?;
|
||||
@ -943,12 +987,30 @@ impl Driver {
|
||||
Phase::DriveSpawn(spawn_blista(x, y, z + 0.5, heading)?, z)
|
||||
}
|
||||
None if since.elapsed() > GROUND_WAIT => {
|
||||
let pos = coords(player()?).ok();
|
||||
return Err(RouteError::Failed(format!(
|
||||
"the ground at the start did not load in {} s",
|
||||
"the ground at the start did not load in {} s (hold_z={hold_z:.0}, player={pos:?})",
|
||||
GROUND_WAIT.as_secs()
|
||||
)));
|
||||
}
|
||||
None => Phase::DriveGround(since),
|
||||
None => {
|
||||
if stepped.elapsed() >= HOLD_STEP_INTERVAL {
|
||||
let me = player()?;
|
||||
let pos = coords(me).ok();
|
||||
let next_z = next_hold_z(hold_z);
|
||||
tracing::info!(
|
||||
"bench route: drive: ground not yet loaded after {:.0} s (player={pos:?}); lowering hold_z {hold_z:.0} -> {next_z:.0}",
|
||||
since.elapsed().as_secs_f32()
|
||||
);
|
||||
if (next_z - hold_z).abs() > 1.0 {
|
||||
hold_z = next_z;
|
||||
freeze(me, true)?;
|
||||
teleport(me, x, y, hold_z)?;
|
||||
}
|
||||
stepped = Instant::now();
|
||||
}
|
||||
Phase::DriveGround(since, stepped, hold_z)
|
||||
}
|
||||
}
|
||||
}
|
||||
Phase::DriveSpawn(mut spawning, ground) => match spawning.poll()? {
|
||||
@ -1006,26 +1068,32 @@ impl Driver {
|
||||
Ok(match self.route {
|
||||
Route::Downtown => {
|
||||
let (x, y) = bench::DOWNTOWN_CORNER;
|
||||
let before = coords(me).ok();
|
||||
// Held at the corner while the area streams in; the collision
|
||||
// is asked for each frame until the ground is found.
|
||||
freeze(me, true)?;
|
||||
teleport(me, x, y, HOLD_Z)?;
|
||||
let after = coords(me).ok();
|
||||
tracing::info!(
|
||||
"bench route: downtown: waiting for the ground at ({x:.0}, {y:.0}) to load"
|
||||
"bench route: downtown: waiting for the ground at ({x:.0}, {y:.0}) to load (before={before:?}, after={after:?})"
|
||||
);
|
||||
Phase::FlyGround(Instant::now())
|
||||
let now = Instant::now();
|
||||
Phase::FlyGround(now, now, HOLD_Z)
|
||||
}
|
||||
Route::Drive => {
|
||||
let (x, y) = bench::DRIVE_WAYPOINTS[0];
|
||||
let before = coords(me).ok();
|
||||
// Held over the start while the area streams in (from 800 m
|
||||
// up its collision never loaded); the collision is asked for
|
||||
// each frame until the ground is found.
|
||||
freeze(me, true)?;
|
||||
teleport(me, x, y, HOLD_Z)?;
|
||||
let after = coords(me).ok();
|
||||
tracing::info!(
|
||||
"bench route: drive: waiting for the ground at ({x:.0}, {y:.0}) to load"
|
||||
"bench route: drive: waiting for the ground at ({x:.0}, {y:.0}) to load (before={before:?}, after={after:?})"
|
||||
);
|
||||
Phase::DriveGround(Instant::now())
|
||||
let now = Instant::now();
|
||||
Phase::DriveGround(now, now, HOLD_Z)
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -1535,4 +1603,12 @@ mod tests {
|
||||
assert!(leg_stalled(Duration::from_secs(601), 100.0));
|
||||
assert!(!leg_stalled(Duration::from_secs(601), REACHED_M - 1.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hold_z_steps_down_monotonically_to_floor() {
|
||||
assert_eq!(next_hold_z(300.0), 150.0);
|
||||
assert_eq!(next_hold_z(150.0), 80.0);
|
||||
assert_eq!(next_hold_z(80.0), 45.0);
|
||||
assert_eq!(next_hold_z(45.0), 45.0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user