javascript_main.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*************************************************************************/
  2. /* javascript_main.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "emscripten.h"
  31. #include "io/resource_loader.h"
  32. #include "main/main.h"
  33. #include "os_javascript.h"
  34. #include <GL/glut.h>
  35. #include <string.h>
  36. OS_JavaScript *os = NULL;
  37. static void _gfx_init(void *ud, bool gl2, int w, int h, bool fs) {
  38. glutInitWindowSize(w, h);
  39. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  40. glutCreateWindow("godot");
  41. }
  42. static void _gfx_idle() {
  43. glutPostRedisplay();
  44. }
  45. int start_step = 0;
  46. static void _godot_draw(void) {
  47. if (start_step == 1) {
  48. start_step = 2;
  49. Main::start();
  50. os->main_loop_begin();
  51. }
  52. if (start_step == 2) {
  53. os->main_loop_iterate();
  54. }
  55. glutSwapBuffers();
  56. }
  57. extern "C" {
  58. void main_after_fs_sync(int value) {
  59. start_step = 1;
  60. printf("FS SYNCHED!\n");
  61. }
  62. }
  63. int main(int argc, char *argv[]) {
  64. /* Initialize the window */
  65. printf("let it go!\n");
  66. glutInit(&argc, argv);
  67. os = new OS_JavaScript(_gfx_init, NULL, NULL);
  68. #if 0
  69. char *args[]={"-test","gui","-v",NULL};
  70. Error err = Main::setup("apk",3,args);
  71. #else
  72. // char *args[]={"-v",NULL};//
  73. // Error err = Main::setup("",1,args);
  74. Error err = Main::setup("", 0, NULL);
  75. #endif
  76. ResourceLoader::set_abort_on_missing_resources(false); //ease up compatibility
  77. /* Set up glut callback functions */
  78. glutIdleFunc(_gfx_idle);
  79. // glutReshapeFunc(gears_reshape);
  80. glutDisplayFunc(_godot_draw);
  81. //glutSpecialFunc(gears_special);
  82. //mount persistent filesystem
  83. /* clang-format off */
  84. EM_ASM(
  85. FS.mkdir('/userfs');
  86. FS.mount(IDBFS, {}, '/userfs');
  87. // sync from persisted state into memory and then
  88. // run the 'test' function
  89. FS.syncfs(true, function (err) {
  90. assert(!err);
  91. console.log("done syncinc!");
  92. _after_sync_cb = Module.cwrap('main_after_fs_sync', 'void',['number']);
  93. _after_sync_cb(0);
  94. });
  95. );
  96. /* clang-format on */
  97. glutMainLoop();
  98. return 0;
  99. }
  100. /*
  101. *
  102. *09] <azakai|2__> reduz: yes, define TOTAL_MEMORY on Module. for example var Module = { TOTAL_MEMORY: 12345.. }; before the main
  103. *
  104. */