From e81377cf05a0b2e82fbe2a25e4102e655e20e578 Mon Sep 17 00:00:00 2001 From: nick black Date: Thu, 28 Nov 2019 15:59:49 -0500 Subject: [PATCH] render: slow but simple z-depth algorithm #1 --- src/lib/notcurses.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index c90864a0d..1f5abf718 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -781,6 +781,28 @@ term_setstyles(const notcurses* nc, FILE* out, uint32_t* curattr, const cell* c) return ret; } +// find the topmost cell for this coordinate +static const cell* +visible_cell(const notcurses* nc, int y, int x){ + const ncplane* p = nc->top; + while(p){ + // where in the plane this coordinate would be, based off absy/absx. the + // true origin is 0,0, so abs=2,2 means coordinate 3,3 would be 1,1, while + // abs=-2,-2 would make coordinate 3,3 relative 5, 5. + int poffx, poffy; + poffy = y - p->absy; + poffx = x - p->absx; + if(poffy < p->leny && poffy >= 0){ + if(poffx < p->lenx && poffx >= 0){ + return &p->fb[fbcellidx(p, poffy, poffx)]; + } + } + p = p->z; + } + // should never happen for valid y, x thanks to the stdscreen + return NULL; +} + // FIXME this needs to keep an invalidation bitmap, rather than blitting the // world every time int notcurses_render(notcurses* nc){ @@ -800,8 +822,10 @@ int notcurses_render(notcurses* nc){ // FIXME previous line could have ended halfway through multicol. what happens? for(x = 0 ; x < nc->stdscr->lenx ; ++x){ unsigned r, g, b, br, bg, bb; - // FIXME z-culling! - const cell* c = &nc->stdscr->fb[fbcellidx(nc->stdscr, y, x)]; + const cell* c = visible_cell(nc, y, x); + if(c == NULL){ // very bad :( + continue; + } // we allow these to be set distinctly, but terminfo only supports using // them both via the 'op' capability. unless we want to generate the 'op' // escapes ourselves, if either is set to default, we first send op, and