добавленно частичное сглаживание
This commit is contained in:
@@ -31,7 +31,11 @@ public:
|
||||
}
|
||||
|
||||
void setSeed(int number){
|
||||
seed = ((unsigned short)number+23729 xor (unsigned short)number+16786);
|
||||
seed = ((unsigned short)(number*23729) xor (unsigned short)(number+16786));
|
||||
rand();
|
||||
}
|
||||
void setSeed(int number1,int number2){
|
||||
seed = (((unsigned short)(number1*23729) or (unsigned short)(number2%16786)) xor (unsigned short)(number2*number1));
|
||||
rand();
|
||||
}
|
||||
};
|
||||
@@ -70,27 +74,28 @@ float calc_height_faster(fnl_state *noise, int real_x, int real_z){
|
||||
return height;
|
||||
}
|
||||
|
||||
int generate_tree(fnl_state *noise, PseudoRandom* random, const float* heights, int real_x, int real_y, int real_z, int tileSize){
|
||||
int generate_tree(fnl_state *noise, PseudoRandom* random, float* heights, int real_x, int real_y, int real_z, int tileSize){
|
||||
const int tileX = floor((double)real_x/(double)tileSize);
|
||||
const int tileY = floor((double)real_z/(double)tileSize);
|
||||
random->setSeed(tileX*4325261+tileY*12160951+tileSize*9431111);
|
||||
const int tileZ = floor((double)real_z/(double)tileSize);
|
||||
random->setSeed(tileX*4325261+tileZ*12160951+tileSize*9431111);
|
||||
|
||||
bool gentree = fnlGetNoise3D(noise, tileX*3.0f+633, 0.0, tileY*3.0f) > -0.1f && (random->rand() % 10) < 7;
|
||||
bool gentree = fnlGetNoise3D(noise, tileX*3.0f+633, 0.0, tileZ*3.0f) > -0.1f && (random->rand() % 10) < 7;
|
||||
if (!gentree)
|
||||
return 0;
|
||||
|
||||
const int randomX = (random->rand() % (tileSize/2)) - tileSize/4;
|
||||
const int randomZ = (random->rand() % (tileSize/2)) - tileSize/4;
|
||||
int centerX = tileX * tileSize + tileSize/2 + randomX;
|
||||
int centerY = tileY * tileSize + tileSize/2 + randomZ;
|
||||
int height = (int)calc_height_faster(noise, centerX, centerY);
|
||||
if ((height < 57) || (fnlGetNoise3D(noise, real_x*0.025f,real_z*0.025f, 0.0f)*0.5f > 0.5))
|
||||
int centerZ = tileZ * tileSize + tileSize/2 + randomZ;
|
||||
// int height = (int)(heights[centerX*CHUNK_W+centerZ]);
|
||||
int height = (int)calc_height_faster(noise, centerX, centerZ);
|
||||
if ((height < 57)/* || (fnlGetNoise3D(noise, real_x*0.025f,real_z*0.025f, 0.0f)*0.5f > 0.5)*/)
|
||||
return 0;
|
||||
int lx = real_x - centerX;
|
||||
int radius = random->rand() % 4 + 3;
|
||||
int radius = random->rand() % 4 + 2;
|
||||
int ly = real_y - height - 3 * radius;
|
||||
int lz = real_z - centerY;
|
||||
if (lx == 0 && lz == 0 && real_y - height < 4*radius)
|
||||
int lz = real_z - centerZ;
|
||||
if (lx == 0 && lz == 0 && real_y - height < (3*radius + radius/2))
|
||||
return 6;
|
||||
if (lx*lx+ly*ly/2+lz*lz < radius*radius)
|
||||
return 7;
|
||||
@@ -102,6 +107,7 @@ void WorldGenerator::generate(voxel* voxels, int cx, int cz, int seed){
|
||||
noise.noise_type = FNL_NOISE_OPENSIMPLEX2;
|
||||
noise.seed = seed * 60617077 % 25896307;
|
||||
PseudoRandom randomtree;
|
||||
PseudoRandom randomgrass;
|
||||
|
||||
float heights[CHUNK_VOL];
|
||||
|
||||
@@ -123,6 +129,7 @@ void WorldGenerator::generate(voxel* voxels, int cx, int cz, int seed){
|
||||
for (int y = 0; y < CHUNK_H; y++){
|
||||
int real_y = y;
|
||||
int id = real_y < 55 ? BLOCK_WATER : BLOCK_AIR;
|
||||
int states = 0;
|
||||
if ((real_y == (int)height) && (54 < real_y)) {
|
||||
id = BLOCK_GRASS_BLOCK;
|
||||
} else if (real_y < (height - 6)){
|
||||
@@ -130,13 +137,14 @@ void WorldGenerator::generate(voxel* voxels, int cx, int cz, int seed){
|
||||
} else if (real_y < height){
|
||||
id = BLOCK_DIRT;
|
||||
} else {
|
||||
int tree = generate_tree(&noise, &randomtree, heights, real_x, real_y, real_z, 16);
|
||||
int tree = generate_tree(&noise, &randomtree, heights, real_x, real_y, real_z, 23);
|
||||
if (tree) {
|
||||
id = tree;
|
||||
} else if ((tree = generate_tree(&noise, &randomtree, heights, real_x, real_y, real_z, 19))){
|
||||
id = tree;
|
||||
} else if ((tree = generate_tree(&noise, &randomtree, heights, real_x, real_y, real_z, 23))){
|
||||
id = tree;
|
||||
states = 0x32;
|
||||
// } else if ((tree = generate_tree(&noise, &randomtree, heights, real_x, real_y, real_z, 19))){
|
||||
// id = tree;
|
||||
// } else if ((tree = generate_tree(&noise, &randomtree, heights, real_x, real_y, real_z, 23))){
|
||||
// id = tree;
|
||||
}
|
||||
}
|
||||
if ( ((height - (1.5 - 0.2 * pow(height - 54, 4))) < real_y) && (real_y < height)){
|
||||
@@ -144,14 +152,20 @@ void WorldGenerator::generate(voxel* voxels, int cx, int cz, int seed){
|
||||
}
|
||||
if (real_y <= 2)
|
||||
id = BLOCK_BEDROCK;
|
||||
if ((id == 0) && (height > 55.5) && ((int)(height + 1) == real_y) && ((unsigned short)random() > 56000)){
|
||||
|
||||
randomgrass.setSeed(real_x,real_z);
|
||||
if ((id == 0) && (height > 55.5) && ((int)(height + 1) == real_y) && ((unsigned short)randomgrass.rand() > 56000)){
|
||||
id = BLOCK_GRASS;
|
||||
}
|
||||
if ((id == 0) && (height > 55.5) && ((int)(height + 1) == real_y) && ((unsigned short)random() > 64000)){
|
||||
if ((id == 0) && (height > 55.5) && ((int)(height + 1) == real_y) && ((unsigned short)randomgrass.rand() > 65000)){
|
||||
id = BLOCK_FLOWER;
|
||||
}
|
||||
if ((height > 56) && ((int)(height + 1) == real_y) && ((unsigned short)randomgrass.rand() > 65533)){
|
||||
id = BLOCK_WOOD;
|
||||
states = 0x32;
|
||||
}
|
||||
voxels[(y * CHUNK_D + z) * CHUNK_W + x].id = id;
|
||||
voxels[(y * CHUNK_D + z) * CHUNK_W + x].states = 0x32;
|
||||
voxels[(y * CHUNK_D + z) * CHUNK_W + x].states = states;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user