mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-24 17:10:03 +00:00
query:archetypes is a method
This commit is contained in:
parent
6359701a69
commit
76ab6838f2
5 changed files with 225 additions and 267 deletions
|
@ -4,18 +4,6 @@ A World contains entities which have components. The World is queryable and can
|
|||
|
||||
# Methods
|
||||
|
||||
## drain
|
||||
This method will impede it from being reset when the query is being iterated.
|
||||
```luau
|
||||
function query:drain(): Query
|
||||
```
|
||||
|
||||
## next
|
||||
Get the next result in the query. Drain must have been called beforehand or otherwise it will error.
|
||||
```luau
|
||||
function query:next(): Query
|
||||
```
|
||||
|
||||
## with
|
||||
Adds components (IDs) to query with, but will not use their data. This is useful for Tags or generally just data you do not care for.
|
||||
|
||||
|
@ -71,41 +59,16 @@ for (const [entity, position] of world.query(Position).without(Velocity)) {
|
|||
```
|
||||
:::
|
||||
|
||||
## replace
|
||||
This function takes a callback which is given the current queried data of each matching entity. The values returned by the callback will be set as the new data for each given ID on the entity.
|
||||
```luau
|
||||
function query:replace(
|
||||
fn: (entity: Entity, ...: T...) -> U... -- ): () -- The callback that will transform the entities' data
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
::: code-group
|
||||
```luau [luau]
|
||||
world:query(Position, Velocity):replace(function(e, position, velocity)
|
||||
return position + velocity, velocity * 0.9
|
||||
end
|
||||
```
|
||||
|
||||
```ts [typescript]
|
||||
world
|
||||
.query(Position, Velocity)
|
||||
.replace((e, position, velocity) =>
|
||||
$tuple(position.add(velocity), velocity.mul(0.9)),
|
||||
);
|
||||
```
|
||||
:::
|
||||
|
||||
## archetypes
|
||||
Returns the matching archetypes of the query.
|
||||
```luau
|
||||
function query.archetypes(): { Archetype }
|
||||
function query:archetypes(): { Archetype }
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```luau [luau]
|
||||
for i, archetype in world:query(Position, Velocity).archetypes() do
|
||||
for i, archetype in world:query(Position, Velocity):archetypes() do
|
||||
local columns = archetype.columns
|
||||
local field = archetype.records
|
||||
|
||||
|
@ -121,5 +84,5 @@ end
|
|||
```
|
||||
|
||||
:::info
|
||||
This function is meant for internal usage. Use this if you want to maximize performance by inlining the iterator.
|
||||
This function is meant for people who wants to really customize their query behaviour at the archetype-level
|
||||
:::
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Addons
|
||||
A collection of third-party jecs addons made by the community. If you would like to share what you're working on, [submit a pull request](https://github.com/Ukendio/jecs)!
|
||||
# Assets
|
||||
A collection of third-party jecs assets made by the community. If you would like to share what you're working on, [submit a pull request](https://github.com/Ukendio/jecs)!
|
||||
|
||||
# Debuggers
|
||||
## [jabby](https://github.com/alicesaidhi/jabby)
|
||||
|
@ -14,5 +14,3 @@ A batteries-included [sapphire](https://github.com/mark-marks/sapphire) schedule
|
|||
|
||||
## [jam](https://github.com/revvy02/Jam)
|
||||
Provides hooks and a scheduler that implements jabby and a topographical runtime
|
||||
|
||||
This page takes wording and terminology directly from Bevy's [assets page](https://bevyengine.org/assets/)
|
||||
|
|
|
@ -5,8 +5,6 @@ Entities represent things in a game. In a game there may be entities of characte
|
|||
|
||||
By itself, an entity is just an unique identifier without any data
|
||||
|
||||
### Creation
|
||||
|
||||
## Components
|
||||
A component is something that is added to an entity. Components can simply tag an entity ("this entity is an `Npc`"), attach data to an entity ("this entity is at `Position` `Vector3.new(10, 20, 30)`") and create relationships between entities ("bob `Likes` alice") that may also contain data ("bob `Eats` `10` apples").
|
||||
|
||||
|
@ -21,7 +19,7 @@ Operation | Description
|
|||
|
||||
### Components are entities
|
||||
|
||||
In an ECS, components need to be uniquely identified. In Jecs this is done by making each component is its own unique entity. If a game has a component Position and Velocity, there will be two entities, one for each component. Component entities can be distinguished from "regular" entities as they have a `Component` component. An example:
|
||||
In an ECS, components need to be uniquely identified. In Jecs this is done by making each component its own unique entity. If a game has a component Position and Velocity, there will be two entities, one for each component. Component entities can be distinguished from "regular" entities as they have a `Component` component. An example:
|
||||
|
||||
::: code-group
|
||||
|
||||
|
|
|
@ -51,6 +51,8 @@ Jecs currently only supports the `Any` type of wildcards which a single result f
|
|||
|
||||
When using the `Any` type wildcard it is undefined which component will be matched, as this can be influenced by other parts of the query. It is guaranteed that iterating the same query twice on the same dataset will produce the same result.
|
||||
|
||||
If you want to iterate multiple targets for the same relation on a pair, then use [`world:target`](world.md#target)
|
||||
|
||||
Wildcards are particularly useful when used in combination with pairs (next section).
|
||||
|
||||
### Pairs
|
||||
|
|
|
@ -1676,12 +1676,9 @@ type Query<T...> = typeof(setmetatable({}, {
|
|||
__iter = (nil :: any) :: Iter<T...>,
|
||||
})) & {
|
||||
iter: Iter<T...>,
|
||||
next: Item<T...>,
|
||||
drain: (self: Query<T...>) -> Query<T...>,
|
||||
with: (self: Query<T...>, ...i53) -> Query<T...>,
|
||||
without: (self: Query<T...>, ...i53) -> Query<T...>,
|
||||
replace: (self: Query<T...>, <U...>(T...) -> U...) -> (),
|
||||
archetypes: () -> { Archetype },
|
||||
archetypes: (self: Query<T...>) -> { Archetype },
|
||||
}
|
||||
|
||||
export type World = {
|
||||
|
|
Loading…
Reference in a new issue