Skip to content

Commit

Permalink
Fixes for quad-base generation and parameter range finder
Browse files Browse the repository at this point in the history
added stopping flag for quad-base gen
fixed seed duplication when restarting quad-base generation
fixed premature stop on parameter finder when noise has only one lacunarity
  • Loading branch information
Cubitect committed Jun 29, 2023
1 parent f81c2e4 commit d278faf
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
2 changes: 0 additions & 2 deletions finders.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions layers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 20 additions & 3 deletions quadbase.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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];
Expand All @@ -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);
Expand All @@ -350,6 +358,8 @@ static DWORD WINAPI searchAll48Thread(LPVOID data)
}
}
seed++;
if ((seed & 0xfff) == 0 && info->stop && *info->stop)
break;
}
}

Expand All @@ -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));
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -483,6 +497,9 @@ int searchAll48(

#endif

if (stop && *stop)
goto L_err;

if (path)
{
// merge partial files
Expand Down
6 changes: 4 additions & 2 deletions quadbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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),
Expand Down

0 comments on commit d278faf

Please sign in to comment.