diff options
Diffstat (limited to 'core/os')
-rw-r--r-- | core/os/keyboard.cpp | 40 | ||||
-rw-r--r-- | core/os/keyboard.h | 115 | ||||
-rw-r--r-- | core/os/memory.h | 8 | ||||
-rw-r--r-- | core/os/os.cpp | 52 | ||||
-rw-r--r-- | core/os/os.h | 19 | ||||
-rw-r--r-- | core/os/pool_allocator.h | 16 | ||||
-rw-r--r-- | core/os/spin_lock.h | 1 | ||||
-rw-r--r-- | core/os/thread.h | 1 | ||||
-rw-r--r-- | core/os/time.cpp | 8 | ||||
-rw-r--r-- | core/os/time.h | 4 |
10 files changed, 185 insertions, 79 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 3176a8a210..517a53e505 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, diff --git a/core/os/memory.h b/core/os/memory.h index baa96ef3e9..42ba9634e2 100644 --- a/core/os/memory.h +++ b/core/os/memory.h @@ -197,4 +197,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 4f7095b0fc..619e3eb06f 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -100,6 +100,21 @@ void OS::print(const char *p_format, ...) { 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); +} + void OS::printerr(const char *p_format, ...) { if (!_stderr_enabled) { return; @@ -144,7 +159,7 @@ 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 { @@ -388,6 +403,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; @@ -413,19 +432,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; @@ -457,6 +486,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)) { diff --git a/core/os/os.h b/core/os/os.h index 9ec0dd7728..b9f7328929 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -54,11 +54,11 @@ class OS { 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; + bool _writing_movie = false; CompositeLogger *_logger = nullptr; @@ -68,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); @@ -83,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. @@ -95,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); @@ -126,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; @@ -138,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; } @@ -147,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); @@ -164,6 +162,7 @@ public: virtual String get_name() const = 0; virtual List<String> get_cmdline_args() const { return _cmdline; } + 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; } @@ -258,8 +257,6 @@ 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; diff --git a/core/os/pool_allocator.h b/core/os/pool_allocator.h index 27a936ed78..a7a8523aa4 100644 --- a/core/os/pool_allocator.h +++ b/core/os/pool_allocator.h @@ -77,20 +77,20 @@ private: Entry *entry_array = nullptr; int *entry_indices = nullptr; - int entry_max; - int entry_count; + int entry_max = 0; + int entry_count = 0; uint8_t *pool = nullptr; void *mem_ptr = nullptr; - int pool_size; + 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); 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 f10a2ec186..a30e2a906b 100644 --- a/core/os/time.cpp +++ b/core/os/time.cpp @@ -261,7 +261,7 @@ 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 { +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; @@ -279,7 +279,7 @@ 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("") @@ -410,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 c4d10006fc..4b4ce3526a 100644 --- a/core/os/time.h +++ b/core/os/time.h @@ -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; |