mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-10 01:29:05 -04:00
sliders: fix timing
This commit is contained in:
parent
cb2bf16a73
commit
4b6063e1ce
@ -20,10 +20,8 @@ move_square(struct notcurses* nc, struct ncplane* chunk, int* holey, int* holex,
|
|||||||
// divide movetime into abs(max(deltay, deltax)) units, and move delta
|
// divide movetime into abs(max(deltay, deltax)) units, and move delta
|
||||||
int units = abs(deltay) > abs(deltax) ? abs(deltay) : abs(deltax);
|
int units = abs(deltay) > abs(deltax) ? abs(deltay) : abs(deltax);
|
||||||
movens /= units;
|
movens /= units;
|
||||||
struct timespec movetime = {
|
struct timespec movetime;
|
||||||
.tv_sec = (movens / MOVES) / GIG,
|
ns_to_timespec(movens, &movetime);
|
||||||
.tv_nsec = (movens / MOVES) % GIG,
|
|
||||||
};
|
|
||||||
int i;
|
int i;
|
||||||
int targy = newholey;
|
int targy = newholey;
|
||||||
int targx = newholex;
|
int targx = newholex;
|
||||||
@ -44,16 +42,16 @@ move_square(struct notcurses* nc, struct ncplane* chunk, int* holey, int* holex,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// we take (MOVES / 5) * demodelay to play MOVES moves
|
// we take demodelay * 5 to play MOVES moves
|
||||||
static int
|
static int
|
||||||
play(struct notcurses* nc, struct ncplane** chunks){
|
play(struct notcurses* nc, struct ncplane** chunks){
|
||||||
const uint64_t delayns = demodelay.tv_sec * GIG + demodelay.tv_nsec;
|
const uint64_t delayns = timespec_to_ns(&demodelay);
|
||||||
const int chunkcount = CHUNKS_VERT * CHUNKS_HORZ;
|
const int chunkcount = CHUNKS_VERT * CHUNKS_HORZ;
|
||||||
struct timespec cur;
|
struct timespec cur;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &cur);
|
clock_gettime(CLOCK_MONOTONIC, &cur);
|
||||||
// we don't want to spend more than demodelay * 5
|
// we don't want to spend more than demodelay * 5
|
||||||
const uint64_t totalns = delayns * 5;
|
const uint64_t totalns = delayns * 5;
|
||||||
const uint64_t deadline_ns = cur.tv_sec * GIG + cur.tv_nsec + totalns;
|
const uint64_t deadline_ns = timespec_to_ns(&cur) + totalns;
|
||||||
const uint64_t movens = totalns / MOVES;
|
const uint64_t movens = totalns / MOVES;
|
||||||
int hole = random() % chunkcount;
|
int hole = random() % chunkcount;
|
||||||
int holex, holey;
|
int holex, holey;
|
||||||
@ -99,7 +97,7 @@ fill_chunk(struct ncplane* n, int idx){
|
|||||||
char buf[4];
|
char buf[4];
|
||||||
int maxy, maxx;
|
int maxy, maxx;
|
||||||
ncplane_dim_yx(n, &maxy, &maxx);
|
ncplane_dim_yx(n, &maxy, &maxx);
|
||||||
snprintf(buf, sizeof(buf), "%02d", idx);
|
snprintf(buf, sizeof(buf), "%02d", idx + 1); // don't zero-index to viewer
|
||||||
uint64_t channels = 0;
|
uint64_t channels = 0;
|
||||||
int r = 64 + hidx * 10;
|
int r = 64 + hidx * 10;
|
||||||
int b = 64 + vidx * 30;
|
int b = 64 + vidx * 30;
|
||||||
@ -147,8 +145,6 @@ int sliding_puzzle_demo(struct notcurses* nc){
|
|||||||
notcurses_term_dim_yx(nc, &maxy, &maxx);
|
notcurses_term_dim_yx(nc, &maxy, &maxx);
|
||||||
// want at least 2x2 for each sliding chunk
|
// want at least 2x2 for each sliding chunk
|
||||||
if(maxy < CHUNKS_VERT * 2 || maxx < CHUNKS_HORZ * 2){
|
if(maxy < CHUNKS_VERT * 2 || maxx < CHUNKS_HORZ * 2){
|
||||||
fprintf(stderr, "Terminal too small, need at least %dx%d\n",
|
|
||||||
CHUNKS_HORZ, CHUNKS_VERT);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
// we want an 8x8 grid of chunks with a border. the leftover space will be unused
|
// we want an 8x8 grid of chunks with a border. the leftover space will be unused
|
||||||
|
@ -773,11 +773,12 @@ notcurses* notcurses_init(const notcurses_options* opts, FILE* outfp){
|
|||||||
ret->colors, ret->RGBflag ? "direct" : "palette",
|
ret->colors, ret->RGBflag ? "direct" : "palette",
|
||||||
__VERSION__, curses_version());
|
__VERSION__, curses_version());
|
||||||
#ifndef DISABLE_FFMPEG
|
#ifndef DISABLE_FFMPEG
|
||||||
fprintf(ret->ttyfp, " avformat %u.%u.%u\navutil %u.%u.%u\nswscale %u.%u.%u\n",
|
fprintf(ret->ttyfp, " avformat %u.%u.%u\n avutil %u.%u.%u\n swscale %u.%u.%u\n",
|
||||||
LIBAVFORMAT_VERSION_MAJOR, LIBAVFORMAT_VERSION_MINOR, LIBAVFORMAT_VERSION_MICRO,
|
LIBAVFORMAT_VERSION_MAJOR, LIBAVFORMAT_VERSION_MINOR, LIBAVFORMAT_VERSION_MICRO,
|
||||||
LIBAVUTIL_VERSION_MAJOR, LIBAVUTIL_VERSION_MINOR, LIBAVUTIL_VERSION_MICRO,
|
LIBAVUTIL_VERSION_MAJOR, LIBAVUTIL_VERSION_MINOR, LIBAVUTIL_VERSION_MICRO,
|
||||||
LIBSWSCALE_VERSION_MAJOR, LIBSWSCALE_VERSION_MINOR, LIBSWSCALE_VERSION_MICRO);
|
LIBSWSCALE_VERSION_MAJOR, LIBSWSCALE_VERSION_MINOR, LIBSWSCALE_VERSION_MICRO);
|
||||||
#else
|
#else
|
||||||
|
putp(tiparm(ret->setaf, 3));
|
||||||
fprintf(ret->ttyfp, " warning: built without ffmpeg support\n");
|
fprintf(ret->ttyfp, " warning: built without ffmpeg support\n");
|
||||||
#endif
|
#endif
|
||||||
if(!ret->RGBflag){ // FIXME
|
if(!ret->RGBflag){ // FIXME
|
||||||
|
Loading…
x
Reference in New Issue
Block a user