2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* area.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2015-04-18 19:38:54 +02:00
|
|
|
/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#include "area.h"
|
|
|
|
#include "scene/scene_string_names.h"
|
|
|
|
#include "servers/physics_server.h"
|
|
|
|
void Area::set_space_override_mode(SpaceOverride p_mode) {
|
|
|
|
|
|
|
|
space_override=p_mode;
|
|
|
|
PhysicsServer::get_singleton()->area_set_space_override_mode(get_rid(),PhysicsServer::AreaSpaceOverrideMode(p_mode));
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
Area::SpaceOverride Area::get_space_override_mode() const{
|
|
|
|
|
|
|
|
return space_override;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Area::set_gravity_is_point(bool p_enabled){
|
2015-04-29 18:06:25 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
gravity_is_point=p_enabled;
|
|
|
|
PhysicsServer::get_singleton()->area_set_param(get_rid(),PhysicsServer::AREA_PARAM_GRAVITY_IS_POINT,p_enabled);
|
|
|
|
|
|
|
|
}
|
|
|
|
bool Area::is_gravity_a_point() const{
|
|
|
|
|
|
|
|
return gravity_is_point;
|
|
|
|
}
|
|
|
|
|
2015-03-19 15:10:07 +01:00
|
|
|
void Area::set_gravity_distance_scale(real_t p_scale){
|
|
|
|
|
|
|
|
gravity_distance_scale=p_scale;
|
|
|
|
PhysicsServer::get_singleton()->area_set_param(get_rid(),PhysicsServer::AREA_PARAM_GRAVITY_DISTANCE_SCALE,p_scale);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
real_t Area::get_gravity_distance_scale() const{
|
|
|
|
return gravity_distance_scale;
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void Area::set_gravity_vector(const Vector3& p_vec){
|
|
|
|
|
|
|
|
gravity_vec=p_vec;
|
|
|
|
PhysicsServer::get_singleton()->area_set_param(get_rid(),PhysicsServer::AREA_PARAM_GRAVITY_VECTOR,p_vec);
|
|
|
|
|
|
|
|
}
|
|
|
|
Vector3 Area::get_gravity_vector() const{
|
|
|
|
|
|
|
|
return gravity_vec;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Area::set_gravity(real_t p_gravity){
|
|
|
|
|
|
|
|
gravity=p_gravity;
|
|
|
|
PhysicsServer::get_singleton()->area_set_param(get_rid(),PhysicsServer::AREA_PARAM_GRAVITY,p_gravity);
|
|
|
|
}
|
|
|
|
real_t Area::get_gravity() const{
|
|
|
|
|
|
|
|
return gravity;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Area::set_density(real_t p_density){
|
|
|
|
|
|
|
|
density=p_density;
|
|
|
|
PhysicsServer::get_singleton()->area_set_param(get_rid(),PhysicsServer::AREA_PARAM_DENSITY,p_density);
|
|
|
|
}
|
|
|
|
real_t Area::get_density() const{
|
|
|
|
|
|
|
|
return density;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Area::set_priority(real_t p_priority){
|
|
|
|
|
|
|
|
priority=p_priority;
|
|
|
|
PhysicsServer::get_singleton()->area_set_param(get_rid(),PhysicsServer::AREA_PARAM_PRIORITY,p_priority);
|
|
|
|
}
|
|
|
|
real_t Area::get_priority() const{
|
|
|
|
|
|
|
|
return priority;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-06 01:20:42 +01:00
|
|
|
void Area::_body_enter_tree(ObjectID p_id) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Object *obj = ObjectDB::get_instance(p_id);
|
|
|
|
Node *node = obj ? obj->cast_to<Node>() : NULL;
|
|
|
|
ERR_FAIL_COND(!node);
|
|
|
|
|
|
|
|
Map<ObjectID,BodyState>::Element *E=body_map.find(p_id);
|
|
|
|
ERR_FAIL_COND(!E);
|
2014-11-06 01:20:42 +01:00
|
|
|
ERR_FAIL_COND(E->get().in_tree);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2014-11-06 01:20:42 +01:00
|
|
|
E->get().in_tree=true;
|
2014-02-10 02:10:30 +01:00
|
|
|
emit_signal(SceneStringNames::get_singleton()->body_enter,node);
|
|
|
|
for(int i=0;i<E->get().shapes.size();i++) {
|
|
|
|
|
|
|
|
emit_signal(SceneStringNames::get_singleton()->body_enter_shape,p_id,node,E->get().shapes[i].body_shape,E->get().shapes[i].area_shape);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-11-06 01:20:42 +01:00
|
|
|
void Area::_body_exit_tree(ObjectID p_id) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2014-12-07 06:04:20 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
Object *obj = ObjectDB::get_instance(p_id);
|
|
|
|
Node *node = obj ? obj->cast_to<Node>() : NULL;
|
|
|
|
ERR_FAIL_COND(!node);
|
|
|
|
Map<ObjectID,BodyState>::Element *E=body_map.find(p_id);
|
|
|
|
ERR_FAIL_COND(!E);
|
2014-11-06 01:20:42 +01:00
|
|
|
ERR_FAIL_COND(!E->get().in_tree);
|
|
|
|
E->get().in_tree=false;
|
2014-02-10 02:10:30 +01:00
|
|
|
emit_signal(SceneStringNames::get_singleton()->body_exit,node);
|
|
|
|
for(int i=0;i<E->get().shapes.size();i++) {
|
|
|
|
|
|
|
|
emit_signal(SceneStringNames::get_singleton()->body_exit_shape,p_id,node,E->get().shapes[i].body_shape,E->get().shapes[i].area_shape);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Area::_body_inout(int p_status,const RID& p_body, int p_instance, int p_body_shape,int p_area_shape) {
|
|
|
|
|
2014-12-07 06:04:20 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
bool body_in = p_status==PhysicsServer::AREA_BODY_ADDED;
|
|
|
|
ObjectID objid=p_instance;
|
|
|
|
|
|
|
|
Object *obj = ObjectDB::get_instance(objid);
|
|
|
|
Node *node = obj ? obj->cast_to<Node>() : NULL;
|
|
|
|
|
|
|
|
Map<ObjectID,BodyState>::Element *E=body_map.find(objid);
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!body_in && !E);
|
|
|
|
|
2014-12-07 06:04:20 +01:00
|
|
|
locked=true;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
if (body_in) {
|
|
|
|
if (!E) {
|
|
|
|
|
|
|
|
E = body_map.insert(objid,BodyState());
|
|
|
|
E->get().rc=0;
|
2014-11-06 01:20:42 +01:00
|
|
|
E->get().in_tree=node && node->is_inside_tree();
|
2014-02-10 02:10:30 +01:00
|
|
|
if (node) {
|
2014-11-06 01:20:42 +01:00
|
|
|
node->connect(SceneStringNames::get_singleton()->enter_tree,this,SceneStringNames::get_singleton()->_body_enter_tree,make_binds(objid));
|
|
|
|
node->connect(SceneStringNames::get_singleton()->exit_tree,this,SceneStringNames::get_singleton()->_body_exit_tree,make_binds(objid));
|
|
|
|
if (E->get().in_tree) {
|
2014-02-10 02:10:30 +01:00
|
|
|
emit_signal(SceneStringNames::get_singleton()->body_enter,node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
E->get().rc++;
|
|
|
|
if (node)
|
|
|
|
E->get().shapes.insert(ShapePair(p_body_shape,p_area_shape));
|
|
|
|
|
|
|
|
|
2014-11-06 01:20:42 +01:00
|
|
|
if (E->get().in_tree) {
|
2014-02-10 02:10:30 +01:00
|
|
|
emit_signal(SceneStringNames::get_singleton()->body_enter_shape,objid,node,p_body_shape,p_area_shape);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
E->get().rc--;
|
|
|
|
|
|
|
|
if (node)
|
|
|
|
E->get().shapes.erase(ShapePair(p_body_shape,p_area_shape));
|
|
|
|
|
|
|
|
bool eraseit=false;
|
|
|
|
|
|
|
|
if (E->get().rc==0) {
|
|
|
|
|
|
|
|
if (node) {
|
2014-11-06 01:20:42 +01:00
|
|
|
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);
|
|
|
|
if (E->get().in_tree)
|
2014-02-10 02:10:30 +01:00
|
|
|
emit_signal(SceneStringNames::get_singleton()->body_exit,obj);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
eraseit=true;
|
|
|
|
|
|
|
|
}
|
2014-11-06 01:20:42 +01:00
|
|
|
if (node && E->get().in_tree) {
|
2014-02-10 02:10:30 +01:00
|
|
|
emit_signal(SceneStringNames::get_singleton()->body_exit_shape,objid,obj,p_body_shape,p_area_shape);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eraseit)
|
|
|
|
body_map.erase(E);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-12-07 06:04:20 +01:00
|
|
|
locked=false;
|
|
|
|
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Area::_clear_monitoring() {
|
|
|
|
|
2014-12-07 06:04:20 +01:00
|
|
|
if (locked) {
|
|
|
|
ERR_EXPLAIN("This function can't be used during the in/out signal.");
|
|
|
|
}
|
|
|
|
ERR_FAIL_COND(locked);
|
|
|
|
|
2015-06-12 20:52:21 +02:00
|
|
|
{
|
|
|
|
Map<ObjectID,BodyState> bmcopy = body_map;
|
|
|
|
body_map.clear();
|
|
|
|
//disconnect all monitored stuff
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-06-12 20:52:21 +02:00
|
|
|
for (Map<ObjectID,BodyState>::Element *E=bmcopy.front();E;E=E->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-06-12 20:52:21 +02:00
|
|
|
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++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-06-12 20:52:21 +02:00
|
|
|
emit_signal(SceneStringNames::get_singleton()->body_exit_shape,E->key(),node,E->get().shapes[i].body_shape,E->get().shapes[i].area_shape);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-06-12 20:52:21 +02:00
|
|
|
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);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2015-06-12 20:52:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
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++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-06-12 20:52:21 +02:00
|
|
|
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);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
void Area::_notification(int p_what) {
|
|
|
|
|
2014-11-06 01:20:42 +01:00
|
|
|
if (p_what==NOTIFICATION_EXIT_TREE) {
|
2014-02-10 02:10:30 +01:00
|
|
|
_clear_monitoring();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Area::set_enable_monitoring(bool p_enable) {
|
|
|
|
|
2014-12-07 06:04:20 +01:00
|
|
|
if (locked) {
|
|
|
|
ERR_EXPLAIN("This function can't be used during the in/out signal.");
|
|
|
|
}
|
|
|
|
ERR_FAIL_COND(locked);
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
if (p_enable==monitoring)
|
|
|
|
return;
|
|
|
|
|
|
|
|
monitoring=p_enable;
|
|
|
|
|
|
|
|
if (monitoring) {
|
|
|
|
|
2015-06-29 05:29:49 +02:00
|
|
|
PhysicsServer::get_singleton()->area_set_monitor_callback(get_rid(),this,SceneStringNames::get_singleton()->_body_inout);
|
|
|
|
PhysicsServer::get_singleton()->area_set_area_monitor_callback(get_rid(),this,SceneStringNames::get_singleton()->_area_inout);
|
2014-02-10 02:10:30 +01:00
|
|
|
} else {
|
|
|
|
PhysicsServer::get_singleton()->area_set_monitor_callback(get_rid(),NULL,StringName());
|
2015-06-12 20:52:21 +02:00
|
|
|
PhysicsServer::get_singleton()->area_set_area_monitor_callback(get_rid(),NULL,StringName());
|
2014-02-10 02:10:30 +01:00
|
|
|
_clear_monitoring();
|
2015-06-12 20:52:21 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Area::_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 Area::_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);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2015-06-12 20:52:21 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Area::_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==PhysicsServer::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;
|
|
|
|
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Area::is_monitoring_enabled() const {
|
|
|
|
|
|
|
|
return monitoring;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-13 04:53:12 +01:00
|
|
|
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;
|
|
|
|
}
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2015-06-12 20:52:21 +02:00
|
|
|
void Area::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;
|
|
|
|
|
|
|
|
PhysicsServer::get_singleton()->area_set_monitorable(get_rid(),monitorable);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Area::is_monitorable() const {
|
|
|
|
|
|
|
|
return monitorable;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Array Area::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 Area::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 Area::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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void Area::_bind_methods() {
|
|
|
|
|
2014-11-06 01:20:42 +01:00
|
|
|
ObjectTypeDB::bind_method(_MD("_body_enter_tree","id"),&Area::_body_enter_tree);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_body_exit_tree","id"),&Area::_body_exit_tree);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-06-12 20:52:21 +02:00
|
|
|
ObjectTypeDB::bind_method(_MD("_area_enter_tree","id"),&Area::_area_enter_tree);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_area_exit_tree","id"),&Area::_area_exit_tree);
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
ObjectTypeDB::bind_method(_MD("set_space_override_mode","enable"),&Area::set_space_override_mode);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_space_override_mode"),&Area::get_space_override_mode);
|
|
|
|
|
|
|
|
ObjectTypeDB::bind_method(_MD("set_gravity_is_point","enable"),&Area::set_gravity_is_point);
|
|
|
|
ObjectTypeDB::bind_method(_MD("is_gravity_a_point"),&Area::is_gravity_a_point);
|
|
|
|
|
2015-03-19 15:10:07 +01:00
|
|
|
ObjectTypeDB::bind_method(_MD("set_gravity_distance_scale","distance_scale"),&Area::set_gravity_distance_scale);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_gravity_distance_scale"),&Area::get_gravity_distance_scale);
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
ObjectTypeDB::bind_method(_MD("set_gravity_vector","vector"),&Area::set_gravity_vector);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_gravity_vector"),&Area::get_gravity_vector);
|
|
|
|
|
|
|
|
ObjectTypeDB::bind_method(_MD("set_gravity","gravity"),&Area::set_gravity);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_gravity"),&Area::get_gravity);
|
|
|
|
|
|
|
|
ObjectTypeDB::bind_method(_MD("set_density","density"),&Area::set_density);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_density"),&Area::get_density);
|
|
|
|
|
|
|
|
ObjectTypeDB::bind_method(_MD("set_priority","priority"),&Area::set_priority);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_priority"),&Area::get_priority);
|
|
|
|
|
2015-06-12 20:52:21 +02:00
|
|
|
ObjectTypeDB::bind_method(_MD("set_monitorable","enable"),&Area::set_monitorable);
|
|
|
|
ObjectTypeDB::bind_method(_MD("is_monitorable"),&Area::is_monitorable);
|
|
|
|
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
ObjectTypeDB::bind_method(_MD("set_enable_monitoring","enable"),&Area::set_enable_monitoring);
|
|
|
|
ObjectTypeDB::bind_method(_MD("is_monitoring_enabled"),&Area::is_monitoring_enabled);
|
|
|
|
|
2014-11-13 04:53:12 +01:00
|
|
|
ObjectTypeDB::bind_method(_MD("get_overlapping_bodies"),&Area::get_overlapping_bodies);
|
2015-06-12 20:52:21 +02:00
|
|
|
ObjectTypeDB::bind_method(_MD("get_overlapping_areas"),&Area::get_overlapping_areas);
|
|
|
|
|
|
|
|
ObjectTypeDB::bind_method(_MD("overlaps_body:PhysicsBody","body"),&Area::overlaps_body);
|
|
|
|
ObjectTypeDB::bind_method(_MD("overlaps_area:Area","area"),&Area::overlaps_area);
|
2014-11-13 04:53:12 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
ObjectTypeDB::bind_method(_MD("_body_inout"),&Area::_body_inout);
|
2015-06-12 20:52:21 +02:00
|
|
|
ObjectTypeDB::bind_method(_MD("_area_inout"),&Area::_area_inout);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
|
|
|
|
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")));
|
|
|
|
|
2015-06-12 20:52:21 +02:00
|
|
|
ADD_SIGNAL( MethodInfo("area_enter_shape",PropertyInfo(Variant::INT,"area_id"),PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area"),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,"Area"),PropertyInfo(Variant::INT,"area_shape"),PropertyInfo(Variant::INT,"area_shape")));
|
|
|
|
ADD_SIGNAL( MethodInfo("area_enter",PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area")));
|
|
|
|
ADD_SIGNAL( MethodInfo("area_exit",PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area")));
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
ADD_PROPERTY( 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"));
|
2015-03-19 15:10:07 +01:00
|
|
|
ADD_PROPERTY( PropertyInfo(Variant::REAL,"gravity_distance_scale", PROPERTY_HINT_RANGE,"0,1024,0.001"),_SCS("set_gravity_distance_scale"),_SCS("get_gravity_distance_scale"));
|
2014-02-10 02:10:30 +01:00
|
|
|
ADD_PROPERTY( PropertyInfo(Variant::VECTOR3,"gravity_vec"),_SCS("set_gravity_vector"),_SCS("get_gravity_vector"));
|
|
|
|
ADD_PROPERTY( PropertyInfo(Variant::REAL,"gravity",PROPERTY_HINT_RANGE,"-1024,1024,0.01"),_SCS("set_gravity"),_SCS("get_gravity"));
|
|
|
|
ADD_PROPERTY( PropertyInfo(Variant::REAL,"density",PROPERTY_HINT_RANGE,"0,1024,0.001"),_SCS("set_density"),_SCS("get_density"));
|
|
|
|
ADD_PROPERTY( 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"));
|
2015-06-12 20:52:21 +02:00
|
|
|
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"monitorable"),_SCS("set_monitorable"),_SCS("is_monitorable"));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Area::Area() : CollisionObject(PhysicsServer::get_singleton()->area_create(),true) {
|
|
|
|
|
|
|
|
space_override=SPACE_OVERRIDE_DISABLED;
|
|
|
|
set_gravity(9.8);;
|
2014-12-07 06:04:20 +01:00
|
|
|
locked=false;
|
2014-02-10 02:10:30 +01:00
|
|
|
set_gravity_vector(Vector3(0,-1,0));
|
|
|
|
gravity_is_point=false;
|
2015-03-19 15:10:07 +01:00
|
|
|
gravity_distance_scale=0;
|
2014-02-10 02:10:30 +01:00
|
|
|
density=0.1;
|
|
|
|
priority=0;
|
|
|
|
monitoring=false;
|
2014-10-03 05:10:51 +02:00
|
|
|
set_ray_pickable(false);
|
2014-09-15 16:33:30 +02:00
|
|
|
set_enable_monitoring(true);
|
2015-06-12 20:52:21 +02:00
|
|
|
set_monitorable(true);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Area::~Area() {
|
|
|
|
|
|
|
|
|
|
|
|
}
|