mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 02:51:49 +00:00
feat: multiple components per entity support
This commit is contained in:
parent
a6aa42a521
commit
8f379f2ee7
8 changed files with 120 additions and 65 deletions
|
|
@ -53,6 +53,7 @@ return {
|
|||
entity.rigidbody = new_Rigidbody(eid)
|
||||
entity.modeltree = new_Modeltree(eid)
|
||||
entity.data = {}
|
||||
entity.components = {}
|
||||
entities[eid] = entity;
|
||||
return entity
|
||||
end,
|
||||
|
|
@ -62,17 +63,19 @@ return {
|
|||
remove_Entity = function(eid)
|
||||
local entity = entities[eid]
|
||||
if entity then
|
||||
entity.env = nil
|
||||
entity.components = nil
|
||||
entities[eid] = nil;
|
||||
end
|
||||
end,
|
||||
update = function()
|
||||
for id,entity in pairs(entities) do
|
||||
local callback = entity.env.on_update
|
||||
if callback then
|
||||
local result, err = pcall(callback)
|
||||
if err then
|
||||
print(err)
|
||||
for _, component in pairs(entity.components) do
|
||||
local callback = component.on_update
|
||||
if callback then
|
||||
local result, err = pcall(callback)
|
||||
if err then
|
||||
print(err)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue