diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2020-02-10 13:43:09 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2020-02-10 13:43:09 +0000 |
| commit | 11f3f88323a9f1b120b15a634538b05f1e5ccf3c (patch) | |
| tree | 2070209852da84e604e9767876f7a0ae46947694 /init.moon | |
| parent | re-fix functions (diff) | |
| download | alive-11f3f88323a9f1b120b15a634538b05f1e5ccf3c.tar.gz alive-11f3f88323a9f1b120b15a634538b05f1e5ccf3c.zip | |
switch from luaposix to luasystem
Diffstat (limited to 'init.moon')
| -rw-r--r-- | init.moon | 25 |
1 files changed, 14 insertions, 11 deletions
@@ -1,5 +1,5 @@ -- run from CLI -import clock_gettime, nanosleep, CLOCK_MONOTONIC from require 'posix.time' +import monotime, sleep from require 'system' import Logger from require 'logger' import Registry from require 'registry' import Copilot from require 'copilot' @@ -18,13 +18,18 @@ for a in *arg Logger.init arguments.log delta = do - gettime = -> - spec = clock_gettime CLOCK_MONOTONIC - spec.tv_sec + spec.tv_nsec * 1e-9 - - local last, time + period = 1 / 60 + + local last -> - time = gettime! + if last + target, current = (last + period), monotime! + if current > target + L\warn 'Frame Skipped!' + else + sleep target - current + + time = monotime! with time - (last or time) last = time @@ -32,9 +37,7 @@ env = Registry! copilot = Copilot arguments[1], env while true - copilot\poll! - dt = delta! - env\update dt - assert nanosleep tv_sec: 0, tv_nsec: math.floor 1e9 / 60 + copilot\poll! + env\update dt |
