mirror of
https://github.com/Keyslam-Group/Concord.git
synced 2025-09-01 20:03:55 -04:00
Streamline entity lifetime
This commit is contained in:
parent
bc47eaa651
commit
038111d558
7 changed files with 117 additions and 163 deletions
37
main.lua
37
main.lua
|
@ -22,20 +22,49 @@ local test_comp_3 = Concord.component("test_comp_3", function(e, b)
|
|||
end)
|
||||
|
||||
local test_system = Concord.system({Component.test_comp_1})
|
||||
function test_system:update(dt)
|
||||
print(#self.pool)
|
||||
|
||||
function onEntityAdded(e)
|
||||
print("Added")
|
||||
end
|
||||
|
||||
function onEntityRemoved(e)
|
||||
print("Removed")
|
||||
end
|
||||
|
||||
function test_system:init()
|
||||
self.pool.onEntityAdded = onEntityAdded
|
||||
self.pool.onEntityRemoved = onEntityRemoved
|
||||
end
|
||||
|
||||
function test_system:update(dt)
|
||||
--print(#self.pool)
|
||||
end
|
||||
|
||||
|
||||
|
||||
local world = Concord.world()
|
||||
|
||||
local entity = Concord.entity()
|
||||
entity:give(Component.test_comp_2, 100, 100)
|
||||
entity:apply()
|
||||
entity:give(Component.test_comp_1, 100, 100)
|
||||
|
||||
world:addEntity(entity)
|
||||
|
||||
world:addSystem(test_system(), "update")
|
||||
|
||||
function love.update(dt)
|
||||
world:flush()
|
||||
|
||||
world:emit("update", dt)
|
||||
end
|
||||
|
||||
function love.keypressed(key)
|
||||
if key == "q" then
|
||||
entity:remove(Component.test_comp_1)
|
||||
end
|
||||
if key == "w" then
|
||||
entity:give(Component.test_comp_1)
|
||||
end
|
||||
if key == "e" then
|
||||
world:removeEntity(entity)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue