1
0
mirror of https://github.com/veden/Rampant.git synced 2025-03-17 20:58:35 +02:00

potential optimization

This commit is contained in:
Aaron Veden 2017-05-19 01:14:04 -07:00
parent e8251eec86
commit f21a294696
3 changed files with 8 additions and 17 deletions

View File

@ -144,28 +144,21 @@ function mapUtils.getCardinalChunksWithDirection(regionMap, chunkX, chunkY)
end
function mapUtils.getCardinalChunks(regionMap, chunkX, chunkY)
local neighbors = {1,2,3,4}
local neighbors = {0,0,0,0}
local xChunks = regionMap[chunkX]
if (xChunks ~= nil) then
neighbors[1] = xChunks[chunkY-1]
neighbors[4] = xChunks[chunkY+1]
else
neighbors[1] = nil
neighbors[4] = nil
end
xChunks = regionMap[chunkX-1]
if (xChunks ~= nil) then
neighbors[2] = xChunks[chunkY]
else
neighbors[2] = nil
end
xChunks = regionMap[chunkX+1]
if (xChunks ~= nil) then
neighbors[3] = xChunks[chunkY]
else
neighbors[3] = nil
end
return neighbors
end

View File

@ -68,13 +68,13 @@ function pheromoneUtils.processPheromone(regionMap, chunk)
local totalBase = 0
local totalPlayer = 0
local neighbors = getCardinalChunks(regionMap, chunk.cX, chunk.cY)
for i=1,#neighbors do
local neighborChunk = neighbors[i]
if (neighborChunk ~= nil) then
totalMovement = totalMovement + (neighborChunk[MOVEMENT_PHEROMONE] - chunk[MOVEMENT_PHEROMONE])
totalBase = totalBase + (neighborChunk[BASE_PHEROMONE] - chunk[BASE_PHEROMONE])
totalPlayer = totalPlayer + (neighborChunk[PLAYER_PHEROMONE] - chunk[PLAYER_PHEROMONE])
end
for i=1,4 do
local neighborChunk = neighbors[i]
if neighborChunk and (neighborChunk ~= 0) then
totalMovement = totalMovement + (neighborChunk[MOVEMENT_PHEROMONE] - chunk[MOVEMENT_PHEROMONE])
totalBase = totalBase + (neighborChunk[BASE_PHEROMONE] - chunk[BASE_PHEROMONE])
totalPlayer = totalPlayer + (neighborChunk[PLAYER_PHEROMONE] - chunk[PLAYER_PHEROMONE])
end
end
chunk[MOVEMENT_PHEROMONE] = (chunk[MOVEMENT_PHEROMONE] + (0.125 * totalMovement)) * MOVEMENT_PHEROMONE_PERSISTANCE
chunk[BASE_PHEROMONE] = (chunk[BASE_PHEROMONE] + (0.25 * totalBase)) * BASE_PHEROMONE_PERSISTANCE

View File

@ -27,7 +27,6 @@
(string->path "control.lua")
(string->path "config.lua")
(string->path "data.lua")
(string->path "upgrade.lua")
(string->path "data-updates.lua")
(string->path "LICENSE.md")
(string->path "tests.lua")
@ -66,7 +65,6 @@
(copyFile "config.lua" modFolder)
(copyFile "info.json" modFolder)
(copyFile "data.lua" modFolder)
(copyFile "upgrade.lua" modFolder)
(copyFile "data-updates.lua" modFolder)
(copyFile "settings.lua" modFolder)
(copyFile "Upgrade.lua" modFolder)