Two dimensional optimization, yay

This commit is contained in:
lustlion 2022-02-07 12:07:57 +01:00
parent 3f5cc2e111
commit a899e40c73
2 changed files with 46 additions and 14 deletions

View File

@ -57,6 +57,7 @@ function EditorStep()
if Keybind:HasPressed(Keybind.debug.editor) then if Keybind:HasPressed(Keybind.debug.editor) then
editor_mode = false editor_mode = false
TileCreateObjects()
end end
end end

View File

@ -115,7 +115,6 @@ end
function LevelReloadTiles() function LevelReloadTiles()
LevelUpdateDimensions() LevelUpdateDimensions()
TileCreateObjects()
end end
function LevelUpdateDimensions() function LevelUpdateDimensions()
@ -245,7 +244,7 @@ function GridDisplay()
end end
function TileOptimizeObjects() function TileOptimizeObjects()
logPrint("new optimization") logPrint("Optimizing Objects...")
local unoptimized = 0 local unoptimized = 0
local isTileOptimized = {} local isTileOptimized = {}
@ -263,25 +262,57 @@ function TileOptimizeObjects()
local light = TileData[LevelTiles[i][j].id].light local light = TileData[LevelTiles[i][j].id].light
if type == "whole" and not isTileOptimized[i][j] then if type == "whole" and not isTileOptimized[i][j] then
isTileOptimized[i][j] = true isTileOptimized[i][j] = true
local n = 1 local n = 1
local check = true local check = true
while check do while check do
check = false check = false
if LevelTiles[i][j+n] ~= nil then if LevelTiles[i][j+n] ~= nil
if TileData[LevelTiles[i][j+n].id] ~= nil then and TileData[LevelTiles[i][j+n].id] ~= nil
then
local type_check = TileData[LevelTiles[i][j+n].id].type local type_check = TileData[LevelTiles[i][j+n].id].type
if type_check == "whole" and not isTileOptimized[i][j+n] then if type_check == "whole"
and not isTileOptimized[i][j+n]
then
check = true check = true
isTileOptimized[i][j+n] = true isTileOptimized[i][j+n] = true
n = n + 1 n = n + 1
end end
end end
end end
local m = 1
local check = true
while check do
check = false
local checkline = true
for l = 0, n-1 do
checkline = false
if LevelTiles[i+m] ~= nil
and LevelTiles[i+m][j+l] ~= nil
and TileData[LevelTiles[i+m][j+l].id] ~= nil
then
local type_check = TileData[LevelTiles[i+m][j+l].id].type
if type_check == "whole"
and not isTileOptimized[i+m][j+n]
then
checkline = true
end
end
end
if checkline then
check = true
for l = 0, n-1 do
isTileOptimized[i+m][j+l] = true
end
m = m + 1
end
end end
logPrint("Group size: "..n) logPrint("Group size: "..m.."x"..n)
unoptimized = unoptimized + n unoptimized = unoptimized + m * n
local base_x = tileProperties.scale * j * tileProperties.width + tileProperties.scale * (levelProperties.offset.x - tileProperties.height) local base_x = tileProperties.scale * j * tileProperties.width + tileProperties.scale * (levelProperties.offset.x - tileProperties.height)
local base_y = tileProperties.scale * i * tileProperties.height + tileProperties.scale * (levelProperties.offset.y - tileProperties.height) local base_y = tileProperties.scale * i * tileProperties.height + tileProperties.scale * (levelProperties.offset.y - tileProperties.height)
@ -289,7 +320,7 @@ function TileOptimizeObjects()
base_x, base_x,
base_y, base_y,
base_x + tileProperties.width * tileProperties.scale * n, base_x + tileProperties.width * tileProperties.scale * n,
base_y + tileProperties.height * tileProperties.scale base_y + tileProperties.height * tileProperties.scale * m
) )
table.insert(LoadedObjects.Collisions,col) table.insert(LoadedObjects.Collisions,col)
end end