Debian Codegraph @

platform/web/os_web.h

raw symbols SCIP
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
31 #pragma once
32
33 #include "audio_driver_web.h"
34 #include "webmidi_driver.h"
35
36 #include "godot_js.h"
37
38 #include "core/input/input.h"
39 #include "drivers/unix/os_unix.h"
40 #include "servers/audio/audio_server.h"
41
42 #include <emscripten/html5.h>
43
44 class OS_Web : public OS_Unix {
45 MainLoop *main_loop = nullptr;
46 List<AudioDriverWeb *> audio_drivers;
47
48 MIDIDriverWebMidi midi_driver;
49
50 bool idb_is_syncing = false;
51 bool idb_available = false;
52 bool idb_needs_sync = false;
53 bool pwa_is_waiting = false;
54
55 WASM_EXPORT static void main_loop_callback();
56
57 WASM_EXPORT static void file_access_close_callback(const String &p_file, int p_flags);
58 WASM_EXPORT static void dir_access_remove_callback(const String &p_file);
59 WASM_EXPORT static void fs_sync_callback();
60 WASM_EXPORT static void update_pwa_state_callback();
61
62 protected:
63 void initialize() override;
64
65 void set_main_loop(MainLoop *p_main_loop) override;
66 void delete_main_loop() override;
67
68 void finalize() override;
69
70 bool _check_internal_feature_support(const String &p_feature) override;
71
72 public:
73 // Override return type to make writing static callbacks less tedious.
74 static OS_Web *get_singleton();
75
76 bool pwa_needs_update() const { return pwa_is_waiting; }
77 Error pwa_update();
78 void force_fs_sync();
79
80 void initialize_joypads() override;
81
82 MainLoop *get_main_loop() const override;
83 bool main_loop_iterate();
84
85 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;
86 Dictionary execute_with_pipe(const String &p_path, const List<String> &p_arguments, bool p_blocking = true) override;
87 Error create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id = nullptr, bool p_open_console = false) override;
88 Error kill(const ProcessID &p_pid) override;
89 int get_process_id() const override;
90 bool is_process_running(const ProcessID &p_pid) const override;
91 int get_process_exit_code(const ProcessID &p_pid) const override;
92 int get_processor_count() const override;
93 String get_unique_id() const override;
94 int get_default_thread_pool_size() const override;
95
96 String get_executable_path() const override;
97 Error shell_open(const String &p_uri) override;
98 String get_name() const override;
99
100 // Override default OS implementation which would block the main thread with delay_usec.
101 // Implemented in web_main.cpp loop callback instead.
102 void add_frame_delay(bool p_can_draw, bool p_wake_for_events) override;
103
104 void vibrate_handheld(int p_duration_ms, float p_amplitude) override;
105
106 String get_cache_path() const override;
107 String get_config_path() const override;
108 String get_data_path() const override;
109 String get_user_data_dir(const String &p_user_dir) const override;
110
111 bool is_userfs_persistent() const override;
112
113 void alert(const String &p_alert, const String &p_title = "ALERT!") override;
114
115 Error open_dynamic_library(const String &p_path, void *&p_library_handle, GDExtensionData *p_data = nullptr) override;
116
117 void resume_audio();
118
119 OS_Web();
120 };