diff options
author | Matthew Michelotti <michelotti.matthew@gmail.com> | 2018-06-02 21:17:03 -0500 |
---|---|---|
committer | Matthew Michelotti <michelotti.matthew@gmail.com> | 2018-06-02 21:17:03 -0500 |
commit | f995f0469197aba24fa31843ab3cd1526da1e0ed (patch) | |
tree | bdc1da26f7929028676e9bc2693bb92ff41313c6 | |
parent | 9e8dc0f6fd7374f7466427da57443537d36b9eb5 (diff) |
clearing pressed keys after a restart in gate.js
-rw-r--r-- | gate/src/core/wasm/mod.rs | 9 | ||||
-rw-r--r-- | gate/src/core/wasm/wasm_exports.rs | 5 | ||||
-rw-r--r-- | gate_build/src/html/gate.js | 3 |
3 files changed, 16 insertions, 1 deletions
diff --git a/gate/src/core/wasm/mod.rs b/gate/src/core/wasm/mod.rs index 15e1430..c71c97d 100644 --- a/gate/src/core/wasm/mod.rs +++ b/gate/src/core/wasm/mod.rs @@ -60,6 +60,7 @@ trait TraitAppRunner { fn input(&mut self, key: KeyCode, down: bool) -> bool; fn music_count(&self) -> u16; fn sound_count(&self) -> u16; + fn on_restart(&mut self); } struct StaticAppRunner { r: RefCell<Option<Box<TraitAppRunner>>> } @@ -110,6 +111,7 @@ impl<AS: AppAssetId, AP: App<AS>> TraitAppRunner for AppRunner<AS, AP> { let renderer = self.renderer.as_ref().unwrap(); self.ctx.set_dims(renderer.app_dims(), renderer.native_px()); self.app.start(&mut self.ctx); + assert!(!self.ctx.take_close_request(), "unexpected close immediately upon start"); } fn resize(&mut self, dims: (u32, u32)) { @@ -152,6 +154,13 @@ impl<AS: AppAssetId, AP: App<AS>> TraitAppRunner for AppRunner<AS, AP> { fn music_count(&self) -> u16 { AS::Music::count() } fn sound_count(&self) -> u16 { AS::Sound::count() } + + fn on_restart(&mut self) { + for key in self.held_keys.drain() { + self.app.key_up(key, &mut self.ctx); + } + assert!(!self.ctx.take_close_request(), "unexpected close immediately upon restart"); + } } pub fn run<AS: 'static + AppAssetId, AP: 'static + App<AS>>(info: AppInfo, app: AP) { diff --git a/gate/src/core/wasm/wasm_exports.rs b/gate/src/core/wasm/wasm_exports.rs index 49557b5..7681099 100644 --- a/gate/src/core/wasm/wasm_exports.rs +++ b/gate/src/core/wasm/wasm_exports.rs @@ -87,3 +87,8 @@ pub unsafe extern "C" fn gateWasmSpriteVertSrc() -> *const c_char { pub unsafe extern "C" fn gateWasmSpriteFragSrc() -> *const c_char { shaders::FS_SPRITE_SRC } + +#[no_mangle] +pub unsafe extern "C" fn gateWasmOnRestart() { + app_runner_borrow_mut().on_restart(); +} diff --git a/gate_build/src/html/gate.js b/gate_build/src/html/gate.js index 1d1e872..262debb 100644 --- a/gate_build/src/html/gate.js +++ b/gate_build/src/html/gate.js @@ -161,6 +161,7 @@ function gate(canvas, wasmFilePath, onQuit) { Module.gateWasmSoundCount = mod.exports.gateWasmSoundCount; Module.gateWasmSpriteVertSrc = mod.exports.gateWasmSpriteVertSrc; Module.gateWasmSpriteFragSrc = mod.exports.gateWasmSpriteFragSrc; + Module.gateWasmOnRestart = mod.exports.gateWasmOnRestart; tryStart(); }); @@ -343,7 +344,7 @@ function gate(canvas, wasmFilePath, onQuit) { if (Module.currentMusic != null) { Module.currentMusic.play(); } - // TODO notify app of all keys that were released after the app was quit... + Module.gateWasmOnRestart(); } } }; |