From: matthew Date: Sun, 29 Jul 2018 19:59:51 +0000 (+0000) Subject: moved to a single array solution for board X-Git-Url: https://git.owens.tech///git?a=commitdiff_plain;h=a62f55d5c68b6e63ff5e5be235c789efe92be02c;p=csrpg.git moved to a single array solution for board --- diff --git a/common/board.c b/common/board.c index 33918fe..7b37abd 100644 --- a/common/board.c +++ b/common/board.c @@ -2,7 +2,7 @@ #include typedef struct { - Tile ***tiles; + Tile **tiles; Point2i dimensions; } Board_t; @@ -16,10 +16,17 @@ Board *board_init(int sizex, int sizey) b->dimensions.y = sizey; b->tiles = malloc(sizet * sizeof(Tile)); + //for(int x = 0; x < sizex; ++x){ + // b->tiles[x] = malloc(sizey * sizeof(Tile)); + // for(int y = 0; y < sizey; ++y){ + // b->tiles[x][y] = tile_init(point3i(x,y,1), PLAINS); + // } + //} for(int x = 0; x < sizex; ++x){ - b->tiles[x] = malloc(sizey * sizeof(Tile)); for(int y = 0; y < sizey; ++y){ - b->tiles[x][y] = tile_init(point3i(x,y,1), PLAINS); + + b->tiles[x + (y * sizey)] = + tile_init(point3i(x,y,1), PLAINS); } } @@ -33,7 +40,7 @@ void board_cleanup(Board *b) for(int i = 0; i < bt->dimensions.x; ++i){ for(int j = 0; j < bt->dimensions.y; ++j){ - tile_cleanup(bt->tiles[i][j]); + tile_cleanup(bt->tiles[i + (j*bt->dimensions.y)]); } } @@ -51,5 +58,5 @@ Tile* board_tile_at(Board* b, Point2i point) return NULL; } - return bt->tiles[point.x][point.y]; + return bt->tiles[point.x + (point.y * bt->dimensions.y)]; } diff --git a/nogl/main.c b/nogl/main.c index 878bc4f..6a30f67 100644 --- a/nogl/main.c +++ b/nogl/main.c @@ -34,10 +34,10 @@ int main() Point2i loc; Tile* sel = NULL; - for(int i = 0; i < 5; ++i){ - for(int j = 0; j < 3; ++j){ - loc.x = i; - loc.y = j; + for(int x = 0; x < 5; ++x){ + for(int y = 0; y < 3; ++y){ + loc.x = x; + loc.y = y; sel = board_tile_at(board, loc); if(sel == NULL){ printf("N");