着重优化调度

Signed-off-by: TRADER_FOER <lhf190@outlook.com>
This commit is contained in:
2026-07-21 09:58:21 +08:00
parent 04ec368a59
commit 02617c1385
117 changed files with 107322 additions and 1326 deletions

View File

@@ -3,6 +3,7 @@ using System.Linq;
using Ichni.RhythmGame.Beatmap;
using UniRx;
using UniRx.Triggers;
using Unity.Profiling;
using Unity.VisualScripting;
using UnityEngine;
@@ -25,7 +26,8 @@ namespace Ichni.RhythmGame
public bool baseColorDirtyMark;
public bool emissionColorDirtyMark;
public bool queuedForApply;
public IDisposable observer;
public Color GetCurrentEmissionColor()
@@ -73,7 +75,7 @@ namespace Ichni.RhythmGame
this.baseColorDirtyMark = true;
this.emissionColorDirtyMark = true;
if (!HaveSameSubmodule && attachedGameElement is IHaveColorSubmodule host)
{
host.colorSubmodule = this;
@@ -89,8 +91,34 @@ namespace Ichni.RhythmGame
currentBaseColor = originalBaseColor;
currentEmissionColor = originalEmissionColor;
currentEmissionIntensity = originalEmissionIntensity;
MarkAllDirty();
}
public void MarkBaseColorDirty()
{
baseColorDirtyMark = true;
RequestApply();
}
public void MarkEmissionColorDirty()
{
emissionColorDirtyMark = true;
RequestApply();
}
public void MarkAllDirty()
{
baseColorDirtyMark = true;
emissionColorDirtyMark = true;
RequestApply();
}
private void RequestApply()
{
if (attachedGameElement is IHaveColorSubmodule host)
{
CoreServices.UpdateScheduler?.RegisterDirtyColor(host);
}
}
private bool HaveAnimation() => attachedGameElement.childElementList
@@ -109,9 +137,12 @@ namespace Ichni.RhythmGame
#region [] Component Interface
public interface IHaveColorSubmodule
{
private static readonly ProfilerMarker PhaseMarker = new ProfilerMarker("Ichni.UpdateScheduler.RefreshColor");
private static readonly ProfilerMarker PhaseMarker1 = new ProfilerMarker("Ichni.UpdateScheduler.UpdateColor");
public ColorSubmodule colorSubmodule { get; set; }
public virtual bool haveEmission => false;
public void SetColorObserver()
{
// 旧版的 UniRx 各自监听已淘汰,现由 GameManager 中枢在 LateUpdate 统一下发 UpdateColor()
@@ -119,27 +150,33 @@ namespace Ichni.RhythmGame
public void UpdateColor(bool refreshAll = true)
{
if(colorSubmodule == null) return;
bool willRefresh = false;
if (colorSubmodule.baseColorDirtyMark)
using (PhaseMarker1.Auto())
{
//在动画物体中改变currentColor
colorSubmodule.baseColorDirtyMark = false;
willRefresh = true;
}
if (colorSubmodule.emissionColorDirtyMark)
{
//在动画物体中改变currentColor
colorSubmodule.emissionColorDirtyMark = false;
willRefresh = true;
}
if (willRefresh && refreshAll)
{
colorSubmodule.attachedGameElement.Refresh();
if (colorSubmodule == null) return;
bool willRefresh = false;
if (colorSubmodule.baseColorDirtyMark)
{
//在动画物体中改变currentColor
colorSubmodule.baseColorDirtyMark = false;
willRefresh = true;
}
if (colorSubmodule.emissionColorDirtyMark)
{
//在动画物体中改变currentColor
colorSubmodule.emissionColorDirtyMark = false;
willRefresh = true;
}
if (willRefresh && refreshAll)
{
using (PhaseMarker.Auto())
{
colorSubmodule.attachedGameElement.Refresh();
}
}
}
}
}

View File

@@ -5,6 +5,7 @@ using System.Linq;
using Ichni.RhythmGame.Beatmap;
using UniRx;
using UniRx.Triggers;
using Unity.Profiling;
using Unity.VisualScripting;
using UnityEngine;
using Object = UnityEngine.Object;
@@ -25,13 +26,14 @@ namespace Ichni.RhythmGame
public Vector3 currentPosition;
public Vector3 currentEulerAngles;
public Vector3 currentScale;
public bool positionDirtyMark;
public bool eulerAnglesDirtyMark;
public bool scaleDirtyMark;
public bool queuedForApply;
public bool eulerAnglesOffsetLock;
public IDisposable observer;
#endregion
@@ -49,7 +51,7 @@ namespace Ichni.RhythmGame
currentPosition = Vector3.zero;
currentEulerAngles = Vector3.zero;
currentScale = Vector3.one;
positionDirtyMark = true;
eulerAnglesDirtyMark = true;
scaleDirtyMark = true;
@@ -77,13 +79,13 @@ namespace Ichni.RhythmGame
currentPosition = originalPosition;
currentEulerAngles = originalEulerAngles;
currentScale = originalScale;
positionDirtyMark = true;
eulerAnglesDirtyMark = true;
scaleDirtyMark = true;
eulerAnglesOffsetLock = false;
if (!HaveSameSubmodule && attachedGameElement is IHaveTransformSubmodule host)
{
host.transformSubmodule = this;
@@ -91,14 +93,46 @@ namespace Ichni.RhythmGame
}
}
#endregion
#region [] Lifecycle & State Refresh
public override void Refresh()
{
MarkAllDirty();
}
public void MarkPositionDirty()
{
positionDirtyMark = true;
RequestApply();
}
public void MarkEulerAnglesDirty()
{
eulerAnglesDirtyMark = true;
RequestApply();
}
public void MarkScaleDirty()
{
scaleDirtyMark = true;
RequestApply();
}
public void MarkAllDirty()
{
positionDirtyMark = true;
eulerAnglesDirtyMark = true;
scaleDirtyMark = true;
RequestApply();
}
private void RequestApply()
{
if (attachedGameElement is IHaveTransformSubmodule host)
{
CoreServices.UpdateScheduler?.RegisterDirtyTransform(host);
}
}
private bool HaveAnimation() => attachedGameElement.childElementList
@@ -117,6 +151,9 @@ namespace Ichni.RhythmGame
#region [] Component Interface
public interface IHaveTransformSubmodule
{
private static readonly ProfilerMarker PhaseMarker = new ProfilerMarker("Ichni.UpdateScheduler.RefreshTransform");
private static readonly ProfilerMarker PhaseMarker1 = new ProfilerMarker("Ichni.UpdateScheduler.UpdateTransform");
TransformSubmodule transformSubmodule { get; set; }
/// <summary>
@@ -131,50 +168,54 @@ namespace Ichni.RhythmGame
public void UpdateTransform(bool refreshAll = true)
{
if(transformSubmodule == null) return;
GameElement attachedGameElement = transformSubmodule.attachedGameElement;
bool willRefresh = false;
if (transformSubmodule.scaleDirtyMark)
if (transformSubmodule == null) return;
using (PhaseMarker1.Auto())
{
transformSubmodule.currentScale = transformSubmodule.originalScale + transformSubmodule.scaleOffset;
attachedGameElement.transform.localScale = transformSubmodule.currentScale;
transformSubmodule.scaleDirtyMark = false;
willRefresh = true;
transformSubmodule.scaleOffset = Vector3.zero;
}
GameElement attachedGameElement = transformSubmodule.attachedGameElement;
bool willRefresh = false;
if (!transformSubmodule.eulerAnglesOffsetLock && transformSubmodule.eulerAnglesDirtyMark)
{
transformSubmodule.currentEulerAngles = transformSubmodule.originalEulerAngles + transformSubmodule.eulerAnglesOffset;
attachedGameElement.transform.localEulerAngles = transformSubmodule.currentEulerAngles;
transformSubmodule.eulerAnglesDirtyMark = false;
willRefresh = true;
transformSubmodule.eulerAnglesOffset = Vector3.zero;
}
if (transformSubmodule.scaleDirtyMark)
{
transformSubmodule.currentScale = transformSubmodule.originalScale + transformSubmodule.scaleOffset;
if (transformSubmodule.positionDirtyMark)
{
transformSubmodule.currentPosition = transformSubmodule.originalPosition + transformSubmodule.positionOffset;
attachedGameElement.transform.localPosition = transformSubmodule.currentPosition;
transformSubmodule.positionDirtyMark = false;
willRefresh = true;
transformSubmodule.positionOffset = Vector3.zero;
}
if(refreshAll && willRefresh)
{
attachedGameElement.Refresh();
attachedGameElement.transform.localScale = transformSubmodule.currentScale;
transformSubmodule.scaleDirtyMark = false;
willRefresh = true;
transformSubmodule.scaleOffset = Vector3.zero;
}
if (!transformSubmodule.eulerAnglesOffsetLock && transformSubmodule.eulerAnglesDirtyMark)
{
transformSubmodule.currentEulerAngles = transformSubmodule.originalEulerAngles + transformSubmodule.eulerAnglesOffset;
attachedGameElement.transform.localEulerAngles = transformSubmodule.currentEulerAngles;
transformSubmodule.eulerAnglesDirtyMark = false;
willRefresh = true;
transformSubmodule.eulerAnglesOffset = Vector3.zero;
}
if (transformSubmodule.positionDirtyMark)
{
transformSubmodule.currentPosition = transformSubmodule.originalPosition + transformSubmodule.positionOffset;
attachedGameElement.transform.localPosition = transformSubmodule.currentPosition;
transformSubmodule.positionDirtyMark = false;
willRefresh = true;
transformSubmodule.positionOffset = Vector3.zero;
}
if (refreshAll && willRefresh)
{
using (PhaseMarker.Auto())
attachedGameElement.Refresh();
}
}
}
public void UpdateLookAt(LookAt lookAt) // 处理LookAt
{
Transform target = lookAt.targetGameElement.transform;
Transform self = transformSubmodule.attachedGameElement.transform;
if (transformSubmodule.eulerAnglesOffsetLock && transformSubmodule.eulerAnglesDirtyMark)
{
Vector3 lookingDirection = (target.position - self.position).normalized;