summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2021-08-22 09:31:44 -0300
committerGitHub <noreply@github.com>2021-08-22 09:31:44 -0300
commita73b5fa1124ab91401f965f0bf6fd48407b79c4e (patch)
treefee311b675144ae3a5fecc58857912ea250b1bb7 /modules
parent2a5c64f2a188360d09f793c0dbd35e1911b4c073 (diff)
parent3682978aee06cd5cf26ba462a4e44d352e9e0cd1 (diff)
Merge pull request #51970 from reduz/implement-gdvirtuals-everywhere
Replace BIND_VMETHOD by new GDVIRTUAL syntax
Diffstat (limited to 'modules')
-rw-r--r--modules/gdscript/editor/gdscript_highlighter.cpp2
-rw-r--r--modules/gdscript/editor/gdscript_highlighter.h2
-rw-r--r--modules/visual_script/doc_classes/VisualScriptCustomNode.xml54
-rw-r--r--modules/visual_script/doc_classes/VisualScriptSubCall.xml7
-rw-r--r--modules/visual_script/visual_script_nodes.cpp164
-rw-r--r--modules/visual_script/visual_script_nodes.h26
6 files changed, 149 insertions, 106 deletions
diff --git a/modules/gdscript/editor/gdscript_highlighter.cpp b/modules/gdscript/editor/gdscript_highlighter.cpp
index 0b1cb5d502..8b9bd2659d 100644
--- a/modules/gdscript/editor/gdscript_highlighter.cpp
+++ b/modules/gdscript/editor/gdscript_highlighter.cpp
@@ -45,7 +45,7 @@ static bool _is_bin_symbol(char32_t c) {
return (c == '0' || c == '1');
}
-Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting(int p_line) {
+Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_line) {
Dictionary color_map;
Type next_type = NONE;
diff --git a/modules/gdscript/editor/gdscript_highlighter.h b/modules/gdscript/editor/gdscript_highlighter.h
index d07c182aa6..fabd64dab8 100644
--- a/modules/gdscript/editor/gdscript_highlighter.h
+++ b/modules/gdscript/editor/gdscript_highlighter.h
@@ -80,7 +80,7 @@ private:
public:
virtual void _update_cache() override;
- virtual Dictionary _get_line_syntax_highlighting(int p_line) override;
+ virtual Dictionary _get_line_syntax_highlighting_impl(int p_line) override;
virtual String _get_name() const override;
virtual Array _get_supported_languages() const override;
diff --git a/modules/visual_script/doc_classes/VisualScriptCustomNode.xml b/modules/visual_script/doc_classes/VisualScriptCustomNode.xml
index 8aa34f8cae..b574576856 100644
--- a/modules/visual_script/doc_classes/VisualScriptCustomNode.xml
+++ b/modules/visual_script/doc_classes/VisualScriptCustomNode.xml
@@ -9,118 +9,118 @@
<tutorials>
</tutorials>
<methods>
- <method name="_get_caption" qualifiers="virtual">
+ <method name="_get_caption" qualifiers="virtual const">
<return type="String" />
<description>
Return the node's title.
</description>
</method>
- <method name="_get_category" qualifiers="virtual">
+ <method name="_get_category" qualifiers="virtual const">
<return type="String" />
<description>
Return the node's category.
</description>
</method>
- <method name="_get_input_value_port_count" qualifiers="virtual">
+ <method name="_get_input_value_port_count" qualifiers="virtual const">
<return type="int" />
<description>
Return the count of input value ports.
</description>
</method>
- <method name="_get_input_value_port_hint" qualifiers="virtual">
+ <method name="_get_input_value_port_hint" qualifiers="virtual const">
<return type="int" />
- <argument index="0" name="idx" type="int" />
+ <argument index="0" name="input_idx" type="int" />
<description>
Return the specified input port's hint. See the [enum @GlobalScope.PropertyHint] hints.
</description>
</method>
- <method name="_get_input_value_port_hint_string" qualifiers="virtual">
+ <method name="_get_input_value_port_hint_string" qualifiers="virtual const">
<return type="String" />
- <argument index="0" name="idx" type="int" />
+ <argument index="0" name="input_idx" type="int" />
<description>
Return the specified input port's hint string.
</description>
</method>
- <method name="_get_input_value_port_name" qualifiers="virtual">
+ <method name="_get_input_value_port_name" qualifiers="virtual const">
<return type="String" />
- <argument index="0" name="idx" type="int" />
+ <argument index="0" name="input_idx" type="int" />
<description>
Return the specified input port's name.
</description>
</method>
- <method name="_get_input_value_port_type" qualifiers="virtual">
+ <method name="_get_input_value_port_type" qualifiers="virtual const">
<return type="int" />
- <argument index="0" name="idx" type="int" />
+ <argument index="0" name="input_idx" type="int" />
<description>
Return the specified input port's type. See the [enum Variant.Type] values.
</description>
</method>
- <method name="_get_output_sequence_port_count" qualifiers="virtual">
+ <method name="_get_output_sequence_port_count" qualifiers="virtual const">
<return type="int" />
<description>
Return the amount of output [b]sequence[/b] ports.
</description>
</method>
- <method name="_get_output_sequence_port_text" qualifiers="virtual">
+ <method name="_get_output_sequence_port_text" qualifiers="virtual const">
<return type="String" />
- <argument index="0" name="idx" type="int" />
+ <argument index="0" name="seq_idx" type="int" />
<description>
Return the specified [b]sequence[/b] output's name.
</description>
</method>
- <method name="_get_output_value_port_count" qualifiers="virtual">
+ <method name="_get_output_value_port_count" qualifiers="virtual const">
<return type="int" />
<description>
Return the amount of output value ports.
</description>
</method>
- <method name="_get_output_value_port_hint" qualifiers="virtual">
+ <method name="_get_output_value_port_hint" qualifiers="virtual const">
<return type="int" />
- <argument index="0" name="idx" type="int" />
+ <argument index="0" name="output_idx" type="int" />
<description>
Return the specified output port's hint. See the [enum @GlobalScope.PropertyHint] hints.
</description>
</method>
- <method name="_get_output_value_port_hint_string" qualifiers="virtual">
+ <method name="_get_output_value_port_hint_string" qualifiers="virtual const">
<return type="String" />
- <argument index="0" name="idx" type="int" />
+ <argument index="0" name="output_idx" type="int" />
<description>
Return the specified output port's hint string.
</description>
</method>
- <method name="_get_output_value_port_name" qualifiers="virtual">
+ <method name="_get_output_value_port_name" qualifiers="virtual const">
<return type="String" />
- <argument index="0" name="idx" type="int" />
+ <argument index="0" name="output_idx" type="int" />
<description>
Return the specified output port's name.
</description>
</method>
- <method name="_get_output_value_port_type" qualifiers="virtual">
+ <method name="_get_output_value_port_type" qualifiers="virtual const">
<return type="int" />
- <argument index="0" name="idx" type="int" />
+ <argument index="0" name="output_idx" type="int" />
<description>
Return the specified output port's type. See the [enum Variant.Type] values.
</description>
</method>
- <method name="_get_text" qualifiers="virtual">
+ <method name="_get_text" qualifiers="virtual const">
<return type="String" />
<description>
Return the custom node's text, which is shown right next to the input [b]sequence[/b] port (if there is none, on the place that is usually taken by it).
</description>
</method>
- <method name="_get_working_memory_size" qualifiers="virtual">
+ <method name="_get_working_memory_size" qualifiers="virtual const">
<return type="int" />
<description>
Return the size of the custom node's working memory. See [method _step] for more details.
</description>
</method>
- <method name="_has_input_sequence_port" qualifiers="virtual">
+ <method name="_has_input_sequence_port" qualifiers="virtual const">
<return type="bool" />
<description>
Return whether the custom node has an input [b]sequence[/b] port.
</description>
</method>
- <method name="_step" qualifiers="virtual">
+ <method name="_step" qualifiers="virtual const">
<return type="Variant" />
<argument index="0" name="inputs" type="Array" />
<argument index="1" name="outputs" type="Array" />
diff --git a/modules/visual_script/doc_classes/VisualScriptSubCall.xml b/modules/visual_script/doc_classes/VisualScriptSubCall.xml
index 374e7d0f35..f54887b09c 100644
--- a/modules/visual_script/doc_classes/VisualScriptSubCall.xml
+++ b/modules/visual_script/doc_classes/VisualScriptSubCall.xml
@@ -9,13 +9,6 @@
<tutorials>
</tutorials>
<methods>
- <method name="_subcall" qualifiers="virtual">
- <return type="Variant" />
- <argument index="0" name="arguments" type="Variant" />
- <description>
- Called by this node.
- </description>
- </method>
</methods>
<constants>
</constants>
diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp
index c517d89aa5..c9e426fa6c 100644
--- a/modules/visual_script/visual_script_nodes.cpp
+++ b/modules/visual_script/visual_script_nodes.cpp
@@ -2825,36 +2825,41 @@ VisualScriptSelf::VisualScriptSelf() {
//////////////////////////////////////////
int VisualScriptCustomNode::get_output_sequence_port_count() const {
- if (get_script_instance() && get_script_instance()->has_method("_get_output_sequence_port_count")) {
- return get_script_instance()->call("_get_output_sequence_port_count");
+ int ret;
+ if (GDVIRTUAL_CALL(_get_output_sequence_port_count, ret)) {
+ return ret;
}
return 0;
}
bool VisualScriptCustomNode::has_input_sequence_port() const {
- if (get_script_instance() && get_script_instance()->has_method("_has_input_sequence_port")) {
- return get_script_instance()->call("_has_input_sequence_port");
+ bool ret;
+ if (GDVIRTUAL_CALL(_has_input_sequence_port, ret)) {
+ return ret;
}
return false;
}
int VisualScriptCustomNode::get_input_value_port_count() const {
- if (get_script_instance() && get_script_instance()->has_method("_get_input_value_port_count")) {
- return get_script_instance()->call("_get_input_value_port_count");
+ int ret;
+ if (GDVIRTUAL_CALL(_get_input_value_port_count, ret)) {
+ return ret;
}
return 0;
}
int VisualScriptCustomNode::get_output_value_port_count() const {
- if (get_script_instance() && get_script_instance()->has_method("_get_output_value_port_count")) {
- return get_script_instance()->call("_get_output_value_port_count");
+ int ret;
+ if (GDVIRTUAL_CALL(_get_output_value_port_count, ret)) {
+ return ret;
}
return 0;
}
String VisualScriptCustomNode::get_output_sequence_port_text(int p_port) const {
- if (get_script_instance() && get_script_instance()->has_method("_get_output_sequence_port_text")) {
- return get_script_instance()->call("_get_output_sequence_port_text", p_port);
+ String ret;
+ if (GDVIRTUAL_CALL(_get_output_sequence_port_text, p_port, ret)) {
+ return ret;
}
return String();
@@ -2862,34 +2867,61 @@ String VisualScriptCustomNode::get_output_sequence_port_text(int p_port) const {
PropertyInfo VisualScriptCustomNode::get_input_value_port_info(int p_idx) const {
PropertyInfo info;
- if (get_script_instance() && get_script_instance()->has_method("_get_input_value_port_type")) {
- info.type = Variant::Type(int(get_script_instance()->call("_get_input_value_port_type", p_idx)));
+ {
+ int type;
+ if (GDVIRTUAL_CALL(_get_input_value_port_type, p_idx, type)) {
+ info.type = Variant::Type(type);
+ }
}
- if (get_script_instance() && get_script_instance()->has_method("_get_input_value_port_name")) {
- info.name = get_script_instance()->call("_get_input_value_port_name", p_idx);
+ {
+ String name;
+ if (GDVIRTUAL_CALL(_get_input_value_port_name, p_idx, name)) {
+ info.name = name;
+ }
}
- if (get_script_instance() && get_script_instance()->has_method("_get_input_value_port_hint")) {
- info.hint = PropertyHint(int(get_script_instance()->call("_get_input_value_port_hint", p_idx)));
+ {
+ int hint;
+ if (GDVIRTUAL_CALL(_get_input_value_port_hint, p_idx, hint)) {
+ info.hint = PropertyHint(hint);
+ }
}
- if (get_script_instance() && get_script_instance()->has_method("_get_input_value_port_hint_string")) {
- info.hint_string = get_script_instance()->call("_get_input_value_port_hint_string", p_idx);
+
+ {
+ String hint_string;
+ if (GDVIRTUAL_CALL(_get_input_value_port_hint_string, p_idx, hint_string)) {
+ info.hint_string = hint_string;
+ }
}
+
return info;
}
PropertyInfo VisualScriptCustomNode::get_output_value_port_info(int p_idx) const {
PropertyInfo info;
- if (get_script_instance() && get_script_instance()->has_method("_get_output_value_port_type")) {
- info.type = Variant::Type(int(get_script_instance()->call("_get_output_value_port_type", p_idx)));
+ {
+ int type;
+ if (GDVIRTUAL_CALL(_get_output_value_port_type, p_idx, type)) {
+ info.type = Variant::Type(type);
+ }
}
- if (get_script_instance() && get_script_instance()->has_method("_get_output_value_port_name")) {
- info.name = get_script_instance()->call("_get_output_value_port_name", p_idx);
+ {
+ String name;
+ if (GDVIRTUAL_CALL(_get_output_value_port_name, p_idx, name)) {
+ info.name = name;
+ }
}
- if (get_script_instance() && get_script_instance()->has_method("_get_output_value_port_hint")) {
- info.hint = PropertyHint(int(get_script_instance()->call("_get_output_value_port_hint", p_idx)));
+ {
+ int hint;
+ if (GDVIRTUAL_CALL(_get_output_value_port_hint, p_idx, hint)) {
+ info.hint = PropertyHint(hint);
+ }
}
- if (get_script_instance() && get_script_instance()->has_method("_get_output_value_port_hint_string")) {
- info.hint_string = get_script_instance()->call("_get_output_value_port_hint_string", p_idx);
+
+ {
+ String hint_string;
+ if (GDVIRTUAL_CALL(_get_output_value_port_hint_string, p_idx, hint_string)) {
+ info.hint_string = hint_string;
+ }
}
return info;
}
@@ -2911,22 +2943,25 @@ VisualScriptCustomNode::TypeGuess VisualScriptCustomNode::guess_output_type(Type
}
String VisualScriptCustomNode::get_caption() const {
- if (get_script_instance() && get_script_instance()->has_method("_get_caption")) {
- return get_script_instance()->call("_get_caption");
+ String ret;
+ if (GDVIRTUAL_CALL(_get_caption, ret)) {
+ return ret;
}
return "CustomNode";
}
String VisualScriptCustomNode::get_text() const {
- if (get_script_instance() && get_script_instance()->has_method("_get_text")) {
- return get_script_instance()->call("_get_text");
+ String ret;
+ if (GDVIRTUAL_CALL(_get_text, ret)) {
+ return ret;
}
return "";
}
String VisualScriptCustomNode::get_category() const {
- if (get_script_instance() && get_script_instance()->has_method("_get_category")) {
- return get_script_instance()->call("_get_category");
+ String ret;
+ if (GDVIRTUAL_CALL(_get_category, ret)) {
+ return ret;
}
return "Custom";
}
@@ -2941,14 +2976,7 @@ public:
virtual int get_working_memory_size() const { return work_mem_size; }
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
- if (node->get_script_instance()) {
-#ifdef DEBUG_ENABLED
- if (!node->get_script_instance()->has_method(VisualScriptLanguage::singleton->_step)) {
- r_error_str = RTR("Custom node has no _step() method, can't process graph.");
- r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
- return 0;
- }
-#endif
+ if (GDVIRTUAL_IS_OVERRIDEN_PTR(node, _step)) {
Array in_values;
Array out_values;
Array work_mem;
@@ -2969,7 +2997,8 @@ public:
int ret_out;
- Variant ret = node->get_script_instance()->call(VisualScriptLanguage::singleton->_step, in_values, out_values, p_start_mode, work_mem);
+ Variant ret;
+ GDVIRTUAL_CALL_PTR(node, _step, in_values, out_values, p_start_mode, work_mem, ret);
if (ret.get_type() == Variant::STRING) {
r_error_str = ret;
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
@@ -2995,6 +3024,9 @@ public:
}
return ret_out;
+ } else {
+ r_error_str = RTR("Custom node has no _step() method, can't process graph.");
+ r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
}
return 0;
@@ -3008,11 +3040,8 @@ VisualScriptNodeInstance *VisualScriptCustomNode::instantiate(VisualScriptInstan
instance->in_count = get_input_value_port_count();
instance->out_count = get_output_value_port_count();
- if (get_script_instance() && get_script_instance()->has_method("_get_working_memory_size")) {
- instance->work_mem_size = get_script_instance()->call("_get_working_memory_size");
- } else {
- instance->work_mem_size = 0;
- }
+ instance->work_mem_size = 0;
+ GDVIRTUAL_CALL(_get_working_memory_size, instance->work_mem_size);
return instance;
}
@@ -3022,32 +3051,29 @@ void VisualScriptCustomNode::_script_changed() {
}
void VisualScriptCustomNode::_bind_methods() {
- BIND_VMETHOD(MethodInfo(Variant::INT, "_get_output_sequence_port_count"));
- BIND_VMETHOD(MethodInfo(Variant::BOOL, "_has_input_sequence_port"));
-
- BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_output_sequence_port_text", PropertyInfo(Variant::INT, "idx")));
- BIND_VMETHOD(MethodInfo(Variant::INT, "_get_input_value_port_count"));
- BIND_VMETHOD(MethodInfo(Variant::INT, "_get_output_value_port_count"));
+ GDVIRTUAL_BIND(_get_output_sequence_port_count);
+ GDVIRTUAL_BIND(_has_input_sequence_port);
+ GDVIRTUAL_BIND(_get_output_sequence_port_text, "seq_idx");
- BIND_VMETHOD(MethodInfo(Variant::INT, "_get_input_value_port_type", PropertyInfo(Variant::INT, "idx")));
- BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_input_value_port_name", PropertyInfo(Variant::INT, "idx")));
- BIND_VMETHOD(MethodInfo(Variant::INT, "_get_input_value_port_hint", PropertyInfo(Variant::INT, "idx")));
- BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_input_value_port_hint_string", PropertyInfo(Variant::INT, "idx")));
+ GDVIRTUAL_BIND(_get_input_value_port_count);
+ GDVIRTUAL_BIND(_get_input_value_port_type, "input_idx");
+ GDVIRTUAL_BIND(_get_input_value_port_name, "input_idx");
+ GDVIRTUAL_BIND(_get_input_value_port_hint, "input_idx");
+ GDVIRTUAL_BIND(_get_input_value_port_hint_string, "input_idx");
- BIND_VMETHOD(MethodInfo(Variant::INT, "_get_output_value_port_type", PropertyInfo(Variant::INT, "idx")));
- BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_output_value_port_name", PropertyInfo(Variant::INT, "idx")));
- BIND_VMETHOD(MethodInfo(Variant::INT, "_get_output_value_port_hint", PropertyInfo(Variant::INT, "idx")));
- BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_output_value_port_hint_string", PropertyInfo(Variant::INT, "idx")));
+ GDVIRTUAL_BIND(_get_output_value_port_count);
+ GDVIRTUAL_BIND(_get_output_value_port_type, "output_idx");
+ GDVIRTUAL_BIND(_get_output_value_port_name, "output_idx");
+ GDVIRTUAL_BIND(_get_output_value_port_hint, "output_idx");
+ GDVIRTUAL_BIND(_get_output_value_port_hint_string, "output_idx");
- BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_caption"));
- BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_text"));
- BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_category"));
+ GDVIRTUAL_BIND(_get_caption);
+ GDVIRTUAL_BIND(_get_text);
+ GDVIRTUAL_BIND(_get_category);
- BIND_VMETHOD(MethodInfo(Variant::INT, "_get_working_memory_size"));
+ GDVIRTUAL_BIND(_get_working_memory_size);
- MethodInfo stepmi(Variant::NIL, "_step", PropertyInfo(Variant::ARRAY, "inputs"), PropertyInfo(Variant::ARRAY, "outputs"), PropertyInfo(Variant::INT, "start_mode"), PropertyInfo(Variant::ARRAY, "working_mem"));
- stepmi.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
- BIND_VMETHOD(stepmi);
+ GDVIRTUAL_BIND(_step, "inputs", "outputs", "start_mode", "working_mem");
BIND_ENUM_CONSTANT(START_MODE_BEGIN_SEQUENCE);
BIND_ENUM_CONSTANT(START_MODE_CONTINUE_SEQUENCE);
@@ -3170,9 +3196,7 @@ VisualScriptNodeInstance *VisualScriptSubCall::instantiate(VisualScriptInstance
}
void VisualScriptSubCall::_bind_methods() {
- MethodInfo scmi(Variant::NIL, "_subcall", PropertyInfo(Variant::NIL, "arguments"));
- scmi.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
- BIND_VMETHOD(scmi);
+ // Since this is script only, registering virtual function is no longer valid. Will have to go in docs.
}
VisualScriptSubCall::VisualScriptSubCall() {
diff --git a/modules/visual_script/visual_script_nodes.h b/modules/visual_script/visual_script_nodes.h
index 2390e5c7bc..35d9b0b4fe 100644
--- a/modules/visual_script/visual_script_nodes.h
+++ b/modules/visual_script/visual_script_nodes.h
@@ -31,6 +31,8 @@
#ifndef VISUAL_SCRIPT_NODES_H
#define VISUAL_SCRIPT_NODES_H
+#include "core/object/gdvirtual.gen.inc"
+#include "core/object/script_language.h"
#include "visual_script.h"
class VisualScriptFunction : public VisualScriptNode {
@@ -757,6 +759,30 @@ class VisualScriptCustomNode : public VisualScriptNode {
protected:
static void _bind_methods();
+ friend class VisualScriptNodeInstanceCustomNode;
+ GDVIRTUAL0RC(int, _get_output_sequence_port_count)
+ GDVIRTUAL0RC(bool, _has_input_sequence_port)
+ GDVIRTUAL1RC(String, _get_output_sequence_port_text, int)
+
+ GDVIRTUAL0RC(int, _get_input_value_port_count)
+ GDVIRTUAL1RC(int, _get_input_value_port_type, int)
+ GDVIRTUAL1RC(String, _get_input_value_port_name, int)
+ GDVIRTUAL1RC(int, _get_input_value_port_hint, int)
+ GDVIRTUAL1RC(String, _get_input_value_port_hint_string, int)
+
+ GDVIRTUAL0RC(int, _get_output_value_port_count)
+ GDVIRTUAL1RC(int, _get_output_value_port_type, int)
+ GDVIRTUAL1RC(String, _get_output_value_port_name, int)
+ GDVIRTUAL1RC(int, _get_output_value_port_hint, int)
+ GDVIRTUAL1RC(String, _get_output_value_port_hint_string, int)
+
+ GDVIRTUAL0RC(String, _get_caption)
+ GDVIRTUAL0RC(String, _get_text)
+ GDVIRTUAL0RC(String, _get_category)
+
+ GDVIRTUAL0RC(int, _get_working_memory_size)
+
+ GDVIRTUAL4RC(Variant, _step, Array, Array, int, Array)
public:
enum StartMode { //replicated for step