2016-08-05 06:47:51 +02:00
|
|
|
local chunkProcessor = {}
|
|
|
|
|
2016-08-20 04:52:27 +02:00
|
|
|
-- imports
|
|
|
|
|
2016-08-05 06:47:51 +02:00
|
|
|
local chunkUtils = require("ChunkUtils")
|
2017-06-01 03:46:53 +02:00
|
|
|
local constants = require("Constants")
|
|
|
|
|
|
|
|
-- constants
|
|
|
|
|
|
|
|
local CHUNK_SIZE = constants.CHUNK_SIZE
|
2016-08-20 04:52:27 +02:00
|
|
|
|
2017-11-21 09:27:03 +02:00
|
|
|
local SENTINEL_IMPASSABLE_CHUNK = constants.SENTINEL_IMPASSABLE_CHUNK
|
|
|
|
|
2016-08-20 04:52:27 +02:00
|
|
|
-- imported functions
|
|
|
|
|
2017-07-01 06:36:23 +02:00
|
|
|
local remakeChunk = chunkUtils.remakeChunk
|
2016-08-20 04:52:27 +02:00
|
|
|
local createChunk = chunkUtils.createChunk
|
2016-08-21 23:48:55 +02:00
|
|
|
local checkChunkPassability = chunkUtils.checkChunkPassability
|
|
|
|
local scoreChunk = chunkUtils.scoreChunk
|
2017-06-15 07:08:13 +02:00
|
|
|
local registerChunkEnemies = chunkUtils.registerChunkEnemies
|
|
|
|
|
2016-08-20 04:52:27 +02:00
|
|
|
-- module code
|
|
|
|
|
2017-05-27 07:56:45 +02:00
|
|
|
function chunkProcessor.processPendingChunks(natives, regionMap, surface, pendingStack, tick)
|
2016-10-15 02:00:18 +02:00
|
|
|
local processQueue = regionMap.processQueue
|
2016-08-05 06:47:51 +02:00
|
|
|
|
2017-06-01 03:46:53 +02:00
|
|
|
local offset = {0, 0}
|
|
|
|
local areaBoundingBox = {false, offset}
|
|
|
|
local query = {area=areaBoundingBox,
|
|
|
|
force=false}
|
|
|
|
|
2017-06-16 03:30:26 +02:00
|
|
|
local vanillaAI = not natives.useCustomAI
|
2017-06-15 07:08:13 +02:00
|
|
|
|
2017-06-11 02:59:06 +02:00
|
|
|
local chunkTiles = regionMap.chunkTiles
|
|
|
|
|
2017-08-08 10:19:51 +02:00
|
|
|
for i=#pendingStack, 1, -1 do
|
2017-06-01 03:46:53 +02:00
|
|
|
local event = pendingStack[i]
|
|
|
|
pendingStack[i] = nil
|
|
|
|
|
2017-08-08 10:19:51 +02:00
|
|
|
local topLeft = event.area.left_top
|
|
|
|
local x = topLeft.x
|
|
|
|
local y = topLeft.y
|
2017-06-01 03:46:53 +02:00
|
|
|
local chunk = createChunk(x, y)
|
|
|
|
|
2017-11-21 09:27:03 +02:00
|
|
|
chunk = checkChunkPassability(chunkTiles, chunk, surface)
|
|
|
|
|
|
|
|
if (chunk ~= SENTINEL_IMPASSABLE_CHUNK) then
|
|
|
|
|
|
|
|
areaBoundingBox[1] = chunk
|
|
|
|
offset[1] = x + CHUNK_SIZE
|
|
|
|
offset[2] = y + CHUNK_SIZE
|
|
|
|
|
|
|
|
if vanillaAI then
|
|
|
|
registerChunkEnemies(regionMap, chunk, surface, query)
|
|
|
|
else
|
|
|
|
remakeChunk(regionMap, chunk, surface, natives, tick, query)
|
|
|
|
end
|
|
|
|
scoreChunk(regionMap, chunk, surface, natives, query)
|
|
|
|
|
|
|
|
local chunkX = chunk.x
|
|
|
|
|
|
|
|
if regionMap[chunkX] == nil then
|
|
|
|
regionMap[chunkX] = {}
|
|
|
|
end
|
|
|
|
regionMap[chunkX][chunk.y] = chunk
|
|
|
|
|
|
|
|
processQueue[#processQueue+1] = chunk
|
2017-06-15 07:08:13 +02:00
|
|
|
end
|
2016-08-05 06:47:51 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-30 06:08:22 +02:00
|
|
|
return chunkProcessor
|