Skip to content

Instantly share code, notes, and snippets.

@randomPoison
Created July 30, 2020 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save randomPoison/2cf4d81efa9c444801fe4912e46d5a71 to your computer and use it in GitHub Desktop.
Save randomPoison/2cf4d81efa9c444801fe4912e46d5a71 to your computer and use it in GitHub Desktop.
#[wasm_bindgen]
pub struct MyEmulator {
// Put any state that needs to persist between frames.
}
#[wasm_bindgen]
impl MyEmulator {
#[wasm_bindgen(constructor)]
pub fn new() -> Self {
// ...
}
pub fn do_one_frame(&mut self) {
// Perform any necessary simulation for one frame.
}
}
import { MyEmulator } from './emulator';
let emulator = new MyEmulator();
function step(timestamp) {
emulator.do_one_frame();
window.requestAnimationFrame(step);
}
window.requestAnimationFrame(step);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment