mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-24 17:10:03 +00:00
Separate ids and add tests (#11)
This commit is contained in:
parent
275aa6ec6d
commit
4978ac7856
3 changed files with 23 additions and 14 deletions
|
@ -30,14 +30,14 @@ local B6 = ecr.component()
|
|||
local B7 = ecr.component()
|
||||
local B8 = ecr.component()
|
||||
|
||||
local D1 = ecs:entity()
|
||||
local D2 = ecs:entity()
|
||||
local D3 = ecs:entity()
|
||||
local D4 = ecs:entity()
|
||||
local D5 = ecs:entity()
|
||||
local D6 = ecs:entity()
|
||||
local D7 = ecs:entity()
|
||||
local D8 = ecs:entity()
|
||||
local D1 = ecs:component()
|
||||
local D2 = ecs:component()
|
||||
local D3 = ecs:component()
|
||||
local D4 = ecs:component()
|
||||
local D5 = ecs:component()
|
||||
local D6 = ecs:component()
|
||||
local D7 = ecs:component()
|
||||
local D8 = ecs:component()
|
||||
|
||||
|
||||
local E1 = mcs:entity()
|
||||
|
|
14
lib/init.lua
14
lib/init.lua
|
@ -159,7 +159,8 @@ function World.new()
|
|||
archetypes = {},
|
||||
archetypeIndex = {},
|
||||
ROOT_ARCHETYPE = (nil :: any) :: Archetype,
|
||||
nextId = 0,
|
||||
nextEntityId = 0,
|
||||
nextComponentId = 0,
|
||||
nextArchetypeId = 0,
|
||||
hooks = {
|
||||
[ON_ADD] = {}
|
||||
|
@ -521,16 +522,17 @@ function World.query(world: World, ...: i53): any
|
|||
end
|
||||
|
||||
function World.component(world: World)
|
||||
local id = world.nextId + 1
|
||||
if id > HI_COMPONENT_ID then
|
||||
local componentId = world.nextComponentId + 1
|
||||
if componentId > HI_COMPONENT_ID then
|
||||
error("Too many components")
|
||||
end
|
||||
return id
|
||||
world.nextComponentId = componentId
|
||||
return componentId
|
||||
end
|
||||
|
||||
function World.entity(world: World)
|
||||
world.nextId += 1
|
||||
return world.nextId + REST
|
||||
world.nextEntityId += 1
|
||||
return world.nextEntityId + REST
|
||||
end
|
||||
|
||||
function World.observer(world: World, ...)
|
||||
|
|
|
@ -157,6 +157,13 @@ return function()
|
|||
expect(withoutCount).to.equal(1)
|
||||
end)
|
||||
|
||||
it("should allow calling world:entity before world:component", function()
|
||||
for _ = 1, 256 do
|
||||
world:entity()
|
||||
end
|
||||
expect(world:component()).to.be.ok()
|
||||
end)
|
||||
|
||||
it("should skip iteration", function()
|
||||
local Position, Velocity = world:entity(), world:entity()
|
||||
local e = world:entity()
|
||||
|
|
Loading…
Reference in a new issue