2
0

javascript_main.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*************************************************************************/
  2. /* javascript_main.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.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() {
  59. start_step = 1;
  60. }
  61. }
  62. int main(int argc, char *argv[]) {
  63. /* Initialize the window */
  64. printf("let it go dude!\n");
  65. glutInit(&argc, argv);
  66. os = new OS_JavaScript(argv[0], _gfx_init, NULL, NULL);
  67. Error err = Main::setup(argv[0], argc - 1, &argv[1]);
  68. ResourceLoader::set_abort_on_missing_resources(false); //ease up compatibility
  69. /* Set up glut callback functions */
  70. glutIdleFunc(_gfx_idle);
  71. // glutReshapeFunc(gears_reshape);
  72. glutDisplayFunc(_godot_draw);
  73. //glutSpecialFunc(gears_special);
  74. //mount persistent file system
  75. /* clang-format off */
  76. EM_ASM(
  77. FS.mkdir('/userfs');
  78. FS.mount(IDBFS, {}, '/userfs');
  79. // sync from persistent state into memory and then
  80. // run the 'main_after_fs_sync' function
  81. FS.syncfs(true, function(err) {
  82. if (err) {
  83. Module.setStatus('Failed to load persistent data\nPlease allow (third-party) cookies');
  84. Module.printErr('Failed to populate IDB file system: ' + err.message);
  85. Module.exit();
  86. } else {
  87. Module.print('Successfully populated IDB file system');
  88. ccall('main_after_fs_sync', 'void', []);
  89. }
  90. });
  91. );
  92. /* clang-format on */
  93. glutMainLoop();
  94. return 0;
  95. }
  96. /*
  97. *
  98. *09] <azakai|2__> reduz: yes, define TOTAL_MEMORY on Module. for example var Module = { TOTAL_MEMORY: 12345.. }; before the main
  99. *
  100. */