@rbxts/planck 0.1.3-rc.1 → 0.1.3-rc.3

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.
@@ -23,6 +23,7 @@ declare class Scheduler<T extends unknown[]> {
23
23
  replaceSystem(oldSystem: System<T>, newSystem: System<T>): Scheduler<T>
24
24
  editSystem(system: System<T>, phase: Phase): Scheduler<T>
25
25
  addSystem(system: System<T>, phase?: Phase): Scheduler<T>
26
+ addSystems(...systems: System<T>[]): Scheduler<T>
26
27
  addPlugin(plugin: Plugin): Scheduler<T>
27
28
  /** @hidden */
28
29
  _addHook<K extends keyof HookFunctionMap>(hook: K, fn: (info: HookFunctionArgs<K, T>) => void): void
@@ -57,6 +57,23 @@ function Scheduler:_addHook(hook, fn)
57
57
  table.insert(self._hooks[hook], fn)
58
58
  end
59
59
 
60
+ --- @method getDeltaTime
61
+ --- @within Scheduler
62
+ --- @return number
63
+ ---
64
+ --- Returns the time since the system was ran last.
65
+ --- This must be used within a registered system.
66
+ function Scheduler:getDeltaTime()
67
+ local systemFn = debug.info(2, "f")
68
+ if not systemFn or not self._systemInfo[systemFn] then
69
+ error(
70
+ "Scheduler:getDeltaTime() must be used within a registered system"
71
+ )
72
+ end
73
+
74
+ return self._systemInfo[systemFn].deltaTime or 0
75
+ end
76
+
60
77
  -- Inspiration from https://github.com/matter-ecs/matter <3
61
78
  function Scheduler:_handleLogs(systemInfo)
62
79
  if not systemInfo.timeLastLogged then
@@ -94,6 +111,10 @@ function Scheduler:runSystem(system)
94
111
  end
95
112
 
96
113
  local systemInfo = self._systemInfo[system]
114
+ local now = os.clock()
115
+
116
+ systemInfo.deltaTime = now - (systemInfo.lastTime or now)
117
+ systemInfo.lastTime = now
97
118
 
98
119
  if not self._thread then
99
120
  self._thread = coroutine.create(function()
@@ -475,7 +496,7 @@ function Scheduler:editSystem(system, newPhase)
475
496
  local systemInfo = self._systemInfo[systemFn]
476
497
  assert(
477
498
  systemInfo,
478
- "Attempt to edit a non-exist system in Scheduler:editSystem(_)"
499
+ "Attempt to remove a non-exist system in Scheduler:removeSystem(_)"
479
500
  )
480
501
 
481
502
  assert(
@@ -630,17 +651,6 @@ function Scheduler:_addBuiltins()
630
651
 
631
652
  local startupHasRan = {}
632
653
 
633
- self:setRunCondition(Pipeline.Startup, function()
634
- local phases = Pipeline.Startup._phases
635
- local hasRan = startupHasRan[phases[#phases] ]
636
-
637
- if not hasRan then
638
- startupHasRan[phases[#phases] ] = true
639
- end
640
-
641
- return not hasRan
642
- end)
643
-
644
654
  for _, phase in Pipeline.Startup._phases do
645
655
  self:setRunCondition(phase, function()
646
656
  local hasRan = startupHasRan[phase]
@@ -664,7 +674,7 @@ function Scheduler:_scheduleEvent(instance, event)
664
674
 
665
675
  local callback = function()
666
676
  for _, phase in self._eventToPhases[identifier] do
667
- self:runPhase(phase)
677
+ self:run(phase)
668
678
  end
669
679
  end
670
680
 
@@ -752,4 +762,4 @@ function Scheduler.new(...)
752
762
  return self
753
763
  end
754
764
 
755
- return Scheduler
765
+ return Scheduler
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rbxts/planck",
3
- "version": "0.1.3-rc.1",
3
+ "version": "0.1.3-rc.3",
4
4
  "description": "An agnostic scheduler for ECS",
5
5
  "main": "out/init.lua",
6
6
  "repository": {