1
0
mirror of https://github.com/veden/Rampant.git synced 2025-01-07 23:01:39 +02:00
Rampant/libs/ChunkProcessor.lua

73 lines
1.8 KiB
Lua
Raw Normal View History

local chunkProcessor = {}
-- imports
local chunkUtils = require("ChunkUtils")
2017-06-01 03:46:53 +02:00
local constants = require("Constants")
-- constants
local CHUNK_SIZE = constants.CHUNK_SIZE
2017-11-21 09:27:03 +02:00
local SENTINEL_IMPASSABLE_CHUNK = constants.SENTINEL_IMPASSABLE_CHUNK
-- imported functions
local remakeChunk = chunkUtils.remakeChunk
local createChunk = chunkUtils.createChunk
2016-08-21 23:48:55 +02:00
local checkChunkPassability = chunkUtils.checkChunkPassability
local scoreChunk = chunkUtils.scoreChunk
local registerChunkEnemies = chunkUtils.registerChunkEnemies
-- 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
2017-06-01 03:46:53 +02:00
local offset = {0, 0}
local areaBoundingBox = {false, offset}
local query = {area=areaBoundingBox,
force=false}
local vanillaAI = not natives.useCustomAI
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
end
end
end
return chunkProcessor