Skip to content

Commit

Permalink
Merge pull request #253 from sschmid/feature/#252-rename-entity-colle…
Browse files Browse the repository at this point in the history
…ctor

Renamed EntityCollector to Collector
  • Loading branch information
sschmid authored Jan 9, 2017
2 parents 7bebfd4 + 80f3bf3 commit 89726d9
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 61 deletions.
2 changes: 1 addition & 1 deletion Entitas/Entitas.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<Compile Include="Entitas\Interfaces\ISystem.cs" />
<Compile Include="Entitas\Context.cs" />
<Compile Include="Entitas\Extensions\ContextExtension.cs" />
<Compile Include="Entitas\EntityCollector.cs" />
<Compile Include="Entitas\Collector.cs" />
<Compile Include="Entitas\Extensions\GroupExtension.cs" />
<Compile Include="Entitas\ReactiveSystem.cs" />
<Compile Include="Entitas\Systems.cs" />
Expand Down
28 changes: 14 additions & 14 deletions Entitas/Entitas/EntityCollector.cs → Entitas/Entitas/Collector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

namespace Entitas {

/// An EntityCollector can observe one or more groups and collects
/// An Collector can observe one or more groups and collects
/// changed entities based on the specified eventType.
public class EntityCollector {
public class Collector {

/// Returns all collected entities.
/// Call collector.ClearCollectedEntities()
Expand All @@ -21,23 +21,23 @@ public HashSet<Entity> collectedEntities {
string _toStringCache;
StringBuilder _toStringBuilder;

/// Creates an EntityCollector and will collect changed entities
/// Creates an Collector and will collect changed entities
/// based on the specified eventType.
public EntityCollector(Group group, GroupEventType eventType)
public Collector(Group group, GroupEventType eventType)
: this(new [] { group }, new [] { eventType }) {
}

/// Creates an EntityCollector and will collect changed entities
/// Creates an Collector and will collect changed entities
/// based on the specified eventTypes.
public EntityCollector(Group[] groups, GroupEventType[] eventTypes) {
public Collector(Group[] groups, GroupEventType[] eventTypes) {
_groups = groups;
_collectedEntities = new HashSet<Entity>(
EntityEqualityComparer.comparer
);
_eventTypes = eventTypes;

if(groups.Length != eventTypes.Length) {
throw new EntityCollectorException(
throw new CollectorException(
"Unbalanced count with groups (" + groups.Length +
") and event types (" + eventTypes.Length + ").",
"Group and event type count must be equal."
Expand All @@ -48,8 +48,8 @@ public EntityCollector(Group[] groups, GroupEventType[] eventTypes) {
Activate();
}

/// Activates the EntityCollector and will start collecting
/// changed entities. EntityCollectors are activated by default.
/// Activates the Collector and will start collecting
/// changed entities. Collectors are activated by default.
public void Activate() {
for (int i = 0; i < _groups.Length; i++) {
var group = _groups[i];
Expand All @@ -69,9 +69,9 @@ public void Activate() {
}
}

/// Deactivates the EntityCollector.
/// Deactivates the Collector.
/// This will also clear all collected entities.
/// EntityCollectors are activated by default.
/// Collectors are activated by default.
public void Deactivate() {
for (int i = 0; i < _groups.Length; i++) {
var group = _groups[i];
Expand Down Expand Up @@ -123,13 +123,13 @@ public override string ToString() {
return _toStringCache;
}

~EntityCollector () {
~Collector () {
Deactivate();
}
}

public class EntityCollectorException : EntitasException {
public EntityCollectorException(string message, string hint) :
public class CollectorException : EntitasException {
public CollectorException(string message, string hint) :
base(message, hint) {
}
}
Expand Down
6 changes: 3 additions & 3 deletions Entitas/Entitas/Extensions/ContextExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ public static Entity[] GetEntities(this Context context, IMatcher matcher) {
return context.GetGroup(matcher).GetEntities();
}

/// Creates an EntityCollector.
public static EntityCollector CreateCollector(this Context context, IMatcher matcher, GroupEventType eventType = GroupEventType.OnEntityAdded) {
return new EntityCollector(context.GetGroup(matcher), eventType);
/// Creates an Collector.
public static Collector CreateCollector(this Context context, IMatcher matcher, GroupEventType eventType = GroupEventType.OnEntityAdded) {
return new Collector(context.GetGroup(matcher), eventType);
}

/// Creates a new entity and adds copies of all
Expand Down
6 changes: 3 additions & 3 deletions Entitas/Entitas/Extensions/GroupExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ namespace Entitas {

public static class GroupExtension {

/// Creates an EntityCollector for this group.
public static EntityCollector CreateCollector(
/// Creates an Collector for this group.
public static Collector CreateCollector(
this Group group,
GroupEventType eventType = GroupEventType.OnEntityAdded) {
return new EntityCollector(group, eventType);
return new Collector(group, eventType);
}
}
}
8 changes: 4 additions & 4 deletions Entitas/Entitas/ReactiveSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
namespace Entitas {

/// A ReactiveSystem calls Execute(entities) if there were changes based on
/// the specified EntityCollector and will only pass in changed entities.
/// the specified Collector and will only pass in changed entities.
/// A common use-case is to react to changes, e.g. a change of the position
/// of an entity to update the gameObject.transform.position
/// of the related gameObject.
public abstract class ReactiveSystem : IExecuteSystem {

readonly EntityCollector _collector;
readonly Collector _collector;
readonly List<Entity> _buffer;
string _toStringCache;

protected ReactiveSystem(EntityCollector collector) {
protected ReactiveSystem(Collector collector) {
_collector = collector;
_buffer = new List<Entity>();
}
Expand All @@ -24,7 +24,7 @@ protected ReactiveSystem(EntityCollector collector) {
public abstract void Execute(List<Entity> entities);

/// Activates the ReactiveSystem and starts observing changes
/// based on the specified EntityCollector.
/// based on the specified Collector.
/// ReactiveSystem are activated by default.
public void Activate() {
_collector.Activate();
Expand Down
4 changes: 2 additions & 2 deletions PerformanceTests/PerformanceTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<Compile Include="PerformanceTests\DataStructures\IterateHashetToArray.cs" />
<Compile Include="PerformanceTests\Entity\EntityAddComponent.cs" />
<Compile Include="PerformanceTests\Entity\ObjectGetProperty.cs" />
<Compile Include="PerformanceTests\GroupObserver\EntityCollectorIterateCollectedEntities.cs" />
<Compile Include="PerformanceTests\GroupObserver\CollectorIterateCollectedEntities.cs" />
<Compile Include="PerformanceTests\DataStructures\QueueDequeue.cs" />
<Compile Include="PerformanceTests\DataStructures\ListQueue.cs" />
<Compile Include="PerformanceTests\Context\ContextCreateEntity.cs" />
Expand All @@ -79,7 +79,7 @@
<Compile Include="PerformanceTests\Context\ContextCreateBlueprint.cs" />
<Compile Include="PerformanceTests\Fixtures\NameComponent.cs" />
<Compile Include="PerformanceTests\EntityIndex\EntityIndexGetEntity.cs" />
<Compile Include="PerformanceTests\GroupObserver\EntityCollectorActivate.cs" />
<Compile Include="PerformanceTests\GroupObserver\CollectorActivate.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Entitas;

public class EntityCollectorActivate : IPerformanceTest {
public class CollectorActivate : IPerformanceTest {

const int n = 10000;
EntityCollector _collector;
Collector _collector;

public void Before() {
var context = Helper.CreateContext();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Entitas;

public class EntityCollectorIterateCollectedEntities : IPerformanceTest {
public class CollectorIterateCollectedEntities : IPerformanceTest {

const int n = 100000;
EntityCollector _collector;
Collector _collector;

public void Before() {
var context = Helper.CreateContext();
Expand Down
8 changes: 4 additions & 4 deletions PerformanceTests/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public static void Main(string[] args) {

run<ObjectGetProperty>();
run<EmptyTest>();
run<EntityCollectorIterateCollectedEntities>();
run<EntityCollectorActivate>();
run<CollectorIterateCollectedEntities>();
run<CollectorActivate>();

run<HashSetContainsAdd>();
run<ArrayGetItem>();
Expand Down Expand Up @@ -93,8 +93,8 @@ public static void Main(string[] args) {

//ObjectGetProperty: 6 ms

//EntityCollectorIterateCollectedEntities:957 ms
//EntityCollectorActivate: 1 ms
//CollectorIterateCollectedEntities:957 ms
//CollectorActivate: 1 ms
//PropertiesCreate: 251 ms

//HashSetContainsAdd: 173 ms
Expand Down
4 changes: 2 additions & 2 deletions Readme/Readme.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
<Compile Include="..\Entitas\Entitas\Group.cs">
<Link>Linked Libraries\Entitas\Group.cs</Link>
</Compile>
<Compile Include="..\Entitas\Entitas\EntityCollector.cs">
<Link>Linked Libraries\Entitas\EntityCollector.cs</Link>
<Compile Include="..\Entitas\Entitas\Collector.cs">
<Link>Linked Libraries\Entitas\Collector.cs</Link>
</Compile>
<Compile Include="..\Entitas\Entitas\Context.cs">
<Link>Linked Libraries\Entitas\Context.cs</Link>
Expand Down
2 changes: 1 addition & 1 deletion Readme/Readme/ReadmeSnippets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static void groupExample(Context context) {
};
}

static void entityCollectorExample(Context context) {
static void collectorExample(Context context) {
var group = context.GetGroup(Matcher.Position);
var collector = group.CreateCollector(GroupEventType.OnEntityAdded);

Expand Down
6 changes: 3 additions & 3 deletions Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<ItemGroup>
<Compile Include="Tests\Entitas\describe_Entity.cs" />
<Compile Include="Tests\Entitas\describe_Group.cs" />
<Compile Include="Tests\Entitas\describe_EntityCollector.cs" />
<Compile Include="Tests\Entitas\describe_Collector.cs" />
<Compile Include="Tests\Entitas\describe_Matcher.cs" />
<Compile Include="Tests\Entitas\describe_Context.cs" />
<Compile Include="Tests\Entitas\describe_ReactiveSystem.cs" />
Expand Down Expand Up @@ -103,8 +103,8 @@
<Compile Include="..\Entitas\Entitas\Group.cs">
<Link>Linked Libraries\Entitas\Group.cs</Link>
</Compile>
<Compile Include="..\Entitas\Entitas\EntityCollector.cs">
<Link>Linked Libraries\Entitas\EntityCollector.cs</Link>
<Compile Include="..\Entitas\Entitas\Collector.cs">
<Link>Linked Libraries\Entitas\Collector.cs</Link>
</Compile>
<Compile Include="..\Entitas\Entitas\Context.cs">
<Link>Linked Libraries\Entitas\Context.cs</Link>
Expand Down
4 changes: 2 additions & 2 deletions Tests/Tests/Entitas/Fixtures/Systems/ReactiveSystemSpy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public class ReactiveSystemSpy : ReactiveSystem, IReactiveSystemSpy, IInitialize

readonly Func<Entity, bool> _filter;

public ReactiveSystemSpy(EntityCollector collector) : base(collector) {
public ReactiveSystemSpy(Collector collector) : base(collector) {
}

public ReactiveSystemSpy(EntityCollector collector, Func<Entity, bool> filter) : base(collector) {
public ReactiveSystemSpy(Collector collector, Func<Entity, bool> filter) : base(collector) {
_filter = filter;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using Entitas;
using NSpec;

class describe_EntityCollector : nspec {
class describe_Collector : nspec {

Context _context;

void when_created() {

Group groupA = null;
EntityCollector collectorA = null;
Collector collectorA = null;

IMatcher matcherA = Matcher.AllOf(CID.ComponentA);

Expand All @@ -20,7 +20,7 @@ void when_created() {
context["when observing with eventType OnEntityAdded"] = () => {
before = () => {
collectorA = new EntityCollector(groupA, GroupEventType.OnEntityAdded);
collectorA = new Collector(groupA, GroupEventType.OnEntityAdded);
};
it["is empty when nothing happend"] = () => {
Expand Down Expand Up @@ -125,7 +125,7 @@ void when_created() {
context["when observing with eventType OnEntityRemoved"] = () => {
before = () => {
collectorA = new EntityCollector(groupA, GroupEventType.OnEntityRemoved);
collectorA = new Collector(groupA, GroupEventType.OnEntityRemoved);
};
it["returns collected entities"] = () => {
Expand All @@ -142,7 +142,7 @@ void when_created() {
context["when observing with eventType OnEntityAddedOrRemoved"] = () => {
before = () => {
collectorA = new EntityCollector(groupA, GroupEventType.OnEntityAddedOrRemoved);
collectorA = new Collector(groupA, GroupEventType.OnEntityAddedOrRemoved);
};
it["returns collected entities"] = () => {
Expand All @@ -167,8 +167,8 @@ void when_created() {
groupB = _context.GetGroup(Matcher.AllOf(CID.ComponentB));
};
it["throws when group count != eventType count"] = expect<EntityCollectorException>(() => {
collectorA = new EntityCollector(
it["throws when group count != eventType count"] = expect<CollectorException>(() => {
collectorA = new Collector(
new [] { groupA },
new [] {
GroupEventType.OnEntityAdded,
Expand All @@ -180,7 +180,7 @@ void when_created() {
context["when observing with eventType OnEntityAdded"] = () => {
before = () => {
collectorA = new EntityCollector(
collectorA = new Collector(
new [] { groupA, groupB },
new [] {
GroupEventType.OnEntityAdded,
Expand All @@ -207,7 +207,7 @@ void when_created() {
context["when observing with eventType OnEntityRemoved"] = () => {
before = () => {
collectorA = new EntityCollector(
collectorA = new Collector(
new [] { groupA, groupB },
new [] {
GroupEventType.OnEntityRemoved,
Expand All @@ -232,7 +232,7 @@ void when_created() {
context["when observing with eventType OnEntityAddedOrRemoved"] = () => {
before = () => {
collectorA = new EntityCollector(
collectorA = new Collector(
new [] { groupA, groupB },
new [] {
GroupEventType.OnEntityAddedOrRemoved,
Expand Down Expand Up @@ -261,7 +261,7 @@ void when_created() {
context["when observing with mixed eventTypes"] = () => {
before = () => {
collectorA = new EntityCollector(
collectorA = new Collector(
new [] { groupA, groupB },
new [] {
GroupEventType.OnEntityAdded,
Expand Down
4 changes: 2 additions & 2 deletions Tests/Tests/Entitas/describe_EntitasErrorMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ void when_throwing() {
});
};

context["EntityCollector"] = () => {
context["Collector"] = () => {
it["unbalanced goups"] = () => printErrorMessage(() => {
var g1 = new Group(Matcher.AllOf(CID.ComponentA));
var g2 = new Group(Matcher.AllOf(CID.ComponentB));
var e1 = GroupEventType.OnEntityAdded;
new EntityCollector(new [] { g1, g2 }, new [] { e1 });
new Collector(new [] { g1, g2 }, new [] { e1 });
});
};

Expand Down
Loading

0 comments on commit 89726d9

Please sign in to comment.