atlas groundwork
This commit is contained in:
parent
a46d9e68ab
commit
8e7423fc86
4
conf.lua
4
conf.lua
@ -1,7 +1,9 @@
|
|||||||
return {
|
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
|
AUTO_RUN = true, --Replaces the default love.run
|
||||||
DEBUG = true, --Reserved for later
|
DEBUG = true, --Reserved for later
|
||||||
PURE_G = true, --whether to keep _G pure
|
PURE_G = true, --whether to keep _G pure
|
||||||
HARD_ERROR = true, --Whether to display element errors inside or hard cras
|
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)
|
||||||
}
|
}
|
||||||
82
core/atlas.lua
Normal file
82
core/atlas.lua
Normal file
@ -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
|
||||||
@ -104,7 +104,7 @@ end
|
|||||||
local childrenNum = 5
|
local childrenNum = 5
|
||||||
local selfRenderTime = false
|
local selfRenderTime = false
|
||||||
local screenSize = 1/50
|
local screenSize = 1/50
|
||||||
local coefficient = 1.5
|
local coefficient = 1000000
|
||||||
|
|
||||||
function element.setBench(time)
|
function element.setBench(time)
|
||||||
selfRenderTime = time
|
selfRenderTime = time
|
||||||
@ -260,6 +260,7 @@ function element:externalRender()
|
|||||||
if self.settings.hasCanvas then
|
if self.settings.hasCanvas then
|
||||||
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)
|
||||||
love.graphics.rectangle('line', 1, 1, self.view.w-1, self.view.h-1)
|
love.graphics.rectangle('line', 1, 1, self.view.w-1, self.view.h-1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
7
init.lua
7
init.lua
@ -32,7 +32,7 @@ function helium.render()
|
|||||||
|
|
||||||
local startTime = love.timer.getTime()
|
local startTime = love.timer.getTime()
|
||||||
for i = 1, 20 do
|
for i = 1, 20 do
|
||||||
love.graphics.print(i)
|
love.graphics.print(i,-100,-100)
|
||||||
end
|
end
|
||||||
helium.element.setBench((love.timer.getTime()-startTime)/9)
|
helium.element.setBench((love.timer.getTime()-startTime)/9)
|
||||||
|
|
||||||
@ -117,14 +117,19 @@ if helium.conf.AUTO_RUN then
|
|||||||
|
|
||||||
-- Call update and draw
|
-- Call update and draw
|
||||||
if love.update then love.update(dt) end -- will pass 0 if love.timer is disabled
|
if love.update then love.update(dt) end -- will pass 0 if love.timer is disabled
|
||||||
|
local st = love.timer.getTime()
|
||||||
helium.update(dt)
|
helium.update(dt)
|
||||||
|
heliumTime = love.timer.getTime()-st
|
||||||
|
|
||||||
if love.graphics and love.graphics.isActive() then
|
if love.graphics and love.graphics.isActive() then
|
||||||
love.graphics.origin()
|
love.graphics.origin()
|
||||||
love.graphics.clear(love.graphics.getBackgroundColor())
|
love.graphics.clear(love.graphics.getBackgroundColor())
|
||||||
|
|
||||||
if love.draw then love.draw() end
|
if love.draw then love.draw() end
|
||||||
|
|
||||||
|
st = love.timer.getTime()
|
||||||
helium.render()
|
helium.render()
|
||||||
|
heliumTime=heliumTime+love.timer.getTime()-st
|
||||||
|
|
||||||
love.graphics.present()
|
love.graphics.present()
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user