From f1b427d6cbec14d048086ddde31719941150520d Mon Sep 17 00:00:00 2001 From: Kied Llaentenn <32681240+Kiedtl@users.noreply.github.com> Date: Fri, 13 Dec 2019 16:15:29 -0500 Subject: [PATCH] options: truecolor, refresh rate --- args.h | 5 ++++- colors.h | 52 +++++++++++++++++++++++++++++++++++++++++++--------- draw.c | 17 ++++++++++++++--- draw.h | 1 + main.c | 22 ++++++++++++++++++++-- makefile | 2 +- 6 files changed, 83 insertions(+), 16 deletions(-) diff --git a/args.h b/args.h index 2809697..7b2beb9 100644 --- a/args.h +++ b/args.h @@ -15,11 +15,14 @@ #ifndef ARGS_INCLUDED #define ARGS_INCLUDED #include "bool.h" +#include "args.h" +#include "types.h" extern char *argv0; typedef struct Options { - bool stub; // no real options... yet + usize refresh_rate; + bool truecolor; } Options; /* use main(int argc, char *argv[]) */ diff --git a/colors.h b/colors.h index 5c2a5dd..293e784 100644 --- a/colors.h +++ b/colors.h @@ -1,27 +1,61 @@ -// colors.h: defines the colors for the fire. -// feel free to modify to customize the look of the animation. :) -// structure: , , - #ifndef COLORS_INCLUDED #define COLORS_INCLUDED +#include "types.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 }, + + // red/black { 0x2591, 2, 0 }, { 0x2592, 2, 0 }, { 0x2593, 2, 0 }, { 0x2588, 2, 0 }, + + // yellow/red { 0x2591, 4, 2 }, { 0x2592, 4, 2 }, { 0x2593, 4, 2 }, { 0x2588, 4, 2 }, - { 0x2591, 8, 4 }, - { 0x2592, 8, 4 }, - { 0x2593, 8, 4 }, - { 0x2588, 8, 4 }, + + // white/red + { 0x2591, 8, 2 }, + { 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 diff --git a/draw.c b/draw.c index 6163ea9..7c859c3 100644 --- a/draw.c +++ b/draw.c @@ -2,11 +2,15 @@ #include #include +#include "args.h" #include "termbox.h" #include "types.h" #include "draw.h" -#include "output.h" #include "colors.h" +#include "output.h" + +// arguments +extern struct Options *opts; // initialize the framebuffer void @@ -62,8 +66,15 @@ dofire ( struct buffer *buf ) if (buf->buf[dest] > 12) buf->buf[dest] = 0; - realbuf[dest] = colors[buf->buf[dest]]; - realbuf[src] = colors[buf->buf[src]]; + if (opts->truecolor) { + 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]]; + } } } } diff --git a/draw.h b/draw.h index 7b3c51a..d91525b 100644 --- a/draw.h +++ b/draw.h @@ -1,5 +1,6 @@ #ifndef DRAW_INCLUDED #define DRAW_INCLUDED + #include "types.h" typedef struct buffer diff --git a/main.c b/main.c index c2d4281..d21f530 100644 --- a/main.c +++ b/main.c @@ -16,10 +16,27 @@ struct Options *opts; int 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 argv0 = argv[0]; ARGBEGIN { + case 't': + tb_select_output_mode(TB_OUTPUT_TRUECOLOR); + opts->truecolor = TRUE; + break; + case 'r': + opts->refresh_rate = atoi(ARGF()); + break; case 'V': PRINT("%s %s\n", argv0, VERSION); exit(0); @@ -28,7 +45,8 @@ main ( int argc, char *argv[] ) 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("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"); exit(1); } ARGEND @@ -56,7 +74,7 @@ main ( int argc, char *argv[] ) tb_present(); // event handling - int err = (usize) tb_peek_event(&e, 5); + int err = (usize) tb_peek_event(&e, opts->refresh_rate); if (err < 0) continue; diff --git a/makefile b/makefile index a92d399..f03d31c 100644 --- a/makefile +++ b/makefile @@ -12,7 +12,7 @@ INC = -Isub/termbox_next/src -Isub/ccommon/ CC = gcc CFLAGS = -std=c99 -O3 $(WARNING) $(INC) -LDFLAGS = -fuse-ld=lld +LDFLAGS = TRMBOX = sub/termbox_next/bin/termbox.a SRC = main.c draw.c