os_javascript.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*************************************************************************/
  2. /* os_javascript.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 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. #ifndef OS_JAVASCRIPT_H
  31. #define OS_JAVASCRIPT_H
  32. #include "audio_driver_javascript.h"
  33. #include "core/input/input.h"
  34. #include "drivers/unix/os_unix.h"
  35. #include "servers/audio_server.h"
  36. #include <emscripten/html5.h>
  37. class OS_JavaScript : public OS_Unix {
  38. MainLoop *main_loop = nullptr;
  39. AudioDriverJavaScript audio_driver_javascript;
  40. bool finalizing = false;
  41. bool idb_available = false;
  42. int64_t sync_wait_time = -1;
  43. int64_t last_sync_check_time = -1;
  44. static void main_loop_callback();
  45. static void file_access_close_callback(const String &p_file, int p_flags);
  46. protected:
  47. virtual void initialize();
  48. virtual void set_main_loop(MainLoop *p_main_loop);
  49. virtual void delete_main_loop();
  50. virtual void finalize();
  51. virtual bool _check_internal_feature_support(const String &p_feature);
  52. public:
  53. // Override return type to make writing static callbacks less tedious.
  54. static OS_JavaScript *get_singleton();
  55. virtual void initialize_joypads();
  56. virtual bool has_touchscreen_ui_hint() const;
  57. virtual int get_audio_driver_count() const;
  58. virtual const char *get_audio_driver_name(int p_driver) const;
  59. virtual MainLoop *get_main_loop() const;
  60. void finalize_async();
  61. bool main_loop_iterate();
  62. virtual Error execute(const String &p_path, const List<String> &p_arguments, bool p_blocking = true, ProcessID *r_child_id = nullptr, String *r_pipe = nullptr, int *r_exitcode = nullptr, bool read_stderr = false, Mutex *p_pipe_mutex = nullptr);
  63. virtual Error kill(const ProcessID &p_pid);
  64. virtual int get_process_id() const;
  65. String get_executable_path() const;
  66. virtual Error shell_open(String p_uri);
  67. virtual String get_name() const;
  68. // Override default OS implementation which would block the main thread with delay_usec.
  69. // Implemented in javascript_main.cpp loop callback instead.
  70. virtual void add_frame_delay(bool p_can_draw) {}
  71. virtual bool can_draw() const;
  72. virtual String get_cache_path() const;
  73. virtual String get_config_path() const;
  74. virtual String get_data_path() const;
  75. virtual String get_user_data_dir() const;
  76. void set_idb_available(bool p_idb_available);
  77. virtual bool is_userfs_persistent() const;
  78. void resume_audio();
  79. bool is_finalizing() { return finalizing; }
  80. OS_JavaScript();
  81. };
  82. #endif