canvas assignment fix
This commit is contained in:
parent
91e3441201
commit
6cca604b46
@ -57,18 +57,18 @@ function atlases: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, interQuad = self.atlases[canvasID]:assignElement(element)
|
local canvas, quad = self.atlases[canvasID]:assignElement(element)
|
||||||
if not canvas and self.atlases[canvasID].ideal_area < self.atlases[canvasID].taken_area*4 then
|
if not canvas and self.atlases[canvasID].ideal_area < self.atlases[canvasID].taken_area*4 then
|
||||||
--print('refragmenting ;3')
|
--print('refragmenting ;3')
|
||||||
self.atlases[canvasID]:refragment()
|
self.atlases[canvasID]:refragment()
|
||||||
canvas, quad, interQuad = self.atlases[canvasID]:assignElement(element)
|
canvas, quad = self.atlases[canvasID]: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, interQuad
|
return canvas, quad, canvasID
|
||||||
end
|
end
|
||||||
|
|
||||||
function atlases:unassign(element)
|
function atlases:unassign(element)
|
||||||
@ -142,12 +142,9 @@ function atlas:assignElement(element)
|
|||||||
if self.users[element] and self.users[element].quad and self.users[element].interQuad then
|
if self.users[element] and self.users[element].quad and self.users[element].interQuad 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] = {
|
||||||
@ -162,7 +159,7 @@ function atlas:assignElement(element)
|
|||||||
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, iquad
|
return self.canvas, self.users[element].quad
|
||||||
else
|
else
|
||||||
print('failed to allocate :X')
|
print('failed to allocate :X')
|
||||||
return false
|
return false
|
||||||
|
|||||||
@ -8,6 +8,8 @@ local helium = require(path .. ".dummy")
|
|||||||
local context = require(path.. ".core.stack")
|
local context = require(path.. ".core.stack")
|
||||||
local scene = require(path.. ".core.scene")
|
local scene = require(path.. ".core.scene")
|
||||||
|
|
||||||
|
local currentCanvasID
|
||||||
|
|
||||||
---@class Element
|
---@class Element
|
||||||
local element = {}
|
local element = {}
|
||||||
element.__index = element
|
element.__index = element
|
||||||
@ -55,6 +57,8 @@ function element:new(param, immediate, w, h, flags)
|
|||||||
immediate = immediate or false,
|
immediate = immediate or false,
|
||||||
--Whether this element has a canvas assigned
|
--Whether this element has a canvas assigned
|
||||||
hasCanvas = false,
|
hasCanvas = false,
|
||||||
|
--Which canvas is it assigned to
|
||||||
|
currentCanvasIndex = nil,
|
||||||
--Current test render passes to be benchmarked
|
--Current test render passes to be benchmarked
|
||||||
testRenderPasses = 20,
|
testRenderPasses = 20,
|
||||||
--
|
--
|
||||||
@ -198,7 +202,7 @@ end
|
|||||||
local newCanvas, newQuad = love.graphics.newCanvas, love.graphics.newQuad
|
local newCanvas, newQuad = love.graphics.newCanvas, love.graphics.newQuad
|
||||||
function element:createCanvas()
|
function element:createCanvas()
|
||||||
|
|
||||||
self.canvas, self.quad = scene.activeScene.atlas:assign(self)
|
self.canvas, self.quad, self.settings.currentCanvasIndex = scene.activeScene.atlas:assign(self)
|
||||||
|
|
||||||
if not self.canvas then
|
if not self.canvas then
|
||||||
self.settings.failedCanvas = true
|
self.settings.failedCanvas = true
|
||||||
@ -292,6 +296,18 @@ function element:externalRender()
|
|||||||
self.settings.isSetup = true
|
self.settings.isSetup = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local oldCanvasId
|
||||||
|
if self.settings.hasCanvas then
|
||||||
|
if self.settings.currentCanvasIndex == currentCanvasID then
|
||||||
|
--problem lol
|
||||||
|
self.settings.renderingParentCanvasIndex = currentCanvasID
|
||||||
|
self:reassignCanvas()
|
||||||
|
else
|
||||||
|
oldCanvasId = currentCanvasID
|
||||||
|
currentCanvasID = self.settings.currentCanvasIndex
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if self.settings.needsRendering then
|
if self.settings.needsRendering then
|
||||||
if self.settings.hasCanvas then
|
if self.settings.hasCanvas then
|
||||||
setCanvas(self.canvas)
|
setCanvas(self.canvas)
|
||||||
@ -329,6 +345,7 @@ function element:externalRender()
|
|||||||
|
|
||||||
lg.setScissor()
|
lg.setScissor()
|
||||||
love.graphics.pop()
|
love.graphics.pop()
|
||||||
|
currentCanvasID = oldCanvasId
|
||||||
end
|
end
|
||||||
|
|
||||||
function element:externalUpdate()
|
function element:externalUpdate()
|
||||||
|
|||||||
@ -109,6 +109,9 @@ function context:getCanvasIndex(forCanvas)
|
|||||||
return self.parentCtx:getCanvasIndex() == 1 and 2 or 1
|
return self.parentCtx:getCanvasIndex() == 1 and 2 or 1
|
||||||
else
|
else
|
||||||
if forCanvas then
|
if forCanvas then
|
||||||
|
if self.element.settings.renderingParentCanvasIndex then
|
||||||
|
return self.element.settings.renderingParentCanvasIndex == 1 and 2 or 1
|
||||||
|
end
|
||||||
return self.parentCtx:getCanvasIndex() == 1 and 2 or 1
|
return self.parentCtx:getCanvasIndex() == 1 and 2 or 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user