diff options
Diffstat (limited to 'core')
48 files changed, 553 insertions, 708 deletions
diff --git a/core/SCsub b/core/SCsub index c9f84a9a00..21829553a7 100644 --- a/core/SCsub +++ b/core/SCsub @@ -54,7 +54,7 @@ thirdparty_misc_sources = [ "smaz.c", # C++ sources "pcg.cpp", - "triangulator.cpp", + "polypartition.cpp", "clipper.cpp", ] thirdparty_misc_sources = [thirdparty_misc_dir + file for file in thirdparty_misc_sources] diff --git a/core/core_bind.cpp b/core/core_bind.cpp index a84a208050..456a97e5e5 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -228,24 +228,32 @@ Error _OS::shell_open(String p_uri) { return OS::get_singleton()->shell_open(p_uri); } -int _OS::execute(const String &p_path, const Vector<String> &p_arguments, bool p_blocking, Array p_output, bool p_read_stderr) { - OS::ProcessID pid = -2; - int exitcode = 0; +int _OS::execute(const String &p_path, const Vector<String> &p_arguments, Array r_output, bool p_read_stderr) { List<String> args; for (int i = 0; i < p_arguments.size(); i++) { args.push_back(p_arguments[i]); } String pipe; - Error err = OS::get_singleton()->execute(p_path, args, p_blocking, &pid, &pipe, &exitcode, p_read_stderr); - p_output.clear(); - p_output.push_back(pipe); + int exitcode = 0; + Error err = OS::get_singleton()->execute(p_path, args, &pipe, &exitcode, p_read_stderr); + r_output.push_back(pipe); + if (err != OK) { + return -1; + } + return exitcode; +} + +int _OS::create_process(const String &p_path, const Vector<String> &p_arguments) { + List<String> args; + for (int i = 0; i < p_arguments.size(); i++) { + args.push_back(p_arguments[i]); + } + OS::ProcessID pid = 0; + Error err = OS::get_singleton()->create_process(p_path, args, &pid); if (err != OK) { return -1; - } else if (p_blocking) { - return exitcode; - } else { - return pid; } + return pid; } Error _OS::kill(int p_pid) { @@ -290,6 +298,10 @@ Error _OS::set_thread_name(const String &p_name) { return Thread::set_name(p_name); } +Thread::ID _OS::get_thread_caller_id() const { + return Thread::get_caller_id(); +}; + bool _OS::has_feature(const String &p_feature) const { return OS::get_singleton()->has_feature(p_feature); } @@ -697,7 +709,8 @@ void _OS::_bind_methods() { ClassDB::bind_method(D_METHOD("get_processor_count"), &_OS::get_processor_count); ClassDB::bind_method(D_METHOD("get_executable_path"), &_OS::get_executable_path); - ClassDB::bind_method(D_METHOD("execute", "path", "arguments", "blocking", "output", "read_stderr"), &_OS::execute, DEFVAL(true), DEFVAL(Array()), DEFVAL(false)); + ClassDB::bind_method(D_METHOD("execute", "path", "arguments", "output", "read_stderr"), &_OS::execute, DEFVAL(Array()), DEFVAL(false)); + ClassDB::bind_method(D_METHOD("create_process", "path", "arguments"), &_OS::create_process); ClassDB::bind_method(D_METHOD("kill", "pid"), &_OS::kill); ClassDB::bind_method(D_METHOD("shell_open", "uri"), &_OS::shell_open); ClassDB::bind_method(D_METHOD("get_process_id"), &_OS::get_process_id); @@ -755,6 +768,7 @@ void _OS::_bind_methods() { ClassDB::bind_method(D_METHOD("set_use_file_access_save_and_swap", "enabled"), &_OS::set_use_file_access_save_and_swap); ClassDB::bind_method(D_METHOD("set_thread_name", "name"), &_OS::set_thread_name); + ClassDB::bind_method(D_METHOD("get_thread_caller_id"), &_OS::get_thread_caller_id); ClassDB::bind_method(D_METHOD("has_feature", "tag_name"), &_OS::has_feature); @@ -1981,24 +1995,13 @@ Error _Thread::start(Object *p_instance, const StringName &p_method, const Varia Thread::Settings s; s.priority = (Thread::Priority)p_priority; - thread = Thread::create(_start_func, ud, s); - if (!thread) { - active = false; - target_method = StringName(); - target_instance = nullptr; - userdata = Variant(); - return ERR_CANT_CREATE; - } + thread.start(_start_func, ud, s); return OK; } String _Thread::get_id() const { - if (!thread) { - return String(); - } - - return itos(thread->get_id()); + return itos(thread.get_id()); } bool _Thread::is_active() const { @@ -2006,18 +2009,13 @@ bool _Thread::is_active() const { } Variant _Thread::wait_to_finish() { - ERR_FAIL_COND_V_MSG(!thread, Variant(), "Thread must exist to wait for its completion."); ERR_FAIL_COND_V_MSG(!active, Variant(), "Thread must be active to wait for its completion."); - Thread::wait_to_finish(thread); + thread.wait_to_finish(); Variant r = ret; active = false; target_method = StringName(); target_instance = nullptr; userdata = Variant(); - if (thread) { - memdelete(thread); - } - thread = nullptr; return r; } @@ -2033,10 +2031,6 @@ void _Thread::_bind_methods() { BIND_ENUM_CONSTANT(PRIORITY_HIGH); } -_Thread::~_Thread() { - ERR_FAIL_COND_MSG(active, "Reference to a Thread object was lost while the thread is still running..."); -} - ////// _ClassDB ////// PackedStringArray _ClassDB::get_class_list() const { diff --git a/core/core_bind.h b/core/core_bind.h index 30dfa2d7a8..3305c93089 100644 --- a/core/core_bind.h +++ b/core/core_bind.h @@ -155,8 +155,8 @@ public: int get_low_processor_usage_mode_sleep_usec() const; String get_executable_path() const; - int execute(const String &p_path, const Vector<String> &p_arguments, bool p_blocking = true, Array p_output = Array(), bool p_read_stderr = false); - + int execute(const String &p_path, const Vector<String> &p_arguments, Array r_output = Array(), bool p_read_stderr = false); + int create_process(const String &p_path, const Vector<String> &p_arguments); Error kill(int p_pid); Error shell_open(String p_uri); @@ -232,6 +232,7 @@ public: String get_user_data_dir() const; Error set_thread_name(const String &p_name); + Thread::ID get_thread_caller_id() const; bool has_feature(const String &p_feature) const; @@ -553,7 +554,7 @@ protected: volatile bool active = false; Object *target_instance = nullptr; StringName target_method; - Thread *thread = nullptr; + Thread thread; static void _bind_methods(); static void _start_func(void *ud); @@ -569,9 +570,6 @@ public: String get_id() const; bool is_active() const; Variant wait_to_finish(); - - _Thread() {} - ~_Thread(); }; VARIANT_ENUM_CAST(_Thread::Priority); diff --git a/core/debugger/remote_debugger_peer.cpp b/core/debugger/remote_debugger_peer.cpp index 2e388d5934..857e3af268 100644 --- a/core/debugger/remote_debugger_peer.cpp +++ b/core/debugger/remote_debugger_peer.cpp @@ -65,12 +65,8 @@ int RemoteDebuggerPeerTCP::get_max_message_size() const { } void RemoteDebuggerPeerTCP::close() { - if (thread) { - running = false; - Thread::wait_to_finish(thread); - memdelete(thread); - thread = nullptr; - } + running = false; + thread.wait_to_finish(); tcp_client->disconnect_from_host(); out_buf.resize(0); in_buf.resize(0); @@ -85,7 +81,7 @@ RemoteDebuggerPeerTCP::RemoteDebuggerPeerTCP(Ref<StreamPeerTCP> p_tcp) { connected = true; #ifndef NO_THREADS running = true; - thread = Thread::create(_thread_func, this); + thread.start(_thread_func, this); #endif } else { tcp_client.instance(); @@ -188,7 +184,7 @@ Error RemoteDebuggerPeerTCP::connect_to_host(const String &p_host, uint16_t p_po connected = true; #ifndef NO_THREADS running = true; - thread = Thread::create(_thread_func, this); + thread.start(_thread_func, this); #endif return OK; } diff --git a/core/debugger/remote_debugger_peer.h b/core/debugger/remote_debugger_peer.h index c759c65568..652e2d9d20 100644 --- a/core/debugger/remote_debugger_peer.h +++ b/core/debugger/remote_debugger_peer.h @@ -58,7 +58,7 @@ class RemoteDebuggerPeerTCP : public RemoteDebuggerPeer { private: Ref<StreamPeerTCP> tcp_client; Mutex mutex; - Thread *thread = nullptr; + Thread thread; List<Array> in_queue; List<Array> out_queue; int out_left = 0; diff --git a/core/input/godotcontrollerdb.txt b/core/input/godotcontrollerdb.txt index 51ddda1e4e..e8e250e3be 100644 --- a/core/input/godotcontrollerdb.txt +++ b/core/input/godotcontrollerdb.txt @@ -8,13 +8,20 @@ __XINPUT_DEVICE__,XInput Gamepad,a:b12,b:b13,x:b14,y:b15,start:b4,back:b5,leftst Default Android Gamepad,Default Controller,leftx:a0,lefty:a1,dpdown:h0.4,rightstick:b8,rightshoulder:b10,rightx:a2,start:b6,righty:a3,dpleft:h0.8,lefttrigger:a4,x:b2,dpup:h0.1,back:b4,leftstick:b7,leftshoulder:b9,y:b3,a:b0,dpright:h0.2,righttrigger:a5,b:b1,platform:Android, # Javascript -Default HTML5 Gamepad, Default Mapping,leftx:a0,lefty:a1,dpdown:b13,rightstick:b11,rightshoulder:b5,rightx:a2,start:b9,righty:a3,dpleft:b14,lefttrigger:a6,x:b2,dpup:b12,back:b8,leftstick:b10,leftshoulder:b4,y:b3,a:b0,dpright:b15,righttrigger:a7,b:b1,platform:Javascript, -c2a94d6963726f736f66742058626f78,Wireless X360 Controller,leftx:a0,lefty:a1,dpdown:b14,rightstick:b10,rightshoulder:b5,rightx:a3,start:b7,righty:a4,dpleft:b11,lefttrigger:a2,x:b2,dpup:b13,back:b6,leftstick:b9,leftshoulder:b4,y:b3,a:b0,dpright:b12,righttrigger:a5,b:b1,platform:Javascript, -303534632d303563342d576972656c65,PS4 Controller USB/Win,leftx:a0,lefty:a1,dpdown:b15,rightstick:b11,rightshoulder:b5,rightx:a2,start:b9,righty:a5,lefttrigger:a3,x:b0,dpup:b14,dpleft:b16,dpright:b17,back:b8,leftstick:b10,leftshoulder:b4,y:b3,a:b1,righttrigger:b7,b:b2,platform:Javascript, -303534632d303563342d536f6e792043,PS4 Controller USB/Linux,leftx:a0,lefty:a1,dpdown:a7,rightstick:b11,rightshoulder:b5,rightx:a2,start:b9,righty:a5,dpleft:a6,lefttrigger:a3,x:b0,dpup:a7,back:b8,leftstick:b10,leftshoulder:b4,y:b3,a:b1,dpright:a6,righttrigger:a4,b:b2,platform:Javascript, -303534632d303236382d536f6e792050,PS3 Controller USB/Linux,leftx:a0,lefty:a1,dpdown:b6,rightstick:b2,rightshoulder:b11,rightx:a2,start:b3,righty:a3,dpleft:b7,lefttrigger:b8,x:b15,dpup:b4,back:b0,leftstick:b1,leftshoulder:b10,y:b12,a:b14,dpright:b5,righttrigger:b9,b:b13,platform:Javascript, -303435652d303731392d58626f782033,Wireless X360 Controller,leftx:a0,lefty:a1,dpdown:b14,rightstick:b10,rightshoulder:b5,rightx:a3,start:b7,righty:a4,dpleft:b11,lefttrigger:a2,x:b2,dpup:b13,back:b6,leftstick:b9,leftshoulder:b4,y:b3,a:b0,dpright:b12,righttrigger:a5,b:b1,platform:Javascript, -303435652d303238652d4d6963726f73,Wired X360 Controller,leftx:a0,lefty:a1,dpdown:a7,rightstick:b10,rightshoulder:b5,rightx:a3,start:b7,righty:a4,dpleft:a6,lefttrigger:a2,x:b2,dpup:a7,back:b6,leftstick:b9,leftshoulder:b4,y:b3,a:b0,dpright:a6,righttrigger:a5,b:b1,platform:Javascript, +standard,Standard Gamepad Mapping,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a6,righttrigger:a7,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b8,start:b9,leftstick:b10,rightstick:b11,dpup:b12,dpdown:b13,dpleft:b14,dpright:b15,guide:b16,leftstick:b10,rightstick:b11,platform:Javascript, +Linux24c6581a,PowerA Xbox One Cabled,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:-a7,dpleft:-a6,dpdown:+a7,dpright:+a6,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,platform:Javascript, +Linux0e6f0301,Logic 3 Controller (xbox compatible),a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:-a7,dpleft:-a6,dpdown:+a7,dpright:+a6,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,platform:Javascript, +Linux045e028e,Microsoft X-Box 360 pad,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:-a7,dpleft:-a6,dpdown:+a7,dpright:+a6,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,platform:Javascript, +Linux045e02d1,Microsoft X-Box One pad,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:-a7,dpleft:-a6,dpdown:+a7,dpright:+a6,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,platform:Javascript, +Linux045e02ea,Microsoft X-Box One S pad,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:-a7,dpleft:-a6,dpdown:+a7,dpright:+a6,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,platform:Javascript, +Linux045e0b12,Microsoft X-Box Series X pad,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:-a7,dpleft:-a6,dpdown:+a7,dpright:+a6,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,platform:Javascript, +Linux044fb315,Thrustmaster dual analog 3.2,a:b0,b:b2,y:b3,x:b1,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b6,dpup:-a5,dpleft:-a4,dpdown:+a5,dpright:+a4,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b5,righttrigger:b7,platform:Javascript, +Linux0e8f0003,PS3 Controller,a:b2,b:b1,back:b8,dpdown:+a5,dpleft:-a4,dpright:+a4,dpup:-a5,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b3,y:b0,platform:Javascript, +MacOSX24c6581a,PowerA Xbox One Cabled,a:b11,b:b12,y:b14,x:b13,start:b4,back:b5,leftstick:b6,rightstick:b7,leftshoulder:b8,rightshoulder:b9,dpup:b0,dpleft:b2,dpdown:b1,dpright:b3,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,platform:Javascript +MacOSX045e028e,Xbox 360 Wired Controller,a:b11,b:b12,y:b14,x:b13,start:b4,back:b5,leftstick:b6,rightstick:b7,leftshoulder:b8,rightshoulder:b9,dpup:b0,dpleft:b2,dpdown:b1,dpright:b3,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,platform:Javascript +MacOSX045e02d1,Xbox One Controller,a:b11,b:b12,y:b14,x:b13,start:b4,back:b5,leftstick:b6,rightstick:b7,leftshoulder:b8,rightshoulder:b9,dpup:b0,dpleft:b2,dpdown:b1,dpright:b3,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,platform:Javascript +MacOSX045e02ea,Xbox One S Controller,a:b11,b:b12,y:b14,x:b13,start:b4,back:b5,leftstick:b6,rightstick:b7,leftshoulder:b8,rightshoulder:b9,dpup:b0,dpleft:b2,dpdown:b1,dpright:b3,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,platform:Javascript +MacOSX045e0b12,Xbox Series X Controller,a:b11,b:b12,y:b14,x:b13,start:b4,back:b5,leftstick:b6,rightstick:b7,leftshoulder:b8,rightshoulder:b9,dpup:b0,dpleft:b2,dpdown:b1,dpright:b3,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,platform:Javascript # UWP __UWP_GAMEPAD__,Xbox Controller,a:b2,b:b3,x:b4,y:b5,start:b0,back:b1,leftstick:b12,rightstick:b13,leftshoulder:b10,rightshoulder:b11,dpup:b6,dpdown:b7,dpleft:b8,dpright:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,platform:UWP, diff --git a/core/input/input.cpp b/core/input/input.cpp index c96884a7b3..2e3f112ebc 100644 --- a/core/input/input.cpp +++ b/core/input/input.cpp @@ -886,10 +886,10 @@ void Input::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) { jx.min = p_value.min; jx.value = p_value.value < 0.5 ? 0.6 : 0.4; joy_axis(p_device, p_axis, jx); - } else if (ABS(last) > 0.5 && last * p_value.value < 0) { + } else if (ABS(last) > 0.5 && last * p_value.value <= 0) { JoyAxis jx; jx.min = p_value.min; - jx.value = p_value.value < 0 ? 0.1 : -0.1; + jx.value = last > 0 ? 0.1 : -0.1; joy_axis(p_device, p_axis, jx); } diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp index 1d9aa846eb..97838fd14c 100644 --- a/core/io/file_access_network.cpp +++ b/core/io/file_access_network.cpp @@ -201,7 +201,7 @@ Error FileAccessNetworkClient::connect(const String &p_host, int p_port, const S return ERR_INVALID_PARAMETER; } - thread = Thread::create(_thread_func, this); + thread.start(_thread_func, this); return OK; } @@ -214,12 +214,9 @@ FileAccessNetworkClient::FileAccessNetworkClient() { } FileAccessNetworkClient::~FileAccessNetworkClient() { - if (thread) { - quit = true; - sem.post(); - Thread::wait_to_finish(thread); - memdelete(thread); - } + quit = true; + sem.post(); + thread.wait_to_finish(); } void FileAccessNetwork::_set_block(int p_offset, const Vector<uint8_t> &p_block) { diff --git a/core/io/file_access_network.h b/core/io/file_access_network.h index 6aec2869fc..1f5de3e5dd 100644 --- a/core/io/file_access_network.h +++ b/core/io/file_access_network.h @@ -48,7 +48,7 @@ class FileAccessNetworkClient { List<BlockRequest> block_requests; Semaphore sem; - Thread *thread = nullptr; + Thread thread; bool quit = false; Mutex mutex; Mutex blockrequest_mutex; diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp index a2fcf074ae..18afdc678e 100644 --- a/core/io/http_client.cpp +++ b/core/io/http_client.cpp @@ -736,14 +736,14 @@ String HTTPClient::query_string_from_dict(const Dictionary &p_dict) { String query = ""; Array keys = p_dict.keys(); for (int i = 0; i < keys.size(); ++i) { - String encoded_key = String(keys[i]).http_escape(); + String encoded_key = String(keys[i]).uri_encode(); Variant value = p_dict[keys[i]]; switch (value.get_type()) { case Variant::ARRAY: { // Repeat the key with every values Array values = value; for (int j = 0; j < values.size(); ++j) { - query += "&" + encoded_key + "=" + String(values[j]).http_escape(); + query += "&" + encoded_key + "=" + String(values[j]).uri_encode(); } break; } @@ -754,7 +754,7 @@ String HTTPClient::query_string_from_dict(const Dictionary &p_dict) { } default: { // Add the key-value pair - query += "&" + encoded_key + "=" + String(value).http_escape(); + query += "&" + encoded_key + "=" + String(value).uri_encode(); } } } diff --git a/core/io/ip.cpp b/core/io/ip.cpp index 6fb812e78d..df95785000 100644 --- a/core/io/ip.cpp +++ b/core/io/ip.cpp @@ -71,7 +71,7 @@ struct _IP_ResolverPrivate { Mutex mutex; Semaphore sem; - Thread *thread; + Thread thread; //Semaphore* semaphore; bool thread_abort; @@ -141,7 +141,7 @@ IP::ResolverID IP::resolve_hostname_queue_item(const String &p_hostname, IP::Typ } else { resolver->queue[id].response = IP_Address(); resolver->queue[id].status = IP::RESOLVER_STATUS_WAITING; - if (resolver->thread) { + if (resolver->thread.is_started()) { resolver->sem.post(); } else { resolver->resolve_queues(); @@ -285,26 +285,14 @@ IP::IP() { singleton = this; resolver = memnew(_IP_ResolverPrivate); -#ifndef NO_THREADS - resolver->thread_abort = false; - - resolver->thread = Thread::create(_IP_ResolverPrivate::_thread_function, resolver); -#else - resolver->thread = nullptr; -#endif + resolver->thread.start(_IP_ResolverPrivate::_thread_function, resolver); } IP::~IP() { -#ifndef NO_THREADS - if (resolver->thread) { - resolver->thread_abort = true; - resolver->sem.post(); - Thread::wait_to_finish(resolver->thread); - memdelete(resolver->thread); - } - -#endif + resolver->thread_abort = true; + resolver->sem.post(); + resolver->thread.wait_to_finish(); memdelete(resolver); } diff --git a/core/io/resource.cpp b/core/io/resource.cpp index 716da5e395..db79998a90 100644 --- a/core/io/resource.cpp +++ b/core/io/resource.cpp @@ -52,29 +52,29 @@ void Resource::set_path(const String &p_path, bool p_take_over) { } if (path_cache != "") { - ResourceCache::lock->write_lock(); + ResourceCache::lock.write_lock(); ResourceCache::resources.erase(path_cache); - ResourceCache::lock->write_unlock(); + ResourceCache::lock.write_unlock(); } path_cache = ""; - ResourceCache::lock->read_lock(); + ResourceCache::lock.read_lock(); bool has_path = ResourceCache::resources.has(p_path); - ResourceCache::lock->read_unlock(); + ResourceCache::lock.read_unlock(); if (has_path) { if (p_take_over) { - ResourceCache::lock->write_lock(); + ResourceCache::lock.write_lock(); Resource **res = ResourceCache::resources.getptr(p_path); if (res) { (*res)->set_name(""); } - ResourceCache::lock->write_unlock(); + ResourceCache::lock.write_unlock(); } else { - ResourceCache::lock->read_lock(); + ResourceCache::lock.read_lock(); bool exists = ResourceCache::resources.has(p_path); - ResourceCache::lock->read_unlock(); + ResourceCache::lock.read_unlock(); ERR_FAIL_COND_MSG(exists, "Another resource is loaded from path '" + p_path + "' (possible cyclic resource inclusion)."); } @@ -82,9 +82,9 @@ void Resource::set_path(const String &p_path, bool p_take_over) { path_cache = p_path; if (path_cache != "") { - ResourceCache::lock->write_lock(); + ResourceCache::lock.write_lock(); ResourceCache::resources[path_cache] = this; - ResourceCache::lock->write_unlock(); + ResourceCache::lock.write_unlock(); } _change_notify("resource_path"); @@ -315,9 +315,7 @@ void Resource::set_as_translation_remapped(bool p_remapped) { return; } - if (ResourceCache::lock) { - ResourceCache::lock->write_lock(); - } + ResourceCache::lock.write_lock(); if (p_remapped) { ResourceLoader::remapped_list.add(&remapped_list); @@ -325,9 +323,7 @@ void Resource::set_as_translation_remapped(bool p_remapped) { ResourceLoader::remapped_list.remove(&remapped_list); } - if (ResourceCache::lock) { - ResourceCache::lock->write_unlock(); - } + ResourceCache::lock.write_unlock(); } bool Resource::is_translation_remapped() const { @@ -338,38 +334,24 @@ bool Resource::is_translation_remapped() const { //helps keep IDs same number when loading/saving scenes. -1 clears ID and it Returns -1 when no id stored void Resource::set_id_for_path(const String &p_path, int p_id) { if (p_id == -1) { - if (ResourceCache::path_cache_lock) { - ResourceCache::path_cache_lock->write_lock(); - } + ResourceCache::path_cache_lock.write_lock(); ResourceCache::resource_path_cache[p_path].erase(get_path()); - if (ResourceCache::path_cache_lock) { - ResourceCache::path_cache_lock->write_unlock(); - } + ResourceCache::path_cache_lock.write_unlock(); } else { - if (ResourceCache::path_cache_lock) { - ResourceCache::path_cache_lock->write_lock(); - } + ResourceCache::path_cache_lock.write_lock(); ResourceCache::resource_path_cache[p_path][get_path()] = p_id; - if (ResourceCache::path_cache_lock) { - ResourceCache::path_cache_lock->write_unlock(); - } + ResourceCache::path_cache_lock.write_unlock(); } } int Resource::get_id_for_path(const String &p_path) const { - if (ResourceCache::path_cache_lock) { - ResourceCache::path_cache_lock->read_lock(); - } + ResourceCache::path_cache_lock.read_lock(); if (ResourceCache::resource_path_cache[p_path].has(get_path())) { int result = ResourceCache::resource_path_cache[p_path][get_path()]; - if (ResourceCache::path_cache_lock) { - ResourceCache::path_cache_lock->read_unlock(); - } + ResourceCache::path_cache_lock.read_unlock(); return result; } else { - if (ResourceCache::path_cache_lock) { - ResourceCache::path_cache_lock->read_unlock(); - } + ResourceCache::path_cache_lock.read_unlock(); return -1; } } @@ -386,6 +368,7 @@ void Resource::_bind_methods() { ClassDB::bind_method(D_METHOD("is_local_to_scene"), &Resource::is_local_to_scene); ClassDB::bind_method(D_METHOD("get_local_scene"), &Resource::get_local_scene); ClassDB::bind_method(D_METHOD("setup_local_to_scene"), &Resource::setup_local_to_scene); + ClassDB::bind_method(D_METHOD("emit_changed"), &Resource::emit_changed); ClassDB::bind_method(D_METHOD("duplicate", "subresources"), &Resource::duplicate, DEFVAL(false)); ADD_SIGNAL(MethodInfo("changed")); @@ -402,9 +385,9 @@ Resource::Resource() : Resource::~Resource() { if (path_cache != "") { - ResourceCache::lock->write_lock(); + ResourceCache::lock.write_lock(); ResourceCache::resources.erase(path_cache); - ResourceCache::lock->write_unlock(); + ResourceCache::lock.write_unlock(); } if (owners.size()) { WARN_PRINT("Resource is still owned."); @@ -416,18 +399,11 @@ HashMap<String, Resource *> ResourceCache::resources; HashMap<String, HashMap<String, int>> ResourceCache::resource_path_cache; #endif -RWLock *ResourceCache::lock = nullptr; +RWLock ResourceCache::lock; #ifdef TOOLS_ENABLED -RWLock *ResourceCache::path_cache_lock = nullptr; +RWLock ResourceCache::path_cache_lock; #endif -void ResourceCache::setup() { - lock = RWLock::create(); -#ifdef TOOLS_ENABLED - path_cache_lock = RWLock::create(); -#endif -} - void ResourceCache::clear() { if (resources.size()) { ERR_PRINT("Resources still in use at exit (run with --verbose for details)."); @@ -441,29 +417,25 @@ void ResourceCache::clear() { } resources.clear(); - memdelete(lock); -#ifdef TOOLS_ENABLED - memdelete(path_cache_lock); -#endif } void ResourceCache::reload_externals() { } bool ResourceCache::has(const String &p_path) { - lock->read_lock(); + lock.read_lock(); bool b = resources.has(p_path); - lock->read_unlock(); + lock.read_unlock(); return b; } Resource *ResourceCache::get(const String &p_path) { - lock->read_lock(); + lock.read_lock(); Resource **res = resources.getptr(p_path); - lock->read_unlock(); + lock.read_unlock(); if (!res) { return nullptr; @@ -473,26 +445,26 @@ Resource *ResourceCache::get(const String &p_path) { } void ResourceCache::get_cached_resources(List<Ref<Resource>> *p_resources) { - lock->read_lock(); + lock.read_lock(); const String *K = nullptr; while ((K = resources.next(K))) { Resource *r = resources[*K]; p_resources->push_back(Ref<Resource>(r)); } - lock->read_unlock(); + lock.read_unlock(); } int ResourceCache::get_cached_resource_count() { - lock->read_lock(); + lock.read_lock(); int rc = resources.size(); - lock->read_unlock(); + lock.read_unlock(); return rc; } void ResourceCache::dump(const char *p_file, bool p_short) { #ifdef DEBUG_ENABLED - lock->read_lock(); + lock.read_lock(); Map<String, int> type_count; @@ -529,6 +501,6 @@ void ResourceCache::dump(const char *p_file, bool p_short) { memdelete(f); } - lock->read_unlock(); + lock.read_unlock(); #endif } diff --git a/core/io/resource.h b/core/io/resource.h index eda18a8538..d0cd6ea3ac 100644 --- a/core/io/resource.h +++ b/core/io/resource.h @@ -149,16 +149,15 @@ typedef Ref<Resource> RES; class ResourceCache { friend class Resource; friend class ResourceLoader; //need the lock - static RWLock *lock; + static RWLock lock; static HashMap<String, Resource *> resources; #ifdef TOOLS_ENABLED static HashMap<String, HashMap<String, int>> resource_path_cache; // each tscn has a set of resource paths and IDs - static RWLock *path_cache_lock; + static RWLock path_cache_lock; #endif // TOOLS_ENABLED friend void unregister_core_types(); static void clear(); friend void register_core_types(); - static void setup(); public: static void reload_externals(); diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index ae4643a19f..fad58d65fd 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -261,11 +261,11 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { r_v = v; } break; case VARIANT_COLOR: { - Color v; - v.r = f->get_real(); - v.g = f->get_real(); - v.b = f->get_real(); - v.a = f->get_real(); + Color v; // Colors should always be in single-precision. + v.r = f->get_float(); + v.g = f->get_float(); + v.b = f->get_float(); + v.a = f->get_float(); r_v = v; } break; diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 821e468aee..d66511a39f 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -323,9 +323,7 @@ Error ResourceLoader::load_threaded_request(const String &p_path, const String & ERR_FAIL_V_MSG(ERR_INVALID_PARAMETER, "Attempted to load a resource already being loaded from this thread, cyclic reference?"); } //lock first if possible - if (ResourceCache::lock) { - ResourceCache::lock->read_lock(); - } + ResourceCache::lock.read_lock(); //get ptr Resource **rptr = ResourceCache::resources.getptr(local_path); @@ -340,9 +338,7 @@ Error ResourceLoader::load_threaded_request(const String &p_path, const String & load_task.progress = 1.0; } } - if (ResourceCache::lock) { - ResourceCache::lock->read_unlock(); - } + ResourceCache::lock.read_unlock(); } if (p_source_resource != String()) { @@ -366,7 +362,8 @@ Error ResourceLoader::load_threaded_request(const String &p_path, const String & print_lt("REQUEST: load count: " + itos(thread_loading_count) + " / wait count: " + itos(thread_waiting_count) + " / suspended count: " + itos(thread_suspended_count) + " / active: " + itos(thread_loading_count - thread_suspended_count)); - load_task.thread = Thread::create(_thread_load_function, &thread_load_tasks[local_path]); + load_task.thread = memnew(Thread); + load_task.thread->start(_thread_load_function, &thread_load_tasks[local_path]); load_task.loader_id = load_task.thread->get_id(); } @@ -493,7 +490,7 @@ RES ResourceLoader::load_threaded_get(const String &p_path, Error *r_error) { if (load_task.requests == 0) { if (load_task.thread) { //thread may not have been used - Thread::wait_to_finish(load_task.thread); + load_task.thread->wait_to_finish(); memdelete(load_task.thread); } thread_load_tasks.erase(local_path); @@ -535,9 +532,7 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p } //Is it cached? - if (ResourceCache::lock) { - ResourceCache::lock->read_lock(); - } + ResourceCache::lock.read_lock(); Resource **rptr = ResourceCache::resources.getptr(local_path); @@ -546,9 +541,7 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p //it is possible this resource was just freed in a thread. If so, this referencing will not work and resource is considered not cached if (res.is_valid()) { - if (ResourceCache::lock) { - ResourceCache::lock->read_unlock(); - } + ResourceCache::lock.read_unlock(); thread_load_mutex->unlock(); if (r_error) { @@ -559,9 +552,7 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p } } - if (ResourceCache::lock) { - ResourceCache::lock->read_unlock(); - } + ResourceCache::lock.read_unlock(); //load using task (but this thread) ThreadLoadTask load_task; @@ -955,9 +946,7 @@ String ResourceLoader::path_remap(const String &p_path) { } void ResourceLoader::reload_translation_remaps() { - if (ResourceCache::lock) { - ResourceCache::lock->read_lock(); - } + ResourceCache::lock.read_lock(); List<Resource *> to_reload; SelfList<Resource> *E = remapped_list.first(); @@ -967,9 +956,7 @@ void ResourceLoader::reload_translation_remaps() { E = E->next(); } - if (ResourceCache::lock) { - ResourceCache::lock->read_unlock(); - } + ResourceCache::lock.read_unlock(); //now just make sure to not delete any of these resources while changing locale.. while (to_reload.front()) { diff --git a/core/math/aabb.h b/core/math/aabb.h index 2861358e32..e16246902a 100644 --- a/core/math/aabb.h +++ b/core/math/aabb.h @@ -107,8 +107,8 @@ public: Variant intersects_segment_bind(const Vector3 &p_from, const Vector3 &p_to) const; Variant intersects_ray_bind(const Vector3 &p_from, const Vector3 &p_dir) const; - _FORCE_INLINE_ void quantize(float p_unit); - _FORCE_INLINE_ AABB quantized(float p_unit) const; + _FORCE_INLINE_ void quantize(real_t p_unit); + _FORCE_INLINE_ AABB quantized(real_t p_unit) const; _FORCE_INLINE_ void set_end(const Vector3 &p_end) { size = p_end - position; @@ -430,7 +430,7 @@ void AABB::grow_by(real_t p_amount) { size.z += 2.0 * p_amount; } -void AABB::quantize(float p_unit) { +void AABB::quantize(real_t p_unit) { size += position; position.x -= Math::fposmodp(position.x, p_unit); @@ -448,7 +448,7 @@ void AABB::quantize(float p_unit) { size -= position; } -AABB AABB::quantized(float p_unit) const { +AABB AABB::quantized(real_t p_unit) const { AABB ret = *this; ret.quantize(p_unit); return ret; diff --git a/core/math/basis.cpp b/core/math/basis.cpp index 26b4caba39..cbdd8a8c9f 100644 --- a/core/math/basis.cpp +++ b/core/math/basis.cpp @@ -790,8 +790,8 @@ Quat Basis::get_quat() const { temp[2] = ((m.elements[1][0] - m.elements[0][1]) * s); } else { int i = m.elements[0][0] < m.elements[1][1] ? - (m.elements[1][1] < m.elements[2][2] ? 2 : 1) : - (m.elements[0][0] < m.elements[2][2] ? 2 : 0); + (m.elements[1][1] < m.elements[2][2] ? 2 : 1) : + (m.elements[0][0] < m.elements[2][2] ? 2 : 0); int j = (i + 1) % 3; int k = (i + 2) % 3; diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp index 9ec71af57f..7dbda1d149 100644 --- a/core/math/camera_matrix.cpp +++ b/core/math/camera_matrix.cpp @@ -74,6 +74,15 @@ Plane CameraMatrix::xform4(const Plane &p_vec4) const { return ret; } +void CameraMatrix::adjust_perspective_znear(real_t p_new_znear) { + real_t zfar = get_z_far(); + real_t znear = p_new_znear; + + real_t deltaZ = zfar - znear; + matrix[2][2] = -(zfar + znear) / deltaZ; + matrix[3][2] = -2 * znear * zfar / deltaZ; +} + void CameraMatrix::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far, bool p_flip_fov) { if (p_flip_fov) { p_fovy_degrees = get_fovy(p_fovy_degrees, 1.0 / p_aspect); diff --git a/core/math/camera_matrix.h b/core/math/camera_matrix.h index 03068bc7ea..3f327d3bc4 100644 --- a/core/math/camera_matrix.h +++ b/core/math/camera_matrix.h @@ -59,6 +59,7 @@ struct CameraMatrix { void set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear, real_t p_zfar, bool p_flip_fov = false); void set_frustum(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_near, real_t p_far); void set_frustum(real_t p_size, real_t p_aspect, Vector2 p_offset, real_t p_near, real_t p_far, bool p_flip_fov = false); + void adjust_perspective_znear(real_t p_new_znear); static real_t get_fovy(real_t p_fovx, real_t p_aspect) { return Math::rad2deg(Math::atan(p_aspect * Math::tan(Math::deg2rad(p_fovx) * 0.5)) * 2.0); diff --git a/core/math/color.cpp b/core/math/color.cpp index 588aedf821..0398d43838 100644 --- a/core/math/color.cpp +++ b/core/math/color.cpp @@ -544,12 +544,12 @@ Color Color::operator*(const Color &p_color) const { a * p_color.a); } -Color Color::operator*(real_t p_rvalue) const { +Color Color::operator*(float p_scalar) const { return Color( - r * p_rvalue, - g * p_rvalue, - b * p_rvalue, - a * p_rvalue); + r * p_scalar, + g * p_scalar, + b * p_scalar, + a * p_scalar); } void Color::operator*=(const Color &p_color) { @@ -559,11 +559,11 @@ void Color::operator*=(const Color &p_color) { a = a * p_color.a; } -void Color::operator*=(real_t p_rvalue) { - r = r * p_rvalue; - g = g * p_rvalue; - b = b * p_rvalue; - a = a * p_rvalue; +void Color::operator*=(float p_scalar) { + r = r * p_scalar; + g = g * p_scalar; + b = b * p_scalar; + a = a * p_scalar; } Color Color::operator/(const Color &p_color) const { @@ -574,12 +574,12 @@ Color Color::operator/(const Color &p_color) const { a / p_color.a); } -Color Color::operator/(real_t p_rvalue) const { +Color Color::operator/(float p_scalar) const { return Color( - r / p_rvalue, - g / p_rvalue, - b / p_rvalue, - a / p_rvalue); + r / p_scalar, + g / p_scalar, + b / p_scalar, + a / p_scalar); } void Color::operator/=(const Color &p_color) { @@ -589,18 +589,11 @@ void Color::operator/=(const Color &p_color) { a = a / p_color.a; } -void Color::operator/=(real_t p_rvalue) { - if (p_rvalue == 0) { - r = 1.0; - g = 1.0; - b = 1.0; - a = 1.0; - } else { - r = r / p_rvalue; - g = g / p_rvalue; - b = b / p_rvalue; - a = a / p_rvalue; - } +void Color::operator/=(float p_scalar) { + r = r / p_scalar; + g = g / p_scalar; + b = b / p_scalar; + a = a / p_scalar; } Color Color::operator-() const { diff --git a/core/math/color.h b/core/math/color.h index 779f770761..d3b27a9c65 100644 --- a/core/math/color.h +++ b/core/math/color.h @@ -78,14 +78,14 @@ struct Color { void operator-=(const Color &p_color); Color operator*(const Color &p_color) const; - Color operator*(real_t p_rvalue) const; + Color operator*(float p_scalar) const; void operator*=(const Color &p_color); - void operator*=(real_t p_rvalue); + void operator*=(float p_scalar); Color operator/(const Color &p_color) const; - Color operator/(real_t p_rvalue) const; + Color operator/(float p_scalar) const; void operator/=(const Color &p_color); - void operator/=(real_t p_rvalue); + void operator/=(float p_scalar); bool is_equal_approx(const Color &p_color) const; @@ -259,8 +259,8 @@ bool Color::operator<(const Color &p_color) const { } } -_FORCE_INLINE_ Color operator*(real_t p_real, const Color &p_color) { - return p_color * p_real; +_FORCE_INLINE_ Color operator*(float p_scalar, const Color &p_color) { + return p_color * p_scalar; } #endif // COLOR_H diff --git a/core/math/geometry_2d.cpp b/core/math/geometry_2d.cpp index 5d4c31088b..783750b9e6 100644 --- a/core/math/geometry_2d.cpp +++ b/core/math/geometry_2d.cpp @@ -31,7 +31,7 @@ #include "geometry_2d.h" #include "thirdparty/misc/clipper.hpp" -#include "thirdparty/misc/triangulator.h" +#include "thirdparty/misc/polypartition.h" #define STB_RECT_PACK_IMPLEMENTATION #include "thirdparty/misc/stb_rect_pack.h" @@ -39,16 +39,16 @@ Vector<Vector<Vector2>> Geometry2D::decompose_polygon_in_convex(Vector<Point2> polygon) { Vector<Vector<Vector2>> decomp; - List<TriangulatorPoly> in_poly, out_poly; + List<TPPLPoly> in_poly, out_poly; - TriangulatorPoly inp; + TPPLPoly inp; inp.Init(polygon.size()); for (int i = 0; i < polygon.size(); i++) { inp.GetPoint(i) = polygon[i]; } - inp.SetOrientation(TRIANGULATOR_CCW); + inp.SetOrientation(TPPL_ORIENTATION_CCW); in_poly.push_back(inp); - TriangulatorPartition tpart; + TPPLPartition tpart; if (tpart.ConvexPartition_HM(&in_poly, &out_poly) == 0) { // Failed. ERR_PRINT("Convex decomposing failed!"); return decomp; @@ -56,8 +56,8 @@ Vector<Vector<Vector2>> Geometry2D::decompose_polygon_in_convex(Vector<Point2> p decomp.resize(out_poly.size()); int idx = 0; - for (List<TriangulatorPoly>::Element *I = out_poly.front(); I; I = I->next()) { - TriangulatorPoly &tp = I->get(); + for (List<TPPLPoly>::Element *I = out_poly.front(); I; I = I->next()) { + TPPLPoly &tp = I->get(); decomp.write[idx].resize(tp.GetNumPoints()); diff --git a/core/math/geometry_3d.cpp b/core/math/geometry_3d.cpp index a918d1de0d..553184303d 100644 --- a/core/math/geometry_3d.cpp +++ b/core/math/geometry_3d.cpp @@ -33,7 +33,7 @@ #include "core/string/print_string.h" #include "thirdparty/misc/clipper.hpp" -#include "thirdparty/misc/triangulator.h" +#include "thirdparty/misc/polypartition.h" void Geometry3D::MeshData::optimize_vertices() { Map<int, int> vtx_remap; diff --git a/core/math/quat.cpp b/core/math/quat.cpp index 4cecc20fef..a9a21a1ba3 100644 --- a/core/math/quat.cpp +++ b/core/math/quat.cpp @@ -33,32 +33,6 @@ #include "core/math/basis.h" #include "core/string/print_string.h" -// set_euler_xyz expects a vector containing the Euler angles in the format -// (ax,ay,az), where ax is the angle of rotation around x axis, -// and similar for other axes. -// This implementation uses XYZ convention (Z is the first rotation). -void Quat::set_euler_xyz(const Vector3 &p_euler) { - real_t half_a1 = p_euler.x * 0.5; - real_t half_a2 = p_euler.y * 0.5; - real_t half_a3 = p_euler.z * 0.5; - - // R = X(a1).Y(a2).Z(a3) convention for Euler angles. - // Conversion to quaternion as listed in https://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/19770024290.pdf (page A-2) - // a3 is the angle of the first rotation, following the notation in this reference. - - real_t cos_a1 = Math::cos(half_a1); - real_t sin_a1 = Math::sin(half_a1); - real_t cos_a2 = Math::cos(half_a2); - real_t sin_a2 = Math::sin(half_a2); - real_t cos_a3 = Math::cos(half_a3); - real_t sin_a3 = Math::sin(half_a3); - - set(sin_a1 * cos_a2 * cos_a3 + sin_a2 * sin_a3 * cos_a1, - -sin_a1 * sin_a3 * cos_a2 + sin_a2 * cos_a1 * cos_a3, - sin_a1 * sin_a2 * cos_a3 + sin_a3 * cos_a1 * cos_a2, - -sin_a1 * sin_a2 * sin_a3 + cos_a1 * cos_a2 * cos_a3); -} - // get_euler_xyz returns a vector containing the Euler angles in the format // (ax,ay,az), where ax is the angle of rotation around x axis, // and similar for other axes. @@ -68,32 +42,6 @@ Vector3 Quat::get_euler_xyz() const { return m.get_euler_xyz(); } -// set_euler_yxz expects a vector containing the Euler angles in the format -// (ax,ay,az), where ax is the angle of rotation around x axis, -// and similar for other axes. -// This implementation uses YXZ convention (Z is the first rotation). -void Quat::set_euler_yxz(const Vector3 &p_euler) { - real_t half_a1 = p_euler.y * 0.5; - real_t half_a2 = p_euler.x * 0.5; - real_t half_a3 = p_euler.z * 0.5; - - // R = Y(a1).X(a2).Z(a3) convention for Euler angles. - // Conversion to quaternion as listed in https://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/19770024290.pdf (page A-6) - // a3 is the angle of the first rotation, following the notation in this reference. - - real_t cos_a1 = Math::cos(half_a1); - real_t sin_a1 = Math::sin(half_a1); - real_t cos_a2 = Math::cos(half_a2); - real_t sin_a2 = Math::sin(half_a2); - real_t cos_a3 = Math::cos(half_a3); - real_t sin_a3 = Math::sin(half_a3); - - set(sin_a1 * cos_a2 * sin_a3 + cos_a1 * sin_a2 * cos_a3, - sin_a1 * cos_a2 * cos_a3 - cos_a1 * sin_a2 * sin_a3, - -sin_a1 * sin_a2 * cos_a3 + cos_a1 * cos_a2 * sin_a3, - sin_a1 * sin_a2 * sin_a3 + cos_a1 * cos_a2 * cos_a3); -} - // get_euler_yxz returns a vector containing the Euler angles in the format // (ax,ay,az), where ax is the angle of rotation around x axis, // and similar for other axes. @@ -107,10 +55,10 @@ Vector3 Quat::get_euler_yxz() const { } void Quat::operator*=(const Quat &p_q) { - set(w * p_q.x + x * p_q.w + y * p_q.z - z * p_q.y, - w * p_q.y + y * p_q.w + z * p_q.x - x * p_q.z, - w * p_q.z + z * p_q.w + x * p_q.y - y * p_q.x, - w * p_q.w - x * p_q.x - y * p_q.y - z * p_q.z); + x = w * p_q.x + x * p_q.w + y * p_q.z - z * p_q.y; + y = w * p_q.y + y * p_q.w + z * p_q.x - x * p_q.z; + z = w * p_q.z + z * p_q.w + x * p_q.y - y * p_q.x; + w = w * p_q.w - x * p_q.x - y * p_q.y - z * p_q.z; } Quat Quat::operator*(const Quat &p_q) const { @@ -233,18 +181,49 @@ Quat::operator String() const { return String::num(x) + ", " + String::num(y) + ", " + String::num(z) + ", " + String::num(w); } -void Quat::set_axis_angle(const Vector3 &axis, const real_t &angle) { +Quat::Quat(const Vector3 &p_axis, real_t p_angle) { #ifdef MATH_CHECKS - ERR_FAIL_COND_MSG(!axis.is_normalized(), "The axis Vector3 must be normalized."); + ERR_FAIL_COND_MSG(!p_axis.is_normalized(), "The axis Vector3 must be normalized."); #endif - real_t d = axis.length(); + real_t d = p_axis.length(); if (d == 0) { - set(0, 0, 0, 0); + x = 0; + y = 0; + z = 0; + w = 0; } else { - real_t sin_angle = Math::sin(angle * 0.5); - real_t cos_angle = Math::cos(angle * 0.5); + real_t sin_angle = Math::sin(p_angle * 0.5); + real_t cos_angle = Math::cos(p_angle * 0.5); real_t s = sin_angle / d; - set(axis.x * s, axis.y * s, axis.z * s, - cos_angle); + x = p_axis.x * s; + y = p_axis.y * s; + z = p_axis.z * s; + w = cos_angle; } } + +// Euler constructor expects a vector containing the Euler angles in the format +// (ax, ay, az), where ax is the angle of rotation around x axis, +// and similar for other axes. +// This implementation uses YXZ convention (Z is the first rotation). +Quat::Quat(const Vector3 &p_euler) { + real_t half_a1 = p_euler.y * 0.5; + real_t half_a2 = p_euler.x * 0.5; + real_t half_a3 = p_euler.z * 0.5; + + // R = Y(a1).X(a2).Z(a3) convention for Euler angles. + // Conversion to quaternion as listed in https://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/19770024290.pdf (page A-6) + // a3 is the angle of the first rotation, following the notation in this reference. + + real_t cos_a1 = Math::cos(half_a1); + real_t sin_a1 = Math::sin(half_a1); + real_t cos_a2 = Math::cos(half_a2); + real_t sin_a2 = Math::sin(half_a2); + real_t cos_a3 = Math::cos(half_a3); + real_t sin_a3 = Math::sin(half_a3); + + x = sin_a1 * cos_a2 * sin_a3 + cos_a1 * sin_a2 * cos_a3; + y = sin_a1 * cos_a2 * cos_a3 - cos_a1 * sin_a2 * sin_a3; + z = -sin_a1 * sin_a2 * cos_a3 + cos_a1 * cos_a2 * sin_a3; + w = sin_a1 * sin_a2 * sin_a3 + cos_a1 * cos_a2 * cos_a3; +} diff --git a/core/math/quat.h b/core/math/quat.h index 423a7f8dfe..9db914fe52 100644 --- a/core/math/quat.h +++ b/core/math/quat.h @@ -65,19 +65,14 @@ public: Quat inverse() const; _FORCE_INLINE_ real_t dot(const Quat &p_q) const; - void set_euler_xyz(const Vector3 &p_euler); Vector3 get_euler_xyz() const; - void set_euler_yxz(const Vector3 &p_euler); Vector3 get_euler_yxz() const; - - void set_euler(const Vector3 &p_euler) { set_euler_yxz(p_euler); }; Vector3 get_euler() const { return get_euler_yxz(); }; Quat slerp(const Quat &p_to, const real_t &p_weight) const; Quat slerpni(const Quat &p_to, const real_t &p_weight) const; Quat cubic_slerp(const Quat &p_b, const Quat &p_pre_a, const Quat &p_post_b, const real_t &p_weight) const; - void set_axis_angle(const Vector3 &axis, const real_t &angle); _FORCE_INLINE_ void get_axis_angle(Vector3 &r_axis, real_t &r_angle) const { r_angle = 2 * Math::acos(w); real_t r = ((real_t)1) / Math::sqrt(1 - w * w); @@ -124,23 +119,19 @@ public: operator String() const; - inline void set(real_t p_x, real_t p_y, real_t p_z, real_t p_w) { - x = p_x; - y = p_y; - z = p_z; - w = p_w; - } - _FORCE_INLINE_ Quat() {} + _FORCE_INLINE_ Quat(real_t p_x, real_t p_y, real_t p_z, real_t p_w) : x(p_x), y(p_y), z(p_z), w(p_w) { } - Quat(const Vector3 &axis, const real_t &angle) { set_axis_angle(axis, angle); } - Quat(const Vector3 &euler) { set_euler(euler); } + Quat(const Vector3 &p_axis, real_t p_angle); + + Quat(const Vector3 &p_euler); + Quat(const Quat &p_q) : x(p_q.x), y(p_q.y), diff --git a/core/math/vector2.cpp b/core/math/vector2.cpp index 496e29ebe4..5129ed336e 100644 --- a/core/math/vector2.cpp +++ b/core/math/vector2.cpp @@ -211,11 +211,11 @@ Vector2i Vector2i::operator*(const Vector2i &p_v1) const { return Vector2i(x * p_v1.x, y * p_v1.y); } -Vector2i Vector2i::operator*(const int &rvalue) const { +Vector2i Vector2i::operator*(const int32_t &rvalue) const { return Vector2i(x * rvalue, y * rvalue); } -void Vector2i::operator*=(const int &rvalue) { +void Vector2i::operator*=(const int32_t &rvalue) { x *= rvalue; y *= rvalue; } @@ -224,11 +224,11 @@ Vector2i Vector2i::operator/(const Vector2i &p_v1) const { return Vector2i(x / p_v1.x, y / p_v1.y); } -Vector2i Vector2i::operator/(const int &rvalue) const { +Vector2i Vector2i::operator/(const int32_t &rvalue) const { return Vector2i(x / rvalue, y / rvalue); } -void Vector2i::operator/=(const int &rvalue) { +void Vector2i::operator/=(const int32_t &rvalue) { x /= rvalue; y /= rvalue; } @@ -237,11 +237,11 @@ Vector2i Vector2i::operator%(const Vector2i &p_v1) const { return Vector2i(x % p_v1.x, y % p_v1.y); } -Vector2i Vector2i::operator%(const int &rvalue) const { +Vector2i Vector2i::operator%(const int32_t &rvalue) const { return Vector2i(x % rvalue, y % rvalue); } -void Vector2i::operator%=(const int &rvalue) { +void Vector2i::operator%=(const int32_t &rvalue) { x %= rvalue; y %= rvalue; } diff --git a/core/math/vector2.h b/core/math/vector2.h index 24795857a3..81bc71d590 100644 --- a/core/math/vector2.h +++ b/core/math/vector2.h @@ -265,18 +265,18 @@ struct Vector2i { }; union { - int x = 0; - int width; + int32_t x = 0; + int32_t width; }; union { - int y = 0; - int height; + int32_t y = 0; + int32_t height; }; - _FORCE_INLINE_ int &operator[](int p_idx) { + _FORCE_INLINE_ int32_t &operator[](int p_idx) { return p_idx ? y : x; } - _FORCE_INLINE_ const int &operator[](int p_idx) const { + _FORCE_INLINE_ const int32_t &operator[](int p_idx) const { return p_idx ? y : x; } @@ -286,16 +286,16 @@ struct Vector2i { void operator-=(const Vector2i &p_v); Vector2i operator*(const Vector2i &p_v1) const; - Vector2i operator*(const int &rvalue) const; - void operator*=(const int &rvalue); + Vector2i operator*(const int32_t &rvalue) const; + void operator*=(const int32_t &rvalue); Vector2i operator/(const Vector2i &p_v1) const; - Vector2i operator/(const int &rvalue) const; - void operator/=(const int &rvalue); + Vector2i operator/(const int32_t &rvalue) const; + void operator/=(const int32_t &rvalue); Vector2i operator%(const Vector2i &p_v1) const; - Vector2i operator%(const int &rvalue) const; - void operator%=(const int &rvalue); + Vector2i operator%(const int32_t &rvalue) const; + void operator%=(const int32_t &rvalue); Vector2i operator-() const; bool operator<(const Vector2i &p_vec2) const { return (x == p_vec2.x) ? (y < p_vec2.y) : (x < p_vec2.x); } @@ -317,10 +317,10 @@ struct Vector2i { inline Vector2i() {} inline Vector2i(const Vector2 &p_vec2) { - x = (int)p_vec2.x; - y = (int)p_vec2.y; + x = (int32_t)p_vec2.x; + y = (int32_t)p_vec2.y; } - inline Vector2i(int p_x, int p_y) { + inline Vector2i(int32_t p_x, int32_t p_y) { x = p_x; y = p_y; } diff --git a/core/math/vector3.h b/core/math/vector3.h index 3fdb944729..6b4ff3f9a8 100644 --- a/core/math/vector3.h +++ b/core/math/vector3.h @@ -324,48 +324,40 @@ bool Vector3::operator<(const Vector3 &p_v) const { if (x == p_v.x) { if (y == p_v.y) { return z < p_v.z; - } else { - return y < p_v.y; } - } else { - return x < p_v.x; + return y < p_v.y; } + return x < p_v.x; } bool Vector3::operator>(const Vector3 &p_v) const { if (x == p_v.x) { if (y == p_v.y) { return z > p_v.z; - } else { - return y > p_v.y; } - } else { - return x > p_v.x; + return y > p_v.y; } + return x > p_v.x; } bool Vector3::operator<=(const Vector3 &p_v) const { if (x == p_v.x) { if (y == p_v.y) { return z <= p_v.z; - } else { - return y < p_v.y; } - } else { - return x < p_v.x; + return y < p_v.y; } + return x < p_v.x; } bool Vector3::operator>=(const Vector3 &p_v) const { if (x == p_v.x) { if (y == p_v.y) { return z >= p_v.z; - } else { - return y > p_v.y; } - } else { - return x > p_v.x; + return y > p_v.y; } + return x > p_v.x; } _FORCE_INLINE_ Vector3 vec3_cross(const Vector3 &p_a, const Vector3 &p_b) { diff --git a/core/object/class_db.cpp b/core/object/class_db.cpp index 6bc6d653d1..375ad8fae1 100644 --- a/core/object/class_db.cpp +++ b/core/object/class_db.cpp @@ -983,9 +983,9 @@ void ClassDB::add_property_subgroup(StringName p_class, const String &p_name, co // NOTE: For implementation simplicity reasons, this method doesn't allow setters to have optional arguments at the end. void ClassDB::add_property(StringName p_class, const PropertyInfo &p_pinfo, const StringName &p_setter, const StringName &p_getter, int p_index) { - lock->read_lock(); + lock.read_lock(); ClassInfo *type = classes.getptr(p_class); - lock->read_unlock(); + lock.read_unlock(); ERR_FAIL_COND(!type); @@ -1541,11 +1541,7 @@ Variant ClassDB::class_get_default_property_value(const StringName &p_class, con return var; } -RWLock *ClassDB::lock = nullptr; - -void ClassDB::init() { - lock = RWLock::create(); -} +RWLock ClassDB::lock; void ClassDB::cleanup_defaults() { default_values.clear(); @@ -1568,8 +1564,6 @@ void ClassDB::cleanup() { classes.clear(); resource_base_extensions.clear(); compat_classes.clear(); - - memdelete(lock); } // diff --git a/core/object/class_db.h b/core/object/class_db.h index 0591676b92..6fd5748dbb 100644 --- a/core/object/class_db.h +++ b/core/object/class_db.h @@ -146,7 +146,7 @@ public: return memnew(T); } - static RWLock *lock; + static RWLock lock; static HashMap<StringName, ClassInfo> classes; static HashMap<StringName, StringName> resource_base_extensions; static HashMap<StringName, StringName> compat_classes; @@ -387,7 +387,6 @@ public: static void get_extensions_for_type(const StringName &p_class, List<String> *p_extensions); static void add_compatibility_class(const StringName &p_class, const StringName &p_fallback); - static void init(); static void set_current_api(APIType p_api); static APIType get_current_api(); diff --git a/core/object/undo_redo.cpp b/core/object/undo_redo.cpp index c699820e75..3b1165b8f6 100644 --- a/core/object/undo_redo.cpp +++ b/core/object/undo_redo.cpp @@ -53,6 +53,23 @@ void UndoRedo::_discard_redo() { actions.resize(current_action + 1); } +bool UndoRedo::_redo(bool p_execute) { + ERR_FAIL_COND_V(action_level > 0, false); + + if ((current_action + 1) >= actions.size()) { + return false; //nothing to redo + } + + current_action++; + if (p_execute) { + _process_operation_list(actions.write[current_action].do_ops.front()); + } + version++; + emit_signal("version_changed"); + + return true; +} + void UndoRedo::create_action(const String &p_name, MergeMode p_mode) { uint32_t ticks = OS::get_singleton()->get_ticks_msec(); @@ -242,7 +259,7 @@ bool UndoRedo::is_committing_action() const { return committing > 0; } -void UndoRedo::commit_action() { +void UndoRedo::commit_action(bool p_execute) { ERR_FAIL_COND(action_level <= 0); action_level--; if (action_level > 0) { @@ -255,8 +272,9 @@ void UndoRedo::commit_action() { } committing++; - redo(); // perform action + _redo(p_execute); // perform action committing--; + if (callback && actions.size() > 0) { callback(callback_ud, actions[actions.size() - 1].name); } @@ -323,19 +341,7 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E) { } bool UndoRedo::redo() { - ERR_FAIL_COND_V(action_level > 0, false); - - if ((current_action + 1) >= actions.size()) { - return false; //nothing to redo - } - - current_action++; - - _process_operation_list(actions.write[current_action].do_ops.front()); - version++; - emit_signal("version_changed"); - - return true; + return _redo(true); } bool UndoRedo::undo() { @@ -351,6 +357,24 @@ bool UndoRedo::undo() { return true; } +int UndoRedo::get_history_count() { + ERR_FAIL_COND_V(action_level > 0, -1); + + return actions.size(); +} + +int UndoRedo::get_current_action() { + ERR_FAIL_COND_V(action_level > 0, -1); + + return current_action; +} + +String UndoRedo::get_action_name(int p_id) { + ERR_FAIL_INDEX_V(p_id, actions.size(), ""); + + return actions[p_id].name; +} + void UndoRedo::clear_history(bool p_increase_version) { ERR_FAIL_COND(action_level > 0); _discard_redo(); @@ -480,7 +504,7 @@ Variant UndoRedo::_add_undo_method(const Variant **p_args, int p_argcount, Calla void UndoRedo::_bind_methods() { ClassDB::bind_method(D_METHOD("create_action", "name", "merge_mode"), &UndoRedo::create_action, DEFVAL(MERGE_DISABLE)); - ClassDB::bind_method(D_METHOD("commit_action"), &UndoRedo::commit_action); + ClassDB::bind_method(D_METHOD("commit_action", "execute"), &UndoRedo::commit_action, DEFVAL(true)); ClassDB::bind_method(D_METHOD("is_committing_action"), &UndoRedo::is_committing_action); { @@ -505,8 +529,14 @@ void UndoRedo::_bind_methods() { ClassDB::bind_method(D_METHOD("add_undo_property", "object", "property", "value"), &UndoRedo::add_undo_property); ClassDB::bind_method(D_METHOD("add_do_reference", "object"), &UndoRedo::add_do_reference); ClassDB::bind_method(D_METHOD("add_undo_reference", "object"), &UndoRedo::add_undo_reference); + + ClassDB::bind_method(D_METHOD("get_history_count"), &UndoRedo::get_history_count); + ClassDB::bind_method(D_METHOD("get_current_action"), &UndoRedo::get_current_action); + ClassDB::bind_method(D_METHOD("get_action_name"), &UndoRedo::get_action_name); ClassDB::bind_method(D_METHOD("clear_history", "increase_version"), &UndoRedo::clear_history, DEFVAL(true)); + ClassDB::bind_method(D_METHOD("get_current_action_name"), &UndoRedo::get_current_action_name); + ClassDB::bind_method(D_METHOD("has_undo"), &UndoRedo::has_undo); ClassDB::bind_method(D_METHOD("has_redo"), &UndoRedo::has_redo); ClassDB::bind_method(D_METHOD("get_version"), &UndoRedo::get_version); diff --git a/core/object/undo_redo.h b/core/object/undo_redo.h index 7b28b138c1..a08ca7792f 100644 --- a/core/object/undo_redo.h +++ b/core/object/undo_redo.h @@ -84,6 +84,7 @@ private: void _pop_history_tail(); void _process_operation_list(List<Operation>::Element *E); void _discard_redo(); + bool _redo(bool p_execute); CommitNotifyCallback callback = nullptr; void *callback_ud = nullptr; @@ -109,11 +110,15 @@ public: void add_undo_reference(Object *p_object); bool is_committing_action() const; - void commit_action(); + void commit_action(bool p_execute = true); bool redo(); bool undo(); String get_current_action_name() const; + + int get_history_count(); + int get_current_action(); + String get_action_name(int p_id); void clear_history(bool p_increase_version = true); bool has_undo(); diff --git a/core/os/os.h b/core/os/os.h index ed3c6ddc94..e02ce7d5ec 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -129,7 +129,8 @@ public: virtual int get_low_processor_usage_mode_sleep_usec() const; virtual String get_executable_path() const; - virtual Error execute(const String &p_path, const List<String> &p_arguments, bool p_blocking = true, ProcessID *r_child_id = nullptr, String *r_pipe = nullptr, int *r_exitcode = nullptr, bool read_stderr = false, Mutex *p_pipe_mutex = nullptr) = 0; + 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) = 0; + virtual Error create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id = nullptr) = 0; virtual Error kill(const ProcessID &p_pid) = 0; virtual int get_process_id() const; virtual void vibrate_handheld(int p_duration_ms = 500); diff --git a/core/os/rw_lock.cpp b/core/os/rw_lock.cpp deleted file mode 100644 index 26db0aab30..0000000000 --- a/core/os/rw_lock.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/*************************************************************************/ -/* rw_lock.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* 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 "rw_lock.h" - -#include "core/error/error_macros.h" - -#include <stddef.h> - -RWLock *(*RWLock::create_func)() = nullptr; - -RWLock *RWLock::create() { - ERR_FAIL_COND_V(!create_func, nullptr); - - return create_func(); -} diff --git a/core/os/rw_lock.h b/core/os/rw_lock.h index ff6ad3cc4a..560ec57a5f 100644 --- a/core/os/rw_lock.h +++ b/core/os/rw_lock.h @@ -33,55 +33,83 @@ #include "core/error/error_list.h" +#if !defined(NO_THREADS) + +#include <shared_mutex> + class RWLock { -protected: - static RWLock *(*create_func)(); + mutable std::shared_timed_mutex mutex; public: - virtual void read_lock() = 0; ///< Lock the rwlock, block if locked by someone else - virtual void read_unlock() = 0; ///< Unlock the rwlock, let other threads continue - virtual Error read_try_lock() = 0; ///< Attempt to lock the rwlock, OK on success, ERROR means it can't lock. + // Lock the rwlock, block if locked by someone else + void read_lock() const { + mutex.lock_shared(); + } - virtual void write_lock() = 0; ///< Lock the rwlock, block if locked by someone else - virtual void write_unlock() = 0; ///< Unlock the rwlock, let other thwrites continue - virtual Error write_try_lock() = 0; ///< Attempt to lock the rwlock, OK on success, ERROR means it can't lock. + // Unlock the rwlock, let other threads continue + void read_unlock() const { + mutex.unlock_shared(); + } - static RWLock *create(); ///< Create a rwlock + // Attempt to lock the rwlock, OK on success, ERR_BUSY means it can't lock. + Error read_try_lock() const { + return mutex.try_lock_shared() ? OK : ERR_BUSY; + } + + // Lock the rwlock, block if locked by someone else + void write_lock() { + mutex.lock(); + } + + // Unlock the rwlock, let other thwrites continue + void write_unlock() { + mutex.unlock(); + } - virtual ~RWLock() {} + // Attempt to lock the rwlock, OK on success, ERR_BUSY means it can't lock. + Error write_try_lock() { + return mutex.try_lock() ? OK : ERR_BUSY; + } +}; + +#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 { - RWLock *lock; + const RWLock &lock; public: - RWLockRead(const RWLock *p_lock) { - lock = const_cast<RWLock *>(p_lock); - if (lock) { - lock->read_lock(); - } + RWLockRead(const RWLock &p_lock) : + lock(p_lock) { + lock.read_lock(); } ~RWLockRead() { - if (lock) { - lock->read_unlock(); - } + lock.read_unlock(); } }; class RWLockWrite { - RWLock *lock; + RWLock &lock; public: - RWLockWrite(RWLock *p_lock) { - lock = p_lock; - if (lock) { - lock->write_lock(); - } + RWLockWrite(RWLock &p_lock) : + lock(p_lock) { + lock.write_lock(); } ~RWLockWrite() { - if (lock) { - lock->write_unlock(); - } + lock.write_unlock(); } }; diff --git a/core/os/thread.cpp b/core/os/thread.cpp index 0ed8825452..936e5d5500 100644 --- a/core/os/thread.cpp +++ b/core/os/thread.cpp @@ -30,30 +30,70 @@ #include "thread.h" -Thread *(*Thread::create_func)(ThreadCreateCallback, void *, const Settings &) = nullptr; -Thread::ID (*Thread::get_thread_id_func)() = nullptr; -void (*Thread::wait_to_finish_func)(Thread *) = nullptr; +#include "core/object/script_language.h" + +#if !defined(NO_THREADS) + 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::ID Thread::main_thread_id = 1; +Thread::ID Thread::last_thread_id = 1; +thread_local Thread::ID Thread::caller_id = 1; -Thread::ID Thread::_main_thread_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; +} -Thread::ID Thread::get_caller_id() { - if (get_thread_id_func) { - return get_thread_id_func(); +void Thread::callback(Thread *p_self, const Settings &p_settings, Callback p_callback, void *p_userdata) { + Thread::caller_id = p_self->id; + if (set_priority_func) { + set_priority_func(p_settings.priority); + } + if (init_func) { + init_func(); + } + ScriptServer::thread_enter(); //scripts may need to attach a stack + p_callback(p_userdata); + ScriptServer::thread_exit(); + if (term_func) { + term_func(); } - return 0; } -Thread *Thread::create(ThreadCreateCallback p_callback, void *p_user, const Settings &p_settings) { - if (create_func) { - return create_func(p_callback, p_user, p_settings); +void Thread::start(Thread::Callback p_callback, void *p_user, const Settings &p_settings) { + if (id != 0) { +#ifdef DEBUG_ENABLED + WARN_PRINT("A Thread object has been re-started without wait_to_finish() having been called on it. Please do so to ensure correct cleanup of the thread."); +#endif + thread.detach(); + std::thread empty_thread; + thread.swap(empty_thread); } - return nullptr; + id = atomic_increment(&last_thread_id); + std::thread new_thread(&Thread::callback, this, p_settings, p_callback, p_user); + thread.swap(new_thread); } -void Thread::wait_to_finish(Thread *p_thread) { - if (wait_to_finish_func) { - wait_to_finish_func(p_thread); +bool Thread::is_started() const { + return id != 0; +} + +void Thread::wait_to_finish() { + if (id != 0) { + thread.join(); + std::thread empty_thread; + thread.swap(empty_thread); + id = 0; } } @@ -64,3 +104,14 @@ Error Thread::set_name(const String &p_name) { return ERR_UNAVAILABLE; } + +Thread::~Thread() { + if (id != 0) { +#ifdef DEBUG_ENABLED + WARN_PRINT("A Thread object has been destroyed without wait_to_finish() having been called on it. Please do so to ensure correct cleanup of the thread."); +#endif + thread.detach(); + } +} + +#endif diff --git a/core/os/thread.h b/core/os/thread.h index 993c7ad33d..b5449d2ed6 100644 --- a/core/os/thread.h +++ b/core/os/thread.h @@ -31,13 +31,20 @@ #ifndef THREAD_H #define THREAD_H -#include "core/string/ustring.h" #include "core/typedefs.h" -typedef void (*ThreadCreateCallback)(void *p_userdata); +#if !defined(NO_THREADS) +#include <thread> +#endif + +class String; class Thread { public: + typedef void (*Callback)(void *p_userdata); + + typedef uint64_t ID; + enum Priority { PRIORITY_LOW, PRIORITY_NORMAL, @@ -49,30 +56,60 @@ public: Settings() { priority = PRIORITY_NORMAL; } }; - typedef uint64_t ID; +private: +#if !defined(NO_THREADS) + friend class Main; -protected: - static Thread *(*create_func)(ThreadCreateCallback p_callback, void *, const Settings &); - static ID (*get_thread_id_func)(); - static void (*wait_to_finish_func)(Thread *); - static Error (*set_name_func)(const String &); + static ID main_thread_id; + static ID last_thread_id; - friend class Main; + ID id = 0; + static thread_local ID caller_id; + std::thread thread; - static ID _main_thread_id; + static void callback(Thread *p_self, const Settings &p_settings, Thread::Callback p_callback, void *p_userdata); - Thread() {} + static Error (*set_name_func)(const String &); + static void (*set_priority_func)(Thread::Priority); + static void (*init_func)(); + static void (*term_func)(); +#endif public: - virtual ID get_id() const = 0; + 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); + +#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; } + // get the ID of the main thread + _FORCE_INLINE_ static ID get_main_id() { return main_thread_id; } static Error set_name(const String &p_name); - _FORCE_INLINE_ static ID get_main_id() { return _main_thread_id; } ///< get the ID of the main thread - static ID get_caller_id(); ///< get the ID of the caller function ID - static void wait_to_finish(Thread *p_thread); ///< waits until thread is finished, and deallocates it. - static Thread *create(ThreadCreateCallback p_callback, void *p_user, const Settings &p_settings = Settings()); ///< Static function to create a thread, will call p_callback - virtual ~Thread() {} + void start(Thread::Callback p_callback, void *p_user, const Settings &p_settings = Settings()); + bool is_started() const; + ///< waits until thread is finished, and deallocates it. + void wait_to_finish(); + + ~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/thread_dummy.cpp b/core/os/thread_dummy.cpp deleted file mode 100644 index 006757b8e4..0000000000 --- a/core/os/thread_dummy.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/*************************************************************************/ -/* thread_dummy.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* 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 "thread_dummy.h" - -#include "core/os/memory.h" - -Thread *ThreadDummy::create(ThreadCreateCallback p_callback, void *p_user, const Thread::Settings &p_settings) { - return memnew(ThreadDummy); -} - -void ThreadDummy::make_default() { - Thread::create_func = &ThreadDummy::create; -} - -RWLock *RWLockDummy::create() { - return memnew(RWLockDummy); -} - -void RWLockDummy::make_default() { - RWLock::create_func = &RWLockDummy::create; -} diff --git a/core/os/thread_dummy.h b/core/os/thread_dummy.h deleted file mode 100644 index 35e19732bf..0000000000 --- a/core/os/thread_dummy.h +++ /dev/null @@ -1,62 +0,0 @@ -/*************************************************************************/ -/* thread_dummy.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* 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. */ -/*************************************************************************/ - -#ifndef THREAD_DUMMY_H -#define THREAD_DUMMY_H - -#include "core/os/rw_lock.h" -#include "core/os/semaphore.h" -#include "core/os/thread.h" - -class ThreadDummy : public Thread { - static Thread *create(ThreadCreateCallback p_callback, void *p_user, const Settings &p_settings = Settings()); - -public: - virtual ID get_id() const { return 0; }; - - static void make_default(); -}; - -class RWLockDummy : public RWLock { - static RWLock *create(); - -public: - virtual void read_lock() {} - virtual void read_unlock() {} - virtual Error read_try_lock() { return OK; } - - virtual void write_lock() {} - virtual void write_unlock() {} - virtual Error write_try_lock() { return OK; } - - static void make_default(); -}; - -#endif // THREAD_DUMMY_H diff --git a/core/os/threaded_array_processor.h b/core/os/threaded_array_processor.h index 57f3de20bf..9538ac5957 100644 --- a/core/os/threaded_array_processor.h +++ b/core/os/threaded_array_processor.h @@ -74,18 +74,17 @@ void thread_process_array(uint32_t p_elements, C *p_instance, M p_method, U p_us data.elements = p_elements; data.process(data.index); //process first, let threads increment for next - Vector<Thread *> threads; + int thread_count = OS::get_singleton()->get_processor_count(); + Thread *threads = memnew_arr(Thread, thread_count); - threads.resize(OS::get_singleton()->get_processor_count()); - - for (int i = 0; i < threads.size(); i++) { - threads.write[i] = Thread::create(process_array_thread<ThreadArrayProcessData<C, U>>, &data); + for (int i = 0; i < thread_count; i++) { + threads[i].start(process_array_thread<ThreadArrayProcessData<C, U>>, &data); } - for (int i = 0; i < threads.size(); i++) { - Thread::wait_to_finish(threads[i]); - memdelete(threads[i]); + for (int i = 0; i < thread_count; i++) { + threads[i].wait_to_finish(); } + memdelete_arr(threads); } #else diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp index 9eef7700f9..b58abc81d1 100644 --- a/core/register_core_types.cpp +++ b/core/register_core_types.cpp @@ -103,7 +103,6 @@ void register_core_types() { static_assert(sizeof(Callable) <= 16); ObjectDB::setup(); - ResourceCache::setup(); StringName::setup(); ResourceLoader::initialize(); diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index 21336a99ec..0b6311dadf 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -1409,8 +1409,9 @@ String String::num(double p_num, int p_decimals) { if (digit == MAX_DIGITS) //no point in going to infinite break; - if ((dec - (double)((int)dec)) < 1e-6) + if (dec - (double)((int)dec) < 1e-6) { break; + } } if (digit == p_decimals) @@ -2096,8 +2097,9 @@ String::String(const StrRange &p_range) { copy_from(p_range.c_str, p_range.len); } -int64_t String::hex_to_int(bool p_with_prefix) const { - if (p_with_prefix && length() < 3) { +int64_t String::hex_to_int() const { + int len = length(); + if (len == 0) { return 0; } @@ -2109,10 +2111,7 @@ int64_t String::hex_to_int(bool p_with_prefix) const { s++; } - if (p_with_prefix) { - if (s[0] != '0' || s[1] != 'x') { - return 0; - } + if (len > 2 && s[0] == '0' && s[1] == 'x') { s += 2; } @@ -2139,8 +2138,9 @@ int64_t String::hex_to_int(bool p_with_prefix) const { return hex * sign; } -int64_t String::bin_to_int(bool p_with_prefix) const { - if (p_with_prefix && length() < 3) { +int64_t String::bin_to_int() const { + int len = length(); + if (len == 0) { return 0; } @@ -2152,10 +2152,7 @@ int64_t String::bin_to_int(bool p_with_prefix) const { s++; } - if (p_with_prefix) { - if (s[0] != '0' || s[1] != 'b') { - return 0; - } + if (len > 2 && s[0] == '0' && s[1] == 'b') { s += 2; } @@ -3074,11 +3071,16 @@ int String::rfindn(const String &p_str, int p_from) const { } bool String::ends_with(const String &p_string) const { + int l = p_string.length(); + if (l == 0) { + return true; + } + int pos = rfind(p_string); if (pos == -1) { return false; } - return pos + p_string.length() == length(); + return pos + l == length(); } bool String::begins_with(const String &p_string) const { @@ -3250,8 +3252,8 @@ float String::similarity(const String &p_string) const { int src_size = src_bigrams.size(); int tgt_size = tgt_bigrams.size(); - double sum = src_size + tgt_size; - double inter = 0; + int sum = src_size + tgt_size; + int inter = 0; for (int i = 0; i < src_size; i++) { for (int j = 0; j < tgt_size; j++) { if (src_bigrams[i] == tgt_bigrams[j]) { @@ -3478,7 +3480,7 @@ String String::right(int p_pos) const { return substr(p_pos, (length() - p_pos)); } -char32_t String::ord_at(int p_idx) const { +char32_t String::unicode_at(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, length(), 0); return operator[](p_idx); } @@ -3750,7 +3752,7 @@ bool String::is_valid_string() const { return valid; } -String String::http_escape() const { +String String::uri_encode() const { const CharString temp = utf8(); String res; for (int i = 0; i < temp.length(); ++i) { @@ -3774,23 +3776,25 @@ String String::http_escape() const { return res; } -String String::http_unescape() const { +String String::uri_decode() const { String res; for (int i = 0; i < length(); ++i) { - if (ord_at(i) == '%' && i + 2 < length()) { - char32_t ord1 = ord_at(i + 1); + if (unicode_at(i) == '%' && i + 2 < length()) { + char32_t ord1 = unicode_at(i + 1); if ((ord1 >= '0' && ord1 <= '9') || (ord1 >= 'A' && ord1 <= 'Z')) { - char32_t ord2 = ord_at(i + 2); + char32_t ord2 = unicode_at(i + 2); if ((ord2 >= '0' && ord2 <= '9') || (ord2 >= 'A' && ord2 <= 'Z')) { char bytes[3] = { (char)ord1, (char)ord2, 0 }; res += (char)strtol(bytes, nullptr, 16); i += 2; } } else { - res += ord_at(i); + res += unicode_at(i); } + } else if (unicode_at(i) == '+') { + res += ' '; } else { - res += ord_at(i); + res += unicode_at(i); } } return String::utf8(res.ascii()); @@ -4245,7 +4249,7 @@ bool String::is_valid_ip_address() const { continue; } if (n.is_valid_hex_number(false)) { - int64_t nint = n.hex_to_int(false); + int64_t nint = n.hex_to_int(); if (nint < 0 || nint > 0xffff) { return false; } @@ -4340,63 +4344,6 @@ String String::plus_file(const String &p_file) const { return *this + "/" + p_file; } -String String::percent_encode() const { - CharString cs = utf8(); - String encoded; - for (int i = 0; i < cs.length(); i++) { - uint8_t c = cs[i]; - if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '-' || c == '_' || c == '~' || c == '.') { - char p[2] = { (char)c, 0 }; - encoded += p; - } else { - char p[4] = { '%', 0, 0, 0 }; - static const char hex[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; - - p[1] = hex[c >> 4]; - p[2] = hex[c & 0xF]; - encoded += p; - } - } - - return encoded; -} - -String String::percent_decode() const { - CharString pe; - - CharString cs = utf8(); - for (int i = 0; i < cs.length(); i++) { - uint8_t c = cs[i]; - if (c == '%' && i < length() - 2) { - uint8_t a = LOWERCASE(cs[i + 1]); - uint8_t b = LOWERCASE(cs[i + 2]); - - if (a >= '0' && a <= '9') { - c = (a - '0') << 4; - } else if (a >= 'a' && a <= 'f') { - c = (a - 'a' + 10) << 4; - } else { - continue; - } - - uint8_t d = 0; - - if (b >= '0' && b <= '9') { - d = (b - '0'); - } else if (b >= 'a' && b <= 'f') { - d = (b - 'a' + 10); - } else { - continue; - } - c += d; - i += 2; - } - pe += c; - } - - return String::utf8(pe.ptr()); -} - String String::property_name_encode() const { // Escape and quote strings with extended ASCII or further Unicode characters // as well as '"', '=' or ' ' (32) diff --git a/core/string/ustring.h b/core/string/ustring.h index 654e327320..821941036f 100644 --- a/core/string/ustring.h +++ b/core/string/ustring.h @@ -318,8 +318,8 @@ public: bool is_numeric() const; double to_float() const; - int64_t hex_to_int(bool p_with_prefix = true) const; - int64_t bin_to_int(bool p_with_prefix = true) const; + int64_t hex_to_int() const; + int64_t bin_to_int() const; int64_t to_int() const; static int64_t to_int(const char *p_str, int p_len = -1); @@ -366,7 +366,7 @@ public: String get_extension() const; String get_basename() const; String plus_file(const String &p_file) const; - char32_t ord_at(int p_idx) const; + char32_t unicode_at(int p_idx) const; void erase(int p_pos, int p_chars); @@ -409,17 +409,14 @@ public: String xml_escape(bool p_escape_quotes = false) const; String xml_unescape() const; - String http_escape() const; - String http_unescape() const; + String uri_encode() const; + String uri_decode() const; String c_escape() const; String c_escape_multiline() const; String c_unescape() const; String json_escape() const; String word_wrap(int p_chars_per_line) const; - String percent_encode() const; - String percent_decode() const; - String property_name_encode() const; bool is_valid_identifier() const; diff --git a/core/templates/local_vector.h b/core/templates/local_vector.h index 4ffb93b2ad..ffd17b7ee9 100644 --- a/core/templates/local_vector.h +++ b/core/templates/local_vector.h @@ -82,6 +82,19 @@ public: } } + /// Removes the item copying the last value into the position of the one to + /// remove. It's generally faster than `remove`. + void remove_unordered(U p_index) { + ERR_FAIL_INDEX(p_index, count); + count--; + if (count > p_index) { + data[p_index] = data[count]; + } + if (!__has_trivial_destructor(T) && !force_trivial) { + data[count].~T(); + } + } + void erase(const T &p_val) { int64_t idx = find(p_val); if (idx >= 0) { @@ -105,6 +118,7 @@ public: } } _FORCE_INLINE_ bool is_empty() const { return count == 0; } + _FORCE_INLINE_ U get_capacity() const { return capacity; } _FORCE_INLINE_ void reserve(U p_size) { p_size = nearest_power_of_2_templated(p_size); if (p_size > capacity) { diff --git a/core/templates/thread_work_pool.cpp b/core/templates/thread_work_pool.cpp index ea784e510c..17969a2c90 100644 --- a/core/templates/thread_work_pool.cpp +++ b/core/templates/thread_work_pool.cpp @@ -32,14 +32,15 @@ #include "core/os/os.h" -void ThreadWorkPool::_thread_function(ThreadData *p_thread) { +void ThreadWorkPool::_thread_function(void *p_user) { + ThreadData *thread = static_cast<ThreadData *>(p_user); while (true) { - p_thread->start.wait(); - if (p_thread->exit.load()) { + thread->start.wait(); + if (thread->exit.load()) { break; } - p_thread->work->work(); - p_thread->completed.post(); + thread->work->work(); + thread->completed.post(); } } @@ -54,7 +55,7 @@ void ThreadWorkPool::init(int p_thread_count) { for (uint32_t i = 0; i < thread_count; i++) { threads[i].exit.store(false); - threads[i].thread = memnew(std::thread(ThreadWorkPool::_thread_function, &threads[i])); + threads[i].thread.start(&ThreadWorkPool::_thread_function, &threads[i]); } } @@ -68,8 +69,7 @@ void ThreadWorkPool::finish() { threads[i].start.post(); } for (uint32_t i = 0; i < thread_count; i++) { - threads[i].thread->join(); - memdelete(threads[i].thread); + threads[i].thread.wait_to_finish(); } memdelete_arr(threads); diff --git a/core/templates/thread_work_pool.h b/core/templates/thread_work_pool.h index 7c3508814f..19ab1dda3a 100644 --- a/core/templates/thread_work_pool.h +++ b/core/templates/thread_work_pool.h @@ -33,9 +33,9 @@ #include "core/os/memory.h" #include "core/os/semaphore.h" +#include "core/os/thread.h" #include <atomic> -#include <thread> class ThreadWorkPool { std::atomic<uint32_t> index; @@ -64,7 +64,7 @@ class ThreadWorkPool { }; struct ThreadData { - std::thread *thread; + Thread thread; Semaphore start; Semaphore completed; std::atomic<bool> exit; @@ -75,7 +75,7 @@ class ThreadWorkPool { uint32_t thread_count = 0; BaseWork *current_work = nullptr; - static void _thread_function(ThreadData *p_thread); + static void _thread_function(void *p_user); public: template <class C, class M, class U> diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index 85e3b29279..2fd8134fbd 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -929,7 +929,7 @@ static void _register_variant_builtin_methods() { bind_method(String, get_extension, sarray(), varray()); bind_method(String, get_basename, sarray(), varray()); bind_method(String, plus_file, sarray("file"), varray()); - bind_method(String, ord_at, sarray("at"), varray()); + bind_method(String, unicode_at, sarray("at"), varray()); bind_method(String, dedent, sarray(), varray()); // FIXME: String needs to be immutable when binding //bind_method(String, erase, sarray("position", "chars"), varray()); @@ -950,13 +950,11 @@ static void _register_variant_builtin_methods() { bind_method(String, get_file, sarray(), varray()); bind_method(String, xml_escape, sarray("escape_quotes"), varray(false)); bind_method(String, xml_unescape, sarray(), varray()); - bind_method(String, http_escape, sarray(), varray()); - bind_method(String, http_unescape, sarray(), varray()); + bind_method(String, uri_encode, sarray(), varray()); + bind_method(String, uri_decode, sarray(), varray()); bind_method(String, c_escape, sarray(), varray()); bind_method(String, c_unescape, sarray(), varray()); bind_method(String, json_escape, sarray(), varray()); - bind_method(String, percent_encode, sarray(), varray()); - bind_method(String, percent_decode, sarray(), varray()); bind_method(String, is_valid_identifier, sarray(), varray()); bind_method(String, is_valid_integer, sarray(), varray()); @@ -968,8 +966,8 @@ static void _register_variant_builtin_methods() { bind_method(String, to_int, sarray(), varray()); bind_method(String, to_float, sarray(), varray()); - bind_method(String, hex_to_int, sarray("with_prefix"), varray(true)); - bind_method(String, bin_to_int, sarray("with_prefix"), varray(true)); + bind_method(String, hex_to_int, sarray(), varray()); + bind_method(String, bin_to_int, sarray(), varray()); bind_method(String, lpad, sarray("min_length", "character"), varray(" ")); bind_method(String, rpad, sarray("min_length", "character"), varray(" ")); @@ -1126,10 +1124,6 @@ static void _register_variant_builtin_methods() { bind_method(Quat, cubic_slerp, sarray("b", "pre_a", "post_b", "weight"), varray()); bind_method(Quat, get_euler, sarray(), varray()); - // FIXME: Quat is atomic, this should be done via construcror - //ADDFUNC1(QUAT, NIL, Quat, set_euler, VECTOR3, "euler", varray()); - //ADDFUNC2(QUAT, NIL, Quat, set_axis_angle, VECTOR3, "axis", FLOAT, "angle", varray()); - /* Color */ bind_method(Color, to_argb32, sarray(), varray()); @@ -1216,7 +1210,7 @@ static void _register_variant_builtin_methods() { bind_method(Basis, transposed, sarray(), varray()); bind_method(Basis, orthonormalized, sarray(), varray()); bind_method(Basis, determinant, sarray(), varray()); - bind_methodv(Basis, rotated, static_cast<Basis (Basis::*)(const Vector3 &, float) const>(&Basis::rotated), sarray("axis", "phi"), varray()); + bind_methodv(Basis, rotated, static_cast<Basis (Basis::*)(const Vector3 &, real_t) const>(&Basis::rotated), sarray("axis", "phi"), varray()); bind_method(Basis, scaled, sarray("scale"), varray()); bind_method(Basis, get_scale, sarray(), varray()); bind_method(Basis, get_euler, sarray(), varray()); diff --git a/core/variant/variant_op.cpp b/core/variant/variant_op.cpp index e9c817bc9f..e0a3cf4215 100644 --- a/core/variant/variant_op.cpp +++ b/core/variant/variant_op.cpp @@ -318,6 +318,7 @@ public: r_valid = true; } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<R>::change(r_ret); *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) & *VariantGetInternalPtr<B>::get_ptr(right); } static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |