Skip to content

Commit

Permalink
Enable diagnostics without debug bits.
Browse files Browse the repository at this point in the history
  • Loading branch information
isadorasophia committed Oct 12, 2023
1 parent c4d5274 commit c27b7c2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
11 changes: 6 additions & 5 deletions src/Bang/Systems/MessagerAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ public class MessagerAttribute : Attribute
/// <param name="types">Messages that will be fired to this system.</param>
public MessagerAttribute(params Type[] types)
{
#if DEBUG
foreach (Type t in types)
if (World.DIAGNOSTICS_MODE)
{
Debug.Assert(t.IsValueType || t == typeof(IMessage),
"Why are we adding a watcher attribute for a non-struct? This won't be notified when the value changes.");
foreach (Type t in types)
{
Debug.Assert(t.IsValueType || t == typeof(IMessage),
"Why are we adding a watcher attribute for a non-struct? This won't be notified when the value changes.");
}
}
#endif

Types = types;
}
Expand Down
14 changes: 8 additions & 6 deletions src/Bang/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -869,14 +869,16 @@ public Entity GetUniqueEntity<T>() where T : struct, IComponent
Context context = Contexts[contextId];

// We expect more than one entity if the remaining ones have been destroyed
#if DEBUG
int nonDestroyedCount = 0;
if (context.Entities.Length > 1)

if (DIAGNOSTICS_MODE)
{
nonDestroyedCount = context.Entities.Where(e => !e.IsDestroyed).Count();
Debug.Assert(nonDestroyedCount == 1, "Why are there more than one entity with an unique component?");
int nonDestroyedCount = 0;
if (context.Entities.Length > 1)
{
nonDestroyedCount = context.Entities.Where(e => !e.IsDestroyed).Count();
Debug.Assert(nonDestroyedCount == 1, "Why are there more than one entity with an unique component?");
}
}
#endif

Entity? e = context.Entities.LastOrDefault();
return e is null || e.IsDestroyed ? null : e;
Expand Down

0 comments on commit c27b7c2

Please sign in to comment.