diff options
author | Juan Linietsky <reduzio@gmail.com> | 2015-06-13 22:14:36 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2015-06-13 22:14:36 -0300 |
commit | edf1f271180a8e2481ebb3d7808f47493e5ad13e (patch) | |
tree | 56bd486d23eb353e4bcf3090a23878f37767ce28 /servers/physics/area_sw.cpp | |
parent | 9a58960d288b0c68c34f296dd97d0134fa1e5f02 (diff) | |
parent | 4e46143499be0e40ae29eff550cbeec4ebde3d85 (diff) |
Merge branch 'master' of https://github.com/okamstudio/godot
Diffstat (limited to 'servers/physics/area_sw.cpp')
-rw-r--r-- | servers/physics/area_sw.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/servers/physics/area_sw.cpp b/servers/physics/area_sw.cpp index aa1c530221..83be80f816 100644 --- a/servers/physics/area_sw.cpp +++ b/servers/physics/area_sw.cpp @@ -31,6 +31,7 @@ #include "body_sw.h" AreaSW::BodyKey::BodyKey(BodySW *p_body, uint32_t p_body_shape,uint32_t p_area_shape) { rid=p_body->get_self(); instance_id=p_body->get_instance_id(); body_shape=p_body_shape; area_shape=p_area_shape; } +AreaSW::BodyKey::BodyKey(AreaSW *p_body, uint32_t p_body_shape,uint32_t p_area_shape) { rid=p_body->get_self(); instance_id=p_body->get_instance_id(); body_shape=p_body_shape; area_shape=p_area_shape; } void AreaSW::_shapes_changed() { @@ -57,6 +58,7 @@ void AreaSW::set_space(SpaceSW *p_space) { } monitored_bodies.clear(); + monitored_areas.clear(); _set_space(p_space); } @@ -76,11 +78,32 @@ void AreaSW::set_monitor_callback(ObjectID p_id, const StringName& p_method) { monitor_callback_method=p_method; monitored_bodies.clear(); + monitored_areas.clear(); + _shape_changed(); } +void AreaSW::set_area_monitor_callback(ObjectID p_id, const StringName& p_method) { + + + if (p_id==area_monitor_callback_id) { + area_monitor_callback_method=p_method; + return; + } + + _unregister_shapes(); + + area_monitor_callback_id=p_id; + area_monitor_callback_method=p_method; + + monitored_bodies.clear(); + monitored_areas.clear(); + + _shape_changed(); + +} void AreaSW::set_space_override_mode(PhysicsServer::AreaSpaceOverrideMode p_mode) { @@ -134,6 +157,15 @@ void AreaSW::_queue_monitor_update() { } +void AreaSW::set_monitorable(bool p_monitorable) { + + if (monitorable==p_monitorable) + return; + + monitorable=p_monitorable; + _set_static(!monitorable); +} + void AreaSW::call_queries() { if (monitor_callback_id && !monitored_bodies.empty()) { @@ -168,6 +200,41 @@ void AreaSW::call_queries() { monitored_bodies.clear(); + if (area_monitor_callback_id && !monitored_areas.empty()) { + + + Variant res[5]; + Variant *resptr[5]; + for(int i=0;i<5;i++) + resptr[i]=&res[i]; + + Object *obj = ObjectDB::get_instance(area_monitor_callback_id); + if (!obj) { + monitored_areas.clear(); + area_monitor_callback_id=0; + return; + } + + + + for (Map<BodyKey,BodyState>::Element *E=monitored_areas.front();E;E=E->next()) { + + if (E->get().state==0) + continue; //nothing happened + + res[0]=E->get().state>0 ? PhysicsServer::AREA_BODY_ADDED : PhysicsServer::AREA_BODY_REMOVED; + res[1]=E->key().rid; + res[2]=E->key().instance_id; + res[3]=E->key().body_shape; + res[4]=E->key().area_shape; + + + Variant::CallError ce; + obj->call(area_monitor_callback_method,(const Variant**)resptr,5,ce); + } + } + + monitored_areas.clear(); //get_space()->area_remove_from_monitor_query_list(&monitor_query_list); } @@ -185,6 +252,8 @@ AreaSW::AreaSW() : CollisionObjectSW(TYPE_AREA), monitor_query_list(this), move priority=0; set_ray_pickable(false); monitor_callback_id=0; + area_monitor_callback_id=0; + monitorable=false; } |