Merge pull request #46121 from Faless/js/3.x_processor_count

[HTML5] Implement OS.get_processor_count()
This commit is contained in:
Rémi Verschelde 2021-02-17 14:04:58 +01:00 committed by GitHub
commit 6fc9580299
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 0 deletions

View file

@ -49,6 +49,7 @@ extern int godot_js_os_fs_is_persistent();
extern void godot_js_os_fs_sync(void (*p_callback)()); extern void godot_js_os_fs_sync(void (*p_callback)());
extern int godot_js_os_execute(const char *p_json); extern int godot_js_os_execute(const char *p_json);
extern void godot_js_os_shell_open(const char *p_uri); extern void godot_js_os_shell_open(const char *p_uri);
extern int godot_js_os_hw_concurrency_get();
// Display // Display
extern int godot_js_display_screen_dpi_get(); extern int godot_js_display_screen_dpi_get();

View file

@ -282,6 +282,11 @@ const GodotOS = {
godot_js_os_shell_open: function (p_uri) { godot_js_os_shell_open: function (p_uri) {
window.open(GodotRuntime.parseString(p_uri), '_blank'); window.open(GodotRuntime.parseString(p_uri), '_blank');
}, },
godot_js_os_hw_concurrency_get__sig: 'i',
godot_js_os_hw_concurrency_get: function () {
return navigator.hardwareConcurrency || 1;
},
}; };
autoAddDeps(GodotOS, '$GodotOS'); autoAddDeps(GodotOS, '$GodotOS');

View file

@ -1069,6 +1069,10 @@ int OS_JavaScript::get_process_id() const {
ERR_FAIL_V_MSG(0, "OS::get_process_id() is not available on the HTML5 platform."); ERR_FAIL_V_MSG(0, "OS::get_process_id() is not available on the HTML5 platform.");
} }
int OS_JavaScript::get_processor_count() const {
return godot_js_os_hw_concurrency_get();
}
bool OS_JavaScript::_check_internal_feature_support(const String &p_feature) { bool OS_JavaScript::_check_internal_feature_support(const String &p_feature) {
if (p_feature == "HTML5" || p_feature == "web") { if (p_feature == "HTML5" || p_feature == "web") {

View file

@ -168,6 +168,7 @@ public:
virtual Error execute(const String &p_path, const List<String> &p_arguments, bool p_blocking = true, ProcessID *r_child_id = NULL, String *r_pipe = NULL, int *r_exitcode = NULL, bool read_stderr = false, Mutex *p_pipe_mutex = NULL); virtual Error execute(const String &p_path, const List<String> &p_arguments, bool p_blocking = true, ProcessID *r_child_id = NULL, String *r_pipe = NULL, int *r_exitcode = NULL, bool read_stderr = false, Mutex *p_pipe_mutex = NULL);
virtual Error kill(const ProcessID &p_pid); virtual Error kill(const ProcessID &p_pid);
virtual int get_process_id() const; virtual int get_process_id() const;
int get_processor_count() const;
virtual void alert(const String &p_alert, const String &p_title = "ALERT!"); virtual void alert(const String &p_alert, const String &p_title = "ALERT!");
virtual void set_window_title(const String &p_title); virtual void set_window_title(const String &p_title);