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
editor_mode = false
TileCreateObjects()
end
end

View File

@ -115,7 +115,6 @@ end
function LevelReloadTiles()
LevelUpdateDimensions()
TileCreateObjects()
end
function LevelUpdateDimensions()
@ -245,7 +244,7 @@ function GridDisplay()
end
function TileOptimizeObjects()
logPrint("new optimization")
logPrint("Optimizing Objects...")
local unoptimized = 0
local isTileOptimized = {}
@ -263,25 +262,57 @@ function TileOptimizeObjects()
local light = TileData[LevelTiles[i][j].id].light
if type == "whole" and not isTileOptimized[i][j] then
isTileOptimized[i][j] = true
local n = 1
local check = true
while check do
check = false
if LevelTiles[i][j+n] ~= nil then
if TileData[LevelTiles[i][j+n].id] ~= nil then
local type_check = TileData[LevelTiles[i][j+n].id].type
if type_check == "whole" and not isTileOptimized[i][j+n] then
check = true
isTileOptimized[i][j+n] = true
n = n + 1
end
check = false
if LevelTiles[i][j+n] ~= nil
and TileData[LevelTiles[i][j+n].id] ~= nil
then
local type_check = TileData[LevelTiles[i][j+n].id].type
if type_check == "whole"
and not isTileOptimized[i][j+n]
then
check = true
isTileOptimized[i][j+n] = true
n = n + 1
end
end
end
logPrint("Group size: "..n)
unoptimized = unoptimized + n
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
logPrint("Group size: "..m.."x"..n)
unoptimized = unoptimized + m * n
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)
@ -289,7 +320,7 @@ function TileOptimizeObjects()
base_x,
base_y,
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)
end