diff options
| author | eunhhu <[email protected]> | 2026-09-26 17:58:26 +0100 |
|---|---|---|
| committer | eunhhu <[email protected]> | 2026-09-26 17:58:26 +0100 |
| commit | b466603358f8fa5a74551a9819fdd54ad124ef0c (patch) | |
| tree | 6f34265f30455589201222521c1a452274a0601d /src/web.c | |
| parent | 15c4616e19d997c64a983e39501289c7d9f50d0a (diff) | |
| download | vega-b466603358f8fa5a74551a9819fdd54ad124ef0c.tar.gz vega-b466603358f8fa5a74551a9819fdd54ad124ef0c.zip | |
Give live surfaces a clock and run timers; add a stopwatch
The terminal and the web page set the time events see to the wall clock
and tick an app's timers on time: each round ticks what is due, draws,
then waits for input, a frame or the next tick, and a tick is news to
every open page at once. Scripts have no clock: time MS sets the time
the next events see and tick TIMER ticks, so an app that uses time
replays exactly. A module swap reschedules the timers.
examples/stopwatch.aup runs on every surface; the checks drive it by
script, on a pseudo-terminal by the clock, and on the web page.
Diffstat (limited to 'src/web.c')
| -rw-r--r-- | src/web.c | 17 |
1 files changed, 14 insertions, 3 deletions
@@ -382,7 +382,12 @@ int vega_web(PureApp *app, const VegaScreen *screen, const char *listen_on, unsi signal(SIGPIPE, SIG_IGN); static Client clients[CLIENTS]; for (unsigned i = 0; i < CLIENTS; ++i) clients[i].fd = -1; + VegaTimers timers; + vega_timers_start(&timers, app->module, vega_now()); while (!stopping) { + /* Tick what is due; every page hears of it this round, without waiting. */ + bool ticked = false; + long due = vega_timers_run(&timers, app, vega_now(), &ticked); struct pollfd fds[CLIENTS + 1]; unsigned slot[CLIENTS + 1], count = 1; fds[0] = (struct pollfd){listener, POLLIN, 0}; @@ -392,11 +397,17 @@ int vega_web(PureApp *app, const VegaScreen *screen, const char *listen_on, unsi fds[count] = (struct pollfd){c->fd, (short)(POLLIN | (c->out_at < c->out.used ? POLLOUT : 0)), 0}; slot[count++] = i; } - int ready = poll(fds, count, screen->ticks ? 33 : reload ? 200 : 1000); + int timeout = ticked ? 0 : screen->ticks ? 33 : reload ? 200 : 1000; + if (due >= 0 && due < timeout) timeout = (int)due; + int ready = poll(fds, count, timeout); if (ready < 0 && errno != EINTR) break; - bool changed = false; + bool changed = ticked; + app->now = vega_now(); /* what the events of this round see */ if (ready == 0 && screen->ticks) changed = pure_app_frame(app) == PURE_OK; - if (reload && reload()) changed = true; /* a new module: every page draws it */ + if (reload && reload()) { /* a new module: every page draws it */ + changed = true; + vega_timers_start(&timers, app->module, app->now); + } if (fds[0].revents & POLLIN) for (int fd; (fd = accept4(listener, NULL, NULL, SOCK_NONBLOCK | SOCK_CLOEXEC)) >= 0;) { unsigned free_slot = CLIENTS; |
