mirror of
https://github.com/Cubitect/cubiomes.git
synced 2025-09-09 04:05:08 -04:00
Improved compatibility with non-GNU environments
This commit is contained in:
parent
aa0a6203b6
commit
5644cb1c22
@ -4322,6 +4322,10 @@ static const uint64_t biome_tree_19[] =
|
||||
0xFF026869603A5B60,
|
||||
};
|
||||
|
||||
#if __cplusplus >= 201703L
|
||||
#define __restrict
|
||||
#endif
|
||||
|
||||
struct _args
|
||||
{
|
||||
const uint64_t * __restrict np;
|
||||
@ -4363,7 +4367,7 @@ int get_resulting_node(const struct _args *arg, int idx, int alt, uint64_t ds, i
|
||||
do
|
||||
{
|
||||
if (depth >= 4) {
|
||||
__builtin_unreachable();
|
||||
UNREACHABLE();
|
||||
//fprintf(stderr, "get_resulting_node(): fatal error\n");
|
||||
//exit(1);
|
||||
}
|
||||
|
41
finders.c
41
finders.c
@ -30,6 +30,7 @@
|
||||
uint64_t *loadSavedSeeds(const char *fnam, uint64_t *scnt)
|
||||
{
|
||||
FILE *fp = fopen(fnam, "r");
|
||||
printf("open(%s) -> %p\n", fnam, fp);
|
||||
|
||||
uint64_t seed, i;
|
||||
uint64_t *baseSeeds;
|
||||
@ -323,7 +324,7 @@ int getMineshafts(int mc, uint64_t seed, int cx0, int cz0, int cx1, int cz1,
|
||||
|
||||
if (mc >= MC_1_13)
|
||||
{
|
||||
if U(nextDouble(&s) < 0.004)
|
||||
if unlikely(nextDouble(&s) < 0.004)
|
||||
{
|
||||
if (out && n < nout)
|
||||
{
|
||||
@ -336,7 +337,7 @@ int getMineshafts(int mc, uint64_t seed, int cx0, int cz0, int cx1, int cz1,
|
||||
else
|
||||
{
|
||||
skipNextN(&s, 1);
|
||||
if U(nextDouble(&s) < 0.004)
|
||||
if unlikely(nextDouble(&s) < 0.004)
|
||||
{
|
||||
int d = i;
|
||||
if (-i > d) d = -i;
|
||||
@ -619,7 +620,7 @@ static DWORD WINAPI searchAll48Thread(LPVOID data)
|
||||
|
||||
while (seed <= end)
|
||||
{
|
||||
if U(info->check(seed, info->data))
|
||||
if unlikely(info->check(seed, info->data))
|
||||
{
|
||||
if (info->fp)
|
||||
{
|
||||
@ -658,7 +659,7 @@ static DWORD WINAPI searchAll48Thread(LPVOID data)
|
||||
{
|
||||
while (seed <= end)
|
||||
{
|
||||
if U(info->check(seed, info->data))
|
||||
if unlikely(info->check(seed, info->data))
|
||||
{
|
||||
if (info->fp)
|
||||
{
|
||||
@ -1738,7 +1739,7 @@ static const char *getValidMansionBiomes()
|
||||
static int mapViableBiome(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
{
|
||||
int err = mapBiome(l, out, x, z, w, h);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
int styp = ((const int*) l->data)[0];
|
||||
@ -1793,7 +1794,7 @@ static int mapViableBiome(const Layer * l, int * out, int x, int z, int w, int h
|
||||
static int mapViableShore(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
{
|
||||
int err = mapShore(l, out, x, z, w, h);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
int styp = ((const int*) l->data)[0];
|
||||
@ -2361,7 +2362,7 @@ int getVariant(StructureVariant *r, int structType, int mc, uint64_t seed,
|
||||
else if (t < 202) { r->variant = 1; sx = 10; sy = 7; sz = 10; r->abandoned = 1; }
|
||||
else if (t < 203) { r->variant = 2; sx = 8; sy = 5; sz = 15; r->abandoned = 1; }
|
||||
else if (t < 204) { r->variant = 3; sx = 11; sy = 9; sz = 11; r->abandoned = 1; }
|
||||
else __builtin_unreachable();
|
||||
else UNREACHABLE();
|
||||
break;
|
||||
case desert:
|
||||
t = nextInt(&rng, 250);
|
||||
@ -2371,7 +2372,7 @@ int getVariant(StructureVariant *r, int structType, int mc, uint64_t seed,
|
||||
else if (t < 247) { r->variant = 1; sx = 17; sy = 6; sz = 9; r->abandoned = 1; }
|
||||
else if (t < 249) { r->variant = 2; sx = 12; sy = 6; sz = 12; r->abandoned = 1; }
|
||||
else if (t < 250) { r->variant = 3; sx = 15; sy = 6; sz = 15; r->abandoned = 1; }
|
||||
else __builtin_unreachable();
|
||||
else UNREACHABLE();
|
||||
break;
|
||||
case savanna:
|
||||
t = nextInt(&rng, 459);
|
||||
@ -2383,7 +2384,7 @@ int getVariant(StructureVariant *r, int structType, int mc, uint64_t seed,
|
||||
else if (t < 453) { r->variant = 2; sx = 11; sy = 6; sz = 11; r->abandoned = 1; }
|
||||
else if (t < 456) { r->variant = 3; sx = 9; sy = 6; sz = 11; r->abandoned = 1; }
|
||||
else if (t < 459) { r->variant = 4; sx = 9; sy = 6; sz = 9; r->abandoned = 1; }
|
||||
else __builtin_unreachable();
|
||||
else UNREACHABLE();
|
||||
break;
|
||||
case taiga:
|
||||
t = nextInt(&rng, 100);
|
||||
@ -2391,7 +2392,7 @@ int getVariant(StructureVariant *r, int structType, int mc, uint64_t seed,
|
||||
else if (t < 98) { r->variant = 2; sx = 9; sy = 7; sz = 9; } // taiga_meeting_point_2
|
||||
else if (t < 99) { r->variant = 1; sx = 22; sy = 3; sz = 18; r->abandoned = 1; }
|
||||
else if (t < 100) { r->variant = 2; sx = 9; sy = 7; sz = 9; r->abandoned = 1; }
|
||||
else __builtin_unreachable();
|
||||
else UNREACHABLE();
|
||||
break;
|
||||
case snowy_tundra:
|
||||
t = nextInt(&rng, 306);
|
||||
@ -2401,7 +2402,7 @@ int getVariant(StructureVariant *r, int structType, int mc, uint64_t seed,
|
||||
else if (t < 302) { r->variant = 1; sx = 12; sy = 8; sz = 8; r->abandoned = 1; }
|
||||
else if (t < 303) { r->variant = 2; sx = 11; sy = 5; sz = 9; r->abandoned = 1; }
|
||||
else if (t < 306) { r->variant = 3; sx = 7; sy = 7; sz = 7; r->abandoned = 1; }
|
||||
else __builtin_unreachable();
|
||||
else UNREACHABLE();
|
||||
break;
|
||||
default:
|
||||
sx = sy = sz = 0;
|
||||
@ -3172,7 +3173,7 @@ static int mapFilterSpecial(const Layer * l, int * out, int x, int z, int w, int
|
||||
}
|
||||
|
||||
int err = f->map(l, out, x, z, w, h);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
temps = 0;
|
||||
@ -3223,7 +3224,7 @@ static int mapFilterMushroom(const Layer * l, int * out, int x, int z, int w, in
|
||||
|
||||
L_generate:
|
||||
err = f->map(l, out, x, z, w, h);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
if (f->bf->majorToFind & (1ULL << mushroom_fields))
|
||||
@ -3243,7 +3244,7 @@ static int mapFilterBiome(const Layer * l, int * out, int x, int z, int w, int h
|
||||
uint64_t b;
|
||||
|
||||
int err = f->map(l, out, x, z, w, h);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
b = 0;
|
||||
@ -3270,7 +3271,7 @@ static int mapFilterOceanTemp(const Layer * l, int * out, int x, int z, int w, i
|
||||
uint64_t b;
|
||||
|
||||
int err = f->map(l, out, x, z, w, h);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
b = 0;
|
||||
@ -3296,7 +3297,7 @@ static int mapFilterBiomeEdge(const Layer * l, int * out, int x, int z, int w, i
|
||||
int err;
|
||||
|
||||
err = f->map(l, out, x, z, w, h);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
b = 0;
|
||||
@ -3320,7 +3321,7 @@ static int mapFilterRareBiome(const Layer * l, int * out, int x, int z, int w, i
|
||||
int err;
|
||||
|
||||
err = f->map(l, out, x, z, w, h);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
b = 0; bm = 0;
|
||||
@ -3350,7 +3351,7 @@ static int mapFilterShore(const Layer * l, int * out, int x, int z, int w, int h
|
||||
int i;
|
||||
|
||||
int err = f->map(l, out, x, z, w, h);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
b = 0; bm = 0;
|
||||
@ -3380,7 +3381,7 @@ static int mapFilterRiverMix(const Layer * l, int * out, int x, int z, int w, in
|
||||
int i;
|
||||
|
||||
int err = f->map(l, out, x, z, w, h);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
b = 0; bm = 0;
|
||||
@ -3418,7 +3419,7 @@ static int mapFilterOceanMix(const Layer * l, int * out, int x, int z, int w, in
|
||||
}
|
||||
|
||||
err = f->map(l, out, x, z, w, h);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
b = 0;
|
||||
|
76
finders.h
76
finders.h
@ -427,18 +427,18 @@ static inline float isQuadBase(const StructureConfig sconf, uint64_t seed, int r
|
||||
* generally don't want to inline them. However, these functions usually return
|
||||
* so quickly that the function call is a major contributor to the overall time.
|
||||
*/
|
||||
static inline __attribute__((always_inline, const))
|
||||
static inline ATTR(always_inline, const)
|
||||
float isQuadBaseFeature24Classic (const StructureConfig sconf, uint64_t seed);
|
||||
|
||||
static inline __attribute__((always_inline, const))
|
||||
static inline ATTR(always_inline, const)
|
||||
float isQuadBaseFeature24 (const StructureConfig sconf, uint64_t seed,
|
||||
int ax, int ay, int az);
|
||||
|
||||
static inline __attribute__((always_inline, const))
|
||||
static inline ATTR(always_inline, const)
|
||||
float isQuadBaseFeature (const StructureConfig sconf, uint64_t seed,
|
||||
int ax, int ay, int az, int radius);
|
||||
|
||||
static inline __attribute__((always_inline, const))
|
||||
static inline ATTR(always_inline, const)
|
||||
float isQuadBaseLarge (const StructureConfig sconf, uint64_t seed,
|
||||
int ax, int ay, int az, int radius);
|
||||
|
||||
@ -1018,12 +1018,12 @@ float isQuadBaseFeature24(const StructureConfig sconf, uint64_t seed,
|
||||
// check that the two structures in the opposing diagonal quadrants are
|
||||
// close enough together
|
||||
s00 ^= K;
|
||||
JAVA_NEXT_INT24(s00, x0); if L(x0 < 20) return 0;
|
||||
JAVA_NEXT_INT24(s00, z0); if L(z0 < 20) return 0;
|
||||
JAVA_NEXT_INT24(s00, x0); if likely(x0 < 20) return 0;
|
||||
JAVA_NEXT_INT24(s00, z0); if likely(z0 < 20) return 0;
|
||||
|
||||
s11 ^= K;
|
||||
JAVA_NEXT_INT24(s11, x1); if L(x1 > x0-20) return 0;
|
||||
JAVA_NEXT_INT24(s11, z1); if L(z1 > z0-20) return 0;
|
||||
JAVA_NEXT_INT24(s11, x1); if likely(x1 > x0-20) return 0;
|
||||
JAVA_NEXT_INT24(s11, z1); if likely(z1 > z0-20) return 0;
|
||||
|
||||
x = x1 + 32 - x0;
|
||||
z = z1 + 32 - z0;
|
||||
@ -1034,12 +1034,12 @@ float isQuadBaseFeature24(const StructureConfig sconf, uint64_t seed,
|
||||
uint64_t s10 = 132897987541ULL + seed;
|
||||
|
||||
s01 ^= K;
|
||||
JAVA_NEXT_INT24(s01, x2); if L(x2 >= 4) return 0;
|
||||
JAVA_NEXT_INT24(s01, z2); if L(z2 < 20) return 0;
|
||||
JAVA_NEXT_INT24(s01, x2); if likely(x2 >= 4) return 0;
|
||||
JAVA_NEXT_INT24(s01, z2); if likely(z2 < 20) return 0;
|
||||
|
||||
s10 ^= K;
|
||||
JAVA_NEXT_INT24(s10, x3); if L(x3 < 20) return 0;
|
||||
JAVA_NEXT_INT24(s10, z3); if L(z3 >= 4) return 0;
|
||||
JAVA_NEXT_INT24(s10, x3); if likely(x3 < 20) return 0;
|
||||
JAVA_NEXT_INT24(s10, z3); if likely(z3 >= 4) return 0;
|
||||
|
||||
x = x2 + 32 - x3;
|
||||
z = z3 + 32 - z2;
|
||||
@ -1067,23 +1067,23 @@ float isQuadBaseFeature24Classic(const StructureConfig sconf, uint64_t seed)
|
||||
// check that the two structures in the opposing diagonal quadrants are
|
||||
// close enough together
|
||||
s00 ^= K;
|
||||
JAVA_NEXT_INT24(s00, p); if L(p < 22) return 0;
|
||||
JAVA_NEXT_INT24(s00, p); if L(p < 22) return 0;
|
||||
JAVA_NEXT_INT24(s00, p); if likely(p < 22) return 0;
|
||||
JAVA_NEXT_INT24(s00, p); if likely(p < 22) return 0;
|
||||
|
||||
s11 ^= K;
|
||||
JAVA_NEXT_INT24(s11, p); if L(p > 1) return 0;
|
||||
JAVA_NEXT_INT24(s11, p); if L(p > 1) return 0;
|
||||
JAVA_NEXT_INT24(s11, p); if likely(p > 1) return 0;
|
||||
JAVA_NEXT_INT24(s11, p); if likely(p > 1) return 0;
|
||||
|
||||
uint64_t s01 = 341873128712ULL + seed;
|
||||
uint64_t s10 = 132897987541ULL + seed;
|
||||
|
||||
s01 ^= K;
|
||||
JAVA_NEXT_INT24(s01, p); if L(p > 1) return 0;
|
||||
JAVA_NEXT_INT24(s01, p); if L(p < 22) return 0;
|
||||
JAVA_NEXT_INT24(s01, p); if likely(p > 1) return 0;
|
||||
JAVA_NEXT_INT24(s01, p); if likely(p < 22) return 0;
|
||||
|
||||
s10 ^= K;
|
||||
JAVA_NEXT_INT24(s10, p); if L(p < 22) return 0;
|
||||
JAVA_NEXT_INT24(s10, p); if L(p > 1) return 0;
|
||||
JAVA_NEXT_INT24(s10, p); if likely(p < 22) return 0;
|
||||
JAVA_NEXT_INT24(s10, p); if likely(p > 1) return 0;
|
||||
|
||||
return 1; // should actually return one of 122.781311 or 127.887650
|
||||
}
|
||||
@ -1110,35 +1110,35 @@ float isQuadBaseFeature(const StructureConfig sconf, uint64_t seed,
|
||||
uint64_t s;
|
||||
|
||||
s = s00 ^ K;
|
||||
s = (s * K + b) & M; x0 = (int)(s >> 17) % C; if L(x0 <= rm) return 0;
|
||||
s = (s * K + b) & M; z0 = (int)(s >> 17) % C; if L(z0 <= rm) return 0;
|
||||
s = (s * K + b) & M; x0 = (int)(s >> 17) % C; if likely(x0 <= rm) return 0;
|
||||
s = (s * K + b) & M; z0 = (int)(s >> 17) % C; if likely(z0 <= rm) return 0;
|
||||
|
||||
s = s11 ^ K;
|
||||
s = (s * K + b) & M; x1 = (int)(s >> 17) % C; if L(x1 >= x0-rm) return 0;
|
||||
s = (s * K + b) & M; z1 = (int)(s >> 17) % C; if L(z1 >= z0-rm) return 0;
|
||||
s = (s * K + b) & M; x1 = (int)(s >> 17) % C; if likely(x1 >= x0-rm) return 0;
|
||||
s = (s * K + b) & M; z1 = (int)(s >> 17) % C; if likely(z1 >= z0-rm) return 0;
|
||||
|
||||
// check that the two structures in the opposing diagonal quadrants are
|
||||
// close enough together
|
||||
|
||||
x = x1 + R - x0;
|
||||
z = z1 + R - z0;
|
||||
if L(x*x + z*z > cd*cd)
|
||||
if likely(x*x + z*z > cd*cd)
|
||||
return 0;
|
||||
|
||||
uint64_t s01 = 341873128712ULL + seed;
|
||||
uint64_t s10 = 132897987541ULL + seed;
|
||||
|
||||
s = s01 ^ K;
|
||||
s = (s * K + b) & M; x2 = (int)(s >> 17) % C; if L(x2 >= C-rm) return 0;
|
||||
s = (s * K + b) & M; z2 = (int)(s >> 17) % C; if L(z2 <= rm) return 0;
|
||||
s = (s * K + b) & M; x2 = (int)(s >> 17) % C; if likely(x2 >= C-rm) return 0;
|
||||
s = (s * K + b) & M; z2 = (int)(s >> 17) % C; if likely(z2 <= rm) return 0;
|
||||
|
||||
s = s10 ^ K;
|
||||
s = (s * K + b) & M; x3 = (int)(s >> 17) % C; if L(x3 <= rm) return 0;
|
||||
s = (s * K + b) & M; z3 = (int)(s >> 17) % C; if L(z3 >= C-rm) return 0;
|
||||
s = (s * K + b) & M; x3 = (int)(s >> 17) % C; if likely(x3 <= rm) return 0;
|
||||
s = (s * K + b) & M; z3 = (int)(s >> 17) % C; if likely(z3 >= C-rm) return 0;
|
||||
|
||||
x = x2 + R - x3;
|
||||
z = z3 + R - z2;
|
||||
if L(x*x + z*z > cd*cd)
|
||||
if likely(x*x + z*z > cd*cd)
|
||||
return 0;
|
||||
|
||||
float sqrad = getEnclosingRadius(
|
||||
@ -1176,18 +1176,18 @@ float isQuadBaseLarge(const StructureConfig sconf, uint64_t seed,
|
||||
|
||||
s = s00 ^ K;
|
||||
s = (s * K + b) & M; p = (int)(s >> 17) % C;
|
||||
s = (s * K + b) & M; p += (int)(s >> 17) % C; if L(p <= rm) return 0;
|
||||
s = (s * K + b) & M; p += (int)(s >> 17) % C; if likely(p <= rm) return 0;
|
||||
x0 = p;
|
||||
s = (s * K + b) & M; p = (int)(s >> 17) % C;
|
||||
s = (s * K + b) & M; p += (int)(s >> 17) % C; if L(p <= rm) return 0;
|
||||
s = (s * K + b) & M; p += (int)(s >> 17) % C; if likely(p <= rm) return 0;
|
||||
z0 = p;
|
||||
|
||||
s = s11 ^ K;
|
||||
s = (s * K + b) & M; p = (int)(s >> 17) % C;
|
||||
s = (s * K + b) & M; p += (int)(s >> 17) % C; if L(p > x0-rm) return 0;
|
||||
s = (s * K + b) & M; p += (int)(s >> 17) % C; if likely(p > x0-rm) return 0;
|
||||
x1 = p;
|
||||
s = (s * K + b) & M; p = (int)(s >> 17) % C;
|
||||
s = (s * K + b) & M; p += (int)(s >> 17) % C; if L(p > z0-rm) return 0;
|
||||
s = (s * K + b) & M; p += (int)(s >> 17) % C; if likely(p > z0-rm) return 0;
|
||||
z1 = p;
|
||||
|
||||
s = ((x1-x0)>>1)*((x1-x0)>>1) + ((z1-z0)>>1)*((z1-z0)>>1);
|
||||
@ -1196,18 +1196,18 @@ float isQuadBaseLarge(const StructureConfig sconf, uint64_t seed,
|
||||
|
||||
s = s01 ^ K;
|
||||
s = (s * K + b) & M; p = (int)(s >> 17) % C;
|
||||
s = (s * K + b) & M; p += (int)(s >> 17) % C; if L(p > x0-rm) return 0;
|
||||
s = (s * K + b) & M; p += (int)(s >> 17) % C; if likely(p > x0-rm) return 0;
|
||||
x2 = p;
|
||||
s = (s * K + b) & M; p = (int)(s >> 17) % C;
|
||||
s = (s * K + b) & M; p += (int)(s >> 17) % C; if L(p <= rm) return 0;
|
||||
s = (s * K + b) & M; p += (int)(s >> 17) % C; if likely(p <= rm) return 0;
|
||||
z2 = p;
|
||||
|
||||
s = s10 ^ K;
|
||||
s = (s * K + b) & M; p = (int)(s >> 17) % C;
|
||||
s = (s * K + b) & M; p += (int)(s >> 17) % C; if L(p <= rm) return 0;
|
||||
s = (s * K + b) & M; p += (int)(s >> 17) % C; if likely(p <= rm) return 0;
|
||||
x3 = p;
|
||||
s = (s * K + b) & M; p = (int)(s >> 17) % C;
|
||||
s = (s * K + b) & M; p += (int)(s >> 17) % C; if L(p > z0-rm) return 0;
|
||||
s = (s * K + b) & M; p += (int)(s >> 17) % C; if likely(p > z0-rm) return 0;
|
||||
z3 = p;
|
||||
|
||||
float sqrad = getEnclosingRadius(
|
||||
|
90
layers.c
90
layers.c
@ -737,14 +737,19 @@ static int getEndBiome(int hx, int hz, const uint16_t *hmap, int hw)
|
||||
uint16_t dsj = p_dsj[j];
|
||||
uint16_t e;
|
||||
uint32_t u;
|
||||
for (i = 0; i < 25; i += 5)
|
||||
{
|
||||
if (U(e = p_elev[i+0]) && (u = (p_dsi[i+0] + (uint32_t)dsj) * e) < h) h = u;
|
||||
if (U(e = p_elev[i+1]) && (u = (p_dsi[i+1] + (uint32_t)dsj) * e) < h) h = u;
|
||||
if (U(e = p_elev[i+2]) && (u = (p_dsi[i+2] + (uint32_t)dsj) * e) < h) h = u;
|
||||
if (U(e = p_elev[i+3]) && (u = (p_dsi[i+3] + (uint32_t)dsj) * e) < h) h = u;
|
||||
if (U(e = p_elev[i+4]) && (u = (p_dsi[i+4] + (uint32_t)dsj) * e) < h) h = u;
|
||||
}
|
||||
|
||||
// force unroll for(i=0;i<25;i++) in a cross compatible way
|
||||
#define x5(i,x) { x; i++; x; i++; x; i++; x; i++; x; i++; }
|
||||
#define for25(i,x) { i = 0; x5(i,x) x5(i,x) x5(i,x) x5(i,x) x5(i,x) }
|
||||
for25(i,
|
||||
if unlikely(e = p_elev[i])
|
||||
{
|
||||
if ((u = (p_dsi[i] + (uint32_t)dsj) * e) < h)
|
||||
h = u;
|
||||
}
|
||||
);
|
||||
#undef for25
|
||||
#undef x5
|
||||
p_elev += hw;
|
||||
}
|
||||
|
||||
@ -934,7 +939,8 @@ int getSurfaceHeightEnd(int mc, uint64_t seed, int x, int z)
|
||||
double dx = (x & 7) / 8.0;
|
||||
double dz = (z & 7) / 8.0;
|
||||
|
||||
const int y0 = 0, y1 = 32, yn = y1-y0+1;
|
||||
// abusing enum for local compile time constants rather than enumeration
|
||||
enum { y0 = 0, y1 = 32, yn = y1-y0+1 };
|
||||
double ncol00[yn];
|
||||
double ncol01[yn];
|
||||
double ncol10[yn];
|
||||
@ -1631,7 +1637,7 @@ int mapZoomFuzzy(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
int i, j;
|
||||
|
||||
int err = l->p->getMap(l->p, out, pX, pZ, pW, pH);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
int newW = (pW) << 1;
|
||||
@ -1734,7 +1740,7 @@ int mapZoom(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
int i, j;
|
||||
|
||||
int err = l->p->getMap(l->p, out, pX, pZ, pW, pH);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
int newW = (pW) << 1;
|
||||
@ -1812,7 +1818,7 @@ int mapLand(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
int i, j;
|
||||
|
||||
int err = l->p->getMap(l->p, out, pX, pZ, pW, pH);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
uint64_t st = l->startSalt;
|
||||
@ -1928,7 +1934,7 @@ int mapLand16(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
int i, j;
|
||||
|
||||
int err = l->p->getMap(l->p, out, pX, pZ, pW, pH);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
uint64_t st = l->startSalt;
|
||||
@ -2024,7 +2030,7 @@ int mapIsland(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
int i, j;
|
||||
|
||||
int err = l->p->getMap(l->p, out, pX, pZ, pW, pH);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
uint64_t ss = l->startSeed;
|
||||
@ -2065,7 +2071,7 @@ int mapSnow16(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
int i, j;
|
||||
|
||||
int err = l->p->getMap(l->p, out, pX, pZ, pW, pH);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
uint64_t ss = l->startSeed;
|
||||
@ -2098,7 +2104,7 @@ int mapSnow(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
int i, j;
|
||||
|
||||
int err = l->p->getMap(l->p, out, pX, pZ, pW, pH);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
uint64_t ss = l->startSeed;
|
||||
@ -2142,7 +2148,7 @@ int mapCool(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
int i, j;
|
||||
|
||||
int err = l->p->getMap(l->p, out, pX, pZ, pW, pH);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
for (j = 0; j < h; j++)
|
||||
@ -2181,7 +2187,7 @@ int mapHeat(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
int i, j;
|
||||
|
||||
int err = l->p->getMap(l->p, out, pX, pZ, pW, pH);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
for (j = 0; j < h; j++)
|
||||
@ -2214,7 +2220,7 @@ int mapHeat(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
int mapSpecial(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
{
|
||||
int err = l->p->getMap(l->p, out, x, z, w, h);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
uint64_t st = l->startSalt;
|
||||
@ -2254,7 +2260,7 @@ int mapMushroom(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
int i, j;
|
||||
|
||||
int err = l->p->getMap(l->p, out, pX, pZ, pW, pH);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
uint64_t ss = l->startSeed;
|
||||
@ -2293,7 +2299,7 @@ int mapDeepOcean(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
int i, j;
|
||||
|
||||
int err = l->p->getMap(l->p, out, pX, pZ, pW, pH);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
for (j = 0; j < h; j++)
|
||||
@ -2356,7 +2362,7 @@ const int oldBiomes11[] = { desert, forest, mountains, swamp, plains, taiga };
|
||||
int mapBiome(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
{
|
||||
int err = l->p->getMap(l->p, out, x, z, w, h);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
int mc = l->mc;
|
||||
@ -2435,7 +2441,7 @@ int mapBiome(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
int mapNoise(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
{
|
||||
int err = l->p->getMap(l->p, out, x, z, w, h);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
uint64_t ss = l->startSeed;
|
||||
@ -2467,7 +2473,7 @@ int mapNoise(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
int mapBamboo(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
{
|
||||
int err = l->p->getMap(l->p, out, x, z, w, h);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
uint64_t ss = l->startSeed;
|
||||
@ -2517,7 +2523,7 @@ int mapBiomeEdge(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
int mc = l->mc;
|
||||
|
||||
int err = l->p->getMap(l->p, out, pX, pZ, pW, pH);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
for (j = 0; j < h; j++)
|
||||
@ -2586,7 +2592,7 @@ int mapHills(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
int pH = h + 2;
|
||||
int i, j;
|
||||
|
||||
if U(l->p2 == NULL)
|
||||
if unlikely(l->p2 == NULL)
|
||||
{
|
||||
printf("mapHills() requires two parents! Use setupMultiLayer()\n");
|
||||
exit(1);
|
||||
@ -2594,12 +2600,12 @@ int mapHills(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
|
||||
int err;
|
||||
err = l->p->getMap(l->p, out, pX, pZ, pW, pH);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
int *riv = out + pW * pH;
|
||||
err = l->p2->getMap(l->p2, riv, pX, pZ, pW, pH);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
int mc = l->mc;
|
||||
@ -2756,7 +2762,7 @@ int mapRiver(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
int i, j;
|
||||
|
||||
int err = l->p->getMap(l->p, out, pX, pZ, pW, pH);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
int mc = l->mc;
|
||||
@ -2813,7 +2819,7 @@ int mapSmooth(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
int i, j;
|
||||
|
||||
int err = l->p->getMap(l->p, out, pX, pZ, pW, pH);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
uint64_t ss = l->startSeed;
|
||||
@ -2863,7 +2869,7 @@ int mapSunflower(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
int i, j;
|
||||
|
||||
int err = l->p->getMap(l->p, out, x, z, w, h);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
uint64_t ss = l->startSeed;
|
||||
@ -2925,7 +2931,7 @@ int mapShore(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
int i, j;
|
||||
|
||||
int err = l->p->getMap(l->p, out, pX, pZ, pW, pH);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
int mc = l->mc;
|
||||
@ -3033,7 +3039,7 @@ int mapSwampRiver(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
int i, j;
|
||||
|
||||
int err = l->p->getMap(l->p, out, x, z, w, h);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
uint64_t ss = l->startSeed;
|
||||
@ -3061,14 +3067,14 @@ int mapSwampRiver(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
|
||||
int mapRiverMix(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
{
|
||||
if U(l->p2 == NULL)
|
||||
if unlikely(l->p2 == NULL)
|
||||
{
|
||||
printf("mapRiverMix() requires two parents! Use setupMultiLayer()\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int err = l->p->getMap(l->p, out, x, z, w, h); // biome chain
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
int idx;
|
||||
@ -3077,7 +3083,7 @@ int mapRiverMix(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
int *buf = out + len;
|
||||
|
||||
err = l->p2->getMap(l->p2, buf, x, z, w, h); // rivers
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
|
||||
@ -3135,14 +3141,14 @@ int mapOceanMix(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
int i, j;
|
||||
int lx0, lx1, lz0, lz1, lw, lh;
|
||||
|
||||
if U(l->p2 == NULL)
|
||||
if unlikely(l->p2 == NULL)
|
||||
{
|
||||
printf("mapOceanMix() requires two parents! Use setupMultiLayer()\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int err = l->p2->getMap(l->p2, out, x, z, w, h);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
// determine the minimum required land area: (x+lx0, z+lz0), (lw, lh)
|
||||
@ -3172,7 +3178,7 @@ int mapOceanMix(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
lw = lx1 - lx0;
|
||||
lh = lz1 - lz0;
|
||||
err = l->p->getMap(l->p, land, x+lx0, z+lz0, lw, lh);
|
||||
if U(err != 0)
|
||||
if unlikely(err != 0)
|
||||
return err;
|
||||
|
||||
for (j = 0; j < h; j++)
|
||||
@ -3558,11 +3564,11 @@ int mapVoronoi114(const Layer * l, int * out, int x, int z, int w, int h)
|
||||
dc = (mi-dc1) * (mi-dc1) + sjc;
|
||||
dd = (mi-dd1) * (mi-dd1) + sjd;
|
||||
|
||||
if U((da < db) && (da < dc) && (da < dd))
|
||||
if unlikely((da < db) && (da < dc) && (da < dd))
|
||||
v = v00;
|
||||
else if U((db < da) && (db < dc) && (db < dd))
|
||||
else if unlikely((db < da) && (db < dc) && (db < dd))
|
||||
v = v10;
|
||||
else if U((dc < da) && (dc < db) && (dc < dd))
|
||||
else if unlikely((dc < da) && (dc < db) && (dc < dd))
|
||||
v = v01;
|
||||
else
|
||||
v = v11;
|
||||
|
4
noise.c
4
noise.c
@ -47,9 +47,7 @@ static inline double indexedLerp(int idx, double a, double b, double c)
|
||||
case 14: return -a + b;
|
||||
case 15: return -b - c;
|
||||
}
|
||||
#if __GNUC__
|
||||
__builtin_unreachable();
|
||||
#endif
|
||||
UNREACHABLE();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
20
rng.h
20
rng.h
@ -19,23 +19,33 @@
|
||||
#define STRUCT(S) typedef struct S S; struct S
|
||||
|
||||
#if __GNUC__
|
||||
|
||||
#define IABS(X) __builtin_abs(X)
|
||||
#define PREFETCH(PTR,RW,LOC) __builtin_prefetch(PTR,RW,LOC)
|
||||
#define L(COND) (__builtin_expect(!!(COND),1)) // [[likely]]
|
||||
#define U(COND) (__builtin_expect((COND),0)) // [[unlikely]
|
||||
#define likely(COND) (__builtin_expect(!!(COND),1))
|
||||
#define unlikely(COND) (__builtin_expect((COND),0))
|
||||
#define ATTR(...) __attribute__((__VA_ARGS__))
|
||||
#define BSWAP32(X) __builtin_bswap32(X)
|
||||
#define UNREACHABLE() __builtin_unreachable()
|
||||
|
||||
#else
|
||||
|
||||
#define IABS(X) ((int)abs(X))
|
||||
#define PREFETCH(PTR,RW,LOC)
|
||||
#define L(COND) (COND)
|
||||
#define U(COND) (COND)
|
||||
#define likely(COND) (COND)
|
||||
#define unlikely(COND) (COND)
|
||||
#define ATTR(...)
|
||||
static inline uint32_t BSWAP32(uint32_t x) {
|
||||
x = ((x & 0x000000ff) << 24) | ((x & 0x0000ff00) << 8) |
|
||||
((x & 0x00ff0000) >> 8) | ((x & 0xff000000) >> 24);
|
||||
return x;
|
||||
}
|
||||
#if _MSC_VER
|
||||
#define UNREACHABLE() __assume(false)
|
||||
#else
|
||||
#define UNREACHABLE() exit(1) // [[noreturn]]
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/// imitate amd64/x64 rotate instructions
|
||||
@ -104,7 +114,7 @@ static inline double nextDouble(uint64_t *seed)
|
||||
return (int64_t) x / (double) (1ULL << 53);
|
||||
}
|
||||
|
||||
/* A macro to generate the ideal assembly for X = nextInt(S, 24)
|
||||
/* 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.
|
||||
*/
|
||||
|
9
tests.c
9
tests.c
@ -134,7 +134,7 @@ uint32_t testAreas(int mc, int dim, int scale)
|
||||
uint64_t s;
|
||||
for (s = 0; s < 100; s++)
|
||||
{
|
||||
int d = 10000;
|
||||
int d = 40000;
|
||||
int x = hash32(s << 5) % d - d/2;
|
||||
int y = ((int)(hash32(s << 7) % 384) - 64);
|
||||
int z = hash32(s << 9) % d - d/2;
|
||||
@ -353,7 +353,12 @@ void findBiomeParaBounds()
|
||||
|
||||
int main()
|
||||
{
|
||||
testGeneration();
|
||||
int i;
|
||||
for (i = 0; i < 10; i++)
|
||||
{
|
||||
testAreas(MC_NEWEST, +1, 16);
|
||||
}
|
||||
//testGeneration();
|
||||
//findBiomeParaBounds();
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user