Merge pull request #1112 from ludovic111/fix/loading-screen-square
🤖 Agent: merged. Verify passes. Local integration of #1109–#1112 on main ae21bd54: parity --changed 142/142. CI parity's world_spawn diff (seed -2080727421395798566) also happens on main: vanilla itself gives y64/65/66/72 across runs. The other failure is the known dedicated_server pearl flake.
This commit is contained in:
@@ -10006,6 +10006,9 @@ impl Game<'_> {
|
||||
(p.position.z.floor() as i32) >> 4,
|
||||
);
|
||||
}
|
||||
// The loading screen's chunk map fills ring by ring, as vanilla's.
|
||||
self.streaming.loading =
|
||||
self.options.dedicated.is_none() && self.loading_reason().is_some();
|
||||
let (uploads, unloaded) =
|
||||
horizon_client::spans::time("streaming", || self.streaming.update(&mut self.world));
|
||||
if let Some(lod) = &mut self.lod {
|
||||
|
||||
@@ -247,6 +247,8 @@ pub struct Streaming {
|
||||
pub forced: HashSet<(i32, i32)>,
|
||||
/// No work is scheduled while paused (title screen).
|
||||
pub paused: bool,
|
||||
/// The level loading screen is up: work goes ring by ring (`Ranges::rings`).
|
||||
pub loading: bool,
|
||||
/// Dimension flags: sky light, Nether face shading.
|
||||
pub sky_light: bool,
|
||||
pub nether_shading: bool,
|
||||
@@ -316,6 +318,7 @@ struct GenerationInputs<'a> {
|
||||
finishing: &'a FxHashSet<(i32, i32)>,
|
||||
decorates: bool,
|
||||
remote: bool,
|
||||
loading: bool,
|
||||
}
|
||||
impl GenerationScan {
|
||||
/// None means the scan was skipped; Some preserves the original candidate
|
||||
@@ -362,7 +365,7 @@ impl GenerationScan {
|
||||
{
|
||||
continue;
|
||||
}
|
||||
wanted.push((input.ranges.distance(x, z), x, z));
|
||||
wanted.push((input.ranges.priority(x, z, input.loading), x, z));
|
||||
}
|
||||
}
|
||||
// Forced chunks and their generation neighbourhood.
|
||||
@@ -378,7 +381,7 @@ impl GenerationScan {
|
||||
{
|
||||
continue;
|
||||
}
|
||||
wanted.push((input.ranges.distance(x, z), x, z));
|
||||
wanted.push((input.ranges.priority(x, z, input.loading), x, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -543,6 +546,7 @@ impl Streaming {
|
||||
radius: 8,
|
||||
forced: HashSet::new(),
|
||||
paused: false,
|
||||
loading: false,
|
||||
sky_light: true,
|
||||
nether_shading: false,
|
||||
biome_zoom: BiomeZoom::new(0),
|
||||
@@ -718,8 +722,9 @@ impl Streaming {
|
||||
}
|
||||
}
|
||||
}
|
||||
/// The order jobs around the player run in, lowest first.
|
||||
fn distance(&self, x: i32, z: i32) -> i64 {
|
||||
self.ranges().distance(x, z)
|
||||
self.ranges().priority(x, z, self.loading)
|
||||
}
|
||||
fn region(world: &World, x: i32, z: i32) -> Option<Box<Region>> {
|
||||
let mut region: Region = Default::default();
|
||||
@@ -1187,6 +1192,7 @@ impl Streaming {
|
||||
finishing: &self.finishing,
|
||||
decorates: self.decorates,
|
||||
remote: self.remote,
|
||||
loading: self.loading,
|
||||
};
|
||||
if let Some(wanted) = self.generation_scan.candidates(input, workers * 3) {
|
||||
for (d, x, z) in wanted {
|
||||
@@ -1361,6 +1367,29 @@ struct Ranges<'a> {
|
||||
forced: &'a HashSet<(i32, i32)>,
|
||||
}
|
||||
impl Ranges<'_> {
|
||||
/// `distance`, or `rings` while the level loading screen is up.
|
||||
fn priority(&self, x: i32, z: i32, loading: bool) -> i64 {
|
||||
if loading {
|
||||
self.rings(x, z)
|
||||
} else {
|
||||
self.distance(x, z)
|
||||
}
|
||||
}
|
||||
/// Ring by ring: the Chebyshev distance to the nearest centre first, then
|
||||
/// the squared distance. Vanilla's chunk tasks run by ticket level, which
|
||||
/// spreads one level per ring of chunks (`ChunkTaskPriorityQueue`), so
|
||||
/// `LevelLoadingScreen`'s chunk map fills squares around the spawn.
|
||||
fn rings(&self, x: i32, z: i32) -> i64 {
|
||||
let d = |c: (i32, i32)| {
|
||||
let (dx, dz) = (i64::from(x - c.0), i64::from(z - c.1));
|
||||
let ring = dx.abs().max(dz.abs());
|
||||
(ring * ring) << 20 | (dx * dx + dz * dz)
|
||||
};
|
||||
self.extra
|
||||
.iter()
|
||||
.map(|(c, _)| d(*c))
|
||||
.fold(d(self.center), i64::min)
|
||||
}
|
||||
fn distance(&self, x: i32, z: i32) -> i64 {
|
||||
let d = |c: (i32, i32)| {
|
||||
let (dx, dz) = (i64::from(x - c.0), i64::from(z - c.1));
|
||||
@@ -1532,6 +1561,7 @@ mod tests {
|
||||
finishing: &self.finishing,
|
||||
decorates: self.decorates,
|
||||
remote: self.remote,
|
||||
loading: false,
|
||||
}
|
||||
}
|
||||
fn fill(&mut self) {
|
||||
@@ -1880,6 +1910,31 @@ mod tests {
|
||||
/// from the save) and is not unloaded right after: either way it would be
|
||||
/// asked for and loaded again on the next frame, forever (8 such columns
|
||||
/// after a teleport at render distance 16 held 8 of the in-flight slots).
|
||||
/// #770: while the loading screen is up, chunks go ring by ring (a
|
||||
/// square front, as vanilla's ticket levels), nearest first in a ring.
|
||||
#[test]
|
||||
fn loading_goes_ring_by_ring() {
|
||||
let forced = HashSet::new();
|
||||
let r = Ranges {
|
||||
center: (2, -1),
|
||||
radius: 12,
|
||||
extra: &[],
|
||||
forced: &forced,
|
||||
};
|
||||
let at = |dx: i32, dz: i32| (2 + dx, -1 + dz);
|
||||
let key = |(x, z): (i32, i32), loading| r.priority(x, z, loading);
|
||||
// The corner of ring 3 comes before the edge of ring 4 only while loading.
|
||||
assert!(key(at(3, 3), true) < key(at(0, 4), true));
|
||||
assert!(key(at(3, 3), false) > key(at(0, 4), false));
|
||||
// Inside a ring, nearest first; rings never interleave.
|
||||
assert!(key(at(0, 3), true) < key(at(2, -3), true));
|
||||
assert!(key(at(-3, -3), true) < key(at(4, 0), true));
|
||||
for dx in -20..=20 {
|
||||
for dz in -20..=20 {
|
||||
assert_eq!(key(at(dx, dz), false), r.distance(2 + dx, -1 + dz));
|
||||
}
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn requested_columns_stay_loaded() {
|
||||
let forced = HashSet::new();
|
||||
|
||||
Reference in New Issue
Block a user