diff --git a/finders.c b/finders.c index 5bbcf37..92e5116 100644 --- a/finders.c +++ b/finders.c @@ -4682,8 +4682,6 @@ int getParaRange(const DoublePerlinNoise *para, double *pmin, double *pmax, } //(*(double*)data) = -1e9+1; // testing - if (lmin == lmax) - return 0; step = (int) (1.0 / (perlin_grad * lmax + FLT_EPSILON)) + 1; diff --git a/layers.h b/layers.h index 54a8ffd..d3b1e65 100644 --- a/layers.h +++ b/layers.h @@ -547,6 +547,8 @@ int p2overworld(int mc, const uint64_t np[6], uint64_t *dat); * Initialize BiomeNoise for only a single climate parameter. * If nptype == NP_DEPTH, the value is sampled at y=0. Note that this value * changes linearly with the height (i.e. -= y/128). + * A maximum of nmax octaves is set, initializing only the most contributing + * octaves up to that point. Use -1 for a full initialization. */ void setClimateParaSeed(BiomeNoise *bn, uint64_t seed, int large, int nptype, int nmax); double sampleClimatePara(const BiomeNoise *bn, int64_t *np, double x, double z); diff --git a/quadbase.c b/quadbase.c index db0eba7..22735c7 100644 --- a/quadbase.c +++ b/quadbase.c @@ -213,11 +213,15 @@ STRUCT(threadinfo_t) const uint64_t *lowBits; int lowBitCnt; int lowBitN; + char skipStart; // testing function int (*check)(uint64_t, void*); void *data; + // abort check + volatile char *stop; + // output char path[MAX_PATHLEN]; FILE *fp; @@ -288,7 +292,8 @@ static DWORD WINAPI searchAll48Thread(LPVOID data) { if unlikely(info->check(seed, info->data)) { - if (info->fp) + if (seed == info->start && info->skipStart) {} // skip + else if (info->fp) { fprintf(info->fp, "%" PRId64"\n", (int64_t)seed); fflush(info->fp); @@ -316,6 +321,8 @@ static DWORD WINAPI searchAll48Thread(LPVOID data) { idx = 0; mid += hstep; + if (info->stop && *info->stop) + break; } seed = mid | info->lowBits[idx]; @@ -327,7 +334,8 @@ static DWORD WINAPI searchAll48Thread(LPVOID data) { if unlikely(info->check(seed, info->data)) { - if (info->fp) + if (seed == info->start && info->skipStart) {} // skip + else if (info->fp) { fprintf(info->fp, "%" PRId64"\n", (int64_t)seed); fflush(info->fp); @@ -350,6 +358,8 @@ static DWORD WINAPI searchAll48Thread(LPVOID data) } } seed++; + if ((seed & 0xfff) == 0 && info->stop && *info->stop) + break; } } @@ -369,7 +379,8 @@ int searchAll48( int lowBitCnt, int lowBitN, int (*check)(uint64_t s48, void *data), - void * data + void * data, + volatile char * stop ) { threadinfo_t *info = (threadinfo_t*) malloc(threads* sizeof(*info)); @@ -412,8 +423,10 @@ int searchAll48( info[t].lowBits = lowBits; info[t].lowBitCnt = lowBitCnt; info[t].lowBitN = lowBitN; + info[t].skipStart = 0; info[t].check = check; info[t].data = data; + info[t].stop = stop; if (path) { @@ -442,6 +455,7 @@ int searchAll48( if (sscanf(buf, "%" PRId64, &lentry) == 1) { info[t].start = lentry; + info[t].skipStart = 1; printf("Continuing thread %d at seed %" PRId64 "\n", t, lentry); } @@ -483,6 +497,9 @@ int searchAll48( #endif + if (stop && *stop) + goto L_err; + if (path) { // merge partial files diff --git a/quadbase.h b/quadbase.h index ade1a58..1fa2420 100644 --- a/quadbase.h +++ b/quadbase.h @@ -148,7 +148,8 @@ float isQuadBaseLarge (const StructureConfig sconf, uint64_t seed, * @lowBitCnt length of lower bit subset * @lowBitN number of bits in the subset values * @check the testing function, should return non-zero for desired seeds - * @data custon data argument passed to 'check' + * @data custom data argument passed to 'check' + * @stop occasional check for abort (nullable) * * Returns zero upon success. */ @@ -161,7 +162,8 @@ int searchAll48( int lowBitCnt, int lowBitN, int (*check)(uint64_t s48, void *data), - void * data + void * data, + volatile char * stop // should be atomic, but is fine as stop flag ); /* Finds the optimal AFK location for four structures of size (ax,ay,az),