(wad_path: PathBuf, guest_path: PathBuf)
| 26 | |
| 27 | impl Runtime { |
| 28 | pub fn new(wad_path: PathBuf, guest_path: PathBuf) -> Result<Self> { |
| 29 | let module = tinywasm::parse_file(&guest_path)?; |
| 30 | let mut store = Store::default(); |
| 31 | let host_state = Rc::new(RefCell::new(HostState::new(wad_path))); |
| 32 | let imports = build_imports(&mut store, host_state.clone()); |
| 33 | let instance = ModuleInstance::instantiate(&mut store, &module, Some(imports))?; |
| 34 | |
| 35 | let wad_path_buf = instance.func::<(), i32>(&store, "tinywasm_doom_wad_path_buf")?; |
| 36 | let init = instance.func::<(), ()>(&store, "tinywasm_doom_init")?; |
| 37 | let update = instance.func::<(), ()>(&store, "tinywasm_doom_update")?; |
| 38 | let framebuffer = instance.func::<(), i32>(&store, "tinywasm_doom_framebuffer")?; |
| 39 | let key_down = instance.func::<i32, ()>(&store, "tinywasm_doom_key_down")?; |
| 40 | let key_up = instance.func::<i32, ()>(&store, "tinywasm_doom_key_up")?; |
| 41 | let memory = instance.memory("memory")?; |
| 42 | |
| 43 | let buf_ptr = wad_path_buf.call(&mut store, ())? as usize; |
| 44 | let wad_path_string = host_state.borrow().wad_path.to_string_lossy().into_owned(); |
| 45 | memory.write_cstring_bytes(&mut store, buf_ptr, &wad_path_string)?; |
| 46 | init.call(&mut store, ())?; |
| 47 | |
| 48 | let width = SCREEN_WIDTH; |
| 49 | let height = SCREEN_HEIGHT; |
| 50 | |
| 51 | Ok(Self { |
| 52 | store, |
| 53 | update, |
| 54 | framebuffer, |
| 55 | key_down, |
| 56 | key_up, |
| 57 | memory, |
| 58 | framebuffer_bytes: vec![0; width * height * 4], |
| 59 | host_state, |
| 60 | }) |
| 61 | } |
| 62 | |
| 63 | pub fn tick(&mut self) -> Result<()> { |
| 64 | self.update.call(&mut self.store, ())?; |
nothing calls this directly
no test coverage detected