Skip to content

Commit

Permalink
Render scene in test
Browse files Browse the repository at this point in the history
  • Loading branch information
tene committed Mar 20, 2012
1 parent 3e176ce commit 2c592de
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
2 changes: 2 additions & 0 deletions gridfluid.c
Expand Up @@ -31,6 +31,8 @@ static const uint8_t rindex[9] = {

gridfluid_t gridfluid_create_empty_scene(uint8_t x, uint8_t y) {
gridfluid_t gf = calloc(1, sizeof(struct gridfluid));
gf->x = x;
gf->y = y;
gf->grid = calloc(x*y, sizeof(gridfluid_cell_t));
gf->nextgrid = calloc(x*y, sizeof(gridfluid_cell_t));
for (uint8_t i = 1; i < x-1; i++) {
Expand Down
47 changes: 34 additions & 13 deletions test.c
Expand Up @@ -4,6 +4,34 @@
#include <unistd.h>
#include <assert.h>

void render(gridfluid_t gf) {
set_bg(rgb_f(0,0,0));
for (int x=0; x<40; x++) {
for (int y=0; y<20; y++) {
curs_xy(x,y);
switch(gridfluid_get_type(gf,x,y)) {
case GF_OBSTACLE:
set_fg(rgb_f(1,1,1));
set_bg(rgb_f(1,1,1));
break;
case GF_EMPTY:
set_fg(rgb_f(0,0,0));
set_bg(rgb_f(0,0,0));
break;
case GF_FLUID:
set_fg(rgb_f(0,0,1));
set_bg(rgb_f(0,0,1));
break;
case GF_INTERFACE:
set_fg(rgb_f(0,0,0.5));
set_bg(rgb_f(0,0,0.5));
break;
}
printf("█");
}
}
}

int main() {
gridfluid_t gf = gridfluid_create_empty_scene(40,20);
gridfluid_set_obstacle(gf,5,7);
Expand All @@ -14,23 +42,16 @@ int main() {
printf("Failed to setup screen; exiting\n");
return(1);
}
set_fg(rgb_f(1,1,1));
set_bg(rgb_f(0,0,0));
curs_xy(30,5);
printf("lol\n");
set_fg(rgb_f(1,0,0));
set_bg(rgb_f(0,0,1));
curs_xy(100,5);
printf("ohai\n");

set_fg(rgb_f(1,1,1));
set_bg(rgb_f(0,0,0));

ssize_t len;
unsigned char buf[1];
int running = 1;
curs_xy(10,10);
while (running) {
render(gf);
curs_xy(10,30);
set_fg(rgb_f(1,1,1));
set_bg(rgb_f(0,0,0));

len = read(0, buf, 1);
if (len == -1) {
perror("read: ");
Expand All @@ -41,7 +62,7 @@ int main() {
running = 0;
break;
default:
//printf("read: %3u\n", buf[0]);
printf("read: %3u ", buf[0]);
break;
}
}
Expand Down

0 comments on commit 2c592de

Please sign in to comment.