Add optional optimization for worlds and systems

This commit is contained in:
Tjakka5 2020-01-03 23:01:04 +01:00
parent 56b5244541
commit 6aeb91d984
4 changed files with 58 additions and 57 deletions

View file

@ -2,10 +2,13 @@
local PATH = (...):gsub('%.[^%.]+$', '')
local Type = require(PATH..".type")
local List = require(PATH..".list")
local Type = require(PATH..".type")
local List = require(PATH..".list")
local Utils = require(PATH..".utils")
local World = {}
local World = {
ENABLE_OPTIMIZATION = true,
}
World.__index = World
--- Creates a new World.
@ -26,6 +29,13 @@ function World.new()
__isWorld = true,
}, World)
-- 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 (World.ENABLE_OPTIMIZATION) then
Utils.shallowCopy(World, world)
end
return world
end