aboutsummaryrefslogtreecommitdiffstats
path: root/init.moon
diff options
context:
space:
mode:
Diffstat (limited to 'init.moon')
-rw-r--r--init.moon25
1 files changed, 14 insertions, 11 deletions
diff --git a/init.moon b/init.moon
index 0603c5b..41acabe 100644
--- a/init.moon
+++ b/init.moon
@@ -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