diff --git a/conf.lua b/conf.lua index 8eceffa..b0cd590 100644 --- a/conf.lua +++ b/conf.lua @@ -1,7 +1,9 @@ return { - HOTSWAP = true, --Turns on hotswap, disable this once you're deploying a project + HOTSWAP = true, --Deprecated AUTO_RUN = true, --Replaces the default love.run DEBUG = true, --Reserved for later PURE_G = true, --whether to keep _G pure HARD_ERROR = true, --Whether to display element errors inside or hard cras + AUTO_CACHING = true, --Enable for cache money + CACHING_CANVASES = 2, --How many fullscreen atlas canvases to create (change if auto_caching is enabled, to suit your needs, more means more texturememory) } \ No newline at end of file diff --git a/core/atlas.lua b/core/atlas.lua new file mode 100644 index 0000000..e5d2342 --- /dev/null +++ b/core/atlas.lua @@ -0,0 +1,82 @@ +local atlas = {} +local atlases = {} +atlas.__index = atlas +local BLOCK_SIZE = 10 + +function atlas.init() + local w, h = love.graphics.getDimensions() + + +end + +function atlas.onscreenchange(newW,newH) + +end + +function atlas.new(w, h) + local tiles = {} + + local ymax = math.floor(h/BLOCK_SIZE) + for y = 1, ymax do + tiles[y] = {} + tiles[y].empty = ymax + for x = 1, math.floor(w/BLOCK_SIZE) do + tiles[y][x] = { + taken = false + } + end + end + + local self = { + w = w, + h = h, + ideal_area = w*h, + canvas = love.graphics.newCanvas(w, h), + users = {}, + tiles = tiles, + } + + return setmetatable(self, atlas) +end + +function atlas:assignElement(elW, elH, element) + local tileSizeY, tileSizeW = math.ceil(elH/BLOCK_SIZE), math.ceil(elW/BLOCK_SIZE) + +end + +--Work only with rounded values inside here +function atlas:find(sizeY, sizeX) + for y = 1, #self.tiles do + local skipUntilX=0 + if self.tiles[y].empty > sizeY then + for x = 1, #self.tiles[1] do + if not self.tiles[y][x].taken and x>skipUntilX then + local result, y, x = self:slice(y, x, sizeY, sizeX) + + if result then + return true, y, x + else + skipUntilX = x + end + end + end + end + end +end + +function atlas:slice(startY, startX, sizeY, sizeX) + for y = startY, startY+sizeY do + for x = startX, sizeX do + if self.tiles[y][x].taken then + return false, y, x + end + end + end + return true +end + +function atlas:unassignElement(element) + +end + +return atlas \ No newline at end of file diff --git a/core/element.lua b/core/element.lua index 33a2866..6a685e4 100644 --- a/core/element.lua +++ b/core/element.lua @@ -104,7 +104,7 @@ end local childrenNum = 5 local selfRenderTime = false local screenSize = 1/50 -local coefficient = 1.5 +local coefficient = 1000000 function element.setBench(time) selfRenderTime = time @@ -260,6 +260,7 @@ function element:externalRender() if self.settings.hasCanvas then setColor(1,1,1,1) draw(self.canvas, self.quad, 0, 0) + setColor(0,1,0,0.5) love.graphics.rectangle('line', 1, 1, self.view.w-1, self.view.h-1) end diff --git a/init.lua b/init.lua index f54e0c1..4d99312 100644 --- a/init.lua +++ b/init.lua @@ -32,7 +32,7 @@ function helium.render() local startTime = love.timer.getTime() for i = 1, 20 do - love.graphics.print(i) + love.graphics.print(i,-100,-100) end helium.element.setBench((love.timer.getTime()-startTime)/9) @@ -117,14 +117,19 @@ if helium.conf.AUTO_RUN then -- Call update and draw if love.update then love.update(dt) end -- will pass 0 if love.timer is disabled + local st = love.timer.getTime() helium.update(dt) + heliumTime = love.timer.getTime()-st if love.graphics and love.graphics.isActive() then love.graphics.origin() love.graphics.clear(love.graphics.getBackgroundColor()) if love.draw then love.draw() end + + st = love.timer.getTime() helium.render() + heliumTime=heliumTime+love.timer.getTime()-st love.graphics.present() end