More customization

This commit is contained in:
Carlos Sanchez 2024-08-24 14:46:33 -04:00
parent 165dc24bba
commit 9f73d6b1fd

67
maze.c
View File

@ -15,8 +15,11 @@
#include <stdlib.h>
// INteresting flags for performance comparisons
// INteresting flags for debugging
#define FASTFILL
#define NUMMICE 1
#define MOUSELOGGING
// #define NOWALLS
#define WIDTH 480
#define HEIGHT 300
@ -48,7 +51,7 @@
#define PRINTMAZE
// Max amount of flip polys to generate in maze. actual amount can be lower,
// but there will always at least be 1
#define MAXFLIPPOLYS 6
#define MAXFLIPPOLYS 5
// Min space between flip polys
#define FLIPPOLYBUFFER 3
@ -88,7 +91,7 @@ float ditherend = 8;
float fov = 90.0;
float minlight = 0.15;
float speed = 1.0;
int fps = 45;
int fps = 30;
uint16_t sky = 0xF000;
struct vec2i dirtovec(uint8_t dir) {
@ -446,10 +449,10 @@ void sys_world(ecs_world *w, mecs **ecs) {
if (m.x == w->state->start.x && m.y == w->state->start.y) {
continue;
}
for (int yc = m.y - FLIPPOLYBUFFER; yc < m.y + FLIPPOLYBUFFER; yc++) {
for (int yc = m.y - FLIPPOLYBUFFER; yc <= m.y + FLIPPOLYBUFFER; yc++) {
if (yc < 0 || yc >= w->state->size)
continue;
for (int xc = m.x - FLIPPOLYBUFFER; xc < m.x + FLIPPOLYBUFFER; xc++) {
for (int xc = m.x - FLIPPOLYBUFFER; xc <= m.x + FLIPPOLYBUFFER; xc++) {
if (xc < 0 || xc >= w->state->size)
continue;
if (w->state->maze[m.x + m.y * w->state->size] & MAZEFLIP) {
@ -691,20 +694,26 @@ void sys_mouseai(ecs_mouseai *mouseai, ecs_placement *p, ecs_autonav *anav) {
anav->dest = p->pos;
anav->timer = 0;
mouseai->state = SAI_READY;
#ifdef MOUSELOGGING
eprintf("MOUSE READY: %f %f, waiting for spinup\n", anav->dest.x,
anav->dest.z);
#endif
}
break;
case SAI_READY:
if (mouseai->ws->state == WSTATE_GAMEPLAY) {
mouseai->state = SAI_GAMEPLAY;
#ifdef MOUSELOGGING
eprintf("MOUSE STARTING GAMEPLAY\n");
#endif
}
break;
case SAI_GAMEPLAY:
// Normal gameplay: move through the maze, etc.
if (mouseai->ws->state != WSTATE_GAMEPLAY) {
#ifdef MOUSELOGGING
eprintf("GAMEPLAY OVER, MOUSE RESETTING\n");
#endif
mouseai->state = SAI_INIT;
anav->timer = 0; // Stop moving
return;
@ -712,8 +721,10 @@ void sys_mouseai(ecs_mouseai *mouseai, ecs_placement *p, ecs_autonav *anav) {
// Only decide to do things if you're not moving anymore. Movement is the
// most important thing
if (anav->timer == 0) {
#ifdef MOUSELOGGING
eprintf("MOUSEAI DIR: %d POS: (%f, %f)\n", mouseai->dir, p->pos.x,
p->pos.z);
#endif
// Look left or right randomly. You can affect how "straight" the mouse
// moves by increasing the MOUSETURNRAND
uint8_t ndir;
@ -1032,14 +1043,9 @@ int main() { // int argc, char **argv) {
haloo3d_easyrender_addinstance(&render, starto, startt);
haloo3d_obj_instance *endi =
haloo3d_easyrender_addinstance(&render, endo, endt);
haloo3d_obj_instance *mousei =
haloo3d_easyrender_addinstance(&render, mouseo, mouset);
init_mazeinstances(floori, ceili, walli);
init_billboard(starti, 1.0);
init_billboard(endi, 0.25);
init_billboard(mousei, MOUSESCALE);
// Mouse should be near the floor
mousei->pos.y = MOUSESCALE;
eprintf("Setup all static object instances\n");
unigi_type_event event;
@ -1094,7 +1100,11 @@ int main() { // int argc, char **argv) {
ECS_SETCOMPONENT(&ecs, wallid, ecs_syncgrow){
.obj = walli,
.scale = &eworld->scaleto,
.basescale = 1, // can't set to scale because hscale
#ifdef NOWALLS
.basescale = 0, // can't set to scale because hscale
#else
.basescale = 1,
#endif
.timer = &eworld->scaletimer};
ecs_eid startid = mecs_newentity(&ecs, 0);
ECS_SETCOMPONENT(&ecs, startid, ecs_syncgrow){.obj = starti,
@ -1127,20 +1137,27 @@ int main() { // int argc, char **argv) {
.upsidedown = 0,
.startmarker = starti};
ecs_eid mouseid = mecs_newentity(&ecs, 0);
eprintf("Mouse eid: %d\n", mouseid);
ECS_SETCOMPONENT(&ecs, mouseid, ecs_placement){.pos = mousei->pos,
.rot = {.x = 0, .y = 0}};
ECS_SETCOMPONENT(&ecs, mouseid, ecs_autonav){.timer = 0};
ECS_SETCOMPONENT(&ecs, mouseid, ecs_object) mousei;
ECS_SETCOMPONENT(&ecs, mouseid, ecs_mouseai){.state = SAI_INIT,
.ws = &wstate};
ECS_SETCOMPONENT(&ecs, mouseid, ecs_billboard){.obj = mousei,
.lookat = &render.camera.pos};
ECS_SETCOMPONENT(&ecs, mouseid, ecs_syncgrow){.obj = mousei,
.scale = &eworld->scaleto,
.basescale = mousei->scale.x,
.timer = &eworld->scaletimer};
for (int i = 0; i < NUMMICE; i++) {
haloo3d_obj_instance *mousei =
haloo3d_easyrender_addinstance(&render, mouseo, mouset);
init_billboard(mousei, MOUSESCALE);
// Mouse should be near the floor
mousei->pos.y = MOUSESCALE;
ecs_eid mouseid = mecs_newentity(&ecs, 0);
eprintf("Mouse eid: %d\n", mouseid);
ECS_SETCOMPONENT(&ecs, mouseid, ecs_placement){.pos = mousei->pos,
.rot = {.x = 0, .y = 0}};
ECS_SETCOMPONENT(&ecs, mouseid, ecs_autonav){.timer = 0};
ECS_SETCOMPONENT(&ecs, mouseid, ecs_object) mousei;
ECS_SETCOMPONENT(&ecs, mouseid, ecs_mouseai){.state = SAI_INIT,
.ws = &wstate};
ECS_SETCOMPONENT(&ecs, mouseid, ecs_billboard){
.obj = mousei, .lookat = &render.camera.pos};
ECS_SETCOMPONENT(&ecs, mouseid, ecs_syncgrow){.obj = mousei,
.scale = &eworld->scaleto,
.basescale = mousei->scale.x,
.timer = &eworld->scaletimer};
}
// -----------------------------------
// Actual rendering