1
0
mirror of https://github.com/veden/Rampant.git synced 2025-01-24 03:16:25 +02:00
Rampant/libs/ChunkProcessor.lua

65 lines
1.6 KiB
Lua
Raw Normal View History

local chunkProcessor = {}
-- imports
local chunkUtils = require("ChunkUtils")
2017-05-31 18:46:53 -07:00
local constants = require("Constants")
-- constants
local CHUNK_QUEUE_SIZE = constants.CHUNK_QUEUE_SIZE
2017-05-31 18:46:53 -07:00
local CHUNK_SIZE = constants.CHUNK_SIZE
-- imported functions
local createChunk = chunkUtils.createChunk
2016-08-21 14:48:55 -07:00
local checkChunkPassability = chunkUtils.checkChunkPassability
local scoreChunk = chunkUtils.scoreChunk
local registerChunkEnemies = chunkUtils.registerChunkEnemies
-- 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
2017-05-31 18:46:53 -07:00
local offset = {0, 0}
local areaBoundingBox = {false, offset}
local query = {area=areaBoundingBox,
force=false}
local vanillaAI = not natives.useCustomAI
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
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)
if vanillaAI then
registerChunkEnemies(chunk, surface, query)
end
scoreChunk(chunk, surface, natives, query)
processQueue[#processQueue+1] = chunk
end
end
return chunkProcessor