Skip to content

Commit

Permalink
Remove EntitasCache
Browse files Browse the repository at this point in the history
  • Loading branch information
sschmid committed Dec 6, 2018
1 parent fbd81f1 commit 780430a
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 86 deletions.
1 change: 0 additions & 1 deletion Entitas/Entitas.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
<Compile Include="Entitas\Matcher\MatcherException.cs" />
<Compile Include="Entitas\Collector\Collector.cs" />
<Compile Include="Entitas\Collector\CollectorException.cs" />
<Compile Include="Entitas\EntitasCache.cs" />
<Compile Include="Entitas\EntitasResources.cs" />
<Compile Include="Entitas\Extensions\CollectionExtension.cs" />
<Compile Include="Entitas\Extensions\PublicMemberInfoEntityExtension.cs" />
Expand Down
23 changes: 0 additions & 23 deletions Entitas/Entitas/EntitasCache.cs

This file was deleted.

26 changes: 14 additions & 12 deletions Entitas/Entitas/Entity/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public class Entity : IEntity {
/// release it manually at some point.
public IAERC aerc { get { return _aerc; } }

readonly List<IComponent> _componentBuffer;
readonly List<int> _indexBuffer;

int _creationIndex;
bool _isEnabled;

Expand All @@ -79,6 +82,11 @@ public class Entity : IEntity {
string _toStringCache;
StringBuilder _toStringBuilder;

public Entity() {
_componentBuffer = new List<IComponent>();
_indexBuffer = new List<int>();
}

public void Initialize(int creationIndex, int totalComponents, Stack<IComponent>[] componentPools, ContextInfo contextInfo = null, IAERC aerc = null) {
Reactivate(creationIndex);

Expand Down Expand Up @@ -234,18 +242,15 @@ public IComponent GetComponent(int index) {
/// Returns all added components.
public IComponent[] GetComponents() {
if (_componentsCache == null) {
var components = EntitasCache.GetIComponentList();

for (int i = 0; i < _components.Length; i++) {
var component = _components[i];
if (component != null) {
components.Add(component);
_componentBuffer.Add(component);
}
}

_componentsCache = components.ToArray();

EntitasCache.PushIComponentList(components);
_componentsCache = _componentBuffer.ToArray();
_componentBuffer.Clear();
}

return _componentsCache;
Expand All @@ -254,17 +259,14 @@ public IComponent[] GetComponents() {
/// Returns all indices of added components.
public int[] GetComponentIndices() {
if (_componentIndicesCache == null) {
var indices = EntitasCache.GetIntList();

for (int i = 0; i < _components.Length; i++) {
if (_components[i] != null) {
indices.Add(i);
_indexBuffer.Add(i);
}
}

_componentIndicesCache = indices.ToArray();

EntitasCache.PushIntList(indices);
_componentIndicesCache = _indexBuffer.ToArray();
_indexBuffer.Clear();
}

return _componentIndicesCache;
Expand Down
26 changes: 13 additions & 13 deletions Entitas/Entitas/Matcher/MatcherStatic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ namespace Entitas {

public partial class Matcher<TEntity> {

static readonly List<int> _indexBuffer = new List<int>();
static readonly HashSet<int> _indexSetBuffer = new HashSet<int>();

public static IAllOfMatcher<TEntity> AllOf(params int[] indices) {
var matcher = new Matcher<TEntity>();
matcher._allOfIndices = distinctIndices(indices);
Expand All @@ -30,21 +33,19 @@ public static IAnyOfMatcher<TEntity> AnyOf(params IMatcher<TEntity>[] matchers)
}

static int[] mergeIndices(int[] allOfIndices, int[] anyOfIndices, int[] noneOfIndices) {
var indicesList = EntitasCache.GetIntList();

if (allOfIndices != null) {
indicesList.AddRange(allOfIndices);
_indexBuffer.AddRange(allOfIndices);
}
if (anyOfIndices != null) {
indicesList.AddRange(anyOfIndices);
_indexBuffer.AddRange(anyOfIndices);
}
if (noneOfIndices != null) {
indicesList.AddRange(noneOfIndices);
_indexBuffer.AddRange(noneOfIndices);
}

var mergedIndices = distinctIndices(indicesList);
var mergedIndices = distinctIndices(_indexBuffer);

EntitasCache.PushIntList(indicesList);
_indexBuffer.Clear();

return mergedIndices;
}
Expand Down Expand Up @@ -81,16 +82,15 @@ static void setComponentNames(Matcher<TEntity> matcher, IMatcher<TEntity>[] matc
}

static int[] distinctIndices(IList<int> indices) {
var indicesSet = EntitasCache.GetIntHashSet();

foreach (var index in indices) {
indicesSet.Add(index);
_indexSetBuffer.Add(index);
}
var uniqueIndices = new int[indicesSet.Count];
indicesSet.CopyTo(uniqueIndices);

var uniqueIndices = new int[_indexSetBuffer.Count];
_indexSetBuffer.CopyTo(uniqueIndices);
Array.Sort(uniqueIndices);

EntitasCache.PushIntHashSet(indicesSet);
_indexSetBuffer.Clear();

return uniqueIndices;
}
Expand Down
1 change: 0 additions & 1 deletion Tests/Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
<Compile Include="Fixtures\MyTestContext.cs" />
<Compile Include="Tests\Entitas\describe_Collector.cs" />
<Compile Include="Tests\Entitas\describe_Context.cs" />
<Compile Include="Tests\Entitas\describe_EntitasCache.cs" />
<Compile Include="Tests\Entitas\describe_EntitasErrorMessages.cs" />
<Compile Include="Tests\Entitas\describe_Entity.cs" />
<Compile Include="Tests\Entitas\describe_EntityIndex.cs" />
Expand Down
36 changes: 0 additions & 36 deletions Tests/Tests/Tests/Entitas/describe_EntitasCache.cs

This file was deleted.

0 comments on commit 780430a

Please sign in to comment.