Skip to content

Commit

Permalink
Merge example and wasm scene
Browse files Browse the repository at this point in the history
  • Loading branch information
Speykious committed Feb 15, 2024
1 parent 8fcf30a commit 2205944
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 104 deletions.
4 changes: 4 additions & 0 deletions examples/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ edition = "2021"
[dependencies]
glam = "0.25.0"
inox2d = { path = "../../inox2d" }
tracing = "0.1.40"
winit = "0.29"

[target.'cfg(target_arch = "wasm32")'.dependencies]
web-time = "1.0.0"
4 changes: 4 additions & 0 deletions examples/common/src/scene.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
//! A nice scene controller to smoothly move around in the window.

#[cfg(not(target_arch = "wasm32"))]
use std::time::Instant;

#[cfg(target_arch = "wasm32")]
use web_time::Instant;

use glam::{vec2, Vec2};
use inox2d::math::camera::Camera;
use winit::event::{ElementState, MouseScrollDelta, WindowEvent};
Expand Down
3 changes: 1 addition & 2 deletions examples/render-webgl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ edition = "2021"
[dependencies]
inox2d = { path = "../../inox2d" }
inox2d-opengl = { path = "../../inox2d-opengl" }
common = { path = "../common" }

console_error_panic_hook = "0.1.7"
glam = "0.25.0"
glow = "0.13.1"
js-sys = "0.3.64"
reqwest = "0.11.18"
tracing = "0.1.37"
tracing-subscriber = "0.3.16"
tracing-wasm = "0.2.1"
wasm-bindgen = "0.2.87"
wasm-bindgen-futures = "0.4.37"
web-time = "1.0.0"
winit = "0.29"

[dependencies.web-sys]
Expand Down
11 changes: 3 additions & 8 deletions examples/render-webgl/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#[cfg(target_arch = "wasm32")]
mod scene;

#[cfg(target_arch = "wasm32")]
fn create_window(event: &winit::event_loop::EventLoop<()>) -> Result<winit::window::Window, winit::error::OsError> {
use winit::dpi::PhysicalSize;
Expand Down Expand Up @@ -54,7 +51,7 @@ async fn run() -> Result<(), Box<dyn std::error::Error>> {
use winit::event::{Event, WindowEvent};
use winit::platform::web::EventLoopExtWebSys;

use crate::scene::WasmSceneController;
use common::scene::ExampleSceneController;

let events = winit::event_loop::EventLoop::new().unwrap();
let window = create_window(&events)?;
Expand Down Expand Up @@ -99,7 +96,7 @@ async fn run() -> Result<(), Box<dyn std::error::Error>> {
renderer.camera.scale = Vec2::splat(0.15);
info!("Inox2D renderer initialized");

let scene_ctrl = WasmSceneController::new(&renderer.camera, 0.5);
let scene_ctrl = ExampleSceneController::new(&renderer.camera, 0.5);

// Refcells because we need to make our own continuous animation loop.
// Winit won't help us :(
Expand Down Expand Up @@ -149,9 +146,7 @@ async fn run() -> Result<(), Box<dyn std::error::Error>> {
window.request_redraw();
}
WindowEvent::CloseRequested => elwt.exit(),
_ => scene_ctrl
.borrow_mut()
.interact(&window, event, &renderer.borrow().camera),
_ => (scene_ctrl.borrow_mut()).interact(event, &renderer.borrow().camera),
},
Event::AboutToWait => {
window.request_redraw();
Expand Down
94 changes: 0 additions & 94 deletions examples/render-webgl/src/scene.rs

This file was deleted.

0 comments on commit 2205944

Please sign in to comment.