From 4e4afd2baf71d74057b7b5409ce6f0f5689be917 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Tue, 23 Mar 2021 18:26:05 +0100 Subject: [PATCH] improvement: lazyload sti objects --- .../core/modules/world/maps/tiled/init.lua | 2 +- .../core/modules/world/maps/tiled/stiwrapper.lua | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/sonic-radiance.love/core/modules/world/maps/tiled/init.lua b/sonic-radiance.love/core/modules/world/maps/tiled/init.lua index 0cfa600..728c1d8 100644 --- a/sonic-radiance.love/core/modules/world/maps/tiled/init.lua +++ b/sonic-radiance.love/core/modules/world/maps/tiled/init.lua @@ -25,7 +25,7 @@ function TiledMap:getDimensions() end function TiledMap:loadObjects() - self.wrapper:loadObjects() + --self.wrapper:loadObjects() end -- TILE FUNCTIONS diff --git a/sonic-radiance.love/core/modules/world/maps/tiled/stiwrapper.lua b/sonic-radiance.love/core/modules/world/maps/tiled/stiwrapper.lua index df81759..ee88e82 100644 --- a/sonic-radiance.love/core/modules/world/maps/tiled/stiwrapper.lua +++ b/sonic-radiance.love/core/modules/world/maps/tiled/stiwrapper.lua @@ -8,6 +8,7 @@ function StiWrapper:new(owner, mapfile, x, y) self.y = y or 0 self.objectlayer = 0 + self.isLoaded = false end function StiWrapper:getDimensions() @@ -22,12 +23,20 @@ function StiWrapper:resize(w, h) end function StiWrapper:update(dt) + self:lazyLoad() self.sti:update(dt) end -- OBJECT FUNCTIONS -- Handle objets +function StiWrapper:lazyLoad() + if (not self.isLoaded) then + self:loadObjects() + self.isLoaded = true + end +end + function StiWrapper:loadObjects() self:loadCollisions() self:loadPlayers() @@ -179,6 +188,7 @@ end -- Draw the map function StiWrapper:drawUpperLayers() + self:lazyLoad() if (self.objectlayer > 0) then for i = self.objectlayer, self.nbrLayer, 1 do self:drawLayer(i) @@ -187,6 +197,7 @@ function StiWrapper:drawUpperLayers() end function StiWrapper:drawLowerLayers() + self:lazyLoad() for i = 1, self.objectlayer, 1 do self:drawLayer(i) end