Skip to content

Commit

Permalink
Merge pull request #48746 from KoBeWi/bane_of_all_virtual_compatibility
Browse files Browse the repository at this point in the history
Consistently prefix bound virtual methods with _
  • Loading branch information
akien-mga authored Jun 12, 2021
2 parents ac73059 + 7ff135b commit 6d98f84
Show file tree
Hide file tree
Showing 51 changed files with 1,007 additions and 1,132 deletions.
38 changes: 19 additions & 19 deletions core/io/resource_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ bool ResourceFormatLoader::recognize_path(const String &p_path, const String &p_
}

bool ResourceFormatLoader::handles_type(const String &p_type) const {
if (get_script_instance() && get_script_instance()->has_method("handles_type")) {
if (get_script_instance() && get_script_instance()->has_method("_handles_type")) {
// I guess custom loaders for custom resources should use "Resource"
return get_script_instance()->call("handles_type", p_type);
return get_script_instance()->call("_handles_type", p_type);
}

return false;
}

String ResourceFormatLoader::get_resource_type(const String &p_path) const {
if (get_script_instance() && get_script_instance()->has_method("get_resource_type")) {
return get_script_instance()->call("get_resource_type", p_path);
if (get_script_instance() && get_script_instance()->has_method("_get_resource_type")) {
return get_script_instance()->call("_get_resource_type", p_path);
}

return "";
Expand All @@ -101,8 +101,8 @@ bool ResourceFormatLoader::exists(const String &p_path) const {
}

void ResourceFormatLoader::get_recognized_extensions(List<String> *p_extensions) const {
if (get_script_instance() && get_script_instance()->has_method("get_recognized_extensions")) {
PackedStringArray exts = get_script_instance()->call("get_recognized_extensions");
if (get_script_instance() && get_script_instance()->has_method("_get_recognized_extensions")) {
PackedStringArray exts = get_script_instance()->call("_get_recognized_extensions");

{
const String *r = exts.ptr();
Expand All @@ -115,8 +115,8 @@ void ResourceFormatLoader::get_recognized_extensions(List<String> *p_extensions)

RES ResourceFormatLoader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) {
// Check user-defined loader if there's any. Hard fail if it returns an error.
if (get_script_instance() && get_script_instance()->has_method("load")) {
Variant res = get_script_instance()->call("load", p_path, p_original_path, p_use_sub_threads, p_cache_mode);
if (get_script_instance() && get_script_instance()->has_method("_load")) {
Variant res = get_script_instance()->call("_load", p_path, p_original_path, p_use_sub_threads, p_cache_mode);

if (res.get_type() == Variant::INT) { // Error code, abort.
if (r_error) {
Expand All @@ -135,8 +135,8 @@ RES ResourceFormatLoader::load(const String &p_path, const String &p_original_pa
}

void ResourceFormatLoader::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) {
if (get_script_instance() && get_script_instance()->has_method("get_dependencies")) {
PackedStringArray deps = get_script_instance()->call("get_dependencies", p_path, p_add_types);
if (get_script_instance() && get_script_instance()->has_method("_get_dependencies")) {
PackedStringArray deps = get_script_instance()->call("_get_dependencies", p_path, p_add_types);

{
const String *r = deps.ptr();
Expand All @@ -148,13 +148,13 @@ void ResourceFormatLoader::get_dependencies(const String &p_path, List<String> *
}

Error ResourceFormatLoader::rename_dependencies(const String &p_path, const Map<String, String> &p_map) {
if (get_script_instance() && get_script_instance()->has_method("rename_dependencies")) {
if (get_script_instance() && get_script_instance()->has_method("_rename_dependencies")) {
Dictionary deps_dict;
for (Map<String, String>::Element *E = p_map.front(); E; E = E->next()) {
deps_dict[E->key()] = E->value();
}

int64_t res = get_script_instance()->call("rename_dependencies", deps_dict);
int64_t res = get_script_instance()->call("_rename_dependencies", deps_dict);
return (Error)res;
}

Expand All @@ -163,16 +163,16 @@ Error ResourceFormatLoader::rename_dependencies(const String &p_path, const Map<

void ResourceFormatLoader::_bind_methods() {
{
MethodInfo info = MethodInfo(Variant::NIL, "load", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::STRING, "original_path"), PropertyInfo(Variant::BOOL, "use_sub_threads"), PropertyInfo(Variant::INT, "cache_mode"));
MethodInfo info = MethodInfo(Variant::NIL, "_load", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::STRING, "original_path"), PropertyInfo(Variant::BOOL, "use_sub_threads"), PropertyInfo(Variant::INT, "cache_mode"));
info.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
ClassDB::add_virtual_method(get_class_static(), info);
BIND_VMETHOD(info);
}

ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::PACKED_STRING_ARRAY, "get_recognized_extensions"));
ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "handles_type", PropertyInfo(Variant::STRING_NAME, "typename")));
ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::STRING, "get_resource_type", PropertyInfo(Variant::STRING, "path")));
ClassDB::add_virtual_method(get_class_static(), MethodInfo("get_dependencies", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::STRING, "add_types")));
ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::INT, "rename_dependencies", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::STRING, "renames")));
BIND_VMETHOD(MethodInfo(Variant::PACKED_STRING_ARRAY, "_get_recognized_extensions"));
BIND_VMETHOD(MethodInfo(Variant::BOOL, "_handles_type", PropertyInfo(Variant::STRING_NAME, "typename")));
BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_resource_type", PropertyInfo(Variant::STRING, "path")));
BIND_VMETHOD(MethodInfo("_get_dependencies", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::STRING, "add_types")));
BIND_VMETHOD(MethodInfo(Variant::INT, "_rename_dependencies", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::STRING, "renames")));

BIND_ENUM_CONSTANT(CACHE_MODE_IGNORE);
BIND_ENUM_CONSTANT(CACHE_MODE_REUSE);
Expand Down
18 changes: 9 additions & 9 deletions core/io/resource_saver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,24 @@ bool ResourceSaver::timestamp_on_save = false;
ResourceSavedCallback ResourceSaver::save_callback = nullptr;

Error ResourceFormatSaver::save(const String &p_path, const RES &p_resource, uint32_t p_flags) {
if (get_script_instance() && get_script_instance()->has_method("save")) {
return (Error)get_script_instance()->call("save", p_path, p_resource, p_flags).operator int64_t();
if (get_script_instance() && get_script_instance()->has_method("_save")) {
return (Error)get_script_instance()->call("_save", p_path, p_resource, p_flags).operator int64_t();
}

return ERR_METHOD_NOT_FOUND;
}

bool ResourceFormatSaver::recognize(const RES &p_resource) const {
if (get_script_instance() && get_script_instance()->has_method("recognize")) {
return get_script_instance()->call("recognize", p_resource);
if (get_script_instance() && get_script_instance()->has_method("_recognize")) {
return get_script_instance()->call("_recognize", p_resource);
}

return false;
}

void ResourceFormatSaver::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const {
if (get_script_instance() && get_script_instance()->has_method("get_recognized_extensions")) {
PackedStringArray exts = get_script_instance()->call("get_recognized_extensions", p_resource);
if (get_script_instance() && get_script_instance()->has_method("_get_recognized_extensions")) {
PackedStringArray exts = get_script_instance()->call("_get_recognized_extensions", p_resource);

{
const String *r = exts.ptr();
Expand All @@ -74,11 +74,11 @@ void ResourceFormatSaver::_bind_methods() {
PropertyInfo arg0 = PropertyInfo(Variant::STRING, "path");
PropertyInfo arg1 = PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource");
PropertyInfo arg2 = PropertyInfo(Variant::INT, "flags");
ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::INT, "save", arg0, arg1, arg2));
BIND_VMETHOD(MethodInfo(Variant::INT, "_save", arg0, arg1, arg2));
}

ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::PACKED_STRING_ARRAY, "get_recognized_extensions", PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource")));
ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "recognize", PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource")));
BIND_VMETHOD(MethodInfo(Variant::PACKED_STRING_ARRAY, "_get_recognized_extensions", PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource")));
BIND_VMETHOD(MethodInfo(Variant::BOOL, "_recognize", PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource")));
}

Error ResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t p_flags) {
Expand Down
118 changes: 59 additions & 59 deletions doc/classes/AnimationNode.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,65 @@
<link title="AnimationTree">https://docs.godotengine.org/en/latest/tutorials/animation/animation_tree.html</link>
</tutorials>
<methods>
<method name="_get_caption" qualifiers="virtual">
<return type="String">
</return>
<description>
Gets the text caption for this node (used by some editors).
</description>
</method>
<method name="_get_child_by_name" qualifiers="virtual">
<return type="Object">
</return>
<argument index="0" name="name" type="String">
</argument>
<description>
Gets a child node by index (used by editors inheriting from [AnimationRootNode]).
</description>
</method>
<method name="_get_child_nodes" qualifiers="virtual">
<return type="Dictionary">
</return>
<description>
Gets all children nodes in order as a [code]name: node[/code] dictionary. Only useful when inheriting [AnimationRootNode].
</description>
</method>
<method name="_get_parameter_default_value" qualifiers="virtual">
<return type="Variant">
</return>
<argument index="0" name="name" type="StringName">
</argument>
<description>
Gets the default value of a parameter. Parameters are custom local memory used for your nodes, given a resource can be reused in multiple trees.
</description>
</method>
<method name="_get_parameter_list" qualifiers="virtual">
<return type="Array">
</return>
<description>
Gets the property information for parameter. Parameters are custom local memory used for your nodes, given a resource can be reused in multiple trees. Format is similar to [method Object.get_property_list].
</description>
</method>
<method name="_has_filter" qualifiers="virtual">
<return type="bool">
</return>
<description>
Returns [code]true[/code] whether you want the blend tree editor to display filter editing on this node.
</description>
</method>
<method name="_process" qualifiers="virtual">
<return type="void">
</return>
<argument index="0" name="time" type="float">
</argument>
<argument index="1" name="seek" type="bool">
</argument>
<description>
User-defined callback called when a custom node is processed. The [code]time[/code] parameter is a relative delta, unless [code]seek[/code] is [code]true[/code], in which case it is absolute.
Here, call the [method blend_input], [method blend_node] or [method blend_animation] functions. You can also use [method get_parameter] and [method set_parameter] to modify local memory.
This function should return the time left for the current animation to finish (if unsure, pass the value from the main blend being called).
</description>
</method>
<method name="add_input">
<return type="void">
</return>
Expand Down Expand Up @@ -77,29 +136,6 @@
Blend another animation node (in case this node contains children animation nodes). This function is only useful if you inherit from [AnimationRootNode] instead, else editors will not display your node for addition.
</description>
</method>
<method name="get_caption" qualifiers="virtual">
<return type="String">
</return>
<description>
Gets the text caption for this node (used by some editors).
</description>
</method>
<method name="get_child_by_name" qualifiers="virtual">
<return type="Object">
</return>
<argument index="0" name="name" type="String">
</argument>
<description>
Gets a child node by index (used by editors inheriting from [AnimationRootNode]).
</description>
</method>
<method name="get_child_nodes" qualifiers="virtual">
<return type="Dictionary">
</return>
<description>
Gets all children nodes in order as a [code]name: node[/code] dictionary. Only useful when inheriting [AnimationRootNode].
</description>
</method>
<method name="get_input_count" qualifiers="const">
<return type="int">
</return>
Expand All @@ -125,29 +161,6 @@
Gets the value of a parameter. Parameters are custom local memory used for your nodes, given a resource can be reused in multiple trees.
</description>
</method>
<method name="get_parameter_default_value" qualifiers="virtual">
<return type="Variant">
</return>
<argument index="0" name="name" type="StringName">
</argument>
<description>
Gets the default value of a parameter. Parameters are custom local memory used for your nodes, given a resource can be reused in multiple trees.
</description>
</method>
<method name="get_parameter_list" qualifiers="virtual">
<return type="Array">
</return>
<description>
Gets the property information for parameter. Parameters are custom local memory used for your nodes, given a resource can be reused in multiple trees. Format is similar to [method Object.get_property_list].
</description>
</method>
<method name="has_filter" qualifiers="virtual">
<return type="bool">
</return>
<description>
Returns [code]true[/code] whether you want the blend tree editor to display filter editing on this node.
</description>
</method>
<method name="is_path_filtered" qualifiers="const">
<return type="bool">
</return>
Expand All @@ -157,19 +170,6 @@
Returns [code]true[/code] whether a given path is filtered.
</description>
</method>
<method name="process" qualifiers="virtual">
<return type="void">
</return>
<argument index="0" name="time" type="float">
</argument>
<argument index="1" name="seek" type="bool">
</argument>
<description>
User-defined callback called when a custom node is processed. The [code]time[/code] parameter is a relative delta, unless [code]seek[/code] is [code]true[/code], in which case it is absolute.
Here, call the [method blend_input], [method blend_node] or [method blend_animation] functions. You can also use [method get_parameter] and [method set_parameter] to modify local memory.
This function should return the time left for the current animation to finish (if unsure, pass the value from the main blend being called).
</description>
</method>
<method name="remove_input">
<return type="void">
</return>
Expand Down
Loading

0 comments on commit 6d98f84

Please sign in to comment.