mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
Merge pull request #43890 from vnen/gdscript-builtin-functions-refactor
GDScript: Refactor builtin functions
This commit is contained in:
commit
abfc528439
17 changed files with 1085 additions and 2116 deletions
|
@ -283,6 +283,30 @@ GDScriptFunction *GDScriptByteCodeGenerator::write_end() {
|
|||
function->_constructors_count = 0;
|
||||
}
|
||||
|
||||
if (utilities_map.size()) {
|
||||
function->utilities.resize(utilities_map.size());
|
||||
function->_utilities_ptr = function->utilities.ptr();
|
||||
function->_utilities_count = utilities_map.size();
|
||||
for (const Map<Variant::ValidatedUtilityFunction, int>::Element *E = utilities_map.front(); E; E = E->next()) {
|
||||
function->utilities.write[E->get()] = E->key();
|
||||
}
|
||||
} else {
|
||||
function->_utilities_ptr = nullptr;
|
||||
function->_utilities_count = 0;
|
||||
}
|
||||
|
||||
if (gds_utilities_map.size()) {
|
||||
function->gds_utilities.resize(gds_utilities_map.size());
|
||||
function->_gds_utilities_ptr = function->gds_utilities.ptr();
|
||||
function->_gds_utilities_count = gds_utilities_map.size();
|
||||
for (const Map<GDScriptUtilityFunctions::FunctionPtr, int>::Element *E = gds_utilities_map.front(); E; E = E->next()) {
|
||||
function->gds_utilities.write[E->get()] = E->key();
|
||||
}
|
||||
} else {
|
||||
function->_gds_utilities_ptr = nullptr;
|
||||
function->_gds_utilities_count = 0;
|
||||
}
|
||||
|
||||
if (method_bind_map.size()) {
|
||||
function->methods.resize(method_bind_map.size());
|
||||
function->_methods_ptr = function->methods.ptrw();
|
||||
|
@ -704,8 +728,8 @@ void GDScriptByteCodeGenerator::write_call_async(const Address &p_target, const
|
|||
append(p_function_name);
|
||||
}
|
||||
|
||||
void GDScriptByteCodeGenerator::write_call_builtin(const Address &p_target, GDScriptFunctions::Function p_function, const Vector<Address> &p_arguments) {
|
||||
append(GDScriptFunction::OPCODE_CALL_BUILT_IN, 1 + p_arguments.size());
|
||||
void GDScriptByteCodeGenerator::write_call_gdscript_utility(const Address &p_target, GDScriptUtilityFunctions::FunctionPtr p_function, const Vector<Address> &p_arguments) {
|
||||
append(GDScriptFunction::OPCODE_CALL_GDSCRIPT_UTILITY, 1 + p_arguments.size());
|
||||
for (int i = 0; i < p_arguments.size(); i++) {
|
||||
append(p_arguments[i]);
|
||||
}
|
||||
|
@ -714,6 +738,41 @@ void GDScriptByteCodeGenerator::write_call_builtin(const Address &p_target, GDSc
|
|||
append(p_function);
|
||||
}
|
||||
|
||||
void GDScriptByteCodeGenerator::write_call_utility(const Address &p_target, const StringName &p_function, const Vector<Address> &p_arguments) {
|
||||
bool is_validated = true;
|
||||
if (Variant::is_utility_function_vararg(p_function)) {
|
||||
is_validated = true; // Vararg works fine with any argument, since they can be any type.
|
||||
} else if (p_arguments.size() == Variant::get_utility_function_argument_count(p_function)) {
|
||||
bool all_types_exact = true;
|
||||
for (int i = 0; i < p_arguments.size(); i++) {
|
||||
if (!IS_BUILTIN_TYPE(p_arguments[i], Variant::get_utility_function_argument_type(p_function, i))) {
|
||||
all_types_exact = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
is_validated = all_types_exact;
|
||||
}
|
||||
|
||||
if (is_validated) {
|
||||
append(GDScriptFunction::OPCODE_CALL_UTILITY_VALIDATED, 1 + p_arguments.size());
|
||||
for (int i = 0; i < p_arguments.size(); i++) {
|
||||
append(p_arguments[i]);
|
||||
}
|
||||
append(p_target);
|
||||
append(p_arguments.size());
|
||||
append(Variant::get_validated_utility_function(p_function));
|
||||
} else {
|
||||
append(GDScriptFunction::OPCODE_CALL_UTILITY, 1 + p_arguments.size());
|
||||
for (int i = 0; i < p_arguments.size(); i++) {
|
||||
append(p_arguments[i]);
|
||||
}
|
||||
append(p_target);
|
||||
append(p_arguments.size());
|
||||
append(p_function);
|
||||
}
|
||||
}
|
||||
|
||||
void GDScriptByteCodeGenerator::write_call_builtin_type(const Address &p_target, const Address &p_base, Variant::Type p_type, const StringName &p_method, const Vector<Address> &p_arguments) {
|
||||
bool is_validated = false;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue