Skip to content

Commit

Permalink
Get wasm building
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy-xr committed Jun 9, 2024
1 parent 7334025 commit d39cf15
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 36 deletions.
5 changes: 0 additions & 5 deletions runtime/functor-runtime-desktop/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,6 @@ pub fn main() {

gl.enable(glow::DEPTH_TEST);

let init_ctx = functor_runtime_common::RenderContext {
gl: &gl,
shader_version,
};

let projection_matrix: Matrix4<f32> =
perspective(Deg(45.0), SCR_WIDTH as f32 / SCR_HEIGHT as f32, 0.1, 100.0);

Expand Down
47 changes: 17 additions & 30 deletions runtime/functor-runtime-web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ async fn run_async() -> Result<(), JsValue> {
.expect("performance should be available");

let mut i = 0;

let initial_time = performance.now() as f32;
let mut last_time = initial_time;

*g.borrow_mut() = Some(Closure::new(move || {
// let matrix: Matrix4<f32> = Matrix4::from_nonuniform_scale(1.0, 2.5, 1.0);

Expand All @@ -158,14 +162,10 @@ async fn run_async() -> Result<(), JsValue> {
shader_version,
};

let mut basic_material = BasicMaterial::create();
basic_material.initialize(&render_ctx);

let projection_matrix: Matrix4<f32> =
perspective(Deg(45.0), SCR_WIDTH as f32 / SCR_HEIGHT as f32, 0.1, 100.0);

let world_matrix = Matrix4::from_nonuniform_scale(1.0, 1.0, 1.0);
let skinning_data: Vec<Matrix4<f32>> = vec![];

gl.clear(glow::COLOR_BUFFER_BIT | glow::DEPTH_BUFFER_BIT);
let radius = 5.0;
Expand All @@ -178,40 +178,27 @@ async fn run_async() -> Result<(), JsValue> {
vec3(0.0, 1.0, 0.0),
);

basic_material.draw_opaque(
&render_ctx,
&projection_matrix,
&view_matrix,
&world_matrix,
&skinning_data,
);

// let scene = Scene3D::cube();

let now = performance.now() as f32;
let frameTime = FrameTime {
dts: 99.0,
tts: 100.0,
dts: (now - last_time) / 1000.0,
tts: (now - initial_time) / 1000.0,
};
last_time = now;

let val = game_render(functor_runtime_common::to_js_value(&frameTime));
web_sys::console::log_2(&JsValue::from_str("calling render"), &val);

let scene = functor_runtime_common::from_js_value(val);

match scene {
Scene3D::Cube => {
let mut cube = functor_runtime_common::geometry::Cube::create();
cube.draw(&gl);
}
Scene3D::Cylinder => {
let mut cylinder = functor_runtime_common::geometry::Cylinder::create();
cylinder.draw(&gl);
}
Scene3D::Sphere => {
let mut sphere = functor_runtime_common::geometry::Sphere::create();
sphere.draw(&gl);
}
}
let scene: Scene3D = functor_runtime_common::from_js_value(val);

functor_runtime_common::Scene3D::render(
&scene,
&render_ctx,
&world_matrix,
&projection_matrix,
&view_matrix,
);

// Schedule ourself for another requestAnimationFrame callback.
request_animation_frame(f.borrow().as_ref().unwrap());
Expand Down
2 changes: 1 addition & 1 deletion src/Functor.Game/Runtime.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module Runtime
[<Erase; Emit("JsValue")>] type JsValue = | Noop

module UnsafeJsValue =
[<Emit("functor_runtime_common::to_js_value($0)")>]
[<Emit("functor_runtime_common::to_js_value(&$0)")>]
let to_js<'a>(obj): JsValue = nativeOnly
// let from_js<'a>(jsValue: JsValue): 'a = nativeOnly

Expand Down

0 comments on commit d39cf15

Please sign in to comment.