From 2582e85fc7a868c0e2740f8147cf1f7186cb987a Mon Sep 17 00:00:00 2001 From: Alan Burkes <18322232+aburkes@users.noreply.github.com> Date: Wed, 5 Feb 2025 12:34:02 -0800 Subject: [PATCH 1/2] added code to flatten chunks for infinite maps. Please note that I did not remove all code that works with chunks, but I set chunks to nil after copying the data so the majority of that code should never run. --- sti/init.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sti/init.lua b/sti/init.lua index 646a224..5250461 100644 --- a/sti/init.lua +++ b/sti/init.lua @@ -377,6 +377,20 @@ function Map:setTileData(layer) for _, chunk in ipairs(layer.chunks) do self:setTileData(chunk) end + + -- flatten chunks into single data table + local data = {} + for _, chunk in ipairs(layer.chunks) do + for row, column in ipairs(chunk.data) do + data[row + chunk.x] = {} + for k, v in ipairs(column) do + data[row][k + chunk.x] = v + end + end + end + layer.data = data + layer.chunks = nil + return end @@ -1746,3 +1760,5 @@ end -- @see Map.objects return setmetatable({}, STI) + + From 13a21b3021e763189c1c8e6c2f5b71f9475b490b Mon Sep 17 00:00:00 2001 From: Alan Burkes <18322232+aburkes@users.noreply.github.com> Date: Fri, 14 Feb 2025 18:16:27 -0800 Subject: [PATCH 2/2] I discovered another error where chunked maps might come up with errors if they have chunk rows that are do not have tiles in them, so I added an if statement that prevents it from crashing and returns the correct nil values. --- sti/init.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sti/init.lua b/sti/init.lua index 5250461..fa5cce9 100644 --- a/sti/init.lua +++ b/sti/init.lua @@ -612,9 +612,17 @@ function Map:set_batches(layer, chunk) -- NOTE: Cannot short circuit this since it is valid for tile to be assigned nil local tile if chunk then - tile = chunk.data[y][x] + if chunk.tile[y] then + tile = chunk.data[y][x] + else + tile = nil + end else - tile = layer.data[y][x] + if layer.data[y] then + tile = layer.data[y][x] + else + tile = nil + end end if tile then