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 { typedef struct Options {
size_t refresh_rate; size_t refresh_rate;
size_t animation_speed;
size_t max_heat_loss; size_t max_heat_loss;
size_t wind; size_t wind;
size_t random_factor; size_t random_factor;

2
draw.c
View File

@ -41,7 +41,7 @@ init(struct buffer *buf)
// calloc sets the entire screen to black // calloc sets the entire screen to black
// ...except for the last row, which is white. // ...except for the last row, which is white.
// this is the 'base' of the fire. // 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 // update the framebuffer

31
main.c
View File

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