add on_update, on_render to docs & change entities tps to 20

This commit is contained in:
MihailRis
2024-08-01 16:04:27 +03:00
parent 3f67944cc2
commit f8907f7db1
10 changed files with 62 additions and 21 deletions
+9 -5
View File
@@ -88,25 +88,29 @@ return {
entities[eid] = nil;
end
end,
update = function()
for _,entity in pairs(entities) do
update = function(tps, parts, part)
for uid, entity in pairs(entities) do
if uid % parts ~= part then
goto continue
end
for _, component in pairs(entity.components) do
local callback = component.on_update
if callback then
local result, err = pcall(callback)
local result, err = pcall(callback, tps)
if err then
debug.error(err)
end
end
end
::continue::
end
end,
render = function()
render = function(delta)
for _,entity in pairs(entities) do
for _, component in pairs(entity.components) do
local callback = component.on_render
if callback then
local result, err = pcall(callback)
local result, err = pcall(callback, delta)
if err then
debug.error(err)
end