add ProfilerMarkers into ent methods

This commit is contained in:
Mikhail 2023-03-30 06:17:06 +08:00
parent a7afdfdde3
commit fea46221e0
2 changed files with 24 additions and 8 deletions

View File

@ -9,6 +9,7 @@ namespace DCFApixels.DragonECS
{ {
public readonly int id; public readonly int id;
public EcsProfilerMarker(int id) => this.id = id; public EcsProfilerMarker(int id) => this.id = id;
public EcsProfilerMarker(string name) => id = EcsDebug.RegisterMark(name);
public void Begin() => EcsDebug.ProfileMarkBegin(id); public void Begin() => EcsDebug.ProfileMarkBegin(id);
public void End() => EcsDebug.ProfileMarkEnd(id); public void End() => EcsDebug.ProfileMarkEnd(id);
public AutoScope Auto() => new AutoScope(id); public AutoScope Auto() => new AutoScope(id);

View File

@ -87,43 +87,58 @@ namespace DCFApixels.DragonECS
public static partial class entExtensions 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)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsAlive(this ref ent self) public static bool IsAlive(this ref ent self)
{ {
bool result = EcsWorld.Worlds[self.world].EntityIsAlive(self.id, self.gen); using (_IsAliveMarker.Auto())
if (!result) self = ent.NULL; {
return result; bool result = EcsWorld.Worlds[self.world].EntityIsAlive(self.id, self.gen);
if (!result) self = ent.NULL;
return result;
}
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsNull(this in ent self) public static bool IsNull(this in ent self)
{ {
return self == ent.NULL; using (_IsNullMarker.Auto())
return self == ent.NULL;
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref readonly T Read<T>(this in ent self) public static ref readonly T Read<T>(this in ent self)
where T : struct where T : struct
{ {
return ref EcsWorld.Worlds[self.world].GetPool<T>().Read(self.id); using (_ReadMarker.Auto())
return ref EcsWorld.Worlds[self.world].GetPool<T>().Read(self.id);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref T Write<T>(this in ent self) public static ref T Write<T>(this in ent self)
where T : struct where T : struct
{ {
return ref EcsWorld.Worlds[self.world].GetPool<T>().Write(self.id); using (_WriteMarker.Auto())
return ref EcsWorld.Worlds[self.world].GetPool<T>().Write(self.id);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool Has<T>(this in ent self) public static bool Has<T>(this in ent self)
where T : struct where T : struct
{ {
return EcsWorld.Worlds[self.world].GetPool<T>().Has(self.id); using (_HasMarker.Auto())
return EcsWorld.Worlds[self.world].GetPool<T>().Has(self.id);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Del<T>(this in ent self) public static void Del<T>(this in ent self)
where T : struct where T : struct
{ {
EcsWorld.Worlds[self.world].GetPool<T>().Del(self.id); using (_DelMarker.Auto())
EcsWorld.Worlds[self.world].GetPool<T>().Del(self.id);
} }
} }
} }