--- /dev/null
+target remote localhost:2345
bnstate = get_input();
player_input(&player, bnstate);
+
+ upd_vis(lvl, player.x, player.y, player.theta);
}
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);
}
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);
+}
#include <stdint.h>
+/* cell size in 16.16 fixed point */
+#define CELL_SIZE 0x20000
+
enum { MOBS_DEAD, MOBS_IDLE, MOBS_ENGAGE, MOBS_RUN };
struct mob {
struct cell {
uint8_t type;
uint8_t x, y;
- uint8_t pad;
+ uint8_t rank;
struct mob *mobs;
struct item *items;
};
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_ */