From 5d4dc2d45caef77cdb52e365bc02f64d54046df5 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 20 Apr 2020 19:06:00 -0300 Subject: Add ability to bind typed arrays to script API Note: Only replaced 2 instances to test, Node.get_children and TileMap.get_used_cells Note: Will do a mass replace on later PRs of whathever I can find, but probably need a tool to grep through doc. Warning: Mono will break, needs to be fixed (and so do TypeScript and NativeScript, need to ask respective maintainers) --- scene/2d/tile_map.cpp | 6 +++--- scene/2d/tile_map.h | 2 +- scene/main/node.cpp | 4 ++-- scene/main/node.h | 3 ++- 4 files changed, 8 insertions(+), 7 deletions(-) (limited to 'scene') diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index 1cf12e4421..14a4d24b44 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -1691,14 +1691,14 @@ bool TileMap::is_centered_textures_enabled() const { return centered_textures; } -Array TileMap::get_used_cells() const { +TypedArray TileMap::get_used_cells() const { - Array a; + TypedArray a; a.resize(tile_map.size()); int i = 0; for (Map::Element *E = tile_map.front(); E; E = E->next()) { - Vector2 p(E->key().x, E->key().y); + Vector2i p(E->key().x, E->key().y); a[i++] = p; } diff --git a/scene/2d/tile_map.h b/scene/2d/tile_map.h index d9490aae13..cc44bc147b 100644 --- a/scene/2d/tile_map.h +++ b/scene/2d/tile_map.h @@ -328,7 +328,7 @@ public: void set_centered_textures(bool p_enable); bool is_centered_textures_enabled() const; - Array get_used_cells() const; + TypedArray get_used_cells() const; Array get_used_cells_by_id(int p_id) const; Rect2 get_used_rect(); // Not const because of cache diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 50f3bf834f..4c02a15531 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -2693,9 +2693,9 @@ void Node::queue_delete() { } } -Array Node::_get_children() const { +TypedArray Node::_get_children() const { - Array arr; + TypedArray arr; int cc = get_child_count(); arr.resize(cc); for (int i = 0; i < cc; i++) diff --git a/scene/main/node.h b/scene/main/node.h index 5de07d506e..1c1b7bbd7a 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -37,6 +37,7 @@ #include "core/object.h" #include "core/project_settings.h" #include "core/script_language.h" +#include "core/typed_array.h" #include "scene/main/scene_tree.h" class Viewport; @@ -182,7 +183,7 @@ private: void _duplicate_and_reown(Node *p_new_parent, const Map &p_reown_map) const; Node *_duplicate(int p_flags, Map *r_duplimap = nullptr) const; - Array _get_children() const; + TypedArray _get_children() const; Array _get_groups() const; Variant _rpc_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error); -- cgit v1.2.3