52 lines
1.8 KiB
Markdown
52 lines
1.8 KiB
Markdown
# Darklord.js — nextBloodSpreadCoord() (satır 1279)
|
||
|
||
[← Darklord.js](index.md) · [← Master](../../wiki.md)
|
||
|
||
Parça 1/2 · [sonraki](nextBloodSpreadCoord-2.md)
|
||
|
||
```javascript
|
||
function nextBloodSpreadCoord(world, pool)
|
||
{
|
||
var radius = Math.max(1, Math.floor(Number(pool.radius || 1)));
|
||
var cx = Math.floor(Number(pool.x || 0));
|
||
var cy = Math.floor(Number(pool.y || 0)) - 1;
|
||
var cz = Math.floor(Number(pool.z || 0));
|
||
var radiusSq = radius * radius;
|
||
|
||
if (!pool.frontier) pool.frontier = [];
|
||
if (!pool.frontierMap) pool.frontierMap = {};
|
||
if (!pool.visited) pool.visited = {};
|
||
if (!pool.scanReady)
|
||
{
|
||
addBloodSpreadFrontier(pool, cx, cz);
|
||
addBloodSpreadFrontier(pool, cx + 1, cz);
|
||
addBloodSpreadFrontier(pool, cx - 1, cz);
|
||
addBloodSpreadFrontier(pool, cx, cz + 1);
|
||
addBloodSpreadFrontier(pool, cx, cz - 1);
|
||
pool.scanReady = true;
|
||
}
|
||
|
||
var guard = BLOOD_SPREAD_BATCH * BLOOD_SPREAD_SCAN_MULT;
|
||
while (pool.frontier.length > 0 && guard-- > 0)
|
||
{
|
||
var idx = Math.floor(Math.random() * pool.frontier.length);
|
||
var point = pool.frontier[idx];
|
||
pool.frontier[idx] = pool.frontier[pool.frontier.length - 1];
|
||
pool.frontier.pop();
|
||
if (!point) continue;
|
||
|
||
var x = Math.floor(Number(point.x || 0));
|
||
var z = Math.floor(Number(point.z || 0));
|
||
var fkey = bloodSpreadVisitKey(x, z);
|
||
delete pool.frontierMap[fkey];
|
||
if (pool.visited[fkey]) continue;
|
||
|
||
var dx = x - cx;
|
||
var dz = z - cz;
|
||
if (dx * dx + dz * dz > radiusSq) continue;
|
||
|
||
pool.visited[fkey] = true;
|
||
pool.visitedCount = Number(pool.visitedCount || 0) + 1;
|
||
if (pool.visitedCount > BLOOD_SPREAD_VISITED_LIMIT) trimBloodSpreadVisited(pool);
|
||
```
|