summaryrefslogtreecommitdiffstats
path: root/modules/gdscript/gdscript_function.h
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gdscript/gdscript_function.h')
-rw-r--r--modules/gdscript/gdscript_function.h105
1 files changed, 39 insertions, 66 deletions
diff --git a/modules/gdscript/gdscript_function.h b/modules/gdscript/gdscript_function.h
index e984d97149..177c68533e 100644
--- a/modules/gdscript/gdscript_function.h
+++ b/modules/gdscript/gdscript_function.h
@@ -45,10 +45,9 @@ class GDScriptInstance;
class GDScript;
class GDScriptDataType {
-private:
- GDScriptDataType *container_element_type = nullptr;
-
public:
+ Vector<GDScriptDataType> container_element_types;
+
enum Kind {
UNINITIALIZED,
BUILTIN,
@@ -76,19 +75,20 @@ public:
case BUILTIN: {
Variant::Type var_type = p_variant.get_type();
bool valid = builtin_type == var_type;
- if (valid && builtin_type == Variant::ARRAY && has_container_element_type()) {
+ if (valid && builtin_type == Variant::ARRAY && has_container_element_type(0)) {
Array array = p_variant;
if (array.is_typed()) {
+ GDScriptDataType array_container_type = get_container_element_type(0);
Variant::Type array_builtin_type = (Variant::Type)array.get_typed_builtin();
StringName array_native_type = array.get_typed_class_name();
Ref<Script> array_script_type_ref = array.get_typed_script();
if (array_script_type_ref.is_valid()) {
- valid = (container_element_type->kind == SCRIPT || container_element_type->kind == GDSCRIPT) && container_element_type->script_type == array_script_type_ref.ptr();
+ valid = (array_container_type.kind == SCRIPT || array_container_type.kind == GDSCRIPT) && array_container_type.script_type == array_script_type_ref.ptr();
} else if (array_native_type != StringName()) {
- valid = container_element_type->kind == NATIVE && container_element_type->native_type == array_native_type;
+ valid = array_container_type.kind == NATIVE && array_container_type.native_type == array_native_type;
} else {
- valid = container_element_type->kind == BUILTIN && container_element_type->builtin_type == array_builtin_type;
+ valid = array_container_type.kind == BUILTIN && array_container_type.builtin_type == array_builtin_type;
}
} else {
valid = false;
@@ -147,24 +147,32 @@ public:
return false;
}
- void set_container_element_type(const GDScriptDataType &p_element_type) {
- container_element_type = memnew(GDScriptDataType(p_element_type));
+ void set_container_element_type(int p_index, const GDScriptDataType &p_element_type) {
+ ERR_FAIL_COND(p_index < 0);
+ while (p_index >= container_element_types.size()) {
+ container_element_types.push_back(GDScriptDataType());
+ }
+ container_element_types.write[p_index] = GDScriptDataType(p_element_type);
+ }
+
+ GDScriptDataType get_container_element_type(int p_index) const {
+ ERR_FAIL_INDEX_V(p_index, container_element_types.size(), GDScriptDataType());
+ return container_element_types[p_index];
}
- GDScriptDataType get_container_element_type() const {
- ERR_FAIL_NULL_V(container_element_type, GDScriptDataType());
- return *container_element_type;
+ GDScriptDataType get_container_element_type_or_variant(int p_index) const {
+ if (p_index < 0 || p_index >= container_element_types.size()) {
+ return GDScriptDataType();
+ }
+ return container_element_types[p_index];
}
- bool has_container_element_type() const {
- return container_element_type != nullptr;
+ bool has_container_element_type(int p_index) const {
+ return p_index >= 0 && p_index < container_element_types.size();
}
- void unset_container_element_type() {
- if (container_element_type) {
- memdelete(container_element_type);
- }
- container_element_type = nullptr;
+ bool has_container_element_types() const {
+ return !container_element_types.is_empty();
}
GDScriptDataType() = default;
@@ -176,19 +184,14 @@ public:
native_type = p_other.native_type;
script_type = p_other.script_type;
script_type_ref = p_other.script_type_ref;
- unset_container_element_type();
- if (p_other.has_container_element_type()) {
- set_container_element_type(p_other.get_container_element_type());
- }
+ container_element_types = p_other.container_element_types;
}
GDScriptDataType(const GDScriptDataType &p_other) {
*this = p_other;
}
- ~GDScriptDataType() {
- unset_container_element_type();
- }
+ ~GDScriptDataType() {}
};
class GDScriptFunction {
@@ -241,45 +244,8 @@ public:
OPCODE_CALL_METHOD_BIND_RET,
OPCODE_CALL_BUILTIN_STATIC,
OPCODE_CALL_NATIVE_STATIC,
- // ptrcall have one instruction per return type.
- OPCODE_CALL_PTRCALL_NO_RETURN,
- OPCODE_CALL_PTRCALL_BOOL,
- OPCODE_CALL_PTRCALL_INT,
- OPCODE_CALL_PTRCALL_FLOAT,
- OPCODE_CALL_PTRCALL_STRING,
- OPCODE_CALL_PTRCALL_VECTOR2,
- OPCODE_CALL_PTRCALL_VECTOR2I,
- OPCODE_CALL_PTRCALL_RECT2,
- OPCODE_CALL_PTRCALL_RECT2I,
- OPCODE_CALL_PTRCALL_VECTOR3,
- OPCODE_CALL_PTRCALL_VECTOR3I,
- OPCODE_CALL_PTRCALL_TRANSFORM2D,
- OPCODE_CALL_PTRCALL_VECTOR4,
- OPCODE_CALL_PTRCALL_VECTOR4I,
- OPCODE_CALL_PTRCALL_PLANE,
- OPCODE_CALL_PTRCALL_QUATERNION,
- OPCODE_CALL_PTRCALL_AABB,
- OPCODE_CALL_PTRCALL_BASIS,
- OPCODE_CALL_PTRCALL_TRANSFORM3D,
- OPCODE_CALL_PTRCALL_PROJECTION,
- OPCODE_CALL_PTRCALL_COLOR,
- OPCODE_CALL_PTRCALL_STRING_NAME,
- OPCODE_CALL_PTRCALL_NODE_PATH,
- OPCODE_CALL_PTRCALL_RID,
- OPCODE_CALL_PTRCALL_OBJECT,
- OPCODE_CALL_PTRCALL_CALLABLE,
- OPCODE_CALL_PTRCALL_SIGNAL,
- OPCODE_CALL_PTRCALL_DICTIONARY,
- OPCODE_CALL_PTRCALL_ARRAY,
- OPCODE_CALL_PTRCALL_PACKED_BYTE_ARRAY,
- OPCODE_CALL_PTRCALL_PACKED_INT32_ARRAY,
- OPCODE_CALL_PTRCALL_PACKED_INT64_ARRAY,
- OPCODE_CALL_PTRCALL_PACKED_FLOAT32_ARRAY,
- OPCODE_CALL_PTRCALL_PACKED_FLOAT64_ARRAY,
- OPCODE_CALL_PTRCALL_PACKED_STRING_ARRAY,
- OPCODE_CALL_PTRCALL_PACKED_VECTOR2_ARRAY,
- OPCODE_CALL_PTRCALL_PACKED_VECTOR3_ARRAY,
- OPCODE_CALL_PTRCALL_PACKED_COLOR_ARRAY,
+ OPCODE_CALL_METHOD_BIND_VALIDATED_RETURN,
+ OPCODE_CALL_METHOD_BIND_VALIDATED_NO_RETURN,
OPCODE_AWAIT,
OPCODE_AWAIT_RESUME,
OPCODE_CREATE_LAMBDA,
@@ -425,7 +391,6 @@ private:
int _argument_count = 0;
int _stack_size = 0;
int _instruction_args_size = 0;
- int _ptrcall_args_size = 0;
SelfList<GDScriptFunction> function_list{ this };
mutable Variant nil;
@@ -509,6 +474,13 @@ private:
uint64_t last_frame_call_count = 0;
uint64_t last_frame_self_time = 0;
uint64_t last_frame_total_time = 0;
+ typedef struct NativeProfile {
+ uint64_t call_count;
+ uint64_t total_time;
+ String signature;
+ } NativeProfile;
+ HashMap<String, NativeProfile> native_calls;
+ HashMap<String, NativeProfile> last_native_calls;
} profile;
#endif
@@ -549,6 +521,7 @@ public:
void debug_get_stack_member_state(int p_line, List<Pair<StringName, int>> *r_stackvars) const;
#ifdef DEBUG_ENABLED
+ void _profile_native_call(uint64_t p_t_taken, const String &p_function_name, const String &p_instance_class_name = String());
void disassemble(const Vector<String> &p_code_lines) const;
#endif