mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-25 09:30:03 +00:00
Entity lookups
This commit is contained in:
parent
2b0d55db83
commit
0fd04c75c5
1 changed files with 7 additions and 10 deletions
17
lib/init.lua
17
lib/init.lua
|
@ -283,10 +283,8 @@ function World.new()
|
||||||
nextComponentId = 0,
|
nextComponentId = 0,
|
||||||
nextEntityId = 0,
|
nextEntityId = 0,
|
||||||
ROOT_ARCHETYPE = (nil :: any) :: Archetype,
|
ROOT_ARCHETYPE = (nil :: any) :: Archetype,
|
||||||
entityLookup = {
|
aliases = {},
|
||||||
id = {},
|
ids = {}
|
||||||
name = {}
|
|
||||||
}
|
|
||||||
}, World)
|
}, World)
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
@ -300,10 +298,9 @@ local function nextEntityId(world: World, index: i24, name: string?)
|
||||||
dense = index
|
dense = index
|
||||||
} :: Record
|
} :: Record
|
||||||
entityIndex.dense[index] = id
|
entityIndex.dense[index] = id
|
||||||
local entityLookup = world.entityLookup
|
|
||||||
if name then
|
if name then
|
||||||
entityLookup.id[id] = name
|
world.aliases[name] = id
|
||||||
entityLookup.name[name] = id
|
world.ids[id] = name
|
||||||
end
|
end
|
||||||
|
|
||||||
return id
|
return id
|
||||||
|
@ -329,7 +326,7 @@ end
|
||||||
|
|
||||||
function World.entity(world: World, name: string?)
|
function World.entity(world: World, name: string?)
|
||||||
if name then
|
if name then
|
||||||
local entity = world.entityLookup.name[name]
|
local entity = world.aliases[name]
|
||||||
if entity then
|
if entity then
|
||||||
return entity
|
return entity
|
||||||
end
|
end
|
||||||
|
@ -341,11 +338,11 @@ function World.entity(world: World, name: string?)
|
||||||
end
|
end
|
||||||
|
|
||||||
function World.lookup(world: World, name: string): i53
|
function World.lookup(world: World, name: string): i53
|
||||||
return world.entityLookup.name[name]
|
return world.aliases[name]
|
||||||
end
|
end
|
||||||
|
|
||||||
function World.name(world: World, entity: i53): string
|
function World.name(world: World, entity: i53): string
|
||||||
return world.entityLookup.id[entity]
|
return world.ids[entity]
|
||||||
end
|
end
|
||||||
|
|
||||||
-- should reuse this logic in World.set instead of swap removing in transition archetype
|
-- should reuse this logic in World.set instead of swap removing in transition archetype
|
||||||
|
|
Loading…
Reference in a new issue