Time cache for scaled time and delta time, fixed and not fixed
This commit is contained in:
parent
9861009bd8
commit
cb17398e8d
|
@ -6,3 +6,9 @@
|
|||
### Added
|
||||
|
||||
- Initial release
|
||||
|
||||
## [1.0.1] - 2023-07-24
|
||||
|
||||
### Added
|
||||
|
||||
- Time cache for scaled time and delta time, fixed and not fixed
|
||||
|
|
|
@ -38,6 +38,28 @@ namespace RK.MicroComponents {
|
|||
|
||||
public sealed class MicroSystem : MonoBehaviour {
|
||||
|
||||
public class _TimeCache {
|
||||
internal double _fixedTime;
|
||||
internal double _time;
|
||||
internal float _fixedDeltaTime;
|
||||
internal float _deltaTime;
|
||||
|
||||
public double FixedTime { get => _fixedTime; }
|
||||
public double Time { get => _time; }
|
||||
public float FixedDeltaTime { get => _fixedDeltaTime; }
|
||||
public float DeltaTime { get => _deltaTime; }
|
||||
|
||||
internal void Update() {
|
||||
_timeCache._fixedTime = UnityEngine.Time.fixedTimeAsDouble;
|
||||
_timeCache._time = UnityEngine.Time.timeAsDouble;
|
||||
_timeCache._fixedDeltaTime = UnityEngine.Time.fixedDeltaTime;
|
||||
_timeCache._deltaTime = UnityEngine.Time.deltaTime;
|
||||
}
|
||||
}
|
||||
|
||||
internal static _TimeCache _timeCache = new _TimeCache();
|
||||
public static _TimeCache TimeCache { get => _timeCache; }
|
||||
|
||||
internal static readonly ParallelOptions ParallelOptions = new ParallelOptions {
|
||||
MaxDegreeOfParallelism = Environment.ProcessorCount
|
||||
};
|
||||
|
@ -125,6 +147,7 @@ public sealed class MicroSystem : MonoBehaviour {
|
|||
Destroy(this);
|
||||
return;
|
||||
}
|
||||
_timeCache.Update();
|
||||
_instance = this;
|
||||
_managersByType = new Dictionary<Type, MicroManager>();
|
||||
foreach (MicroManager manager in _managers) {
|
||||
|
@ -171,16 +194,19 @@ public sealed class MicroSystem : MonoBehaviour {
|
|||
}
|
||||
|
||||
private void FixedUpdate() {
|
||||
_timeCache.Update();
|
||||
InvokeUpdate(_parallelFixedUpdateManagers, manager => manager.ParallelFixedUpdate());
|
||||
InvokeUpdate(_syncFixedUpdateManagers, manager => manager.SyncFixedUpdate());
|
||||
}
|
||||
|
||||
private void Update() {
|
||||
_timeCache.Update();
|
||||
InvokeUpdate(_parallelUpdateManagers, manager => manager.ParallelUpdate());
|
||||
InvokeUpdate(_syncUpdateManagers, manager => manager.SyncUpdate());
|
||||
}
|
||||
|
||||
private void LateUpdate() {
|
||||
_timeCache.Update();
|
||||
InvokeUpdate(_parallelLateUpdateManagers, manager => manager.ParallelLateUpdate());
|
||||
InvokeUpdate(_syncLateUpdateManagers, manager => manager.SyncLateUpdate());
|
||||
}
|
||||
|
|
|
@ -54,7 +54,9 @@ public sealed class SimpleTestInstance1 : MicroInstance<SimpleTestComponent1, Si
|
|||
}
|
||||
|
||||
protected sealed override void ParallelUpdate() {
|
||||
Debug.Log("TestInstance1.ParallelUpdate()");
|
||||
double time = MicroSystem.TimeCache.Time;
|
||||
float deltaTime = MicroSystem.TimeCache.DeltaTime;
|
||||
Debug.Log($"TestInstance1.ParallelUpdate() : time = {time}, deltaTime = {deltaTime}");
|
||||
InvokeEvent(OnUpdate, new OnUpdateParams(this, 42));
|
||||
SimpleTestInstance2 instance2 = _reference2.Instance;
|
||||
if (instance2 is not null) {
|
||||
|
|
Loading…
Reference in New Issue