From 451b88cdea6a63df4ca6ee8bd41d44b521ba3274 Mon Sep 17 00:00:00 2001 From: Tjakka5 Date: Sat, 4 Jan 2020 10:47:45 +0100 Subject: [PATCH] Finish system optimization --- README.md | 4 ++-- src/system.lua | 9 ++++++++- src/world.lua | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 436e7a0..099e929 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/system.lua b/src/system.lua index 5c12d39..0215b7b 100644 --- a/src/system.lua +++ b/src/system.lua @@ -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 diff --git a/src/world.lua b/src/world.lua index fe6107e..a98d38d 100644 --- a/src/world.lua +++ b/src/world.lua @@ -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