entry_emscripten.cpp 728 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright 2011-2013 Branimir Karadzic. All rights reserved.
  3. * License: http://www.opensource.org/licenses/BSD-2-Clause
  4. */
  5. #include <bx/bx.h>
  6. #if BX_PLATFORM_EMSCRIPTEN
  7. #include <emscripten/emscripten.h>
  8. #include <alloca.h>
  9. #include <setjmp.h>
  10. extern int _main_(int _argc, char** _argv);
  11. static jmp_buf s_main;
  12. static jmp_buf s_loop;
  13. void emscripten_yield()
  14. {
  15. if (!setjmp(s_main) )
  16. {
  17. longjmp(s_loop, 1);
  18. }
  19. }
  20. void loop()
  21. {
  22. if (!setjmp(s_loop) )
  23. {
  24. longjmp(s_main, 1);
  25. }
  26. }
  27. int main(int _argc, char** _argv)
  28. {
  29. if (!setjmp(s_loop) )
  30. {
  31. alloca(16<<10);
  32. _main_(_argc, _argv);
  33. }
  34. emscripten_set_main_loop(loop, 10, true);
  35. }
  36. #endif // BX_PLATFORM_EMSCRIPTEN