mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-17 17:34:36 +08:00
simple refactoring
This commit is contained in:
parent
e574e4a64d
commit
05bf563f76
@ -48,7 +48,7 @@ namespace DCFApixels.DragonECS
|
||||
_markers = new EcsProfilerMarker[targets.Length];
|
||||
for (int i = 0; i < targets.Length; i++)
|
||||
{
|
||||
_markers[i] = new EcsProfilerMarker($"EcsRunner.{targets[i].GetType().Name}.{nameof(PreInit)}");
|
||||
_markers[i] = new EcsProfilerMarker($"{targets[i].GetType().Name}.{nameof(PreInit)}");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -77,7 +77,7 @@ namespace DCFApixels.DragonECS
|
||||
_markers = new EcsProfilerMarker[targets.Length];
|
||||
for (int i = 0; i < targets.Length; i++)
|
||||
{
|
||||
_markers[i] = new EcsProfilerMarker($"EcsRunner.{targets[i].GetType().Name}.{nameof(Init)}");
|
||||
_markers[i] = new EcsProfilerMarker($"{targets[i].GetType().Name}.{nameof(Init)}");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -107,7 +107,7 @@ namespace DCFApixels.DragonECS
|
||||
_markers = new EcsProfilerMarker[targets.Length];
|
||||
for (int i = 0; i < targets.Length; i++)
|
||||
{
|
||||
_markers[i] = new EcsProfilerMarker($"EcsRunner.{targets[i].GetType().Name}.{nameof(Run)}");
|
||||
_markers[i] = new EcsProfilerMarker($"{targets[i].GetType().Name}.{nameof(Run)}");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -136,7 +136,7 @@ namespace DCFApixels.DragonECS
|
||||
_markers = new EcsProfilerMarker[targets.Length];
|
||||
for (int i = 0; i < targets.Length; i++)
|
||||
{
|
||||
_markers[i] = new EcsProfilerMarker($"EcsRunner.{targets[i].GetType().Name}.{nameof(Destroy)}");
|
||||
_markers[i] = new EcsProfilerMarker($"{targets[i].GetType().Name}.{nameof(Destroy)}");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -12,9 +12,9 @@ namespace DCFApixels.DragonECS
|
||||
internal EcsProfilerMarker(int id) => this.id = id;
|
||||
public EcsProfilerMarker(string name) => id = DebugService.Instance.RegisterMark(name);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Begin() => DebugService.Instance.ProfileMarkBegin(id);
|
||||
public void Begin() => DebugService.Instance.ProfilerMarkBegin(id);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void End() => DebugService.Instance.ProfileMarkEnd(id);
|
||||
public void End() => DebugService.Instance.ProfilerMarkEnd(id);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public AutoScope Auto() => new AutoScope(id);
|
||||
public readonly ref struct AutoScope
|
||||
@ -23,9 +23,9 @@ namespace DCFApixels.DragonECS
|
||||
public AutoScope(int id)
|
||||
{
|
||||
_id = id;
|
||||
DebugService.Instance.ProfileMarkBegin(id);
|
||||
DebugService.Instance.ProfilerMarkBegin(id);
|
||||
}
|
||||
public void Dispose() => DebugService.Instance.ProfileMarkEnd(_id);
|
||||
public void Dispose() => DebugService.Instance.ProfilerMarkEnd(_id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,18 +55,7 @@ namespace DCFApixels.DragonECS
|
||||
public abstract class DebugService
|
||||
{
|
||||
private static DebugService _instance;
|
||||
|
||||
public static DebugService Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = new DefaultDebugService();
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
public static DebugService Instance => _instance ??= new DefaultDebugService();
|
||||
|
||||
public static void Set<T>() where T : DebugService, new() => Set(new T());
|
||||
public static void Set(DebugService service)
|
||||
@ -92,7 +81,7 @@ namespace DCFApixels.DragonECS
|
||||
id = _idDispenser.GetFree();
|
||||
_nameIdTable.Add(name, id);
|
||||
}
|
||||
OnNewMark(id, name);
|
||||
OnNewProfilerMark(id, name);
|
||||
return id;
|
||||
}
|
||||
public void DeleteMark(string name)
|
||||
@ -100,15 +89,15 @@ namespace DCFApixels.DragonECS
|
||||
int id = _nameIdTable[name];
|
||||
_nameIdTable.Remove(name);
|
||||
_idDispenser.Release(id);
|
||||
OnDelMark(id);
|
||||
OnDelProfilerMark(id);
|
||||
|
||||
}
|
||||
|
||||
protected abstract void OnNewMark(int id, string name);
|
||||
protected abstract void OnDelMark(int id);
|
||||
protected abstract void OnNewProfilerMark(int id, string name);
|
||||
protected abstract void OnDelProfilerMark(int id);
|
||||
|
||||
public abstract void ProfileMarkBegin(int id);
|
||||
public abstract void ProfileMarkEnd(int id);
|
||||
public abstract void ProfilerMarkBegin(int id);
|
||||
public abstract void ProfilerMarkEnd(int id);
|
||||
}
|
||||
|
||||
public sealed class DefaultDebugService : DebugService
|
||||
@ -126,22 +115,22 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
Console.WriteLine($"[{tag}] {v}");
|
||||
}
|
||||
public override void ProfileMarkBegin(int id)
|
||||
public override void ProfilerMarkBegin(int id)
|
||||
{
|
||||
_stopwatchs[id].Start();
|
||||
}
|
||||
public override void ProfileMarkEnd(int id)
|
||||
public override void ProfilerMarkEnd(int id)
|
||||
{
|
||||
_stopwatchs[id].Stop();
|
||||
var time = _stopwatchs[id].Elapsed;
|
||||
_stopwatchs[id].Reset();
|
||||
Print(_stopwatchsNames[id] + " s:" + time.TotalSeconds);
|
||||
Print("ProfilerMark", _stopwatchsNames[id] + " s:" + time.TotalSeconds);
|
||||
}
|
||||
protected override void OnDelMark(int id)
|
||||
protected override void OnDelProfilerMark(int id)
|
||||
{
|
||||
_stopwatchs[id] = null;
|
||||
}
|
||||
protected override void OnNewMark(int id, string name)
|
||||
protected override void OnNewProfilerMark(int id, string name)
|
||||
{
|
||||
if (id >= _stopwatchs.Length)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user