Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/core
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-08-19 15:09:00 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-08-19 15:09:00 +1000
commit7ff3e0fecc347f6a0c22a56acb2f64b60a26ed25 (patch)
tree33b2b1bca14c97b6b7730d18c1659744ee8f3913 /source/core
parent0c74c70475348a326f7757e97cd64f6faaf79a3c (diff)
Fix parallax and space dust jitter when lerping zoom level on very old universes
Diffstat (limited to 'source/core')
-rw-r--r--source/core/StarRandomPoint.hpp35
1 files changed, 18 insertions, 17 deletions
diff --git a/source/core/StarRandomPoint.hpp b/source/core/StarRandomPoint.hpp
index ff7d354..ac9fcd9 100644
--- a/source/core/StarRandomPoint.hpp
+++ b/source/core/StarRandomPoint.hpp
@@ -13,34 +13,36 @@ namespace Star {
// predictable and uses the RandomSource in a predictable way. Useful for
// things like starfields, fields of debris, random object placement, etc.
-template <typename PointData>
+template <typename PointData, typename DataType = float>
class Random2dPointGenerator {
public:
- typedef List<pair<Vec2F, PointData>> PointSet;
-
+ typedef Star::Polygon<DataType> Poly;
+ typedef Star::Vector<DataType, 2> Point;
+ typedef Star::Rect<DataType> Rect;
+ typedef List<pair<Point, PointData>> PointSet;
Random2dPointGenerator(uint64_t seed, float cellSize, Vec2I const& densityRange);
// Each point will in the area will be generated in a predictable order, and
// if the callback uses the RandomSource in a predictable way, will generate
// the same field for every call.
template <typename PointCallback>
- PointSet generate(PolyF const& area, PointCallback callback);
+ PointSet generate(Poly const& area, PointCallback callback);
private:
- HashTtlCache<Vec2F, PointSet> m_cache;
+ HashTtlCache<Point, PointSet> m_cache;
uint64_t m_seed;
float m_cellSize;
Vec2I m_densityRange;
};
-template <typename PointData>
-inline Random2dPointGenerator<PointData>::Random2dPointGenerator(uint64_t seed, float cellSize, Vec2I const& densityRange)
+template <typename PointData, typename DataType>
+inline Random2dPointGenerator<PointData, DataType>::Random2dPointGenerator(uint64_t seed, float cellSize, Vec2I const& densityRange)
: m_seed(seed), m_cellSize(cellSize), m_densityRange(densityRange) {}
-template <typename PointData>
+template <typename PointData, typename DataType>
template <typename PointCallback>
-auto Random2dPointGenerator<PointData>::generate(PolyF const& area, PointCallback callback) -> PointSet {
+auto Random2dPointGenerator<PointData, DataType>::generate(Poly const& area, PointCallback callback) -> PointSet {
auto bound = area.boundBox();
int64_t sectorXMin = std::floor(bound.xMin() / m_cellSize);
int64_t sectorYMin = std::floor(bound.yMin() / m_cellSize);
@@ -48,22 +50,21 @@ auto Random2dPointGenerator<PointData>::generate(PolyF const& area, PointCallbac
int64_t sectorYMax = std::ceil(bound.yMax() / m_cellSize);
PointSet finalResult;
+ RandomSource sectorRandomness;
for (int64_t x = sectorXMin; x <= sectorXMax; ++x) {
for (int64_t y = sectorYMin; y <= sectorYMax; ++y) {
- auto sector = RectF::withSize({x * m_cellSize, y * m_cellSize}, Vec2F::filled(m_cellSize));
- if (!area.intersects(PolyF(sector)))
+ auto sector = Rect::withSize({x * m_cellSize, y * m_cellSize}, Point::filled(m_cellSize));
+ if (!area.intersects(Poly(sector)))
continue;
- finalResult.appendAll(m_cache.get(Vec2F(x, y), [&](Vec2F const&) {
+ finalResult.appendAll(m_cache.get(Point(x, y), [&](Point const&) {
PointSet sectorResult;
-
- RandomSource sectorRandomness(staticRandomU64(m_seed, x, y));
-
+ sectorRandomness.init(staticRandomU64(m_seed, x, y));
unsigned max = sectorRandomness.randInt(m_densityRange[0], m_densityRange[1]);
for (unsigned i = 0; i < max; ++i) {
- Vec2F pointPos = Vec2F(x + sectorRandomness.randf(), y + sectorRandomness.randf()) * m_cellSize;
- sectorResult.append(pair<Vec2F, PointData>(pointPos, callback(sectorRandomness)));
+ Point pointPos = Point(x + (DataType)sectorRandomness.randd(), y + (DataType)sectorRandomness.randd()) * m_cellSize;
+ sectorResult.append(pair<Point, PointData>(pointPos, callback(sectorRandomness)));
}
return sectorResult;