Skip to content

Commit 696285f

Browse files
committed
Use MethodInfo::get_compatibility_hash() to generate the hash for MethodBind::get_hash() and other GDExtension hash clean up
1 parent 5b52b4b commit 696285f

File tree

8 files changed

+26
-28
lines changed

8 files changed

+26
-28
lines changed

core/extension/gdextension_special_compat_hashes.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ void GDExtensionSpecialCompatHashes::initialize() {
255255
#endif
256256
});
257257
mappings.insert("DirAccess", {
258-
{ "list_dir_begin", 2018049411, 2610976713 },
258+
{ "list_dir_begin", 2018049411, 166280745 },
259+
{ "list_dir_begin", 2610976713, 166280745 },
259260
{ "copy", 198434953, 1063198817 },
260261
{ "copy_absolute", 198434953, 1063198817 },
261262
});
@@ -277,7 +278,8 @@ void GDExtensionSpecialCompatHashes::initialize() {
277278
{ "global_menu_add_multistate_item", 3431222859, 3297554655 },
278279
{ "global_menu_add_separator", 1041533178, 3214812433 },
279280
{ "tts_speak", 3741216677, 903992738 },
280-
{ "is_touchscreen_available", 4162880507, 3323674545 },
281+
{ "is_touchscreen_available", 4162880507, 36873697 },
282+
{ "is_touchscreen_available", 3323674545, 36873697 },
281283
{ "screen_set_orientation", 2629526904, 2211511631 },
282284
{ "window_get_native_handle", 2709193271, 1096425680 },
283285
{ "window_set_title", 3043792800, 441246282 },
@@ -548,6 +550,9 @@ void GDExtensionSpecialCompatHashes::initialize() {
548550
{ "tr", 2475554935, 1195764410 },
549551
{ "tr_n", 4021311862, 162698058 },
550552
});
553+
mappings.insert("OpenXRAPIExtension", {
554+
{ "transform_from_pose", 3255299855, 2963875352 },
555+
});
551556
mappings.insert("OptionButton", {
552557
{ "add_item", 3043792800, 2697778442 },
553558
{ "add_icon_item", 3944051090, 3781678508 },
@@ -912,6 +917,9 @@ void GDExtensionSpecialCompatHashes::initialize() {
912917
{ "set_cells_terrain_path", 3072115677, 3578627656 },
913918
{ "get_used_cells_by_id", 4152068407, 2931012785 },
914919
});
920+
mappings.insert("TileMapLayer", {
921+
{ "notify_runtime_tile_data_update", 2275361663, 3218959716 },
922+
});
915923
mappings.insert("TileMapPattern", {
916924
{ "set_cell", 634000503, 2224802556 },
917925
});

core/io/dir_access.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ void DirAccess::_bind_methods() {
631631
ClassDB::bind_static_method("DirAccess", D_METHOD("get_open_error"), &DirAccess::get_open_error);
632632
ClassDB::bind_static_method("DirAccess", D_METHOD("create_temp", "prefix", "keep"), &DirAccess::_create_temp, DEFVAL(""), DEFVAL(false));
633633

634-
ClassDB::bind_method(D_METHOD("list_dir_begin"), &DirAccess::list_dir_begin, DEFVAL(false), DEFVAL(false));
634+
ClassDB::bind_method(D_METHOD("list_dir_begin"), &DirAccess::list_dir_begin);
635635
ClassDB::bind_method(D_METHOD("get_next"), &DirAccess::_get_next);
636636
ClassDB::bind_method(D_METHOD("current_is_dir"), &DirAccess::current_is_dir);
637637
ClassDB::bind_method(D_METHOD("list_dir_end"), &DirAccess::list_dir_end);

core/object/class_db.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,6 +1959,11 @@ MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, bool p_
19591959
ERR_FAIL_V_MSG(nullptr, vformat("Method definition provides more arguments than the method actually has '%s::%s'.", instance_type, mdname));
19601960
}
19611961

1962+
if (p_defcount > p_bind->get_argument_count()) {
1963+
memdelete(p_bind);
1964+
ERR_FAIL_V_MSG(nullptr, vformat("Method definition for '%s::%s' provides more default arguments than the method has arguments.", instance_type, mdname));
1965+
}
1966+
19621967
p_bind->set_argument_names(method_name.args);
19631968

19641969
if (!p_compatibility) {

core/object/method_bind.cpp

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,15 @@
3535
#include "method_bind.h"
3636

3737
uint32_t MethodBind::get_hash() const {
38-
uint32_t hash = hash_murmur3_one_32(has_return() ? 1 : 0);
39-
hash = hash_murmur3_one_32(get_argument_count(), hash);
40-
41-
for (int i = (has_return() ? -1 : 0); i < get_argument_count(); i++) {
42-
PropertyInfo pi = i == -1 ? get_return_info() : get_argument_info(i);
43-
hash = hash_murmur3_one_32(get_argument_type(i), hash);
44-
if (pi.class_name != StringName()) {
45-
hash = hash_murmur3_one_32(pi.class_name.operator String().hash(), hash);
46-
}
47-
}
48-
49-
hash = hash_murmur3_one_32(get_default_argument_count(), hash);
38+
MethodInfo mi;
39+
mi.return_val = get_return_info();
40+
mi.flags = get_hint_flags();
5041
for (int i = 0; i < get_argument_count(); i++) {
51-
if (has_default_argument(i)) {
52-
Variant v = get_default_argument(i);
53-
hash = hash_murmur3_one_32(v.hash(), hash);
54-
}
42+
mi.arguments.push_back(get_argument_info(i));
5543
}
44+
mi.default_arguments = default_arguments;
5645

57-
hash = hash_murmur3_one_32(is_const(), hash);
58-
hash = hash_murmur3_one_32(is_vararg(), hash);
59-
60-
return hash_fmix32(hash);
46+
return mi.get_compatibility_hash();
6147
}
6248

6349
PropertyInfo MethodBind::get_argument_info(int p_argument) const {

core/object/object.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ MethodInfo MethodInfo::from_dict(const Dictionary &p_dict) {
165165
return mi;
166166
}
167167

168-
// This was copied from MethodBind::get_hash() so that the compatibility hashes for virtual and non-virtual methods would be the same.
169168
uint32_t MethodInfo::get_compatibility_hash() const {
170169
bool has_return = (return_val.type != Variant::NIL) || (return_val.usage & PROPERTY_USAGE_NIL_IS_VARIANT);
171170

core/variant/native_ptr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ struct GDExtensionPtr {
121121

122122
template <typename T>
123123
struct GetTypeInfo<GDExtensionConstPtr<T>> {
124-
static const Variant::Type VARIANT_TYPE = Variant::NIL;
124+
static const Variant::Type VARIANT_TYPE = Variant::INT;
125125
static const GodotTypeInfo::Metadata METADATA = GodotTypeInfo::METADATA_NONE;
126126
static inline PropertyInfo get_class_info() {
127127
return PropertyInfo(Variant::INT, String(), PROPERTY_HINT_INT_IS_POINTER, GDExtensionConstPtr<T>::get_name());
@@ -130,7 +130,7 @@ struct GetTypeInfo<GDExtensionConstPtr<T>> {
130130

131131
template <typename T>
132132
struct GetTypeInfo<GDExtensionPtr<T>> {
133-
static const Variant::Type VARIANT_TYPE = Variant::NIL;
133+
static const Variant::Type VARIANT_TYPE = Variant::INT;
134134
static const GodotTypeInfo::Metadata METADATA = GodotTypeInfo::METADATA_NONE;
135135
static inline PropertyInfo get_class_info() {
136136
return PropertyInfo(Variant::INT, String(), PROPERTY_HINT_INT_IS_POINTER, GDExtensionPtr<T>::get_name());

scene/2d/tile_map_layer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1834,7 +1834,7 @@ void TileMapLayer::_bind_methods() {
18341834

18351835
// --- Runtime ---
18361836
ClassDB::bind_method(D_METHOD("update_internals"), &TileMapLayer::update_internals);
1837-
ClassDB::bind_method(D_METHOD("notify_runtime_tile_data_update"), &TileMapLayer::notify_runtime_tile_data_update, DEFVAL(-1));
1837+
ClassDB::bind_method(D_METHOD("notify_runtime_tile_data_update"), &TileMapLayer::notify_runtime_tile_data_update);
18381838

18391839
// --- Shortcuts to methods defined in TileSet ---
18401840
ClassDB::bind_method(D_METHOD("map_pattern", "position_in_tilemap", "coords_in_pattern", "pattern"), &TileMapLayer::map_pattern);

servers/display_server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ void DisplayServer::_bind_methods() {
917917
ClassDB::bind_method(D_METHOD("screen_get_usable_rect", "screen"), &DisplayServer::screen_get_usable_rect, DEFVAL(SCREEN_OF_MAIN_WINDOW));
918918
ClassDB::bind_method(D_METHOD("screen_get_dpi", "screen"), &DisplayServer::screen_get_dpi, DEFVAL(SCREEN_OF_MAIN_WINDOW));
919919
ClassDB::bind_method(D_METHOD("screen_get_scale", "screen"), &DisplayServer::screen_get_scale, DEFVAL(SCREEN_OF_MAIN_WINDOW));
920-
ClassDB::bind_method(D_METHOD("is_touchscreen_available"), &DisplayServer::is_touchscreen_available, DEFVAL(SCREEN_OF_MAIN_WINDOW));
920+
ClassDB::bind_method(D_METHOD("is_touchscreen_available"), &DisplayServer::is_touchscreen_available);
921921
ClassDB::bind_method(D_METHOD("screen_get_max_scale"), &DisplayServer::screen_get_max_scale);
922922
ClassDB::bind_method(D_METHOD("screen_get_refresh_rate", "screen"), &DisplayServer::screen_get_refresh_rate, DEFVAL(SCREEN_OF_MAIN_WINDOW));
923923
ClassDB::bind_method(D_METHOD("screen_get_pixel", "position"), &DisplayServer::screen_get_pixel);

0 commit comments

Comments
 (0)