Skip to content

Commit 4901f05

Browse files
[Core] WIP refactor;
1 parent 1d2f3c6 commit 4901f05

34 files changed

Lines changed: 457 additions & 579 deletions

Engine/Staple.Core/Assets/NoiseGeneratorSettings.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ public class NoiseGeneratorSettings : IStapleAsset, IGuidAsset
2323
public NoiseGenerator.DomainWarpType domainWarpType = NoiseGenerator.DomainWarpType.OpenSimplex2;
2424
public float domainWarpAmp = 1;
2525

26-
private readonly GuidHasher guidHasher = new();
27-
28-
public GuidHasher Guid => guidHasher;
26+
public GuidHasher Guid { get; } = new();
2927

3028
public static object Create(string guid)
3129
{

Engine/Staple.Core/Assets/TextAsset.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ public class TextAsset : IGuidAsset
88

99
public byte[] bytes;
1010

11-
private readonly GuidHasher guidHasher = new();
12-
13-
public GuidHasher Guid => guidHasher;
11+
public GuidHasher Guid { get; } = new();
1412

1513
public static object Create(string guid)
1614
{

Engine/Staple.Core/Audio/AudioClip.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ public sealed class AudioClip : IGuidAsset
5555
/// </summary>
5656
internal byte[] fileData;
5757

58-
private readonly GuidHasher guidHasher = new();
59-
60-
public GuidHasher Guid => guidHasher;
58+
public GuidHasher Guid { get; } = new();
6159

6260
/// <summary>
6361
/// Gets an internal audio stream for the audio.

Engine/Staple.Core/Entities/EntityQuery.cs

Lines changed: 62 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -39,45 +39,40 @@ public enum EntityQueryMode
3939
public sealed class EntityQuery<T> : ISceneQuery
4040
where T : IComponent
4141
{
42-
private T[] contents = [];
43-
private T content;
44-
private (Entity, T)[] contentEntities = [];
45-
private (Entity, T) contentEntity;
46-
4742
private readonly EntityQueryMode queryMode;
4843
private readonly Entity target;
4944
private readonly bool getEntities;
5045

51-
public int Length => contents.Length;
46+
public int Length => Contents.Length;
5247

5348
/// <summary>
5449
/// Contained content. Only valid if we have a single element.
5550
/// </summary>
56-
public T Content => content;
51+
public T Content { get; private set; }
5752

5853
/// <summary>
5954
/// Contained content. Only valid if we have a single element.
6055
/// </summary>
61-
public T[] Contents => contents;
56+
public T[] Contents { get; private set; } = [];
6257

6358
/// <summary>
6459
/// The content with its entity, if available.
6560
/// </summary>
66-
public (Entity, T) ContentEntity => contentEntity;
61+
public (Entity, T) ContentEntity { get; private set; }
6762

6863
/// <summary>
6964
/// The content with its entity, if available.
7065
/// </summary>
71-
public (Entity, T)[] ContentEntities => contentEntities;
66+
public (Entity, T)[] ContentEntities { get; private set; } = [];
7267

73-
public T this[int index] => contents[index];
68+
public T this[int index] => Contents[index];
7469

7570
/// <summary>
7671
/// Gets an entity and component at a specific index
7772
/// </summary>
7873
/// <param name="index">The index to get at</param>
7974
/// <returns>The entity and component as a tuple, if valid</returns>
80-
public (Entity, T) ContentEntityAt(int index) => index >= 0 && index < contentEntities.Length ? contentEntities[index] : default;
75+
public (Entity, T) ContentEntityAt(int index) => index >= 0 && index < ContentEntities.Length ? ContentEntities[index] : default;
8176

8277
/// <summary>
8378
/// Creates an entity query for a specific entity.
@@ -101,20 +96,20 @@ public void Unregister()
10196
{
10297
World.RemoveSceneQuery(this);
10398

104-
content = default;
105-
contentEntity = default;
99+
Content = default;
100+
ContentEntity = default;
106101

107-
contents = [];
108-
contentEntities = [];
102+
Contents = [];
103+
ContentEntities = [];
109104
}
110105

111106
public void WorldChanged()
112107
{
113-
content = default;
114-
contentEntity = default;
108+
Content = default;
109+
ContentEntity = default;
115110

116-
contents = [];
117-
contentEntities = [];
111+
Contents = [];
112+
ContentEntities = [];
118113

119114
if (!target.IsValid)
120115
{
@@ -143,7 +138,7 @@ public void WorldChanged()
143138
count++;
144139
}
145140

146-
contents = new T[count];
141+
Contents = new T[count];
147142

148143
for(int i = 0, counter = 0; i < items.Length; i++)
149144
{
@@ -152,27 +147,29 @@ public void WorldChanged()
152147
continue;
153148
}
154149

155-
contents[counter++] = (T)items[i];
150+
Contents[counter++] = items[i];
156151
}
157152

158-
if(count == 1 && contents[0] != null)
153+
if(count == 1 && Contents[0] != null)
159154
{
160-
content = contents[0];
155+
Content = Contents[0];
161156
}
162157

163-
if(getEntities)
158+
if (!getEntities)
164159
{
165-
contentEntities = new (Entity, T)[count];
160+
return;
161+
}
162+
163+
ContentEntities = new (Entity, T)[count];
166164

167-
for(var i = 0; i < items.Length; i++)
168-
{
169-
contentEntities[i] = (World.Current.GetComponentEntity(contents[i]), contents[i]);
170-
}
165+
for(var i = 0; i < items.Length; i++)
166+
{
167+
ContentEntities[i] = (World.Current.GetComponentEntity(Contents[i]), Contents[i]);
168+
}
171169

172-
if(count == 1 && contents[0] != null)
173-
{
174-
contentEntity = contentEntities[0];
175-
}
170+
if(count == 1 && Contents[0] != null)
171+
{
172+
ContentEntity = ContentEntities[0];
176173
}
177174
}
178175
}
@@ -187,45 +184,40 @@ public sealed class EntityQuery<T, T2> : ISceneQuery
187184
where T : IComponent
188185
where T2 : IComponent
189186
{
190-
private (T, T2)[] contents = [];
191-
private (T, T2) content;
192-
private (Entity, T, T2)[] contentEntities = [];
193-
private (Entity, T, T2) contentEntity;
194-
195187
private readonly EntityQueryMode queryMode;
196188
private readonly Entity target;
197189
private readonly bool getEntities;
198190

199-
public int Length => contents.Length;
191+
public int Length => Contents.Length;
200192

201193
/// <summary>
202194
/// Contained content. Only valid if we have a single element.
203195
/// </summary>
204-
public (T, T2) Content => content;
196+
public (T, T2) Content { get; private set; }
205197

206198
/// <summary>
207199
/// Contained content. Only valid if we have a single element.
208200
/// </summary>
209-
public (T, T2)[] Contents => contents;
201+
public (T, T2)[] Contents { get; private set; } = [];
210202

211203
/// <summary>
212204
/// The content with its entity, if available.
213205
/// </summary>
214-
public (Entity, T, T2) ContentEntity => contentEntity;
206+
public (Entity, T, T2) ContentEntity { get; private set; }
215207

216208
/// <summary>
217209
/// The content with its entity, if available.
218210
/// </summary>
219-
public (Entity, T, T2)[] ContentEntities => contentEntities;
211+
public (Entity, T, T2)[] ContentEntities { get; private set; } = [];
220212

221-
public (T, T2) this[int index] => contents[index];
213+
public (T, T2) this[int index] => Contents[index];
222214

223215
/// <summary>
224216
/// Gets an entity and component at a specific index
225217
/// </summary>
226218
/// <param name="index">The index to get at</param>
227219
/// <returns>The entity and component as a tuple, if valid</returns>
228-
public (Entity, T, T2) ContentEntityAt(int index) => index >= 0 && index < contentEntities.Length ? contentEntities[index] : default;
220+
public (Entity, T, T2) ContentEntityAt(int index) => index >= 0 && index < ContentEntities.Length ? ContentEntities[index] : default;
229221

230222
/// <summary>
231223
/// Creates an entity query for a specific entity.
@@ -249,20 +241,20 @@ public void Unregister()
249241
{
250242
World.RemoveSceneQuery(this);
251243

252-
content = default;
253-
contentEntity = default;
244+
Content = default;
245+
ContentEntity = default;
254246

255-
contents = [];
256-
contentEntities = [];
247+
Contents = [];
248+
ContentEntities = [];
257249
}
258250

259251
public void WorldChanged()
260252
{
261-
content = default;
262-
contentEntity = default;
253+
Content = default;
254+
ContentEntity = default;
263255

264-
contents = [];
265-
contentEntities = [];
256+
Contents = [];
257+
ContentEntities = [];
266258

267259
if (!target.IsValid)
268260
{
@@ -413,28 +405,30 @@ void Recursive(Transform transform)
413405
break;
414406
}
415407

416-
contents = items.ToArray();
408+
Contents = items.ToArray();
417409

418-
if (contents.Length == 1)
410+
if (Contents.Length == 1)
419411
{
420-
content = contents[0];
412+
Content = Contents[0];
421413
}
422414

423-
if (getEntities)
415+
if (!getEntities)
424416
{
425-
contentEntities = new (Entity, T, T2)[items.Count];
417+
return;
418+
}
426419

427-
for (var i = 0; i < items.Count; i++)
428-
{
429-
var item = items[i];
420+
ContentEntities = new (Entity, T, T2)[items.Count];
430421

431-
contentEntities[i] = (World.Current.GetComponentEntity(item.Item1), item.Item1, item.Item2);
432-
}
422+
for (var i = 0; i < items.Count; i++)
423+
{
424+
var item = items[i];
433425

434-
if (items.Count == 1)
435-
{
436-
contentEntity = contentEntities[0];
437-
}
426+
ContentEntities[i] = (World.Current.GetComponentEntity(item.Item1), item.Item1, item.Item2);
427+
}
428+
429+
if (items.Count == 1)
430+
{
431+
ContentEntity = ContentEntities[0];
438432
}
439433
}
440434
}

Engine/Staple.Core/Entities/Prefab.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ public sealed class Prefab : IGuidAsset
99
{
1010
internal SerializablePrefab data;
1111

12-
private readonly GuidHasher guidHasher = new();
13-
14-
public GuidHasher Guid => guidHasher;
12+
public GuidHasher Guid { get; } = new();
1513

1614
public static object Create(string guid)
1715
{

Engine/Staple.Core/External/StbRectPackSharp/src/Packer.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,11 @@ public PackerRectangle(Rectangle rect, object data)
3939
unsafe class Packer : IDisposable
4040
{
4141
private readonly stbrp_context _context;
42-
private readonly List<PackerRectangle> _rectangles = new List<PackerRectangle>();
4342

4443
public int Width => _context.width;
4544
public int Height => _context.height;
4645

47-
public List<PackerRectangle> PackRectangles => _rectangles;
46+
public List<PackerRectangle> PackRectangles { get; } = new List<PackerRectangle>();
4847

4948

5049
public Packer(int width = 256, int height = 256)
@@ -85,7 +84,7 @@ public PackerRectangle PackRect(int width, int height, object userData)
8584
{
8685
var rect = new stbrp_rect
8786
{
88-
id = _rectangles.Count,
87+
id = PackRectangles.Count,
8988
w = width,
9089
h = height
9190
};
@@ -102,7 +101,7 @@ public PackerRectangle PackRect(int width, int height, object userData)
102101
}
103102

104103
var packRectangle = new PackerRectangle(new Rectangle(rect.x, rect.y, rect.w, rect.h), userData);
105-
_rectangles.Add(packRectangle);
104+
PackRectangles.Add(packRectangle);
106105

107106
return packRectangle;
108107
}

Engine/Staple.Core/Input/InputActions.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ public sealed class InputActions : IStapleAsset, IGuidAsset
1313
/// </summary>
1414
public List<InputAction> actions = [];
1515

16-
private readonly GuidHasher guidHasher = new();
17-
18-
public GuidHasher Guid => guidHasher;
16+
public GuidHasher Guid { get; } = new();
1917

2018
public static object Create(string guid)
2119
{

Engine/Staple.Core/Physics/3D/Physics3D.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,7 @@ namespace Staple.Internal;
1010
/// </summary>
1111
public sealed class Physics3D : ISubsystem
1212
{
13-
private static Physics3D instance;
14-
15-
public static Physics3D Instance
16-
{
17-
get => instance;
18-
19-
internal set
20-
{
21-
instance = value;
22-
}
23-
}
13+
public static Physics3D Instance { get; internal set; }
2414

2515
public const int PhysicsPickLayer = 31;
2616

Engine/Staple.Core/Rendering/Animation/SkinnedAnimationStateMachine.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,7 @@ public class EditorData
179179
[SerializeField]
180180
public EditorData editorData = new();
181181

182-
private readonly GuidHasher guidHasher = new();
183-
184-
public GuidHasher Guid => guidHasher;
182+
public GuidHasher Guid { get; } = new();
185183

186184
public static object Create(string guid)
187185
{

Engine/Staple.Core/Rendering/Animation/SkinnedMeshRenderSystem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ void SetupMaterial()
306306
continue;
307307
}
308308

309-
material.ApplyProperties(Material.ApplyMode.All, ref renderState);
309+
material.ApplyProperties(ref renderState);
310310
}
311311

312312
SetupMaterial();

0 commit comments

Comments
 (0)