diff --git a/make_ps2.sh b/make_ps2.sh index 38091c2..9986153 100755 --- a/make_ps2.sh +++ b/make_ps2.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -e + if [ "$#" -lt "1" ]; then echo "ERROR: You must pass the program name! For instance, to build maze.elf," echo "pass in just 'maze'" diff --git a/modeleditor/go.mod b/modeleditor/go.mod new file mode 100644 index 0000000..d4e8bd0 --- /dev/null +++ b/modeleditor/go.mod @@ -0,0 +1,3 @@ +module gitlumen.sh/haloopdy/3dtoys/modeleditor + +go 1.23.0 diff --git a/modeleditor/main.go b/modeleditor/main.go new file mode 100644 index 0000000..dabda60 --- /dev/null +++ b/modeleditor/main.go @@ -0,0 +1,9 @@ +package main + +import ( + "fmt" +) + +func main() { + fmt.Printf("Program starting\n") +} diff --git a/modeleditor/modeleditor b/modeleditor/modeleditor new file mode 100755 index 0000000..a6163d1 Binary files /dev/null and b/modeleditor/modeleditor differ diff --git a/terrain.c b/terrain.c index 74bb276..5553173 100644 --- a/terrain.c +++ b/terrain.c @@ -36,19 +36,34 @@ #include // #define LIMITEDPRINT +// #define NOPRINT #ifdef _EE #define WIDTH 160 #define HEIGHT 120 #define SCREENSCALE 4 +#define VIEWDISTANCE 2 // MAX IS AROUND 12 +#define MAXTREEPERCELL 4 +#define MAXTREEACROSS 2 +#define CHUNKINITFACES (H3D_OBJ_MAXFACES / 2) +#define CHUNKINITVERTS (H3D_OBJ_MAXVERTICES / 2) +#define INIT_DITHEREND 999 +#define INIT_DITHERSTART 999 #else #define WIDTH 480 #define HEIGHT 300 #define SCREENSCALE 2 +#define VIEWDISTANCE 10 // MAX IS AROUND 12 +#define MAXTREEPERCELL 9 +#define MAXTREEACROSS 3 +#define CHUNKINITFACES H3D_OBJ_MAXFACES +#define CHUNKINITVERTS H3D_OBJ_MAXVERTICES +#define INIT_DITHEREND H3DVF(VIEWDISTANCE - 1.0) +#define INIT_DITHERSTART H3DVF(INIT_DITHEREND * 0.5) #endif #define SWIDTH (WIDTH * SCREENSCALE) #define SHEIGHT (HEIGHT * SCREENSCALE) -#define AVGWEIGHT 0.85 +#define AVGWEIGHT H3DVF(0.85) #define DEFAULTUP \ { .x = 0, .y = 1, .z = 0 } // Lookvec for objects which all face forward along with the player @@ -57,16 +72,15 @@ // How big each chunk is (x and y, square). MUST BE POWER OF 2 - 1 #define CHUNKSIZE 7 // This is the width in tiles -#define CHUNKSCALE (1.0 / CHUNKSIZE) +#define CHUNKSCALE H3DVF(1.0 / CHUNKSIZE) // This is how many vertices across a chunk is #define CHUNKVSIZE (CHUNKSIZE + 1) -#define VIEWDISTANCE 10 // MAX IS AROUND 12 #define PLBOXEDGE (VIEWDISTANCE * 2 + 1) #define MAXCHUNKPERFRAME PLBOXEDGE // Generation consts / things for looks #define COLOREDTERRAIN // Some cost, not much -#define LANDHEIGHT 4.0 +#define LANDHEIGHT H3DVF(4.0) #define LANDCOL 0xF7C3 // 0xF4E1 #define FLANDCOL 0xF260 // 0xF3A0 // 0xF4E1 #define UWLANDCOL 0xF026 @@ -81,40 +95,36 @@ #define TOWERCOL 0xF111 #define LIGHTCOL 0xFF00 #define SANDCOL 0xFDD8 -#define TOWERLOW 0.755 // small changes to this make a huge difference -#define TOWERLIGHTMINSIZE (CHUNKSCALE * 0.1) -#define TOWERLIGHTMAXSIZE (CHUNKSCALE * 0.3) -#define TOWERLIGHTMINTRANS 0 -#define TOWERLIGHTMAXTRANS 0.4 -#define TOWERLIGHTRATE 1.5 -#define SANDSTART 0.085 -#define TREEBOTTOM -0.333 -#define TREETRUNKWIDTH 0.2 -#define SEATRANS 0.75 -#define CLOUDTRANSMIN 0.1 -#define CLOUDTRANSMAX 0.2 -#define CLOUDHEIGHT 2.0 -#define CLOUDSTRETCH 2 -#define CLOUDCHANCE 0.1 -#define INIT_LIGHTPITCH (MPI_2 * 1.65) -#define INIT_LIGHTYAW (MPI_2 * 0.65) -#define INIT_MINLIGHT 0.2 -#define INIT_DITHEREND (VIEWDISTANCE - 1.0) -#define INIT_DITHERSTART (INIT_DITHEREND * 0.5) -#define MAXTREEPERCELL 9 -#define MAXTREEACROSS 3 -#define MAXTREECLOSENESS 0.2 +#define TOWERLOW H3DVF(0.755) // small changes to this make a huge difference +#define TOWERLIGHTMINSIZE H3DVF(CHUNKSCALE * 0.1) +#define TOWERLIGHTMAXSIZE H3DVF(CHUNKSCALE * 0.3) +#define TOWERLIGHTMINTRANS H3DVF(0) +#define TOWERLIGHTMAXTRANS H3DVF(0.4) +#define TOWERLIGHTRATE H3DVF(1.5) +#define SANDSTART H3DVF(0.085) +#define TREEBOTTOM H3DVF(-0.333) +#define TREETRUNKWIDTH H3DVF(0.20) +#define SEATRANS H3DVF(0.5) +#define CLOUDTRANSMIN H3DVF(0.1) +#define CLOUDTRANSMAX H3DVF(0.2) +#define CLOUDHEIGHT H3DVF(1 + VIEWDISTANCE * 0.1) +#define CLOUDSTRETCH H3DVF(2) +#define CLOUDCHANCE H3DVF(0.1) +#define INIT_LIGHTPITCH H3DVF(MPI_2 * 1.65) +#define INIT_LIGHTYAW H3DVF(MPI_2 * 0.65) +#define INIT_MINLIGHT H3DVF(0.2) +#define MAXTREECLOSENESS H3DVF(0.2) // Player things -#define INIT_FOV 90.0 -#define INIT_CAMPITCH (MPI_2 * 1.3) // MPI_2 * 1.6 // 1.575 -#define INIT_PLAYERHEIGHT 0.65 -#define INIT_NEARCLIP 0.01 -#define INIT_FARCLIP 100.0 +#define INIT_FOV H3DVF(90.0) +#define INIT_CAMPITCH H3DVF(MPI_2 * 1.3) // MPI_2 * 1.6 // 1.575 +#define INIT_PLAYERHEIGHT H3DVF(0.65) +#define INIT_NEARCLIP H3DVF(0.010) +#define INIT_FARCLIP H3DVF(100.0) #define INIT_PLAYERSPEED \ { .x = 0, .y = 0, .z = -1.5 } -#define RANDF() ((float)rand() / RAND_MAX) +#define RANDF() ((float)rand() / H3DVF(RAND_MAX)) #define OFLOOR(v) (floor(fabs(v)) * ((v) < 0 ? -1 : 1)) // Some globals you can mess around with potentially @@ -152,9 +162,9 @@ static inline mfloat_t calc_barycentric(mfloat_t *point, mfloat_t *values, void gen_tower(haloo3d_obj *model, haloo3d_obj *tower, tecs *ecs, render_context *ctx, struct vec3i chunk, struct vec3 pos) { const float scale = 0.5; - pos.x += 0.5; + pos.x += H3DVF(0.5); pos.y += scale; - pos.z -= 0.5; + pos.z -= H3DVF(0.5); haloo3d_obj_addobj(model, tower, pos, (struct vec3)DEFAULTLOOK, (struct vec3)DEFAULTUP, (struct vec3){.x = scale, .y = scale, .z = scale}); @@ -175,7 +185,7 @@ void gen_tower(haloo3d_obj *model, haloo3d_obj *tower, tecs *ecs, .flatdither = 0.2, .texture = haloo3d_easystore_gettex(&ecs->storage, PALETTEKEY), .scale = {.x = CHUNKSCALE, .y = CHUNKSCALE, .z = CHUNKSCALE}, - .lighting = NULL, //&ecs->chunklight, + .lighting = NULL, .stoplighting = 0, .model = light, .cullbackface = 0, @@ -187,17 +197,19 @@ void gen_cloud(render_context *ctx, tecs *ecs, struct vec3i pos) { haloo3d_obj *cloud = haloo3d_easystore_getobj(&ecs->storage, CLOUDKEY); ecs_eid cloudid = tecs_newentity(ecs, 0); ECS_SETCOMPONENT(ecs, cloudid, ecs_playergarbage){}; - ECS_SETCOMPONENT(ecs, cloudid, - ecs_placement){.up = DEFAULTUP, - .lookvec = DEFAULTLOOK, - .pos = {.x = pos.x + RANDF(), - .y = CLOUDHEIGHT + 0.5 * RANDF(), - .z = pos.z - 0.9}}; + ECS_SETCOMPONENT(ecs, cloudid, ecs_placement){ + .up = DEFAULTUP, + .lookvec = DEFAULTLOOK, + .pos = {.x = pos.x + RANDF(), + .y = CLOUDHEIGHT + H3DVF(0.5) * RANDF(), + .z = pos.z - 0.9}}; ECS_SETCOMPONENT(ecs, cloudid, ecs_object){ .flatdither = CLOUDTRANSMIN + (CLOUDTRANSMAX - CLOUDTRANSMIN) * RANDF(), .texture = haloo3d_easystore_gettex(&ecs->storage, PALETTEKEY), - .scale = {.x = 1 + RANDF(), .y = 1.0 / CLOUDSTRETCH, .z = 1}, - .lighting = NULL, //&ecs->chunklight, + .scale = {.x = H3DVF(1) + RANDF(), + .y = H3DVF(1.0 / CLOUDSTRETCH), + .z = 1}, + .lighting = NULL, .stoplighting = 0, .model = cloud, .cullbackface = 0, @@ -215,23 +227,22 @@ uint16_t gen_terrain(struct vec3i pos, haloo3d_obj *model, tecs *ecs, flowers[0] = haloo3d_easystore_getobj(storage, REDFLOWERKEY); flowers[1] = haloo3d_easystore_getobj(storage, YELLOWFLOWERKEY); // Don't allow the model to have more than some amount of faces/vertices. - haloo3d_obj_resetfixed(model, H3D_OBJ_MAXFACES, H3D_OBJ_MAXVERTICES); + haloo3d_obj_resetfixed(model, CHUNKINITFACES, CHUNKINITVERTS); #define LCOLSTEP 8 // uint16_t sandcol = COMCOL(model, 0xFFF7); uint16_t landcols[(LCOLSTEP + 1) * 2]; for (int i = 0; i <= LCOLSTEP; i++) { - landcols[i] = - COMCOL(model, haloo3d_col_lerp(LANDCOL, FLANDCOL, - (float)i / LCOLSTEP)); // 0xF2C0); + landcols[i] = COMCOL( + model, haloo3d_col_lerp(LANDCOL, FLANDCOL, (float)i / H3DVF(LCOLSTEP))); landcols[i + LCOLSTEP + 1] = // 0xFDE6 COMCOL(model, haloo3d_col_lerp(SANDCOL, UWLANDCOL, - (float)i / LCOLSTEP)); // 0xF2C0); + (float)i / H3DVF(LCOLSTEP))); } fnl_state ns = fnlCreateState(); ns.noise_type = FNL_NOISE_OPENSIMPLEX2; ns.seed = gen_terrain_seed; - ns.frequency = 0.025; + ns.frequency = H3DVF(0.025); ns.fractal_type = FNL_FRACTAL_RIDGED; float noisex = pos.x * CHUNKSIZE; float noisey = -pos.z * CHUNKSIZE; @@ -269,8 +280,8 @@ uint16_t gen_terrain(struct vec3i pos, haloo3d_obj *model, tecs *ecs, float lowys[2]; float highys[2]; for (int t = 0; t < 2; t++) { - lowys[t] = 999; - highys[t] = -999; + lowys[t] = H3DVF(999); + highys[t] = H3DVF(-999); for (int v = 0; v < 3; v++) { int ofs = t * 3; // NOTE: WE SWTICH Y AND Z TO MAKE THE EDGE FUNCTION WORK @@ -290,7 +301,7 @@ uint16_t gen_terrain(struct vec3i pos, haloo3d_obj *model, tecs *ecs, if (highys[t] < SANDSTART) { landcol = LCOLSTEP + 1 + LCOLSTEP * fabs(highys[t]); } else { - landcol = LCOLSTEP * fabs(lowys[t]) * (1 + nlayer) * 0.5; + landcol = LCOLSTEP * fabs(lowys[t]) * (H3DVF(1) + nlayer) * H3DVF(0.5); } for (int v = 0; v < 3; v++) { model->faces[faces[t]][v].texi = landcols[landcol]; @@ -303,19 +314,19 @@ uint16_t gen_terrain(struct vec3i pos, haloo3d_obj *model, tecs *ecs, // We know that the first vec in the first triangle is bl, which is our // base to start generating trees struct vec2 treepos = { - .x = triedge[0].x + - (1.0 / MAXTREEACROSS) * - ((t % MAXTREEACROSS) + (1.0 - MAXTREECLOSENESS) * RANDF()), - .y = triedge[0].y - - ((1.0 / MAXTREEACROSS) * ((int)(t / MAXTREEACROSS) + - (1.0 - MAXTREECLOSENESS) * RANDF()))}; + .x = triedge[0].x + H3DVF(1.0 / MAXTREEACROSS) * + ((t % MAXTREEACROSS) + + (H3DVF(1.0) - MAXTREECLOSENESS) * RANDF()), + .y = triedge[0].y - (H3DVF(1.0 / MAXTREEACROSS) * + ((int)(t / MAXTREEACROSS) + + (H3DVF(1.0) - MAXTREECLOSENESS) * RANDF()))}; float y = calc_barycentric(treepos.v, heights, triedge, 2); float pick = RANDF(); // pow(RANDF(), 2); float nlayer = fnlGetNoise2D(&ns, noisex + treepos.x, noisey + treepos.y); - if (pick < y * (1 + nlayer) * 0.5) { + if (pick < y * (H3DVF(1) + nlayer) * H3DVF(0.5)) { // Generate tree - float scale = 0.1 + RANDF() * 0.05; - float height = 0.5 + RANDF() * 0.5; + float scale = H3DVF(0.1) + RANDF() * H3DVF(0.05); + float height = H3DVF(0.5) + RANDF() * H3DVF(0.5); haloo3d_obj_addobj( model, tree, (struct vec3){ @@ -323,14 +334,16 @@ uint16_t gen_terrain(struct vec3i pos, haloo3d_obj *model, tecs *ecs, (struct vec3)DEFAULTLOOK, (struct vec3)DEFAULTUP, (struct vec3){.x = scale, .y = scale * height, .z = scale}); treecount++; - } else if ((rand() & 3) == 0 && y < 0.4 && y > 0 && RANDF() < -nlayer) { + } else if ((rand() & 3) == 0 && y < H3DVF(0.4) && y > H3DVF(0) && + RANDF() < -nlayer) { // Generate flower of random-ish color - float scale = 0.04; - float vertscale = scale * (1 - 0.5 * RANDF()); + float scale = H3DVF(0.04); + float vertscale = scale * (H3DVF(1) - H3DVF(0.5) * RANDF()); haloo3d_obj_addobj( - &nl_model, flowers[nlayer > -0.9], - (struct vec3){ - .x = treepos.x, .y = y + vertscale * 0.5, .z = treepos.y}, + &nl_model, flowers[nlayer > H3DVF(-0.9)], + (struct vec3){.x = treepos.x, + .y = y + vertscale * H3DVF(0.5), + .z = treepos.y}, (struct vec3)DEFAULTLOOK, (struct vec3)DEFAULTUP, (struct vec3){.x = scale, .y = vertscale, .z = scale}); } @@ -865,6 +878,7 @@ int main() { // int argc, char **argv) { // Scale 3D into final buffer haloo3d_fb_fill(&screen, &context.window); +#ifndef NOPRINT // clang-format off haloo3d_print(&pt, "Pframe: %05.2f (%05.2f) DT: %0.3f\n" @@ -881,7 +895,8 @@ int main() { // int argc, char **argv) { playerpos->pos.x, playerpos->pos.z, #endif ecs.totaldrawn); - // clang-format on +// clang-format on +#endif // Finally, actually put buffer onto screen haloo3d_easytimer_start(&sdltimer);