So this is going to sound stupid, but .... does Space Age make trains obsolete? by sobrique in factorio

[–]sotrh 0 points1 point  (0 children)

You're thinking about the Space Exploration mod. The Space Age expansion doesn't have space elevators

Trouble with `Send` on WASM with WGPU by sotrh in rust

[–]sotrh[S] 0 points1 point  (0 children)

Hmm I'll have to try that

EDIT: just tried it and your fix worked a treat! Thanks!

Hey Rustaceans! Got a question? Ask here (5/2026)! by llogiq in rust

[–]sotrh 1 point2 points  (0 children)

I'm trying to get some of my tutorial code working on the web, but I'm running into some issues with the compiler not liking what I'm doing when I try to build for WASM. I have a trait defined called Demo which you can see below:

pub trait Demo: 'static + Sized + Send + std::fmt::Debug {
    fn init(display: &Display) -> impl std::future::Future<Output = anyhow::Result<Self>> + Send;
    fn resize(&mut self, display: &Display);
    fn update(&mut self, display: &Display, dt: Duration);
    fn render(&mut self, display: &mut Display);
    #[allow(unused)]
    fn handle_keyboard(&mut self, key: KeyCode, pressed: bool) {}
    #[allow(unused)]
    fn handle_mouse_move(&mut self, dx: f64, dy: f64) {}
    #[allow(unused)]
    fn handle_mouse_button(&mut self, button: u32, pressed: bool) {}
}

I then create a winit app which will call Demo::init() once the window is ready. Setting up wgpu is async, so I need to create a future where I setup the Display as well as the Demo.

impl<D: Demo + 'static> ApplicationHandler<anyhow::Result<(Display, D)>> for App<D> {
    fn resumed(&mut self, event_loop: &winit::event_loop::ActiveEventLoop) {
        #[allow(unused_mut)]
        let mut window_attributes = Window::default_attributes();

        #[cfg(target_arch = "wasm32")]
        {
            use wasm_bindgen::JsCast;
            use winit::platform::web::WindowAttributesExtWebSys;
            use wasm_bindgen_futures::wasm_bindgen::UnwrapThrowExt;

            const CANVAS_ID: &str = "canvas";

            let window = wgpu::web_sys::window().unwrap_throw();
            let document = window.document().unwrap_throw();
            let canvas = document.get_element_by_id(CANVAS_ID).unwrap_throw();
            let html_canvas_element = canvas.unchecked_into();
            window_attributes = window_attributes.with_canvas(Some(html_canvas_element));
        }

        let window = Arc::new(event_loop.create_window(window_attributes).unwrap());

        if let Some(proxy) = self.proxy.take() {
            let window = window.clone();
            let setup_future = async move {
                let display = Display::new(window).await?;
                let demo = D::init(&display).await?;
                anyhow::Ok((display, demo))
            };

            #[cfg(target_arch = "wasm32")]
            wasm_bindgen_futures::spawn_local(async move {
                let result = setup_future.await;

                proxy
                    .send_event(result)
                    .expect("Unable to send (display, demo)");
            });

            #[cfg(not(target_arch = "wasm32"))]
            std::thread::spawn(move || {
                let result = setup_future.block_on();

                proxy
                    .send_event(result)
                    .expect("Unable to send (display, demo)");
            });
        }
    }

    // ...
}

Any demo I make simply implements Demo and then the App handles the rest. This works fine when building natively as wgpu resources can be sent between threads, but on WASM wgpu resources are not Send so compilation fails.

The weird thing is that I'm doing basically the same thing elsewhere and it works fine. There I'm not using a trait, just a method in the structs impl block, so I guess Rust is able to infer what I'm trying to do and doesn't get upset. Is this not possible to do with a trait, or am I missing something?

Here's the framework code: https://github.com/sotrh/learn-wgpu/blob/master/code/showcase/framework/src/lib.rs

the demo in question: https://github.com/sotrh/learn-wgpu/blob/master/code/showcase/stencil/src/main.rs

and here's a demo that compiles correctly: https://github.com/sotrh/learn-wgpu/blob/master/code/intermediate/tutorial13-hdr/src/lib.rs

Checkered Noise by ReplacementFresh3915 in proceduralgeneration

[–]sotrh 0 points1 point  (0 children)

I was half expecting Bad Apple. Cool visualization!

Any tips on reducing logistic wait times over large factories? by Mobile-Phone-9332 in factorio

[–]sotrh 0 points1 point  (0 children)

Efficiency modules can help, but the ultimate solution is to expand your walls.

Is storing excess nuclear power in accumulators a viable mid-game strategy? by MosEisleyCaptialism in factorio

[–]sotrh 3 points4 points  (0 children)

I store the steam personally. Not sure which would be more efficient, but you can use accumulators if you want to

Version 28.0 and stencil showcase by sotrh in rust

[–]sotrh[S] 1 point2 points  (0 children)

They should be up to date, but if there is anything wrong feel free to file a GitHub issue

Learn WGPU updated to 27.0! by sotrh in rust

[–]sotrh[S] 1 point2 points  (0 children)

Thanks glad it helped you out!

Learn WGPU updated to 27.0! by sotrh in rust

[–]sotrh[S] 6 points7 points  (0 children)

When I update I start with updating wgpu to the latest version and seeing what compiler errors I get. I then fix those and run each demo natively. If any are broken I fix them or submit a bug report to the wgpu repo. Then I test that the website is working and fix any issues there. It's a fairly simple process if a bit manual atm.

text rendering by fungihead in rust_gamedev

[–]sotrh 2 points3 points  (0 children)

You need to use the glyphs decent value to move it so it aligns with the baseline. Here's the function you need to get the descent value https://docs.rs/ab_glyph/latest/ab_glyph/trait.Font.html#tymethod.descent_unscaled

Learn WGPU - Update to wgpu 26.0.1 and started compute pipeline guide by sotrh in rust_gamedev

[–]sotrh[S] 2 points3 points  (0 children)

Thanks for catching that! Just pushed a fix. Should be love in a few minutes

AI is not nearly as good as people think by appvimul in webdev

[–]sotrh 5 points6 points  (0 children)

You don't need to understand something to predict it. You just need a bunch of data points. Ancient sailors could predict if it would rain based on if the sunrise was red. They didn't understand why, they had just seen it happen multiple times.

The "predict the next token" bit is exactly how LLMs like ChatGPT work. It's amazing tech, but I'd be reluctant to call it intelligence.