summaryrefslogtreecommitdiff
path: root/modules/bullet/collision_object_bullet.h
diff options
context:
space:
mode:
Diffstat (limited to 'modules/bullet/collision_object_bullet.h')
-rw-r--r--modules/bullet/collision_object_bullet.h50
1 files changed, 36 insertions, 14 deletions
diff --git a/modules/bullet/collision_object_bullet.h b/modules/bullet/collision_object_bullet.h
index f1423a69e4..920d80af23 100644
--- a/modules/bullet/collision_object_bullet.h
+++ b/modules/bullet/collision_object_bullet.h
@@ -31,6 +31,7 @@
#ifndef COLLISION_OBJECT_BULLET_H
#define COLLISION_OBJECT_BULLET_H
+#include "core/local_vector.h"
#include "core/math/transform.h"
#include "core/math/vector3.h"
#include "core/object.h"
@@ -70,11 +71,12 @@ public:
struct ShapeWrapper {
ShapeBullet *shape = nullptr;
- btCollisionShape *bt_shape = nullptr;
btTransform transform;
btVector3 scale;
bool active = true;
+ btCollisionShape *bt_shape = nullptr;
+ public:
ShapeWrapper() {}
ShapeWrapper(ShapeBullet *p_shape, const btTransform &p_transform, bool p_active) :
@@ -107,6 +109,7 @@ public:
btTransform get_adjusted_transform() const;
void claim_bt_shape(const btVector3 &body_scale);
+ void release_bt_shape();
};
protected:
@@ -124,13 +127,20 @@ protected:
VSet<RID> exceptions;
+ bool needs_body_reload = true;
+ bool needs_collision_filters_reload = true;
+
/// This array is used to know all areas where this Object is overlapped in
/// New area is added when overlap with new area (AreaBullet::addOverlap), then is removed when it exit (CollisionObjectBullet::onExitArea)
/// This array is used mainly to know which area hold the pointer of this object
- Vector<AreaBullet *> areasOverlapped;
+ LocalVector<AreaBullet *> areasOverlapped;
bool isTransformChanged = false;
public:
+ bool is_in_world = false;
+ bool is_in_flush_queue = false;
+
+public:
CollisionObjectBullet(Type p_type);
virtual ~CollisionObjectBullet();
@@ -164,7 +174,7 @@ public:
_FORCE_INLINE_ void set_collision_layer(uint32_t p_layer) {
if (collisionLayer != p_layer) {
collisionLayer = p_layer;
- on_collision_filters_change();
+ needs_collision_filters_reload = true;
}
}
_FORCE_INLINE_ uint32_t get_collision_layer() const { return collisionLayer; }
@@ -172,25 +182,32 @@ public:
_FORCE_INLINE_ void set_collision_mask(uint32_t p_mask) {
if (collisionMask != p_mask) {
collisionMask = p_mask;
- on_collision_filters_change();
+ needs_collision_filters_reload = true;
}
}
_FORCE_INLINE_ uint32_t get_collision_mask() const { return collisionMask; }
- virtual void on_collision_filters_change() = 0;
+ virtual void do_reload_collision_filters() = 0;
_FORCE_INLINE_ bool test_collision_mask(CollisionObjectBullet *p_other) const {
return collisionLayer & p_other->collisionMask || p_other->collisionLayer & collisionMask;
}
- virtual void reload_body() = 0;
+ bool need_reload_body() const {
+ return needs_body_reload;
+ }
+
+ void reload_body();
+
+ virtual void do_reload_body() = 0;
virtual void set_space(SpaceBullet *p_space) = 0;
_FORCE_INLINE_ SpaceBullet *get_space() const { return space; }
virtual void on_collision_checker_start() = 0;
virtual void on_collision_checker_end() = 0;
- virtual void dispatch_callbacks() = 0;
+ virtual void dispatch_callbacks();
+ virtual void pre_process();
void set_collision_enabled(bool p_enabled);
bool is_collisions_response_enabled();
@@ -214,14 +231,15 @@ public:
class RigidCollisionObjectBullet : public CollisionObjectBullet, public ShapeOwnerBullet {
protected:
btCollisionShape *mainShape = nullptr;
- Vector<ShapeWrapper> shapes;
+ LocalVector<ShapeWrapper> shapes;
+ bool need_shape_reload = true;
public:
RigidCollisionObjectBullet(Type p_type) :
CollisionObjectBullet(p_type) {}
~RigidCollisionObjectBullet();
- _FORCE_INLINE_ const Vector<ShapeWrapper> &get_shapes_wrappers() const { return shapes; }
+ _FORCE_INLINE_ const LocalVector<ShapeWrapper> &get_shapes_wrappers() const { return shapes; }
_FORCE_INLINE_ btCollisionShape *get_main_shape() const { return mainShape; }
@@ -232,9 +250,9 @@ public:
ShapeBullet *get_shape(int p_index) const;
btCollisionShape *get_bt_shape(int p_index) const;
- int find_shape(ShapeBullet *p_shape) const;
+ virtual int find_shape(ShapeBullet *p_shape) const override;
- virtual void remove_shape_full(ShapeBullet *p_shape);
+ virtual void remove_shape_full(ShapeBullet *p_shape) override;
void remove_shape_full(int p_index);
void remove_all_shapes(bool p_permanentlyFromThisBody = false, bool p_force_not_reload = false);
@@ -246,11 +264,15 @@ public:
void set_shape_disabled(int p_index, bool p_disabled);
bool is_shape_disabled(int p_index);
- virtual void shape_changed(int p_shape_index);
- virtual void reload_shapes();
+ virtual void pre_process() override;
+
+ virtual void shape_changed(int p_shape_index) override;
+ virtual void reload_shapes() override;
+ bool need_reload_shapes() const { return need_shape_reload; }
+ virtual void do_reload_shapes();
virtual void main_shape_changed() = 0;
- virtual void body_scale_changed();
+ virtual void body_scale_changed() override;
private:
void internal_shape_destroy(int p_index, bool p_permanentlyFromThisBody = false);