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

corrected typos in chunkProcessing and added one final table sort in upgrade

This commit is contained in:
Aaron Veden 2021-11-26 10:31:15 -08:00
parent 9429fb4516
commit 76dde8d8b6
No known key found for this signature in database
GPG Key ID: FF5990B1C6DD3F84
3 changed files with 20 additions and 4 deletions

View File

@ -29,8 +29,23 @@ local TRIPLE_CHUNK_SIZE = constants.TRIPLE_CHUNK_SIZE
local euclideanDistancePoints = mathUtils.euclideanDistancePoints
local mAbs = math.abs
local tSort = table.sort
-- module code
local function sorter(a, b)
if (a.dOrigin == b.dOrigin) then
if (a.x == b.x) then
return (mAbs(a.y) < mAbs(b.y))
else
return (mAbs(a.x) < mAbs(b.x))
end
end
return (a.dOrigin < b.dOrigin)
end
local function addCommandSet(queriesAndCommands)
-- preallocating memory to be used in code, making it fast by reducing garbage generated.
queriesAndCommands.neighbors = {
@ -429,8 +444,9 @@ function upgrade.attempt(universe)
map.pendingUpgrades = {}
for i=1,#map.processQueue do
local chunk = map.processQueue[i]
map.processQueue[i].dOrgin = euclideanDistancePoints(chunk.x, chunk.y, 0, 0)
map.processQueue[i].dOrigin = euclideanDistancePoints(chunk.x, chunk.y, 0, 0)
end
tSort(map.processQueue, sorter)
for _,base in pairs(map.bases) do
base.mutations = 0
end

View File

@ -38,9 +38,9 @@ local function findInsertionPoint(processQueue, chunk)
while (low <= high) do
pivot = mCeil((low + high) * 0.5)
local pivotChunk = processQueue[pivot]
if (pivotChunk.dOrgin > chunk.dOrgin) then
if (pivotChunk.dOrigin > chunk.dOrigin) then
high = pivot - 1
elseif (pivotChunk.dOrgin <= chunk.dOrgin) then
elseif (pivotChunk.dOrigin <= chunk.dOrigin) then
low = pivot + 1
end
end

View File

@ -377,7 +377,7 @@ function chunkUtils.createChunk(topX, topY)
local chunk = {
x = topX,
y = topY,
dOrgin = euclideanDistancePoints(topX, topY, 0, 0)
dOrigin = euclideanDistancePoints(topX, topY, 0, 0)
}
chunk[BASE_PHEROMONE] = 0
chunk[PLAYER_PHEROMONE] = 0