mirror of
https://github.com/Cubitect/cubiomes.git
synced 2025-09-25 13:00:27 -04:00
Merge pull request #94 from Nel-S/patch-1
Refactor findFittest as nested for loop
This commit is contained in:
commit
1585006467
17
finders.c
17
finders.c
@ -727,29 +727,26 @@ uint64_t getSpawnDist(const Generator *g, int x, int z)
|
|||||||
static
|
static
|
||||||
void findFittest(const Generator *g, Pos *pos, uint64_t *fitness, double maxrad, double step)
|
void findFittest(const Generator *g, Pos *pos, uint64_t *fitness, double maxrad, double step)
|
||||||
{
|
{
|
||||||
double rad = step, ang = 0;
|
|
||||||
Pos p = *pos;
|
Pos p = *pos;
|
||||||
while (rad <= maxrad)
|
for (double rad = step; rad <= maxrad; rad += step)
|
||||||
|
{
|
||||||
|
for (double ang = 0; ang <= PI*2; ang += step/rad)
|
||||||
{
|
{
|
||||||
int x = p.x + (int)(sin(ang) * rad);
|
int x = p.x + (int)(sin(ang) * rad);
|
||||||
int z = p.z + (int)(cos(ang) * rad);
|
int z = p.z + (int)(cos(ang) * rad);
|
||||||
// calc fitness
|
// Calcuate portion of fitness dependent on distance from origin
|
||||||
double d = ((double)x*x + (double)z*z) / (2500*2500);
|
double d = ((double)x*x + (double)z*z) / (2500*2500);
|
||||||
uint64_t fit = (uint64_t)(d*d * 1e8);
|
uint64_t fit = (uint64_t)(d*d * 1e8);
|
||||||
// calculate the distance to the noise points for spawn
|
// Calculate portion of fitness dependent on climate values
|
||||||
fit += getSpawnDist(g, x, z);
|
fit += getSpawnDist(g, x, z);
|
||||||
|
// Then updates pos and fitness if combined total is lower ( = better) than previous best fitness
|
||||||
if (fit < *fitness)
|
if (fit < *fitness)
|
||||||
{
|
{
|
||||||
pos->x = x;
|
pos->x = x;
|
||||||
pos->z = z;
|
pos->z = z;
|
||||||
*fitness = fit;
|
*fitness = fit;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ang += step / rad;
|
|
||||||
if (ang <= PI*2)
|
|
||||||
continue;
|
|
||||||
ang = 0;
|
|
||||||
rad += step;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user