From 6a3ed6c7c19f0c873460097567ee8444237af0cc Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 30 Mar 2025 15:07:16 +0300 Subject: [PATCH] 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. --- source/game/physicssystem.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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(); -- 2.45.2