{-# LANGUAGE AllowAmbiguousTypes #-}
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}

module Mischief.ECS.World.Query.Queryable where

import Control.Applicative
import Control.Monad.IO.Class
import Data.Bifunctor qualified
import Data.Data
import Data.IORef
import Data.Maybe
import Data.Set (Set)
import Data.Set qualified as Set
import Data.Traversable
import GHC.Base (Int (I#))
import Mischief.ECS.App.SystemDef
import Mischief.ECS.Components
import Mischief.ECS.Entities
import Mischief.ECS.Tables
import Mischief.ECS.Vec qualified as Vec
import Mischief.ECS.World
import Mischief.ECS.World.Query.Markers
import Mischief.ECS.World.Query.QueryFilter
import Mischief.ECS.World.Utils

data TypeQuery = CompQ | RelQ | RelQ' Entity deriving (TypeQuery -> TypeQuery -> Bool
(TypeQuery -> TypeQuery -> Bool)
-> (TypeQuery -> TypeQuery -> Bool) -> Eq TypeQuery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TypeQuery -> TypeQuery -> Bool
== :: TypeQuery -> TypeQuery -> Bool
$c/= :: TypeQuery -> TypeQuery -> Bool
/= :: TypeQuery -> TypeQuery -> Bool
Eq, Eq TypeQuery
Eq TypeQuery =>
(TypeQuery -> TypeQuery -> Ordering)
-> (TypeQuery -> TypeQuery -> Bool)
-> (TypeQuery -> TypeQuery -> Bool)
-> (TypeQuery -> TypeQuery -> Bool)
-> (TypeQuery -> TypeQuery -> Bool)
-> (TypeQuery -> TypeQuery -> TypeQuery)
-> (TypeQuery -> TypeQuery -> TypeQuery)
-> Ord TypeQuery
TypeQuery -> TypeQuery -> Bool
TypeQuery -> TypeQuery -> Ordering
TypeQuery -> TypeQuery -> TypeQuery
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: TypeQuery -> TypeQuery -> Ordering
compare :: TypeQuery -> TypeQuery -> Ordering
$c< :: TypeQuery -> TypeQuery -> Bool
< :: TypeQuery -> TypeQuery -> Bool
$c<= :: TypeQuery -> TypeQuery -> Bool
<= :: TypeQuery -> TypeQuery -> Bool
$c> :: TypeQuery -> TypeQuery -> Bool
> :: TypeQuery -> TypeQuery -> Bool
$c>= :: TypeQuery -> TypeQuery -> Bool
>= :: TypeQuery -> TypeQuery -> Bool
$cmax :: TypeQuery -> TypeQuery -> TypeQuery
max :: TypeQuery -> TypeQuery -> TypeQuery
$cmin :: TypeQuery -> TypeQuery -> TypeQuery
min :: TypeQuery -> TypeQuery -> TypeQuery
Ord, Int -> TypeQuery -> ShowS
[TypeQuery] -> ShowS
TypeQuery -> String
(Int -> TypeQuery -> ShowS)
-> (TypeQuery -> String)
-> ([TypeQuery] -> ShowS)
-> Show TypeQuery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TypeQuery -> ShowS
showsPrec :: Int -> TypeQuery -> ShowS
$cshow :: TypeQuery -> String
show :: TypeQuery -> String
$cshowList :: [TypeQuery] -> ShowS
showList :: [TypeQuery] -> ShowS
Show)

data RelTarget = AnyTarget | RelTargets [Entities]

class Queryable qd output | qd -> output where
  runQueryEntity :: qd -> World -> Entity -> IO (Maybe output)
  runQueryInternal :: qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
  queryTypes :: qd -> Set (TypeRep, TypeQuery)

data HTrue

data HFalse

type family IsComponentC c where
  IsComponentC Entity = HFalse
  IsComponentC a = HTrue

instance Queryable () () where
  runQueryEntity :: () -> World -> Entity -> IO (Maybe ())
runQueryEntity ()
_ World
_ Entity
_ = Maybe () -> IO (Maybe ())
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe () -> IO (Maybe ())) -> Maybe () -> IO (Maybe ())
forall a b. (a -> b) -> a -> b
$ () -> Maybe ()
forall a. a -> Maybe a
Just ()
  runQueryInternal :: () -> [ArchetypeId] -> World -> IO [(Entity, Bool, ())]
runQueryInternal ()
_ [ArchetypeId]
archetypes World
world = do
    e <- World -> [ArchetypeId] -> IO [Entity]
tryGetEntities World
world [ArchetypeId]
archetypes
    pure $ map (\Entity
e -> (Entity
e, Bool
True, ())) e
  queryTypes :: () -> Set (TypeRep, TypeQuery)
queryTypes ()
_ = Set (TypeRep, TypeQuery)
forall a. Set a
Set.empty

instance {-# OVERLAPPABLE #-} (Component c) => Queryable (C c) c where
  runQueryEntity :: C c -> World -> Entity -> IO (Maybe c)
runQueryEntity C c
_ World
world Entity
entity = do
    result <- forall c. Component c => World -> Entity -> IO (Maybe (Maybe c))
tryGetEntityComponent @c World
world Entity
entity
    return $ case result of
      Just (Just c
res) -> c -> Maybe c
forall a. a -> Maybe a
Just c
res
      Maybe (Maybe c)
_ -> Maybe c
forall a. Maybe a
Nothing

  runQueryInternal :: C c -> [ArchetypeId] -> World -> IO [(Entity, Bool, c)]
runQueryInternal C c
_ [ArchetypeId]
archetypes World
world = ((Entity, c) -> (Entity, Bool, c))
-> [(Entity, c)] -> [(Entity, Bool, c)]
forall a b. (a -> b) -> [a] -> [b]
map (\(Entity
a, c
b) -> (Entity
a, Bool
True, c
b)) ([(Entity, c)] -> [(Entity, Bool, c)])
-> IO [(Entity, c)] -> IO [(Entity, Bool, c)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall c. Component c => World -> [ArchetypeId] -> IO [(Entity, c)]
tryGetComponents @c World
world [ArchetypeId]
archetypes

  queryTypes :: C c -> Set (TypeRep, TypeQuery)
queryTypes C c
_ = (TypeRep, TypeQuery) -> Set (TypeRep, TypeQuery)
forall a. a -> Set a
Set.singleton (Proxy c -> TypeRep
forall {k} (proxy :: k -> *) (a :: k).
Typeable a =>
proxy a -> TypeRep
typeRep (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @c), TypeQuery
CompQ)

instance (Component c) => Queryable (c -> Res c) (Res c) where
  runQueryEntity :: (c -> Res c) -> World -> Entity -> IO (Maybe (Res c))
runQueryEntity c -> Res c
_ World
world Entity
_ = do
    x <- TypeRep -> Components -> IO (Maybe ComponentId)
getComponentId (Proxy c -> TypeRep
forall {k} (proxy :: k -> *) (a :: k).
Typeable a =>
proxy a -> TypeRep
typeRep (Proxy c -> TypeRep) -> Proxy c -> TypeRep
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @c) World
world.components
    case x of
      Maybe ComponentId
Nothing -> Maybe (Res c) -> IO (Maybe (Res c))
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe (Res c)
forall a. Maybe a
Nothing
      Just (ComponentId (# Word#
id, Maybe Entity
_ #)) -> do
        let entity :: Entity
entity = (# Word#, Word# #) -> Entity
Entity (# Word#
id, Word#
0## #)
        y <- C c -> World -> Entity -> IO (Maybe c)
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity (forall a. C a
forall {k} (a :: k). C a
C @c) World
world Entity
entity
        pure $ fmap Res y

  runQueryInternal :: (c -> Res c)
-> [ArchetypeId] -> World -> IO [(Entity, Bool, Res c)]
runQueryInternal c -> Res c
_ [ArchetypeId]
archetypes World
world = do
    res <- (c -> Res c) -> World -> Entity -> IO (Maybe (Res c))
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity (forall c. c -> Res c
Res @c) World
world (Entity
forall a. HasCallStack => a
undefined :: Entity)
    x <- tryGetEntities world archetypes

    pure $ case res of
      Maybe (Res c)
Nothing -> (Entity -> (Entity, Bool, Res c))
-> [Entity] -> [(Entity, Bool, Res c)]
forall a b. (a -> b) -> [a] -> [b]
map (,Bool
False,Res c
forall a. HasCallStack => a
undefined) [Entity]
x
      Just Res c
res -> (Entity -> (Entity, Bool, Res c))
-> [Entity] -> [(Entity, Bool, Res c)]
forall a b. (a -> b) -> [a] -> [b]
map (,Bool
True,Res c
res) [Entity]
x

  queryTypes :: (c -> Res c) -> Set (TypeRep, TypeQuery)
queryTypes c -> Res c
_ = Set (TypeRep, TypeQuery)
forall a. Set a
Set.empty

instance (Component c) => Queryable (MRes c) (Maybe (Res c)) where
  runQueryEntity :: MRes c -> World -> Entity -> IO (Maybe (Maybe (Res c)))
runQueryEntity MRes c
_ World
world Entity
_ = do
    x <- TypeRep -> Components -> IO (Maybe ComponentId)
getComponentId (Proxy c -> TypeRep
forall {k} (proxy :: k -> *) (a :: k).
Typeable a =>
proxy a -> TypeRep
typeRep (Proxy c -> TypeRep) -> Proxy c -> TypeRep
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @c) World
world.components
    case x of
      Maybe ComponentId
Nothing -> Maybe (Maybe (Res c)) -> IO (Maybe (Maybe (Res c)))
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe (Res c) -> Maybe (Maybe (Res c))
forall a. a -> Maybe a
Just Maybe (Res c)
forall a. Maybe a
Nothing)
      Just (ComponentId (# Word#
id, Maybe Entity
_ #)) -> do
        let entity :: Entity
entity = (# Word#, Word# #) -> Entity
Entity (# Word#
id, Word#
0## #)
        y <- C c -> World -> Entity -> IO (Maybe c)
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity (forall a. C a
forall {k} (a :: k). C a
C @c) World
world Entity
entity
        pure $ Just $ fmap Res y

  runQueryInternal :: MRes c
-> [ArchetypeId] -> World -> IO [(Entity, Bool, Maybe (Res c))]
runQueryInternal MRes c
_ [ArchetypeId]
archetypes World
world = do
    res <- MRes c -> World -> Entity -> IO (Maybe (Maybe (Res c)))
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity (forall a. MRes a
forall {k} (a :: k). MRes a
MRes @c) World
world (Entity
forall a. HasCallStack => a
undefined :: Entity)
    x <- tryGetEntities world archetypes

    pure $ case res of
      Maybe (Maybe (Res c))
Nothing -> (Entity -> (Entity, Bool, Maybe (Res c)))
-> [Entity] -> [(Entity, Bool, Maybe (Res c))]
forall a b. (a -> b) -> [a] -> [b]
map (,Bool
False,Maybe (Res c)
forall a. HasCallStack => a
undefined) [Entity]
x
      Just Maybe (Res c)
res -> (Entity -> (Entity, Bool, Maybe (Res c)))
-> [Entity] -> [(Entity, Bool, Maybe (Res c))]
forall a b. (a -> b) -> [a] -> [b]
map (,Bool
True,Maybe (Res c)
res) [Entity]
x

  queryTypes :: MRes c -> Set (TypeRep, TypeQuery)
queryTypes MRes c
_ = Set (TypeRep, TypeQuery)
forall a. Set a
Set.empty

instance (Component c) => Queryable (HasRes c) Bool where
  runQueryEntity :: HasRes c -> World -> Entity -> IO (Maybe Bool)
runQueryEntity HasRes c
_ World
world Entity
_ = do
    x <- TypeRep -> Components -> IO (Maybe ComponentId)
getComponentId (Proxy c -> TypeRep
forall {k} (proxy :: k -> *) (a :: k).
Typeable a =>
proxy a -> TypeRep
typeRep (Proxy c -> TypeRep) -> Proxy c -> TypeRep
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @c) World
world.components
    case x of
      Maybe ComponentId
Nothing -> Maybe Bool -> IO (Maybe Bool)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False)
      Just (ComponentId (# Word#
id, Maybe Entity
_ #)) -> do
        let entity :: Entity
entity = (# Word#, Word# #) -> Entity
Entity (# Word#
id, Word#
0## #)
        y <- C c -> World -> Entity -> IO (Maybe c)
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity (forall a. C a
forall {k} (a :: k). C a
C @c) World
world Entity
entity
        pure $ Just $ isJust y

  runQueryInternal :: HasRes c -> [ArchetypeId] -> World -> IO [(Entity, Bool, Bool)]
runQueryInternal HasRes c
_ [ArchetypeId]
archetypes World
world = do
    res <- HasRes c -> World -> Entity -> IO (Maybe Bool)
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity (forall a. HasRes a
forall {k} (a :: k). HasRes a
HasRes @c) World
world (Entity
forall a. HasCallStack => a
undefined :: Entity)
    x <- tryGetEntities world archetypes

    pure $ case res of
      Maybe Bool
Nothing -> (Entity -> (Entity, Bool, Bool))
-> [Entity] -> [(Entity, Bool, Bool)]
forall a b. (a -> b) -> [a] -> [b]
map (,Bool
False,Bool
forall a. HasCallStack => a
undefined) [Entity]
x
      Just Bool
res -> (Entity -> (Entity, Bool, Bool))
-> [Entity] -> [(Entity, Bool, Bool)]
forall a b. (a -> b) -> [a] -> [b]
map (,Bool
True,Bool
res) [Entity]
x

  queryTypes :: HasRes c -> Set (TypeRep, TypeQuery)
queryTypes HasRes c
_ = Set (TypeRep, TypeQuery)
forall a. Set a
Set.empty

instance Queryable E Entity where
  runQueryEntity :: E -> World -> Entity -> IO (Maybe Entity)
runQueryEntity E
_ World
_ Entity
entity = Maybe Entity -> IO (Maybe Entity)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Entity -> IO (Maybe Entity))
-> Maybe Entity -> IO (Maybe Entity)
forall a b. (a -> b) -> a -> b
$ Entity -> Maybe Entity
forall a. a -> Maybe a
Just Entity
entity

  runQueryInternal :: E -> [ArchetypeId] -> World -> IO [(Entity, Bool, Entity)]
runQueryInternal E
_ [ArchetypeId]
archetypes World
world = (Entity -> (Entity, Bool, Entity))
-> [Entity] -> [(Entity, Bool, Entity)]
forall a b. (a -> b) -> [a] -> [b]
map (\Entity
x -> (Entity
x, Bool
True, Entity
x)) ([Entity] -> [(Entity, Bool, Entity)])
-> IO [Entity] -> IO [(Entity, Bool, Entity)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> World -> [ArchetypeId] -> IO [Entity]
tryGetEntities World
world [ArchetypeId]
archetypes

  queryTypes :: E -> Set (TypeRep, TypeQuery)
queryTypes E
_ = Set (TypeRep, TypeQuery)
forall a. Set a
Set.empty

class RelQuery (exclusive :: Bool) qd output | qd exclusive -> output where
  relRunQueryEntity :: qd -> World -> Entity -> IO (Maybe output)
  relRunQueryInternal :: qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
  relQueryTypes :: qd -> Set (TypeRep, TypeQuery)

instance (Component c) => RelQuery False (R c Any) [Rel c] where
  relRunQueryEntity :: R c Any -> World -> Entity -> IO (Maybe [Rel c])
relRunQueryEntity R c Any
_ World
world Entity
entity = do
    res <- forall c.
Component c =>
World -> Entity -> IO (Maybe (Maybe [Rel c]))
tryGetEntityRelCollection @c World
world Entity
entity
    return $ case res of
      Just (Just [Rel c]
x) -> [Rel c] -> Maybe [Rel c]
forall a. a -> Maybe a
Just [Rel c]
x
      Maybe (Maybe [Rel c])
_ -> Maybe [Rel c]
forall a. Maybe a
Nothing

  relRunQueryInternal :: R c Any -> [ArchetypeId] -> World -> IO [(Entity, Bool, [Rel c])]
relRunQueryInternal R c Any
_ [ArchetypeId]
archetypes World
world = ((Entity, [Rel c]) -> (Entity, Bool, [Rel c]))
-> [(Entity, [Rel c])] -> [(Entity, Bool, [Rel c])]
forall a b. (a -> b) -> [a] -> [b]
map (\(Entity
a, [Rel c]
b) -> (Entity
a, Bool
True, [Rel c]
b)) ([(Entity, [Rel c])] -> [(Entity, Bool, [Rel c])])
-> IO [(Entity, [Rel c])] -> IO [(Entity, Bool, [Rel c])]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall c.
Component c =>
World -> [ArchetypeId] -> IO [(Entity, [Rel c])]
tryGetRelCollections @c World
world [ArchetypeId]
archetypes

  relQueryTypes :: R c Any -> Set (TypeRep, TypeQuery)
relQueryTypes R c Any
_ = (TypeRep, TypeQuery) -> Set (TypeRep, TypeQuery)
forall a. a -> Set a
Set.singleton (Proxy c -> TypeRep
forall {k} (proxy :: k -> *) (a :: k).
Typeable a =>
proxy a -> TypeRep
typeRep (Proxy c -> TypeRep) -> Proxy c -> TypeRep
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @c, TypeQuery
RelQ)

instance (Component c) => RelQuery True (R c Any) (Rel c) where
  relRunQueryEntity :: R c Any -> World -> Entity -> IO (Maybe (Rel c))
relRunQueryEntity R c Any
_ World
world Entity
entity = do
    res <- forall c.
Component c =>
World -> Entity -> IO (Maybe (Maybe [Rel c]))
tryGetEntityRelCollection @c World
world Entity
entity
    return $ case res of
      Just (Just [Rel c
x]) -> Rel c -> Maybe (Rel c)
forall a. a -> Maybe a
Just Rel c
x
      Maybe (Maybe [Rel c])
_ -> Maybe (Rel c)
forall a. Maybe a
Nothing

  relRunQueryInternal :: R c Any -> [ArchetypeId] -> World -> IO [(Entity, Bool, Rel c)]
relRunQueryInternal R c Any
_ [ArchetypeId]
archetypes World
world = do
    rels <- forall c.
Component c =>
World -> [ArchetypeId] -> IO [(Entity, [Rel c])]
tryGetRelCollections @c World
world [ArchetypeId]
archetypes
    return $ map (\(Entity
e, Rel c
x : [Rel c]
_) -> (Entity
e, Bool
True, Rel c
x)) rels

  relQueryTypes :: R c Any -> Set (TypeRep, TypeQuery)
relQueryTypes R c Any
_ = (TypeRep, TypeQuery) -> Set (TypeRep, TypeQuery)
forall a. a -> Set a
Set.singleton (Proxy c -> TypeRep
forall {k} (proxy :: k -> *) (a :: k).
Typeable a =>
proxy a -> TypeRep
typeRep (Proxy c -> TypeRep) -> Proxy c -> TypeRep
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @c, TypeQuery
RelQ)

instance (Component c, Queryable q out) => RelQuery False (R c (Q q)) [From out] where
  relRunQueryEntity :: R c (Q q) -> World -> Entity -> IO (Maybe [From out])
relRunQueryEntity (R (Q q
q)) World
world Entity
entity = do
    res <- forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> World -> Entity -> IO (Maybe output)
relRunQueryEntity @False (forall {k} (a :: k) b. b -> R a b
forall a b. b -> R a b
R @c Any
Any) World
world Entity
entity

    case fmap (traverse $ \Rel c
r -> (out -> From out) -> Maybe out -> Maybe (From out)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Entity -> out -> From out
forall c. Entity -> c -> From c
From Rel c
r.target) (Maybe out -> Maybe (From out))
-> IO (Maybe out) -> IO (Maybe (From out))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> q -> World -> Entity -> IO (Maybe out)
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity q
q World
world Rel c
r.target) res of
      Maybe (IO [Maybe (From out)])
Nothing -> Maybe [From out] -> IO (Maybe [From out])
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe [From out]
forall a. Maybe a
Nothing
      Just IO [Maybe (From out)]
x -> do
        x <- IO [Maybe (From out)]
x
        pure $ case catMaybes x of
          [] -> Maybe [From out]
forall a. Maybe a
Nothing
          [From out]
x -> [From out] -> Maybe [From out]
forall a. a -> Maybe a
Just [From out]
x

  relRunQueryInternal :: R c (Q q)
-> [ArchetypeId] -> World -> IO [(Entity, Bool, [From out])]
relRunQueryInternal (R (Q q
q)) [ArchetypeId]
archetypes World
world = do
    res <- forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
relRunQueryInternal @False (forall {k} (a :: k) b. b -> R a b
forall a b. b -> R a b
R @c Any
Any) [ArchetypeId]
archetypes World
world
    for res $ \(Entity
e, Bool
b, [Rel c]
rels) -> do
      a <- [Maybe (From out)] -> [From out]
forall a. [Maybe a] -> [a]
catMaybes ([Maybe (From out)] -> [From out])
-> IO [Maybe (From out)] -> IO [From out]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((Rel c -> IO (Maybe (From out)))
-> [Rel c] -> IO [Maybe (From out)]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse ((Rel c -> IO (Maybe (From out)))
 -> [Rel c] -> IO [Maybe (From out)])
-> (Rel c -> IO (Maybe (From out)))
-> [Rel c]
-> IO [Maybe (From out)]
forall a b. (a -> b) -> a -> b
$ \Rel c
r -> (out -> From out) -> Maybe out -> Maybe (From out)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Entity -> out -> From out
forall c. Entity -> c -> From c
From Rel c
r.target) (Maybe out -> Maybe (From out))
-> IO (Maybe out) -> IO (Maybe (From out))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> q -> World -> Entity -> IO (Maybe out)
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity q
q World
world Rel c
r.target) [Rel c]
rels

      pure $ case a of
        [] -> (Entity
e, Bool
False, [From out]
forall a. HasCallStack => a
undefined)
        [From out]
x -> (Entity
e, Bool
b, [From out]
x)

  relQueryTypes :: R c (Q q) -> Set (TypeRep, TypeQuery)
relQueryTypes R c (Q q)
_ = (TypeRep, TypeQuery) -> Set (TypeRep, TypeQuery)
forall a. a -> Set a
Set.singleton (Proxy c -> TypeRep
forall {k} (proxy :: k -> *) (a :: k).
Typeable a =>
proxy a -> TypeRep
typeRep (Proxy c -> TypeRep) -> Proxy c -> TypeRep
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @c, TypeQuery
RelQ)

instance (Component c, Queryable q out) => RelQuery False (R c (Q' q (QueryFilter ArchetypeFilter))) [From out] where
  relRunQueryEntity :: R c (Q' q (QueryFilter 'ArchetypeFilter))
-> World -> Entity -> IO (Maybe [From out])
relRunQueryEntity (R (Q' q
q QueryFilter 'ArchetypeFilter
f)) World
world Entity
entity = do
    res <- forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> World -> Entity -> IO (Maybe output)
relRunQueryEntity @False (forall {k} (a :: k) b. b -> R a b
forall a b. b -> R a b
R @c Any
Any) World
world Entity
entity

    case fmap
      ( traverse $ \Rel c
r -> do
          t <- QueryFilter 'ArchetypeFilter -> World -> Entity -> IO Bool
filterEntity QueryFilter 'ArchetypeFilter
f World
world Rel c
r.target
          if t
            then
              fmap (From r.target) <$> runQueryEntity q world r.target
            else pure Nothing
      )
      res of
      Maybe (IO [Maybe (From out)])
Nothing -> Maybe [From out] -> IO (Maybe [From out])
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe [From out]
forall a. Maybe a
Nothing
      Just IO [Maybe (From out)]
x -> do
        x <- IO [Maybe (From out)]
x
        pure $ case catMaybes x of
          [] -> Maybe [From out]
forall a. Maybe a
Nothing
          [From out]
x -> [From out] -> Maybe [From out]
forall a. a -> Maybe a
Just [From out]
x

  relRunQueryInternal :: R c (Q' q (QueryFilter 'ArchetypeFilter))
-> [ArchetypeId] -> World -> IO [(Entity, Bool, [From out])]
relRunQueryInternal (R (Q' q
q QueryFilter 'ArchetypeFilter
f)) [ArchetypeId]
archetypes World
world = do
    res <- forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
relRunQueryInternal @False (forall {k} (a :: k) b. b -> R a b
forall a b. b -> R a b
R @c Any
Any) [ArchetypeId]
archetypes World
world
    for res $ \(Entity
e, Bool
b, [Rel c]
rels) -> do
      a <-
        [Maybe (From out)] -> [From out]
forall a. [Maybe a] -> [a]
catMaybes
          ([Maybe (From out)] -> [From out])
-> IO [Maybe (From out)] -> IO [From out]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ( (Rel c -> IO (Maybe (From out)))
-> [Rel c] -> IO [Maybe (From out)]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse ((Rel c -> IO (Maybe (From out)))
 -> [Rel c] -> IO [Maybe (From out)])
-> (Rel c -> IO (Maybe (From out)))
-> [Rel c]
-> IO [Maybe (From out)]
forall a b. (a -> b) -> a -> b
$ \Rel c
r -> do
                  t <- QueryFilter 'ArchetypeFilter -> World -> Entity -> IO Bool
filterEntity QueryFilter 'ArchetypeFilter
f World
world Rel c
r.target
                  if t
                    then
                      fmap (From r.target) <$> runQueryEntity q world r.target
                    else pure Nothing
              )
            [Rel c]
rels

      pure $ case a of
        [] -> (Entity
e, Bool
False, [From out]
forall a. HasCallStack => a
undefined)
        [From out]
x -> (Entity
e, Bool
b, [From out]
x)

  relQueryTypes :: R c (Q' q (QueryFilter 'ArchetypeFilter))
-> Set (TypeRep, TypeQuery)
relQueryTypes R c (Q' q (QueryFilter 'ArchetypeFilter))
_ = (TypeRep, TypeQuery) -> Set (TypeRep, TypeQuery)
forall a. a -> Set a
Set.singleton (Proxy c -> TypeRep
forall {k} (proxy :: k -> *) (a :: k).
Typeable a =>
proxy a -> TypeRep
typeRep (Proxy c -> TypeRep) -> Proxy c -> TypeRep
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @c, TypeQuery
RelQ)

instance (Component c, Queryable q out) => RelQuery True (R c (Q q)) (From out) where
  relRunQueryEntity :: R c (Q q) -> World -> Entity -> IO (Maybe (From out))
relRunQueryEntity (R (Q q
q)) World
world Entity
entity = do
    res <- forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> World -> Entity -> IO (Maybe output)
relRunQueryEntity @True (forall {k} (a :: k) b. b -> R a b
forall a b. b -> R a b
R @c Any
Any) World
world Entity
entity

    case fmap (\Rel c
r -> (Rel c
r.target, q -> World -> Entity -> IO (Maybe out)
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity q
q World
world Rel c
r.target)) res of
      Maybe (Entity, IO (Maybe out))
Nothing -> Maybe (From out) -> IO (Maybe (From out))
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe (From out)
forall a. Maybe a
Nothing
      Just (Entity
e, IO (Maybe out)
x) -> (out -> From out) -> Maybe out -> Maybe (From out)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Entity -> out -> From out
forall c. Entity -> c -> From c
From Entity
e) (Maybe out -> Maybe (From out))
-> IO (Maybe out) -> IO (Maybe (From out))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IO (Maybe out)
x
  relRunQueryInternal :: R c (Q q)
-> [ArchetypeId] -> World -> IO [(Entity, Bool, From out)]
relRunQueryInternal (R (Q q
q)) [ArchetypeId]
archetypes World
world = do
    res <- forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
relRunQueryInternal @True (forall {k} (a :: k) b. b -> R a b
forall a b. b -> R a b
R @c Any
Any) [ArchetypeId]
archetypes World
world
    for res $ \(Entity
e, Bool
b, Rel c
rels) -> do
      r <- (\Rel c
r -> (,Rel c
r.target) (Maybe out -> (Maybe out, Entity))
-> IO (Maybe out) -> IO (Maybe out, Entity)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> q -> World -> Entity -> IO (Maybe out)
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity q
q World
world Rel c
r.target) Rel c
rels

      pure $ case r of
        (Maybe out
Nothing, Entity
_) -> (Entity
e, Bool
False, From out
forall a. HasCallStack => a
undefined)
        (Just out
x, Entity
e') -> (Entity
e, Bool
b, Entity -> out -> From out
forall c. Entity -> c -> From c
From Entity
e' out
x)

  relQueryTypes :: R c (Q q) -> Set (TypeRep, TypeQuery)
relQueryTypes R c (Q q)
_ = (TypeRep, TypeQuery) -> Set (TypeRep, TypeQuery)
forall a. a -> Set a
Set.singleton (Proxy c -> TypeRep
forall {k} (proxy :: k -> *) (a :: k).
Typeable a =>
proxy a -> TypeRep
typeRep (Proxy c -> TypeRep) -> Proxy c -> TypeRep
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @c, TypeQuery
RelQ)

instance (Component c, Queryable q out) => RelQuery True (R c (Q' q (QueryFilter ArchetypeFilter))) (From out) where
  relRunQueryEntity :: R c (Q' q (QueryFilter 'ArchetypeFilter))
-> World -> Entity -> IO (Maybe (From out))
relRunQueryEntity (R (Q' q
q QueryFilter 'ArchetypeFilter
f)) World
world Entity
entity = do
    res <- forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> World -> Entity -> IO (Maybe output)
relRunQueryEntity @True (forall {k} (a :: k) b. b -> R a b
forall a b. b -> R a b
R @c Any
Any) World
world Entity
entity

    case fmap
      ( \Rel c
r -> do
          t <- QueryFilter 'ArchetypeFilter -> World -> Entity -> IO Bool
filterEntity QueryFilter 'ArchetypeFilter
f World
world Rel c
r.target
          if t
            then
              fmap (From r.target) <$> runQueryEntity q world r.target
            else pure Nothing
      )
      res of
      Maybe (IO (Maybe (From out)))
Nothing -> Maybe (From out) -> IO (Maybe (From out))
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe (From out)
forall a. Maybe a
Nothing
      Just IO (Maybe (From out))
x -> IO (Maybe (From out))
x
  relRunQueryInternal :: R c (Q' q (QueryFilter 'ArchetypeFilter))
-> [ArchetypeId] -> World -> IO [(Entity, Bool, From out)]
relRunQueryInternal (R (Q' q
q QueryFilter 'ArchetypeFilter
f)) [ArchetypeId]
archetypes World
world = do
    res <- forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
relRunQueryInternal @True (forall {k} (a :: k) b. b -> R a b
forall a b. b -> R a b
R @c Any
Any) [ArchetypeId]
archetypes World
world
    for res $ \(Entity
e, Bool
b, Rel c
rels) -> do
      r <-
        ( \Rel c
r -> do
            t <- QueryFilter 'ArchetypeFilter -> World -> Entity -> IO Bool
filterEntity QueryFilter 'ArchetypeFilter
f World
world Rel c
r.target
            if t
              then
                fmap (From r.target) <$> runQueryEntity q world r.target
              else pure Nothing
        )
          Rel c
rels
      pure $ case r of
        Maybe (From out)
Nothing -> (Entity
e, Bool
False, From out
forall a. HasCallStack => a
undefined)
        Just From out
x -> (Entity
e, Bool
b, From out
x)

  relQueryTypes :: R c (Q' q (QueryFilter 'ArchetypeFilter))
-> Set (TypeRep, TypeQuery)
relQueryTypes R c (Q' q (QueryFilter 'ArchetypeFilter))
_ = (TypeRep, TypeQuery) -> Set (TypeRep, TypeQuery)
forall a. a -> Set a
Set.singleton (Proxy c -> TypeRep
forall {k} (proxy :: k -> *) (a :: k).
Typeable a =>
proxy a -> TypeRep
typeRep (Proxy c -> TypeRep) -> Proxy c -> TypeRep
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @c, TypeQuery
RelQ)

instance (Component c) => Queryable (R c Entity) (Rel c) where
  runQueryEntity :: R c Entity -> World -> Entity -> IO (Maybe (Rel c))
runQueryEntity (R Entity
target) World
world Entity
entity = do
    res <- forall c.
Component c =>
Entity -> World -> Entity -> IO (Maybe (Maybe c))
tryGetEntityRel @c Entity
target World
world Entity
entity
    return $ case res of
      Just (Just c
x) -> Rel c -> Maybe (Rel c)
forall a. a -> Maybe a
Just (c -> Entity -> Rel c
forall c. c -> Entity -> Rel c
Rel c
x Entity
target)
      Maybe (Maybe c)
_ -> Maybe (Rel c)
forall a. Maybe a
Nothing

  runQueryInternal :: R c Entity -> [ArchetypeId] -> World -> IO [(Entity, Bool, Rel c)]
runQueryInternal (R Entity
target) [ArchetypeId]
archetypes World
world = ((Entity, Rel c) -> (Entity, Bool, Rel c))
-> [(Entity, Rel c)] -> [(Entity, Bool, Rel c)]
forall a b. (a -> b) -> [a] -> [b]
map (\(Entity
a, Rel c
b) -> (Entity
a, Bool
True, Rel c
b)) ([(Entity, Rel c)] -> [(Entity, Bool, Rel c)])
-> IO [(Entity, Rel c)] -> IO [(Entity, Bool, Rel c)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall c.
Component c =>
Entity -> World -> [ArchetypeId] -> IO [(Entity, Rel c)]
tryGetRels @c Entity
target World
world [ArchetypeId]
archetypes

  queryTypes :: R c Entity -> Set (TypeRep, TypeQuery)
queryTypes (R Entity
target) = (TypeRep, TypeQuery) -> Set (TypeRep, TypeQuery)
forall a. a -> Set a
Set.singleton (Proxy c -> TypeRep
forall {k} (proxy :: k -> *) (a :: k).
Typeable a =>
proxy a -> TypeRep
typeRep (Proxy c -> TypeRep) -> Proxy c -> TypeRep
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @c, Entity -> TypeQuery
RelQ' Entity
target)

instance (RelQuery (IsExclusiveRel c) (R c Any) out) => Queryable (R c Any) out where
  runQueryEntity :: R c Any -> World -> Entity -> IO (Maybe out)
runQueryEntity = forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> World -> Entity -> IO (Maybe output)
relRunQueryEntity @(IsExclusiveRel c)

  runQueryInternal :: R c Any -> [ArchetypeId] -> World -> IO [(Entity, Bool, out)]
runQueryInternal = forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
relRunQueryInternal @(IsExclusiveRel c)

  queryTypes :: R c Any -> Set (TypeRep, TypeQuery)
queryTypes = forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> Set (TypeRep, TypeQuery)
relQueryTypes @(IsExclusiveRel c)

instance (RelQuery (IsExclusiveRel c) (R c (Q q)) out) => Queryable (R c (Q q)) out where
  runQueryEntity :: R c (Q q) -> World -> Entity -> IO (Maybe out)
runQueryEntity = forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> World -> Entity -> IO (Maybe output)
relRunQueryEntity @(IsExclusiveRel c)

  runQueryInternal :: R c (Q q) -> [ArchetypeId] -> World -> IO [(Entity, Bool, out)]
runQueryInternal = forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
relRunQueryInternal @(IsExclusiveRel c)

  queryTypes :: R c (Q q) -> Set (TypeRep, TypeQuery)
queryTypes = forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> Set (TypeRep, TypeQuery)
relQueryTypes @(IsExclusiveRel c)

instance (RelQuery (IsExclusiveRel c) (R c (Q' q f)) out) => Queryable (R c (Q' q f)) out where
  runQueryEntity :: R c (Q' q f) -> World -> Entity -> IO (Maybe out)
runQueryEntity = forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> World -> Entity -> IO (Maybe output)
relRunQueryEntity @(IsExclusiveRel c)

  runQueryInternal :: R c (Q' q f) -> [ArchetypeId] -> World -> IO [(Entity, Bool, out)]
runQueryInternal = forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
relRunQueryInternal @(IsExclusiveRel c)

  queryTypes :: R c (Q' q f) -> Set (TypeRep, TypeQuery)
queryTypes = forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> Set (TypeRep, TypeQuery)
relQueryTypes @(IsExclusiveRel c)

instance (RelQuery False (R c e) out) => Queryable (R' c e) out where
  runQueryEntity :: R' c e -> World -> Entity -> IO (Maybe out)
runQueryEntity (R' e
e) = forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> World -> Entity -> IO (Maybe output)
relRunQueryEntity @False (forall (a :: k) b. b -> R a b
forall {k} (a :: k) b. b -> R a b
R @c e
e)
  runQueryInternal :: R' c e -> [ArchetypeId] -> World -> IO [(Entity, Bool, out)]
runQueryInternal (R' e
e) = forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
relRunQueryInternal @False (forall (a :: k) b. b -> R a b
forall {k} (a :: k) b. b -> R a b
R @c e
e)
  queryTypes :: R' c e -> Set (TypeRep, TypeQuery)
queryTypes (R' e
e) = forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> Set (TypeRep, TypeQuery)
relQueryTypes @False (forall (a :: k) b. b -> R a b
forall {k} (a :: k) b. b -> R a b
R @c e
e)

instance (Component c) => Queryable (M c) (Maybe c) where
  runQueryEntity :: M c -> World -> Entity -> IO (Maybe (Maybe c))
runQueryEntity M c
_ World
world Entity
entity = do
    res <- forall c. Component c => World -> Entity -> IO (Maybe (Maybe c))
tryGetEntityComponent @c World
world Entity
entity
    case res of
      Maybe (Maybe c)
Nothing -> Maybe (Maybe c) -> IO (Maybe (Maybe c))
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (Maybe c)
forall a. Maybe a
Nothing
      Just Maybe c
Nothing -> Maybe (Maybe c) -> IO (Maybe (Maybe c))
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (Maybe c) -> IO (Maybe (Maybe c)))
-> Maybe (Maybe c) -> IO (Maybe (Maybe c))
forall a b. (a -> b) -> a -> b
$ Maybe c -> Maybe (Maybe c)
forall a. a -> Maybe a
Just Maybe c
forall a. Maybe a
Nothing
      Just (Just c
x) -> Maybe (Maybe c) -> IO (Maybe (Maybe c))
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (Maybe c) -> IO (Maybe (Maybe c)))
-> Maybe (Maybe c) -> IO (Maybe (Maybe c))
forall a b. (a -> b) -> a -> b
$ Maybe c -> Maybe (Maybe c)
forall a. a -> Maybe a
Just (Maybe c -> Maybe (Maybe c)) -> Maybe c -> Maybe (Maybe c)
forall a b. (a -> b) -> a -> b
$ c -> Maybe c
forall a. a -> Maybe a
Just c
x

  runQueryInternal :: M c -> [ArchetypeId] -> World -> IO [(Entity, Bool, Maybe c)]
runQueryInternal M c
_ [ArchetypeId]
archetypes World
world = ((Entity, Maybe c) -> (Entity, Bool, Maybe c))
-> [(Entity, Maybe c)] -> [(Entity, Bool, Maybe c)]
forall a b. (a -> b) -> [a] -> [b]
map (\(Entity
a, Maybe c
b) -> (Entity
a, Bool
True, Maybe c
b)) ([(Entity, Maybe c)] -> [(Entity, Bool, Maybe c)])
-> IO [(Entity, Maybe c)] -> IO [(Entity, Bool, Maybe c)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall c.
Component c =>
World -> [ArchetypeId] -> IO [(Entity, Maybe c)]
tryGetComponentsMaybe @c World
world [ArchetypeId]
archetypes

  queryTypes :: M c -> Set (TypeRep, TypeQuery)
queryTypes M c
_ = Set (TypeRep, TypeQuery)
forall a. Set a
Set.empty

instance (Component c) => Queryable (MR c Entity) (Maybe (Rel c)) where
  runQueryEntity :: MR c Entity -> World -> Entity -> IO (Maybe (Maybe (Rel c)))
runQueryEntity (MR Entity
target) World
world Entity
entity = do
    res <- forall c.
Component c =>
Entity -> World -> Entity -> IO (Maybe (Maybe c))
tryGetEntityRel @c Entity
target World
world Entity
entity
    return $ case res of
      Maybe (Maybe c)
Nothing -> Maybe (Maybe (Rel c))
forall a. Maybe a
Nothing
      Just Maybe c
Nothing -> Maybe (Rel c) -> Maybe (Maybe (Rel c))
forall a. a -> Maybe a
Just Maybe (Rel c)
forall a. Maybe a
Nothing
      Just (Just c
x) -> Maybe (Rel c) -> Maybe (Maybe (Rel c))
forall a. a -> Maybe a
Just (Maybe (Rel c) -> Maybe (Maybe (Rel c)))
-> Maybe (Rel c) -> Maybe (Maybe (Rel c))
forall a b. (a -> b) -> a -> b
$ Rel c -> Maybe (Rel c)
forall a. a -> Maybe a
Just (c -> Entity -> Rel c
forall c. c -> Entity -> Rel c
Rel c
x Entity
target)

  runQueryInternal :: MR c Entity
-> [ArchetypeId] -> World -> IO [(Entity, Bool, Maybe (Rel c))]
runQueryInternal (MR Entity
target) [ArchetypeId]
archetypes World
world = ((Entity, Maybe (Rel c)) -> (Entity, Bool, Maybe (Rel c)))
-> [(Entity, Maybe (Rel c))] -> [(Entity, Bool, Maybe (Rel c))]
forall a b. (a -> b) -> [a] -> [b]
map (\(Entity
a, Maybe (Rel c)
b) -> (Entity
a, Bool
True, Maybe (Rel c)
b)) ([(Entity, Maybe (Rel c))] -> [(Entity, Bool, Maybe (Rel c))])
-> IO [(Entity, Maybe (Rel c))]
-> IO [(Entity, Bool, Maybe (Rel c))]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall c.
Component c =>
Entity -> World -> [ArchetypeId] -> IO [(Entity, Maybe (Rel c))]
tryGetRelsMaybe @c Entity
target World
world [ArchetypeId]
archetypes
  queryTypes :: MR c Entity -> Set (TypeRep, TypeQuery)
queryTypes MR c Entity
_ = Set (TypeRep, TypeQuery)
forall a. Set a
Set.empty

instance (Component c) => RelQuery False (MR c Any) (Maybe [Rel c]) where
  relRunQueryEntity :: MR c Any -> World -> Entity -> IO (Maybe (Maybe [Rel c]))
relRunQueryEntity MR c Any
_ = forall c.
Component c =>
World -> Entity -> IO (Maybe (Maybe [Rel c]))
tryGetEntityRelCollection @c

  relRunQueryInternal :: MR c Any
-> [ArchetypeId] -> World -> IO [(Entity, Bool, Maybe [Rel c])]
relRunQueryInternal MR c Any
_ [ArchetypeId]
archetypes World
world = do
    x <- forall c.
Component c =>
World -> [ArchetypeId] -> IO [(Entity, [Rel c])]
tryGetRelCollections @c World
world [ArchetypeId]
archetypes
    return $ flip map x $ \(Entity
e, [Rel c]
x) ->
      case [Rel c]
x of
        [] -> (Entity
e, Bool
True, Maybe [Rel c]
forall a. Maybe a
Nothing)
        [Rel c]
x -> (Entity
e, Bool
True, [Rel c] -> Maybe [Rel c]
forall a. a -> Maybe a
Just [Rel c]
x)
  relQueryTypes :: MR c Any -> Set (TypeRep, TypeQuery)
relQueryTypes MR c Any
_ = Set (TypeRep, TypeQuery)
forall a. Set a
Set.empty

instance (Component c) => RelQuery True (MR c Any) (Maybe (Rel c)) where
  relRunQueryEntity :: MR c Any -> World -> Entity -> IO (Maybe (Maybe (Rel c)))
relRunQueryEntity MR c Any
_ World
world Entity
entity = do
    res <- forall c.
Component c =>
World -> Entity -> IO (Maybe (Maybe [Rel c]))
tryGetEntityRelCollection @c World
world Entity
entity
    pure $ case res of
      Just (Just [Rel c
x]) -> Maybe (Rel c) -> Maybe (Maybe (Rel c))
forall a. a -> Maybe a
Just (Rel c -> Maybe (Rel c)
forall a. a -> Maybe a
Just Rel c
x)
      Just (Just [Rel c]
_) -> Maybe (Maybe (Rel c))
forall a. HasCallStack => a
undefined
      Just Maybe [Rel c]
Nothing -> Maybe (Rel c) -> Maybe (Maybe (Rel c))
forall a. a -> Maybe a
Just Maybe (Rel c)
forall a. Maybe a
Nothing
      Maybe (Maybe [Rel c])
Nothing -> Maybe (Maybe (Rel c))
forall a. Maybe a
Nothing

  relRunQueryInternal :: MR c Any
-> [ArchetypeId] -> World -> IO [(Entity, Bool, Maybe (Rel c))]
relRunQueryInternal MR c Any
_ [ArchetypeId]
archetypes World
world = do
    x <- forall c.
Component c =>
World -> [ArchetypeId] -> IO [(Entity, [Rel c])]
tryGetRelCollections @c World
world [ArchetypeId]
archetypes
    return $ flip map x $ \(Entity
e, [Rel c]
x) ->
      case [Rel c]
x of
        [] -> (Entity
e, Bool
True, Maybe (Rel c)
forall a. Maybe a
Nothing)
        [Rel c
x] -> (Entity
e, Bool
True, Rel c -> Maybe (Rel c)
forall a. a -> Maybe a
Just Rel c
x)
        [Rel c]
_ -> (Entity, Bool, Maybe (Rel c))
forall a. HasCallStack => a
undefined
  relQueryTypes :: MR c Any -> Set (TypeRep, TypeQuery)
relQueryTypes MR c Any
_ = Set (TypeRep, TypeQuery)
forall a. Set a
Set.empty

instance (Component c, Queryable q out) => RelQuery False (MR c (Q q)) (Maybe [From out]) where
  relRunQueryEntity :: MR c (Q q) -> World -> Entity -> IO (Maybe (Maybe [From out]))
relRunQueryEntity (MR (Q q
q)) World
world Entity
entity = do
    res <- forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> World -> Entity -> IO (Maybe output)
relRunQueryEntity @False (forall {k} (a :: k) b. b -> MR a b
forall a b. b -> MR a b
MR @c Any
Any) World
world Entity
entity
    case res of
      Maybe (Maybe [Rel c])
Nothing -> Maybe (Maybe [From out]) -> IO (Maybe (Maybe [From out]))
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe (Maybe [From out])
forall a. Maybe a
Nothing
      Just Maybe [Rel c]
Nothing -> Maybe (Maybe [From out]) -> IO (Maybe (Maybe [From out]))
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe (Maybe [From out]) -> IO (Maybe (Maybe [From out])))
-> Maybe (Maybe [From out]) -> IO (Maybe (Maybe [From out]))
forall a b. (a -> b) -> a -> b
$ Maybe [From out] -> Maybe (Maybe [From out])
forall a. a -> Maybe a
Just Maybe [From out]
forall a. Maybe a
Nothing
      Just (Just [Rel c]
r) ->
        Maybe [From out] -> Maybe (Maybe [From out])
forall a. a -> Maybe a
Just (Maybe [From out] -> Maybe (Maybe [From out]))
-> IO (Maybe [From out]) -> IO (Maybe (Maybe [From out]))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> do
          let targets :: [Entity]
targets = (Rel c -> Entity) -> [Rel c] -> [Entity]
forall a b. (a -> b) -> [a] -> [b]
map (\Rel c
x -> Rel c
x.target) [Rel c]
r
          results <- [Maybe (From out)] -> [From out]
forall a. [Maybe a] -> [a]
catMaybes ([Maybe (From out)] -> [From out])
-> IO [Maybe (From out)] -> IO [From out]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Entity]
-> (Entity -> IO (Maybe (From out))) -> IO [Maybe (From out)]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
t a -> (a -> f b) -> f (t b)
for [Entity]
targets (\Entity
x -> (out -> From out) -> Maybe out -> Maybe (From out)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Entity -> out -> From out
forall c. Entity -> c -> From c
From Entity
x) (Maybe out -> Maybe (From out))
-> IO (Maybe out) -> IO (Maybe (From out))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> q -> World -> Entity -> IO (Maybe out)
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity q
q World
world Entity
x)
          case results of
            [] -> Maybe [From out] -> IO (Maybe [From out])
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe [From out]
forall a. Maybe a
Nothing
            [From out]
x -> Maybe [From out] -> IO (Maybe [From out])
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe [From out] -> IO (Maybe [From out]))
-> Maybe [From out] -> IO (Maybe [From out])
forall a b. (a -> b) -> a -> b
$ [From out] -> Maybe [From out]
forall a. a -> Maybe a
Just [From out]
x

  relRunQueryInternal :: MR c (Q q)
-> [ArchetypeId] -> World -> IO [(Entity, Bool, Maybe [From out])]
relRunQueryInternal (MR (Q q
q)) [ArchetypeId]
archetypes World
world = do
    res <- forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
relRunQueryInternal @False (forall {k} (a :: k) b. b -> MR a b
forall a b. b -> MR a b
MR @c Any
Any) [ArchetypeId]
archetypes World
world
    for res $ \(Entity
e, Bool
b, Maybe [Rel c]
r) -> do
      case Maybe [Rel c]
r of
        Maybe [Rel c]
Nothing -> (Entity, Bool, Maybe [From out])
-> IO (Entity, Bool, Maybe [From out])
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Entity
e, Bool
b, Maybe [From out]
forall a. Maybe a
Nothing)
        Just [Rel c]
r -> do
          rs <- [Rel c]
-> (Rel c -> IO (Maybe (From out))) -> IO [Maybe (From out)]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
t a -> (a -> f b) -> f (t b)
for [Rel c]
r (\Rel c
x -> (out -> From out) -> Maybe out -> Maybe (From out)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Entity -> out -> From out
forall c. Entity -> c -> From c
From Rel c
x.target) (Maybe out -> Maybe (From out))
-> IO (Maybe out) -> IO (Maybe (From out))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> q -> World -> Entity -> IO (Maybe out)
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity q
q World
world Rel c
x.target)
          case catMaybes rs of
            [] -> (Entity, Bool, Maybe [From out])
-> IO (Entity, Bool, Maybe [From out])
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Entity
e, Bool
b, Maybe [From out]
forall a. Maybe a
Nothing)
            [From out]
x -> (Entity, Bool, Maybe [From out])
-> IO (Entity, Bool, Maybe [From out])
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Entity
e, Bool
b, [From out] -> Maybe [From out]
forall a. a -> Maybe a
Just [From out]
x)

  relQueryTypes :: MR c (Q q) -> Set (TypeRep, TypeQuery)
relQueryTypes MR c (Q q)
_ = Set (TypeRep, TypeQuery)
forall a. Set a
Set.empty

instance (Component c, Queryable q out) => RelQuery False (MR c (Q' q (QueryFilter ArchetypeFilter))) (Maybe [From out]) where
  relRunQueryEntity :: MR c (Q' q (QueryFilter 'ArchetypeFilter))
-> World -> Entity -> IO (Maybe (Maybe [From out]))
relRunQueryEntity (MR (Q' q
q QueryFilter 'ArchetypeFilter
f)) World
world Entity
entity = do
    res <- forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> World -> Entity -> IO (Maybe output)
relRunQueryEntity @False (forall {k} (a :: k) b. b -> MR a b
forall a b. b -> MR a b
MR @c Any
Any) World
world Entity
entity
    case res of
      Maybe (Maybe [Rel c])
Nothing -> Maybe (Maybe [From out]) -> IO (Maybe (Maybe [From out]))
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe (Maybe [From out])
forall a. Maybe a
Nothing
      Just Maybe [Rel c]
Nothing -> Maybe (Maybe [From out]) -> IO (Maybe (Maybe [From out]))
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe (Maybe [From out]) -> IO (Maybe (Maybe [From out])))
-> Maybe (Maybe [From out]) -> IO (Maybe (Maybe [From out]))
forall a b. (a -> b) -> a -> b
$ Maybe [From out] -> Maybe (Maybe [From out])
forall a. a -> Maybe a
Just Maybe [From out]
forall a. Maybe a
Nothing
      Just (Just [Rel c]
r) ->
        Maybe [From out] -> Maybe (Maybe [From out])
forall a. a -> Maybe a
Just (Maybe [From out] -> Maybe (Maybe [From out]))
-> IO (Maybe [From out]) -> IO (Maybe (Maybe [From out]))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> do
          let targets :: [Entity]
targets = (Rel c -> Entity) -> [Rel c] -> [Entity]
forall a b. (a -> b) -> [a] -> [b]
map (\Rel c
x -> Rel c
x.target) [Rel c]
r
          results <-
            [Maybe (From out)] -> [From out]
forall a. [Maybe a] -> [a]
catMaybes
              ([Maybe (From out)] -> [From out])
-> IO [Maybe (From out)] -> IO [From out]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Entity]
-> (Entity -> IO (Maybe (From out))) -> IO [Maybe (From out)]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
t a -> (a -> f b) -> f (t b)
for
                [Entity]
targets
                ( \Entity
t -> do
                    b <- QueryFilter 'ArchetypeFilter -> World -> Entity -> IO Bool
filterEntity QueryFilter 'ArchetypeFilter
f World
world Entity
t
                    if b
                      then
                        fmap (From t) <$> runQueryEntity q world t
                      else
                        pure Nothing
                )
          case results of
            [] -> Maybe [From out] -> IO (Maybe [From out])
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe [From out]
forall a. Maybe a
Nothing
            [From out]
x -> Maybe [From out] -> IO (Maybe [From out])
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe [From out] -> IO (Maybe [From out]))
-> Maybe [From out] -> IO (Maybe [From out])
forall a b. (a -> b) -> a -> b
$ [From out] -> Maybe [From out]
forall a. a -> Maybe a
Just [From out]
x

  relRunQueryInternal :: MR c (Q' q (QueryFilter 'ArchetypeFilter))
-> [ArchetypeId] -> World -> IO [(Entity, Bool, Maybe [From out])]
relRunQueryInternal (MR (Q' q
q QueryFilter 'ArchetypeFilter
f)) [ArchetypeId]
archetypes World
world = do
    res <- forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
relRunQueryInternal @False (forall {k} (a :: k) b. b -> MR a b
forall a b. b -> MR a b
MR @c Any
Any) [ArchetypeId]
archetypes World
world
    for res $ \(Entity
e, Bool
b, Maybe [Rel c]
r) -> do
      case Maybe [Rel c]
r of
        Maybe [Rel c]
Nothing -> (Entity, Bool, Maybe [From out])
-> IO (Entity, Bool, Maybe [From out])
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Entity
e, Bool
b, Maybe [From out]
forall a. Maybe a
Nothing)
        Just [Rel c]
r -> do
          rs <-
            [Rel c]
-> (Rel c -> IO (Maybe (From out))) -> IO [Maybe (From out)]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
t a -> (a -> f b) -> f (t b)
for
              [Rel c]
r
              ( \Rel c
x -> do
                  t <- QueryFilter 'ArchetypeFilter -> World -> Entity -> IO Bool
filterEntity QueryFilter 'ArchetypeFilter
f World
world Rel c
x.target
                  if t
                    then
                      fmap (From x.target) <$> runQueryEntity q world x.target
                    else pure Nothing
              )
          case catMaybes rs of
            [] -> (Entity, Bool, Maybe [From out])
-> IO (Entity, Bool, Maybe [From out])
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Entity
e, Bool
b, Maybe [From out]
forall a. Maybe a
Nothing)
            [From out]
x -> (Entity, Bool, Maybe [From out])
-> IO (Entity, Bool, Maybe [From out])
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Entity
e, Bool
b, [From out] -> Maybe [From out]
forall a. a -> Maybe a
Just [From out]
x)

  relQueryTypes :: MR c (Q' q (QueryFilter 'ArchetypeFilter))
-> Set (TypeRep, TypeQuery)
relQueryTypes MR c (Q' q (QueryFilter 'ArchetypeFilter))
_ = Set (TypeRep, TypeQuery)
forall a. Set a
Set.empty

instance (Component c, Queryable q out) => RelQuery True (MR c (Q q)) (Maybe (From out)) where
  relRunQueryEntity :: MR c (Q q) -> World -> Entity -> IO (Maybe (Maybe (From out)))
relRunQueryEntity (MR (Q q
q)) World
world Entity
entity = do
    res <- forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> World -> Entity -> IO (Maybe output)
relRunQueryEntity @True (forall {k} (a :: k) b. b -> MR a b
forall a b. b -> MR a b
MR @c Any
Any) World
world Entity
entity
    case res of
      Maybe (Maybe (Rel c))
Nothing -> Maybe (Maybe (From out)) -> IO (Maybe (Maybe (From out)))
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe (Maybe (From out))
forall a. Maybe a
Nothing
      Just Maybe (Rel c)
Nothing -> Maybe (Maybe (From out)) -> IO (Maybe (Maybe (From out)))
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe (Maybe (From out)) -> IO (Maybe (Maybe (From out))))
-> Maybe (Maybe (From out)) -> IO (Maybe (Maybe (From out)))
forall a b. (a -> b) -> a -> b
$ Maybe (From out) -> Maybe (Maybe (From out))
forall a. a -> Maybe a
Just Maybe (From out)
forall a. Maybe a
Nothing
      Just (Just Rel c
x) -> Maybe (From out) -> Maybe (Maybe (From out))
forall a. a -> Maybe a
Just (Maybe (From out) -> Maybe (Maybe (From out)))
-> (Maybe out -> Maybe (From out))
-> Maybe out
-> Maybe (Maybe (From out))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (out -> From out) -> Maybe out -> Maybe (From out)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Entity -> out -> From out
forall c. Entity -> c -> From c
From Rel c
x.target) (Maybe out -> Maybe (Maybe (From out)))
-> IO (Maybe out) -> IO (Maybe (Maybe (From out)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> q -> World -> Entity -> IO (Maybe out)
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity q
q World
world Rel c
x.target

  relRunQueryInternal :: MR c (Q q)
-> [ArchetypeId] -> World -> IO [(Entity, Bool, Maybe (From out))]
relRunQueryInternal (MR (Q q
q)) [ArchetypeId]
archetypes World
world = do
    res <- forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
relRunQueryInternal @True (forall {k} (a :: k) b. b -> MR a b
forall a b. b -> MR a b
MR @c Any
Any) [ArchetypeId]
archetypes World
world
    for res $ \(Entity
e, Bool
b, Maybe (Rel c)
r) -> do
      case Maybe (Rel c)
r of
        Maybe (Rel c)
Nothing -> (Entity, Bool, Maybe (From out))
-> IO (Entity, Bool, Maybe (From out))
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Entity
e, Bool
b, Maybe (From out)
forall a. Maybe a
Nothing)
        Just Rel c
r -> do
          res <- (out -> From out) -> Maybe out -> Maybe (From out)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Entity -> out -> From out
forall c. Entity -> c -> From c
From Rel c
r.target) (Maybe out -> Maybe (From out))
-> IO (Maybe out) -> IO (Maybe (From out))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> q -> World -> Entity -> IO (Maybe out)
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity q
q World
world Rel c
r.target
          pure (e, b, res)

  relQueryTypes :: MR c (Q q) -> Set (TypeRep, TypeQuery)
relQueryTypes MR c (Q q)
_ = Set (TypeRep, TypeQuery)
forall a. Set a
Set.empty

instance (Component c, Queryable q out) => RelQuery True (MR c (Q' q (QueryFilter ArchetypeFilter))) (Maybe (From out)) where
  relRunQueryEntity :: MR c (Q' q (QueryFilter 'ArchetypeFilter))
-> World -> Entity -> IO (Maybe (Maybe (From out)))
relRunQueryEntity (MR (Q' q
q QueryFilter 'ArchetypeFilter
f)) World
world Entity
entity = do
    res <- forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> World -> Entity -> IO (Maybe output)
relRunQueryEntity @True (forall {k} (a :: k) b. b -> MR a b
forall a b. b -> MR a b
MR @c Any
Any) World
world Entity
entity
    case res of
      Maybe (Maybe (Rel c))
Nothing -> Maybe (Maybe (From out)) -> IO (Maybe (Maybe (From out)))
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe (Maybe (From out))
forall a. Maybe a
Nothing
      Just Maybe (Rel c)
Nothing -> Maybe (Maybe (From out)) -> IO (Maybe (Maybe (From out)))
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe (Maybe (From out)) -> IO (Maybe (Maybe (From out))))
-> Maybe (Maybe (From out)) -> IO (Maybe (Maybe (From out)))
forall a b. (a -> b) -> a -> b
$ Maybe (From out) -> Maybe (Maybe (From out))
forall a. a -> Maybe a
Just Maybe (From out)
forall a. Maybe a
Nothing
      Just (Just Rel c
x) -> do
        t <- QueryFilter 'ArchetypeFilter -> World -> Entity -> IO Bool
filterEntity QueryFilter 'ArchetypeFilter
f World
world Rel c
x.target
        if t
          then
            Just . fmap (From x.target) <$> runQueryEntity q world x.target
          else pure (Just Nothing)

  relRunQueryInternal :: MR c (Q' q (QueryFilter 'ArchetypeFilter))
-> [ArchetypeId] -> World -> IO [(Entity, Bool, Maybe (From out))]
relRunQueryInternal (MR (Q' q
q QueryFilter 'ArchetypeFilter
f)) [ArchetypeId]
archetypes World
world = do
    res <- forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
relRunQueryInternal @True (forall {k} (a :: k) b. b -> MR a b
forall a b. b -> MR a b
MR @c Any
Any) [ArchetypeId]
archetypes World
world
    for res $ \(Entity
e, Bool
b, Maybe (Rel c)
r) -> do
      case Maybe (Rel c)
r of
        Maybe (Rel c)
Nothing -> (Entity, Bool, Maybe (From out))
-> IO (Entity, Bool, Maybe (From out))
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Entity
e, Bool
b, Maybe (From out)
forall a. Maybe a
Nothing)
        Just Rel c
r -> do
          res <- do
            t <- QueryFilter 'ArchetypeFilter -> World -> Entity -> IO Bool
filterEntity QueryFilter 'ArchetypeFilter
f World
world Rel c
r.target
            if t
              then
                fmap (From r.target) <$> runQueryEntity q world r.target
              else pure Nothing
          pure (e, b, res)

  relQueryTypes :: MR c (Q' q (QueryFilter 'ArchetypeFilter))
-> Set (TypeRep, TypeQuery)
relQueryTypes MR c (Q' q (QueryFilter 'ArchetypeFilter))
_ = Set (TypeRep, TypeQuery)
forall a. Set a
Set.empty

instance (RelQuery (IsExclusiveRel c) (MR c Any) out) => Queryable (MR c Any) out where
  runQueryEntity :: MR c Any -> World -> Entity -> IO (Maybe out)
runQueryEntity = forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> World -> Entity -> IO (Maybe output)
relRunQueryEntity @(IsExclusiveRel c)

  runQueryInternal :: MR c Any -> [ArchetypeId] -> World -> IO [(Entity, Bool, out)]
runQueryInternal = forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
relRunQueryInternal @(IsExclusiveRel c)
  queryTypes :: MR c Any -> Set (TypeRep, TypeQuery)
queryTypes MR c Any
_ = Set (TypeRep, TypeQuery)
forall a. Set a
Set.empty

instance (RelQuery (IsExclusiveRel c) (MR c (Q q)) out) => Queryable (MR c (Q q)) out where
  runQueryEntity :: MR c (Q q) -> World -> Entity -> IO (Maybe out)
runQueryEntity = forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> World -> Entity -> IO (Maybe output)
relRunQueryEntity @(IsExclusiveRel c)

  runQueryInternal :: MR c (Q q) -> [ArchetypeId] -> World -> IO [(Entity, Bool, out)]
runQueryInternal = forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
relRunQueryInternal @(IsExclusiveRel c)
  queryTypes :: MR c (Q q) -> Set (TypeRep, TypeQuery)
queryTypes MR c (Q q)
_ = Set (TypeRep, TypeQuery)
forall a. Set a
Set.empty

instance (RelQuery (IsExclusiveRel c) (MR c (Q' q f)) out) => Queryable (MR c (Q' q f)) out where
  runQueryEntity :: MR c (Q' q f) -> World -> Entity -> IO (Maybe out)
runQueryEntity = forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> World -> Entity -> IO (Maybe output)
relRunQueryEntity @(IsExclusiveRel c)

  runQueryInternal :: MR c (Q' q f) -> [ArchetypeId] -> World -> IO [(Entity, Bool, out)]
runQueryInternal = forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
relRunQueryInternal @(IsExclusiveRel c)
  queryTypes :: MR c (Q' q f) -> Set (TypeRep, TypeQuery)
queryTypes MR c (Q' q f)
_ = Set (TypeRep, TypeQuery)
forall a. Set a
Set.empty

instance (Component c) => Queryable (Has c) Bool where
  runQueryEntity :: Has c -> World -> Entity -> IO (Maybe Bool)
runQueryEntity Has c
_ World
world Entity
entity = do
    list <- M c -> World -> Entity -> IO (Maybe (Maybe c))
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity (forall a. M a
forall {k} (a :: k). M a
M @c) World
world Entity
entity
    case list of
      Maybe (Maybe c)
Nothing -> Maybe Bool -> IO (Maybe Bool)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Bool
forall a. Maybe a
Nothing
      Just Maybe c
x -> Maybe Bool -> IO (Maybe Bool)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Bool -> IO (Maybe Bool)) -> Maybe Bool -> IO (Maybe Bool)
forall a b. (a -> b) -> a -> b
$ Bool -> Maybe Bool
forall a. a -> Maybe a
Just (Maybe c -> Bool
forall a. Maybe a -> Bool
isJust Maybe c
x)

  runQueryInternal :: Has c -> [ArchetypeId] -> World -> IO [(Entity, Bool, Bool)]
runQueryInternal Has c
_ [ArchetypeId]
archetypes World
world = do
    list <- M c -> [ArchetypeId] -> World -> IO [(Entity, Bool, Maybe c)]
forall qd output.
Queryable qd output =>
qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
runQueryInternal (forall a. M a
forall {k} (a :: k). M a
M @c) [ArchetypeId]
archetypes World
world
    return $ map (Data.Bifunctor.second isJust) list

  queryTypes :: Has c -> Set (TypeRep, TypeQuery)
queryTypes Has c
_ = Set (TypeRep, TypeQuery)
forall a. Set a
Set.empty

instance (Component c) => Queryable (HasR c Any) Bool where
  runQueryEntity :: HasR c Any -> World -> Entity -> IO (Maybe Bool)
runQueryEntity HasR c Any
_ World
world Entity
entity = do
    res <- forall c.
Component c =>
World -> Entity -> IO (Maybe (Maybe [Rel c]))
tryGetEntityRelCollection @c World
world Entity
entity
    return $ case res of
      Maybe (Maybe [Rel c])
Nothing -> Maybe Bool
forall a. Maybe a
Nothing
      Just Maybe [Rel c]
Nothing -> Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False
      Just (Just [Rel c]
_) -> Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True

  runQueryInternal :: HasR c Any -> [ArchetypeId] -> World -> IO [(Entity, Bool, Bool)]
runQueryInternal HasR c Any
_ [ArchetypeId]
archetypes World
world = do
    res <- forall c.
Component c =>
World -> [ArchetypeId] -> IO [(Entity, [Rel c])]
tryGetRelCollections @c World
world [ArchetypeId]
archetypes
    return $ map ((\(Entity
a, Bool
b) -> (Entity
a, Bool
True, Bool
b)) . Data.Bifunctor.second null) res

  queryTypes :: HasR c Any -> Set (TypeRep, TypeQuery)
queryTypes HasR c Any
_ = Set (TypeRep, TypeQuery)
forall a. Set a
Set.empty

instance (Component c) => Queryable (HasR c Entity) Bool where
  runQueryEntity :: HasR c Entity -> World -> Entity -> IO (Maybe Bool)
runQueryEntity (HasR Entity
target) World
world Entity
entity = do
    res <- forall c.
Component c =>
Entity -> World -> Entity -> IO (Maybe (Maybe c))
tryGetEntityRel @c Entity
target World
world Entity
entity
    return $ case res of
      Maybe (Maybe c)
Nothing -> Maybe Bool
forall a. Maybe a
Nothing
      Just Maybe c
Nothing -> Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False
      Just (Just c
_) -> Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True

  runQueryInternal :: HasR c Entity
-> [ArchetypeId] -> World -> IO [(Entity, Bool, Bool)]
runQueryInternal (HasR Entity
target) [ArchetypeId]
archetypes World
world = do
    res <- MR c Entity
-> [ArchetypeId] -> World -> IO [(Entity, Bool, Maybe (Rel c))]
forall qd output.
Queryable qd output =>
qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
runQueryInternal (forall {k} (a :: k) b. b -> MR a b
forall a b. b -> MR a b
MR @c Entity
target) [ArchetypeId]
archetypes World
world
    return $ map (Data.Bifunctor.second isNothing) res

  queryTypes :: HasR c Entity -> Set (TypeRep, TypeQuery)
queryTypes HasR c Entity
_ = Set (TypeRep, TypeQuery)
forall a. Set a
Set.empty

instance (Component c, Queryable q out) => Queryable (HasR c (Q q)) Bool where
  runQueryEntity :: HasR c (Q q) -> World -> Entity -> IO (Maybe Bool)
runQueryEntity (HasR (Q q
q)) World
world Entity
entity = do
    res <- forall c.
Component c =>
World -> Entity -> IO (Maybe (Maybe [Rel c]))
tryGetEntityRelCollection @c World
world Entity
entity
    case res of
      Maybe (Maybe [Rel c])
Nothing -> Maybe Bool -> IO (Maybe Bool)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Bool
forall a. Maybe a
Nothing
      Just Maybe [Rel c]
Nothing -> Maybe Bool -> IO (Maybe Bool)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe Bool -> IO (Maybe Bool)) -> Maybe Bool -> IO (Maybe Bool)
forall a b. (a -> b) -> a -> b
$ Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False
      Just (Just [Rel c]
r) -> do
        res <- [Maybe out] -> [out]
forall a. [Maybe a] -> [a]
catMaybes ([Maybe out] -> [out]) -> IO [Maybe out] -> IO [out]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Rel c] -> (Rel c -> IO (Maybe out)) -> IO [Maybe out]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
t a -> (a -> f b) -> f (t b)
for [Rel c]
r (\Rel c
r -> q -> World -> Entity -> IO (Maybe out)
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity q
q World
world Rel c
r.target)
        case res of
          [] -> Maybe Bool -> IO (Maybe Bool)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe Bool -> IO (Maybe Bool)) -> Maybe Bool -> IO (Maybe Bool)
forall a b. (a -> b) -> a -> b
$ Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False
          [out]
_ -> Maybe Bool -> IO (Maybe Bool)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe Bool -> IO (Maybe Bool)) -> Maybe Bool -> IO (Maybe Bool)
forall a b. (a -> b) -> a -> b
$ Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True

  runQueryInternal :: HasR c (Q q) -> [ArchetypeId] -> World -> IO [(Entity, Bool, Bool)]
runQueryInternal (HasR (Q q
q)) [ArchetypeId]
archetypes World
world = do
    res <- forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
relRunQueryInternal @False (forall {k} (a :: k) b. b -> MR a b
forall a b. b -> MR a b
MR @c Any
Any) [ArchetypeId]
archetypes World
world
    for res $ \(Entity
e, Bool
b, Maybe [Rel c]
r) -> do
      case Maybe [Rel c]
r of
        Maybe [Rel c]
Nothing -> (Entity, Bool, Bool) -> IO (Entity, Bool, Bool)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Entity
e, Bool
b, Bool
False)
        Just [Rel c]
r -> do
          res <- [Maybe out] -> [out]
forall a. [Maybe a] -> [a]
catMaybes ([Maybe out] -> [out]) -> IO [Maybe out] -> IO [out]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Rel c] -> (Rel c -> IO (Maybe out)) -> IO [Maybe out]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
t a -> (a -> f b) -> f (t b)
for [Rel c]
r (\Rel c
r -> q -> World -> Entity -> IO (Maybe out)
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity q
q World
world Rel c
r.target)
          case res of
            [] -> (Entity, Bool, Bool) -> IO (Entity, Bool, Bool)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Entity
e, Bool
b, Bool
False)
            [out]
_ -> (Entity, Bool, Bool) -> IO (Entity, Bool, Bool)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Entity
e, Bool
b, Bool
True)

  queryTypes :: HasR c (Q q) -> Set (TypeRep, TypeQuery)
queryTypes HasR c (Q q)
_ = Set (TypeRep, TypeQuery)
forall a. Set a
Set.empty

instance (Component c, Queryable q out) => Queryable (HasR c (Q' q (QueryFilter ArchetypeFilter))) Bool where
  runQueryEntity :: HasR c (Q' q (QueryFilter 'ArchetypeFilter))
-> World -> Entity -> IO (Maybe Bool)
runQueryEntity (HasR (Q' q
q QueryFilter 'ArchetypeFilter
f)) World
world Entity
entity = do
    res <- forall c.
Component c =>
World -> Entity -> IO (Maybe (Maybe [Rel c]))
tryGetEntityRelCollection @c World
world Entity
entity
    case res of
      Maybe (Maybe [Rel c])
Nothing -> Maybe Bool -> IO (Maybe Bool)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Bool
forall a. Maybe a
Nothing
      Just Maybe [Rel c]
Nothing -> Maybe Bool -> IO (Maybe Bool)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe Bool -> IO (Maybe Bool)) -> Maybe Bool -> IO (Maybe Bool)
forall a b. (a -> b) -> a -> b
$ Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False
      Just (Just [Rel c]
r) -> do
        res <-
          [Maybe out] -> [out]
forall a. [Maybe a] -> [a]
catMaybes
            ([Maybe out] -> [out]) -> IO [Maybe out] -> IO [out]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Rel c] -> (Rel c -> IO (Maybe out)) -> IO [Maybe out]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
t a -> (a -> f b) -> f (t b)
for
              [Rel c]
r
              ( \Rel c
r -> do
                  t <- QueryFilter 'ArchetypeFilter -> World -> Entity -> IO Bool
filterEntity QueryFilter 'ArchetypeFilter
f World
world Rel c
r.target
                  if t
                    then
                      runQueryEntity q world r.target
                    else pure Nothing
              )
        case res of
          [] -> Maybe Bool -> IO (Maybe Bool)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe Bool -> IO (Maybe Bool)) -> Maybe Bool -> IO (Maybe Bool)
forall a b. (a -> b) -> a -> b
$ Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False
          [out]
_ -> Maybe Bool -> IO (Maybe Bool)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe Bool -> IO (Maybe Bool)) -> Maybe Bool -> IO (Maybe Bool)
forall a b. (a -> b) -> a -> b
$ Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True

  runQueryInternal :: HasR c (Q' q (QueryFilter 'ArchetypeFilter))
-> [ArchetypeId] -> World -> IO [(Entity, Bool, Bool)]
runQueryInternal (HasR (Q' q
q QueryFilter 'ArchetypeFilter
f)) [ArchetypeId]
archetypes World
world = do
    res <- forall (exclusive :: Bool) qd output.
RelQuery exclusive qd output =>
qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
relRunQueryInternal @False (forall {k} (a :: k) b. b -> MR a b
forall a b. b -> MR a b
MR @c Any
Any) [ArchetypeId]
archetypes World
world
    for res $ \(Entity
e, Bool
b, Maybe [Rel c]
r) -> do
      case Maybe [Rel c]
r of
        Maybe [Rel c]
Nothing -> (Entity, Bool, Bool) -> IO (Entity, Bool, Bool)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Entity
e, Bool
b, Bool
False)
        Just [Rel c]
r -> do
          res <-
            [Maybe out] -> [out]
forall a. [Maybe a] -> [a]
catMaybes
              ([Maybe out] -> [out]) -> IO [Maybe out] -> IO [out]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Rel c] -> (Rel c -> IO (Maybe out)) -> IO [Maybe out]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
t a -> (a -> f b) -> f (t b)
for
                [Rel c]
r
                ( \Rel c
r -> do
                    t <- QueryFilter 'ArchetypeFilter -> World -> Entity -> IO Bool
filterEntity QueryFilter 'ArchetypeFilter
f World
world Rel c
r.target
                    if t
                      then
                        runQueryEntity q world r.target
                      else pure Nothing
                )
          case res of
            [] -> (Entity, Bool, Bool) -> IO (Entity, Bool, Bool)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Entity
e, Bool
b, Bool
False)
            [out]
_ -> (Entity, Bool, Bool) -> IO (Entity, Bool, Bool)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Entity
e, Bool
b, Bool
True)

  queryTypes :: HasR c (Q' q (QueryFilter 'ArchetypeFilter))
-> Set (TypeRep, TypeQuery)
queryTypes HasR c (Q' q (QueryFilter 'ArchetypeFilter))
_ = Set (TypeRep, TypeQuery)
forall a. Set a
Set.empty

filterEntity' :: FilterComponent -> Entity -> World -> IO Bool
filterEntity' :: FilterComponent -> Entity -> World -> IO Bool
filterEntity' (FilterComponent (TypeRep
x, Maybe Entity
Nothing, Maybe Any
Nothing)) Entity
entity World
world = do
  comp <- TypeRep -> Components -> IO (Maybe ComponentId)
getComponentId TypeRep
x World
world.components
  case comp of
    Maybe ComponentId
Nothing -> Bool -> IO Bool
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
False
    Just (ComponentId (# Word#
id, Maybe Entity
_ #)) -> do
      Just (ComponentType (_ :: Proxy a)) <- C ComponentType -> World -> Entity -> IO (Maybe ComponentType)
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity (forall a. C a
forall {k} (a :: k). C a
C @ComponentType) World
world ((# Word#, Word# #) -> Entity
Entity (# Word#
id, Word#
0## #))
      a <- runQueryEntity (Has @a) world entity
      pure $ fromMaybe False a
filterEntity' (FilterComponent (TypeRep
x, Just Entity
e, Maybe Any
Nothing)) Entity
entity World
world = do
  comp <- TypeRep -> Components -> IO (Maybe ComponentId)
getComponentId TypeRep
x World
world.components
  case comp of
    Maybe ComponentId
Nothing -> Bool -> IO Bool
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
    Just (ComponentId (# Word#
id, Maybe Entity
_ #)) -> do
      Just (ComponentType (_ :: Proxy a)) <- C ComponentType -> World -> Entity -> IO (Maybe ComponentType)
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity (forall a. C a
forall {k} (a :: k). C a
C @ComponentType) World
world ((# Word#, Word# #) -> Entity
Entity (# Word#
id, Word#
0## #))
      a <- runQueryEntity (HasR @a e) world entity
      pure $ fromMaybe False a
filterEntity' (FilterComponent (TypeRep
x, Maybe Entity
_, Just Any
_)) Entity
entity World
world = do
  comp <- IO (Maybe ComponentId) -> IO (Maybe ComponentId)
forall a. IO a -> IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe ComponentId) -> IO (Maybe ComponentId))
-> IO (Maybe ComponentId) -> IO (Maybe ComponentId)
forall a b. (a -> b) -> a -> b
$ TypeRep -> Components -> IO (Maybe ComponentId)
getComponentId TypeRep
x World
world.components
  case comp of
    Maybe ComponentId
Nothing -> Bool -> IO Bool
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
    Just (ComponentId (# Word#
id, Maybe Entity
_ #)) -> do
      Just (ComponentType (_ :: Proxy a)) <- IO (Maybe ComponentType) -> IO (Maybe ComponentType)
forall a. IO a -> IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe ComponentType) -> IO (Maybe ComponentType))
-> IO (Maybe ComponentType) -> IO (Maybe ComponentType)
forall a b. (a -> b) -> a -> b
$ C ComponentType -> World -> Entity -> IO (Maybe ComponentType)
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity (forall a. C a
forall {k} (a :: k). C a
C @ComponentType) World
world ((# Word#, Word# #) -> Entity
Entity (# Word#
id, Word#
0## #))
      a <- liftIO $ runQueryEntity (HasR @a Any) world entity
      pure $ fromMaybe False a

filterEntity :: QueryFilter ArchetypeFilter -> World -> Entity -> IO Bool
filterEntity :: QueryFilter 'ArchetypeFilter -> World -> Entity -> IO Bool
filterEntity QueryFilter 'ArchetypeFilter
NoFilter World
_ Entity
_ = Bool -> IO Bool
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
True
filterEntity (With a
x) World
world Entity
entity = FilterComponent -> Entity -> World -> IO Bool
filterEntity' (a -> FilterComponent
forall a. ToFilterComponent a => a -> FilterComponent
toFilterComponent a
x) Entity
entity World
world
filterEntity (Without a
x) World
world Entity
entity = Bool -> Bool
not (Bool -> Bool) -> IO Bool -> IO Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FilterComponent -> Entity -> World -> IO Bool
filterEntity' (a -> FilterComponent
forall a. ToFilterComponent a => a -> FilterComponent
toFilterComponent a
x) Entity
entity World
world
filterEntity (Not QueryFilter 'ArchetypeFilter
a) World
world Entity
entity = Bool -> Bool
not (Bool -> Bool) -> IO Bool -> IO Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> QueryFilter 'ArchetypeFilter -> World -> Entity -> IO Bool
filterEntity QueryFilter 'ArchetypeFilter
a World
world Entity
entity
filterEntity (And QueryFilter 'ArchetypeFilter
a QueryFilter 'ArchetypeFilter
b) World
world Entity
entity = Bool -> Bool -> Bool
(&&) (Bool -> Bool -> Bool) -> IO Bool -> IO (Bool -> Bool)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> QueryFilter 'ArchetypeFilter -> World -> Entity -> IO Bool
filterEntity QueryFilter 'ArchetypeFilter
a World
world Entity
entity IO (Bool -> Bool) -> IO Bool -> IO Bool
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> QueryFilter 'ArchetypeFilter -> World -> Entity -> IO Bool
filterEntity QueryFilter 'ArchetypeFilter
b World
world Entity
entity
filterEntity (Or QueryFilter 'ArchetypeFilter
a QueryFilter 'ArchetypeFilter
b) World
world Entity
entity = Bool -> Bool -> Bool
(||) (Bool -> Bool -> Bool) -> IO Bool -> IO (Bool -> Bool)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> QueryFilter 'ArchetypeFilter -> World -> Entity -> IO Bool
filterEntity QueryFilter 'ArchetypeFilter
a World
world Entity
entity IO (Bool -> Bool) -> IO Bool -> IO Bool
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> QueryFilter 'ArchetypeFilter -> World -> Entity -> IO Bool
filterEntity QueryFilter 'ArchetypeFilter
b World
world Entity
entity

findComponentsOfEntity :: World -> Entity -> IO (Maybe [ComponentId])
findComponentsOfEntity :: World -> Entity -> IO (Maybe [ComponentId])
findComponentsOfEntity World
world Entity
entity = do
  pointer <- Entity -> Entities -> IO (Maybe (IORef EntityPointer))
getPointer Entity
entity World
world.entities

  case pointer of
    Maybe (IORef EntityPointer)
Nothing -> Maybe [ComponentId] -> IO (Maybe [ComponentId])
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe [ComponentId]
forall a. Maybe a
Nothing
    Just IORef EntityPointer
x -> do
      (EntityPointer (# archetypeId, _ #)) <- IORef EntityPointer -> IO EntityPointer
forall a. IORef a -> IO a
readIORef IORef EntityPointer
x

      x <- Vec.read world.tables.inner (I# archetypeId)

      pure $ Just x.components

addedChanged' :: forall m w. (MonadSystem w m) => (ComponentTicks -> Tick -> Tick -> Bool) -> ComponentId -> Entity -> m Bool
addedChanged' :: forall (m :: * -> *) w.
MonadSystem w m =>
(ComponentTicks -> Tick -> Tick -> Bool)
-> ComponentId -> Entity -> m Bool
addedChanged' ComponentTicks -> Tick -> Tick -> Bool
f ComponentId
id Entity
entity = do
  world <- m World
forall w (m :: * -> *). MonadSystem w m => m World
unsafeGetWorld
  ticks <- liftIO $ tryGetEntityTicks entity id world
  case ticks of
    Maybe ComponentTicks
Nothing -> Bool -> m Bool
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
    Just ComponentTicks
ticks -> do
      (lastSystemTick, currentSystemTick) <- IO (Tick, Tick) -> m (Tick, Tick)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Tick, Tick) -> m (Tick, Tick))
-> IO (Tick, Tick) -> m (Tick, Tick)
forall a b. (a -> b) -> a -> b
$ World -> IO (Tick, Tick)
getSystemTicksInternal World
world
      return $ f ticks lastSystemTick currentSystemTick

getSystemTicksInternal :: World -> IO (Tick, Tick)
getSystemTicksInternal :: World -> IO (Tick, Tick)
getSystemTicksInternal World
world = do
  let (SystemId Entity
sys) = World
world.systemId
  Just a <- C LastSystemTick -> World -> Entity -> IO (Maybe LastSystemTick)
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity (forall a. C a
forall {k} (a :: k). C a
C @LastSystemTick) World
world Entity
sys
  Just b <- runQueryEntity (C @SystemTick) world sys
  return (a.inner, b.inner)

instance {-# OVERLAPPING #-} (Queryable q0 o0, Queryable q1 o1) => Queryable (q0, q1) (o0, o1) where
  runQueryEntity :: (q0, q1) -> World -> Entity -> IO (Maybe (o0, o1))
runQueryEntity (q0
q0, q1
q1) World
world Entity
entity = do
    r0 <- q0 -> World -> Entity -> IO (Maybe o0)
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity q0
q0 World
world Entity
entity
    r1 <- runQueryEntity q1 world entity

    return $ (,) <$> r0 <*> r1

  runQueryInternal :: (q0, q1) -> [ArchetypeId] -> World -> IO [(Entity, Bool, (o0, o1))]
runQueryInternal (q0
q0, q1
q1) [ArchetypeId]
archetypes World
world = do
    r0 <- q0 -> [ArchetypeId] -> World -> IO [(Entity, Bool, o0)]
forall qd output.
Queryable qd output =>
qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
runQueryInternal q0
q0 [ArchetypeId]
archetypes World
world
    r1 <- runQueryInternal q1 archetypes world

    return $ map (\((Entity
e0, Bool
b0, o0
r0), (Entity
_, Bool
b1, o1
r1)) -> (Entity
e0, Bool
b0 Bool -> Bool -> Bool
|| Bool
b1, (o0
r0, o1
r1))) $ getZipList $ (,) <$> ZipList r0 <*> ZipList r1

  queryTypes :: (q0, q1) -> Set (TypeRep, TypeQuery)
queryTypes (q0
q0, q1
q1) = [Set (TypeRep, TypeQuery)] -> Set (TypeRep, TypeQuery)
forall (f :: * -> *) a. (Foldable f, Ord a) => f (Set a) -> Set a
Set.unions [q0 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q0
q0, q1 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q1
q1]

instance {-# OVERLAPPING #-} (Queryable q0 o0, Queryable q1 o1, Queryable q2 o2) => Queryable (q0, q1, q2) (o0, o1, o2) where
  runQueryEntity :: (q0, q1, q2) -> World -> Entity -> IO (Maybe (o0, o1, o2))
runQueryEntity (q0
q0, q1
q1, q2
q2) World
world Entity
entity = do
    r0 <- q0 -> World -> Entity -> IO (Maybe o0)
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity q0
q0 World
world Entity
entity
    r1 <- runQueryEntity q1 world entity
    r2 <- runQueryEntity q2 world entity

    return $ (,,) <$> r0 <*> r1 <*> r2

  runQueryInternal :: (q0, q1, q2)
-> [ArchetypeId] -> World -> IO [(Entity, Bool, (o0, o1, o2))]
runQueryInternal (q0
q0, q1
q1, q2
q2) [ArchetypeId]
archetypes World
world = do
    r0 <- q0 -> [ArchetypeId] -> World -> IO [(Entity, Bool, o0)]
forall qd output.
Queryable qd output =>
qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
runQueryInternal q0
q0 [ArchetypeId]
archetypes World
world
    r1 <- runQueryInternal q1 archetypes world
    r2 <- runQueryInternal q2 archetypes world

    return $ map (\((Entity
e0, Bool
b0, o0
r0), (Entity
_, Bool
b1, o1
r1), (Entity
_, Bool
b2, o2
r2)) -> (Entity
e0, Bool
b0 Bool -> Bool -> Bool
|| Bool
b1 Bool -> Bool -> Bool
|| Bool
b2, (o0
r0, o1
r1, o2
r2))) $ getZipList $ (,,) <$> ZipList r0 <*> ZipList r1 <*> ZipList r2

  queryTypes :: (q0, q1, q2) -> Set (TypeRep, TypeQuery)
queryTypes (q0
q0, q1
q1, q2
q2) = [Set (TypeRep, TypeQuery)] -> Set (TypeRep, TypeQuery)
forall (f :: * -> *) a. (Foldable f, Ord a) => f (Set a) -> Set a
Set.unions [q0 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q0
q0, q1 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q1
q1, q2 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q2
q2]

instance {-# OVERLAPPING #-} (Queryable q0 o0, Queryable q1 o1, Queryable q2 o2, Queryable q3 o3) => Queryable (q0, q1, q2, q3) (o0, o1, o2, o3) where
  runQueryEntity :: (q0, q1, q2, q3) -> World -> Entity -> IO (Maybe (o0, o1, o2, o3))
runQueryEntity (q0
q0, q1
q1, q2
q2, q3
q3) World
world Entity
entity = do
    r0 <- q0 -> World -> Entity -> IO (Maybe o0)
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity q0
q0 World
world Entity
entity
    r1 <- runQueryEntity q1 world entity
    r2 <- runQueryEntity q2 world entity
    r3 <- runQueryEntity q3 world entity

    return $ (,,,) <$> r0 <*> r1 <*> r2 <*> r3

  runQueryInternal :: (q0, q1, q2, q3)
-> [ArchetypeId] -> World -> IO [(Entity, Bool, (o0, o1, o2, o3))]
runQueryInternal (q0
q0, q1
q1, q2
q2, q3
q3) [ArchetypeId]
archetypes World
world = do
    r0 <- q0 -> [ArchetypeId] -> World -> IO [(Entity, Bool, o0)]
forall qd output.
Queryable qd output =>
qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
runQueryInternal q0
q0 [ArchetypeId]
archetypes World
world
    r1 <- runQueryInternal q1 archetypes world
    r2 <- runQueryInternal q2 archetypes world
    r3 <- runQueryInternal q3 archetypes world

    return $ map (\((Entity
e0, Bool
b0, o0
r0), (Entity
_, Bool
b1, o1
r1), (Entity
_, Bool
b2, o2
r2), (Entity
_, Bool
b3, o3
r3)) -> (Entity
e0, Bool
b0 Bool -> Bool -> Bool
|| Bool
b1 Bool -> Bool -> Bool
|| Bool
b2 Bool -> Bool -> Bool
|| Bool
b3, (o0
r0, o1
r1, o2
r2, o3
r3))) $ getZipList $ (,,,) <$> ZipList r0 <*> ZipList r1 <*> ZipList r2 <*> ZipList r3

  queryTypes :: (q0, q1, q2, q3) -> Set (TypeRep, TypeQuery)
queryTypes (q0
q0, q1
q1, q2
q2, q3
q3) = [Set (TypeRep, TypeQuery)] -> Set (TypeRep, TypeQuery)
forall (f :: * -> *) a. (Foldable f, Ord a) => f (Set a) -> Set a
Set.unions [q0 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q0
q0, q1 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q1
q1, q2 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q2
q2, q3 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q3
q3]

instance {-# OVERLAPPING #-} (Queryable q0 o0, Queryable q1 o1, Queryable q2 o2, Queryable q3 o3, Queryable q4 o4) => Queryable (q0, q1, q2, q3, q4) (o0, o1, o2, o3, o4) where
  runQueryEntity :: (q0, q1, q2, q3, q4)
-> World -> Entity -> IO (Maybe (o0, o1, o2, o3, o4))
runQueryEntity (q0
q0, q1
q1, q2
q2, q3
q3, q4
q4) World
world Entity
entity = do
    r0 <- q0 -> World -> Entity -> IO (Maybe o0)
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity q0
q0 World
world Entity
entity
    r1 <- runQueryEntity q1 world entity
    r2 <- runQueryEntity q2 world entity
    r3 <- runQueryEntity q3 world entity
    r4 <- runQueryEntity q4 world entity

    return $ (,,,,) <$> r0 <*> r1 <*> r2 <*> r3 <*> r4

  runQueryInternal :: (q0, q1, q2, q3, q4)
-> [ArchetypeId]
-> World
-> IO [(Entity, Bool, (o0, o1, o2, o3, o4))]
runQueryInternal (q0
q0, q1
q1, q2
q2, q3
q3, q4
q4) [ArchetypeId]
archetypes World
world = do
    r0 <- q0 -> [ArchetypeId] -> World -> IO [(Entity, Bool, o0)]
forall qd output.
Queryable qd output =>
qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
runQueryInternal q0
q0 [ArchetypeId]
archetypes World
world
    r1 <- runQueryInternal q1 archetypes world
    r2 <- runQueryInternal q2 archetypes world
    r3 <- runQueryInternal q3 archetypes world
    r4 <- runQueryInternal q4 archetypes world

    return $ map (\((Entity
e0, Bool
b0, o0
r0), (Entity
_, Bool
b1, o1
r1), (Entity
_, Bool
b2, o2
r2), (Entity
_, Bool
b3, o3
r3), (Entity
_, Bool
b4, o4
r4)) -> (Entity
e0, Bool
b0 Bool -> Bool -> Bool
|| Bool
b1 Bool -> Bool -> Bool
|| Bool
b2 Bool -> Bool -> Bool
|| Bool
b3 Bool -> Bool -> Bool
|| Bool
b4, (o0
r0, o1
r1, o2
r2, o3
r3, o4
r4))) $ getZipList $ (,,,,) <$> ZipList r0 <*> ZipList r1 <*> ZipList r2 <*> ZipList r3 <*> ZipList r4

  queryTypes :: (q0, q1, q2, q3, q4) -> Set (TypeRep, TypeQuery)
queryTypes (q0
q0, q1
q1, q2
q2, q3
q3, q4
q4) = [Set (TypeRep, TypeQuery)] -> Set (TypeRep, TypeQuery)
forall (f :: * -> *) a. (Foldable f, Ord a) => f (Set a) -> Set a
Set.unions [q0 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q0
q0, q1 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q1
q1, q2 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q2
q2, q3 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q3
q3, q4 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q4
q4]

instance {-# OVERLAPPING #-} (Queryable q0 o0, Queryable q1 o1, Queryable q2 o2, Queryable q3 o3, Queryable q4 o4, Queryable q5 o5) => Queryable (q0, q1, q2, q3, q4, q5) (o0, o1, o2, o3, o4, o5) where
  runQueryEntity :: (q0, q1, q2, q3, q4, q5)
-> World -> Entity -> IO (Maybe (o0, o1, o2, o3, o4, o5))
runQueryEntity (q0
q0, q1
q1, q2
q2, q3
q3, q4
q4, q5
q5) World
world Entity
entity = do
    r0 <- q0 -> World -> Entity -> IO (Maybe o0)
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity q0
q0 World
world Entity
entity
    r1 <- runQueryEntity q1 world entity
    r2 <- runQueryEntity q2 world entity
    r3 <- runQueryEntity q3 world entity
    r4 <- runQueryEntity q4 world entity
    r5 <- runQueryEntity q5 world entity

    return $ (,,,,,) <$> r0 <*> r1 <*> r2 <*> r3 <*> r4 <*> r5

  runQueryInternal :: (q0, q1, q2, q3, q4, q5)
-> [ArchetypeId]
-> World
-> IO [(Entity, Bool, (o0, o1, o2, o3, o4, o5))]
runQueryInternal (q0
q0, q1
q1, q2
q2, q3
q3, q4
q4, q5
q5) [ArchetypeId]
archetypes World
world = do
    r0 <- q0 -> [ArchetypeId] -> World -> IO [(Entity, Bool, o0)]
forall qd output.
Queryable qd output =>
qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
runQueryInternal q0
q0 [ArchetypeId]
archetypes World
world
    r1 <- runQueryInternal q1 archetypes world
    r2 <- runQueryInternal q2 archetypes world
    r3 <- runQueryInternal q3 archetypes world
    r4 <- runQueryInternal q4 archetypes world
    r5 <- runQueryInternal q5 archetypes world

    return $ map (\((Entity
e0, Bool
b0, o0
r0), (Entity
_, Bool
b1, o1
r1), (Entity
_, Bool
b2, o2
r2), (Entity
_, Bool
b3, o3
r3), (Entity
_, Bool
b4, o4
r4), (Entity
_, Bool
b5, o5
r5)) -> (Entity
e0, Bool
b0 Bool -> Bool -> Bool
|| Bool
b1 Bool -> Bool -> Bool
|| Bool
b2 Bool -> Bool -> Bool
|| Bool
b3 Bool -> Bool -> Bool
|| Bool
b4 Bool -> Bool -> Bool
|| Bool
b5, (o0
r0, o1
r1, o2
r2, o3
r3, o4
r4, o5
r5))) $ getZipList $ (,,,,,) <$> ZipList r0 <*> ZipList r1 <*> ZipList r2 <*> ZipList r3 <*> ZipList r4 <*> ZipList r5

  queryTypes :: (q0, q1, q2, q3, q4, q5) -> Set (TypeRep, TypeQuery)
queryTypes (q0
q0, q1
q1, q2
q2, q3
q3, q4
q4, q5
q5) = [Set (TypeRep, TypeQuery)] -> Set (TypeRep, TypeQuery)
forall (f :: * -> *) a. (Foldable f, Ord a) => f (Set a) -> Set a
Set.unions [q0 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q0
q0, q1 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q1
q1, q2 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q2
q2, q3 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q3
q3, q4 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q4
q4, q5 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q5
q5]

instance {-# OVERLAPPING #-} (Queryable q0 o0, Queryable q1 o1, Queryable q2 o2, Queryable q3 o3, Queryable q4 o4, Queryable q5 o5, Queryable q6 o6) => Queryable (q0, q1, q2, q3, q4, q5, q6) (o0, o1, o2, o3, o4, o5, o6) where
  runQueryEntity :: (q0, q1, q2, q3, q4, q5, q6)
-> World -> Entity -> IO (Maybe (o0, o1, o2, o3, o4, o5, o6))
runQueryEntity (q0
q0, q1
q1, q2
q2, q3
q3, q4
q4, q5
q5, q6
q6) World
world Entity
entity = do
    r0 <- q0 -> World -> Entity -> IO (Maybe o0)
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity q0
q0 World
world Entity
entity
    r1 <- runQueryEntity q1 world entity
    r2 <- runQueryEntity q2 world entity
    r3 <- runQueryEntity q3 world entity
    r4 <- runQueryEntity q4 world entity
    r5 <- runQueryEntity q5 world entity
    r6 <- runQueryEntity q6 world entity

    return $ (,,,,,,) <$> r0 <*> r1 <*> r2 <*> r3 <*> r4 <*> r5 <*> r6

  runQueryInternal :: (q0, q1, q2, q3, q4, q5, q6)
-> [ArchetypeId]
-> World
-> IO [(Entity, Bool, (o0, o1, o2, o3, o4, o5, o6))]
runQueryInternal (q0
q0, q1
q1, q2
q2, q3
q3, q4
q4, q5
q5, q6
q6) [ArchetypeId]
archetypes World
world = do
    r0 <- q0 -> [ArchetypeId] -> World -> IO [(Entity, Bool, o0)]
forall qd output.
Queryable qd output =>
qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
runQueryInternal q0
q0 [ArchetypeId]
archetypes World
world
    r1 <- runQueryInternal q1 archetypes world
    r2 <- runQueryInternal q2 archetypes world
    r3 <- runQueryInternal q3 archetypes world
    r4 <- runQueryInternal q4 archetypes world
    r5 <- runQueryInternal q5 archetypes world
    r6 <- runQueryInternal q6 archetypes world

    return $ map (\((Entity
e0, Bool
b0, o0
r0), (Entity
_, Bool
b1, o1
r1), (Entity
_, Bool
b2, o2
r2), (Entity
_, Bool
b3, o3
r3), (Entity
_, Bool
b4, o4
r4), (Entity
_, Bool
b5, o5
r5), (Entity
_, Bool
b6, o6
r6)) -> (Entity
e0, Bool
b0 Bool -> Bool -> Bool
|| Bool
b1 Bool -> Bool -> Bool
|| Bool
b2 Bool -> Bool -> Bool
|| Bool
b3 Bool -> Bool -> Bool
|| Bool
b4 Bool -> Bool -> Bool
|| Bool
b5 Bool -> Bool -> Bool
|| Bool
b6, (o0
r0, o1
r1, o2
r2, o3
r3, o4
r4, o5
r5, o6
r6))) $ getZipList $ (,,,,,,) <$> ZipList r0 <*> ZipList r1 <*> ZipList r2 <*> ZipList r3 <*> ZipList r4 <*> ZipList r5 <*> ZipList r6

  queryTypes :: (q0, q1, q2, q3, q4, q5, q6) -> Set (TypeRep, TypeQuery)
queryTypes (q0
q0, q1
q1, q2
q2, q3
q3, q4
q4, q5
q5, q6
q6) = [Set (TypeRep, TypeQuery)] -> Set (TypeRep, TypeQuery)
forall (f :: * -> *) a. (Foldable f, Ord a) => f (Set a) -> Set a
Set.unions [q0 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q0
q0, q1 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q1
q1, q2 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q2
q2, q3 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q3
q3, q4 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q4
q4, q5 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q5
q5, q6 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q6
q6]

instance {-# OVERLAPPING #-} (Queryable q0 o0, Queryable q1 o1, Queryable q2 o2, Queryable q3 o3, Queryable q4 o4, Queryable q5 o5, Queryable q6 o6, Queryable q7 o7) => Queryable (q0, q1, q2, q3, q4, q5, q6, q7) (o0, o1, o2, o3, o4, o5, o6, o7) where
  runQueryEntity :: (q0, q1, q2, q3, q4, q5, q6, q7)
-> World -> Entity -> IO (Maybe (o0, o1, o2, o3, o4, o5, o6, o7))
runQueryEntity (q0
q0, q1
q1, q2
q2, q3
q3, q4
q4, q5
q5, q6
q6, q7
q7) World
world Entity
entity = do
    r0 <- q0 -> World -> Entity -> IO (Maybe o0)
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity q0
q0 World
world Entity
entity
    r1 <- runQueryEntity q1 world entity
    r2 <- runQueryEntity q2 world entity
    r3 <- runQueryEntity q3 world entity
    r4 <- runQueryEntity q4 world entity
    r5 <- runQueryEntity q5 world entity
    r6 <- runQueryEntity q6 world entity
    r7 <- runQueryEntity q7 world entity

    return $ (,,,,,,,) <$> r0 <*> r1 <*> r2 <*> r3 <*> r4 <*> r5 <*> r6 <*> r7

  runQueryInternal :: (q0, q1, q2, q3, q4, q5, q6, q7)
-> [ArchetypeId]
-> World
-> IO [(Entity, Bool, (o0, o1, o2, o3, o4, o5, o6, o7))]
runQueryInternal (q0
q0, q1
q1, q2
q2, q3
q3, q4
q4, q5
q5, q6
q6, q7
q7) [ArchetypeId]
archetypes World
world = do
    r0 <- q0 -> [ArchetypeId] -> World -> IO [(Entity, Bool, o0)]
forall qd output.
Queryable qd output =>
qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
runQueryInternal q0
q0 [ArchetypeId]
archetypes World
world
    r1 <- runQueryInternal q1 archetypes world
    r2 <- runQueryInternal q2 archetypes world
    r3 <- runQueryInternal q3 archetypes world
    r4 <- runQueryInternal q4 archetypes world
    r5 <- runQueryInternal q5 archetypes world
    r6 <- runQueryInternal q6 archetypes world
    r7 <- runQueryInternal q7 archetypes world

    return $ map (\((Entity
e0, Bool
b0, o0
r0), (Entity
_, Bool
b1, o1
r1), (Entity
_, Bool
b2, o2
r2), (Entity
_, Bool
b3, o3
r3), (Entity
_, Bool
b4, o4
r4), (Entity
_, Bool
b5, o5
r5), (Entity
_, Bool
b6, o6
r6), (Entity
_, Bool
b7, o7
r7)) -> (Entity
e0, Bool
b0 Bool -> Bool -> Bool
|| Bool
b1 Bool -> Bool -> Bool
|| Bool
b2 Bool -> Bool -> Bool
|| Bool
b3 Bool -> Bool -> Bool
|| Bool
b4 Bool -> Bool -> Bool
|| Bool
b5 Bool -> Bool -> Bool
|| Bool
b6 Bool -> Bool -> Bool
|| Bool
b7, (o0
r0, o1
r1, o2
r2, o3
r3, o4
r4, o5
r5, o6
r6, o7
r7))) $ getZipList $ (,,,,,,,) <$> ZipList r0 <*> ZipList r1 <*> ZipList r2 <*> ZipList r3 <*> ZipList r4 <*> ZipList r5 <*> ZipList r6 <*> ZipList r7

  queryTypes :: (q0, q1, q2, q3, q4, q5, q6, q7) -> Set (TypeRep, TypeQuery)
queryTypes (q0
q0, q1
q1, q2
q2, q3
q3, q4
q4, q5
q5, q6
q6, q7
q7) = [Set (TypeRep, TypeQuery)] -> Set (TypeRep, TypeQuery)
forall (f :: * -> *) a. (Foldable f, Ord a) => f (Set a) -> Set a
Set.unions [q0 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q0
q0, q1 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q1
q1, q2 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q2
q2, q3 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q3
q3, q4 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q4
q4, q5 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q5
q5, q6 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q6
q6, q7 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q7
q7]

instance {-# OVERLAPPING #-} (Queryable q0 o0, Queryable q1 o1, Queryable q2 o2, Queryable q3 o3, Queryable q4 o4, Queryable q5 o5, Queryable q6 o6, Queryable q7 o7, Queryable q8 o8) => Queryable (q0, q1, q2, q3, q4, q5, q6, q7, q8) (o0, o1, o2, o3, o4, o5, o6, o7, o8) where
  runQueryEntity :: (q0, q1, q2, q3, q4, q5, q6, q7, q8)
-> World
-> Entity
-> IO (Maybe (o0, o1, o2, o3, o4, o5, o6, o7, o8))
runQueryEntity (q0
q0, q1
q1, q2
q2, q3
q3, q4
q4, q5
q5, q6
q6, q7
q7, q8
q8) World
world Entity
entity = do
    r0 <- q0 -> World -> Entity -> IO (Maybe o0)
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity q0
q0 World
world Entity
entity
    r1 <- runQueryEntity q1 world entity
    r2 <- runQueryEntity q2 world entity
    r3 <- runQueryEntity q3 world entity
    r4 <- runQueryEntity q4 world entity
    r5 <- runQueryEntity q5 world entity
    r6 <- runQueryEntity q6 world entity
    r7 <- runQueryEntity q7 world entity
    r8 <- runQueryEntity q8 world entity

    return $ (,,,,,,,,) <$> r0 <*> r1 <*> r2 <*> r3 <*> r4 <*> r5 <*> r6 <*> r7 <*> r8

  runQueryInternal :: (q0, q1, q2, q3, q4, q5, q6, q7, q8)
-> [ArchetypeId]
-> World
-> IO [(Entity, Bool, (o0, o1, o2, o3, o4, o5, o6, o7, o8))]
runQueryInternal (q0
q0, q1
q1, q2
q2, q3
q3, q4
q4, q5
q5, q6
q6, q7
q7, q8
q8) [ArchetypeId]
archetypes World
world = do
    r0 <- q0 -> [ArchetypeId] -> World -> IO [(Entity, Bool, o0)]
forall qd output.
Queryable qd output =>
qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
runQueryInternal q0
q0 [ArchetypeId]
archetypes World
world
    r1 <- runQueryInternal q1 archetypes world
    r2 <- runQueryInternal q2 archetypes world
    r3 <- runQueryInternal q3 archetypes world
    r4 <- runQueryInternal q4 archetypes world
    r5 <- runQueryInternal q5 archetypes world
    r6 <- runQueryInternal q6 archetypes world
    r7 <- runQueryInternal q7 archetypes world
    r8 <- runQueryInternal q8 archetypes world

    return $ map (\((Entity
e0, Bool
b0, o0
r0), (Entity
_, Bool
b1, o1
r1), (Entity
_, Bool
b2, o2
r2), (Entity
_, Bool
b3, o3
r3), (Entity
_, Bool
b4, o4
r4), (Entity
_, Bool
b5, o5
r5), (Entity
_, Bool
b6, o6
r6), (Entity
_, Bool
b7, o7
r7), (Entity
_, Bool
b8, o8
r8)) -> (Entity
e0, Bool
b0 Bool -> Bool -> Bool
|| Bool
b1 Bool -> Bool -> Bool
|| Bool
b2 Bool -> Bool -> Bool
|| Bool
b3 Bool -> Bool -> Bool
|| Bool
b4 Bool -> Bool -> Bool
|| Bool
b5 Bool -> Bool -> Bool
|| Bool
b6 Bool -> Bool -> Bool
|| Bool
b7 Bool -> Bool -> Bool
|| Bool
b8, (o0
r0, o1
r1, o2
r2, o3
r3, o4
r4, o5
r5, o6
r6, o7
r7, o8
r8))) $ getZipList $ (,,,,,,,,) <$> ZipList r0 <*> ZipList r1 <*> ZipList r2 <*> ZipList r3 <*> ZipList r4 <*> ZipList r5 <*> ZipList r6 <*> ZipList r7 <*> ZipList r8

  queryTypes :: (q0, q1, q2, q3, q4, q5, q6, q7, q8) -> Set (TypeRep, TypeQuery)
queryTypes (q0
q0, q1
q1, q2
q2, q3
q3, q4
q4, q5
q5, q6
q6, q7
q7, q8
q8) = [Set (TypeRep, TypeQuery)] -> Set (TypeRep, TypeQuery)
forall (f :: * -> *) a. (Foldable f, Ord a) => f (Set a) -> Set a
Set.unions [q0 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q0
q0, q1 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q1
q1, q2 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q2
q2, q3 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q3
q3, q4 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q4
q4, q5 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q5
q5, q6 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q6
q6, q7 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q7
q7, q8 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q8
q8]

instance {-# OVERLAPPING #-} (Queryable q0 o0, Queryable q1 o1, Queryable q2 o2, Queryable q3 o3, Queryable q4 o4, Queryable q5 o5, Queryable q6 o6, Queryable q7 o7, Queryable q8 o8, Queryable q9 o9) => Queryable (q0, q1, q2, q3, q4, q5, q6, q7, q8, q9) (o0, o1, o2, o3, o4, o5, o6, o7, o8, o9) where
  runQueryEntity :: (q0, q1, q2, q3, q4, q5, q6, q7, q8, q9)
-> World
-> Entity
-> IO (Maybe (o0, o1, o2, o3, o4, o5, o6, o7, o8, o9))
runQueryEntity (q0
q0, q1
q1, q2
q2, q3
q3, q4
q4, q5
q5, q6
q6, q7
q7, q8
q8, q9
q9) World
world Entity
entity = do
    r0 <- q0 -> World -> Entity -> IO (Maybe o0)
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity q0
q0 World
world Entity
entity
    r1 <- runQueryEntity q1 world entity
    r2 <- runQueryEntity q2 world entity
    r3 <- runQueryEntity q3 world entity
    r4 <- runQueryEntity q4 world entity
    r5 <- runQueryEntity q5 world entity
    r6 <- runQueryEntity q6 world entity
    r7 <- runQueryEntity q7 world entity
    r8 <- runQueryEntity q8 world entity
    r9 <- runQueryEntity q9 world entity

    return $ (,,,,,,,,,) <$> r0 <*> r1 <*> r2 <*> r3 <*> r4 <*> r5 <*> r6 <*> r7 <*> r8 <*> r9

  runQueryInternal :: (q0, q1, q2, q3, q4, q5, q6, q7, q8, q9)
-> [ArchetypeId]
-> World
-> IO [(Entity, Bool, (o0, o1, o2, o3, o4, o5, o6, o7, o8, o9))]
runQueryInternal (q0
q0, q1
q1, q2
q2, q3
q3, q4
q4, q5
q5, q6
q6, q7
q7, q8
q8, q9
q9) [ArchetypeId]
archetypes World
world = do
    r0 <- q0 -> [ArchetypeId] -> World -> IO [(Entity, Bool, o0)]
forall qd output.
Queryable qd output =>
qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
runQueryInternal q0
q0 [ArchetypeId]
archetypes World
world
    r1 <- runQueryInternal q1 archetypes world
    r2 <- runQueryInternal q2 archetypes world
    r3 <- runQueryInternal q3 archetypes world
    r4 <- runQueryInternal q4 archetypes world
    r5 <- runQueryInternal q5 archetypes world
    r6 <- runQueryInternal q6 archetypes world
    r7 <- runQueryInternal q7 archetypes world
    r8 <- runQueryInternal q8 archetypes world
    r9 <- runQueryInternal q9 archetypes world

    return $ map (\((Entity
e0, Bool
b0, o0
r0), (Entity
_, Bool
b1, o1
r1), (Entity
_, Bool
b2, o2
r2), (Entity
_, Bool
b3, o3
r3), (Entity
_, Bool
b4, o4
r4), (Entity
_, Bool
b5, o5
r5), (Entity
_, Bool
b6, o6
r6), (Entity
_, Bool
b7, o7
r7), (Entity
_, Bool
b8, o8
r8), (Entity
_, Bool
b9, o9
r9)) -> (Entity
e0, Bool
b0 Bool -> Bool -> Bool
|| Bool
b1 Bool -> Bool -> Bool
|| Bool
b2 Bool -> Bool -> Bool
|| Bool
b3 Bool -> Bool -> Bool
|| Bool
b4 Bool -> Bool -> Bool
|| Bool
b5 Bool -> Bool -> Bool
|| Bool
b6 Bool -> Bool -> Bool
|| Bool
b7 Bool -> Bool -> Bool
|| Bool
b8 Bool -> Bool -> Bool
|| Bool
b9, (o0
r0, o1
r1, o2
r2, o3
r3, o4
r4, o5
r5, o6
r6, o7
r7, o8
r8, o9
r9))) $ getZipList $ (,,,,,,,,,) <$> ZipList r0 <*> ZipList r1 <*> ZipList r2 <*> ZipList r3 <*> ZipList r4 <*> ZipList r5 <*> ZipList r6 <*> ZipList r7 <*> ZipList r8 <*> ZipList r9

  queryTypes :: (q0, q1, q2, q3, q4, q5, q6, q7, q8, q9)
-> Set (TypeRep, TypeQuery)
queryTypes (q0
q0, q1
q1, q2
q2, q3
q3, q4
q4, q5
q5, q6
q6, q7
q7, q8
q8, q9
q9) = [Set (TypeRep, TypeQuery)] -> Set (TypeRep, TypeQuery)
forall (f :: * -> *) a. (Foldable f, Ord a) => f (Set a) -> Set a
Set.unions [q0 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q0
q0, q1 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q1
q1, q2 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q2
q2, q3 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q3
q3, q4 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q4
q4, q5 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q5
q5, q6 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q6
q6, q7 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q7
q7, q8 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q8
q8, q9 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q9
q9]

instance {-# OVERLAPPING #-} (Queryable q0 o0, Queryable q1 o1, Queryable q2 o2, Queryable q3 o3, Queryable q4 o4, Queryable q5 o5, Queryable q6 o6, Queryable q7 o7, Queryable q8 o8, Queryable q9 o9, Queryable q10 o10) => Queryable (q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10) (o0, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10) where
  runQueryEntity :: (q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10)
-> World
-> Entity
-> IO (Maybe (o0, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10))
runQueryEntity (q0
q0, q1
q1, q2
q2, q3
q3, q4
q4, q5
q5, q6
q6, q7
q7, q8
q8, q9
q9, q10
q10) World
world Entity
entity = do
    r0 <- q0 -> World -> Entity -> IO (Maybe o0)
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity q0
q0 World
world Entity
entity
    r1 <- runQueryEntity q1 world entity
    r2 <- runQueryEntity q2 world entity
    r3 <- runQueryEntity q3 world entity
    r4 <- runQueryEntity q4 world entity
    r5 <- runQueryEntity q5 world entity
    r6 <- runQueryEntity q6 world entity
    r7 <- runQueryEntity q7 world entity
    r8 <- runQueryEntity q8 world entity
    r9 <- runQueryEntity q9 world entity
    r10 <- runQueryEntity q10 world entity

    return $ (,,,,,,,,,,) <$> r0 <*> r1 <*> r2 <*> r3 <*> r4 <*> r5 <*> r6 <*> r7 <*> r8 <*> r9 <*> r10

  runQueryInternal :: (q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10)
-> [ArchetypeId]
-> World
-> IO
     [(Entity, Bool, (o0, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10))]
runQueryInternal (q0
q0, q1
q1, q2
q2, q3
q3, q4
q4, q5
q5, q6
q6, q7
q7, q8
q8, q9
q9, q10
q10) [ArchetypeId]
archetypes World
world = do
    r0 <- q0 -> [ArchetypeId] -> World -> IO [(Entity, Bool, o0)]
forall qd output.
Queryable qd output =>
qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
runQueryInternal q0
q0 [ArchetypeId]
archetypes World
world
    r1 <- runQueryInternal q1 archetypes world
    r2 <- runQueryInternal q2 archetypes world
    r3 <- runQueryInternal q3 archetypes world
    r4 <- runQueryInternal q4 archetypes world
    r5 <- runQueryInternal q5 archetypes world
    r6 <- runQueryInternal q6 archetypes world
    r7 <- runQueryInternal q7 archetypes world
    r8 <- runQueryInternal q8 archetypes world
    r9 <- runQueryInternal q9 archetypes world
    r10 <- runQueryInternal q10 archetypes world

    return $ map (\((Entity
e0, Bool
b0, o0
r0), (Entity
_, Bool
b1, o1
r1), (Entity
_, Bool
b2, o2
r2), (Entity
_, Bool
b3, o3
r3), (Entity
_, Bool
b4, o4
r4), (Entity
_, Bool
b5, o5
r5), (Entity
_, Bool
b6, o6
r6), (Entity
_, Bool
b7, o7
r7), (Entity
_, Bool
b8, o8
r8), (Entity
_, Bool
b9, o9
r9), (Entity
_, Bool
b10, o10
r10)) -> (Entity
e0, Bool
b0 Bool -> Bool -> Bool
|| Bool
b1 Bool -> Bool -> Bool
|| Bool
b2 Bool -> Bool -> Bool
|| Bool
b3 Bool -> Bool -> Bool
|| Bool
b4 Bool -> Bool -> Bool
|| Bool
b5 Bool -> Bool -> Bool
|| Bool
b6 Bool -> Bool -> Bool
|| Bool
b7 Bool -> Bool -> Bool
|| Bool
b8 Bool -> Bool -> Bool
|| Bool
b9 Bool -> Bool -> Bool
|| Bool
b10, (o0
r0, o1
r1, o2
r2, o3
r3, o4
r4, o5
r5, o6
r6, o7
r7, o8
r8, o9
r9, o10
r10))) $ getZipList $ (,,,,,,,,,,) <$> ZipList r0 <*> ZipList r1 <*> ZipList r2 <*> ZipList r3 <*> ZipList r4 <*> ZipList r5 <*> ZipList r6 <*> ZipList r7 <*> ZipList r8 <*> ZipList r9 <*> ZipList r10

  queryTypes :: (q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10)
-> Set (TypeRep, TypeQuery)
queryTypes (q0
q0, q1
q1, q2
q2, q3
q3, q4
q4, q5
q5, q6
q6, q7
q7, q8
q8, q9
q9, q10
q10) = [Set (TypeRep, TypeQuery)] -> Set (TypeRep, TypeQuery)
forall (f :: * -> *) a. (Foldable f, Ord a) => f (Set a) -> Set a
Set.unions [q0 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q0
q0, q1 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q1
q1, q2 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q2
q2, q3 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q3
q3, q4 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q4
q4, q5 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q5
q5, q6 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q6
q6, q7 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q7
q7, q8 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q8
q8, q9 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q9
q9, q10 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q10
q10]

instance {-# OVERLAPPING #-} (Queryable q0 o0, Queryable q1 o1, Queryable q2 o2, Queryable q3 o3, Queryable q4 o4, Queryable q5 o5, Queryable q6 o6, Queryable q7 o7, Queryable q8 o8, Queryable q9 o9, Queryable q10 o10, Queryable q11 o11) => Queryable (q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11) (o0, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11) where
  runQueryEntity :: (q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11)
-> World
-> Entity
-> IO (Maybe (o0, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11))
runQueryEntity (q0
q0, q1
q1, q2
q2, q3
q3, q4
q4, q5
q5, q6
q6, q7
q7, q8
q8, q9
q9, q10
q10, q11
q11) World
world Entity
entity = do
    r0 <- q0 -> World -> Entity -> IO (Maybe o0)
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity q0
q0 World
world Entity
entity
    r1 <- runQueryEntity q1 world entity
    r2 <- runQueryEntity q2 world entity
    r3 <- runQueryEntity q3 world entity
    r4 <- runQueryEntity q4 world entity
    r5 <- runQueryEntity q5 world entity
    r6 <- runQueryEntity q6 world entity
    r7 <- runQueryEntity q7 world entity
    r8 <- runQueryEntity q8 world entity
    r9 <- runQueryEntity q9 world entity
    r10 <- runQueryEntity q10 world entity
    r11 <- runQueryEntity q11 world entity

    return $ (,,,,,,,,,,,) <$> r0 <*> r1 <*> r2 <*> r3 <*> r4 <*> r5 <*> r6 <*> r7 <*> r8 <*> r9 <*> r10 <*> r11

  runQueryInternal :: (q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11)
-> [ArchetypeId]
-> World
-> IO
     [(Entity, Bool,
       (o0, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11))]
runQueryInternal (q0
q0, q1
q1, q2
q2, q3
q3, q4
q4, q5
q5, q6
q6, q7
q7, q8
q8, q9
q9, q10
q10, q11
q11) [ArchetypeId]
archetypes World
world = do
    r0 <- q0 -> [ArchetypeId] -> World -> IO [(Entity, Bool, o0)]
forall qd output.
Queryable qd output =>
qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
runQueryInternal q0
q0 [ArchetypeId]
archetypes World
world
    r1 <- runQueryInternal q1 archetypes world
    r2 <- runQueryInternal q2 archetypes world
    r3 <- runQueryInternal q3 archetypes world
    r4 <- runQueryInternal q4 archetypes world
    r5 <- runQueryInternal q5 archetypes world
    r6 <- runQueryInternal q6 archetypes world
    r7 <- runQueryInternal q7 archetypes world
    r8 <- runQueryInternal q8 archetypes world
    r9 <- runQueryInternal q9 archetypes world
    r10 <- runQueryInternal q10 archetypes world
    r11 <- runQueryInternal q11 archetypes world

    return $ map (\((Entity
e0, Bool
b0, o0
r0), (Entity
_, Bool
b1, o1
r1), (Entity
_, Bool
b2, o2
r2), (Entity
_, Bool
b3, o3
r3), (Entity
_, Bool
b4, o4
r4), (Entity
_, Bool
b5, o5
r5), (Entity
_, Bool
b6, o6
r6), (Entity
_, Bool
b7, o7
r7), (Entity
_, Bool
b8, o8
r8), (Entity
_, Bool
b9, o9
r9), (Entity
_, Bool
b10, o10
r10), (Entity
_, Bool
b11, o11
r11)) -> (Entity
e0, Bool
b0 Bool -> Bool -> Bool
|| Bool
b1 Bool -> Bool -> Bool
|| Bool
b2 Bool -> Bool -> Bool
|| Bool
b3 Bool -> Bool -> Bool
|| Bool
b4 Bool -> Bool -> Bool
|| Bool
b5 Bool -> Bool -> Bool
|| Bool
b6 Bool -> Bool -> Bool
|| Bool
b7 Bool -> Bool -> Bool
|| Bool
b8 Bool -> Bool -> Bool
|| Bool
b9 Bool -> Bool -> Bool
|| Bool
b10 Bool -> Bool -> Bool
|| Bool
b11, (o0
r0, o1
r1, o2
r2, o3
r3, o4
r4, o5
r5, o6
r6, o7
r7, o8
r8, o9
r9, o10
r10, o11
r11))) $ getZipList $ (,,,,,,,,,,,) <$> ZipList r0 <*> ZipList r1 <*> ZipList r2 <*> ZipList r3 <*> ZipList r4 <*> ZipList r5 <*> ZipList r6 <*> ZipList r7 <*> ZipList r8 <*> ZipList r9 <*> ZipList r10 <*> ZipList r11

  queryTypes :: (q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11)
-> Set (TypeRep, TypeQuery)
queryTypes (q0
q0, q1
q1, q2
q2, q3
q3, q4
q4, q5
q5, q6
q6, q7
q7, q8
q8, q9
q9, q10
q10, q11
q11) = [Set (TypeRep, TypeQuery)] -> Set (TypeRep, TypeQuery)
forall (f :: * -> *) a. (Foldable f, Ord a) => f (Set a) -> Set a
Set.unions [q0 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q0
q0, q1 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q1
q1, q2 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q2
q2, q3 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q3
q3, q4 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q4
q4, q5 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q5
q5, q6 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q6
q6, q7 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q7
q7, q8 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q8
q8, q9 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q9
q9, q10 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q10
q10, q11 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q11
q11]

instance {-# OVERLAPPING #-} (Queryable q0 o0, Queryable q1 o1, Queryable q2 o2, Queryable q3 o3, Queryable q4 o4, Queryable q5 o5, Queryable q6 o6, Queryable q7 o7, Queryable q8 o8, Queryable q9 o9, Queryable q10 o10, Queryable q11 o11, Queryable q12 o12) => Queryable (q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12) (o0, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, o12) where
  runQueryEntity :: (q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12)
-> World
-> Entity
-> IO
     (Maybe (o0, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, o12))
runQueryEntity (q0
q0, q1
q1, q2
q2, q3
q3, q4
q4, q5
q5, q6
q6, q7
q7, q8
q8, q9
q9, q10
q10, q11
q11, q12
q12) World
world Entity
entity = do
    r0 <- q0 -> World -> Entity -> IO (Maybe o0)
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity q0
q0 World
world Entity
entity
    r1 <- runQueryEntity q1 world entity
    r2 <- runQueryEntity q2 world entity
    r3 <- runQueryEntity q3 world entity
    r4 <- runQueryEntity q4 world entity
    r5 <- runQueryEntity q5 world entity
    r6 <- runQueryEntity q6 world entity
    r7 <- runQueryEntity q7 world entity
    r8 <- runQueryEntity q8 world entity
    r9 <- runQueryEntity q9 world entity
    r10 <- runQueryEntity q10 world entity
    r11 <- runQueryEntity q11 world entity
    r12 <- runQueryEntity q12 world entity

    return $ (,,,,,,,,,,,,) <$> r0 <*> r1 <*> r2 <*> r3 <*> r4 <*> r5 <*> r6 <*> r7 <*> r8 <*> r9 <*> r10 <*> r11 <*> r12

  runQueryInternal :: (q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12)
-> [ArchetypeId]
-> World
-> IO
     [(Entity, Bool,
       (o0, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, o12))]
runQueryInternal (q0
q0, q1
q1, q2
q2, q3
q3, q4
q4, q5
q5, q6
q6, q7
q7, q8
q8, q9
q9, q10
q10, q11
q11, q12
q12) [ArchetypeId]
archetypes World
world = do
    r0 <- q0 -> [ArchetypeId] -> World -> IO [(Entity, Bool, o0)]
forall qd output.
Queryable qd output =>
qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
runQueryInternal q0
q0 [ArchetypeId]
archetypes World
world
    r1 <- runQueryInternal q1 archetypes world
    r2 <- runQueryInternal q2 archetypes world
    r3 <- runQueryInternal q3 archetypes world
    r4 <- runQueryInternal q4 archetypes world
    r5 <- runQueryInternal q5 archetypes world
    r6 <- runQueryInternal q6 archetypes world
    r7 <- runQueryInternal q7 archetypes world
    r8 <- runQueryInternal q8 archetypes world
    r9 <- runQueryInternal q9 archetypes world
    r10 <- runQueryInternal q10 archetypes world
    r11 <- runQueryInternal q11 archetypes world
    r12 <- runQueryInternal q12 archetypes world

    return $ map (\((Entity
e0, Bool
b0, o0
r0), (Entity
_, Bool
b1, o1
r1), (Entity
_, Bool
b2, o2
r2), (Entity
_, Bool
b3, o3
r3), (Entity
_, Bool
b4, o4
r4), (Entity
_, Bool
b5, o5
r5), (Entity
_, Bool
b6, o6
r6), (Entity
_, Bool
b7, o7
r7), (Entity
_, Bool
b8, o8
r8), (Entity
_, Bool
b9, o9
r9), (Entity
_, Bool
b10, o10
r10), (Entity
_, Bool
b11, o11
r11), (Entity
_, Bool
b12, o12
r12)) -> (Entity
e0, Bool
b0 Bool -> Bool -> Bool
|| Bool
b1 Bool -> Bool -> Bool
|| Bool
b2 Bool -> Bool -> Bool
|| Bool
b3 Bool -> Bool -> Bool
|| Bool
b4 Bool -> Bool -> Bool
|| Bool
b5 Bool -> Bool -> Bool
|| Bool
b6 Bool -> Bool -> Bool
|| Bool
b7 Bool -> Bool -> Bool
|| Bool
b8 Bool -> Bool -> Bool
|| Bool
b9 Bool -> Bool -> Bool
|| Bool
b10 Bool -> Bool -> Bool
|| Bool
b11 Bool -> Bool -> Bool
|| Bool
b12, (o0
r0, o1
r1, o2
r2, o3
r3, o4
r4, o5
r5, o6
r6, o7
r7, o8
r8, o9
r9, o10
r10, o11
r11, o12
r12))) $ getZipList $ (,,,,,,,,,,,,) <$> ZipList r0 <*> ZipList r1 <*> ZipList r2 <*> ZipList r3 <*> ZipList r4 <*> ZipList r5 <*> ZipList r6 <*> ZipList r7 <*> ZipList r8 <*> ZipList r9 <*> ZipList r10 <*> ZipList r11 <*> ZipList r12

  queryTypes :: (q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12)
-> Set (TypeRep, TypeQuery)
queryTypes (q0
q0, q1
q1, q2
q2, q3
q3, q4
q4, q5
q5, q6
q6, q7
q7, q8
q8, q9
q9, q10
q10, q11
q11, q12
q12) = [Set (TypeRep, TypeQuery)] -> Set (TypeRep, TypeQuery)
forall (f :: * -> *) a. (Foldable f, Ord a) => f (Set a) -> Set a
Set.unions [q0 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q0
q0, q1 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q1
q1, q2 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q2
q2, q3 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q3
q3, q4 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q4
q4, q5 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q5
q5, q6 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q6
q6, q7 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q7
q7, q8 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q8
q8, q9 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q9
q9, q10 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q10
q10, q11 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q11
q11, q12 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q12
q12]

instance {-# OVERLAPPING #-} (Queryable q0 o0, Queryable q1 o1, Queryable q2 o2, Queryable q3 o3, Queryable q4 o4, Queryable q5 o5, Queryable q6 o6, Queryable q7 o7, Queryable q8 o8, Queryable q9 o9, Queryable q10 o10, Queryable q11 o11, Queryable q12 o12, Queryable q13 o13) => Queryable (q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13) (o0, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, o12, o13) where
  runQueryEntity :: (q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13)
-> World
-> Entity
-> IO
     (Maybe
        (o0, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, o12, o13))
runQueryEntity (q0
q0, q1
q1, q2
q2, q3
q3, q4
q4, q5
q5, q6
q6, q7
q7, q8
q8, q9
q9, q10
q10, q11
q11, q12
q12, q13
q13) World
world Entity
entity = do
    r0 <- q0 -> World -> Entity -> IO (Maybe o0)
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity q0
q0 World
world Entity
entity
    r1 <- runQueryEntity q1 world entity
    r2 <- runQueryEntity q2 world entity
    r3 <- runQueryEntity q3 world entity
    r4 <- runQueryEntity q4 world entity
    r5 <- runQueryEntity q5 world entity
    r6 <- runQueryEntity q6 world entity
    r7 <- runQueryEntity q7 world entity
    r8 <- runQueryEntity q8 world entity
    r9 <- runQueryEntity q9 world entity
    r10 <- runQueryEntity q10 world entity
    r11 <- runQueryEntity q11 world entity
    r12 <- runQueryEntity q12 world entity
    r13 <- runQueryEntity q13 world entity

    return $ (,,,,,,,,,,,,,) <$> r0 <*> r1 <*> r2 <*> r3 <*> r4 <*> r5 <*> r6 <*> r7 <*> r8 <*> r9 <*> r10 <*> r11 <*> r12 <*> r13

  runQueryInternal :: (q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13)
-> [ArchetypeId]
-> World
-> IO
     [(Entity, Bool,
       (o0, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, o12, o13))]
runQueryInternal (q0
q0, q1
q1, q2
q2, q3
q3, q4
q4, q5
q5, q6
q6, q7
q7, q8
q8, q9
q9, q10
q10, q11
q11, q12
q12, q13
q13) [ArchetypeId]
archetypes World
world = do
    r0 <- q0 -> [ArchetypeId] -> World -> IO [(Entity, Bool, o0)]
forall qd output.
Queryable qd output =>
qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
runQueryInternal q0
q0 [ArchetypeId]
archetypes World
world
    r1 <- runQueryInternal q1 archetypes world
    r2 <- runQueryInternal q2 archetypes world
    r3 <- runQueryInternal q3 archetypes world
    r4 <- runQueryInternal q4 archetypes world
    r5 <- runQueryInternal q5 archetypes world
    r6 <- runQueryInternal q6 archetypes world
    r7 <- runQueryInternal q7 archetypes world
    r8 <- runQueryInternal q8 archetypes world
    r9 <- runQueryInternal q9 archetypes world
    r10 <- runQueryInternal q10 archetypes world
    r11 <- runQueryInternal q11 archetypes world
    r12 <- runQueryInternal q12 archetypes world
    r13 <- runQueryInternal q13 archetypes world

    return $ map (\((Entity
e0, Bool
b0, o0
r0), (Entity
_, Bool
b1, o1
r1), (Entity
_, Bool
b2, o2
r2), (Entity
_, Bool
b3, o3
r3), (Entity
_, Bool
b4, o4
r4), (Entity
_, Bool
b5, o5
r5), (Entity
_, Bool
b6, o6
r6), (Entity
_, Bool
b7, o7
r7), (Entity
_, Bool
b8, o8
r8), (Entity
_, Bool
b9, o9
r9), (Entity
_, Bool
b10, o10
r10), (Entity
_, Bool
b11, o11
r11), (Entity
_, Bool
b12, o12
r12), (Entity
_, Bool
b13, o13
r13)) -> (Entity
e0, Bool
b0 Bool -> Bool -> Bool
|| Bool
b1 Bool -> Bool -> Bool
|| Bool
b2 Bool -> Bool -> Bool
|| Bool
b3 Bool -> Bool -> Bool
|| Bool
b4 Bool -> Bool -> Bool
|| Bool
b5 Bool -> Bool -> Bool
|| Bool
b6 Bool -> Bool -> Bool
|| Bool
b7 Bool -> Bool -> Bool
|| Bool
b8 Bool -> Bool -> Bool
|| Bool
b9 Bool -> Bool -> Bool
|| Bool
b10 Bool -> Bool -> Bool
|| Bool
b11 Bool -> Bool -> Bool
|| Bool
b12 Bool -> Bool -> Bool
|| Bool
b13, (o0
r0, o1
r1, o2
r2, o3
r3, o4
r4, o5
r5, o6
r6, o7
r7, o8
r8, o9
r9, o10
r10, o11
r11, o12
r12, o13
r13))) $ getZipList $ (,,,,,,,,,,,,,) <$> ZipList r0 <*> ZipList r1 <*> ZipList r2 <*> ZipList r3 <*> ZipList r4 <*> ZipList r5 <*> ZipList r6 <*> ZipList r7 <*> ZipList r8 <*> ZipList r9 <*> ZipList r10 <*> ZipList r11 <*> ZipList r12 <*> ZipList r13

  queryTypes :: (q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13)
-> Set (TypeRep, TypeQuery)
queryTypes (q0
q0, q1
q1, q2
q2, q3
q3, q4
q4, q5
q5, q6
q6, q7
q7, q8
q8, q9
q9, q10
q10, q11
q11, q12
q12, q13
q13) = [Set (TypeRep, TypeQuery)] -> Set (TypeRep, TypeQuery)
forall (f :: * -> *) a. (Foldable f, Ord a) => f (Set a) -> Set a
Set.unions [q0 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q0
q0, q1 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q1
q1, q2 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q2
q2, q3 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q3
q3, q4 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q4
q4, q5 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q5
q5, q6 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q6
q6, q7 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q7
q7, q8 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q8
q8, q9 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q9
q9, q10 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q10
q10, q11 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q11
q11, q12 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q12
q12, q13 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q13
q13]

instance {-# OVERLAPPING #-} (Queryable q0 o0, Queryable q1 o1, Queryable q2 o2, Queryable q3 o3, Queryable q4 o4, Queryable q5 o5, Queryable q6 o6, Queryable q7 o7, Queryable q8 o8, Queryable q9 o9, Queryable q10 o10, Queryable q11 o11, Queryable q12 o12, Queryable q13 o13, Queryable q14 o14) => Queryable (q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13, q14) (o0, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, o12, o13, o14) where
  runQueryEntity :: (q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13, q14)
-> World
-> Entity
-> IO
     (Maybe
        (o0, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, o12, o13, o14))
runQueryEntity (q0
q0, q1
q1, q2
q2, q3
q3, q4
q4, q5
q5, q6
q6, q7
q7, q8
q8, q9
q9, q10
q10, q11
q11, q12
q12, q13
q13, q14
q14) World
world Entity
entity = do
    r0 <- q0 -> World -> Entity -> IO (Maybe o0)
forall qd output.
Queryable qd output =>
qd -> World -> Entity -> IO (Maybe output)
runQueryEntity q0
q0 World
world Entity
entity
    r1 <- runQueryEntity q1 world entity
    r2 <- runQueryEntity q2 world entity
    r3 <- runQueryEntity q3 world entity
    r4 <- runQueryEntity q4 world entity
    r5 <- runQueryEntity q5 world entity
    r6 <- runQueryEntity q6 world entity
    r7 <- runQueryEntity q7 world entity
    r8 <- runQueryEntity q8 world entity
    r9 <- runQueryEntity q9 world entity
    r10 <- runQueryEntity q10 world entity
    r11 <- runQueryEntity q11 world entity
    r12 <- runQueryEntity q12 world entity
    r13 <- runQueryEntity q13 world entity
    r14 <- runQueryEntity q14 world entity

    return $ (,,,,,,,,,,,,,,) <$> r0 <*> r1 <*> r2 <*> r3 <*> r4 <*> r5 <*> r6 <*> r7 <*> r8 <*> r9 <*> r10 <*> r11 <*> r12 <*> r13 <*> r14

  runQueryInternal :: (q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13, q14)
-> [ArchetypeId]
-> World
-> IO
     [(Entity, Bool,
       (o0, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, o12, o13, o14))]
runQueryInternal (q0
q0, q1
q1, q2
q2, q3
q3, q4
q4, q5
q5, q6
q6, q7
q7, q8
q8, q9
q9, q10
q10, q11
q11, q12
q12, q13
q13, q14
q14) [ArchetypeId]
archetypes World
world = do
    r0 <- q0 -> [ArchetypeId] -> World -> IO [(Entity, Bool, o0)]
forall qd output.
Queryable qd output =>
qd -> [ArchetypeId] -> World -> IO [(Entity, Bool, output)]
runQueryInternal q0
q0 [ArchetypeId]
archetypes World
world
    r1 <- runQueryInternal q1 archetypes world
    r2 <- runQueryInternal q2 archetypes world
    r3 <- runQueryInternal q3 archetypes world
    r4 <- runQueryInternal q4 archetypes world
    r5 <- runQueryInternal q5 archetypes world
    r6 <- runQueryInternal q6 archetypes world
    r7 <- runQueryInternal q7 archetypes world
    r8 <- runQueryInternal q8 archetypes world
    r9 <- runQueryInternal q9 archetypes world
    r10 <- runQueryInternal q10 archetypes world
    r11 <- runQueryInternal q11 archetypes world
    r12 <- runQueryInternal q12 archetypes world
    r13 <- runQueryInternal q13 archetypes world
    r14 <- runQueryInternal q14 archetypes world

    return $ map (\((Entity
e0, Bool
b0, o0
r0), (Entity
_, Bool
b1, o1
r1), (Entity
_, Bool
b2, o2
r2), (Entity
_, Bool
b3, o3
r3), (Entity
_, Bool
b4, o4
r4), (Entity
_, Bool
b5, o5
r5), (Entity
_, Bool
b6, o6
r6), (Entity
_, Bool
b7, o7
r7), (Entity
_, Bool
b8, o8
r8), (Entity
_, Bool
b9, o9
r9), (Entity
_, Bool
b10, o10
r10), (Entity
_, Bool
b11, o11
r11), (Entity
_, Bool
b12, o12
r12), (Entity
_, Bool
b13, o13
r13), (Entity
_, Bool
b14, o14
r14)) -> (Entity
e0, Bool
b0 Bool -> Bool -> Bool
|| Bool
b1 Bool -> Bool -> Bool
|| Bool
b2 Bool -> Bool -> Bool
|| Bool
b3 Bool -> Bool -> Bool
|| Bool
b4 Bool -> Bool -> Bool
|| Bool
b5 Bool -> Bool -> Bool
|| Bool
b6 Bool -> Bool -> Bool
|| Bool
b7 Bool -> Bool -> Bool
|| Bool
b8 Bool -> Bool -> Bool
|| Bool
b9 Bool -> Bool -> Bool
|| Bool
b10 Bool -> Bool -> Bool
|| Bool
b11 Bool -> Bool -> Bool
|| Bool
b12 Bool -> Bool -> Bool
|| Bool
b13 Bool -> Bool -> Bool
|| Bool
b14, (o0
r0, o1
r1, o2
r2, o3
r3, o4
r4, o5
r5, o6
r6, o7
r7, o8
r8, o9
r9, o10
r10, o11
r11, o12
r12, o13
r13, o14
r14))) $ getZipList $ (,,,,,,,,,,,,,,) <$> ZipList r0 <*> ZipList r1 <*> ZipList r2 <*> ZipList r3 <*> ZipList r4 <*> ZipList r5 <*> ZipList r6 <*> ZipList r7 <*> ZipList r8 <*> ZipList r9 <*> ZipList r10 <*> ZipList r11 <*> ZipList r12 <*> ZipList r13 <*> ZipList r14

  queryTypes :: (q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13, q14)
-> Set (TypeRep, TypeQuery)
queryTypes (q0
q0, q1
q1, q2
q2, q3
q3, q4
q4, q5
q5, q6
q6, q7
q7, q8
q8, q9
q9, q10
q10, q11
q11, q12
q12, q13
q13, q14
q14) = [Set (TypeRep, TypeQuery)] -> Set (TypeRep, TypeQuery)
forall (f :: * -> *) a. (Foldable f, Ord a) => f (Set a) -> Set a
Set.unions [q0 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q0
q0, q1 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q1
q1, q2 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q2
q2, q3 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q3
q3, q4 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q4
q4, q5 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q5
q5, q6 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q6
q6, q7 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q7
q7, q8 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q8
q8, q9 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q9
q9, q10 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q10
q10, q11 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q11
q11, q12 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q12
q12, q13 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q13
q13, q14 -> Set (TypeRep, TypeQuery)
forall qd output.
Queryable qd output =>
qd -> Set (TypeRep, TypeQuery)
queryTypes q14
q14]