mirror of
https://github.com/veden/Rampant.git
synced 2025-03-17 20:58:35 +02:00
optimized adding chunks to processQueue
This commit is contained in:
parent
320615c3a4
commit
89f3580887
@ -3,6 +3,7 @@ local upgrade = {}
|
||||
-- imports
|
||||
|
||||
local constants = require("libs/Constants")
|
||||
local mathUtils = require("libs/MathUtils")
|
||||
|
||||
-- constants
|
||||
|
||||
@ -26,6 +27,8 @@ local TRIPLE_CHUNK_SIZE = constants.TRIPLE_CHUNK_SIZE
|
||||
|
||||
-- imported functions
|
||||
|
||||
local euclideanDistancePoints = mathUtils.euclideanDistancePoints
|
||||
|
||||
-- module code
|
||||
|
||||
local function addCommandSet(queriesAndCommands)
|
||||
@ -424,6 +427,10 @@ function upgrade.attempt(universe)
|
||||
if (universe.maps) then
|
||||
for _,map in pairs(universe.maps) do
|
||||
map.pendingUpgrades = {}
|
||||
for i=1,#map.processQueue do
|
||||
local chunk = map.processQueue[i]
|
||||
map.processQueue[i].dOrgin = euclideanDistancePoints(chunk.x, chunk.y, 0, 0)
|
||||
end
|
||||
for _,base in pairs(map.bases) do
|
||||
base.mutations = 0
|
||||
end
|
||||
|
@ -9,6 +9,7 @@ Date: 23. 11. 2021
|
||||
- Readded regional bases going dormant in regards to upgrading structures to allow for a buildup of base points to upgrade larger structures like hives. DOES NOT EFFECT ATTACK WAVES.
|
||||
- Number of groups that can be active in aggressive AI state now scales with the number of active nests. Rougly for every 30 pollution covered nests you will get an additional attack group.
|
||||
- Optimized regional base upgrades so that the work is spread over many ticks reducing lag spikes
|
||||
- Optimized adding new chunks to the Rampant in-memory state map
|
||||
Tweaks:
|
||||
- Doubled the processing rate of regional faction bases with new enemies
|
||||
- Added a small chance (0.5%) that Hives can spawn outside resource patches (Thank you Dimm2101)
|
||||
|
@ -323,9 +323,6 @@ local function prepMap(surface)
|
||||
map.chunkToActiveNest = {}
|
||||
map.chunkToActiveRaidNest = {}
|
||||
|
||||
map.nextChunkSort = 0
|
||||
map.nextChunkSortTick = 0
|
||||
|
||||
map.pendingUpgradeIterator = nil
|
||||
map.squadIterator = nil
|
||||
map.regroupIterator = nil
|
||||
@ -382,7 +379,6 @@ local function prepMap(surface)
|
||||
-- queue all current chunks that wont be generated during play
|
||||
local tick = game.tick
|
||||
local position = {0,0}
|
||||
map.nextChunkSort = 0
|
||||
for chunk in surface.get_chunks() do
|
||||
local x = chunk.x
|
||||
local y = chunk.y
|
||||
|
@ -6,15 +6,12 @@ local chunkProcessor = {}
|
||||
-- imports
|
||||
|
||||
local chunkUtils = require("ChunkUtils")
|
||||
local mathUtils = require("MathUtils")
|
||||
local constants = require("Constants")
|
||||
|
||||
-- constants
|
||||
|
||||
local CHUNK_SIZE = constants.CHUNK_SIZE
|
||||
|
||||
local MAX_TICKS_BEFORE_SORT_CHUNKS = constants.MAX_TICKS_BEFORE_SORT_CHUNKS
|
||||
|
||||
-- imported functions
|
||||
|
||||
local mapScanEnemyChunk = chunkUtils.mapScanEnemyChunk
|
||||
@ -25,33 +22,29 @@ local createChunk = chunkUtils.createChunk
|
||||
local initialScan = chunkUtils.initialScan
|
||||
local chunkPassScan = chunkUtils.chunkPassScan
|
||||
|
||||
local euclideanDistanceNamed = mathUtils.euclideanDistanceNamed
|
||||
|
||||
local tSort = table.sort
|
||||
|
||||
local abs = math.abs
|
||||
local next = next
|
||||
local table_size = table_size
|
||||
|
||||
local tRemove = table.remove
|
||||
local tInsert = table.insert
|
||||
local mCeil = math.ceil
|
||||
|
||||
-- module code
|
||||
|
||||
local origin = {x=0,y=0}
|
||||
|
||||
local function sorter(a, b)
|
||||
local aDistance = euclideanDistanceNamed(a, origin)
|
||||
local bDistance = euclideanDistanceNamed(b, origin)
|
||||
|
||||
if (aDistance == bDistance) then
|
||||
if (a.x == b.x) then
|
||||
return (abs(a.y) < abs(b.y))
|
||||
else
|
||||
return (abs(a.x) < abs(b.x))
|
||||
local function findInsertionPoint(processQueue, chunk)
|
||||
local low = 1
|
||||
local high = #processQueue
|
||||
local pivot
|
||||
while (low <= high) do
|
||||
pivot = mCeil((low + high) * 0.5)
|
||||
local pivotChunk = processQueue[pivot]
|
||||
if (pivotChunk.dOrgin > chunk.dOrgin) then
|
||||
high = pivot - 1
|
||||
elseif (pivotChunk.dOrgin <= chunk.dOrgin) then
|
||||
low = pivot + 1
|
||||
end
|
||||
end
|
||||
|
||||
return (aDistance < bDistance)
|
||||
return low
|
||||
end
|
||||
|
||||
function chunkProcessor.processPendingChunks(map, tick, flush)
|
||||
@ -109,7 +102,11 @@ function chunkProcessor.processPendingChunks(map, tick, flush)
|
||||
|
||||
if (chunk ~= -1) then
|
||||
map[x][y] = chunk
|
||||
processQueue[#processQueue+1] = chunk
|
||||
tInsert(
|
||||
processQueue,
|
||||
findInsertionPoint(processQueue, chunk),
|
||||
chunk
|
||||
)
|
||||
end
|
||||
end
|
||||
local newEvent = next(pendingChunks, event)
|
||||
@ -118,15 +115,6 @@ function chunkProcessor.processPendingChunks(map, tick, flush)
|
||||
end
|
||||
end
|
||||
map.chunkProcessorIterator = event
|
||||
|
||||
if (#processQueue > map.nextChunkSort) or
|
||||
(((tick - map.nextChunkSortTick) > MAX_TICKS_BEFORE_SORT_CHUNKS) and
|
||||
((map.nextChunkSort - 150) < #processQueue))
|
||||
then
|
||||
map.nextChunkSort = #processQueue + 150
|
||||
map.nextChunkSortTick = tick
|
||||
tSort(processQueue, sorter)
|
||||
end
|
||||
end
|
||||
|
||||
function chunkProcessor.processScanChunks(map)
|
||||
|
@ -9,6 +9,7 @@ local baseUtils = require("BaseUtils")
|
||||
local constants = require("Constants")
|
||||
local mapUtils = require("MapUtils")
|
||||
local chunkPropertyUtils = require("ChunkPropertyUtils")
|
||||
local mathUtils = require("MathUtils")
|
||||
|
||||
-- constants
|
||||
|
||||
@ -73,6 +74,8 @@ local createBase = baseUtils.createBase
|
||||
|
||||
local upgradeEntity = baseUtils.upgradeEntity
|
||||
|
||||
local euclideanDistancePoints = mathUtils.euclideanDistancePoints
|
||||
|
||||
local getChunkBase = chunkPropertyUtils.getChunkBase
|
||||
local setChunkBase = chunkPropertyUtils.setChunkBase
|
||||
local setPassable = chunkPropertyUtils.setPassable
|
||||
@ -373,7 +376,8 @@ end
|
||||
function chunkUtils.createChunk(topX, topY)
|
||||
local chunk = {
|
||||
x = topX,
|
||||
y = topY
|
||||
y = topY,
|
||||
dOrgin = euclideanDistancePoints(topX, topY, 0, 0)
|
||||
}
|
||||
chunk[BASE_PHEROMONE] = 0
|
||||
chunk[PLAYER_PHEROMONE] = 0
|
||||
|
@ -60,21 +60,6 @@ constants.TICKS_A_MINUTE = constants.TICKS_A_SECOND * 60
|
||||
|
||||
constants.CHUNK_PASS_THRESHOLD = 0.2
|
||||
|
||||
-- constants.INTERVAL_PLAYER_PROCESS = 63
|
||||
-- constants.INTERVAL_MAP_PROCESS = 5
|
||||
-- constants.INTERVAL_MAP_STATIC_PROCESS = 11
|
||||
-- constants.INTERVAL_SCAN = 19
|
||||
-- constants.INTERVAL_CHUNK_PROCESS = 23
|
||||
-- constants.INTERVAL_LOGIC = 59
|
||||
-- constants.INTERVAL_TEMPERAMENT = 121
|
||||
-- constants.INTERVAL_SQUAD = 14
|
||||
-- constants.INTERVAL_NEST = 16
|
||||
-- constants.INTERVAL_PASS_SCAN = 29
|
||||
-- constants.INTERVAL_RESQUAD = 101
|
||||
-- constants.INTERVAL_SPAWNER = 19
|
||||
-- constants.INTERVAL_VICTORY = 10
|
||||
-- constants.INTERVAL_CLEANUP = 34
|
||||
|
||||
constants.COOLDOWN_RALLY = constants.TICKS_A_SECOND * 10
|
||||
constants.COOLDOWN_RETREAT = constants.TICKS_A_SECOND * 10
|
||||
|
||||
@ -111,8 +96,6 @@ constants.DIVISOR_DEATH_TRAIL_TABLE = { 0.75, 0.65, 0.55, 0.45, 0.35 }
|
||||
|
||||
-- ai
|
||||
|
||||
constants.MAX_TICKS_BEFORE_SORT_CHUNKS = 60 * 60 * 30 -- 1 tick = 1/60 sec * 60 = 1 second
|
||||
|
||||
constants.RESOURCE_MINIMUM_FORMATION_DELTA = 15
|
||||
|
||||
constants.MINIMUM_AI_POINTS = 400
|
||||
|
Loading…
x
Reference in New Issue
Block a user