unidamage PoC #117

This commit is contained in:
nick black 2019-12-17 00:33:51 -05:00
parent c30bd1b531
commit 0f175e58d3
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
3 changed files with 66 additions and 15 deletions

View File

@ -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})

View File

@ -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;
}

46
src/poc/unidamage.cpp Normal file
View File

@ -0,0 +1,46 @@
#include <cstdio>
#include <cstdlib>
#include <clocale>
#include <cassert>
#include <notcurses.h>
// 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;
}