Skip to content

Commit 780430a

Browse files
committed
Remove EntitasCache
1 parent fbd81f1 commit 780430a

File tree

6 files changed

+27
-86
lines changed

6 files changed

+27
-86
lines changed

Entitas/Entitas.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
<Compile Include="Entitas\Matcher\MatcherException.cs" />
7070
<Compile Include="Entitas\Collector\Collector.cs" />
7171
<Compile Include="Entitas\Collector\CollectorException.cs" />
72-
<Compile Include="Entitas\EntitasCache.cs" />
7372
<Compile Include="Entitas\EntitasResources.cs" />
7473
<Compile Include="Entitas\Extensions\CollectionExtension.cs" />
7574
<Compile Include="Entitas\Extensions\PublicMemberInfoEntityExtension.cs" />

Entitas/Entitas/EntitasCache.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

Entitas/Entitas/Entity/Entity.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ public class Entity : IEntity {
6565
/// release it manually at some point.
6666
public IAERC aerc { get { return _aerc; } }
6767

68+
readonly List<IComponent> _componentBuffer;
69+
readonly List<int> _indexBuffer;
70+
6871
int _creationIndex;
6972
bool _isEnabled;
7073

@@ -79,6 +82,11 @@ public class Entity : IEntity {
7982
string _toStringCache;
8083
StringBuilder _toStringBuilder;
8184

85+
public Entity() {
86+
_componentBuffer = new List<IComponent>();
87+
_indexBuffer = new List<int>();
88+
}
89+
8290
public void Initialize(int creationIndex, int totalComponents, Stack<IComponent>[] componentPools, ContextInfo contextInfo = null, IAERC aerc = null) {
8391
Reactivate(creationIndex);
8492

@@ -234,18 +242,15 @@ public IComponent GetComponent(int index) {
234242
/// Returns all added components.
235243
public IComponent[] GetComponents() {
236244
if (_componentsCache == null) {
237-
var components = EntitasCache.GetIComponentList();
238-
239245
for (int i = 0; i < _components.Length; i++) {
240246
var component = _components[i];
241247
if (component != null) {
242-
components.Add(component);
248+
_componentBuffer.Add(component);
243249
}
244250
}
245251

246-
_componentsCache = components.ToArray();
247-
248-
EntitasCache.PushIComponentList(components);
252+
_componentsCache = _componentBuffer.ToArray();
253+
_componentBuffer.Clear();
249254
}
250255

251256
return _componentsCache;
@@ -254,17 +259,14 @@ public IComponent[] GetComponents() {
254259
/// Returns all indices of added components.
255260
public int[] GetComponentIndices() {
256261
if (_componentIndicesCache == null) {
257-
var indices = EntitasCache.GetIntList();
258-
259262
for (int i = 0; i < _components.Length; i++) {
260263
if (_components[i] != null) {
261-
indices.Add(i);
264+
_indexBuffer.Add(i);
262265
}
263266
}
264267

265-
_componentIndicesCache = indices.ToArray();
266-
267-
EntitasCache.PushIntList(indices);
268+
_componentIndicesCache = _indexBuffer.ToArray();
269+
_indexBuffer.Clear();
268270
}
269271

270272
return _componentIndicesCache;

Entitas/Entitas/Matcher/MatcherStatic.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ namespace Entitas {
55

66
public partial class Matcher<TEntity> {
77

8+
static readonly List<int> _indexBuffer = new List<int>();
9+
static readonly HashSet<int> _indexSetBuffer = new HashSet<int>();
10+
811
public static IAllOfMatcher<TEntity> AllOf(params int[] indices) {
912
var matcher = new Matcher<TEntity>();
1013
matcher._allOfIndices = distinctIndices(indices);
@@ -30,21 +33,19 @@ public static IAnyOfMatcher<TEntity> AnyOf(params IMatcher<TEntity>[] matchers)
3033
}
3134

3235
static int[] mergeIndices(int[] allOfIndices, int[] anyOfIndices, int[] noneOfIndices) {
33-
var indicesList = EntitasCache.GetIntList();
34-
3536
if (allOfIndices != null) {
36-
indicesList.AddRange(allOfIndices);
37+
_indexBuffer.AddRange(allOfIndices);
3738
}
3839
if (anyOfIndices != null) {
39-
indicesList.AddRange(anyOfIndices);
40+
_indexBuffer.AddRange(anyOfIndices);
4041
}
4142
if (noneOfIndices != null) {
42-
indicesList.AddRange(noneOfIndices);
43+
_indexBuffer.AddRange(noneOfIndices);
4344
}
4445

45-
var mergedIndices = distinctIndices(indicesList);
46+
var mergedIndices = distinctIndices(_indexBuffer);
4647

47-
EntitasCache.PushIntList(indicesList);
48+
_indexBuffer.Clear();
4849

4950
return mergedIndices;
5051
}
@@ -81,16 +82,15 @@ static void setComponentNames(Matcher<TEntity> matcher, IMatcher<TEntity>[] matc
8182
}
8283

8384
static int[] distinctIndices(IList<int> indices) {
84-
var indicesSet = EntitasCache.GetIntHashSet();
85-
8685
foreach (var index in indices) {
87-
indicesSet.Add(index);
86+
_indexSetBuffer.Add(index);
8887
}
89-
var uniqueIndices = new int[indicesSet.Count];
90-
indicesSet.CopyTo(uniqueIndices);
88+
89+
var uniqueIndices = new int[_indexSetBuffer.Count];
90+
_indexSetBuffer.CopyTo(uniqueIndices);
9191
Array.Sort(uniqueIndices);
9292

93-
EntitasCache.PushIntHashSet(indicesSet);
93+
_indexSetBuffer.Clear();
9494

9595
return uniqueIndices;
9696
}

Tests/Tests/Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@
7474
<Compile Include="Fixtures\MyTestContext.cs" />
7575
<Compile Include="Tests\Entitas\describe_Collector.cs" />
7676
<Compile Include="Tests\Entitas\describe_Context.cs" />
77-
<Compile Include="Tests\Entitas\describe_EntitasCache.cs" />
7877
<Compile Include="Tests\Entitas\describe_EntitasErrorMessages.cs" />
7978
<Compile Include="Tests\Entitas\describe_Entity.cs" />
8079
<Compile Include="Tests\Entitas\describe_EntityIndex.cs" />

Tests/Tests/Tests/Entitas/describe_EntitasCache.cs

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)