mischief-ecs 0.2.2.0 → 0.2.3.0
raw patch · 4 files changed
+55/−10 lines, 4 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Mischief.ECS.World.Query.TH.QF: Tup' :: [Qf] -> Qf
+ Mischief.ECS.World.Query.TH.QF: NoFilter' :: Qf
+ Mischief.ECS.World.Query.TH.QF: buildTup :: [Qf] -> Qf
+ Mischief.ECS.World.Query.TH.QF: opt0 :: Qf -> Qf
+ Mischief.ECS.World.Query.TH.QF: opt1 :: Qf -> Qf
+ Mischief.ECS.World.Query.TH.QF: optF :: Qf -> Qf
+ Mischief.ECS.World.Query.TH.QF: optQf :: Qf -> Qf
+ Mischief.ECS.World.Query.TH.QF: type HasWith = Bool
Files
- CHANGELOG.md +5/−0
- mischief-ecs.cabal +1/−1
- src/Mischief/ECS/World/Query.hs +9/−6
- src/Mischief/ECS/World/Query/TH/QF.hs +40/−3
CHANGELOG.md view
@@ -1,5 +1,10 @@ # Revision history for mischief-ecs +## 0.2.3.0 ++* Fixed a bug when checking for change detection on components that are not yet registered+* Added compile-time optimizations for query filters when using quasi-queries. + ## 0.2.2.0 * Performance improvements when chaining multiple Changed filters with Or.
mischief-ecs.cabal view
@@ -18,7 +18,7 @@ -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change-version: 0.2.2.0+version: 0.2.3.0 -- A short (one-line) description of the package. synopsis: An archetype ECS engine built in Haskell. homepage: https://codeberg.org/mischief/mischief
src/Mischief/ECS/World/Query.hs view
@@ -423,12 +423,15 @@ filterAllArchetypes (Without x) = do world <- unsafeGetWorld f <- liftIO $ filterToQuery world x+ maybe allArchetypes archetypesWithout f+filterAllArchetypes (Changed x f1 f2) = do+ world <- unsafeGetWorld+ f <- liftIO $ filterToQuery world x case f of Nothing -> pure Set.empty- Just f -> archetypesWithout f-filterAllArchetypes (Changed x f1 f2) = do- a <- allArchetypes- filterArchetypes a (Changed x f1 f2)+ Just f -> do+ a <- archetypesWith f+ filterArchetypes a (Changed x f1 f2) filterAllArchetypes (Or a b) = do a' <- filterAllArchetypes a b' <- filterAllArchetypes b@@ -453,8 +456,8 @@ case f of Nothing -> pure prev Just f -> do- a <- archetypesWithout f- pure $ Set.intersection prev a+ a <- archetypesWith f+ pure $ Set.difference prev a filterArchetypes prev (Changed x f1 f2) = do -- TODO: use Set.filterA from containers>=0.8.1 Set.fromList <$> filterM (filterOnlyChanged (Changed x f1 f2)) (Set.toList prev)
src/Mischief/ECS/World/Query/TH/QF.hs view
@@ -12,12 +12,49 @@ import Text.Megaparsec (MonadParsec (notFollowedBy, try), choice, many, optional, satisfy, some, (<|>)) import Text.Megaparsec.Char -data Qf = With' [QfType] | Without' [QfType] | Changed' [QfType] Text Text | Tup' [Qf] | And' Qf Qf | Or' Qf Qf deriving (Show)+data Qf = With' [QfType] | Without' [QfType] | Changed' [QfType] Text Text | And' Qf Qf | Or' Qf Qf | NoFilter' deriving (Show) +type HasWith =+ Bool++optQf :: Qf -> Qf+optQf = optF . opt1 . opt0++-- | Flatten Ands and Ors in one direction.+opt0 :: Qf -> Qf+opt0 (And' (And' a b) c) = opt0 $ And' a (And' b c)+opt0 (And' a b) = And' (opt0 a) (opt0 b)+opt0 (Or' (Or' a b) c) = opt0 $ Or' a (Or' b c)+opt0 (Or' a b) = Or' (opt0 a) (opt0 b)+opt0 x = x++-- |+-- Sort the And chains so that Withs are first, and Withouts second.+-- Sort the Or chains so that Changed are last.+opt1 :: Qf -> Qf+opt1 (And' a (And' (With' b) c)) = And' (With' b) $ opt1 (And' a c)+opt1 (And' a (And' (Without' b) c)) = And' (Without' b) $ opt1 (And' a c)+opt1 (Or' (Changed' a a1 a2) b) = Or' (opt1 b) (Changed' a a1 a2)+opt1 (And' a b) = And' (opt1 a) (opt1 b)+opt1 (Or' a b) = Or' (opt1 a) (opt1 b)+opt1 x = x++-- | If possible, ensure that the first filter is not a Without or Or.+optF :: Qf -> Qf+optF (And' (Without' a) b) = And' (optF b) (Without' a)+optF (And' (Or' a b) c) = And' (optF c) (Or' a b)+optF (Or' a b) = Or' (optF a) (optF b)+optF x = x++-- optimizeQfFinal+ data QfType = QfType {name :: Text, compType :: CompType} deriving (Show) +buildTup :: [Qf] -> Qf+buildTup = foldl' (flip And') NoFilter'+ pQf :: Parser Qf-pQf = Tup' . concat <$> pTup pTup'+pQf = optQf . buildTup . concat <$> pTup pTup' pTup' :: Parser [Qf] pTup' = try ((char '(' *> whitespace) *> (concat <$> pTup pTup') <* (char ')' *> whitespace)) <|> (: []) <$> pOr@@ -113,7 +150,7 @@ } quoteQf :: Qf -> Q Exp-quoteQf (Tup' !qf) = processTup qf+quoteQf NoFilter' = pure $ ConE 'NoFilter quoteQf (With' !x) = processTypes (ConE 'With) x quoteQf (Without' !x) = processTypes (ConE 'Without) x quoteQf (Changed' !x f1 f2) = do