From fea46221e0a93723532f43111f7f3c5093a18106 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Thu, 30 Mar 2023 06:17:06 +0800 Subject: [PATCH] add ProfilerMarkers into ent methods --- src/Debug/EcsDebug.cs | 1 + src/ent.cs | 31 +++++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/Debug/EcsDebug.cs b/src/Debug/EcsDebug.cs index fbc7265..3917b77 100644 --- a/src/Debug/EcsDebug.cs +++ b/src/Debug/EcsDebug.cs @@ -9,6 +9,7 @@ namespace DCFApixels.DragonECS { public readonly int id; public EcsProfilerMarker(int id) => this.id = id; + public EcsProfilerMarker(string name) => id = EcsDebug.RegisterMark(name); public void Begin() => EcsDebug.ProfileMarkBegin(id); public void End() => EcsDebug.ProfileMarkEnd(id); public AutoScope Auto() => new AutoScope(id); diff --git a/src/ent.cs b/src/ent.cs index 5630641..aadd8e6 100644 --- a/src/ent.cs +++ b/src/ent.cs @@ -87,43 +87,58 @@ namespace DCFApixels.DragonECS public static partial class entExtensions { + private static EcsProfilerMarker _IsAliveMarker = new EcsProfilerMarker("ent.IsAlive"); + private static EcsProfilerMarker _IsNullMarker = new EcsProfilerMarker("ent.IsNull"); + private static EcsProfilerMarker _ReadMarker = new EcsProfilerMarker("ent.Read"); + private static EcsProfilerMarker _WriteMarker = new EcsProfilerMarker("ent.Write"); + private static EcsProfilerMarker _HasMarker = new EcsProfilerMarker("ent.Has"); + private static EcsProfilerMarker _DelMarker = new EcsProfilerMarker("ent.Del"); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsAlive(this ref ent self) { - bool result = EcsWorld.Worlds[self.world].EntityIsAlive(self.id, self.gen); - if (!result) self = ent.NULL; - return result; + using (_IsAliveMarker.Auto()) + { + bool result = EcsWorld.Worlds[self.world].EntityIsAlive(self.id, self.gen); + if (!result) self = ent.NULL; + return result; + } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsNull(this in ent self) { - return self == ent.NULL; + using (_IsNullMarker.Auto()) + return self == ent.NULL; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ref readonly T Read(this in ent self) where T : struct { - return ref EcsWorld.Worlds[self.world].GetPool().Read(self.id); + using (_ReadMarker.Auto()) + return ref EcsWorld.Worlds[self.world].GetPool().Read(self.id); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ref T Write(this in ent self) where T : struct { - return ref EcsWorld.Worlds[self.world].GetPool().Write(self.id); + using (_WriteMarker.Auto()) + return ref EcsWorld.Worlds[self.world].GetPool().Write(self.id); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool Has(this in ent self) where T : struct { - return EcsWorld.Worlds[self.world].GetPool().Has(self.id); + using (_HasMarker.Auto()) + return EcsWorld.Worlds[self.world].GetPool().Has(self.id); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Del(this in ent self) where T : struct { - EcsWorld.Worlds[self.world].GetPool().Del(self.id); + using (_DelMarker.Auto()) + EcsWorld.Worlds[self.world].GetPool().Del(self.id); } } }