Allow for getting/setting indexed properties of objects using get/set_indexed

Performance is around the same as using pure set() through GDScript.
This commit is contained in:
Bojidar Marinov 2017-05-30 23:20:15 +03:00
parent 7bbde636e8
commit 0cf9597758
No known key found for this signature in database
GPG key ID: 4D546A8F1E091856
23 changed files with 416 additions and 246 deletions

View file

@ -2466,24 +2466,19 @@ bool Node::has_node_and_resource(const NodePath &p_path) const {
return false;
Node *node = get_node(p_path);
if (p_path.get_subname_count()) {
bool result = false;
RES r;
for (int j = 0; j < p_path.get_subname_count(); j++) {
r = j == 0 ? node->get(p_path.get_subname(j)) : r->get(p_path.get_subname(j));
if (r.is_null())
return false;
}
}
node->get_indexed(p_path.get_subnames(), &result);
return true;
return result;
}
Array Node::_get_node_and_resource(const NodePath &p_path) {
Node *node;
RES res;
node = get_node_and_resource(p_path, res);
Vector<StringName> leftover_path;
node = get_node_and_resource(p_path, res, leftover_path);
Array result;
if (node)
@ -2496,21 +2491,35 @@ Array Node::_get_node_and_resource(const NodePath &p_path) {
else
result.push_back(Variant());
result.push_back(NodePath(Vector<StringName>(), leftover_path, false));
return result;
}
Node *Node::get_node_and_resource(const NodePath &p_path, RES &r_res) const {
Node *Node::get_node_and_resource(const NodePath &p_path, RES &r_res, Vector<StringName> &r_leftover_subpath, bool p_last_is_property) const {
Node *node = get_node(p_path);
r_res = RES();
r_leftover_subpath = Vector<StringName>();
if (!node)
return NULL;
if (p_path.get_subname_count()) {
for (int j = 0; j < p_path.get_subname_count(); j++) {
r_res = j == 0 ? node->get(p_path.get_subname(j)) : r_res->get(p_path.get_subname(j));
ERR_FAIL_COND_V(r_res.is_null(), node);
int j = 0;
// If not p_last_is_property, we shouldn't consider the last one as part of the resource
for (; j < p_path.get_subname_count() - p_last_is_property; j++) {
RES new_res = j == 0 ? node->get(p_path.get_subname(j)) : r_res->get(p_path.get_subname(j));
if (new_res.is_null()) {
break;
}
r_res = new_res;
}
for (; j < p_path.get_subname_count(); j++) {
// Put the rest of the subpath in the leftover path
r_leftover_subpath.push_back(p_path.get_subname(j));
}
}