mirror of
https://github.com/Ukendio/jecs.git
synced 2025-08-04 11:19:17 +00:00
Compare commits
4 commits
42278ce414
...
6a52ad6cec
Author | SHA1 | Date | |
---|---|---|---|
|
6a52ad6cec | ||
|
0b6bfea5c8 | ||
|
3cfce10a4a | ||
|
f912866fcb |
1 changed files with 19 additions and 2 deletions
21
jecs.luau
21
jecs.luau
|
@ -118,6 +118,8 @@ type world = {
|
||||||
|
|
||||||
max_component_id: number,
|
max_component_id: number,
|
||||||
max_archetype_id: number,
|
max_archetype_id: number,
|
||||||
|
start_component_id: number,
|
||||||
|
start_tag_id: number,
|
||||||
|
|
||||||
observable: Map<i53, Map<i53, { Observer }>>,
|
observable: Map<i53, Map<i53, { Observer }>>,
|
||||||
|
|
||||||
|
@ -155,6 +157,8 @@ export type World = {
|
||||||
|
|
||||||
max_component_id: number,
|
max_component_id: number,
|
||||||
max_archetype_id: number,
|
max_archetype_id: number,
|
||||||
|
start_component_id: number,
|
||||||
|
start_tag_id: number,
|
||||||
|
|
||||||
observable: Map<Id, Map<Id, { Observer }>>,
|
observable: Map<Id, Map<Id, { Observer }>>,
|
||||||
|
|
||||||
|
@ -733,7 +737,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]]
|
||||||
|
@ -752,6 +756,12 @@ local function ECS_ID_IS_WILDCARD(e: i53): boolean
|
||||||
return first == EcsWildcard or second == EcsWildcard
|
return first == EcsWildcard or second == EcsWildcard
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function get_max_ids_difference(world: World): (number, number)
|
||||||
|
local diff_components = world.start_component_id - ecs_max_component_id
|
||||||
|
local diff_tags = world.start_tag_id - ecs_max_tag_id
|
||||||
|
return diff_components, diff_tags
|
||||||
|
end
|
||||||
|
|
||||||
local function id_record_get(world: World, id: Entity): ComponentRecord?
|
local function id_record_get(world: World, id: Entity): ComponentRecord?
|
||||||
local component_index = world.component_index
|
local component_index = world.component_index
|
||||||
local idr: ComponentRecord = component_index[id]
|
local idr: ComponentRecord = component_index[id]
|
||||||
|
@ -879,6 +889,7 @@ local function archetype_create(world: world, id_types: { i53 }, ty, prev: i53?)
|
||||||
|
|
||||||
for i, component_id in archetype.types do
|
for i, component_id in archetype.types do
|
||||||
local idr = id_record_ensure(world, component_id)
|
local idr = id_record_ensure(world, component_id)
|
||||||
|
idr.size += 1
|
||||||
local is_tag = bit32.btest(idr.flags, ECS_ID_IS_TAG)
|
local is_tag = bit32.btest(idr.flags, ECS_ID_IS_TAG)
|
||||||
local column = if is_tag then NULL_ARRAY else {}
|
local column = if is_tag then NULL_ARRAY else {}
|
||||||
columns[i] = column
|
columns[i] = column
|
||||||
|
@ -890,11 +901,13 @@ local function archetype_create(world: world, id_types: { i53 }, ty, prev: i53?)
|
||||||
local object = ECS_PAIR_SECOND(component_id)
|
local object = ECS_PAIR_SECOND(component_id)
|
||||||
local r = ECS_PAIR(relation, EcsWildcard)
|
local r = ECS_PAIR(relation, EcsWildcard)
|
||||||
local idr_r = id_record_ensure(world, r)
|
local idr_r = id_record_ensure(world, r)
|
||||||
|
idr_r.size += 1
|
||||||
|
|
||||||
archetype_append_to_records(idr_r, archetype_id, columns_map, r, i, column)
|
archetype_append_to_records(idr_r, archetype_id, columns_map, r, i, column)
|
||||||
|
|
||||||
local t = ECS_PAIR(EcsWildcard, object)
|
local t = ECS_PAIR(EcsWildcard, object)
|
||||||
local idr_t = id_record_ensure(world, t)
|
local idr_t = id_record_ensure(world, t)
|
||||||
|
idr_t.size += 1
|
||||||
|
|
||||||
archetype_append_to_records(idr_t, archetype_id, columns_map, t, i, column)
|
archetype_append_to_records(idr_t, archetype_id, columns_map, t, i, column)
|
||||||
end
|
end
|
||||||
|
@ -2250,6 +2263,9 @@ local function world_new()
|
||||||
max_archetype_id = 0,
|
max_archetype_id = 0,
|
||||||
max_component_id = ecs_max_component_id,
|
max_component_id = ecs_max_component_id,
|
||||||
|
|
||||||
|
start_component_id = ecs_max_component_id,
|
||||||
|
start_tag_id = ecs_max_tag_id,
|
||||||
|
|
||||||
observable = observable,
|
observable = observable,
|
||||||
signals = signals,
|
signals = signals,
|
||||||
} :: world
|
} :: world
|
||||||
|
@ -2756,7 +2772,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]]
|
||||||
|
@ -3313,6 +3329,7 @@ return {
|
||||||
pair_first = ecs_pair_first :: <P, O>(world: World, pair: Pair<P, O>) -> Id<P>,
|
pair_first = ecs_pair_first :: <P, O>(world: World, pair: Pair<P, O>) -> Id<P>,
|
||||||
pair_second = ecs_pair_second :: <P, O>(world: World, pair: Pair<P, O>) -> Id<O>,
|
pair_second = ecs_pair_second :: <P, O>(world: World, pair: Pair<P, O>) -> Id<O>,
|
||||||
entity_index_get_alive = entity_index_get_alive,
|
entity_index_get_alive = entity_index_get_alive,
|
||||||
|
get_max_ids_difference = get_max_ids_difference,
|
||||||
|
|
||||||
archetype_append_to_records = archetype_append_to_records,
|
archetype_append_to_records = archetype_append_to_records,
|
||||||
id_record_ensure = id_record_ensure :: (World, Id) -> ComponentRecord,
|
id_record_ensure = id_record_ensure :: (World, Id) -> ComponentRecord,
|
||||||
|
|
Loading…
Reference in a new issue