13cd89578a
Sections that terrain in front hides entirely are drawn with an instance count of 0. Phase 1 draws the sections the last test read back saw; in the same pass every other section's box (and an eighth of phase 1's) is drawn against phase 1's depth, front faces only, with a fragment shader forced past an early depth test that marks the section seen. Phase 2, in a second pass, draws what the test saw. The test is exact per pixel and needs no depth read or Hi-Z, and every solid draw stays one entry of one list, so the CPU records as many draws as before (Mesa unrolls a multi-draw per entry on Intel Gen9). Culling pauses while the last result hid under a tenth of the solid indices, with one frame in 64 testing everything. HD 620 at RD16: +23-42% FPS in five of perf-frame-6's six views, the peak view unchanged; RD32: +14-109%. Pixels unchanged, also on camera jumps. Vulkan only: naga's MSL has no early fragment tests. HORIZON_GPU_CULL=0 turns it off, `all` culls every frame; `section-cull on|off` in a game. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
139 lines
6.3 KiB
Rust
139 lines
6.3 KiB
Rust
//! Control-socket commands for inspecting rendering: place blocks without
|
|
//! updates (`setblock`, `fill`) to build test scenes.
|
|
use super::Game;
|
|
use horizon_client::Result;
|
|
use horizon_core::random::RandomSource;
|
|
use horizon_world::registry::BlockStateId;
|
|
use serde_json::{Value, json};
|
|
|
|
pub const HELP: &[&str] = &[
|
|
"setblock X Y Z STATE set a block state (name[prop=value,...]) without updates",
|
|
"fill X1 Y1 Z1 X2 Y2 Z2 STATE fill a box with a block state without updates",
|
|
"particle NAME X Y Z [DX DY DZ] [COUNT] spawn particles (vanilla /particle spread)",
|
|
"signedit X Y Z [front|back] open the sign editor for the sign at X Y Z",
|
|
"section-draws [flat|indirect] how terrain sections are drawn (A/B checks); replies the mode",
|
|
"section-cull [on|off] occlusion culling of solid sections (A/B checks); replies the mode",
|
|
];
|
|
|
|
impl Game<'_> {
|
|
/// Parse `name[k=v,...]` into a registry state (defaults for missing properties).
|
|
fn parse_state(&self, text: &str) -> Result<BlockStateId> {
|
|
let (name, props) = match text.split_once('[') {
|
|
Some((n, rest)) => (n, rest.trim_end_matches(']')),
|
|
None => (text, ""),
|
|
};
|
|
let name = if name.contains(':') {
|
|
name.to_owned()
|
|
} else {
|
|
format!("minecraft:{name}")
|
|
};
|
|
let registry = &self.pack.assets.registry;
|
|
let default = registry
|
|
.default_state(&name)
|
|
.ok_or_else(|| format!("unknown block {name}"))?;
|
|
let mut state = registry
|
|
.state(default)
|
|
.ok_or("missing default state")?
|
|
.clone();
|
|
for pair in props.split(',').filter(|p| !p.is_empty()) {
|
|
let (k, v) = pair
|
|
.split_once('=')
|
|
.ok_or_else(|| format!("bad property {pair}"))?;
|
|
if !state.properties.contains_key(k) {
|
|
return Err(format!("{name} has no property {k}").into());
|
|
}
|
|
state.properties.insert(k.to_owned(), v.to_owned());
|
|
}
|
|
Ok(registry.resolve(&state)?)
|
|
}
|
|
pub(super) fn render_command(&mut self, words: &[&str]) -> Result<Option<Value>> {
|
|
let int = |i: usize| -> Result<i32> {
|
|
Ok(words
|
|
.get(i)
|
|
.ok_or_else(|| format!("missing argument {i}"))?
|
|
.parse::<i32>()?)
|
|
};
|
|
match words[0] {
|
|
"setblock" => {
|
|
let state = self.parse_state(words.get(4).ok_or("missing state")?)?;
|
|
self.world.set(int(1)?, int(2)?, int(3)?, state)?;
|
|
Ok(Some(json!({ "ok": true, "state": state.0 })))
|
|
}
|
|
"fill" => {
|
|
let state = self.parse_state(words.get(7).ok_or("missing state")?)?;
|
|
let (a, b) = ([int(1)?, int(2)?, int(3)?], [int(4)?, int(5)?, int(6)?]);
|
|
let mut count = 0;
|
|
for x in a[0].min(b[0])..=a[0].max(b[0]) {
|
|
for y in a[1].min(b[1])..=a[1].max(b[1]) {
|
|
for z in a[2].min(b[2])..=a[2].max(b[2]) {
|
|
self.world.set(x, y, z, state)?;
|
|
count += 1;
|
|
}
|
|
}
|
|
}
|
|
Ok(Some(json!({ "ok": true, "blocks": count })))
|
|
}
|
|
"particle" => {
|
|
use horizon_client::particles::{ParticleOptions, ParticleType};
|
|
let ty = ParticleType::from_name(words.get(1).ok_or("missing particle")?)
|
|
.ok_or("unknown particle type")?;
|
|
let num = |i: usize, default: f64| -> Result<f64> {
|
|
Ok(words.get(i).map_or(Ok(default), |w| w.parse::<f64>())?)
|
|
};
|
|
let at = [num(2, 0.0)?, num(3, 0.0)?, num(4, 0.0)?];
|
|
let delta = [num(5, 0.0)?, num(6, 0.0)?, num(7, 0.0)?];
|
|
let count = num(8, 1.0)? as u32;
|
|
let options = match ty {
|
|
ParticleType::Dust => ParticleOptions::dust([1.0, 0.0, 0.0], 1.0),
|
|
ParticleType::Block
|
|
| ParticleType::FallingDust
|
|
| ParticleType::DustPillar
|
|
| ParticleType::BlockMarker => {
|
|
ParticleOptions::block(ty, "block/stone".into(), 0x808080)
|
|
}
|
|
ParticleType::Item => self.item_particle(
|
|
&horizon_client::items::ItemStack::new("minecraft:apple", 1),
|
|
),
|
|
ParticleType::ItemSlime
|
|
| ParticleType::ItemSnowball
|
|
| ParticleType::ItemCobweb => {
|
|
self.ensure_item_particle_sprites();
|
|
ParticleOptions::simple(ty)
|
|
}
|
|
_ => ParticleOptions::simple(ty),
|
|
};
|
|
// ServerLevel.sendParticles: count 0 uses the delta as velocity.
|
|
if count == 0 {
|
|
self.particles.create(&options, at, delta);
|
|
}
|
|
for _ in 0..count {
|
|
let r = self.particles.random();
|
|
let p = [
|
|
at[0] + r.next_gaussian() * delta[0],
|
|
at[1] + r.next_gaussian() * delta[1],
|
|
at[2] + r.next_gaussian() * delta[2],
|
|
];
|
|
self.particles.create(&options, p, [0.0; 3]);
|
|
}
|
|
Ok(Some(json!({ "ok": true, "live": self.particles.len() })))
|
|
}
|
|
"signedit" => {
|
|
let key = (int(1)?, int(2)?, int(3)?);
|
|
let name = self
|
|
.res
|
|
.facts()
|
|
.get(self.world.block(key.0, key.1, key.2))
|
|
.name
|
|
.clone();
|
|
let entity = horizon_client::containers::BlockEntity::for_block(&name)
|
|
.filter(|e| matches!(e, horizon_client::containers::BlockEntity::Sign(_)))
|
|
.ok_or("no sign there")?;
|
|
self.world.block_entities.get_or_insert_with(key, || entity);
|
|
self.open_sign_editor(key, words.get(4) != Some(&"back"));
|
|
Ok(Some(json!({ "ok": true })))
|
|
}
|
|
other => Err(format!("unknown render command {other}").into()),
|
|
}
|
|
}
|
|
}
|