Finish system optimization

This commit is contained in:
Tjakka5 2020-01-04 10:47:45 +01:00
parent 424f27ed8a
commit 451b88cdea
3 changed files with 11 additions and 4 deletions

View file

@ -199,7 +199,7 @@ print(positionComponent.x, positionComponent.y) -- 100, 50
```lua
-- Remove a Component
myEntity:remove(Concord.compoennts.positionComponent)
myEntity:remove(Concord.components.positionComponent)
```
```lua
@ -209,7 +209,7 @@ print(hasPositionComponent) -- false
```
```lua
-- Entity:give will override a Component if the Entity already had it
-- Entity:give will override a Component if the Entity already has it
-- Entity:ensure will only put the Component if the Entity does not already have it
Entity:ensure(Concord.components.positionComponents, 0, 0) -- Will give

View file

@ -29,7 +29,7 @@ System.mt = {
-- This grants slightly faster access times at the cost of memory.
-- Since there (generally) won't be many instances of worlds this is a worthwhile tradeoff
if (System.ENABLE_OPTIMIZATION) then
Utils.shallowCopy(System, system)
Utils.shallowCopy(systemClass, system)
end
for _, filter in pairs(systemClass.__filter) do
@ -58,6 +58,13 @@ function System.new(...)
}, System.mt)
systemClass.__index = systemClass
-- Optimization: We deep copy the World class into our instance of a world.
-- This grants slightly faster access times at the cost of memory.
-- Since there (generally) won't be many instances of worlds this is a worthwhile tradeoff
if (System.ENABLE_OPTIMIZATION) then
Utils.shallowCopy(System, systemClass)
end
return systemClass
end

View file

@ -243,7 +243,7 @@ function World:emit(functionName, ...)
error("bad argument #1 to 'World:emit' (String expected, got "..type(functionName)..")")
end
local listeners = self.events[functionName]
local listeners = self.events[functionName]
if listeners then
for i = 1, #listeners do