# Horizon Web (26.3-r2) Source Modifications # Upstream repository: https://github.com/nobuildersnotools/horizon-web # Base upstream commit: 83eb3376109f0676fc8d12c6b2455dd3258c84db # Modification date: 2026-12-04 # License notice (LGPL-3.0 Section 2 / GPL-3.0 Section 5a): # This file states prominent notices that the source files below were modified # on 2026-12-04 from upstream nobuildersnotools/horizon-web commit # 83eb3376109f0676fc8d12c6b2455dd3258c84db for browser WebGPU/WebGL2 rendering, # touch controls, active backend reporting, world-export save flushing, # Web Worker thread bounds, and VFS cache exclusions. # Licensed under LGPL-3.0-or-later (see LGPL-3.0.txt, GPL-3.0.txt, and # THIRD_PARTY_NOTICES.md in /games-embed/minecraft/licenses/). diff --git a/Cargo.lock b/Cargo.lock index c9c425a..e28df71 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5481,6 +5481,7 @@ dependencies = [ "thiserror 2.0.21", "wgpu-core-deps-apple", "wgpu-core-deps-emscripten", + "wgpu-core-deps-wasm", "wgpu-core-deps-windows-linux-android", "wgpu-hal", "wgpu-naga-bridge", @@ -5505,6 +5506,15 @@ dependencies = [ "wgpu-hal", ] +[[package]] +name = "wgpu-core-deps-wasm" +version = "30.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b20f43aeb9962d05e61e3ccb717e2e27ba1b04e979d4ca7e361384f8ee03db56" +dependencies = [ + "wgpu-hal", +] + [[package]] name = "wgpu-core-deps-windows-linux-android" version = "30.0.1" diff --git a/crates/horizon-client-input/src/window.rs b/crates/horizon-client-input/src/window.rs index 60f26a4..ad1d875 100644 --- a/crates/horizon-client-input/src/window.rs +++ b/crates/horizon-client-input/src/window.rs @@ -409,6 +409,9 @@ impl FullscreenState { preferred: Option, in_video_screen: bool, ) { + if cfg!(target_arch = "wasm32") { + return; + } let request = self.request(wanted); let reapply = self.set_exclusive(exclusive); self.set_preferred_mode(preferred); @@ -605,11 +608,16 @@ fn monitor_current_mode( /// state first: winit keeps a maximized window's client area inside the work area, so a /// borderless fullscreen kept the taskbar over its bottom and pushed its top off screen (#9984). pub fn enter_fullscreen(window: &winit::window::Window, fullscreen: winit::window::Fullscreen) { - #[cfg(target_os = "windows")] - if window.is_maximized() { - window.set_maximized(false); + #[cfg(target_arch = "wasm32")] + let _ = (window, fullscreen); + #[cfg(not(target_arch = "wasm32"))] + { + #[cfg(target_os = "windows")] + if window.is_maximized() { + window.set_maximized(false); + } + window.set_fullscreen(Some(fullscreen)); } - window.set_fullscreen(Some(fullscreen)); } /// Borderless fullscreen on the window's own monitor (the primary one when it has none). diff --git a/crates/horizon-client-render/Cargo.toml b/crates/horizon-client-render/Cargo.toml index 897937e..979b9ec 100644 --- a/crates/horizon-client-render/Cargo.toml +++ b/crates/horizon-client-render/Cargo.toml @@ -91,9 +91,9 @@ naga = { version = "30.0.1", features = ["wgsl-in", "hlsl-out", "glsl-out", "msl [target.'cfg(target_arch = "wasm32")'.dependencies] # The browser's stand-in for ureq: every request fails as if offline (the crate root names it `ureq`). horizon-ureq-web = { path = "../horizon-ureq-web" } -wgpu = { version = "30.0.1", default-features = false, features = ["webgpu"] } -# gfx::naga_source writes naga IR as WGSL for the browser. -naga = { version = "30.0.1", features = ["wgsl-out"] } +wgpu = { version = "30.0.1", default-features = false, features = ["webgpu", "webgl"] } +# gfx::naga_source writes naga IR as WGSL for the browser; WebGL2 compiles to GLSL. +naga = { version = "30.0.1", features = ["wgsl-out", "glsl-out"] } # Sound through the browser's Web Audio. cpal = { version = "0.16", optional = true, features = ["wasm-bindgen"] } diff --git a/crates/horizon-client-render/src/gfx.rs b/crates/horizon-client-render/src/gfx.rs index e022237..9242b00 100644 --- a/crates/horizon-client-render/src/gfx.rs +++ b/crates/horizon-client-render/src/gfx.rs @@ -215,21 +215,35 @@ impl<'a> SectionLists<'a> { .slice(..), ), }; - pass.set_vertex_buffer(0, vertices); - if pulled - && index_page.is_none() + let pulled_solid = pulled && index_page.is_none(); + if pulled_solid && let Some(group) = self.flat.and_then(|f| f.page_group(page)) { pass.set_bind_group(1, group, &[]); } pass.set_index_buffer(indices, wgpu::IndexFormat::Uint32); if self.multi_draw { + pass.set_vertex_buffer(0, vertices); let offset = (i - base as usize) as u64 * 20; pass.multi_draw_indexed_indirect(indirect, offset, run as u32); - } else { + } else if pulled_solid { + pass.set_vertex_buffer(0, vertices); for d in &draws[i..i + run] { pass.draw_indexed(d[2]..d[2] + d[0], d[3] as i32, d[4]..d[4] + 1); } + } else { + let page_buffer = match (self.translucent_arena, index_page) { + (Some(arena), Some(_)) => arena.buffer(page), + _ => self.arena.buffer(page), + }; + let stride = std::mem::size_of::() as u64; + for d in &draws[i..i + run] { + if d[0] == 0 || d[1] == 0 { + continue; + } + pass.set_vertex_buffer(0, page_buffer.slice(u64::from(d[3]) * stride..)); + pass.draw_indexed(d[2]..d[2] + d[0], 0, d[4]..d[4] + d[1]); + } } i += run; } @@ -2088,9 +2102,13 @@ fn backend_order( wgpu_backend: bool, ) -> Vec { use wgpu::Backends; - // A page has the browser's WebGPU and nothing else Horizon can draw with. + // In the browser, Auto tries WebGPU first and falls back to WebGL2; OpenGL selects WebGL2. if cfg!(target_arch = "wasm32") { - return vec![Backends::BROWSER_WEBGPU]; + return match api { + GraphicsApi::OpenGl => vec![Backends::GL], + GraphicsApi::Vulkan | GraphicsApi::Dx12 => vec![Backends::BROWSER_WEBGPU], + GraphicsApi::Auto => vec![Backends::BROWSER_WEBGPU, Backends::GL], + }; } if os == "macos" || wgpu_backend { return vec![Backends::default()]; @@ -2109,8 +2127,10 @@ fn backend_order( } fn backends_name(backends: wgpu::Backends) -> &'static str { match backends { + wgpu::Backends::BROWSER_WEBGPU => "WebGPU", wgpu::Backends::VULKAN => "Vulkan", wgpu::Backends::DX12 => "DirectX 12", + wgpu::Backends::GL if cfg!(target_arch = "wasm32") => "WebGL2", wgpu::Backends::GL => "OpenGL", _ => "graphics", } @@ -2579,7 +2599,9 @@ const NO_GPU_DRIVER: &str = "No graphics driver with Vulkan, DirectX 12 or OpenG start the game again"; #[cfg(target_os = "macos")] const NO_GPU_DRIVER: &str = "No Metal graphics device found"; -#[cfg(not(any(target_os = "windows", target_os = "macos")))] +#[cfg(target_arch = "wasm32")] +const NO_GPU_DRIVER: &str = "No WebGPU or WebGL2 graphics adapter found in this browser"; +#[cfg(not(any(target_os = "windows", target_os = "macos", target_arch = "wasm32")))] const NO_GPU_DRIVER: &str = "No Vulkan or OpenGL graphics driver found: Horizon needs the Vulkan loader \ (libvulkan.so.1) and a Vulkan driver for your GPU (Mesa's, or NVIDIA's), or OpenGL through EGL"; /// Logs a step of the renderer's start, for a native crash in the graphics @@ -2672,6 +2694,12 @@ impl Renderer { // shader pack atlas all cut the sprites by it. let split = check_layers(&adapter, layers)?; let info = adapter.get_info(); + #[cfg(target_arch = "wasm32")] + horizon_os::web::set_graphics_backend(match info.backend { + wgpu::Backend::BrowserWebGpu => "WebGPU", + wgpu::Backend::Gl => "WebGL2", + _ => "", + }); surface_setup::log_sprite_split(&info, split, layers); crate::graphics::suggest_reduced_far_detail(crate::graphics::lod_capped(&info)); let size = window.inner_size(); @@ -5001,12 +5029,22 @@ impl Renderer { }) } /// The first-person hand's quads, which follow `first` quads of the entity buffer. + fn quad_slice(buffer: &wgpu::Buffer, first_quad: u32) -> wgpu::BufferSlice<'_> { + let offset = u64::from(first_quad) * 4 * std::mem::size_of::() as u64; + buffer.slice(offset..) + } + fn entity_quad_slice(&self, first_quad: u32) -> wgpu::BufferSlice<'_> { + Self::quad_slice(&self.entity_buffer, first_quad) + } fn draw_hand(&self, pass: &mut wgpu::RenderPass<'_>, quads: u32, first: u32) { + if quads == 0 { + return; + } pass.set_pipeline(&self.entity_pipeline); pass.set_bind_group(0, &self.hand_group, &[]); pass.set_index_buffer(self.indices.slice(..), wgpu::IndexFormat::Uint32); - pass.set_vertex_buffer(0, self.entity_buffer.slice(..)); - pass.draw_indexed(0..quads * 6, (first * 4) as i32, 0..1); + pass.set_vertex_buffer(0, self.entity_quad_slice(first)); + pass.draw_indexed(0..quads * 6, 0, 0..1); } /// The shared atlas's LabPBR maps (`HudAtlas::material_maps`), uploaded for the shader packs /// loaded from now on; a map too large for this GPU is left out. @@ -10475,8 +10513,8 @@ impl Renderer { pass.stage(self.own_timing.as_mut(), "entity text"); pass.set_pipeline(warped.map_or(&self.text_polygon_offset_pipeline, |w| &w.text)); self.bind_world_text(&mut pass, warped.is_none(), false); - pass.set_vertex_buffer(0, self.entity_buffer.slice(..)); - pass.draw_indexed(0..text_quads * 6, (entity_quads * 4) as i32, 0..1); + pass.set_vertex_buffer(0, self.entity_quad_slice(entity_quads)); + pass.draw_indexed(0..text_quads * 6, 0, 0..1); pass.set_bind_group(0, &self.group, &[]); } // FeatureRenderDispatcher.PreparedFrame.executeTranslucent: the shadows @@ -10485,16 +10523,12 @@ impl Renderer { pass.stage(self.own_timing.as_mut(), "shadows"); pass.set_pipeline(warped.map_or(&self.shadow_blob_pipeline, |w| &w.entity_shadows)); pass.set_bind_group(0, &self.entity_group, &[]); - pass.set_vertex_buffer(0, self.entity_buffer.slice(..)); - pass.draw_indexed( - 0..shadow_quads * 6, - ((base_quads - - translucent_item_quads - - translucent_particle_quads - - shadow_quads) - * 4) as i32, - 0..1, - ); + let shadow_first = base_quads + - translucent_item_quads + - translucent_particle_quads + - shadow_quads; + pass.set_vertex_buffer(0, self.entity_quad_slice(shadow_first)); + pass.draw_indexed(0..shadow_quads * 6, 0, 0..1); pass.set_bind_group(0, &self.group, &[]); } if translucent_item_quads > 0 && !oit_on { @@ -10503,12 +10537,11 @@ impl Renderer { warped.map_or(&self.translucent_item_pipeline, |w| &w.translucent_items), ); pass.set_bind_group(0, &self.entity_group, &[]); - pass.set_vertex_buffer(0, self.entity_buffer.slice(..)); - pass.draw_indexed( - 0..translucent_item_quads * 6, - ((base_quads - translucent_item_quads) * 4) as i32, - 0..1, + pass.set_vertex_buffer( + 0, + self.entity_quad_slice(base_quads - translucent_item_quads), ); + pass.draw_indexed(0..translucent_item_quads * 6, 0, 0..1); pass.set_bind_group(0, &self.group, &[]); } // Native terrain models use the block sprite arrays with their own @@ -10536,8 +10569,8 @@ impl Renderer { }, &[], ); - pass.set_vertex_buffer(0, self.entity_buffer.slice(..)); - pass.draw_indexed(0..count * 6, (first * 4) as i32, 0..1); + pass.set_vertex_buffer(0, self.entity_quad_slice(first)); + pass.draw_indexed(0..count * 6, 0, 0..1); } first += count; } @@ -10549,12 +10582,8 @@ impl Renderer { pass.stage(self.own_timing.as_mut(), "fluid block entities"); pass.set_pipeline(&self.fluid_pipeline); pass.set_bind_group(0, &self.fluid_group, &[]); - pass.set_vertex_buffer(0, self.entity_buffer.slice(..)); - pass.draw_indexed( - 0..fluid_quads * 6, - ((base_quads + oit_entity_quads) * 4) as i32, - 0..1, - ); + pass.set_vertex_buffer(0, self.entity_quad_slice(base_quads + oit_entity_quads)); + pass.draw_indexed(0..fluid_quads * 6, 0, 0..1); pass.set_bind_group(0, &self.group, &[]); } // A solid block's crack is classic whatever the setting (`DESTROY_TYPES`, solid phase). @@ -10562,12 +10591,8 @@ impl Renderer { pass.stage(self.own_timing.as_mut(), "block breaking"); pass.set_pipeline(&self.crumbling_pipeline); pass.set_bind_group(0, &self.entity_group, &[]); - pass.set_vertex_buffer(0, self.entity_buffer.slice(..)); - pass.draw_indexed( - 0..crumbling_quads * 6, - ((entity_quads + text_quads) * 4) as i32, - 0..1, - ); + pass.set_vertex_buffer(0, self.entity_quad_slice(entity_quads + text_quads)); + pass.draw_indexed(0..crumbling_quads * 6, 0, 0..1); pass.set_bind_group(0, &self.group, &[]); } // BoatRenderer's water patch (RenderTypes.waterMask): depth only, @@ -10576,13 +10601,10 @@ impl Renderer { pass.stage(self.own_timing.as_mut(), "boat water mask"); pass.set_pipeline(&self.water_mask_pipeline); pass.set_bind_group(0, &self.entity_group, &[]); - pass.set_vertex_buffer(0, self.entity_buffer.slice(..)); - pass.draw_indexed( - 0..water_mask_quads * 6, - ((entity_quads + text_quads + crumbling_quads + translucent_crumbling_quads) - * 4) as i32, - 0..1, - ); + let mask_first = + entity_quads + text_quads + crumbling_quads + translucent_crumbling_quads; + pass.set_vertex_buffer(0, self.entity_quad_slice(mask_first)); + pass.draw_indexed(0..water_mask_quads * 6, 0, 0..1); pass.set_bind_group(0, &self.group, &[]); } if !frame.lightning.bolts.is_empty() && !oit_on { @@ -10596,23 +10618,19 @@ impl Renderer { pass.stage(self.own_timing.as_mut(), "energy swirl"); pass.set_pipeline(&self.energy_swirl_pipeline); pass.set_bind_group(0, &self.entity_group, &[]); - pass.set_vertex_buffer(0, self.entity_buffer.slice(..)); - pass.draw_indexed( - 0..swirl_quads * 6, - ((entity_quads - + text_quads - + crumbling_quads - + translucent_crumbling_quads - + water_mask_quads) - * 4) as i32, - 0..1, - ); + let swirl_first = entity_quads + + text_quads + + crumbling_quads + + translucent_crumbling_quads + + water_mask_quads; + pass.set_vertex_buffer(0, self.entity_quad_slice(swirl_first)); + pass.draw_indexed(0..swirl_quads * 6, 0, 0..1); pass.set_bind_group(0, &self.group, &[]); } if additive_quads > 0 && !oit_on { pass.stage(self.own_timing.as_mut(), "additive entities"); pass.set_bind_group(0, &self.entity_group, &[]); - pass.set_vertex_buffer(0, self.entity_buffer.slice(..)); + pass.set_vertex_buffer(0, self.entity_quad_slice(world_quads)); let mut first = 0; for run in frame.additive.as_chunks::<4>().0.chunk_by(|a, b| { (a[0].layer & 0xffff == DRAGON_RAYS_OVERLAY) @@ -10625,7 +10643,7 @@ impl Renderer { &self.additive_pipeline }); let end = first + run.len() as u32; - pass.draw_indexed(first * 6..end * 6, (world_quads * 4) as i32, 0..1); + pass.draw_indexed(first * 6..end * 6, 0, 0..1); first = end; } pass.set_bind_group(0, &self.group, &[]); @@ -10701,16 +10719,12 @@ impl Renderer { pass.set_pipeline(&self.water_mask_pipeline); pass.set_bind_group(0, &self.entity_group, &[]); pass.set_index_buffer(self.indices.slice(..), wgpu::IndexFormat::Uint32); - pass.set_vertex_buffer(0, self.entity_buffer.slice(..)); - pass.draw_indexed( - 0..water_mask_quads * 6, - ((entity_quads - + text_quads - + crumbling_quads - + translucent_crumbling_quads) - * 4) as i32, - 0..1, - ); + let mask_first = entity_quads + + text_quads + + crumbling_quads + + translucent_crumbling_quads; + pass.set_vertex_buffer(0, Self::quad_slice(&self.entity_buffer, mask_first)); + pass.draw_indexed(0..water_mask_quads * 6, 0, 0..1); }; let clouds = |pass: &mut wgpu::RenderPass<'_>, pipeline: &wgpu::RenderPipeline| { @@ -10731,7 +10745,6 @@ impl Renderer { let s = stage as usize; pass.set_index_buffer(self.indices.slice(..), wgpu::IndexFormat::Uint32); pass.set_bind_group(0, &self.entity_group, &[]); - pass.set_vertex_buffer(0, self.entity_buffer.slice(..)); // Quads of a material, `first` quads into the buffer. let quads = |pass: &mut wgpu::RenderPass<'_>, pipeline: &wgpu::RenderPipeline, @@ -10739,7 +10752,8 @@ impl Renderer { first: u32| { if count > 0 { pass.set_pipeline(pipeline); - pass.draw_indexed(0..count * 6, (first * 4) as i32, 0..1); + pass.set_vertex_buffer(0, Self::quad_slice(&self.entity_buffer, first)); + pass.draw_indexed(0..count * 6, 0, 0..1); } }; quads(pass, &f.text[s], text_quads, entity_quads); @@ -10789,7 +10803,6 @@ impl Renderer { if !frame.lightning.bolts.is_empty() { pass.set_pipeline(&f.lightning[s]); self.lightning.draw(pass, &frame.lightning); - pass.set_vertex_buffer(0, self.entity_buffer.slice(..)); } quads(pass, &f.additive[s], additive_quads, world_quads); self.weather @@ -10901,12 +10914,10 @@ impl Renderer { } pass.set_bind_group(0, &self.entity_group, &[]); pass.set_index_buffer(self.indices.slice(..), wgpu::IndexFormat::Uint32); - pass.set_vertex_buffer(0, self.entity_buffer.slice(..)); - pass.draw_indexed( - 0..translucent_particle_quads * 6, - ((base_quads - translucent_item_quads - translucent_particle_quads) * 4) as i32, - 0..1, - ); + let particle_first = + base_quads - translucent_item_quads - translucent_particle_quads; + pass.set_vertex_buffer(0, self.entity_quad_slice(particle_first)); + pass.draw_indexed(0..translucent_particle_quads * 6, 0, 0..1); pass.set_bind_group(0, &self.group, &[]); } // Native world text is an ordinary depth-tested overlay, after @@ -10916,7 +10927,6 @@ impl Renderer { pass.stage(self.own_timing.as_mut(), "world text"); pass.set_bind_group(0, &self.entity_group, &[]); pass.set_index_buffer(self.indices.slice(..), wgpu::IndexFormat::Uint32); - pass.set_vertex_buffer(0, self.entity_buffer.slice(..)); let first = base_quads + oit_entity_quads + fluid_quads; for (pipeline, count, offset) in [ (&self.world_text_pipeline, world_text_quads, first), @@ -10928,7 +10938,8 @@ impl Renderer { ] { if count > 0 { pass.set_pipeline(pipeline); - pass.draw_indexed(0..count * 6, (offset * 4) as i32, 0..1); + pass.set_vertex_buffer(0, self.entity_quad_slice(offset)); + pass.draw_indexed(0..count * 6, 0, 0..1); } } pass.set_bind_group(0, &self.group, &[]); @@ -10944,12 +10955,9 @@ impl Renderer { pass.stage(self.own_timing.as_mut(), "block breaking"); pass.set_pipeline(&self.crumbling_pipeline); pass.set_bind_group(0, &self.entity_group, &[]); - pass.set_vertex_buffer(0, self.entity_buffer.slice(..)); - pass.draw_indexed( - 0..translucent_crumbling_quads * 6, - ((entity_quads + text_quads + crumbling_quads) * 4) as i32, - 0..1, - ); + let crumbling_first = entity_quads + text_quads + crumbling_quads; + pass.set_vertex_buffer(0, self.entity_quad_slice(crumbling_first)); + pass.draw_indexed(0..translucent_crumbling_quads * 6, 0, 0..1); } if cloud_quads > 0 && !pack_draws_clouds && !oit_on { pass.stage(self.own_timing.as_mut(), "clouds"); @@ -10990,12 +10998,9 @@ impl Renderer { pass.stage(self.own_timing.as_mut(), "see-through"); pass.set_pipeline(&self.see_through_pipeline); self.bind_world_text(&mut pass, true, true); - pass.set_vertex_buffer(0, self.entity_buffer.slice(..)); - pass.draw_indexed( - 0..see_through_quads * 6, - ((world_quads + additive_quads + hand_quads) * 4) as i32, - 0..1, - ); + let see_through_first = world_quads + additive_quads + hand_quads; + pass.set_vertex_buffer(0, self.entity_quad_slice(see_through_first)); + pass.draw_indexed(0..see_through_quads * 6, 0, 0..1); } // Native mods' primitives: after the entities and the rest of the world, into its // targets (its resolution, reversed depth and TAA), before the hand. @@ -11521,8 +11526,10 @@ impl Renderer { pass.set_pipeline(self.overlay_hand.as_ref().unwrap_or(&self.entity_pipeline)); pass.set_bind_group(0, &self.hand_group, &[]); pass.set_index_buffer(self.indices.slice(..), wgpu::IndexFormat::Uint32); - pass.set_vertex_buffer(0, self.entity_buffer.slice(..)); - pass.draw_indexed(0..overlay.hand_quads * 6, overlay.first_hand_vertex, 0..1); + let hand_offset = u64::try_from(overlay.first_hand_vertex).unwrap_or(0) + * std::mem::size_of::() as u64; + pass.set_vertex_buffer(0, self.entity_buffer.slice(hand_offset..)); + pass.draw_indexed(0..overlay.hand_quads * 6, 0, 0..1); } // A native mod's turn after the hand, on the real frame only. if overlay.real && !frame.title { @@ -11616,14 +11623,15 @@ impl Renderer { }); pass.set_bind_group(0, &self.entity_group, &[]); pass.set_index_buffer(self.indices.slice(..), wgpu::IndexFormat::Uint32); - pass.set_vertex_buffer(0, self.screen_buffer.slice(..)); + let screen_stride = std::mem::size_of::() as u64; for (i, quad) in frame.screen.iter().enumerate() { let blend = match quad.blend { crate::screen_effects::Blend::Alpha => 0, crate::screen_effects::Blend::Vignette => 4, }; pass.set_pipeline(&self.screen_pipelines[blend + (quad.sampling & 3) as usize]); - pass.draw_indexed(0..6, (i * 4) as i32, 0..1); + pass.set_vertex_buffer(0, self.screen_buffer.slice(i as u64 * 4 * screen_stride..)); + pass.draw_indexed(0..6, 0, 0..1); } } if let Some(hdr) = &self.hdr { diff --git a/crates/horizon-client-render/src/gfx/cull.wgsl b/crates/horizon-client-render/src/gfx/cull.wgsl index ccc6b61..a3eb264 100644 --- a/crates/horizon-client-render/src/gfx/cull.wgsl +++ b/crates/horizon-client-render/src/gfx/cull.wgsl @@ -5,6 +5,7 @@ struct Params { stamp: u32, // Boxes covering more than this share of the screen count as seen. big: f32, + _pad: vec2, } // The leading member of terrain.wgsl's Globals. struct Globals { diff --git a/crates/horizon-client-render/src/gfx/entity_outline.rs b/crates/horizon-client-render/src/gfx/entity_outline.rs index d7d8d80..e247225 100644 --- a/crates/horizon-client-render/src/gfx/entity_outline.rs +++ b/crates/horizon-client-render/src/gfx/entity_outline.rs @@ -297,8 +297,9 @@ impl EntityOutline { } let (first, quads) = self.posed; if quads > 0 { - pass.set_vertex_buffer(0, entities.slice(..)); - pass.draw_indexed(0..quads * 6, first as i32, 0..1); + let offset = u64::from(first) * std::mem::size_of::() as u64; + pass.set_vertex_buffer(0, entities.slice(offset..)); + pass.draw_indexed(0..quads * 6, 0, 0..1); } } // post_effect/entity_outline.json; its last pass only copies swap back to the diff --git a/crates/horizon-client-render/src/gfx/flat.rs b/crates/horizon-client-render/src/gfx/flat.rs index b1a52b6..9ea563d 100644 --- a/crates/horizon-client-render/src/gfx/flat.rs +++ b/crates/horizon-client-render/src/gfx/flat.rs @@ -272,7 +272,11 @@ pub fn is_broken_intel_vulkan(info: &wgpu::AdapterInfo) -> bool { fn supported(adapter: &wgpu::Adapter, device: &wgpu::Device) -> bool { let flags = adapter.get_downlevel_capabilities().flags; let limits = device.limits(); - flags.contains(wgpu::DownlevelFlags::VERTEX_STORAGE | wgpu::DownlevelFlags::COMPUTE_SHADERS) + flags.contains( + wgpu::DownlevelFlags::VERTEX_STORAGE + | wgpu::DownlevelFlags::COMPUTE_SHADERS + | wgpu::DownlevelFlags::BASE_VERTEX, + ) && limits.max_storage_buffers_per_shader_stage >= 3 && limits.max_storage_buffer_binding_size >= super::arena::PAGE_BYTES } diff --git a/crates/horizon-client-render/src/gfx/lightning.rs b/crates/horizon-client-render/src/gfx/lightning.rs index 86191bb..22cd1ee 100644 --- a/crates/horizon-client-render/src/gfx/lightning.rs +++ b/crates/horizon-client-render/src/gfx/lightning.rs @@ -209,12 +209,13 @@ impl Renderer { let Some(instances) = &self.instances else { return; }; - pass.set_vertex_buffer(1, instances.slice(..)); + let stride = std::mem::size_of::<[f32; 3]>() as u64; // Follow simulation order, including repeated seeds; HashMap order must // never change additive accumulation or the order before dragon rays. for (i, bolt) in input.bolts.iter().enumerate() { pass.set_vertex_buffer(0, self.cache.meshes[&bolt.seed].mesh.slice(..)); - pass.draw_indexed(0..QUADS * 6, 0, i as u32..i as u32 + 1); + pass.set_vertex_buffer(1, instances.slice(i as u64 * stride..)); + pass.draw_indexed(0..QUADS * 6, 0, 0..1); } } } diff --git a/crates/horizon-client-render/src/gfx/native_shadow.rs b/crates/horizon-client-render/src/gfx/native_shadow.rs index db4f80b..d0bb95e 100644 --- a/crates/horizon-client-render/src/gfx/native_shadow.rs +++ b/crates/horizon-client-render/src/gfx/native_shadow.rs @@ -859,12 +859,18 @@ impl super::native_pack::NativePack { pass.set_pipeline(&shadow.entity); pass.set_bind_group(0, lists.entity_group, &[]); pass.set_bind_group(GROUP, &shadow.group, &[]); - pass.set_vertex_buffer(0, lists.entity_vertices.slice(..)); pass.set_index_buffer(sections.indices.slice(..), wgpu::IndexFormat::Uint32); - pass.draw_indexed(0..quads * 6, 0, 0..1); + if quads > 0 { + pass.set_vertex_buffer(0, lists.entity_vertices.slice(..)); + pass.draw_indexed(0..quads * 6, 0, 0..1); + } // Before the GPU-posed outlines (`EntityBatch::append_shadow_only`). - let first = lists.outline_base - shadow_only * 4; - pass.draw_indexed(0..shadow_only * 6, first as i32, 0..1); + if shadow_only > 0 { + let first = lists.outline_base - shadow_only * 4; + let offset = u64::from(first) * std::mem::size_of::() as u64; + pass.set_vertex_buffer(0, lists.entity_vertices.slice(offset..)); + pass.draw_indexed(0..shadow_only * 6, 0, 0..1); + } } } } diff --git a/crates/horizon-client-render/src/graphics.rs b/crates/horizon-client-render/src/graphics.rs index fc44f20..df8cc99 100644 --- a/crates/horizon-client-render/src/graphics.rs +++ b/crates/horizon-client-render/src/graphics.rs @@ -310,8 +310,10 @@ impl GraphicsApi { pub fn label(self) -> &'static str { match self { GraphicsApi::Auto => "Auto", + GraphicsApi::Vulkan if cfg!(target_arch = "wasm32") => "WebGPU", GraphicsApi::Vulkan => "Vulkan", GraphicsApi::Dx12 => "DirectX 12", + GraphicsApi::OpenGl if cfg!(target_arch = "wasm32") => "WebGL2", GraphicsApi::OpenGl => "OpenGL", } } diff --git a/crates/horizon-client-render/src/hdr_stats.wgsl b/crates/horizon-client-render/src/hdr_stats.wgsl index 36b6cf5..b11f36e 100644 --- a/crates/horizon-client-render/src/hdr_stats.wgsl +++ b/crates/horizon-client-render/src/hdr_stats.wgsl @@ -20,6 +20,7 @@ struct Params { // threshold lies, for bright parts and for all over (hdr.rs `Masks`). parts: f32, whole: f32, + _pad: vec2, }; @group(0) @binding(8) var params: Params; diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index f66dadf..ec72648 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -10264,6 +10264,10 @@ impl Game<'_> { self.observe_fullscreen(); } WindowEvent::Focused(focused) => { + #[cfg(target_arch = "wasm32")] + if !focused && horizon_os::web::touch_active() { + return Ok(()); + } self.focused = focused; self.focus_lost = (!focused).then(Instant::now); if focused { @@ -10660,8 +10664,21 @@ impl Game<'_> { match self.screen { Screen::Playing => { if pressed && !self.captured { - self.capture(true); - return Ok(()); + #[cfg(target_arch = "wasm32")] + if horizon_os::web::touch_active() { + self.focused = true; + self.focus_lost = None; + self.captured = true; + self.capture_mode = Some(CursorGrabMode::Locked); + } else { + self.capture(true); + return Ok(()); + } + #[cfg(not(target_arch = "wasm32"))] + { + self.capture(true); + return Ok(()); + } } self.extras_mouse(button, pressed); if pressed @@ -11074,6 +11091,15 @@ impl Game<'_> { let PhysicalKey::Code(key) = event.physical_key else { return Ok(()); }; + #[cfg(target_arch = "wasm32")] + if event.state == ElementState::Pressed && horizon_os::web::touch_active() { + self.focused = true; + self.focus_lost = None; + if self.screen == Screen::Playing && !self.screen_over_playing() { + self.captured = true; + self.capture_mode = Some(CursorGrabMode::Locked); + } + } self.native_key_event(key, event.state == ElementState::Pressed, event.repeat); // Screen.keyPressed sees the physical key, repeats included. if event.state == ElementState::Pressed diff --git a/crates/horizon-client/src/game/integrated.rs b/crates/horizon-client/src/game/integrated.rs index 196f65a..f0bf650 100644 --- a/crates/horizon-client/src/game/integrated.rs +++ b/crates/horizon-client/src/game/integrated.rs @@ -144,6 +144,15 @@ impl Integrated { } })); } + #[cfg(target_arch = "wasm32")] + pub(super) fn flush_export_save(&self) { + let _ = self.tasks.send(Box::new(|g| { + if horizon_os::web::take_export_save() { + log::info!("Saving game for world export..."); + let _ = g.save_game_with(true); + } + })); + } /// The generator of the server's level in `dimension`, once it has run. pub fn terrain( &self, @@ -803,6 +812,11 @@ impl Game<'_> { self.experience.total = 37; panic!("integrated tick fixture"); } + #[cfg(target_arch = "wasm32")] + if horizon_os::web::take_export_save() { + log::info!("Saving game for world export..."); + self.save_game_with(true)?; + } if paused && !was_paused { // IntegratedServer.tickServer: the tick the game pauses saves // everything (saveEverything, without flushing), as an diff --git a/crates/horizon-client/src/game/loading_screen.rs b/crates/horizon-client/src/game/loading_screen.rs index 20c2a94..dd24567 100644 --- a/crates/horizon-client/src/game/loading_screen.rs +++ b/crates/horizon-client/src/game/loading_screen.rs @@ -92,8 +92,8 @@ impl Loading { return; } // The Window constructor: created fullscreen when options.txt or --fullscreen says so. - let fullscreen = - self.settings.fullscreen || self.options.as_ref().is_some_and(|o| o.fullscreen); + let fullscreen = !cfg!(target_arch = "wasm32") + && (self.settings.fullscreen || self.options.as_ref().is_some_and(|o| o.fullscreen)); let size = self .options .as_ref() diff --git a/crates/horizon-client/src/game/options.rs b/crates/horizon-client/src/game/options.rs index d75fb08..6454d29 100644 --- a/crates/horizon-client/src/game/options.rs +++ b/crates/horizon-client/src/game/options.rs @@ -226,6 +226,9 @@ impl Game<'_> { } })); } + if cfg!(target_arch = "wasm32") { + return; + } let Some(window) = &self.window else { return; }; @@ -531,7 +534,7 @@ impl Game<'_> { /// the compositor set up. fn apply_fullscreen(&mut self) { // A splitscreen guest draws in a window it shares: its option never changes the window. - if self.options.split_guest { + if cfg!(target_arch = "wasm32") || self.options.split_guest { return; } if let Some(w) = self.window.clone() { @@ -652,6 +655,9 @@ impl Game<'_> { pub(super) fn observe_fullscreen(&mut self) { // HDR calibration's own fullscreen is not the player's option: it // goes back to what it was when the calibration ends. + if cfg!(target_arch = "wasm32") { + return; + } if self.ui.options.calibration_window.is_some() { return; } @@ -670,6 +676,13 @@ impl Game<'_> { pub(super) fn toggle_fullscreen(&mut self) { // Splitscreen: another player's F11 toggles the window it plays in, kept out of its // options (a profile that saved it would turn the next window fullscreen on joining). + if cfg!(target_arch = "wasm32") { + if self.settings.fullscreen { + self.settings.fullscreen = false; + self.settings.save(&Self::options_path()); + } + return; + } if self.options.split_guest { // Window 1 is P1's: its fullscreen follows P1's option, not a guest's key. if self.options.split_in_main_window { diff --git a/crates/horizon-client/src/game/pointer_capture.rs b/crates/horizon-client/src/game/pointer_capture.rs index cfe3054..b351ce4 100644 --- a/crates/horizon-client/src/game/pointer_capture.rs +++ b/crates/horizon-client/src/game/pointer_capture.rs @@ -20,7 +20,25 @@ impl Game<'_> { /// `MouseHandler.handleAccumulatedMovement` and `Entity.turn`, once per frame. /// An agent moving the mouse (`mouse-move`) counts as a grabbed pointer in /// an active window, as it cannot grab the real one. + #[cfg(target_arch = "wasm32")] + pub(super) fn apply_queued_touch_look(&mut self) { + if let Some((dx, dy)) = horizon_os::web::take_touch_look() + && self.screen == Screen::Playing + && (self.player.is_some() || self.studio.flying()) + && !self.screen_over_playing() + { + self.focused = true; + self.focus_lost = None; + self.captured = true; + self.capture_mode = Some(CursorGrabMode::Locked); + self.mouse.on_move(0.0, 0.0, 0.0, 0.0, true, true); + self.mouse.on_move(0.0, 0.0, dx, dy, true, true); + self.last_input = Instant::now(); + } + } pub(super) fn apply_mouse_look(&mut self) { + #[cfg(target_arch = "wasm32")] + self.apply_queued_touch_look(); let look = self.look_options(); let time = self.started.elapsed().as_secs_f64(); let pointer = self.captured || self.agent_pointer; @@ -81,6 +99,10 @@ impl Game<'_> { /// pauses the game. An open screen (books, signs, the pack prompt, a server /// dialog) stays instead of pausing (`Gui.setPauseScreen`). pub(super) fn pause_if_inactive(&mut self) { + #[cfg(target_arch = "wasm32")] + if horizon_os::web::touch_active() { + return; + } if self .focus_lost .is_some_and(|t| t.elapsed() > Duration::from_millis(500)) @@ -141,14 +163,22 @@ impl Game<'_> { // MouseHandler.grabMouse never captures an inactive window, and vanilla // grabs only on `setScreen(null)`: the pack prompt and server dialogs // are screens over the world that keep the pointer. + #[cfg(target_arch = "wasm32")] + let touch = horizon_os::web::touch_active(); + #[cfg(not(target_arch = "wasm32"))] + let touch = false; if capture - && ((!self.focused && !self.unclaimed_window && !self.scripted_run()) + && ((!self.focused && !touch && !self.unclaimed_window && !self.scripted_run()) || self.server_packs.prompt.is_some() || self.dialog_open() || self.command_prompt.is_some()) { return; } + if capture && touch { + self.focused = true; + self.focus_lost = None; + } // The container screen's press state belongs to the screen: a screen // that takes the pointer over starts with its own state, as // `AbstractContainerScreen` does, so a press whose release never @@ -213,7 +243,9 @@ impl Game<'_> { // winit's request throws through the frame when the browser refuses it. #[cfg(target_arch = "wasm32")] { - horizon_os::web::pointer_lock(true); + if !horizon_os::web::touch_active() { + horizon_os::web::pointer_lock(true); + } self.capture_mode = Some(CursorGrabMode::Locked); self.captured = true; } diff --git a/crates/horizon-client/src/game/startup_menu.rs b/crates/horizon-client/src/game/startup_menu.rs index ea6a9ed..4346c78 100644 --- a/crates/horizon-client/src/game/startup_menu.rs +++ b/crates/horizon-client/src/game/startup_menu.rs @@ -1227,7 +1227,9 @@ impl Loading { } } WindowEvent::KeyboardInput { event, .. } if event.state == ElementState::Pressed => { - if event.physical_key == PhysicalKey::Code(KeyCode::F11) { + if !cfg!(target_arch = "wasm32") + && event.physical_key == PhysicalKey::Code(KeyCode::F11) + { self.settings.fullscreen = !self.settings.fullscreen; self.apply_menu_settings(); self.save_menu_settings(); diff --git a/crates/horizon-client/src/game/window_handler.rs b/crates/horizon-client/src/game/window_handler.rs index e867bc4..58c9403 100644 --- a/crates/horizon-client/src/game/window_handler.rs +++ b/crates/horizon-client/src/game/window_handler.rs @@ -305,11 +305,39 @@ impl Game<'_> { return; } horizon_client::spans::time("pads", || self.poll_pads(event_loop)); + #[cfg(target_arch = "wasm32")] + { + self.apply_queued_touch_look(); + if horizon_os::web::take_prepare_export() { + if self.integrated.is_some() { + if self.screen == Screen::Playing + && self.player.is_some() + && !self.screen_over_playing() + { + self.pause_focus = None; + self.screen = Screen::Paused; + self.capture(false); + if let Some(server) = &self.integrated { + server.set_paused(true); + } + } + if let Some(server) = &self.integrated { + server.flush_export_save(); + } + } else { + let _ = horizon_os::web::take_export_save(); + if self.remote.is_none() && !self.world_root.as_os_str().is_empty() { + let _ = self.save_game_with(true); + } + } + } + } self.settle_after_run(event_loop); self.pause_if_inactive(); // Escape releases the browser's pointer lock and never reaches the page. #[cfg(target_arch = "wasm32")] if horizon_os::web::pointer_lock_lost() + && !horizon_os::web::touch_active() && self.screen == Screen::Playing && self.player.is_some() && let Err(error) = self.key_pressed(KeyCode::Escape, KeyCode::Escape) @@ -377,7 +405,8 @@ impl ApplicationHandler for Game<'_> { } debug_keys::warm_debug_cpu(); // The Window constructor: created fullscreen when options.txt or --fullscreen says so. - let fullscreen = self.settings.fullscreen || self.options.fullscreen; + let fullscreen = + !cfg!(target_arch = "wasm32") && (self.settings.fullscreen || self.options.fullscreen); let size = self.options.window_size.map(f64::from); self.fullscreen = horizon_client::window::FullscreenState::new(fullscreen); let attributes = diff --git a/crates/horizon-os/src/fs.rs b/crates/horizon-os/src/fs.rs index 39b7913..dfbac00 100644 --- a/crates/horizon-os/src/fs.rs +++ b/crates/horizon-os/src/fs.rs @@ -121,7 +121,7 @@ export function horizon_fetch_sync(url) { /// Scratch files and the prepared resources aren't the player's: they stay /// out of the browser's storage. fn persisted(key: &str) -> bool { - !["/tmp", "/.local"] + !["/tmp", "/.local", "/.horizon-cache", "/logs", "/crash-reports"] .iter() .any(|root| key == *root || key.starts_with(&format!("{root}/"))) } diff --git a/crates/horizon-os/src/web.rs b/crates/horizon-os/src/web.rs index 799e6e4..06bfe10 100644 --- a/crates/horizon-os/src/web.rs +++ b/crates/horizon-os/src/web.rs @@ -1,7 +1,10 @@ //! The page's side of the game: what the page calls before and to start the //! game, and where the log and panics go (the browser's console). -use std::sync::Mutex; +use std::sync::{ + Mutex, + atomic::{AtomicBool, AtomicU8, Ordering}, +}; use wasm_bindgen::prelude::*; #[wasm_bindgen(inline_js = r#" @@ -126,15 +129,23 @@ function lock(canvas) { // Asked at every mouse motion (hundreds to thousands a second with a fast // mouse): kept from the lock's events, not looked up each time. let lockedCanvas = false; +let touchActive = false; if (typeof document !== "undefined") { document.addEventListener("pointerlockchange", () => { lockedCanvas = !!document.pointerLockElement && document.pointerLockElement === document.querySelector("canvas"); + if (lockedCanvas) touchActive = false; }); } export function horizon_pointer_locked() { return lockedCanvas; } +export function horizon_js_touch_active() { + return touchActive && !(typeof document !== "undefined" && document.hidden); +} +export function horizon_js_mark_touch() { + touchActive = true; +} export function horizon_pointer_lock(want) { wantLock = want; const canvas = document.querySelector("canvas"); @@ -151,9 +162,17 @@ export function horizon_pointer_lock(want) { // Browsers refuse the lock asked with Escape (no user gesture), and for // a moment after Escape let it go: the game then waits for the next // click or key. The click that takes the lock only takes the lock, so - // it doesn't swing a sword. + // it doesn't swing a sword. Touch and synthetic events bypass Pointer Lock. let swallowUp = false; window.addEventListener("pointerdown", (e) => { + if (e.pointerType === "touch" || !e.isTrusted) { + touchActive = true; + swallowUp = false; + return; + } + if (e.pointerType === "mouse") { + touchActive = false; + } if (wantLock && e.target === canvas && document.pointerLockElement !== canvas) { lock(canvas); swallowUp = true; @@ -161,17 +180,31 @@ export function horizon_pointer_lock(want) { } }, true); window.addEventListener("pointerup", (e) => { + if (e.pointerType === "touch" || !e.isTrusted) { + touchActive = true; + swallowUp = false; + return; + } if (swallowUp) { swallowUp = false; e.stopImmediatePropagation(); } }, true); + window.addEventListener("touchstart", () => { + touchActive = true; + }, { capture: true, passive: true }); window.addEventListener("keydown", (e) => { - if (wantLock && e.key !== "Escape" && document.pointerLockElement !== canvas) lock(canvas); + if (!e.isTrusted) { + touchActive = true; + return; + } + if (wantLock && !touchActive && e.key !== "Escape" && document.pointerLockElement !== canvas) { + lock(canvas); + } }, true); } if (want) { - if (document.pointerLockElement !== canvas) lock(canvas); + if (!touchActive && document.pointerLockElement !== canvas) lock(canvas); } else if (document.pointerLockElement) { document.exitPointerLock(); } @@ -234,6 +267,8 @@ extern "C" { fn horizon_pointer_lock(want: bool); fn horizon_pointer_lock_lost() -> bool; fn horizon_pointer_locked() -> bool; + fn horizon_js_touch_active() -> bool; + fn horizon_js_mark_touch(); } static START: Mutex> = Mutex::new(None); @@ -455,3 +490,71 @@ pub fn set_status(status: String) { pub fn horizon_status() -> String { STATUS.with(|s| s.borrow().clone()) } + +static TOUCH_LOOK: Mutex<(f64, f64)> = Mutex::new((0.0, 0.0)); +static GRAPHICS_BACKEND: AtomicU8 = AtomicU8::new(0); +static PREPARE_EXPORT_UI: AtomicBool = AtomicBool::new(false); +static PREPARE_EXPORT_SERVER: AtomicBool = AtomicBool::new(false); + +/// Queues relative camera look deltas `(dx, dy)` from touch controls without +/// requiring browser Pointer Lock, and marks touch-control input active. +#[wasm_bindgen] +pub fn horizon_touch_look(dx: f64, dy: f64) { + horizon_js_mark_touch(); + if !dx.is_finite() || !dy.is_finite() { + return; + } + let mut pending = crate::sync::lock(&TOUCH_LOOK).unwrap_or_else(|e| e.into_inner()); + pending.0 += dx; + pending.1 += dy; +} + +/// Takes the accumulated touch-look delta queued since the last call. +pub fn take_touch_look() -> Option<(f64, f64)> { + let mut pending = crate::sync::lock(&TOUCH_LOOK).unwrap_or_else(|e| e.into_inner()); + let (dx, dy) = *pending; + *pending = (0.0, 0.0); + (dx != 0.0 || dy != 0.0).then_some((dx, dy)) +} + +/// Whether touch or synthetic touch-control input is currently driving the game. +pub fn touch_active() -> bool { + horizon_js_touch_active() +} + +/// Records the active wgpu backend once the renderer opens an adapter/device. +pub fn set_graphics_backend(name: &str) { + let code = match name { + "WebGPU" => 1, + "WebGL2" => 2, + _ => 0, + }; + GRAPHICS_BACKEND.store(code, Ordering::Release); +} + +/// Returns `"WebGPU"`, `"WebGL2"`, or `""` before renderer initialization completes. +#[wasm_bindgen] +pub fn horizon_graphics_backend() -> String { + match GRAPHICS_BACKEND.load(Ordering::Acquire) { + 1 => "WebGPU".to_owned(), + 2 => "WebGL2".to_owned(), + _ => String::new(), + } +} + +/// Requests an immediate singleplayer save/pause flush on the next idle/tick. +#[wasm_bindgen] +pub fn horizon_prepare_export() { + PREPARE_EXPORT_SERVER.store(true, Ordering::Release); + PREPARE_EXPORT_UI.store(true, Ordering::Release); +} + +/// Takes a pending UI-side export preparation request. +pub fn take_prepare_export() -> bool { + PREPARE_EXPORT_UI.swap(false, Ordering::AcqRel) +} + +/// Takes a pending server-side world-save flush request. +pub fn take_export_save() -> bool { + PREPARE_EXPORT_SERVER.swap(false, Ordering::AcqRel) +} diff --git a/crates/horizon-threads/src/lib.rs b/crates/horizon-threads/src/lib.rs index 234a4ea..ed84ac9 100644 --- a/crates/horizon-threads/src/lib.rs +++ b/crates/horizon-threads/src/lib.rs @@ -41,7 +41,10 @@ pub fn worker_count() -> usize { 0 => { let count = parse_worker_count(std::env::var("HORIZON_WORKER_THREADS").ok()) .unwrap_or_else(|| { - horizon_os::thread::available_parallelism().map_or(1, |n| n.get()) + let count = horizon_os::thread::available_parallelism().map_or(1, |n| n.get()); + #[cfg(target_arch = "wasm32")] + let count = count.clamp(2, 6); + count }); match COUNT.compare_exchange(0, count, Ordering::Relaxed, Ordering::Relaxed) { Ok(_) => count, @@ -800,6 +803,8 @@ mod tests { return; } let machine = horizon_os::thread::available_parallelism().map_or(1, |n| n.get()); + #[cfg(target_arch = "wasm32")] + let machine = machine.clamp(2, 6); assert_eq!(super::worker_count(), machine); } diff --git a/crates/horizon-world/src/registry.rs b/crates/horizon-world/src/registry.rs index 87f81cb..55cba6d 100644 --- a/crates/horizon-world/src/registry.rs +++ b/crates/horizon-world/src/registry.rs @@ -298,16 +298,23 @@ impl BlockRegistry { pub fn resolve(&self, descriptor: &BlockState) -> io::Result { let default = self .default_state(&descriptor.name) - .ok_or_else(|| invalid("unknown block name"))?; + .ok_or_else(|| invalid(format!("unknown block name {}", descriptor.name)))?; let mut state = self.state(default).unwrap().clone(); for (key, value) in &descriptor.properties { if !state.properties.contains_key(key) { - return Err(invalid("unknown block property")); + return Err(invalid(format!( + "unknown block property {}[{key}={value}]", + descriptor.name + ))); } state.properties.insert(key.clone(), value.clone()); } - self.id(&state) - .ok_or_else(|| invalid("invalid block property value")) + self.id(&state).ok_or_else(|| { + invalid(format!( + "invalid block property value {}{:?}", + descriptor.name, descriptor.properties + )) + }) } }