Add test fn to clear screens from js
This commit is contained in:
parent
7ca57870eb
commit
6cbc044251
4 changed files with 21 additions and 0 deletions
|
@ -21,3 +21,5 @@ void Game::update() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::draw() { screen_stack->draw(); }
|
void Game::draw() { screen_stack->draw(); }
|
||||||
|
|
||||||
|
void Game::clear_screens() { screen_stack->clear_screens(); }
|
||||||
|
|
|
@ -22,6 +22,8 @@ class Game {
|
||||||
void update();
|
void update();
|
||||||
void draw();
|
void draw();
|
||||||
|
|
||||||
|
void clear_screens();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ScreenStack::Ptr screen_stack;
|
ScreenStack::Ptr screen_stack;
|
||||||
std::chrono::steady_clock::time_point prev_time;
|
std::chrono::steady_clock::time_point prev_time;
|
||||||
|
|
14
src/main.cc
14
src/main.cc
|
@ -15,6 +15,9 @@
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
|
||||||
#ifdef __EMSCRIPTEN__
|
#ifdef __EMSCRIPTEN__
|
||||||
|
|
||||||
|
extern Game *global_game_ptr = nullptr;
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
EM_BOOL resize_event_callback(int event_type, const EmscriptenUiEvent *event,
|
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;
|
return false;
|
||||||
} // resize_event_callback(...)
|
} // resize_event_callback(...)
|
||||||
|
|
||||||
|
int EMSCRIPTEN_KEEPALIVE clear_all_screens() {
|
||||||
|
if (global_game_ptr) {
|
||||||
|
global_game_ptr->clear_screens();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -46,6 +58,8 @@ int main() {
|
||||||
#ifdef __EMSCRIPTEN__
|
#ifdef __EMSCRIPTEN__
|
||||||
Game game{};
|
Game game{};
|
||||||
|
|
||||||
|
global_game_ptr = &game;
|
||||||
|
|
||||||
SetWindowSize(call_js_get_canvas_width(), call_js_get_canvas_height());
|
SetWindowSize(call_js_get_canvas_width(), call_js_get_canvas_height());
|
||||||
|
|
||||||
emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, &game, false,
|
emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, &game, false,
|
||||||
|
|
|
@ -59,6 +59,9 @@
|
||||||
window.onerror = function() {
|
window.onerror = function() {
|
||||||
console.log("onerror: " + event);
|
console.log("onerror: " + event);
|
||||||
};
|
};
|
||||||
|
function demo0_clear_all_screens() {
|
||||||
|
Module.ccall('clear_all_screens', 'number', [], []);
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
{{{ SCRIPT }}}
|
{{{ SCRIPT }}}
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Reference in a new issue