blitters PoC: hoist ncv creation from main loop #866

pull/873/head
nick black 4 years ago
parent 73e71622f7
commit 4232ca1427
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -19,6 +19,11 @@ int main(int argc, char** argv){
if(nc == NULL){ if(nc == NULL){
return EXIT_FAILURE; return EXIT_FAILURE;
} }
nc_err_e err;
struct ncvisual* ncv = ncvisual_from_file(fname, &err);
if(ncv == NULL){
goto err;
}
struct ncplane* std = notcurses_stdplane(nc); struct ncplane* std = notcurses_stdplane(nc);
// FIXME not all work yet; this subset does // FIXME not all work yet; this subset does
const int blitters[] = { const int blitters[] = {
@ -38,35 +43,28 @@ int main(int argc, char** argv){
for(int i = 1 ; i < argc ; ++i){ for(int i = 1 ; i < argc ; ++i){
ncplane_erase(std); ncplane_erase(std);
const char* fname = argv[i]; const char* fname = argv[i];
nc_err_e err;
struct ncvisual* ncv = ncvisual_from_file(fname, &err);
if(ncv == NULL){
goto err;
}
notcurses_render(nc);
struct ncvisual_options vopts = { struct ncvisual_options vopts = {
.n = std, .n = std,
.scaling = scaling, .scaling = scaling,
.blitter = *blitter, .blitter = *blitter,
}; };
if(!ncvisual_render(nc, ncv, &vopts)){ if(!ncvisual_render(nc, ncv, &vopts)){
ncvisual_destroy(ncv);
goto err; goto err;
} }
notcurses_render(nc); if(notcurses_render(nc)){
struct timespec ts = { goto err;
.tv_sec = 0, }
.tv_nsec = 500000000, struct timespec ts = { .tv_sec = 0, .tv_nsec = 500000000, };
};
clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL); clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL);
ncvisual_destroy(ncv);
} }
} }
} }
ncvisual_destroy(ncv);
notcurses_stop(nc); notcurses_stop(nc);
return EXIT_SUCCESS; return EXIT_SUCCESS;
err: err:
ncvisual_destroy(ncv);
notcurses_stop(nc); notcurses_stop(nc);
return EXIT_FAILURE; return EXIT_FAILURE;
} }

Loading…
Cancel
Save