Replace forM in physics with cmap

Signed-off-by: magic_rb <richard@brezak.sk>
This commit is contained in:
magic_rb 2024-01-03 22:47:58 +01:00
parent 5d53c2aa90
commit e5f10c6e34
No known key found for this signature in database
GPG key ID: 08D5287CC5DDCA0E

View file

@ -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