summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2014-11-13 00:53:12 -0300
committerJuan Linietsky <reduzio@gmail.com>2014-11-13 00:53:12 -0300
commitabbea4d945bbb1114570c3b6c7f649e01ca8ebb8 (patch)
treed2b131b32705bbcf118efa72d5d9a21618c1227e /scene
parentd02953c5963ca080d26500ea8250e0632a80b234 (diff)
UDP Fixes
-=-=-=-=- Curse the day I decided to port UDP code, as it ended up being two nights of work. At least It's done now (I hope). -Fixed UDP Support, API seems stable -Added UDP Chat demo (chat that can lose your packets, heh) -Added helpers to areas and bodies to get list of collided bodies and contained bodies. -Sped up screen/viewport capture code. -Added code to save an image as PNG -Small fix so scripts register their singletons after modules did.
Diffstat (limited to 'scene')
-rw-r--r--scene/2d/area_2d.cpp21
-rw-r--r--scene/2d/area_2d.h2
-rw-r--r--scene/2d/physics_body_2d.cpp22
-rw-r--r--scene/2d/physics_body_2d.h2
-rw-r--r--scene/3d/area.cpp20
-rw-r--r--scene/3d/area.h2
-rw-r--r--scene/3d/physics_body.cpp23
-rw-r--r--scene/3d/physics_body.h1
8 files changed, 93 insertions, 0 deletions
diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp
index 33176c4f34..3114106235 100644
--- a/scene/2d/area_2d.cpp
+++ b/scene/2d/area_2d.cpp
@@ -263,6 +263,25 @@ bool Area2D::is_monitoring_enabled() const {
return monitoring;
}
+Array Area2D::get_overlapping_bodies() const {
+
+ ERR_FAIL_COND_V(!monitoring,Array());
+ Array ret;
+ ret.resize(body_map.size());
+ int idx=0;
+ for (const Map<ObjectID,BodyState>::Element *E=body_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;
+}
+
void Area2D::_bind_methods() {
@@ -290,6 +309,8 @@ 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("get_overlapping_bodies"),&Area2D::get_overlapping_bodies);
+
ObjectTypeDB::bind_method(_MD("_body_inout"),&Area2D::_body_inout);
diff --git a/scene/2d/area_2d.h b/scene/2d/area_2d.h
index 85f2b91582..c6210e7c9a 100644
--- a/scene/2d/area_2d.h
+++ b/scene/2d/area_2d.h
@@ -112,6 +112,8 @@ public:
void set_enable_monitoring(bool p_enable);
bool is_monitoring_enabled() const;
+ Array get_overlapping_bodies() const; //function for script
+
Area2D();
~Area2D();
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp
index f2f7a15e91..655c6e8bf6 100644
--- a/scene/2d/physics_body_2d.cpp
+++ b/scene/2d/physics_body_2d.cpp
@@ -618,6 +618,26 @@ RigidBody2D::CCDMode RigidBody2D::get_continuous_collision_detection_mode() cons
}
+Array RigidBody2D::get_colliding_bodies() const {
+
+ ERR_FAIL_COND_V(!contact_monitor,Array());
+
+ Array ret;
+ ret.resize(contact_monitor->body_map.size());
+ int idx=0;
+ for (const Map<ObjectID,BodyState>::Element *E=contact_monitor->body_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;
+}
+
void RigidBody2D::set_contact_monitor(bool p_enabled) {
if (p_enabled==is_contact_monitor_enabled())
@@ -697,6 +717,8 @@ void RigidBody2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_body_enter_tree"),&RigidBody2D::_body_enter_tree);
ObjectTypeDB::bind_method(_MD("_body_exit_tree"),&RigidBody2D::_body_exit_tree);
+ ObjectTypeDB::bind_method(_MD("get_colliding_bodies"),&RigidBody2D::get_colliding_bodies);
+
BIND_VMETHOD(MethodInfo("_integrate_forces",PropertyInfo(Variant::OBJECT,"state:Physics2DDirectBodyState")));
ADD_PROPERTY( PropertyInfo(Variant::INT,"mode",PROPERTY_HINT_ENUM,"Rigid,Static,Character,Kinematic"),_SCS("set_mode"),_SCS("get_mode"));
diff --git a/scene/2d/physics_body_2d.h b/scene/2d/physics_body_2d.h
index 77e909f105..ca7b757497 100644
--- a/scene/2d/physics_body_2d.h
+++ b/scene/2d/physics_body_2d.h
@@ -229,6 +229,8 @@ public:
void set_applied_force(const Vector2& p_force);
Vector2 get_applied_force() const;
+ Array get_colliding_bodies() const; //function for script
+
RigidBody2D();
~RigidBody2D();
diff --git a/scene/3d/area.cpp b/scene/3d/area.cpp
index 407747fc0d..cb1df78fda 100644
--- a/scene/3d/area.cpp
+++ b/scene/3d/area.cpp
@@ -255,6 +255,24 @@ bool Area::is_monitoring_enabled() const {
}
+Array Area::get_overlapping_bodies() const {
+
+ ERR_FAIL_COND_V(!monitoring,Array());
+ Array ret;
+ ret.resize(body_map.size());
+ int idx=0;
+ for (const Map<ObjectID,BodyState>::Element *E=body_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;
+}
void Area::_bind_methods() {
@@ -283,6 +301,8 @@ void Area::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_enable_monitoring","enable"),&Area::set_enable_monitoring);
ObjectTypeDB::bind_method(_MD("is_monitoring_enabled"),&Area::is_monitoring_enabled);
+ ObjectTypeDB::bind_method(_MD("get_overlapping_bodies"),&Area::get_overlapping_bodies);
+
ObjectTypeDB::bind_method(_MD("_body_inout"),&Area::_body_inout);
diff --git a/scene/3d/area.h b/scene/3d/area.h
index 96b8585338..4707b73e1c 100644
--- a/scene/3d/area.h
+++ b/scene/3d/area.h
@@ -112,6 +112,8 @@ public:
void set_enable_monitoring(bool p_enable);
bool is_monitoring_enabled() const;
+ Array get_overlapping_bodies() const;
+
Area();
~Area();
diff --git a/scene/3d/physics_body.cpp b/scene/3d/physics_body.cpp
index a80fdce64c..21ecac6e3d 100644
--- a/scene/3d/physics_body.cpp
+++ b/scene/3d/physics_body.cpp
@@ -637,6 +637,27 @@ RigidBody::AxisLock RigidBody::get_axis_lock() const {
}
+Array RigidBody::get_colliding_bodies() const {
+
+ ERR_FAIL_COND_V(!contact_monitor,Array());
+
+ Array ret;
+ ret.resize(contact_monitor->body_map.size());
+ int idx=0;
+ for (const Map<ObjectID,BodyState>::Element *E=contact_monitor->body_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;
+}
+
+
void RigidBody::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_mode","mode"),&RigidBody::set_mode);
@@ -688,6 +709,8 @@ void RigidBody::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_axis_lock","axis_lock"),&RigidBody::set_axis_lock);
ObjectTypeDB::bind_method(_MD("get_axis_lock"),&RigidBody::get_axis_lock);
+ ObjectTypeDB::bind_method(_MD("get_colliding_bodies"),&RigidBody::get_colliding_bodies);
+
BIND_VMETHOD(MethodInfo("_integrate_forces",PropertyInfo(Variant::OBJECT,"state:PhysicsDirectBodyState")));
ADD_PROPERTY( PropertyInfo(Variant::INT,"mode",PROPERTY_HINT_ENUM,"Rigid,Static,Character,Kinematic"),_SCS("set_mode"),_SCS("get_mode"));
diff --git a/scene/3d/physics_body.h b/scene/3d/physics_body.h
index f9f028e20d..0d1de7f236 100644
--- a/scene/3d/physics_body.h
+++ b/scene/3d/physics_body.h
@@ -236,6 +236,7 @@ public:
void set_axis_lock(AxisLock p_lock);
AxisLock get_axis_lock() const;
+ Array get_colliding_bodies() const;
void apply_impulse(const Vector3& p_pos, const Vector3& p_impulse);