mirror of
https://github.com/Cubitect/cubiomes.git
synced 2025-09-23 03:33:50 -04:00
An approximation is sufficient for scaled 1.18 noise sampling.
This commit is contained in:
parent
849839af55
commit
65414ac3be
@ -2452,7 +2452,7 @@ int checkForBiomes(
|
||||
if (ret)
|
||||
{
|
||||
uint64_t b = 0, bm = 0;
|
||||
for (int i = 0; i < r.sx*r.sy*r.sz; i++)
|
||||
for (i = 0; i < r.sx*r.sy*r.sz; i++)
|
||||
{
|
||||
int id = ids[i];
|
||||
if (id < 128) b |= (1ULL << id);
|
||||
|
129
javarnd.h
129
javarnd.h
@ -1,129 +0,0 @@
|
||||
#ifndef JAVARND_H_
|
||||
#define JAVARND_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
/********************** C copy of the Java Random methods **********************
|
||||
*/
|
||||
|
||||
static inline void setSeed(uint64_t *seed, uint64_t value)
|
||||
{
|
||||
*seed = (value ^ 0x5deece66d) & ((1ULL << 48) - 1);
|
||||
}
|
||||
|
||||
static inline int next(uint64_t *seed, const int bits)
|
||||
{
|
||||
*seed = (*seed * 0x5deece66d + 0xb) & ((1ULL << 48) - 1);
|
||||
return (int) ((int64_t)*seed >> (48 - bits));
|
||||
}
|
||||
|
||||
static inline int nextInt(uint64_t *seed, const int n)
|
||||
{
|
||||
int bits, val;
|
||||
const int m = n - 1;
|
||||
|
||||
if ((m & n) == 0) {
|
||||
uint64_t x = n * (uint64_t)next(seed, 31);
|
||||
return (int) ((int64_t) x >> 31);
|
||||
}
|
||||
|
||||
do {
|
||||
bits = next(seed, 31);
|
||||
val = bits % n;
|
||||
}
|
||||
while (bits - val + m < 0);
|
||||
return val;
|
||||
}
|
||||
|
||||
static inline uint64_t nextLong(uint64_t *seed)
|
||||
{
|
||||
return ((uint64_t) next(seed, 32) << 32) + next(seed, 32);
|
||||
}
|
||||
|
||||
static inline float nextFloat(uint64_t *seed)
|
||||
{
|
||||
return next(seed, 24) / (float) (1 << 24);
|
||||
}
|
||||
|
||||
static inline double nextDouble(uint64_t *seed)
|
||||
{
|
||||
uint64_t x = (uint64_t)next(seed, 26);
|
||||
x <<= 27;
|
||||
x += next(seed, 27);
|
||||
return (int64_t) x / (double) (1ULL << 53);
|
||||
}
|
||||
|
||||
/* A macro to generate the ideal assembly for X = nextInt(S, 24)
|
||||
* This is a macro and not an inline function, as many compilers can make use
|
||||
* of the additional optimisation passes for the surrounding code.
|
||||
*/
|
||||
#define JAVA_NEXT_INT24(S,X) \
|
||||
do { \
|
||||
uint64_t a = (1ULL << 48) - 1; \
|
||||
uint64_t c = 0x5deece66dULL * (S); \
|
||||
c += 11; a &= c; \
|
||||
(S) = a; \
|
||||
a = (uint64_t) ((int64_t)a >> 17); \
|
||||
c = 0xaaaaaaab * a; \
|
||||
c = (uint64_t) ((int64_t)c >> 36); \
|
||||
(X) = (int)a - (int)(c << 3) * 3; \
|
||||
} while (0)
|
||||
|
||||
|
||||
/* skipNextN
|
||||
* ---------
|
||||
* Jumps forwards in the random number sequence by simulating 'n' calls to next.
|
||||
*/
|
||||
static inline void skipNextN(uint64_t *seed, uint64_t n)
|
||||
{
|
||||
uint64_t m = 1;
|
||||
uint64_t a = 0;
|
||||
uint64_t im = 0x5deece66dULL;
|
||||
uint64_t ia = 0xb;
|
||||
uint64_t k;
|
||||
|
||||
for (k = n; k; k >>= 1)
|
||||
{
|
||||
if (k & 1)
|
||||
{
|
||||
m *= im;
|
||||
a = im * a + ia;
|
||||
}
|
||||
ia = (im + 1) * ia;
|
||||
im *= im;
|
||||
}
|
||||
|
||||
*seed = *seed * m + a;
|
||||
*seed &= 0xffffffffffffULL;
|
||||
}
|
||||
|
||||
|
||||
/* Find the modular inverse: (1/x) | mod m.
|
||||
* Assumes x and m are positive (less than 2^63), co-prime.
|
||||
*/
|
||||
static inline __attribute__((const))
|
||||
uint64_t mulInv(uint64_t x, uint64_t m)
|
||||
{
|
||||
uint64_t t, q, a, b, n;
|
||||
if ((int64_t)m <= 1)
|
||||
return 0; // no solution
|
||||
|
||||
n = m;
|
||||
a = 0; b = 1;
|
||||
|
||||
while ((int64_t)x > 1)
|
||||
{
|
||||
if (m == 0)
|
||||
return 0; // x and m are co-prime
|
||||
q = x / m;
|
||||
t = m; m = x % m; x = t;
|
||||
t = a; a = b - q * a; b = t;
|
||||
}
|
||||
|
||||
if ((int64_t)b < 0)
|
||||
b += n;
|
||||
return b;
|
||||
}
|
||||
|
||||
#endif /* JAVARND_H_ */
|
14
layers.c
14
layers.c
@ -1354,11 +1354,15 @@ int p2overworld(const uint64_t np[6], uint64_t *dat);
|
||||
#endif
|
||||
|
||||
/// Biome sampler for MC 1.18
|
||||
int sampleBiomeNoise(const BiomeNoise *bn, int x, int y, int z, uint64_t *dat)
|
||||
int sampleBiomeNoise(const BiomeNoise *bn, int x, int y, int z, uint64_t *dat, int approx)
|
||||
{
|
||||
float t = 0, h = 0, c = 0, e = 0, d = 0, w = 0;
|
||||
double px = x + sampleDoublePerlin(&bn->shift, x, 0, z) * 4.0;
|
||||
double pz = z + sampleDoublePerlin(&bn->shift, z, x, 0) * 4.0;
|
||||
double px = x, pz = z;
|
||||
if (approx == 0)
|
||||
{
|
||||
px += sampleDoublePerlin(&bn->shift, x, 0, z) * 4.0;
|
||||
pz += sampleDoublePerlin(&bn->shift, z, x, 0) * 4.0;
|
||||
}
|
||||
|
||||
c = sampleDoublePerlin(&bn->continentalness, px, 0, pz);
|
||||
e = sampleDoublePerlin(&bn->erosion, px, 0, pz);
|
||||
@ -1405,7 +1409,7 @@ static void genBiomeNoise3D(const BiomeNoise *bn, int *out, Range r, int opt)
|
||||
for (i = 0; i < r.sx; i++)
|
||||
{
|
||||
int xi = (r.x+i)*scale + mid;
|
||||
*p = sampleBiomeNoise(bn, xi, yk, zj, opt ? &dat : NULL);
|
||||
*p = sampleBiomeNoise(bn, xi, yk, zj, opt ? &dat : NULL, opt);
|
||||
p++;
|
||||
}
|
||||
}
|
||||
@ -1453,7 +1457,7 @@ int genBiomeNoiseScaled(const BiomeNoise *bn, int *out, Range r, int mc, uint64_
|
||||
}
|
||||
else
|
||||
{
|
||||
*p = sampleBiomeNoise(bn, x4, y4, z4, 0);
|
||||
*p = sampleBiomeNoise(bn, x4, y4, z4, 0, 0);
|
||||
}
|
||||
p++;
|
||||
}
|
||||
|
2
layers.h
2
layers.h
@ -438,7 +438,7 @@ int genEndScaled(const EndNoise *en, int *out, Range r, int mc, uint64_t sha);
|
||||
*/
|
||||
void initBiomeNoise(BiomeNoise *bn, int mc);
|
||||
void setBiomeSeed(BiomeNoise *bn, uint64_t seed, int large);
|
||||
int sampleBiomeNoise(const BiomeNoise *bn, int x, int y, int z, uint64_t *dat);
|
||||
int sampleBiomeNoise(const BiomeNoise *bn, int x, int y, int z, uint64_t *dat, int approx);
|
||||
/**
|
||||
* The scaled biome noise generation applies for the Overworld version 1.18.
|
||||
* The 'sha' hash of the seed is only required for voronoi at scale 1:1.
|
||||
|
Loading…
x
Reference in New Issue
Block a user