From e5f10c6e34087f71992496618f107bac079cbe7f Mon Sep 17 00:00:00 2001 From: magic_rb Date: Wed, 3 Jan 2024 22:47:58 +0100 Subject: [PATCH] Replace `forM` in physics with `cmap` Signed-off-by: magic_rb --- rpg/src/System/Physics.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rpg/src/System/Physics.hs b/rpg/src/System/Physics.hs index e03f379..753f897 100644 --- a/rpg/src/System/Physics.hs +++ b/rpg/src/System/Physics.hs @@ -172,13 +172,13 @@ applyVelocity'' = do fractions' = filter (not . isNaN . (^. _2)) clampedFractions (info, minTime) = minimumBy order ((Nothing, remainingTime) : fractions') - forM_ allEntities \entity1 -> do - (position1, velocity1, body1) <- AE.get @w @(PositionComponent, Maybe VelocityComponent, Maybe BodyComponent) entity1 + AE.cmap @w @(PositionComponent, AABBComponent, Maybe BodyComponent, Maybe VelocityComponent) @PositionComponent \(position1, _, body1, velocity1) -> let velocity1' = fromMaybe (Velocity $ pure 0) velocity1 - - unless (unVelocity velocity1' == pure 0 || maybe False (^. immovable) body1) $ - AE.set @w entity1 (Position $ position1.position + unVelocity velocity1' * pure (clampDown minTime)) + in + if unVelocity velocity1' == pure 0 || maybe False (^. immovable) body1 + then position1 + else Position $ position1.position + unVelocity velocity1' * pure (clampDown minTime) case info of Just ((entityA, positionA, velocityA, aabbA, bodyA), (entityB, positionB, velocityB, aabbB, bodyB)) -> do do