Skip to content

Commit

Permalink
fix: fixed wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
lukexor committed Nov 11, 2024
1 parent 37cbbd5 commit 84e02c9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
1 change: 1 addition & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ with (import <nixpkgs> {
];
targets = ["wasm32-unknown-unknown"];
}))
trunk
udev
];

Expand Down
6 changes: 5 additions & 1 deletion tetanes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ tracing.workspace = true
tracing-subscriber.workspace = true
uuid = { version = "1.10", features = ["v4", "fast-rng", "serde"] }
webbrowser = { version = "1.0", features = ["hardened", "disable-wsl"] }
wgpu = { version = "23.0", features = ["webgl", "webgpu"] }
wgpu = { version = "23.0", features = [
"webgl",
"webgpu",
"fragile-send-sync-non-atomic-wasm", # Safe because we're not enabling atomics
] }
winit = { version = "0.30", features = ["serde"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
Expand Down
27 changes: 9 additions & 18 deletions tetanes/src/nes/renderer/gui/ppu_viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,6 @@ impl PpuViewer {

let open = Arc::clone(&self.open);
let state = Arc::clone(&self.state);
// let Some(cfg) = self.resources.take() else {
// warn!("PpuViewer::prepare was not called with required resources");
// return;
// };

let mut viewport_builder = egui::ViewportBuilder::default()
.with_title(Self::TITLE)
Expand All @@ -357,20 +353,15 @@ impl PpuViewer {
viewport_builder = viewport_builder.with_always_on_top();
}

ctx.show_viewport_deferred(self.id, viewport_builder, move |ctx, class| {
if class == ViewportClass::Embedded {
let mut window_open = open.load(Ordering::Acquire);
egui::Window::new(PpuViewer::TITLE)
.open(&mut window_open)
.show(ctx, |ui| state.lock().ui(ui, opts.enabled));
open.store(window_open, Ordering::Release);
} else {
CentralPanel::default().show(ctx, |ui| state.lock().ui(ui, opts.enabled));
if ctx.input(|i| i.viewport().close_requested()) {
open.store(false, Ordering::Release);
}
}
});
let show_viewport = move |ctx: &Context, _: ViewportClass| {
let mut window_open = open.load(Ordering::Acquire);
egui::Window::new(PpuViewer::TITLE)
.open(&mut window_open)
.show(ctx, |ui| state.lock().ui(ui, opts.enabled));
open.store(window_open, Ordering::Release);
};

ctx.show_viewport_deferred(self.id, viewport_builder, show_viewport);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tetanes/src/sys/platform/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ pub mod renderer {
(viewport_ui_cb, raw_input.take())
};

let mut output = ctx.run(raw_input, |ctx| match viewport_ui_cb {
let mut output = ctx.run(raw_input, |ctx| match &viewport_ui_cb {
Some(viewport_ui_cb) => viewport_ui_cb(ctx),
None => gui.borrow_mut().ui(ctx, None),
});
Expand Down

0 comments on commit 84e02c9

Please sign in to comment.