From: John Tsiombikas Date: Fri, 9 Sep 2022 08:45:39 +0000 (+0300) Subject: foo X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=gbajam22;a=commitdiff_plain;h=5d7112b5fad9e69a556898a705eeef2307bb83d9 foo --- diff --git a/.gdbinit b/.gdbinit new file mode 100644 index 0000000..f4d7543 --- /dev/null +++ b/.gdbinit @@ -0,0 +1 @@ +target remote localhost:2345 diff --git a/src/gamescr.c b/src/gamescr.c index 840a9e4..5a2347d 100644 --- a/src/gamescr.c +++ b/src/gamescr.c @@ -93,6 +93,8 @@ static void update(void) bnstate = get_input(); player_input(&player, bnstate); + + upd_vis(lvl, player.x, player.y, player.theta); } static void draw(void) @@ -101,7 +103,6 @@ static void draw(void) xgl_rotate_x(player.phi); xgl_rotate_y(player.theta); xgl_translate(player.x, 0, player.y); - xgl_rotate_y(X_QPI); xgl_draw(XGL_QUADS, tm_floor, sizeof tm_floor / sizeof *tm_floor); } diff --git a/src/level.c b/src/level.c index dfe3475..0ae8d3e 100644 --- a/src/level.c +++ b/src/level.c @@ -74,3 +74,29 @@ void free_level(struct level *lvl) free(tmp); } } + +void upd_vis(struct level *lvl, int32_t px, int32_t py, int32_t angle) +{ + int cx, cy; + + lvl->numvis = 0; + + pos_to_cell(px, py, &cx, &cy); + + /* TODO: cont. */ +} + +void cell_to_pos(int cx, int cy, int32_t *px, int32_t *py) +{ + *px = cx * CELL_SIZE - (CELL_SIZE >> 1); + *py = cy * CELL_SIZE - (CELL_SIZE >> 1); +} + +void pos_to_cell(int32_t px, int32_t py, int *cx, int *cy) +{ + _Static_assert((CELL_SIZE & ~0xff) == CELL_SIZE, + "CELL_SIZE >> 8 in pos_to_cell will lose significant bits"); + + *cx = ((px + (CELL_SIZE >> 1)) << 8) / (CELL_SIZE >> 8); + *cy = ((py + (CELL_SIZE >> 1)) << 8) / (CELL_SIZE >> 8); +} diff --git a/src/level.h b/src/level.h index 0bcf578..95ab9d9 100644 --- a/src/level.h +++ b/src/level.h @@ -3,6 +3,9 @@ #include +/* cell size in 16.16 fixed point */ +#define CELL_SIZE 0x20000 + enum { MOBS_DEAD, MOBS_IDLE, MOBS_ENGAGE, MOBS_RUN }; struct mob { @@ -28,7 +31,7 @@ enum { CELL_SOLID, CELL_WALK }; struct cell { uint8_t type; uint8_t x, y; - uint8_t pad; + uint8_t rank; struct mob *mobs; struct item *items; }; @@ -40,10 +43,19 @@ struct level { struct mob *mobs; struct item *items; + + /* populated by calc_vis */ + struct cell **vis; + int numvis; }; struct level *init_level(const char *descstr); void free_level(struct level *lvl); +void upd_vis(struct level *lvl, int32_t px, int32_t py, int32_t angle); + +void cell_to_pos(int cx, int cy, int32_t *px, int32_t *py); +void pos_to_cell(int32_t px, int32_t py, int *cx, int *cy); + #endif /* LEVEL_H_ */