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]
end,
__newindex = function(t, index, val)
print(index, val)
if fakeBase[index] ~= val then
fakeBase[index] = val
activeContext:bubbleUpdate()

View File

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

View File

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

View File

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

View File

@ -43,7 +43,7 @@ function context:set()
if activeContext then
if not self.parentCtx and activeContext~=self then
self.parentCtx = activeContext
activeContext.childrenContexts[#activeContext.childrenContexts] = self
activeContext.childrenContexts[#activeContext.childrenContexts+1] = self
end
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
end
end
print('finished layout')
end

View File

View File

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