mirror of
https://github.com/Ukendio/jecs.git
synced 2025-08-04 11:19:17 +00:00
Compare commits
4 commits
3b1ecadbe5
...
3e5f20f96c
Author | SHA1 | Date | |
---|---|---|---|
|
3e5f20f96c | ||
|
0b6bfea5c8 | ||
|
2b9c04c90a | ||
|
535b9f24b6 |
2 changed files with 27 additions and 22 deletions
45
jecs.d.ts
vendored
45
jecs.d.ts
vendored
|
@ -43,18 +43,18 @@ type InferComponents<A extends Id[]> = { [K in keyof A]: InferComponent<A[K]> };
|
||||||
type ArchetypeId = number;
|
type ArchetypeId = number;
|
||||||
export type Column<T> = T[];
|
export type Column<T> = T[];
|
||||||
|
|
||||||
export type Archetype<T extends unknown[]> = {
|
export type Archetype<T extends Id[]> = {
|
||||||
id: number;
|
id: number;
|
||||||
types: number[];
|
types: number[];
|
||||||
type: string;
|
type: string;
|
||||||
entities: number[];
|
entities: number[];
|
||||||
columns: Column<unknown>[];
|
columns: Column<unknown>[];
|
||||||
columns_map: Record<Id, Column<T[number]>>
|
columns_map: { [K in T[number]]: Column<InferComponent<K>> };
|
||||||
};
|
};
|
||||||
|
|
||||||
type Iter<T extends unknown[]> = IterableFunction<LuaTuple<[Entity, ...T]>>;
|
type Iter<T extends Id[]> = IterableFunction<LuaTuple<[Entity, ...InferComponents<T>]>>;
|
||||||
|
|
||||||
export type CachedQuery<T extends unknown[]> = {
|
export type CachedQuery<T extends Id[]> = {
|
||||||
/**
|
/**
|
||||||
* Returns an iterator that produces a tuple of [Entity, ...queriedComponents].
|
* Returns an iterator that produces a tuple of [Entity, ...queriedComponents].
|
||||||
*/
|
*/
|
||||||
|
@ -67,7 +67,7 @@ export type CachedQuery<T extends unknown[]> = {
|
||||||
archetypes(): Archetype<T>[];
|
archetypes(): Archetype<T>[];
|
||||||
} & Iter<T>;
|
} & Iter<T>;
|
||||||
|
|
||||||
export type Query<T extends unknown[]> = {
|
export type Query<T extends Id[]> = {
|
||||||
/**
|
/**
|
||||||
* Returns an iterator that produces a tuple of [Entity, ...queriedComponents].
|
* Returns an iterator that produces a tuple of [Entity, ...queriedComponents].
|
||||||
*/
|
*/
|
||||||
|
@ -246,11 +246,11 @@ export class World {
|
||||||
* @param components The list of components to query.
|
* @param components The list of components to query.
|
||||||
* @returns A Query object to iterate over results.
|
* @returns A Query object to iterate over results.
|
||||||
*/
|
*/
|
||||||
query<T extends Id[]>(...components: T): Query<InferComponents<T>>;
|
query<T extends Id[]>(...components: T): Query<T>;
|
||||||
|
|
||||||
added<T>(component: Entity<T>, listener: (e: Entity, id: Id<T>, value: T) => void): () => void
|
added<T>(component: Entity<T>, listener: (e: Entity, id: Id<T>, value: T) => void): () => void;
|
||||||
changed<T>(component: Entity<T>, listener: (e: Entity, id: Id<T>, value: T) => void): () => void
|
changed<T>(component: Entity<T>, listener: (e: Entity, id: Id<T>, value: T) => void): () => void;
|
||||||
removed<T>(component: Entity<T>, listener: (e: Entity, id: Id<T>) => void): () => void
|
removed<T>(component: Entity<T>, listener: (e: Entity, id: Id<T>) => void): () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function world(): World;
|
export function world(): World;
|
||||||
|
@ -297,11 +297,11 @@ export function ECS_PAIR_FIRST(pair: Pair): number;
|
||||||
export function ECS_PAIR_SECOND(pair: Pair): number;
|
export function ECS_PAIR_SECOND(pair: Pair): number;
|
||||||
|
|
||||||
type StatefulHook = Entity<<T>(e: Entity<T>, id: Id<T>, data: T) => void> & {
|
type StatefulHook = Entity<<T>(e: Entity<T>, id: Id<T>, data: T) => void> & {
|
||||||
readonly __nominal_StatefulHook: unique symbol,
|
readonly __nominal_StatefulHook: unique symbol;
|
||||||
}
|
};
|
||||||
type StatelessHook = Entity<<T>(e: Entity<T>, id: Id<T>) => void> & {
|
type StatelessHook = Entity<<T>(e: Entity<T>, id: Id<T>) => void> & {
|
||||||
readonly __nominal_StatelessHook: unique symbol,
|
readonly __nominal_StatelessHook: unique symbol;
|
||||||
}
|
};
|
||||||
|
|
||||||
export declare const OnAdd: StatefulHook;
|
export declare const OnAdd: StatefulHook;
|
||||||
export declare const OnRemove: StatelessHook;
|
export declare const OnRemove: StatelessHook;
|
||||||
|
@ -319,12 +319,17 @@ export declare const Exclusive: Tag;
|
||||||
export declare const Rest: Entity;
|
export declare const Rest: Entity;
|
||||||
|
|
||||||
export type ComponentRecord = {
|
export type ComponentRecord = {
|
||||||
records: Map<Id, number>,
|
records: Map<Id, number>;
|
||||||
counts: Map<Id, number>,
|
counts: Map<Id, number>;
|
||||||
size: number,
|
size: number;
|
||||||
}
|
};
|
||||||
|
|
||||||
export function component_record(world: World, id: Id): ComponentRecord
|
export function component_record(world: World, id: Id): ComponentRecord;
|
||||||
|
|
||||||
export function bulk_insert<const C extends Id[]>(world: World, entity: Entity, ids: C, values: InferComponents<C>): void
|
export function bulk_insert<const C extends Id[]>(
|
||||||
export function bulk_remove(world: World, entity: Entity, ids: Id[]): void
|
world: World,
|
||||||
|
entity: Entity,
|
||||||
|
ids: C,
|
||||||
|
values: InferComponents<C>,
|
||||||
|
): void;
|
||||||
|
export function bulk_remove(world: World, entity: Entity, ids: Id[]): void;
|
||||||
|
|
|
@ -733,7 +733,7 @@ local function world_target(world: world, entity: i53, relation: i53, index: num
|
||||||
local nth = index or 0
|
local nth = index or 0
|
||||||
|
|
||||||
if nth >= count then
|
if nth >= count then
|
||||||
nth = nth + count + 1
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
nth = archetype.types[nth + idr.records[archetype_id]]
|
nth = archetype.types[nth + idr.records[archetype_id]]
|
||||||
|
@ -2759,7 +2759,7 @@ local function world_new()
|
||||||
local nth = index or 0
|
local nth = index or 0
|
||||||
|
|
||||||
if nth >= count then
|
if nth >= count then
|
||||||
nth = nth + count + 1
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
nth = archetype.types[nth + idr.records[archetype_id]]
|
nth = archetype.types[nth + idr.records[archetype_id]]
|
||||||
|
|
Loading…
Reference in a new issue