Merge pull request #2434 from RoyalPixelsDE/fix/forced-decoration-order

🤖 Agent: Gate check by Ludovic's AI agent (Claude). Checked against 26.3: `ForceLoadCommand` adds its FORCED tickets x-outer, z-inner, all at once, so the decoration order follows from that; the new `forced_order` reproduces it with the same ticket simulation as `vanilla_order`. Gate: this wave's 50 PRs merged on main in one tree (union 9033a9c3b): fmt and clippy `-D warnings` clean, the horizon-client (1136 lib plus the integration tests), horizon-client-core (37), horizon-world (165) and horizon-protocol (100) tests pass, the fast build links, and the 140 harnesses `parity.py` picks for the tree's changed files pass on playhorizon (remote_fireworks, a known load flake there, passed on a rerun on a quiet Mac mini). `lan_e2e.py` passes 14 checks with the host on its server thread and in-frame (chest, xp, damage, kills, projectiles, mobs, drops, body, stopsound, digging, instant_digging, books, knockback, barter); `hurt` fails on main too when run after `damage` (check-order dependency, not this wave). Thanks @FusselTV!
This commit is contained in:
Ludovic Marie
2026-10-27 03:54:00 +01:00
committed by GitHub
5 changed files with 71 additions and 16 deletions
@@ -244,7 +244,11 @@ impl Game<'_> {
/// hand them the next jobs as soon as each one is done, rather than once
/// a tick.
pub(in crate::game) fn pump_pregen(&mut self, until: Instant) {
while self.pregen_runs_here() {
// Force-loaded chunks too: decorating in vanilla's order, a chunk
// waits for its neighbours far more often than once a tick allows.
while self.pregen_runs_here()
|| (!self.streaming.forced.is_empty() && self.streaming.busy())
{
let now = Instant::now();
if now >= until {
break;
@@ -120,6 +120,9 @@ impl Game<'_> {
tracker.track(&holder(chunk_text(x, z)), i32::from(changed));
}
}
if add {
self.streaming.rank_forced(cx0, cz0, cx1, cz1);
}
let (lo, hi) = (chunk_text(cx0, cz0), chunk_text(cx1, cz1));
let verb = if add { "added" } else { "removed" };
let (message, total) = tracker.message(
+2 -1
View File
@@ -400,7 +400,8 @@ impl Game<'_> {
}
*next += self.clock.tick_duration();
if *next > now {
// A `/pregen` task keeps the workers fed until the next tick.
// A `/pregen` task or force-loaded chunks keep the workers fed
// until the next tick.
self.pump_pregen(*next);
let now = Instant::now();
if *next > now {
+8
View File
@@ -1417,6 +1417,14 @@ impl Streaming {
pub fn band(&self) -> Option<Band> {
self.band
}
/// Rank the chunks `/forceload add` over chunks `(x0, z0)..=(x1, z1)`
/// decorates in vanilla's order (`forced_order`), after every chunk
/// ranked before.
pub fn rank_forced(&mut self, x0: i32, z0: i32, x1: i32, z1: i32) {
for (x, z) in horizon_world::worldgen::decoration_order::forced_order(x0, z0, x1, z1) {
self.decoration_order.rank_or_append(x, z);
}
}
/// Generate, light and keep the chunks of `band` (none: stop), and let
/// go of what earlier bands held as it falls out of range. The chunks a
/// band reaches are ranked for decoration row by row, as they first come
@@ -29,7 +29,7 @@
//! overlap), so a chunk may be decorated as soon as no lower-ranked chunk
//! within two of it is still waiting: [`DecorationOrder::blocked`]. Chunks
//! further apart still decorate in parallel.
use std::collections::HashMap;
use std::collections::{HashMap, VecDeque};
#[derive(Default)]
pub struct DecorationOrder {
@@ -121,7 +121,6 @@ fn ticket_hash(x: i32, z: i32) -> u64 {
/// The chunks decorated around a player at `center`, in vanilla's order.
pub fn vanilla_order(center: (i32, i32), radius: i32) -> Vec<(i32, i32)> {
use std::cmp::Reverse;
use std::collections::{BinaryHeap, VecDeque};
let mut tickets: Vec<(i32, i32)> = (-radius..=radius)
.flat_map(|dx| (-radius..=radius).map(move |dz| (center.0 + dx, center.1 + dz)))
.collect();
@@ -132,16 +131,31 @@ pub fn vanilla_order(center: (i32, i32), radius: i32) -> Vec<(i32, i32)> {
Reverse(ticket_hash(x, z) & (TICKET_SET_CAPACITY - 1)),
)
});
let mut tickets: VecDeque<_> = tickets.into();
// Every chunk this touches lies within `half` of the centre: tickets
// reach `LIGHT_LEVEL - TICKET_LEVEL` further, and FULL tasks decorate
// one more ring. Dense grids over that square replace hash maps.
// one more ring.
let half = radius.max(0) + LIGHT_LEVEL - TICKET_LEVEL + 1;
ticket_order(
tickets.into(),
TICKETS_IN_FLIGHT,
(center.0 - half, center.1 - half),
(2 * half + 1) as usize,
)
}
/// The decoration order of `tickets` (level 31) added in turn, at most
/// `in_flight` at a time. Dense grids of `side` chunks from `origin` hold
/// every chunk this touches, in place of hash maps.
fn ticket_order(
mut tickets: VecDeque<(i32, i32)>,
in_flight: usize,
origin: (i32, i32),
side: usize,
) -> Vec<(i32, i32)> {
use std::cmp::Reverse;
use std::collections::BinaryHeap;
let reach = LIGHT_LEVEL - TICKET_LEVEL;
let half = radius.max(0) + reach + 1;
let side = (2 * half + 1) as usize;
let cell = |(x, z): (i32, i32)| {
((x - center.0 + half) as usize) * side + (z - center.1 + half) as usize
};
let cell = |(x, z): (i32, i32)| ((x - origin.0) as usize) * side + (z - origin.1) as usize;
let mut active: Vec<(i32, i32)> = Vec::new();
// Queued task per chunk (level, sequence), `NONE` when there is none;
// stale heap entries are skipped.
@@ -177,10 +191,9 @@ pub fn vanilla_order(center: (i32, i32), radius: i32) -> Vec<(i32, i32)> {
}
}
};
for _ in 0..TICKETS_IN_FLIGHT {
if let Some(t) = tickets.pop_front() {
add(t, &mut active, &mut queued, &mut heap, &full);
}
while active.len() < in_flight {
let Some(t) = tickets.pop_front() else { break };
add(t, &mut active, &mut queued, &mut heap, &full);
}
while let Some(Reverse((l, s, chunk))) = heap.pop() {
let i = cell(chunk);
@@ -202,7 +215,7 @@ pub fn vanilla_order(center: (i32, i32), radius: i32) -> Vec<(i32, i32)> {
full[i] = true;
}
active.retain(|t| !(-2..=2).all(|dx| (-2..=2).all(|dz| full[cell((t.0 + dx, t.1 + dz))])));
while active.len() < TICKETS_IN_FLIGHT {
while active.len() < in_flight {
let Some(t) = tickets.pop_front() else { break };
add(t, &mut active, &mut queued, &mut heap, &full);
}
@@ -210,10 +223,36 @@ pub fn vanilla_order(center: (i32, i32), radius: i32) -> Vec<(i32, i32)> {
order
}
/// The chunks `/forceload add` over chunks `(x0, z0)..=(x1, z1)` decorates,
/// in vanilla's order: ForceLoadCommand adds a FORCED ticket (level 31) per
/// chunk, x-outer, z-inner, all at once.
pub fn forced_order(x0: i32, z0: i32, x1: i32, z1: i32) -> Vec<(i32, i32)> {
let tickets = (x0..=x1)
.flat_map(|x| (z0..=z1).map(move |z| (x, z)))
.collect();
let pad = LIGHT_LEVEL - TICKET_LEVEL + 1;
let side = ((x1 - x0).max(z1 - z0) + 2 * pad + 1) as usize;
ticket_order(tickets, usize::MAX, (x0 - pad, z0 - pad), side)
}
#[cfg(test)]
mod tests {
use super::*;
/// Seed 8675309's geodes in chunks (-26, -1) and (14, -20) run into the
/// trial chambers of (-26, 0) and (14, -19); vanilla decorates the lower
/// z first, wherever the batch lies, so the chambers are drawn over them.
#[test]
fn forced_chunks_decorate_x_outer_z_inner() {
let rank = |order: &[(i32, i32)], c| order.iter().position(|&o| o == c).unwrap();
let west = forced_order(-32, -16, -17, -1);
assert!(rank(&west, (-26, -1)) < rank(&west, (-26, 0)));
let east = forced_order(0, -32, 15, -17);
assert!(rank(&east, (14, -20)) < rank(&east, (14, -19)));
assert_eq!(west[0], (-33, -17));
assert_eq!(west.len(), 22 * 22);
}
/// The hash map version this module had before its dense grids.
fn hashed_order(center: (i32, i32), radius: i32) -> Vec<(i32, i32)> {
use std::cmp::Reverse;