Simple performance boost

Changed old, heavily inefficient grid-population function to index images from a table that is registered once, rather than recreating images every time a new frame is called. Massive performance boost.
master
Avicennia_g 2021-01-07 19:21:03 -08:00 committed by GitHub
parent 12e0bd2e12
commit 621b455181
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 3 deletions

View File

@ -4,7 +4,7 @@ function love.load()
love.filesystem.read("data.txt"):gsub("%d+", function(w) table.insert(rdata,tonumber(w)) end)
tdata = {}
layer = {}
floor = 0
floor = 1
color = {}
gsize = 256*4
scale = 1
@ -24,13 +24,16 @@ function love.load()
reg2 = {},
prep = function(x) return love.graphics.newImage("/textures/"..x..".png") end,
}
for k,v in pairs(img.reg)do
img.reg2[k] = img.prep(v)
end
-------------------------------------
function floor_adjust(x)
return x and floor + 1 < #rdata/256 and floor + 1 or not x and floor - 1 >= 0 and floor - 1 or floor
return x and floor + 1 < #rdata/gsize and floor + 1 or not x and floor - 1 >= 0 and floor - 1 or floor
end
function populate_layer()
for n = 1, gsize do -- Remember 0 and 1 offsets from front and end
layer[n] = img.prep(img.reg[rdata[n+(gsize*floor)]])
layer[n] = img.reg2[rdata[n+(gsize*floor)]]
end end
populate_layer()
-------------------------------------