1
0
mirror of https://github.com/veden/Rampant.git synced 2025-01-03 22:52:20 +02:00
Rampant/libs/ChunkProcessor.lua
2016-10-14 17:01:56 -07:00

38 lines
989 B
Lua

local chunkProcessor = {}
-- imports
local chunkUtils = require("ChunkUtils")
-- imported functions
local createChunk = chunkUtils.createChunk
local checkChunkPassability = chunkUtils.checkChunkPassability
local scoreChunk = chunkUtils.scoreChunk
-- module code
function chunkProcessor.processPendingChunks(regionMap, surface, pendingStack)
local processQueue = regionMap.processQueue
for _=#pendingStack, 1, -1 do
local event = pendingStack[#pendingStack]
pendingStack[#pendingStack] = nil
local chunk = createChunk(event.area.left_top.x, event.area.left_top.y)
local chunkX = chunk.cX
if regionMap[chunkX] == nil then
regionMap[chunkX] = {}
end
regionMap[chunkX][chunk.cY] = chunk
checkChunkPassability(chunk, surface)
scoreChunk(chunk, surface)
processQueue[#processQueue+1] = chunk
end
end
return chunkProcessor