diff options
author | Juan Linietsky <reduzio@gmail.com> | 2014-11-13 00:53:12 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2014-11-13 00:53:12 -0300 |
commit | abbea4d945bbb1114570c3b6c7f649e01ca8ebb8 (patch) | |
tree | d2b131b32705bbcf118efa72d5d9a21618c1227e /scene/2d | |
parent | d02953c5963ca080d26500ea8250e0632a80b234 (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/2d')
-rw-r--r-- | scene/2d/area_2d.cpp | 21 | ||||
-rw-r--r-- | scene/2d/area_2d.h | 2 | ||||
-rw-r--r-- | scene/2d/physics_body_2d.cpp | 22 | ||||
-rw-r--r-- | scene/2d/physics_body_2d.h | 2 |
4 files changed, 47 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(); |