summaryrefslogtreecommitdiff
path: root/scene/main
diff options
context:
space:
mode:
Diffstat (limited to 'scene/main')
-rw-r--r--scene/main/canvas_layer.cpp2
-rw-r--r--scene/main/canvas_layer.h2
-rw-r--r--scene/main/misc.cpp2
-rw-r--r--scene/main/misc.h2
-rw-r--r--scene/main/node.cpp80
-rw-r--r--scene/main/node.h10
-rw-r--r--scene/main/resource_preloader.cpp2
-rw-r--r--scene/main/resource_preloader.h2
-rw-r--r--scene/main/scene_main_loop.cpp85
-rw-r--r--scene/main/scene_main_loop.h17
-rw-r--r--scene/main/scene_singleton.cpp2
-rw-r--r--scene/main/scene_singleton.h2
-rw-r--r--scene/main/timer.cpp71
-rw-r--r--scene/main/timer.h16
-rw-r--r--scene/main/viewport.cpp11
-rw-r--r--scene/main/viewport.h3
16 files changed, 274 insertions, 35 deletions
diff --git a/scene/main/canvas_layer.cpp b/scene/main/canvas_layer.cpp
index ae842577a9..ee3d7f5afd 100644
--- a/scene/main/canvas_layer.cpp
+++ b/scene/main/canvas_layer.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/scene/main/canvas_layer.h b/scene/main/canvas_layer.h
index 638f3ec579..edd00c1a7a 100644
--- a/scene/main/canvas_layer.h
+++ b/scene/main/canvas_layer.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/scene/main/misc.cpp b/scene/main/misc.cpp
index 761f470c11..108621baa5 100644
--- a/scene/main/misc.cpp
+++ b/scene/main/misc.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/scene/main/misc.h b/scene/main/misc.h
index 34b80a08b4..e7894aa68d 100644
--- a/scene/main/misc.h
+++ b/scene/main/misc.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index fbdc87a7cc..7e31bf8dd0 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -295,7 +295,7 @@ void Node::add_child_notify(Node *p_child) {
// to be used when not wanted
}
-
+/*
void Node::remove_and_delete_child(Node *p_child) {
ERR_FAIL_NULL( p_child );
@@ -305,6 +305,7 @@ void Node::remove_and_delete_child(Node *p_child) {
memdelete(p_child);
}
+*/
void Node::remove_child_notify(Node *p_child) {
@@ -640,6 +641,7 @@ void Node::_add_child_nocheck(Node* p_child,const StringName& p_name) {
p_child->data.pos=data.children.size();
data.children.push_back( p_child );
p_child->data.parent=this;
+ p_child->notification(NOTIFICATION_PARENTED);
if (data.tree) {
p_child->_set_tree(data.tree);
@@ -648,7 +650,6 @@ void Node::_add_child_nocheck(Node* p_child,const StringName& p_name) {
/* Notify */
//recognize childs created in this node constructor
p_child->data.parent_owned=data.in_constructor;
- p_child->notification(NOTIFICATION_PARENTED);
add_child_notify(p_child);
@@ -839,6 +840,28 @@ bool Node::has_node(const NodePath& p_path) const {
return _get_node(p_path)!=NULL;
}
+
+Node* Node::find_node(const String& p_mask,bool p_recursive,bool p_owned) const {
+
+ Node * const*cptr = data.children.ptr();
+ int ccount = data.children.size();
+ for(int i=0;i<ccount;i++) {
+ if (p_owned && !cptr[i]->data.owner)
+ continue;
+ if (cptr[i]->data.name.operator String().match(p_mask))
+ return cptr[i];
+
+ if (!p_recursive)
+ continue;
+
+ Node* ret = cptr[i]->find_node(p_mask,true,p_owned);
+ if (ret)
+ return ret;
+ }
+ return NULL;
+
+}
+
Node *Node::get_parent() const {
return data.parent;
@@ -1416,6 +1439,41 @@ void Node::_duplicate_and_reown(Node* p_new_parent, const Map<Node*,Node*>& p_re
}
+
+void Node::_duplicate_signals(const Node* p_original,Node* p_copy) const {
+
+ if (this!=p_original && get_owner()!=p_original)
+ return;
+
+ List<Connection> conns;
+ get_all_signal_connections(&conns);
+
+ for (List<Connection>::Element *E=conns.front();E;E=E->next()) {
+
+ if (E->get().flags&CONNECT_PERSIST) {
+ //user connected
+ NodePath p = p_original->get_path_to(this);
+ Node *copy = p_copy->get_node(p);
+
+ Node *target = E->get().target->cast_to<Node>();
+ if (!target)
+ continue;
+ NodePath ptarget = p_original->get_path_to(target);
+ Node *copytarget = p_copy->get_node(ptarget);
+
+ if (copy && copytarget) {
+ copy->connect(E->get().signal,copytarget,E->get().method,E->get().binds,CONNECT_PERSIST);
+ }
+ }
+ }
+
+ for(int i=0;i<get_child_count();i++) {
+ get_child(i)->_duplicate_signals(p_original,p_copy);
+ }
+
+}
+
+
Node *Node::duplicate_and_reown(const Map<Node*,Node*>& p_reown_map) const {
@@ -1454,6 +1512,7 @@ Node *Node::duplicate_and_reown(const Map<Node*,Node*>& p_reown_map) const {
get_child(i)->_duplicate_and_reown(node,p_reown_map);
}
+ _duplicate_signals(this,node);
return node;
}
@@ -1757,19 +1816,30 @@ void Node::get_argument_options(const StringName& p_function,int p_idx,List<Stri
Object::get_argument_options(p_function,p_idx,r_options);
}
+
+void Node::clear_internal_tree_resource_paths() {
+
+ clear_internal_resource_paths();
+ for(int i=0;i<data.children.size();i++) {
+ data.children[i]->clear_internal_tree_resource_paths();
+ }
+
+}
+
void Node::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_name","name"),&Node::set_name);
ObjectTypeDB::bind_method(_MD("get_name"),&Node::get_name);
ObjectTypeDB::bind_method(_MD("add_child","node:Node"),&Node::add_child);
ObjectTypeDB::bind_method(_MD("remove_child","node:Node"),&Node::remove_child);
- ObjectTypeDB::bind_method(_MD("remove_and_delete_child","node:Node"),&Node::remove_and_delete_child);
+ //ObjectTypeDB::bind_method(_MD("remove_and_delete_child","node:Node"),&Node::remove_and_delete_child);
ObjectTypeDB::bind_method(_MD("get_child_count"),&Node::get_child_count);
ObjectTypeDB::bind_method(_MD("get_children"),&Node::_get_children);
ObjectTypeDB::bind_method(_MD("get_child:Node","idx"),&Node::get_child);
ObjectTypeDB::bind_method(_MD("has_node","path"),&Node::has_node);
ObjectTypeDB::bind_method(_MD("get_node:Node","path"),&Node::get_node);
ObjectTypeDB::bind_method(_MD("get_parent:Parent"),&Node::get_parent);
+ ObjectTypeDB::bind_method(_MD("find_node:Node","mask","recursive","owned"),&Node::get_node,DEFVAL(true),DEFVAL(true));
ObjectTypeDB::bind_method(_MD("has_node_and_resource","path"),&Node::has_node_and_resource);
ObjectTypeDB::bind_method(_MD("get_node_and_resource","path"),&Node::_get_node_and_resource);
@@ -1821,7 +1891,7 @@ void Node::_bind_methods() {
#ifdef TOOLS_ENABLED
ObjectTypeDB::bind_method(_MD("_set_import_path","import_path"),&Node::set_import_path);
ObjectTypeDB::bind_method(_MD("_get_import_path"),&Node::get_import_path);
- ADD_PROPERTY( PropertyInfo(Variant::NODE_PATH,"_import_path",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("_set_import_path"),_SCS("_get_import_path"));
+ ADD_PROPERTYNZ( PropertyInfo(Variant::NODE_PATH,"_import_path",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("_set_import_path"),_SCS("_get_import_path"));
#endif
diff --git a/scene/main/node.h b/scene/main/node.h
index 47f49eb625..be91c6e1bb 100644
--- a/scene/main/node.h
+++ b/scene/main/node.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -114,6 +114,7 @@ private:
Node *_get_node(const NodePath& p_path) const;
+
void _validate_child_name(Node *p_name);
void _propagate_reverse_notification(int p_notification);
@@ -126,6 +127,7 @@ private:
void _propagate_pause_owner(Node*p_owner);
Array _get_node_and_resource(const NodePath& p_path);
+ void _duplicate_signals(const Node* p_original,Node* p_copy) const;
void _duplicate_and_reown(Node* p_new_parent, const Map<Node*,Node*>& p_reown_map) const;
Array _get_children() const;
Array _get_groups() const;
@@ -143,7 +145,7 @@ protected:
virtual void add_child_notify(Node *p_child);
virtual void remove_child_notify(Node *p_child);
virtual void move_child_notify(Node *p_child);
- void remove_and_delete_child(Node *p_child);
+ //void remove_and_delete_child(Node *p_child);
void _propagate_replace_owner(Node *p_owner,Node* p_by_owner);
@@ -170,6 +172,7 @@ public:
NOTIFICATION_PROCESS = 17,
NOTIFICATION_PARENTED=18,
NOTIFICATION_UNPARENTED=19,
+ NOTIFICATION_INSTANCED=20,
};
/* NODE/TREE */
@@ -184,6 +187,7 @@ public:
Node *get_child(int p_index) const;
bool has_node(const NodePath& p_path) const;
Node *get_node(const NodePath& p_path) const;
+ Node* find_node(const String& p_mask,bool p_recursive=true,bool p_owned=true) const;
bool has_node_and_resource(const NodePath& p_path) const;
Node *get_node_and_resource(const NodePath& p_path,RES& r_res) const;
@@ -286,6 +290,8 @@ public:
void get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const;
+ void clear_internal_tree_resource_paths();
+
_FORCE_INLINE_ Viewport *get_viewport() const { return data.viewport; }
/* CANVAS */
diff --git a/scene/main/resource_preloader.cpp b/scene/main/resource_preloader.cpp
index 8227046ecb..f49f626e78 100644
--- a/scene/main/resource_preloader.cpp
+++ b/scene/main/resource_preloader.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/scene/main/resource_preloader.h b/scene/main/resource_preloader.h
index e1e3beb0b3..b3e7496fb7 100644
--- a/scene/main/resource_preloader.h
+++ b/scene/main/resource_preloader.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/scene/main/scene_main_loop.cpp b/scene/main/scene_main_loop.cpp
index ed3e419359..1664a9bea1 100644
--- a/scene/main/scene_main_loop.cpp
+++ b/scene/main/scene_main_loop.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -41,7 +41,7 @@
#include "scene/scene_string_names.h"
#include "io/resource_loader.h"
#include "viewport.h"
-
+#include "scene/resources/packed_scene.h"
void SceneTree::tree_changed() {
@@ -51,6 +51,9 @@ void SceneTree::tree_changed() {
void SceneTree::node_removed(Node *p_node) {
+ if (current_scene==p_node) {
+ current_scene=NULL;
+ }
emit_signal(node_removed_name,p_node);
if (call_lock>0)
call_skip.insert(p_node);
@@ -850,6 +853,7 @@ void SceneTree::queue_delete(Object *p_object) {
_THREAD_SAFE_METHOD_
ERR_FAIL_NULL(p_object);
+ p_object->_is_queued_for_deletion = true;
delete_queue.push_back(p_object->get_instance_ID());
}
@@ -983,6 +987,63 @@ Node *SceneTree::get_edited_scene_root() const {
}
#endif
+void SceneTree::set_current_scene(Node* p_scene) {
+
+ ERR_FAIL_COND(p_scene && p_scene->get_parent()!=root);
+ current_scene=p_scene;
+}
+
+Node* SceneTree::get_current_scene() const{
+
+ return current_scene;
+}
+
+void SceneTree::_change_scene(Node* p_to) {
+
+ if (current_scene) {
+ memdelete( current_scene );
+ current_scene=NULL;
+ }
+
+ if (p_to) {
+ current_scene=p_to;
+ root->add_child(p_to);
+ }
+}
+
+Error SceneTree::change_scene(const String& p_path){
+
+ Ref<PackedScene> new_scene = ResourceLoader::load(p_path);
+ if (new_scene.is_null())
+ return ERR_CANT_OPEN;
+
+ return change_scene_to(new_scene);
+
+}
+Error SceneTree::change_scene_to(const Ref<PackedScene>& p_scene){
+
+ Node *new_scene=NULL;
+ if (p_scene.is_valid()) {
+ new_scene = p_scene->instance();
+ ERR_FAIL_COND_V(!new_scene,ERR_CANT_CREATE);
+ }
+
+ call_deferred("_change_scene",new_scene);
+ return OK;
+
+}
+Error SceneTree::reload_current_scene() {
+
+ ERR_FAIL_COND_V(!current_scene,ERR_UNCONFIGURED);
+ String fname = current_scene->get_filename();
+ return change_scene(fname);
+}
+
+void SceneTree::add_current_scene(Node * p_current) {
+
+ current_scene=p_current;
+ root->add_child(p_current);
+}
void SceneTree::_bind_methods() {
@@ -1015,10 +1076,11 @@ void SceneTree::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_screen_stretch","mode","aspect","minsize"),&SceneTree::set_screen_stretch);
-
ObjectTypeDB::bind_method(_MD("queue_delete","obj"),&SceneTree::queue_delete);
+
+
MethodInfo mi;
mi.name="call_group";
mi.arguments.push_back( PropertyInfo( Variant::INT, "flags"));
@@ -1032,10 +1094,23 @@ void SceneTree::_bind_methods() {
ObjectTypeDB::bind_native_method(METHOD_FLAGS_DEFAULT,"call_group",&SceneTree::_call_group,mi,defargs);
+ ObjectTypeDB::bind_method(_MD("set_current_scene","child_node:Node"),&SceneTree::set_current_scene);
+ ObjectTypeDB::bind_method(_MD("get_current_scene:Node"),&SceneTree::get_current_scene);
+
+ ObjectTypeDB::bind_method(_MD("change_scene","path"),&SceneTree::change_scene);
+ ObjectTypeDB::bind_method(_MD("change_scene_to","packed_scene:PackedScene"),&SceneTree::change_scene_to);
+
+ ObjectTypeDB::bind_method(_MD("reload_current_scene"),&SceneTree::reload_current_scene);
+
+ ObjectTypeDB::bind_method(_MD("_change_scene"),&SceneTree::_change_scene);
+
ADD_SIGNAL( MethodInfo("tree_changed") );
ADD_SIGNAL( MethodInfo("node_removed",PropertyInfo( Variant::OBJECT, "node") ) );
ADD_SIGNAL( MethodInfo("screen_resized") );
+ ADD_SIGNAL( MethodInfo("idle_frame"));
+ ADD_SIGNAL( MethodInfo("fixed_frame"));
+
BIND_CONSTANT( GROUP_CALL_DEFAULT );
BIND_CONSTANT( GROUP_CALL_REVERSE );
BIND_CONSTANT( GROUP_CALL_REALTIME );
@@ -1076,6 +1151,7 @@ SceneTree::SceneTree() {
//root->set_world_2d( Ref<World2D>( memnew( World2D )));
root->set_as_audio_listener(true);
root->set_as_audio_listener_2d(true);
+ current_scene=NULL;
stretch_mode=STRETCH_MODE_DISABLED;
stretch_aspect=STRETCH_ASPECT_IGNORE;
@@ -1093,8 +1169,7 @@ SceneTree::SceneTree() {
edited_scene_root=NULL;
#endif
- ADD_SIGNAL( MethodInfo("idle_frame"));
- ADD_SIGNAL( MethodInfo("fixed_frame"));
+
}
diff --git a/scene/main/scene_main_loop.h b/scene/main/scene_main_loop.h
index 31a823ab1a..e49c150fbf 100644
--- a/scene/main/scene_main_loop.h
+++ b/scene/main/scene_main_loop.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -42,7 +42,7 @@
class SceneTree;
-
+class PackedScene;
class Node;
class Viewport;
@@ -136,7 +136,9 @@ private:
Array _get_nodes_in_group(const StringName& p_group);
+ Node *current_scene;
+ void _change_scene(Node* p_to);
//void _call_group(uint32_t p_call_flags,const StringName& p_group,const StringName& p_function,const Variant& p_arg1,const Variant& p_arg2);
friend class Node;
@@ -234,6 +236,17 @@ public:
Node *get_edited_scene_root() const;
#endif
+ void set_current_scene(Node* p_scene);
+ Node* get_current_scene() const;
+ Error change_scene(const String& p_path);
+ Error change_scene_to(const Ref<PackedScene>& p_scene);
+ Error reload_current_scene();
+
+ //used by Main::start, don't use otherwise
+ void add_current_scene(Node * p_current);
+
+
+
SceneTree();
~SceneTree();
diff --git a/scene/main/scene_singleton.cpp b/scene/main/scene_singleton.cpp
index 042164a1f3..69eb6e24d9 100644
--- a/scene/main/scene_singleton.cpp
+++ b/scene/main/scene_singleton.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/scene/main/scene_singleton.h b/scene/main/scene_singleton.h
index 1e0359fe91..25157a26ac 100644
--- a/scene/main/scene_singleton.h
+++ b/scene/main/scene_singleton.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/scene/main/timer.cpp b/scene/main/timer.cpp
index f718a09577..3a80382a40 100644
--- a/scene/main/timer.cpp
+++ b/scene/main/timer.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -45,12 +45,14 @@ void Timer::_notification(int p_what) {
}
} break;
case NOTIFICATION_PROCESS: {
-
+ if (timer_process_mode == TIMER_PROCESS_FIXED || !is_processing())
+ return;
time_left -= get_process_delta_time();
if (time_left<0) {
if (!one_shot)
- time_left=wait_time+time_left;
+ //time_left=wait_time+time_left;
+ time_left = wait_time;
else
stop();
@@ -58,13 +60,27 @@ void Timer::_notification(int p_what) {
}
} break;
+ case NOTIFICATION_FIXED_PROCESS: {
+ if (timer_process_mode == TIMER_PROCESS_IDLE || !is_fixed_processing())
+ return;
+ time_left -= get_fixed_process_delta_time();
+
+ if (time_left<0) {
+ if (!one_shot)
+ //time_left = wait_time + time_left;
+ time_left = wait_time;
+ else
+ stop();
+ emit_signal("timeout");
+ }
+
+ } break;
}
}
void Timer::set_wait_time(float p_time) {
-
ERR_EXPLAIN("time should be greater than zero.");
ERR_FAIL_COND(p_time<=0);
wait_time=p_time;
@@ -94,14 +110,13 @@ bool Timer::has_autostart() const {
}
void Timer::start() {
-
time_left=wait_time;
- set_process(true);
+ _set_process(true);
}
void Timer::stop() {
time_left=-1;
- set_process(false);
+ _set_process(false);
autostart=false;
}
@@ -110,6 +125,41 @@ float Timer::get_time_left() const {
return time_left >0 ? time_left : 0;
}
+void Timer::set_timer_process_mode(TimerProcessMode p_mode) {
+
+ if (timer_process_mode == p_mode)
+ return;
+
+ switch (timer_process_mode) {
+ case TIMER_PROCESS_FIXED:
+ if (is_fixed_processing()) {
+ set_fixed_process(false);
+ set_process(true);
+ }
+ break;
+ case TIMER_PROCESS_IDLE:
+ if (is_processing()) {
+ set_process(false);
+ set_fixed_process(true);
+ }
+ break;
+ }
+ timer_process_mode = p_mode;
+}
+
+Timer::TimerProcessMode Timer::get_timer_process_mode() const{
+
+ return timer_process_mode;
+}
+
+
+void Timer::_set_process(bool p_process, bool p_force)
+{
+ switch (timer_process_mode) {
+ case TIMER_PROCESS_FIXED: set_fixed_process(p_process); break;
+ case TIMER_PROCESS_IDLE: set_process(p_process); break;
+ }
+}
void Timer::_bind_methods() {
@@ -127,8 +177,12 @@ void Timer::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_time_left"),&Timer::get_time_left);
+ ObjectTypeDB::bind_method(_MD("set_timer_process_mode", "mode"), &Timer::set_timer_process_mode);
+ ObjectTypeDB::bind_method(_MD("get_timer_process_mode"), &Timer::get_timer_process_mode);
+
ADD_SIGNAL( MethodInfo("timeout") );
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "Fixed,Idle"), _SCS("set_timer_process_mode"), _SCS("get_timer_process_mode"));
ADD_PROPERTY( PropertyInfo(Variant::REAL, "wait_time", PROPERTY_HINT_EXP_RANGE, "0.01,4096,0.01" ), _SCS("set_wait_time"), _SCS("get_wait_time") );
ADD_PROPERTY( PropertyInfo(Variant::BOOL, "one_shot" ), _SCS("set_one_shot"), _SCS("is_one_shot") );
ADD_PROPERTY( PropertyInfo(Variant::BOOL, "autostart" ), _SCS("set_autostart"), _SCS("has_autostart") );
@@ -136,8 +190,7 @@ void Timer::_bind_methods() {
}
Timer::Timer() {
-
-
+ timer_process_mode = TIMER_PROCESS_IDLE;
autostart=false;
wait_time=1;
one_shot=false;
diff --git a/scene/main/timer.h b/scene/main/timer.h
index b89cd10664..4b9cecba84 100644
--- a/scene/main/timer.h
+++ b/scene/main/timer.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -46,6 +46,11 @@ protected:
static void _bind_methods();
public:
+ enum TimerProcessMode {
+ TIMER_PROCESS_FIXED,
+ TIMER_PROCESS_IDLE,
+ };
+
void set_wait_time(float p_time);
float get_wait_time() const;
@@ -60,7 +65,16 @@ public:
float get_time_left() const;
+ void set_timer_process_mode(TimerProcessMode p_mode);
+ TimerProcessMode get_timer_process_mode() const;
Timer();
+
+private:
+ TimerProcessMode timer_process_mode;
+ void _set_process(bool p_process, bool p_force = false);
+
};
+VARIANT_ENUM_CAST(Timer::TimerProcessMode);
+
#endif // TIMER_H
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index ee400ae6d5..3bb64e54c6 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -406,7 +406,7 @@ void Viewport::_notification(int p_what) {
int rc = ss2d->intersect_point(point,res,64,Set<RID>(),0xFFFFFFFF,0xFFFFFFFF);
for(int i=0;i<rc;i++) {
- if (res[i].collider) {
+ if (res[i].collider_id && res[i].collider) {
CollisionObject2D *co=res[i].collider->cast_to<CollisionObject2D>();
if (co) {
@@ -1177,6 +1177,11 @@ void Viewport::_vp_unhandled_input(const InputEvent& p_ev) {
}
+Vector2 Viewport::get_mouse_pos() const {
+
+ return (get_final_transform().affine_inverse() * _get_input_pre_xform()).xform(Input::get_singleton()->get_mouse_pos());
+}
+
void Viewport::warp_mouse(const Vector2& p_pos) {
Vector2 gpos = (get_final_transform().affine_inverse() * _get_input_pre_xform()).affine_inverse().xform(p_pos);
@@ -1377,6 +1382,7 @@ void Viewport::_bind_methods() {
ObjectTypeDB::bind_method(_MD("is_audio_listener_2d","enable"), &Viewport::is_audio_listener_2d);
ObjectTypeDB::bind_method(_MD("set_render_target_to_screen_rect"), &Viewport::set_render_target_to_screen_rect);
+ ObjectTypeDB::bind_method(_MD("get_mouse_pos"), &Viewport::get_mouse_pos);
ObjectTypeDB::bind_method(_MD("warp_mouse","to_pos"), &Viewport::warp_mouse);
ADD_PROPERTY( PropertyInfo(Variant::RECT2,"rect"), _SCS("set_rect"), _SCS("get_rect") );
@@ -1450,6 +1456,7 @@ Viewport::~Viewport() {
VisualServer::get_singleton()->free( viewport );
SpatialSoundServer::get_singleton()->free(listener);
+ SpatialSound2DServer::get_singleton()->free(listener_2d);
if (render_target_texture.is_valid())
render_target_texture->vp=NULL; //so if used, will crash
}
diff --git a/scene/main/viewport.h b/scene/main/viewport.h
index 14f4f68217..c3c339ac5d 100644
--- a/scene/main/viewport.h
+++ b/scene/main/viewport.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -252,6 +252,7 @@ public:
void set_render_target_to_screen_rect(const Rect2& p_rect);
Rect2 get_render_target_to_screen_rect() const;
+ Vector2 get_mouse_pos() const;
void warp_mouse(const Vector2& p_pos);
void set_physics_object_picking(bool p_enable);