MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / getWeighting

Method getWeighting

source/game/StarWorldLayout.cpp:390–488  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

388}
389
390List<WorldLayout::RegionWeighting> WorldLayout::getWeighting(int x, int y) const {
391 List<RegionWeighting> weighting;
392 WorldGeometry geometry(m_worldSize);
393
394 auto cellWeighting = [&](WorldLayer const& layer, size_t cellIndex, int x) -> float {
395 int xMin = 0;
396 if (cellIndex > 0)
397 xMin = layer.boundaries[cellIndex - 1];
398
399 int xMax = m_worldSize[0];
400 if (cellIndex < layer.boundaries.size())
401 xMax = layer.boundaries[cellIndex];
402
403 if (x > (xMin + xMax) / 2.0f)
404 return clamp<float>(0.5f - (x - xMax) / m_regionBlending, 0.0f, 1.0f);
405 else
406 return clamp<float>(0.5f - (xMin - x) / m_regionBlending, 0.0f, 1.0f);
407 };
408
409 auto addLayerWeighting = [&](WorldLayer const& layer, int x, float weightFactor) {
410 if (layer.cells.empty())
411 return;
412
413 size_t innerCellIndex;
414 int innerCellXValue;
415 tie(innerCellIndex, innerCellXValue) = findContainingCell(layer, x);
416 float innerCellWeight = cellWeighting(layer, innerCellIndex, innerCellXValue);
417
418 size_t leftCellIndex;
419 int leftCellXValue;
420 tie(leftCellIndex, leftCellXValue) = leftCell(layer, innerCellIndex, innerCellXValue);
421 float leftCellWeight = cellWeighting(layer, leftCellIndex, leftCellXValue);
422
423 size_t rightCellIndex;
424 int rightCellXValue;
425 tie(rightCellIndex, rightCellXValue) = rightCell(layer, innerCellIndex, innerCellXValue);
426 float rightCellWeight = cellWeighting(layer, rightCellIndex, rightCellXValue);
427
428 float totalWeight = innerCellWeight + leftCellWeight + rightCellWeight;
429 if (totalWeight <= 0.0f)
430 return;
431
432 innerCellWeight *= weightFactor / totalWeight;
433 leftCellWeight *= weightFactor / totalWeight;
434 rightCellWeight *= weightFactor / totalWeight;
435
436 if (innerCellWeight > 0.0f)
437 weighting.append(RegionWeighting{innerCellWeight, innerCellXValue, layer.cells[innerCellIndex].get()});
438
439 if (leftCellWeight > 0.0f)
440 weighting.append(RegionWeighting{leftCellWeight, leftCellXValue, layer.cells[leftCellIndex].get()});
441
442 if (rightCellWeight > 0.0f)
443 weighting.append(RegionWeighting{rightCellWeight, rightCellXValue, layer.cells[rightCellIndex].get()});
444 };
445
446 auto yi = std::lower_bound(m_layers.begin(), m_layers.end(), y, [](WorldLayer const& layer, int y) {
447 return layer.yStart < y;

Callers 3

blockBiomeInfoMethod · 0.80
getBlockInfoMethod · 0.80
mainFunction · 0.80

Calls 7

sortFunction · 0.50
sizeMethod · 0.45
emptyMethod · 0.45
appendMethod · 0.45
getMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected