From: matthew Date: Sat, 4 Aug 2018 20:01:40 +0000 (+0100) Subject: implemented board_renderer, creating a bordered ncurses window for the board to be... X-Git-Url: https://git.owens.tech/assets/static/gitweb.css/assets/static/gitweb.css/git?a=commitdiff_plain;h=bc869e1ac1cfdaed682ddef23de9c058eb779df3;p=csrpg.git implemented board_renderer, creating a bordered ncurses window for the board to be drawn to --- diff --git a/nogl/board_renderer.c b/nogl/board_renderer.c new file mode 100644 index 0000000..9b02faa --- /dev/null +++ b/nogl/board_renderer.c @@ -0,0 +1,38 @@ +#include "board_renderer.h" +#include "point.h" + +static Board *b = NULL; +static WINDOW *win = NULL; +static Point2i winPos; +static Point2i winSize; + +void boardRenderer_init() +{ + Point2i termsize; + + winPos = point2i(0,0); + getmaxyx(stdscr, termsize.y, termsize.x); + winSize = termsize; + winSize.y -= 2; + + win = newwin(winSize.y, winSize.x, winPos.y, winPos.x); +} + +void boardRenderer_render() +{ + wborder(win, '|', '|', '-', '-', '+', '+', '+', '+'); + wrefresh(win); +} + +void boardRenderer_set_board(Board *board) +{ + b = board; +} + +void boardRenderer_cleanup() +{ + // clearing the border + wborder(win, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '); + b = NULL; + delwin(win); +} diff --git a/nogl/board_renderer.h b/nogl/board_renderer.h new file mode 100644 index 0000000..68ee1fa --- /dev/null +++ b/nogl/board_renderer.h @@ -0,0 +1,11 @@ +#ifndef BOARD_RENDERER_H +#define BOARD_RENDERER_H +#include +#include "board.h" + +void boardRenderer_init(); +void boardRenderer_render(); +void boardRenderer_cleanup(); +void boardRenderer_set_board(Board *board); + +#endif//BOARD_RENDERER_H diff --git a/nogl/main.c b/nogl/main.c index 4d6e839..fd2a7c1 100644 --- a/nogl/main.c +++ b/nogl/main.c @@ -3,6 +3,7 @@ #include #include "board.h" #include "point.h" +#include "board_renderer.h" #include static Board* board = NULL; @@ -15,6 +16,8 @@ bool init() } initscr(); + boardRenderer_init(); + curs_set(false); return true; } @@ -48,50 +51,11 @@ int main() return -1; } - Uint32 itime = SDL_GetTicks(); - Uint32 ctime = 0; - Point2i loc; - Point2i bsize = board_get_size(board); - Uint32 cclock = 0; - Uint32 pclock = SDL_GetTicks(); - Point2i rpos = point2i(10,10); // where to draw the arr - - char *reprs = malloc(bsize.x * bsize.y * sizeof(char)); - char *elevs = malloc(bsize.x * bsize.y * sizeof(char)); - char *sel = NULL; - - for(int y = 0; y < bsize.y; ++y){ - for(int x = 0; x < bsize.x; ++x){ - elevs[x + (bsize.x * y)] = - board_elevation_at(board, point2i(x, y)) + '0'; - reprs[x + (bsize.x * y)] = - tile_repr(board_terrain_at(board, point2i(x, y))); - } - } - - draw_borders(); - - // 'game' loop - while(ctime < itime + 5000){ - ctime = SDL_GetTicks(); - cclock = SDL_GetTicks(); - - // Switching the selection if needed - if(cclock > pclock + 500 || pclock == 0){ - sel = (sel == reprs) ? elevs : reprs; - pclock = cclock; - - for(int y = 0; y < bsize.y; ++y){ - for(int x = 0; x < bsize.x; ++x){ - mvaddch(y + rpos.y, x + rpos.x , sel[x + bsize.x * y]); - } - } - refresh(); - } - } - + boardRenderer_render(); + getchar(); SDL_Quit(); + boardRenderer_cleanup(); endwin(); return 0;