Skip to content

Commit c8bd395

Browse files
[Core] Added IGuidAsset GuidHash property;
[Rendering] Add MeshRenderSystem ordering to optimize;
1 parent 8297dac commit c8bd395

File tree

19 files changed

+264
-112
lines changed

19 files changed

+264
-112
lines changed

Engine/Core/Audio/AudioClip.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,21 @@ public sealed class AudioClip : IGuidAsset
5757

5858
private string guid;
5959

60-
public string Guid { get => guid; set => guid = value; }
60+
private int guidHash;
61+
62+
public int GuidHash => guidHash;
63+
64+
public string Guid
65+
{
66+
get => guid;
67+
68+
set
69+
{
70+
guid = value;
71+
72+
guidHash = guid?.GetHashCode() ?? 0;
73+
}
74+
}
6175

6276
/// <summary>
6377
/// Gets an internal audio stream for the audio.

Engine/Core/Entities/Prefab.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,22 @@ public class Prefab : IGuidAsset
99
{
1010
internal SerializablePrefab data;
1111

12-
public string Guid { get; set; }
12+
private int guidHash;
13+
private string guid;
14+
15+
public int GuidHash => guidHash;
16+
17+
public string Guid
18+
{
19+
get => guid;
20+
21+
set
22+
{
23+
guid = value;
24+
25+
guidHash = guid?.GetHashCode() ?? 0;
26+
}
27+
}
1328

1429
public static object Create(string guid)
1530
{

Engine/Core/Rendering/Animation/SkinnedAnimationStateMachine.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,22 @@ public class AnimationState
153153
/// </summary>
154154
public List<AnimationParameter> parameters = [];
155155

156-
public string Guid { get; set; }
156+
private int guidHash;
157+
private string guid;
158+
159+
public int GuidHash => guidHash;
160+
161+
public string Guid
162+
{
163+
get => guid;
164+
165+
set
166+
{
167+
guid = value;
168+
169+
guidHash = guid?.GetHashCode() ?? 0;
170+
}
171+
}
157172

158173
public static object Create(string guid)
159174
{

Engine/Core/Rendering/Animation/SkinnedMeshRenderSystem.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public void Process((Entity, Transform, IComponent)[] entities, Camera activeCam
151151

152152
Matrix4x4[] boneMatrices;
153153

154-
if (renderCache.TryGetValue(meshAsset.Guid.GetHashCode(), out var cache) == false)
154+
if (renderCache.TryGetValue(meshAsset.GuidHash, out var cache) == false)
155155
{
156156
boneMatrices = new Matrix4x4[meshAsset.BoneCount];
157157

@@ -160,7 +160,7 @@ public void Process((Entity, Transform, IComponent)[] entities, Camera activeCam
160160
boneMatrices = boneMatrices,
161161
};
162162

163-
renderCache.Add(meshAsset.Guid.GetHashCode(), cache);
163+
renderCache.Add(meshAsset.GuidHash, cache);
164164
}
165165
else
166166
{
@@ -235,14 +235,14 @@ public void Submit()
235235

236236
for (var j = 0; j < renderer.mesh.submeshes.Count; j++)
237237
{
238-
var assetGuid = meshAsset.Guid.GetHashCode();
238+
var assetGuid = meshAsset.GuidHash;
239239

240240
var material = renderer.materials[j];
241241

242242
var useAnimator = animator != null && animator.evaluator != null;
243243

244244
var needsChange = assetGuid != lastMeshAsset ||
245-
material.Guid != (lastMaterial?.Guid ?? "") ||
245+
material.GuidHash != (lastMaterial?.GuidHash ?? 0) ||
246246
lastAnimator != animator ||
247247
lastLighting != renderer.lighting;
248248

Engine/Core/Rendering/Lighting/LightSystem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public void ApplyLightProperties(Vector3 position, Matrix4x4 transform, Material
185185
cachedLightSpotDirection[i] = forward.ToVector4();
186186
}
187187

188-
var key = material.shader.Guid.GetHashCode();
188+
var key = material.shader.GuidHash;
189189

190190
if(cachedMaterialInfo.TryGetValue(key, out var handles) == false)
191191
{

Engine/Core/Rendering/Material.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ internal static Texture WhiteTexture
9898
}
9999

100100
internal Shader shader;
101-
internal string guid;
102101
internal MaterialMetadata metadata;
103102

104103
internal Dictionary<int, ParameterInfo> parameters = [];
@@ -185,14 +184,21 @@ internal bgfx.StateFlags CullingFlag
185184
}
186185
}
187186

188-
/// <summary>
189-
/// The asset's guid (if any)
190-
/// </summary>
187+
private int guidHash;
188+
private string guid;
189+
190+
public int GuidHash => guidHash;
191+
191192
public string Guid
192193
{
193194
get => guid;
194195

195-
set => guid = value;
196+
set
197+
{
198+
guid = value;
199+
200+
guidHash = guid?.GetHashCode() ?? 0;
201+
}
196202
}
197203

198204
/// <summary>

Engine/Core/Rendering/Mesh/Mesh.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -674,16 +674,21 @@ public int VertexCount
674674
/// </summary>
675675
public int IndexCount => indices?.Length ?? 0;
676676

677-
internal string guid;
677+
private int guidHash;
678+
private string guid;
679+
680+
public int GuidHash => guidHash;
678681

679-
/// <summary>
680-
/// Asset GUID
681-
/// </summary>
682682
public string Guid
683683
{
684684
get => guid;
685685

686-
set => guid = value;
686+
set
687+
{
688+
guid = value;
689+
690+
guidHash = guid?.GetHashCode() ?? 0;
691+
}
687692
}
688693

689694
/// <summary>

Engine/Core/Rendering/Mesh/MeshAsset.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -635,10 +635,22 @@ public class Animation
635635
/// </summary>
636636
public int BoneCount { get; internal set; }
637637

638-
/// <summary>
639-
/// Asset GUID
640-
/// </summary>
641-
public string Guid { get; set; }
638+
private int guidHash;
639+
private string guid;
640+
641+
public int GuidHash => guidHash;
642+
643+
public string Guid
644+
{
645+
get => guid;
646+
647+
set
648+
{
649+
guid = value;
650+
651+
guidHash = guid?.GetHashCode() ?? 0;
652+
}
653+
}
642654

643655
/// <summary>
644656
/// Attempts to get an animation by name

0 commit comments

Comments
 (0)