options: truecolor, refresh rate

This commit is contained in:
Kied Llaentenn 2019-12-13 16:15:29 -05:00
parent 31692a9f13
commit f1b427d6cb
6 changed files with 83 additions and 16 deletions

5
args.h
View File

@ -15,11 +15,14 @@
#ifndef ARGS_INCLUDED #ifndef ARGS_INCLUDED
#define ARGS_INCLUDED #define ARGS_INCLUDED
#include "bool.h" #include "bool.h"
#include "args.h"
#include "types.h"
extern char *argv0; extern char *argv0;
typedef struct Options { typedef struct Options {
bool stub; // no real options... yet usize refresh_rate;
bool truecolor;
} Options; } Options;
/* use main(int argc, char *argv[]) */ /* use main(int argc, char *argv[]) */

View File

@ -1,27 +1,61 @@
// colors.h: defines the colors for the fire.
// feel free to modify to customize the look of the animation. :)
// structure: <unicode hex value>, <foreground>, <background>
#ifndef COLORS_INCLUDED #ifndef COLORS_INCLUDED
#define COLORS_INCLUDED #define COLORS_INCLUDED
#include "types.h"
#include "termbox.h" #include "termbox.h"
#define CLRS_LEN 13
struct tb_cell colors[13] = #define RED 0xdd1111
#define BLACK 0x000000
#define YELLOW 0xffdd00
#define WHITE 0xffffff
struct tb_cell normcolors[CLRS_LEN] =
{ {
// default
{ ' ', 9, 0 }, { ' ', 9, 0 },
// red/black
{ 0x2591, 2, 0 }, { 0x2591, 2, 0 },
{ 0x2592, 2, 0 }, { 0x2592, 2, 0 },
{ 0x2593, 2, 0 }, { 0x2593, 2, 0 },
{ 0x2588, 2, 0 }, { 0x2588, 2, 0 },
// yellow/red
{ 0x2591, 4, 2 }, { 0x2591, 4, 2 },
{ 0x2592, 4, 2 }, { 0x2592, 4, 2 },
{ 0x2593, 4, 2 }, { 0x2593, 4, 2 },
{ 0x2588, 4, 2 }, { 0x2588, 4, 2 },
{ 0x2591, 8, 4 },
{ 0x2592, 8, 4 }, // white/red
{ 0x2593, 8, 4 }, { 0x2591, 8, 2 },
{ 0x2588, 8, 4 }, { 0x2592, 8, 2 },
{ 0x2593, 8, 2 },
{ 0x2588, 8, 2 },
};
struct tb_cell truecolors[CLRS_LEN] =
{
// default
{ ' ', 9, 0 },
// red/black
{ 0x2591, RED, BLACK },
{ 0x2592, RED, BLACK },
{ 0x2593, RED, BLACK },
{ 0x2588, RED, BLACK },
// yellow/red
{ 0x2591, YELLOW, RED },
{ 0x2592, YELLOW, RED },
{ 0x2593, YELLOW, RED },
{ 0x2588, YELLOW, RED },
// white/red
{ 0x2591, WHITE, RED },
{ 0x2592, WHITE, RED },
{ 0x2593, WHITE, RED },
{ 0x2588, WHITE, RED },
}; };
#endif #endif

17
draw.c
View File

@ -2,11 +2,15 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "args.h"
#include "termbox.h" #include "termbox.h"
#include "types.h" #include "types.h"
#include "draw.h" #include "draw.h"
#include "output.h"
#include "colors.h" #include "colors.h"
#include "output.h"
// arguments
extern struct Options *opts;
// initialize the framebuffer // initialize the framebuffer
void void
@ -62,8 +66,15 @@ dofire ( struct buffer *buf )
if (buf->buf[dest] > 12) if (buf->buf[dest] > 12)
buf->buf[dest] = 0; buf->buf[dest] = 0;
realbuf[dest] = colors[buf->buf[dest]]; if (opts->truecolor) {
realbuf[src] = colors[buf->buf[src]]; realbuf[dest] = truecolors[buf->buf[dest]];
realbuf[src] = truecolors[buf->buf[src]];
}
else
{
realbuf[dest] = normcolors[buf->buf[dest]];
realbuf[src] = normcolors[buf->buf[src]];
}
} }
} }
} }

1
draw.h
View File

@ -1,5 +1,6 @@
#ifndef DRAW_INCLUDED #ifndef DRAW_INCLUDED
#define DRAW_INCLUDED #define DRAW_INCLUDED
#include "types.h" #include "types.h"
typedef struct buffer typedef struct buffer

22
main.c
View File

@ -16,10 +16,27 @@ struct Options *opts;
int int
main ( int argc, char *argv[] ) main ( int argc, char *argv[] )
{ {
opts = (struct Options*) calloc(1, sizeof(struct Options*));
if (opts == NULL) {
PRINT("fire: error: cannot ");
perror("calloc()");
}
// default args
opts->refresh_rate = 5;
opts->truecolor = FALSE;
// argument parsing // argument parsing
argv0 = argv[0]; argv0 = argv[0];
ARGBEGIN { ARGBEGIN {
case 't':
tb_select_output_mode(TB_OUTPUT_TRUECOLOR);
opts->truecolor = TRUE;
break;
case 'r':
opts->refresh_rate = atoi(ARGF());
break;
case 'V': case 'V':
PRINT("%s %s\n", argv0, VERSION); PRINT("%s %s\n", argv0, VERSION);
exit(0); exit(0);
@ -28,7 +45,8 @@ main ( int argc, char *argv[] )
PRINT("fire %s\n(c) Kied Llaentenn and contributors\n", VERSION); PRINT("fire %s\n(c) Kied Llaentenn and contributors\n", VERSION);
PRINT("https://github.com/lptstr/fire\n"); PRINT("https://github.com/lptstr/fire\n");
PRINT("\nUSAGE:\n\t$ fire\n\n"); PRINT("\nUSAGE:\n\t$ fire\n\n");
PRINT("OPTIONS:\n\t-V\tshow version and exit.\n"); PRINT("OPTIONS:\n\t-t\tenable true colors.\n");
PRINT("\t-V\tshow version and exit.\n");
PRINT("\t-h\tshow this help message and exit.\n\n"); PRINT("\t-h\tshow this help message and exit.\n\n");
exit(1); exit(1);
} ARGEND } ARGEND
@ -56,7 +74,7 @@ main ( int argc, char *argv[] )
tb_present(); tb_present();
// event handling // event handling
int err = (usize) tb_peek_event(&e, 5); int err = (usize) tb_peek_event(&e, opts->refresh_rate);
if (err < 0) if (err < 0)
continue; continue;

View File

@ -12,7 +12,7 @@ INC = -Isub/termbox_next/src -Isub/ccommon/
CC = gcc CC = gcc
CFLAGS = -std=c99 -O3 $(WARNING) $(INC) CFLAGS = -std=c99 -O3 $(WARNING) $(INC)
LDFLAGS = -fuse-ld=lld LDFLAGS =
TRMBOX = sub/termbox_next/bin/termbox.a TRMBOX = sub/termbox_next/bin/termbox.a
SRC = main.c draw.c SRC = main.c draw.c