os_web.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /**************************************************************************/
  2. /* os_web.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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_WEB_H
  31. #define OS_WEB_H
  32. #include "audio_driver_web.h"
  33. #include "godot_js.h"
  34. #include "core/input/input.h"
  35. #include "drivers/unix/os_unix.h"
  36. #include "servers/audio_server.h"
  37. #include <emscripten/html5.h>
  38. class OS_Web : public OS_Unix {
  39. MainLoop *main_loop = nullptr;
  40. List<AudioDriverWeb *> audio_drivers;
  41. bool idb_is_syncing = false;
  42. bool idb_available = false;
  43. bool idb_needs_sync = false;
  44. bool pwa_is_waiting = false;
  45. WASM_EXPORT static void main_loop_callback();
  46. WASM_EXPORT static void file_access_close_callback(const String &p_file, int p_flags);
  47. WASM_EXPORT static void fs_sync_callback();
  48. WASM_EXPORT static void update_pwa_state_callback();
  49. protected:
  50. void initialize() override;
  51. void set_main_loop(MainLoop *p_main_loop) override;
  52. void delete_main_loop() override;
  53. void finalize() override;
  54. bool _check_internal_feature_support(const String &p_feature) override;
  55. public:
  56. // Override return type to make writing static callbacks less tedious.
  57. static OS_Web *get_singleton();
  58. bool pwa_needs_update() const { return pwa_is_waiting; }
  59. Error pwa_update();
  60. void force_fs_sync();
  61. void initialize_joypads() override;
  62. MainLoop *get_main_loop() const override;
  63. bool main_loop_iterate();
  64. 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;
  65. Dictionary execute_with_pipe(const String &p_path, const List<String> &p_arguments, bool p_blocking = true) override;
  66. Error create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id = nullptr, bool p_open_console = false) override;
  67. Error kill(const ProcessID &p_pid) override;
  68. int get_process_id() const override;
  69. bool is_process_running(const ProcessID &p_pid) const override;
  70. int get_process_exit_code(const ProcessID &p_pid) const override;
  71. int get_processor_count() const override;
  72. String get_unique_id() const override;
  73. int get_default_thread_pool_size() const override { return 1; }
  74. String get_executable_path() const override;
  75. Error shell_open(const String &p_uri) override;
  76. String get_name() const override;
  77. // Override default OS implementation which would block the main thread with delay_usec.
  78. // Implemented in web_main.cpp loop callback instead.
  79. void add_frame_delay(bool p_can_draw) override;
  80. void vibrate_handheld(int p_duration_ms, float p_amplitude) override;
  81. String get_cache_path() const override;
  82. String get_config_path() const override;
  83. String get_data_path() const override;
  84. String get_user_data_dir() const override;
  85. bool is_userfs_persistent() const override;
  86. void alert(const String &p_alert, const String &p_title = "ALERT!") override;
  87. Error open_dynamic_library(const String &p_path, void *&p_library_handle, GDExtensionData *p_data = nullptr) override;
  88. void resume_audio();
  89. OS_Web();
  90. };
  91. #endif // OS_WEB_H