os_javascript.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*************************************************************************/
  2. /* os_javascript.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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. List<AudioDriverJavaScript *> audio_drivers;
  40. bool idb_is_syncing = false;
  41. bool idb_available = false;
  42. bool idb_needs_sync = false;
  43. static void main_loop_callback();
  44. static void file_access_close_callback(const String &p_file, int p_flags);
  45. static void fs_sync_callback();
  46. protected:
  47. void initialize() override;
  48. void set_main_loop(MainLoop *p_main_loop) override;
  49. void delete_main_loop() override;
  50. void finalize() override;
  51. bool _check_internal_feature_support(const String &p_feature) override;
  52. public:
  53. // Override return type to make writing static callbacks less tedious.
  54. static OS_JavaScript *get_singleton();
  55. void initialize_joypads() override;
  56. MainLoop *get_main_loop() const override;
  57. bool main_loop_iterate();
  58. Error execute(const String &p_path, const List<String> &p_arguments, String *r_pipe = nullptr, int *r_exitcode = nullptr, bool read_stderr = false, Mutex *p_pipe_mutex = nullptr, bool p_open_console = false) override;
  59. Error create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id = nullptr, bool p_open_console = false) override;
  60. Error kill(const ProcessID &p_pid) override;
  61. int get_process_id() const override;
  62. int get_processor_count() const override;
  63. int get_default_thread_pool_size() const override { return 1; }
  64. String get_executable_path() const override;
  65. Error shell_open(String p_uri) override;
  66. String get_name() const override;
  67. // Override default OS implementation which would block the main thread with delay_usec.
  68. // Implemented in javascript_main.cpp loop callback instead.
  69. void add_frame_delay(bool p_can_draw) override {}
  70. String get_cache_path() const override;
  71. String get_config_path() const override;
  72. String get_data_path() const override;
  73. String get_user_data_dir() const override;
  74. bool is_userfs_persistent() const override;
  75. bool is_single_window() const override { return true; }
  76. void alert(const String &p_alert, const String &p_title = "ALERT!") override;
  77. Error open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path) override;
  78. void resume_audio();
  79. OS_JavaScript();
  80. };
  81. #endif