-
Notifications
You must be signed in to change notification settings - Fork 0
Query
RedRimmedBox edited this page Jan 4, 2025
·
11 revisions
The Query
class group provides a flexible data query framework for the system. It has the following characteristics:
- Cannot be instantiated directly: The constructor is defined as private.
- Cannot be subclassed: Each class is marked with the final modifier, preventing inheritance.
- Type safety: Generic parameters must conform to the Component protocol.
- Flexible structure: Classes like
Query2
andQuery3
are available for handling multiple generic parameters, supporting up to 10 generic parameters.
public final class Query<T: Component> {
private init() {
// Prevents direct instantiation
}
}
To support multiple generic parameters, classes like Query2
and Query3
are provided. This allows queries to handle multiple data types flexibly.
/// A query for two `Component` types.
public final class Query2<T1: Component, T2: Component> {
private init() {
// Prevents direct instantiation
}
}
Tip
Classes such as Query2 and beyond are auto-generated using Swift Macros. They are not directly defined in the codebase.
Since Query
classes cannot be instantiated directly, they are typically instantiated by the system and passed as parameters to functions as shown below:
Example: Using in System Functions
/// Example: A system function using a query for the `Position` component.
func exampleSystem(query: Query<Position>) {
// Use the query to perform system logic
}
/// Example: A system function handling up to 10 components.
func exampleSystemWithMore(query: Query10<ComponentA, ComponentB, ComponentC, ComponentD, ComponentE, ComponentF, ComponentG, ComponentH, ComponentI, ComponentJ>) {
// Supports up to 10 generic parameters
}
rrbox note
-
Filtered<Query, Condition>
クラスについても説明したい - そういえば Query のデータにアクセスする方法(
update
メソッドとcomponents
メソッド)について書き忘れたな...(覚えていたら書きますmm)
現在 wiki は ecs-swift v0.2 に対応しています。