From: Mikko Rasa Date: Sun, 30 Mar 2025 12:07:16 +0000 (+0300) Subject: Set physics bodies on different layers based on whether they move X-Git-Url: https://git.tdb.fi/?a=commitdiff_plain;h=6a3ed6c7c19f0c873460097567ee8444237af0cc;p=libs%2Fgame.git Set physics bodies on different layers based on whether they move This should improve performance when there's a lot of static bodies compared to moving ones. --- diff --git a/source/game/physicssystem.cpp b/source/game/physicssystem.cpp index 9d5fc47..621b9d1 100644 --- a/source/game/physicssystem.cpp +++ b/source/game/physicssystem.cpp @@ -10,6 +10,17 @@ using namespace std; namespace Msp::Game { +namespace CollisionLayer { + +enum +{ + STATIC, + MOVING +}; + +} // namespace CollisionLayer + + PhysicsSystem::PhysicsSystem(Stage &s): System(s), event_observer(stage.get_event_bus()), @@ -45,6 +56,9 @@ void PhysicsSystem::early_tick() Handle transform = i->entity->get_transform(); Physics::MotionType motion = (i->motion ? Physics::DYNAMIC : Physics::STATIC); i->physics_body = make_unique(world, i->shape->get_shape(), transform->get_position(), transform->get_rotation(), motion); + unsigned layer = (motion==Physics::STATIC ? CollisionLayer::STATIC : CollisionLayer::MOVING); + uint32_t collision_mask = (1<physics_body->set_collisions(layer, collision_mask); } } pending.clear();