Skip to content

Commit

Permalink
ECS - change EntityState to ref readonly struct
Browse files Browse the repository at this point in the history
  • Loading branch information
friflo committed Jul 31, 2024
1 parent 3c47b03 commit 769f77d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/ECS/Entity/EntityState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// ReSharper disable once CheckNamespace
namespace Friflo.Engine.ECS;

public readonly struct EntityState
public readonly ref struct EntityState
{
#region entity getter
public bool IsNull => archetype == null;
Expand Down
14 changes: 12 additions & 2 deletions src/Tests/ECS/Entity/Test_EntityState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,22 @@ public static void Test_EntityState_getter()
state = entity.State;
IsTrue(state.IsNull);
Throws<NullReferenceException>(() => {
_ = state.Tags;
GetTags(entity);
});
Throws<NullReferenceException>(() => {
_ = state.Get<Position>();
GetComponent(entity);
});
}

private static void GetTags(Entity entity) {
var state = entity.State;
_ = state.Tags;
}

private static void GetComponent(Entity entity) {
var state = entity.State;
_ = state.Get<Position>();
}
}

}

0 comments on commit 769f77d

Please sign in to comment.