Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/maps/random/rmgen/math.js
Context not available. | |||||
return order; | return order; | ||||
} | } | ||||
/** | |||||
* Flood fill algorithm to verify if all the points are connected against the given list of tileClass | |||||
*/ | |||||
function areConnected(points, tileClasses) | |||||
{ | |||||
let connectionArray = new Uint8Array(mapSize*mapSize).fill(0); | |||||
lyv: These arrays should be avoided if the typed versions could be used. These generic ones also… | |||||
Done Inline ActionsActually, needing true/false was a relic from when I didn't use early stop when all connections were reached. Now we just need 0 = unvisited and 1 = visited Feldfeld: Actually, needing true/false was a relic from when I didn't use early stop when all connections… | |||||
Not Done Inline ActionsAh, my typo while writing Int8Array turned out to not be a typo after all. Seems like this array can now be named touchedPoints or something similar. Guess this is just keeping track of processed tiles now. Aside, from that, looks good. I will try to come up with some visual tests. lyv: Ah, my typo while writing `Int8Array` turned out to not be a typo after all.
Seems like this… | |||||
let initialPos = pickRandom(points); | |||||
let tilesToVisit = [new Vector2D(initialPos.x, initialPos.y)]; | |||||
let connectionAmount = 0; | |||||
while (tilesToVisit.length > 0) { | |||||
let position = tilesToVisit.pop(); | |||||
let idx = position.x * mapSize + position.y; | |||||
if (connectionArray[idx] != 0) { | |||||
continue; | |||||
} | |||||
if (!g_Map.validTilePassable(position)) { | |||||
connectionArray[idx] = 1; | |||||
continue; | |||||
} | |||||
let tcValid = true; | |||||
for (let tileClass of tileClasses) { | |||||
if (tileClass.has(position)) { | |||||
connectionArray[idx] = 1; | |||||
tcValid = false; | |||||
} | |||||
} | |||||
if (!tcValid) { | |||||
continue; | |||||
} | |||||
connectionArray[idx] = 1; | |||||
for (let point of points) { | |||||
if (position.x == point.x && position.y == point.y) { | |||||
connectionAmount++; | |||||
if (connectionAmount == points.length) { | |||||
return true; | |||||
} | |||||
} | |||||
} | |||||
tilesToVisit.push(new Vector2D(position.x + 1, position.y)); | |||||
tilesToVisit.push(new Vector2D(position.x - 1, position.y)); | |||||
tilesToVisit.push(new Vector2D(position.x, position.y + 1)); | |||||
tilesToVisit.push(new Vector2D(position.x, position.y - 1)); | |||||
} | |||||
return false; | |||||
} | |||||
Context not available. | |||||
Not Done Inline ActionsThis one was not renamed. lyv: This one was not renamed. | |||||
Not Done Inline ActionsWould be nice to not push and pop useless values. I dont think it matters, but the idx values for these points could be calculated using some basic arithmetic. lyv: Would be nice to not push and pop useless values.
I dont think it matters, but the idx values… |
Wildfire Games · Phabricator
These arrays should be avoided if the typed versions could be used. These generic ones also prone to cache misses. So, thats a nice bonus.
let connectionArray = new Uint8Array(mapSize*mapSize).fill(-1);
You can check against -1 instead of undefined and keep 1 and 0 for true and false respectively.