2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* os.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2020-01-01 11:16:22 +01:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* */
|
|
|
|
/* 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-05 00:50:27 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "os.h"
|
2017-01-13 18:25:43 +01:00
|
|
|
|
2020-04-28 15:19:37 +02:00
|
|
|
#include "core/input/input.h"
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/os/dir_access.h"
|
|
|
|
#include "core/os/file_access.h"
|
|
|
|
#include "core/os/midi_driver.h"
|
|
|
|
#include "core/project_settings.h"
|
|
|
|
#include "core/version_generated.gen.h"
|
2018-03-04 18:18:05 +01:00
|
|
|
#include "servers/audio_server.h"
|
2017-01-13 18:25:43 +01:00
|
|
|
|
|
|
|
#include <stdarg.h>
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
OS *OS::singleton = nullptr;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
OS *OS::get_singleton() {
|
2014-02-10 02:10:30 +01:00
|
|
|
return singleton;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
uint32_t OS::get_ticks_msec() const {
|
|
|
|
return get_ticks_usec() / 1000;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2019-03-29 14:53:11 +01: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";
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-04-12 22:55:01 +02:00
|
|
|
uint64_t OS::get_splash_tick_msec() const {
|
|
|
|
return _msec_splash;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-05-31 14:19:31 +02:00
|
|
|
double OS::get_unix_time() const {
|
2018-12-19 22:18:52 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-05-19 11:24:58 +02:00
|
|
|
void OS::debug_break() {
|
2014-02-10 02:10:30 +01:00
|
|
|
// something
|
2020-05-19 11:24:58 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-11-21 10:35:01 +01:00
|
|
|
void OS::_set_logger(CompositeLogger *p_logger) {
|
2017-09-22 07:56:02 +02:00
|
|
|
if (_logger) {
|
|
|
|
memdelete(_logger);
|
2015-11-05 20:13:05 +01:00
|
|
|
}
|
2017-09-22 07:56:02 +02:00
|
|
|
_logger = p_logger;
|
|
|
|
}
|
|
|
|
|
2017-11-21 10:35:01 +01: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 07:56:02 +02: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 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void OS::print(const char *p_format, ...) {
|
2014-02-10 02:10:30 +01:00
|
|
|
va_list argp;
|
|
|
|
va_start(argp, p_format);
|
|
|
|
|
2017-09-22 07:56:02 +02:00
|
|
|
_logger->logv(p_format, argp, false);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
va_end(argp);
|
2020-05-19 15:46:49 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void OS::printerr(const char *p_format, ...) {
|
2014-02-10 02:10:30 +01:00
|
|
|
va_list argp;
|
|
|
|
va_start(argp, p_format);
|
|
|
|
|
2017-09-22 07:56:02 +02:00
|
|
|
_logger->logv(p_format, argp, true);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
va_end(argp);
|
2020-05-19 15:46:49 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
void OS::set_low_processor_usage_mode(bool p_enabled) {
|
2017-03-05 16:44:50 +01:00
|
|
|
low_processor_usage_mode = p_enabled;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool OS::is_in_low_processor_usage_mode() const {
|
|
|
|
return low_processor_usage_mode;
|
|
|
|
}
|
|
|
|
|
2017-11-22 18:40:43 +01: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;
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
String OS::get_executable_path() const {
|
|
|
|
return _execpath;
|
|
|
|
}
|
|
|
|
|
2017-08-07 12:17:31 +02:00
|
|
|
int OS::get_process_id() const {
|
2014-04-05 17:39:30 +02:00
|
|
|
return -1;
|
2020-05-19 15:46:49 +02:00
|
|
|
}
|
2014-04-05 17:39:30 +02:00
|
|
|
|
2019-08-17 17:27:29 +02:00
|
|
|
void OS::vibrate_handheld(int p_duration_ms) {
|
2019-11-07 09:44:15 +01:00
|
|
|
WARN_PRINT("vibrate_handheld() only works with Android and iOS");
|
2019-08-17 17:27:29 +02:00
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
bool OS::is_stdout_verbose() const {
|
|
|
|
return _verbose_stdout;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void OS::dump_memory_to_file(const char *p_file) {
|
2017-01-14 12:26:56 +01:00
|
|
|
//Memory::dump_static_mem_to_file(p_file);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
static FileAccess *_OSPRF = nullptr;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
static void _OS_printres(Object *p_obj) {
|
2017-08-24 22:58:51 +02:00
|
|
|
Resource *res = Object::cast_to<Resource>(p_obj);
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!res) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-07 12:17:31 +02:00
|
|
|
String str = itos(res->get_instance_id()) + String(res->get_class()) + ":" + String(res->get_name()) + " - " + res->get_path();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (_OSPRF) {
|
2014-02-10 02:10:30 +01:00
|
|
|
_OSPRF->store_line(str);
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2014-02-10 02:10:30 +01:00
|
|
|
print_line(str);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void OS::print_all_resources(String p_to_file) {
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND(p_to_file != "" && _OSPRF);
|
|
|
|
if (p_to_file != "") {
|
2014-02-10 02:10:30 +01:00
|
|
|
Error err;
|
2017-03-05 16:44:50 +01:00
|
|
|
_OSPRF = FileAccess::open(p_to_file, FileAccess::WRITE, &err);
|
|
|
|
if (err != OK) {
|
2020-04-02 01:20:12 +02:00
|
|
|
_OSPRF = nullptr;
|
2019-08-15 04:57:49 +02:00
|
|
|
ERR_FAIL_MSG("Can't print all resources to file: " + String(p_to_file) + ".");
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectDB::debug_objects(_OS_printres);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_to_file != "") {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (_OSPRF) {
|
2014-02-10 02:10:30 +01:00
|
|
|
memdelete(_OSPRF);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-04-02 01:20:12 +02:00
|
|
|
_OSPRF = nullptr;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS::print_resources_in_use(bool p_short) {
|
2020-04-02 01:20:12 +02:00
|
|
|
ResourceCache::dump(nullptr, p_short);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void OS::dump_resources_to_file(const char *p_file) {
|
2014-02-10 02:10:30 +01:00
|
|
|
ResourceCache::dump(p_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS::set_no_window_mode(bool p_enable) {
|
2017-03-05 16:44:50 +01:00
|
|
|
_no_window = p_enable;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool OS::is_no_window_mode_enabled() const {
|
|
|
|
return _no_window;
|
|
|
|
}
|
|
|
|
|
|
|
|
int OS::get_exit_code() const {
|
|
|
|
return _exit_code;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void OS::set_exit_code(int p_code) {
|
2017-03-05 16:44:50 +01:00
|
|
|
_exit_code = p_code;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
String OS::get_locale() const {
|
|
|
|
return "en";
|
|
|
|
}
|
|
|
|
|
2017-11-26 19:00:53 +01: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 20:39:37 +02:00
|
|
|
}
|
2017-11-26 19:00:53 +01:00
|
|
|
return safe_dir_name;
|
2016-06-02 20:39:37 +02: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 17:11:41 +01: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 21:18:01 +01: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 17:11:41 +01: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 17:02:29 +01:00
|
|
|
// Path to macOS .app bundle resources
|
|
|
|
String OS::get_bundle_resource_dir() const {
|
|
|
|
return ".";
|
2020-05-19 15:46:49 +02:00
|
|
|
}
|
2020-01-10 17:02:29 +01: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 17:11:41 +01:00
|
|
|
// OS specific path for user://
|
2017-11-17 15:25:22 +01:00
|
|
|
String OS::get_user_data_dir() const {
|
2014-02-10 02:10:30 +01:00
|
|
|
return ".";
|
2020-05-19 15:46:49 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01: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 17:11:41 +01: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.
|
|
|
|
String OS::get_system_dir(SystemDir p_dir) const {
|
|
|
|
return ".";
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
Error OS::shell_open(String p_uri) {
|
|
|
|
return ERR_UNAVAILABLE;
|
2020-05-19 15:46:49 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
// implement these with the canvas?
|
|
|
|
|
2019-01-30 19:07:46 +01:00
|
|
|
uint64_t OS::get_static_memory_usage() const {
|
2017-01-06 14:15:44 +01:00
|
|
|
return Memory::get_mem_usage();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 19:07:46 +01:00
|
|
|
uint64_t OS::get_static_memory_peak_usage() const {
|
2017-01-06 14:15:44 +01:00
|
|
|
return Memory::get_mem_max_usage();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Error OS::set_cwd(const String &p_cwd) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return ERR_CANT_OPEN;
|
|
|
|
}
|
|
|
|
|
2019-01-30 19:07:46 +01:00
|
|
|
uint64_t OS::get_free_static_memory() const {
|
2017-01-06 14:15:44 +01:00
|
|
|
return Memory::get_mem_available();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void OS::yield() {
|
|
|
|
}
|
|
|
|
|
2020-03-03 14:36:29 +01:00
|
|
|
void OS::ensure_user_data_dir() {
|
2017-11-17 15:25:22 +01:00
|
|
|
String dd = get_user_data_dir();
|
2014-02-10 02:10:30 +01:00
|
|
|
DirAccess *da = DirAccess::open(dd);
|
|
|
|
if (da) {
|
|
|
|
memdelete(da);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
2014-09-19 23:39:50 +02:00
|
|
|
Error err = da->make_dir_recursive(dd);
|
2019-08-15 04:57:49 +02:00
|
|
|
ERR_FAIL_COND_MSG(err != OK, "Error attempting to create data dir: " + dd + ".");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
memdelete(da);
|
|
|
|
}
|
|
|
|
|
|
|
|
String OS::get_model_name() const {
|
2017-03-05 16:44:50 +01:00
|
|
|
return "GenericDevice";
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void OS::set_cmdline(const char *p_execpath, const List<String> &p_args) {
|
2014-02-10 02:10:30 +01:00
|
|
|
_execpath = p_execpath;
|
|
|
|
_cmdline = p_args;
|
2020-05-19 15:46:49 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-07 12:17:31 +02:00
|
|
|
String OS::get_unique_id() const {
|
2014-02-10 02:10:30 +01:00
|
|
|
ERR_FAIL_V("");
|
|
|
|
}
|
|
|
|
|
|
|
|
int OS::get_processor_count() const {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-03-14 02:57:24 +01:00
|
|
|
bool OS::can_use_threads() const {
|
|
|
|
#ifdef NO_THREADS
|
|
|
|
return false;
|
|
|
|
#else
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-02-26 15:58:47 +01:00
|
|
|
void OS::set_has_server_feature_callback(HasServerFeatureCallback p_callback) {
|
|
|
|
has_server_feature_callback = p_callback;
|
|
|
|
}
|
|
|
|
|
2017-10-02 21:38:39 +02:00
|
|
|
bool OS::has_feature(const String &p_feature) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_feature == get_name()) {
|
2017-07-19 22:00:46 +02:00
|
|
|
return true;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-07-19 22:00:46 +02:00
|
|
|
#ifdef DEBUG_ENABLED
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_feature == "debug") {
|
2017-07-19 22:00:46 +02:00
|
|
|
return true;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-07-19 22:00:46 +02:00
|
|
|
#else
|
|
|
|
if (p_feature == "release")
|
|
|
|
return true;
|
|
|
|
#endif
|
2018-07-25 23:20:54 +02:00
|
|
|
#ifdef TOOLS_ENABLED
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_feature == "editor") {
|
2018-07-25 23:20:54 +02:00
|
|
|
return true;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-07-25 23:20:54 +02:00
|
|
|
#else
|
|
|
|
if (p_feature == "standalone")
|
|
|
|
return true;
|
|
|
|
#endif
|
2017-07-19 22:00:46 +02:00
|
|
|
|
2017-10-02 21:38:39 +02:00
|
|
|
if (sizeof(void *) == 8 && p_feature == "64") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (sizeof(void *) == 4 && p_feature == "32") {
|
|
|
|
return true;
|
|
|
|
}
|
2017-11-20 19:12:36 +01:00
|
|
|
#if defined(__x86_64) || defined(__x86_64__) || defined(__amd64__)
|
2017-10-02 17:01:43 +02:00
|
|
|
if (p_feature == "x86_64") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#elif (defined(__i386) || defined(__i386__))
|
|
|
|
if (p_feature == "x86") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#elif defined(__aarch64__)
|
|
|
|
if (p_feature == "arm64") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#elif defined(__arm__)
|
|
|
|
#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;
|
|
|
|
}
|
|
|
|
#endif
|
2017-10-02 21:38:39 +02:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (_check_internal_feature_support(p_feature)) {
|
2017-07-19 22:00:46 +02:00
|
|
|
return true;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-07-19 22:00:46 +02:00
|
|
|
|
2019-02-26 15:58:47 +01:00
|
|
|
if (has_server_feature_callback && has_server_feature_callback(p_feature)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (ProjectSettings::get_singleton()->has_custom_feature(p_feature)) {
|
2018-07-18 10:22:59 +02:00
|
|
|
return true;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-07-18 10:22:59 +02:00
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-19 23:58:15 +02: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 08:37:10 +02:00
|
|
|
|
|
|
|
List<String> OS::get_restart_on_exit_arguments() const {
|
2018-07-19 23:58:15 +02:00
|
|
|
return restart_commandline;
|
|
|
|
}
|
|
|
|
|
2020-02-17 22:06:54 +01:00
|
|
|
PackedStringArray OS::get_connected_midi_inputs() {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (MIDIDriver::get_singleton()) {
|
2018-07-14 14:11:28 +02:00
|
|
|
return MIDIDriver::get_singleton()->get_connected_inputs();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-07-14 14:11:28 +02:00
|
|
|
|
2020-02-17 22:06:54 +01:00
|
|
|
PackedStringArray list;
|
2020-05-31 19:10:27 +02:00
|
|
|
ERR_FAIL_V_MSG(list, vformat("MIDI input isn't supported on %s.", OS::get_singleton()->get_name()));
|
2018-07-14 14:11:28 +02:00
|
|
|
}
|
|
|
|
|
2018-08-04 02:17:33 +02:00
|
|
|
void OS::open_midi_inputs() {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (MIDIDriver::get_singleton()) {
|
2018-08-04 02:17:33 +02:00
|
|
|
MIDIDriver::get_singleton()->open();
|
2020-05-31 19:10:27 +02:00
|
|
|
} else {
|
|
|
|
ERR_PRINT(vformat("MIDI input isn't supported on %s.", OS::get_singleton()->get_name()));
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-08-04 02:17:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void OS::close_midi_inputs() {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (MIDIDriver::get_singleton()) {
|
2018-08-04 02:17:33 +02:00
|
|
|
MIDIDriver::get_singleton()->close();
|
2020-05-31 19:10:27 +02:00
|
|
|
} else {
|
|
|
|
ERR_PRINT(vformat("MIDI input isn't supported on %s.", OS::get_singleton()->get_name()));
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-08-04 02:17:33 +02:00
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
OS::OS() {
|
2017-07-19 13:49:19 +02:00
|
|
|
void *volatile stack_bottom;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
singleton = this;
|
|
|
|
|
2017-07-19 13:49:19 +02:00
|
|
|
_stack_bottom = (void *)(&stack_bottom);
|
2017-09-22 07:56:02 +02:00
|
|
|
|
2017-11-21 10:35:01 +01:00
|
|
|
Vector<Logger *> loggers;
|
|
|
|
loggers.push_back(memnew(StdLogger));
|
|
|
|
_set_logger(memnew(CompositeLogger(loggers)));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
OS::~OS() {
|
2017-09-22 07:56:02 +02:00
|
|
|
memdelete(_logger);
|
2020-04-02 01:20:12 +02:00
|
|
|
singleton = nullptr;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|