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