summaryrefslogtreecommitdiff
path: root/core/os
diff options
context:
space:
mode:
Diffstat (limited to 'core/os')
-rw-r--r--core/os/keyboard.cpp40
-rw-r--r--core/os/keyboard.h117
-rw-r--r--core/os/memory.h23
-rw-r--r--core/os/os.cpp97
-rw-r--r--core/os/os.h30
-rw-r--r--core/os/pool_allocator.cpp4
-rw-r--r--core/os/pool_allocator.h26
-rw-r--r--core/os/spin_lock.h1
-rw-r--r--core/os/thread.h1
-rw-r--r--core/os/time.cpp144
-rw-r--r--core/os/time.h6
11 files changed, 305 insertions, 184 deletions
diff --git a/core/os/keyboard.cpp b/core/os/keyboard.cpp
index 24907d34c8..a592791d06 100644
--- a/core/os/keyboard.cpp
+++ b/core/os/keyboard.cpp
@@ -61,7 +61,7 @@ static const _KeyCodeText _keycodes[] = {
{Key::PAGEDOWN ,"PageDown"},
{Key::SHIFT ,"Shift"},
{Key::CTRL ,"Ctrl"},
-#ifdef OSX_ENABLED
+#ifdef MACOS_ENABLED
{Key::META ,"Command"},
#else
{Key::META ,"Meta"},
@@ -86,6 +86,25 @@ static const _KeyCodeText _keycodes[] = {
{Key::F14 ,"F14"},
{Key::F15 ,"F15"},
{Key::F16 ,"F16"},
+ {Key::F17 ,"F17"},
+ {Key::F18 ,"F18"},
+ {Key::F19 ,"F19"},
+ {Key::F20 ,"F20"},
+ {Key::F21 ,"F21"},
+ {Key::F22 ,"F22"},
+ {Key::F23 ,"F23"},
+ {Key::F24 ,"F24"},
+ {Key::F25 ,"F25"},
+ {Key::F26 ,"F26"},
+ {Key::F27 ,"F27"},
+ {Key::F28 ,"F28"},
+ {Key::F29 ,"F29"},
+ {Key::F30 ,"F30"},
+ {Key::F31 ,"F31"},
+ {Key::F32 ,"F32"},
+ {Key::F33 ,"F33"},
+ {Key::F34 ,"F34"},
+ {Key::F35 ,"F35"},
{Key::KP_MULTIPLY ,"Kp Multiply"},
{Key::KP_DIVIDE ,"Kp Divide"},
{Key::KP_SUBTRACT ,"Kp Subtract"},
@@ -333,6 +352,25 @@ bool keycode_has_unicode(Key p_keycode) {
case Key::F14:
case Key::F15:
case Key::F16:
+ case Key::F17:
+ case Key::F18:
+ case Key::F19:
+ case Key::F20:
+ case Key::F21:
+ case Key::F22:
+ case Key::F23:
+ case Key::F24:
+ case Key::F25:
+ case Key::F26:
+ case Key::F27:
+ case Key::F28:
+ case Key::F29:
+ case Key::F30:
+ case Key::F31:
+ case Key::F32:
+ case Key::F33:
+ case Key::F34:
+ case Key::F35:
case Key::SUPER_L:
case Key::SUPER_R:
case Key::MENU:
diff --git a/core/os/keyboard.h b/core/os/keyboard.h
index 86b86fb970..29418049cb 100644
--- a/core/os/keyboard.h
+++ b/core/os/keyboard.h
@@ -85,6 +85,25 @@ enum class Key {
F14 = SPECIAL | 0x29,
F15 = SPECIAL | 0x2A,
F16 = SPECIAL | 0x2B,
+ F17 = SPECIAL | 0x2C,
+ F18 = SPECIAL | 0x2D,
+ F19 = SPECIAL | 0x2E,
+ F20 = SPECIAL | 0x2F,
+ F21 = SPECIAL | 0x30,
+ F22 = SPECIAL | 0x31,
+ F23 = SPECIAL | 0x32,
+ F24 = SPECIAL | 0x33,
+ F25 = SPECIAL | 0x34,
+ F26 = SPECIAL | 0x35,
+ F27 = SPECIAL | 0x36,
+ F28 = SPECIAL | 0x37,
+ F29 = SPECIAL | 0x38,
+ F30 = SPECIAL | 0x39,
+ F31 = SPECIAL | 0x3A,
+ F32 = SPECIAL | 0x3B,
+ F33 = SPECIAL | 0x3C,
+ F34 = SPECIAL | 0x3D,
+ F35 = SPECIAL | 0x3E,
KP_MULTIPLY = SPECIAL | 0x81,
KP_DIVIDE = SPECIAL | 0x82,
KP_SUBTRACT = SPECIAL | 0x83,
@@ -100,54 +119,54 @@ enum class Key {
KP_7 = SPECIAL | 0x8D,
KP_8 = SPECIAL | 0x8E,
KP_9 = SPECIAL | 0x8F,
- SUPER_L = SPECIAL | 0x2C,
- SUPER_R = SPECIAL | 0x2D,
- MENU = SPECIAL | 0x2E,
- HYPER_L = SPECIAL | 0x2F,
- HYPER_R = SPECIAL | 0x30,
- HELP = SPECIAL | 0x31,
- DIRECTION_L = SPECIAL | 0x32,
- DIRECTION_R = SPECIAL | 0x33,
- BACK = SPECIAL | 0x40,
- FORWARD = SPECIAL | 0x41,
- STOP = SPECIAL | 0x42,
- REFRESH = SPECIAL | 0x43,
- VOLUMEDOWN = SPECIAL | 0x44,
- VOLUMEMUTE = SPECIAL | 0x45,
- VOLUMEUP = SPECIAL | 0x46,
- BASSBOOST = SPECIAL | 0x47,
- BASSUP = SPECIAL | 0x48,
- BASSDOWN = SPECIAL | 0x49,
- TREBLEUP = SPECIAL | 0x4A,
- TREBLEDOWN = SPECIAL | 0x4B,
- MEDIAPLAY = SPECIAL | 0x4C,
- MEDIASTOP = SPECIAL | 0x4D,
- MEDIAPREVIOUS = SPECIAL | 0x4E,
- MEDIANEXT = SPECIAL | 0x4F,
- MEDIARECORD = SPECIAL | 0x50,
- HOMEPAGE = SPECIAL | 0x51,
- FAVORITES = SPECIAL | 0x52,
- SEARCH = SPECIAL | 0x53,
- STANDBY = SPECIAL | 0x54,
- OPENURL = SPECIAL | 0x55,
- LAUNCHMAIL = SPECIAL | 0x56,
- LAUNCHMEDIA = SPECIAL | 0x57,
- LAUNCH0 = SPECIAL | 0x58,
- LAUNCH1 = SPECIAL | 0x59,
- LAUNCH2 = SPECIAL | 0x5A,
- LAUNCH3 = SPECIAL | 0x5B,
- LAUNCH4 = SPECIAL | 0x5C,
- LAUNCH5 = SPECIAL | 0x5D,
- LAUNCH6 = SPECIAL | 0x5E,
- LAUNCH7 = SPECIAL | 0x5F,
- LAUNCH8 = SPECIAL | 0x60,
- LAUNCH9 = SPECIAL | 0x61,
- LAUNCHA = SPECIAL | 0x62,
- LAUNCHB = SPECIAL | 0x63,
- LAUNCHC = SPECIAL | 0x64,
- LAUNCHD = SPECIAL | 0x65,
- LAUNCHE = SPECIAL | 0x66,
- LAUNCHF = SPECIAL | 0x67,
+ SUPER_L = SPECIAL | 0x40,
+ SUPER_R = SPECIAL | 0x41,
+ MENU = SPECIAL | 0x42,
+ HYPER_L = SPECIAL | 0x43,
+ HYPER_R = SPECIAL | 0x44,
+ HELP = SPECIAL | 0x45,
+ DIRECTION_L = SPECIAL | 0x46,
+ DIRECTION_R = SPECIAL | 0x47,
+ BACK = SPECIAL | 0x48,
+ FORWARD = SPECIAL | 0x49,
+ STOP = SPECIAL | 0x4A,
+ REFRESH = SPECIAL | 0x4B,
+ VOLUMEDOWN = SPECIAL | 0x4C,
+ VOLUMEMUTE = SPECIAL | 0x4D,
+ VOLUMEUP = SPECIAL | 0x4E,
+ BASSBOOST = SPECIAL | 0x4F,
+ BASSUP = SPECIAL | 0x50,
+ BASSDOWN = SPECIAL | 0x51,
+ TREBLEUP = SPECIAL | 0x52,
+ TREBLEDOWN = SPECIAL | 0x53,
+ MEDIAPLAY = SPECIAL | 0x54,
+ MEDIASTOP = SPECIAL | 0x55,
+ MEDIAPREVIOUS = SPECIAL | 0x56,
+ MEDIANEXT = SPECIAL | 0x57,
+ MEDIARECORD = SPECIAL | 0x58,
+ HOMEPAGE = SPECIAL | 0x59,
+ FAVORITES = SPECIAL | 0x5A,
+ SEARCH = SPECIAL | 0x5B,
+ STANDBY = SPECIAL | 0x5C,
+ OPENURL = SPECIAL | 0x5D,
+ LAUNCHMAIL = SPECIAL | 0x5E,
+ LAUNCHMEDIA = SPECIAL | 0x5F,
+ LAUNCH0 = SPECIAL | 0x60,
+ LAUNCH1 = SPECIAL | 0x61,
+ LAUNCH2 = SPECIAL | 0x62,
+ LAUNCH3 = SPECIAL | 0x63,
+ LAUNCH4 = SPECIAL | 0x64,
+ LAUNCH5 = SPECIAL | 0x65,
+ LAUNCH6 = SPECIAL | 0x66,
+ LAUNCH7 = SPECIAL | 0x67,
+ LAUNCH8 = SPECIAL | 0x68,
+ LAUNCH9 = SPECIAL | 0x69,
+ LAUNCHA = SPECIAL | 0x6A,
+ LAUNCHB = SPECIAL | 0x6B,
+ LAUNCHC = SPECIAL | 0x6C,
+ LAUNCHD = SPECIAL | 0x6D,
+ LAUNCHE = SPECIAL | 0x6E,
+ LAUNCHF = SPECIAL | 0x6F,
UNKNOWN = SPECIAL | 0xFFFFFF,
@@ -294,7 +313,7 @@ enum class Key {
enum class KeyModifierMask {
CODE_MASK = ((1 << 25) - 1), ///< Apply this mask to any keycode to remove modifiers.
- MODIFIER_MASK = (0xFF << 24), ///< Apply this mask to isolate modifiers.
+ MODIFIER_MASK = (0x7F << 24), ///< Apply this mask to isolate modifiers.
SHIFT = (1 << 25),
ALT = (1 << 26),
META = (1 << 27),
diff --git a/core/os/memory.h b/core/os/memory.h
index 27eaad5010..0e1afe027e 100644
--- a/core/os/memory.h
+++ b/core/os/memory.h
@@ -36,6 +36,7 @@
#include <stddef.h>
#include <new>
+#include <type_traits>
#ifndef PAD_ALIGN
#define PAD_ALIGN 16 //must always be greater than this at much
@@ -104,7 +105,7 @@ void memdelete(T *p_class) {
if (!predelete_handler(p_class)) {
return; // doesn't want to be deleted
}
- if (!__has_trivial_destructor(T)) {
+ if (!std::is_trivially_destructible<T>::value) {
p_class->~T();
}
@@ -116,7 +117,7 @@ void memdelete_allocator(T *p_class) {
if (!predelete_handler(p_class)) {
return; // doesn't want to be deleted
}
- if (!__has_trivial_destructor(T)) {
+ if (!std::is_trivially_destructible<T>::value) {
p_class->~T();
}
@@ -146,7 +147,7 @@ T *memnew_arr_template(size_t p_elements) {
ERR_FAIL_COND_V(!mem, failptr);
*(mem - 1) = p_elements;
- if (!__has_trivial_constructor(T)) {
+ if (!std::is_trivially_constructible<T>::value) {
T *elems = (T *)mem;
/* call operator new */
@@ -173,7 +174,7 @@ template <typename T>
void memdelete_arr(T *p_class) {
uint64_t *ptr = (uint64_t *)p_class;
- if (!__has_trivial_destructor(T)) {
+ if (!std::is_trivially_destructible<T>::value) {
uint64_t elem_count = *(ptr - 1);
for (uint64_t i = 0; i < elem_count; i++) {
@@ -186,9 +187,9 @@ void memdelete_arr(T *p_class) {
struct _GlobalNil {
int color = 1;
- _GlobalNil *right;
- _GlobalNil *left;
- _GlobalNil *parent;
+ _GlobalNil *right = nullptr;
+ _GlobalNil *left = nullptr;
+ _GlobalNil *parent = nullptr;
_GlobalNil();
};
@@ -197,4 +198,12 @@ struct _GlobalNilClass {
static _GlobalNil _nil;
};
+template <class T>
+class DefaultTypedAllocator {
+public:
+ template <class... Args>
+ _FORCE_INLINE_ T *new_allocation(const Args &&...p_args) { return memnew(T(p_args...)); }
+ _FORCE_INLINE_ void delete_allocation(T *p_allocation) { memdelete(p_allocation); }
+};
+
#endif // MEMORY_H
diff --git a/core/os/os.cpp b/core/os/os.cpp
index 2e5db145a4..6091079241 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -80,7 +80,9 @@ void OS::print_error(const char *p_function, const char *p_file, int p_line, con
return;
}
- _logger->log_error(p_function, p_file, p_line, p_code, p_rationale, p_editor_notify, p_type);
+ if (_logger) {
+ _logger->log_error(p_function, p_file, p_line, p_code, p_rationale, p_editor_notify, p_type);
+ }
}
void OS::print(const char *p_format, ...) {
@@ -91,7 +93,24 @@ void OS::print(const char *p_format, ...) {
va_list argp;
va_start(argp, p_format);
- _logger->logv(p_format, argp, false);
+ if (_logger) {
+ _logger->logv(p_format, argp, false);
+ }
+
+ va_end(argp);
+}
+
+void OS::print_rich(const char *p_format, ...) {
+ if (!_stdout_enabled) {
+ return;
+ }
+
+ va_list argp;
+ va_start(argp, p_format);
+
+ if (_logger) {
+ _logger->logv(p_format, argp, false);
+ }
va_end(argp);
}
@@ -104,7 +123,9 @@ void OS::printerr(const char *p_format, ...) {
va_list argp;
va_start(argp, p_format);
- _logger->logv(p_format, argp, true);
+ if (_logger) {
+ _logger->logv(p_format, argp, true);
+ }
va_end(argp);
}
@@ -138,17 +159,13 @@ int OS::get_process_id() const {
}
void OS::vibrate_handheld(int p_duration_ms) {
- WARN_PRINT("vibrate_handheld() only works with Android and iOS");
+ WARN_PRINT("vibrate_handheld() only works with Android, iOS and HTML5");
}
bool OS::is_stdout_verbose() const {
return _verbose_stdout;
}
-bool OS::is_single_window() const {
- return _single_window;
-}
-
bool OS::is_stdout_debug_enabled() const {
return _debug_stdout;
}
@@ -173,7 +190,7 @@ void OS::dump_memory_to_file(const char *p_file) {
//Memory::dump_static_mem_to_file(p_file);
}
-static FileAccess *_OSPRF = nullptr;
+static Ref<FileAccess> _OSPRF;
static void _OS_printres(Object *p_obj) {
Resource *res = Object::cast_to<Resource>(p_obj);
@@ -182,7 +199,7 @@ static void _OS_printres(Object *p_obj) {
}
String str = vformat("%s - %s - %s", res->to_string(), res->get_name(), res->get_path());
- if (_OSPRF) {
+ if (_OSPRF.is_valid()) {
_OSPRF->store_line(str);
} else {
print_line(str);
@@ -190,24 +207,19 @@ static void _OS_printres(Object *p_obj) {
}
void OS::print_all_resources(String p_to_file) {
- ERR_FAIL_COND(!p_to_file.is_empty() && _OSPRF);
+ ERR_FAIL_COND(!p_to_file.is_empty() && _OSPRF.is_valid());
if (!p_to_file.is_empty()) {
Error err;
_OSPRF = FileAccess::open(p_to_file, FileAccess::WRITE, &err);
if (err != OK) {
- _OSPRF = nullptr;
+ _OSPRF.unref();
ERR_FAIL_MSG("Can't print all resources to file: " + String(p_to_file) + ".");
}
}
ObjectDB::debug_objects(_OS_printres);
- if (!p_to_file.is_empty()) {
- if (_OSPRF) {
- memdelete(_OSPRF);
- }
- _OSPRF = nullptr;
- }
+ _OSPRF.unref();
}
void OS::print_resources_in_use(bool p_short) {
@@ -236,6 +248,11 @@ String OS::get_locale_language() const {
return get_locale().left(3).replace("_", "");
}
+// Embedded PCK offset.
+uint64_t OS::get_embedded_pck_offset() const {
+ return 0;
+}
+
// 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(" ");
@@ -332,7 +349,7 @@ void OS::ensure_user_data_dir() {
return;
}
- DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
+ Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
Error err = da->make_dir_recursive(dd);
ERR_FAIL_COND_MSG(err != OK, "Error attempting to create data dir: " + dd + ".");
}
@@ -341,9 +358,10 @@ String OS::get_model_name() const {
return "GenericDevice";
}
-void OS::set_cmdline(const char *p_execpath, const List<String> &p_args) {
+void OS::set_cmdline(const char *p_execpath, const List<String> &p_args, const List<String> &p_user_args) {
_execpath = String::utf8(p_execpath);
_cmdline = p_args;
+ _user_args = p_user_args;
}
String OS::get_unique_id() const {
@@ -382,6 +400,10 @@ bool OS::has_feature(const String &p_feature) {
return true;
}
+ if (p_feature == "movie") {
+ return _writing_movie;
+ }
+
#ifdef DEBUG_ENABLED
if (p_feature == "debug") {
return true;
@@ -407,19 +429,29 @@ bool OS::has_feature(const String &p_feature) {
if (sizeof(void *) == 4 && p_feature == "32") {
return true;
}
-#if defined(__x86_64) || defined(__x86_64__) || defined(__amd64__)
+#if defined(__x86_64) || defined(__x86_64__) || defined(__amd64__) || defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(_M_X64)
+#if defined(__x86_64) || defined(__x86_64__) || defined(__amd64__) || defined(_M_X64)
if (p_feature == "x86_64") {
return true;
}
-#elif (defined(__i386) || defined(__i386__))
+#elif defined(__i386) || defined(__i386__) || defined(_M_IX86)
+ if (p_feature == "x86_32") {
+ return true;
+ }
+#endif
if (p_feature == "x86") {
return true;
}
-#elif defined(__aarch64__)
+#elif defined(__arm__) || defined(__aarch64__) || defined(_M_ARM) || defined(_M_ARM64)
+#if defined(__aarch64__) || defined(_M_ARM64)
if (p_feature == "arm64") {
return true;
}
-#elif defined(__arm__)
+#elif defined(__arm__) || defined(_M_ARM)
+ if (p_feature == "arm32") {
+ return true;
+ }
+#endif
#if defined(__ARM_ARCH_7A__)
if (p_feature == "armv7a" || p_feature == "armv7") {
return true;
@@ -451,6 +483,19 @@ bool OS::has_feature(const String &p_feature) {
if (p_feature == "ppc") {
return true;
}
+#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;
+ }
#endif
if (_check_internal_feature_support(p_feature)) {
@@ -550,6 +595,8 @@ OS::OS() {
}
OS::~OS() {
- memdelete(_logger);
+ if (_logger) {
+ memdelete(_logger);
+ }
singleton = nullptr;
}
diff --git a/core/os/os.h b/core/os/os.h
index 808d704b3d..be9d73c22d 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -46,21 +46,19 @@ class OS {
static uint64_t target_ticks;
String _execpath;
List<String> _cmdline;
+ List<String> _user_args;
bool _keep_screen_on = true; // set default value to true, because this had been true before godot 2.0.
bool low_processor_usage_mode = false;
int low_processor_usage_mode_sleep_usec = 10000;
bool _verbose_stdout = false;
bool _debug_stdout = false;
- bool _single_window = false;
String _local_clipboard;
int _exit_code = EXIT_FAILURE; // unexpected exit is marked as failure
- int _orientation;
bool _allow_hidpi = false;
bool _allow_layered = false;
bool _stdout_enabled = true;
bool _stderr_enabled = true;
-
- char *last_error;
+ bool _writing_movie = false;
CompositeLogger *_logger = nullptr;
@@ -70,7 +68,7 @@ class OS {
// for the user interface we keep a record of the current display driver
// so we can retrieve the rendering drivers available
int _display_driver_id = -1;
- String _current_rendering_driver_name = "";
+ String _current_rendering_driver_name;
protected:
void _set_logger(CompositeLogger *p_logger);
@@ -85,11 +83,6 @@ public:
RENDER_SEPARATE_THREAD
};
- enum RenderMainThreadMode {
- RENDER_MAIN_THREAD_ONLY,
- RENDER_ANY_THREAD,
- };
-
protected:
friend class Main;
// Needed by tests to setup command-line args.
@@ -97,7 +90,6 @@ protected:
HasServerFeatureCallback has_server_feature_callback = nullptr;
RenderThreadMode _render_thread_mode = RENDER_THREAD_SAFE;
- RenderMainThreadMode _render_main_thread_mode = RENDER_ANY_THREAD;
// Functions used by Main to initialize/deinitialize the OS.
void add_logger(Logger *p_logger);
@@ -114,7 +106,7 @@ protected:
virtual void finalize() = 0;
virtual void finalize_core() = 0;
- virtual void set_cmdline(const char *p_execpath, const List<String> &p_args);
+ virtual void set_cmdline(const char *p_execpath, const List<String> &p_args, const List<String> &p_user_args);
virtual bool _check_internal_feature_support(const String &p_feature) = 0;
@@ -128,6 +120,7 @@ public:
void print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, bool p_editor_notify = false, Logger::ErrorType p_type = Logger::ERR_ERROR);
void print(const char *p_format, ...) _PRINTF_FORMAT_ATTRIBUTE_2_3;
+ void print_rich(const char *p_format, ...) _PRINTF_FORMAT_ATTRIBUTE_2_3;
void printerr(const char *p_format, ...) _PRINTF_FORMAT_ATTRIBUTE_2_3;
virtual String get_stdin_string(bool p_block = true) = 0;
@@ -140,7 +133,7 @@ public:
virtual void alert(const String &p_alert, const String &p_title = "ALERT!");
- virtual Error open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path = false) { return ERR_UNAVAILABLE; }
+ virtual Error open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path = false, String *r_resolved_path = nullptr) { return ERR_UNAVAILABLE; }
virtual Error close_dynamic_library(void *p_library_handle) { return ERR_UNAVAILABLE; }
virtual Error get_dynamic_library_symbol_handle(void *p_library_handle, const String p_name, void *&p_symbol_handle, bool p_optional = false) { return ERR_UNAVAILABLE; }
@@ -149,12 +142,15 @@ public:
virtual void set_low_processor_usage_mode_sleep_usec(int p_usec);
virtual int get_low_processor_usage_mode_sleep_usec() const;
+ virtual Vector<String> get_system_fonts() const { return Vector<String>(); };
+ virtual String get_system_font_path(const String &p_font_name, bool p_bold = false, bool p_italic = false) const { return String(); };
virtual String get_executable_path() const;
virtual Error execute(const String &p_path, const List<String> &p_arguments, String *r_pipe = nullptr, int *r_exitcode = nullptr, bool read_stderr = false, Mutex *p_pipe_mutex = nullptr, bool p_open_console = false) = 0;
virtual Error create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id = nullptr, bool p_open_console = false) = 0;
virtual Error create_instance(const List<String> &p_arguments, ProcessID *r_child_id = nullptr) { return create_process(get_executable_path(), p_arguments, r_child_id); };
virtual Error kill(const ProcessID &p_pid) = 0;
virtual int get_process_id() const;
+ virtual bool is_process_running(const ProcessID &p_pid) const = 0;
virtual void vibrate_handheld(int p_duration_ms = 500);
virtual Error shell_open(String p_uri);
@@ -166,6 +162,8 @@ public:
virtual String get_name() const = 0;
virtual List<String> get_cmdline_args() const { return _cmdline; }
+ virtual List<String> get_cmdline_user_args() const { return _user_args; }
+ virtual List<String> get_cmdline_platform_args() const { return List<String>(); }
virtual String get_model_name() const;
bool is_layered_allowed() const { return _allow_layered; }
@@ -244,8 +242,6 @@ public:
void set_stdout_enabled(bool p_enabled);
void set_stderr_enabled(bool p_enabled);
- virtual bool is_single_window() const;
-
virtual void disable_crash_handler() {}
virtual bool is_disable_crash_handler() const { return false; }
virtual void initialize_debugging() {}
@@ -260,12 +256,12 @@ public:
virtual uint64_t get_free_static_memory() const;
RenderThreadMode get_render_thread_mode() const { return _render_thread_mode; }
- RenderMainThreadMode get_render_main_thread_mode() const { return _render_main_thread_mode; }
- void set_render_main_thread_mode(RenderMainThreadMode p_thread_mode) { _render_main_thread_mode = p_thread_mode; }
virtual String get_locale() const;
String get_locale_language() const;
+ virtual uint64_t get_embedded_pck_offset() const;
+
String get_safe_dir_name(const String &p_dir_name, bool p_allow_dir_separator = false) const;
virtual String get_godot_dir_name() const;
diff --git a/core/os/pool_allocator.cpp b/core/os/pool_allocator.cpp
index 190617f967..f622e2c7c5 100644
--- a/core/os/pool_allocator.cpp
+++ b/core/os/pool_allocator.cpp
@@ -149,7 +149,7 @@ void PoolAllocator::compact_up(int p_from) {
}
}
-bool PoolAllocator::find_entry_index(EntryIndicesPos *p_map_pos, Entry *p_entry) {
+bool PoolAllocator::find_entry_index(EntryIndicesPos *p_map_pos, const Entry *p_entry) {
EntryArrayPos entry_pos = entry_max;
for (int i = 0; i < entry_count; i++) {
@@ -424,7 +424,7 @@ bool PoolAllocator::is_locked(ID p_mem) const {
}
mt_lock();
- const Entry *e = ((PoolAllocator *)(this))->get_entry(p_mem);
+ const Entry *e = const_cast<PoolAllocator *>(this)->get_entry(p_mem);
if (!e) {
mt_unlock();
ERR_PRINT("!e");
diff --git a/core/os/pool_allocator.h b/core/os/pool_allocator.h
index 11a252bc54..a7a8523aa4 100644
--- a/core/os/pool_allocator.h
+++ b/core/os/pool_allocator.h
@@ -75,22 +75,22 @@ private:
typedef int EntryArrayPos;
typedef int EntryIndicesPos;
- Entry *entry_array;
- int *entry_indices;
- int entry_max;
- int entry_count;
+ Entry *entry_array = nullptr;
+ int *entry_indices = nullptr;
+ int entry_max = 0;
+ int entry_count = 0;
- uint8_t *pool;
- void *mem_ptr;
- int pool_size;
+ uint8_t *pool = nullptr;
+ void *mem_ptr = nullptr;
+ int pool_size = 0;
- int free_mem;
- int free_mem_peak;
+ int free_mem = 0;
+ int free_mem_peak = 0;
- unsigned int check_count;
- int align;
+ unsigned int check_count = 0;
+ int align = 1;
- bool needs_locking;
+ bool needs_locking = false;
inline int entry_end(const Entry &p_entry) const {
return p_entry.pos + aligned(p_entry.len);
@@ -108,7 +108,7 @@ private:
void compact_up(int p_from = 0);
bool get_free_entry(EntryArrayPos *p_pos);
bool find_hole(EntryArrayPos *p_pos, int p_for_size);
- bool find_entry_index(EntryIndicesPos *p_map_pos, Entry *p_entry);
+ bool find_entry_index(EntryIndicesPos *p_map_pos, const Entry *p_entry);
Entry *get_entry(ID p_mem);
const Entry *get_entry(ID p_mem) const;
diff --git a/core/os/spin_lock.h b/core/os/spin_lock.h
index 6e8d7f46d5..80eeef3386 100644
--- a/core/os/spin_lock.h
+++ b/core/os/spin_lock.h
@@ -48,4 +48,5 @@ public:
locked.clear(std::memory_order_release);
}
};
+
#endif // SPIN_LOCK_H
diff --git a/core/os/thread.h b/core/os/thread.h
index 3382dd81f9..0fb283e224 100644
--- a/core/os/thread.h
+++ b/core/os/thread.h
@@ -123,4 +123,5 @@ public:
};
#endif // THREAD_H
+
#endif // PLATFORM_THREAD_OVERRIDE
diff --git a/core/os/time.cpp b/core/os/time.cpp
index e339805475..a30e2a906b 100644
--- a/core/os/time.cpp
+++ b/core/os/time.cpp
@@ -95,16 +95,21 @@ VARIANT_ENUM_CAST(Time::Weekday);
day = day_number_copy + 1; \
}
-#define VALIDATE_YMDHMS \
- ERR_FAIL_COND_V_MSG(month == 0, 0, "Invalid month value of: " + itos(month) + ", months are 1-indexed and cannot be 0. See the Time.Month enum for valid values."); \
- ERR_FAIL_COND_V_MSG(month > 12, 0, "Invalid month value of: " + itos(month) + ". See the Time.Month enum for valid values."); \
- ERR_FAIL_COND_V_MSG(hour > 23, 0, "Invalid hour value of: " + itos(hour) + "."); \
- ERR_FAIL_COND_V_MSG(minute > 59, 0, "Invalid minute value of: " + itos(minute) + "."); \
- ERR_FAIL_COND_V_MSG(second > 59, 0, "Invalid second value of: " + itos(second) + " (leap seconds are not supported)."); \
- /* Do this check after month is tested as valid. */ \
- ERR_FAIL_COND_V_MSG(day == 0, 0, "Invalid day value of: " + itos(month) + ", days are 1-indexed and cannot be 0."); \
- uint8_t days_in_this_month = MONTH_DAYS_TABLE[IS_LEAP_YEAR(year)][month - 1]; \
- ERR_FAIL_COND_V_MSG(day > days_in_this_month, 0, "Invalid day value of: " + itos(day) + " which is larger than the maximum for this month, " + itos(days_in_this_month) + ".");
+#define VALIDATE_YMDHMS(ret) \
+ ERR_FAIL_COND_V_MSG(month == 0, ret, "Invalid month value of: " + itos(month) + ", months are 1-indexed and cannot be 0. See the Time.Month enum for valid values."); \
+ ERR_FAIL_COND_V_MSG(month < 0, ret, "Invalid month value of: " + itos(month) + "."); \
+ ERR_FAIL_COND_V_MSG(month > 12, ret, "Invalid month value of: " + itos(month) + ". See the Time.Month enum for valid values."); \
+ ERR_FAIL_COND_V_MSG(hour > 23, ret, "Invalid hour value of: " + itos(hour) + "."); \
+ ERR_FAIL_COND_V_MSG(hour < 0, ret, "Invalid hour value of: " + itos(hour) + "."); \
+ ERR_FAIL_COND_V_MSG(minute > 59, ret, "Invalid minute value of: " + itos(minute) + "."); \
+ ERR_FAIL_COND_V_MSG(minute < 0, ret, "Invalid minute value of: " + itos(minute) + "."); \
+ ERR_FAIL_COND_V_MSG(second > 59, ret, "Invalid second value of: " + itos(second) + " (leap seconds are not supported)."); \
+ ERR_FAIL_COND_V_MSG(second < 0, ret, "Invalid second value of: " + itos(second) + "."); \
+ ERR_FAIL_COND_V_MSG(day == 0, ret, "Invalid day value of: " + itos(day) + ", days are 1-indexed and cannot be 0."); \
+ ERR_FAIL_COND_V_MSG(day < 0, ret, "Invalid day value of: " + itos(day) + "."); \
+ /* Do this check after month is tested as valid. */ \
+ uint8_t days_in_this_month = MONTH_DAYS_TABLE[IS_LEAP_YEAR(year)][month - 1]; \
+ ERR_FAIL_COND_V_MSG(day > days_in_this_month, ret, "Invalid day value of: " + itos(day) + " which is larger than the maximum for this month, " + itos(days_in_this_month) + ".");
#define YMD_TO_DAY_NUMBER \
/* The day number since Unix epoch (0-index). Days before 1970 are negative. */ \
@@ -124,61 +129,65 @@ VARIANT_ENUM_CAST(Time::Weekday);
} \
}
-#define PARSE_ISO8601_STRING \
- int64_t year = UNIX_EPOCH_YEAR_AD; \
- Month month = MONTH_JANUARY; \
- uint8_t day = 1; \
- uint8_t hour = 0; \
- uint8_t minute = 0; \
- uint8_t second = 0; \
- { \
- bool has_date = false, has_time = false; \
- String date, time; \
- if (p_datetime.find_char('T') > 0) { \
- has_date = has_time = true; \
- PackedStringArray array = p_datetime.split("T"); \
- date = array[0]; \
- time = array[1]; \
- } else if (p_datetime.find_char(' ') > 0) { \
- has_date = has_time = true; \
- PackedStringArray array = p_datetime.split(" "); \
- date = array[0]; \
- time = array[1]; \
- } else if (p_datetime.find_char('-', 1) > 0) { \
- has_date = true; \
- date = p_datetime; \
- } else if (p_datetime.find_char(':') > 0) { \
- has_time = true; \
- time = p_datetime; \
- } \
- /* Set the variables from the contents of the string. */ \
- if (has_date) { \
- PackedInt32Array array = date.split_ints("-", false); \
- year = array[0]; \
- month = (Month)array[1]; \
- day = array[2]; \
- /* Handle negative years. */ \
- if (p_datetime.find_char('-') == 0) { \
- year *= -1; \
- } \
- } \
- if (has_time) { \
- PackedInt32Array array = time.split_ints(":", false); \
- hour = array[0]; \
- minute = array[1]; \
- second = array[2]; \
- } \
+#define PARSE_ISO8601_STRING(ret) \
+ int64_t year = UNIX_EPOCH_YEAR_AD; \
+ Month month = MONTH_JANUARY; \
+ int day = 1; \
+ int hour = 0; \
+ int minute = 0; \
+ int second = 0; \
+ { \
+ bool has_date = false, has_time = false; \
+ String date, time; \
+ if (p_datetime.find_char('T') > 0) { \
+ has_date = has_time = true; \
+ PackedStringArray array = p_datetime.split("T"); \
+ ERR_FAIL_COND_V_MSG(array.size() < 2, ret, "Invalid ISO 8601 date/time string."); \
+ date = array[0]; \
+ time = array[1]; \
+ } else if (p_datetime.find_char(' ') > 0) { \
+ has_date = has_time = true; \
+ PackedStringArray array = p_datetime.split(" "); \
+ ERR_FAIL_COND_V_MSG(array.size() < 2, ret, "Invalid ISO 8601 date/time string."); \
+ date = array[0]; \
+ time = array[1]; \
+ } else if (p_datetime.find_char('-', 1) > 0) { \
+ has_date = true; \
+ date = p_datetime; \
+ } else if (p_datetime.find_char(':') > 0) { \
+ has_time = true; \
+ time = p_datetime; \
+ } \
+ /* Set the variables from the contents of the string. */ \
+ if (has_date) { \
+ PackedInt32Array array = date.split_ints("-", false); \
+ ERR_FAIL_COND_V_MSG(array.size() < 3, ret, "Invalid ISO 8601 date string."); \
+ year = array[0]; \
+ month = (Month)array[1]; \
+ day = array[2]; \
+ /* Handle negative years. */ \
+ if (p_datetime.find_char('-') == 0) { \
+ year *= -1; \
+ } \
+ } \
+ if (has_time) { \
+ PackedInt32Array array = time.split_ints(":", false); \
+ ERR_FAIL_COND_V_MSG(array.size() < 3, ret, "Invalid ISO 8601 time string."); \
+ hour = array[0]; \
+ minute = array[1]; \
+ second = array[2]; \
+ } \
}
#define EXTRACT_FROM_DICTIONARY \
/* Get all time values from the dictionary. If it doesn't exist, set the */ \
/* values to the default values for Unix epoch (1970-01-01 00:00:00). */ \
int64_t year = p_datetime.has(YEAR_KEY) ? int64_t(p_datetime[YEAR_KEY]) : UNIX_EPOCH_YEAR_AD; \
- Month month = Month((p_datetime.has(MONTH_KEY)) ? uint8_t(p_datetime[MONTH_KEY]) : 1); \
- uint8_t day = p_datetime.has(DAY_KEY) ? uint8_t(p_datetime[DAY_KEY]) : 1; \
- uint8_t hour = p_datetime.has(HOUR_KEY) ? uint8_t(p_datetime[HOUR_KEY]) : 0; \
- uint8_t minute = p_datetime.has(MINUTE_KEY) ? uint8_t(p_datetime[MINUTE_KEY]) : 0; \
- uint8_t second = p_datetime.has(SECOND_KEY) ? uint8_t(p_datetime[SECOND_KEY]) : 0;
+ Month month = Month((p_datetime.has(MONTH_KEY)) ? int(p_datetime[MONTH_KEY]) : 1); \
+ int day = p_datetime.has(DAY_KEY) ? int(p_datetime[DAY_KEY]) : 1; \
+ int hour = p_datetime.has(HOUR_KEY) ? int(p_datetime[HOUR_KEY]) : 0; \
+ int minute = p_datetime.has(MINUTE_KEY) ? int(p_datetime[MINUTE_KEY]) : 0; \
+ int second = p_datetime.has(SECOND_KEY) ? int(p_datetime[SECOND_KEY]) : 0;
Time *Time::singleton = nullptr;
@@ -252,8 +261,8 @@ String Time::get_time_string_from_unix_time(int64_t p_unix_time_val) const {
return vformat("%02d:%02d:%02d", hour, minute, second);
}
-Dictionary Time::get_datetime_dict_from_string(String p_datetime, bool p_weekday) const {
- PARSE_ISO8601_STRING
+Dictionary Time::get_datetime_dict_from_datetime_string(String p_datetime, bool p_weekday) const {
+ PARSE_ISO8601_STRING(Dictionary())
Dictionary dict;
dict[YEAR_KEY] = year;
dict[MONTH_KEY] = (uint8_t)month;
@@ -270,9 +279,10 @@ Dictionary Time::get_datetime_dict_from_string(String p_datetime, bool p_weekday
return dict;
}
-String Time::get_datetime_string_from_dict(const Dictionary p_datetime, bool p_use_space) const {
+String Time::get_datetime_string_from_datetime_dict(const Dictionary p_datetime, bool p_use_space) const {
ERR_FAIL_COND_V_MSG(p_datetime.is_empty(), "", "Invalid datetime Dictionary: Dictionary is empty.");
EXTRACT_FROM_DICTIONARY
+ VALIDATE_YMDHMS("")
// vformat only supports up to 6 arguments, so we need to split this up into 2 parts.
String timestamp = vformat("%04d-%02d-%02d", year, (uint8_t)month, day);
if (p_use_space) {
@@ -286,14 +296,14 @@ String Time::get_datetime_string_from_dict(const Dictionary p_datetime, bool p_u
int64_t Time::get_unix_time_from_datetime_dict(const Dictionary p_datetime) const {
ERR_FAIL_COND_V_MSG(p_datetime.is_empty(), 0, "Invalid datetime Dictionary: Dictionary is empty");
EXTRACT_FROM_DICTIONARY
- VALIDATE_YMDHMS
+ VALIDATE_YMDHMS(0)
YMD_TO_DAY_NUMBER
return day_number * SECONDS_PER_DAY + hour * 3600 + minute * 60 + second;
}
int64_t Time::get_unix_time_from_datetime_string(String p_datetime) const {
- PARSE_ISO8601_STRING
- VALIDATE_YMDHMS
+ PARSE_ISO8601_STRING(-1)
+ VALIDATE_YMDHMS(0)
YMD_TO_DAY_NUMBER
return day_number * SECONDS_PER_DAY + hour * 3600 + minute * 60 + second;
}
@@ -400,8 +410,8 @@ void Time::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_datetime_string_from_unix_time", "unix_time_val", "use_space"), &Time::get_datetime_string_from_unix_time, DEFVAL(false));
ClassDB::bind_method(D_METHOD("get_date_string_from_unix_time", "unix_time_val"), &Time::get_date_string_from_unix_time);
ClassDB::bind_method(D_METHOD("get_time_string_from_unix_time", "unix_time_val"), &Time::get_time_string_from_unix_time);
- ClassDB::bind_method(D_METHOD("get_datetime_dict_from_string", "datetime", "weekday"), &Time::get_datetime_dict_from_string);
- ClassDB::bind_method(D_METHOD("get_datetime_string_from_dict", "datetime", "use_space"), &Time::get_datetime_string_from_dict);
+ ClassDB::bind_method(D_METHOD("get_datetime_dict_from_datetime_string", "datetime", "weekday"), &Time::get_datetime_dict_from_datetime_string);
+ ClassDB::bind_method(D_METHOD("get_datetime_string_from_datetime_dict", "datetime", "use_space"), &Time::get_datetime_string_from_datetime_dict);
ClassDB::bind_method(D_METHOD("get_unix_time_from_datetime_dict", "datetime"), &Time::get_unix_time_from_datetime_dict);
ClassDB::bind_method(D_METHOD("get_unix_time_from_datetime_string", "datetime"), &Time::get_unix_time_from_datetime_string);
ClassDB::bind_method(D_METHOD("get_offset_string_from_offset_minutes", "offset_minutes"), &Time::get_offset_string_from_offset_minutes);
diff --git a/core/os/time.h b/core/os/time.h
index 0021c0ac6f..4b4ce3526a 100644
--- a/core/os/time.h
+++ b/core/os/time.h
@@ -51,7 +51,7 @@ class Time : public Object {
public:
static Time *get_singleton();
- enum Month : uint8_t {
+ enum Month {
/// Start at 1 to follow Windows SYSTEMTIME structure
/// https://msdn.microsoft.com/en-us/library/windows/desktop/ms724950(v=vs.85).aspx
MONTH_JANUARY = 1,
@@ -85,8 +85,8 @@ public:
String get_datetime_string_from_unix_time(int64_t p_unix_time_val, bool p_use_space = false) const;
String get_date_string_from_unix_time(int64_t p_unix_time_val) const;
String get_time_string_from_unix_time(int64_t p_unix_time_val) const;
- Dictionary get_datetime_dict_from_string(String p_datetime, bool p_weekday = true) const;
- String get_datetime_string_from_dict(const Dictionary p_datetime, bool p_use_space = false) const;
+ Dictionary get_datetime_dict_from_datetime_string(String p_datetime, bool p_weekday = true) const;
+ String get_datetime_string_from_datetime_dict(const Dictionary p_datetime, bool p_use_space = false) const;
int64_t get_unix_time_from_datetime_dict(const Dictionary p_datetime) const;
int64_t get_unix_time_from_datetime_string(String p_datetime) const;
String get_offset_string_from_offset_minutes(int64_t p_offset_minutes) const;