world gen additions

This commit is contained in:
Akos Horvath 2022-04-20 22:16:30 +02:00
parent 6910c2b80e
commit 72204711b3

View File

@ -252,17 +252,17 @@ float calc_frame_time(struct timespec *start, struct timespec *end)
return elapsed_time;
}
void app_generate_world(App *app, int x)
void app_generate_world(App *app, int a)
{
app->chunk_count = x*x;
app->chunks = malloc(x*x*sizeof(Chunk));
memset(app->chunks, 0, x*x*sizeof(Chunk));
app->chunk_count = a*a;
app->chunks = malloc(a*a*sizeof(Chunk));
memset(app->chunks, 0, a*a*sizeof(Chunk));
unsigned char ptable[512];
noise_init_ptable(ptable);
for (int i = 0; i < x; i++) {
for (int j = 0; j < x; j++) {
for (int i = 0; i < a; i++) {
for (int j = 0; j < a; j++) {
Chunk c;
c.start_pos.x = i*CHUNK_MAX_X;
c.start_pos.y = j*CHUNK_MAX_Y;
@ -270,9 +270,18 @@ void app_generate_world(App *app, int x)
for (int x = 0; x < CHUNK_MAX_X; x++) {
for (int y = 0; y < CHUNK_MAX_Y; y++) {
printf("x: %d y:%d noise: %f\n",
x, y, (noise_noise2(ptable, x*0.01, y*0.01) + 1) * 0.5 * 60);
x, y, (noise_noise2(ptable, x*0.005, y*0.005) + 1) * 0.5 * 60);
int mz = round((noise_noise2(ptable, x*0.005, y*0.005) + 1) * 0.5 * 60);
for (int z = 0; z < mz; z++)
c.blocks[x][y][z].type = BLOCKTYPE_STONE;
for (int z = mz; i < CHUNK_MAX_Z; i++)
c.blocks[x][y][z].type = BLOCKTYPE_AIR;
}
}
chunk_set_blocks_visibility(&c);
chunk_create_displayl(app, &c);
app->chunks[i+(j*a)] = c;
}
}
}