Add engine.elementsByType

This commit is contained in:
Fierelier 2022-11-26 19:26:43 +01:00
parent 66c6ef44a5
commit 31e446f232
1 changed files with 5 additions and 0 deletions

View File

@ -3,6 +3,7 @@ local engine = {}
function engine.null() end
engine.elements = {}
engine.elementsByType = {}
engine.elementTypes = {}
engine.element = {}
@ -26,6 +27,7 @@ function engine.element.create(elementType)
_references = 0
}
engine.elementsByType[elementType] = {}
assert(loadfile(engine.path(elementType.. ".lua")))(engine.elementTypes[elementType])
end
@ -51,6 +53,7 @@ function engine.element.create(elementType)
engine.elementTypes[elementType].create(element)
engine.elements[id] = element
engine.elementsByType[elementType][id] = element
return element
end
@ -87,11 +90,13 @@ function engine.element.destroy(element,destroyChildren)
engine.elementTypes[element.memhi._type].destroy(element)
engine.elements[element.memhi._id] = nil
engine.elementsByType[element.memhi._type][element.memhi._id] = nil
engine.elementTypes[element.memhi._type]._references = engine.elementTypes[element.memhi._type]._references - 1
if engine.elementTypes[element.memhi._type]._references == 0 then
engine.elementTypes[element.memhi._type].unload()
engine.elementTypes[element.memhi._type] = nil
engine.elementsByType[element.memhi._type] = nil
end
end