From bf04799fd08b2f45c3f912911ffaf96feccfb511 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Mon, 24 Oct 2022 04:36:40 +0300 Subject: [PATCH] removed old level and player data structures from the original game idea --- src/gamescr.c | 2 - src/level.c | 175 --------------------------------------------------------- src/level.h | 66 ---------------------- src/player.c | 52 ----------------- src/player.h | 19 ------- 5 files changed, 314 deletions(-) delete mode 100644 src/level.c delete mode 100644 src/level.h delete mode 100644 src/player.c delete mode 100644 src/player.h diff --git a/src/gamescr.c b/src/gamescr.c index b923a73..c422119 100644 --- a/src/gamescr.c +++ b/src/gamescr.c @@ -6,11 +6,9 @@ #include "util.h" #include "intr.h" #include "input.h" -#include "player.h" #include "gba.h" #include "sprite.h" #include "debug.h" -#include "level.h" #include "voxscape.h" #include "data.h" diff --git a/src/level.c b/src/level.c deleted file mode 100644 index d74d52f..0000000 --- a/src/level.c +++ /dev/null @@ -1,175 +0,0 @@ -#include "util.h" -#include "debug.h" -#include "level.h" -#include "player.h" -#include "xgl.h" - -struct level *init_level(const char *descstr) -{ - const char *str, *line; - int i, j, x, ncols = 0, nrows = 0; - struct level *lvl; - struct cell *cell; - - str = line = descstr; - - while(*str) { - if(*str == '\n') { - if(ncols > 0 && str > line && str - line != ncols) { - panic(get_pc(), "init_level: inconsistent ncols (%d != %d)\n", str - line, ncols); - } - ncols = str - line; - nrows++; - while(*++str == '\n'); - line = str; - } else { - str++; - } - } - - if(!ispow2(ncols)) { - panic(get_pc(), "init_level: width is not pow2 (%d)\n", ncols); - } - - lvl = malloc_nf(sizeof *lvl); - lvl->width = ncols; - lvl->xmask = ncols - 1; - lvl->height = nrows; - lvl->orgx = lvl->width >> 1; - lvl->orgy = lvl->height >> 1; - lvl->cells = calloc_nf(ncols * nrows, sizeof *lvl->cells); - lvl->mobs = 0; - lvl->items = 0; - - lvl->xshift = 0; - x = ncols - 1; - while(x) { - x >>= 1; - lvl->xshift++; - } - - str = descstr; - cell = lvl->cells; - - for(i=0; ix = j; - cell->y = i; - if(*str == '#') { - cell->type = CELL_SOLID; - } else { - cell->type = CELL_WALK; - switch(*str) { - case 's': - lvl->orgx = j; - lvl->orgy = i; - break; - } - } - cell++; - while(*++str == '\n') str++; - } - } - - return lvl; -} - -void free_level(struct level *lvl) -{ - void *tmp; - - free(lvl->cells); - - while(lvl->mobs) { - tmp = lvl->mobs; - lvl->mobs = lvl->mobs->next; - free(tmp); - } - while(lvl->items) { - tmp = lvl->items; - lvl->items = lvl->items->next; - free(tmp); - } -} - -struct cell *level_cell(struct level *lvl, int cx, int cy) -{ - return lvl->cells + (cy << lvl->xshift) + cx; -} - -/* generated with tools/vistab */ -struct {int dx, dy;} visoffs[8][32] = { - /* dir 0 */ - {{-4,-4}, {4,-4}, {-3,-4}, {3,-4}, {-2,-4}, {2,-4}, {-3,-3}, {3,-3}, {-1,-4}, - {1,-4}, {0,-4}, {-2,-3}, {2,-3}, {-1,-3}, {1,-3}, {0,-3}, {-2,-2}, {2,-2}, - {-1,-2}, {1,-2}, {0,-2}, {-1,-1}, {1,-1}, {0,-1}, {0,0}}, - /* dir 1 */ - {{4,-4}, {3,-4}, {4,-3}, {2,-4}, {4,-2}, {3,-3}, {1,-4}, {4,-1}, {0,-4}, - {4,0}, {2,-3}, {3,-2}, {1,-3}, {3,-1}, {0,-3}, {3,0}, {2,-2}, {1,-2}, - {2,-1}, {0,-2}, {2,0}, {1,-1}, {0,-1}, {1,0}, {0,0}}, - /* dir 2 */ - {{4,-4}, {4,4}, {4,-3}, {4,3}, {4,-2}, {4,2}, {3,-3}, {3,3}, {4,-1}, {4,1}, - {4,0}, {3,-2}, {3,2}, {3,-1}, {3,1}, {3,0}, {2,-2}, {2,2}, {2,-1}, {2,1}, - {2,0}, {1,-1}, {1,1}, {1,0}, {0,0}}, - /* dir 3 */ - {{4,4}, {4,3}, {3,4}, {4,2}, {2,4}, {3,3}, {4,1}, {1,4}, {4,0}, {0,4}, - {3,2}, {2,3}, {3,1}, {1,3}, {3,0}, {0,3}, {2,2}, {2,1}, {1,2}, {2,0}, - {0,2}, {1,1}, {1,0}, {0,1}, {0,0}}, - /* dir 4 */ - {{-4,4}, {4,4}, {-3,4}, {3,4}, {-2,4}, {2,4}, {-3,3}, {3,3}, {-1,4}, {1,4}, - {0,4}, {-2,3}, {2,3}, {-1,3}, {1,3}, {0,3}, {-2,2}, {2,2}, {-1,2}, {1,2}, - {0,2}, {-1,1}, {1,1}, {0,1}, {0,0}}, - /* dir 5 */ - {{-4,4}, {-4,3}, {-3,4}, {-4,2}, {-2,4}, {-3,3}, {-4,1}, {-1,4}, {-4,0}, - {0,4}, {-3,2}, {-2,3}, {-3,1}, {-1,3}, {-3,0}, {0,3}, {-2,2}, {-2,1}, - {-1,2}, {-2,0}, {0,2}, {-1,1}, {-1,0}, {0,1}, {0,0}}, - /* dir 6 */ - {{-4,-4}, {-4,4}, {-4,-3}, {-4,3}, {-4,-2}, {-4,2}, {-3,-3}, {-3,3}, {-4,-1}, - {-4,1}, {-4,0}, {-3,-2}, {-3,2}, {-3,-1}, {-3,1}, {-3,0}, {-2,-2}, {-2,2}, - {-2,-1}, {-2,1}, {-2,0}, {-1,-1}, {-1,1}, {-1,0}, {0,0}}, - /* dir 7 */ - {{-4,-4}, {-3,-4}, {-4,-3}, {-2,-4}, {-4,-2}, {-3,-3}, {-1,-4}, {-4,-1}, - {0,-4}, {-4,0}, {-2,-3}, {-3,-2}, {-1,-3}, {-3,-1}, {0,-3}, {-3,0}, {-2,-2}, - {-1,-2}, {-2,-1}, {0,-2}, {-2,0}, {-1,-1}, {0,-1}, {-1,0}, {0,0}} -}; - -void upd_vis(struct level *lvl, struct player *p) -{ - int dir, idx; - int x, y; - struct cell *cptr; - int32_t theta; - - pos_to_cell(lvl, p->x, p->y, &p->cx, &p->cy); - - lvl->numvis = 0; - idx = -1; - theta = X_2PI - p->theta + X_2PI / 16; - if(theta >= X_2PI) theta -= X_2PI; - dir = (theta << 3) / X_2PI; /* p->theta is always [0, 2pi) */ - if(dir < 0 || dir >= 8) { - panic(get_pc(), "dir: %d\ntheta: %d.%d (%d)\n", dir, p->theta >> 16, - p->theta & 0xffff, p->theta); - } - do { - idx++; - x = p->cx + visoffs[dir][idx].dx; - y = p->cy + visoffs[dir][idx].dy; - cptr = lvl->cells + y * lvl->width + x; - if(cptr->type != CELL_SOLID) { - lvl->vis[lvl->numvis++] = cptr; - } - } while(visoffs[dir][idx].dx | visoffs[dir][idx].dy); -} - -void cell_to_pos(struct level *lvl, int cx, int cy, int32_t *px, int32_t *py) -{ - *px = (cx - lvl->orgx) * CELL_SIZE; - *py = (cy - lvl->orgy) * CELL_SIZE; -} - -void pos_to_cell(struct level *lvl, int32_t px, int32_t py, int *cx, int *cy) -{ - *cx = (px + (CELL_SIZE >> 1)) / CELL_SIZE + lvl->orgx; - *cy = (py + (CELL_SIZE >> 1)) / CELL_SIZE + lvl->orgy; -} diff --git a/src/level.h b/src/level.h deleted file mode 100644 index dc9af8d..0000000 --- a/src/level.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef LEVEL_H_ -#define LEVEL_H_ - -#include - -/* cell size in 16.16 fixed point */ -#define CELL_SIZE 0x20000 - -enum { MOBS_DEAD, MOBS_IDLE, MOBS_ENGAGE, MOBS_RUN }; - -struct mob { - uint8_t type; - uint8_t x, y; - uint8_t state; - struct mob *next; - struct mob *cellnext; - - void (*update)(void); -}; - -struct item { - uint8_t type; - uint8_t x, y; - uint8_t pad; - struct item *next; - struct item *cellnext; -}; - -enum { CELL_SOLID, CELL_WALK }; - -struct cell { - uint8_t type; - uint8_t x, y; - uint8_t rank; - struct mob *mobs; - struct item *items; -}; - -struct level { - int width, height; - int orgx, orgy; - unsigned int xmask; - int xshift; - struct cell *cells; - - struct mob *mobs; - struct item *items; - - /* populated by calc_vis */ - struct cell *vis[128]; - int numvis; -}; - -struct player; - -struct level *init_level(const char *descstr); -void free_level(struct level *lvl); - -struct cell *level_cell(struct level *lvl, int cx, int cy); - -void upd_vis(struct level *lvl, struct player *p); - -void cell_to_pos(struct level *lvl, int cx, int cy, int32_t *px, int32_t *py); -void pos_to_cell(struct level *lvl, int32_t px, int32_t py, int *cx, int *cy); - -#endif /* LEVEL_H_ */ diff --git a/src/player.c b/src/player.c deleted file mode 100644 index 6c97e38..0000000 --- a/src/player.c +++ /dev/null @@ -1,52 +0,0 @@ -#include -#include "game.h" -#include "player.h" -#include "level.h" -#include "gbaregs.h" -#include "xgl.h" - -void init_player(struct player *p, struct level *lvl) -{ - memset(p, 0, sizeof *p); - p->cx = lvl->orgx; - p->cy = lvl->orgy; - cell_to_pos(lvl, lvl->orgx, lvl->orgy, &p->x, &p->y); - p->cell = level_cell(lvl, lvl->orgx, lvl->orgy); -} - -void player_input(struct player *p, uint16_t bnstate) -{ -#ifndef BUILD_GBA - p->theta = (p->theta + view_dtheta) % X_2PI; - if(p->theta < 0) p->theta += X_2PI; - p->phi += view_dphi; - if(p->phi > X_HPI) p->phi = X_HPI; - if(p->phi < -X_HPI) p->phi = -X_HPI; - - view_dtheta = 0; - view_dphi = 0; -#endif - - if(bnstate & KEY_UP) { - p->phi += 0x800; - if(p->phi > X_HPI) p->phi = X_HPI; - } - if(bnstate & KEY_DOWN) { - p->phi -= 0x800; - if(p->phi < -X_HPI) p->phi = -X_HPI; - } - if(bnstate & KEY_LEFT) { - p->theta += 0x800; - if(p->theta >= X_2PI) p->theta -= X_2PI; - } - if(bnstate & KEY_RIGHT) { - p->theta -= 0x800; - if(p->theta < 0) p->theta += X_2PI; - } - if(bnstate & KEY_A) { - p->y += 0x2000; - } - if(bnstate & KEY_B) { - p->y -= 0x2000; - } -} diff --git a/src/player.h b/src/player.h deleted file mode 100644 index 7636af5..0000000 --- a/src/player.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef PLAYER_H_ -#define PLAYER_H_ - -#include - -struct cell; -struct level; - -struct player { - int32_t x, y; - int32_t theta, phi; - int cx, cy; - struct cell *cell; -}; - -void init_player(struct player *p, struct level *lvl); -void player_input(struct player *p, uint16_t bnstate); - -#endif /* PLAYER_H_ */ -- 1.7.10.4