fire/main.c

82 lines
1.3 KiB
C
Raw Normal View History

2019-12-12 22:08:35 +00:00
#include <stdlib.h>
2019-12-12 23:46:24 +00:00
#include "bool.h"
2019-12-13 03:27:13 +00:00
#include "output.h"
#include "draw.h"
#include "types.h"
#include "termbox.h"
#include "args.h"
2019-12-13 02:18:56 +00:00
2019-12-13 03:39:35 +00:00
#define VERSION "0.1.0"
2019-12-13 03:27:13 +00:00
// argument parsing (args.h)
char *argv0;
struct Options *opts;
2019-12-12 22:08:35 +00:00
int
2019-12-13 03:39:35 +00:00
main ( int argc, char *argv[] )
2019-12-12 22:08:35 +00:00
{
2019-12-13 03:39:35 +00:00
// argument parsing
argv0 = argv[0];
ARGBEGIN {
case 'V':
PRINT("%s %s\n", argv0, VERSION);
exit(0);
case 'h':
default:
PRINT("fire %s\n(c) Kied Llaentenn and contributors\n", VERSION);
PRINT("https://github.com/lptstr/fire\n");
PRINT("\nUSAGE:\n\t$ fire\n\n");
PRINT("OPTIONS:\n\t-V\tshow version and exit.\n");
PRINT("\t-h\tshow this help message and exit.\n\n");
exit(1);
} ARGEND
2019-12-12 23:46:24 +00:00
// initialize termbox
tb_init();
tb_select_output_mode(TB_OUTPUT_NORMAL);
tb_clear();
2019-12-13 03:27:13 +00:00
struct buffer buf;
2019-12-13 04:03:58 +00:00
struct tb_event e;
2019-12-12 23:46:24 +00:00
2019-12-13 02:18:56 +00:00
// initialize drawing
init(&buf);
2019-12-12 22:08:35 +00:00
2019-12-13 02:18:56 +00:00
// animate
while (TRUE)
{
2019-12-13 03:27:13 +00:00
// clear the screen
2019-12-13 02:18:56 +00:00
tb_clear();
2019-12-13 03:27:13 +00:00
// update framebuffer
2019-12-13 02:18:56 +00:00
dofire(&buf);
2019-12-13 03:27:13 +00:00
// draw framebuffer to terminal
2019-12-13 02:18:56 +00:00
tb_present();
2019-12-12 23:46:24 +00:00
2019-12-13 04:03:58 +00:00
// event handling
int err = (usize) tb_peek_event(&e, 5);
2019-12-13 04:03:58 +00:00
2019-12-13 04:08:35 +00:00
if (err < 0)
2019-12-13 04:03:58 +00:00
continue;
if (e.type == TB_EVENT_KEY)
{
switch (e.key)
{
case 0x03:
cleanup(&buf);
exit(0);
default:
break;
}
}
}
2019-12-13 03:27:13 +00:00
2019-12-13 04:03:58 +00:00
// perform cleanup
cleanup(&buf);
2019-12-12 23:46:24 +00:00
2019-12-12 22:08:35 +00:00
return 0;
}