Small cleanup

This commit is contained in:
Carlos Sanchez 2024-09-22 17:38:19 -04:00
parent c52bf93daf
commit 8284f29be2

View File

@ -259,21 +259,6 @@ uint16_t gen_terrain(struct vec3i pos, haloo3d_obj *model, tecs *ecs,
uint16_t br = i + 1;
uint16_t tl = i + CHUNKVSIZE;
uint16_t tr = i + CHUNKVSIZE + 1;
// float lowy = MIN(model->vertices[bl].y, model->vertices[br].y);
// lowy = MIN(lowy, model->vertices[tl].y);
// lowy = MIN(lowy, model->vertices[tr].y);
// float highy = MAX(model->vertices[bl].y, model->vertices[br].y);
// highy = MAX(highy, model->vertices[tl].y);
// highy = MAX(highy, model->vertices[tr].y);
// float nlayer = fnlGetNoise2D(&ns, noisex + model->vertices[bl].x,
// noisey + model->vertices[bl].z);
// // int landcol = nlayer > 0.0 ? 4 * fabs(lowy) : 0;
// int landcol;
// if (highy < 0) {
// landcol = LCOLSTEP + 1 + LCOLSTEP * fabs(highy);
// } else {
// landcol = LCOLSTEP * fabs(lowy) * (1 + nlayer) * 0.5;
// }
faces[0] = fastface2(model, landcols[0], bl, br, tl);
faces[1] = fastface2(model, landcols[0], br, tr, tl);
float lowys[2];
@ -296,7 +281,6 @@ uint16_t gen_terrain(struct vec3i pos, haloo3d_obj *model, tecs *ecs,
uint16_t tfvi = model->faces[faces[t]][0].posi;
float nlayer = fnlGetNoise2D(&ns, noisex + model->vertices[tfvi].x,
noisey + model->vertices[tfvi].z);
// int landcol = nlayer > 0.0 ? 4 * fabs(lowy) : 0;
int landcol;
if (highys[t] < 0) {
landcol = LCOLSTEP + 1 + LCOLSTEP * fabs(highys[t]);
@ -324,6 +308,7 @@ uint16_t gen_terrain(struct vec3i pos, haloo3d_obj *model, tecs *ecs,
float pick = RANDF(); // pow(RANDF(), 2);
float nlayer = fnlGetNoise2D(&ns, noisex + treepos.x, noisey + treepos.y);
if (pick < y * (1 + nlayer) * 0.5) {
// Generate tree
float scale = 0.1 + RANDF() * 0.05;
float height = 0.5 + RANDF() * 0.5;
haloo3d_obj_addobj(
@ -334,31 +319,32 @@ uint16_t gen_terrain(struct vec3i pos, haloo3d_obj *model, tecs *ecs,
(struct vec3){.x = scale, .y = scale * height, .z = scale});
treecount++;
} else if ((rand() & 3) == 0 && y < 0.4 && y > 0 && RANDF() < -nlayer) {
// Generate flower of random-ish color
float scale = 0.04;
float vertscale = scale * (1 - 0.5 * RANDF()); // * CHUNKSCALE * 4;
float vertscale = scale * (1 - 0.5 * RANDF());
haloo3d_obj_addobj(
&nl_model, flowers[nlayer > -0.9], // flowers[RANDF() * 0.4 > y],
&nl_model, flowers[nlayer > -0.9],
(struct vec3){
.x = treepos.x, .y = y + vertscale * 0.5, .z = treepos.y},
(struct vec3)DEFAULTLOOK,
//(struct vec3){.x = -sin(MPI * 0.25), .y = 0, .z = -cos(MPI *
// 0.25)},
(struct vec3)DEFAULTUP,
(struct vec3)DEFAULTLOOK, (struct vec3)DEFAULTUP,
(struct vec3){.x = scale, .y = vertscale, .z = scale});
}
}
// You can put towers in cells with no trees that are high enough, as long
// as this chunk doesn't already have one
if (treecount == 0 && lowy > TOWERLOW && !gentower) {
gentower = 1;
gen_tower(&nl_model, tower, ecs, ctx, pos,
(struct vec3){.x = triedge[0].x, .y = lowy, .z = triedge[0].y});
}
}
// A silly hack to get a single model to render in multiple ways. Not good!
uint16_t stoplighting = model->numfaces;
haloo3d_obj_addobj(model, &nl_model, (struct vec3){.x = 0, .y = 0, .z = 0},
(struct vec3)DEFAULTLOOK, (struct vec3)DEFAULTUP,
(struct vec3){.x = 1, .y = 1, .z = 1});
haloo3d_obj_free(&nl_model);
// Generate a cloud
// Generate a cloud maybe
if (RANDF() < CLOUDCHANCE)
gen_cloud(ctx, ecs, pos);
return stoplighting;