From 0f175e58d3a25830abad5e075e3e18619af0f6ff Mon Sep 17 00:00:00 2001 From: nick black Date: Tue, 17 Dec 2019 00:33:51 -0500 Subject: [PATCH] unidamage PoC #117 --- CMakeLists.txt | 2 +- src/lib/notcurses.c | 33 ++++++++++++++++++------------- src/poc/unidamage.cpp | 46 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 15 deletions(-) create mode 100644 src/poc/unidamage.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 283ba795a..7b27cc332 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,7 +79,7 @@ target_compile_definitions(notcurses-demo ) # tiny proofs of concept, one binary per source file -file(GLOB POCSRCS CONFIGURE_DEPENDS src/poc/*.c) +file(GLOB POCSRCS CONFIGURE_DEPENDS src/poc/*.c src/poc/*.cpp) foreach(f ${POCSRCS}) get_filename_component(fe "${f}" NAME_WE) add_executable(${fe} ${f}) diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index 6fa3aab9f..cf35a7c01 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -164,10 +164,19 @@ timespec_to_ns(const struct timespec* t){ static void update_render_stats(const struct timespec* time1, const struct timespec* time0, - ncstats* stats){ + ncstats* stats, int bytes){ int64_t elapsed = timespec_to_ns(time1) - timespec_to_ns(time0); //fprintf(stderr, "Rendering took %ld.%03lds\n", elapsed / NANOSECS_IN_SEC, // (elapsed % NANOSECS_IN_SEC) / 1000000); + if(bytes >= 0){ + stats->render_bytes += bytes; + if(bytes > stats->render_max_bytes){ + stats->render_max_bytes = bytes; + } + if(bytes < stats->render_min_bytes){ + stats->render_min_bytes = bytes; + } + } if(elapsed > 0){ // don't count clearly incorrect information, egads ++stats->renders; stats->render_ns += elapsed; @@ -806,8 +815,8 @@ int notcurses_stop(notcurses* nc){ ret |= tcsetattr(nc->ttyfd, TCSANOW, &nc->tpreserved); if(nc->stats.renders){ double avg = nc->stats.render_ns / (double)nc->stats.renders; - fprintf(stderr, "%ju renders, %.03gs total (%.03gs min, %.03gs max, %.02gs avg %.1f fps)\n", - nc->stats.renders, + fprintf(stderr, "%ju render%s, %.03gs total (%.03gs min, %.03gs max, %.02gs avg %.1f fps)\n", + nc->stats.renders, nc->stats.renders == 1 ? "" : "s", nc->stats.render_ns / 1000000000.0, nc->stats.render_min_ns / 1000000000.0, nc->stats.render_max_ns / 1000000000.0, @@ -890,7 +899,12 @@ int ncplane_set_bg_alpha(ncplane *n, int alpha){ } int ncplane_set_default(ncplane* ncp, const cell* c){ - return cell_duplicate(ncp, &ncp->defcell, c); + int ret = cell_duplicate(ncp, &ncp->defcell, c); + if(ret < 0){ + return -1; + } + ncplane_updamage(ncp); + return ret; } int ncplane_default(ncplane* ncp, cell* c){ @@ -1435,17 +1449,8 @@ int notcurses_render(notcurses* nc){ int bytes = notcurses_render_internal(nc); int dimy, dimx; notcurses_resize(nc, &dimy, &dimx); - if(bytes > 0){ - nc->stats.render_bytes += bytes; - if(bytes > nc->stats.render_max_bytes){ - nc->stats.render_max_bytes = bytes; - } - if(bytes < nc->stats.render_min_bytes){ - nc->stats.render_min_bytes = bytes; - } - } clock_gettime(CLOCK_MONOTONIC_RAW, &done); - update_render_stats(&done, &start, &nc->stats); + update_render_stats(&done, &start, &nc->stats, bytes); if(bytes < 0){ ret = -1; } diff --git a/src/poc/unidamage.cpp b/src/poc/unidamage.cpp new file mode 100644 index 000000000..2e7da5a09 --- /dev/null +++ b/src/poc/unidamage.cpp @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include + +// What happens when we print over half of a wide glyph? + +int main(int argc, char** argv){ + setlocale(LC_ALL, ""); + notcurses_options opts{}; + opts.inhibit_alternate_screen = true; + struct notcurses* nc; + if((nc = notcurses_init(&opts, stdout)) == nullptr){ + return EXIT_FAILURE; + } + struct ncplane* n = notcurses_stdplane(nc); + int dimx, dimy; + ncplane_dim_yx(n, &dimy, &dimx); + cell c = CELL_TRIVIAL_INITIALIZER; + if(cell_load(n, &c, "🐳") < 0){ + goto err; + } + if(ncplane_set_default(n, &c) < 0){ + goto err; + } + cell_release(n, &c); + if(cell_load(n, &c, "x") < 0){ + goto err; + } + for(int i = 0 ; i < dimy ; ++i){ + for(int j = 0 ; j < dimx / 2 ; j += 2){ + if(ncplane_putc_yx(n, i, j, &c) < 0){ + goto err; + } + } + } + if(notcurses_render(nc)){ + goto err; + } + return notcurses_stop(nc) ? EXIT_FAILURE : EXIT_SUCCESS; + +err: + notcurses_stop(nc); + return EXIT_FAILURE; +}