2023-01-10 14:26:54 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
/* os.cpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "os.h"
|
2017-01-13 17:25:43 +00:00
|
|
|
|
2023-01-22 18:42:34 +00:00
|
|
|
#include "core/io/json.h"
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/os/dir_access.h"
|
|
|
|
#include "core/os/file_access.h"
|
|
|
|
#include "core/os/input.h"
|
|
|
|
#include "core/os/midi_driver.h"
|
|
|
|
#include "core/project_settings.h"
|
|
|
|
#include "core/version_generated.gen.h"
|
2018-03-04 17:18:05 +00:00
|
|
|
#include "servers/audio_server.h"
|
2017-01-13 17:25:43 +00:00
|
|
|
|
|
|
|
#include <stdarg.h>
|
2022-08-24 07:50:33 +00:00
|
|
|
#include <thread>
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2021-05-04 14:00:45 +00:00
|
|
|
OS *OS::singleton = nullptr;
|
2020-06-29 18:46:21 +00:00
|
|
|
uint64_t OS::target_ticks = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
OS *OS::get_singleton() {
|
2014-02-10 01:10:30 +00:00
|
|
|
return singleton;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
uint32_t OS::get_ticks_msec() const {
|
|
|
|
return get_ticks_usec() / 1000;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-03-29 13:53:11 +00:00
|
|
|
String OS::get_iso_date_time(bool local) const {
|
|
|
|
OS::Date date = get_date(local);
|
|
|
|
OS::Time time = get_time(local);
|
|
|
|
|
|
|
|
String timezone;
|
|
|
|
if (!local) {
|
|
|
|
TimeZoneInfo zone = get_time_zone_info();
|
|
|
|
if (zone.bias >= 0) {
|
|
|
|
timezone = "+";
|
|
|
|
}
|
|
|
|
timezone = timezone + itos(zone.bias / 60).pad_zeros(2) + itos(zone.bias % 60).pad_zeros(2);
|
|
|
|
} else {
|
|
|
|
timezone = "Z";
|
|
|
|
}
|
|
|
|
|
2021-10-28 11:23:24 +00:00
|
|
|
return itos(date.year).pad_zeros(2) + "-" +
|
|
|
|
itos(date.month).pad_zeros(2) + "-" +
|
|
|
|
itos(date.day).pad_zeros(2) + "T" +
|
|
|
|
itos(time.hour).pad_zeros(2) + ":" +
|
|
|
|
itos(time.min).pad_zeros(2) + ":" +
|
|
|
|
itos(time.sec).pad_zeros(2) + timezone;
|
2019-03-29 13:53:11 +00:00
|
|
|
}
|
|
|
|
|
2015-04-12 20:55:01 +00:00
|
|
|
uint64_t OS::get_splash_tick_msec() const {
|
|
|
|
return _msec_splash;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
uint64_t OS::get_unix_time() const {
|
|
|
|
return 0;
|
|
|
|
};
|
2016-01-10 21:24:55 +00:00
|
|
|
uint64_t OS::get_system_time_secs() const {
|
2015-08-06 17:29:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2018-12-19 21:18:52 +00:00
|
|
|
uint64_t OS::get_system_time_msecs() const {
|
|
|
|
return 0;
|
|
|
|
}
|
2022-08-08 09:45:32 +00:00
|
|
|
double OS::get_subsecond_unix_time() const {
|
|
|
|
return 0.0;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-11-21 09:35:01 +00:00
|
|
|
void OS::_set_logger(CompositeLogger *p_logger) {
|
2017-09-22 05:56:02 +00:00
|
|
|
if (_logger) {
|
|
|
|
memdelete(_logger);
|
2015-11-05 19:13:05 +00:00
|
|
|
}
|
2017-09-22 05:56:02 +00:00
|
|
|
_logger = p_logger;
|
|
|
|
}
|
|
|
|
|
2017-11-21 09:35:01 +00:00
|
|
|
void OS::add_logger(Logger *p_logger) {
|
|
|
|
if (!_logger) {
|
|
|
|
Vector<Logger *> loggers;
|
|
|
|
loggers.push_back(p_logger);
|
|
|
|
_logger = memnew(CompositeLogger(loggers));
|
|
|
|
} else {
|
|
|
|
_logger->add_logger(p_logger);
|
|
|
|
}
|
2017-09-22 05:56:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OS::print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, Logger::ErrorType p_type) {
|
|
|
|
_logger->log_error(p_function, p_file, p_line, p_code, p_rationale, p_type);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS::print(const char *p_format, ...) {
|
2014-02-10 01:10:30 +00:00
|
|
|
va_list argp;
|
|
|
|
va_start(argp, p_format);
|
|
|
|
|
2017-09-22 05:56:02 +00:00
|
|
|
_logger->logv(p_format, argp, false);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
va_end(argp);
|
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS::printerr(const char *p_format, ...) {
|
2014-02-10 01:10:30 +00:00
|
|
|
va_list argp;
|
|
|
|
va_start(argp, p_format);
|
|
|
|
|
2017-09-22 05:56:02 +00:00
|
|
|
_logger->logv(p_format, argp, true);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
va_end(argp);
|
|
|
|
};
|
|
|
|
|
2015-11-27 14:40:04 +00:00
|
|
|
void OS::set_keep_screen_on(bool p_enabled) {
|
2017-03-05 15:44:50 +00:00
|
|
|
_keep_screen_on = p_enabled;
|
2015-11-27 14:40:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool OS::is_keep_screen_on() const {
|
|
|
|
return _keep_screen_on;
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void OS::set_low_processor_usage_mode(bool p_enabled) {
|
2017-03-05 15:44:50 +00:00
|
|
|
low_processor_usage_mode = p_enabled;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool OS::is_in_low_processor_usage_mode() const {
|
|
|
|
return low_processor_usage_mode;
|
|
|
|
}
|
|
|
|
|
2021-10-05 18:05:57 +00:00
|
|
|
void OS::set_update_vital_only(bool p_enabled) {
|
|
|
|
_update_vital_only = p_enabled;
|
|
|
|
}
|
|
|
|
|
2017-11-22 17:40:43 +00:00
|
|
|
void OS::set_low_processor_usage_mode_sleep_usec(int p_usec) {
|
|
|
|
low_processor_usage_mode_sleep_usec = p_usec;
|
|
|
|
}
|
|
|
|
|
|
|
|
int OS::get_low_processor_usage_mode_sleep_usec() const {
|
|
|
|
return low_processor_usage_mode_sleep_usec;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS::set_clipboard(const String &p_text) {
|
|
|
|
_local_clipboard = p_text;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2022-01-19 12:06:44 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
String OS::get_clipboard() const {
|
|
|
|
return _local_clipboard;
|
|
|
|
}
|
|
|
|
|
2022-01-19 12:06:44 +00:00
|
|
|
bool OS::has_clipboard() const {
|
|
|
|
return !get_clipboard().empty();
|
|
|
|
}
|
|
|
|
|
2021-10-20 14:19:17 +00:00
|
|
|
void OS::set_clipboard_primary(const String &p_text) {
|
|
|
|
_primary_clipboard = p_text;
|
|
|
|
}
|
|
|
|
|
|
|
|
String OS::get_clipboard_primary() const {
|
|
|
|
return _primary_clipboard;
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
String OS::get_executable_path() const {
|
|
|
|
return _execpath;
|
|
|
|
}
|
|
|
|
|
2017-08-07 10:17:31 +00:00
|
|
|
int OS::get_process_id() const {
|
2014-04-05 15:39:30 +00:00
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
bool OS::is_stdout_verbose() const {
|
|
|
|
return _verbose_stdout;
|
|
|
|
}
|
|
|
|
|
2020-07-09 07:32:42 +00:00
|
|
|
bool OS::is_stdout_debug_enabled() const {
|
|
|
|
return _debug_stdout;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS::dump_memory_to_file(const char *p_file) {
|
2017-01-14 11:26:56 +00:00
|
|
|
//Memory::dump_static_mem_to_file(p_file);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2021-05-04 14:00:45 +00:00
|
|
|
static FileAccess *_OSPRF = nullptr;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
static void _OS_printres(Object *p_obj) {
|
2017-08-24 20:58:51 +00:00
|
|
|
Resource *res = Object::cast_to<Resource>(p_obj);
|
2021-05-05 10:44:11 +00:00
|
|
|
if (!res) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2021-02-28 11:10:47 +00:00
|
|
|
String str = vformat("%s - %s - %s", res->to_string(), res->get_name(), res->get_path());
|
2021-05-05 10:44:11 +00:00
|
|
|
if (_OSPRF) {
|
2014-02-10 01:10:30 +00:00
|
|
|
_OSPRF->store_line(str);
|
2021-05-05 10:44:11 +00:00
|
|
|
} else {
|
2014-02-10 01:10:30 +00:00
|
|
|
print_line(str);
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool OS::has_virtual_keyboard() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-07-07 18:22:28 +00:00
|
|
|
void OS::show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect, VirtualKeyboardType p_type, int p_max_input_length, int p_cursor_start, int p_cursor_end) {
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS::hide_virtual_keyboard() {
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-10-04 08:39:31 +00:00
|
|
|
int OS::get_virtual_keyboard_height() const {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-12-17 10:39:40 +00:00
|
|
|
uint32_t OS::keyboard_get_scancode_from_physical(uint32_t p_scancode) const {
|
|
|
|
return p_scancode;
|
|
|
|
}
|
|
|
|
|
2019-04-15 15:30:20 +00:00
|
|
|
void OS::set_cursor_shape(CursorShape p_shape) {
|
|
|
|
}
|
|
|
|
|
|
|
|
OS::CursorShape OS::get_cursor_shape() const {
|
|
|
|
return CURSOR_ARROW;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) {
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void OS::print_all_resources(String p_to_file) {
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(p_to_file != "" && _OSPRF);
|
|
|
|
if (p_to_file != "") {
|
2014-02-10 01:10:30 +00:00
|
|
|
Error err;
|
2017-03-05 15:44:50 +00:00
|
|
|
_OSPRF = FileAccess::open(p_to_file, FileAccess::WRITE, &err);
|
|
|
|
if (err != OK) {
|
2021-05-04 14:00:45 +00:00
|
|
|
_OSPRF = nullptr;
|
2019-08-15 02:57:49 +00:00
|
|
|
ERR_FAIL_MSG("Can't print all resources to file: " + String(p_to_file) + ".");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectDB::debug_objects(_OS_printres);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_to_file != "") {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (_OSPRF) {
|
2014-02-10 01:10:30 +00:00
|
|
|
memdelete(_OSPRF);
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2021-05-04 14:00:45 +00:00
|
|
|
_OSPRF = nullptr;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS::print_resources_in_use(bool p_short) {
|
2021-05-04 14:00:45 +00:00
|
|
|
ResourceCache::dump(nullptr, p_short);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS::dump_resources_to_file(const char *p_file) {
|
2014-02-10 01:10:30 +00:00
|
|
|
ResourceCache::dump(p_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS::set_no_window_mode(bool p_enable) {
|
2017-03-05 15:44:50 +00:00
|
|
|
_no_window = p_enable;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool OS::is_no_window_mode_enabled() const {
|
|
|
|
return _no_window;
|
|
|
|
}
|
|
|
|
|
|
|
|
int OS::get_exit_code() const {
|
|
|
|
return _exit_code;
|
|
|
|
}
|
|
|
|
void OS::set_exit_code(int p_code) {
|
2017-03-05 15:44:50 +00:00
|
|
|
_exit_code = p_code;
|
2020-05-21 16:08:48 +00:00
|
|
|
_is_custom_exit_code = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OS::is_custom_exit_code() {
|
|
|
|
return _is_custom_exit_code;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String OS::get_locale() const {
|
|
|
|
return "en";
|
|
|
|
}
|
|
|
|
|
2021-09-16 07:27:56 +00:00
|
|
|
// Non-virtual helper to extract the 2 or 3-letter language code from
|
|
|
|
// `get_locale()` in a way that's consistent for all platforms.
|
|
|
|
String OS::get_locale_language() const {
|
|
|
|
return get_locale().left(3).replace("_", "");
|
|
|
|
}
|
|
|
|
|
2022-04-28 07:24:29 +00:00
|
|
|
// Embedded PCK offset.
|
|
|
|
uint64_t OS::get_embedded_pck_offset() const {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-11-26 18:00:53 +00:00
|
|
|
// Helper function to ensure that a dir name/path will be valid on the OS
|
|
|
|
String OS::get_safe_dir_name(const String &p_dir_name, bool p_allow_dir_separator) const {
|
|
|
|
Vector<String> invalid_chars = String(": * ? \" < > |").split(" ");
|
|
|
|
if (p_allow_dir_separator) {
|
|
|
|
// Dir separators are allowed, but disallow ".." to avoid going up the filesystem
|
|
|
|
invalid_chars.push_back("..");
|
|
|
|
} else {
|
|
|
|
invalid_chars.push_back("/");
|
|
|
|
}
|
|
|
|
|
|
|
|
String safe_dir_name = p_dir_name.replace("\\", "/").strip_edges();
|
|
|
|
for (int i = 0; i < invalid_chars.size(); i++) {
|
|
|
|
safe_dir_name = safe_dir_name.replace(invalid_chars[i], "-");
|
2016-06-02 18:39:37 +00:00
|
|
|
}
|
2017-11-26 18:00:53 +00:00
|
|
|
return safe_dir_name;
|
2016-06-02 18:39:37 +00:00
|
|
|
}
|
|
|
|
|
Add initial support for the XDG Base Directory spec
Spec version 0.7 from https://standards.freedesktop.org/basedir-spec/basedir-spec-0.7.html
(latest as of this commit).
Three virtual methods are added to OS for the various XDG paths we will use:
- OS::get_data_path gives XDG_DATA_HOME, or if missing:
~/.local/share on X11, ~/Library/Application Support/ on macOS and %APPDATA% on Windows
- OS::get_config_path gives XDG_CONFIG_HOME, or if missing:
~/.config on X11, ~/Library/Application Support/ on macOS and %APPDATA% on Windows
- OS::get_cache_path gives XDG_CACHE_HOME, or if missing:
~/.cache on X11, ~/Library/Caches on macOS and %APPDATA% on Windows
So for Windows there are no changes, for Linux we follow the full split spec
and for macOS stuff will move from ~/.godot to ~/Library/Application Support/Godot.
Support for system-wide installation of templates on Unix was removed for now,
as it's a bit hackish and I don't think anyone uses it.
user:// will still be OS::get_data_path() + "/godot/app_userdata/$name" by
default, but when using the application/config/use_shared_user_dir option
it will now use XDG_DATA_HOME/$name, e.g. ~/.local/share/MyGame.
For now everything still goes in EditorSettings::get_settings_dir(), but
this will be changed in a later commit to make use of the new splitting
where relevant.
Part of #3513.
2017-11-17 16:11:41 +00:00
|
|
|
// Path to data, config, cache, etc. OS-specific folders
|
|
|
|
|
|
|
|
// Get properly capitalized engine name for system paths
|
|
|
|
String OS::get_godot_dir_name() const {
|
|
|
|
// Default to lowercase, so only override when different case is needed
|
2017-11-19 20:18:01 +00:00
|
|
|
return String(VERSION_SHORT_NAME).to_lower();
|
Add initial support for the XDG Base Directory spec
Spec version 0.7 from https://standards.freedesktop.org/basedir-spec/basedir-spec-0.7.html
(latest as of this commit).
Three virtual methods are added to OS for the various XDG paths we will use:
- OS::get_data_path gives XDG_DATA_HOME, or if missing:
~/.local/share on X11, ~/Library/Application Support/ on macOS and %APPDATA% on Windows
- OS::get_config_path gives XDG_CONFIG_HOME, or if missing:
~/.config on X11, ~/Library/Application Support/ on macOS and %APPDATA% on Windows
- OS::get_cache_path gives XDG_CACHE_HOME, or if missing:
~/.cache on X11, ~/Library/Caches on macOS and %APPDATA% on Windows
So for Windows there are no changes, for Linux we follow the full split spec
and for macOS stuff will move from ~/.godot to ~/Library/Application Support/Godot.
Support for system-wide installation of templates on Unix was removed for now,
as it's a bit hackish and I don't think anyone uses it.
user:// will still be OS::get_data_path() + "/godot/app_userdata/$name" by
default, but when using the application/config/use_shared_user_dir option
it will now use XDG_DATA_HOME/$name, e.g. ~/.local/share/MyGame.
For now everything still goes in EditorSettings::get_settings_dir(), but
this will be changed in a later commit to make use of the new splitting
where relevant.
Part of #3513.
2017-11-17 16:11:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// OS equivalent of XDG_DATA_HOME
|
|
|
|
String OS::get_data_path() const {
|
|
|
|
return ".";
|
|
|
|
}
|
|
|
|
|
|
|
|
// OS equivalent of XDG_CONFIG_HOME
|
|
|
|
String OS::get_config_path() const {
|
|
|
|
return ".";
|
|
|
|
}
|
|
|
|
|
|
|
|
// OS equivalent of XDG_CACHE_HOME
|
|
|
|
String OS::get_cache_path() const {
|
|
|
|
return ".";
|
|
|
|
}
|
|
|
|
|
2020-01-10 16:02:29 +00:00
|
|
|
// Path to macOS .app bundle resources
|
|
|
|
String OS::get_bundle_resource_dir() const {
|
|
|
|
return ".";
|
|
|
|
};
|
|
|
|
|
2021-05-13 06:25:40 +00:00
|
|
|
// Path to macOS .app bundle embedded icon
|
|
|
|
String OS::get_bundle_icon_path() const {
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
Add initial support for the XDG Base Directory spec
Spec version 0.7 from https://standards.freedesktop.org/basedir-spec/basedir-spec-0.7.html
(latest as of this commit).
Three virtual methods are added to OS for the various XDG paths we will use:
- OS::get_data_path gives XDG_DATA_HOME, or if missing:
~/.local/share on X11, ~/Library/Application Support/ on macOS and %APPDATA% on Windows
- OS::get_config_path gives XDG_CONFIG_HOME, or if missing:
~/.config on X11, ~/Library/Application Support/ on macOS and %APPDATA% on Windows
- OS::get_cache_path gives XDG_CACHE_HOME, or if missing:
~/.cache on X11, ~/Library/Caches on macOS and %APPDATA% on Windows
So for Windows there are no changes, for Linux we follow the full split spec
and for macOS stuff will move from ~/.godot to ~/Library/Application Support/Godot.
Support for system-wide installation of templates on Unix was removed for now,
as it's a bit hackish and I don't think anyone uses it.
user:// will still be OS::get_data_path() + "/godot/app_userdata/$name" by
default, but when using the application/config/use_shared_user_dir option
it will now use XDG_DATA_HOME/$name, e.g. ~/.local/share/MyGame.
For now everything still goes in EditorSettings::get_settings_dir(), but
this will be changed in a later commit to make use of the new splitting
where relevant.
Part of #3513.
2017-11-17 16:11:41 +00:00
|
|
|
// OS specific path for user://
|
2017-11-17 14:25:22 +00:00
|
|
|
String OS::get_user_data_dir() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
return ".";
|
|
|
|
};
|
|
|
|
|
Add initial support for the XDG Base Directory spec
Spec version 0.7 from https://standards.freedesktop.org/basedir-spec/basedir-spec-0.7.html
(latest as of this commit).
Three virtual methods are added to OS for the various XDG paths we will use:
- OS::get_data_path gives XDG_DATA_HOME, or if missing:
~/.local/share on X11, ~/Library/Application Support/ on macOS and %APPDATA% on Windows
- OS::get_config_path gives XDG_CONFIG_HOME, or if missing:
~/.config on X11, ~/Library/Application Support/ on macOS and %APPDATA% on Windows
- OS::get_cache_path gives XDG_CACHE_HOME, or if missing:
~/.cache on X11, ~/Library/Caches on macOS and %APPDATA% on Windows
So for Windows there are no changes, for Linux we follow the full split spec
and for macOS stuff will move from ~/.godot to ~/Library/Application Support/Godot.
Support for system-wide installation of templates on Unix was removed for now,
as it's a bit hackish and I don't think anyone uses it.
user:// will still be OS::get_data_path() + "/godot/app_userdata/$name" by
default, but when using the application/config/use_shared_user_dir option
it will now use XDG_DATA_HOME/$name, e.g. ~/.local/share/MyGame.
For now everything still goes in EditorSettings::get_settings_dir(), but
this will be changed in a later commit to make use of the new splitting
where relevant.
Part of #3513.
2017-11-17 16:11:41 +00:00
|
|
|
// Absolute path to res://
|
|
|
|
String OS::get_resource_dir() const {
|
|
|
|
return ProjectSettings::get_singleton()->get_resource_path();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Access system-specific dirs like Documents, Downloads, etc.
|
2021-07-11 01:39:31 +00:00
|
|
|
String OS::get_system_dir(SystemDir p_dir, bool p_shared_storage) const {
|
Add initial support for the XDG Base Directory spec
Spec version 0.7 from https://standards.freedesktop.org/basedir-spec/basedir-spec-0.7.html
(latest as of this commit).
Three virtual methods are added to OS for the various XDG paths we will use:
- OS::get_data_path gives XDG_DATA_HOME, or if missing:
~/.local/share on X11, ~/Library/Application Support/ on macOS and %APPDATA% on Windows
- OS::get_config_path gives XDG_CONFIG_HOME, or if missing:
~/.config on X11, ~/Library/Application Support/ on macOS and %APPDATA% on Windows
- OS::get_cache_path gives XDG_CACHE_HOME, or if missing:
~/.cache on X11, ~/Library/Caches on macOS and %APPDATA% on Windows
So for Windows there are no changes, for Linux we follow the full split spec
and for macOS stuff will move from ~/.godot to ~/Library/Application Support/Godot.
Support for system-wide installation of templates on Unix was removed for now,
as it's a bit hackish and I don't think anyone uses it.
user:// will still be OS::get_data_path() + "/godot/app_userdata/$name" by
default, but when using the application/config/use_shared_user_dir option
it will now use XDG_DATA_HOME/$name, e.g. ~/.local/share/MyGame.
For now everything still goes in EditorSettings::get_settings_dir(), but
this will be changed in a later commit to make use of the new splitting
where relevant.
Part of #3513.
2017-11-17 16:11:41 +00:00
|
|
|
return ".";
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
Error OS::shell_open(String p_uri) {
|
|
|
|
return ERR_UNAVAILABLE;
|
|
|
|
};
|
|
|
|
|
|
|
|
// implement these with the canvas?
|
2017-03-05 15:44:50 +00:00
|
|
|
Error OS::dialog_show(String p_title, String p_description, Vector<String> p_buttons, Object *p_obj, String p_callback) {
|
2014-02-10 01:10:30 +00:00
|
|
|
while (true) {
|
|
|
|
print("%ls\n--------\n%ls\n", p_title.c_str(), p_description.c_str());
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < p_buttons.size(); i++) {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (i > 0) {
|
2021-05-04 12:28:27 +00:00
|
|
|
print(", ");
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
print("%i=%ls", i + 1, p_buttons[i].c_str());
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
print("\n");
|
|
|
|
String res = get_stdin_string().strip_edges();
|
2021-05-05 10:44:11 +00:00
|
|
|
if (!res.is_numeric()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
int n = res.to_int();
|
2021-05-05 10:44:11 +00:00
|
|
|
if (n < 0 || n >= p_buttons.size()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
|
|
|
if (p_obj && p_callback != "") {
|
2014-02-10 01:10:30 +00:00
|
|
|
p_obj->call_deferred(p_callback, n);
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
|
|
|
};
|
|
|
|
return OK;
|
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Error OS::dialog_input_text(String p_title, String p_description, String p_partial, Object *p_obj, String p_callback) {
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_FAIL_COND_V(!p_obj, FAILED);
|
|
|
|
ERR_FAIL_COND_V(p_callback == "", FAILED);
|
|
|
|
print("%ls\n---------\n%ls\n[%ls]:\n", p_title.c_str(), p_description.c_str(), p_partial.c_str());
|
|
|
|
|
|
|
|
String res = get_stdin_string().strip_edges();
|
|
|
|
bool success = true;
|
|
|
|
if (res == "") {
|
|
|
|
res = p_partial;
|
|
|
|
};
|
|
|
|
|
|
|
|
p_obj->call_deferred(p_callback, success, res);
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
};
|
|
|
|
|
2019-01-30 18:07:46 +00:00
|
|
|
uint64_t OS::get_static_memory_usage() const {
|
2017-01-06 13:15:44 +00:00
|
|
|
return Memory::get_mem_usage();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2019-01-30 18:07:46 +00:00
|
|
|
uint64_t OS::get_dynamic_memory_usage() const {
|
2017-01-07 21:25:37 +00:00
|
|
|
return MemoryPool::total_memory;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2019-01-30 18:07:46 +00:00
|
|
|
uint64_t OS::get_static_memory_peak_usage() const {
|
2017-01-06 13:15:44 +00:00
|
|
|
return Memory::get_mem_max_usage();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Error OS::set_cwd(const String &p_cwd) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return ERR_CANT_OPEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OS::has_touchscreen_ui_hint() const {
|
|
|
|
//return false;
|
2018-02-24 02:04:30 +00:00
|
|
|
return Input::get_singleton() && Input::get_singleton()->is_emulating_touch_from_mouse();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2019-01-30 18:07:46 +00:00
|
|
|
uint64_t OS::get_free_static_memory() const {
|
2017-01-06 13:15:44 +00:00
|
|
|
return Memory::get_mem_available();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OS::yield() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS::set_screen_orientation(ScreenOrientation p_orientation) {
|
2017-03-05 15:44:50 +00:00
|
|
|
_orientation = p_orientation;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OS::ScreenOrientation OS::get_screen_orientation() const {
|
|
|
|
return (OS::ScreenOrientation)_orientation;
|
|
|
|
}
|
|
|
|
|
2021-05-21 21:57:02 +00:00
|
|
|
// Internal helper function that returns the screen orientation enum value from a string
|
|
|
|
// (generally coming from the Project Settings).
|
|
|
|
// This is required to keep compatibility with existing projects.
|
|
|
|
OS::ScreenOrientation OS::get_screen_orientation_from_string(const String &p_orientation) const {
|
|
|
|
if (p_orientation == "portrait") {
|
|
|
|
return OS::SCREEN_PORTRAIT;
|
|
|
|
} else if (p_orientation == "reverse_landscape") {
|
|
|
|
return OS::SCREEN_REVERSE_LANDSCAPE;
|
|
|
|
} else if (p_orientation == "reverse_portrait") {
|
|
|
|
return OS::SCREEN_REVERSE_PORTRAIT;
|
|
|
|
} else if (p_orientation == "sensor_landscape") {
|
|
|
|
return OS::SCREEN_SENSOR_LANDSCAPE;
|
|
|
|
} else if (p_orientation == "sensor_portrait") {
|
|
|
|
return OS::SCREEN_SENSOR_PORTRAIT;
|
|
|
|
} else if (p_orientation == "sensor") {
|
|
|
|
return OS::SCREEN_SENSOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OS::SCREEN_LANDSCAPE;
|
|
|
|
}
|
|
|
|
|
2021-01-08 09:24:41 +00:00
|
|
|
void OS::ensure_user_data_dir() {
|
2017-11-17 14:25:22 +00:00
|
|
|
String dd = get_user_data_dir();
|
2014-02-10 01:10:30 +00:00
|
|
|
DirAccess *da = DirAccess::open(dd);
|
|
|
|
if (da) {
|
|
|
|
memdelete(da);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
2014-09-19 21:39:50 +00:00
|
|
|
Error err = da->make_dir_recursive(dd);
|
2019-08-15 02:57:49 +00:00
|
|
|
ERR_FAIL_COND_MSG(err != OK, "Error attempting to create data dir: " + dd + ".");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
memdelete(da);
|
|
|
|
}
|
|
|
|
|
2019-05-17 13:43:56 +00:00
|
|
|
void OS::set_native_icon(const String &p_filename) {
|
|
|
|
}
|
|
|
|
|
2017-05-17 10:36:47 +00:00
|
|
|
void OS::set_icon(const Ref<Image> &p_icon) {
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String OS::get_model_name() const {
|
2017-03-05 15:44:50 +00:00
|
|
|
return "GenericDevice";
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS::set_cmdline(const char *p_execpath, const List<String> &p_args) {
|
2022-01-06 09:34:10 +00:00
|
|
|
_execpath = String::utf8(p_execpath);
|
2014-02-10 01:10:30 +00:00
|
|
|
_cmdline = p_args;
|
|
|
|
};
|
|
|
|
|
|
|
|
void OS::release_rendering_thread() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS::make_rendering_thread() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS::swap_buffers() {
|
|
|
|
}
|
|
|
|
|
2017-08-07 10:17:31 +00:00
|
|
|
String OS::get_unique_id() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_FAIL_V("");
|
|
|
|
}
|
|
|
|
|
|
|
|
int OS::get_processor_count() const {
|
2022-08-24 07:50:33 +00:00
|
|
|
return std::thread::hardware_concurrency();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2022-02-15 21:25:51 +00:00
|
|
|
String OS::get_processor_name() const {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2014-11-17 10:46:11 +00:00
|
|
|
Error OS::native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track) {
|
2014-02-13 21:03:28 +00:00
|
|
|
return FAILED;
|
2021-05-07 14:42:17 +00:00
|
|
|
}
|
2014-02-13 21:03:28 +00:00
|
|
|
|
2014-03-14 01:57:24 +00:00
|
|
|
bool OS::native_video_is_playing() const {
|
2014-02-13 21:03:28 +00:00
|
|
|
return false;
|
2021-05-07 14:42:17 +00:00
|
|
|
}
|
2016-02-19 04:09:06 +00:00
|
|
|
|
2021-05-07 14:42:17 +00:00
|
|
|
void OS::native_video_pause() {
|
|
|
|
}
|
2016-02-19 04:09:06 +00:00
|
|
|
|
2021-05-07 14:42:17 +00:00
|
|
|
void OS::native_video_unpause() {
|
|
|
|
}
|
2014-02-13 21:03:28 +00:00
|
|
|
|
2021-05-07 14:42:17 +00:00
|
|
|
void OS::native_video_stop() {
|
|
|
|
}
|
2014-02-13 21:03:28 +00:00
|
|
|
|
|
|
|
void OS::set_mouse_mode(MouseMode p_mode) {
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2014-03-14 01:57:24 +00:00
|
|
|
bool OS::can_use_threads() const {
|
|
|
|
#ifdef NO_THREADS
|
|
|
|
return false;
|
|
|
|
#else
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-05-23 12:02:12 +00:00
|
|
|
bool OS::tts_is_speaking() const {
|
|
|
|
WARN_PRINT("TTS is not supported by this platform.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OS::tts_is_paused() const {
|
|
|
|
WARN_PRINT("TTS is not supported by this platform.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS::tts_pause() {
|
|
|
|
WARN_PRINT("TTS is not supported by this platformr.");
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS::tts_resume() {
|
|
|
|
WARN_PRINT("TTS is not supported by this platform.");
|
|
|
|
}
|
|
|
|
|
|
|
|
Array OS::tts_get_voices() const {
|
|
|
|
WARN_PRINT("TTS is not supported by this platform.");
|
|
|
|
return Array();
|
|
|
|
}
|
|
|
|
|
|
|
|
PoolStringArray OS::tts_get_voices_for_language(const String &p_language) const {
|
|
|
|
PoolStringArray ret;
|
|
|
|
Array voices = tts_get_voices();
|
|
|
|
for (int i = 0; i < voices.size(); i++) {
|
|
|
|
const Dictionary &voice = voices[i];
|
|
|
|
if (voice.has("id") && voice.has("language") && voice["language"].operator String().begins_with(p_language)) {
|
|
|
|
ret.push_back(voice["id"]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS::tts_speak(const String &p_text, const String &p_voice, int p_volume, float p_pitch, float p_rate, int p_utterance_id, bool p_interrupt) {
|
|
|
|
WARN_PRINT("TTS is not supported by this platform.");
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS::tts_stop() {
|
|
|
|
WARN_PRINT("TTS is not supported by this platform.");
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS::tts_set_utterance_callback(TTSUtteranceEvent p_event, Object *p_object, const StringName &p_callback) {
|
|
|
|
ERR_FAIL_INDEX(p_event, OS::TTS_UTTERANCE_MAX);
|
|
|
|
utterance_callback[p_event].object = p_object;
|
|
|
|
utterance_callback[p_event].cb_name = p_callback;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS::tts_post_utterance_event(TTSUtteranceEvent p_event, int p_id, int p_pos) {
|
|
|
|
ERR_FAIL_INDEX(p_event, OS::TTS_UTTERANCE_MAX);
|
|
|
|
switch (p_event) {
|
|
|
|
case OS::TTS_UTTERANCE_STARTED:
|
|
|
|
case OS::TTS_UTTERANCE_ENDED:
|
|
|
|
case OS::TTS_UTTERANCE_CANCELED: {
|
|
|
|
if (utterance_callback[p_event].object != nullptr) {
|
|
|
|
utterance_callback[p_event].object->call_deferred(utterance_callback[p_event].cb_name, p_id);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case OS::TTS_UTTERANCE_BOUNDARY: {
|
|
|
|
if (utterance_callback[p_event].object != nullptr) {
|
|
|
|
utterance_callback[p_event].object->call_deferred(utterance_callback[p_event].cb_name, p_pos, p_id);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
OS::MouseMode OS::get_mouse_mode() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
return MOUSE_MODE_VISIBLE;
|
|
|
|
}
|
|
|
|
|
2015-01-05 00:16:40 +00:00
|
|
|
OS::LatinKeyboardVariant OS::get_latin_keyboard_variant() const {
|
|
|
|
return LATIN_KEYBOARD_QWERTY;
|
|
|
|
}
|
|
|
|
|
2020-06-12 12:51:51 +00:00
|
|
|
int OS::keyboard_get_layout_count() const {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int OS::keyboard_get_current_layout() const {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS::keyboard_set_current_layout(int p_index) {}
|
|
|
|
|
|
|
|
String OS::keyboard_get_layout_language(int p_index) const {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
String OS::keyboard_get_layout_name(int p_index) const {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2016-01-07 23:40:41 +00:00
|
|
|
bool OS::is_joy_known(int p_device) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
String OS::get_joy_guid(int p_device) const {
|
2017-01-08 20:05:51 +00:00
|
|
|
return "Default Joypad";
|
2016-01-07 23:40:41 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-01-27 20:53:37 +00:00
|
|
|
void OS::set_context(int p_context) {
|
|
|
|
}
|
2017-12-16 20:09:25 +00:00
|
|
|
|
2021-05-04 14:00:45 +00:00
|
|
|
OS::SwitchVSyncCallbackInThread OS::switch_vsync_function = nullptr;
|
2017-12-16 20:09:25 +00:00
|
|
|
|
2016-06-05 22:14:33 +00:00
|
|
|
void OS::set_use_vsync(bool p_enable) {
|
2017-12-16 20:09:25 +00:00
|
|
|
_use_vsync = p_enable;
|
|
|
|
if (switch_vsync_function) { //if a function was set, use function
|
|
|
|
switch_vsync_function(p_enable);
|
|
|
|
} else { //otherwise just call here
|
|
|
|
_set_use_vsync(p_enable);
|
|
|
|
}
|
2016-06-05 22:14:33 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool OS::is_vsync_enabled() const {
|
2017-12-16 20:09:25 +00:00
|
|
|
return _use_vsync;
|
2016-06-05 22:14:33 +00:00
|
|
|
}
|
2016-01-27 20:53:37 +00:00
|
|
|
|
2019-11-07 02:18:55 +00:00
|
|
|
void OS::set_vsync_via_compositor(bool p_enable) {
|
|
|
|
_vsync_via_compositor = p_enable;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OS::is_vsync_via_compositor_enabled() const {
|
|
|
|
return _vsync_via_compositor;
|
|
|
|
}
|
|
|
|
|
2021-04-30 18:48:08 +00:00
|
|
|
void OS::set_delta_smoothing(bool p_enabled) {
|
|
|
|
_delta_smoothing_enabled = p_enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OS::is_delta_smoothing_enabled() const {
|
|
|
|
return _delta_smoothing_enabled;
|
|
|
|
}
|
|
|
|
|
2017-09-12 19:09:06 +00:00
|
|
|
OS::PowerState OS::get_power_state() {
|
2016-07-23 11:15:55 +00:00
|
|
|
return POWERSTATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
int OS::get_power_seconds_left() {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
int OS::get_power_percent_left() {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-02-26 14:58:47 +00:00
|
|
|
void OS::set_has_server_feature_callback(HasServerFeatureCallback p_callback) {
|
|
|
|
has_server_feature_callback = p_callback;
|
|
|
|
}
|
|
|
|
|
2017-10-02 19:38:39 +00:00
|
|
|
bool OS::has_feature(const String &p_feature) {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (p_feature == get_name()) {
|
2017-07-19 20:00:46 +00:00
|
|
|
return true;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2017-07-19 20:00:46 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
2021-05-05 10:44:11 +00:00
|
|
|
if (p_feature == "debug") {
|
2017-07-19 20:00:46 +00:00
|
|
|
return true;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2017-07-19 20:00:46 +00:00
|
|
|
#else
|
2021-05-05 10:44:11 +00:00
|
|
|
if (p_feature == "release") {
|
2017-07-19 20:00:46 +00:00
|
|
|
return true;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2017-07-19 20:00:46 +00:00
|
|
|
#endif
|
2018-07-25 21:20:54 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
2021-05-05 10:44:11 +00:00
|
|
|
if (p_feature == "editor") {
|
2018-07-25 21:20:54 +00:00
|
|
|
return true;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2018-07-25 21:20:54 +00:00
|
|
|
#else
|
2021-05-05 10:44:11 +00:00
|
|
|
if (p_feature == "standalone") {
|
2018-07-25 21:20:54 +00:00
|
|
|
return true;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2018-07-25 21:20:54 +00:00
|
|
|
#endif
|
2017-07-19 20:00:46 +00:00
|
|
|
|
2017-10-02 19:38:39 +00:00
|
|
|
if (sizeof(void *) == 8 && p_feature == "64") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (sizeof(void *) == 4 && p_feature == "32") {
|
|
|
|
return true;
|
|
|
|
}
|
2022-06-05 19:10:20 +00:00
|
|
|
#if defined(__x86_64) || defined(__x86_64__) || defined(__amd64__) || defined(_M_X64)
|
2017-10-02 15:01:43 +00:00
|
|
|
if (p_feature == "x86_64") {
|
|
|
|
return true;
|
|
|
|
}
|
2022-06-05 19:10:20 +00:00
|
|
|
#elif defined(__i386) || defined(__i386__) || defined(_M_IX86)
|
|
|
|
if (p_feature == "x86_32") {
|
|
|
|
return true;
|
|
|
|
}
|
2017-10-02 15:01:43 +00:00
|
|
|
if (p_feature == "x86") {
|
|
|
|
return true;
|
|
|
|
}
|
2022-06-05 19:10:20 +00:00
|
|
|
#elif defined(__aarch64__) || defined(_M_ARM64)
|
2017-10-02 15:01:43 +00:00
|
|
|
if (p_feature == "arm64") {
|
|
|
|
return true;
|
|
|
|
}
|
2022-06-05 19:10:20 +00:00
|
|
|
#elif defined(__arm__) || defined(_M_ARM)
|
|
|
|
if (p_feature == "arm32") {
|
|
|
|
return true;
|
|
|
|
}
|
2017-10-02 15:01:43 +00:00
|
|
|
#if defined(__ARM_ARCH_7A__)
|
|
|
|
if (p_feature == "armv7a" || p_feature == "armv7") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if defined(__ARM_ARCH_7S__)
|
|
|
|
if (p_feature == "armv7s" || p_feature == "armv7") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (p_feature == "arm") {
|
|
|
|
return true;
|
|
|
|
}
|
2021-08-31 05:27:46 +00:00
|
|
|
#elif defined(__riscv)
|
|
|
|
#if __riscv_xlen == 8
|
|
|
|
if (p_feature == "rv64") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (p_feature == "riscv") {
|
|
|
|
return true;
|
|
|
|
}
|
2021-11-01 20:23:18 +00:00
|
|
|
#elif defined(__powerpc__)
|
|
|
|
#if defined(__powerpc64__)
|
|
|
|
if (p_feature == "ppc64") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (p_feature == "ppc") {
|
|
|
|
return true;
|
|
|
|
}
|
2022-06-05 19:10:20 +00:00
|
|
|
#elif defined(__wasm__)
|
|
|
|
#if defined(__wasm64__)
|
|
|
|
if (p_feature == "wasm64") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#elif defined(__wasm32__)
|
|
|
|
if (p_feature == "wasm32") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (p_feature == "wasm") {
|
|
|
|
return true;
|
|
|
|
}
|
2017-10-02 15:01:43 +00:00
|
|
|
#endif
|
2017-10-02 19:38:39 +00:00
|
|
|
|
2021-05-05 10:44:11 +00:00
|
|
|
if (_check_internal_feature_support(p_feature)) {
|
2017-07-19 20:00:46 +00:00
|
|
|
return true;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2017-07-19 20:00:46 +00:00
|
|
|
|
2019-02-26 14:58:47 +00:00
|
|
|
if (has_server_feature_callback && has_server_feature_callback(p_feature)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-05-05 10:44:11 +00:00
|
|
|
if (ProjectSettings::get_singleton()->has_custom_feature(p_feature)) {
|
2018-07-18 08:22:59 +00:00
|
|
|
return true;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2018-07-18 08:22:59 +00:00
|
|
|
|
2017-07-19 20:00:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-02-12 17:17:29 +00:00
|
|
|
void OS::center_window() {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (is_window_fullscreen()) {
|
2021-05-04 12:28:27 +00:00
|
|
|
return;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2018-02-12 17:17:29 +00:00
|
|
|
|
2018-09-03 02:13:04 +00:00
|
|
|
Point2 sp = get_screen_position(get_current_screen());
|
2018-02-12 17:17:29 +00:00
|
|
|
Size2 scr = get_screen_size(get_current_screen());
|
|
|
|
Size2 wnd = get_real_window_size();
|
2018-09-03 02:13:04 +00:00
|
|
|
|
|
|
|
int x = sp.width + (scr.width - wnd.width) / 2;
|
|
|
|
int y = sp.height + (scr.height - wnd.height) / 2;
|
|
|
|
|
2018-02-12 17:17:29 +00:00
|
|
|
set_window_position(Vector2(x, y));
|
|
|
|
}
|
|
|
|
|
2018-03-04 17:18:05 +00:00
|
|
|
int OS::get_video_driver_count() const {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *OS::get_video_driver_name(int p_driver) const {
|
|
|
|
switch (p_driver) {
|
|
|
|
case VIDEO_DRIVER_GLES2:
|
|
|
|
return "GLES2";
|
|
|
|
case VIDEO_DRIVER_GLES3:
|
|
|
|
default:
|
|
|
|
return "GLES3";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-24 12:07:44 +00:00
|
|
|
bool OS::is_offscreen_gl_available() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS::set_offscreen_gl_current(bool p_current) {}
|
|
|
|
|
2018-03-04 17:18:05 +00:00
|
|
|
int OS::get_audio_driver_count() const {
|
|
|
|
return AudioDriverManager::get_driver_count();
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *OS::get_audio_driver_name(int p_driver) const {
|
|
|
|
AudioDriver *driver = AudioDriverManager::get_driver(p_driver);
|
2019-09-25 08:28:50 +00:00
|
|
|
ERR_FAIL_COND_V_MSG(!driver, "", "Cannot get audio driver at index '" + itos(p_driver) + "'.");
|
2018-03-04 17:18:05 +00:00
|
|
|
return AudioDriverManager::get_driver(p_driver)->get_name();
|
|
|
|
}
|
|
|
|
|
2018-07-19 21:58:15 +00:00
|
|
|
void OS::set_restart_on_exit(bool p_restart, const List<String> &p_restart_arguments) {
|
|
|
|
restart_on_exit = p_restart;
|
|
|
|
restart_commandline = p_restart_arguments;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OS::is_restart_on_exit_set() const {
|
|
|
|
return restart_on_exit;
|
|
|
|
}
|
2018-07-20 06:37:10 +00:00
|
|
|
|
|
|
|
List<String> OS::get_restart_on_exit_arguments() const {
|
2018-07-19 21:58:15 +00:00
|
|
|
return restart_commandline;
|
|
|
|
}
|
|
|
|
|
2018-07-14 12:11:28 +00:00
|
|
|
PoolStringArray OS::get_connected_midi_inputs() {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (MIDIDriver::get_singleton()) {
|
2018-07-14 12:11:28 +00:00
|
|
|
return MIDIDriver::get_singleton()->get_connected_inputs();
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2018-07-14 12:11:28 +00:00
|
|
|
|
|
|
|
PoolStringArray list;
|
2020-05-31 17:10:27 +00:00
|
|
|
ERR_FAIL_V_MSG(list, vformat("MIDI input isn't supported on %s.", OS::get_singleton()->get_name()));
|
2018-07-14 12:11:28 +00:00
|
|
|
}
|
|
|
|
|
2018-08-04 00:17:33 +00:00
|
|
|
void OS::open_midi_inputs() {
|
2020-05-31 17:10:27 +00:00
|
|
|
if (MIDIDriver::get_singleton()) {
|
2018-08-04 00:17:33 +00:00
|
|
|
MIDIDriver::get_singleton()->open();
|
2020-05-31 17:10:27 +00:00
|
|
|
} else {
|
|
|
|
ERR_PRINT(vformat("MIDI input isn't supported on %s.", OS::get_singleton()->get_name()));
|
|
|
|
}
|
2018-08-04 00:17:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OS::close_midi_inputs() {
|
2020-05-31 17:10:27 +00:00
|
|
|
if (MIDIDriver::get_singleton()) {
|
2018-08-04 00:17:33 +00:00
|
|
|
MIDIDriver::get_singleton()->close();
|
2020-05-31 17:10:27 +00:00
|
|
|
} else {
|
|
|
|
ERR_PRINT(vformat("MIDI input isn't supported on %s.", OS::get_singleton()->get_name()));
|
|
|
|
}
|
2018-08-04 00:17:33 +00:00
|
|
|
}
|
|
|
|
|
2020-06-29 18:46:21 +00:00
|
|
|
void OS::add_frame_delay(bool p_can_draw) {
|
|
|
|
const uint32_t frame_delay = Engine::get_singleton()->get_frame_delay();
|
|
|
|
if (frame_delay) {
|
|
|
|
// Add fixed frame delay to decrease CPU/GPU usage. This doesn't take
|
|
|
|
// the actual frame time into account.
|
|
|
|
// Due to the high fluctuation of the actual sleep duration, it's not recommended
|
|
|
|
// to use this as a FPS limiter.
|
|
|
|
delay_usec(frame_delay * 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add a dynamic frame delay to decrease CPU/GPU usage. This takes the
|
|
|
|
// previous frame time into account for a smoother result.
|
|
|
|
uint64_t dynamic_delay = 0;
|
|
|
|
if (is_in_low_processor_usage_mode() || !p_can_draw) {
|
|
|
|
dynamic_delay = get_low_processor_usage_mode_sleep_usec();
|
|
|
|
}
|
|
|
|
const int target_fps = Engine::get_singleton()->get_target_fps();
|
|
|
|
if (target_fps > 0 && !Engine::get_singleton()->is_editor_hint()) {
|
|
|
|
// Override the low processor usage mode sleep delay if the target FPS is lower.
|
|
|
|
dynamic_delay = MAX(dynamic_delay, (uint64_t)(1000000 / target_fps));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dynamic_delay > 0) {
|
|
|
|
target_ticks += dynamic_delay;
|
|
|
|
uint64_t current_ticks = get_ticks_usec();
|
|
|
|
|
|
|
|
if (current_ticks < target_ticks) {
|
|
|
|
delay_usec(target_ticks - current_ticks);
|
|
|
|
}
|
|
|
|
|
|
|
|
current_ticks = get_ticks_usec();
|
|
|
|
target_ticks = MIN(MAX(target_ticks, current_ticks - dynamic_delay), current_ticks + dynamic_delay);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-22 18:42:34 +00:00
|
|
|
void OS::set_use_benchmark(bool p_use_benchmark) {
|
|
|
|
use_benchmark = p_use_benchmark;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OS::is_use_benchmark_set() {
|
|
|
|
return use_benchmark;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS::set_benchmark_file(const String &p_benchmark_file) {
|
|
|
|
benchmark_file = p_benchmark_file;
|
|
|
|
}
|
|
|
|
|
|
|
|
String OS::get_benchmark_file() {
|
|
|
|
return benchmark_file;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS::benchmark_begin_measure(const String &p_what) {
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
start_benchmark_from[p_what] = OS::get_singleton()->get_ticks_usec();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
void OS::benchmark_end_measure(const String &p_what) {
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
uint64_t total = OS::get_singleton()->get_ticks_usec() - start_benchmark_from[p_what];
|
|
|
|
double total_f = double(total) / double(1000000);
|
|
|
|
|
|
|
|
startup_benchmark_json[p_what] = total_f;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS::benchmark_dump() {
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
if (!use_benchmark) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!benchmark_file.empty()) {
|
|
|
|
FileAccess *f = FileAccess::open(benchmark_file, FileAccess::WRITE);
|
|
|
|
if (f) {
|
|
|
|
f->store_string(JSON::print(startup_benchmark_json, "\t", false));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
List<Variant> keys;
|
|
|
|
startup_benchmark_json.get_key_list(&keys);
|
|
|
|
print_line("BENCHMARK:");
|
|
|
|
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
|
|
|
|
Variant &K = E->get();
|
|
|
|
print_line("\t-" + K.operator String() + ": " + startup_benchmark_json[K] + " sec.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::OS() {
|
2017-07-19 11:49:19 +00:00
|
|
|
void *volatile stack_bottom;
|
|
|
|
|
2018-07-20 01:41:32 +00:00
|
|
|
restart_on_exit = false;
|
2017-03-05 15:44:50 +00:00
|
|
|
singleton = this;
|
|
|
|
_keep_screen_on = true; // set default value to true, because this had been true before godot 2.0.
|
|
|
|
low_processor_usage_mode = false;
|
2017-11-22 17:40:43 +00:00
|
|
|
low_processor_usage_mode_sleep_usec = 10000;
|
2021-10-05 18:05:57 +00:00
|
|
|
_update_vital_only = false;
|
|
|
|
_update_pending = false;
|
2017-03-05 15:44:50 +00:00
|
|
|
_verbose_stdout = false;
|
2020-07-09 07:32:42 +00:00
|
|
|
_debug_stdout = false;
|
2017-03-05 15:44:50 +00:00
|
|
|
_no_window = false;
|
|
|
|
_exit_code = 0;
|
|
|
|
_orientation = SCREEN_LANDSCAPE;
|
2021-04-30 18:48:08 +00:00
|
|
|
_delta_smoothing_enabled = false;
|
2017-03-05 15:44:50 +00:00
|
|
|
|
|
|
|
_render_thread_mode = RENDER_THREAD_SAFE;
|
|
|
|
|
2017-10-05 19:41:42 +00:00
|
|
|
_allow_hidpi = false;
|
2017-12-10 18:38:26 +00:00
|
|
|
_allow_layered = false;
|
2017-07-19 11:49:19 +00:00
|
|
|
_stack_bottom = (void *)(&stack_bottom);
|
2017-09-22 05:56:02 +00:00
|
|
|
|
2021-05-04 14:00:45 +00:00
|
|
|
_logger = nullptr;
|
2017-11-21 09:35:01 +00:00
|
|
|
|
2021-05-04 14:00:45 +00:00
|
|
|
has_server_feature_callback = nullptr;
|
2019-02-26 14:58:47 +00:00
|
|
|
|
2017-11-21 09:35:01 +00:00
|
|
|
Vector<Logger *> loggers;
|
|
|
|
loggers.push_back(memnew(StdLogger));
|
|
|
|
_set_logger(memnew(CompositeLogger(loggers)));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OS::~OS() {
|
2017-09-22 05:56:02 +00:00
|
|
|
memdelete(_logger);
|
2021-05-04 14:00:45 +00:00
|
|
|
singleton = nullptr;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|