Dankamongmen/no prisoners damage (#198)

* notcurses: set up lastframe #189
* render: o(1) take no prisoners damage detection
* EAAAAAAAAAAGLES
* slight background on intro
* 0.9.2
pull/204/head v0.9.2
Nick Black 5 years ago committed by GitHub
parent 9b81de3789
commit 4278a53523
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.13)
project(notcurses VERSION 0.9.1
project(notcurses VERSION 0.9.2
DESCRIPTION "UI for modern terminal emulators"
HOMEPAGE_URL "https://nick-black.com/dankwiki/index.php/notcurses"
LANGUAGES C CXX)

7
debian/changelog vendored

@ -1,3 +1,10 @@
notcurses (0.9.2) unstable; urgency=medium
* New upstream
* Install man1 pages to the correct location
-- Nick Black <dankamongmen@gmail.com> Sun, 22 Dec 2019 09:25:31 -0500
notcurses (0.9.1-1) unstable; urgency=medium
* Install binaries' man pages in notcurses-bin

@ -78,7 +78,9 @@ intro(struct notcurses* nc){
if((ncp = notcurses_stdplane(nc)) == NULL){
return -1;
}
ncplane_erase(ncp);
cell c = CELL_TRIVIAL_INITIALIZER;
cell_set_bg_rgb(&c, 0x20, 0x20, 0x20);
ncplane_set_default(ncp, &c);
if(ncplane_cursor_move_yx(ncp, 0, 0)){
return -1;
}
@ -102,8 +104,6 @@ intro(struct notcurses* nc){
cell_release(ncp, &ul); cell_release(ncp, &ur);
cell_release(ncp, &ll); cell_release(ncp, &lr);
cell_release(ncp, &hl); cell_release(ncp, &vl);
cell c;
cell_init(&c);
const char* cstr = "Δ";
cell_load(ncp, &c, cstr);
cell_set_fg_rgb(&c, 200, 0, 200);
@ -162,6 +162,7 @@ typedef struct demoresult {
char selector;
struct ncstats stats;
uint64_t timens;
bool failed;
} demoresult;
static demoresult*
@ -196,6 +197,7 @@ ext_demos(struct notcurses* nc, const char* demos){
break;
}
if(ret){
results[i].failed = true;
break;
}
notcurses_stats(nc, &results[i].stats);
@ -304,14 +306,15 @@ int main(int argc, char** argv){
char totalbuf[BPREFIXSTRLEN + 1];
bprefix(results[i].stats.render_bytes, 1, totalbuf, 0);
double avg = results[i].stats.render_ns / (double)results[i].stats.renders;
printf("%2zu|%c|%2lu.%03lus|%4luf|%*sB|%8juµs|%6.1f FPS|\n", i,
printf("%2zu|%c|%2lu.%03lus|%4luf|%*sB|%8juµs|%6.1f FPS|%s\n", i,
results[i].selector,
results[i].timens / GIG,
(results[i].timens % GIG) / 1000000,
results[i].stats.renders,
BPREFIXSTRLEN, totalbuf,
results[i].stats.render_ns / 1000,
GIG / avg);
GIG / avg,
results[i].failed ? "***FAILED" : "");
// FIXME
}
free(results);

@ -1,6 +1,29 @@
#include <libavutil/frame.h>
#include "demo.h"
// 0: transparent
// 1: white
// 2: grey
// 3: black
const char eagle1[] =
"0000003333333000"
"0000331113112300"
"0003111111113130"
"0031111113133330"
"3311311111333030"
"2131111111313000"
"3331111111311300"
"0311111111331330"
"0311311111131130"
"0323111111133130"
"0323111111133113"
"0033213111113313"
"0003213211111333"
"0000332321321233"
"0000003312332223"
"0000000033003330"
;
// display the level map scaled to fit entirely within the visual area
static struct ncvisual*
outzoomed_map(struct notcurses* nc, const char* map){
@ -18,11 +41,10 @@ outzoomed_map(struct notcurses* nc, const char* map){
if(notcurses_render(nc)){
return NULL;
}
nanosleep(&demodelay, NULL);
return ncv;
}
static int
static struct ncplane*
zoom_map(struct notcurses* nc, const char* map){
int averr;
// determine size that will be represented on screen at once, and how
@ -32,12 +54,12 @@ zoom_map(struct notcurses* nc, const char* map){
// scrolling through the map, whooooooooosh.
struct ncvisual* ncv = ncvisual_open_plane(nc, map, &averr, 0, 0, NCSCALE_NONE);
if(ncv == NULL){
return -1;
return NULL;
}
struct AVFrame* frame;
if((frame = ncvisual_decode(ncv, &averr)) == NULL){
ncvisual_destroy(ncv);
return -1;
return NULL;
}
ncvisual_destroy(ncv);
// we start at the lower left corner of the outzoomed map
@ -49,31 +71,120 @@ zoom_map(struct notcurses* nc, const char* map){
int vy = vheight / 2;
int zoomy = truey;
int zoomx = truex;
struct ncplane* zncp = NULL;
while(zoomy < vy && zoomx < vx){
ncplane_destroy(zncp);
zoomy += 2;
zoomx += 2;
struct ncplane* zncp = notcurses_newplane(nc, zoomy, zoomx, 0, 0, NULL);
zncp = notcurses_newplane(nc, zoomy, zoomx, 0, 0, NULL);
struct ncvisual* zncv = ncplane_visual_open(zncp, map, &averr);
if(zncv == NULL){
ncvisual_destroy(ncv);
return -1;
ncplane_destroy(zncp);
return NULL;
}
if(ncvisual_decode(zncv, &averr) == NULL){
ncvisual_destroy(zncv);
return -1;
ncplane_destroy(zncp);
return NULL;
}
if(ncvisual_render(zncv, (zoomy - truey) * 2, 0, 0, ((float)truex / zoomx) * zoomx)){
ncvisual_destroy(zncv);
return -1;
ncplane_destroy(zncp);
return NULL;
}
if(notcurses_render(nc)){
ncvisual_destroy(zncv);
return -1;
ncplane_destroy(zncp);
return NULL;
}
ncvisual_destroy(zncv);
ncplane_destroy(zncp);
}
nanosleep(&demodelay, NULL);
return zncp;
}
static int
draw_eagle(struct ncplane* n, const char* sprite){
cell bgc = CELL_TRIVIAL_INITIALIZER;
cell_set_bg_alpha(&bgc, CELL_ALPHA_TRANSPARENT);
ncplane_set_default(n, &bgc);
cell_release(n, &bgc);
size_t s;
int sbytes;
uint64_t channels = 0;
// optimization so we can elide more color changes, see README's "#perf"
channels_set_bg_rgb(&channels, 0x00, 0x00, 0x00);
ncplane_cursor_move_yx(n, 0, 0);
for(s = 0 ; sprite[s] ; ++s){
switch(sprite[s]){
case '0':
ncplane_cursor_move_yx(n, (s + 1) / 16, (s + 1) % 16);
break;
case '1':
channels_set_fg_rgb(&channels, 0xff, 0xff, 0xff);
break;
case '2':
channels_set_fg_rgb(&channels, 0xe3, 0x9d, 0x25);
break;
case '3':
channels_set_fg_rgb(&channels, 0x3a, 0x84, 0x00);
break;
}
if(sprite[s] != '0'){
if(ncplane_putegc(n, "\u2588", 0, channels, &sbytes) != 1){
return -1;
}
}
}
return 0;
}
static int
eagles(struct notcurses* nc){
int truex, truey; // dimensions of true display
notcurses_term_dim_yx(nc, &truey, &truex);
struct timespec flapiter;
timespec_div(&demodelay, truex / 2, &flapiter);
const int height = 16;
const int width = 16;
struct eagle {
int yoff, xoff;
struct ncplane* n;
} e[3];
for(size_t i = 0 ; i < sizeof(e) / sizeof(*e) ; ++i){
e[i].xoff = 0;
e[i].yoff = random() % ((truey - height) / 2);
e[i].n = notcurses_newplane(nc, height, width, e[i].yoff, e[i].xoff, NULL);
if(e[i].n == NULL){
return -1;
}
if(draw_eagle(e[i].n, eagle1)){
return -1;
}
}
int eaglesmoved;
do{
eaglesmoved = 0;
notcurses_render(nc);
for(size_t i = 0 ; i < sizeof(e) / sizeof(*e) ; ++i){
if(e[i].xoff >= truex){
continue;
}
e[i].yoff += random() % (3 + i) - 1;
if(e[i].yoff < 0){
e[i].yoff = 0;
}else if(e[i].yoff + height >= truey){
e[i].yoff = truey - height - 1;
}
e[i].xoff += random() % 2 + 1;
ncplane_move_yx(e[i].n, e[i].yoff, e[i].xoff);
++eaglesmoved;
}
nanosleep(&flapiter, NULL);
}while(eaglesmoved);
for(size_t i = 0 ; i < sizeof(e) / sizeof(*e) ; ++i){
ncplane_destroy(e[i].n);
}
return 0;
}
@ -86,10 +197,16 @@ int eagle_demo(struct notcurses* nc){
return -1;
}
ncvisual_destroy(zo);
if(zoom_map(nc, map)){
struct ncplane* zncp = zoom_map(nc, map);
if(zncp == NULL){
free(map);
return -1;
}
if(eagles(nc)){
ncplane_destroy(zncp);
return -1;
}
ncplane_destroy(zncp);
free(map);
return 0;
}

Loading…
Cancel
Save