add animation_speed control

This commit is contained in:
Kiëd Llaentenn 2020-09-17 18:34:19 +00:00
parent 7a417130c9
commit 85794e888f
3 changed files with 31 additions and 15 deletions

1
args.h
View File

@ -25,6 +25,7 @@ extern char *argv0;
typedef struct Options {
size_t refresh_rate;
size_t animation_speed;
size_t max_heat_loss;
size_t wind;
size_t random_factor;

2
draw.c
View File

@ -41,7 +41,7 @@ init(struct buffer *buf)
// calloc sets the entire screen to black
// ...except for the last row, which is white.
// this is the 'base' of the fire.
memset(buf->buf + len, 12, buf->width);
memset(buf->buf + len, opts->truecolor ? 35 : 12, buf->width);
}
// update the framebuffer

31
main.c
View File

@ -27,7 +27,8 @@ main(int argc, char *argv[])
}
// default args
opts->refresh_rate = 5;
opts->animation_speed = 5;
opts->refresh_rate = 1;
size_t output_mode = TB_OUTPUT_NORMAL;
opts->truecolor = FALSE;
opts->max_heat_loss = 1;
@ -43,6 +44,9 @@ main(int argc, char *argv[])
output_mode = TB_OUTPUT_TRUECOLOR;
opts->truecolor = TRUE;
break;
case 's':
opts->animation_speed = atoi(ARGF());
break;
case 'r':
opts->refresh_rate = atoi(ARGF());
break;
@ -63,10 +67,13 @@ main(int argc, char *argv[])
return 0;
case 'h':
default:
printf("Usage: %s [-RtVh] [-r speed] [-l loss] [-w wind] [-f fact]\n", argv0);
printf("Usage: %s [-RtVh] [-r rate] [-s speed] [-l loss] [-w wind] [-f fact]\n", argv0);
printf("Display a nice fiery animation.\n\n");
printf("ARGUMENTS:\n");
printf(" -r [speed] Change refresh rate. (default: 5)\n");
printf(" -r [rate] Change refresh rate. (default: 1)\n");
printf(" Higher values == slower refresh rate.\n");
printf(" -s [speed] Change animation speed. (default: 5)\n");
printf(" Higher values == slower animation.\n");
printf(" -l [loss] Maximum heat loss for each row upward. (default: 1)\n");
printf(" Higher values will lead to a smaller fire.\n");
printf(" -w [wind] Wind. Negative values, or values less than one will\n");
@ -80,10 +87,10 @@ main(int argc, char *argv[])
printf(" -h Display this help message and exit.\n");
printf(" -V Display version and exit.\n\n");
printf("EXAMPLES:\n");
printf(" %s 'Normal' fire.\n");
printf(" %s -Rw0 -f100 Cmatrix-esque effect.\n");
printf(" %s -l2 -w2 Small fire with wind blowing east.\n");
printf(" %s -Rw0 -f10000000 Heatwaves!\n");
printf(" %s 'Normal' fire.\n", argv0);
printf(" %s -Rw0 -f100 Cmatrix-esque effect.\n", argv0);
printf(" %s -l2 -w2 Small fire with wind blowing east.\n", argv0);
printf(" %s -Rw0 -f10000000 Heatwaves!\n", argv0);
printf("(c) Kiëd Llaentenn, nullgemm\n");
printf("https://github.com/lptstr/fire\n");
@ -100,16 +107,24 @@ main(int argc, char *argv[])
// initialize drawing
init(&buf);
uint64_t ctr = 0;
// animate
while (TRUE) {
ctr += 1;
// update framebuffer
dofire(&buf);
if ((ctr % opts->refresh_rate) != 0) {
continue;
}
// draw framebuffer to terminal
tb_present();
// event handling
int err = (size_t) tb_peek_event(&e, opts->refresh_rate);
int err = (size_t) tb_peek_event(&e, opts->animation_speed);
if (err < 0) {
continue;