From c2ad4f64d266b4c725ef383e8d14e9f5d303dfa8 Mon Sep 17 00:00:00 2001 From: Carlos Sanchez Date: Mon, 19 Aug 2024 13:05:16 -0400 Subject: [PATCH] Proper start spawn --- haloo3d | 2 +- maze.c | 34 ++++++++++++++++++++++------------ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/haloo3d b/haloo3d index e5ec412..a4b465b 160000 --- a/haloo3d +++ b/haloo3d @@ -1 +1 @@ -Subproject commit e5ec412b3b20ff87106aae1dc50148b0af7a071d +Subproject commit a4b465b82d9d4160fbba59f7d61b749dea066a5a diff --git a/maze.c b/maze.c index 8b2aa37..c328ee4 100644 --- a/maze.c +++ b/maze.c @@ -432,6 +432,7 @@ typedef struct { uint32_t timer; struct vec2i mpos; worldstate *ws; + haloo3d_obj_instance *startmarker; } ecs_smartai; static void sys_smartai(ecs_smartai *smartai, ecs_placement *p, @@ -444,16 +445,24 @@ static void sys_smartai(ecs_smartai *smartai, ecs_placement *p, // case we can spawn and face if (smartai->ws->state == WSTATE_SPINUP) { smartai->mpos = smartai->ws->start; - p->pos.x = smartai->ws->cellsize * (smartai->ws->start.x + 0.5); - p->pos.z = smartai->ws->cellsize * (smartai->ws->start.y + 0.5); - // Reset autonav - anav->dest = p->pos; - anav->timer = 0; smartai->dir = maze_longesthallway(smartai->ws->maze, MAZESIZE, smartai->ws->start.x, smartai->ws->start.y); + p->pos.x = smartai->ws->cellsize * (smartai->ws->start.x + 0.5); + p->pos.z = smartai->ws->cellsize * (smartai->ws->start.y + 0.5); p->rot.x = dirtoyaw(smartai->dir); - // reset autorotate + // Move startmarker to in front of player. + struct vec2i lookdir = dirtovec(smartai->dir); + smartai->startmarker->pos.x = p->pos.x + lookdir.x; + smartai->startmarker->pos.y = 0.0; + smartai->startmarker->pos.z = p->pos.z + lookdir.y; + vec3_subtract(smartai->startmarker->lookvec.v, p->pos.v, + smartai->startmarker->pos.v); + // To not face up or down, always set y = 0; + smartai->startmarker->lookvec.y = 0; + // Reset autonav + autorotate + anav->dest = p->pos; + anav->timer = 0; arot->dest = p->rot; arot->timer = 0; smartai->state = SAI_READY; @@ -662,7 +671,8 @@ int main() { // int argc, char **argv) { init_ceilingtexture(ceilt); init_walltexture(wallt); init_starttexture(startt); - haloo3d_gen_quad(starto, startt); + struct vec3 center = {.x = 0, .y = 0.5, .z = 0}; + haloo3d_gen_quad(starto, startt, center); eprintf("Initialized models and textures\n"); @@ -751,8 +761,11 @@ int main() { // int argc, char **argv) { ECS_SETCOMPONENT(&ecs, playerid, ecs_camera){.camera = &render.camera}; ECS_SETCOMPONENT(&ecs, playerid, ecs_autonav){.timer = 0}; ECS_SETCOMPONENT(&ecs, playerid, ecs_autorotate){.timer = 0}; - ECS_SETCOMPONENT(&ecs, playerid, ecs_smartai){ - .state = SAI_INIT, .ws = &wstate, .rotstate = 0, .timer = 0}; + ECS_SETCOMPONENT(&ecs, playerid, ecs_smartai){.state = SAI_INIT, + .ws = &wstate, + .rotstate = 0, + .timer = 0, + .startmarker = starti}; // ----------------------------------- // Actual rendering @@ -805,9 +818,6 @@ int main() { // int argc, char **argv) { } haloo3d_easytimer_end(&logictimer); - starti->pos = render.camera.pos; - starti->pos.z -= 1; - totaldrawn = 0; haloo3d_obj_instance *object = NULL;