Skip to content

Commit 5134802

Browse files
committed
feat!: simplify systems
1 parent 72990d0 commit 5134802

File tree

4 files changed

+69
-249
lines changed

4 files changed

+69
-249
lines changed

examples/ECS.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ move = fetch & zipFetchMap (\(Velocity v) (Position p) -> Position $ p + v)
1818

1919
run :: SystemT IO ()
2020
run = do
21-
positions <- query move
21+
positions <- fromSystem $ query move
2222
liftIO $ print positions
2323

2424
app :: AccessT IO ()

src/Aztecs/ECS.hs

+1-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ module Aztecs.ECS
3737
EntityID,
3838
spawn,
3939
system,
40-
concurrently,
4140
World,
4241
)
4342
where
@@ -52,7 +51,7 @@ import Aztecs.ECS.Query hiding
5251
readQuery,
5352
readQueryEntities,
5453
)
55-
import Aztecs.ECS.System hiding (concurrently)
54+
import Aztecs.ECS.System
5655
import Aztecs.ECS.World (World)
5756
import Aztecs.ECS.World.Bundle
5857
import Aztecs.ECS.World.Bundle.Dynamic

src/Aztecs/ECS/Access.hs

+3-27
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,16 @@ module Aztecs.ECS.Access
2323
runAccessT,
2424
runAccessT_,
2525
system,
26-
concurrently,
2726
)
2827
where
2928

3029
import Aztecs.ECS.Component
3130
import Aztecs.ECS.Entity
3231
import Aztecs.ECS.System (SystemT (..), runSystemT)
33-
import qualified Aztecs.ECS.System as S
32+
import Aztecs.ECS.View
3433
import Aztecs.ECS.World (World (..))
3534
import qualified Aztecs.ECS.World as W
3635
import Aztecs.ECS.World.Bundle
37-
import Control.Concurrent.STM
3836
import Control.DeepSeq
3937
import Control.Monad.Fix
4038
import Control.Monad.Identity
@@ -123,28 +121,6 @@ despawn e = AccessT $ do
123121
system :: (Monad m) => SystemT m a -> AccessT m a
124122
system s = AccessT $ do
125123
!w <- get
126-
let go f = do
127-
es <- get
128-
let es' = f es
129-
put es'
130-
return es'
131-
(a, es) <- lift $ runStateT (runSystemT s go) (entities w)
132-
put w {entities = es}
133-
return a
134-
135-
-- | Run a `System` concurrently.
136-
--
137-
-- @since 0.11
138-
concurrently :: SystemT IO a -> AccessT IO a
139-
concurrently s = AccessT $ do
140-
!w <- get
141-
esVar <- lift . newTVarIO $ entities w
142-
let go f = atomically $ do
143-
es <- readTVar esVar
144-
let es' = f es
145-
writeTVar esVar es'
146-
return es'
147-
a <- liftIO $ S.concurrently s go
148-
es <- lift $ readTVarIO esVar
149-
put w {entities = es}
124+
(a, v) <- lift . runSystemT s $ entities w
125+
put w {entities = unview v $ entities w}
150126
return a

0 commit comments

Comments
 (0)