2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* os.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2017-01-01 21:01:57 +00:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-07 22:11:42 +00:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 01:10:30 +00: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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#include "os.h"
|
2017-01-13 17:25:43 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "dir_access.h"
|
2015-08-29 20:16:11 +00:00
|
|
|
#include "input.h"
|
2017-01-13 17:25:43 +00:00
|
|
|
#include "os/file_access.h"
|
2017-07-19 20:00:46 +00:00
|
|
|
#include "project_settings.h"
|
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
|
|
|
#include "version_generated.gen.h"
|
2017-01-13 17:25:43 +00:00
|
|
|
|
|
|
|
#include <stdarg.h>
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
OS *OS::singleton = NULL;
|
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
|
|
|
|
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;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS::debug_break(){
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
// something
|
|
|
|
};
|
|
|
|
|
2017-09-22 05:56:02 +00:00
|
|
|
void OS::_set_logger(Logger *p_logger) {
|
|
|
|
if (_logger) {
|
|
|
|
memdelete(_logger);
|
2015-11-05 19:13:05 +00:00
|
|
|
}
|
2017-09-22 05:56:02 +00:00
|
|
|
_logger = p_logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS::initialize_logger() {
|
|
|
|
_set_logger(memnew(StdLogger));
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2015-11-05 19:13:05 +00:00
|
|
|
|
2017-09-22 05:56:02 +00:00
|
|
|
_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;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS::set_clipboard(const String &p_text) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
_local_clipboard = p_text;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
String OS::get_clipboard() const {
|
|
|
|
|
|
|
|
return _local_clipboard;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS::set_last_error(const char *p_error) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
GLOBAL_LOCK_FUNCTION
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_error == NULL)
|
|
|
|
p_error = "Unknown Error";
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (last_error)
|
|
|
|
memfree(last_error);
|
2017-03-05 15:44:50 +00:00
|
|
|
last_error = NULL;
|
|
|
|
int len = 0;
|
|
|
|
while (p_error[len++])
|
|
|
|
;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
last_error = (char *)memalloc(len);
|
|
|
|
for (int i = 0; i < len; i++)
|
|
|
|
last_error[i] = p_error[i];
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *OS::get_last_error() const {
|
|
|
|
GLOBAL_LOCK_FUNCTION
|
2017-03-05 15:44:50 +00:00
|
|
|
return last_error ? last_error : "";
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS::dump_memory_to_file(const char *p_file) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-14 11:26:56 +00:00
|
|
|
//Memory::dump_static_mem_to_file(p_file);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
static FileAccess *_OSPRF = NULL;
|
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);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!res)
|
|
|
|
return;
|
|
|
|
|
2017-08-07 10:17:31 +00:00
|
|
|
String str = itos(res->get_instance_id()) + String(res->get_class()) + ":" + String(res->get_name()) + " - " + res->get_path();
|
2014-02-10 01:10:30 +00:00
|
|
|
if (_OSPRF)
|
|
|
|
_OSPRF->store_line(str);
|
|
|
|
else
|
|
|
|
print_line(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OS::has_virtual_keyboard() const {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS::show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect) {
|
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;
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
_OSPRF = NULL;
|
|
|
|
ERR_FAIL_COND(err != OK);
|
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 != "") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (_OSPRF)
|
|
|
|
memdelete(_OSPRF);
|
2017-03-05 15:44:50 +00:00
|
|
|
_OSPRF = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS::print_resources_in_use(bool p_short) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ResourceCache::dump(NULL, 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::clear_last_error() {
|
|
|
|
|
|
|
|
GLOBAL_LOCK_FUNCTION
|
|
|
|
if (last_error)
|
|
|
|
memfree(last_error);
|
2017-03-05 15:44:50 +00:00
|
|
|
last_error = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String OS::get_locale() const {
|
|
|
|
|
|
|
|
return "en";
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// Helper function used by OS_Unix and OS_Windows
|
2016-06-02 18:39:37 +00:00
|
|
|
String OS::get_safe_application_name() const {
|
2017-07-19 20:00:46 +00:00
|
|
|
String an = ProjectSettings::get_singleton()->get("application/config/name");
|
2016-06-02 18:39:37 +00:00
|
|
|
Vector<String> invalid_char = String("\\ / : * ? \" < > |").split(" ");
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < invalid_char.size(); i++) {
|
|
|
|
an = an.replace(invalid_char[i], "-");
|
2016-06-02 18:39:37 +00:00
|
|
|
}
|
|
|
|
return an;
|
|
|
|
}
|
|
|
|
|
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 ".";
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
String OS::get_system_dir(SystemDir p_dir) const {
|
|
|
|
|
|
|
|
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++) {
|
|
|
|
if (i > 0) print(", ");
|
|
|
|
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();
|
|
|
|
if (!res.is_numeric())
|
|
|
|
continue;
|
|
|
|
int n = res.to_int();
|
|
|
|
if (n < 0 || n >= p_buttons.size())
|
|
|
|
continue;
|
|
|
|
if (p_obj && p_callback != "")
|
|
|
|
p_obj->call_deferred(p_callback, n);
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
int 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
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
int OS::get_dynamic_memory_usage() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-07 21:25:37 +00:00
|
|
|
return MemoryPool::total_memory;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int 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;
|
2015-08-29 20:16:11 +00:00
|
|
|
return Input::get_singleton() && Input::get_singleton()->is_emulating_touchscreen();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int 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;
|
|
|
|
}
|
|
|
|
|
2017-11-17 14:25:22 +00:00
|
|
|
void OS::_ensure_user_data_dir() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
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);
|
2017-03-05 15:44:50 +00:00
|
|
|
if (err != OK) {
|
|
|
|
ERR_EXPLAIN("Error attempting to create data dir: " + dd);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(err != OK);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
memdelete(da);
|
|
|
|
}
|
|
|
|
|
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) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
_execpath = p_execpath;
|
|
|
|
_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 {
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
};
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS::native_video_pause(){
|
2014-02-13 21:03:28 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS::native_video_unpause(){
|
2016-02-19 04:09:06 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +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
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
}
|
2016-06-05 22:14:33 +00:00
|
|
|
void OS::set_use_vsync(bool p_enable) {
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool OS::is_vsync_enabled() const {
|
2016-06-05 22:14:33 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-01-27 20:53:37 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-10-02 19:38:39 +00:00
|
|
|
bool OS::has_feature(const String &p_feature) {
|
2017-07-19 20:00:46 +00:00
|
|
|
|
|
|
|
if (p_feature == get_name())
|
|
|
|
return true;
|
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
if (p_feature == "debug")
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
if (p_feature == "release")
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
|
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;
|
|
|
|
}
|
2017-10-02 15:01:43 +00:00
|
|
|
#if defined(__x86_64) || defined(__x86_64__)
|
|
|
|
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 19:38:39 +00:00
|
|
|
|
2017-07-19 20:00:46 +00:00
|
|
|
if (_check_internal_feature_support(p_feature))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-19 11:49:19 +00:00
|
|
|
void *OS::get_stack_bottom() const {
|
|
|
|
return _stack_bottom;
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::OS() {
|
2017-07-19 11:49:19 +00:00
|
|
|
void *volatile stack_bottom;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
last_error = NULL;
|
|
|
|
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;
|
|
|
|
_verbose_stdout = false;
|
|
|
|
_no_window = false;
|
|
|
|
_exit_code = 0;
|
|
|
|
_orientation = SCREEN_LANDSCAPE;
|
|
|
|
|
|
|
|
_render_thread_mode = RENDER_THREAD_SAFE;
|
|
|
|
|
2017-10-05 19:41:42 +00:00
|
|
|
_allow_hidpi = false;
|
2017-07-19 11:49:19 +00:00
|
|
|
_stack_bottom = (void *)(&stack_bottom);
|
2017-09-22 05:56:02 +00:00
|
|
|
|
|
|
|
_logger = NULL;
|
|
|
|
_set_logger(memnew(StdLogger));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OS::~OS() {
|
2017-09-22 05:56:02 +00:00
|
|
|
memdelete(_logger);
|
2017-03-05 15:44:50 +00:00
|
|
|
singleton = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|