fully accurate determine_totalmoves #1263

pull/1297/head
nick black 4 years ago committed by Nick Black
parent 57044946ad
commit 22ecc09dc0

@ -153,18 +153,25 @@ get_next_end(struct ncplane* std, struct ncplane* left, struct ncplane* right,
get_next_head(std, left, right, endy, endx, endphase); get_next_head(std, left, right, endy, endx, endphase);
} }
// determine the total number of moves we will make // determine the total number of moves we will make. this is most easily and
// accurately done by running through a loop.
static int static int
determine_totalmoves(struct ncplane* left, struct ncplane* right){ determine_totalmoves(struct ncplane* std, struct ncplane* left, struct ncplane* right,
int lrcol; // left column of right progbar int heady, int headx, int endy, int endx, int totallength){
int rlcol; // right column of left progbar int moves = 0, length = 0;
int trow, brow; // top and bottom phase_e headphase, endphase;
ncplane_abs_yx(right, &trow, &lrcol); do{
ncplane_abs_yx(left, &brow, &rlcol); get_next_head(std, left, right, &heady, &headx, &headphase);
rlcol += ncplane_dim_x(left) - 1; if(length < totallength){
brow += ncplane_dim_y(left) - 1; ++length;
return ((brow - trow + 3) * (brow - trow + 3) + }else{
ncplane_dim_x(left) * 2 + ncplane_dim_y(left) * 2); get_next_end(std, left, right, &endy, &endx, &endphase);
}
++moves;
fprintf(stderr, "move %d: %d/%d %d/%d\n", moves, heady, headx, endy, endx);
}while(endy != heady || endx != headx);
fprintf(stderr, "done! move %d: %d/%d %d/%d\n", moves, heady, headx, endy, endx);
return moves;
} }
static int static int
@ -180,7 +187,9 @@ animate(struct notcurses* nc, struct ncprogbar* left, struct ncprogbar* right){
for(const char** c = cycles ; *c ; ++c){ for(const char** c = cycles ; *c ; ++c){
totallength += ncstrwidth(*c); totallength += ncstrwidth(*c);
} }
const int totalmoves = determine_totalmoves(ncprogbar_plane(left), ncprogbar_plane(right)); int totalmoves = determine_totalmoves(std, ncprogbar_plane(left), ncprogbar_plane(right),
heady, headx, endy, endx, totallength);
++totalmoves; // for final render
// headx and heady will not return to their starting location until the // headx and heady will not return to their starting location until the
// string begins to disappear. endx and endy won't equal heady/headx until // string begins to disappear. endx and endy won't equal heady/headx until
// the entire string has been consumed. // the entire string has been consumed.
@ -316,11 +325,6 @@ int animate_demo(struct notcurses* nc){
} }
ncplane_destroy(column); ncplane_destroy(column);
int r = animate(nc, pbarleft, pbarright); int r = animate(nc, pbarleft, pbarright);
// reflash the gradient to eliminate the counter, setting stage for next demo
ncplane_cursor_move_yx(n, 1, 0);
if(ncplane_highgradient(n, tl, tr, bl, br, dimy - 1, dimx - 1) < 0){
return -1;
}
ncprogbar_destroy(pbarleft); ncprogbar_destroy(pbarleft);
ncprogbar_destroy(pbarright); ncprogbar_destroy(pbarright);
return r; return r;

Loading…
Cancel
Save