-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathabstractions.luau
64 lines (51 loc) · 1.59 KB
/
abstractions.luau
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
--!strict
-- !!! NOT UNIT TESTS !!!
local abstractions = require("@lib/abstractions")
local function tick(tick_time: number)
return function(run: (number) -> ())
local last = os.clock()
while true do
local now = os.clock()
if now < (last + tick_time) then
continue
end
local dt = now - last
run(dt)
last = now
end
end
end
-- Some weird luau screwery makes `debug.info(2, "sl")` for each of these `test/abstractions.luau`
local tick_a = abstractions.pipe("tick_a")
local tick_b = abstractions.pipe("tick_b")
local tick_c = abstractions.pipe("tick_c")
local tick_pipeline = abstractions.pipeline():with(tick_a):with(tick_b)
local function tick_a_system(dt: number)
print(`Running on tick_a, dt: {dt}s`)
end
local function tick_b_system(dt: number)
print(`Running on tick_b, dt: {dt}s`)
end
local function tick_c_system(dt: number)
print(`Running on tick_c, dt: {dt}s`)
end
abstractions.hook("SystemAdd", function(id)
print(`Added system {id}`)
end)
abstractions.hook("SystemCall", function(id)
print(`Called system {id}`)
end)
abstractions.hook("SystemChange", function(id)
print(`Changed system {id}`)
end)
abstractions.hook("SystemRemove", function(id)
print(`Removed system {id}`)
end)
local scheduler = abstractions
.scheduler()
:with_pipeline(tick_pipeline, tick(1 / 5))
:with_pipe(tick_c, tick(1 / 6), tick_pipeline)
:with_system(tick_a_system, tick_a)
:with_system(tick_b_system, tick_b)
:with_system(tick_c_system, tick_c)
:start()