@quenty/immediateutils 1.4.0 → 1.6.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/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [1.6.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/immediateutils@1.5.0...@quenty/immediateutils@1.6.0) (2026-09-02)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @quenty/immediateutils
|
|
9
|
+
|
|
10
|
+
# [1.5.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/immediateutils@1.4.0...@quenty/immediateutils@1.5.0) (2026-09-01)
|
|
11
|
+
|
|
12
|
+
**Note:** Version bump only for package @quenty/immediateutils
|
|
13
|
+
|
|
6
14
|
# [1.4.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/immediateutils@1.3.0...@quenty/immediateutils@1.4.0) (2026-08-28)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @quenty/immediateutils
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/immediateutils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Immediate-mode ECS loop and hooks implemented via jecs+iris addons",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"@quenty/servicebag": "11.21.0",
|
|
43
43
|
"@quenty/signal": "7.13.2",
|
|
44
44
|
"@quenty/spring": "10.12.1",
|
|
45
|
-
"@quenty/tie": "10.
|
|
45
|
+
"@quenty/tie": "10.50.0",
|
|
46
46
|
"@quenty/valueobject": "13.38.0",
|
|
47
47
|
"@quentystudios/jest-lua": "3.10.0-quenty.2"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "278f4ca25486a8ba0601704b27a11da8c77499c9"
|
|
53
53
|
}
|
|
@@ -19,7 +19,7 @@ local ImmediateCoreUtils = {}
|
|
|
19
19
|
-- Additional functionality can be installed if a package has an installer function
|
|
20
20
|
-- that takes in a runtime table and returns a modified runtime table.
|
|
21
21
|
export type ImmediateRuntime<CustomBlackboardType = {}> = {
|
|
22
|
-
--
|
|
22
|
+
-- Scheduler debug: yield-detection around systems. Independent of Jecs.world(DEBUG).
|
|
23
23
|
DEBUG: boolean,
|
|
24
24
|
|
|
25
25
|
-- A single maid that cleans up the entire runtime.
|
|
@@ -64,18 +64,20 @@ function ImmediateCoreUtils.createImmediateRuntime<CustomBlackboardType>(
|
|
|
64
64
|
serviceBag: ServiceBag.ServiceBag,
|
|
65
65
|
requireCallback: (path: string) -> any,
|
|
66
66
|
initialBlackboard: CustomBlackboardType?,
|
|
67
|
-
plugin: Plugin
|
|
68
|
-
|
|
67
|
+
plugin: Plugin?,
|
|
68
|
+
DEBUG: boolean?
|
|
69
|
+
): ImmediateRuntime<CustomBlackboardType>
|
|
69
70
|
local maid = Maid.new()
|
|
70
71
|
local usingServiceBag = serviceBag or maid:Add(ServiceBag.new())
|
|
71
72
|
|
|
72
73
|
-- Create final runtime table
|
|
73
|
-
local runtime: ImmediateRuntime
|
|
74
|
+
local runtime: ImmediateRuntime<CustomBlackboardType>
|
|
74
75
|
runtime = {
|
|
75
76
|
require = requireCallback,
|
|
76
77
|
serviceBag = usingServiceBag,
|
|
77
78
|
maid = maid,
|
|
78
79
|
blackboard = (initialBlackboard :: any) or {},
|
|
80
|
+
DEBUG = DEBUG or false,
|
|
79
81
|
|
|
80
82
|
errorlog = {
|
|
81
83
|
lastErrorShout = 0,
|
|
@@ -87,7 +89,7 @@ function ImmediateCoreUtils.createImmediateRuntime<CustomBlackboardType>(
|
|
|
87
89
|
end,
|
|
88
90
|
|
|
89
91
|
plugin = plugin,
|
|
90
|
-
} :: ImmediateRuntime
|
|
92
|
+
} :: ImmediateRuntime<CustomBlackboardType>
|
|
91
93
|
|
|
92
94
|
return runtime
|
|
93
95
|
end
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
--!nonstrict
|
|
2
2
|
--[=[
|
|
3
|
-
@class
|
|
3
|
+
@class ImmediateDeferInstall
|
|
4
4
|
|
|
5
|
-
Runtime decorator: adds rt.
|
|
6
|
-
middleware to drain
|
|
5
|
+
Runtime decorator: adds `rt.defer` / `rt.defer_buffer`, and registers
|
|
6
|
+
postSystem middleware to drain that queue after each gameplay system.
|
|
7
7
|
]=]
|
|
8
8
|
local require = require(script.Parent.loader).load(script)
|
|
9
9
|
|
|
@@ -29,20 +29,19 @@ return function<Rt>(
|
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
scheduler:RegisterSystem({
|
|
32
|
-
name = "
|
|
32
|
+
name = "mw_immediate_defer_flush",
|
|
33
33
|
postSystem = true,
|
|
34
34
|
priority = DEFAULT_PRIORITY,
|
|
35
|
-
notProtected = false,
|
|
36
35
|
system = function()
|
|
37
36
|
-- Snapshot-and-clear first so a callback error cannot leave the live
|
|
38
|
-
--
|
|
37
|
+
-- buffer uncleared and double-fire next postSystem.
|
|
39
38
|
assert(rt.defer_buffer, "rt.defer_buffer is not defined")
|
|
40
|
-
|
|
39
|
+
local snapshot = table.clone(rt.defer_buffer)
|
|
40
|
+
table.clear(rt.defer_buffer)
|
|
41
|
+
for _, callback in ipairs(snapshot) do
|
|
41
42
|
callback()
|
|
42
43
|
end
|
|
43
|
-
table.clear(rt.defer_buffer)
|
|
44
44
|
end,
|
|
45
|
-
Destroy = function() end,
|
|
46
45
|
})
|
|
47
46
|
|
|
48
47
|
return rt
|
|
@@ -66,7 +66,7 @@ export type ImmediateSchedulableSystem<CallShape = (...any) -> ()> = {
|
|
|
66
66
|
-- RegisterDescendantModuleScripts fills this from the ModuleScript name if omitted.
|
|
67
67
|
name: string?,
|
|
68
68
|
|
|
69
|
-
--
|
|
69
|
+
-- Opt out of xpcall and DEBUG yield-detection. Errors propagate to the caller.
|
|
70
70
|
notProtected: boolean?,
|
|
71
71
|
|
|
72
72
|
-- Hard-coded slot topology: preTick -> (preSystem -> system -> postSystem)* -> postTick.
|
|
@@ -87,6 +87,7 @@ export type ImmediateScheduler =
|
|
|
87
87
|
typeof(setmetatable(
|
|
88
88
|
{} :: {
|
|
89
89
|
_systemDictionary: { [string]: SchedulableSystem },
|
|
90
|
+
_profileLabels: { [string]: string },
|
|
90
91
|
_sortFlag: boolean,
|
|
91
92
|
_sorted_systems: { SchedulableSystem },
|
|
92
93
|
_sorted_preSystem: { SchedulableSystem },
|
|
@@ -107,6 +108,7 @@ function ImmediateScheduler.new(): ImmediateScheduler
|
|
|
107
108
|
local self = setmetatable(BaseObject.new() :: any, ImmediateScheduler)
|
|
108
109
|
|
|
109
110
|
self._systemDictionary = {}
|
|
111
|
+
self._profileLabels = {}
|
|
110
112
|
|
|
111
113
|
-- If set to true, will re-order systems for next tick
|
|
112
114
|
self._sortFlag = false
|
|
@@ -134,7 +136,10 @@ local function _sortSystemsInPlace(array: { SchedulableSystem })
|
|
|
134
136
|
table.sort(array, function(a, b)
|
|
135
137
|
local aPriority = _systemSortKey(a)
|
|
136
138
|
local bPriority = _systemSortKey(b)
|
|
137
|
-
|
|
139
|
+
if aPriority ~= bPriority then
|
|
140
|
+
return aPriority < bPriority
|
|
141
|
+
end
|
|
142
|
+
return (a.name or "") < (b.name or "")
|
|
138
143
|
end)
|
|
139
144
|
end
|
|
140
145
|
|
|
@@ -177,30 +182,42 @@ end
|
|
|
177
182
|
local SYSTEM_ERROR_SUPPRESS_SECONDS = 10
|
|
178
183
|
local SYSTEM_OVERALL_SUPPRESS_ERRORS = 5
|
|
179
184
|
|
|
180
|
-
function
|
|
181
|
-
|
|
182
|
-
rt
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
185
|
+
local function _invokeSystem(rt: ImmediateRuntime, system: SchedulableSystem, label: string, ...: any)
|
|
186
|
+
debug.profilebegin(label)
|
|
187
|
+
system.system(rt, ...)
|
|
188
|
+
debug.profileend()
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
function ImmediateScheduler._runSystem(self: ImmediateScheduler, rt: ImmediateRuntime, system: SchedulableSystem, ...)
|
|
192
|
+
local label = self._profileLabels[system.name :: string] or (system.name :: string)
|
|
193
|
+
|
|
194
|
+
if system.notProtected == true then
|
|
195
|
+
_invokeSystem(rt, system, label, ...)
|
|
196
|
+
return
|
|
197
|
+
end
|
|
198
|
+
|
|
186
199
|
local errorLog = rt.errorlog
|
|
187
200
|
local ok, errmsg = xpcall(function(...)
|
|
188
201
|
if rt.DEBUG then
|
|
202
|
+
debug.profilebegin(label)
|
|
189
203
|
local args = table.pack(...)
|
|
190
204
|
local thread = coroutine.create(function()
|
|
191
205
|
system.system(rt, unpack(args, 1, args.n))
|
|
192
206
|
end)
|
|
193
207
|
local resumed, err = coroutine.resume(thread)
|
|
194
208
|
if not resumed then
|
|
209
|
+
debug.profileend()
|
|
195
210
|
error(err)
|
|
196
211
|
end
|
|
197
212
|
if coroutine.status(thread) ~= "dead" then
|
|
198
213
|
local traceback = debug.traceback(thread)
|
|
199
214
|
task.cancel(thread)
|
|
200
|
-
|
|
215
|
+
debug.profileend()
|
|
216
|
+
error(`ImmediateScheduler system {system.name} yielded:\n{traceback}`)
|
|
201
217
|
end
|
|
218
|
+
debug.profileend()
|
|
202
219
|
else
|
|
203
|
-
|
|
220
|
+
_invokeSystem(rt, system, label, ...)
|
|
204
221
|
end
|
|
205
222
|
end, function(err)
|
|
206
223
|
return debug.traceback(err, 2)
|
|
@@ -229,7 +246,7 @@ function ImmediateScheduler._runProtectedSystem(
|
|
|
229
246
|
>= SYSTEM_OVERALL_SUPPRESS_ERRORS
|
|
230
247
|
|
|
231
248
|
if weErroredAfterCooldown and weErroredAfterOverallCooldown then
|
|
232
|
-
task.spawn(error, `[
|
|
249
|
+
task.spawn(error, `[ImmediateScheduler] {key}, traceback: {foundEntry.traceback}`)
|
|
233
250
|
foundEntry.lastShoutedAt = os.clock()
|
|
234
251
|
errorLog.lastErrorShout = os.clock()
|
|
235
252
|
end
|
|
@@ -241,36 +258,53 @@ function ImmediateScheduler.Tick(self: ImmediateScheduler, rt: ImmediateRuntime,
|
|
|
241
258
|
self:_sortSystemArrays()
|
|
242
259
|
end
|
|
243
260
|
|
|
261
|
+
debug.profilebegin("ImmediateScheduler.Tick")
|
|
262
|
+
|
|
263
|
+
debug.profilebegin("sorted_preTick")
|
|
244
264
|
for _, systemTable in self._sorted_preTick do
|
|
245
|
-
self:
|
|
265
|
+
self:_runSystem(rt, systemTable, ...)
|
|
246
266
|
rt.previousRawSystem = systemTable
|
|
247
267
|
end
|
|
268
|
+
debug.profileend()
|
|
269
|
+
|
|
270
|
+
debug.profilebegin("sorted_systems")
|
|
248
271
|
for _, systemTable in self._sorted_systems do
|
|
272
|
+
-- Run all pre-system middleware before this one system.
|
|
249
273
|
for _, preSystemTable in self._sorted_preSystem do
|
|
250
|
-
self:
|
|
274
|
+
self:_runSystem(rt, preSystemTable, ...)
|
|
251
275
|
rt.previousRawSystem = preSystemTable
|
|
252
276
|
end
|
|
253
|
-
|
|
277
|
+
|
|
278
|
+
-- The main system.
|
|
279
|
+
self:_runSystem(rt, systemTable, ...)
|
|
254
280
|
rt.previousRawSystem = systemTable
|
|
255
281
|
rt.previousSystem = systemTable
|
|
282
|
+
|
|
283
|
+
-- Run all post-system middleware after this one system.
|
|
256
284
|
for _, postSystemTable in self._sorted_postSystem do
|
|
257
|
-
self:
|
|
285
|
+
self:_runSystem(rt, postSystemTable, ...)
|
|
258
286
|
rt.previousRawSystem = postSystemTable
|
|
259
287
|
end
|
|
260
288
|
end
|
|
289
|
+
debug.profileend()
|
|
290
|
+
|
|
291
|
+
debug.profilebegin("sorted_postTick")
|
|
261
292
|
for _, systemTable in self._sorted_postTick do
|
|
262
|
-
self:
|
|
293
|
+
self:_runSystem(rt, systemTable, ...)
|
|
263
294
|
rt.previousRawSystem = systemTable
|
|
264
295
|
end
|
|
296
|
+
debug.profileend()
|
|
297
|
+
|
|
298
|
+
debug.profileend()
|
|
265
299
|
end
|
|
266
300
|
|
|
267
301
|
function ImmediateScheduler.RegisterSystem(self: ImmediateScheduler, systemTable: SchedulableSystem)
|
|
268
|
-
-- TODO: upsert into the schedule by `name`, then sort by priority/name.
|
|
269
302
|
local systemName = assert(systemTable.name, "ImmediateSchedulableSystem requires name")
|
|
270
303
|
if self._systemDictionary[systemName] then
|
|
271
304
|
self:UnregisterSystem(systemName)
|
|
272
305
|
end
|
|
273
306
|
self._systemDictionary[systemName] = systemTable
|
|
307
|
+
self._profileLabels[systemName] = `sys.{systemName}`
|
|
274
308
|
self._sortFlag = true
|
|
275
309
|
return function()
|
|
276
310
|
self:UnregisterSystem(systemName)
|
|
@@ -300,17 +334,25 @@ function ImmediateScheduler.UnregisterSystem(self: ImmediateScheduler, systemNam
|
|
|
300
334
|
targetSystem.Destroy()
|
|
301
335
|
end
|
|
302
336
|
self._systemDictionary[systemName] = nil
|
|
337
|
+
self._profileLabels[systemName] = nil
|
|
303
338
|
end
|
|
304
339
|
self._sortFlag = true
|
|
305
340
|
end
|
|
306
341
|
|
|
307
342
|
function ImmediateScheduler.Destroy(self: ImmediateScheduler)
|
|
308
|
-
|
|
343
|
+
local pendingNames = {}
|
|
344
|
+
for systemName in self._systemDictionary do
|
|
345
|
+
table.insert(pendingNames, systemName)
|
|
346
|
+
end
|
|
347
|
+
for _, systemName in pendingNames do
|
|
348
|
+
self:UnregisterSystem(systemName)
|
|
349
|
+
end
|
|
309
350
|
table.clear(self._sorted_systems)
|
|
310
351
|
table.clear(self._sorted_preSystem)
|
|
311
352
|
table.clear(self._sorted_postSystem)
|
|
312
353
|
table.clear(self._sorted_preTick)
|
|
313
354
|
table.clear(self._sorted_postTick)
|
|
355
|
+
self:Destroy()
|
|
314
356
|
end
|
|
315
357
|
|
|
316
358
|
return ImmediateScheduler
|