@rbxts/planck 0.1.3-rc.4 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/DependencyGraph.luau +180 -0
- package/out/Phase.d.ts +0 -9
- package/out/Phase.luau +1 -49
- package/out/Pipeline.d.ts +1 -1
- package/out/Pipeline.luau +33 -21
- package/out/Scheduler.d.ts +13 -16
- package/out/Scheduler.luau +313 -172
- package/out/conditions.d.ts +14 -0
- package/out/conditions.luau +151 -0
- package/out/index.d.ts +6 -0
- package/out/init.luau +41 -47
- package/out/types.d.ts +5 -1
- package/out/utils.luau +95 -17
- package/package.json +1 -1
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
local AdjacencyMatrix = {}
|
|
2
|
+
AdjacencyMatrix.__index = AdjacencyMatrix
|
|
3
|
+
|
|
4
|
+
function AdjacencyMatrix:__tostring()
|
|
5
|
+
local s = "\n"
|
|
6
|
+
|
|
7
|
+
for i = 1, self.length do
|
|
8
|
+
if i == 1 then
|
|
9
|
+
s ..= "\n"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
local sub = ""
|
|
13
|
+
for j = 1, self.width do
|
|
14
|
+
if j == self.width then
|
|
15
|
+
sub ..= `{self.matrix[i][j]}`
|
|
16
|
+
continue
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
sub ..= `{self.matrix[i][j]}, `
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
sub ..= "\n"
|
|
23
|
+
s ..= sub
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
return s
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
function AdjacencyMatrix:extend()
|
|
30
|
+
self.length = (self.length :: number) + 1
|
|
31
|
+
self.width = (self.length :: number) + 1
|
|
32
|
+
|
|
33
|
+
self.matrix[self.length] = {}
|
|
34
|
+
for j = 1, self.width do
|
|
35
|
+
self.matrix[self.length][j] = 0
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
for i = 1, self.length do
|
|
39
|
+
self.matrix[i][self.width] = 0
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
function AdjacencyMatrix:setEdge(i, j, val)
|
|
44
|
+
self.matrix[i][j] = val
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
function AdjacencyMatrix:toAdjacencyList()
|
|
48
|
+
local list = {}
|
|
49
|
+
|
|
50
|
+
for i = 1, self.length do
|
|
51
|
+
list[i] = {}
|
|
52
|
+
for j = 1, self.width do
|
|
53
|
+
if self.matrix[i][j] ~= 0 then
|
|
54
|
+
table.insert(list[i], j)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
return list
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
function AdjacencyMatrix:topologicalSort(): { number }?
|
|
63
|
+
local adjacencyList = self:toAdjacencyList()
|
|
64
|
+
|
|
65
|
+
local result = {}
|
|
66
|
+
local inDegrees = table.create(self.length, 0)
|
|
67
|
+
|
|
68
|
+
for i = 1, self.length do
|
|
69
|
+
for _, j in adjacencyList[i] do
|
|
70
|
+
inDegrees[j] += 1
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
local queue = {}
|
|
75
|
+
for i = 1, self.length do
|
|
76
|
+
if inDegrees[i] == 0 then
|
|
77
|
+
table.insert(queue, i)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
while #queue ~= 0 do
|
|
82
|
+
local i = table.remove(queue, 1) :: number
|
|
83
|
+
table.insert(result, i)
|
|
84
|
+
|
|
85
|
+
for _, j in adjacencyList[i] do
|
|
86
|
+
inDegrees[j] -= 1
|
|
87
|
+
if inDegrees[j] == 0 then
|
|
88
|
+
table.insert(queue, j)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
if #result ~= self.length then
|
|
94
|
+
return nil
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
return result
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
function AdjacencyMatrix.new()
|
|
101
|
+
return setmetatable({
|
|
102
|
+
matrix = {},
|
|
103
|
+
length = 0,
|
|
104
|
+
width = 0,
|
|
105
|
+
}, AdjacencyMatrix)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
local DependencyGraph = {}
|
|
109
|
+
DependencyGraph.__index = DependencyGraph
|
|
110
|
+
|
|
111
|
+
function DependencyGraph:getOrderedList(): { any }?
|
|
112
|
+
local orderedList = {}
|
|
113
|
+
|
|
114
|
+
local topologicalSort = self.matrix:topologicalSort()
|
|
115
|
+
if not topologicalSort then
|
|
116
|
+
return nil
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
for _, i in topologicalSort do
|
|
120
|
+
table.insert(orderedList, self.nodes[i])
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
return orderedList
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
function DependencyGraph:insertBefore(node, beforeNode)
|
|
127
|
+
if not table.find(self.nodes, beforeNode) then
|
|
128
|
+
error("Node not found in DependencyGraph:insertBefore(_, unknown)")
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
table.insert(self.nodes, node)
|
|
132
|
+
local j = #self.nodes
|
|
133
|
+
local i = table.find(self.nodes, beforeNode)
|
|
134
|
+
|
|
135
|
+
self.matrix:extend()
|
|
136
|
+
self.matrix:setEdge(j, i, 1)
|
|
137
|
+
|
|
138
|
+
return self
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
function DependencyGraph:insertAfter(node, afterNode)
|
|
142
|
+
if not table.find(self.nodes, afterNode) then
|
|
143
|
+
error("Node not found in DependencyGraph:insertAfter(_, unknown)")
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
table.insert(self.nodes, node)
|
|
147
|
+
|
|
148
|
+
local j = #self.nodes
|
|
149
|
+
local i = table.find(self.nodes, afterNode)
|
|
150
|
+
|
|
151
|
+
self.matrix:extend()
|
|
152
|
+
self.matrix:setEdge(i, j, 1)
|
|
153
|
+
|
|
154
|
+
return self
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
function DependencyGraph:insert(node)
|
|
158
|
+
local i = #self.nodes
|
|
159
|
+
table.insert(self.nodes, node)
|
|
160
|
+
local j = #self.nodes
|
|
161
|
+
|
|
162
|
+
self.matrix:extend()
|
|
163
|
+
|
|
164
|
+
if i ~= 0 then
|
|
165
|
+
self.matrix:setEdge(i, j, 1)
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
return self
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
function DependencyGraph.new()
|
|
172
|
+
return setmetatable({
|
|
173
|
+
nodes = {},
|
|
174
|
+
matrix = AdjacencyMatrix.new(),
|
|
175
|
+
length = 0,
|
|
176
|
+
width = 0,
|
|
177
|
+
}, DependencyGraph)
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
return DependencyGraph
|
package/out/Phase.d.ts
CHANGED
|
@@ -3,15 +3,6 @@ declare class Phase {
|
|
|
3
3
|
static readonly PreStartup: Phase
|
|
4
4
|
static readonly Startup: Phase
|
|
5
5
|
static readonly PostStartup: Phase
|
|
6
|
-
static readonly PreRender: Phase
|
|
7
|
-
static readonly PreAnimation: Phase
|
|
8
|
-
static readonly PreSimulation: Phase
|
|
9
|
-
static readonly PostSimulation: Phase
|
|
10
|
-
static readonly First: Phase
|
|
11
|
-
static readonly PreUpdate: Phase
|
|
12
|
-
static readonly Update: Phase
|
|
13
|
-
static readonly PostUpdate: Phase
|
|
14
|
-
static readonly Last: Phase
|
|
15
6
|
}
|
|
16
7
|
|
|
17
8
|
export = Phase;
|
package/out/Phase.luau
CHANGED
|
@@ -38,52 +38,4 @@ Phase.PreStartup = Phase.new("PreStartup")
|
|
|
38
38
|
Phase.Startup = Phase.new("Startup")
|
|
39
39
|
Phase.PostStartup = Phase.new("PostStartup")
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
--- @within Phase
|
|
43
|
-
--- Runs on the `RunService.PreRender` Event.
|
|
44
|
-
|
|
45
|
-
--- @prop PreAnimation Phase
|
|
46
|
-
--- @within Phase
|
|
47
|
-
--- Runs on the `RunService.PreAnimation` Event.
|
|
48
|
-
|
|
49
|
-
--- @prop PreSimulation Phase
|
|
50
|
-
--- @within Phase
|
|
51
|
-
--- Runs on the `RunService.PreSimulation` Event.
|
|
52
|
-
|
|
53
|
-
--- @prop PostSimulation Phase
|
|
54
|
-
--- @within Phase
|
|
55
|
-
--- Runs on the `RunService.PostSimulation` Event.
|
|
56
|
-
|
|
57
|
-
Phase.PreRender = Phase.new("PreRender")
|
|
58
|
-
Phase.PreAnimation = Phase.new("PreAnimation")
|
|
59
|
-
Phase.PreSimulation = Phase.new("PreSimulation")
|
|
60
|
-
Phase.PostSimulation = Phase.new("PostSimulation")
|
|
61
|
-
|
|
62
|
-
--- @prop First Phase
|
|
63
|
-
--- @within Phase
|
|
64
|
-
--- Will always run first on the `RunService.Heartbeat` Event.
|
|
65
|
-
|
|
66
|
-
--- @prop PreUpdate Phase
|
|
67
|
-
--- @within Phase
|
|
68
|
-
--- Runs before the `Update` Phase.
|
|
69
|
-
|
|
70
|
-
--- @prop Update Phase
|
|
71
|
-
--- @within Phase
|
|
72
|
-
--- Runs on the `RunService.Heartbeat` Event.
|
|
73
|
-
--- This is the default Phase systems will run on.
|
|
74
|
-
|
|
75
|
-
--- @prop PostUpdate Phase
|
|
76
|
-
--- @within Phase
|
|
77
|
-
--- Runs after the `Update` Phase.
|
|
78
|
-
|
|
79
|
-
--- @prop Last Phase
|
|
80
|
-
--- @within Phase
|
|
81
|
-
--- Will always run last on the `RunService.Heartbeat` Event.
|
|
82
|
-
|
|
83
|
-
Phase.First = Phase.new("First")
|
|
84
|
-
Phase.PreUpdate = Phase.new("PreUpdate")
|
|
85
|
-
Phase.Update = Phase.new("Update")
|
|
86
|
-
Phase.PostUpdate = Phase.new("PostUpdate")
|
|
87
|
-
Phase.Last = Phase.new("Last")
|
|
88
|
-
|
|
89
|
-
return Phase
|
|
41
|
+
return Phase
|
package/out/Pipeline.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ declare class Pipeline {
|
|
|
4
4
|
constructor(debugName?: string)
|
|
5
5
|
insert(phase: Phase) : Pipeline
|
|
6
6
|
insertAfter(phase: Phase, after: Phase): Pipeline
|
|
7
|
-
|
|
7
|
+
insertBefore(phase: Phase, before: Phase): Pipeline
|
|
8
8
|
static readonly Startup: Pipeline
|
|
9
9
|
}
|
|
10
10
|
|
package/out/Pipeline.luau
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
--!nonstrict
|
|
2
|
+
local DependencyGraph = require("./DependencyGraph")
|
|
3
|
+
local Phase = require("./Phase")
|
|
4
|
+
|
|
2
5
|
--- @class Pipeline
|
|
3
6
|
---
|
|
4
7
|
--- Pipelines represent a set of ordered Phases. Systems cannot be
|
|
5
8
|
--- assigned to Pipelines themselves, but rather to Phases within
|
|
6
9
|
--- those Pipelines.
|
|
7
|
-
|
|
8
10
|
local Pipeline = {}
|
|
9
11
|
Pipeline.__index = Pipeline
|
|
10
12
|
|
|
@@ -19,22 +21,43 @@ end
|
|
|
19
21
|
---
|
|
20
22
|
--- Adds a Phase to the Pipeline, ordering it implicitly.
|
|
21
23
|
function Pipeline:insert(phase)
|
|
22
|
-
|
|
24
|
+
self.dependencyGraph:insert(phase)
|
|
23
25
|
return self
|
|
24
26
|
end
|
|
25
27
|
|
|
26
|
-
--- @method
|
|
28
|
+
--- @method insertAfter
|
|
27
29
|
--- @within Pipeline
|
|
28
30
|
--- @param phase Phase
|
|
29
31
|
--- @param after Phase
|
|
30
32
|
--- @return Pipeline
|
|
31
33
|
---
|
|
32
34
|
--- Adds a Phase to the Pipeline after another Phase, ordering it explicitly.
|
|
33
|
-
function Pipeline:insertAfter(phase,
|
|
34
|
-
local i = table.find(self.
|
|
35
|
-
assert(
|
|
35
|
+
function Pipeline:insertAfter(phase, afterPhase)
|
|
36
|
+
local i = table.find(self.dependencyGraph.nodes, afterPhase)
|
|
37
|
+
assert(
|
|
38
|
+
i,
|
|
39
|
+
"Unknown Phase in Pipeline:insertAfter(_, unknown), try adding this Phase to the Pipeline."
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
self.dependencyGraph:insertAfter(phase, afterPhase)
|
|
43
|
+
return self
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
--- @method insertBefore
|
|
47
|
+
--- @within Pipeline
|
|
48
|
+
--- @param phase Phase
|
|
49
|
+
--- @param before Phase
|
|
50
|
+
--- @return Pipeline
|
|
51
|
+
---
|
|
52
|
+
--- Adds a Phase to the Pipeline before another Phase, ordering it explicitly.
|
|
53
|
+
function Pipeline:insertBefore(phase, beforePhase)
|
|
54
|
+
local i = table.find(self.dependencyGraph.nodes, beforePhase)
|
|
55
|
+
assert(
|
|
56
|
+
i,
|
|
57
|
+
"Unknown Phase in Pipeline:insertBefore(_, unknown), try adding this Phase to the Pipeline."
|
|
58
|
+
)
|
|
36
59
|
|
|
37
|
-
|
|
60
|
+
self.dependencyGraph:insertBefore(phase, beforePhase)
|
|
38
61
|
return self
|
|
39
62
|
end
|
|
40
63
|
|
|
@@ -47,7 +70,7 @@ function Pipeline.new(name: string?)
|
|
|
47
70
|
return setmetatable({
|
|
48
71
|
_name = name,
|
|
49
72
|
_type = "pipeline",
|
|
50
|
-
|
|
73
|
+
dependencyGraph = DependencyGraph.new(),
|
|
51
74
|
}, Pipeline)
|
|
52
75
|
end
|
|
53
76
|
|
|
@@ -60,15 +83,4 @@ Pipeline.Startup = Pipeline.new()
|
|
|
60
83
|
:insert(Phase.Startup)
|
|
61
84
|
:insert(Phase.PostStartup)
|
|
62
85
|
|
|
63
|
-
|
|
64
|
-
--- @within Pipeline
|
|
65
|
-
---
|
|
66
|
-
--- A Pipeline containing the `First`, `PreUpdate`, `Update`, `PostUpdate`, and `Last` phases.
|
|
67
|
-
Pipeline.Main = Pipeline.new()
|
|
68
|
-
:insert(Phase.First)
|
|
69
|
-
:insert(Phase.PreUpdate)
|
|
70
|
-
:insert(Phase.Update)
|
|
71
|
-
:insert(Phase.PostUpdate)
|
|
72
|
-
:insert(Phase.Last)
|
|
73
|
-
|
|
74
|
-
return Pipeline
|
|
86
|
+
return Pipeline
|
package/out/Scheduler.d.ts
CHANGED
|
@@ -6,25 +6,22 @@ declare class Scheduler<T extends unknown[]> {
|
|
|
6
6
|
/** @hidden */
|
|
7
7
|
_orderedPhases: Phase[]
|
|
8
8
|
Hooks: Hooks["Hooks"]
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
insert(phase: Phase): Scheduler<T>
|
|
12
|
-
insert(phase: Pipeline): Scheduler<T>
|
|
13
|
-
getDeltaTime(): number
|
|
14
|
-
insert(phase: Phase, instance: EventInstance | EventLike): Scheduler<T>
|
|
15
|
-
insert(pipeline: Pipeline, instance: EventInstance | EventLike): Scheduler<T>
|
|
16
|
-
runAll(): Scheduler<T>
|
|
17
|
-
run(system: System<T>): Scheduler<T>
|
|
18
|
-
run(phase: Phase): Scheduler<T>
|
|
19
|
-
run(pipeline: Pipeline): Scheduler<T>
|
|
20
|
-
setRunCondition(system: System<T>, fn: (...args: T) => boolean): Scheduler<T>
|
|
21
|
-
setRunCondition(phase: Phase, fn: (...args: T) => boolean): Scheduler<T>
|
|
22
|
-
setRunCondition(pipeline: Pipeline, fn: (...args: T) => boolean): Scheduler<T>
|
|
23
|
-
removeSystem(system: System<T>): Scheduler<T>
|
|
9
|
+
cleanup(): void
|
|
10
|
+
addRunCondition(dependent: System<T>, fn: (...args: T) => boolean): Scheduler<T>
|
|
24
11
|
replaceSystem(oldSystem: System<T>, newSystem: System<T>): Scheduler<T>
|
|
12
|
+
removeSystem(system: System<T>): Scheduler<T>
|
|
25
13
|
editSystem(system: System<T>, phase: Phase): Scheduler<T>
|
|
26
14
|
addSystem(system: System<T>, phase?: Phase): Scheduler<T>
|
|
27
|
-
addSystems(
|
|
15
|
+
addSystems(systems: System<T>[], phase?: Phase): Scheduler<T>
|
|
16
|
+
insertBefore(dependent: Phase, before: Phase): Scheduler<T>
|
|
17
|
+
insertBefore(dependent: Pipeline, before: Phase): Scheduler<T>
|
|
18
|
+
insertAfter(phase: Phase, after: Phase | Pipeline): Scheduler<T>
|
|
19
|
+
insertAfter(pipeline: Pipeline, after: Phase | Pipeline): Scheduler<T>
|
|
20
|
+
insert(dependent: Phase | Pipeline, instance: EventInstance | EventLike, event?: string | EventLike): Scheduler<T>
|
|
21
|
+
insert(dependent: Phase | Pipeline): Scheduler<T>
|
|
22
|
+
runAll(): Scheduler<T>
|
|
23
|
+
run(dependent: System<T> | Phase | Pipeline): Scheduler<T>
|
|
24
|
+
getDeltaTime(): number
|
|
28
25
|
addPlugin(plugin: Plugin): Scheduler<T>
|
|
29
26
|
/** @hidden */
|
|
30
27
|
_addHook<K extends keyof HookFunctionMap>(hook: K, fn: (info: HookFunctionArgs<K, T>) => void): void
|