mirror of
https://github.com/kiedtl/fire.git
synced 2024-12-22 14:16:43 +00:00
style changes
This commit is contained in:
parent
da742e282d
commit
6c076eb2a9
6
draw.c
6
draw.c
@ -19,7 +19,7 @@ extern struct Options *opts;
|
|||||||
|
|
||||||
// initialize the framebuffer
|
// initialize the framebuffer
|
||||||
void
|
void
|
||||||
init ( struct buffer *buf )
|
init(struct buffer *buf)
|
||||||
{
|
{
|
||||||
// initialize width/height of terminal
|
// initialize width/height of terminal
|
||||||
buf->width = tb_width();
|
buf->width = tb_width();
|
||||||
@ -45,7 +45,7 @@ init ( struct buffer *buf )
|
|||||||
|
|
||||||
// update the framebuffer
|
// update the framebuffer
|
||||||
void
|
void
|
||||||
dofire ( struct buffer *buf )
|
dofire(struct buffer *buf)
|
||||||
{
|
{
|
||||||
size_t src;
|
size_t src;
|
||||||
size_t random;
|
size_t random;
|
||||||
@ -85,7 +85,7 @@ dofire ( struct buffer *buf )
|
|||||||
|
|
||||||
// free framebuffer and shutdown termbox
|
// free framebuffer and shutdown termbox
|
||||||
void
|
void
|
||||||
cleanup ( struct buffer *buf )
|
cleanup(struct buffer *buf)
|
||||||
{
|
{
|
||||||
free(buf->buf);
|
free(buf->buf);
|
||||||
tb_shutdown();
|
tb_shutdown();
|
||||||
|
15
draw.h
15
draw.h
@ -7,16 +7,15 @@
|
|||||||
#include "stdint.h"
|
#include "stdint.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct buffer
|
struct buffer {
|
||||||
{
|
size_t width;
|
||||||
size_t width;
|
size_t height;
|
||||||
size_t height;
|
|
||||||
|
|
||||||
uint8_t* buf;
|
uint8_t* buf;
|
||||||
} buffer;
|
};
|
||||||
|
|
||||||
void init ( struct buffer *buf );
|
void init(struct buffer *buf);
|
||||||
void dofire ( struct buffer *buf );
|
void dofire(struct buffer *buf);
|
||||||
void cleanup ( struct buffer *buf );
|
void cleanup(struct buffer *buf);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
36
main.c
36
main.c
@ -23,14 +23,13 @@ main ( int argc, char *argv[] )
|
|||||||
{
|
{
|
||||||
opts = (struct Options*) calloc(1, sizeof(struct Options*));
|
opts = (struct Options*) calloc(1, sizeof(struct Options*));
|
||||||
if (opts == NULL) {
|
if (opts == NULL) {
|
||||||
EPRINT("fire: error: cannot ");
|
perror("fire: error: calloc()");
|
||||||
perror("calloc()");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// default args
|
// default args
|
||||||
opts->refresh_rate = 5;
|
opts->refresh_rate = 5;
|
||||||
opts->truecolor = FALSE;
|
|
||||||
size_t output_mode = TB_OUTPUT_NORMAL;
|
size_t output_mode = TB_OUTPUT_NORMAL;
|
||||||
|
opts->truecolor = FALSE;
|
||||||
|
|
||||||
// argument parsing
|
// argument parsing
|
||||||
argv0 = argv[0];
|
argv0 = argv[0];
|
||||||
@ -45,7 +44,7 @@ main ( int argc, char *argv[] )
|
|||||||
break;
|
break;
|
||||||
case 'V':
|
case 'V':
|
||||||
printf("%s %s\n", argv0, VERSION);
|
printf("%s %s\n", argv0, VERSION);
|
||||||
exit(EXIT_SUCCESS);
|
return 0;
|
||||||
case 'h':
|
case 'h':
|
||||||
default:
|
default:
|
||||||
printf("Usage: %s [-tVh] [-r rate]\n", argv0);
|
printf("Usage: %s [-tVh] [-r rate]\n", argv0);
|
||||||
@ -58,7 +57,7 @@ main ( int argc, char *argv[] )
|
|||||||
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");
|
||||||
|
|
||||||
exit(EXIT_SUCCESS);
|
return 0;
|
||||||
} ARGEND
|
} ARGEND
|
||||||
|
|
||||||
// initialize termbox
|
// initialize termbox
|
||||||
@ -72,11 +71,7 @@ main ( int argc, char *argv[] )
|
|||||||
init(&buf);
|
init(&buf);
|
||||||
|
|
||||||
// animate
|
// animate
|
||||||
while (TRUE)
|
while (TRUE) {
|
||||||
{
|
|
||||||
// clear the screen
|
|
||||||
//tb_clear();
|
|
||||||
|
|
||||||
// update framebuffer
|
// update framebuffer
|
||||||
dofire(&buf);
|
dofire(&buf);
|
||||||
|
|
||||||
@ -86,11 +81,13 @@ main ( int argc, char *argv[] )
|
|||||||
// event handling
|
// event handling
|
||||||
int err = (size_t) tb_peek_event(&e, opts->refresh_rate);
|
int err = (size_t) tb_peek_event(&e, opts->refresh_rate);
|
||||||
|
|
||||||
if (err < 0)
|
if (err < 0) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (e.type == TB_EVENT_KEY)
|
// handle keypresses
|
||||||
{
|
// q, ctrl+c, ctrl+d => quit
|
||||||
|
if (e.type == TB_EVENT_KEY) {
|
||||||
switch (e.ch) {
|
switch (e.ch) {
|
||||||
case 'q':
|
case 'q':
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -98,13 +95,12 @@ main ( int argc, char *argv[] )
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (e.key)
|
switch (e.key) {
|
||||||
{
|
case TB_KEY_CTRL_C:
|
||||||
case TB_KEY_CTRL_C:
|
case TB_KEY_CTRL_D:
|
||||||
case TB_KEY_CTRL_D:
|
goto cleanup;
|
||||||
goto cleanup;
|
default:
|
||||||
default:
|
break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user