Normalized some stuff

This commit is contained in:
Carlos Sanchez 2024-09-21 02:54:24 -04:00
parent 2cef922233
commit dcca92ee43
2 changed files with 10 additions and 12 deletions

View File

@ -1,6 +1,6 @@
# Compiler and other things.
CC = gcc
CFLAGS = -std=c99 -Wall -Wextra
CFLAGS = -std=c99 -Wall -Wextra
BUILDD = build
# NOTE: there is a gcc bug (?) which is making some of the code produce spurrious warnings

View File

@ -59,7 +59,7 @@
#define CHUNKSCALE (1.0 / CHUNKSIZE)
// This is how many vertices across a chunk is
#define CHUNKVSIZE (CHUNKSIZE + 1)
#define VIEWDISTANCE 11
#define VIEWDISTANCE 10
#define PLBOXEDGE (VIEWDISTANCE * 2 + 1)
#define INIT_NEARCLIP 0.01
#define INIT_FARCLIP 100.0
@ -85,8 +85,8 @@
#define INIT_LIGHTPITCH (MPI_2 * 1.65)
#define INIT_LIGHTYAW (MPI_2 * 0.65)
#define INIT_MINLIGHT 0.2
#define INIT_DITHERSTART 3.5
#define INIT_DITHEREND (VIEWDISTANCE - 1.5)
#define INIT_DITHEREND (VIEWDISTANCE - 1.0)
#define INIT_DITHERSTART (INIT_DITHEREND * 0.33)
#define MAXTREEPERCELL 9
#define MAXTREEACROSS 3
#define MAXTREECLOSENESS 0.2
@ -117,9 +117,6 @@ void gen_terrain(struct vec3i pos, haloo3d_obj *model,
haloo3d_obj *tree = haloo3d_easystore_getobj(storage, TREEKEY);
// Don't allow the model to have more than some amount of faces/vertices.
haloo3d_obj_resetfixed(model, H3D_OBJ_MAXFACES, H3D_OBJ_MAXVERTICES);
// CHUNKVSIZE * CHUNKVSIZE * 32,
// CHUNKVSIZE * CHUNKVSIZE * 32);
// if (rand() & 3) return;
struct vec3 landcol = haloo3d_gen_paletteuv(LANDCOL); // 0xF2C0);
int landuv = haloo3d_obj_addvtexture(model, landcol);
fnl_state ns = fnlCreateState();
@ -134,7 +131,6 @@ void gen_terrain(struct vec3i pos, haloo3d_obj *model,
// clang-format off
haloo3d_obj_addvertex(model,
(struct vec4){.x = x, .y = fnlGetNoise2D(&ns, noisex + x, noisey + z), .z = -z, .w = 1 });
//(struct vec4){.x = x, .y = 2 * RANDF() - 1, .z = -z});
// clang-format on
}
}
@ -165,7 +161,6 @@ void gen_terrain(struct vec3i pos, haloo3d_obj *model,
// ns.seed = 0;
ns.frequency = 0.02;
ns.fractal_type = FNL_FRACTAL_NONE;
// Generate up to 4 trees per cell (usually not)
for (int t = 0; t < MAXTREEPERCELL; t++) {
// We know that the first vec in the first triangle is bl, which is our
// base to start generating trees
@ -217,7 +212,7 @@ void gen_cloud(render_context *ctx, tecs *ecs, struct vec3i pos) {
.up = DEFAULTUP,
.lookvec = DEFAULTLOOK,
.pos = {
.x = pos.x + RANDF(), .y = CLOUDHEIGHT + 1.0 * RANDF(), .z = pos.z}};
.x = pos.x + RANDF(), .y = CLOUDHEIGHT + 0.5 * RANDF(), .z = pos.z}};
ECS_SETCOMPONENT(ecs, cloudid, ecs_object){
.flatdither = CLOUDTRANSMIN + (CLOUDTRANSMAX - CLOUDTRANSMIN) * RANDF(),
.texture = haloo3d_easystore_gettex(&ecs->storage, PALETTEKEY),
@ -275,7 +270,7 @@ void player_chunkload(ecs_placement *ppos, render_context *ctx, tecs *ecs) {
// Find + iterate over killable objects placed in world
int mcount = tecs_query(
ecs, ecs_playergarbage_fl | ecs_placement_fl | ecs_object_fl, matches);
// eprintf("KILLABLE OBJS: %d PCHUNK: %d,%d\n", mcount, pchunk.x, pchunk.y);
int lostobjects = 0;
for (int i = 0; i < mcount; i++) {
ecs_placement *placement =
&ECS_GETCOMPONENT(ecs, matches[i], ecs_placement);
@ -286,6 +281,7 @@ void player_chunkload(ecs_placement *ppos, render_context *ctx, tecs *ecs) {
fabs(floor(placement->pos.z) - pchunk.z) > VIEWDISTANCE) {
// OK, reduce the chunk refcount, since we're no longer close to it
obj->contextcount--;
lostobjects++;
}
// This is specifically a chunk, it might be within our view radius.
if (ECS_HASCOMPONENT(ecs, matches[i], ecs_chunk)) {
@ -298,6 +294,9 @@ void player_chunkload(ecs_placement *ppos, render_context *ctx, tecs *ecs) {
}
}
}
if (lostobjects) {
eprintf("KILLABLE OBJS: %d PCHUNK: %d,%d\n", mcount, pchunk.x, pchunk.y);
}
int chunkgen = 0;
// We now have our view radius box and which chunks are not loaded. Up to
// some amount, let's load them
@ -307,7 +306,6 @@ void player_chunkload(ecs_placement *ppos, render_context *ctx, tecs *ecs) {
int surz = z - pchunk.z + VIEWDISTANCE;
if (!surround[surz][surx]) {
gen_chunk(ctx, ecs, (struct vec3i){.x = x, .y = 0, .z = z});
//.y = pchunk.y - VIEWDISTANCE + y});
if (++chunkgen >= MAXCHUNKPERFRAME) {
break;
}