Cleanup maze, paintings work, good version

This commit is contained in:
Carlos Sanchez 2024-08-22 00:25:26 -04:00
parent aa0c785a49
commit 4fdd6f95e9
2 changed files with 12 additions and 50 deletions

56
maze.c
View File

@ -9,8 +9,6 @@
#include "unigi/unigi.headers/src/main.h"
#include "unigi/unigi.platform.sdl1/src/main.c"
#define ECS_MAXENTITIES 100
#include "ecs2.h"
#include "keys.h"
#include "maze_ecstypes.h"
@ -23,7 +21,7 @@
#define WIDTH 320
#define HEIGHT 200
#define ASPECT ((float)WIDTH / HEIGHT)
#define SCREENSCALE 1
#define SCREENSCALE 3
#define SWIDTH (WIDTH * SCREENSCALE)
#define SHEIGHT (HEIGHT * SCREENSCALE)
#define NEARCLIP 0.01
@ -32,9 +30,10 @@
#define AVGWEIGHT 0.85
// Game options
#define MAZESIZE 5
#define MAZESIZE 15
#define MAZEENDGAP (MAZESIZE / 5)
#define HSCALE 1.5
#define PAINTINGODDS 2
#define PAINTINGODDS 20
// Maze grows in the positive direction
#define MAZENORTH 1
@ -227,7 +226,8 @@ void maze_generate(uint8_t *maze, int size, struct vec2i *start,
do {
end->x = rand() % size;
end->y = rand() % size;
} while (abs(end->x - start->x) < 3 && abs(end->y - start->y) < 3);
} while (abs(end->x - start->x) < MAZEENDGAP &&
abs(end->y - start->y) < MAZEENDGAP);
eprintf("Maze generate: %d,%d -> %d,%d maxdepth: %d\n", start->x, start->y,
end->x, end->y, maxmazetop);
@ -417,7 +417,7 @@ void sys_dieoninit(ecs_dieoninit *die, mecs **ecs) {
}
void sys_world(ecs_world *w, mecs **ecs) {
const int spinspeed = w->state->fps * 4.0 / (5 * speed);
const int spinspeed = fps * 4.0 / (5 * speed);
switch (w->state->state) {
case WSTATE_INIT:
// We don't need to free anything created from previous runs; they delete
@ -477,7 +477,7 @@ int smartai_mazeend(ecs_smartai *smartai) {
void sys_smartai(ecs_smartai *smartai, ecs_placement *p, ecs_autonav *anav,
ecs_autorotate *arot) {
const int actiontime = smartai->ws->fps / (2 * speed);
const int actiontime = fps / (2 * speed);
const int rotdelaytime = actiontime / 2; // 2 * actiontime / 5;
switch (smartai->state) {
case SAI_INIT:
@ -592,41 +592,6 @@ ECS_SYSTEM2(mecs, sys_camera, ecs_camera, ecs_placement);
ECS_SYSTEM4(mecs, sys_smartai, ecs_smartai, ecs_placement, ecs_autonav,
ecs_autorotate);
// typedef struct {
// haloo3d_easyrender *render;
// haloo3d_obj_instance *paintings[MAXPAINTINGS];
// ecs_eid paintingecs[MAXPAINTINGS];
// haloo3d_fb *texture;
// haloo3d_obj *model;
// mecs *ecs;
// mfloat_t *scaleto;
// int *scaletimer;
// int numpaintings;
// } paintingmanager;
//
// void pm_add_painting(paintingmanager *pm) {
// if (pm->numpaintings < MAXPAINTINGS) {
// pm->paintings[pm->numpaintings] =
// haloo3d_easyrender_addinstance(pm->render, pm->model, pm->texture);
// ecs_eid id = mecs_newentity(pm->ecs, 0);
// ECS_SETCOMPONENT(pm->ecs, id,
// ecs_syncgrow){.obj = pm->paintings[pm->numpaintings],
// .scale = pm->scaleto,
// .basescale = 1,
// .timer = pm->scaletimer};
// pm->paintingecs[pm->numpaintings] = id;
// pm->numpaintings++;
// }
// }
//
// void pm_clear_all(paintingmanager * pm) {
// for(int i = 0; i < pm->numpaintings; i++) {
// mecs_deleteentity(pm->ecs, pm->paintingecs[i]);
// haloo3d_easyrender_deleteinstance(pm->render, pm->paintings[i]);
// }
// pm->numpaintings = 0;
// }
void init_floortexture(haloo3d_fb *floort) {
uint16_t cols[1] = {0xFD93};
haloo3d_fb_init_tex(floort, 64, 64);
@ -844,7 +809,6 @@ int main() { // int argc, char **argv) {
uint8_t maze[MAZESIZE * MAZESIZE];
wstate.size = MAZESIZE;
wstate.maze = maze;
wstate.fps = fps;
wstate.state = WSTATE_INIT;
wstate.cellsize = HSCALE;
@ -894,7 +858,7 @@ int main() { // int argc, char **argv) {
haloo3d_debugconsole_init(&dc);
haloo3d_debugconsole_set(&dc, "game/speed.f", &speed);
haloo3d_debugconsole_set(&dc, "render/fps.i", &wstate.fps);
haloo3d_debugconsole_set(&dc, "render/fps.i", &fps);
haloo3d_debugconsole_set(&dc, "render/fov.f", &fov);
haloo3d_debugconsole_set(&dc, "render/trifunc.i", &render.trifunc);
haloo3d_debugconsole_set(&dc, "render/ditherstart.f", &ditherstart);
@ -1052,7 +1016,7 @@ int main() { // int argc, char **argv) {
haloo3d_easytimer_end(&frametimer);
float waittime = (1.0 / wstate.fps) - frametimer.last;
float waittime = (1.0 / fps) - frametimer.last;
if (waittime > 0) {
unigi_time_sleep(waittime * unigi_time_clocks_per_s);
}

View File

@ -8,11 +8,9 @@
// Turning into a blob? IDK. Maybe certain things should be
// global state, which is this.
typedef struct {
// float timedelta;
int fps;
uint8_t state;
uint8_t *maze; //[MAZESIZE * MAZESIZE];
int size; // The length of an edge, guaranteed to be a square
uint8_t *maze;
int size; // The length of an edge, guaranteed to be a square
// A suggested start and end. The end is the actual
// end, where we put the ending indicator
struct vec2i start;