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 B7 = ecr.component()
|
||||||
local B8 = ecr.component()
|
local B8 = ecr.component()
|
||||||
|
|
||||||
local D1 = ecs:entity()
|
local D1 = ecs:component()
|
||||||
local D2 = ecs:entity()
|
local D2 = ecs:component()
|
||||||
local D3 = ecs:entity()
|
local D3 = ecs:component()
|
||||||
local D4 = ecs:entity()
|
local D4 = ecs:component()
|
||||||
local D5 = ecs:entity()
|
local D5 = ecs:component()
|
||||||
local D6 = ecs:entity()
|
local D6 = ecs:component()
|
||||||
local D7 = ecs:entity()
|
local D7 = ecs:component()
|
||||||
local D8 = ecs:entity()
|
local D8 = ecs:component()
|
||||||
|
|
||||||
|
|
||||||
local E1 = mcs:entity()
|
local E1 = mcs:entity()
|
||||||
|
|
14
lib/init.lua
14
lib/init.lua
|
@ -159,7 +159,8 @@ function World.new()
|
||||||
archetypes = {},
|
archetypes = {},
|
||||||
archetypeIndex = {},
|
archetypeIndex = {},
|
||||||
ROOT_ARCHETYPE = (nil :: any) :: Archetype,
|
ROOT_ARCHETYPE = (nil :: any) :: Archetype,
|
||||||
nextId = 0,
|
nextEntityId = 0,
|
||||||
|
nextComponentId = 0,
|
||||||
nextArchetypeId = 0,
|
nextArchetypeId = 0,
|
||||||
hooks = {
|
hooks = {
|
||||||
[ON_ADD] = {}
|
[ON_ADD] = {}
|
||||||
|
@ -521,16 +522,17 @@ function World.query(world: World, ...: i53): any
|
||||||
end
|
end
|
||||||
|
|
||||||
function World.component(world: World)
|
function World.component(world: World)
|
||||||
local id = world.nextId + 1
|
local componentId = world.nextComponentId + 1
|
||||||
if id > HI_COMPONENT_ID then
|
if componentId > HI_COMPONENT_ID then
|
||||||
error("Too many components")
|
error("Too many components")
|
||||||
end
|
end
|
||||||
return id
|
world.nextComponentId = componentId
|
||||||
|
return componentId
|
||||||
end
|
end
|
||||||
|
|
||||||
function World.entity(world: World)
|
function World.entity(world: World)
|
||||||
world.nextId += 1
|
world.nextEntityId += 1
|
||||||
return world.nextId + REST
|
return world.nextEntityId + REST
|
||||||
end
|
end
|
||||||
|
|
||||||
function World.observer(world: World, ...)
|
function World.observer(world: World, ...)
|
||||||
|
|
|
@ -157,6 +157,13 @@ return function()
|
||||||
expect(withoutCount).to.equal(1)
|
expect(withoutCount).to.equal(1)
|
||||||
end)
|
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()
|
it("should skip iteration", function()
|
||||||
local Position, Velocity = world:entity(), world:entity()
|
local Position, Velocity = world:entity(), world:entity()
|
||||||
local e = world:entity()
|
local e = world:entity()
|
||||||
|
|
Loading…
Reference in a new issue