summaryrefslogtreecommitdiff
path: root/core/os
diff options
context:
space:
mode:
Diffstat (limited to 'core/os')
-rw-r--r--core/os/keyboard.cpp16
-rw-r--r--core/os/keyboard.h61
-rw-r--r--core/os/main_loop.cpp18
-rw-r--r--core/os/midi_driver.cpp5
-rw-r--r--core/os/mutex.cpp4
-rw-r--r--core/os/mutex.h27
-rw-r--r--core/os/os.cpp71
-rw-r--r--core/os/os.h31
-rw-r--r--core/os/pool_allocator.cpp8
-rw-r--r--core/os/rw_lock.h17
-rw-r--r--core/os/semaphore.h13
-rw-r--r--core/os/thread.cpp44
-rw-r--r--core/os/thread.h40
-rw-r--r--core/os/threaded_array_processor.h19
-rw-r--r--core/os/time.cpp55
15 files changed, 124 insertions, 305 deletions
diff --git a/core/os/keyboard.cpp b/core/os/keyboard.cpp
index a592791d06..f3be495c8e 100644
--- a/core/os/keyboard.cpp
+++ b/core/os/keyboard.cpp
@@ -61,12 +61,16 @@ static const _KeyCodeText _keycodes[] = {
{Key::PAGEDOWN ,"PageDown"},
{Key::SHIFT ,"Shift"},
{Key::CTRL ,"Ctrl"},
-#ifdef MACOS_ENABLED
+#if defined(MACOS_ENABLED)
{Key::META ,"Command"},
+ {Key::ALT ,"Option"},
+#elif defined(WINDOWS_ENABLED)
+ {Key::META ,"Windows"},
+ {Key::ALT ,"Alt"},
#else
{Key::META ,"Meta"},
-#endif
{Key::ALT ,"Alt"},
+#endif
{Key::CAPSLOCK ,"CapsLock"},
{Key::NUMLOCK ,"NumLock"},
{Key::SCROLLLOCK ,"ScrollLock"},
@@ -437,6 +441,14 @@ String keycode_get_string(Key p_code) {
codestr += find_keycode_name(Key::ALT);
codestr += "+";
}
+ if ((p_code & KeyModifierMask::CMD_OR_CTRL) != Key::NONE) {
+#ifdef MACOS_ENABLED
+ codestr += find_keycode_name(Key::META);
+#else
+ codestr += find_keycode_name(Key::CTRL);
+#endif
+ codestr += "+";
+ }
if ((p_code & KeyModifierMask::CTRL) != Key::NONE) {
codestr += find_keycode_name(Key::CTRL);
codestr += "+";
diff --git a/core/os/keyboard.h b/core/os/keyboard.h
index 517a53e505..e5d9b24e85 100644
--- a/core/os/keyboard.h
+++ b/core/os/keyboard.h
@@ -36,11 +36,11 @@
enum class Key {
NONE = 0,
// Special key: The strategy here is similar to the one used by toolkits,
- // which consists in leaving the 24 bits unicode range for printable
- // characters, and use the upper 8 bits for special keys and modifiers.
+ // which consists in leaving the 21 bits unicode range for printable
+ // characters, and use the upper 11 bits for special keys and modifiers.
// This way everything (char/keycode) can fit nicely in one 32-bit
// integer (the enum's underlying type is `int` by default).
- SPECIAL = (1 << 24),
+ SPECIAL = (1 << 22),
/* CURSOR/FUNCTION/BROWSER/MULTIMEDIA/MISC KEYS */
ESCAPE = SPECIAL | 0x01,
TAB = SPECIAL | 0x02,
@@ -312,84 +312,85 @@ enum class Key {
};
enum class KeyModifierMask {
- CODE_MASK = ((1 << 25) - 1), ///< Apply this mask to any keycode to remove modifiers.
- MODIFIER_MASK = (0x7F << 24), ///< Apply this mask to isolate modifiers.
+ CODE_MASK = ((1 << 23) - 1), ///< Apply this mask to any keycode to remove modifiers.
+ MODIFIER_MASK = (0x7F << 22), ///< Apply this mask to isolate modifiers.
+ //RESERVED = (1 << 23),
+ CMD_OR_CTRL = (1 << 24),
SHIFT = (1 << 25),
ALT = (1 << 26),
META = (1 << 27),
CTRL = (1 << 28),
-#ifdef APPLE_STYLE_KEYS
- CMD = META,
-#else
- CMD = CTRL,
-#endif
KPAD = (1 << 29),
GROUP_SWITCH = (1 << 30)
};
// To avoid having unnecessary operators, only define the ones that are needed.
-inline Key operator-(uint32_t a, Key b) {
+constexpr Key operator-(uint32_t a, Key b) {
return (Key)(a - (uint32_t)b);
}
-inline Key &operator-=(Key &a, int b) {
- return (Key &)((int &)a -= b);
+constexpr Key &operator-=(Key &a, int b) {
+ a = static_cast<Key>(static_cast<int>(a) - static_cast<int>(b));
+ return a;
}
-inline Key operator+(Key a, int b) {
+constexpr Key operator+(Key a, int b) {
return (Key)((int)a + (int)b);
}
-inline Key operator+(Key a, Key b) {
+constexpr Key operator+(Key a, Key b) {
return (Key)((int)a + (int)b);
}
-inline Key operator-(Key a, Key b) {
+constexpr Key operator-(Key a, Key b) {
return (Key)((int)a - (int)b);
}
-inline Key operator&(Key a, Key b) {
+constexpr Key operator&(Key a, Key b) {
return (Key)((int)a & (int)b);
}
-inline Key operator|(Key a, Key b) {
+constexpr Key operator|(Key a, Key b) {
return (Key)((int)a | (int)b);
}
-inline Key &operator|=(Key &a, Key b) {
- return (Key &)((int &)a |= (int)b);
+constexpr Key &operator|=(Key &a, Key b) {
+ a = static_cast<Key>(static_cast<int>(a) | static_cast<int>(b));
+ return a;
}
-inline Key &operator|=(Key &a, KeyModifierMask b) {
- return (Key &)((int &)a |= (int)b);
+constexpr Key &operator|=(Key &a, KeyModifierMask b) {
+ a = static_cast<Key>(static_cast<int>(a) | static_cast<int>(b));
+ return a;
}
-inline Key &operator&=(Key &a, KeyModifierMask b) {
- return (Key &)((int &)a &= (int)b);
+constexpr Key &operator&=(Key &a, KeyModifierMask b) {
+ a = static_cast<Key>(static_cast<int>(a) & static_cast<int>(b));
+ return a;
}
-inline Key operator|(Key a, KeyModifierMask b) {
+constexpr Key operator|(Key a, KeyModifierMask b) {
return (Key)((int)a | (int)b);
}
-inline Key operator&(Key a, KeyModifierMask b) {
+constexpr Key operator&(Key a, KeyModifierMask b) {
return (Key)((int)a & (int)b);
}
-inline Key operator+(KeyModifierMask a, Key b) {
+constexpr Key operator+(KeyModifierMask a, Key b) {
return (Key)((int)a + (int)b);
}
-inline Key operator|(KeyModifierMask a, Key b) {
+constexpr Key operator|(KeyModifierMask a, Key b) {
return (Key)((int)a | (int)b);
}
-inline KeyModifierMask operator+(KeyModifierMask a, KeyModifierMask b) {
+constexpr KeyModifierMask operator+(KeyModifierMask a, KeyModifierMask b) {
return (KeyModifierMask)((int)a + (int)b);
}
-inline KeyModifierMask operator|(KeyModifierMask a, KeyModifierMask b) {
+constexpr KeyModifierMask operator|(KeyModifierMask a, KeyModifierMask b) {
return (KeyModifierMask)((int)a | (int)b);
}
diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp
index a96e1989f9..c0504a174c 100644
--- a/core/os/main_loop.cpp
+++ b/core/os/main_loop.cpp
@@ -65,21 +65,15 @@ void MainLoop::initialize() {
}
bool MainLoop::physics_process(double p_time) {
- bool quit;
- if (GDVIRTUAL_CALL(_physics_process, p_time, quit)) {
- return quit;
- }
-
- return false;
+ bool quit = false;
+ GDVIRTUAL_CALL(_physics_process, p_time, quit);
+ return quit;
}
bool MainLoop::process(double p_time) {
- bool quit;
- if (GDVIRTUAL_CALL(_process, p_time, quit)) {
- return quit;
- }
-
- return false;
+ bool quit = false;
+ GDVIRTUAL_CALL(_process, p_time, quit);
+ return quit;
}
void MainLoop::finalize() {
diff --git a/core/os/midi_driver.cpp b/core/os/midi_driver.cpp
index 410b62068a..79eef95ef2 100644
--- a/core/os/midi_driver.cpp
+++ b/core/os/midi_driver.cpp
@@ -86,11 +86,6 @@ void MIDIDriver::receive_input_packet(uint64_t timestamp, uint8_t *data, uint32_
if (length >= 2 + param_position) {
event->set_pitch(data[param_position]);
event->set_velocity(data[param_position + 1]);
-
- if (event->get_message() == MIDIMessage::NOTE_ON && event->get_velocity() == 0) {
- // https://www.midi.org/forum/228-writing-midi-software-send-note-off,-or-zero-velocity-note-on
- event->set_message(MIDIMessage::NOTE_OFF);
- }
}
break;
diff --git a/core/os/mutex.cpp b/core/os/mutex.cpp
index 1d4400bfc1..512db1737a 100644
--- a/core/os/mutex.cpp
+++ b/core/os/mutex.cpp
@@ -40,11 +40,7 @@ void _global_unlock() {
_global_mutex.unlock();
}
-#ifndef NO_THREADS
-
template class MutexImpl<std::recursive_mutex>;
template class MutexImpl<std::mutex>;
template class MutexLock<MutexImpl<std::recursive_mutex>>;
template class MutexLock<MutexImpl<std::mutex>>;
-
-#endif
diff --git a/core/os/mutex.h b/core/os/mutex.h
index a51248807b..eb58418bd6 100644
--- a/core/os/mutex.h
+++ b/core/os/mutex.h
@@ -34,8 +34,6 @@
#include "core/error/error_list.h"
#include "core/typedefs.h"
-#if !defined(NO_THREADS)
-
#include <mutex>
template <class StdMutexT>
@@ -79,29 +77,4 @@ extern template class MutexImpl<std::mutex>;
extern template class MutexLock<MutexImpl<std::recursive_mutex>>;
extern template class MutexLock<MutexImpl<std::mutex>>;
-#else
-
-class FakeMutex {
- FakeMutex() {}
-};
-
-template <class MutexT>
-class MutexImpl {
-public:
- _ALWAYS_INLINE_ void lock() const {}
- _ALWAYS_INLINE_ void unlock() const {}
- _ALWAYS_INLINE_ Error try_lock() const { return OK; }
-};
-
-template <class MutexT>
-class MutexLock {
-public:
- explicit MutexLock(const MutexT &p_mutex) {}
-};
-
-using Mutex = MutexImpl<FakeMutex>;
-using BinaryMutex = MutexImpl<FakeMutex>; // Non-recursive, handle with care
-
-#endif // !NO_THREADS
-
#endif // MUTEX_H
diff --git a/core/os/os.cpp b/core/os/os.cpp
index 1358c926d1..bbb2a94fe7 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -38,6 +38,7 @@
#include "core/version_generated.gen.h"
#include <stdarg.h>
+#include <thread>
OS *OS::singleton = nullptr;
uint64_t OS::target_ticks = 0;
@@ -54,10 +55,6 @@ double OS::get_unix_time() const {
return 0;
}
-void OS::debug_break() {
- // something
-}
-
void OS::_set_logger(CompositeLogger *p_logger) {
if (_logger) {
memdelete(_logger);
@@ -159,17 +156,13 @@ int OS::get_process_id() const {
}
void OS::vibrate_handheld(int p_duration_ms) {
- WARN_PRINT("vibrate_handheld() only works with Android, iOS and HTML5");
+ WARN_PRINT("vibrate_handheld() only works with Android, iOS and Web");
}
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;
}
@@ -190,50 +183,6 @@ void OS::set_stderr_enabled(bool p_enabled) {
_stderr_enabled = p_enabled;
}
-void OS::dump_memory_to_file(const char *p_file) {
- //Memory::dump_static_mem_to_file(p_file);
-}
-
-static Ref<FileAccess> _OSPRF;
-
-static void _OS_printres(Object *p_obj) {
- Resource *res = Object::cast_to<Resource>(p_obj);
- if (!res) {
- return;
- }
-
- String str = vformat("%s - %s - %s", res->to_string(), res->get_name(), res->get_path());
- if (_OSPRF.is_valid()) {
- _OSPRF->store_line(str);
- } else {
- print_line(str);
- }
-}
-
-void OS::print_all_resources(String p_to_file) {
- 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.unref();
- ERR_FAIL_MSG("Can't print all resources to file: " + String(p_to_file) + ".");
- }
- }
-
- ObjectDB::debug_objects(_OS_printres);
-
- _OSPRF.unref();
-}
-
-void OS::print_resources_in_use(bool p_short) {
- ResourceCache::dump(nullptr, p_short);
-}
-
-void OS::dump_resources_to_file(const char *p_file) {
- ResourceCache::dump(p_file);
-}
-
int OS::get_exit_code() const {
return _exit_code;
}
@@ -373,21 +322,13 @@ String OS::get_unique_id() const {
}
int OS::get_processor_count() const {
- return 1;
+ return std::thread::hardware_concurrency();
}
String OS::get_processor_name() const {
return "";
}
-bool OS::can_use_threads() const {
-#ifdef NO_THREADS
- return false;
-#else
- return true;
-#endif
-}
-
void OS::set_has_server_feature_callback(HasServerFeatureCallback p_callback) {
has_server_feature_callback = p_callback;
}
@@ -571,10 +512,10 @@ void OS::add_frame_delay(bool p_can_draw) {
if (is_in_low_processor_usage_mode() || !p_can_draw) {
dynamic_delay = get_low_processor_usage_mode_sleep_usec();
}
- const int target_fps = Engine::get_singleton()->get_target_fps();
- if (target_fps > 0 && !Engine::get_singleton()->is_editor_hint()) {
+ const int max_fps = Engine::get_singleton()->get_max_fps();
+ if (max_fps > 0 && !Engine::get_singleton()->is_editor_hint()) {
// Override the low processor usage mode sleep delay if the target FPS is lower.
- dynamic_delay = MAX(dynamic_delay, (uint64_t)(1000000 / target_fps));
+ dynamic_delay = MAX(dynamic_delay, (uint64_t)(1000000 / max_fps));
}
if (dynamic_delay > 0) {
diff --git a/core/os/os.h b/core/os/os.h
index 9152b797ef..af7b40f3ec 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -52,7 +52,6 @@ class OS {
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
bool _allow_hidpi = false;
@@ -70,6 +69,7 @@ class OS {
// so we can retrieve the rendering drivers available
int _display_driver_id = -1;
String _current_rendering_driver_name;
+ String _current_rendering_method;
protected:
void _set_logger(CompositeLogger *p_logger);
@@ -99,6 +99,8 @@ protected:
virtual void initialize_joypads() = 0;
void set_current_rendering_driver_name(String p_driver_name) { _current_rendering_driver_name = p_driver_name; }
+ void set_current_rendering_method(String p_name) { _current_rendering_method = p_name; }
+
void set_display_driver_id(int p_display_driver_id) { _display_driver_id = p_display_driver_id; }
virtual void set_main_loop(MainLoop *p_main_loop) = 0;
@@ -117,8 +119,12 @@ public:
static OS *get_singleton();
String get_current_rendering_driver_name() const { return _current_rendering_driver_name; }
+ String get_current_rendering_method() const { return _current_rendering_method; }
+
int get_display_driver_id() const { return _display_driver_id; }
+ virtual Vector<String> get_video_adapter_driver_info() const = 0;
+
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;
@@ -162,6 +168,8 @@ public:
virtual bool set_environment(const String &p_var, const String &p_value) const = 0;
virtual String get_name() const = 0;
+ virtual String get_distribution_name() const = 0;
+ virtual String get_version() 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>(); }
@@ -203,18 +211,15 @@ public:
MONTH_DECEMBER,
};
- struct Date {
+ struct DateTime {
int64_t year;
Month month;
uint8_t day;
Weekday weekday;
- bool dst;
- };
-
- struct Time {
uint8_t hour;
uint8_t minute;
uint8_t second;
+ bool dst;
};
struct TimeZoneInfo {
@@ -222,8 +227,7 @@ public:
String name;
};
- virtual Date get_date(bool p_utc = false) const = 0;
- virtual Time get_time(bool p_utc = false) const = 0;
+ virtual DateTime get_datetime(bool utc = false) const = 0;
virtual TimeZoneInfo get_time_zone_info() const = 0;
virtual double get_unix_time() const;
@@ -243,17 +247,10 @@ 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() {}
- virtual void dump_memory_to_file(const char *p_file);
- virtual void dump_resources_to_file(const char *p_file);
- virtual void print_resources_in_use(bool p_short = false);
- virtual void print_all_resources(String p_to_file = "");
-
virtual uint64_t get_static_memory_usage() const;
virtual uint64_t get_static_memory_peak_usage() const;
virtual uint64_t get_free_static_memory() const;
@@ -292,8 +289,6 @@ public:
virtual Error move_to_trash(const String &p_path) { return FAILED; }
- virtual void debug_break();
-
virtual int get_exit_code() const;
// `set_exit_code` should only be used from `SceneTree` (or from a similar
// level, e.g. from the `Main::start` if leaving without creating a `SceneTree`).
@@ -306,8 +301,6 @@ public:
virtual String get_unique_id() const;
- virtual bool can_use_threads() const;
-
bool has_feature(const String &p_feature);
void set_has_server_feature_callback(HasServerFeatureCallback p_callback);
diff --git a/core/os/pool_allocator.cpp b/core/os/pool_allocator.cpp
index f622e2c7c5..e7f2cff7c5 100644
--- a/core/os/pool_allocator.cpp
+++ b/core/os/pool_allocator.cpp
@@ -35,8 +35,6 @@
#include "core/os/os.h"
#include "core/string/print_string.h"
-#include <assert.h>
-
#define COMPACT_CHUNK(m_entry, m_to_pos) \
do { \
void *_dst = &((unsigned char *)pool)[m_to_pos]; \
@@ -169,11 +167,6 @@ bool PoolAllocator::find_entry_index(EntryIndicesPos *p_map_pos, const Entry *p_
PoolAllocator::ID PoolAllocator::alloc(int p_size) {
ERR_FAIL_COND_V(p_size < 1, POOL_ALLOCATOR_INVALID_ID);
-#ifdef DEBUG_ENABLED
- if (p_size > free_mem) {
- OS::get_singleton()->debug_break();
- }
-#endif
ERR_FAIL_COND_V(p_size > free_mem, POOL_ALLOCATOR_INVALID_ID);
mt_lock();
@@ -482,7 +475,6 @@ void *PoolAllocator::get(ID p_mem) {
ERR_FAIL_COND_V(!e, nullptr);
}
if (e->lock == 0) {
- //assert(0);
mt_unlock();
ERR_PRINT("e->lock == 0");
return nullptr;
diff --git a/core/os/rw_lock.h b/core/os/rw_lock.h
index a046f474ea..d3206547c7 100644
--- a/core/os/rw_lock.h
+++ b/core/os/rw_lock.h
@@ -33,8 +33,6 @@
#include "core/error/error_list.h"
-#if !defined(NO_THREADS)
-
#include <shared_mutex>
class RWLock {
@@ -72,21 +70,6 @@ public:
}
};
-#else
-
-class RWLock {
-public:
- void read_lock() const {}
- void read_unlock() const {}
- Error read_try_lock() const { return OK; }
-
- void write_lock() {}
- void write_unlock() {}
- Error write_try_lock() { return OK; }
-};
-
-#endif
-
class RWLockRead {
const RWLock &lock;
diff --git a/core/os/semaphore.h b/core/os/semaphore.h
index 72df52dd34..1a93d3ee2c 100644
--- a/core/os/semaphore.h
+++ b/core/os/semaphore.h
@@ -34,8 +34,6 @@
#include "core/error/error_list.h"
#include "core/typedefs.h"
-#if !defined(NO_THREADS)
-
#include <condition_variable>
#include <mutex>
@@ -70,15 +68,4 @@ public:
}
};
-#else
-
-class Semaphore {
-public:
- _ALWAYS_INLINE_ void post() const {}
- _ALWAYS_INLINE_ void wait() const {}
- _ALWAYS_INLINE_ bool try_wait() const { return true; }
-};
-
-#endif
-
#endif // SEMAPHORE_H
diff --git a/core/os/thread.cpp b/core/os/thread.cpp
index c8072b7280..712f4793eb 100644
--- a/core/os/thread.cpp
+++ b/core/os/thread.cpp
@@ -34,15 +34,9 @@
#include "thread.h"
#include "core/object/script_language.h"
-
-#if !defined(NO_THREADS)
-
#include "core/templates/safe_refcount.h"
-Error (*Thread::set_name_func)(const String &) = nullptr;
-void (*Thread::set_priority_func)(Thread::Priority) = nullptr;
-void (*Thread::init_func)() = nullptr;
-void (*Thread::term_func)() = nullptr;
+Thread::PlatformFunctions Thread::platform_functions;
uint64_t Thread::_thread_id_hash(const std::thread::id &p_t) {
static std::hash<std::thread::id> hasher;
@@ -52,30 +46,27 @@ uint64_t Thread::_thread_id_hash(const std::thread::id &p_t) {
Thread::ID Thread::main_thread_id = _thread_id_hash(std::this_thread::get_id());
thread_local Thread::ID Thread::caller_id = 0;
-void Thread::_set_platform_funcs(
- Error (*p_set_name_func)(const String &),
- void (*p_set_priority_func)(Thread::Priority),
- void (*p_init_func)(),
- void (*p_term_func)()) {
- Thread::set_name_func = p_set_name_func;
- Thread::set_priority_func = p_set_priority_func;
- Thread::init_func = p_init_func;
- Thread::term_func = p_term_func;
+void Thread::_set_platform_functions(const PlatformFunctions &p_functions) {
+ platform_functions = p_functions;
}
void Thread::callback(Thread *p_self, const Settings &p_settings, Callback p_callback, void *p_userdata) {
Thread::caller_id = _thread_id_hash(p_self->thread.get_id());
- if (set_priority_func) {
- set_priority_func(p_settings.priority);
+ if (platform_functions.set_priority) {
+ platform_functions.set_priority(p_settings.priority);
}
- if (init_func) {
- init_func();
+ if (platform_functions.init) {
+ platform_functions.init();
+ }
+ ScriptServer::thread_enter(); // Scripts may need to attach a stack.
+ if (platform_functions.wrapper) {
+ platform_functions.wrapper(p_callback, p_userdata);
+ } else {
+ p_callback(p_userdata);
}
- ScriptServer::thread_enter(); //scripts may need to attach a stack
- p_callback(p_userdata);
ScriptServer::thread_exit();
- if (term_func) {
- term_func();
+ if (platform_functions.term) {
+ platform_functions.term();
}
}
@@ -108,8 +99,8 @@ void Thread::wait_to_finish() {
}
Error Thread::set_name(const String &p_name) {
- if (set_name_func) {
- return set_name_func(p_name);
+ if (platform_functions.set_name) {
+ return platform_functions.set_name(p_name);
}
return ERR_UNAVAILABLE;
@@ -128,5 +119,4 @@ Thread::~Thread() {
}
}
-#endif
#endif // PLATFORM_THREAD_OVERRIDE
diff --git a/core/os/thread.h b/core/os/thread.h
index 0fb283e224..86442de760 100644
--- a/core/os/thread.h
+++ b/core/os/thread.h
@@ -35,15 +35,14 @@
#ifdef PLATFORM_THREAD_OVERRIDE
#include "platform_thread.h"
#else
+
#ifndef THREAD_H
#define THREAD_H
+#include "core/templates/safe_refcount.h"
#include "core/typedefs.h"
-#if !defined(NO_THREADS)
-#include "core/templates/safe_refcount.h"
#include <thread>
-#endif
class String;
@@ -64,8 +63,15 @@ public:
Settings() { priority = PRIORITY_NORMAL; }
};
+ struct PlatformFunctions {
+ Error (*set_name)(const String &) = nullptr;
+ void (*set_priority)(Thread::Priority) = nullptr;
+ void (*init)() = nullptr;
+ void (*wrapper)(Thread::Callback, void *) = nullptr;
+ void (*term)() = nullptr;
+ };
+
private:
-#if !defined(NO_THREADS)
friend class Main;
static ID main_thread_id;
@@ -78,20 +84,11 @@ private:
static void callback(Thread *p_self, const Settings &p_settings, Thread::Callback p_callback, void *p_userdata);
- static Error (*set_name_func)(const String &);
- static void (*set_priority_func)(Thread::Priority);
- static void (*init_func)();
- static void (*term_func)();
-#endif
+ static PlatformFunctions platform_functions;
public:
- static void _set_platform_funcs(
- Error (*p_set_name_func)(const String &),
- void (*p_set_priority_func)(Thread::Priority),
- void (*p_init_func)() = nullptr,
- void (*p_term_func)() = nullptr);
+ static void _set_platform_functions(const PlatformFunctions &p_functions);
-#if !defined(NO_THREADS)
_FORCE_INLINE_ ID get_id() const { return id; }
// get the ID of the caller thread
_FORCE_INLINE_ static ID get_caller_id() { return caller_id; }
@@ -107,19 +104,6 @@ public:
Thread();
~Thread();
-#else
- _FORCE_INLINE_ ID get_id() const { return 0; }
- // get the ID of the caller thread
- _FORCE_INLINE_ static ID get_caller_id() { return 0; }
- // get the ID of the main thread
- _FORCE_INLINE_ static ID get_main_id() { return 0; }
-
- static Error set_name(const String &p_name) { return ERR_UNAVAILABLE; }
-
- void start(Thread::Callback p_callback, void *p_user, const Settings &p_settings = Settings()) {}
- bool is_started() const { return false; }
- void wait_to_finish() {}
-#endif
};
#endif // THREAD_H
diff --git a/core/os/threaded_array_processor.h b/core/os/threaded_array_processor.h
index 935fc7a360..95a2253f14 100644
--- a/core/os/threaded_array_processor.h
+++ b/core/os/threaded_array_processor.h
@@ -49,8 +49,6 @@ struct ThreadArrayProcessData {
}
};
-#ifndef NO_THREADS
-
template <class T>
void process_array_thread(void *ud) {
T &data = *(T *)ud;
@@ -86,21 +84,4 @@ void thread_process_array(uint32_t p_elements, C *p_instance, M p_method, U p_us
memdelete_arr(threads);
}
-#else
-
-template <class C, class M, class U>
-void thread_process_array(uint32_t p_elements, C *p_instance, M p_method, U p_userdata) {
- ThreadArrayProcessData<C, U> data;
- data.method = p_method;
- data.instance = p_instance;
- data.userdata = p_userdata;
- data.index.set(0);
- data.elements = p_elements;
- for (uint32_t i = 0; i < p_elements; i++) {
- data.process(i);
- }
-}
-
-#endif
-
#endif // THREADED_ARRAY_PROCESSOR_H
diff --git a/core/os/time.cpp b/core/os/time.cpp
index a30e2a906b..a3c2c99b4c 100644
--- a/core/os/time.cpp
+++ b/core/os/time.cpp
@@ -324,63 +324,60 @@ String Time::get_offset_string_from_offset_minutes(int64_t p_offset_minutes) con
}
Dictionary Time::get_datetime_dict_from_system(bool p_utc) const {
- OS::Date date = OS::get_singleton()->get_date(p_utc);
- OS::Time time = OS::get_singleton()->get_time(p_utc);
+ OS::DateTime dt = OS::get_singleton()->get_datetime(p_utc);
Dictionary datetime;
- datetime[YEAR_KEY] = date.year;
- datetime[MONTH_KEY] = (uint8_t)date.month;
- datetime[DAY_KEY] = date.day;
- datetime[WEEKDAY_KEY] = (uint8_t)date.weekday;
- datetime[DST_KEY] = date.dst;
- datetime[HOUR_KEY] = time.hour;
- datetime[MINUTE_KEY] = time.minute;
- datetime[SECOND_KEY] = time.second;
+ datetime[YEAR_KEY] = dt.year;
+ datetime[MONTH_KEY] = (uint8_t)dt.month;
+ datetime[DAY_KEY] = dt.day;
+ datetime[WEEKDAY_KEY] = (uint8_t)dt.weekday;
+ datetime[HOUR_KEY] = dt.hour;
+ datetime[MINUTE_KEY] = dt.minute;
+ datetime[SECOND_KEY] = dt.second;
+ datetime[DST_KEY] = dt.dst;
return datetime;
}
Dictionary Time::get_date_dict_from_system(bool p_utc) const {
- OS::Date date = OS::get_singleton()->get_date(p_utc);
+ OS::DateTime dt = OS::get_singleton()->get_datetime(p_utc);
Dictionary date_dictionary;
- date_dictionary[YEAR_KEY] = date.year;
- date_dictionary[MONTH_KEY] = (uint8_t)date.month;
- date_dictionary[DAY_KEY] = date.day;
- date_dictionary[WEEKDAY_KEY] = (uint8_t)date.weekday;
- date_dictionary[DST_KEY] = date.dst;
+ date_dictionary[YEAR_KEY] = dt.year;
+ date_dictionary[MONTH_KEY] = (uint8_t)dt.month;
+ date_dictionary[DAY_KEY] = dt.day;
+ date_dictionary[WEEKDAY_KEY] = (uint8_t)dt.weekday;
return date_dictionary;
}
Dictionary Time::get_time_dict_from_system(bool p_utc) const {
- OS::Time time = OS::get_singleton()->get_time(p_utc);
+ OS::DateTime dt = OS::get_singleton()->get_datetime(p_utc);
Dictionary time_dictionary;
- time_dictionary[HOUR_KEY] = time.hour;
- time_dictionary[MINUTE_KEY] = time.minute;
- time_dictionary[SECOND_KEY] = time.second;
+ time_dictionary[HOUR_KEY] = dt.hour;
+ time_dictionary[MINUTE_KEY] = dt.minute;
+ time_dictionary[SECOND_KEY] = dt.second;
return time_dictionary;
}
String Time::get_datetime_string_from_system(bool p_utc, bool p_use_space) const {
- OS::Date date = OS::get_singleton()->get_date(p_utc);
- OS::Time time = OS::get_singleton()->get_time(p_utc);
+ OS::DateTime dt = OS::get_singleton()->get_datetime(p_utc);
// vformat only supports up to 6 arguments, so we need to split this up into 2 parts.
- String timestamp = vformat("%04d-%02d-%02d", date.year, (uint8_t)date.month, date.day);
+ String timestamp = vformat("%04d-%02d-%02d", dt.year, (uint8_t)dt.month, dt.day);
if (p_use_space) {
- timestamp = vformat("%s %02d:%02d:%02d", timestamp, time.hour, time.minute, time.second);
+ timestamp = vformat("%s %02d:%02d:%02d", timestamp, dt.hour, dt.minute, dt.second);
} else {
- timestamp = vformat("%sT%02d:%02d:%02d", timestamp, time.hour, time.minute, time.second);
+ timestamp = vformat("%sT%02d:%02d:%02d", timestamp, dt.hour, dt.minute, dt.second);
}
return timestamp;
}
String Time::get_date_string_from_system(bool p_utc) const {
- OS::Date date = OS::get_singleton()->get_date(p_utc);
+ OS::DateTime dt = OS::get_singleton()->get_datetime(p_utc);
// Android is picky about the types passed to make Variant, so we need a cast.
- return vformat("%04d-%02d-%02d", date.year, (uint8_t)date.month, date.day);
+ return vformat("%04d-%02d-%02d", dt.year, (uint8_t)dt.month, dt.day);
}
String Time::get_time_string_from_system(bool p_utc) const {
- OS::Time time = OS::get_singleton()->get_time(p_utc);
- return vformat("%02d:%02d:%02d", time.hour, time.minute, time.second);
+ OS::DateTime dt = OS::get_singleton()->get_datetime(p_utc);
+ return vformat("%02d:%02d:%02d", dt.hour, dt.minute, dt.second);
}
Dictionary Time::get_time_zone_from_system() const {