Add test fn to clear screens from js
All checks were successful
Build and Publish WASM version of demo / Build-And-Deploy-main (push) Has been skipped
Build and Publish WASM version of demo / Build-And-Deploy-devel (push) Successful in 26s

This commit is contained in:
Stephen Seo 2023-08-31 22:11:04 +09:00
parent 7ca57870eb
commit 6cbc044251
4 changed files with 21 additions and 0 deletions

View file

@ -21,3 +21,5 @@ void Game::update() {
}
void Game::draw() { screen_stack->draw(); }
void Game::clear_screens() { screen_stack->clear_screens(); }

View file

@ -22,6 +22,8 @@ class Game {
void update();
void draw();
void clear_screens();
private:
ScreenStack::Ptr screen_stack;
std::chrono::steady_clock::time_point prev_time;

View file

@ -15,6 +15,9 @@
#include "game.h"
#ifdef __EMSCRIPTEN__
extern Game *global_game_ptr = nullptr;
extern "C" {
EM_BOOL resize_event_callback(int event_type, const EmscriptenUiEvent *event,
@ -25,6 +28,15 @@ EM_BOOL resize_event_callback(int event_type, const EmscriptenUiEvent *event,
}
return false;
} // resize_event_callback(...)
int EMSCRIPTEN_KEEPALIVE clear_all_screens() {
if (global_game_ptr) {
global_game_ptr->clear_screens();
return 0;
}
return 1;
}
} // extern "C"
#endif
@ -46,6 +58,8 @@ int main() {
#ifdef __EMSCRIPTEN__
Game game{};
global_game_ptr = &game;
SetWindowSize(call_js_get_canvas_width(), call_js_get_canvas_height());
emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, &game, false,

View file

@ -59,6 +59,9 @@
window.onerror = function() {
console.log("onerror: " + event);
};
function demo0_clear_all_screens() {
Module.ccall('clear_all_screens', 'number', [], []);
};
</script>
{{{ SCRIPT }}}
</body>