diff options
Diffstat (limited to 'core')
99 files changed, 1507 insertions, 608 deletions
diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp index c872ae2162..25dd408dce 100644 --- a/core/config/project_settings.cpp +++ b/core/config/project_settings.cpp @@ -393,7 +393,7 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b if (exec_path != "") { // We do several tests sequentially until one succeeds to find a PCK, - // and if so we attempt loading it at the end. + // and if so, we attempt loading it at the end. // Attempt with PCK bundled into executable. bool found = _load_resource_pack(exec_path); @@ -467,16 +467,17 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b d->change_dir(p_path); String current_dir = d->get_current_dir(); - String candidate = current_dir; bool found = false; Error err; while (true) { + // Set the resource path early so things can be resolved when loading. + resource_path = current_dir; + resource_path = resource_path.replace("\\", "/"); // Windows path to Unix path just in case. err = _load_settings_text_or_binary(current_dir.plus_file("project.godot"), current_dir.plus_file("project.binary")); if (err == OK) { // Optional, we don't mind if it fails. _load_settings_text(current_dir.plus_file("override.cfg")); - candidate = current_dir; found = true; break; } @@ -493,8 +494,6 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b } } - resource_path = candidate; - resource_path = resource_path.replace("\\", "/"); // Windows path to Unix path just in case. memdelete(d); if (!found) { @@ -643,7 +642,6 @@ Error ProjectSettings::_load_settings_text_or_binary(const String &p_text_path, } else if (err != ERR_FILE_NOT_FOUND) { // If the file exists but can't be loaded, we want to know it. ERR_PRINT("Couldn't load file '" + p_bin_path + "', error code " + itos(err) + "."); - return err; } // Fallback to text-based project.godot file if binary was not found. @@ -652,7 +650,6 @@ Error ProjectSettings::_load_settings_text_or_binary(const String &p_text_path, return OK; } else if (err != ERR_FILE_NOT_FOUND) { ERR_PRINT("Couldn't load file '" + p_text_path + "', error code " + itos(err) + "."); - return err; } return err; @@ -909,7 +906,7 @@ Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_cust custom_features += f; } - if (p_path.ends_with(".godot")) { + if (p_path.ends_with(".godot") || p_path.ends_with("override.cfg")) { return _save_settings_text(p_path, props, p_custom, custom_features); } else if (p_path.ends_with(".binary")) { return _save_settings_binary(p_path, props, p_custom, custom_features); diff --git a/core/core_bind.cpp b/core/core_bind.cpp index 47c75cfa28..84d8d0d4d3 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -373,6 +373,9 @@ Dictionary _OS::get_time(bool utc) const { * @return epoch calculated */ int64_t _OS::get_unix_time_from_datetime(Dictionary datetime) const { + // if datetime is an empty Dictionary throws an error + ERR_FAIL_COND_V_MSG(datetime.is_empty(), 0, "Invalid datetime Dictionary: Dictionary is empty"); + // Bunch of conversion constants static const unsigned int SECONDS_PER_MINUTE = 60; static const unsigned int MINUTES_PER_HOUR = 60; @@ -566,7 +569,7 @@ struct _OSCoreBindImg { void _OS::print_all_textures_by_size() { List<_OSCoreBindImg> imgs; - int total = 0; + uint64_t total = 0; { List<Ref<Resource>> rsrc; ResourceCache::get_cached_resources(&rsrc); @@ -1331,7 +1334,7 @@ Vector<uint8_t> _File::get_buffer(int p_length) const { ERR_FAIL_COND_V(len < 0, Vector<uint8_t>()); if (len < p_length) { - data.resize(p_length); + data.resize(len); } return data; @@ -1374,9 +1377,9 @@ Vector<String> _File::get_csv_line(const String &p_delim) const { return f->get_csv_line(p_delim); } -/**< use this for files WRITTEN in _big_ endian machines (ie, amiga/mac) +/**< use this for files WRITTEN in _big_ endian machines (i.e. amiga/mac) * It's not about the current CPU type but file formats. - * this flags get reset to false (little endian) on each open + * These flags get reset to false (little endian) on each open */ void _File::set_endian_swap(bool p_swap) { diff --git a/core/core_constants.cpp b/core/core_constants.cpp index f9edff1899..f40928350a 100644 --- a/core/core_constants.cpp +++ b/core/core_constants.cpp @@ -104,12 +104,12 @@ static Vector<_CoreConstant> _global_constants; #endif -VARIANT_ENUM_CAST(KeyList); +VARIANT_ENUM_CAST(Key); VARIANT_ENUM_CAST(KeyModifierMask); -VARIANT_ENUM_CAST(ButtonList); -VARIANT_ENUM_CAST(JoyButtonList); -VARIANT_ENUM_CAST(JoyAxisList); -VARIANT_ENUM_CAST(MidiMessageList); +VARIANT_ENUM_CAST(MouseButton); +VARIANT_ENUM_CAST(JoyButton); +VARIANT_ENUM_CAST(JoyAxis); +VARIANT_ENUM_CAST(MIDIMessage); void register_global_constants() { BIND_CORE_ENUM_CONSTANT(SIDE_LEFT); @@ -397,20 +397,20 @@ void register_global_constants() { BIND_CORE_ENUM_CONSTANT(KEY_MASK_GROUP_SWITCH); // mouse - BIND_CORE_ENUM_CONSTANT(BUTTON_LEFT); - BIND_CORE_ENUM_CONSTANT(BUTTON_RIGHT); - BIND_CORE_ENUM_CONSTANT(BUTTON_MIDDLE); - BIND_CORE_ENUM_CONSTANT(BUTTON_XBUTTON1); - BIND_CORE_ENUM_CONSTANT(BUTTON_XBUTTON2); - BIND_CORE_ENUM_CONSTANT(BUTTON_WHEEL_UP); - BIND_CORE_ENUM_CONSTANT(BUTTON_WHEEL_DOWN); - BIND_CORE_ENUM_CONSTANT(BUTTON_WHEEL_LEFT); - BIND_CORE_ENUM_CONSTANT(BUTTON_WHEEL_RIGHT); - BIND_CORE_ENUM_CONSTANT(BUTTON_MASK_LEFT); - BIND_CORE_ENUM_CONSTANT(BUTTON_MASK_RIGHT); - BIND_CORE_ENUM_CONSTANT(BUTTON_MASK_MIDDLE); - BIND_CORE_ENUM_CONSTANT(BUTTON_MASK_XBUTTON1); - BIND_CORE_ENUM_CONSTANT(BUTTON_MASK_XBUTTON2); + BIND_CORE_ENUM_CONSTANT(MOUSE_BUTTON_LEFT); + BIND_CORE_ENUM_CONSTANT(MOUSE_BUTTON_RIGHT); + BIND_CORE_ENUM_CONSTANT(MOUSE_BUTTON_MIDDLE); + BIND_CORE_ENUM_CONSTANT(MOUSE_BUTTON_XBUTTON1); + BIND_CORE_ENUM_CONSTANT(MOUSE_BUTTON_XBUTTON2); + BIND_CORE_ENUM_CONSTANT(MOUSE_BUTTON_WHEEL_UP); + BIND_CORE_ENUM_CONSTANT(MOUSE_BUTTON_WHEEL_DOWN); + BIND_CORE_ENUM_CONSTANT(MOUSE_BUTTON_WHEEL_LEFT); + BIND_CORE_ENUM_CONSTANT(MOUSE_BUTTON_WHEEL_RIGHT); + BIND_CORE_ENUM_CONSTANT(MOUSE_BUTTON_MASK_LEFT); + BIND_CORE_ENUM_CONSTANT(MOUSE_BUTTON_MASK_RIGHT); + BIND_CORE_ENUM_CONSTANT(MOUSE_BUTTON_MASK_MIDDLE); + BIND_CORE_ENUM_CONSTANT(MOUSE_BUTTON_MASK_XBUTTON1); + BIND_CORE_ENUM_CONSTANT(MOUSE_BUTTON_MASK_XBUTTON2); // Joypad buttons BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_INVALID); @@ -521,8 +521,10 @@ void register_global_constants() { BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_LAYERS_2D_RENDER); BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_LAYERS_2D_PHYSICS); + BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_LAYERS_2D_NAVIGATION); BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_LAYERS_3D_RENDER); BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_LAYERS_3D_PHYSICS); + BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_LAYERS_3D_NAVIGATION); BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_FILE); BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_DIR); @@ -562,6 +564,7 @@ void register_global_constants() { BIND_CORE_ENUM_CONSTANT(METHOD_FLAG_REVERSE); BIND_CORE_ENUM_CONSTANT(METHOD_FLAG_VIRTUAL); BIND_CORE_ENUM_CONSTANT(METHOD_FLAG_FROM_SCRIPT); + BIND_CORE_ENUM_CONSTANT(METHOD_FLAG_STATIC); BIND_CORE_ENUM_CONSTANT(METHOD_FLAGS_DEFAULT); BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_NIL", Variant::NIL); diff --git a/core/crypto/crypto.cpp b/core/crypto/crypto.cpp index f43f3e3290..fe913549c9 100644 --- a/core/crypto/crypto.cpp +++ b/core/crypto/crypto.cpp @@ -100,7 +100,7 @@ void Crypto::load_default_certificates(String p_path) { PackedByteArray Crypto::hmac_digest(HashingContext::HashType p_hash_type, PackedByteArray p_key, PackedByteArray p_msg) { Ref<HMACContext> ctx = Ref<HMACContext>(HMACContext::create()); - ERR_FAIL_COND_V_MSG(ctx.is_null(), PackedByteArray(), "HMAC is not available witout mbedtls module."); + ERR_FAIL_COND_V_MSG(ctx.is_null(), PackedByteArray(), "HMAC is not available without mbedtls module."); Error err = ctx->start(p_hash_type, p_key); ERR_FAIL_COND_V(err != OK, PackedByteArray()); err = ctx->update(p_msg); @@ -108,7 +108,7 @@ PackedByteArray Crypto::hmac_digest(HashingContext::HashType p_hash_type, Packed return ctx->finish(); } -// Compares two HMACS for equality without leaking timing information in order to prevent timing attakcs. +// Compares two HMACS for equality without leaking timing information in order to prevent timing attacks. // @see: https://paragonie.com/blog/2015/11/preventing-timing-attacks-on-string-comparison-with-double-hmac-strategy bool Crypto::constant_time_compare(PackedByteArray p_trusted, PackedByteArray p_received) { const uint8_t *t = p_trusted.ptr(); @@ -157,8 +157,9 @@ RES ResourceFormatLoaderCrypto::load(const String &p_path, const String &p_origi return key; } else if (el == "pub") { CryptoKey *key = CryptoKey::create(); - if (key) + if (key) { key->load(p_path, true); + } return key; } return nullptr; diff --git a/core/debugger/engine_debugger.cpp b/core/debugger/engine_debugger.cpp index 895b8c23a9..e5dba029c9 100644 --- a/core/debugger/engine_debugger.cpp +++ b/core/debugger/engine_debugger.cpp @@ -192,7 +192,7 @@ void EngineDebugger::deinitialize() { singleton = nullptr; } - // Clear profilers/captuers/protocol handlers. + // Clear profilers/captures/protocol handlers. profilers.clear(); captures.clear(); protocols.clear(); diff --git a/core/debugger/remote_debugger_peer.cpp b/core/debugger/remote_debugger_peer.cpp index 857e3af268..90b0975159 100644 --- a/core/debugger/remote_debugger_peer.cpp +++ b/core/debugger/remote_debugger_peer.cpp @@ -190,13 +190,18 @@ Error RemoteDebuggerPeerTCP::connect_to_host(const String &p_host, uint16_t p_po } void RemoteDebuggerPeerTCP::_thread_func(void *p_ud) { + const uint64_t min_tick = 100; RemoteDebuggerPeerTCP *peer = (RemoteDebuggerPeerTCP *)p_ud; while (peer->running && peer->is_peer_connected()) { + uint64_t ticks_usec = OS::get_singleton()->get_ticks_usec(); peer->_poll(); if (!peer->is_peer_connected()) { break; } - peer->tcp_client->poll(NetSocket::POLL_TYPE_IN_OUT, 1); + ticks_usec = OS::get_singleton()->get_ticks_usec() - ticks_usec; + if (ticks_usec < min_tick) { + OS::get_singleton()->delay_usec(min_tick - ticks_usec); + } } } diff --git a/core/input/gamecontrollerdb.txt b/core/input/gamecontrollerdb.txt index 668a531b1f..884fb9550c 100644 --- a/core/input/gamecontrollerdb.txt +++ b/core/input/gamecontrollerdb.txt @@ -13,10 +13,8 @@ 03000000c82d00002028000000000000,8BitDo N30,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b2,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a2,righty:a5,start:b11,x:b4,y:b3,platform:Windows, 03000000c82d00008010000000000000,8BitDo N30,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftx:a0,lefty:a1,rightshoulder:b7,start:b11,x:b3,y:b4,platform:Windows, 03000000c82d00000190000000000000,8BitDo N30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b2,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a3,righty:a4,start:b11,x:b4,y:b3,platform:Windows, -03000000c82d00001590000000000000,8BitDo N30 Pro 2,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b2,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a3,righty:a4,start:b11,x:b4,y:b3,platform:Windows, +03000000c82d00001590000000000000,8BitDo N30 Pro 2,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b2,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a2,righty:a5,start:b11,x:b4,y:b3,platform:Windows, 03000000c82d00006528000000000000,8BitDo N30 Pro 2,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b2,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a3,righty:a4,start:b11,x:b4,y:b3,platform:Windows, -03000000c82d00015900000000000000,8BitDo N30 Pro 2,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b2,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a2,righty:a5,start:b11,x:b4,y:b3,platform:Windows, -03000000c82d00065280000000000000,8BitDo N30 Pro 2,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b2,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a2,righty:a5,start:b11,x:b4,y:b3,platform:Windows, 03000000022000000090000000000000,8Bitdo NES30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a3,righty:a4,start:b11,x:b4,y:b3,platform:Windows, 03000000203800000900000000000000,8Bitdo NES30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a3,righty:a4,start:b11,x:b4,y:b3,platform:Windows, 03000000c82d00000130000000000000,8BitDo SF30,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b2,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a2,righty:a5,start:b11,x:b4,y:b3,platform:Windows, @@ -40,6 +38,7 @@ 03000000c82d00003032000000000000,8BitDo Zero 2,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftx:a0,lefty:a1,rightshoulder:b7,rightx:a2,righty:a3,start:b11,x:b4,y:b3,platform:Windows, 03000000a00500003232000000000000,8Bitdo Zero GamePad,a:b0,b:b1,back:b10,dpdown:+a2,dpleft:-a0,dpright:+a0,dpup:-a2,leftshoulder:b6,rightshoulder:b7,start:b11,x:b3,y:b4,platform:Windows, 030000008f0e00001200000000000000,Acme GA-02,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b5,leftx:a0,lefty:a1,rightshoulder:b6,rightstick:b11,righttrigger:b7,rightx:a3,righty:a2,start:b9,x:b2,y:b3,platform:Windows, +03000000c01100000355000011010000,ACRUX USB GAME PAD,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Windows, 03000000fa190000f0ff000000000000,Acteck AGJ-3200,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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:Windows, 030000006f0e00001413000000000000,Afterglow,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Windows, 03000000341a00003608000000000000,Afterglow PS3 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Windows, @@ -66,6 +65,7 @@ 03000000808300000300000000000000,Betop Gamepad,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a4,start:b9,x:b3,y:b0,platform:Windows, 030000006b1400000055000000000000,Bigben PS3 Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,platform:Windows, 030000006b1400000103000000000000,Bigben PS3 Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,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:b2,platform:Windows, +03000000120c0000210e000000000000,Brook Mars,a:b1,b:b2,x:b0,y:b3,back:b8,guide:b12,start:b9,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,platform:Windows, 0300000066f700000500000000000000,BrutalLegendTest,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a3,righty:a2,start:b9,x:b0,y:b3,platform:Windows, 03000000d81d00000b00000000000000,BUFFALO BSGP1601 Series ,a:b5,b:b3,back:b12,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b8,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b9,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b13,x:b4,y:b2,platform:Windows, 03000000e82000006058000000000000,Cideko AK08b,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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:Windows, @@ -202,7 +202,7 @@ 03000000efbe0000edfe000000000000,Monect Virtual Controller,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a5,rightx:a3,righty:a4,start:b9,x:b3,y:b0,platform:Windows, 03000000250900006688000000000000,MP-8866 Super Dual Box,a:b2,b:b1,back:b9,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b10,lefttrigger:b4,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b11,righttrigger:b5,rightx:a2,righty:a3,start:b8,x:b3,y:b0,platform:Windows, 030000006b140000010c000000000000,NACON GC-400ES,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,platform:Windows, -030000001008000001e5000000000000,NEXT SNES Controller,a:b2,b:b1,back:b8,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b4,rightshoulder:b6,start:b9,x:b3,y:b0,platform:Windows, +030000001008000001e5000000000000,NEXT SNES Controller,a:b2,b:b1,back:b8,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b4,rightshoulder:b5,righttrigger:b6,start:b9,x:b3,y:b0,platform:Windows, 03000000152000000182000000000000,NGDS,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a3,righty:a4,start:b9,x:b3,y:b0,platform:Windows, 03000000bd12000015d0000000000000,Nintendo Retrolink USB Super SNES Classic Controller,a:b2,b:b1,back:b8,leftshoulder:b4,leftx:a0,lefty:a1,rightshoulder:b5,start:b9,x:b3,y:b0,platform:Windows, 030000007e0500000920000000000000,Nintendo Switch Pro Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,platform:Windows, @@ -290,8 +290,8 @@ 03000000730700000401000000000000,Sanwa PlayOnline Mobile,a:b0,b:b1,back:b2,leftx:a0,lefty:a1,start:b3,platform:Windows, 0300000000050000289b000000000000,Saturn_Adapter_2.0,a:b1,b:b2,leftshoulder:b6,lefttrigger:b4,leftx:a0,lefty:a1,rightshoulder:b7,righttrigger:b5,start:b9,x:b0,y:b3,platform:Windows, 030000009b2800000500000000000000,Saturn_Adapter_2.0,a:b1,b:b2,leftshoulder:b6,lefttrigger:b4,leftx:a0,lefty:a1,rightshoulder:b7,righttrigger:b5,start:b9,x:b0,y:b3,platform:Windows, -03000000a30c00002500000000000000,Sega Genesis Mini 3B controller,a:b2,b:b1,start:b9,dpup:-a4,dpdown:+a4,dpleft:-a3,dpright:+a3,righttrigger:b5,platform:Windows, -03000000a30c00002400000000000000,Sega Mega Drive Mini 6B controller,a:b2,b:b1,start:b9,dpup:-a4,dpdown:+a4,dpleft:-a3,dpright:+a3,rightshoulder:b4,righttrigger:b5,x:b3,y:b0,platform:Windows, +03000000a30c00002500000000000000,Sega Genesis Mini 3B controller,a:b2,b:b1,dpdown:+a4,dpleft:-a3,dpright:+a3,dpup:-a4,righttrigger:b5,start:b9,platform:Windows, +03000000a30c00002400000000000000,Sega Mega Drive Mini 6B controller,a:b2,b:b1,dpdown:+a4,dpleft:-a3,dpright:+a3,dpup:-a4,rightshoulder:b4,righttrigger:b5,start:b9,x:b3,y:b0,platform:Windows, 030000005e0400008e02000000007801,ShanWan PS3/PC Wired GamePad,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Windows, 03000000341a00000208000000000000,SL-6555-SBK,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b8,lefttrigger:-a4,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a4,rightx:a3,righty:a2,start:b7,x:b2,y:b3,platform:Windows, 03000000341a00000908000000000000,SL-6566,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,platform:Windows, @@ -335,7 +335,7 @@ 03000000790000001b18000000000000,Venom Arcade Joystick,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,start:b9,x:b0,y:b3,platform:Windows, 030000006f0e00000302000000000000,Victrix Pro Fight Stick for PS4,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,start:b9,x:b0,y:b3,platform:Windows, 030000006f0e00000702000000000000,Victrix Pro Fight Stick for PS4,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,start:b9,x:b0,y:b3,platform:Windows, -0300000034120000adbe000000000000,vJoy Device,a:b0,b:b1,back:b15,dpdown:b6,dpleft:b7,dpright:b8,dpup:b5,guide:b16,leftshoulder:b9,leftstick:b13,lefttrigger:b11,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b14,righttrigger:b12,rightx:+a3,righty:+a4,start:b4,x:b2,y:b3,platform:Windows, +0300000034120000adbe000000000000,vJoy Device,a:b0,b:b1,back:b15,dpdown:b6,dpleft:b7,dpright:b8,dpup:b5,guide:b16,leftshoulder:b9,leftstick:b13,lefttrigger:b11,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b14,righttrigger:b12,rightx:a3,righty:a4,start:b4,x:b2,y:b3,platform:Windows, 030000005e0400000a0b000000000000,Xbox Adaptive Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b8,lefttrigger:+a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:-a2,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Windows, 030000005e040000ff02000000007801,Xbox One Elite Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Windows, 030000005e040000130b000000000000,Xbox Series Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Windows, @@ -375,6 +375,8 @@ xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2, 03000000c62400001a89000000010000,BDA MOGA XP5-X Plus,a:b0,b:b1,back:b12,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b14,leftshoulder:b6,leftstick:b15,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b16,righttrigger:a4,rightx:a2,righty:a3,start:b13,x:b3,y:b4,platform:Mac OS X, 03000000c62400001b89000000010000,BDA MOGA XP5-X Plus,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,platform:Mac OS X, 03000000d62000002a79000000010000,BDA PS4 Fightpad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Mac OS X, +03000000120c0000200e000000010000,Brook Mars,a:b1,b:b2,x:b0,y:b3,back:b8,guide:b12,start:b9,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a5,lefttrigger:a3,righttrigger:a4,platform:Mac OS X, +03000000120c0000210e000000010000,Brook Mars,a:b1,b:b2,x:b0,y:b3,back:b8,guide:b12,start:b9,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,platform:Mac OS X, 030000008305000031b0000000000000,Cideko AK08b,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Mac OS X, 03000000260900008888000088020000,Cyber Gadget GameCube Controller,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b6,righttrigger:a5,rightx:a2,righty:a3~,start:b7,x:b2,y:b3,platform:Mac OS X, 03000000a306000022f6000001030000,Cyborg V.3 Rumble Pad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:+a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:-a3,rightx:a2,righty:a4,start:b9,x:b0,y:b3,platform:Mac OS X, @@ -383,6 +385,7 @@ xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2, 03000000c01100000140000000010000,GameStop PS4 Fun Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Mac OS X, 030000006f0e00000102000000000000,GameStop Xbox 360 Wired Controller,a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,platform:Mac OS X, 030000007d0400000540000001010000,Gravis Eliminator GamePad Pro,a:b1,b:b2,back:b8,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,start:b9,x:b0,y:b3,platform:Mac OS X, +030000008f0e00000300000007010000,GreenAsia Inc. USB Joystick,a:b2,b:b3,x:b0,y:b1,back:b8,start:b9,leftshoulder:b4,rightshoulder:b6,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a2,lefttrigger:b5,righttrigger:b7,platform:Mac OS X, 030000000d0f00002d00000000100000,Hori Fighting Commander 3 Pro,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Mac OS X, 030000000d0f00005f00000000010000,Hori Fighting Commander 4 (PS3),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Mac OS X, 030000000d0f00005e00000000010000,Hori Fighting Commander 4 (PS4),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Mac OS X, @@ -425,7 +428,7 @@ xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2, 03000000c62400002a89000000010000,MOGA XP5-A Plus,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b21,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,platform:Mac OS X, 03000000c62400002b89000000010000,MOGA XP5-A Plus,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,platform:Mac OS X, 03000000632500007505000000020000,NEOGEO mini PAD Controller,a:b1,b:b0,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,start:b9,x:b2,y:b3,platform:Mac OS X, -030000001008000001e5000006010000,NEXT SNES Controller,a:b2,b:b1,back:b8,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b4,rightshoulder:b6,start:b9,x:b3,y:b0,platform:Mac OS X, +030000001008000001e5000006010000,NEXT SNES Controller,a:b2,b:b1,back:b8,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b4,rightshoulder:b5,righttrigger:b6,start:b9,x:b3,y:b0,platform:Mac OS X, 03000000d620000011a7000000020000,Nintendo Switch Core (Plus) Wired Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Mac OS X, 030000007e0500000920000000000000,Nintendo Switch Pro Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,platform:Mac OS X, 030000007e0500000920000001000000,Nintendo Switch Pro Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,platform:Mac OS X, @@ -460,7 +463,7 @@ xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2, 03000000b40400000a01000000000000,Sega Saturn USB Gamepad,a:b0,b:b1,back:b5,guide:b2,leftshoulder:b6,leftx:a0,lefty:a1,rightshoulder:b7,start:b8,x:b3,y:b4,platform:Mac OS X, 030000003512000021ab000000000000,SFC30 Joystick,a:b1,b:b0,back:b10,leftshoulder:b6,leftx:a0,lefty:a1,rightshoulder:b7,start:b11,x:b4,y:b3,platform:Mac OS X, 0300000000f00000f100000000000000,SNES RetroPort,a:b2,b:b3,back:b4,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b5,rightshoulder:b7,start:b6,x:b0,y:b1,platform:Mac OS X, -030000004c050000e60c000000010000,Sony DualSense,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Mac OS X, +030000004c050000e60c000000010000,Sony DualSense,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Mac OS X, 030000004c050000cc09000000000000,Sony DualShock 4 V2,a:b1,b:b2,back:b13,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Mac OS X, 030000004c050000a00b000000000000,Sony DualShock 4 Wireless Adaptor,a:b1,b:b2,back:b13,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Mac OS X, 03000000d11800000094000000010000,Stadia Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a4,rightx:a2,righty:a3,start:b7,x:b2,y:b3,platform:Mac OS X, @@ -468,6 +471,7 @@ xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2, 03000000110100002014000000000000,SteelSeries Nimbus,a:b0,b:b1,dpdown:b9,dpleft:b11,dpright:b10,dpup:b8,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3,start:b12,x:b2,y:b3,platform:Mac OS X, 03000000110100002014000001000000,SteelSeries Nimbus,a:b0,b:b1,dpdown:b9,dpleft:b11,dpright:b10,dpup:b8,guide:b12,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1~,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3~,x:b2,y:b3,platform:Mac OS X, 03000000381000002014000001000000,SteelSeries Nimbus,a:b0,b:b1,dpdown:b9,dpleft:b11,dpright:b10,dpup:b8,guide:b12,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1~,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3~,x:b2,y:b3,platform:Mac OS X, +050000004e696d6275732b0000000000,SteelSeries Nimbus Plus,a:b0,b:b1,back:b15,dpdown:b11,dpleft:b13,dpright:b12,dpup:b10,guide:b16,leftshoulder:b4,leftstick:b8,lefttrigger:b6,leftx:a0,lefty:a1~,rightshoulder:b5,rightstick:b9,righttrigger:b7,rightx:a2,righty:a3~,start:b14,x:b2,y:b3,platform:Mac OS X, 03000000110100001714000000000000,SteelSeries Stratus XL,a:b0,b:b1,dpdown:b9,dpleft:b11,dpright:b10,dpup:b8,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1~,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3~,start:b12,x:b2,y:b3,platform:Mac OS X, 03000000110100001714000020010000,SteelSeries Stratus XL,a:b0,b:b1,dpdown:b9,dpleft:b11,dpright:b10,dpup:b8,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1~,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3~,start:b12,x:b2,y:b3,platform:Mac OS X, 03000000457500002211000000010000,SZMY-POWER PC Gamepad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Mac OS X, @@ -526,13 +530,14 @@ xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2, 03000000c82d00000260000011010000,8BitDo SN30 Pro+,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a2,righty:a3,start:b11,x:b4,y:b3,platform:Linux, 05000000c82d00000261000000010000,8BitDo SN30 Pro+,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a2,righty:a3,start:b11,x:b4,y:b3,platform:Linux, 05000000202800000900000000010000,8BitDo SNES30 Gamepad,a:b1,b:b0,back:b10,dpdown:b122,dpleft:b119,dpright:b120,dpup:b117,leftshoulder:b6,rightshoulder:b7,start:b11,x:b4,y:b3,platform:Linux, -030000005e0400008e02000020010000,8BitDo Wireless Adapter (XInput),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux, 03000000c82d00000031000011010000,8BitDo Wireless Adapter (DInput),a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b2,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a2,righty:a3,start:b11,x:b3,y:b4,platform:Linux, +030000005e0400008e02000020010000,8BitDo Wireless Adapter (XInput),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux, 03000000c82d00001890000011010000,8BitDo Zero 2,a:b1,b:b0,back:b10,leftshoulder:b6,leftx:a0,lefty:a1,rightshoulder:b7,start:b11,x:b4,y:b3,platform:Linux, -050000005e040000e002000030110000,8BitDo Zero 2 (XInput),a:b0,b:b1,back:b6,leftshoulder:b4,rightshoulder:b5,dpup:-a1,dpdown:+a1,dpleft:-a0,dpright:+a0,start:b7,x:b2,y:b3,platform:Linux, 05000000c82d00003032000000010000,8BitDo Zero 2,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftx:a0,lefty:a1,rightshoulder:b7,rightx:a2,righty:a3,start:b11,x:b4,y:b3,platform:Linux, +050000005e040000e002000030110000,8BitDo Zero 2 (XInput),a:b0,b:b1,back:b6,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b4,rightshoulder:b5,start:b7,x:b2,y:b3,platform:Linux, 05000000a00500003232000001000000,8Bitdo Zero GamePad,a:b0,b:b1,back:b10,leftshoulder:b6,leftx:a0,lefty:a1,rightshoulder:b7,start:b11,x:b3,y:b4,platform:Linux, 05000000a00500003232000008010000,8Bitdo Zero GamePad,a:b0,b:b1,back:b10,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b6,rightshoulder:b7,start:b11,x:b3,y:b4,platform:Linux, +03000000c01100000355000011010000,ACRUX USB GAME PAD,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Linux, 030000006f0e00001302000000010000,Afterglow,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux, 030000006f0e00003901000020060000,Afterglow Controller for Xbox One,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux, 030000006f0e00003901000000430000,Afterglow Prismatic Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux, @@ -550,6 +555,8 @@ xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2, 03000000c31100000791000011010000,Be1 GC101 GAMEPAD 1.03 mode,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,platform:Linux, 030000005e0400008e02000003030000,Be1 GC101 Xbox 360 Controller mode,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux, 03000000666600006706000000010000,boom PSX to PC Converter,a:b2,b:b1,back:b8,dpdown:b14,dpleft:b15,dpright:b13,dpup:b12,leftshoulder:b6,leftstick:b9,lefttrigger:b4,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b10,righttrigger:b5,rightx:a2,righty:a3,start:b11,x:b3,y:b0,platform:Linux, +03000000120c0000200e000011010000,Brook Mars,a:b1,b:b2,x:b0,y:b3,back:b8,guide:b12,start:b9,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a5,lefttrigger:a3,righttrigger:a4,platform:Linux, +03000000120c0000210e000011010000,Brook Mars,a:b1,b:b2,x:b0,y:b3,back:b8,guide:b12,start:b9,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,platform:Linux, 03000000ffff0000ffff000000010000,Chinese-made Xbox Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b5,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b2,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b3,y:b4,platform:Linux, 03000000e82000006058000001010000,Cideko AK08b,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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:Linux, 030000000b0400003365000000010000,Competition Pro,a:b0,b:b1,back:b2,leftx:a0,lefty:a1,start:b3,platform:Linux, @@ -565,6 +572,7 @@ xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2, 030000006f0e00000104000000010000,Gamestop Logic3 Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux, 030000008f0e00000800000010010000,Gasia Co. Ltd PS(R) Gamepad,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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:Linux, 030000006f0e00001304000000010000,Generic X-Box pad,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux, +03000000451300000010000010010000,Genius Maxfire Grandias 12,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,platform:Linux, 03000000f0250000c183000010010000,Goodbetterbest Ltd USB Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Linux, 0300000079000000d418000000010000,GPD Win 2 Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux, 030000007d0400000540000000010000,Gravis Eliminator GamePad Pro,a:b1,b:b2,back:b8,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,start:b9,x:b0,y:b3,platform:Linux, @@ -628,7 +636,7 @@ xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2, 030000006d0400000ac2000010010000,Logitech Inc. WingMan RumblePad,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,lefttrigger:b7,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b2,rightx:a3,righty:a4,x:b3,y:b4,platform:Linux, 030000006d04000018c2000010010000,Logitech RumblePad 2,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Linux, 030000006d04000011c2000010010000,Logitech WingMan Cordless RumblePad,a:b0,b:b1,back:b2,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b5,leftshoulder:b6,lefttrigger:b9,leftx:a0,lefty:a1,rightshoulder:b7,righttrigger:b10,rightx:a3,righty:a4,start:b8,x:b3,y:b4,platform:Linux, -050000004d4f435554452d3035305800,M54-PC,a:b0,b:b1,x:b3,y:b4,back:b10,start:b11,leftshoulder:b6,rightshoulder:b7,leftstick:b13,rightstick:b14,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a5,righttrigger:a4,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,platform:Linux, +050000004d4f435554452d3035305800,M54-PC,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,platform:Linux, 05000000380700006652000025010000,Mad Catz C.T.R.L.R ,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Linux, 03000000380700005032000011010000,Mad Catz FightPad PRO (PS3),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Linux, 03000000380700005082000011010000,Mad Catz FightPad PRO (PS4),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Linux, @@ -673,13 +681,15 @@ xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2, 03000000250900006688000000010000,MP-8866 Super Dual Box,a:b2,b:b1,back:b9,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b10,lefttrigger:b4,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b11,righttrigger:b5,rightx:a2,righty:a3,start:b8,x:b3,y:b0,platform:Linux, 030000006b140000010c000010010000,NACON GC-400ES,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,platform:Linux, 030000000d0f00000900000010010000,Natec Genesis P44,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Linux, -030000001008000001e5000010010000,NEXT SNES Controller,a:b2,b:b1,back:b8,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b4,rightshoulder:b6,start:b9,x:b3,y:b0,platform:Linux, +030000001008000001e5000010010000,NEXT SNES Controller,a:b2,b:b1,back:b8,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b4,rightshoulder:b5,righttrigger:b6,start:b9,x:b3,y:b0,platform:Linux, 060000007e0500000820000000000000,Nintendo Combined Joy-Cons (joycond),a:b0,b:b1,back:b9,dpdown:b15,dpleft:b16,dpright:b17,dpup:b14,guide:b11,leftshoulder:b5,leftstick:b12,lefttrigger:b7,leftx:a0,lefty:a1,rightshoulder:b6,rightstick:b13,righttrigger:b8,rightx:a2,righty:a3,start:b10,x:b3,y:b2,platform:Linux, 030000007e0500003703000000016800,Nintendo GameCube Controller,a:b0,b:b2,dpdown:b6,dpleft:b4,dpright:b5,dpup:b7,lefttrigger:a4,leftx:a0,lefty:a1~,rightshoulder:b9,righttrigger:a5,rightx:a2,righty:a3~,start:b8,x:b1,y:b3,platform:Linux, 03000000790000004618000010010000,Nintendo GameCube Controller Adapter,a:b1,b:b2,dpdown:b14,dpleft:b15,dpright:b13,dpup:b12,lefttrigger:b4,leftx:a0,lefty:a1,rightshoulder:b7,righttrigger:b5,rightx:a5~,righty:a2~,start:b9,x:b0,y:b3,platform:Linux, +050000007e0500000620000001800000,Nintendo Switch Left Joy-Con,a:b9,b:b8,x:b7,y:b10,back:b5,start:b0,leftstick:b6,leftshoulder:b2,rightshoulder:b4,leftx:a1,lefty:a0~,platform:Linux, +050000007e0500000720000001800000,Nintendo Switch Right Joy-Con,a:b1,b:b2,x:b0,y:b3,back:b9,start:b8,leftstick:b10,leftshoulder:b4,rightshoulder:b6,leftx:a1~,lefty:a0~,platform:Linux, 050000007e0500000920000001000000,Nintendo Switch Pro Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,platform:Linux, -050000007e0500000920000001800000,Nintendo Switch Pro Controller (joycond),a:b0,b:b1,back:b9,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b11,leftshoulder:b5,leftstick:b12,lefttrigger:b7,leftx:a0,lefty:a1,rightshoulder:b6,rightstick:b13,righttrigger:b8,rightx:a2,righty:a3,start:b10,x:b3,y:b2,platform:Linux, -030000007e0500000920000011810000,Nintendo Switch Pro Controller Wired (joycond),a:b0,b:b1,back:b9,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b11,leftshoulder:b5,leftstick:b12,lefttrigger:b7,leftx:a0,lefty:a1,rightshoulder:b6,rightstick:b13,righttrigger:b8,rightx:a2,righty:a3,start:b10,x:b3,y:b2,platform:Linux, +050000007e0500000920000001800000,Nintendo Switch Pro Controller,a:b0,b:b1,back:b9,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b11,leftshoulder:b5,leftstick:b12,lefttrigger:b7,leftx:a0,lefty:a1,rightshoulder:b6,rightstick:b13,righttrigger:b8,rightx:a2,righty:a3,start:b10,x:b3,y:b2,platform:Linux, +030000007e0500000920000011810000,Nintendo Switch Pro Controller,a:b0,b:b1,back:b9,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b11,leftshoulder:b5,leftstick:b12,lefttrigger:b7,leftx:a0,lefty:a1,rightshoulder:b6,rightstick:b13,righttrigger:b8,rightx:a2,righty:a3,start:b10,x:b3,y:b2,platform:Linux, 050000007e0500003003000001000000,Nintendo Wii Remote Pro Controller,a:b0,b:b1,back:b8,dpdown:b14,dpleft:b15,dpright:b16,dpup:b13,guide:b10,leftshoulder:b4,leftstick:b11,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b12,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b3,y:b2,platform:Linux, 05000000010000000100000003000000,Nintendo Wiimote,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b11,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b12,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,platform:Linux, 030000000d0500000308000010010000,Nostromo n45 Dual Analog Gamepad,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b9,leftshoulder:b4,leftstick:b12,lefttrigger:b5,leftx:a0,lefty:a1,rightshoulder:b6,rightstick:b11,righttrigger:b7,rightx:a3,righty:a2,start:b10,x:b2,y:b3,platform:Linux, @@ -690,6 +700,7 @@ xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2, 19000000010000000100000001010000,odroidgo2_joypad,a:b1,b:b0,dpdown:b7,dpleft:b8,dpright:b9,dpup:b6,guide:b10,leftshoulder:b4,leftstick:b12,lefttrigger:b11,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b13,righttrigger:b14,start:b15,x:b2,y:b3,platform:Linux, 19000000010000000200000011000000,odroidgo2_joypad_v11,a:b1,b:b0,dpdown:b9,dpleft:b10,dpright:b11,dpup:b8,guide:b12,leftshoulder:b4,leftstick:b14,lefttrigger:b13,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b15,righttrigger:b16,start:b17,x:b2,y:b3,platform:Linux, 030000005e0400000202000000010000,Old Xbox pad,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b5,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b2,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b3,y:b4,platform:Linux, +03000000c0160000dc27000001010000,OnyxSoft Dual JoyDivision,a:b0,b:b1,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b4,rightshoulder:b5,start:b6,x:b2,y:b3,platform:Linux, 05000000362800000100000002010000,OUYA Game Controller,a:b0,b:b3,dpdown:b9,dpleft:b10,dpright:b11,dpup:b8,guide:b14,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,x:b1,y:b2,platform:Linux, 05000000362800000100000003010000,OUYA Game Controller,a:b0,b:b3,dpdown:b9,dpleft:b10,dpright:b11,dpup:b8,guide:b14,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,x:b1,y:b2,platform:Linux, 03000000830500005020000010010000,Padix Co. Ltd. Rockfire PSX/USB Bridge,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b8,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:b7,rightx:a2,righty:a3,start:b11,x:b2,y:b3,platform:Linux, @@ -705,13 +716,15 @@ xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2, 030000006f0e00000901000011010000,PDP Versus Fighting Pad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,start:b9,x:b0,y:b3,platform:Linux, 030000006f0e0000a802000023020000,PDP Wired Controller for Xbox One,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b11,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b12,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,platform:Linux, 030000006f0e00008501000011010000,PDP Wired Fight Pad Pro for Nintendo Switch,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,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:Linux, -05000000491900000204000000000000,PG-9118,x:b76,a:b73,b:b74,y:b77,back:b83,start:b84,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b79,lefttrigger:b81,rightshoulder:b80,righttrigger:b82,leftstick:b86,rightstick:b87,leftx:a0,lefty:a1,rightx:a2,righty:a3,platform:Linux, 0500000049190000030400001b010000,PG-9099,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a2,righty:a3,start:b11,x:b3,y:b4,platform:Linux, +05000000491900000204000000000000,PG-9118,a:b73,b:b74,back:b83,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b79,leftstick:b86,lefttrigger:b81,leftx:a0,lefty:a1,rightshoulder:b80,rightstick:b87,righttrigger:b82,rightx:a2,righty:a3,start:b84,x:b76,y:b77,platform:Linux, 030000004c050000da0c000011010000,Playstation Controller,a:b2,b:b1,back:b8,leftshoulder:b6,lefttrigger:b4,leftx:a0,lefty:a1,rightshoulder:b7,righttrigger:b5,start:b9,x:b3,y:b0,platform:Linux, 03000000c62400000053000000010000,PowerA,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux, 03000000c62400003a54000001010000,PowerA 1428124-01,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux, 03000000d62000006dca000011010000,PowerA Pro Ex,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Linux, +03000000d62000000228000001010000,PowerA Wired Controller for Xbox One,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux, 03000000c62400001a58000001010000,PowerA Xbox One Cabled,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux, +03000000c62400001a54000001010000,PowerA Xbox One Mini Wired Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux, 030000006d040000d2ca000011010000,Precision Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Linux, 03000000ff1100004133000010010000,PS2 Controller,a:b2,b:b1,back:b8,leftshoulder:b6,lefttrigger:b4,leftx:a0,lefty:a1,rightshoulder:b7,righttrigger:b5,start:b9,x:b3,y:b0,platform:Linux, 03000000341a00003608000011010000,PS3 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Linux, @@ -783,8 +796,13 @@ xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2, 03000000f025000021c1000010010000,ShanWan Gioteck PS3 Wired Controller,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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:Linux, 03000000632500007505000010010000,SHANWAN PS3/PC Gamepad,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,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:Linux, 03000000bc2000000055000010010000,ShanWan PS3/PC Wired GamePad,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,platform:Linux, +030000005f140000c501000010010000,SHANWAN Trust Gamepad,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,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:Linux, 03000000632500002305000010010000,ShanWan USB Gamepad,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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:Linux, 03000000341a00000908000010010000,SL-6566,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,platform:Linux, +030000004c050000e60c000011810000,Sony DualSense,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b11,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b12,righttrigger:a5,rightx:a3,righty:a4,start:b9,x:b3,y:b2,platform:Linux, +030000004c050000e60c000000006800,Sony DualSense,a:b0,b:b1,x:b2,y:b3,back:b4,guide:b5,start:b6,leftstick:b7,rightstick:b8,leftshoulder:b9,rightshoulder:b10,dpup:b11,dpdown:b12,dpleft:b13,dpright:b14,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,platform:Linux, +050000004c050000e60c000000810000,Sony DualSense ,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b11,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b12,righttrigger:a5,rightx:a3,righty:a4,start:b9,x:b3,y:b2,platform:Linux, +030000004c050000e60c000000016800,Sony DualSense ,a:b0,b:b1,x:b2,y:b3,back:b4,guide:b5,start:b6,leftstick:b7,rightstick:b8,leftshoulder:b9,rightshoulder:b10,dpup:b11,dpdown:b12,dpleft:b13,dpright:b14,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,platform:Linux, 03000000250900000500000000010000,Sony PS2 pad with SmartJoy adapter,a:b2,b:b1,back:b9,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b10,lefttrigger:b4,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b11,righttrigger:b5,rightx:a2,righty:a3,start:b8,x:b3,y:b0,platform:Linux, 030000005e0400008e02000073050000,Speedlink TORID Wireless Gamepad,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux, 030000005e0400008e02000020200000,SpeedLink XEOX Pro Analog Gamepad pad,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux, @@ -792,8 +810,8 @@ xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2, 03000000de2800000112000001000000,Steam Controller,a:b0,b:b1,back:b6,dpdown:b14,dpleft:b15,dpright:b13,dpup:b12,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,paddle1:b11,paddle2:b10,rightshoulder:b5,righttrigger:a3,start:b7,x:b2,y:b3,platform:Linux, 03000000de2800000211000001000000,Steam Controller,a:b0,b:b1,back:b6,dpdown:b14,dpleft:b15,dpright:b13,dpup:b12,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,paddle1:b11,paddle2:b10,rightshoulder:b5,righttrigger:a3,start:b7,x:b2,y:b3,platform:Linux, 03000000de2800004211000001000000,Steam Controller,a:b0,b:b1,back:b6,dpdown:b14,dpleft:b15,dpright:b13,dpup:b12,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,paddle1:b11,paddle2:b10,rightshoulder:b5,righttrigger:a3,start:b7,x:b2,y:b3,platform:Linux, -03000000de2800004211000001000000,Steam Controller,a:b0,b:b1,back:b6,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:a3,start:b7,x:b2,y:b3,platform:Linux, -03000000de2800004211000011010000,Steam Controller,a:b2,b:b3,back:b10,dpdown:b18,dpleft:b19,dpright:b20,dpup:b17,guide:b12,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,righttrigger:b9,rightx:a2,righty:a3,start:b11,x:b4,y:b5,platform:Linux, +03000000de2800000211000011010000,Steam Controller,a:b2,b:b3,back:b10,dpdown:b18,dpleft:b19,dpright:b20,dpup:b17,guide:b12,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,paddle1:b15,paddle2:b16,rightshoulder:b7,righttrigger:b9,rightx:a2,righty:a3,start:b11,x:b4,y:b5,platform:Linux, +03000000de2800004211000011010000,Steam Controller,a:b2,b:b3,back:b10,dpdown:b18,dpleft:b19,dpright:b20,dpup:b17,guide:b12,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,paddle1:b15,paddle2:b16,rightshoulder:b7,righttrigger:b9,rightx:a2,righty:a3,start:b11,x:b4,y:b5,platform:Linux, 03000000de280000fc11000001000000,Steam Controller,a:b0,b:b1,back:b6,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux, 05000000de2800000212000001000000,Steam Controller,a:b0,b:b1,back:b6,dpdown:b14,dpleft:b15,dpright:b13,dpup:b12,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,paddle1:b11,paddle2:b10,rightshoulder:b5,righttrigger:a3,start:b7,x:b2,y:b3,platform:Linux, 05000000de2800000511000001000000,Steam Controller,a:b0,b:b1,back:b6,dpdown:b14,dpleft:b15,dpright:b13,dpup:b12,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,paddle1:b11,paddle2:b10,rightshoulder:b5,righttrigger:a3,start:b7,x:b2,y:b3,platform:Linux, @@ -809,7 +827,7 @@ xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2, 0300000000f00000f100000000010000,Super RetroPort,a:b1,b:b5,back:b2,leftshoulder:b6,leftx:a0,lefty:a1,rightshoulder:b7,start:b3,x:b0,y:b4,platform:Linux, 03000000457500002211000010010000,SZMY-POWER CO. LTD. GAMEPAD,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,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:Linux, 030000008f0e00000d31000010010000,SZMY-POWER CO. LTD. GAMEPAD 3 TURBO,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Linux, -030000008f0e00001431000010010000,SZMY-POWER CO. LTD. PS3 gamepad,a:b1,b:b2,x:b0,y:b3,back:b8,guide:b12,start:b9,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,platform:Linux, +030000008f0e00001431000010010000,SZMY-POWER CO. LTD. PS3 gamepad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Linux, 030000004f04000020b3000010010000,Thrustmaster 2 in 1 DT,a:b0,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b5,leftx:a0,lefty:a1,rightshoulder:b6,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b1,y:b3,platform:Linux, 030000004f04000015b3000010010000,Thrustmaster Dual Analog 4,a:b0,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b5,leftx:a0,lefty:a1,rightshoulder:b6,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b1,y:b3,platform:Linux, 030000004f04000023b3000000010000,Thrustmaster Dual Trigger 3-in-1,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Linux, @@ -864,7 +882,6 @@ xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2, xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux, 03000000120c0000100e000011010000,ZEROPLUS P4 Gamepad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Linux, 03000000120c0000101e000011010000,ZEROPLUS P4 Wired Gamepad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Linux, -03000000c0160000dc27000001010000,OnyxSoft Dual JoyDivision,platform:Linux,a:b0,b:b1,x:b2,y:b3,start:b6,leftshoulder:b4,rightshoulder:b5,dpup:-a1,dpdown:+a1,dpleft:-a0,dpright:+a0, # Android 05000000c82d000006500000ffff3f00,8BitDo M30 Gamepad,a:b1,b:b0,back:b4,guide:b17,leftshoulder:b9,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b10,righttrigger:a4,start:b6,x:b3,y:b2,platform:Android, @@ -883,12 +900,13 @@ xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2, 050000003512000020ab000000780f00,8BitDo SNES30 Gamepad,a:b21,b:b20,back:b30,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b26,rightshoulder:b27,start:b31,x:b24,y:b23,platform:Android, 05000000c82d000018900000ffff0f00,8BitDo Zero 2,a:b1,b:b0,back:b4,leftshoulder:b9,leftx:a0,lefty:a1,rightshoulder:b10,start:b6,x:b3,y:b2,platform:Android, 05000000c82d000030320000ffff0f00,8BitDo Zero 2,a:b1,b:b0,back:b4,leftshoulder:b9,leftx:a0,lefty:a1,rightshoulder:b10,start:b6,x:b3,y:b2,platform:Android, +38383337343564366131323064613561,Brook Mars,a:b1,b:b19,x:b0,y:b2,leftshoulder:b3,rightshoulder:b20,lefttrigger:b9,righttrigger:b10,back:b17,start:b18,leftx:a0,lefty:a1,rightx:a2,righty:a3,leftstick:b15,rightstick:b6,platform:Android, 05000000bc20000000550000ffff3f00,GameSir G3w,a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,leftshoulder:b9,leftstick:b7,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a4,rightx:a2,righty:a3,start:b6,x:b2,y:b3,platform:Android, 05000000d6020000e5890000dfff3f00,GPD XD Plus,a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,leftshoulder:b9,leftstick:b7,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a4,rightx:a2,righty:a5,start:b6,x:b2,y:b3,platform:Android, 0500000031366332860c44aadfff0f00,GS Gamepad,a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,leftshoulder:b9,leftstick:b7,lefttrigger:b15,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:b16,rightx:a2,righty:a3,start:b6,x:b2,y:b3,platform:Android, 0500000083050000602000000ffe0000,iBuffalo SNES Controller,a:b1,b:b0,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,leftshoulder:b15,rightshoulder:b16,start:b10,x:b3,y:b2,platform:Android, 64633436313965656664373634323364,Microsoft X-Box 360 pad,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,x:b2,y:b3,platform:Android, -7573622067616d657061642020202020,NEXT SNES Controller,a:b2,b:b1,back:b8,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b4,rightshoulder:b6,start:b9,x:b3,y:b0,platform:Android, +7573622067616d657061642020202020,NEXT SNES Controller,a:b2,b:b1,back:b8,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b4,rightshoulder:b5,righttrigger:b6,start:b9,x:b3,y:b0,platform:Android, 050000007e05000009200000ffff0f00,Nintendo Switch Pro Controller,a:b0,b:b1,back:b15,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b3,leftstick:b4,lefttrigger:b9,leftx:a0,lefty:a1,rightshoulder:b18,rightstick:b6,righttrigger:b10,rightx:a2,righty:a3,start:b16,x:b17,y:b2,platform:Android, 37336435666338653565313731303834,NVIDIA Controller,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,platform:Android, 4e564944494120436f72706f72617469,NVIDIA Controller,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,platform:Android, @@ -936,8 +954,8 @@ xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2, 4d466947616d65706164020000000000,MFi Gamepad,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,rightshoulder:b5,start:b6,x:b2,y:b3,platform:iOS, 050000004c050000cc090000df070000,PS4 Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b9,x:b2,y:b3,platform:iOS, 050000004c050000cc090000ff070000,PS4 Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b9,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b10,x:b2,y:b3,platform:iOS, -050000004c050000cc090000ff876d01,PS4 Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b9,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,misc1:b11,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b10,x:b2,y:b3,,platform:iOS, 050000004c050000cc090000ff870001,PS4 Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b9,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b10,touchpad:b11,x:b2,y:b3,platform:iOS, +050000004c050000cc090000ff876d01,PS4 Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b9,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,misc1:b11,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b10,x:b2,y:b3,platform:iOS, 05000000ac0500000300000000006d03,Remote,a:b0,b:b2,leftx:a0,lefty:a1,platform:iOS, 05000000ac0500000300000043006d03,Remote,a:b0,b:b2,leftx:a0,lefty:a1,platform:iOS, 05000000de2800000511000001000000,Steam Controller,a:b0,b:b1,back:b6,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:a3,start:b7,x:b2,y:b3,platform:iOS, diff --git a/core/input/godotcontrollerdb.txt b/core/input/godotcontrollerdb.txt index c43cd6c8ac..db612f04d2 100644 --- a/core/input/godotcontrollerdb.txt +++ b/core/input/godotcontrollerdb.txt @@ -28,6 +28,7 @@ MacOSX05832060,iBuffalo BSGP801,a:b1,b:b0,y:b2,x:b3,start:b7,back:b6,leftshoulde Linux0e8f3013,HuiJia USB GamePad,a:b2,b:b1,y:b0,x:b3,start:b9,back:b8,leftshoulder:b6,rightshoulder:b7,dpup:-a1,dpleft:-a0,dpdown:+a1,dpright:+a0,platform:Javascript Windows0e8f3013,HuiJia USB GamePad,a:b2,b:b1,y:b0,x:b3,start:b9,back:b8,leftshoulder:b6,rightshoulder:b7,dpup:-a1,dpleft:-a0,dpdown:+a1,dpright:+a0,platform:Javascript MacOSX0e8f3013,HuiJia USB GamePad,a:b2,b:b1,y:b0,x:b3,start:b9,back:b8,leftshoulder:b6,rightshoulder:b7,dpup:-a4,dpleft:-a3,dpdown:+a4,dpright:+a3,platform:Javascript +Linux046dc216,046d-c216-Logitech Logitech Dual Action,a:b1,b:b2,y:b3,x:b0,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:-a5,dpleft:-a4,dpdown:+a5,dpright:+a4,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,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 f928ae7654..2304c05bf8 100644 --- a/core/input/input.cpp +++ b/core/input/input.cpp @@ -560,11 +560,11 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em button_event->set_position(st->get_position()); button_event->set_global_position(st->get_position()); button_event->set_pressed(st->is_pressed()); - button_event->set_button_index(BUTTON_LEFT); + button_event->set_button_index(MOUSE_BUTTON_LEFT); if (st->is_pressed()) { - button_event->set_button_mask(mouse_button_mask | (1 << (BUTTON_LEFT - 1))); + button_event->set_button_mask(mouse_button_mask | (1 << (MOUSE_BUTTON_LEFT - 1))); } else { - button_event->set_button_mask(mouse_button_mask & ~(1 << (BUTTON_LEFT - 1))); + button_event->set_button_mask(mouse_button_mask & ~(1 << (MOUSE_BUTTON_LEFT - 1))); } _parse_input_event_impl(button_event, true); @@ -723,7 +723,7 @@ void Input::warp_mouse_position(const Vector2 &p_to) { Point2i Input::warp_mouse_motion(const Ref<InputEventMouseMotion> &p_motion, const Rect2 &p_rect) { // The relative distance reported for the next event after a warp is in the boundaries of the - // size of the rect on that axis, but it may be greater, in which case there's not problem as fmod() + // size of the rect on that axis, but it may be greater, in which case there's no problem as fmod() // will warp it, but if the pointer has moved in the opposite direction between the pointer relocation // and the subsequent event, the reported relative distance will be less than the size of the rect // and thus fmod() will be disabled for handling the situation. @@ -779,7 +779,7 @@ bool Input::is_emulating_touch_from_mouse() const { return emulate_touch_from_mouse; } -// Calling this whenever the game window is focused helps unstucking the "touch mouse" +// Calling this whenever the game window is focused helps unsticking the "touch mouse" // if the OS or its abstraction class hasn't properly reported that touch pointers raised void Input::ensure_touch_mouse_raised() { if (mouse_from_touch_index != -1) { @@ -792,8 +792,8 @@ void Input::ensure_touch_mouse_raised() { button_event->set_position(mouse_pos); button_event->set_global_position(mouse_pos); button_event->set_pressed(false); - button_event->set_button_index(BUTTON_LEFT); - button_event->set_button_mask(mouse_button_mask & ~(1 << (BUTTON_LEFT - 1))); + button_event->set_button_index(MOUSE_BUTTON_LEFT); + button_event->set_button_mask(mouse_button_mask & ~(1 << (MOUSE_BUTTON_LEFT - 1))); _parse_input_event_impl(button_event, true); } @@ -907,7 +907,7 @@ void Input::joy_button(int p_device, int p_button, bool p_pressed) { // no event? } -void Input::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) { +void Input::joy_axis(int p_device, int p_axis, const JoyAxisValue &p_value) { _THREAD_SAFE_METHOD_; ERR_FAIL_INDEX(p_axis, JOY_AXIS_MAX); @@ -921,12 +921,12 @@ void Input::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) { //when changing direction quickly, insert fake event to release pending inputmap actions float last = joy.last_axis[p_axis]; if (p_value.min == 0 && (last < 0.25 || last > 0.75) && (last - 0.5) * (p_value.value - 0.5) < 0) { - JoyAxis jx; + JoyAxisValue jx; 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) { - JoyAxis jx; + JoyAxisValue jx; jx.min = p_value.min; jx.value = last > 0 ? 0.1 : -0.1; joy_axis(p_device, p_axis, jx); @@ -1206,22 +1206,22 @@ void Input::_get_mapped_hat_events(const JoyDeviceMapping &mapping, int p_hat, J } } -JoyButtonList Input::_get_output_button(String output) { +JoyButton Input::_get_output_button(String output) { for (int i = 0; i < JOY_BUTTON_SDL_MAX; i++) { if (output == _joy_buttons[i]) { - return JoyButtonList(i); + return JoyButton(i); } } - return JoyButtonList::JOY_BUTTON_INVALID; + return JoyButton::JOY_BUTTON_INVALID; } -JoyAxisList Input::_get_output_axis(String output) { +JoyAxis Input::_get_output_axis(String output) { for (int i = 0; i < JOY_AXIS_SDL_MAX; i++) { if (output == _joy_axes[i]) { - return JoyAxisList(i); + return JoyAxis(i); } } - return JoyAxisList::JOY_AXIS_INVALID; + return JoyAxis::JOY_AXIS_INVALID; } void Input::parse_mapping(String p_mapping) { @@ -1279,8 +1279,8 @@ void Input::parse_mapping(String p_mapping) { input = input.left(input.length() - 1); } - JoyButtonList output_button = _get_output_button(output); - JoyAxisList output_axis = _get_output_axis(output); + JoyButton output_button = _get_output_button(output); + JoyAxis output_axis = _get_output_axis(output); ERR_CONTINUE_MSG(output_button == JOY_BUTTON_INVALID && output_axis == JOY_AXIS_INVALID, String(entry[idx] + "\nUnrecognised output string: " + output)); ERR_CONTINUE_MSG(output_button != JOY_BUTTON_INVALID && output_axis != JOY_AXIS_INVALID, @@ -1329,9 +1329,10 @@ void Input::add_joy_mapping(String p_mapping, bool p_update_existing) { if (p_update_existing) { Vector<String> entry = p_mapping.split(","); String uid = entry[0]; - for (int i = 0; i < joy_names.size(); i++) { - if (uid == joy_names[i].uid) { - joy_names[i].mapping = map_db.size() - 1; + for (Map<int, Joypad>::Element *E = joy_names.front(); E; E = E->next()) { + Joypad &joy = E->get(); + if (joy.uid == uid) { + joy.mapping = map_db.size() - 1; } } } @@ -1343,9 +1344,10 @@ void Input::remove_joy_mapping(String p_guid) { map_db.remove(i); } } - for (int i = 0; i < joy_names.size(); i++) { - if (joy_names[i].uid == p_guid) { - joy_names[i].mapping = -1; + for (Map<int, Joypad>::Element *E = joy_names.front(); E; E = E->next()) { + Joypad &joy = E->get(); + if (joy.uid == p_guid) { + joy.mapping = -1; } } } @@ -1361,8 +1363,13 @@ void Input::set_fallback_mapping(String p_guid) { //platforms that use the remapping system can override and call to these ones bool Input::is_joy_known(int p_device) { - int mapping = joy_names[p_device].mapping; - return mapping != -1 ? (mapping != fallback_mapping) : false; + if (joy_names.has(p_device)) { + int mapping = joy_names[p_device].mapping; + if (mapping != -1 && mapping != fallback_mapping) { + return true; + } + } + return false; } String Input::get_joy_guid(int p_device) const { diff --git a/core/input/input.h b/core/input/input.h index 0e3af42381..99b45db325 100644 --- a/core/input/input.h +++ b/core/input/input.h @@ -91,7 +91,7 @@ public: JOYPADS_MAX = 16, }; - struct JoyAxis { + struct JoyAxisValue { int min; float value; }; @@ -199,10 +199,10 @@ private: JoyType outputType; union { - JoyButtonList button; + JoyButton button; struct { - JoyAxisList axis; + JoyAxis axis; JoyAxisRange range; } axis; @@ -220,8 +220,8 @@ private: JoyEvent _get_mapped_button_event(const JoyDeviceMapping &mapping, int p_button); JoyEvent _get_mapped_axis_event(const JoyDeviceMapping &mapping, int p_axis, float p_value); void _get_mapped_hat_events(const JoyDeviceMapping &mapping, int p_hat, JoyEvent r_events[HAT_MAX]); - JoyButtonList _get_output_button(String output); - JoyAxisList _get_output_axis(String output); + JoyButton _get_output_button(String output); + JoyAxis _get_output_axis(String output); void _button_event(int p_device, int p_index, bool p_pressed); void _axis_event(int p_device, int p_axis, float p_value); @@ -325,7 +325,7 @@ public: void parse_mapping(String p_mapping); void joy_button(int p_device, int p_button, bool p_pressed); - void joy_axis(int p_device, int p_axis, const JoyAxis &p_value); + void joy_axis(int p_device, int p_axis, const JoyAxisValue &p_value); void joy_hat(int p_device, int p_val); void add_joy_mapping(String p_mapping, bool p_update_existing = false); diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp index c6910d2b1f..99cc51b95e 100644 --- a/core/input/input_event.cpp +++ b/core/input/input_event.cpp @@ -619,15 +619,15 @@ String InputEventMouseButton::as_text() const { // Button int idx = get_button_index(); switch (idx) { - case BUTTON_LEFT: - case BUTTON_RIGHT: - case BUTTON_MIDDLE: - case BUTTON_WHEEL_UP: - case BUTTON_WHEEL_DOWN: - case BUTTON_WHEEL_LEFT: - case BUTTON_WHEEL_RIGHT: - case BUTTON_XBUTTON1: - case BUTTON_XBUTTON2: + case MOUSE_BUTTON_LEFT: + case MOUSE_BUTTON_RIGHT: + case MOUSE_BUTTON_MIDDLE: + case MOUSE_BUTTON_WHEEL_UP: + case MOUSE_BUTTON_WHEEL_DOWN: + case MOUSE_BUTTON_WHEEL_LEFT: + case MOUSE_BUTTON_WHEEL_RIGHT: + case MOUSE_BUTTON_XBUTTON1: + case MOUSE_BUTTON_XBUTTON2: full_string += RTR(_mouse_button_descriptions[idx - 1]); // button index starts from 1, array index starts from 0, so subtract 1 break; default: @@ -651,15 +651,15 @@ String InputEventMouseButton::to_string() { String button_string = itos(idx); switch (idx) { - case BUTTON_LEFT: - case BUTTON_RIGHT: - case BUTTON_MIDDLE: - case BUTTON_WHEEL_UP: - case BUTTON_WHEEL_DOWN: - case BUTTON_WHEEL_LEFT: - case BUTTON_WHEEL_RIGHT: - case BUTTON_XBUTTON1: - case BUTTON_XBUTTON2: + case MOUSE_BUTTON_LEFT: + case MOUSE_BUTTON_RIGHT: + case MOUSE_BUTTON_MIDDLE: + case MOUSE_BUTTON_WHEEL_UP: + case MOUSE_BUTTON_WHEEL_DOWN: + case MOUSE_BUTTON_WHEEL_LEFT: + case MOUSE_BUTTON_WHEEL_RIGHT: + case MOUSE_BUTTON_XBUTTON1: + case MOUSE_BUTTON_XBUTTON2: button_string += " (" + RTR(_mouse_button_descriptions[idx - 1]) + ")"; // button index starts from 1, array index starts from 0, so subtract 1 break; default: @@ -761,20 +761,20 @@ String InputEventMouseMotion::to_string() { int button_mask = get_button_mask(); String button_mask_string = itos(button_mask); switch (get_button_mask()) { - case BUTTON_MASK_LEFT: - button_mask_string += " (" + RTR(_mouse_button_descriptions[BUTTON_LEFT - 1]) + ")"; + case MOUSE_BUTTON_MASK_LEFT: + button_mask_string += " (" + RTR(_mouse_button_descriptions[MOUSE_BUTTON_LEFT - 1]) + ")"; break; - case BUTTON_MASK_MIDDLE: - button_mask_string += " (" + RTR(_mouse_button_descriptions[BUTTON_MIDDLE - 1]) + ")"; + case MOUSE_BUTTON_MASK_MIDDLE: + button_mask_string += " (" + RTR(_mouse_button_descriptions[MOUSE_BUTTON_MIDDLE - 1]) + ")"; break; - case BUTTON_MASK_RIGHT: - button_mask_string += " (" + RTR(_mouse_button_descriptions[BUTTON_RIGHT - 1]) + ")"; + case MOUSE_BUTTON_MASK_RIGHT: + button_mask_string += " (" + RTR(_mouse_button_descriptions[MOUSE_BUTTON_RIGHT - 1]) + ")"; break; - case BUTTON_MASK_XBUTTON1: - button_mask_string += " (" + RTR(_mouse_button_descriptions[BUTTON_XBUTTON1 - 1]) + ")"; + case MOUSE_BUTTON_MASK_XBUTTON1: + button_mask_string += " (" + RTR(_mouse_button_descriptions[MOUSE_BUTTON_XBUTTON1 - 1]) + ")"; break; - case BUTTON_MASK_XBUTTON2: - button_mask_string += " (" + RTR(_mouse_button_descriptions[BUTTON_XBUTTON2 - 1]) + ")"; + case MOUSE_BUTTON_MASK_XBUTTON2: + button_mask_string += " (" + RTR(_mouse_button_descriptions[MOUSE_BUTTON_XBUTTON2 - 1]) + ")"; break; default: break; diff --git a/core/input/input_event.h b/core/input/input_event.h index df81b9fc75..94aa68db33 100644 --- a/core/input/input_event.h +++ b/core/input/input_event.h @@ -33,7 +33,6 @@ #include "core/io/resource.h" #include "core/math/transform_2d.h" -#include "core/os/copymem.h" #include "core/string/ustring.h" #include "core/typedefs.h" @@ -42,24 +41,24 @@ * The events are pretty obvious. */ -enum ButtonList { - BUTTON_LEFT = 1, - BUTTON_RIGHT = 2, - BUTTON_MIDDLE = 3, - BUTTON_WHEEL_UP = 4, - BUTTON_WHEEL_DOWN = 5, - BUTTON_WHEEL_LEFT = 6, - BUTTON_WHEEL_RIGHT = 7, - BUTTON_XBUTTON1 = 8, - BUTTON_XBUTTON2 = 9, - BUTTON_MASK_LEFT = (1 << (BUTTON_LEFT - 1)), - BUTTON_MASK_RIGHT = (1 << (BUTTON_RIGHT - 1)), - BUTTON_MASK_MIDDLE = (1 << (BUTTON_MIDDLE - 1)), - BUTTON_MASK_XBUTTON1 = (1 << (BUTTON_XBUTTON1 - 1)), - BUTTON_MASK_XBUTTON2 = (1 << (BUTTON_XBUTTON2 - 1)) +enum MouseButton { + MOUSE_BUTTON_LEFT = 1, + MOUSE_BUTTON_RIGHT = 2, + MOUSE_BUTTON_MIDDLE = 3, + MOUSE_BUTTON_WHEEL_UP = 4, + MOUSE_BUTTON_WHEEL_DOWN = 5, + MOUSE_BUTTON_WHEEL_LEFT = 6, + MOUSE_BUTTON_WHEEL_RIGHT = 7, + MOUSE_BUTTON_XBUTTON1 = 8, + MOUSE_BUTTON_XBUTTON2 = 9, + MOUSE_BUTTON_MASK_LEFT = (1 << (MOUSE_BUTTON_LEFT - 1)), + MOUSE_BUTTON_MASK_RIGHT = (1 << (MOUSE_BUTTON_RIGHT - 1)), + MOUSE_BUTTON_MASK_MIDDLE = (1 << (MOUSE_BUTTON_MIDDLE - 1)), + MOUSE_BUTTON_MASK_XBUTTON1 = (1 << (MOUSE_BUTTON_XBUTTON1 - 1)), + MOUSE_BUTTON_MASK_XBUTTON2 = (1 << (MOUSE_BUTTON_XBUTTON2 - 1)) }; -enum JoyButtonList { +enum JoyButton { JOY_BUTTON_INVALID = -1, JOY_BUTTON_A = 0, JOY_BUTTON_B = 1, @@ -86,7 +85,7 @@ enum JoyButtonList { JOY_BUTTON_MAX = 36, // Android supports up to 36 buttons. }; -enum JoyAxisList { +enum JoyAxis { JOY_AXIS_INVALID = -1, JOY_AXIS_LEFT_X = 0, JOY_AXIS_LEFT_Y = 1, @@ -98,7 +97,7 @@ enum JoyAxisList { JOY_AXIS_MAX = 10, // OpenVR supports up to 5 Joysticks making a total of 10 axes. }; -enum MidiMessageList { +enum MIDIMessage { MIDI_MESSAGE_NOTE_OFF = 0x8, MIDI_MESSAGE_NOTE_ON = 0x9, MIDI_MESSAGE_AFTERTOUCH = 0xA, diff --git a/core/input/input_map.cpp b/core/input/input_map.cpp index e0b25fa092..aab4e6593c 100644 --- a/core/input/input_map.cpp +++ b/core/input/input_map.cpp @@ -54,8 +54,36 @@ void InputMap::_bind_methods() { ClassDB::bind_method(D_METHOD("load_from_project_settings"), &InputMap::load_from_project_settings); } +/** + * Returns an nonexistent action error message with a suggestion of the closest + * matching action name (if possible). + */ +String InputMap::_suggest_actions(const StringName &p_action) const { + List<StringName> actions = get_actions(); + StringName closest_action; + float closest_similarity = 0.0; + + // Find the most action with the most similar name. + for (List<StringName>::Element *E = actions.front(); E; E = E->next()) { + const float similarity = String(E->get()).similarity(p_action); + + if (similarity > closest_similarity) { + closest_action = E->get(); + closest_similarity = similarity; + } + } + + String error_message = vformat("The InputMap action \"%s\" doesn't exist.", p_action); + + if (closest_similarity >= 0.4) { + // Only include a suggestion in the error message if it's similar enough. + error_message += vformat(" Did you mean \"%s\"?", closest_action); + } + return error_message; +} + void InputMap::add_action(const StringName &p_action, float p_deadzone) { - ERR_FAIL_COND_MSG(input_map.has(p_action), "InputMap already has action '" + String(p_action) + "'."); + ERR_FAIL_COND_MSG(input_map.has(p_action), "InputMap already has action \"" + String(p_action) + "\"."); input_map[p_action] = Action(); static int last_id = 1; input_map[p_action].id = last_id; @@ -64,7 +92,8 @@ void InputMap::add_action(const StringName &p_action, float p_deadzone) { } void InputMap::erase_action(const StringName &p_action) { - ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'."); + ERR_FAIL_COND_MSG(!input_map.has(p_action), _suggest_actions(p_action)); + input_map.erase(p_action); } @@ -122,20 +151,20 @@ bool InputMap::has_action(const StringName &p_action) const { } float InputMap::action_get_deadzone(const StringName &p_action) { - ERR_FAIL_COND_V_MSG(!input_map.has(p_action), 0.0f, "Request for nonexistent InputMap action '" + String(p_action) + "'."); + ERR_FAIL_COND_V_MSG(!input_map.has(p_action), 0.0f, _suggest_actions(p_action)); return input_map[p_action].deadzone; } void InputMap::action_set_deadzone(const StringName &p_action, float p_deadzone) { - ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'."); + ERR_FAIL_COND_MSG(!input_map.has(p_action), _suggest_actions(p_action)); input_map[p_action].deadzone = p_deadzone; } void InputMap::action_add_event(const StringName &p_action, const Ref<InputEvent> &p_event) { ERR_FAIL_COND_MSG(p_event.is_null(), "It's not a reference to a valid InputEvent object."); - ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'."); + ERR_FAIL_COND_MSG(!input_map.has(p_action), _suggest_actions(p_action)); if (_find_event(input_map[p_action], p_event, true)) { return; // Already addded. } @@ -144,12 +173,12 @@ void InputMap::action_add_event(const StringName &p_action, const Ref<InputEvent } bool InputMap::action_has_event(const StringName &p_action, const Ref<InputEvent> &p_event) { - ERR_FAIL_COND_V_MSG(!input_map.has(p_action), false, "Request for nonexistent InputMap action '" + String(p_action) + "'."); + ERR_FAIL_COND_V_MSG(!input_map.has(p_action), false, _suggest_actions(p_action)); return (_find_event(input_map[p_action], p_event, true) != nullptr); } void InputMap::action_erase_event(const StringName &p_action, const Ref<InputEvent> &p_event) { - ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'."); + ERR_FAIL_COND_MSG(!input_map.has(p_action), _suggest_actions(p_action)); List<Ref<InputEvent>>::Element *E = _find_event(input_map[p_action], p_event, true); if (E) { @@ -161,7 +190,7 @@ void InputMap::action_erase_event(const StringName &p_action, const Ref<InputEve } void InputMap::action_erase_events(const StringName &p_action) { - ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'."); + ERR_FAIL_COND_MSG(!input_map.has(p_action), _suggest_actions(p_action)); input_map[p_action].inputs.clear(); } @@ -193,7 +222,7 @@ bool InputMap::event_is_action(const Ref<InputEvent> &p_event, const StringName bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const StringName &p_action, bool p_exact_match, bool *p_pressed, float *p_strength, float *p_raw_strength) const { OrderedHashMap<StringName, Action>::Element E = input_map.find(p_action); - ERR_FAIL_COND_V_MSG(!E, false, "Request for nonexistent InputMap action '" + String(p_action) + "'."); + ERR_FAIL_COND_V_MSG(!E, false, _suggest_actions(p_action)); Ref<InputEventAction> input_event_action = p_event; if (input_event_action.is_valid()) { @@ -567,6 +596,7 @@ const OrderedHashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins() { inputs.push_back(InputEventKey::create_reference(KEY_E | KEY_MASK_CTRL)); inputs.push_back(InputEventKey::create_reference(KEY_RIGHT | KEY_MASK_CMD)); default_builtin_cache.insert("ui_text_caret_line_end.OSX", inputs); + // Text Caret Movement Page Up/Down inputs = List<Ref<InputEvent>>(); diff --git a/core/input/input_map.h b/core/input/input_map.h index 99c71e1e53..0e0567464a 100644 --- a/core/input/input_map.h +++ b/core/input/input_map.h @@ -61,6 +61,7 @@ private: Array _action_get_events(const StringName &p_action); Array _get_actions(); + String _suggest_actions(const StringName &p_action) const; protected: static void _bind_methods(); diff --git a/core/io/compression.cpp b/core/io/compression.cpp index 456023e2a6..6de626db99 100644 --- a/core/io/compression.cpp +++ b/core/io/compression.cpp @@ -32,7 +32,6 @@ #include "core/config/project_settings.h" #include "core/io/zip_io.h" -#include "core/os/copymem.h" #include "thirdparty/misc/fastlz.h" @@ -44,8 +43,8 @@ int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size, case MODE_FASTLZ: { if (p_src_size < 16) { uint8_t src[16]; - zeromem(&src[p_src_size], 16 - p_src_size); - copymem(src, p_src, p_src_size); + memset(&src[p_src_size], 0, 16 - p_src_size); + memcpy(src, p_src, p_src_size); return fastlz_compress(src, 16, p_dst); } else { return fastlz_compress(p_src, p_src_size, p_dst); @@ -136,7 +135,7 @@ int Compression::decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p if (p_dst_max_size < 16) { uint8_t dst[16]; ret_size = fastlz_decompress(p_src, p_src_size, dst, 16); - copymem(p_dst, dst, p_dst_max_size); + memcpy(p_dst, dst, p_dst_max_size); } else { ret_size = fastlz_decompress(p_src, p_src_size, p_dst, p_dst_max_size); } @@ -181,8 +180,8 @@ int Compression::decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p } /** - This will handle both Gzip and Deflat streams. It will automatically allocate the output buffer into the provided p_dst_vect Vector. - This is required for compressed data who's final uncompressed size is unknown, as is the case for HTTP response bodies. + This will handle both Gzip and Deflate streams. It will automatically allocate the output buffer into the provided p_dst_vect Vector. + This is required for compressed data whose final uncompressed size is unknown, as is the case for HTTP response bodies. This is much slower however than using Compression::decompress because it may result in multiple full copies of the output buffer. */ int Compression::decompress_dynamic(Vector<uint8_t> *p_dst_vect, int p_max_dst_size, const uint8_t *p_src, int p_src_size, Mode p_mode) { @@ -248,7 +247,7 @@ int Compression::decompress_dynamic(Vector<uint8_t> *p_dst_vect, int p_max_dst_s out_mark += gzip_chunk; - // Encorce max output size + // Enforce max output size if (p_max_dst_size > -1 && strm.total_out > (uint64_t)p_max_dst_size) { (void)inflateEnd(&strm); p_dst_vect->resize(0); diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp index 015c1f0d90..10f68f3cef 100644 --- a/core/io/config_file.cpp +++ b/core/io/config_file.cpp @@ -295,6 +295,9 @@ Error ConfigFile::_parse(const String &p_path, VariantParser::Stream *p_stream) return OK; } +void ConfigFile::clear() { + values.clear(); +} void ConfigFile::_bind_methods() { ClassDB::bind_method(D_METHOD("set_value", "section", "key", "value"), &ConfigFile::set_value); ClassDB::bind_method(D_METHOD("get_value", "section", "key", "default"), &ConfigFile::get_value, DEFVAL(Variant())); @@ -317,4 +320,6 @@ void ConfigFile::_bind_methods() { ClassDB::bind_method(D_METHOD("save_encrypted", "path", "key"), &ConfigFile::save_encrypted); ClassDB::bind_method(D_METHOD("save_encrypted_pass", "path", "password"), &ConfigFile::save_encrypted_pass); + + ClassDB::bind_method(D_METHOD("clear"), &ConfigFile::clear); } diff --git a/core/io/config_file.h b/core/io/config_file.h index 386d304f07..1b28257c60 100644 --- a/core/io/config_file.h +++ b/core/io/config_file.h @@ -68,6 +68,8 @@ public: Error load(const String &p_path); Error parse(const String &p_data); + void clear(); + Error load_encrypted(const String &p_path, const Vector<uint8_t> &p_key); Error load_encrypted_pass(const String &p_path, const String &p_pass); diff --git a/core/io/file_access_compressed.cpp b/core/io/file_access_compressed.cpp index 9ec2b27e88..b2440629e3 100644 --- a/core/io/file_access_compressed.cpp +++ b/core/io/file_access_compressed.cpp @@ -286,8 +286,10 @@ uint8_t FileAccessCompressed::get_8() const { } int FileAccessCompressed::get_buffer(uint8_t *p_dst, int p_length) const { - ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); - ERR_FAIL_COND_V_MSG(writing, 0, "File has not been opened in read mode."); + ERR_FAIL_COND_V(!p_dst && p_length > 0, -1); + ERR_FAIL_COND_V(p_length < 0, -1); + ERR_FAIL_COND_V_MSG(!f, -1, "File must be opened before use."); + ERR_FAIL_COND_V_MSG(writing, -1, "File has not been opened in read mode."); if (at_end) { read_eof = true; diff --git a/core/io/file_access_encrypted.cpp b/core/io/file_access_encrypted.cpp index 8b4c57ce64..13377a3a25 100644 --- a/core/io/file_access_encrypted.cpp +++ b/core/io/file_access_encrypted.cpp @@ -31,7 +31,6 @@ #include "file_access_encrypted.h" #include "core/crypto/crypto_core.h" -#include "core/os/copymem.h" #include "core/string/print_string.h" #include "core/variant/variant.h" @@ -151,7 +150,7 @@ void FileAccessEncrypted::_release() { ERR_FAIL_COND(CryptoCore::md5(data.ptr(), data.size(), hash) != OK); // Bug? compressed.resize(len); - zeromem(compressed.ptrw(), len); + memset(compressed.ptrw(), 0, len); for (int i = 0; i < data.size(); i++) { compressed.write[i] = data[i]; } @@ -237,7 +236,9 @@ uint8_t FileAccessEncrypted::get_8() const { } int FileAccessEncrypted::get_buffer(uint8_t *p_dst, int p_length) const { - ERR_FAIL_COND_V_MSG(writing, 0, "File has not been opened in read mode."); + ERR_FAIL_COND_V(!p_dst && p_length > 0, -1); + ERR_FAIL_COND_V(p_length < 0, -1); + ERR_FAIL_COND_V_MSG(writing, -1, "File has not been opened in read mode."); int to_copy = MIN(p_length, data.size() - pos); for (int i = 0; i < to_copy; i++) { diff --git a/core/io/file_access_memory.cpp b/core/io/file_access_memory.cpp index 04270de77f..af155a77a8 100644 --- a/core/io/file_access_memory.cpp +++ b/core/io/file_access_memory.cpp @@ -31,7 +31,6 @@ #include "file_access_memory.h" #include "core/config/project_settings.h" -#include "core/os/copymem.h" #include "core/os/dir_access.h" #include "core/templates/map.h" @@ -138,6 +137,8 @@ uint8_t FileAccessMemory::get_8() const { } int FileAccessMemory::get_buffer(uint8_t *p_dst, int p_length) const { + ERR_FAIL_COND_V(!p_dst && p_length > 0, -1); + ERR_FAIL_COND_V(p_length < 0, -1); ERR_FAIL_COND_V(!data, -1); int left = length - pos; @@ -147,7 +148,7 @@ int FileAccessMemory::get_buffer(uint8_t *p_dst, int p_length) const { WARN_PRINT("Reading less data than requested"); } - copymem(p_dst, &data[pos], read); + memcpy(p_dst, &data[pos], read); pos += p_length; return read; @@ -174,6 +175,6 @@ void FileAccessMemory::store_buffer(const uint8_t *p_src, int p_length) { WARN_PRINT("Writing less data than requested"); } - copymem(&data[pos], p_src, write); + memcpy(&data[pos], p_src, write); pos += p_length; } diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp index 97838fd14c..31b7d658d0 100644 --- a/core/io/file_access_network.cpp +++ b/core/io/file_access_network.cpp @@ -366,6 +366,9 @@ void FileAccessNetwork::_queue_page(int p_page) const { } int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const { + ERR_FAIL_COND_V(!p_dst && p_length > 0, -1); + ERR_FAIL_COND_V(p_length < 0, -1); + //bool eof=false; if (pos + p_length > total_size) { eof_flag = true; diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp index faf4fca14f..e24dc40166 100644 --- a/core/io/file_access_pack.cpp +++ b/core/io/file_access_pack.cpp @@ -299,6 +299,9 @@ uint8_t FileAccessPack::get_8() const { } int FileAccessPack::get_buffer(uint8_t *p_dst, int p_length) const { + ERR_FAIL_COND_V(!p_dst && p_length > 0, -1); + ERR_FAIL_COND_V(p_length < 0, -1); + if (eof) { return 0; } diff --git a/core/io/file_access_pack.h b/core/io/file_access_pack.h index 343adbe592..955108f455 100644 --- a/core/io/file_access_pack.h +++ b/core/io/file_access_pack.h @@ -36,6 +36,7 @@ #include "core/string/print_string.h" #include "core/templates/list.h" #include "core/templates/map.h" +#include "core/templates/set.h" // Godot's packed file magic header ("GDPC" in ASCII). #define PACK_HEADER_MAGIC 0x43504447 diff --git a/core/io/file_access_zip.cpp b/core/io/file_access_zip.cpp index 01f9337a80..397b577612 100644 --- a/core/io/file_access_zip.cpp +++ b/core/io/file_access_zip.cpp @@ -32,7 +32,6 @@ #include "file_access_zip.h" -#include "core/os/copymem.h" #include "core/os/file_access.h" ZipArchive *ZipArchive::instance = nullptr; @@ -120,7 +119,7 @@ unzFile ZipArchive::get_file_handle(String p_file) const { ERR_FAIL_COND_V_MSG(!f, nullptr, "Cannot open file '" + packages[file.package].filename + "'."); zlib_filefunc_def io; - zeromem(&io, sizeof(io)); + memset(&io, 0, sizeof(io)); io.opaque = f; io.zopen_file = godot_open; @@ -303,6 +302,8 @@ uint8_t FileAccessZip::get_8() const { } int FileAccessZip::get_buffer(uint8_t *p_dst, int p_length) const { + ERR_FAIL_COND_V(!p_dst && p_length > 0, -1); + ERR_FAIL_COND_V(p_length < 0, -1); ERR_FAIL_COND_V(!zfile, -1); at_eof = unzeof(zfile); if (at_eof) { diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp index 3863dce0f6..4b053d576c 100644 --- a/core/io/http_client.cpp +++ b/core/io/http_client.cpp @@ -633,7 +633,7 @@ PackedByteArray HTTPClient::read_response_body_chunk() { ret.resize(chunk.size() - 2); uint8_t *w = ret.ptrw(); - copymem(w, chunk.ptr(), chunk.size() - 2); + memcpy(w, chunk.ptr(), chunk.size() - 2); chunk.clear(); } diff --git a/core/io/image.cpp b/core/io/image.cpp index 5d46d75efe..c36fa6e45f 100644 --- a/core/io/image.cpp +++ b/core/io/image.cpp @@ -34,7 +34,6 @@ #include "core/io/image_loader.h" #include "core/io/resource_loader.h" #include "core/math/math_funcs.h" -#include "core/os/copymem.h" #include "core/string/print_string.h" #include "core/templates/hash_map.h" @@ -1537,7 +1536,7 @@ void Image::shrink_x2() { uint8_t *w = new_img.ptrw(); const uint8_t *r = data.ptr(); - copymem(w, &r[ofs], new_size); + memcpy(w, &r[ofs], new_size); } width = MAX(width / 2, 1); @@ -1932,7 +1931,7 @@ Error Image::generate_mipmap_roughness(RoughnessChannel p_roughness_channel, con uint8_t* wr = imgdata.ptrw(); - copymem(wr.ptr(), ptr, size); + memcpy(wr.ptr(), ptr, size); wr = uint8_t*(); Ref<Image> im; im.instance(); @@ -1982,7 +1981,7 @@ void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_forma { uint8_t *w = data.ptrw(); - zeromem(w, size); + memset(w, 0, size); } width = p_width; @@ -3010,26 +3009,28 @@ Image::UsedChannels Image::detect_used_channels(CompressSource p_source) { ERR_FAIL_COND_V(is_compressed(), USED_CHANNELS_RGBA); bool r = false, g = false, b = false, a = false, c = false; - for (int i = 0; i < width; i++) { - for (int j = 0; j < height; j++) { - Color col = get_pixel(i, j); + const uint8_t *data_ptr = data.ptr(); - if (col.r > 0.001) { - r = true; - } - if (col.g > 0.001) { - g = true; - } - if (col.b > 0.001) { - b = true; - } - if (col.a < 0.999) { - a = true; - } + uint32_t data_total = width * height; - if (col.r != col.b || col.r != col.g || col.b != col.g) { - c = true; - } + for (uint32_t i = 0; i < data_total; i++) { + Color col = _get_color_at_ofs(data_ptr, i); + + if (col.r > 0.001) { + r = true; + } + if (col.g > 0.001) { + g = true; + } + if (col.b > 0.001) { + b = true; + } + if (col.a < 0.999) { + a = true; + } + + if (col.r != col.b || col.r != col.g || col.b != col.g) { + c = true; } } @@ -3293,7 +3294,7 @@ Ref<Image> Image::get_image_from_mipmap(int p_mipamp) const { { uint8_t *wr = new_data.ptrw(); const uint8_t *rd = data.ptr(); - copymem(wr, rd + ofs, size); + memcpy(wr, rd + ofs, size); } Ref<Image> image; @@ -3620,5 +3621,5 @@ Ref<Resource> Image::duplicate(bool p_subresources) const { } void Image::set_as_black() { - zeromem(data.ptrw(), data.size()); + memset(data.ptrw(), 0, data.size()); } diff --git a/core/io/json.cpp b/core/io/json.cpp index 0d9117fdda..394cf216e8 100644 --- a/core/io/json.cpp +++ b/core/io/json.cpp @@ -347,7 +347,6 @@ Error JSON::_parse_value(Variant &value, Token &token, const char32_t *p_str, in return err; } value = d; - return OK; } else if (token.type == TK_BRACKET_OPEN) { Array a; Error err = _parse_array(a, p_str, index, p_len, line, r_err_str); @@ -355,8 +354,6 @@ Error JSON::_parse_value(Variant &value, Token &token, const char32_t *p_str, in return err; } value = a; - return OK; - } else if (token.type == TK_IDENTIFIER) { String id = token.value; if (id == "true") { @@ -369,18 +366,16 @@ Error JSON::_parse_value(Variant &value, Token &token, const char32_t *p_str, in r_err_str = "Expected 'true','false' or 'null', got '" + id + "'."; return ERR_PARSE_ERROR; } - return OK; - } else if (token.type == TK_NUMBER) { value = token.value; - return OK; } else if (token.type == TK_STRING) { value = token.value; - return OK; } else { r_err_str = "Expected value, got " + String(tk_name[token.type]) + "."; return ERR_PARSE_ERROR; } + + return OK; } Error JSON::_parse_array(Array &array, const char32_t *p_str, int &index, int p_len, int &line, String &r_err_str) { @@ -499,6 +494,19 @@ Error JSON::parse(const String &p_json, Variant &r_ret, String &r_err_str, int & err = _parse_value(r_ret, token, str, idx, len, r_err_line, r_err_str); + // Check if EOF is reached + // or it's a type of the next token. + if (err == OK && idx < len) { + err = _get_token(str, idx, len, token, r_err_line, r_err_str); + + if (err || token.type != TK_EOF) { + r_err_str = "Expected 'EOF'"; + // Reset return value to empty `Variant` + r_ret = Variant(); + return ERR_PARSE_ERROR; + } + } + return err; } diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index 218a612da2..0282609270 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -851,7 +851,7 @@ static void _encode_string(const String &p_string, uint8_t *&buf, int &r_len) { if (buf) { encode_uint32(utf8.length(), buf); buf += 4; - copymem(buf, utf8.get_data(), utf8.length()); + memcpy(buf, utf8.get_data(), utf8.length()); buf += utf8.length(); } @@ -995,7 +995,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo if (buf) { encode_uint32(utf8.length(), buf); buf += 4; - copymem(buf, utf8.get_data(), utf8.length()); + memcpy(buf, utf8.get_data(), utf8.length()); buf += pad + utf8.length(); } @@ -1079,7 +1079,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo Transform2D val = p_variant; for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { - copymem(&buf[(i * 2 + j) * 4], &val.elements[i][j], sizeof(float)); + memcpy(&buf[(i * 2 + j) * 4], &val.elements[i][j], sizeof(float)); } } } @@ -1130,7 +1130,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo Basis val = p_variant; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - copymem(&buf[(i * 3 + j) * 4], &val.elements[i][j], sizeof(float)); + memcpy(&buf[(i * 3 + j) * 4], &val.elements[i][j], sizeof(float)); } } } @@ -1143,7 +1143,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo Transform val = p_variant; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - copymem(&buf[(i * 3 + j) * 4], &val.basis.elements[i][j], sizeof(float)); + memcpy(&buf[(i * 3 + j) * 4], &val.basis.elements[i][j], sizeof(float)); } } @@ -1258,7 +1258,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo if (buf) { encode_uint32(utf8.length()+1,buf); buf+=4; - copymem(buf,utf8.get_data(),utf8.length()+1); + memcpy(buf,utf8.get_data(),utf8.length()+1); } r_len+=4+utf8.length()+1; @@ -1314,7 +1314,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo encode_uint32(datalen, buf); buf += 4; const uint8_t *r = data.ptr(); - copymem(buf, &r[0], datalen * datasize); + memcpy(buf, &r[0], datalen * datasize); buf += datalen * datasize; } @@ -1412,7 +1412,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo if (buf) { encode_uint32(utf8.length() + 1, buf); buf += 4; - copymem(buf, utf8.get_data(), utf8.length() + 1); + memcpy(buf, utf8.get_data(), utf8.length() + 1); buf += utf8.length() + 1; } diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp index 6b550e69c8..8414ee7c0c 100644 --- a/core/io/multiplayer_api.cpp +++ b/core/io/multiplayer_api.cpp @@ -50,7 +50,7 @@ _FORCE_INLINE_ bool _should_call_local(MultiplayerAPI::RPCMode mode, bool is_mas // Do nothing. } break; case MultiplayerAPI::RPC_MODE_REMOTE: { - // Do nothing also. Remote cannot produce a local call. + // Do nothing. Remote cannot produce a local call. } break; case MultiplayerAPI::RPC_MODE_MASTERSYNC: { if (is_master) { @@ -675,7 +675,7 @@ Error MultiplayerAPI::_encode_and_compress_variant(const Variant &p_variant, uin return err; } if (r_buffer) { - // The first byte is not used by the marshaling, so store the type + // The first byte is not used by the marshalling, so store the type // so we know how to decompress and decode this variant. r_buffer[0] = p_variant.get_type(); } @@ -791,7 +791,7 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p packet_cache.resize(m_amount); // Encode meta. - // The meta is composed by a single byte that contains (starting from the least segnificant bit): + // The meta is composed by a single byte that contains (starting from the least significant bit): // - `NetworkCommands` in the first three bits. // - `NetworkNodeIdCompression` in the next 2 bits. // - `NetworkNameIdCompression` in the next 1 bit. @@ -830,7 +830,7 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p ofs += 4; } } else { - // The targets doesn't know the node yet, so we need to use 32 bits int. + // The targets don't know the node yet, so we need to use 32 bits int. node_id_compression = NETWORK_NODE_ID_COMPRESSION_32; MAKE_ROOM(ofs + 4); encode_uint32(psc->id, &(packet_cache.write[ofs])); @@ -897,7 +897,7 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p // Special optimization when only the byte vector is sent. const Vector<uint8_t> data = *p_arg[0]; MAKE_ROOM(ofs + data.size()); - copymem(&(packet_cache.write[ofs]), data.ptr(), sizeof(uint8_t) * data.size()); + memcpy(&(packet_cache.write[ofs]), data.ptr(), sizeof(uint8_t) * data.size()); ofs += data.size(); } else { // Arguments diff --git a/core/io/net_socket.h b/core/io/net_socket.h index bc09477693..a632ad2ea7 100644 --- a/core/io/net_socket.h +++ b/core/io/net_socket.h @@ -67,6 +67,7 @@ public: virtual bool is_open() const = 0; virtual int get_available_bytes() const = 0; + virtual Error get_socket_address(IP_Address *r_ip, uint16_t *r_port) const = 0; virtual Error set_broadcasting_enabled(bool p_enabled) = 0; // Returns OK if the socket option has been set successfully. virtual void set_blocking_enabled(bool p_enabled) = 0; diff --git a/core/io/packed_data_container.cpp b/core/io/packed_data_container.cpp index a0b97772e6..c6354b11b7 100644 --- a/core/io/packed_data_container.cpp +++ b/core/io/packed_data_container.cpp @@ -317,7 +317,7 @@ Error PackedDataContainer::pack(const Variant &p_data) { datalen = tmpdata.size(); data.resize(tmpdata.size()); uint8_t *w = data.ptrw(); - copymem(w, tmpdata.ptr(), tmpdata.size()); + memcpy(w, tmpdata.ptr(), tmpdata.size()); return OK; } diff --git a/core/io/packet_peer_udp.cpp b/core/io/packet_peer_udp.cpp index d8d63d976f..40e4ce4f77 100644 --- a/core/io/packet_peer_udp.cpp +++ b/core/io/packet_peer_udp.cpp @@ -159,10 +159,11 @@ int PacketPeerUDP::get_max_packet_size() const { return 512; // uhm maybe not } -Error PacketPeerUDP::listen(int p_port, const IP_Address &p_bind_address, int p_recv_buffer_size) { +Error PacketPeerUDP::bind(int p_port, const IP_Address &p_bind_address, int p_recv_buffer_size) { ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE); ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V_MSG(p_port < 0 || p_port > 65535, ERR_INVALID_PARAMETER, "The local port number must be between 0 and 65535 (inclusive)."); Error err; IP::Type ip_type = IP::TYPE_ANY; @@ -210,6 +211,7 @@ Error PacketPeerUDP::connect_to_host(const IP_Address &p_host, int p_port) { ERR_FAIL_COND_V(udp_server, ERR_LOCKED); ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); ERR_FAIL_COND_V(!p_host.is_valid(), ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V_MSG(p_port < 1 || p_port > 65535, ERR_INVALID_PARAMETER, "The remote port number must be between 1 and 65535 (inclusive)."); Error err; @@ -224,7 +226,7 @@ Error PacketPeerUDP::connect_to_host(const IP_Address &p_host, int p_port) { // I see no reason why we should get ERR_BUSY (wouldblock/eagain) here. // This is UDP, so connect is only used to tell the OS to which socket - // it shuold deliver packets when multiple are bound on the same address/port. + // it should deliver packets when multiple are bound on the same address/port. if (err != OK) { close(); ERR_FAIL_V_MSG(FAILED, "Unable to connect"); @@ -316,7 +318,7 @@ Error PacketPeerUDP::store_packet(IP_Address p_ip, uint32_t p_port, uint8_t *p_b return OK; } -bool PacketPeerUDP::is_listening() const { +bool PacketPeerUDP::is_bound() const { return _sock.is_valid() && _sock->is_open(); } @@ -328,6 +330,12 @@ int PacketPeerUDP::get_packet_port() const { return packet_port; } +int PacketPeerUDP::get_local_port() const { + uint16_t local_port; + _sock->get_socket_address(nullptr, &local_port); + return local_port; +} + void PacketPeerUDP::set_dest_address(const IP_Address &p_address, int p_port) { ERR_FAIL_COND_MSG(connected, "Destination address cannot be set for connected sockets"); peer_addr = p_address; @@ -335,14 +343,15 @@ void PacketPeerUDP::set_dest_address(const IP_Address &p_address, int p_port) { } void PacketPeerUDP::_bind_methods() { - ClassDB::bind_method(D_METHOD("listen", "port", "bind_address", "recv_buf_size"), &PacketPeerUDP::listen, DEFVAL("*"), DEFVAL(65536)); + ClassDB::bind_method(D_METHOD("bind", "port", "bind_address", "recv_buf_size"), &PacketPeerUDP::bind, DEFVAL("*"), DEFVAL(65536)); ClassDB::bind_method(D_METHOD("close"), &PacketPeerUDP::close); ClassDB::bind_method(D_METHOD("wait"), &PacketPeerUDP::wait); - ClassDB::bind_method(D_METHOD("is_listening"), &PacketPeerUDP::is_listening); + ClassDB::bind_method(D_METHOD("is_bound"), &PacketPeerUDP::is_bound); ClassDB::bind_method(D_METHOD("connect_to_host", "host", "port"), &PacketPeerUDP::connect_to_host); ClassDB::bind_method(D_METHOD("is_connected_to_host"), &PacketPeerUDP::is_connected_to_host); ClassDB::bind_method(D_METHOD("get_packet_ip"), &PacketPeerUDP::_get_packet_ip); ClassDB::bind_method(D_METHOD("get_packet_port"), &PacketPeerUDP::get_packet_port); + ClassDB::bind_method(D_METHOD("get_local_port"), &PacketPeerUDP::get_local_port); ClassDB::bind_method(D_METHOD("set_dest_address", "host", "port"), &PacketPeerUDP::_set_dest_address); ClassDB::bind_method(D_METHOD("set_broadcast_enabled", "enabled"), &PacketPeerUDP::set_broadcast_enabled); ClassDB::bind_method(D_METHOD("join_multicast_group", "multicast_address", "interface_name"), &PacketPeerUDP::join_multicast_group); diff --git a/core/io/packet_peer_udp.h b/core/io/packet_peer_udp.h index 4bac6994fc..b9d11c465c 100644 --- a/core/io/packet_peer_udp.h +++ b/core/io/packet_peer_udp.h @@ -70,10 +70,10 @@ protected: public: void set_blocking_mode(bool p_enable); - Error listen(int p_port, const IP_Address &p_bind_address = IP_Address("*"), int p_recv_buffer_size = 65536); + Error bind(int p_port, const IP_Address &p_bind_address = IP_Address("*"), int p_recv_buffer_size = 65536); void close(); Error wait(); - bool is_listening() const; + bool is_bound() const; Error connect_shared_socket(Ref<NetSocket> p_sock, IP_Address p_ip, uint16_t p_port, UDPServer *ref); // Used by UDPServer void disconnect_shared_socket(); // Used by UDPServer @@ -83,6 +83,7 @@ public: IP_Address get_packet_address() const; int get_packet_port() const; + int get_local_port() const; void set_dest_address(const IP_Address &p_address, int p_port); Error put_packet(const uint8_t *p_buffer, int p_buffer_size) override; diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index fb6ad7d65e..c4eb2a20bb 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -1245,7 +1245,7 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons String ResourceFormatLoaderBinary::get_resource_type(const String &p_path) const { FileAccess *f = FileAccess::open(p_path, FileAccess::READ); if (!f) { - return ""; //could not rwead + return ""; //could not read } ResourceLoaderBinary loader; diff --git a/core/io/resource_importer.cpp b/core/io/resource_importer.cpp index 5ca0eb884a..b503655edd 100644 --- a/core/io/resource_importer.cpp +++ b/core/io/resource_importer.cpp @@ -192,6 +192,34 @@ bool ResourceFormatImporter::recognize_path(const String &p_path, const String & return FileAccess::exists(p_path + ".import"); } +Error ResourceFormatImporter::get_import_order_threads_and_importer(const String &p_path, int &r_order, bool &r_can_threads, String &r_importer) const { + r_order = 0; + r_importer = ""; + + r_can_threads = false; + Ref<ResourceImporter> importer; + + if (FileAccess::exists(p_path + ".import")) { + PathAndType pat; + Error err = _get_path_and_type(p_path, pat); + + if (err == OK) { + importer = get_importer_by_name(pat.importer); + } + } else { + importer = get_importer_by_extension(p_path.get_extension().to_lower()); + } + + if (importer.is_valid()) { + r_order = importer->get_import_order(); + r_importer = importer->get_importer_name(); + r_can_threads = importer->can_import_threaded(); + return OK; + } else { + return ERR_INVALID_PARAMETER; + } +} + int ResourceFormatImporter::get_import_order(const String &p_path) const { Ref<ResourceImporter> importer; diff --git a/core/io/resource_importer.h b/core/io/resource_importer.h index 91efec5534..a14d6ba52c 100644 --- a/core/io/resource_importer.h +++ b/core/io/resource_importer.h @@ -72,6 +72,8 @@ public: virtual int get_import_order(const String &p_path) const; + Error get_import_order_threads_and_importer(const String &p_path, int &r_order, bool &r_can_threads, String &r_importer) const; + String get_internal_resource_path(const String &p_path) const; void get_internal_resource_path_list(const String &p_path, List<String> *r_paths); @@ -115,6 +117,9 @@ public: ImportOption() {} }; + virtual bool has_advanced_options() const { return false; } + virtual void show_advanced_options(const String &p_path) {} + virtual int get_preset_count() const { return 0; } virtual String get_preset_name(int p_idx) const { return String(); } @@ -123,6 +128,9 @@ public: virtual String get_option_group_file() const { return String(); } virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = nullptr, Variant *r_metadata = nullptr) = 0; + virtual bool can_import_threaded() const { return true; } + virtual void import_threaded_begin() {} + virtual void import_threaded_end() {} virtual Error import_group_file(const String &p_group_file, const Map<String, Map<StringName, Variant>> &p_source_file_options, const Map<String, String> &p_base_paths) { return ERR_UNAVAILABLE; } virtual bool are_import_settings_valid(const String &p_path) const { return true; } diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 8275dd0ad4..dcf71bb4a9 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -215,7 +215,7 @@ void ResourceLoader::_thread_load_function(void *p_userdata) { load_task.loader_id = Thread::get_caller_id(); if (load_task.semaphore) { - //this is an actual thread, so wait for Ok fom semaphore + //this is an actual thread, so wait for Ok from semaphore thread_load_semaphore->wait(); //wait until its ok to start loading } load_task.resource = _load(load_task.remapped_path, load_task.remapped_path != load_task.local_path ? load_task.local_path : String(), load_task.type_hint, load_task.cache_mode, &load_task.error, load_task.use_sub_threads, &load_task.progress); @@ -443,7 +443,7 @@ RES ResourceLoader::load_threaded_get(const String &p_path, Error *r_error) { ThreadLoadTask &load_task = thread_load_tasks[local_path]; - //semaphore still exists, meaning its still loading, request poll + //semaphore still exists, meaning it's still loading, request poll Semaphore *semaphore = load_task.semaphore; if (semaphore) { load_task.poll_requests++; @@ -452,7 +452,7 @@ RES ResourceLoader::load_threaded_get(const String &p_path, Error *r_error) { // As we got a semaphore, this means we are going to have to wait // until the sub-resource is done loading // - // As this thread will become 'blocked' we should "echange" its + // As this thread will become 'blocked' we should "exchange" its // active status with a waiting one, to ensure load continues. // // This ensures loading is never blocked and that is also within diff --git a/core/io/stream_peer.cpp b/core/io/stream_peer.cpp index 8407d55196..74154321b3 100644 --- a/core/io/stream_peer.cpp +++ b/core/io/stream_peer.cpp @@ -433,7 +433,7 @@ Error StreamPeerBuffer::put_data(const uint8_t *p_data, int p_bytes) { } uint8_t *w = data.ptrw(); - copymem(&w[pointer], p_data, p_bytes); + memcpy(&w[pointer], p_data, p_bytes); pointer += p_bytes; return OK; @@ -466,7 +466,7 @@ Error StreamPeerBuffer::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_ } const uint8_t *r = data.ptr(); - copymem(p_buffer, r + pointer, r_received); + memcpy(p_buffer, r + pointer, r_received); pointer += r_received; // FIXME: return what? OK or ERR_* diff --git a/core/io/stream_peer_tcp.cpp b/core/io/stream_peer_tcp.cpp index 760710a9eb..9906b9e4c3 100644 --- a/core/io/stream_peer_tcp.cpp +++ b/core/io/stream_peer_tcp.cpp @@ -67,21 +67,40 @@ void StreamPeerTCP::accept_socket(Ref<NetSocket> p_sock, IP_Address p_host, uint peer_port = p_port; } -Error StreamPeerTCP::connect_to_host(const IP_Address &p_host, uint16_t p_port) { +Error StreamPeerTCP::bind(int p_port, const IP_Address &p_host) { ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE); - ERR_FAIL_COND_V(!p_host.is_valid(), ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V_MSG(p_port < 0 || p_port > 65535, ERR_INVALID_PARAMETER, "The local port number must be between 0 and 65535 (inclusive)."); - Error err; IP::Type ip_type = p_host.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6; + if (p_host.is_wildcard()) { + ip_type = IP::TYPE_ANY; + } + Error err = _sock->open(NetSocket::TYPE_TCP, ip_type); + if (err != OK) { + return err; + } + _sock->set_blocking_enabled(false); + return _sock->bind(p_host, p_port); +} - err = _sock->open(NetSocket::TYPE_TCP, ip_type); - ERR_FAIL_COND_V(err != OK, FAILED); +Error StreamPeerTCP::connect_to_host(const IP_Address &p_host, int p_port) { + ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); + ERR_FAIL_COND_V(status != STATUS_NONE, ERR_ALREADY_IN_USE); + ERR_FAIL_COND_V(!p_host.is_valid(), ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V_MSG(p_port < 1 || p_port > 65535, ERR_INVALID_PARAMETER, "The remote port number must be between 1 and 65535 (inclusive)."); - _sock->set_blocking_enabled(false); + if (!_sock->is_open()) { + IP::Type ip_type = p_host.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6; + Error err = _sock->open(NetSocket::TYPE_TCP, ip_type); + if (err != OK) { + return err; + } + _sock->set_blocking_enabled(false); + } timeout = OS::get_singleton()->get_ticks_msec() + (((uint64_t)GLOBAL_GET("network/limits/tcp/connect_timeout_seconds")) * 1000); - err = _sock->connect_to_host(p_host, p_port); + Error err = _sock->connect_to_host(p_host, p_port); if (err == OK) { status = STATUS_CONNECTED; @@ -300,10 +319,16 @@ IP_Address StreamPeerTCP::get_connected_host() const { return peer_host; } -uint16_t StreamPeerTCP::get_connected_port() const { +int StreamPeerTCP::get_connected_port() const { return peer_port; } +int StreamPeerTCP::get_local_port() const { + uint16_t local_port; + _sock->get_socket_address(nullptr, &local_port); + return local_port; +} + Error StreamPeerTCP::_connect(const String &p_address, int p_port) { IP_Address ip; if (p_address.is_valid_ip_address()) { @@ -319,11 +344,13 @@ Error StreamPeerTCP::_connect(const String &p_address, int p_port) { } void StreamPeerTCP::_bind_methods() { + ClassDB::bind_method(D_METHOD("bind", "port", "host"), &StreamPeerTCP::bind, DEFVAL("*")); ClassDB::bind_method(D_METHOD("connect_to_host", "host", "port"), &StreamPeerTCP::_connect); ClassDB::bind_method(D_METHOD("is_connected_to_host"), &StreamPeerTCP::is_connected_to_host); ClassDB::bind_method(D_METHOD("get_status"), &StreamPeerTCP::get_status); ClassDB::bind_method(D_METHOD("get_connected_host"), &StreamPeerTCP::get_connected_host); ClassDB::bind_method(D_METHOD("get_connected_port"), &StreamPeerTCP::get_connected_port); + ClassDB::bind_method(D_METHOD("get_local_port"), &StreamPeerTCP::get_local_port); ClassDB::bind_method(D_METHOD("disconnect_from_host"), &StreamPeerTCP::disconnect_from_host); ClassDB::bind_method(D_METHOD("set_no_delay", "enabled"), &StreamPeerTCP::set_no_delay); diff --git a/core/io/stream_peer_tcp.h b/core/io/stream_peer_tcp.h index 10b90908d4..3bc7b252dc 100644 --- a/core/io/stream_peer_tcp.h +++ b/core/io/stream_peer_tcp.h @@ -65,10 +65,12 @@ protected: public: void accept_socket(Ref<NetSocket> p_sock, IP_Address p_host, uint16_t p_port); - Error connect_to_host(const IP_Address &p_host, uint16_t p_port); + Error bind(int p_port, const IP_Address &p_host); + Error connect_to_host(const IP_Address &p_host, int p_port); bool is_connected_to_host() const; IP_Address get_connected_host() const; - uint16_t get_connected_port() const; + int get_connected_port() const; + int get_local_port() const; void disconnect_from_host(); int get_available_bytes() const override; diff --git a/core/io/tcp_server.cpp b/core/io/tcp_server.cpp index 323d2bbd7f..348be66ba4 100644 --- a/core/io/tcp_server.cpp +++ b/core/io/tcp_server.cpp @@ -34,6 +34,7 @@ void TCP_Server::_bind_methods() { ClassDB::bind_method(D_METHOD("listen", "port", "bind_address"), &TCP_Server::listen, DEFVAL("*")); ClassDB::bind_method(D_METHOD("is_connection_available"), &TCP_Server::is_connection_available); ClassDB::bind_method(D_METHOD("is_listening"), &TCP_Server::is_listening); + ClassDB::bind_method(D_METHOD("get_local_port"), &TCP_Server::get_local_port); ClassDB::bind_method(D_METHOD("take_connection"), &TCP_Server::take_connection); ClassDB::bind_method(D_METHOD("stop"), &TCP_Server::stop); } @@ -42,6 +43,7 @@ Error TCP_Server::listen(uint16_t p_port, const IP_Address &p_bind_address) { ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE); ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V_MSG(p_port < 0 || p_port > 65535, ERR_INVALID_PARAMETER, "The local port number must be between 0 and 65535 (inclusive)."); Error err; IP::Type ip_type = IP::TYPE_ANY; @@ -74,6 +76,12 @@ Error TCP_Server::listen(uint16_t p_port, const IP_Address &p_bind_address) { return OK; } +int TCP_Server::get_local_port() const { + uint16_t local_port; + _sock->get_socket_address(nullptr, &local_port); + return local_port; +} + bool TCP_Server::is_listening() const { ERR_FAIL_COND_V(!_sock.is_valid(), false); diff --git a/core/io/tcp_server.h b/core/io/tcp_server.h index f06ddd2d99..58c04d87ec 100644 --- a/core/io/tcp_server.h +++ b/core/io/tcp_server.h @@ -49,6 +49,7 @@ protected: public: Error listen(uint16_t p_port, const IP_Address &p_bind_address = IP_Address("*")); + int get_local_port() const; bool is_listening() const; bool is_connection_available() const; Ref<StreamPeerTCP> take_connection(); diff --git a/core/io/translation_loader_po.cpp b/core/io/translation_loader_po.cpp index 0e11ff514a..9adf912224 100644 --- a/core/io/translation_loader_po.cpp +++ b/core/io/translation_loader_po.cpp @@ -194,7 +194,7 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) { l = l.substr(1, l.length()); // Find final quote, ignoring escaped ones (\"). // The escape_next logic is necessary to properly parse things like \\" - // where the blackslash is the one being escaped, not the quote. + // where the backslash is the one being escaped, not the quote. int end_pos = -1; bool escape_next = false; for (int i = 0; i < l.length(); i++) { diff --git a/core/io/udp_server.cpp b/core/io/udp_server.cpp index f56fb431ef..99642f4af4 100644 --- a/core/io/udp_server.cpp +++ b/core/io/udp_server.cpp @@ -34,6 +34,7 @@ void UDPServer::_bind_methods() { ClassDB::bind_method(D_METHOD("listen", "port", "bind_address"), &UDPServer::listen, DEFVAL("*")); ClassDB::bind_method(D_METHOD("poll"), &UDPServer::poll); ClassDB::bind_method(D_METHOD("is_connection_available"), &UDPServer::is_connection_available); + ClassDB::bind_method(D_METHOD("get_local_port"), &UDPServer::get_local_port); ClassDB::bind_method(D_METHOD("is_listening"), &UDPServer::is_listening); ClassDB::bind_method(D_METHOD("take_connection"), &UDPServer::take_connection); ClassDB::bind_method(D_METHOD("stop"), &UDPServer::stop); @@ -90,6 +91,7 @@ Error UDPServer::listen(uint16_t p_port, const IP_Address &p_bind_address) { ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE); ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V_MSG(p_port < 0 || p_port > 65535, ERR_INVALID_PARAMETER, "The local port number must be between 0 and 65535 (inclusive)."); Error err; IP::Type ip_type = IP::TYPE_ANY; @@ -112,11 +114,15 @@ Error UDPServer::listen(uint16_t p_port, const IP_Address &p_bind_address) { stop(); return err; } - bind_address = p_bind_address; - bind_port = p_port; return OK; } +int UDPServer::get_local_port() const { + uint16_t local_port; + _sock->get_socket_address(nullptr, &local_port); + return local_port; +} + bool UDPServer::is_listening() const { ERR_FAIL_COND_V(!_sock.is_valid(), false); @@ -176,8 +182,6 @@ void UDPServer::stop() { if (_sock.is_valid()) { _sock->close(); } - bind_port = 0; - bind_address = IP_Address(); List<Peer>::Element *E = peers.front(); while (E) { E->get().peer->disconnect_shared_socket(); diff --git a/core/io/udp_server.h b/core/io/udp_server.h index bbd2f951c9..298d4d4b63 100644 --- a/core/io/udp_server.h +++ b/core/io/udp_server.h @@ -53,21 +53,18 @@ protected: }; uint8_t recv_buffer[PACKET_BUFFER_SIZE]; - int bind_port = 0; - IP_Address bind_address; - List<Peer> peers; List<Peer> pending; int max_pending_connections = 16; Ref<NetSocket> _sock; - static void _bind_methods(); public: void remove_peer(IP_Address p_ip, int p_port); Error listen(uint16_t p_port, const IP_Address &p_bind_address = IP_Address("*")); Error poll(); + int get_local_port() const; bool is_listening() const; bool is_connection_available() const; void set_max_pending_connections(int p_max); diff --git a/core/io/xml_parser.cpp b/core/io/xml_parser.cpp index 1574634aad..a1f8e79adc 100644 --- a/core/io/xml_parser.cpp +++ b/core/io/xml_parser.cpp @@ -344,7 +344,7 @@ void XMLParser::_bind_methods() { } Error XMLParser::read() { - // if not end reached, parse the node + // if end not reached, parse the node if (P && (P - data) < (int64_t)length - 1 && *P != 0) { _parse_current_node(); return OK; @@ -433,7 +433,7 @@ Error XMLParser::open_buffer(const Vector<uint8_t> &p_buffer) { length = p_buffer.size(); data = memnew_arr(char, length + 1); - copymem(data, p_buffer.ptr(), length); + memcpy(data, p_buffer.ptr(), length); data[length] = 0; P = data; return OK; diff --git a/core/io/zip_io.cpp b/core/io/zip_io.cpp index 4b4a46e198..fe46868dd0 100644 --- a/core/io/zip_io.cpp +++ b/core/io/zip_io.cpp @@ -30,8 +30,6 @@ #include "zip_io.h" -#include "core/os/copymem.h" - void *zipio_open(void *data, const char *p_fname, int mode) { FileAccess *&f = *(FileAccess **)data; @@ -103,7 +101,7 @@ int zipio_testerror(voidpf opaque, voidpf stream) { voidpf zipio_alloc(voidpf opaque, uInt items, uInt size) { voidpf ptr = memalloc(items * size); - zeromem(ptr, items * size); + memset(ptr, 0, items * size); return ptr; } diff --git a/core/math/basis.cpp b/core/math/basis.cpp index cbdd8a8c9f..50299902eb 100644 --- a/core/math/basis.cpp +++ b/core/math/basis.cpp @@ -31,7 +31,6 @@ #include "basis.h" #include "core/math/math_funcs.h" -#include "core/os/copymem.h" #include "core/string/print_string.h" #define cofac(row1, col1, row2, col2) \ @@ -132,7 +131,7 @@ bool Basis::is_symmetric() const { Basis Basis::diagonalize() { //NOTE: only implemented for symmetric matrices -//with the Jacobi iterative method method +//with the Jacobi iterative method #ifdef MATH_CHECKS ERR_FAIL_COND_V(!is_symmetric(), Basis()); #endif @@ -317,7 +316,7 @@ Vector3 Basis::rotref_posscale_decomposition(Basis &rotref) const { // Multiplies the matrix from left by the rotation matrix: M -> R.M // Note that this does *not* rotate the matrix itself. // -// The main use of Basis is as Transform.basis, which is used a the transformation matrix +// The main use of Basis is as Transform.basis, which is used by the transformation matrix // of 3D object. Rotate here refers to rotation of the object (which is R * (*this)), // not the matrix itself (which is R * (*this) * R.transposed()). Basis Basis::rotated(const Vector3 &p_axis, real_t p_phi) const { @@ -881,7 +880,7 @@ void Basis::get_axis_angle(Vector3 &r_axis, real_t &r_angle) const { if ((Math::abs(elements[1][0] - elements[0][1]) < epsilon) && (Math::abs(elements[2][0] - elements[0][2]) < epsilon) && (Math::abs(elements[2][1] - elements[1][2]) < epsilon)) { // singularity found // first check for identity matrix which must have +1 for all terms - // in leading diagonaland zero in other terms + // in leading diagonal and zero in other terms if ((Math::abs(elements[1][0] + elements[0][1]) < epsilon2) && (Math::abs(elements[2][0] + elements[0][2]) < epsilon2) && (Math::abs(elements[2][1] + elements[1][2]) < epsilon2) && (Math::abs(elements[0][0] + elements[1][1] + elements[2][2] - 3) < epsilon2)) { // this singularity is identity matrix so angle = 0 r_axis = Vector3(0, 1, 0); diff --git a/core/math/color.h b/core/math/color.h index 5eb8b1119a..e404d80c8a 100644 --- a/core/math/color.h +++ b/core/math/color.h @@ -197,13 +197,13 @@ struct Color { // For the binder. _FORCE_INLINE_ void set_r8(int32_t r8) { r = (CLAMP(r8, 0, 255) / 255.0); } - _FORCE_INLINE_ int32_t get_r8() const { return int32_t(CLAMP(r * 255.0, 0.0, 255.0)); } + _FORCE_INLINE_ int32_t get_r8() const { return int32_t(CLAMP(Math::round(r * 255.0f), 0.0f, 255.0f)); } _FORCE_INLINE_ void set_g8(int32_t g8) { g = (CLAMP(g8, 0, 255) / 255.0); } - _FORCE_INLINE_ int32_t get_g8() const { return int32_t(CLAMP(g * 255.0, 0.0, 255.0)); } + _FORCE_INLINE_ int32_t get_g8() const { return int32_t(CLAMP(Math::round(g * 255.0f), 0.0f, 255.0f)); } _FORCE_INLINE_ void set_b8(int32_t b8) { b = (CLAMP(b8, 0, 255) / 255.0); } - _FORCE_INLINE_ int32_t get_b8() const { return int32_t(CLAMP(b * 255.0, 0.0, 255.0)); } + _FORCE_INLINE_ int32_t get_b8() const { return int32_t(CLAMP(Math::round(b * 255.0f), 0.0f, 255.0f)); } _FORCE_INLINE_ void set_a8(int32_t a8) { a = (CLAMP(a8, 0, 255) / 255.0); } - _FORCE_INLINE_ int32_t get_a8() const { return int32_t(CLAMP(a * 255.0, 0.0, 255.0)); } + _FORCE_INLINE_ int32_t get_a8() const { return int32_t(CLAMP(Math::round(a * 255.0f), 0.0f, 255.0f)); } _FORCE_INLINE_ void set_h(float p_h) { set_hsv(p_h, get_s(), get_v()); } _FORCE_INLINE_ void set_s(float p_s) { set_hsv(get_h(), p_s, get_v()); } diff --git a/core/math/dynamic_bvh.cpp b/core/math/dynamic_bvh.cpp index 4639a52278..200095d8cb 100644 --- a/core/math/dynamic_bvh.cpp +++ b/core/math/dynamic_bvh.cpp @@ -61,7 +61,7 @@ DynamicBVH::Node *DynamicBVH::_create_node_with_volume(Node *p_parent, const Vol void DynamicBVH::_insert_leaf(Node *p_root, Node *p_leaf) { if (!bvh_root) { bvh_root = p_leaf; - p_leaf->parent = 0; + p_leaf->parent = nullptr; } else { if (!p_root->is_leaf()) { do { @@ -71,7 +71,7 @@ void DynamicBVH::_insert_leaf(Node *p_root, Node *p_leaf) { } while (!p_root->is_leaf()); } Node *prev = p_root->parent; - Node *node = _create_node_with_volume(prev, p_leaf->volume.merge(p_root->volume), 0); + Node *node = _create_node_with_volume(prev, p_leaf->volume.merge(p_root->volume), nullptr); if (prev) { prev->childs[p_root->get_index_in_parent()] = node; node->childs[0] = p_root; @@ -85,7 +85,7 @@ void DynamicBVH::_insert_leaf(Node *p_root, Node *p_leaf) { break; } node = prev; - } while (0 != (prev = node->parent)); + } while (nullptr != (prev = node->parent)); } else { node->childs[0] = p_root; p_root->parent = node; @@ -98,8 +98,8 @@ void DynamicBVH::_insert_leaf(Node *p_root, Node *p_leaf) { DynamicBVH::Node *DynamicBVH::_remove_leaf(Node *leaf) { if (leaf == bvh_root) { - bvh_root = 0; - return (0); + bvh_root = nullptr; + return (nullptr); } else { Node *parent = leaf->parent; Node *prev = parent->parent; @@ -113,13 +113,14 @@ DynamicBVH::Node *DynamicBVH::_remove_leaf(Node *leaf) { prev->volume = prev->childs[0]->volume.merge(prev->childs[1]->volume); if (pb.is_not_equal_to(prev->volume)) { prev = prev->parent; - } else + } else { break; + } } return (prev ? prev : bvh_root); } else { bvh_root = sibling; - sibling->parent = 0; + sibling->parent = nullptr; _delete_node(parent); return (bvh_root); } @@ -262,10 +263,11 @@ DynamicBVH::Node *DynamicBVH::_node_sort(Node *n, Node *&r) { Node *s = p->childs[j]; Node *q = p->parent; ERR_FAIL_COND_V(n != p->childs[i], nullptr); - if (q) + if (q) { q->childs[p->get_index_in_parent()] = n; - else + } else { r = n; + } s->parent = n; p->parent = n; n->parent = q; @@ -307,8 +309,9 @@ void DynamicBVH::optimize_top_down(int bu_threshold) { } void DynamicBVH::optimize_incremental(int passes) { - if (passes < 0) + if (passes < 0) { passes = total_leaves; + } if (bvh_root && (passes > 0)) { do { Node *node = bvh_root; @@ -345,8 +348,9 @@ void DynamicBVH::_update(Node *leaf, int lookahead) { for (int i = 0; (i < lookahead) && root->parent; ++i) { root = root->parent; } - } else + } else { root = bvh_root; + } } _insert_leaf(root, leaf); } @@ -370,8 +374,9 @@ bool DynamicBVH::update(const ID &p_id, const AABB &p_box) { for (int i = 0; (i < lkhd) && base->parent; ++i) { base = base->parent; } - } else + } else { base = bvh_root; + } } leaf->volume = volume; _insert_leaf(base, leaf); diff --git a/core/math/dynamic_bvh.h b/core/math/dynamic_bvh.h index c71db2d24d..0b6286cd9d 100644 --- a/core/math/dynamic_bvh.h +++ b/core/math/dynamic_bvh.h @@ -87,14 +87,16 @@ private: _FORCE_INLINE_ Volume merge(const Volume &b) const { Volume r; for (int i = 0; i < 3; ++i) { - if (min[i] < b.min[i]) + if (min[i] < b.min[i]) { r.min[i] = min[i]; - else + } else { r.min[i] = b.min[i]; - if (max[i] > b.max[i]) + } + if (max[i] > b.max[i]) { r.max[i] = max[i]; - else + } else { r.max[i] = b.max[i]; + } } return r; } @@ -202,10 +204,11 @@ private: // int count_leaves() const { - if (is_internal()) + if (is_internal()) { return childs[0]->count_leaves() + childs[1]->count_leaves(); - else + } else { return (1); + } } bool is_left_of_axis(const Vector3 &org, const Vector3 &axis) const { @@ -254,31 +257,37 @@ private: tymin = (bounds[raySign[1]].y - rayFrom.y) * rayInvDirection.y; tymax = (bounds[1 - raySign[1]].y - rayFrom.y) * rayInvDirection.y; - if ((tmin > tymax) || (tymin > tmax)) + if ((tmin > tymax) || (tymin > tmax)) { return false; + } - if (tymin > tmin) + if (tymin > tmin) { tmin = tymin; + } - if (tymax < tmax) + if (tymax < tmax) { tmax = tymax; + } tzmin = (bounds[raySign[2]].z - rayFrom.z) * rayInvDirection.z; tzmax = (bounds[1 - raySign[2]].z - rayFrom.z) * rayInvDirection.z; - if ((tmin > tzmax) || (tzmin > tmax)) + if ((tmin > tzmax) || (tzmin > tmax)) { return false; - if (tzmin > tmin) + } + if (tzmin > tmin) { tmin = tzmin; - if (tzmax < tmax) + } + if (tzmax < tmax) { tmax = tzmax; + } return ((tmin < lambda_max) && (tmax > lambda_min)); } public: // Methods void clear(); - bool is_empty() const { return (0 == bvh_root); } + bool is_empty() const { return (nullptr == bvh_root); } void optimize_bottom_up(); void optimize_top_down(int bu_threshold = 128); void optimize_incremental(int passes); @@ -334,7 +343,7 @@ void DynamicBVH::aabb_query(const AABB &p_box, QueryResult &r_result) { if (depth > threshold) { if (aux_stack.is_empty()) { aux_stack.resize(ALLOCA_STACK_SIZE * 2); - copymem(aux_stack.ptr(), stack, ALLOCA_STACK_SIZE * sizeof(const Node *)); + memcpy(aux_stack.ptr(), stack, ALLOCA_STACK_SIZE * sizeof(const Node *)); } else { aux_stack.resize(aux_stack.size() * 2); } @@ -390,7 +399,7 @@ void DynamicBVH::convex_query(const Plane *p_planes, int p_plane_count, const Ve if (depth > threshold) { if (aux_stack.is_empty()) { aux_stack.resize(ALLOCA_STACK_SIZE * 2); - copymem(aux_stack.ptr(), stack, ALLOCA_STACK_SIZE * sizeof(const Node *)); + memcpy(aux_stack.ptr(), stack, ALLOCA_STACK_SIZE * sizeof(const Node *)); } else { aux_stack.resize(aux_stack.size() * 2); } @@ -447,7 +456,7 @@ void DynamicBVH::ray_query(const Vector3 &p_from, const Vector3 &p_to, QueryResu if (depth > threshold) { if (aux_stack.is_empty()) { aux_stack.resize(ALLOCA_STACK_SIZE * 2); - copymem(aux_stack.ptr(), stack, ALLOCA_STACK_SIZE * sizeof(const Node *)); + memcpy(aux_stack.ptr(), stack, ALLOCA_STACK_SIZE * sizeof(const Node *)); } else { aux_stack.resize(aux_stack.size() * 2); } diff --git a/core/math/expression.cpp b/core/math/expression.cpp index 636ea601c7..f7ac44d321 100644 --- a/core/math/expression.cpp +++ b/core/math/expression.cpp @@ -978,7 +978,7 @@ Expression::ENode *Expression::_parse_expression() { } } - /* Reduce the set set of expressions and place them in an operator tree, respecting precedence */ + /* Reduce the set of expressions and place them in an operator tree, respecting precedence */ while (expression.size() > 1) { int next_op = -1; diff --git a/core/math/face3.cpp b/core/math/face3.cpp index beb0a8e405..20c316c322 100644 --- a/core/math/face3.cpp +++ b/core/math/face3.cpp @@ -169,7 +169,7 @@ Vector3 Face3::get_median_point() const { } real_t Face3::get_area() const { - return vec3_cross(vertex[0] - vertex[1], vertex[0] - vertex[2]).length(); + return vec3_cross(vertex[0] - vertex[1], vertex[0] - vertex[2]).length() * 0.5; } ClockDirection Face3::get_clock_dir() const { diff --git a/core/math/geometry_2d.cpp b/core/math/geometry_2d.cpp index d67be14d33..7b2630b4ff 100644 --- a/core/math/geometry_2d.cpp +++ b/core/math/geometry_2d.cpp @@ -87,9 +87,9 @@ struct _AtlasWorkRectResult { void Geometry2D::make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_result, Size2i &r_size) { // Super simple, almost brute force scanline stacking fitter. // It's pretty basic for now, but it tries to make sure that the aspect ratio of the - // resulting atlas is somehow square. This is necessary because video cards have limits. - // On texture size (usually 2048 or 4096), so the more square a texture, the more chances. - // It will work in every hardware. + // resulting atlas is somehow square. This is necessary because video cards have limits + // on texture size (usually 2048 or 4096), so the squarer a texture, the more the chances + // that it will work in every hardware. // For example, it will prioritize a 1024x1024 atlas (works everywhere) instead of a // 256x8192 atlas (won't work anywhere). @@ -358,7 +358,7 @@ Vector<Point2i> Geometry2D::pack_rects(const Vector<Size2i> &p_sizes, const Size Vector<Vector3i> Geometry2D::partial_pack_rects(const Vector<Vector2i> &p_sizes, const Size2i &p_atlas_size) { Vector<stbrp_node> nodes; nodes.resize(p_atlas_size.width); - zeromem(nodes.ptrw(), sizeof(stbrp_node) * nodes.size()); + memset(nodes.ptrw(), 0, sizeof(stbrp_node) * nodes.size()); stbrp_context context; stbrp_init_target(&context, p_atlas_size.width, p_atlas_size.height, nodes.ptrw(), p_atlas_size.width); diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index 267f6a4fe2..8cf13efdb6 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -103,6 +103,9 @@ public: static _ALWAYS_INLINE_ double log(double p_x) { return ::log(p_x); } static _ALWAYS_INLINE_ float log(float p_x) { return ::logf(p_x); } + static _ALWAYS_INLINE_ double log2(double p_x) { return ::log2(p_x); } + static _ALWAYS_INLINE_ float log2(float p_x) { return ::log2f(p_x); } + static _ALWAYS_INLINE_ double exp(double p_x) { return ::exp(p_x); } static _ALWAYS_INLINE_ float exp(float p_x) { return ::expf(p_x); } diff --git a/core/math/quat.cpp b/core/math/quat.cpp index a9a21a1ba3..6f13e04027 100644 --- a/core/math/quat.cpp +++ b/core/math/quat.cpp @@ -55,10 +55,13 @@ Vector3 Quat::get_euler_yxz() const { } void Quat::operator*=(const Quat &p_q) { - 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; + real_t xx = w * p_q.x + x * p_q.w + y * p_q.z - z * p_q.y; + real_t yy = w * p_q.y + y * p_q.w + z * p_q.x - x * p_q.z; + real_t zz = 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; + x = xx; + y = yy; + z = zz; } Quat Quat::operator*(const Quat &p_q) const { diff --git a/core/math/quick_hull.cpp b/core/math/quick_hull.cpp index ad28967d7a..fe18cc3d41 100644 --- a/core/math/quick_hull.cpp +++ b/core/math/quick_hull.cpp @@ -268,7 +268,7 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry3D::MeshData &r_ for (Map<Edge, FaceConnect>::Element *E = lit_edges.front(); E; E = E->next()) { FaceConnect &fc = E->get(); if (fc.left && fc.right) { - continue; //edge is uninteresting, not on horizont + continue; //edge is uninteresting, not on horizon } //create new face! diff --git a/core/math/random_pcg.cpp b/core/math/random_pcg.cpp index 9609620469..1152c4e834 100644 --- a/core/math/random_pcg.cpp +++ b/core/math/random_pcg.cpp @@ -39,7 +39,7 @@ RandomPCG::RandomPCG(uint64_t p_seed, uint64_t p_inc) : } void RandomPCG::randomize() { - seed(OS::get_singleton()->get_ticks_usec() * pcg.state + PCG_DEFAULT_INC_64); + seed((OS::get_singleton()->get_unix_time() + OS::get_singleton()->get_ticks_usec()) * pcg.state + PCG_DEFAULT_INC_64); } double RandomPCG::random(double p_from, double p_to) { diff --git a/core/math/transform.cpp b/core/math/transform.cpp index fab5d124fa..d4d7ff6d28 100644 --- a/core/math/transform.cpp +++ b/core/math/transform.cpp @@ -31,7 +31,6 @@ #include "transform.h" #include "core/math/math_funcs.h" -#include "core/os/copymem.h" #include "core/string/print_string.h" void Transform::affine_invert() { diff --git a/core/math/triangulate.cpp b/core/math/triangulate.cpp index 0047c0705d..fa1588dbc5 100644 --- a/core/math/triangulate.cpp +++ b/core/math/triangulate.cpp @@ -97,7 +97,7 @@ bool Triangulate::snip(const Vector<Vector2> &p_contour, int u, int v, int w, in // It can happen that the triangulation ends up with three aligned vertices to deal with. // In this scenario, making the check below strict may reject the possibility of - // forming a last triangle with these aligned vertices, preventing the triangulatiom + // forming a last triangle with these aligned vertices, preventing the triangulation // from completing. // To avoid that we allow zero-area triangles if all else failed. float threshold = relaxed ? -CMP_EPSILON : CMP_EPSILON; diff --git a/core/object/callable_method_pointer.h b/core/object/callable_method_pointer.h index 115797a00c..8ba01be4e4 100644 --- a/core/object/callable_method_pointer.h +++ b/core/object/callable_method_pointer.h @@ -32,7 +32,6 @@ #define CALLABLE_METHOD_POINTER_H #include "core/object/object.h" -#include "core/os/copymem.h" #include "core/templates/hashfuncs.h" #include "core/templates/simple_type.h" #include "core/variant/binder_common.h" @@ -98,7 +97,7 @@ public: } CallableCustomMethodPointer(T *p_instance, void (T::*p_method)(P...)) { - zeromem(&data, sizeof(Data)); // Clear beforehand, may have padding bytes. + memset(&data, 0, sizeof(Data)); // Clear beforehand, may have padding bytes. data.instance = p_instance; #ifdef DEBUG_ENABLED data.object_id = p_instance->get_instance_id(); @@ -153,7 +152,7 @@ public: } CallableCustomMethodPointerRet(T *p_instance, R (T::*p_method)(P...)) { - zeromem(&data, sizeof(Data)); // Clear beforehand, may have padding bytes. + memset(&data, 0, sizeof(Data)); // Clear beforehand, may have padding bytes. data.instance = p_instance; #ifdef DEBUG_ENABLED data.object_id = p_instance->get_instance_id(); @@ -208,7 +207,7 @@ public: } CallableCustomMethodPointerRetC(T *p_instance, R (T::*p_method)(P...) const) { - zeromem(&data, sizeof(Data)); // Clear beforehand, may have padding bytes. + memset(&data, 0, sizeof(Data)); // Clear beforehand, may have padding bytes. data.instance = p_instance; #ifdef DEBUG_ENABLED data.object_id = p_instance->get_instance_id(); diff --git a/core/object/class_db.cpp b/core/object/class_db.cpp index 375ad8fae1..fb7eb42738 100644 --- a/core/object/class_db.cpp +++ b/core/object/class_db.cpp @@ -1095,6 +1095,8 @@ bool ClassDB::get_property_info(StringName p_class, StringName p_property, Prope } bool ClassDB::set_property(Object *p_object, const StringName &p_property, const Variant &p_value, bool *r_valid) { + ERR_FAIL_NULL_V(p_object, false); + ClassInfo *type = classes.getptr(p_object->get_class_name()); ClassInfo *check = type; while (check) { @@ -1142,6 +1144,8 @@ bool ClassDB::set_property(Object *p_object, const StringName &p_property, const } bool ClassDB::get_property(Object *p_object, const StringName &p_property, Variant &r_value) { + ERR_FAIL_NULL_V(p_object, false); + ClassInfo *type = classes.getptr(p_object->get_class_name()); ClassInfo *check = type; while (check) { diff --git a/core/object/method_bind.h b/core/object/method_bind.h index 7cf4f8d4e8..7030ae201b 100644 --- a/core/object/method_bind.h +++ b/core/object/method_bind.h @@ -42,6 +42,7 @@ enum MethodFlags { METHOD_FLAG_VIRTUAL = 32, METHOD_FLAG_FROM_SCRIPT = 64, METHOD_FLAG_VARARG = 128, + METHOD_FLAG_STATIC = 256, METHOD_FLAGS_DEFAULT = METHOD_FLAG_NORMAL, }; diff --git a/core/object/object.cpp b/core/object/object.cpp index 1a9cce49d8..413f917518 100644 --- a/core/object/object.cpp +++ b/core/object/object.cpp @@ -596,7 +596,7 @@ void Object::get_property_list(List<PropertyInfo> *p_list, bool p_reversed) cons _get_property_listv(p_list, p_reversed); - if (!is_class("Script")) { // can still be set, but this is for userfriendlyness + if (!is_class("Script")) { // can still be set, but this is for user-friendliness p_list->push_back(PropertyInfo(Variant::OBJECT, "script", PROPERTY_HINT_RESOURCE_TYPE, "Script", PROPERTY_USAGE_DEFAULT)); } if (!metadata.is_empty()) { @@ -1671,7 +1671,7 @@ Variant::Type Object::get_static_property_type_indexed(const Vector<StringName> for (int i = 1; i < p_path.size(); i++) { if (check.get_type() == Variant::OBJECT || check.get_type() == Variant::DICTIONARY || check.get_type() == Variant::ARRAY) { - // We cannot be sure about the type of properties this types can have + // We cannot be sure about the type of properties this type can have if (r_valid) { *r_valid = false; } @@ -1719,10 +1719,10 @@ void *Object::get_script_instance_binding(int p_script_language_index) { ERR_FAIL_INDEX_V(p_script_language_index, MAX_SCRIPT_INSTANCE_BINDINGS, nullptr); #endif - //it's up to the script language to make this thread safe, if the function is called twice due to threads being out of syncro + //it's up to the script language to make this thread safe, if the function is called twice due to threads being out of sync //just return the same pointer. //if you want to put a big lock in the entire function and keep allocated pointers in a map or something, feel free to do it - //as it should not really affect performance much (won't be called too often), as in far most caes the condition below will be false afterwards + //as it should not really affect performance much (won't be called too often), as in far most cases the condition below will be false afterwards if (!_script_instance_bindings[p_script_language_index]) { void *script_data = ScriptServer::get_language(p_script_language_index)->alloc_instance_binding_data(this); diff --git a/core/object/object.h b/core/object/object.h index 029478873d..448a33d3bc 100644 --- a/core/object/object.h +++ b/core/object/object.h @@ -66,8 +66,10 @@ enum PropertyHint { PROPERTY_HINT_FLAGS, ///< hint_text= "flag1,flag2,etc" (as bit flags) PROPERTY_HINT_LAYERS_2D_RENDER, PROPERTY_HINT_LAYERS_2D_PHYSICS, + PROPERTY_HINT_LAYERS_2D_NAVIGATION, PROPERTY_HINT_LAYERS_3D_RENDER, PROPERTY_HINT_LAYERS_3D_PHYSICS, + PROPERTY_HINT_LAYERS_3D_NAVIGATION, PROPERTY_HINT_FILE, ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc," PROPERTY_HINT_DIR, ///< a directory path must be passed PROPERTY_HINT_GLOBAL_FILE, ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc," diff --git a/core/os/copymem.h b/core/os/copymem.h deleted file mode 100644 index 6fd559356c..0000000000 --- a/core/os/copymem.h +++ /dev/null @@ -1,50 +0,0 @@ -/*************************************************************************/ -/* copymem.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 COPYMEM_H -#define COPYMEM_H - -#include "core/typedefs.h" - -#ifdef PLATFORM_COPYMEM - -#include "platform_copymem.h" // included from platform/<current_platform>/platform_copymem.h" - -#else - -#include <string.h> - -#define copymem(to, from, count) memcpy(to, from, count) -#define zeromem(to, count) memset(to, 0, count) -#define movemem(to, from, count) memmove(to, from, count) - -#endif - -#endif // COPYMEM_H diff --git a/core/os/dir_access.h b/core/os/dir_access.h index c49c4cc4b8..7f0bcd372d 100644 --- a/core/os/dir_access.h +++ b/core/os/dir_access.h @@ -84,6 +84,8 @@ public: virtual bool file_exists(String p_file) = 0; virtual bool dir_exists(String p_dir) = 0; + virtual bool is_readable(String p_dir) { return true; }; + virtual bool is_writable(String p_dir) { return true; }; static bool exists(String p_dir); virtual size_t get_space_left() = 0; diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp index 5a3df88619..ad234c2d49 100644 --- a/core/os/file_access.cpp +++ b/core/os/file_access.cpp @@ -368,6 +368,8 @@ Vector<String> FileAccess::get_csv_line(const String &p_delim) const { } int FileAccess::get_buffer(uint8_t *p_dst, int p_length) const { + ERR_FAIL_COND_V(!p_dst && p_length > 0, -1); + ERR_FAIL_COND_V(p_length < 0, -1); int i = 0; for (i = 0; i < p_length && !eof_reached(); i++) { p_dst[i] = get_8(); diff --git a/core/os/keyboard.h b/core/os/keyboard.h index 3ef70e786f..f6fe5fc070 100644 --- a/core/os/keyboard.h +++ b/core/os/keyboard.h @@ -45,7 +45,7 @@ enum { SPKEY = (1 << 24) }; -enum KeyList { +enum Key { /* CURSOR/FUNCTION/BROWSER/MULTIMEDIA/MISC KEYS */ KEY_ESCAPE = SPKEY | 0x01, KEY_TAB = SPKEY | 0x02, diff --git a/core/os/memory.cpp b/core/os/memory.cpp index 5910cb0e7b..a756c1d5dd 100644 --- a/core/os/memory.cpp +++ b/core/os/memory.cpp @@ -31,7 +31,6 @@ #include "memory.h" #include "core/error/error_macros.h" -#include "core/os/copymem.h" #include "core/templates/safe_refcount.h" #include <stdio.h> diff --git a/core/os/os.cpp b/core/os/os.cpp index 182bab4058..ca1b798e11 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -106,10 +106,18 @@ void OS::add_logger(Logger *p_logger) { } void OS::print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, Logger::ErrorType p_type) { + if (!_stderr_enabled) { + return; + } + _logger->log_error(p_function, p_file, p_line, p_code, p_rationale, p_type); } void OS::print(const char *p_format, ...) { + if (!_stdout_enabled) { + return; + } + va_list argp; va_start(argp, p_format); @@ -119,6 +127,10 @@ void OS::print(const char *p_format, ...) { } void OS::printerr(const char *p_format, ...) { + if (!_stderr_enabled) { + return; + } + va_list argp; va_start(argp, p_format); @@ -163,6 +175,22 @@ bool OS::is_stdout_debug_enabled() const { return _debug_stdout; } +bool OS::is_stdout_enabled() const { + return _stdout_enabled; +} + +bool OS::is_stderr_enabled() const { + return _stderr_enabled; +} + +void OS::set_stdout_enabled(bool p_enabled) { + _stdout_enabled = p_enabled; +} + +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); } diff --git a/core/os/os.h b/core/os/os.h index e41d788e12..7198607237 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -60,6 +60,8 @@ class OS { bool _allow_layered = false; bool _use_vsync; bool _vsync_via_compositor; + bool _stdout_enabled = true; + bool _stderr_enabled = true; char *last_error; @@ -219,6 +221,11 @@ public: bool is_stdout_verbose() const; bool is_stdout_debug_enabled() const; + bool is_stdout_enabled() const; + bool is_stderr_enabled() const; + void set_stdout_enabled(bool p_enabled); + void set_stderr_enabled(bool p_enabled); + virtual void disable_crash_handler() {} virtual bool is_disable_crash_handler() const { return false; } virtual void initialize_debugging() {} diff --git a/core/os/pool_allocator.cpp b/core/os/pool_allocator.cpp index b538ca0c96..74e9c24e04 100644 --- a/core/os/pool_allocator.cpp +++ b/core/os/pool_allocator.cpp @@ -31,7 +31,6 @@ #include "pool_allocator.h" #include "core/error/error_macros.h" -#include "core/os/copymem.h" #include "core/os/memory.h" #include "core/os/os.h" #include "core/string/print_string.h" @@ -42,7 +41,7 @@ do { \ void *_dst = &((unsigned char *)pool)[m_to_pos]; \ void *_src = &((unsigned char *)pool)[(m_entry).pos]; \ - movemem(_dst, _src, aligned((m_entry).len)); \ + memmove(_dst, _src, aligned((m_entry).len)); \ (m_entry).pos = m_to_pos; \ } while (0); @@ -136,7 +135,7 @@ void PoolAllocator::compact_up(int p_from) { for (int i = entry_count - 1; i >= p_from; i--) { Entry &entry = entry_array[entry_indices[i]]; - /* determine hole size to nextious entry */ + /* determine hole size for next entry */ int hole_size = next_entry_end_pos - (entry.pos + aligned(entry.len)); diff --git a/core/os/thread.cpp b/core/os/thread.cpp index aea370787d..73e31bdb3d 100644 --- a/core/os/thread.cpp +++ b/core/os/thread.cpp @@ -41,9 +41,13 @@ 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; -SafeNumeric<Thread::ID> Thread::last_thread_id{ 1 }; -thread_local Thread::ID Thread::caller_id = 1; +uint64_t Thread::_thread_id_hash(const std::thread::id &p_t) { + static std::hash<std::thread::id> hasher; + return hasher(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 &), @@ -57,7 +61,7 @@ void Thread::_set_platform_funcs( } void Thread::callback(Thread *p_self, const Settings &p_settings, Callback p_callback, void *p_userdata) { - Thread::caller_id = p_self->id; + Thread::caller_id = _thread_id_hash(p_self->thread.get_id()); if (set_priority_func) { set_priority_func(p_settings.priority); } @@ -73,7 +77,7 @@ void Thread::callback(Thread *p_self, const Settings &p_settings, Callback p_cal } void Thread::start(Thread::Callback p_callback, void *p_user, const Settings &p_settings) { - if (id != 0) { + if (id != _thread_id_hash(std::thread::id())) { #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 @@ -81,22 +85,22 @@ void Thread::start(Thread::Callback p_callback, void *p_user, const Settings &p_ std::thread empty_thread; thread.swap(empty_thread); } - id = last_thread_id.increment(); std::thread new_thread(&Thread::callback, this, p_settings, p_callback, p_user); thread.swap(new_thread); + id = _thread_id_hash(thread.get_id()); } bool Thread::is_started() const { - return id != 0; + return id != _thread_id_hash(std::thread::id()); } void Thread::wait_to_finish() { - if (id != 0) { + if (id != _thread_id_hash(std::thread::id())) { ERR_FAIL_COND_MSG(id == get_caller_id(), "A Thread can't wait for itself to finish."); thread.join(); std::thread empty_thread; thread.swap(empty_thread); - id = 0; + id = _thread_id_hash(std::thread::id()); } } @@ -108,8 +112,12 @@ Error Thread::set_name(const String &p_name) { return ERR_UNAVAILABLE; } +Thread::Thread() { + caller_id = _thread_id_hash(std::this_thread::get_id()); +} + Thread::~Thread() { - if (id != 0) { + if (id != _thread_id_hash(std::thread::id())) { #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 diff --git a/core/os/thread.h b/core/os/thread.h index 76f5be182e..17ac82c650 100644 --- a/core/os/thread.h +++ b/core/os/thread.h @@ -62,9 +62,10 @@ private: friend class Main; static ID main_thread_id; - static SafeNumeric<Thread::ID> last_thread_id; - ID id = 0; + static uint64_t _thread_id_hash(const std::thread::id &p_t); + + ID id = _thread_id_hash(std::thread::id()); static thread_local ID caller_id; std::thread thread; @@ -97,6 +98,7 @@ public: ///< waits until thread is finished, and deallocates it. void wait_to_finish(); + Thread(); ~Thread(); #else _FORCE_INLINE_ ID get_id() const { return 0; } diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp index b58abc81d1..d6a5eff10d 100644 --- a/core/register_core_types.cpp +++ b/core/register_core_types.cpp @@ -68,7 +68,7 @@ #include "core/object/class_db.h" #include "core/object/undo_redo.h" #include "core/os/main_loop.h" -#include "core/string/compressed_translation.h" +#include "core/string/optimized_translation.h" #include "core/string/translation.h" static Ref<ResourceFormatSaverBinary> resource_saver_binary; @@ -183,7 +183,7 @@ void register_core_types() { ClassDB::register_class<MultiplayerAPI>(); ClassDB::register_class<MainLoop>(); ClassDB::register_class<Translation>(); - ClassDB::register_class<PHashTranslation>(); + ClassDB::register_class<OptimizedTranslation>(); ClassDB::register_class<UndoRedo>(); ClassDB::register_class<HTTPClient>(); ClassDB::register_class<TriangleMesh>(); diff --git a/core/string/node_path.h b/core/string/node_path.h index 26e15636d9..a277ab26fa 100644 --- a/core/string/node_path.h +++ b/core/string/node_path.h @@ -66,8 +66,6 @@ public: void prepend_period(); - NodePath get_parent() const; - _FORCE_INLINE_ uint32_t hash() const { if (!data) { return 0; diff --git a/core/string/compressed_translation.cpp b/core/string/optimized_translation.cpp index ad90924293..53d0a8924d 100644 --- a/core/string/compressed_translation.cpp +++ b/core/string/optimized_translation.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* compressed_translation.cpp */ +/* optimized_translation.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "compressed_translation.h" +#include "optimized_translation.h" #include "core/templates/pair.h" @@ -36,15 +36,15 @@ extern "C" { #include "thirdparty/misc/smaz.h" } -struct _PHashTranslationCmp { +struct CompressedString { int orig_len; CharString compressed; int offset; }; -void PHashTranslation::generate(const Ref<Translation> &p_from) { +void OptimizedTranslation::generate(const Ref<Translation> &p_from) { // This method compresses a Translation instance. - // Right now it doesn't handle context or plurals, so Translation subclasses using plurals or context (i.e TranslationPO) shouldn't be compressed. + // Right now, it doesn't handle context or plurals, so Translation subclasses using plurals or context (i.e TranslationPO) shouldn't be compressed. #ifdef TOOLS_ENABLED List<StringName> keys; p_from->get_message_list(&keys); @@ -54,7 +54,7 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) { Vector<Vector<Pair<int, CharString>>> buckets; Vector<Map<uint32_t, int>> table; Vector<uint32_t> hfunc_table; - Vector<_PHashTranslationCmp> compressed; + Vector<CompressedString> compressed; table.resize(size); hfunc_table.resize(size); @@ -76,7 +76,7 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) { //compress string CharString src_s = p_from->get_message(E->get()).operator String().utf8(); - _PHashTranslationCmp ps; + CompressedString ps; ps.orig_len = src_s.size(); ps.offset = total_compression_size; @@ -182,7 +182,7 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) { #endif } -bool PHashTranslation::_set(const StringName &p_name, const Variant &p_value) { +bool OptimizedTranslation::_set(const StringName &p_name, const Variant &p_value) { String name = p_name.operator String(); if (name == "hash_table") { hash_table = p_value; @@ -199,7 +199,7 @@ bool PHashTranslation::_set(const StringName &p_name, const Variant &p_value) { return true; } -bool PHashTranslation::_get(const StringName &p_name, Variant &r_ret) const { +bool OptimizedTranslation::_get(const StringName &p_name, Variant &r_ret) const { String name = p_name.operator String(); if (name == "hash_table") { r_ret = hash_table; @@ -214,8 +214,8 @@ bool PHashTranslation::_get(const StringName &p_name, Variant &r_ret) const { return true; } -StringName PHashTranslation::get_message(const StringName &p_src_text, const StringName &p_context) const { - // p_context passed in is ignore. The use of context is not yet supported in PHashTranslation. +StringName OptimizedTranslation::get_message(const StringName &p_src_text, const StringName &p_context) const { + // p_context passed in is ignore. The use of context is not yet supported in OptimizedTranslation. int htsize = hash_table.size(); @@ -271,18 +271,18 @@ StringName PHashTranslation::get_message(const StringName &p_src_text, const Str } } -StringName PHashTranslation::get_plural_message(const StringName &p_src_text, const StringName &p_plural_text, int p_n, const StringName &p_context) const { - // The use of plurals translation is not yet supported in PHashTranslation. +StringName OptimizedTranslation::get_plural_message(const StringName &p_src_text, const StringName &p_plural_text, int p_n, const StringName &p_context) const { + // The use of plurals translation is not yet supported in OptimizedTranslation. return get_message(p_src_text, p_context); } -void PHashTranslation::_get_property_list(List<PropertyInfo> *p_list) const { +void OptimizedTranslation::_get_property_list(List<PropertyInfo> *p_list) const { p_list->push_back(PropertyInfo(Variant::PACKED_INT32_ARRAY, "hash_table")); p_list->push_back(PropertyInfo(Variant::PACKED_INT32_ARRAY, "bucket_table")); p_list->push_back(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "strings")); p_list->push_back(PropertyInfo(Variant::OBJECT, "load_from", PROPERTY_HINT_RESOURCE_TYPE, "Translation", PROPERTY_USAGE_EDITOR)); } -void PHashTranslation::_bind_methods() { - ClassDB::bind_method(D_METHOD("generate", "from"), &PHashTranslation::generate); +void OptimizedTranslation::_bind_methods() { + ClassDB::bind_method(D_METHOD("generate", "from"), &OptimizedTranslation::generate); } diff --git a/core/string/compressed_translation.h b/core/string/optimized_translation.h index 0abb770178..bccf932383 100644 --- a/core/string/compressed_translation.h +++ b/core/string/optimized_translation.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* compressed_translation.h */ +/* optimized_translation.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,13 +28,13 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef COMPRESSED_TRANSLATION_H -#define COMPRESSED_TRANSLATION_H +#ifndef OPTIMIZED_TRANSLATION_H +#define OPTIMIZED_TRANSLATION_H #include "core/string/translation.h" -class PHashTranslation : public Translation { - GDCLASS(PHashTranslation, Translation); +class OptimizedTranslation : public Translation { + GDCLASS(OptimizedTranslation, Translation); //this translation uses a sort of modified perfect hash algorithm //it requires hashing strings twice and then does a binary search, @@ -83,7 +83,7 @@ public: virtual StringName get_plural_message(const StringName &p_src_text, const StringName &p_plural_text, int p_n, const StringName &p_context = "") const override; void generate(const Ref<Translation> &p_from); - PHashTranslation() {} + OptimizedTranslation() {} }; -#endif // COMPRESSED_TRANSLATION_H +#endif // OPTIMIZED_TRANSLATION_H diff --git a/core/string/translation.cpp b/core/string/translation.cpp index 9cee218735..153f0190fd 100644 --- a/core/string/translation.cpp +++ b/core/string/translation.cpp @@ -835,7 +835,7 @@ Vector<String> Translation::_get_message_list() const { void Translation::_set_messages(const Dictionary &p_messages) { List<Variant> keys; p_messages.get_key_list(&keys); - for (auto E = keys.front(); E; E = E->next()) { + for (List<Variant>::Element *E = keys.front(); E; E = E->next()) { translation_map[E->get()] = p_messages[E->get()]; } } @@ -853,7 +853,7 @@ void Translation::set_locale(const String &p_locale) { locale = univ_locale; } - if (OS::get_singleton()->get_main_loop()) { + if (OS::get_singleton()->get_main_loop() && TranslationServer::get_singleton()->get_loaded_locales().has(this)) { OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_TRANSLATION_CHANGED); } } diff --git a/core/string/translation_po.cpp b/core/string/translation_po.cpp index 846afe761b..ad768f7140 100644 --- a/core/string/translation_po.cpp +++ b/core/string/translation_po.cpp @@ -47,14 +47,14 @@ void TranslationPO::print_translation_map() { List<StringName> context_l; translation_map.get_key_list(&context_l); - for (auto E = context_l.front(); E; E = E->next()) { + for (List<StringName>::Element *E = context_l.front(); E; E = E->next()) { StringName ctx = E->get(); file->store_line(" ===== Context: " + String::utf8(String(ctx).utf8()) + " ===== "); const HashMap<StringName, Vector<StringName>> &inner_map = translation_map[ctx]; List<StringName> id_l; inner_map.get_key_list(&id_l); - for (auto E2 = id_l.front(); E2; E2 = E2->next()) { + for (List<StringName>::Element *E2 = id_l.front(); E2; E2 = E2->next()) { StringName id = E2->get(); file->store_line("msgid: " + String::utf8(String(id).utf8())); for (int i = 0; i < inner_map[id].size(); i++) { @@ -74,7 +74,7 @@ Dictionary TranslationPO::_get_messages() const { List<StringName> context_l; translation_map.get_key_list(&context_l); - for (auto E = context_l.front(); E; E = E->next()) { + for (List<StringName>::Element *E = context_l.front(); E; E = E->next()) { StringName ctx = E->get(); const HashMap<StringName, Vector<StringName>> &id_str_map = translation_map[ctx]; @@ -82,7 +82,7 @@ Dictionary TranslationPO::_get_messages() const { List<StringName> id_l; id_str_map.get_key_list(&id_l); // Save list of id and strs associated with a context in a temporary dictionary. - for (auto E2 = id_l.front(); E2; E2 = E2->next()) { + for (List<StringName>::Element *E2 = id_l.front(); E2; E2 = E2->next()) { StringName id = E2->get(); d2[id] = id_str_map[id]; } @@ -98,14 +98,14 @@ void TranslationPO::_set_messages(const Dictionary &p_messages) { List<Variant> context_l; p_messages.get_key_list(&context_l); - for (auto E = context_l.front(); E; E = E->next()) { + for (List<Variant>::Element *E = context_l.front(); E; E = E->next()) { StringName ctx = E->get(); const Dictionary &id_str_map = p_messages[ctx]; HashMap<StringName, Vector<StringName>> temp_map; List<Variant> id_l; id_str_map.get_key_list(&id_l); - for (auto E2 = id_l.front(); E2; E2 = E2->next()) { + for (List<Variant>::Element *E2 = id_l.front(); E2; E2 = E2->next()) { StringName id = E2->get(); temp_map[id] = id_str_map[id]; } @@ -121,7 +121,7 @@ Vector<String> TranslationPO::_get_message_list() const { get_message_list(&msgs); Vector<String> v; - for (auto E = msgs.front(); E; E = E->next()) { + for (List<StringName>::Element *E = msgs.front(); E; E = E->next()) { v.push_back(E->get()); } @@ -158,7 +158,7 @@ int TranslationPO::_get_plural_index(int p_n) const { void TranslationPO::_cache_plural_tests(const String &p_plural_rule) { // Some examples of p_plural_rule passed in can have the form: // "n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 && n%100<=99 ? 4 : 5" (Arabic) - // "n >= 2" (French) // When evaluating the last, esp careful with this one. + // "n >= 2" (French) // When evaluating the last, especially careful with this one. // "n != 1" (English) int first_ques_mark = p_plural_rule.find("?"); if (first_ques_mark == -1) { @@ -275,13 +275,13 @@ void TranslationPO::erase_message(const StringName &p_src_text, const StringName } void TranslationPO::get_message_list(List<StringName> *r_messages) const { - // PHashTranslation uses this function to get the list of msgid. + // OptimizedTranslation uses this function to get the list of msgid. // Return all the keys of translation_map under "" context. List<StringName> context_l; translation_map.get_key_list(&context_l); - for (auto E = context_l.front(); E; E = E->next()) { + for (List<StringName>::Element *E = context_l.front(); E; E = E->next()) { if (String(E->get()) != "") { continue; } @@ -289,7 +289,7 @@ void TranslationPO::get_message_list(List<StringName> *r_messages) const { List<StringName> msgid_l; translation_map[E->get()].get_key_list(&msgid_l); - for (auto E2 = msgid_l.front(); E2; E2 = E2->next()) { + for (List<StringName>::Element *E2 = msgid_l.front(); E2; E2 = E2->next()) { r_messages->push_back(E2->get()); } } @@ -300,7 +300,7 @@ int TranslationPO::get_message_count() const { translation_map.get_key_list(&context_l); int count = 0; - for (auto E = context_l.front(); E; E = E->next()) { + for (List<StringName>::Element *E = context_l.front(); E; E = E->next()) { count += translation_map[E->get()].size(); } return count; diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index a57c7b2504..c8d71c3236 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -1138,7 +1138,7 @@ Vector<String> String::rsplit(const String &p_splitter, bool p_allow_empty, int remaining_len = left_edge; } - ret.invert(); + ret.reverse(); return ret; } @@ -1764,7 +1764,7 @@ bool String::parse_utf8(const char *p_utf8, int p_len) { if (skip) { _UNICERROR("no space left"); - return true; //not enough spac + return true; //not enough space } } @@ -3772,9 +3772,9 @@ String String::uri_encode() const { } else { char h_Val[3]; #if defined(__GNUC__) || defined(_MSC_VER) - snprintf(h_Val, 3, "%hhX", ord); + snprintf(h_Val, 3, "%02hhX", ord); #else - sprintf(h_Val, "%hhX", ord); + sprintf(h_Val, "%02hhX", ord); #endif res += "%"; res += h_Val; @@ -4394,6 +4394,18 @@ String String::property_name_encode() const { return *this; } +// Changes made to the set of invalid characters must also be reflected in the String documentation. +const String String::invalid_node_name_characters = ". : @ / \""; + +String String::validate_node_name() const { + Vector<String> chars = String::invalid_node_name_characters.split(" "); + String name = this->replace(chars[0], ""); + for (int i = 1; i < chars.size(); i++) { + name = name.replace(chars[i], ""); + } + return name; +} + String String::get_basename() const { int pos = rfind("."); if (pos < 0 || pos < MAX(rfind("/"), rfind("\\"))) { @@ -4468,7 +4480,7 @@ String String::sprintf(const Array &values, bool *error) const { for (; *self; self++) { const char32_t c = *self; - if (in_format) { // We have % - lets see what else we get. + if (in_format) { // We have % - let's see what else we get. switch (c) { case '%': { // Replace %% with % formatted += chr(c); @@ -4753,7 +4765,7 @@ Vector<uint8_t> String::to_ascii_buffer() const { size_t len = charstr.length(); retval.resize(len); uint8_t *w = retval.ptrw(); - copymem(w, charstr.ptr(), len); + memcpy(w, charstr.ptr(), len); return retval; } @@ -4769,7 +4781,7 @@ Vector<uint8_t> String::to_utf8_buffer() const { size_t len = charstr.length(); retval.resize(len); uint8_t *w = retval.ptrw(); - copymem(w, charstr.ptr(), len); + memcpy(w, charstr.ptr(), len); return retval; } @@ -4785,7 +4797,7 @@ Vector<uint8_t> String::to_utf16_buffer() const { size_t len = charstr.length() * sizeof(char16_t); retval.resize(len); uint8_t *w = retval.ptrw(); - copymem(w, (const void *)charstr.ptr(), len); + memcpy(w, (const void *)charstr.ptr(), len); return retval; } @@ -4800,7 +4812,7 @@ Vector<uint8_t> String::to_utf32_buffer() const { size_t len = s->length() * sizeof(char32_t); retval.resize(len); uint8_t *w = retval.ptrw(); - copymem(w, (const void *)s->ptr(), len); + memcpy(w, (const void *)s->ptr(), len); return retval; } diff --git a/core/string/ustring.h b/core/string/ustring.h index 821941036f..1e362d7683 100644 --- a/core/string/ustring.h +++ b/core/string/ustring.h @@ -419,6 +419,10 @@ public: String property_name_encode() const; + // node functions + static const String invalid_node_name_characters; + String validate_node_name() const; + bool is_valid_identifier() const; bool is_valid_integer() const; bool is_valid_float() const; diff --git a/core/templates/list.h b/core/templates/list.h index eaf1dbb4a0..010e35eed8 100644 --- a/core/templates/list.h +++ b/core/templates/list.h @@ -492,7 +492,7 @@ public: _data->last = p_I; } - void invert() { + void reverse() { int s = size() / 2; Element *F = front(); Element *B = back(); diff --git a/core/templates/local_vector.h b/core/templates/local_vector.h index ffd17b7ee9..5f22e08eb8 100644 --- a/core/templates/local_vector.h +++ b/core/templates/local_vector.h @@ -32,7 +32,6 @@ #define LOCAL_VECTOR_H #include "core/error/error_macros.h" -#include "core/os/copymem.h" #include "core/os/memory.h" #include "core/templates/sort_array.h" #include "core/templates/vector.h" @@ -216,7 +215,7 @@ public: Vector<T> ret; ret.resize(size()); T *w = ret.ptrw(); - copymem(w, data, sizeof(T) * count); + memcpy(w, data, sizeof(T) * count); return ret; } @@ -224,7 +223,7 @@ public: Vector<uint8_t> ret; ret.resize(count * sizeof(T)); uint8_t *w = ret.ptrw(); - copymem(w, data, sizeof(T) * count); + memcpy(w, data, sizeof(T) * count); return ret; } diff --git a/core/templates/map.h b/core/templates/map.h index 51a237472d..7dfee13d2c 100644 --- a/core/templates/map.h +++ b/core/templates/map.h @@ -32,7 +32,7 @@ #define MAP_H #include "core/error/error_macros.h" -#include "core/templates/set.h" +#include "core/os/memory.h" // based on the very nice implementation of rb-trees by: // https://web.archive.org/web/20120507164830/http://web.mit.edu/~emin/www/source_code/red_black_tree/index.html diff --git a/core/templates/oa_hash_map.h b/core/templates/oa_hash_map.h index 1d4176eb10..2c7c64cd78 100644 --- a/core/templates/oa_hash_map.h +++ b/core/templates/oa_hash_map.h @@ -32,7 +32,6 @@ #define OA_HASH_MAP_H #include "core/math/math_funcs.h" -#include "core/os/copymem.h" #include "core/os/memory.h" #include "core/templates/hashfuncs.h" diff --git a/core/templates/safe_refcount.h b/core/templates/safe_refcount.h index 91a34ecd54..e9e5695f80 100644 --- a/core/templates/safe_refcount.h +++ b/core/templates/safe_refcount.h @@ -36,6 +36,7 @@ #if !defined(NO_THREADS) #include <atomic> +#include <type_traits> // Design goals for these classes: // - No automatic conversions or arithmetic operators, diff --git a/core/templates/thread_work_pool.h b/core/templates/thread_work_pool.h index 19ab1dda3a..9f7a692cc5 100644 --- a/core/templates/thread_work_pool.h +++ b/core/templates/thread_work_pool.h @@ -83,7 +83,7 @@ public: ERR_FAIL_COND(!threads); //never initialized ERR_FAIL_COND(current_work != nullptr); - index.store(0); + index.store(0, std::memory_order_release); Work<C, M, U> *w = memnew((Work<C, M, U>)); w->instance = p_instance; @@ -104,8 +104,15 @@ public: return current_work != nullptr; } + bool is_done_dispatching() const { + ERR_FAIL_COND_V(current_work == nullptr, false); + return index.load(std::memory_order_acquire) >= current_work->max_elements; + } + uint32_t get_work_index() const { - return index; + ERR_FAIL_COND_V(current_work == nullptr, 0); + uint32_t idx = index.load(std::memory_order_acquire); + return MIN(idx, current_work->max_elements); } void end_work() { diff --git a/core/templates/vector.h b/core/templates/vector.h index 6a8902707c..dae8874a87 100644 --- a/core/templates/vector.h +++ b/core/templates/vector.h @@ -38,7 +38,6 @@ */ #include "core/error/error_macros.h" -#include "core/os/copymem.h" #include "core/os/memory.h" #include "core/templates/cowdata.h" #include "core/templates/sort_array.h" @@ -66,6 +65,7 @@ private: public: bool push_back(T p_elem); _FORCE_INLINE_ bool append(const T &p_elem) { return push_back(p_elem); } //alias + void fill(T p_elem); void remove(int p_index) { _cowdata.remove(p_index); } void erase(const T &p_val) { @@ -74,7 +74,7 @@ public: remove(idx); } } - void invert(); + void reverse(); _FORCE_INLINE_ T *ptrw() { return _cowdata.ptrw(); } _FORCE_INLINE_ const T *ptr() const { return _cowdata.ptr(); } @@ -134,7 +134,7 @@ public: Vector<uint8_t> to_byte_array() const { Vector<uint8_t> ret; ret.resize(size() * sizeof(T)); - copymem(ret.ptrw(), ptr(), sizeof(T) * size()); + memcpy(ret.ptrw(), ptr(), sizeof(T) * size()); return ret; } @@ -194,7 +194,7 @@ public: }; template <class T> -void Vector<T>::invert() { +void Vector<T>::reverse() { for (int i = 0; i < size() / 2; i++) { T *p = ptrw(); SWAP(p[i], p[size() - i - 1]); @@ -223,4 +223,12 @@ bool Vector<T>::push_back(T p_elem) { return false; } +template <class T> +void Vector<T>::fill(T p_elem) { + T *p = ptrw(); + for (int i = 0; i < size(); i++) { + p[i] = p_elem; + } +} + #endif // VECTOR_H diff --git a/core/variant/array.cpp b/core/variant/array.cpp index 9a2922a777..2fb2dd4a30 100644 --- a/core/variant/array.cpp +++ b/core/variant/array.cpp @@ -139,9 +139,9 @@ uint32_t Array::hash() const { return h; } -void Array::_assign(const Array &p_array) { +bool Array::_assign(const Array &p_array) { if (_p->typed.type != Variant::OBJECT && _p->typed.type == p_array._p->typed.type) { - //same type or untyped, just reference, shuold be fine + //same type or untyped, just reference, should be fine _ref(p_array); } else if (_p->typed.type == Variant::NIL) { //from typed to untyped, must copy, but this is cheap anyway _p->array = p_array._p->array; @@ -150,7 +150,7 @@ void Array::_assign(const Array &p_array) { //for objects, it needs full validation, either can be converted or fail for (int i = 0; i < p_array._p->array.size(); i++) { if (!_p->typed.validate(p_array._p->array[i], "assign")) { - return; + return false; } } _p->array = p_array._p->array; //then just copy, which is cheap anyway @@ -168,10 +168,10 @@ void Array::_assign(const Array &p_array) { Callable::CallError ce; Variant::construct(_p->typed.type, new_array.write[i], (const Variant **)&ptr, 1, ce); if (ce.error != Callable::CallError::CALL_OK) { - ERR_FAIL_MSG("Unable to convert array index " + itos(i) + " from '" + Variant::get_type_name(src_val.get_type()) + "' to '" + Variant::get_type_name(_p->typed.type) + "'."); + ERR_FAIL_V_MSG(false, "Unable to convert array index " + itos(i) + " from '" + Variant::get_type_name(src_val.get_type()) + "' to '" + Variant::get_type_name(_p->typed.type) + "'."); } } else { - ERR_FAIL_MSG("Unable to convert array index " + itos(i) + " from '" + Variant::get_type_name(src_val.get_type()) + "' to '" + Variant::get_type_name(_p->typed.type) + "'."); + ERR_FAIL_V_MSG(false, "Unable to convert array index " + itos(i) + " from '" + Variant::get_type_name(src_val.get_type()) + "' to '" + Variant::get_type_name(_p->typed.type) + "'."); } } @@ -180,12 +180,13 @@ void Array::_assign(const Array &p_array) { } else if (_p->typed.can_reference(p_array._p->typed)) { //same type or compatible _ref(p_array); } else { - ERR_FAIL_MSG("Assignment of arrays of incompatible types."); + ERR_FAIL_V_MSG(false, "Assignment of arrays of incompatible types."); } + return true; } void Array::operator=(const Array &p_array) { - _assign(p_array); + _ref(p_array); } void Array::push_back(const Variant &p_value) { @@ -207,6 +208,11 @@ void Array::insert(int p_pos, const Variant &p_value) { _p->array.insert(p_pos, p_value); } +void Array::fill(const Variant &p_value) { + ERR_FAIL_COND(!_p->typed.validate(p_value, "fill")); + _p->array.fill(p_value); +} + void Array::erase(const Variant &p_value) { ERR_FAIL_COND(!_p->typed.validate(p_value, "erase")); _p->array.erase(p_value); @@ -445,8 +451,8 @@ int Array::bsearch_custom(const Variant &p_value, Callable p_callable, bool p_be return bisect(_p->array, p_value, p_before, less); } -void Array::invert() { - _p->array.invert(); +void Array::reverse() { + _p->array.reverse(); } void Array::push_front(const Variant &p_value) { @@ -528,6 +534,10 @@ Array::Array(const Array &p_from, uint32_t p_type, const StringName &p_class_nam _assign(p_from); } +bool Array::typed_assign(const Array &p_other) { + return _assign(p_other); +} + void Array::set_typed(uint32_t p_type, const StringName &p_class_name, const Variant &p_script) { ERR_FAIL_COND_MSG(_p->array.size() > 0, "Type can only be set when array is empty."); ERR_FAIL_COND_MSG(_p->refcount.get() > 1, "Type can only be set when array has no more than one user."); @@ -542,6 +552,22 @@ void Array::set_typed(uint32_t p_type, const StringName &p_class_name, const Var _p->typed.where = "TypedArray"; } +bool Array::is_typed() const { + return _p->typed.type != Variant::NIL; +} + +uint32_t Array::get_typed_builtin() const { + return _p->typed.type; +} + +StringName Array::get_typed_class_name() const { + return _p->typed.class_name; +} + +Variant Array::get_typed_script() const { + return _p->typed.script; +} + Array::Array(const Array &p_from) { _p = nullptr; _ref(p_from); diff --git a/core/variant/array.h b/core/variant/array.h index d8f2402330..5ce977ee4b 100644 --- a/core/variant/array.h +++ b/core/variant/array.h @@ -48,7 +48,7 @@ class Array { protected: Array(const Array &p_base, uint32_t p_type, const StringName &p_class_name, const Variant &p_script); - void _assign(const Array &p_array); + bool _assign(const Array &p_array); public: Variant &operator[](int p_idx); @@ -74,6 +74,7 @@ public: void insert(int p_pos, const Variant &p_value); void remove(int p_pos); + void fill(const Variant &p_value); Variant front() const; Variant back() const; @@ -83,7 +84,7 @@ public: void shuffle(); int bsearch(const Variant &p_value, bool p_before = true); int bsearch_custom(const Variant &p_value, Callable p_callable, bool p_before = true); - void invert(); + void reverse(); int find(const Variant &p_value, int p_from = 0) const; int rfind(const Variant &p_value, int p_from = -1) const; @@ -111,7 +112,12 @@ public: const void *id() const; + bool typed_assign(const Array &p_other); void set_typed(uint32_t p_type, const StringName &p_class_name, const Variant &p_script); + bool is_typed() const; + uint32_t get_typed_builtin() const; + StringName get_typed_class_name() const; + Variant get_typed_script() const; Array(const Array &p_from); Array(); ~Array(); diff --git a/core/variant/binder_common.h b/core/variant/binder_common.h index 490bd45b7b..830e0a5cbd 100644 --- a/core/variant/binder_common.h +++ b/core/variant/binder_common.h @@ -122,6 +122,18 @@ struct VariantObjectClassChecker { } }; +template <typename T> +class Ref; + +template <typename T> +struct VariantObjectClassChecker<const Ref<T> &> { + static _FORCE_INLINE_ bool check(const Variant &p_variant) { + Object *obj = p_variant; + const Ref<T> node = p_variant; + return node.ptr() || !obj; + } +}; + template <> struct VariantObjectClassChecker<Node *> { static _FORCE_INLINE_ bool check(const Variant &p_variant) { @@ -233,11 +245,26 @@ void call_with_ptr_args_retc_helper(T *p_instance, R (T::*p_method)(P...) const, PtrToArg<R>::encode((p_instance->*p_method)(PtrToArg<P>::convert(p_args[Is])...), r_ret); } +template <class T, class... P, size_t... Is> +void call_with_ptr_args_static_helper(T *p_instance, void (*p_method)(T *, P...), const void **p_args, IndexSequence<Is...>) { + p_method(p_instance, PtrToArg<P>::convert(p_args[Is])...); +} + template <class T, class R, class... P, size_t... Is> void call_with_ptr_args_static_retc_helper(T *p_instance, R (*p_method)(T *, P...), const void **p_args, void *r_ret, IndexSequence<Is...>) { PtrToArg<R>::encode(p_method(p_instance, PtrToArg<P>::convert(p_args[Is])...), r_ret); } +template <class R, class... P, size_t... Is> +void call_with_ptr_args_static_method_ret_helper(R (*p_method)(P...), const void **p_args, void *r_ret, IndexSequence<Is...>) { + PtrToArg<R>::encode(p_method(PtrToArg<P>::convert(p_args[Is])...), r_ret); +} + +template <class... P, size_t... Is> +void call_with_ptr_args_static_method_helper(void (*p_method)(P...), const void **p_args, IndexSequence<Is...>) { + p_method(PtrToArg<P>::convert(p_args[Is])...); +} + template <class T, class... P, size_t... Is> void call_with_validated_variant_args_helper(T *p_instance, void (T::*p_method)(P...), const Variant **p_args, IndexSequence<Is...>) { (p_instance->*p_method)((VariantInternalAccessor<typename GetSimpleTypeT<P>::type_t>::get(p_args[Is]))...); @@ -263,6 +290,21 @@ void call_with_validated_variant_args_static_retc_helper(T *p_instance, R (*p_me VariantInternalAccessor<typename GetSimpleTypeT<R>::type_t>::set(r_ret, p_method(p_instance, (VariantInternalAccessor<typename GetSimpleTypeT<P>::type_t>::get(p_args[Is]))...)); } +template <class T, class... P, size_t... Is> +void call_with_validated_variant_args_static_helper(T *p_instance, void (*p_method)(T *, P...), const Variant **p_args, IndexSequence<Is...>) { + p_method(p_instance, (VariantInternalAccessor<typename GetSimpleTypeT<P>::type_t>::get(p_args[Is]))...); +} + +template <class R, class... P, size_t... Is> +void call_with_validated_variant_args_static_method_ret_helper(R (*p_method)(P...), const Variant **p_args, Variant *r_ret, IndexSequence<Is...>) { + VariantInternalAccessor<typename GetSimpleTypeT<R>::type_t>::set(r_ret, p_method((VariantInternalAccessor<typename GetSimpleTypeT<P>::type_t>::get(p_args[Is]))...)); +} + +template <class... P, size_t... Is> +void call_with_validated_variant_args_static_method_helper(void (*p_method)(P...), const Variant **p_args, IndexSequence<Is...>) { + p_method((VariantInternalAccessor<typename GetSimpleTypeT<P>::type_t>::get(p_args[Is]))...); +} + template <class T, class... P> void call_with_variant_args(T *p_instance, void (T::*p_method)(P...), const Variant **p_args, int p_argcount, Callable::CallError &r_error) { #ifdef DEBUG_METHODS_ENABLED @@ -451,11 +493,26 @@ void call_with_ptr_args_retc(T *p_instance, R (T::*p_method)(P...) const, const call_with_ptr_args_retc_helper<T, R, P...>(p_instance, p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{}); } +template <class T, class... P> +void call_with_ptr_args_static(T *p_instance, void (*p_method)(T *, P...), const void **p_args) { + call_with_ptr_args_static_helper<T, P...>(p_instance, p_method, p_args, BuildIndexSequence<sizeof...(P)>{}); +} + template <class T, class R, class... P> void call_with_ptr_args_static_retc(T *p_instance, R (*p_method)(T *, P...), const void **p_args, void *r_ret) { call_with_ptr_args_static_retc_helper<T, R, P...>(p_instance, p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{}); } +template <class R, class... P> +void call_with_ptr_args_static_method_ret(R (*p_method)(P...), const void **p_args, void *r_ret) { + call_with_ptr_args_static_method_ret_helper<R, P...>(p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{}); +} + +template <class... P> +void call_with_ptr_args_static_method(void (*p_method)(P...), const void **p_args) { + call_with_ptr_args_static_method_helper<P...>(p_method, p_args, BuildIndexSequence<sizeof...(P)>{}); +} + template <class T, class... P> void call_with_validated_variant_args(Variant *base, void (T::*p_method)(P...), const Variant **p_args) { call_with_validated_variant_args_helper<T, P...>(VariantGetInternalPtr<T>::get_ptr(base), p_method, p_args, BuildIndexSequence<sizeof...(P)>{}); @@ -471,11 +528,26 @@ void call_with_validated_variant_args_retc(Variant *base, R (T::*p_method)(P...) call_with_validated_variant_args_retc_helper<T, R, P...>(VariantGetInternalPtr<T>::get_ptr(base), p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{}); } +template <class T, class... P> +void call_with_validated_variant_args_static(Variant *base, void (*p_method)(T *, P...), const Variant **p_args) { + call_with_validated_variant_args_static_helper<T, P...>(VariantGetInternalPtr<T>::get_ptr(base), p_method, p_args, BuildIndexSequence<sizeof...(P)>{}); +} + template <class T, class R, class... P> void call_with_validated_variant_args_static_retc(Variant *base, R (*p_method)(T *, P...), const Variant **p_args, Variant *r_ret) { call_with_validated_variant_args_static_retc_helper<T, R, P...>(VariantGetInternalPtr<T>::get_ptr(base), p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{}); } +template <class... P> +void call_with_validated_variant_args_static_method(void (*p_method)(P...), const Variant **p_args) { + call_with_validated_variant_args_static_method_helper<P...>(p_method, p_args, BuildIndexSequence<sizeof...(P)>{}); +} + +template <class R, class... P> +void call_with_validated_variant_args_static_method_ret(R (*p_method)(P...), const Variant **p_args, Variant *r_ret) { + call_with_validated_variant_args_static_method_ret_helper<R, P...>(p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{}); +} + // GCC raises "parameter 'p_args' set but not used" when P = {}, // it's not clever enough to treat other P values as making this branch valid. #if defined(DEBUG_METHODS_ENABLED) && defined(__GNUC__) && !defined(__clang__) @@ -566,6 +638,28 @@ void call_with_variant_args_ret_helper(T *p_instance, R (T::*p_method)(P...), co #endif } +template <class R, class... P, size_t... Is> +void call_with_variant_args_static_ret(R (*p_method)(P...), const Variant **p_args, Variant &r_ret, Callable::CallError &r_error, IndexSequence<Is...>) { + r_error.error = Callable::CallError::CALL_OK; + +#ifdef DEBUG_METHODS_ENABLED + r_ret = (p_method)(VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...); +#else + r_ret = (p_method)(VariantCaster<P>::cast(*p_args[Is])...); +#endif +} + +template <class... P, size_t... Is> +void call_with_variant_args_static(void (*p_method)(P...), const Variant **p_args, Callable::CallError &r_error, IndexSequence<Is...>) { + r_error.error = Callable::CallError::CALL_OK; + +#ifdef DEBUG_METHODS_ENABLED + (p_method)(VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...); +#else + (p_method)(VariantCaster<P>::cast(*p_args[Is])...); +#endif +} + template <class T, class R, class... P> void call_with_variant_args_ret(T *p_instance, R (T::*p_method)(P...), const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) { #ifdef DEBUG_METHODS_ENABLED @@ -596,6 +690,42 @@ void call_with_variant_args_retc_helper(T *p_instance, R (T::*p_method)(P...) co (void)p_args; } +template <class R, class... P> +void call_with_variant_args_static_ret(R (*p_method)(P...), const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) { +#ifdef DEBUG_METHODS_ENABLED + if ((size_t)p_argcount > sizeof...(P)) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; + r_error.argument = sizeof...(P); + return; + } + + if ((size_t)p_argcount < sizeof...(P)) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.argument = sizeof...(P); + return; + } +#endif + call_with_variant_args_static_ret<R, P...>(p_method, p_args, r_ret, r_error, BuildIndexSequence<sizeof...(P)>{}); +} + +template <class... P> +void call_with_variant_args_static_ret(void (*p_method)(P...), const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) { +#ifdef DEBUG_METHODS_ENABLED + if ((size_t)p_argcount > sizeof...(P)) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; + r_error.argument = sizeof...(P); + return; + } + + if ((size_t)p_argcount < sizeof...(P)) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.argument = sizeof...(P); + return; + } +#endif + call_with_variant_args_static<P...>(p_method, p_args, r_error, BuildIndexSequence<sizeof...(P)>{}); +} + template <class T, class R, class... P> void call_with_variant_args_retc(T *p_instance, R (T::*p_method)(P...) const, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) { #ifdef DEBUG_METHODS_ENABLED @@ -660,6 +790,118 @@ void call_with_variant_args_retc_static_helper_dv(T *p_instance, R (*p_method)(T call_with_variant_args_retc_static_helper(p_instance, p_method, args, r_ret, r_error, BuildIndexSequence<sizeof...(P)>{}); } +template <class T, class... P, size_t... Is> +void call_with_variant_args_static_helper(T *p_instance, void (*p_method)(T *, P...), const Variant **p_args, Callable::CallError &r_error, IndexSequence<Is...>) { + r_error.error = Callable::CallError::CALL_OK; + +#ifdef DEBUG_METHODS_ENABLED + (p_method)(p_instance, VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...); +#else + (p_method)(p_instance, VariantCaster<P>::cast(*p_args[Is])...); +#endif + + (void)p_args; +} + +template <class T, class... P> +void call_with_variant_args_static_helper_dv(T *p_instance, void (*p_method)(T *, P...), const Variant **p_args, int p_argcount, const Vector<Variant> &default_values, Callable::CallError &r_error) { +#ifdef DEBUG_ENABLED + if ((size_t)p_argcount > sizeof...(P)) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; + r_error.argument = sizeof...(P); + return; + } +#endif + + int32_t missing = (int32_t)sizeof...(P) - (int32_t)p_argcount; + + int32_t dvs = default_values.size(); +#ifdef DEBUG_ENABLED + if (missing > dvs) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.argument = sizeof...(P); + return; + } +#endif + + const Variant *args[sizeof...(P) == 0 ? 1 : sizeof...(P)]; //avoid zero sized array + for (int32_t i = 0; i < (int32_t)sizeof...(P); i++) { + if (i < p_argcount) { + args[i] = p_args[i]; + } else { + args[i] = &default_values[i - p_argcount + (dvs - missing)]; + } + } + + call_with_variant_args_static_helper(p_instance, p_method, args, r_error, BuildIndexSequence<sizeof...(P)>{}); +} + +template <class R, class... P> +void call_with_variant_args_static_ret_dv(R (*p_method)(P...), const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error, const Vector<Variant> &default_values) { +#ifdef DEBUG_ENABLED + if ((size_t)p_argcount > sizeof...(P)) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; + r_error.argument = sizeof...(P); + return; + } +#endif + + int32_t missing = (int32_t)sizeof...(P) - (int32_t)p_argcount; + + int32_t dvs = default_values.size(); +#ifdef DEBUG_ENABLED + if (missing > dvs) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.argument = sizeof...(P); + return; + } +#endif + + const Variant *args[sizeof...(P) == 0 ? 1 : sizeof...(P)]; //avoid zero sized array + for (int32_t i = 0; i < (int32_t)sizeof...(P); i++) { + if (i < p_argcount) { + args[i] = p_args[i]; + } else { + args[i] = &default_values[i - p_argcount + (dvs - missing)]; + } + } + + call_with_variant_args_static_ret(p_method, args, r_ret, r_error, BuildIndexSequence<sizeof...(P)>{}); +} + +template <class... P> +void call_with_variant_args_static_dv(void (*p_method)(P...), const Variant **p_args, int p_argcount, Callable::CallError &r_error, const Vector<Variant> &default_values) { +#ifdef DEBUG_ENABLED + if ((size_t)p_argcount > sizeof...(P)) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; + r_error.argument = sizeof...(P); + return; + } +#endif + + int32_t missing = (int32_t)sizeof...(P) - (int32_t)p_argcount; + + int32_t dvs = default_values.size(); +#ifdef DEBUG_ENABLED + if (missing > dvs) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.argument = sizeof...(P); + return; + } +#endif + + const Variant *args[sizeof...(P) == 0 ? 1 : sizeof...(P)]; //avoid zero sized array + for (int32_t i = 0; i < (int32_t)sizeof...(P); i++) { + if (i < p_argcount) { + args[i] = p_args[i]; + } else { + args[i] = &default_values[i - p_argcount + (dvs - missing)]; + } + } + + call_with_variant_args_static(p_method, args, r_error, BuildIndexSequence<sizeof...(P)>{}); +} + #if defined(DEBUG_METHODS_ENABLED) && defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic pop #endif diff --git a/core/variant/callable.cpp b/core/variant/callable.cpp index bd51e2dd1e..a1d9c5ed2f 100644 --- a/core/variant/callable.cpp +++ b/core/variant/callable.cpp @@ -126,7 +126,7 @@ bool Callable::operator==(const Callable &p_callable) const { if (custom_a == custom_b) { if (custom_a) { if (custom == p_callable.custom) { - return true; //same pointer, dont even compare + return true; //same pointer, don't even compare } CallableCustom::CompareEqualFunc eq_a = custom->get_compare_equal_func(); @@ -155,7 +155,7 @@ bool Callable::operator<(const Callable &p_callable) const { if (custom_a == custom_b) { if (custom_a) { if (custom == p_callable.custom) { - return false; //same pointer, dont even compare + return false; //same pointer, don't even compare } CallableCustom::CompareLessFunc less_a = custom->get_compare_less_func(); diff --git a/core/variant/variant.h b/core/variant/variant.h index 5050aa24ec..0acafc64fa 100644 --- a/core/variant/variant.h +++ b/core/variant/variant.h @@ -495,6 +495,7 @@ public: static bool has_builtin_method_return_value(Variant::Type p_type, const StringName &p_method); static Variant::Type get_builtin_method_return_type(Variant::Type p_type, const StringName &p_method); static bool is_builtin_method_const(Variant::Type p_type, const StringName &p_method); + static bool is_builtin_method_static(Variant::Type p_type, const StringName &p_method); static bool is_builtin_method_vararg(Variant::Type p_type, const StringName &p_method); static void get_builtin_method_list(Variant::Type p_type, List<StringName> *p_list); static int get_builtin_method_count(Variant::Type p_type); @@ -502,6 +503,8 @@ public: void call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error); Variant call(const StringName &p_method, const Variant &p_arg1 = Variant(), const Variant &p_arg2 = Variant(), const Variant &p_arg3 = Variant(), const Variant &p_arg4 = Variant(), const Variant &p_arg5 = Variant()); + static void call_static(Variant::Type p_type, const StringName &p_method, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error); + static String get_call_error_text(const StringName &p_method, const Variant **p_argptrs, int p_argcount, const Callable::CallError &ce); static String get_call_error_text(Object *p_base, const StringName &p_method, const Variant **p_argptrs, int p_argcount, const Callable::CallError &ce); static String get_callable_error_text(const Callable &p_callable, const Variant **p_argptrs, int p_argcount, const Callable::CallError &ce); diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index 54ca1a911d..deaccc6304 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -34,6 +34,7 @@ #include "core/crypto/crypto_core.h" #include "core/debugger/engine_debugger.h" #include "core/io/compression.h" +#include "core/io/marshalls.h" #include "core/object/class_db.h" #include "core/os/os.h" #include "core/templates/local_vector.h" @@ -42,6 +43,16 @@ typedef void (*VariantFunc)(Variant &r_ret, Variant &p_self, const Variant **p_args); typedef void (*VariantConstructFunc)(Variant &r_ret, const Variant **p_args); +template <class R, class... P> +static _FORCE_INLINE_ void vc_static_method_call(R (*method)(P...), const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { + call_with_variant_args_static_ret_dv(method, p_args, p_argcount, r_ret, r_error, p_defvals); +} + +template <class... P> +static _FORCE_INLINE_ void vc_static_method_call(void (*method)(P...), const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { + call_with_variant_args_static_dv(method, p_args, p_argcount, r_error, p_defvals); +} + template <class R, class T, class... P> static _FORCE_INLINE_ void vc_method_call(R (T::*method)(P...), Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { call_with_variant_args_ret_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_ret, r_error, p_defvals); @@ -63,6 +74,16 @@ static _FORCE_INLINE_ void vc_method_call(void (T::*method)(P...) const, Variant } template <class R, class T, class... P> +static _FORCE_INLINE_ void vc_method_call_static(R (*method)(T *, P...), Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { + call_with_variant_args_retc_static_helper_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_ret, p_defvals, r_error); +} + +template <class T, class... P> +static _FORCE_INLINE_ void vc_method_call_static(void (*method)(T *, P...), Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { + call_with_variant_args_static_helper_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, p_defvals, r_error); +} + +template <class R, class T, class... P> static _FORCE_INLINE_ void vc_validated_call(R (T::*method)(P...), Variant *base, const Variant **p_args, Variant *r_ret) { call_with_validated_variant_args_ret(base, method, p_args, r_ret); } @@ -82,48 +103,43 @@ static _FORCE_INLINE_ void vc_validated_call(void (T::*method)(P...) const, Vari } template <class R, class T, class... P> -static _FORCE_INLINE_ void vc_ptrcall(R (T::*method)(P...), void *p_base, const void **p_args, void *r_ret) { - call_with_ptr_args_ret(reinterpret_cast<T *>(p_base), method, p_args, r_ret); +static _FORCE_INLINE_ void vc_validated_call_static(R (*method)(T *, P...), Variant *base, const Variant **p_args, Variant *r_ret) { + call_with_validated_variant_args_static_retc(base, method, p_args, r_ret); } -template <class R, class T, class... P> -static _FORCE_INLINE_ void vc_ptrcall(R (T::*method)(P...) const, void *p_base, const void **p_args, void *r_ret) { - call_with_ptr_args_retc(reinterpret_cast<T *>(p_base), method, p_args, r_ret); +template <class T, class... P> +static _FORCE_INLINE_ void vc_validated_call_static(void (*method)(T *, P...), Variant *base, const Variant **p_args, Variant *r_ret) { + call_with_validated_variant_args_static(base, method, p_args); } -template <class T, class... P> -static _FORCE_INLINE_ void vc_ptrcall(void (T::*method)(P...), void *p_base, const void **p_args, void *r_ret) { - call_with_ptr_args(reinterpret_cast<T *>(p_base), method, p_args); +template <class R, class... P> +static _FORCE_INLINE_ void vc_validated_static_call(R (*method)(P...), const Variant **p_args, Variant *r_ret) { + call_with_validated_variant_args_static_method_ret(method, p_args, r_ret); } -template <class T, class... P> -static _FORCE_INLINE_ void vc_ptrcall(void (T::*method)(P...) const, void *p_base, const void **p_args, void *r_ret) { - call_with_ptr_argsc(reinterpret_cast<T *>(p_base), method, p_args); +template <class... P> +static _FORCE_INLINE_ void vc_validated_static_call(void (*method)(P...), const Variant **p_args, Variant *r_ret) { + call_with_validated_variant_args_static_method(method, p_args); } template <class R, class T, class... P> -static _FORCE_INLINE_ void vc_change_return_type(R (T::*method)(P...), Variant *v) { - VariantTypeAdjust<R>::adjust(v); +static _FORCE_INLINE_ void vc_ptrcall(R (T::*method)(P...), void *p_base, const void **p_args, void *r_ret) { + call_with_ptr_args_ret(reinterpret_cast<T *>(p_base), method, p_args, r_ret); } template <class R, class T, class... P> -static _FORCE_INLINE_ void vc_change_return_type(R (T::*method)(P...) const, Variant *v) { - VariantTypeAdjust<R>::adjust(v); +static _FORCE_INLINE_ void vc_ptrcall(R (T::*method)(P...) const, void *p_base, const void **p_args, void *r_ret) { + call_with_ptr_args_retc(reinterpret_cast<T *>(p_base), method, p_args, r_ret); } template <class T, class... P> -static _FORCE_INLINE_ void vc_change_return_type(void (T::*method)(P...), Variant *v) { - VariantInternal::clear(v); +static _FORCE_INLINE_ void vc_ptrcall(void (T::*method)(P...), void *p_base, const void **p_args, void *r_ret) { + call_with_ptr_args(reinterpret_cast<T *>(p_base), method, p_args); } template <class T, class... P> -static _FORCE_INLINE_ void vc_change_return_type(void (T::*method)(P...) const, Variant *v) { - VariantInternal::clear(v); -} - -template <class R, class... P> -static _FORCE_INLINE_ void vc_change_return_type(R (*method)(P...), Variant *v) { - VariantTypeAdjust<R>::adjust(v); +static _FORCE_INLINE_ void vc_ptrcall(void (T::*method)(P...) const, void *p_base, const void **p_args, void *r_ret) { + call_with_ptr_argsc(reinterpret_cast<T *>(p_base), method, p_args); } template <class R, class T, class... P> @@ -150,6 +166,11 @@ static _FORCE_INLINE_ int vc_get_argument_count(R (*method)(T *, P...)) { return sizeof...(P); } +template <class R, class... P> +static _FORCE_INLINE_ int vc_get_argument_count_static(R (*method)(P...)) { + return sizeof...(P); +} + template <class R, class T, class... P> static _FORCE_INLINE_ Variant::Type vc_get_argument_type(R (T::*method)(P...), int p_arg) { return call_get_argument_type<P...>(p_arg); @@ -174,6 +195,11 @@ static _FORCE_INLINE_ Variant::Type vc_get_argument_type(R (*method)(T *, P...), return call_get_argument_type<P...>(p_arg); } +template <class R, class... P> +static _FORCE_INLINE_ Variant::Type vc_get_argument_type_static(R (*method)(P...), int p_arg) { + return call_get_argument_type<P...>(p_arg); +} + template <class R, class T, class... P> static _FORCE_INLINE_ Variant::Type vc_get_return_type(R (T::*method)(P...)) { return GetTypeInfo<R>::VARIANT_TYPE; @@ -199,6 +225,11 @@ static _FORCE_INLINE_ Variant::Type vc_get_return_type(R (*method)(P...)) { return GetTypeInfo<R>::VARIANT_TYPE; } +template <class... P> +static _FORCE_INLINE_ Variant::Type vc_get_return_type(void (*method)(P...)) { + return Variant::NIL; +} + template <class R, class T, class... P> static _FORCE_INLINE_ bool vc_has_return_type(R (T::*method)(P...)) { return true; @@ -218,6 +249,16 @@ static _FORCE_INLINE_ bool vc_has_return_type(void (T::*method)(P...) const) { return false; } +template <class... P> +static _FORCE_INLINE_ bool vc_has_return_type_static(void (*method)(P...)) { + return false; +} + +template <class R, class... P> +static _FORCE_INLINE_ bool vc_has_return_type_static(R (*method)(P...)) { + return true; +} + template <class R, class T, class... P> static _FORCE_INLINE_ bool vc_is_const(R (T::*method)(P...)) { return false; @@ -262,7 +303,6 @@ static _FORCE_INLINE_ Variant::Type vc_get_base_type(void (T::*method)(P...) con vc_method_call(m_method_ptr, base, p_args, p_argcount, r_ret, p_defvals, r_error); \ } \ static void validated_call(Variant *base, const Variant **p_args, int p_argcount, Variant *r_ret) { \ - vc_change_return_type(m_method_ptr, r_ret); \ vc_validated_call(m_method_ptr, base, p_args, r_ret); \ } \ static void ptrcall(void *p_base, const void **p_args, void *r_ret, int p_argcount) { \ @@ -283,6 +323,9 @@ static _FORCE_INLINE_ Variant::Type vc_get_base_type(void (T::*method)(P...) con static bool is_const() { \ return vc_is_const(m_method_ptr); \ } \ + static bool is_static() { \ + return false; \ + } \ static bool is_vararg() { \ return false; \ } \ @@ -294,47 +337,104 @@ static _FORCE_INLINE_ Variant::Type vc_get_base_type(void (T::*method)(P...) con } \ }; +template <class R, class... P> +static _FORCE_INLINE_ void vc_static_ptrcall(R (*method)(P...), const void **p_args, void *r_ret) { + call_with_ptr_args_static_method_ret<R, P...>(method, p_args, r_ret); +} + +template <class... P> +static _FORCE_INLINE_ void vc_static_ptrcall(void (*method)(P...), const void **p_args, void *r_ret) { + call_with_ptr_args_static_method<P...>(method, p_args); +} + +#define STATIC_METHOD_CLASS(m_class, m_method_name, m_method_ptr) \ + struct Method_##m_class##_##m_method_name { \ + static void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { \ + vc_static_method_call(m_method_ptr, p_args, p_argcount, r_ret, p_defvals, r_error); \ + } \ + static void validated_call(Variant *base, const Variant **p_args, int p_argcount, Variant *r_ret) { \ + vc_validated_static_call(m_method_ptr, p_args, r_ret); \ + } \ + static void ptrcall(void *p_base, const void **p_args, void *r_ret, int p_argcount) { \ + vc_static_ptrcall(m_method_ptr, p_args, r_ret); \ + } \ + static int get_argument_count() { \ + return vc_get_argument_count_static(m_method_ptr); \ + } \ + static Variant::Type get_argument_type(int p_arg) { \ + return vc_get_argument_type_static(m_method_ptr, p_arg); \ + } \ + static Variant::Type get_return_type() { \ + return vc_get_return_type(m_method_ptr); \ + } \ + static bool has_return_type() { \ + return vc_has_return_type_static(m_method_ptr); \ + } \ + static bool is_const() { \ + return false; \ + } \ + static bool is_static() { \ + return true; \ + } \ + static bool is_vararg() { \ + return false; \ + } \ + static Variant::Type get_base_type() { \ + return GetTypeInfo<m_class>::VARIANT_TYPE; \ + } \ + static StringName get_name() { \ + return #m_method_name; \ + } \ + }; + template <class R, class T, class... P> static _FORCE_INLINE_ void vc_ptrcall(R (*method)(T *, P...), void *p_base, const void **p_args, void *r_ret) { call_with_ptr_args_static_retc<T, R, P...>(reinterpret_cast<T *>(p_base), method, p_args, r_ret); } -#define FUNCTION_CLASS(m_class, m_method_name, m_method_ptr) \ - struct Method_##m_class##_##m_method_name { \ - static void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { \ - call_with_variant_args_retc_static_helper_dv(VariantGetInternalPtr<m_class>::get_ptr(base), m_method_ptr, p_args, p_argcount, r_ret, p_defvals, r_error); \ - } \ - static void validated_call(Variant *base, const Variant **p_args, int p_argcount, Variant *r_ret) { \ - vc_change_return_type(m_method_ptr, r_ret); \ - call_with_validated_variant_args_static_retc(base, m_method_ptr, p_args, r_ret); \ - } \ - static void ptrcall(void *p_base, const void **p_args, void *r_ret, int p_argcount) { \ - vc_ptrcall(m_method_ptr, p_base, p_args, r_ret); \ - } \ - static int get_argument_count() { \ - return vc_get_argument_count(m_method_ptr); \ - } \ - static Variant::Type get_argument_type(int p_arg) { \ - return vc_get_argument_type(m_method_ptr, p_arg); \ - } \ - static Variant::Type get_return_type() { \ - return vc_get_return_type(m_method_ptr); \ - } \ - static bool has_return_type() { \ - return true; \ - } \ - static bool is_const() { \ - return true; \ - } \ - static bool is_vararg() { \ - return false; \ - } \ - static Variant::Type get_base_type() { \ - return GetTypeInfo<m_class>::VARIANT_TYPE; \ - } \ - static StringName get_name() { \ - return #m_method_name; \ - } \ +template <class T, class... P> +static _FORCE_INLINE_ void vc_ptrcall(void (*method)(T *, P...), void *p_base, const void **p_args, void *r_ret) { + call_with_ptr_args_static<T, P...>(reinterpret_cast<T *>(p_base), method, p_args); +} + +#define FUNCTION_CLASS(m_class, m_method_name, m_method_ptr, m_const) \ + struct Method_##m_class##_##m_method_name { \ + static void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { \ + vc_method_call_static(m_method_ptr, base, p_args, p_argcount, r_ret, p_defvals, r_error); \ + } \ + static void validated_call(Variant *base, const Variant **p_args, int p_argcount, Variant *r_ret) { \ + vc_validated_call_static(m_method_ptr, base, p_args, r_ret); \ + } \ + static void ptrcall(void *p_base, const void **p_args, void *r_ret, int p_argcount) { \ + vc_ptrcall(m_method_ptr, p_base, p_args, r_ret); \ + } \ + static int get_argument_count() { \ + return vc_get_argument_count(m_method_ptr); \ + } \ + static Variant::Type get_argument_type(int p_arg) { \ + return vc_get_argument_type(m_method_ptr, p_arg); \ + } \ + static Variant::Type get_return_type() { \ + return vc_get_return_type(m_method_ptr); \ + } \ + static bool has_return_type() { \ + return vc_has_return_type_static(m_method_ptr); \ + } \ + static bool is_const() { \ + return m_const; \ + } \ + static bool is_static() { \ + return false; \ + } \ + static bool is_vararg() { \ + return false; \ + } \ + static Variant::Type get_base_type() { \ + return GetTypeInfo<m_class>::VARIANT_TYPE; \ + } \ + static StringName get_name() { \ + return #m_method_name; \ + } \ }; #define VARARG_CLASS(m_class, m_method_name, m_method_ptr, m_has_return, m_return_type) \ @@ -379,6 +479,9 @@ static _FORCE_INLINE_ void vc_ptrcall(R (*method)(T *, P...), void *p_base, cons static bool is_const() { \ return true; \ } \ + static bool is_static() { \ + return false; \ + } \ static bool is_vararg() { \ return true; \ } \ @@ -397,7 +500,7 @@ struct _VariantCall { const uint8_t *r = p_instance->ptr(); CharString cs; cs.resize(p_instance->size() + 1); - copymem(cs.ptrw(), r, p_instance->size()); + memcpy(cs.ptrw(), r, p_instance->size()); cs[p_instance->size()] = 0; s = cs.get_data(); @@ -490,6 +593,195 @@ struct _VariantCall { return s; } + static int64_t func_PackedByteArray_decode_u8(PackedByteArray *p_instance, int64_t p_offset) { + uint64_t size = p_instance->size(); + ERR_FAIL_COND_V(p_offset < 0 || p_offset > int64_t(size) - 1, 0); + const uint8_t *r = p_instance->ptr(); + return r[p_offset]; + } + static int64_t func_PackedByteArray_decode_s8(PackedByteArray *p_instance, int64_t p_offset) { + uint64_t size = p_instance->size(); + ERR_FAIL_COND_V(p_offset < 0 || p_offset > int64_t(size) - 1, 0); + const uint8_t *r = p_instance->ptr(); + return *((const int8_t *)&r[p_offset]); + } + static int64_t func_PackedByteArray_decode_u16(PackedByteArray *p_instance, int64_t p_offset) { + uint64_t size = p_instance->size(); + ERR_FAIL_COND_V(p_offset < 0 || p_offset > (int64_t(size) - 2), 0); + const uint8_t *r = p_instance->ptr(); + return decode_uint16(&r[p_offset]); + } + static int64_t func_PackedByteArray_decode_s16(PackedByteArray *p_instance, int64_t p_offset) { + uint64_t size = p_instance->size(); + ERR_FAIL_COND_V(p_offset < 0 || p_offset > (int64_t(size) - 2), 0); + const uint8_t *r = p_instance->ptr(); + return (int16_t)decode_uint16(&r[p_offset]); + } + static int64_t func_PackedByteArray_decode_u32(PackedByteArray *p_instance, int64_t p_offset) { + uint64_t size = p_instance->size(); + ERR_FAIL_COND_V(p_offset < 0 || p_offset > (int64_t(size) - 4), 0); + const uint8_t *r = p_instance->ptr(); + return decode_uint32(&r[p_offset]); + } + static int64_t func_PackedByteArray_decode_s32(PackedByteArray *p_instance, int64_t p_offset) { + uint64_t size = p_instance->size(); + ERR_FAIL_COND_V(p_offset < 0 || p_offset > (int64_t(size) - 4), 0); + const uint8_t *r = p_instance->ptr(); + return (int32_t)decode_uint32(&r[p_offset]); + } + static int64_t func_PackedByteArray_decode_u64(PackedByteArray *p_instance, int64_t p_offset) { + uint64_t size = p_instance->size(); + ERR_FAIL_COND_V(p_offset < 0 || p_offset > (int64_t(size) - 8), 0); + const uint8_t *r = p_instance->ptr(); + return (int64_t)decode_uint64(&r[p_offset]); + } + static int64_t func_PackedByteArray_decode_s64(PackedByteArray *p_instance, int64_t p_offset) { + uint64_t size = p_instance->size(); + ERR_FAIL_COND_V(p_offset < 0 || p_offset > (int64_t(size) - 8), 0); + const uint8_t *r = p_instance->ptr(); + return (int64_t)decode_uint64(&r[p_offset]); + } + static double func_PackedByteArray_decode_half(PackedByteArray *p_instance, int64_t p_offset) { + uint64_t size = p_instance->size(); + ERR_FAIL_COND_V(p_offset < 0 || p_offset > (int64_t(size) - 2), 0); + const uint8_t *r = p_instance->ptr(); + return Math::half_to_float(decode_uint16(&r[p_offset])); + } + static double func_PackedByteArray_decode_float(PackedByteArray *p_instance, int64_t p_offset) { + uint64_t size = p_instance->size(); + ERR_FAIL_COND_V(p_offset < 0 || p_offset > (int64_t(size) - 4), 0); + const uint8_t *r = p_instance->ptr(); + return decode_float(&r[p_offset]); + } + + static double func_PackedByteArray_decode_double(PackedByteArray *p_instance, int64_t p_offset) { + uint64_t size = p_instance->size(); + ERR_FAIL_COND_V(p_offset < 0 || p_offset > (int64_t(size) - 8), 0); + const uint8_t *r = p_instance->ptr(); + return decode_double(&r[p_offset]); + } + + static bool func_PackedByteArray_has_encoded_var(PackedByteArray *p_instance, int64_t p_offset, bool p_allow_objects) { + uint64_t size = p_instance->size(); + ERR_FAIL_COND_V(p_offset < 0, false); + const uint8_t *r = p_instance->ptr(); + Variant ret; + Error err = decode_variant(ret, r + p_offset, size - p_offset, nullptr, p_allow_objects); + return err == OK; + } + + static Variant func_PackedByteArray_decode_var(PackedByteArray *p_instance, int64_t p_offset, bool p_allow_objects) { + uint64_t size = p_instance->size(); + ERR_FAIL_COND_V(p_offset < 0, Variant()); + const uint8_t *r = p_instance->ptr(); + Variant ret; + Error err = decode_variant(ret, r + p_offset, size - p_offset, nullptr, p_allow_objects); + if (err != OK) { + ret = Variant(); + } + return ret; + } + + static int64_t func_PackedByteArray_decode_var_size(PackedByteArray *p_instance, int64_t p_offset, bool p_allow_objects) { + uint64_t size = p_instance->size(); + ERR_FAIL_COND_V(p_offset < 0, 0); + const uint8_t *r = p_instance->ptr(); + Variant ret; + int r_size; + Error err = decode_variant(ret, r + p_offset, size - p_offset, &r_size, p_allow_objects); + if (err == OK) { + return r_size; + } + return 0; + } + + static void func_PackedByteArray_encode_u8(PackedByteArray *p_instance, int64_t p_offset, int64_t p_value) { + uint64_t size = p_instance->size(); + ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 1); + uint8_t *w = p_instance->ptrw(); + *((uint8_t *)&w[p_offset]) = p_value; + } + static void func_PackedByteArray_encode_s8(PackedByteArray *p_instance, int64_t p_offset, int64_t p_value) { + uint64_t size = p_instance->size(); + ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 1); + uint8_t *w = p_instance->ptrw(); + *((int8_t *)&w[p_offset]) = p_value; + } + + static void func_PackedByteArray_encode_u16(PackedByteArray *p_instance, int64_t p_offset, int64_t p_value) { + uint64_t size = p_instance->size(); + ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 2); + uint8_t *w = p_instance->ptrw(); + encode_uint16((uint16_t)p_value, &w[p_offset]); + } + static void func_PackedByteArray_encode_s16(PackedByteArray *p_instance, int64_t p_offset, int64_t p_value) { + uint64_t size = p_instance->size(); + ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 2); + uint8_t *w = p_instance->ptrw(); + encode_uint16((int16_t)p_value, &w[p_offset]); + } + + static void func_PackedByteArray_encode_u32(PackedByteArray *p_instance, int64_t p_offset, int64_t p_value) { + uint64_t size = p_instance->size(); + ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 4); + uint8_t *w = p_instance->ptrw(); + encode_uint32((uint32_t)p_value, &w[p_offset]); + } + static void func_PackedByteArray_encode_s32(PackedByteArray *p_instance, int64_t p_offset, int64_t p_value) { + uint64_t size = p_instance->size(); + ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 4); + uint8_t *w = p_instance->ptrw(); + encode_uint32((int32_t)p_value, &w[p_offset]); + } + + static void func_PackedByteArray_encode_u64(PackedByteArray *p_instance, int64_t p_offset, int64_t p_value) { + uint64_t size = p_instance->size(); + ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 8); + uint8_t *w = p_instance->ptrw(); + encode_uint64((uint64_t)p_value, &w[p_offset]); + } + static void func_PackedByteArray_encode_s64(PackedByteArray *p_instance, int64_t p_offset, int64_t p_value) { + uint64_t size = p_instance->size(); + ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 8); + uint8_t *w = p_instance->ptrw(); + encode_uint64((int64_t)p_value, &w[p_offset]); + } + + static void func_PackedByteArray_encode_half(PackedByteArray *p_instance, int64_t p_offset, double p_value) { + uint64_t size = p_instance->size(); + ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 2); + uint8_t *w = p_instance->ptrw(); + encode_uint16(Math::make_half_float(p_value), &w[p_offset]); + } + static void func_PackedByteArray_encode_float(PackedByteArray *p_instance, int64_t p_offset, double p_value) { + uint64_t size = p_instance->size(); + ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 4); + uint8_t *w = p_instance->ptrw(); + encode_float(p_value, &w[p_offset]); + } + static void func_PackedByteArray_encode_double(PackedByteArray *p_instance, int64_t p_offset, double p_value) { + uint64_t size = p_instance->size(); + ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 8); + uint8_t *w = p_instance->ptrw(); + encode_double(p_value, &w[p_offset]); + } + static int64_t func_PackedByteArray_encode_var(PackedByteArray *p_instance, int64_t p_offset, const Variant &p_value, bool p_allow_objects) { + uint64_t size = p_instance->size(); + ERR_FAIL_COND_V(p_offset < 0, -1); + uint8_t *w = p_instance->ptrw(); + int len; + Error err = encode_variant(p_value, nullptr, len, p_allow_objects); + if (err != OK) { + return -1; + } + if (uint64_t(p_offset + len) > size) { + return -1; // did not fit + } + encode_variant(p_value, w + p_offset, len, p_allow_objects); + + return len; + } + static void func_Callable_call(Variant *v, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) { Callable *callable = VariantGetInternalPtr<Callable>::get_ptr(v); callable->call(p_args, p_argcount, r_ret, r_error); @@ -549,6 +841,7 @@ struct VariantBuiltInMethodInfo { Vector<String> argument_names; bool is_const; + bool is_static; bool has_return_type; bool is_vararg; Variant::Type return_type; @@ -580,6 +873,7 @@ static void register_builtin_method(const Vector<String> &p_argnames, const Vect imi.argument_names = p_argnames; imi.is_const = T::is_const(); + imi.is_static = T::is_static(); imi.is_vararg = T::is_vararg(); imi.has_return_type = T::has_return_type(); imi.return_type = T::get_return_type(); @@ -625,6 +919,24 @@ void Variant::call(const StringName &p_method, const Variant **p_args, int p_arg } } +void Variant::call_static(Variant::Type p_type, const StringName &p_method, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) { + r_error.error = Callable::CallError::CALL_OK; + + const VariantBuiltInMethodInfo *imf = builtin_method_info[p_type].lookup_ptr(p_method); + + if (!imf) { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; + return; + } + + if (!imf->is_static) { + r_error.error = Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL; + return; + } + + imf->call(nullptr, p_args, p_argcount, r_ret, imf->default_arguments, r_error); +} + bool Variant::has_method(const StringName &p_method) const { if (type == OBJECT) { Object *obj = get_validated_object(); @@ -724,6 +1036,13 @@ bool Variant::is_builtin_method_const(Variant::Type p_type, const StringName &p_ return method->is_const; } +bool Variant::is_builtin_method_static(Variant::Type p_type, const StringName &p_method) { + ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, false); + const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method); + ERR_FAIL_COND_V(!method, false); + return method->is_static; +} + bool Variant::is_builtin_method_vararg(Variant::Type p_type, const StringName &p_method) { ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, false); const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method); @@ -759,7 +1078,9 @@ void Variant::get_method_list(List<MethodInfo> *p_list) const { if (method->is_vararg) { mi.flags |= METHOD_FLAG_VARARG; } - + if (method->is_static) { + mi.flags |= METHOD_FLAG_STATIC; + } for (int i = 0; i < method->argument_count; i++) { PropertyInfo pi; #ifdef DEBUG_METHODS_ENABLED @@ -855,6 +1176,16 @@ Variant Variant::get_constant_value(Variant::Type p_type, const StringName &p_va #endif #ifdef DEBUG_METHODS_ENABLED +#define bind_static_method(m_type, m_method, m_arg_names, m_default_args) \ + STATIC_METHOD_CLASS(m_type, m_method, m_type::m_method); \ + register_builtin_method<Method_##m_type##_##m_method>(m_arg_names, m_default_args); +#else +#define bind_static_method(m_type, m_method, m_arg_names, m_default_args) \ + STATIC_METHOD_CLASS(m_type, m_method, m_type ::m_method); \ + register_builtin_method<Method_##m_type##_##m_method>(sarray(), m_default_args); +#endif + +#ifdef DEBUG_METHODS_ENABLED #define bind_methodv(m_type, m_name, m_method, m_arg_names, m_default_args) \ METHOD_CLASS(m_type, m_name, m_method); \ register_builtin_method<Method_##m_type##_##m_name>(m_arg_names, m_default_args); @@ -866,11 +1197,21 @@ Variant Variant::get_constant_value(Variant::Type p_type, const StringName &p_va #ifdef DEBUG_METHODS_ENABLED #define bind_function(m_type, m_name, m_method, m_arg_names, m_default_args) \ - FUNCTION_CLASS(m_type, m_name, m_method); \ + FUNCTION_CLASS(m_type, m_name, m_method, true); \ register_builtin_method<Method_##m_type##_##m_name>(m_arg_names, m_default_args); #else #define bind_function(m_type, m_name, m_method, m_arg_names, m_default_args) \ - FUNCTION_CLASS(m_type, m_name, m_method); \ + FUNCTION_CLASS(m_type, m_name, m_method, true); \ + register_builtin_method<Method_##m_type##_##m_name>(sarray(), m_default_args); +#endif + +#ifdef DEBUG_METHODS_ENABLED +#define bind_functionnc(m_type, m_name, m_method, m_arg_names, m_default_args) \ + FUNCTION_CLASS(m_type, m_name, m_method, false); \ + register_builtin_method<Method_##m_type##_##m_name>(m_arg_names, m_default_args); +#else +#define bind_functionnc(m_type, m_name, m_method, m_arg_names, m_default_args) \ + FUNCTION_CLASS(m_type, m_name, m_method, false); \ register_builtin_method<Method_##m_type##_##m_name>(sarray(), m_default_args); #endif @@ -956,6 +1297,8 @@ static void _register_variant_builtin_methods() { bind_method(String, c_unescape, sarray(), varray()); bind_method(String, json_escape, sarray(), varray()); + bind_method(String, validate_node_name, sarray(), varray()); + bind_method(String, is_valid_identifier, sarray(), varray()); bind_method(String, is_valid_integer, sarray(), varray()); bind_method(String, is_valid_float, sarray(), varray()); @@ -981,6 +1324,11 @@ static void _register_variant_builtin_methods() { bind_method(String, to_utf16_buffer, sarray(), varray()); bind_method(String, to_utf32_buffer, sarray(), varray()); + bind_static_method(String, num_scientific, sarray("number"), varray()); + bind_static_method(String, num, sarray("number", "decimals"), varray(-1)); + bind_static_method(String, chr, sarray("char"), varray()); + bind_static_method(String, humanize_size, sarray("size"), varray()); + /* Vector2 */ bind_method(Vector2, angle, sarray(), varray()); @@ -1145,6 +1493,17 @@ static void _register_variant_builtin_methods() { //ADDFUNC4R(COLOR, COLOR, Color, from_hsv, FLOAT, "h", FLOAT, "s", FLOAT, "v", FLOAT, "a", varray(1.0)); bind_method(Color, is_equal_approx, sarray("to"), varray()); + bind_static_method(Color, hex, sarray("hex"), varray()); + bind_static_method(Color, hex64, sarray("hex"), varray()); + bind_static_method(Color, html, sarray("rgba"), varray()); + bind_static_method(Color, html_is_valid, sarray("color"), varray()); + bind_static_method(Color, find_named_color, sarray("name"), varray()); + bind_static_method(Color, get_named_color_count, sarray(), varray()); + bind_static_method(Color, get_named_color_name, sarray("idx"), varray()); + bind_static_method(Color, get_named_color, sarray("idx"), varray()); + bind_static_method(Color, from_string, sarray("str", "default"), varray()); + bind_static_method(Color, from_rgbe9995, sarray("rgbe"), varray()); + /* RID */ bind_method(RID, get_id, sarray(), varray()); @@ -1288,6 +1647,7 @@ static void _register_variant_builtin_methods() { bind_method(Array, resize, sarray("size"), varray()); bind_method(Array, insert, sarray("position", "value"), varray()); bind_method(Array, remove, sarray("position"), varray()); + bind_method(Array, fill, sarray("value"), varray()); bind_method(Array, erase, sarray("value"), varray()); bind_method(Array, front, sarray(), varray()); bind_method(Array, back, sarray(), varray()); @@ -1303,7 +1663,7 @@ static void _register_variant_builtin_methods() { bind_method(Array, shuffle, sarray(), varray()); bind_method(Array, bsearch, sarray("value", "before"), varray(true)); bind_method(Array, bsearch_custom, sarray("value", "func", "before"), varray(true)); - bind_method(Array, invert, sarray(), varray()); + bind_method(Array, reverse, sarray(), varray()); bind_method(Array, duplicate, sarray("deep"), varray(false)); bind_method(Array, slice, sarray("begin", "end", "step", "deep"), varray(1, false)); bind_method(Array, max, sarray(), varray()); @@ -1318,9 +1678,10 @@ static void _register_variant_builtin_methods() { bind_method(PackedByteArray, append_array, sarray("array"), varray()); bind_method(PackedByteArray, remove, sarray("index"), varray()); bind_method(PackedByteArray, insert, sarray("at_index", "value"), varray()); + bind_method(PackedByteArray, fill, sarray("value"), varray()); bind_method(PackedByteArray, resize, sarray("new_size"), varray()); bind_method(PackedByteArray, has, sarray("value"), varray()); - bind_method(PackedByteArray, invert, sarray(), varray()); + bind_method(PackedByteArray, reverse, sarray(), varray()); bind_method(PackedByteArray, subarray, sarray("from", "to"), varray()); bind_method(PackedByteArray, sort, sarray(), varray()); bind_method(PackedByteArray, duplicate, sarray(), varray()); @@ -1334,6 +1695,34 @@ static void _register_variant_builtin_methods() { bind_function(PackedByteArray, decompress, _VariantCall::func_PackedByteArray_decompress, sarray("buffer_size", "compression_mode"), varray(0)); bind_function(PackedByteArray, decompress_dynamic, _VariantCall::func_PackedByteArray_decompress_dynamic, sarray("max_output_size", "compression_mode"), varray(0)); + bind_function(PackedByteArray, decode_u8, _VariantCall::func_PackedByteArray_decode_u8, sarray("byte_offset"), varray()); + bind_function(PackedByteArray, decode_s8, _VariantCall::func_PackedByteArray_decode_s8, sarray("byte_offset"), varray()); + bind_function(PackedByteArray, decode_u16, _VariantCall::func_PackedByteArray_decode_u16, sarray("byte_offset"), varray()); + bind_function(PackedByteArray, decode_s16, _VariantCall::func_PackedByteArray_decode_s16, sarray("byte_offset"), varray()); + bind_function(PackedByteArray, decode_u32, _VariantCall::func_PackedByteArray_decode_u32, sarray("byte_offset"), varray()); + bind_function(PackedByteArray, decode_s32, _VariantCall::func_PackedByteArray_decode_s32, sarray("byte_offset"), varray()); + bind_function(PackedByteArray, decode_u64, _VariantCall::func_PackedByteArray_decode_u64, sarray("byte_offset"), varray()); + bind_function(PackedByteArray, decode_s64, _VariantCall::func_PackedByteArray_decode_s64, sarray("byte_offset"), varray()); + bind_function(PackedByteArray, decode_half, _VariantCall::func_PackedByteArray_decode_half, sarray("byte_offset"), varray()); + bind_function(PackedByteArray, decode_float, _VariantCall::func_PackedByteArray_decode_float, sarray("byte_offset"), varray()); + bind_function(PackedByteArray, decode_double, _VariantCall::func_PackedByteArray_decode_double, sarray("byte_offset"), varray()); + bind_function(PackedByteArray, has_encoded_var, _VariantCall::func_PackedByteArray_has_encoded_var, sarray("byte_offset", "allow_objects"), varray(false)); + bind_function(PackedByteArray, decode_var, _VariantCall::func_PackedByteArray_decode_var, sarray("byte_offset", "allow_objects"), varray(false)); + bind_function(PackedByteArray, decode_var_size, _VariantCall::func_PackedByteArray_decode_var_size, sarray("byte_offset", "allow_objects"), varray(false)); + + bind_functionnc(PackedByteArray, encode_u8, _VariantCall::func_PackedByteArray_encode_u8, sarray("byte_offset", "value"), varray()); + bind_functionnc(PackedByteArray, encode_s8, _VariantCall::func_PackedByteArray_encode_s8, sarray("byte_offset", "value"), varray()); + bind_functionnc(PackedByteArray, encode_u16, _VariantCall::func_PackedByteArray_encode_u16, sarray("byte_offset", "value"), varray()); + bind_functionnc(PackedByteArray, encode_s16, _VariantCall::func_PackedByteArray_encode_s16, sarray("byte_offset", "value"), varray()); + bind_functionnc(PackedByteArray, encode_u32, _VariantCall::func_PackedByteArray_encode_u32, sarray("byte_offset", "value"), varray()); + bind_functionnc(PackedByteArray, encode_s32, _VariantCall::func_PackedByteArray_encode_s32, sarray("byte_offset", "value"), varray()); + bind_functionnc(PackedByteArray, encode_u64, _VariantCall::func_PackedByteArray_encode_u64, sarray("byte_offset", "value"), varray()); + bind_functionnc(PackedByteArray, encode_s64, _VariantCall::func_PackedByteArray_encode_s64, sarray("byte_offset", "value"), varray()); + bind_functionnc(PackedByteArray, encode_half, _VariantCall::func_PackedByteArray_encode_half, sarray("byte_offset", "value"), varray()); + bind_functionnc(PackedByteArray, encode_float, _VariantCall::func_PackedByteArray_encode_float, sarray("byte_offset", "value"), varray()); + bind_functionnc(PackedByteArray, encode_double, _VariantCall::func_PackedByteArray_encode_double, sarray("byte_offset", "value"), varray()); + bind_functionnc(PackedByteArray, encode_var, _VariantCall::func_PackedByteArray_encode_var, sarray("byte_offset", "value", "allow_objects"), varray(false)); + /* Int32 Array */ bind_method(PackedInt32Array, size, sarray(), varray()); @@ -1344,9 +1733,10 @@ static void _register_variant_builtin_methods() { bind_method(PackedInt32Array, append_array, sarray("array"), varray()); bind_method(PackedInt32Array, remove, sarray("index"), varray()); bind_method(PackedInt32Array, insert, sarray("at_index", "value"), varray()); + bind_method(PackedInt32Array, fill, sarray("value"), varray()); bind_method(PackedInt32Array, resize, sarray("new_size"), varray()); bind_method(PackedInt32Array, has, sarray("value"), varray()); - bind_method(PackedInt32Array, invert, sarray(), varray()); + bind_method(PackedInt32Array, reverse, sarray(), varray()); bind_method(PackedInt32Array, subarray, sarray("from", "to"), varray()); bind_method(PackedInt32Array, to_byte_array, sarray(), varray()); bind_method(PackedInt32Array, sort, sarray(), varray()); @@ -1362,9 +1752,10 @@ static void _register_variant_builtin_methods() { bind_method(PackedInt64Array, append_array, sarray("array"), varray()); bind_method(PackedInt64Array, remove, sarray("index"), varray()); bind_method(PackedInt64Array, insert, sarray("at_index", "value"), varray()); + bind_method(PackedInt64Array, fill, sarray("value"), varray()); bind_method(PackedInt64Array, resize, sarray("new_size"), varray()); bind_method(PackedInt64Array, has, sarray("value"), varray()); - bind_method(PackedInt64Array, invert, sarray(), varray()); + bind_method(PackedInt64Array, reverse, sarray(), varray()); bind_method(PackedInt64Array, subarray, sarray("from", "to"), varray()); bind_method(PackedInt64Array, to_byte_array, sarray(), varray()); bind_method(PackedInt64Array, sort, sarray(), varray()); @@ -1380,9 +1771,10 @@ static void _register_variant_builtin_methods() { bind_method(PackedFloat32Array, append_array, sarray("array"), varray()); bind_method(PackedFloat32Array, remove, sarray("index"), varray()); bind_method(PackedFloat32Array, insert, sarray("at_index", "value"), varray()); + bind_method(PackedFloat32Array, fill, sarray("value"), varray()); bind_method(PackedFloat32Array, resize, sarray("new_size"), varray()); bind_method(PackedFloat32Array, has, sarray("value"), varray()); - bind_method(PackedFloat32Array, invert, sarray(), varray()); + bind_method(PackedFloat32Array, reverse, sarray(), varray()); bind_method(PackedFloat32Array, subarray, sarray("from", "to"), varray()); bind_method(PackedFloat32Array, to_byte_array, sarray(), varray()); bind_method(PackedFloat32Array, sort, sarray(), varray()); @@ -1398,9 +1790,10 @@ static void _register_variant_builtin_methods() { bind_method(PackedFloat64Array, append_array, sarray("array"), varray()); bind_method(PackedFloat64Array, remove, sarray("index"), varray()); bind_method(PackedFloat64Array, insert, sarray("at_index", "value"), varray()); + bind_method(PackedFloat64Array, fill, sarray("value"), varray()); bind_method(PackedFloat64Array, resize, sarray("new_size"), varray()); bind_method(PackedFloat64Array, has, sarray("value"), varray()); - bind_method(PackedFloat64Array, invert, sarray(), varray()); + bind_method(PackedFloat64Array, reverse, sarray(), varray()); bind_method(PackedFloat64Array, subarray, sarray("from", "to"), varray()); bind_method(PackedFloat64Array, to_byte_array, sarray(), varray()); bind_method(PackedFloat64Array, sort, sarray(), varray()); @@ -1416,9 +1809,10 @@ static void _register_variant_builtin_methods() { bind_method(PackedStringArray, append_array, sarray("array"), varray()); bind_method(PackedStringArray, remove, sarray("index"), varray()); bind_method(PackedStringArray, insert, sarray("at_index", "value"), varray()); + bind_method(PackedStringArray, fill, sarray("value"), varray()); bind_method(PackedStringArray, resize, sarray("new_size"), varray()); bind_method(PackedStringArray, has, sarray("value"), varray()); - bind_method(PackedStringArray, invert, sarray(), varray()); + bind_method(PackedStringArray, reverse, sarray(), varray()); bind_method(PackedStringArray, subarray, sarray("from", "to"), varray()); bind_method(PackedStringArray, to_byte_array, sarray(), varray()); bind_method(PackedStringArray, sort, sarray(), varray()); @@ -1434,9 +1828,10 @@ static void _register_variant_builtin_methods() { bind_method(PackedVector2Array, append_array, sarray("array"), varray()); bind_method(PackedVector2Array, remove, sarray("index"), varray()); bind_method(PackedVector2Array, insert, sarray("at_index", "value"), varray()); + bind_method(PackedVector2Array, fill, sarray("value"), varray()); bind_method(PackedVector2Array, resize, sarray("new_size"), varray()); bind_method(PackedVector2Array, has, sarray("value"), varray()); - bind_method(PackedVector2Array, invert, sarray(), varray()); + bind_method(PackedVector2Array, reverse, sarray(), varray()); bind_method(PackedVector2Array, subarray, sarray("from", "to"), varray()); bind_method(PackedVector2Array, to_byte_array, sarray(), varray()); bind_method(PackedVector2Array, sort, sarray(), varray()); @@ -1452,9 +1847,10 @@ static void _register_variant_builtin_methods() { bind_method(PackedVector3Array, append_array, sarray("array"), varray()); bind_method(PackedVector3Array, remove, sarray("index"), varray()); bind_method(PackedVector3Array, insert, sarray("at_index", "value"), varray()); + bind_method(PackedVector3Array, fill, sarray("value"), varray()); bind_method(PackedVector3Array, resize, sarray("new_size"), varray()); bind_method(PackedVector3Array, has, sarray("value"), varray()); - bind_method(PackedVector3Array, invert, sarray(), varray()); + bind_method(PackedVector3Array, reverse, sarray(), varray()); bind_method(PackedVector3Array, subarray, sarray("from", "to"), varray()); bind_method(PackedVector3Array, to_byte_array, sarray(), varray()); bind_method(PackedVector3Array, sort, sarray(), varray()); @@ -1470,9 +1866,10 @@ static void _register_variant_builtin_methods() { bind_method(PackedColorArray, append_array, sarray("array"), varray()); bind_method(PackedColorArray, remove, sarray("index"), varray()); bind_method(PackedColorArray, insert, sarray("at_index", "value"), varray()); + bind_method(PackedColorArray, fill, sarray("value"), varray()); bind_method(PackedColorArray, resize, sarray("new_size"), varray()); bind_method(PackedColorArray, has, sarray("value"), varray()); - bind_method(PackedColorArray, invert, sarray(), varray()); + bind_method(PackedColorArray, reverse, sarray(), varray()); bind_method(PackedColorArray, subarray, sarray("from", "to"), varray()); bind_method(PackedColorArray, to_byte_array, sarray(), varray()); bind_method(PackedColorArray, sort, sarray(), varray()); diff --git a/core/variant/variant_op.cpp b/core/variant/variant_op.cpp index e0a3cf4215..6cbc98d14d 100644 --- a/core/variant/variant_op.cpp +++ b/core/variant/variant_op.cpp @@ -1365,10 +1365,10 @@ void register_op(Variant::Operator p_op, Variant::Type p_type_a, Variant::Type p } void Variant::_register_variant_operators() { - zeromem(operator_return_type_table, sizeof(operator_return_type_table)); - zeromem(operator_evaluator_table, sizeof(operator_evaluator_table)); - zeromem(validated_operator_evaluator_table, sizeof(validated_operator_evaluator_table)); - zeromem(ptr_operator_evaluator_table, sizeof(ptr_operator_evaluator_table)); + memset(operator_return_type_table, 0, sizeof(operator_return_type_table)); + memset(operator_evaluator_table, 0, sizeof(operator_evaluator_table)); + memset(validated_operator_evaluator_table, 0, sizeof(validated_operator_evaluator_table)); + memset(ptr_operator_evaluator_table, 0, sizeof(ptr_operator_evaluator_table)); register_op<OperatorEvaluatorAdd<int64_t, int64_t, int64_t>>(Variant::OP_ADD, Variant::INT, Variant::INT); register_op<OperatorEvaluatorAdd<double, int64_t, double>>(Variant::OP_ADD, Variant::INT, Variant::FLOAT); diff --git a/core/variant/variant_parser.cpp b/core/variant/variant_parser.cpp index ed936c626b..edaeddbf27 100644 --- a/core/variant/variant_parser.cpp +++ b/core/variant/variant_parser.cpp @@ -381,7 +381,6 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri r_token.value = num.as_int(); } return OK; - } else if ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_') { StringBuffer<> id; bool first = true; @@ -508,8 +507,8 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, } else if (id == "nan") { value = Math_NAN; } else if (id == "Vector2") { - Vector<float> args; - Error err = _parse_construct<float>(p_stream, args, line, r_err_str); + Vector<real_t> args; + Error err = _parse_construct<real_t>(p_stream, args, line, r_err_str); if (err) { return err; } @@ -534,8 +533,8 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, value = Vector2i(args[0], args[1]); } else if (id == "Rect2") { - Vector<float> args; - Error err = _parse_construct<float>(p_stream, args, line, r_err_str); + Vector<real_t> args; + Error err = _parse_construct<real_t>(p_stream, args, line, r_err_str); if (err) { return err; } @@ -560,8 +559,8 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, value = Rect2i(args[0], args[1], args[2], args[3]); } else if (id == "Vector3") { - Vector<float> args; - Error err = _parse_construct<float>(p_stream, args, line, r_err_str); + Vector<real_t> args; + Error err = _parse_construct<real_t>(p_stream, args, line, r_err_str); if (err) { return err; } @@ -586,8 +585,8 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, value = Vector3i(args[0], args[1], args[2]); } else if (id == "Transform2D" || id == "Matrix32") { //compatibility - Vector<float> args; - Error err = _parse_construct<float>(p_stream, args, line, r_err_str); + Vector<real_t> args; + Error err = _parse_construct<real_t>(p_stream, args, line, r_err_str); if (err) { return err; } @@ -603,8 +602,8 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, m[2] = Vector2(args[4], args[5]); value = m; } else if (id == "Plane") { - Vector<float> args; - Error err = _parse_construct<float>(p_stream, args, line, r_err_str); + Vector<real_t> args; + Error err = _parse_construct<real_t>(p_stream, args, line, r_err_str); if (err) { return err; } @@ -616,8 +615,8 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, value = Plane(args[0], args[1], args[2], args[3]); } else if (id == "Quat") { - Vector<float> args; - Error err = _parse_construct<float>(p_stream, args, line, r_err_str); + Vector<real_t> args; + Error err = _parse_construct<real_t>(p_stream, args, line, r_err_str); if (err) { return err; } @@ -629,8 +628,8 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, value = Quat(args[0], args[1], args[2], args[3]); } else if (id == "AABB" || id == "Rect3") { - Vector<float> args; - Error err = _parse_construct<float>(p_stream, args, line, r_err_str); + Vector<real_t> args; + Error err = _parse_construct<real_t>(p_stream, args, line, r_err_str); if (err) { return err; } @@ -642,8 +641,8 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, value = AABB(Vector3(args[0], args[1], args[2]), Vector3(args[3], args[4], args[5])); } else if (id == "Basis" || id == "Matrix3") { //compatibility - Vector<float> args; - Error err = _parse_construct<float>(p_stream, args, line, r_err_str); + Vector<real_t> args; + Error err = _parse_construct<real_t>(p_stream, args, line, r_err_str); if (err) { return err; } @@ -655,8 +654,8 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, value = Basis(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8]); } else if (id == "Transform") { - Vector<float> args; - Error err = _parse_construct<float>(p_stream, args, line, r_err_str); + Vector<real_t> args; + Error err = _parse_construct<real_t>(p_stream, args, line, r_err_str); if (err) { return err; } @@ -1006,8 +1005,8 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, value = arr; } else if (id == "PackedVector2Array" || id == "PoolVector2Array" || id == "Vector2Array") { - Vector<float> args; - Error err = _parse_construct<float>(p_stream, args, line, r_err_str); + Vector<real_t> args; + Error err = _parse_construct<real_t>(p_stream, args, line, r_err_str); if (err) { return err; } @@ -1024,8 +1023,8 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, value = arr; } else if (id == "PackedVector3Array" || id == "PoolVector3Array" || id == "Vector3Array") { - Vector<float> args; - Error err = _parse_construct<float>(p_stream, args, line, r_err_str); + Vector<real_t> args; + Error err = _parse_construct<real_t>(p_stream, args, line, r_err_str); if (err) { return err; } diff --git a/core/variant/variant_setget.cpp b/core/variant/variant_setget.cpp index ea8263402a..9ab8602782 100644 --- a/core/variant/variant_setget.cpp +++ b/core/variant/variant_setget.cpp @@ -875,65 +875,66 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const { static uint64_t get_indexed_size(const Variant *base) { return m_max; } \ }; -#define INDEXED_SETGET_STRUCT_VARIANT(m_base_type) \ - struct VariantIndexedSetGet_##m_base_type { \ - static void get(const Variant *base, int64_t index, Variant *value, bool *oob) { \ - int64_t size = VariantGetInternalPtr<m_base_type>::get_ptr(base)->size(); \ - if (index < 0) { \ - index += size; \ - } \ - if (index < 0 || index >= size) { \ - *oob = true; \ - return; \ - } \ - *value = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index]; \ - *oob = false; \ - } \ - static void ptr_get(const void *base, int64_t index, void *member) { \ - /* avoid ptrconvert for performance*/ \ - const m_base_type &v = *reinterpret_cast<const m_base_type *>(base); \ - if (index < 0) \ - index += v.size(); \ - OOB_TEST(index, v.size()); \ - PtrToArg<Variant>::encode(v[index], member); \ - } \ - static void set(Variant *base, int64_t index, const Variant *value, bool *valid, bool *oob) { \ - int64_t size = VariantGetInternalPtr<m_base_type>::get_ptr(base)->size(); \ - if (index < 0) { \ - index += size; \ - } \ - if (index < 0 || index >= size) { \ - *oob = true; \ - *valid = false; \ - return; \ - } \ - (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index] = *value; \ - *oob = false; \ - *valid = true; \ - } \ - static void validated_set(Variant *base, int64_t index, const Variant *value, bool *oob) { \ - int64_t size = VariantGetInternalPtr<m_base_type>::get_ptr(base)->size(); \ - if (index < 0) { \ - index += size; \ - } \ - if (index < 0 || index >= size) { \ - *oob = true; \ - return; \ - } \ - (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index] = *value; \ - *oob = false; \ - } \ - static void ptr_set(void *base, int64_t index, const void *member) { \ - /* avoid ptrconvert for performance*/ \ - m_base_type &v = *reinterpret_cast<m_base_type *>(base); \ - if (index < 0) \ - index += v.size(); \ - OOB_TEST(index, v.size()); \ - v[index] = PtrToArg<Variant>::convert(member); \ - } \ - static Variant::Type get_index_type() { return Variant::NIL; } \ - static uint64_t get_indexed_size(const Variant *base) { return 0; } \ - }; +struct VariantIndexedSetGet_Array { + static void get(const Variant *base, int64_t index, Variant *value, bool *oob) { + int64_t size = VariantGetInternalPtr<Array>::get_ptr(base)->size(); + if (index < 0) { + index += size; + } + if (index < 0 || index >= size) { + *oob = true; + return; + } + *value = (*VariantGetInternalPtr<Array>::get_ptr(base))[index]; + *oob = false; + } + static void ptr_get(const void *base, int64_t index, void *member) { + /* avoid ptrconvert for performance*/ + const Array &v = *reinterpret_cast<const Array *>(base); + if (index < 0) { + index += v.size(); + } + OOB_TEST(index, v.size()); + PtrToArg<Variant>::encode(v[index], member); + } + static void set(Variant *base, int64_t index, const Variant *value, bool *valid, bool *oob) { + int64_t size = VariantGetInternalPtr<Array>::get_ptr(base)->size(); + if (index < 0) { + index += size; + } + if (index < 0 || index >= size) { + *oob = true; + *valid = false; + return; + } + VariantGetInternalPtr<Array>::get_ptr(base)->set(index, *value); + *oob = false; + *valid = true; + } + static void validated_set(Variant *base, int64_t index, const Variant *value, bool *oob) { + int64_t size = VariantGetInternalPtr<Array>::get_ptr(base)->size(); + if (index < 0) { + index += size; + } + if (index < 0 || index >= size) { + *oob = true; + return; + } + VariantGetInternalPtr<Array>::get_ptr(base)->set(index, *value); + *oob = false; + } + static void ptr_set(void *base, int64_t index, const void *member) { + /* avoid ptrconvert for performance*/ + Array &v = *reinterpret_cast<Array *>(base); + if (index < 0) { + index += v.size(); + } + OOB_TEST(index, v.size()); + v.set(index, PtrToArg<Variant>::convert(member)); + } + static Variant::Type get_index_type() { return Variant::NIL; } + static uint64_t get_indexed_size(const Variant *base) { return 0; } +}; #define INDEXED_SETGET_STRUCT_DICT(m_base_type) \ struct VariantIndexedSetGet_##m_base_type { \ @@ -990,7 +991,6 @@ INDEXED_SETGET_STRUCT_TYPED(PackedVector3Array, Vector3) INDEXED_SETGET_STRUCT_TYPED(PackedStringArray, String) INDEXED_SETGET_STRUCT_TYPED(PackedColorArray, Color) -INDEXED_SETGET_STRUCT_VARIANT(Array) INDEXED_SETGET_STRUCT_DICT(Dictionary) struct VariantIndexedSetterGetterInfo { @@ -1045,6 +1045,7 @@ void register_indexed_setters_getters() { REGISTER_INDEXED_MEMBER(PackedByteArray); REGISTER_INDEXED_MEMBER(PackedInt32Array); REGISTER_INDEXED_MEMBER(PackedInt64Array); + REGISTER_INDEXED_MEMBER(PackedFloat32Array); REGISTER_INDEXED_MEMBER(PackedFloat64Array); REGISTER_INDEXED_MEMBER(PackedVector2Array); REGISTER_INDEXED_MEMBER(PackedVector3Array); @@ -2198,7 +2199,7 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant & } return; case STRING: { - //this is pretty funny and bizarre, but artists like to use it for typewritter effects + //this is pretty funny and bizarre, but artists like to use it for typewriter effects String sa = *reinterpret_cast<const String *>(a._data._mem); String sb = *reinterpret_cast<const String *>(b._data._mem); String dst; |