2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* area_sw.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2018-01-01 14:40:08 +01:00
|
|
|
/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
|
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. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#ifndef AREA_SW_H
|
|
|
|
#define AREA_SW_H
|
|
|
|
|
|
|
|
#include "collision_object_sw.h"
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/self_list.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "servers/physics_server.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
//#include "servers/physics/query_sw.h"
|
|
|
|
|
|
|
|
class SpaceSW;
|
|
|
|
class BodySW;
|
|
|
|
class ConstraintSW;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
class AreaSW : public CollisionObjectSW {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
PhysicsServer::AreaSpaceOverrideMode space_override_mode;
|
2017-02-14 00:25:05 +01:00
|
|
|
real_t gravity;
|
2014-02-10 02:10:30 +01:00
|
|
|
Vector3 gravity_vector;
|
|
|
|
bool gravity_is_point;
|
2017-02-14 00:25:05 +01:00
|
|
|
real_t gravity_distance_scale;
|
|
|
|
real_t point_attenuation;
|
|
|
|
real_t linear_damp;
|
|
|
|
real_t angular_damp;
|
2014-02-10 02:10:30 +01:00
|
|
|
int priority;
|
2015-06-12 20:52:21 +02:00
|
|
|
bool monitorable;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
ObjectID monitor_callback_id;
|
|
|
|
StringName monitor_callback_method;
|
|
|
|
|
2015-06-12 20:52:21 +02:00
|
|
|
ObjectID area_monitor_callback_id;
|
|
|
|
StringName area_monitor_callback_method;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
SelfList<AreaSW> monitor_query_list;
|
|
|
|
SelfList<AreaSW> moved_list;
|
|
|
|
|
|
|
|
struct BodyKey {
|
|
|
|
|
|
|
|
RID rid;
|
|
|
|
ObjectID instance_id;
|
|
|
|
uint32_t body_shape;
|
|
|
|
uint32_t area_shape;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_FORCE_INLINE_ bool operator<(const BodyKey &p_key) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (rid == p_key.rid) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (body_shape == p_key.body_shape) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return area_shape < p_key.area_shape;
|
|
|
|
} else
|
2014-09-03 04:13:40 +02:00
|
|
|
return body_shape < p_key.body_shape;
|
2014-02-10 02:10:30 +01:00
|
|
|
} else
|
|
|
|
return rid < p_key.rid;
|
|
|
|
}
|
|
|
|
|
|
|
|
_FORCE_INLINE_ BodyKey() {}
|
2017-03-05 16:44:50 +01:00
|
|
|
BodyKey(BodySW *p_body, uint32_t p_body_shape, uint32_t p_area_shape);
|
|
|
|
BodyKey(AreaSW *p_body, uint32_t p_body_shape, uint32_t p_area_shape);
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct BodyState {
|
|
|
|
|
|
|
|
int state;
|
|
|
|
_FORCE_INLINE_ void inc() { state++; }
|
|
|
|
_FORCE_INLINE_ void dec() { state--; }
|
2017-03-05 16:44:50 +01:00
|
|
|
_FORCE_INLINE_ BodyState() { state = 0; }
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<BodyKey, BodyState> monitored_bodies;
|
|
|
|
Map<BodyKey, BodyState> monitored_areas;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
//virtual void shape_changed_notify(ShapeSW *p_shape);
|
|
|
|
//virtual void shape_deleted_notify(ShapeSW *p_shape);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Set<ConstraintSW *> constraints;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
virtual void _shapes_changed();
|
|
|
|
void _queue_monitor_update();
|
|
|
|
|
|
|
|
public:
|
|
|
|
//_FORCE_INLINE_ const Transform& get_inverse_transform() const { return inverse_transform; }
|
|
|
|
//_FORCE_INLINE_ SpaceSW* get_owner() { return owner; }
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_monitor_callback(ObjectID p_id, const StringName &p_method);
|
2014-02-10 02:10:30 +01:00
|
|
|
_FORCE_INLINE_ bool has_monitor_callback() const { return monitor_callback_id; }
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_area_monitor_callback(ObjectID p_id, const StringName &p_method);
|
2015-06-12 20:52:21 +02:00
|
|
|
_FORCE_INLINE_ bool has_area_monitor_callback() const { return area_monitor_callback_id; }
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_FORCE_INLINE_ void add_body_to_query(BodySW *p_body, uint32_t p_body_shape, uint32_t p_area_shape);
|
|
|
|
_FORCE_INLINE_ void remove_body_from_query(BodySW *p_body, uint32_t p_body_shape, uint32_t p_area_shape);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_FORCE_INLINE_ void add_area_to_query(AreaSW *p_area, uint32_t p_area_shape, uint32_t p_self_shape);
|
|
|
|
_FORCE_INLINE_ void remove_area_from_query(AreaSW *p_area, uint32_t p_area_shape, uint32_t p_self_shape);
|
2015-06-12 20:52:21 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_param(PhysicsServer::AreaParameter p_param, const Variant &p_value);
|
2014-02-10 02:10:30 +01:00
|
|
|
Variant get_param(PhysicsServer::AreaParameter p_param) const;
|
|
|
|
|
|
|
|
void set_space_override_mode(PhysicsServer::AreaSpaceOverrideMode p_mode);
|
|
|
|
PhysicsServer::AreaSpaceOverrideMode get_space_override_mode() const { return space_override_mode; }
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_FORCE_INLINE_ void set_gravity(real_t p_gravity) { gravity = p_gravity; }
|
2017-02-14 00:25:05 +01:00
|
|
|
_FORCE_INLINE_ real_t get_gravity() const { return gravity; }
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_FORCE_INLINE_ void set_gravity_vector(const Vector3 &p_gravity) { gravity_vector = p_gravity; }
|
2014-02-10 02:10:30 +01:00
|
|
|
_FORCE_INLINE_ Vector3 get_gravity_vector() const { return gravity_vector; }
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_FORCE_INLINE_ void set_gravity_as_point(bool p_enable) { gravity_is_point = p_enable; }
|
2014-02-10 02:10:30 +01:00
|
|
|
_FORCE_INLINE_ bool is_gravity_point() const { return gravity_is_point; }
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_FORCE_INLINE_ void set_gravity_distance_scale(real_t scale) { gravity_distance_scale = scale; }
|
2017-02-14 00:25:05 +01:00
|
|
|
_FORCE_INLINE_ real_t get_gravity_distance_scale() const { return gravity_distance_scale; }
|
2015-03-19 15:10:07 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_FORCE_INLINE_ void set_point_attenuation(real_t p_point_attenuation) { point_attenuation = p_point_attenuation; }
|
2017-02-14 00:25:05 +01:00
|
|
|
_FORCE_INLINE_ real_t get_point_attenuation() const { return point_attenuation; }
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_FORCE_INLINE_ void set_linear_damp(real_t p_linear_damp) { linear_damp = p_linear_damp; }
|
2017-02-14 00:25:05 +01:00
|
|
|
_FORCE_INLINE_ real_t get_linear_damp() const { return linear_damp; }
|
2015-08-30 23:57:17 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_FORCE_INLINE_ void set_angular_damp(real_t p_angular_damp) { angular_damp = p_angular_damp; }
|
2017-02-14 00:25:05 +01:00
|
|
|
_FORCE_INLINE_ real_t get_angular_damp() const { return angular_damp; }
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_FORCE_INLINE_ void set_priority(int p_priority) { priority = p_priority; }
|
2014-02-10 02:10:30 +01:00
|
|
|
_FORCE_INLINE_ int get_priority() const { return priority; }
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_FORCE_INLINE_ void add_constraint(ConstraintSW *p_constraint) { constraints.insert(p_constraint); }
|
|
|
|
_FORCE_INLINE_ void remove_constraint(ConstraintSW *p_constraint) { constraints.erase(p_constraint); }
|
|
|
|
_FORCE_INLINE_ const Set<ConstraintSW *> &get_constraints() const { return constraints; }
|
2017-07-25 04:26:47 +02:00
|
|
|
_FORCE_INLINE_ void clear_constraints() { constraints.clear(); }
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-06-12 20:52:21 +02:00
|
|
|
void set_monitorable(bool p_monitorable);
|
|
|
|
_FORCE_INLINE_ bool is_monitorable() const { return monitorable; }
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_transform(const Transform &p_transform);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
void set_space(SpaceSW *p_space);
|
|
|
|
|
|
|
|
void call_queries();
|
|
|
|
|
|
|
|
AreaSW();
|
|
|
|
~AreaSW();
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void AreaSW::add_body_to_query(BodySW *p_body, uint32_t p_body_shape, uint32_t p_area_shape) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
BodyKey bk(p_body, p_body_shape, p_area_shape);
|
2014-02-10 02:10:30 +01:00
|
|
|
monitored_bodies[bk].inc();
|
|
|
|
if (!monitor_query_list.in_list())
|
|
|
|
_queue_monitor_update();
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
void AreaSW::remove_body_from_query(BodySW *p_body, uint32_t p_body_shape, uint32_t p_area_shape) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
BodyKey bk(p_body, p_body_shape, p_area_shape);
|
2014-02-10 02:10:30 +01:00
|
|
|
monitored_bodies[bk].dec();
|
|
|
|
if (!monitor_query_list.in_list())
|
|
|
|
_queue_monitor_update();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void AreaSW::add_area_to_query(AreaSW *p_area, uint32_t p_area_shape, uint32_t p_self_shape) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
BodyKey bk(p_area, p_area_shape, p_self_shape);
|
2015-06-12 20:52:21 +02:00
|
|
|
monitored_areas[bk].inc();
|
|
|
|
if (!monitor_query_list.in_list())
|
|
|
|
_queue_monitor_update();
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
void AreaSW::remove_area_from_query(AreaSW *p_area, uint32_t p_area_shape, uint32_t p_self_shape) {
|
2015-06-12 20:52:21 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
BodyKey bk(p_area, p_area_shape, p_self_shape);
|
2015-06-12 20:52:21 +02:00
|
|
|
monitored_areas[bk].dec();
|
|
|
|
if (!monitor_query_list.in_list())
|
|
|
|
_queue_monitor_update();
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#endif // AREA__SW_H
|