-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: improve ergonomics of query syntax
- Loading branch information
Showing
16 changed files
with
105 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
(** Construct and evaluate queries. *) | ||
|
||
(** A filter that can be used to filter entities based on their components. *) | ||
module Filter : sig | ||
type t = | ||
| With of Id.Component.t | ||
| Without of Id.Component.t | ||
| Not of t | ||
| And of t * t | ||
| Or of t * t | ||
| Wildcard | ||
|
||
val matches : t -> Id.ComponentSet.t -> bool | ||
(** Returns true if the given component set matches the filter. *) | ||
end | ||
|
||
(** A query term that can be used to construct queries. *) | ||
type 'a term = | ||
| Req : (module Component.S with type t = 'a) -> 'a term | ||
(** A required component must be present in an entity. *) | ||
| Opt : (module Component.S with type t = 'a) -> 'a option term | ||
(** An optional component will be None if an entity does not have it. *) | ||
|
||
(** The type of a query. *) | ||
type 'a t = Nil : unit t | Cons : 'a term * 'b t -> ('a * 'b) t | ||
|
||
val required_ids : 'a t -> Id.ComponentSet.t | ||
(** Returns the set of required component IDs for the given query. *) | ||
|
||
val evaluate : | ||
?filter:Filter.t -> 'a t -> Archetype.t list -> (Id.Entity.t * 'a) list | ||
(** Evaluates the given query on the given archetypes. *) | ||
|
||
val ( @ ) : 'a term -> 'b t -> ('a * 'b) t | ||
(** Composes query terms. *) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
(** Define systems that query and operate on the world. *) | ||
|
||
(** An operation that can be performed on the world. *) | ||
type ('world, 'a) operation = | ||
| Query of ('a -> unit) | ||
| Immediate of ('world -> 'a -> unit) | ||
|
||
type 'world t | ||
(** The type of a system. *) | ||
|
||
val make : ('world -> 'a) -> ('world, 'a) operation -> 'world t | ||
(** Make a system from a querier and an operation. *) | ||
|
||
val task : ('world, unit) operation -> 'world t | ||
(** Make a system that does not query the world. *) | ||
|
||
val run : 'world -> 'world t -> unit | ||
(** Run a system on the world. *) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.