entry_emscripten.cpp 847 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. #include "entry.h"
  11. namespace entry
  12. {
  13. Event::Enum poll()
  14. {
  15. return Event::Nop;
  16. }
  17. } // namespace entry
  18. extern int _main_(int _argc, char** _argv);
  19. static jmp_buf s_main;
  20. static jmp_buf s_loop;
  21. void emscripten_yield()
  22. {
  23. if (!setjmp(s_main) )
  24. {
  25. longjmp(s_loop, 1);
  26. }
  27. }
  28. void loop()
  29. {
  30. if (!setjmp(s_loop) )
  31. {
  32. longjmp(s_main, 1);
  33. }
  34. }
  35. int main(int _argc, char** _argv)
  36. {
  37. if (!setjmp(s_loop) )
  38. {
  39. alloca(16<<10);
  40. _main_(_argc, _argv);
  41. }
  42. emscripten_set_main_loop(loop, 10, true);
  43. }
  44. #endif // BX_PLATFORM_EMSCRIPTEN