summaryrefslogtreecommitdiff
path: root/scene/2d
diff options
context:
space:
mode:
Diffstat (limited to 'scene/2d')
-rw-r--r--scene/2d/area_2d.cpp261
-rw-r--r--scene/2d/area_2d.h37
-rw-r--r--scene/2d/back_buffer_copy.cpp75
-rw-r--r--scene/2d/back_buffer_copy.h41
-rw-r--r--scene/2d/camera_2d.cpp11
-rw-r--r--scene/2d/camera_2d.h189
-rw-r--r--scene/2d/canvas_item.cpp351
-rw-r--r--scene/2d/canvas_item.h64
-rw-r--r--scene/2d/collision_object_2d.cpp71
-rw-r--r--scene/2d/collision_object_2d.h12
-rw-r--r--scene/2d/light_2d.cpp92
-rw-r--r--scene/2d/light_2d.h16
-rw-r--r--scene/2d/light_occluder_2d.cpp202
-rw-r--r--scene/2d/light_occluder_2d.h73
-rw-r--r--scene/2d/node_2d.cpp49
-rw-r--r--scene/2d/node_2d.h8
-rw-r--r--scene/2d/particles_2d.cpp5
-rw-r--r--scene/2d/physics_body_2d.cpp1
-rw-r--r--scene/2d/tile_map.cpp329
-rw-r--r--scene/2d/tile_map.h45
-rw-r--r--scene/2d/visibility_notifier_2d.cpp22
-rw-r--r--scene/2d/visibility_notifier_2d.h1
22 files changed, 1661 insertions, 294 deletions
diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp
index fce21f6001..a5c455ce64 100644
--- a/scene/2d/area_2d.cpp
+++ b/scene/2d/area_2d.cpp
@@ -216,6 +216,119 @@ void Area2D::_body_inout(int p_status,const RID& p_body, int p_instance, int p_b
}
+
+void Area2D::_area_enter_tree(ObjectID p_id) {
+
+ Object *obj = ObjectDB::get_instance(p_id);
+ Node *node = obj ? obj->cast_to<Node>() : NULL;
+ ERR_FAIL_COND(!node);
+
+ Map<ObjectID,AreaState>::Element *E=area_map.find(p_id);
+ ERR_FAIL_COND(!E);
+ ERR_FAIL_COND(E->get().in_tree);
+
+ E->get().in_tree=true;
+ emit_signal(SceneStringNames::get_singleton()->area_enter,node);
+ for(int i=0;i<E->get().shapes.size();i++) {
+
+ emit_signal(SceneStringNames::get_singleton()->area_enter_shape,p_id,node,E->get().shapes[i].area_shape,E->get().shapes[i].self_shape);
+ }
+
+}
+
+void Area2D::_area_exit_tree(ObjectID p_id) {
+
+ Object *obj = ObjectDB::get_instance(p_id);
+ Node *node = obj ? obj->cast_to<Node>() : NULL;
+ ERR_FAIL_COND(!node);
+ Map<ObjectID,AreaState>::Element *E=area_map.find(p_id);
+ ERR_FAIL_COND(!E);
+ ERR_FAIL_COND(!E->get().in_tree);
+ E->get().in_tree=false;
+ emit_signal(SceneStringNames::get_singleton()->area_exit,node);
+ for(int i=0;i<E->get().shapes.size();i++) {
+
+ emit_signal(SceneStringNames::get_singleton()->area_exit_shape,p_id,node,E->get().shapes[i].area_shape,E->get().shapes[i].self_shape);
+ }
+
+}
+
+void Area2D::_area_inout(int p_status,const RID& p_area, int p_instance, int p_area_shape,int p_self_shape) {
+
+ bool area_in = p_status==Physics2DServer::AREA_BODY_ADDED;
+ ObjectID objid=p_instance;
+
+ Object *obj = ObjectDB::get_instance(objid);
+ Node *node = obj ? obj->cast_to<Node>() : NULL;
+
+ Map<ObjectID,AreaState>::Element *E=area_map.find(objid);
+
+ ERR_FAIL_COND(!area_in && !E);
+
+ locked=true;
+
+ if (area_in) {
+ if (!E) {
+
+ E = area_map.insert(objid,AreaState());
+ E->get().rc=0;
+ E->get().in_tree=node && node->is_inside_tree();
+ if (node) {
+ node->connect(SceneStringNames::get_singleton()->enter_tree,this,SceneStringNames::get_singleton()->_area_enter_tree,make_binds(objid));
+ node->connect(SceneStringNames::get_singleton()->exit_tree,this,SceneStringNames::get_singleton()->_area_exit_tree,make_binds(objid));
+ if (E->get().in_tree) {
+ emit_signal(SceneStringNames::get_singleton()->area_enter,node);
+ }
+ }
+
+ }
+ E->get().rc++;
+ if (node)
+ E->get().shapes.insert(AreaShapePair(p_area_shape,p_self_shape));
+
+
+ if (!node || E->get().in_tree) {
+ emit_signal(SceneStringNames::get_singleton()->area_enter_shape,objid,node,p_area_shape,p_self_shape);
+ }
+
+ } else {
+
+ E->get().rc--;
+
+ if (node)
+ E->get().shapes.erase(AreaShapePair(p_area_shape,p_self_shape));
+
+ bool eraseit=false;
+
+ if (E->get().rc==0) {
+
+ if (node) {
+ node->disconnect(SceneStringNames::get_singleton()->enter_tree,this,SceneStringNames::get_singleton()->_area_enter_tree);
+ node->disconnect(SceneStringNames::get_singleton()->exit_tree,this,SceneStringNames::get_singleton()->_area_exit_tree);
+ if (E->get().in_tree)
+ emit_signal(SceneStringNames::get_singleton()->area_exit,obj);
+
+ }
+
+ eraseit=true;
+
+ }
+ if (!node || E->get().in_tree) {
+ emit_signal(SceneStringNames::get_singleton()->area_exit_shape,objid,obj,p_area_shape,p_self_shape);
+ }
+
+ if (eraseit)
+ area_map.erase(E);
+
+ }
+
+ locked=false;
+
+
+}
+
+
+
void Area2D::_clear_monitoring() {
if (locked) {
@@ -223,27 +336,56 @@ void Area2D::_clear_monitoring() {
}
ERR_FAIL_COND(locked);
- Map<ObjectID,BodyState> bmcopy = body_map;
- body_map.clear();
- //disconnect all monitored stuff
+ {
+ Map<ObjectID,BodyState> bmcopy = body_map;
+ body_map.clear();
+ //disconnect all monitored stuff
- for (Map<ObjectID,BodyState>::Element *E=bmcopy.front();E;E=E->next()) {
+ for (Map<ObjectID,BodyState>::Element *E=bmcopy.front();E;E=E->next()) {
- Object *obj = ObjectDB::get_instance(E->key());
- Node *node = obj ? obj->cast_to<Node>() : NULL;
- ERR_CONTINUE(!node);
- if (!E->get().in_tree)
- continue;
+ Object *obj = ObjectDB::get_instance(E->key());
+ Node *node = obj ? obj->cast_to<Node>() : NULL;
+ ERR_CONTINUE(!node);
+ if (!E->get().in_tree)
+ continue;
- for(int i=0;i<E->get().shapes.size();i++) {
+ for(int i=0;i<E->get().shapes.size();i++) {
- emit_signal(SceneStringNames::get_singleton()->body_exit_shape,E->key(),node,E->get().shapes[i].body_shape,E->get().shapes[i].area_shape);
+ emit_signal(SceneStringNames::get_singleton()->body_exit_shape,E->key(),node,E->get().shapes[i].body_shape,E->get().shapes[i].area_shape);
+ }
+
+ emit_signal(SceneStringNames::get_singleton()->body_exit,obj);
+
+ node->disconnect(SceneStringNames::get_singleton()->enter_tree,this,SceneStringNames::get_singleton()->_body_enter_tree);
+ node->disconnect(SceneStringNames::get_singleton()->exit_tree,this,SceneStringNames::get_singleton()->_body_exit_tree);
}
- emit_signal(SceneStringNames::get_singleton()->body_exit,obj);
+ }
- node->disconnect(SceneStringNames::get_singleton()->enter_tree,this,SceneStringNames::get_singleton()->_body_enter_tree);
- node->disconnect(SceneStringNames::get_singleton()->exit_tree,this,SceneStringNames::get_singleton()->_body_exit_tree);
+ {
+
+ Map<ObjectID,AreaState> bmcopy = area_map;
+ area_map.clear();
+ //disconnect all monitored stuff
+
+ for (Map<ObjectID,AreaState>::Element *E=bmcopy.front();E;E=E->next()) {
+
+ Object *obj = ObjectDB::get_instance(E->key());
+ Node *node = obj ? obj->cast_to<Node>() : NULL;
+ ERR_CONTINUE(!node);
+ if (!E->get().in_tree)
+ continue;
+
+ for(int i=0;i<E->get().shapes.size();i++) {
+
+ emit_signal(SceneStringNames::get_singleton()->area_exit_shape,E->key(),node,E->get().shapes[i].area_shape,E->get().shapes[i].self_shape);
+ }
+
+ emit_signal(SceneStringNames::get_singleton()->area_exit,obj);
+
+ node->disconnect(SceneStringNames::get_singleton()->enter_tree,this,SceneStringNames::get_singleton()->_area_enter_tree);
+ node->disconnect(SceneStringNames::get_singleton()->exit_tree,this,SceneStringNames::get_singleton()->_area_exit_tree);
+ }
}
}
@@ -276,8 +418,10 @@ void Area2D::set_enable_monitoring(bool p_enable) {
if (monitoring) {
Physics2DServer::get_singleton()->area_set_monitor_callback(get_rid(),this,"_body_inout");
+ Physics2DServer::get_singleton()->area_set_area_monitor_callback(get_rid(),this,"_area_inout");
} else {
Physics2DServer::get_singleton()->area_set_monitor_callback(get_rid(),NULL,StringName());
+ Physics2DServer::get_singleton()->area_set_area_monitor_callback(get_rid(),NULL,StringName());
_clear_monitoring();
}
@@ -288,6 +432,26 @@ bool Area2D::is_monitoring_enabled() const {
return monitoring;
}
+void Area2D::set_monitorable(bool p_enable) {
+
+ if (locked) {
+ ERR_EXPLAIN("This function can't be used during the in/out signal.");
+ }
+ ERR_FAIL_COND(locked);
+
+ if (p_enable==monitorable)
+ return;
+
+ monitorable=p_enable;
+
+ Physics2DServer::get_singleton()->area_set_monitorable(get_rid(),monitorable);
+}
+
+bool Area2D::is_monitorable() const {
+
+ return monitorable;
+}
+
Array Area2D::get_overlapping_bodies() const {
ERR_FAIL_COND_V(!monitoring,Array());
@@ -307,12 +471,56 @@ Array Area2D::get_overlapping_bodies() const {
return ret;
}
+Array Area2D::get_overlapping_areas() const {
+
+ ERR_FAIL_COND_V(!monitoring,Array());
+ Array ret;
+ ret.resize(area_map.size());
+ int idx=0;
+ for (const Map<ObjectID,AreaState>::Element *E=area_map.front();E;E=E->next()) {
+ Object *obj = ObjectDB::get_instance(E->key());
+ if (!obj) {
+ ret.resize( ret.size() -1 ); //ops
+ } else {
+ ret[idx++]=obj;
+ }
+
+ }
+
+ return ret;
+}
+
+bool Area2D::overlaps_area(Node* p_area) const {
+
+ ERR_FAIL_NULL_V(p_area,false);
+ const Map<ObjectID,AreaState>::Element *E=area_map.find(p_area->get_instance_ID());
+ if (!E)
+ return false;
+ return E->get().in_tree;
+
+
+
+}
+
+bool Area2D::overlaps_body(Node* p_body) const{
+
+ ERR_FAIL_NULL_V(p_body,false);
+ const Map<ObjectID,BodyState>::Element *E=body_map.find(p_body->get_instance_ID());
+ if (!E)
+ return false;
+ return E->get().in_tree;
+
+}
+
void Area2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_body_enter_tree","id"),&Area2D::_body_enter_tree);
ObjectTypeDB::bind_method(_MD("_body_exit_tree","id"),&Area2D::_body_exit_tree);
+ ObjectTypeDB::bind_method(_MD("_area_enter_tree","id"),&Area2D::_area_enter_tree);
+ ObjectTypeDB::bind_method(_MD("_area_exit_tree","id"),&Area2D::_area_exit_tree);
+
ObjectTypeDB::bind_method(_MD("set_space_override_mode","enable"),&Area2D::set_space_override_mode);
ObjectTypeDB::bind_method(_MD("get_space_override_mode"),&Area2D::get_space_override_mode);
@@ -337,15 +545,29 @@ void Area2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_enable_monitoring","enable"),&Area2D::set_enable_monitoring);
ObjectTypeDB::bind_method(_MD("is_monitoring_enabled"),&Area2D::is_monitoring_enabled);
+ ObjectTypeDB::bind_method(_MD("set_monitorable","enable"),&Area2D::set_monitorable);
+ ObjectTypeDB::bind_method(_MD("is_monitorable"),&Area2D::is_monitorable);
+
ObjectTypeDB::bind_method(_MD("get_overlapping_bodies"),&Area2D::get_overlapping_bodies);
+ ObjectTypeDB::bind_method(_MD("get_overlapping_areas"),&Area2D::get_overlapping_areas);
+
+ ObjectTypeDB::bind_method(_MD("overlaps_body:PhysicsBody2D","body"),&Area2D::overlaps_body);
+ ObjectTypeDB::bind_method(_MD("overlaps_area:Area2D","area"),&Area2D::overlaps_area);
ObjectTypeDB::bind_method(_MD("_body_inout"),&Area2D::_body_inout);
+ ObjectTypeDB::bind_method(_MD("_area_inout"),&Area2D::_area_inout);
+
+
+ ADD_SIGNAL( MethodInfo("body_enter_shape",PropertyInfo(Variant::INT,"body_id"),PropertyInfo(Variant::OBJECT,"body",PROPERTY_HINT_RESOURCE_TYPE,"PhysicsBody2D"),PropertyInfo(Variant::INT,"body_shape"),PropertyInfo(Variant::INT,"area_shape")));
+ ADD_SIGNAL( MethodInfo("body_exit_shape",PropertyInfo(Variant::INT,"body_id"),PropertyInfo(Variant::OBJECT,"body",PROPERTY_HINT_RESOURCE_TYPE,"PhysicsBody2D"),PropertyInfo(Variant::INT,"body_shape"),PropertyInfo(Variant::INT,"area_shape")));
+ ADD_SIGNAL( MethodInfo("body_enter",PropertyInfo(Variant::OBJECT,"body",PROPERTY_HINT_RESOURCE_TYPE,"PhysicsBody2D")));
+ ADD_SIGNAL( MethodInfo("body_exit",PropertyInfo(Variant::OBJECT,"body",PROPERTY_HINT_RESOURCE_TYPE,"PhysicsBody2D")));
+ ADD_SIGNAL( MethodInfo("area_enter_shape",PropertyInfo(Variant::INT,"area_id"),PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area2D"),PropertyInfo(Variant::INT,"area_shape"),PropertyInfo(Variant::INT,"area_shape")));
+ ADD_SIGNAL( MethodInfo("area_exit_shape",PropertyInfo(Variant::INT,"area_id"),PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area2D"),PropertyInfo(Variant::INT,"area_shape"),PropertyInfo(Variant::INT,"area_shape")));
+ ADD_SIGNAL( MethodInfo("area_enter",PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area2D")));
+ ADD_SIGNAL( MethodInfo("area_exit",PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area2D")));
- ADD_SIGNAL( MethodInfo("body_enter_shape",PropertyInfo(Variant::INT,"body_id"),PropertyInfo(Variant::OBJECT,"body"),PropertyInfo(Variant::INT,"body_shape"),PropertyInfo(Variant::INT,"area_shape")));
- ADD_SIGNAL( MethodInfo("body_exit_shape",PropertyInfo(Variant::INT,"body_id"),PropertyInfo(Variant::OBJECT,"body"),PropertyInfo(Variant::INT,"body_shape"),PropertyInfo(Variant::INT,"area_shape")));
- ADD_SIGNAL( MethodInfo("body_enter",PropertyInfo(Variant::OBJECT,"body")));
- ADD_SIGNAL( MethodInfo("body_exit",PropertyInfo(Variant::OBJECT,"body")));
ADD_PROPERTYNZ( PropertyInfo(Variant::INT,"space_override",PROPERTY_HINT_ENUM,"Disabled,Combine,Replace"),_SCS("set_space_override_mode"),_SCS("get_space_override_mode"));
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"gravity_point"),_SCS("set_gravity_is_point"),_SCS("is_gravity_a_point"));
@@ -355,6 +577,7 @@ void Area2D::_bind_methods() {
ADD_PROPERTY( PropertyInfo(Variant::REAL,"angular_damp",PROPERTY_HINT_RANGE,"0,1024,0.001"),_SCS("set_angular_damp"),_SCS("get_angular_damp"));
ADD_PROPERTYNZ( PropertyInfo(Variant::INT,"priority",PROPERTY_HINT_RANGE,"0,128,1"),_SCS("set_priority"),_SCS("get_priority"));
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"monitoring"),_SCS("set_enable_monitoring"),_SCS("is_monitoring_enabled"));
+ ADD_PROPERTY( PropertyInfo(Variant::BOOL,"monitorable"),_SCS("set_monitorable"),_SCS("is_monitorable"));
}
@@ -369,7 +592,9 @@ Area2D::Area2D() : CollisionObject2D(Physics2DServer::get_singleton()->area_crea
locked=false;
priority=0;
monitoring=false;
+ monitorable=false;
set_enable_monitoring(true);
+ set_monitorable(true);
}
diff --git a/scene/2d/area_2d.h b/scene/2d/area_2d.h
index f770e88a19..6a6c757e0c 100644
--- a/scene/2d/area_2d.h
+++ b/scene/2d/area_2d.h
@@ -53,6 +53,7 @@ private:
real_t angular_damp;
int priority;
bool monitoring;
+ bool monitorable;
bool locked;
void _body_inout(int p_status,const RID& p_body, int p_instance, int p_body_shape,int p_area_shape);
@@ -84,6 +85,36 @@ private:
Map<ObjectID,BodyState> body_map;
+
+
+ void _area_inout(int p_status,const RID& p_area, int p_instance, int p_area_shape,int p_self_shape);
+
+ void _area_enter_tree(ObjectID p_id);
+ void _area_exit_tree(ObjectID p_id);
+
+ struct AreaShapePair {
+
+ int area_shape;
+ int self_shape;
+ bool operator<(const AreaShapePair& p_sp) const {
+ if (area_shape==p_sp.area_shape)
+ return self_shape < p_sp.self_shape;
+ else
+ return area_shape < p_sp.area_shape;
+ }
+
+ AreaShapePair() {}
+ AreaShapePair(int p_bs, int p_as) { area_shape=p_bs; self_shape=p_as; }
+ };
+
+ struct AreaState {
+
+ int rc;
+ bool in_tree;
+ VSet<AreaShapePair> shapes;
+ };
+
+ Map<ObjectID,AreaState> area_map;
void _clear_monitoring();
@@ -117,8 +148,14 @@ public:
void set_enable_monitoring(bool p_enable);
bool is_monitoring_enabled() const;
+ void set_monitorable(bool p_enable);
+ bool is_monitorable() const;
+
Array get_overlapping_bodies() const; //function for script
+ Array get_overlapping_areas() const; //function for script
+ bool overlaps_area(Node* p_area) const;
+ bool overlaps_body(Node* p_body) const;
Area2D();
~Area2D();
diff --git a/scene/2d/back_buffer_copy.cpp b/scene/2d/back_buffer_copy.cpp
new file mode 100644
index 0000000000..245b3ba7eb
--- /dev/null
+++ b/scene/2d/back_buffer_copy.cpp
@@ -0,0 +1,75 @@
+#include "back_buffer_copy.h"
+
+void BackBufferCopy::_update_copy_mode() {
+
+ switch(copy_mode) {
+
+ case COPY_MODE_DISALED: {
+
+ VS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(),false,Rect2());
+ } break;
+ case COPY_MODE_RECT: {
+
+ VS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(),true,rect);
+ } break;
+ case COPY_MODE_VIEWPORT: {
+
+ VS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(),true,Rect2());
+
+ } break;
+
+ }
+}
+
+Rect2 BackBufferCopy::get_item_rect() const {
+
+ return rect;
+}
+
+void BackBufferCopy::set_rect(const Rect2& p_rect) {
+
+ rect=p_rect;
+ _update_copy_mode();
+}
+
+Rect2 BackBufferCopy::get_rect() const{
+ return rect;
+}
+
+void BackBufferCopy::set_copy_mode(CopyMode p_mode){
+
+ copy_mode=p_mode;
+ _update_copy_mode();
+}
+BackBufferCopy::CopyMode BackBufferCopy::get_copy_mode() const{
+
+ return copy_mode;
+}
+
+
+void BackBufferCopy::_bind_methods() {
+
+ ObjectTypeDB::bind_method(_MD("set_rect","rect"),&BackBufferCopy::set_rect);
+ ObjectTypeDB::bind_method(_MD("get_rect"),&BackBufferCopy::get_rect);
+
+ ObjectTypeDB::bind_method(_MD("set_copy_mode","copy_mode"),&BackBufferCopy::set_copy_mode);
+ ObjectTypeDB::bind_method(_MD("get_copy_mode"),&BackBufferCopy::get_copy_mode);
+
+ ADD_PROPERTY( PropertyInfo(Variant::INT,"copy_mode",PROPERTY_HINT_ENUM,"Disabled,Rect,Viewport"),_SCS("set_copy_mode"),_SCS("get_copy_mode"));
+ ADD_PROPERTY( PropertyInfo(Variant::RECT2,"rect"),_SCS("set_rect"),_SCS("get_rect"));
+
+ BIND_CONSTANT( COPY_MODE_DISALED );
+ BIND_CONSTANT( COPY_MODE_RECT );
+ BIND_CONSTANT( COPY_MODE_VIEWPORT );
+
+}
+
+BackBufferCopy::BackBufferCopy(){
+
+ rect=Rect2(-100,-100,200,200);
+ copy_mode=COPY_MODE_RECT;
+ _update_copy_mode();
+}
+BackBufferCopy::~BackBufferCopy(){
+
+}
diff --git a/scene/2d/back_buffer_copy.h b/scene/2d/back_buffer_copy.h
new file mode 100644
index 0000000000..3a86ffa309
--- /dev/null
+++ b/scene/2d/back_buffer_copy.h
@@ -0,0 +1,41 @@
+#ifndef BACKBUFFERCOPY_H
+#define BACKBUFFERCOPY_H
+
+#include "scene/2d/node_2d.h"
+
+class BackBufferCopy : public Node2D {
+ OBJ_TYPE( BackBufferCopy,Node2D);
+public:
+ enum CopyMode {
+ COPY_MODE_DISALED,
+ COPY_MODE_RECT,
+ COPY_MODE_VIEWPORT
+ };
+private:
+
+ Rect2 rect;
+ CopyMode copy_mode;
+
+ void _update_copy_mode();
+
+protected:
+
+ static void _bind_methods();
+
+public:
+
+ void set_rect(const Rect2& p_rect);
+ Rect2 get_rect() const;
+
+ void set_copy_mode(CopyMode p_mode);
+ CopyMode get_copy_mode() const;
+
+ Rect2 get_item_rect() const;
+
+ BackBufferCopy();
+ ~BackBufferCopy();
+};
+
+VARIANT_ENUM_CAST(BackBufferCopy::CopyMode);
+
+#endif // BACKBUFFERCOPY_H
diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp
index b3897010bf..b2d74b4ad5 100644
--- a/scene/2d/camera_2d.cpp
+++ b/scene/2d/camera_2d.cpp
@@ -323,6 +323,16 @@ void Camera2D::make_current() {
}
}
+void Camera2D::clear_current() {
+
+ current=false;
+ if (is_inside_tree()) {
+ get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,group_name,"_make_current",(Object*)(NULL));
+ }
+
+}
+
+
void Camera2D::set_limit(Margin p_margin,int p_limit) {
ERR_FAIL_INDEX(p_margin,4);
@@ -435,6 +445,7 @@ void Camera2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("is_rotating"),&Camera2D::is_rotating);
ObjectTypeDB::bind_method(_MD("make_current"),&Camera2D::make_current);
+ ObjectTypeDB::bind_method(_MD("clear_current"),&Camera2D::clear_current);
ObjectTypeDB::bind_method(_MD("_make_current"),&Camera2D::_make_current);
ObjectTypeDB::bind_method(_MD("_update_scroll"),&Camera2D::_update_scroll);
diff --git a/scene/2d/camera_2d.h b/scene/2d/camera_2d.h
index 116169cac1..515f9711bf 100644
--- a/scene/2d/camera_2d.h
+++ b/scene/2d/camera_2d.h
@@ -26,97 +26,98 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#ifndef CAMERA_2D_H
-#define CAMERA_2D_H
-
-#include "scene/2d/node_2d.h"
-#include "scene/main/viewport.h"
-
-
-class Camera2D : public Node2D {
-
- OBJ_TYPE( Camera2D, Node2D );
-
-protected:
- Point2 camera_pos;
- Point2 smoothed_camera_pos;
- bool first;
-
- Viewport *viewport;
-
- StringName group_name;
- StringName canvas_group_name;
- RID canvas;
- Vector2 offset;
- Vector2 zoom;
- bool centered;
- bool rotating;
- bool current;
- float smoothing;
- int limit[4];
- float drag_margin[4];
-
- bool h_drag_enabled;
- bool v_drag_enabled;
- float h_ofs;
- float v_ofs;
-
-
- Point2 camera_screen_center;
- void _update_scroll();
-
- void _make_current(Object *p_which);
- void _set_current(bool p_current);
-protected:
-
- virtual Matrix32 get_camera_transform();
- void _notification(int p_what);
- static void _bind_methods();
-public:
-
- void set_offset(const Vector2& p_offset);
- Vector2 get_offset() const;
-
- void set_centered(bool p_centered);
- bool is_centered() const;
-
- void set_rotating(bool p_rotating);
- bool is_rotating() const;
-
- void set_limit(Margin p_margin,int p_limit);
- int get_limit(Margin p_margin) const;
-
-
- void set_h_drag_enabled(bool p_enabled);
- bool is_h_drag_enabled() const;
-
- void set_v_drag_enabled(bool p_enabled);
- bool is_v_drag_enabled() const;
-
- void set_drag_margin(Margin p_margin,float p_drag_margin);
- float get_drag_margin(Margin p_margin) const;
-
- void set_v_offset(float p_offset);
- float get_v_offset() const;
-
- void set_h_offset(float p_offset);
- float get_h_offset() const;
-
- void set_follow_smoothing(float p_speed);
- float get_follow_smoothing() const;
-
- void make_current();
- bool is_current() const;
-
- void set_zoom(const Vector2& p_zoom);
- Vector2 get_zoom() const;
-
- Point2 get_camera_screen_center() const;
-
- Vector2 get_camera_pos() const;
- void force_update_scroll();
-
- Camera2D();
-};
-
-#endif // CAMERA_2D_H
+#ifndef CAMERA_2D_H
+#define CAMERA_2D_H
+
+#include "scene/2d/node_2d.h"
+#include "scene/main/viewport.h"
+
+
+class Camera2D : public Node2D {
+
+ OBJ_TYPE( Camera2D, Node2D );
+
+protected:
+ Point2 camera_pos;
+ Point2 smoothed_camera_pos;
+ bool first;
+
+ Viewport *viewport;
+
+ StringName group_name;
+ StringName canvas_group_name;
+ RID canvas;
+ Vector2 offset;
+ Vector2 zoom;
+ bool centered;
+ bool rotating;
+ bool current;
+ float smoothing;
+ int limit[4];
+ float drag_margin[4];
+
+ bool h_drag_enabled;
+ bool v_drag_enabled;
+ float h_ofs;
+ float v_ofs;
+
+
+ Point2 camera_screen_center;
+ void _update_scroll();
+
+ void _make_current(Object *p_which);
+ void _set_current(bool p_current);
+protected:
+
+ virtual Matrix32 get_camera_transform();
+ void _notification(int p_what);
+ static void _bind_methods();
+public:
+
+ void set_offset(const Vector2& p_offset);
+ Vector2 get_offset() const;
+
+ void set_centered(bool p_centered);
+ bool is_centered() const;
+
+ void set_rotating(bool p_rotating);
+ bool is_rotating() const;
+
+ void set_limit(Margin p_margin,int p_limit);
+ int get_limit(Margin p_margin) const;
+
+
+ void set_h_drag_enabled(bool p_enabled);
+ bool is_h_drag_enabled() const;
+
+ void set_v_drag_enabled(bool p_enabled);
+ bool is_v_drag_enabled() const;
+
+ void set_drag_margin(Margin p_margin,float p_drag_margin);
+ float get_drag_margin(Margin p_margin) const;
+
+ void set_v_offset(float p_offset);
+ float get_v_offset() const;
+
+ void set_h_offset(float p_offset);
+ float get_h_offset() const;
+
+ void set_follow_smoothing(float p_speed);
+ float get_follow_smoothing() const;
+
+ void make_current();
+ void clear_current();
+ bool is_current() const;
+
+ void set_zoom(const Vector2& p_zoom);
+ Vector2 get_zoom() const;
+
+ Point2 get_camera_screen_center() const;
+
+ Vector2 get_camera_pos() const;
+ void force_update_scroll();
+
+ Camera2D();
+};
+
+#endif // CAMERA_2D_H
diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp
index 4021ba5910..c3ff03d8f4 100644
--- a/scene/2d/canvas_item.cpp
+++ b/scene/2d/canvas_item.cpp
@@ -36,6 +36,191 @@
#include "scene/resources/texture.h"
#include "scene/resources/style_box.h"
+
+bool CanvasItemMaterial::_set(const StringName& p_name, const Variant& p_value) {
+
+ if (p_name==SceneStringNames::get_singleton()->shader_shader) {
+ set_shader(p_value);
+ return true;
+ } else if (p_name==SceneStringNames::get_singleton()->shader_unshaded) {
+ set_unshaded(p_value);
+ return true;
+ } else {
+
+ if (shader.is_valid()) {
+
+
+ StringName pr = shader->remap_param(p_name);
+ if (!pr) {
+ String n = p_name;
+ if (n.find("param/")==0) { //backwards compatibility
+ pr = n.substr(6,n.length());
+ }
+ }
+ if (pr) {
+ VisualServer::get_singleton()->canvas_item_material_set_shader_param(material,pr,p_value);
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
+bool CanvasItemMaterial::_get(const StringName& p_name,Variant &r_ret) const {
+
+
+ if (p_name==SceneStringNames::get_singleton()->shader_shader) {
+
+ r_ret=get_shader();
+ return true;
+ } else if (p_name==SceneStringNames::get_singleton()->shader_unshaded) {
+
+
+ r_ret=unshaded;
+ return true;
+ } else {
+
+ if (shader.is_valid()) {
+
+ StringName pr = shader->remap_param(p_name);
+ if (pr) {
+ r_ret=VisualServer::get_singleton()->canvas_item_material_get_shader_param(material,pr);
+ return true;
+ }
+ }
+
+ }
+
+
+ return false;
+}
+
+
+void CanvasItemMaterial::_get_property_list( List<PropertyInfo> *p_list) const {
+
+ p_list->push_back( PropertyInfo( Variant::OBJECT, "shader/shader", PROPERTY_HINT_RESOURCE_TYPE,"CanvasItemShader,CanvasItemShaderGraph" ) );
+ p_list->push_back( PropertyInfo( Variant::BOOL, "shader/unshaded") );
+
+ if (!shader.is_null()) {
+
+ shader->get_param_list(p_list);
+ }
+
+}
+
+void CanvasItemMaterial::set_shader(const Ref<Shader>& p_shader) {
+
+ ERR_FAIL_COND(p_shader.is_valid() && p_shader->get_mode()!=Shader::MODE_CANVAS_ITEM);
+#ifdef TOOLS_ENABLED
+
+ if (shader.is_valid()) {
+ shader->disconnect("changed",this,"_shader_changed");
+ }
+#endif
+ shader=p_shader;
+
+#ifdef TOOLS_ENABLED
+
+ if (shader.is_valid()) {
+ shader->connect("changed",this,"_shader_changed");
+ }
+#endif
+
+ RID rid;
+ if (shader.is_valid())
+ rid=shader->get_rid();
+
+ VS::get_singleton()->canvas_item_material_set_shader(material,rid);
+ _change_notify(); //properties for shader exposed
+ emit_changed();
+}
+
+Ref<Shader> CanvasItemMaterial::get_shader() const{
+
+ return shader;
+}
+
+void CanvasItemMaterial::set_shader_param(const StringName& p_param,const Variant& p_value){
+
+ VS::get_singleton()->canvas_item_material_set_shader_param(material,p_param,p_value);
+}
+
+Variant CanvasItemMaterial::get_shader_param(const StringName& p_param) const{
+
+ return VS::get_singleton()->canvas_item_material_get_shader_param(material,p_param);
+}
+
+void CanvasItemMaterial::_shader_changed() {
+
+
+}
+
+RID CanvasItemMaterial::get_rid() const {
+
+ return material;
+}
+
+void CanvasItemMaterial::set_unshaded(bool p_unshaded) {
+
+ unshaded=p_unshaded;
+ VS::get_singleton()->canvas_item_material_set_unshaded(material,p_unshaded);
+}
+
+bool CanvasItemMaterial::is_unshaded() const{
+
+ return unshaded;
+}
+
+void CanvasItemMaterial::_bind_methods() {
+
+ ObjectTypeDB::bind_method(_MD("set_shader","shader:Shader"),&CanvasItemMaterial::set_shader);
+ ObjectTypeDB::bind_method(_MD("get_shader:Shader"),&CanvasItemMaterial::get_shader);
+ ObjectTypeDB::bind_method(_MD("set_shader_param","param","value"),&CanvasItemMaterial::set_shader_param);
+ ObjectTypeDB::bind_method(_MD("get_shader_param","param"),&CanvasItemMaterial::get_shader_param);
+ ObjectTypeDB::bind_method(_MD("set_unshaded","unshaded"),&CanvasItemMaterial::set_unshaded);
+ ObjectTypeDB::bind_method(_MD("is_unshaded"),&CanvasItemMaterial::is_unshaded);
+
+}
+
+void CanvasItemMaterial::get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const {
+
+ String f = p_function.operator String();
+ if ((f=="get_shader_param" || f=="set_shader_param") && p_idx==0) {
+
+ if (shader.is_valid()) {
+ List<PropertyInfo> pl;
+ shader->get_param_list(&pl);
+ for (List<PropertyInfo>::Element *E=pl.front();E;E=E->next()) {
+ r_options->push_back("\""+E->get().name.replace_first("shader_param/","")+"\"");
+ }
+ }
+ }
+ Resource::get_argument_options(p_function,p_idx,r_options);
+}
+
+CanvasItemMaterial::CanvasItemMaterial() {
+
+ material=VS::get_singleton()->canvas_item_material_create();
+ unshaded=false;
+}
+
+CanvasItemMaterial::~CanvasItemMaterial(){
+
+ VS::get_singleton()->free(material);
+}
+
+
+
+
+
+
+
+
+///////////////////////////////////////////////////////////////////
+
+
+
bool CanvasItem::is_visible() const {
if (!is_inside_tree())
@@ -521,7 +706,7 @@ void CanvasItem::draw_texture(const Ref<Texture>& p_texture,const Point2& p_pos)
p_texture->draw(canvas_item,p_pos);
}
-void CanvasItem::draw_texture_rect(const Ref<Texture>& p_texture,const Rect2& p_rect, bool p_tile,const Color& p_modulate) {
+void CanvasItem::draw_texture_rect(const Ref<Texture>& p_texture,const Rect2& p_rect, bool p_tile,const Color& p_modulate, bool p_transpose) {
if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
@@ -529,17 +714,17 @@ void CanvasItem::draw_texture_rect(const Ref<Texture>& p_texture,const Rect2& p_
}
ERR_FAIL_COND(p_texture.is_null());
- p_texture->draw_rect(canvas_item,p_rect,p_tile,p_modulate);
+ p_texture->draw_rect(canvas_item,p_rect,p_tile,p_modulate,p_transpose);
}
-void CanvasItem::draw_texture_rect_region(const Ref<Texture>& p_texture,const Rect2& p_rect, const Rect2& p_src_rect,const Color& p_modulate) {
+void CanvasItem::draw_texture_rect_region(const Ref<Texture>& p_texture,const Rect2& p_rect, const Rect2& p_src_rect,const Color& p_modulate, bool p_transpose) {
if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
ERR_FAIL();
}
ERR_FAIL_COND(p_texture.is_null());
- p_texture->draw_rect_region(canvas_item,p_rect,p_src_rect,p_modulate);
+ p_texture->draw_rect_region(canvas_item,p_rect,p_src_rect,p_modulate,p_transpose);
}
void CanvasItem::draw_style_box(const Ref<StyleBox>& p_style_box,const Rect2& p_rect) {
@@ -730,110 +915,94 @@ bool CanvasItem::is_draw_behind_parent_enabled() const{
return behind;
}
-void CanvasItem::set_shader(const Ref<Shader>& p_shader) {
-
- ERR_FAIL_COND(p_shader.is_valid() && p_shader->get_mode()!=Shader::MODE_CANVAS_ITEM);
-
-#ifdef TOOLS_ENABLED
-
- if (shader.is_valid()) {
- shader->disconnect("changed",this,"_shader_changed");
- }
-#endif
- shader=p_shader;
-
-#ifdef TOOLS_ENABLED
+void CanvasItem::set_material(const Ref<CanvasItemMaterial>& p_material) {
- if (shader.is_valid()) {
- shader->connect("changed",this,"_shader_changed");
- }
-#endif
+ material=p_material;
RID rid;
- if (shader.is_valid())
- rid=shader->get_rid();
- VS::get_singleton()->canvas_item_set_shader(canvas_item,rid);
- _change_notify(); //properties for shader exposed
+ if (material.is_valid())
+ rid=material->get_rid();
+ VS::get_singleton()->canvas_item_set_material(canvas_item,rid);
+ _change_notify(); //properties for material exposed
}
-void CanvasItem::set_use_parent_shader(bool p_use_parent_shader) {
+void CanvasItem::set_use_parent_material(bool p_use_parent_material) {
- use_parent_shader=p_use_parent_shader;
- VS::get_singleton()->canvas_item_set_use_parent_shader(canvas_item,p_use_parent_shader);
+ use_parent_material=p_use_parent_material;
+ VS::get_singleton()->canvas_item_set_use_parent_material(canvas_item,p_use_parent_material);
}
-bool CanvasItem::get_use_parent_shader() const{
+bool CanvasItem::get_use_parent_material() const{
- return use_parent_shader;
+ return use_parent_material;
}
-Ref<Shader> CanvasItem::get_shader() const{
+Ref<CanvasItemMaterial> CanvasItem::get_material() const{
- return shader;
+ return material;
}
-void CanvasItem::set_shader_param(const StringName& p_param,const Variant& p_value) {
- VS::get_singleton()->canvas_item_set_shader_param(canvas_item,p_param,p_value);
-}
+InputEvent CanvasItem::make_input_local(const InputEvent& p_event) const {
-Variant CanvasItem::get_shader_param(const StringName& p_param) const {
+ ERR_FAIL_COND_V(!is_inside_tree(),p_event);
- return VS::get_singleton()->canvas_item_get_shader_param(canvas_item,p_param);
-}
+ InputEvent ev = p_event;
-bool CanvasItem::_set(const StringName& p_name, const Variant& p_value) {
+ Matrix32 local_matrix = (get_canvas_transform() * get_global_transform()).affine_inverse();
- if (shader.is_valid()) {
- StringName pr = shader->remap_param(p_name);
- if (pr) {
- set_shader_param(pr,p_value);
- return true;
- }
- }
- return false;
-}
+ switch(ev.type) {
-bool CanvasItem::_get(const StringName& p_name,Variant &r_ret) const{
+ case InputEvent::MOUSE_BUTTON: {
- if (shader.is_valid()) {
- StringName pr = shader->remap_param(p_name);
- if (pr) {
- r_ret=get_shader_param(pr);
- return true;
- }
- }
- return false;
-
-}
-void CanvasItem::_get_property_list( List<PropertyInfo> *p_list) const{
-
- if (shader.is_valid()) {
- shader->get_param_list(p_list);
- }
-}
-
-#ifdef TOOLS_ENABLED
-void CanvasItem::_shader_changed() {
+ Vector2 g = local_matrix.xform(Vector2(ev.mouse_button.global_x,ev.mouse_button.global_y));
+ Vector2 l = local_matrix.xform(Vector2(ev.mouse_button.x,ev.mouse_button.y));
+ ev.mouse_button.x=l.x;
+ ev.mouse_button.y=l.y;
+ ev.mouse_button.global_x=g.x;
+ ev.mouse_button.global_y=g.y;
- _change_notify();
-}
-#endif
+ } break;
+ case InputEvent::MOUSE_MOTION: {
+
+ Vector2 g = local_matrix.xform(Vector2(ev.mouse_motion.global_x,ev.mouse_motion.global_y));
+ Vector2 l = local_matrix.xform(Vector2(ev.mouse_motion.x,ev.mouse_motion.y));
+ Vector2 r = local_matrix.basis_xform(Vector2(ev.mouse_motion.relative_x,ev.mouse_motion.relative_y));
+ Vector2 s = local_matrix.basis_xform(Vector2(ev.mouse_motion.speed_x,ev.mouse_motion.speed_y));
+ ev.mouse_motion.x=l.x;
+ ev.mouse_motion.y=l.y;
+ ev.mouse_motion.global_x=g.x;
+ ev.mouse_motion.global_y=g.y;
+ ev.mouse_motion.relative_x=r.x;
+ ev.mouse_motion.relative_y=r.y;
+ ev.mouse_motion.speed_x=s.x;
+ ev.mouse_motion.speed_y=s.y;
-void CanvasItem::get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const {
+ } break;
+ case InputEvent::SCREEN_TOUCH: {
- if (p_idx==0 && shader.is_valid() && (p_function.operator String()=="get_shader_param" || p_function.operator String()=="set_shader_param")) {
- List<PropertyInfo> pl;
- shader->get_param_list(&pl);
- for(List<PropertyInfo>::Element *E=pl.front();E;E=E->next()) {
- r_options->push_back("\""+E->get().name.replace_first("shader_param/","")+"\"");
- }
+ Vector2 t = local_matrix.xform(Vector2(ev.screen_touch.x,ev.screen_touch.y));
+ ev.screen_touch.x=t.x;
+ ev.screen_touch.y=t.y;
- return;
+ } break;
+ case InputEvent::SCREEN_DRAG: {
+
+
+ Vector2 t = local_matrix.xform(Vector2(ev.screen_drag.x,ev.screen_drag.y));
+ Vector2 r = local_matrix.basis_xform(Vector2(ev.screen_drag.relative_x,ev.screen_drag.relative_y));
+ Vector2 s = local_matrix.basis_xform(Vector2(ev.screen_drag.speed_x,ev.screen_drag.speed_y));
+ ev.screen_drag.x=t.x;
+ ev.screen_drag.y=t.y;
+ ev.screen_drag.relative_x=r.x;
+ ev.screen_drag.relative_y=r.y;
+ ev.screen_drag.speed_x=s.x;
+ ev.screen_drag.speed_y=s.y;
+ } break;
}
- Node::get_argument_options(p_function,p_idx,r_options);
+ return ev;
}
@@ -880,9 +1049,6 @@ void CanvasItem::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_set_on_top","on_top"),&CanvasItem::_set_on_top);
ObjectTypeDB::bind_method(_MD("_is_on_top"),&CanvasItem::_is_on_top);
-#ifdef TOOLS_ENABLED
- ObjectTypeDB::bind_method(_MD("_shader_changed"),&CanvasItem::_shader_changed);
-#endif
//ObjectTypeDB::bind_method(_MD("get_transform"),&CanvasItem::get_transform);
ObjectTypeDB::bind_method(_MD("draw_line","from","to","color","width"),&CanvasItem::draw_line,DEFVAL(1.0));
@@ -901,20 +1067,21 @@ void CanvasItem::_bind_methods() {
ObjectTypeDB::bind_method(_MD("draw_set_transform","pos","rot","scale"),&CanvasItem::draw_set_transform);
ObjectTypeDB::bind_method(_MD("get_transform"),&CanvasItem::get_transform);
ObjectTypeDB::bind_method(_MD("get_global_transform"),&CanvasItem::get_global_transform);
+ ObjectTypeDB::bind_method(_MD("get_global_transform_with_canvas"),&CanvasItem::get_global_transform_with_canvas);
ObjectTypeDB::bind_method(_MD("get_viewport_transform"),&CanvasItem::get_viewport_transform);
ObjectTypeDB::bind_method(_MD("get_viewport_rect"),&CanvasItem::get_viewport_rect);
+ ObjectTypeDB::bind_method(_MD("get_canvas_transform"),&CanvasItem::get_canvas_transform);
ObjectTypeDB::bind_method(_MD("get_canvas"),&CanvasItem::get_canvas);
ObjectTypeDB::bind_method(_MD("get_world_2d"),&CanvasItem::get_world_2d);
//ObjectTypeDB::bind_method(_MD("get_viewport"),&CanvasItem::get_viewport);
- ObjectTypeDB::bind_method(_MD("set_shader","shader"),&CanvasItem::set_shader);
- ObjectTypeDB::bind_method(_MD("get_shader"),&CanvasItem::get_shader);
- ObjectTypeDB::bind_method(_MD("set_use_parent_shader","enable"),&CanvasItem::set_use_parent_shader);
- ObjectTypeDB::bind_method(_MD("get_use_parent_shader"),&CanvasItem::get_use_parent_shader);
+ ObjectTypeDB::bind_method(_MD("set_material","material:CanvasItemMaterial"),&CanvasItem::set_material);
+ ObjectTypeDB::bind_method(_MD("get_material:CanvasItemMaterial"),&CanvasItem::get_material);
- ObjectTypeDB::bind_method(_MD("set_shader_param","param","value"),&CanvasItem::set_shader_param);
- ObjectTypeDB::bind_method(_MD("get_shader_param","param"),&CanvasItem::get_shader_param);
+ ObjectTypeDB::bind_method(_MD("set_use_parent_material","enable"),&CanvasItem::set_use_parent_material);
+ ObjectTypeDB::bind_method(_MD("get_use_parent_material"),&CanvasItem::get_use_parent_material);
+ ObjectTypeDB::bind_method(_MD("make_input_local","event"),&CanvasItem::make_input_local);
BIND_VMETHOD(MethodInfo("_draw"));
@@ -926,8 +1093,8 @@ void CanvasItem::_bind_methods() {
ADD_PROPERTYNZ( PropertyInfo(Variant::INT,"visibility/blend_mode",PROPERTY_HINT_ENUM, "Mix,Add,Sub,Mul,PMAlpha"), _SCS("set_blend_mode"),_SCS("get_blend_mode") );
ADD_PROPERTYNZ( PropertyInfo(Variant::INT,"visibility/light_mask",PROPERTY_HINT_ALL_FLAGS), _SCS("set_light_mask"),_SCS("get_light_mask") );
- ADD_PROPERTYNZ( PropertyInfo(Variant::OBJECT,"shader/shader",PROPERTY_HINT_RESOURCE_TYPE, "CanvasItemShader,CanvasItemShaderGraph"), _SCS("set_shader"),_SCS("get_shader") );
- ADD_PROPERTYNZ( PropertyInfo(Variant::BOOL,"shader/use_parent"), _SCS("set_use_parent_shader"),_SCS("get_use_parent_shader") );
+ ADD_PROPERTYNZ( PropertyInfo(Variant::OBJECT,"material/material",PROPERTY_HINT_RESOURCE_TYPE, "CanvasItemMaterial"), _SCS("set_material"),_SCS("get_material") );
+ ADD_PROPERTYNZ( PropertyInfo(Variant::BOOL,"material/use_parent"), _SCS("set_use_parent_material"),_SCS("get_use_parent_material") );
//exporting these two things doesn't really make much sense i think
//ADD_PROPERTY( PropertyInfo(Variant::BOOL,"transform/toplevel"), _SCS("set_as_toplevel"),_SCS("is_set_as_toplevel") );
//ADD_PROPERTY(PropertyInfo(Variant::BOOL,"transform/notify"),_SCS("set_transform_notify"),_SCS("is_transform_notify_enabled"));
@@ -1004,7 +1171,7 @@ CanvasItem::CanvasItem() : xform_change(this) {
block_transform_notify=false;
// viewport=NULL;
canvas_layer=NULL;
- use_parent_shader=false;
+ use_parent_material=false;
global_invalid=true;
light_mask=1;
diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h
index cccb63fe4c..c43642a8ec 100644
--- a/scene/2d/canvas_item.h
+++ b/scene/2d/canvas_item.h
@@ -40,6 +40,41 @@ class Font;
class StyleBox;
+class CanvasItemMaterial : public Resource{
+
+ OBJ_TYPE(CanvasItemMaterial,Resource);
+ RID material;
+ Ref<Shader> shader;
+ bool unshaded;
+
+protected:
+
+ bool _set(const StringName& p_name, const Variant& p_value);
+ bool _get(const StringName& p_name,Variant &r_ret) const;
+ void _get_property_list( List<PropertyInfo> *p_list) const;
+
+ void _shader_changed();
+ static void _bind_methods();
+
+ void get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const;
+
+public:
+
+ void set_shader(const Ref<Shader>& p_shader);
+ Ref<Shader> get_shader() const;
+
+ void set_shader_param(const StringName& p_param,const Variant& p_value);
+ Variant get_shader_param(const StringName& p_param) const;
+
+ void set_unshaded(bool p_unshaded);
+ bool is_unshaded() const;
+
+ virtual RID get_rid() const;
+ CanvasItemMaterial();
+ ~CanvasItemMaterial();
+};
+
+
class CanvasItem : public Node {
OBJ_TYPE( CanvasItem, Node );
@@ -81,9 +116,9 @@ private:
bool drawing;
bool block_transform_notify;
bool behind;
- bool use_parent_shader;
+ bool use_parent_material;
- Ref<Shader> shader;
+ Ref<CanvasItemMaterial> material;
mutable Matrix32 global_transform;
mutable bool global_invalid;
@@ -104,9 +139,6 @@ private:
void _queue_sort_children();
void _sort_children();
-#ifdef TOOLS_ENABLED
- void _shader_changed();
-#endif
void _notify_transform(CanvasItem *p_node);
void _set_on_top(bool p_on_top) { set_draw_behind_parent(!p_on_top); }
@@ -114,11 +146,6 @@ private:
protected:
- bool _set(const StringName& p_name, const Variant& p_value);
- bool _get(const StringName& p_name,Variant &r_ret) const;
- void _get_property_list( List<PropertyInfo> *p_list) const;
-
-
_FORCE_INLINE_ void _notify_transform() { if (!is_inside_tree()) return; _notify_transform(this); if (!block_transform_notify) notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED); }
void item_rect_changed();
@@ -174,8 +201,8 @@ public:
void draw_rect(const Rect2& p_rect, const Color& p_color);
void draw_circle(const Point2& p_pos, float p_radius, const Color& p_color);
void draw_texture(const Ref<Texture>& p_texture,const Point2& p_pos);
- void draw_texture_rect(const Ref<Texture>& p_texture, const Rect2& p_rect, bool p_tile=false,const Color& p_modulate=Color(1,1,1));
- void draw_texture_rect_region(const Ref<Texture>& p_texture,const Rect2& p_rect, const Rect2& p_src_rect,const Color& p_modulate=Color(1,1,1));
+ void draw_texture_rect(const Ref<Texture>& p_texture, const Rect2& p_rect, bool p_tile=false,const Color& p_modulate=Color(1,1,1), bool p_transpose=false);
+ void draw_texture_rect_region(const Ref<Texture>& p_texture,const Rect2& p_rect, const Rect2& p_src_rect,const Color& p_modulate=Color(1,1,1), bool p_transpose=false);
void draw_style_box(const Ref<StyleBox>& p_style_box,const Rect2& p_rect);
void draw_primitive(const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs, Ref<Texture> p_texture=Ref<Texture>(),float p_width=1);
void draw_polygon(const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs=Vector<Point2>(), Ref<Texture> p_texture=Ref<Texture>());
@@ -216,16 +243,13 @@ public:
RID get_canvas() const;
Ref<World2D> get_world_2d() const;
- void set_shader(const Ref<Shader>& p_shader);
- Ref<Shader> get_shader() const;
+ void set_material(const Ref<CanvasItemMaterial>& p_material);
+ Ref<CanvasItemMaterial> get_material() const;
- void set_use_parent_shader(bool p_use_parent_shader);
- bool get_use_parent_shader() const;
+ void set_use_parent_material(bool p_use_parent_material);
+ bool get_use_parent_material() const;
- void set_shader_param(const StringName& p_param,const Variant& p_value);
- Variant get_shader_param(const StringName& p_param) const;
-
- void get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const;
+ InputEvent make_input_local(const InputEvent& pevent) const;
CanvasItem();
~CanvasItem();
diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp
index 3b859d9366..a883fee103 100644
--- a/scene/2d/collision_object_2d.cpp
+++ b/scene/2d/collision_object_2d.cpp
@@ -28,6 +28,7 @@
/*************************************************************************/
#include "collision_object_2d.h"
#include "servers/physics_2d_server.h"
+#include "scene/scene_string_names.h"
void CollisionObject2D::_update_shapes_from_children() {
@@ -58,9 +59,15 @@ void CollisionObject2D::_notification(int p_what) {
} else
Physics2DServer::get_singleton()->body_set_space(rid,space);
+ _update_pickable();
+
//get space
}
+ case NOTIFICATION_VISIBILITY_CHANGED: {
+
+ _update_pickable();
+ } break;
case NOTIFICATION_TRANSFORM_CHANGED: {
if (area)
@@ -166,6 +173,57 @@ void CollisionObject2D::_get_property_list( List<PropertyInfo> *p_list) const {
}
}
+
+void CollisionObject2D::set_pickable(bool p_enabled) {
+
+ if (pickable==p_enabled)
+ return;
+
+ pickable=p_enabled;
+ _update_pickable();
+}
+
+bool CollisionObject2D::is_pickable() const {
+
+ return pickable;
+}
+
+void CollisionObject2D::_input_event(Node *p_viewport, const InputEvent& p_input_event, int p_shape) {
+
+ if (get_script_instance()) {
+ get_script_instance()->call(SceneStringNames::get_singleton()->_input_event,p_viewport,p_input_event,p_shape);
+ }
+ emit_signal(SceneStringNames::get_singleton()->input_event,p_viewport,p_input_event,p_shape);
+}
+
+void CollisionObject2D::_mouse_enter() {
+
+ if (get_script_instance()) {
+ get_script_instance()->call(SceneStringNames::get_singleton()->_mouse_enter);
+ }
+ emit_signal(SceneStringNames::get_singleton()->mouse_enter);
+}
+
+
+void CollisionObject2D::_mouse_exit() {
+
+ if (get_script_instance()) {
+ get_script_instance()->call(SceneStringNames::get_singleton()->_mouse_exit);
+ }
+ emit_signal(SceneStringNames::get_singleton()->mouse_exit);
+
+}
+
+void CollisionObject2D::_update_pickable() {
+ if (!is_inside_tree())
+ return;
+ bool pickable = this->pickable && is_inside_tree() && is_visible();
+ if (area)
+ Physics2DServer::get_singleton()->area_set_pickable(rid,pickable);
+ else
+ Physics2DServer::get_singleton()->body_set_pickable(rid,pickable);
+}
+
void CollisionObject2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("add_shape","shape:Shape2D","transform"),&CollisionObject2D::add_shape,DEFVAL(Matrix32()));
@@ -180,6 +238,17 @@ void CollisionObject2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("clear_shapes"),&CollisionObject2D::clear_shapes);
ObjectTypeDB::bind_method(_MD("get_rid"),&CollisionObject2D::get_rid);
+ ObjectTypeDB::bind_method(_MD("set_pickable","enabled"),&CollisionObject2D::set_pickable);
+ ObjectTypeDB::bind_method(_MD("is_pickable"),&CollisionObject2D::is_pickable);
+
+ BIND_VMETHOD( MethodInfo("_input_event",PropertyInfo(Variant::OBJECT,"viewport"),PropertyInfo(Variant::INPUT_EVENT,"event"),PropertyInfo(Variant::INT,"shape_idx")));
+
+ ADD_SIGNAL( MethodInfo("input_event",PropertyInfo(Variant::OBJECT,"viewport"),PropertyInfo(Variant::INPUT_EVENT,"event"),PropertyInfo(Variant::INT,"shape_idx")));
+ ADD_SIGNAL( MethodInfo("mouse_enter"));
+ ADD_SIGNAL( MethodInfo("mouse_exit"));
+
+ ADD_PROPERTY( PropertyInfo(Variant::BOOL,"input/pickable"),_SCS("set_pickable"),_SCS("is_pickable"));
+
}
@@ -262,7 +331,9 @@ CollisionObject2D::CollisionObject2D(RID p_rid, bool p_area) {
rid=p_rid;
area=p_area;
+ pickable=true;
if (p_area) {
+
Physics2DServer::get_singleton()->area_attach_object_instance_ID(rid,get_instance_ID());
} else {
Physics2DServer::get_singleton()->body_attach_object_instance_ID(rid,get_instance_ID());
diff --git a/scene/2d/collision_object_2d.h b/scene/2d/collision_object_2d.h
index 4a529ce062..393973ce90 100644
--- a/scene/2d/collision_object_2d.h
+++ b/scene/2d/collision_object_2d.h
@@ -38,6 +38,7 @@ class CollisionObject2D : public Node2D {
bool area;
RID rid;
+ bool pickable;
struct ShapeData {
Matrix32 xform;
@@ -66,9 +67,17 @@ protected:
bool _get(const StringName& p_name,Variant &r_ret) const;
void _get_property_list( List<PropertyInfo> *p_list) const;
static void _bind_methods();
+
+ void _update_pickable();
+friend class Viewport;
+ void _input_event(Node *p_viewport, const InputEvent& p_input_event, int p_shape);
+ void _mouse_enter();
+ void _mouse_exit();
+
public:
+
void add_shape(const Ref<Shape2D>& p_shape, const Matrix32& p_transform=Matrix32());
int get_shape_count() const;
void set_shape(int p_shape_idx, const Ref<Shape2D>& p_shape);
@@ -80,6 +89,9 @@ public:
void remove_shape(int p_shape_idx);
void clear_shapes();
+ void set_pickable(bool p_enabled);
+ bool is_pickable() const;
+
_FORCE_INLINE_ RID get_rid() const { return rid; }
CollisionObject2D();
diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp
index cea8c06d3f..4abb7e5436 100644
--- a/scene/2d/light_2d.cpp
+++ b/scene/2d/light_2d.cpp
@@ -23,7 +23,7 @@ Rect2 Light2D::get_item_rect() const {
Size2i s;
- s = texture->get_size();
+ s = texture->get_size()*_scale;
Point2i ofs=texture_offset;
ofs-=s/2;
@@ -63,6 +63,8 @@ void Light2D::set_texture_offset( const Vector2& p_offset) {
texture_offset=p_offset;
VS::get_singleton()->canvas_light_set_texture_offset(canvas_light,texture_offset);
+ item_rect_changed();
+
}
Vector2 Light2D::get_texture_offset() const {
@@ -87,11 +89,27 @@ void Light2D::set_height( float p_height) {
VS::get_singleton()->canvas_light_set_height(canvas_light,height);
}
+
+
float Light2D::get_height() const {
return height;
}
+void Light2D::set_texture_scale( float p_scale) {
+
+ _scale=p_scale;
+ VS::get_singleton()->canvas_light_set_scale(canvas_light,_scale);
+ item_rect_changed();
+
+}
+
+
+float Light2D::get_texture_scale() const {
+
+ return _scale;
+}
+
void Light2D::set_z_range_min( int p_min_z) {
z_min=p_min_z;
@@ -148,6 +166,18 @@ int Light2D::get_item_mask() const {
return item_mask;
}
+void Light2D::set_item_shadow_mask( int p_mask) {
+
+ item_shadow_mask=p_mask;
+ VS::get_singleton()->canvas_light_set_item_shadow_mask(canvas_light,item_shadow_mask);
+
+}
+
+int Light2D::get_item_shadow_mask() const {
+
+ return item_shadow_mask;
+}
+
void Light2D::set_subtract_mode( bool p_enable ) {
subtract_mode=p_enable;
@@ -170,6 +200,29 @@ bool Light2D::is_shadow_enabled() const {
return shadow;
}
+void Light2D::set_shadow_buffer_size( int p_size ) {
+
+ shadow_buffer_size=p_size;
+ VS::get_singleton()->canvas_light_set_shadow_buffer_size(canvas_light,shadow_buffer_size);
+}
+
+int Light2D::get_shadow_buffer_size() const {
+
+ return shadow_buffer_size;
+}
+
+void Light2D::set_shadow_esm_multiplier( float p_multiplier) {
+
+ shadow_esm_multiplier=p_multiplier;
+ VS::get_singleton()->canvas_light_set_shadow_esm_multiplier(canvas_light,p_multiplier);
+}
+
+float Light2D::get_shadow_esm_multiplier() const{
+
+ return shadow_esm_multiplier;
+}
+
+
void Light2D::_notification(int p_what) {
if (p_what==NOTIFICATION_ENTER_TREE) {
@@ -207,6 +260,10 @@ void Light2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_height","height"),&Light2D::set_height);
ObjectTypeDB::bind_method(_MD("get_height"),&Light2D::get_height);
+ ObjectTypeDB::bind_method(_MD("set_texture_scale","texture_scale"),&Light2D::set_texture_scale);
+ ObjectTypeDB::bind_method(_MD("get_texture_scale"),&Light2D::get_texture_scale);
+
+
ObjectTypeDB::bind_method(_MD("set_z_range_min","z"),&Light2D::set_z_range_min);
ObjectTypeDB::bind_method(_MD("get_z_range_min"),&Light2D::get_z_range_min);
@@ -223,24 +280,37 @@ void Light2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_item_mask","item_mask"),&Light2D::set_item_mask);
ObjectTypeDB::bind_method(_MD("get_item_mask"),&Light2D::get_item_mask);
+ ObjectTypeDB::bind_method(_MD("set_item_shadow_mask","item_shadow_mask"),&Light2D::set_item_shadow_mask);
+ ObjectTypeDB::bind_method(_MD("get_item_shadow_mask"),&Light2D::get_item_shadow_mask);
+
ObjectTypeDB::bind_method(_MD("set_subtract_mode","enable"),&Light2D::set_subtract_mode);
ObjectTypeDB::bind_method(_MD("get_subtract_mode"),&Light2D::get_subtract_mode);
ObjectTypeDB::bind_method(_MD("set_shadow_enabled","enabled"),&Light2D::set_shadow_enabled);
ObjectTypeDB::bind_method(_MD("is_shadow_enabled"),&Light2D::is_shadow_enabled);
+ ObjectTypeDB::bind_method(_MD("set_shadow_buffer_size","size"),&Light2D::set_shadow_buffer_size);
+ ObjectTypeDB::bind_method(_MD("get_shadow_buffer_size"),&Light2D::get_shadow_buffer_size);
+
+ ObjectTypeDB::bind_method(_MD("set_shadow_esm_multiplier","multiplier"),&Light2D::set_shadow_esm_multiplier);
+ ObjectTypeDB::bind_method(_MD("get_shadow_esm_multiplier"),&Light2D::get_shadow_esm_multiplier);
+
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"enabled"),_SCS("set_enabled"),_SCS("is_enabled"));
ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"texture",PROPERTY_HINT_RESOURCE_TYPE,"Texture"),_SCS("set_texture"),_SCS("get_texture"));
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"texture_offset"),_SCS("set_texture_offset"),_SCS("get_texture_offset"));
+ ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"offset"),_SCS("set_texture_offset"),_SCS("get_texture_offset"));
+ ADD_PROPERTY( PropertyInfo(Variant::REAL,"scale",PROPERTY_HINT_RANGE,"0.01,4096,0.01"),_SCS("set_texture_scale"),_SCS("get_texture_scale"));
ADD_PROPERTY( PropertyInfo(Variant::COLOR,"color"),_SCS("set_color"),_SCS("get_color"));
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"height"),_SCS("set_height"),_SCS("get_height"));
- ADD_PROPERTY( PropertyInfo(Variant::INT,"z_range_min",PROPERTY_HINT_RANGE,itos(VS::CANVAS_ITEM_Z_MIN)+","+itos(VS::CANVAS_ITEM_Z_MAX)+",1"),_SCS("set_z_range_min"),_SCS("get_z_range_min"));
- ADD_PROPERTY( PropertyInfo(Variant::INT,"z_range_max",PROPERTY_HINT_RANGE,itos(VS::CANVAS_ITEM_Z_MIN)+","+itos(VS::CANVAS_ITEM_Z_MAX)+",1"),_SCS("set_z_range_max"),_SCS("get_z_range_max"));
- ADD_PROPERTY( PropertyInfo(Variant::INT,"layer_range_min",PROPERTY_HINT_RANGE,"-512,512,1"),_SCS("set_layer_range_min"),_SCS("get_layer_range_min"));
- ADD_PROPERTY( PropertyInfo(Variant::INT,"layer_range_max",PROPERTY_HINT_RANGE,"-512,512,1"),_SCS("set_layer_range_max"),_SCS("get_layer_range_max"));
- ADD_PROPERTY( PropertyInfo(Variant::INT,"item_mask",PROPERTY_HINT_ALL_FLAGS),_SCS("set_item_mask"),_SCS("get_item_mask"));
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"subtract"),_SCS("set_subtract_mode"),_SCS("get_subtract_mode"));
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"shadow_enabled"),_SCS("set_shadow_enabled"),_SCS("is_shadow_enabled"));
+ ADD_PROPERTY( PropertyInfo(Variant::REAL,"range/height"),_SCS("set_height"),_SCS("get_height"));
+ ADD_PROPERTY( PropertyInfo(Variant::INT,"range/z_min",PROPERTY_HINT_RANGE,itos(VS::CANVAS_ITEM_Z_MIN)+","+itos(VS::CANVAS_ITEM_Z_MAX)+",1"),_SCS("set_z_range_min"),_SCS("get_z_range_min"));
+ ADD_PROPERTY( PropertyInfo(Variant::INT,"range/z_max",PROPERTY_HINT_RANGE,itos(VS::CANVAS_ITEM_Z_MIN)+","+itos(VS::CANVAS_ITEM_Z_MAX)+",1"),_SCS("set_z_range_max"),_SCS("get_z_range_max"));
+ ADD_PROPERTY( PropertyInfo(Variant::INT,"range/layer_min",PROPERTY_HINT_RANGE,"-512,512,1"),_SCS("set_layer_range_min"),_SCS("get_layer_range_min"));
+ ADD_PROPERTY( PropertyInfo(Variant::INT,"range/layer_max",PROPERTY_HINT_RANGE,"-512,512,1"),_SCS("set_layer_range_max"),_SCS("get_layer_range_max"));
+ ADD_PROPERTY( PropertyInfo(Variant::INT,"range/item_mask",PROPERTY_HINT_ALL_FLAGS),_SCS("set_item_mask"),_SCS("get_item_mask"));
+ ADD_PROPERTY( PropertyInfo(Variant::BOOL,"shadow/enabled"),_SCS("set_shadow_enabled"),_SCS("is_shadow_enabled"));
+ ADD_PROPERTY( PropertyInfo(Variant::INT,"shadow/buffer_size",PROPERTY_HINT_RANGE,"32,16384,1"),_SCS("set_shadow_buffer_size"),_SCS("get_shadow_buffer_size"));
+ ADD_PROPERTY( PropertyInfo(Variant::REAL,"shadow/esm_multiplier",PROPERTY_HINT_RANGE,"1,4096,0.1"),_SCS("set_shadow_esm_multiplier"),_SCS("get_shadow_esm_multiplier"));
+ ADD_PROPERTY( PropertyInfo(Variant::INT,"shadow/item_mask",PROPERTY_HINT_ALL_FLAGS),_SCS("set_item_shadow_mask"),_SCS("get_item_shadow_mask"));
}
@@ -252,12 +322,16 @@ Light2D::Light2D() {
shadow=false;
color=Color(1,1,1);
height=0;
+ _scale=1.0;
z_min=-1024;
z_max=1024;
layer_min=0;
layer_max=0;
item_mask=1;
+ item_shadow_mask=1;
subtract_mode=false;
+ shadow_buffer_size=2048;
+ shadow_esm_multiplier=80;
}
diff --git a/scene/2d/light_2d.h b/scene/2d/light_2d.h
index dbfd233d39..6cfb055fa9 100644
--- a/scene/2d/light_2d.h
+++ b/scene/2d/light_2d.h
@@ -12,11 +12,15 @@ private:
bool shadow;
Color color;
float height;
+ float _scale;
int z_min;
int z_max;
int layer_min;
int layer_max;
int item_mask;
+ int item_shadow_mask;
+ int shadow_buffer_size;
+ float shadow_esm_multiplier;
bool subtract_mode;
Ref<Texture> texture;
Vector2 texture_offset;
@@ -47,6 +51,9 @@ public:
void set_height( float p_height);
float get_height() const;
+ void set_texture_scale( float p_scale);
+ float get_texture_scale() const;
+
void set_z_range_min( int p_min_z);
int get_z_range_min() const;
@@ -62,12 +69,21 @@ public:
void set_item_mask( int p_mask);
int get_item_mask() const;
+ void set_item_shadow_mask( int p_mask);
+ int get_item_shadow_mask() const;
+
void set_subtract_mode( bool p_enable );
bool get_subtract_mode() const;
void set_shadow_enabled( bool p_enabled);
bool is_shadow_enabled() const;
+ void set_shadow_buffer_size( int p_size );
+ int get_shadow_buffer_size() const;
+
+ void set_shadow_esm_multiplier( float p_multiplier);
+ float get_shadow_esm_multiplier() const;
+
virtual Rect2 get_item_rect() const;
Light2D();
diff --git a/scene/2d/light_occluder_2d.cpp b/scene/2d/light_occluder_2d.cpp
new file mode 100644
index 0000000000..6ebd499f71
--- /dev/null
+++ b/scene/2d/light_occluder_2d.cpp
@@ -0,0 +1,202 @@
+#include "light_occluder_2d.h"
+
+
+void OccluderPolygon2D::set_polygon(const DVector<Vector2>& p_polygon) {
+
+ polygon=p_polygon;
+ VS::get_singleton()->canvas_occluder_polygon_set_shape(occ_polygon,p_polygon,closed);
+ emit_changed();
+}
+
+DVector<Vector2> OccluderPolygon2D::get_polygon() const{
+
+ return polygon;
+}
+
+void OccluderPolygon2D::set_closed(bool p_closed) {
+
+ if (closed==p_closed)
+ return;
+ closed=p_closed;
+ if (polygon.size())
+ VS::get_singleton()->canvas_occluder_polygon_set_shape(occ_polygon,polygon,closed);
+ emit_changed();
+}
+
+bool OccluderPolygon2D::is_closed() const{
+
+ return closed;
+}
+
+void OccluderPolygon2D::set_cull_mode(CullMode p_mode){
+
+ cull=p_mode;
+ VS::get_singleton()->canvas_occluder_polygon_set_cull_mode(occ_polygon,VS::CanvasOccluderPolygonCullMode(p_mode));
+}
+
+OccluderPolygon2D::CullMode OccluderPolygon2D::get_cull_mode() const{
+
+ return cull;
+}
+
+
+RID OccluderPolygon2D::get_rid() const {
+
+ return occ_polygon;
+}
+
+void OccluderPolygon2D::_bind_methods() {
+
+
+ ObjectTypeDB::bind_method(_MD("set_closed","closed"),&OccluderPolygon2D::set_closed);
+ ObjectTypeDB::bind_method(_MD("is_closed"),&OccluderPolygon2D::is_closed);
+
+ ObjectTypeDB::bind_method(_MD("set_cull_mode","cull_mode"),&OccluderPolygon2D::set_cull_mode);
+ ObjectTypeDB::bind_method(_MD("get_cull_mode"),&OccluderPolygon2D::get_cull_mode);
+
+ ObjectTypeDB::bind_method(_MD("set_polygon","polygon"),&OccluderPolygon2D::set_polygon);
+ ObjectTypeDB::bind_method(_MD("get_polygon"),&OccluderPolygon2D::get_polygon);
+
+ ADD_PROPERTY( PropertyInfo(Variant::BOOL,"closed"),_SCS("set_closed"),_SCS("is_closed"));
+ ADD_PROPERTY( PropertyInfo(Variant::INT,"cull_mode",PROPERTY_HINT_ENUM,"Disabled,ClockWise,CounterClockWise"),_SCS("set_cull_mode"),_SCS("get_cull_mode"));
+ ADD_PROPERTY( PropertyInfo(Variant::VECTOR2_ARRAY,"polygon"),_SCS("set_polygon"),_SCS("get_polygon"));
+
+ BIND_CONSTANT(CULL_DISABLED);
+ BIND_CONSTANT(CULL_CLOCKWISE);
+ BIND_CONSTANT(CULL_COUNTER_CLOCKWISE);
+}
+
+
+OccluderPolygon2D::OccluderPolygon2D() {
+
+ occ_polygon=VS::get_singleton()->canvas_occluder_polygon_create();
+ closed=true;
+ cull=CULL_DISABLED;
+}
+
+OccluderPolygon2D::~OccluderPolygon2D() {
+
+ VS::get_singleton()->free(occ_polygon);
+}
+
+#ifdef DEBUG_ENABLED
+void LightOccluder2D::_poly_changed() {
+
+ update();
+}
+#endif
+
+
+void LightOccluder2D::_notification(int p_what) {
+
+ if (p_what==NOTIFICATION_ENTER_CANVAS) {
+
+ VS::get_singleton()->canvas_light_occluder_attach_to_canvas(occluder,get_canvas());
+ VS::get_singleton()->canvas_light_occluder_set_transform(occluder,get_global_transform());
+
+ }
+ if (p_what==NOTIFICATION_TRANSFORM_CHANGED) {
+
+ VS::get_singleton()->canvas_light_occluder_set_transform(occluder,get_global_transform());
+ }
+
+ if (p_what==NOTIFICATION_DRAW) {
+
+ if (get_tree()->is_editor_hint()) {
+
+ if (occluder_polygon.is_valid()) {
+
+ DVector<Vector2> poly = occluder_polygon->get_polygon();
+
+ if (poly.size()) {
+ if (occluder_polygon->is_closed()) {
+ Vector<Color> color;
+ color.push_back(Color(0,0,0,0.6));
+ draw_polygon(Variant(poly),color);
+ } else {
+
+ int ps=poly.size();
+ DVector<Vector2>::Read r = poly.read();
+ for(int i=0;i<ps-1;i++) {
+
+ draw_line(r[i],r[i+1],Color(0,0,0,0.6),3);
+ }
+ }
+ }
+ }
+ }
+ }
+
+
+ if (p_what==NOTIFICATION_EXIT_CANVAS) {
+
+ VS::get_singleton()->canvas_light_occluder_attach_to_canvas(occluder,RID());
+ }
+
+
+}
+
+void LightOccluder2D::set_occluder_polygon(const Ref<OccluderPolygon2D>& p_polygon) {
+
+#ifdef DEBUG_ENABLED
+ if (occluder_polygon.is_valid())
+ occluder_polygon->disconnect("changed",this,"_poly_changed");
+#endif
+ occluder_polygon=p_polygon;
+
+ if (occluder_polygon.is_valid())
+ VS::get_singleton()->canvas_light_occluder_set_polygon(occluder,occluder_polygon->get_rid());
+ else
+ VS::get_singleton()->canvas_light_occluder_set_polygon(occluder,RID());
+
+#ifdef DEBUG_ENABLED
+ if (occluder_polygon.is_valid())
+ occluder_polygon->connect("changed",this,"_poly_changed");
+ update();
+#endif
+
+}
+
+Ref<OccluderPolygon2D> LightOccluder2D::get_occluder_polygon() const {
+
+ return occluder_polygon;
+}
+
+void LightOccluder2D::set_occluder_light_mask(int p_mask) {
+
+ mask=p_mask;
+ VS::get_singleton()->canvas_light_occluder_set_light_mask(occluder,mask);
+}
+
+int LightOccluder2D::get_occluder_light_mask() const{
+
+ return mask;
+}
+
+void LightOccluder2D::_bind_methods() {
+
+ ObjectTypeDB::bind_method(_MD("set_occluder_polygon","polygon:OccluderPolygon2D"),&LightOccluder2D::set_occluder_polygon);
+ ObjectTypeDB::bind_method(_MD("get_occluder_polygon:OccluderPolygon2D"),&LightOccluder2D::get_occluder_polygon);
+
+ ObjectTypeDB::bind_method(_MD("set_occluder_light_mask","mask"),&LightOccluder2D::set_occluder_light_mask);
+ ObjectTypeDB::bind_method(_MD("get_occluder_light_mask"),&LightOccluder2D::get_occluder_light_mask);
+
+#ifdef DEBUG_ENABLED
+ ObjectTypeDB::bind_method("_poly_changed",&LightOccluder2D::_poly_changed);
+#endif
+
+ ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"occluder",PROPERTY_HINT_RESOURCE_TYPE,"OccluderPolygon2D"),_SCS("set_occluder_polygon"),_SCS("get_occluder_polygon"));
+ ADD_PROPERTY( PropertyInfo(Variant::INT,"light_mask",PROPERTY_HINT_ALL_FLAGS),_SCS("set_occluder_light_mask"),_SCS("get_occluder_light_mask"));
+}
+
+LightOccluder2D::LightOccluder2D() {
+
+ occluder=VS::get_singleton()->canvas_light_occluder_create();
+ mask=1;
+}
+
+LightOccluder2D::~LightOccluder2D() {
+
+ VS::get_singleton()->free(occluder);
+}
+
diff --git a/scene/2d/light_occluder_2d.h b/scene/2d/light_occluder_2d.h
new file mode 100644
index 0000000000..0343e3697e
--- /dev/null
+++ b/scene/2d/light_occluder_2d.h
@@ -0,0 +1,73 @@
+#ifndef LIGHTOCCLUDER2D_H
+#define LIGHTOCCLUDER2D_H
+
+#include "scene/2d/node_2d.h"
+
+class OccluderPolygon2D : public Resource {
+
+ OBJ_TYPE(OccluderPolygon2D,Resource);
+public:
+
+ enum CullMode {
+ CULL_DISABLED,
+ CULL_CLOCKWISE,
+ CULL_COUNTER_CLOCKWISE
+ };
+private:
+
+
+ RID occ_polygon;
+ DVector<Vector2> polygon;
+ bool closed;
+ CullMode cull;
+
+protected:
+
+ static void _bind_methods();
+public:
+
+ void set_polygon(const DVector<Vector2>& p_polygon);
+ DVector<Vector2> get_polygon() const;
+
+ void set_closed(bool p_closed);
+ bool is_closed() const;
+
+ void set_cull_mode(CullMode p_mode);
+ CullMode get_cull_mode() const;
+
+ virtual RID get_rid() const;
+ OccluderPolygon2D();
+ ~OccluderPolygon2D();
+
+};
+
+VARIANT_ENUM_CAST(OccluderPolygon2D::CullMode);
+
+class LightOccluder2D : public Node2D {
+ OBJ_TYPE(LightOccluder2D,Node2D);
+
+ RID occluder;
+ bool enabled;
+ int mask;
+ Ref<OccluderPolygon2D> occluder_polygon;
+
+#ifdef DEBUG_ENABLED
+ void _poly_changed();
+#endif
+
+protected:
+ void _notification(int p_what);
+ static void _bind_methods();
+public:
+
+ void set_occluder_polygon(const Ref<OccluderPolygon2D>& p_polygon);
+ Ref<OccluderPolygon2D> get_occluder_polygon() const;
+
+ void set_occluder_light_mask(int p_mask);
+ int get_occluder_light_mask() const;
+
+ LightOccluder2D();
+ ~LightOccluder2D();
+};
+
+#endif // LIGHTOCCLUDER2D_H
diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp
index 36b6b220b3..0b098f0cad 100644
--- a/scene/2d/node_2d.cpp
+++ b/scene/2d/node_2d.cpp
@@ -65,7 +65,7 @@ void Node2D::edit_set_state(const Variant& p_state) {
pos = state[0];
angle = state[1];
- scale = state[2];
+ _scale = state[2];
_update_transform();
_change_notify("transform/rot");
_change_notify("transform/scale");
@@ -93,11 +93,11 @@ void Node2D::edit_set_rect(const Rect2& p_edit_rect) {
Point2 new_pos = p_edit_rect.pos + p_edit_rect.size*zero_offset;//p_edit_rect.pos - r.pos;
Matrix32 postxf;
- postxf.set_rotation_and_scale(angle,scale);
+ postxf.set_rotation_and_scale(angle,_scale);
new_pos = postxf.xform(new_pos);
pos+=new_pos;
- scale*=new_scale;
+ _scale*=new_scale;
_update_transform();
_change_notify("transform/scale");
@@ -118,14 +118,14 @@ void Node2D::_update_xform_values() {
pos=_mat.elements[2];
angle=_mat.get_rotation();
- scale=_mat.get_scale();
+ _scale=_mat.get_scale();
_xform_dirty=false;
}
void Node2D::_update_transform() {
Matrix32 mat(angle,pos);
- _mat.set_rotation_and_scale(angle,scale);
+ _mat.set_rotation_and_scale(angle,_scale);
_mat.elements[2]=pos;
VisualServer::get_singleton()->canvas_item_set_transform(get_canvas_item(),_mat);
@@ -161,11 +161,11 @@ void Node2D::set_scale(const Size2& p_scale) {
if (_xform_dirty)
((Node2D*)this)->_update_xform_values();
- scale=p_scale;
- if (scale.x==0)
- scale.x=CMP_EPSILON;
- if (scale.y==0)
- scale.y=CMP_EPSILON;
+ _scale=p_scale;
+ if (_scale.x==0)
+ _scale.x=CMP_EPSILON;
+ if (_scale.y==0)
+ _scale.y=CMP_EPSILON;
_update_transform();
_change_notify("transform/scale");
@@ -187,7 +187,7 @@ Size2 Node2D::get_scale() const {
if (_xform_dirty)
((Node2D*)this)->_update_xform_values();
- return scale;
+ return _scale;
}
void Node2D::_set_rotd(float p_angle) {
@@ -224,11 +224,27 @@ Rect2 Node2D::get_item_rect() const {
return Rect2(Point2(-32,-32),Size2(64,64));
}
-void Node2D::rotate(float p_degrees) {
+void Node2D::rotate(float p_radians) {
- set_rot( get_rot() + p_degrees);
+ set_rot( get_rot() + p_radians);
}
+void Node2D::translate(const Vector2& p_amount) {
+
+ set_pos( get_pos() + p_amount );
+}
+
+void Node2D::global_translate(const Vector2& p_amount) {
+
+ set_global_pos( get_global_pos() + p_amount );
+}
+
+void Node2D::scale(const Vector2& p_amount) {
+
+ set_scale( get_scale() * p_amount );
+}
+
+
void Node2D::move_x(float p_delta,bool p_scaled){
Matrix32 t = get_transform();
@@ -345,9 +361,12 @@ void Node2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_rot"),&Node2D::get_rot);
ObjectTypeDB::bind_method(_MD("get_scale"),&Node2D::get_scale);
- ObjectTypeDB::bind_method(_MD("rotate","degrees"),&Node2D::rotate);
+ ObjectTypeDB::bind_method(_MD("rotate","radians"),&Node2D::rotate);
ObjectTypeDB::bind_method(_MD("move_local_x","delta","scaled"),&Node2D::move_x,DEFVAL(false));
ObjectTypeDB::bind_method(_MD("move_local_y","delta","scaled"),&Node2D::move_y,DEFVAL(false));
+ ObjectTypeDB::bind_method(_MD("translate","offset"),&Node2D::translate);
+ ObjectTypeDB::bind_method(_MD("global_translate","offset"),&Node2D::global_translate);
+ ObjectTypeDB::bind_method(_MD("scale","ratio"),&Node2D::scale);
ObjectTypeDB::bind_method(_MD("set_global_pos","pos"),&Node2D::set_global_pos);
ObjectTypeDB::bind_method(_MD("get_global_pos"),&Node2D::get_global_pos);
@@ -379,7 +398,7 @@ Node2D::Node2D() {
angle=0;
- scale=Vector2(1,1);
+ _scale=Vector2(1,1);
_xform_dirty=false;
z=0;
z_relative=true;
diff --git a/scene/2d/node_2d.h b/scene/2d/node_2d.h
index 7b059008c2..39a1061195 100644
--- a/scene/2d/node_2d.h
+++ b/scene/2d/node_2d.h
@@ -37,7 +37,7 @@ class Node2D : public CanvasItem {
Point2 pos;
float angle;
- Size2 scale;
+ Size2 _scale;
int z;
bool z_relative;
@@ -72,9 +72,12 @@ public:
void set_rot(float p_angle);
void set_scale(const Size2& p_scale);
- void rotate(float p_degrees);
+ void rotate(float p_radians);
void move_x(float p_delta,bool p_scaled=false);
void move_y(float p_delta,bool p_scaled=false);
+ void translate(const Vector2& p_amount);
+ void global_translate(const Vector2& p_amount);
+ void scale(const Vector2& p_amount);
Point2 get_pos() const;
float get_rot() const;
@@ -96,6 +99,7 @@ public:
Matrix32 get_relative_transform(const Node *p_parent) const;
+
Matrix32 get_transform() const;
Node2D();
diff --git a/scene/2d/particles_2d.cpp b/scene/2d/particles_2d.cpp
index 6e2cf5954b..c9dd92ff3d 100644
--- a/scene/2d/particles_2d.cpp
+++ b/scene/2d/particles_2d.cpp
@@ -1077,13 +1077,18 @@ void Particles2D::_bind_methods() {
BIND_CONSTANT( PARAM_SPREAD );
BIND_CONSTANT( PARAM_LINEAR_VELOCITY );
BIND_CONSTANT( PARAM_SPIN_VELOCITY );
+ BIND_CONSTANT( PARAM_ORBIT_VELOCITY );
BIND_CONSTANT( PARAM_GRAVITY_DIRECTION );
BIND_CONSTANT( PARAM_GRAVITY_STRENGTH );
BIND_CONSTANT( PARAM_RADIAL_ACCEL );
BIND_CONSTANT( PARAM_TANGENTIAL_ACCEL );
+ BIND_CONSTANT( PARAM_DAMPING );
+ BIND_CONSTANT( PARAM_INITIAL_ANGLE );
BIND_CONSTANT( PARAM_INITIAL_SIZE );
BIND_CONSTANT( PARAM_FINAL_SIZE );
BIND_CONSTANT( PARAM_HUE_VARIATION );
+ BIND_CONSTANT( PARAM_ANIM_SPEED_SCALE );
+ BIND_CONSTANT( PARAM_ANIM_INITIAL_POS );
BIND_CONSTANT( PARAM_MAX );
BIND_CONSTANT( MAX_COLOR_PHASES );
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp
index 6f18325212..22dd0f01d0 100644
--- a/scene/2d/physics_body_2d.cpp
+++ b/scene/2d/physics_body_2d.cpp
@@ -98,6 +98,7 @@ PhysicsBody2D::PhysicsBody2D(Physics2DServer::BodyMode p_mode) : CollisionObject
mask=1;
set_one_way_collision_max_depth(0);
+ set_pickable(false);
}
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp
index 52f4d27497..2b88ee5dba 100644
--- a/scene/2d/tile_map.cpp
+++ b/scene/2d/tile_map.cpp
@@ -29,6 +29,15 @@
#include "tile_map.h"
#include "io/marshalls.h"
#include "servers/physics_2d_server.h"
+#include "method_bind_ext.inc"
+
+int TileMap::_get_quadrant_size() const {
+
+ if (y_sort_mode)
+ return 1;
+ else
+ return quadrant_size;
+}
void TileMap::_notification(int p_what) {
@@ -36,6 +45,17 @@ void TileMap::_notification(int p_what) {
case NOTIFICATION_ENTER_TREE: {
+ Node2D *c=this;
+ while(c) {
+
+ navigation=c->cast_to<Navigation2D>();
+ if (navigation) {
+ break;
+ }
+
+ c=c->get_parent()->cast_to<Node2D>();
+ }
+
pending_update=true;
_update_dirty_quadrants();
RID space = get_world_2d()->get_space();
@@ -47,6 +67,25 @@ void TileMap::_notification(int p_what) {
case NOTIFICATION_EXIT_TREE: {
_update_quadrant_space(RID());
+ for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) {
+
+ Quadrant &q=E->get();
+ if (navigation) {
+ for(Map<PosKey,Quadrant::NavPoly>::Element *E=q.navpoly_ids.front();E;E=E->next()) {
+
+ navigation->navpoly_remove(E->get().id);
+ }
+ q.navpoly_ids.clear();
+ }
+
+ for(Map<PosKey,Quadrant::Occluder>::Element *E=q.occluder_instances.front();E;E=E->next()) {
+ VS::get_singleton()->free(E->get().id);
+ }
+ q.occluder_instances.clear();
+ }
+
+ navigation=NULL;
+
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
@@ -74,6 +113,10 @@ void TileMap::_update_quadrant_transform() {
Matrix32 global_transform = get_global_transform();
+ Matrix32 nav_rel;
+ if (navigation)
+ nav_rel = get_relative_transform(navigation);
+
for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) {
Quadrant &q=E->get();
@@ -81,6 +124,17 @@ void TileMap::_update_quadrant_transform() {
xform.set_origin( q.pos );
xform = global_transform * xform;
Physics2DServer::get_singleton()->body_set_state(q.body,Physics2DServer::BODY_STATE_TRANSFORM,xform);
+
+ if (navigation) {
+ for(Map<PosKey,Quadrant::NavPoly>::Element *E=q.navpoly_ids.front();E;E=E->next()) {
+
+ navigation->navpoly_set_transform(E->get().id,nav_rel * E->get().xform);
+ }
+ }
+
+ for(Map<PosKey,Quadrant::Occluder>::Element *E=q.occluder_instances.front();E;E=E->next()) {
+ VS::get_singleton()->canvas_light_occluder_set_transform(E->get().id,global_transform * E->get().xform);
+ }
}
}
@@ -161,6 +215,34 @@ bool TileMap::get_center_y() const {
return center_y;
}
+void TileMap::_fix_cell_transform(Matrix32& xform,const Cell& p_cell, const Vector2& p_offset, const Size2 &p_sc) {
+
+ Size2 s=p_sc;
+ Vector2 offset = p_offset;
+
+ if (p_cell.transpose) {
+ SWAP(xform.elements[0].x, xform.elements[0].y);
+ SWAP(xform.elements[1].x, xform.elements[1].y);
+ SWAP(offset.x, offset.y);
+ SWAP(s.x, s.y);
+ }
+ if (p_cell.flip_h) {
+ xform.elements[0].x=-xform.elements[0].x;
+ xform.elements[1].x=-xform.elements[1].x;
+ if (tile_origin==TILE_ORIGIN_TOP_LEFT)
+ offset.x=s.x-offset.x;
+ }
+ if (p_cell.flip_v) {
+ xform.elements[0].y=-xform.elements[0].y;
+ xform.elements[1].y=-xform.elements[1].y;
+ if (tile_origin==TILE_ORIGIN_TOP_LEFT)
+ offset.y=s.y-offset.y;
+ }
+ xform.elements[2].x+=offset.x;
+ xform.elements[2].y+=offset.y;
+
+}
+
void TileMap::_update_dirty_quadrants() {
if (!pending_update)
@@ -173,15 +255,42 @@ void TileMap::_update_dirty_quadrants() {
VisualServer *vs = VisualServer::get_singleton();
Physics2DServer *ps = Physics2DServer::get_singleton();
Vector2 tofs = get_cell_draw_offset();
+ Vector2 tcenter = cell_size/2;
+ Matrix32 nav_rel;
+ if (navigation)
+ nav_rel = get_relative_transform(navigation);
+
+ Vector2 qofs;
while (dirty_quadrant_list.first()) {
Quadrant &q = *dirty_quadrant_list.first()->self();
- vs->canvas_item_clear(q.canvas_item);
+ for (List<RID>::Element *E=q.canvas_items.front();E;E=E->next()) {
+
+ vs->free(E->get());
+ }
+
+ q.canvas_items.clear();
+
ps->body_clear_shapes(q.body);
int shape_idx=0;
+ if (navigation) {
+ for(Map<PosKey,Quadrant::NavPoly>::Element *E=q.navpoly_ids.front();E;E=E->next()) {
+
+ navigation->navpoly_remove(E->get().id);
+ }
+ q.navpoly_ids.clear();
+ }
+
+ for(Map<PosKey,Quadrant::Occluder>::Element *E=q.occluder_instances.front();E;E=E->next()) {
+ VS::get_singleton()->free(E->get().id);
+ }
+ q.occluder_instances.clear();
+ Ref<CanvasItemMaterial> prev_material;
+ RID prev_canvas_item;
+
for(int i=0;i<q.cells.size();i++) {
Map<PosKey,Cell>::Element *E=tile_map.find( q.cells[i] );
@@ -192,11 +301,35 @@ void TileMap::_update_dirty_quadrants() {
Ref<Texture> tex = tile_set->tile_get_texture(c.id);
Vector2 tile_ofs = tile_set->tile_get_texture_offset(c.id);
- Vector2 offset = _map_to_world(E->key().x, E->key().y) - q.pos + tofs;
+ Vector2 wofs = _map_to_world(E->key().x, E->key().y);
+ Vector2 offset = wofs - q.pos + tofs;
if (!tex.is_valid())
continue;
+ Ref<CanvasItemMaterial> mat = tile_set->tile_get_material(c.id);
+
+ RID canvas_item;
+
+ if (prev_canvas_item==RID() || prev_material!=mat) {
+
+ canvas_item=vs->canvas_item_create();
+ if (mat.is_valid())
+ vs->canvas_item_set_material(canvas_item,mat->get_rid());
+ vs->canvas_item_set_parent( canvas_item, get_canvas_item() );
+ Matrix32 xform;
+ xform.set_origin( q.pos );
+ vs->canvas_item_set_transform( canvas_item, xform );
+ q.canvas_items.push_back(canvas_item);
+
+ prev_canvas_item=canvas_item;
+ prev_material=mat;
+
+ } else {
+ canvas_item=prev_canvas_item;
+ }
+
+
Rect2 r = tile_set->tile_get_region(c.id);
Size2 s = tex->get_size();
@@ -223,14 +356,32 @@ void TileMap::_update_dirty_quadrants() {
if (c.flip_v)
rect.size.y=-rect.size.y;
+ Vector2 center_ofs;
- rect.pos+=tile_ofs;
- if (r==Rect2()) {
+ if (tile_origin==TILE_ORIGIN_TOP_LEFT) {
+ rect.pos+=tile_ofs;
+ } else if (tile_origin==TILE_ORIGIN_CENTER) {
+ rect.pos+=tcenter;
- tex->draw_rect(q.canvas_item,rect);
- } else {
+ Vector2 center = (s/2) - tile_ofs;
+ center_ofs=tcenter-(s/2);
+
+ if (c.flip_h)
+ rect.pos.x-=s.x-center.x;
+ else
+ rect.pos.x-=center.x;
- tex->draw_rect_region(q.canvas_item,rect,r);
+ if (c.flip_v)
+ rect.pos.y-=s.y-center.y;
+ else
+ rect.pos.y-=center.y;
+ }
+
+
+ if (r==Rect2()) {
+ tex->draw_rect(canvas_item,rect,false,Color(1,1,1),c.transpose);
+ } else {
+ tex->draw_rect_region(canvas_item,rect,r,Color(1,1,1),c.transpose);
}
Vector< Ref<Shape2D> > shapes = tile_set->tile_get_shapes(c.id);
@@ -244,27 +395,48 @@ void TileMap::_update_dirty_quadrants() {
Vector2 shape_ofs = tile_set->tile_get_shape_offset(c.id);
Matrix32 xform;
xform.set_origin(offset.floor());
- if (c.flip_h) {
- xform.elements[0]=-xform.elements[0];
- xform.elements[2].x+=s.x-shape_ofs.x;
- } else {
-
- xform.elements[2].x+=shape_ofs.x;
- }
- if (c.flip_v) {
- xform.elements[1]=-xform.elements[1];
- xform.elements[2].y+=s.y-shape_ofs.y;
- } else {
-
- xform.elements[2].y+=shape_ofs.y;
- }
+ _fix_cell_transform(xform,c,shape_ofs+center_ofs,s);
ps->body_add_shape(q.body,shape->get_rid(),xform);
ps->body_set_shape_metadata(q.body,shape_idx++,Vector2(E->key().x,E->key().y));
}
}
+
+ if (navigation) {
+ Ref<NavigationPolygon> navpoly = tile_set->tile_get_navigation_polygon(c.id);
+ Vector2 npoly_ofs = tile_set->tile_get_navigation_polygon_offset(c.id);
+ Matrix32 xform;
+ xform.set_origin(offset.floor()+q.pos);
+ _fix_cell_transform(xform,c,npoly_ofs+center_ofs,s);
+
+ int pid = navigation->navpoly_create(navpoly,nav_rel * xform);
+
+ Quadrant::NavPoly np;
+ np.id=pid;
+ np.xform=xform;
+ q.navpoly_ids[E->key()]=np;
+ }
+
+
+ Ref<OccluderPolygon2D> occluder=tile_set->tile_get_light_occluder(c.id);
+ if (occluder.is_valid()) {
+
+ Vector2 occluder_ofs = tile_set->tile_get_occluder_offset(c.id);
+ Matrix32 xform;
+ xform.set_origin(offset.floor()+q.pos);
+ _fix_cell_transform(xform,c,occluder_ofs+center_ofs,s);
+
+ RID orid = VS::get_singleton()->canvas_light_occluder_create();
+ VS::get_singleton()->canvas_light_occluder_set_transform(orid,get_global_transform() * xform);
+ VS::get_singleton()->canvas_light_occluder_set_polygon(orid,occluder->get_rid());
+ VS::get_singleton()->canvas_light_occluder_attach_to_canvas(orid,get_canvas());
+ Quadrant::Occluder oc;
+ oc.xform=xform;
+ oc.id=orid;
+ q.occluder_instances[E->key()]=oc;
+ }
}
dirty_quadrant_list.remove( dirty_quadrant_list.first() );
@@ -279,10 +451,10 @@ void TileMap::_update_dirty_quadrants() {
for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) {
Quadrant &q=E->get();
- if (q.canvas_item.is_valid()) {
- VS::get_singleton()->canvas_item_raise(q.canvas_item);
- }
+ for (List<RID>::Element *E=q.canvas_items.front();E;E=E->next()) {
+ VS::get_singleton()->canvas_item_raise(E->get());
+ }
}
quadrant_order_dirty=false;
@@ -305,10 +477,10 @@ void TileMap::_recompute_rect_cache() {
Rect2 r;
- r.pos=_map_to_world(E->key().x*quadrant_size, E->key().y*quadrant_size);
- r.expand_to( _map_to_world(E->key().x*quadrant_size+quadrant_size, E->key().y*quadrant_size) );
- r.expand_to( _map_to_world(E->key().x*quadrant_size+quadrant_size, E->key().y*quadrant_size+quadrant_size) );
- r.expand_to( _map_to_world(E->key().x*quadrant_size, E->key().y*quadrant_size+quadrant_size) );
+ r.pos=_map_to_world(E->key().x*_get_quadrant_size(), E->key().y*_get_quadrant_size());
+ r.expand_to( _map_to_world(E->key().x*_get_quadrant_size()+_get_quadrant_size(), E->key().y*_get_quadrant_size()) );
+ r.expand_to( _map_to_world(E->key().x*_get_quadrant_size()+_get_quadrant_size(), E->key().y*_get_quadrant_size()+_get_quadrant_size()) );
+ r.expand_to( _map_to_world(E->key().x*_get_quadrant_size(), E->key().y*_get_quadrant_size()+_get_quadrant_size()) );
if (E==quadrant_map.front())
r_total=r;
else
@@ -319,7 +491,7 @@ void TileMap::_recompute_rect_cache() {
if (r_total==Rect2()) {
rect_cache=Rect2(-10,-10,20,20);
} else {
- rect_cache=r_total.grow(MAX(cell_size.x,cell_size.y)*quadrant_size);
+ rect_cache=r_total.grow(MAX(cell_size.x,cell_size.y)*_get_quadrant_size());
}
item_rect_changed();
@@ -335,11 +507,13 @@ Map<TileMap::PosKey,TileMap::Quadrant>::Element *TileMap::_create_quadrant(const
Matrix32 xform;
//xform.set_origin(Point2(p_qk.x,p_qk.y)*cell_size*quadrant_size);
Quadrant q;
- q.pos = _map_to_world(p_qk.x*quadrant_size,p_qk.y*quadrant_size);
+ q.pos = _map_to_world(p_qk.x*_get_quadrant_size(),p_qk.y*_get_quadrant_size());
+ q.pos+=get_cell_draw_offset();
+ if (tile_origin==TILE_ORIGIN_CENTER)
+ q.pos+=cell_size/2;
+
xform.set_origin( q.pos );
- q.canvas_item = VisualServer::get_singleton()->canvas_item_create();
- VisualServer::get_singleton()->canvas_item_set_parent( q.canvas_item, get_canvas_item() );
- VisualServer::get_singleton()->canvas_item_set_transform( q.canvas_item, xform );
+// q.canvas_item = VisualServer::get_singleton()->canvas_item_create();
q.body=Physics2DServer::get_singleton()->body_create(use_kinematic?Physics2DServer::BODY_MODE_KINEMATIC:Physics2DServer::BODY_MODE_STATIC);
Physics2DServer::get_singleton()->body_attach_object_instance_ID(q.body,get_instance_ID());
Physics2DServer::get_singleton()->body_set_layer_mask(q.body,collision_layer);
@@ -363,10 +537,27 @@ void TileMap::_erase_quadrant(Map<PosKey,Quadrant>::Element *Q) {
Quadrant &q=Q->get();
Physics2DServer::get_singleton()->free(q.body);
- VisualServer::get_singleton()->free(q.canvas_item);
+ for (List<RID>::Element *E=q.canvas_items.front();E;E=E->next()) {
+
+ VisualServer::get_singleton()->free(E->get());
+ }
+ q.canvas_items.clear();
if (q.dirty_list.in_list())
dirty_quadrant_list.remove(&q.dirty_list);
+ if (navigation) {
+ for(Map<PosKey,Quadrant::NavPoly>::Element *E=q.navpoly_ids.front();E;E=E->next()) {
+
+ navigation->navpoly_remove(E->get().id);
+ }
+ q.navpoly_ids.clear();
+ }
+
+ for(Map<PosKey,Quadrant::Occluder>::Element *E=q.occluder_instances.front();E;E=E->next()) {
+ VS::get_singleton()->free(E->get().id);
+ }
+ q.occluder_instances.clear();
+
quadrant_map.erase(Q);
rect_cache_dirty=true;
}
@@ -386,7 +577,7 @@ void TileMap::_make_quadrant_dirty(Map<PosKey,Quadrant>::Element *Q) {
}
-void TileMap::set_cell(int p_x,int p_y,int p_tile,bool p_flip_x,bool p_flip_y) {
+void TileMap::set_cell(int p_x,int p_y,int p_tile,bool p_flip_x,bool p_flip_y,bool p_transpose) {
PosKey pk(p_x,p_y);
@@ -394,7 +585,7 @@ void TileMap::set_cell(int p_x,int p_y,int p_tile,bool p_flip_x,bool p_flip_y) {
if (!E && p_tile==INVALID_CELL)
return; //nothing to do
- PosKey qk(p_x/quadrant_size,p_y/quadrant_size);
+ PosKey qk(p_x/_get_quadrant_size(),p_y/_get_quadrant_size());
if (p_tile==INVALID_CELL) {
//erase existing
tile_map.erase(pk);
@@ -422,7 +613,7 @@ void TileMap::set_cell(int p_x,int p_y,int p_tile,bool p_flip_x,bool p_flip_y) {
} else {
ERR_FAIL_COND(!Q); // quadrant should exist...
- if (E->get().id==p_tile && E->get().flip_h==p_flip_x && E->get().flip_v==p_flip_y)
+ if (E->get().id==p_tile && E->get().flip_h==p_flip_x && E->get().flip_v==p_flip_y && E->get().transpose==p_transpose)
return; //nothing changed
}
@@ -433,6 +624,7 @@ void TileMap::set_cell(int p_x,int p_y,int p_tile,bool p_flip_x,bool p_flip_y) {
c.id=p_tile;
c.flip_h=p_flip_x;
c.flip_v=p_flip_y;
+ c.transpose=p_transpose;
_make_quadrant_dirty(Q);
@@ -472,6 +664,17 @@ bool TileMap::is_cell_y_flipped(int p_x,int p_y) const {
return E->get().flip_v;
}
+bool TileMap::is_cell_transposed(int p_x,int p_y) const {
+
+ PosKey pk(p_x,p_y);
+
+ const Map<PosKey,Cell>::Element *E=tile_map.find(pk);
+
+ if (!E)
+ return false;
+
+ return E->get().transpose;
+}
void TileMap::_recreate_quadrants() {
@@ -480,7 +683,7 @@ void TileMap::_recreate_quadrants() {
for (Map<PosKey,Cell>::Element *E=tile_map.front();E;E=E->next()) {
- PosKey qk(E->key().x/quadrant_size,E->key().y/quadrant_size);
+ PosKey qk(E->key().x/_get_quadrant_size(),E->key().y/_get_quadrant_size());
Map<PosKey,Quadrant>::Element *Q=quadrant_map.find(qk);
if (!Q) {
@@ -496,6 +699,7 @@ void TileMap::_recreate_quadrants() {
}
+
void TileMap::_clear_quadrants() {
while (quadrant_map.size()) {
@@ -536,11 +740,12 @@ void TileMap::_set_tile_data(const DVector<int>& p_data) {
uint32_t v = decode_uint32(&local[4]);
bool flip_h = v&(1<<29);
bool flip_v = v&(1<<30);
+ bool transpose = v&(1<<31);
v&=(1<<29)-1;
// if (x<-20 || y <-20 || x>4000 || y>4000)
// continue;
- set_cell(x,y,v,flip_h,flip_v);
+ set_cell(x,y,v,flip_h,flip_v,transpose);
}
@@ -563,6 +768,8 @@ DVector<int> TileMap::_get_tile_data() const {
val|=(1<<29);
if (E->get().flip_v)
val|=(1<<30);
+ if (E->get().transpose)
+ val|=(1<<31);
encode_uint32(val,&ptr[4]);
idx+=2;
@@ -660,6 +867,20 @@ void TileMap::set_half_offset(HalfOffset p_half_offset) {
emit_signal("settings_changed");
}
+void TileMap::set_tile_origin(TileOrigin p_tile_origin) {
+
+ _clear_quadrants();
+ tile_origin=p_tile_origin;
+ _recreate_quadrants();
+ emit_signal("settings_changed");
+}
+
+TileMap::TileOrigin TileMap::get_tile_origin() const{
+
+ return tile_origin;
+}
+
+
Vector2 TileMap::get_cell_draw_offset() const {
switch(mode) {
@@ -786,6 +1007,21 @@ Vector2 TileMap::world_to_map(const Vector2& p_pos) const{
return ret.floor();
}
+void TileMap::set_y_sort_mode(bool p_enable) {
+
+ _clear_quadrants();
+ y_sort_mode=p_enable;
+ VS::get_singleton()->canvas_item_set_sort_children_by_y(get_canvas_item(),y_sort_mode);
+ _recreate_quadrants();
+ emit_signal("settings_changed");
+
+}
+
+bool TileMap::is_y_sort_mode_enabled() const {
+
+ return y_sort_mode;
+}
+
void TileMap::_bind_methods() {
@@ -811,12 +1047,18 @@ void TileMap::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_quadrant_size","size"),&TileMap::set_quadrant_size);
ObjectTypeDB::bind_method(_MD("get_quadrant_size"),&TileMap::get_quadrant_size);
+ ObjectTypeDB::bind_method(_MD("set_tile_origin","origin"),&TileMap::set_tile_origin);
+ ObjectTypeDB::bind_method(_MD("get_tile_origin"),&TileMap::get_tile_origin);
+
ObjectTypeDB::bind_method(_MD("set_center_x","enable"),&TileMap::set_center_x);
ObjectTypeDB::bind_method(_MD("get_center_x"),&TileMap::get_center_x);
ObjectTypeDB::bind_method(_MD("set_center_y","enable"),&TileMap::set_center_y);
ObjectTypeDB::bind_method(_MD("get_center_y"),&TileMap::get_center_y);
+ ObjectTypeDB::bind_method(_MD("set_y_sort_mode","enable"),&TileMap::set_y_sort_mode);
+ ObjectTypeDB::bind_method(_MD("is_y_sort_mode_enabled"),&TileMap::is_y_sort_mode_enabled);
+
ObjectTypeDB::bind_method(_MD("set_collision_use_kinematic","use_kinematic"),&TileMap::set_collision_use_kinematic);
ObjectTypeDB::bind_method(_MD("get_collision_use_kinematic"),&TileMap::get_collision_use_kinematic);
@@ -829,7 +1071,7 @@ void TileMap::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_collision_bounce","value"),&TileMap::set_collision_bounce);
ObjectTypeDB::bind_method(_MD("get_collision_bounce"),&TileMap::get_collision_bounce);
- ObjectTypeDB::bind_method(_MD("set_cell","x","y","tile","flip_x","flip_y"),&TileMap::set_cell,DEFVAL(false),DEFVAL(false));
+ ObjectTypeDB::bind_method(_MD("set_cell","x","y","tile","flip_x","flip_y","transpose"),&TileMap::set_cell,DEFVAL(false),DEFVAL(false),DEFVAL(false));
ObjectTypeDB::bind_method(_MD("get_cell","x","y"),&TileMap::get_cell);
ObjectTypeDB::bind_method(_MD("is_cell_x_flipped","x","y"),&TileMap::is_cell_x_flipped);
ObjectTypeDB::bind_method(_MD("is_cell_y_flipped","x","y"),&TileMap::is_cell_y_flipped);
@@ -853,6 +1095,8 @@ void TileMap::_bind_methods() {
ADD_PROPERTY( PropertyInfo(Variant::INT,"cell/quadrant_size",PROPERTY_HINT_RANGE,"1,128,1"),_SCS("set_quadrant_size"),_SCS("get_quadrant_size"));
ADD_PROPERTY( PropertyInfo(Variant::MATRIX32,"cell/custom_transform"),_SCS("set_custom_transform"),_SCS("get_custom_transform"));
ADD_PROPERTY( PropertyInfo(Variant::INT,"cell/half_offset",PROPERTY_HINT_ENUM,"Offset X,Offset Y,Disabled"),_SCS("set_half_offset"),_SCS("get_half_offset"));
+ ADD_PROPERTY( PropertyInfo(Variant::INT,"cell/tile_origin",PROPERTY_HINT_ENUM,"Top Left,Center"),_SCS("set_tile_origin"),_SCS("get_tile_origin"));
+ ADD_PROPERTY( PropertyInfo(Variant::BOOL,"cell/y_sort"),_SCS("set_y_sort_mode"),_SCS("is_y_sort_mode_enabled"));
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"collision/use_kinematic",PROPERTY_HINT_NONE,""),_SCS("set_collision_use_kinematic"),_SCS("get_collision_use_kinematic"));
ADD_PROPERTY( PropertyInfo(Variant::REAL,"collision/friction",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_collision_friction"),_SCS("get_collision_friction"));
ADD_PROPERTY( PropertyInfo(Variant::REAL,"collision/bounce",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_collision_bounce"),_SCS("get_collision_bounce"));
@@ -868,6 +1112,8 @@ void TileMap::_bind_methods() {
BIND_CONSTANT( HALF_OFFSET_X );
BIND_CONSTANT( HALF_OFFSET_Y );
BIND_CONSTANT( HALF_OFFSET_DISABLED );
+ BIND_CONSTANT( TILE_ORIGIN_TOP_LEFT );
+ BIND_CONSTANT( TILE_ORIGIN_CENTER );
}
@@ -888,9 +1134,12 @@ TileMap::TileMap() {
mode=MODE_SQUARE;
half_offset=HALF_OFFSET_DISABLED;
use_kinematic=false;
+ navigation=NULL;
+ y_sort_mode=false;
fp_adjust=0.01;
fp_adjust=0.01;
+ tile_origin=TILE_ORIGIN_TOP_LEFT;
}
TileMap::~TileMap() {
diff --git a/scene/2d/tile_map.h b/scene/2d/tile_map.h
index c8708e1bed..e02c4ee5bb 100644
--- a/scene/2d/tile_map.h
+++ b/scene/2d/tile_map.h
@@ -30,6 +30,7 @@
#define TILE_MAP_H
#include "scene/2d/node_2d.h"
+#include "scene/2d/navigation2d.h"
#include "scene/resources/tile_set.h"
#include "self_list.h"
#include "vset.h"
@@ -51,6 +52,12 @@ public:
HALF_OFFSET_DISABLED,
};
+ enum TileOrigin {
+ TILE_ORIGIN_TOP_LEFT,
+ TILE_ORIGIN_CENTER
+ };
+
+
private:
Ref<TileSet> tile_set;
@@ -61,6 +68,7 @@ private:
Matrix32 custom_transform;
HalfOffset half_offset;
bool use_kinematic;
+ Navigation2D *navigation;
union PosKey {
@@ -86,6 +94,7 @@ private:
int32_t id:24;
bool flip_h:1;
bool flip_v:1;
+ bool transpose:1;
};
uint32_t _u32t;
@@ -97,15 +106,29 @@ private:
struct Quadrant {
Vector2 pos;
- RID canvas_item;
+ List<RID> canvas_items;
RID body;
SelfList<Quadrant> dirty_list;
+ struct NavPoly {
+ int id;
+ Matrix32 xform;
+ };
+
+ struct Occluder {
+ RID id;
+ Matrix32 xform;
+ };
+
+
+ Map<PosKey,NavPoly> navpoly_ids;
+ Map<PosKey,Occluder> occluder_instances;
+
VSet<PosKey> cells;
- void operator=(const Quadrant& q) { pos=q.pos; canvas_item=q.canvas_item; body=q.body; cells=q.cells; }
- Quadrant(const Quadrant& q) : dirty_list(this) { pos=q.pos; canvas_item=q.canvas_item; body=q.body; cells=q.cells;}
+ void operator=(const Quadrant& q) { pos=q.pos; canvas_items=q.canvas_items; body=q.body; cells=q.cells; navpoly_ids=q.navpoly_ids; occluder_instances=q.occluder_instances; }
+ Quadrant(const Quadrant& q) : dirty_list(this) { pos=q.pos; canvas_items=q.canvas_items; body=q.body; cells=q.cells; occluder_instances=q.occluder_instances; navpoly_ids=q.navpoly_ids;}
Quadrant() : dirty_list(this) {}
};
@@ -118,11 +141,14 @@ private:
Rect2 rect_cache;
bool rect_cache_dirty;
bool quadrant_order_dirty;
+ bool y_sort_mode;
float fp_adjust;
float friction;
float bounce;
uint32_t collision_layer;
+ TileOrigin tile_origin;
+ void _fix_cell_transform(Matrix32& xform, const Cell& p_cell, const Vector2 &p_offset, const Size2 &p_sc);
Map<PosKey,Quadrant>::Element *_create_quadrant(const PosKey& p_qk);
void _erase_quadrant(Map<PosKey,Quadrant>::Element *Q);
@@ -134,6 +160,9 @@ private:
void _update_quadrant_transform();
void _recompute_rect_cache();
+ _FORCE_INLINE_ int _get_quadrant_size() const;
+
+
void _set_tile_data(const DVector<int>& p_data);
DVector<int> _get_tile_data() const;
@@ -168,10 +197,11 @@ public:
void set_center_y(bool p_enable);
bool get_center_y() const;
- void set_cell(int p_x,int p_y,int p_tile,bool p_flip_x=false,bool p_flip_y=false);
+ void set_cell(int p_x,int p_y,int p_tile,bool p_flip_x=false,bool p_flip_y=false,bool p_transpose=false);
int get_cell(int p_x,int p_y) const;
bool is_cell_x_flipped(int p_x,int p_y) const;
bool is_cell_y_flipped(int p_x,int p_y) const;
+ bool is_cell_transposed(int p_x,int p_y) const;
Rect2 get_item_rect() const;
@@ -193,6 +223,9 @@ public:
void set_half_offset(HalfOffset p_half_offset);
HalfOffset get_half_offset() const;
+ void set_tile_origin(TileOrigin p_tile_origin);
+ TileOrigin get_tile_origin() const;
+
void set_custom_transform(const Matrix32& p_xform);
Matrix32 get_custom_transform() const;
@@ -202,6 +235,9 @@ public:
Vector2 map_to_world(const Vector2& p_pos, bool p_ignore_ofs=false) const;
Vector2 world_to_map(const Vector2& p_pos) const;
+ void set_y_sort_mode(bool p_enable);
+ bool is_y_sort_mode_enabled() const;
+
void clear();
TileMap();
@@ -210,5 +246,6 @@ public:
VARIANT_ENUM_CAST(TileMap::Mode);
VARIANT_ENUM_CAST(TileMap::HalfOffset);
+VARIANT_ENUM_CAST(TileMap::TileOrigin);
#endif // TILE_MAP_H
diff --git a/scene/2d/visibility_notifier_2d.cpp b/scene/2d/visibility_notifier_2d.cpp
index 22534eeb0e..cd3c788b65 100644
--- a/scene/2d/visibility_notifier_2d.cpp
+++ b/scene/2d/visibility_notifier_2d.cpp
@@ -32,6 +32,7 @@
#include "scene/2d/physics_body_2d.h"
#include "scene/animation/animation_player.h"
#include "scene/scene_string_names.h"
+#include "particles_2d.h"
void VisibilityNotifier2D::_enter_viewport(Viewport* p_viewport) {
@@ -188,6 +189,15 @@ void VisibilityEnabler2D::_find_nodes(Node* p_node) {
}
+ if (enabler[ENABLER_PAUSE_PARTICLES]) {
+
+ Particles2D *ps = p_node->cast_to<Particles2D>();
+ if (ps) {
+ add=true;
+ }
+
+ }
+
if (add) {
p_node->connect(SceneStringNames::get_singleton()->exit_tree,this,"_node_removed",varray(p_node),CONNECT_ONESHOT);
@@ -271,6 +281,15 @@ void VisibilityEnabler2D::_change_node_state(Node* p_node,bool p_enabled) {
}
}
+ {
+ Particles2D *ps=p_node->cast_to<Particles2D>();
+
+ if (ps) {
+
+ ps->set_emitting(p_enabled);
+ }
+ }
+
}
@@ -292,9 +311,11 @@ void VisibilityEnabler2D::_bind_methods(){
ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"enabler/pause_animations"),_SCS("set_enabler"),_SCS("is_enabler_enabled"), ENABLER_PAUSE_ANIMATIONS );
ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"enabler/freeze_bodies"),_SCS("set_enabler"),_SCS("is_enabler_enabled"), ENABLER_FREEZE_BODIES);
+ ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"enabler/pause_particles"),_SCS("set_enabler"),_SCS("is_enabler_enabled"), ENABLER_PAUSE_PARTICLES);
BIND_CONSTANT( ENABLER_FREEZE_BODIES );
BIND_CONSTANT( ENABLER_PAUSE_ANIMATIONS );
+ BIND_CONSTANT( ENABLER_PAUSE_PARTICLES );
BIND_CONSTANT( ENABLER_MAX);
}
@@ -320,3 +341,4 @@ VisibilityEnabler2D::VisibilityEnabler2D() {
}
+
diff --git a/scene/2d/visibility_notifier_2d.h b/scene/2d/visibility_notifier_2d.h
index cdf52ecb27..621c470d5d 100644
--- a/scene/2d/visibility_notifier_2d.h
+++ b/scene/2d/visibility_notifier_2d.h
@@ -73,6 +73,7 @@ public:
enum Enabler {
ENABLER_PAUSE_ANIMATIONS,
ENABLER_FREEZE_BODIES,
+ ENABLER_PAUSE_PARTICLES,
ENABLER_MAX
};