more stuff (idk lol)

This commit is contained in:
Elmārs Āboliņš 2020-10-03 15:11:04 +03:00
parent a200960ad1
commit fae63e1b24
10 changed files with 67 additions and 37 deletions

View File

@ -0,0 +1,9 @@
local path = string.sub(..., 1, string.len(...) - string.len(".control.size"))
local stack = require(path..'.core.stack')
--Sets the relative position
return function(x, y)
local currentStack = stack.getContext()
currentStack.element.view.x = x or currentStack.element.view.x
currentStack.element.view.y = y or currentStack.element.view.y
end

View File

@ -10,6 +10,7 @@ return function (base)
return fakeBase[index] or base[index] return fakeBase[index] or base[index]
end, end,
__newindex = function(t, index, val) __newindex = function(t, index, val)
print(index, val)
if fakeBase[index] ~= val then if fakeBase[index] ~= val then
fakeBase[index] = val fakeBase[index] = val
activeContext:bubbleUpdate() activeContext:bubbleUpdate()

View File

@ -1,5 +1,6 @@
local atlas = {} local atlas = {}
local createdAtlas local createdAtlas
local intermediaryCanvas
atlas.__index = atlas atlas.__index = atlas
local BLOCK_SIZE = 5 local BLOCK_SIZE = 5
@ -17,28 +18,30 @@ function atlas.getFreeArea()
return createdAtlas.ideal_area - createdAtlas.taken_area return createdAtlas.ideal_area - createdAtlas.taken_area
end end
local sw, sh = love.graphics.getDimensions()
function atlas.init() function atlas.init()
local w, h = love.graphics.getDimensions()
createdAtlas = atlas.new(w*2, h) createdAtlas = atlas.new(sw*2, sh)
intermediaryCanvas = love.graphics.newCanvas(sw, sh)
atlas.createdAtlas = createdAtlas atlas.createdAtlas = createdAtlas
atlas.interCanvas = intermediaryCanvas
end end
function atlas.assign(element) function atlas.assign(element)
local elW = element.view.w local elW = element.view.w
local elH = element.view.h local elH = element.view.h
local canvas, quad = createdAtlas:assignElement(element) local canvas, quad, interQuad = createdAtlas:assignElement(element)
if not canvas and createdAtlas.ideal_area < createdAtlas.taken_area*4 then if not canvas and createdAtlas.ideal_area < createdAtlas.taken_area*4 then
--print('refragmenting ;3') --print('refragmenting ;3')
createdAtlas:refragment() createdAtlas:refragment()
canvas, quad = createdAtlas:assignElement(element) canvas, quad, interQuad = createdAtlas:assignElement(element)
if not canvas then if not canvas then
--print('ran out of space') --print('ran out of space')
end end
else else
--print('wont refragment', createdAtlas.ideal_area, createdAtlas.taken_area) --print('wont refragment', createdAtlas.ideal_area, createdAtlas.taken_area)
end end
return canvas, quad return canvas, quad, interQuad
end end
function atlas.unassign(element) function atlas.unassign(element)
@ -92,14 +95,17 @@ function atlas:assignElement(element)
local t, y, x = self:find(tileSizeY, tileSizeX) local t, y, x = self:find(tileSizeY, tileSizeX)
if t then if t then
local quad local quad, iquad
--Refragmenting path --Refragmenting path
if self.users[element] then if self.users[element] then
--update by reference owo --update by reference owo
self.users[element].quad:setViewport((x-1)*BLOCK_SIZE, (y-1)*BLOCK_SIZE, elW, elH) self.users[element].quad:setViewport((x-1)*BLOCK_SIZE, (y-1)*BLOCK_SIZE, elW, elH)
self.users[element].interQuad:setViewport(0, 0, elW, elH)
quad = self.users[element].quad quad = self.users[element].quad
iquad = self.users[element].interQuad
else else
quad = love.graphics.newQuad((x-1)*BLOCK_SIZE, (y-1)*BLOCK_SIZE, elW, elH, self.w, self.h) quad = love.graphics.newQuad((x-1)*BLOCK_SIZE, (y-1)*BLOCK_SIZE, elW, elH, self.w, self.h)
iquad = love.graphics.newQuad(0, 0, elW, elH, sw, sh)
end end
self.users[element] = { self.users[element] = {
@ -108,13 +114,14 @@ function atlas:assignElement(element)
y = y, y = y,
w = tileSizeX, w = tileSizeX,
h = tileSizeY, h = tileSizeY,
quad = quad quad = quad,
interQuad = iquad
} }
self:markTiles(x, y, tileSizeX, tileSizeY) self:markTiles(x, y, tileSizeX, tileSizeY)
self.taken_area = self.taken_area + ((tileSizeY*BLOCK_SIZE)*(tileSizeX*BLOCK_SIZE)) self.taken_area = self.taken_area + ((tileSizeY*BLOCK_SIZE)*(tileSizeX*BLOCK_SIZE))
return self.canvas, self.users[element].quad return self.canvas, self.users[element].quad, iquad
else else
print('failed to allocate :X') print('failed to allocate :X')
return false return false

View File

@ -150,7 +150,6 @@ function element:createProxies()
end end
--Random coefficients, if these reach 1.5 then canvas is made --Random coefficients, if these reach 1.5 then canvas is made
local childrenNum = 5
local selfRenderTime = false local selfRenderTime = false
local screenSize = 1/4 local screenSize = 1/4
local coefficient = 1.5 local coefficient = 1.5
@ -173,10 +172,11 @@ function element:calculateCanvasCoeficient()
local area = self.view.h*self.view.w local area = self.view.h*self.view.w
local areaCoef = (2-(helium.atlas.getRatio()) )-(area/(areaBelow/(4+3*helium.atlas.getRatio()))) local areaCoef = (2-(helium.atlas.getRatio()) )-(area/(areaBelow/(4+3*helium.atlas.getRatio())))
local childCoef = self.context:getChildrenCount()/childrenNum local speedCoef = avg/selfRenderTime
local sizeCoef = avg/selfRenderTime
return (areaCoef+childCoef+sizeCoef)>coefficient
return (areaCoef+speedCoef)>coefficient
end end
local newCanvas, newQuad = love.graphics.newCanvas, love.graphics.newQuad local newCanvas, newQuad = love.graphics.newCanvas, love.graphics.newQuad
@ -184,7 +184,7 @@ function element:createCanvas()
self.settings.canvasW = self.view.w self.settings.canvasW = self.view.w
self.settings.canvasH = self.view.h self.settings.canvasH = self.view.h
self.canvas, self.quad = helium.atlas.assign(self) self.canvas, self.quad, self.interQuad = helium.atlas.assign(self)
if not self.canvas then if not self.canvas then
self.settings.failedCanvas = true self.settings.failedCanvas = true
@ -248,7 +248,7 @@ function element:internalRender()
if self.settings.testRenderPasses > 0 and selfRenderTime then if self.settings.testRenderPasses > 0 and selfRenderTime then
self.settings.testRenderPasses = self.settings.testRenderPasses-1 self.settings.testRenderPasses = self.settings.testRenderPasses-1
local selfTime = love.timer.getTime()-calcT local selfTime = love.timer.getTime()-calcT
table.insert(self.renderBench, self.context:endSelfRender(selfTime)) table.insert(self.renderBench, selfTime)
end end
end end
@ -297,10 +297,19 @@ function element:externalRender()
setCanvas(cnvs) setCanvas(cnvs)
if self.settings.hasCanvas then if self.settings.hasCanvas then
if self.canvas == cnvs then
love.graphics.push('all')
love.graphics.origin()
setColor(1,1,1,1)
setCanvas(helium.atlas.interCanvas)
draw(self.canvas, self.quad, 0, 0)
love.graphics.pop()
setCanvas(cnvs)
draw(helium.atlas.interCanvas, self.interQuad, 0, 0)
else
setColor(1,1,1,1) setColor(1,1,1,1)
draw(self.canvas, self.quad, 0, 0) draw(self.canvas, self.quad, 0, 0)
setColor(0,1,0,0.5) end
love.graphics.rectangle('line', 1, 1, self.view.w-1, self.view.h-1)
end end
love.graphics.pop() love.graphics.pop()
@ -328,17 +337,14 @@ function element:externalUpdate()
self.context:sizeChanged() self.context:sizeChanged()
if self.settings.hasCanvas then if self.settings.hasCanvas then
helium.atlas.unassign(self) helium.atlas.unassign(self)
if self:calculateCanvasCoeficient() then
self:createCanvas()
else
self.settings.hasCanvas = false self.settings.hasCanvas = false
self.settings.testRenderPasses = 15
self.canvas = nil self.canvas = nil
self.quad = nil self.quad = nil
self.interQuad = nil
self.deferResize = nil self.deferResize = nil
end end
end end
end
if self.deferRepos then if self.deferRepos then
self.context:posChanged() self.context:posChanged()
@ -374,6 +380,9 @@ function element:draw(x, y, w, h)
if self.settings.firstDraw then if self.settings.firstDraw then
self.settings.remove = false self.settings.remove = false
self.settings.firstDraw = false self.settings.firstDraw = false
if cx then
self.settings.testRenderPasses = self.settings.testRenderPasses-5
end
end end
end end

View File

@ -9,11 +9,7 @@ local input = {
input.__index = input input.__index = input
local function sortFunc(t1, t2) local function sortFunc(t1, t2)
if t1.stack.temporalZ.z == t2.stack.temporalZ.z then
print('same Z ???',t1.stack.temporalZ.z, t2.stack.temporalZ.z)
end
if t1 == t2 then if t1 == t2 then
print(tostring(t1), tostring(t2))
return false return false
end end
return t1.stack.temporalZ.z > t2.stack.temporalZ.z return t1.stack.temporalZ.z > t2.stack.temporalZ.z
@ -22,7 +18,6 @@ end
function input.sortZ() function input.sortZ()
for i, subs in pairs(input.subscriptions) do for i, subs in pairs(input.subscriptions) do
table.sort(subs, sortFunc) table.sort(subs, sortFunc)
print(#subs)
end end
end end
@ -88,7 +83,6 @@ function subscription.create(x, y, w, h, eventType, callback, doff)
sub.onPosChange = stack:onPosChange(function() sub.onPosChange = stack:onPosChange(function()
sub.x, sub.y = sub.stack:normalizePos(sub.origX, sub.origY) sub.x, sub.y = sub.stack:normalizePos(sub.origX, sub.origY)
print(sub.y, sub.stack.absY)
end) end)
if doff == false then if doff == false then

View File

@ -43,7 +43,7 @@ function context:set()
if activeContext then if activeContext then
if not self.parentCtx and activeContext~=self then if not self.parentCtx and activeContext~=self then
self.parentCtx = activeContext self.parentCtx = activeContext
activeContext.childrenContexts[#activeContext.childrenContexts] = self activeContext.childrenContexts[#activeContext.childrenContexts+1] = self
end end
self.absX = self.parentCtx.absX + self.view.x self.absX = self.parentCtx.absX + self.view.x

View File

@ -7,5 +7,4 @@ return function(x, y, width, height, children, hpad, vpad, alignX)
carriagePos = carriagePos + h + vpad carriagePos = carriagePos + h + vpad
end end
end end
print('finished layout')
end end

View File

View File

@ -3,6 +3,7 @@ local path = string.sub(..., 1, string.len(...) - string.len(".layout"))
local layout = {} local layout = {}
local layouts = {} local layouts = {}
layouts.column = require(path..'.layout.column') layouts.column = require(path..'.layout.column')
layouts.row = require(path..'.layout.row')
layout.__index = layout layout.__index = layout
local element = require(path..'.core.element') local element = require(path..'.core.element')
local stack = require(path..'.core.stack') local stack = require(path..'.core.stack')

10
layout/row.lua Normal file
View File

@ -0,0 +1,10 @@
return function(x, y, width, height, children, hpad, vpad, alignX)
local carriagePos = 0
if children then
for i, e in ipairs(children) do
local w, _ = e:getSize()
e:draw(x+carriagePos+hpad, y+vpad)
carriagePos = carriagePos + w + vpad
end
end
end