yield: speed up bitmap solution #1596

pull/1604/head
nick black 3 years ago
parent a7ca2be9e6
commit e84b6a4378
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -34,19 +34,10 @@ int yield_demo(struct notcurses* nc){
return -1; return -1;
} }
int maxy, maxx; int maxy, maxx;
if(bitmaps){ if(ncvisual_blitter_geom(nc, wmv, &vopts, &maxy, &maxx, NULL, NULL, NULL)){
ncplane_pixelgeom(vopts.n, NULL, NULL, NULL, NULL, &maxy, &maxx); ncvisual_destroy(wmv);
if(ncvisual_resize(wmv, maxy, maxx)){ ncplane_destroy(vopts.n);
ncvisual_destroy(wmv); return -1;
ncplane_destroy(vopts.n);
return -1;
}
}else{
if(ncvisual_blitter_geom(nc, wmv, &vopts, &maxy, &maxx, NULL, NULL, NULL)){
ncvisual_destroy(wmv);
ncplane_destroy(vopts.n);
return -1;
}
} }
if(ncvisual_render(nc, wmv, &vopts) == NULL){ if(ncvisual_render(nc, wmv, &vopts) == NULL){
ncvisual_destroy(wmv); ncvisual_destroy(wmv);
@ -57,13 +48,10 @@ int yield_demo(struct notcurses* nc){
const long total = maxy * maxx; const long total = maxy * maxx;
// less than this, and we exit almost immediately. more than this, and we // less than this, and we exit almost immediately. more than this, and we
// run closer to twenty seconds. 11/50 it is, then. pixels are different. // run closer to twenty seconds. 11/50 it is, then. pixels are different.
// it would be nice to hit this all with a rigor stick. yes, the 1 makes const long threshold_painted = total * 11 / 50;
// all the difference in cells v pixels. FIXME const int MAXITER = 1024;
const long threshold_painted = total * (10 + !bitmaps) / 50; timespec_div(&demodelay, 10, &scaled);
const int MAXITER = 256;
timespec_div(&demodelay, MAXITER, &scaled);
long tfilled = 0; long tfilled = 0;
struct ncplane_options labopts = { struct ncplane_options labopts = {
.y = 3, .y = 3,
.x = NCALIGN_CENTER, .x = NCALIGN_CENTER,
@ -88,16 +76,14 @@ int yield_demo(struct notcurses* nc){
ncplane_printf_aligned(label, 0, NCALIGN_CENTER, "Yield: %03.1f%%", ((double)tfilled * 100) / threshold_painted); ncplane_printf_aligned(label, 0, NCALIGN_CENTER, "Yield: %03.1f%%", ((double)tfilled * 100) / threshold_painted);
DEMO_RENDER(nc); DEMO_RENDER(nc);
struct timespec delay; demo_nanosleep(nc, &demodelay);
timespec_div(&demodelay, 2, &delay);
demo_nanosleep(nc, &delay);
int iters = 0; int iters = 0;
// FIXME resize the background once rather than scaling every blit
while(tfilled < threshold_painted && iters < MAXITER){ while(tfilled < threshold_painted && iters < MAXITER){
//fprintf(stderr, "%d/%d tfilled: %ld thresh: %ld total: %ld\n", maxy, maxx, tfilled, threshold_painted, total); //fprintf(stderr, "%d/%d tfilled: %ld thresh: %ld total: %ld\n", maxy, maxx, tfilled, threshold_painted, total);
int pfilled = 0; int pfilled = 0;
do{ do{
++iters;
int x = random() % maxx; int x = random() % maxx;
int y = random() % maxy; int y = random() % maxy;
uint32_t pixel = 0; uint32_t pixel = 0;
@ -135,8 +121,9 @@ int yield_demo(struct notcurses* nc){
} }
ncplane_printf_aligned(label, 0, NCALIGN_CENTER, "Yield: %3.1f%%", ((double)tfilled * 100) / threshold_painted); ncplane_printf_aligned(label, 0, NCALIGN_CENTER, "Yield: %3.1f%%", ((double)tfilled * 100) / threshold_painted);
DEMO_RENDER(nc); DEMO_RENDER(nc);
demo_nanosleep(nc, &scaled); if(!bitmaps){
++iters; demo_nanosleep(nc, &scaled);
}
} }
ncplane_destroy(label); ncplane_destroy(label);
ncvisual_destroy(wmv); ncvisual_destroy(wmv);

Loading…
Cancel
Save