1
0
mirror of https://github.com/veden/Rampant.git synced 2025-09-16 09:16:43 +02:00

FACTO-257: Removed unneeded iterators

This commit is contained in:
Aaron Veden
2023-03-11 18:14:42 -08:00
parent 1b2d7da3ea
commit a7cdf98ce2
9 changed files with 193 additions and 347 deletions

View File

@@ -61,6 +61,7 @@ Version: 3.2.0
- Centralized base points manipulation and chat messaging (Dagothur)
- Base point deductions for unit losses are now batched in 20 to reduce chat spam when using the print AI points to chat options (Dagothur)
- Reduced corpse and particle variation to optimize increased entity times due to high entity counts
- Removed unneeded iterators
- Moved map properties directly into chunk object
---------------------------------------------------------------------------------------------------

View File

@@ -576,12 +576,7 @@ local function processSurfaceTile(map, position, chunks, tick)
local chunk = getChunkByPosition(map, position)
if (chunk ~= -1) then
if not map.Universe.chunkToPassScan[chunk.id] then
map.Universe.chunkToPassScan[chunk.id] = {
map=map,
chunk=chunk
}
end
Universe.chunkToPassScan[chunk.id] = chunk
else
local x,y = positionToChunkXY(position)
local addMe = true
@@ -1015,11 +1010,9 @@ local function onBuilderArrived(event)
game.print(map.surface.name.." Settled: [gps=" .. builder.position.x .. "," .. builder.position.y .."]")
end
if Universe.enabledPurpleSettlerCloud then
local len = Universe.settlePurpleCloud.len + 1
Universe.settlePurpleCloud.len = len
Universe.settlePurpleCloud[len] = {
Universe.eventId = Universe.eventId + 1
Universe.settlePurpleCloud[Universe.eventId] = {
map = map,
position = builder.position,
group = builder,
tick = event.tick + SETTLE_CLOUD_WARMUP
}

View File

@@ -193,16 +193,7 @@ function aiAttackWave.rallyUnits(chunk, tick, base)
if (x ~= cX) and (y ~= cY) then
local rallyChunk = getChunkByXY(map, x, y)
if (rallyChunk ~= -1) and rallyChunk.nestCount then
local pack = vengenceQueue[rallyChunk.id]
if not pack then
pack = {
v = 0,
map = map,
base = base
}
vengenceQueue[rallyChunk.id] = pack
end
pack.v = pack.v + 1
vengenceQueue[rallyChunk.id] = rallyChunk
end
end
end

View File

@@ -65,37 +65,28 @@ local tInsert = table.insert
function ChunkProcessor.processPendingChunks(tick, flush)
local pendingChunks = Universe.pendingChunks
local eventId = Universe.chunkProcessorIterator
local event
local eventId, event = next(pendingChunks, nil)
if not eventId then
eventId, event = next(pendingChunks, nil)
else
event = pendingChunks[eventId]
end
local endCount = 1
if flush then
endCount = table_size(pendingChunks)
eventId, event = next(pendingChunks, nil)
end
for _=1,endCount do
if not eventId then
Universe.chunkProcessorIterator = nil
if (table_size(pendingChunks) == 0) then
if (tableSize(pendingChunks) == 0) then
-- this is needed as the next command remembers the max length a table has been
Universe.pendingChunks = {}
end
break
else
return
end
local endCount = 1
if flush then
endCount = tableSize(pendingChunks)
end
for _=1,endCount do
if not flush and (event.tick > tick) then
Universe.chunkProcessorIterator = eventId
return
end
local newEventId, newEvent = next(pendingChunks, eventId)
pendingChunks[eventId] = nil
local map = event.map
if not map.surface.valid then
Universe.chunkProcessorIterator = newEventId
return
end
@@ -132,28 +123,24 @@ function ChunkProcessor.processPendingChunks(tick, flush)
eventId = newEventId
event = newEvent
if not eventId then
return
end
end
Universe.chunkProcessorIterator = eventId
end
function ChunkProcessor.processPendingUpgrades(tick)
local entityId = Universe.pendingUpgradeIterator
local entityData
local entityId, entityData = next(Universe.pendingUpgrades, nil)
if not entityId then
entityId, entityData = next(Universe.pendingUpgrades, nil)
else
entityData = Universe.pendingUpgrades[entityId]
end
if not entityId then
Universe.pendingUpgradeIterator = nil
if table_size(Universe.pendingUpgrades) == 0 then
if tableSize(Universe.pendingUpgrades) == 0 then
Universe.pendingUpgrades = {}
end
else
return
end
local entity = entityData.entity
if entity.valid then
Universe.pendingUpgradeIterator = next(Universe.pendingUpgrades, entityId)
if not entity.valid then
Universe.pendingUpgrades[entityId] = nil
end
if entityData.delayTLL and tick < entityData.delayTLL then
return
end
@@ -222,43 +209,29 @@ function ChunkProcessor.processPendingUpgrades(tick)
remote.call("kr-creep", "spawn_creep_at_position", surface, foundPosition or position, false, createdEntity.name)
end
end
else
Universe.pendingUpgradeIterator = next(Universe.pendingUpgrades, entityId)
Universe.pendingUpgrades[entityId] = nil
end
end
end
function ChunkProcessor.processScanChunks()
local chunkId = Universe.chunkToPassScanIterator
local chunkPack
local chunkId, chunk = next(Universe.chunkToPassScan, nil)
if not chunkId then
chunkId, chunkPack = next(Universe.chunkToPassScan, nil)
else
chunkPack = Universe.chunkToPassScan[chunkId]
end
if not chunkId then
Universe.chunkToPassScanIterator = nil
if (table_size(Universe.chunkToPassScan) == 0) then
if (tableSize(Universe.chunkToPassScan) == 0) then
-- this is needed as the next command remembers the max length a table has been
Universe.chunkToPassScan = {}
end
else
Universe.chunkToPassScanIterator = next(Universe.chunkToPassScan, chunkId)
return
end
Universe.chunkToPassScan[chunkId] = nil
local map = chunkPack.map
local map = chunk.map
if not map.surface.valid then
return
end
local chunk = chunkPack.chunk
if (chunkPassScan(chunk, map) == -1) then
removeChunkFromMap(map, chunk)
end
end
end
function ChunkProcessor.init(universe)
Universe = universe

View File

@@ -409,11 +409,8 @@ function ChunkUtils.entityForPassScan(map, entity)
for i=1,#overlapArray do
local chunk = overlapArray[i]
if (chunk ~= -1) and not map.Universe.chunkToPassScan[chunk.id] then
map.Universe.chunkToPassScan[chunk.id] = {
map = map,
chunk = chunk
}
if (chunk ~= -1) then
Universe.chunkToPassScan[chunk.id] = chunk
end
end
end

View File

@@ -207,16 +207,7 @@ function MapProcessor.processPlayers(players, tick)
processNestActiveness(chunk, tick)
if vengence then
local pack = Universe.vengenceQueue[chunk.id]
if not pack then
pack = {
v = 0,
map = map,
base = base
}
Universe.vengenceQueue[chunk.id] = pack
end
pack.v = pack.v + 1
Universe.vengenceQueue[chunk.id] = chunk
end
end
end
@@ -228,23 +219,15 @@ function MapProcessor.processPlayers(players, tick)
end
end
local function processCleanUp(chunks, iterator, tick, duration)
local chunkId = Universe[iterator]
local eventTick
local function processCleanUp(chunks, tick, duration)
local chunkId, eventTick = next(chunks, nil)
if not chunkId then
chunkId, eventTick = next(chunks, nil)
else
eventTick = chunks[chunkId]
return
end
if not chunkId then
Universe[iterator] = nil
else
Universe[iterator] = next(chunks, chunkId)
if (tick - eventTick) > duration then
chunks[chunkId] = nil
end
end
end
function MapProcessor.cleanUpMapTables(tick)
local retreats = Universe.chunkToRetreats
@@ -252,11 +235,11 @@ function MapProcessor.cleanUpMapTables(tick)
local drained = Universe.chunkToDrained
for _=1,CLEANUP_QUEUE_SIZE do
processCleanUp(retreats, "chunkToRetreatIterator", tick, COOLDOWN_RETREAT)
processCleanUp(retreats, tick, COOLDOWN_RETREAT)
processCleanUp(rallys, "chunkToRallyIterator", tick, COOLDOWN_RALLY)
processCleanUp(rallys, tick, COOLDOWN_RALLY)
processCleanUp(drained, "chunkToDrainedIterator", tick, COOLDOWN_DRAIN)
processCleanUp(drained, tick, COOLDOWN_DRAIN)
end
end
@@ -292,10 +275,6 @@ function MapProcessor.scanPlayerMap(map, tick)
end
function MapProcessor.scanEnemyMap(map, tick)
if (map.nextProcessMap == tick) or (map.nextPlayerScan == tick) or (map.nextChunkProcess == tick) then
return
end
local index = map.scanEnemyIndex
local processQueue = map.processQueue
@@ -319,11 +298,6 @@ function MapProcessor.scanEnemyMap(map, tick)
end
function MapProcessor.scanResourceMap(map, tick)
if (map.nextProcessMap == tick) or (map.nextPlayerScan == tick) or
(map.nextEnemyScan == tick) or (map.nextChunkProcess == tick)
then
return
end
local index = map.scanResourceIndex
local processQueue = map.processQueue
@@ -348,32 +322,24 @@ end
function MapProcessor.processVengence()
local vengenceQueue = Universe.vengenceQueue
local chunkId = Universe.deployVengenceIterator
local vengencePack
local chunkId, chunk = next(vengenceQueue, nil)
if not chunkId then
chunkId, vengencePack = next(vengenceQueue, nil)
else
vengencePack = vengenceQueue[chunkId]
end
if not chunkId then
Universe.deployVengenceIterator = nil
if (tableSize(vengenceQueue) == 0) then
Universe.vengenceQueue = {}
end
else
Universe.deployVengenceIterator = next(vengenceQueue, chunkId)
return
end
vengenceQueue[chunkId] = nil
local map = vengencePack.map
local map = chunk.map
if not map.surface.valid then
return
end
local chunk = getChunkById(chunkId)
local base = vengencePack.base
local base = chunk.base
if canMigrate(map, base) and (Universe.random() < 0.075) then
formVengenceSettler(map, chunk, base)
formVengenceSettler(chunk, base)
else
formVengenceSquad(map, chunk, base)
end
formVengenceSquad(chunk, base)
end
end
@@ -448,10 +414,10 @@ local function processSpawnersBody(iterator, chunks)
local migrate = canMigrate(map, base)
local attack = canAttack(map, base)
if migrate then
formSettlers(map, chunk, base)
formSettlers(chunk, base)
end
if attack then
formSquads(map, chunk, base)
formSquads(chunk, base)
end
end
end
@@ -466,16 +432,14 @@ function MapProcessor.processAttackWaves()
end
function MapProcessor.processClouds(tick)
local len = Universe.settlePurpleCloud.len
local builderPack = Universe.settlePurpleCloud[len]
local eventId, builderPack = next(Universe.settlePurpleCloud, nil)
if builderPack and (builderPack.tick <= tick) then
Universe.settlePurpleCloud[len] = nil
Universe.settlePurpleCloud.len = len - 1
Universe.settlePurpleCloud[eventId] = nil
local map = builderPack.map
if builderPack.group.valid and map.surface.valid then
setPositionInQuery(
Universe.obaCreateBuildCloudQuery,
builderPack.position
builderPack.group.position
)
map.surface.create_entity(Universe.obaCreateBuildCloudQuery)
end

View File

@@ -82,10 +82,10 @@ function MapUtils.queueGeneratedChunk(event)
return
end
event.tick = (event.tick or game.tick) + 20
Universe.eventId = Universe.eventId + 1
event.id = Universe.eventId
event.map = map
Universe.pendingChunks[event.id] = event
Universe.eventId = Universe.eventId + 1
end
function MapUtils.nextMap()
@@ -155,6 +155,9 @@ function MapUtils.removeChunkFromMap(map, chunk)
Universe.chunkToRallys[chunkId] = nil
Universe.chunkToPassScan[chunkId] = nil
Universe.chunkToNests[chunkId] = nil
Universe.chunkToTurrets[chunkId] = nil
Universe.chunkToUtilities[chunkId] = nil
Universe.chunkToHives[chunkId] = nil
Universe.vengenceQueue[chunkId] = nil
Universe.processActiveNest[chunkId] = nil
Universe.chunkToVictory[chunkId] = nil
@@ -163,44 +166,13 @@ function MapUtils.removeChunkFromMap(map, chunk)
base.chunkCount = base.chunkCount - 1
map.chunkToBase[chunkId] = nil
end
map.chunkToTurrets[chunkId] = nil
map.chunkToTraps[chunkId] = nil
map.chunkToUtilities[chunkId] = nil
map.chunkToHives[chunkId] = nil
map.chunkToNestIds[chunkId] = nil
map.chunkToHiveIds[chunkId] = nil
map.chunkToTrapIds[chunkId] = nil
map.chunkToTurretIds[chunkId] = nil
map.chunkToUtilityIds[chunkId] = nil
map.chunkToPlayerBase[chunkId] = nil
map.chunkToResource[chunkId] = nil
map.chunkToPlayerCount[chunkId] = nil
map.chunkToSquad[chunkId] = nil
map.chunkToPassable[chunkId] = nil
map.chunkToPathRating[chunkId] = nil
map.chunkToDeathGenerator[chunkId] = nil
if Universe.processActiveNestIterator == chunkId then
Universe.processActiveNestIterator = nil
end
if Universe.victoryScentIterator == chunkId then
Universe.victoryScentIterator = nil
end
if Universe.processNestIterator == chunkId then
Universe.processNestIterator = nil
end
if Universe.chunkToDrainedIterator == chunkId then
Universe.chunkToDrainedIterator = nil
end
if Universe.chunkToRetreatIterator == chunkId then
Universe.chunkToRetreatIterator = nil
end
if Universe.chunkToRallyIterator == chunkId then
Universe.chunkToRallyIterator = nil
end
if Universe.chunkToPassScanIterator == chunkId then
Universe.chunkToPassScanIterator = nil
end
if Universe.processActiveSpawnerIterator == chunkId then
Universe.processActiveSpawnerIterator = nil
end
@@ -210,9 +182,6 @@ function MapUtils.removeChunkFromMap(map, chunk)
if Universe.processMigrationIterator == chunkId then
Universe.processMigrationIterator = nil
end
if Universe.deployVengenceIterator == chunkId then
Universe.deployVengenceIterator = nil
end
end
--[[

View File

@@ -78,32 +78,26 @@ local mMax = math.max
-- module code
function PheromoneUtils.victoryScent(map, chunk, entityType)
function PheromoneUtils.victoryScent(chunk, entityType)
local value = VICTORY_SCENT[entityType]
if value then
addVictoryGenerator(map, chunk, value)
addVictoryGenerator(chunk, value)
end
end
function PheromoneUtils.disperseVictoryScent()
local chunkId = Universe.victoryScentIterator
local chunkToVictory = Universe.chunkToVictory
local pheromonePack
local chunkId, pheromonePack = next(chunkToVictory, nil)
if not chunkId then
chunkId, pheromonePack = next(chunkToVictory, nil)
else
pheromonePack = chunkToVictory[chunkId]
return
end
if not chunkId then
Universe.victoryScentIterator = nil
else
Universe.victoryScentIterator = next(chunkToVictory, chunkId)
chunkToVictory[chunkId] = nil
local map = pheromonePack.map
local chunk = pheromonePack.chunk
local map = chunk.map
if not map.surface.valid then
return
end
local chunk = getChunkById(chunkId)
local chunkX = chunk.x
local chunkY = chunk.y
local i = 1
@@ -119,9 +113,8 @@ function PheromoneUtils.disperseVictoryScent()
end
end
end
end
function PheromoneUtils.deathScent(map, chunk, structure)
function PheromoneUtils.deathScent(chunk, structure)
local amount = -DEATH_PHEROMONE_GENERATOR_AMOUNT
if structure then
amount = -TEN_DEATH_PHEROMONE_GENERATOR_AMOUNT

View File

@@ -518,9 +518,6 @@ function Upgrade.addUniverseProperties()
Universe.pendingChunks = {}
Universe.processActiveNest = {}
Universe.processActiveNestIterator = nil
Universe.deployVengenceIterator = nil
Universe.pendingUpgradeIterator = nil
Universe.victoryScentIterator = nil
Universe.squadIterator = nil
Universe.processMapAIIterator = nil
Universe.processNestIterator = nil
@@ -535,16 +532,12 @@ function Upgrade.addUniverseProperties()
Universe.processActiveSpawnerIterator = nil
Universe.processActiveRaidSpawnerIterator = nil
Universe.processMigrationIterator = nil
Universe.chunkToDrainedIterator = nil
Universe.chunkToActiveNest = {}
Universe.chunkToActiveRaidNest = {}
Universe.chunkToDrained = {}
Universe.chunkToRetreatIterator = nil
Universe.chunkToRetreats = {}
Universe.chunkToRallyIterator = nil
Universe.chunkToRallys = {}
Universe.chunkToPassScan = {}
Universe.chunkToPassScanIterator = nil
Universe.baseId = 0
Universe.awake = false
@@ -573,7 +566,6 @@ function Upgrade.addUniverseProperties()
Universe.pendingUpgrades = {}
Universe.settlePurpleCloud = {}
Universe.settlePurpleCloud.len = 0
end
end
@@ -674,45 +666,18 @@ function Upgrade.prepMap(surface)
map.scanPlayerIndex = 1
map.scanResourceIndex = 1
map.scanEnemyIndex = 1
map.processStaticIndex = 1
map.outgoingScanWave = true
map.outgoingStaticScanWave = true
map.chunkToBase = {}
map.chunkToTurrets = {}
map.chunkToTraps = {}
map.chunkToUtilities = {}
map.chunkToHives = {}
map.chunkToNestIds = {}
map.chunkToHiveIds = {}
map.chunkToTrapIds = {}
map.chunkToTurretIds = {}
map.chunkToUtilityIds = {}
map.drainPylons = {}
map.chunkToPlayerBase = {}
map.chunkToResource = {}
map.chunkToPlayerCount = {}
map.playerToChunk = {}
map.chunkToSquad = {}
map.chunkToPassable = {}
map.chunkToPathRating = {}
map.chunkToDeathGenerator = {}
map.chunkToPermanentDeathGenerator = {}
map.chunkToPlayerGenerator = {}
map.chunkScanCounts = {}
map.emptySquadsOnChunk = {}
map.surface = surface
map.bases = {}
map.squads = nil
map.pendingAttack = nil
map.building = nil
-- queue all current chunks that wont be generated during play
local tick = game.tick