Skip to content

Commit 53d082c

Browse files
committed
cleanup
1 parent fc4078f commit 53d082c

9 files changed

+130
-70
lines changed

RelEcs.sln.DotSettings.user

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=TypeParameters/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
3+
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=1fa980a0_002D6593_002D4f8f_002D8d08_002D0367224a454a/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from EntitiesTest.cs" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
4+
&lt;Project Location="D:\Code\C#\RelEcsTest" Presentation="&amp;lt;RelEcsTest&amp;gt;" /&gt;&#xD;
5+
&lt;/SessionState&gt;</s:String></wpf:ResourceDictionary>

src/BitSet.cs

+20-20
Original file line numberDiff line numberDiff line change
@@ -9,65 +9,65 @@ public sealed class BitSet
99
const int ByteSize = 5; // log_2(BitSize + 1)
1010

1111
public int Count { get { return count; } }
12-
public int Capacity { get { return Bits.Length * (BitSize + 1); } }
12+
public int Capacity { get { return bits.Length * (BitSize + 1); } }
1313

14-
public uint[] Bits = new uint[1];
14+
private uint[] bits = new uint[1];
1515

1616
int count;
1717

1818
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1919
public bool Get(int index)
2020
{
2121
int b = index >> ByteSize;
22-
if (b >= Bits.Length)
22+
if (b >= bits.Length)
2323
{
2424
return false;
2525
}
2626

27-
return (Bits[b] & (1 << (index & BitSize))) != 0;
27+
return (bits[b] & (1 << (index & BitSize))) != 0;
2828
}
2929

3030
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3131
public void Set(int index)
3232
{
3333
int b = index >> ByteSize;
34-
if (b >= Bits.Length)
34+
if (b >= bits.Length)
3535
{
36-
Array.Resize(ref Bits, b + 1);
36+
Array.Resize(ref bits, b + 1);
3737
}
3838

39-
Bits[b] |= 1u << (index & BitSize);
39+
bits[b] |= 1u << (index & BitSize);
4040
count++;
4141
}
4242

4343
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4444
public void Clear(int index)
4545
{
4646
int b = index >> ByteSize;
47-
if (b >= Bits.Length)
47+
if (b >= bits.Length)
4848
{
4949
return;
5050
}
5151

52-
Bits[b] &= ~(1u << (index & BitSize));
52+
bits[b] &= ~(1u << (index & BitSize));
5353
count--;
5454
}
5555

5656
[MethodImpl(MethodImplOptions.AggressiveInlining)]
5757
public void ClearAll()
5858
{
59-
Array.Clear(Bits, 0, Bits.Length);
59+
Array.Clear(bits, 0, bits.Length);
6060
count = 0;
6161
}
6262

6363
[MethodImpl(MethodImplOptions.AggressiveInlining)]
6464
public bool HasAllBitsSet(BitSet mask)
6565
{
66-
var count = Math.Min(Bits.Length, mask.Bits.Length);
66+
var min = Math.Min(bits.Length, mask.bits.Length);
6767

68-
for (int i = 0; i < count; i++)
68+
for (int i = 0; i < min; i++)
6969
{
70-
if ((Bits[i] & mask.Bits[i]) != mask.Bits[i])
70+
if ((bits[i] & mask.bits[i]) != mask.bits[i])
7171
{
7272
return false;
7373
}
@@ -79,11 +79,11 @@ public bool HasAllBitsSet(BitSet mask)
7979
[MethodImpl(MethodImplOptions.AggressiveInlining)]
8080
public bool HasAnyBitSet(BitSet mask)
8181
{
82-
var count = Math.Min(Bits.Length, mask.Bits.Length);
82+
var min = Math.Min(bits.Length, mask.bits.Length);
8383

84-
for (int i = 0; i < count; i++)
84+
for (int i = 0; i < min; i++)
8585
{
86-
if ((Bits[i] & mask.Bits[i]) != 0)
86+
if ((bits[i] & mask.bits[i]) != 0)
8787
{
8888
return true;
8989
}
@@ -98,9 +98,9 @@ public bool IsEmpty
9898
get
9999
{
100100
uint k = 0;
101-
for (int i = 0; i < Bits.Length; i++)
101+
for (int i = 0; i < bits.Length; i++)
102102
{
103-
k |= Bits[i];
103+
k |= bits[i];
104104
}
105105
return k == 0;
106106
}
@@ -109,9 +109,9 @@ public bool IsEmpty
109109
public override int GetHashCode()
110110
{
111111
int h = 1234;
112-
for (int i = Bits.Length; --i >= 0;)
112+
for (int i = bits.Length; --i >= 0;)
113113
{
114-
h ^= (int)Bits[i] * (i + 1);
114+
h ^= (int)bits[i] * (i + 1);
115115
}
116116
return ((h >> 32) ^ h);
117117
}

src/CommandsExtensions.cs

+19
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
using System.Runtime.CompilerServices;
2+
13
namespace RelEcs
24
{
35
public static class CommandsExtensions
46
{
57
public delegate void RefAction<C>(ref C c);
8+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
69
public static void ForEach<C>(this Commands commands, RefAction<C> action)
710
where C : struct
811
{
@@ -17,6 +20,7 @@ public static void ForEach<C>(this Commands commands, RefAction<C> action)
1720
}
1821

1922
public delegate void RefAction<C1, C2>(ref C1 c1, ref C2 c2);
23+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2024
public static void ForEach<C1, C2>(this Commands commands, RefAction<C1, C2> action)
2125
where C1 : struct
2226
where C2 : struct
@@ -33,6 +37,7 @@ public static void ForEach<C1, C2>(this Commands commands, RefAction<C1, C2> act
3337
}
3438

3539
public delegate void RefAction<C1, C2, C3>(ref C1 c1, ref C2 c2, ref C3 c3);
40+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3641
public static void ForEach<C1, C2, C3>(this Commands commands, RefAction<C1, C2, C3> action)
3742
where C1 : struct
3843
where C2 : struct
@@ -51,6 +56,7 @@ public static void ForEach<C1, C2, C3>(this Commands commands, RefAction<C1, C2,
5156
}
5257

5358
public delegate void RefAction<C1, C2, C3, C4>(ref C1 c1, ref C2 c2, ref C3 c3, ref C4 c4);
59+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
5460
public static void ForEach<C1, C2, C3, C4>(this Commands commands, RefAction<C1, C2, C3, C4> action)
5561
where C1 : struct
5662
where C2 : struct
@@ -71,6 +77,7 @@ public static void ForEach<C1, C2, C3, C4>(this Commands commands, RefAction<C1,
7177
}
7278

7379
public delegate void RefAction<C1, C2, C3, C4, C5>(ref C1 c1, ref C2 c2, ref C3 c3, ref C4 c4, ref C5 c5);
80+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
7481
public static void ForEach<C1, C2, C3, C4, C5>(this Commands commands, RefAction<C1, C2, C3, C4, C5> action)
7582
where C1 : struct
7683
where C2 : struct
@@ -93,6 +100,7 @@ public static void ForEach<C1, C2, C3, C4, C5>(this Commands commands, RefAction
93100
}
94101

95102
public delegate void RefAction<C1, C2, C3, C4, C5, C6>(ref C1 c1, ref C2 c2, ref C3 c3, ref C4 c4, ref C5 c5, ref C6 c6);
103+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
96104
public static void ForEach<C1, C2, C3, C4, C5, C6>(this Commands commands, RefAction<C1, C2, C3, C4, C5, C6> action)
97105
where C1 : struct
98106
where C2 : struct
@@ -117,6 +125,7 @@ public static void ForEach<C1, C2, C3, C4, C5, C6>(this Commands commands, RefAc
117125
}
118126

119127
public delegate void RefAction<C1, C2, C3, C4, C5, C6, C7>(ref C1 c1, ref C2 c2, ref C3 c3, ref C4 c4, ref C5 c5, ref C6 c6, ref C7 c7);
128+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
120129
public static void ForEach<C1, C2, C3, C4, C5, C6, C7>(this Commands commands, RefAction<C1, C2, C3, C4, C5, C6, C7> action)
121130
where C1 : struct
122131
where C2 : struct
@@ -143,6 +152,7 @@ public static void ForEach<C1, C2, C3, C4, C5, C6, C7>(this Commands commands, R
143152
}
144153

145154
public delegate void RefAction<C1, C2, C3, C4, C5, C6, C7, C8>(ref C1 c1, ref C2 c2, ref C3 c3, ref C4 c4, ref C5 c5, ref C6 c6, ref C7 c7, ref C8 c8);
155+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
146156
public static void ForEach<C1, C2, C3, C4, C5, C6, C7, C8>(this Commands commands, RefAction<C1, C2, C3, C4, C5, C6, C7, C8> action)
147157
where C1 : struct
148158
where C2 : struct
@@ -171,6 +181,7 @@ public static void ForEach<C1, C2, C3, C4, C5, C6, C7, C8>(this Commands command
171181
}
172182

173183
public delegate void EntityRefAction(Entity entity);
184+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
174185
public static void ForEach(this Commands commands, EntityRefAction action)
175186
{
176187
var query = commands.Query();
@@ -182,6 +193,7 @@ public static void ForEach(this Commands commands, EntityRefAction action)
182193
}
183194

184195
public delegate void EntityRefAction<C>(Entity entity, ref C c);
196+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
185197
public static void ForEach<C>(this Commands commands, EntityRefAction<C> action)
186198
where C : struct
187199
{
@@ -196,6 +208,7 @@ public static void ForEach<C>(this Commands commands, EntityRefAction<C> action)
196208
}
197209

198210
public delegate void EntityRefAction<C1, C2>(Entity entity, ref C1 c1, ref C2 c2);
211+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
199212
public static void ForEach<C1, C2>(this Commands commands, EntityRefAction<C1, C2> action)
200213
where C1 : struct
201214
where C2 : struct
@@ -212,6 +225,7 @@ public static void ForEach<C1, C2>(this Commands commands, EntityRefAction<C1, C
212225
}
213226

214227
public delegate void EntityRefAction<C1, C2, C3>(Entity entity, ref C1 c1, ref C2 c2, ref C3 c3);
228+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
215229
public static void ForEach<C1, C2, C3>(this Commands commands, EntityRefAction<C1, C2, C3> action)
216230
where C1 : struct
217231
where C2 : struct
@@ -230,6 +244,7 @@ public static void ForEach<C1, C2, C3>(this Commands commands, EntityRefAction<C
230244
}
231245

232246
public delegate void EntityRefAction<C1, C2, C3, C4>(Entity entity, ref C1 c1, ref C2 c2, ref C3 c3, ref C4 c4);
247+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
233248
public static void ForEach<C1, C2, C3, C4>(this Commands commands, EntityRefAction<C1, C2, C3, C4> action)
234249
where C1 : struct
235250
where C2 : struct
@@ -250,6 +265,7 @@ public static void ForEach<C1, C2, C3, C4>(this Commands commands, EntityRefActi
250265
}
251266

252267
public delegate void EntityRefAction<C1, C2, C3, C4, C5>(Entity entity, ref C1 c1, ref C2 c2, ref C3 c3, ref C4 c4, ref C5 c5);
268+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
253269
public static void ForEach<C1, C2, C3, C4, C5>(this Commands commands, EntityRefAction<C1, C2, C3, C4, C5> action)
254270
where C1 : struct
255271
where C2 : struct
@@ -272,6 +288,7 @@ public static void ForEach<C1, C2, C3, C4, C5>(this Commands commands, EntityRef
272288
}
273289

274290
public delegate void EntityRefAction<C1, C2, C3, C4, C5, C6>(Entity entity, ref C1 c1, ref C2 c2, ref C3 c3, ref C4 c4, ref C5 c5, ref C6 c6);
291+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
275292
public static void ForEach<C1, C2, C3, C4, C5, C6>(this Commands commands, EntityRefAction<C1, C2, C3, C4, C5, C6> action)
276293
where C1 : struct
277294
where C2 : struct
@@ -296,6 +313,7 @@ public static void ForEach<C1, C2, C3, C4, C5, C6>(this Commands commands, Entit
296313
}
297314

298315
public delegate void EntityRefAction<C1, C2, C3, C4, C5, C6, C7>(Entity entity, ref C1 c1, ref C2 c2, ref C3 c3, ref C4 c4, ref C5 c5, ref C6 c6, ref C7 c7);
316+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
299317
public static void ForEach<C1, C2, C3, C4, C5, C6, C7>(this Commands commands, EntityRefAction<C1, C2, C3, C4, C5, C6, C7> action)
300318
where C1 : struct
301319
where C2 : struct
@@ -322,6 +340,7 @@ public static void ForEach<C1, C2, C3, C4, C5, C6, C7>(this Commands commands, E
322340
}
323341

324342
public delegate void EntityRefAction<C1, C2, C3, C4, C5, C6, C7, C8>(Entity entity, ref C1 c1, ref C2 c2, ref C3 c3, ref C4 c4, ref C5 c5, ref C6 c6, ref C7 c7, ref C8 c8);
343+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
325344
public static void ForEach<C1, C2, C3, C4, C5, C6, C7, C8>(this Commands commands, EntityRefAction<C1, C2, C3, C4, C5, C6, C7, C8> action)
326345
where C1 : struct
327346
where C2 : struct

src/Entity.cs

+1-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace RelEcs
66
public struct Entity
77
{
88
public static Entity None = default;
9-
public static Entity Any = new Entity(EntityId.Any);
9+
public static Entity Any = new Entity(null, EntityId.Any);
1010

1111
public bool IsAny => Id == EntityId.Any;
1212
public bool IsNone => Id == EntityId.None;
@@ -16,12 +16,6 @@ public struct Entity
1616

1717
World world;
1818

19-
public Entity(EntityId id)
20-
{
21-
this.world = null;
22-
Id = id;
23-
}
24-
2519
public Entity(World world, EntityId id)
2620
{
2721
this.world = world;

src/Mask.cs

+8-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public Mask()
2828
isBuilt = false;
2929
#endif
3030
}
31-
31+
32+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3233
public void Has(int typeIndex)
3334
{
3435
#if DEBUG
@@ -45,7 +46,8 @@ public void Has(int typeIndex)
4546
HasBitSet.Set(typeIndex);
4647
Types.Add(typeIndex);
4748
}
48-
49+
50+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4951
public void Any(int typeIndex)
5052
{
5153
#if DEBUG
@@ -63,7 +65,8 @@ public void Any(int typeIndex)
6365
AnyBitSet.Set(typeIndex);
6466
Types.Add(typeIndex);
6567
}
66-
68+
69+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
6770
public void Not(int typeIndex)
6871
{
6972
#if DEBUG
@@ -95,7 +98,8 @@ public void Lock(int capacity = 512)
9598
#endif
9699
Types.Sort();
97100
}
98-
101+
102+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
99103
public override int GetHashCode()
100104
{
101105
int hash = Types.Count;

src/Query.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
21
using System;
3-
using System.Collections.Generic;
42
using System.Runtime.CompilerServices;
53

64
namespace RelEcs
75
{
86
public sealed class Query
97
{
10-
World world;
8+
readonly World world;
119

12-
public Mask Mask;
10+
public readonly Mask Mask;
1311

1412
int[] indices;
1513
Entity[] entities;

0 commit comments

Comments
 (0)