From 02e779fc70280d595f94c2471b0a90c5eccd76db Mon Sep 17 00:00:00 2001 From: tovjemam Date: Sun, 1 Mar 2026 12:28:49 +0100 Subject: [PATCH] Take into account parameters of destructibles (threshold/mass) --- src/game/mapinstance.cpp | 2 ++ src/game/mapinstance.hpp | 2 ++ src/game/world.cpp | 7 +++---- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/game/mapinstance.cpp b/src/game/mapinstance.cpp index b3d0023..e2f6b51 100644 --- a/src/game/mapinstance.cpp +++ b/src/game/mapinstance.cpp @@ -73,6 +73,7 @@ game::MapObjectCollision::MapObjectCollision(collision::DynamicsWorld& world, if (destructible) { oflags |= collision::OF_DESTRUCTIBLE; + model_->GetParamFloat("destr_th", destr_th_); } // prefer simple cshape which allow destruction @@ -105,6 +106,7 @@ void game::MapObjectCollision::Break() btCollisionShape* shape = body_->getCollisionShape(); float mass = 10.0f; + model_->GetParamFloat("destr_mass", mass); // dont care if not present btVector3 local_inertia(0, 0, 0); shape->calculateLocalInertia(mass, local_inertia); diff --git a/src/game/mapinstance.hpp b/src/game/mapinstance.hpp index bc2faaf..124de98 100644 --- a/src/game/mapinstance.hpp +++ b/src/game/mapinstance.hpp @@ -29,6 +29,7 @@ public: const std::shared_ptr& GetModel() const { return model_; } btRigidBody& GetBtBody() { return *body_; } net::ObjNum GetNum() const { return num_; } + float GetDestroyThreshold() const { return destr_th_; } virtual ~MapObjectCollision() override; @@ -37,6 +38,7 @@ private: std::shared_ptr model_; net::ObjNum num_; std::unique_ptr body_; + float destr_th_ = 10.0f; }; class MapInstance diff --git a/src/game/world.cpp b/src/game/world.cpp index 62d76c8..aac2f52 100644 --- a/src/game/world.cpp +++ b/src/game/world.cpp @@ -101,6 +101,7 @@ void game::World::HandleContacts() auto& bt_world = GetBtWorld(); int numManifolds = bt_world.getDispatcher()->getNumManifolds(); + // destructibles static std::vector to_destroy; to_destroy.clear(); @@ -120,10 +121,8 @@ void game::World::HandleContacts() auto col = dynamic_cast(cb); if (!col) return; - - const float break_threshold = 100.0f; // TODO: per-object threshold - - if (pt.getAppliedImpulse() > break_threshold) + + if (pt.getAppliedImpulse() > col->GetDestroyThreshold()) { to_destroy.push_back(col->GetNum()); other_body->applyCentralImpulse(pt.m_normalWorldOnB * pt.getAppliedImpulse() * 0.5f);