summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2015-04-18 14:00:15 -0300
committerJuan Linietsky <reduzio@gmail.com>2015-04-18 14:00:15 -0300
commitbe46be78012e98d68b960437bf3d33e577948548 (patch)
treea90870e00664ad963b2c66a704da6bcc3a2bb3d2
parent3b434eacde58450965708c3eafb6b22eb2a99361 (diff)
-renamed function to get object from instance id
-added function to get list of tiles used
-rw-r--r--demos/misc/autoload/global.gd30
-rw-r--r--modules/gdscript/gd_functions.cpp8
-rw-r--r--modules/gdscript/gd_functions.h2
-rw-r--r--scene/2d/tile_map.cpp15
-rw-r--r--scene/2d/tile_map.h2
5 files changed, 38 insertions, 19 deletions
diff --git a/demos/misc/autoload/global.gd b/demos/misc/autoload/global.gd
index 5d81f9e649..d1bd45461f 100644
--- a/demos/misc/autoload/global.gd
+++ b/demos/misc/autoload/global.gd
@@ -3,10 +3,25 @@ extends Node
var current_scene = null
+
+func goto_scene(path):
+
+ # This function will usually be called from a signal callback,
+ # or some other function from the running scene.
+ # Deleting the current scene at this point might be
+ # a bad idea, because it may be inside of a callback or function of it.
+ # The worst case will be a crash or unexpected behavior.
+
+ # The way around this is deferring the load to a later time, when
+ # it is ensured that no code from the current scene is running:
+
+ call_deferred("_deferred_goto_scene",path)
+
+
func _deferred_goto_scene(path):
# Immediately free the current scene,
- # there is no risk here.
+ # there is no risk here.
current_scene.free()
# Load new scene
@@ -18,19 +33,6 @@ func _deferred_goto_scene(path):
# Add it to the active scene, as child of root
get_tree().get_root().add_child(current_scene)
-func goto_scene(path):
-
- # This function will usually be called from a signal callback,
- # or some other function from the running scene.
- # Deleting the current scene at this point might be
- # a bad idea, because it may be inside of a callback or function of it.
- # The worst case will be a crash or unexpected behavior.
-
- # The way around this is deferring the load to a later time, when
- # it is ensured that no code from the current scene is running:
-
- call_deferred("_deferred_goto_scene",path)
-
func _ready():
# Get the current scene, the first time.
diff --git a/modules/gdscript/gd_functions.cpp b/modules/gdscript/gd_functions.cpp
index d4b8639c9b..d10570f9f4 100644
--- a/modules/gdscript/gd_functions.cpp
+++ b/modules/gdscript/gd_functions.cpp
@@ -98,7 +98,7 @@ const char *GDFunctions::get_func_name(Function p_func) {
"dict2inst",
"hash",
"print_stack",
- "get_inst",
+ "instance_from_id",
};
return _names[p_func];
@@ -904,7 +904,7 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
};
} break;
- case GET_INST: {
+ case INSTANCE_FROM_ID: {
VALIDATE_ARG_COUNT(1);
if (p_args[0]->get_type()!=Variant::INT && p_args[0]->get_type()!=Variant::REAL) {
@@ -1316,8 +1316,8 @@ MethodInfo GDFunctions::get_info(Function p_func) {
return mi;
} break;
- case GET_INST: {
- MethodInfo mi("get_info",PropertyInfo(Variant::INT,"instance_id"));
+ case INSTANCE_FROM_ID: {
+ MethodInfo mi("instance_from_id",PropertyInfo(Variant::INT,"instance_id"));
mi.return_val.type=Variant::OBJECT;
return mi;
} break;
diff --git a/modules/gdscript/gd_functions.h b/modules/gdscript/gd_functions.h
index 4fbfe99228..321b11104a 100644
--- a/modules/gdscript/gd_functions.h
+++ b/modules/gdscript/gd_functions.h
@@ -94,7 +94,7 @@ public:
DICT2INST,
HASH,
PRINT_STACK,
- GET_INST,
+ INSTANCE_FROM_ID,
FUNC_MAX
};
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp
index 18f8b5bbbb..bc2dfe1013 100644
--- a/scene/2d/tile_map.cpp
+++ b/scene/2d/tile_map.cpp
@@ -1024,6 +1024,19 @@ bool TileMap::is_y_sort_mode_enabled() const {
return y_sort_mode;
}
+Array TileMap::get_used_cells() const {
+
+ Array a;
+ a.resize(tile_map.size());
+ int i=0;
+ for (Map<PosKey,Cell>::Element *E=tile_map.front();E;E=E->next()) {
+
+ Vector2 p (E->key().x,E->key().y);
+ a[i++]=p;
+ }
+
+ return a;
+}
void TileMap::_bind_methods() {
@@ -1080,6 +1093,8 @@ void TileMap::_bind_methods() {
ObjectTypeDB::bind_method(_MD("clear"),&TileMap::clear);
+ ObjectTypeDB::bind_method(_MD("get_used_cells"),&TileMap::get_used_cells);
+
ObjectTypeDB::bind_method(_MD("map_to_world","mappos","ignore_half_ofs"),&TileMap::map_to_world,DEFVAL(false));
ObjectTypeDB::bind_method(_MD("world_to_map","worldpos"),&TileMap::world_to_map);
diff --git a/scene/2d/tile_map.h b/scene/2d/tile_map.h
index e02c4ee5bb..976ddfc5cf 100644
--- a/scene/2d/tile_map.h
+++ b/scene/2d/tile_map.h
@@ -171,6 +171,8 @@ private:
_FORCE_INLINE_ Vector2 _map_to_world(int p_x,int p_y,bool p_ignore_ofs=false) const;
+ Array get_used_cells() const;
+
protected: