[demo] pass start time to demos for more precise deadlines

pull/2395/head
nick black 3 years ago committed by nick black
parent d5464deb9a
commit efc57333a7

@ -190,7 +190,8 @@ drawcycles(struct ncplane* std, struct ncprogbar* left, struct ncprogbar* right,
}
static int
animate(struct notcurses* nc, struct ncprogbar* left, struct ncprogbar* right){
animate(struct notcurses* nc, struct ncprogbar* left, struct ncprogbar* right,
uint64_t expect_ns){
unsigned dimy, dimx;
struct ncplane* std = notcurses_stddim_yx(nc, &dimy, &dimx);
int headx = -1;
@ -212,9 +213,6 @@ animate(struct notcurses* nc, struct ncprogbar* left, struct ncprogbar* right){
phase_e headphase = PHASE_SPIRAL;
phase_e endphase = PHASE_SPIRAL;
int moves = 0;
struct timespec expected;
clock_gettime(CLOCK_MONOTONIC, &expected);
uint64_t expect_ns = timespec_to_ns(&expected);
uint64_t channels = 0;
int length = 1;
do{
@ -294,7 +292,7 @@ make_pbars(struct ncplane* column, struct ncprogbar** left, struct ncprogbar** r
return 0;
}
int animate_demo(struct notcurses* nc){
int animate_demo(struct notcurses* nc, uint64_t startns){
if(!notcurses_canutf8(nc)){
return 0;
}
@ -342,7 +340,7 @@ int animate_demo(struct notcurses* nc){
return -1;
}
ncplane_destroy(column);
int r = animate(nc, pbarleft, pbarright);
int r = animate(nc, pbarleft, pbarright, startns);
ncprogbar_destroy(pbarleft);
ncprogbar_destroy(pbarright);
return r;

@ -162,7 +162,8 @@ get_ships(struct notcurses* nc, struct ship* ships, unsigned shipcount){
return 0;
}
int box_demo(struct notcurses* nc){
int box_demo(struct notcurses* nc, uint64_t startns){
(void)startns;
unsigned ylen, xlen;
struct ncplane* n = notcurses_stddim_yx(nc, &ylen, &xlen);
ncplane_erase(n);

@ -47,7 +47,8 @@ chunli_draw(struct notcurses* nc, const char* ext, int count, const nccell* b){
}
// test of sprites from files
int chunli_demo(struct notcurses* nc){
int chunli_demo(struct notcurses* nc, uint64_t startns){
(void)startns;
if(!notcurses_canopen_images(nc)){
return 0;
}

@ -73,7 +73,7 @@ int jungle_demo(struct notcurses* nc){
// be disabled) or a non-multimedia build (all images/videos must be disabled).
static struct {
const char* name;
int (*fxn)(struct notcurses*);
int (*fxn)(struct notcurses*, uint64_t startns);
bool dfsg_disabled; // disabled for DFSG builds
} demos[26] = {
{ "animate", animate_demo, false, },
@ -83,22 +83,22 @@ static struct {
{ "eagle", eagle_demo, true, },
{ "fission", fission_demo, false, },
{ "grid", grid_demo, false, },
{ "highcon", highcontrast_demo, false, },
{ "intro", intro, false, },
{ "highcon", highcon_demo, false, },
{ "intro", intro_demo, false, },
{ "jungle", jungle_demo, true, },
{ "keller", keller_demo, true, },
{ "luigi", luigi_demo, true, },
{ "mojibake", mojibake_demo, false, },
{ "normal", normal_demo, false, },
{ "outro", outro, false, },
{ NULL, NULL, false, }, // pango
{ "outro", outro_demo, false, },
{ NULL, NULL, false, }, // it's a secret to everyone
{ "qrcode", qrcode_demo, false, }, // is blank without USE_QRCODEGEN
{ "reel", reel_demo, false, },
{ "sliders", sliding_puzzle_demo, false, },
{ "sliders", sliders_demo, false, },
{ "trans", trans_demo, false, },
{ "uniblock", unicodeblocks_demo, false, },
{ "uniblock", uniblock_demo, false, },
{ "view", view_demo, true, },
{ "whiteout", witherworm_demo, false, },
{ "whiteout", whiteout_demo, false, },
{ "xray", xray_demo, false, },
{ "yield", yield_demo, false, },
{ "zoo", zoo_demo, false, },
@ -219,7 +219,7 @@ ext_demos(struct notcurses* nc, const char* spec){
ncplane_set_base(n, "", 0, stdc);
hud_schedule(demos[idx].name, prevns);
ret = demos[idx].fxn(nc);
ret = demos[idx].fxn(nc, prevns);
notcurses_stats_reset(nc, &results[i].stats);
uint64_t nowns = clock_getns(CLOCK_MONOTONIC);
results[i].timens = nowns - prevns;

@ -25,31 +25,31 @@ extern atomic_bool interrupted;
// heap-allocated, caller must free. locates data files per command line args.
char* find_data(const char* datum);
int animate_demo(struct notcurses* nc);
int unicodeblocks_demo(struct notcurses* nc);
int witherworm_demo(struct notcurses* nc);
int box_demo(struct notcurses* nc);
int trans_demo(struct notcurses* nc);
int chunli_demo(struct notcurses* nc);
int dragon_demo(struct notcurses* nc);
int qrcode_demo(struct notcurses* nc);
int grid_demo(struct notcurses* nc);
int fission_demo(struct notcurses* nc);
int highcontrast_demo(struct notcurses* nc);
int jungle_demo(struct notcurses* nc);
int yield_demo(struct notcurses* nc);
int mojibake_demo(struct notcurses* nc);
int normal_demo(struct notcurses* nc);
int sliding_puzzle_demo(struct notcurses* nc);
int view_demo(struct notcurses* nc);
int eagle_demo(struct notcurses* nc);
int reel_demo(struct notcurses* nc);
int xray_demo(struct notcurses* nc);
int keller_demo(struct notcurses* nc);
int luigi_demo(struct notcurses* nc);
int zoo_demo(struct notcurses* nc);
int intro(struct notcurses* nc);
int outro(struct notcurses* nc);
int animate_demo(struct notcurses* nc, uint64_t startns);
int uniblock_demo(struct notcurses* nc, uint64_t startns);
int whiteout_demo(struct notcurses* nc, uint64_t startns);
int box_demo(struct notcurses* nc, uint64_t startns);
int trans_demo(struct notcurses* nc, uint64_t startns);
int chunli_demo(struct notcurses* nc, uint64_t startns);
int dragon_demo(struct notcurses* nc, uint64_t startns);
int qrcode_demo(struct notcurses* nc, uint64_t startns);
int grid_demo(struct notcurses* nc, uint64_t startns);
int fission_demo(struct notcurses* nc, uint64_t startns);
int highcon_demo(struct notcurses* nc, uint64_t startns);
int jungle_demo(struct notcurses* nc, uint64_t startns);
int yield_demo(struct notcurses* nc, uint64_t startns);
int mojibake_demo(struct notcurses* nc, uint64_t startns);
int normal_demo(struct notcurses* nc, uint64_t startns);
int sliders_demo(struct notcurses* nc, uint64_t startns);
int view_demo(struct notcurses* nc, uint64_t startns);
int eagle_demo(struct notcurses* nc, uint64_t startns);
int reel_demo(struct notcurses* nc, uint64_t startns);
int xray_demo(struct notcurses* nc, uint64_t startns);
int keller_demo(struct notcurses* nc, uint64_t startns);
int luigi_demo(struct notcurses* nc, uint64_t startns);
int zoo_demo(struct notcurses* nc, uint64_t startns);
int intro_demo(struct notcurses* nc, uint64_t startns);
int outro_demo(struct notcurses* nc, uint64_t startns);
/*------------------------------- demo input API --------------------------*/
int input_dispatcher(struct notcurses* nc);

@ -47,7 +47,8 @@ dragonmayer(struct ncvisual* ncv, const char* str, int iters){
return total;
}
int dragon_demo(struct notcurses* nc){
int dragon_demo(struct notcurses* nc, uint64_t startns){
(void)startns;
done = false;
unsigned dimy, dimx;
struct ncplane* n = notcurses_stddim_yx(nc, &dimy, &dimx);

@ -216,7 +216,8 @@ eagles(struct notcurses* nc, struct ncplane* n){
}
// motherfucking eagles!
int eagle_demo(struct notcurses* nc){
int eagle_demo(struct notcurses* nc, uint64_t startns){
(void)startns;
struct ncplane* zncp = NULL;
int err;
if(notcurses_canopen_images(nc)){

@ -102,7 +102,8 @@ shuffle_in(struct ncplane** arr, int count, struct ncplane* n){
}
// you played yourself https://genius.com/De-la-soul-fallin-lyrics
int fission_demo(struct notcurses* nc){
int fission_demo(struct notcurses* nc, uint64_t startns){
(void)startns;
struct ncplane* npl = NULL;
unsigned dimx, dimy;
struct ncplane* stdn = notcurses_stddim_yx(nc, &dimy, &dimx);

@ -245,7 +245,8 @@ gridswitch_demo(struct notcurses* nc, struct ncplane *n){
}
// red across, blue down, green from UL to LR
int grid_demo(struct notcurses* nc){
int grid_demo(struct notcurses* nc, uint64_t startns){
(void)startns;
unsigned y, x;
struct ncplane* n = notcurses_stdplane(nc);
ncplane_erase(n);

@ -60,7 +60,8 @@ generate_next_color(unsigned *total, unsigned *r, unsigned *g, unsigned *b,
return ret;
}
int highcontrast_demo(struct notcurses* nc){
int highcon_demo(struct notcurses* nc, uint64_t startns){
(void)startns;
const int STEP = 16;
int ret = -1;
unsigned dimy, dimx;

@ -86,7 +86,8 @@ orcaride(struct notcurses* nc, struct ncplane* on, int iterations){
return 0;
}
int intro(struct notcurses* nc){
int intro_demo(struct notcurses* nc, uint64_t startns){
(void)startns;
if(!notcurses_canutf8(nc)){
return 0;
}

@ -26562,7 +26562,7 @@ cycle_palettes(struct notcurses* nc, ncpalette* p){
return 0;
}
int jungle_demo(struct notcurses* nc){
int jungle_demo(struct notcurses* nc, uint64_t startns){
if(!notcurses_canchangecolor(nc)){
return 0; // skip
}
@ -26571,8 +26571,7 @@ int jungle_demo(struct notcurses* nc){
if(!notcurses_canutf8(nc)){
return 0;
}
struct timespec start, now;
clock_gettime(CLOCK_MONOTONIC, &start);
struct timespec now;
size_t have = 0, out = 0;
ncpalette* pal;
if((pal = load_palette(nc, palette, sizeof(palette))) == NULL){
@ -26655,7 +26654,7 @@ int jungle_demo(struct notcurses* nc){
}
cycle_palettes(nc, pal);
clock_gettime(CLOCK_MONOTONIC, &now);
nsrunning = timespec_to_ns(&now) - timespec_to_ns(&start);
nsrunning = timespec_to_ns(&now) - startns;
}while(nsrunning > 0 && (uint64_t)nsrunning < 5 * timespec_to_ns(&demodelay));
ncpalette_free(pal);
return 0;

@ -76,7 +76,8 @@ visualize(struct notcurses* nc, struct ncvisual* ncv){
return 0;
}
int keller_demo(struct notcurses* nc){
int keller_demo(struct notcurses* nc, uint64_t startns){
(void)startns;
if(!notcurses_canopen_images(nc)){
return 0;
}

@ -141,7 +141,8 @@ draw_luigi(struct ncplane* n, const char* sprite){
return 0;
}
int luigi_demo(struct notcurses* nc){
int luigi_demo(struct notcurses* nc, uint64_t startns){
(void)startns;
if(!notcurses_canopen_images(nc)){
return 0;
}

@ -3686,7 +3686,8 @@ maketitle(struct ncplane* std){
return title;
}
int mojibake_demo(struct notcurses* nc){
int mojibake_demo(struct notcurses* nc, uint64_t startns){
(void)startns;
if(!notcurses_canutf8(nc)){
return 0;
}

@ -150,7 +150,8 @@ offset(uint32_t* rgba, int y, int x, int dx){
}
// make a pixel array out from the center, blitting it as we go
int normal_demo(struct notcurses* nc){
int normal_demo(struct notcurses* nc, uint64_t startns){
(void)startns;
if(!notcurses_canutf8(nc)){
return 0;
}

@ -184,7 +184,8 @@ outro_message(struct notcurses* nc, unsigned* rows, unsigned* cols){
return non;
}
int outro(struct notcurses* nc){
int outro_demo(struct notcurses* nc, uint64_t startns){
(void)startns;
unsigned rows, cols;
struct ncplane* ncp = notcurses_stddim_yx(nc, &rows, &cols);
ncplane_erase(ncp);

@ -1,6 +1,7 @@
#include "demo.h"
int qrcode_demo(struct notcurses* nc){
int qrcode_demo(struct notcurses* nc, uint64_t startns){
(void)startns;
if(!notcurses_canutf8(nc)){
return 0;
}

@ -188,7 +188,7 @@ handle_input(struct notcurses* nc, const struct timespec* deadline,
}
static int
ncreel_demo_core(struct notcurses* nc){
ncreel_demo_core(struct notcurses* nc, uint64_t startns){
tabletctx* tctxs = NULL;
bool aborted = false;
int x = 8, y = 4;
@ -241,9 +241,7 @@ ncreel_demo_core(struct notcurses* nc){
ncplane_off_styles(std, NCSTYLE_BOLD | NCSTYLE_ITALIC);
// FIXME clrtoeol();
struct timespec deadline;
clock_gettime(CLOCK_MONOTONIC, &deadline);
ns_to_timespec((timespec_to_ns(&demodelay) * 5) + timespec_to_ns(&deadline),
&deadline);
ns_to_timespec((timespec_to_ns(&demodelay) * 5) + startns, &deadline);
unsigned id = 0;
struct tabletctx* newtablet;
// Make an initial number of tablets suitable for the screen's height
@ -323,8 +321,8 @@ ncreel_demo_core(struct notcurses* nc){
return aborted ? 1 : 0;
}
int reel_demo(struct notcurses* nc){
int reel_demo(struct notcurses* nc, uint64_t startns){
ncplane_greyscale(notcurses_stdplane(nc));
int ret = ncreel_demo_core(nc);
int ret = ncreel_demo_core(nc, startns);
return ret;
}

@ -41,14 +41,12 @@ move_square(struct notcurses* nc, struct ncplane* chunk, int* holey, int* holex,
// we take demodelay * 5 to play MOVES moves
static int
play(struct notcurses* nc, struct ncplane** chunks){
play(struct notcurses* nc, struct ncplane** chunks, uint64_t startns){
const uint64_t delayns = timespec_to_ns(&demodelay);
const int chunkcount = CHUNKS_VERT * CHUNKS_HORZ;
struct timespec cur;
clock_gettime(CLOCK_MONOTONIC, &cur);
// we don't want to spend more than demodelay * 5
const uint64_t totalns = delayns * 5;
const uint64_t deadline_ns = timespec_to_ns(&cur) + totalns;
const uint64_t deadline_ns = startns + totalns;
const uint64_t movens = totalns / MOVES;
int hole = rand() % chunkcount;
int holex, holey;
@ -58,8 +56,7 @@ play(struct notcurses* nc, struct ncplane** chunks){
int m;
int lastdir = -1;
for(m = 0 ; m < MOVES ; ++m){
clock_gettime(CLOCK_MONOTONIC, &cur);
uint64_t now = cur.tv_sec * NANOSECS_IN_SEC + cur.tv_nsec;
uint64_t now = clock_getns(CLOCK_MONOTONIC);
if(now >= deadline_ns){
break;
}
@ -132,7 +129,7 @@ draw_bounding_box(struct ncplane* n, int yoff, int xoff, int chunky, int chunkx)
}
// make a bunch of boxes with gradients and use them to play a sliding puzzle.
int sliding_puzzle_demo(struct notcurses* nc){
int sliders_demo(struct notcurses* nc, uint64_t startns){
int ret = -1, z;
unsigned maxx, maxy;
struct ncplane* n = notcurses_stddim_yx(nc, &maxy, &maxx);
@ -205,7 +202,7 @@ int sliding_puzzle_demo(struct notcurses* nc){
chunks[i1] = t;
DEMO_RENDER(nc);
}
ret = play(nc, chunks);
ret = play(nc, chunks, startns);
done:
for(z = 0 ; z < chunkcount ; ++z){

@ -275,7 +275,8 @@ slidepanel(struct notcurses* nc, struct ncplane* stdn){
// markers, each a slightly different color. the goal is to make sure we can
// have a great many colors, that they progress reasonably through the space,
// and that we can write to every coordinate.
int trans_demo(struct notcurses* nc){
int trans_demo(struct notcurses* nc, uint64_t startns){
(void)startns;
unsigned maxx, maxy;
struct ncplane* n = notcurses_stddim_yx(nc, &maxy, &maxx);
ncplane_set_fg_rgb8(n, 255, 255, 255);

@ -119,7 +119,8 @@ draw_block(struct ncplane* nn, uint32_t blockstart){
return 0;
}
int unicodeblocks_demo(struct notcurses* nc){
int uniblock_demo(struct notcurses* nc, uint64_t startns){
(void)startns;
unsigned maxx, maxy;
struct ncplane* n = notcurses_stddim_yx(nc, &maxy, &maxx);
// some blocks are good for the printing, some less so. some are only

@ -169,7 +169,8 @@ view_images(struct notcurses* nc, struct ncplane* nstd, int dimy, int dimx){
return 0;
}
int view_demo(struct notcurses* nc){
int view_demo(struct notcurses* nc, uint64_t startns){
(void)startns;
if(!notcurses_canopen_images(nc)){
return 0;
}

@ -261,7 +261,7 @@ dostring(struct ncplane* n, const char** s, uint32_t rgb,
}
// Much of this text comes from http://kermitproject.org/utf8.html
int witherworm_demo(struct notcurses* nc){
int whiteout_demo(struct notcurses* nc, uint64_t startns){
static const char* strs[] = {
"Война и мир",
"Бра́тья Карама́зовы",
@ -504,6 +504,7 @@ int witherworm_demo(struct notcurses* nc){
bool initial_scroll = ncplane_scrolling_p(n);
ncplane_set_scrolling(n, true);
ncplane_erase(n);
(void)startns; // FIXME integrate
for(i = 0 ; i < screens ; ++i){
uint32_t key = NCKEY_INVALID;
nccell c;

@ -174,8 +174,7 @@ xray_thread(void *vmarsh){
return NULL;
}
int xray_demo(struct notcurses* nc){
uint64_t curns = clock_getns(CLOCK_MONOTONIC);
int xray_demo(struct notcurses* nc, uint64_t startns){
if(!notcurses_canopen_videos(nc)){
return 0;
}
@ -209,7 +208,7 @@ int xray_demo(struct notcurses* nc){
.frame_to_render = &last_frame,
.dm = notcurses_check_pixel_support(nc) ? 0 : 0.5 * delaymultiplier,
.ncv = ncv1,
.startns = curns,
.startns = startns,
.lplane = &kplane,
};
struct marsh m2 = {
@ -219,7 +218,7 @@ int xray_demo(struct notcurses* nc){
.frame_to_render = &last_frame,
.dm = notcurses_check_pixel_support(nc) ? 0 : 0.5 * delaymultiplier,
.ncv = ncv2,
.startns = curns,
.startns = startns,
.lplane = &kplane,
};
int ret = -1;

@ -141,7 +141,8 @@ yielder_thread(void* vmarsh){
return NULL; // FIXME indicate failure/success
}
int yield_demo(struct notcurses* nc){
int yield_demo(struct notcurses* nc, uint64_t startns){
(void)startns;
if(!notcurses_canopen_images(nc)){
return 0;
}

@ -439,7 +439,8 @@ done:
// a plane with exposition text rises from the bottom to the center of the
// screen. as it does so, two widgets (selector and multiselector) come in
// from the left and right, respectively. they then fade out.
int zoo_demo(struct notcurses* nc){
int zoo_demo(struct notcurses* nc, uint64_t startns){
(void)startns;
struct ncplane* bgp;
if(draw_background(nc, &bgp)){
return -1;

Loading…
Cancel
Save