Skip to content

Commit d51c3e9

Browse files
[Platform] Fix AppSettings cloning missing some fields;
[Physics] Add missing Physics profiling tracking; [Rendering] Fix missing vertex/fragment textures causing exceptions; [UI] Add UIPerformanceDisplayer;
1 parent 68ec808 commit d51c3e9

File tree

8 files changed

+136
-6
lines changed

8 files changed

+136
-6
lines changed

Engine/Staple.Core/AppSettings/AppSettings.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public class AppSettings
185185
/// x64 Instruction Level
186186
/// </summary>
187187
[Key(28)]
188-
public X64InstructionLevel x64InstructionLevel = X64InstructionLevel.x86_64v3;
188+
public X64InstructionLevel x64InstructionLevel = X64InstructionLevel.x86_64v2;
189189

190190
[IgnoreMember]
191191
public static AppSettings Default
@@ -285,6 +285,8 @@ internal AppSettings Clone()
285285
enableLighting = enableLighting,
286286
allowUnsafeCode = allowUnsafeCode,
287287
usePhysicsInterpolation = usePhysicsInterpolation,
288+
overrideNativeInstructionSetX64 = overrideNativeInstructionSetX64,
289+
x64InstructionLevel = x64InstructionLevel,
288290
};
289291
}
290292
}

Engine/Staple.Core/Performance/PerformanceProfilerSystem.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Threading;
34

45
namespace Staple.Internal;
56

@@ -13,7 +14,7 @@ internal static class PerformanceProfilerSystem
1314

1415
private static readonly Dictionary<PerformanceProfilerType, int> averageFrameCounters = [];
1516

16-
private static readonly object lockObject = new();
17+
private static readonly Lock lockObject = new();
1718

1819
private static DateTime lastAverageTime = DateTime.UtcNow;
1920

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

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ internal IBody3D CreateBody(Entity entity, World world)
132132
return default;
133133
}
134134

135+
using var profiler = new PerformanceProfiler(PerformanceProfilerType.Physics);
136+
135137
return Impl.CreateBody(entity, world);
136138
}
137139

@@ -166,6 +168,8 @@ internal bool CreateBox(Entity entity, Vector3 extents, Vector3 position, Quater
166168
return false;
167169
}
168170

171+
using var profiler = new PerformanceProfiler(PerformanceProfilerType.Physics);
172+
169173
return Impl.CreateBox(entity, extents, position, rotation, motionType, layer, isTrigger, gravityFactor,
170174
friction, restitution, freezeX, freezeY, freezeZ, is2DPlane, mass, out body);
171175
}
@@ -201,6 +205,8 @@ internal bool CreateSphere(Entity entity, float radius, Vector3 position, Quater
201205
return false;
202206
}
203207

208+
using var profiler = new PerformanceProfiler(PerformanceProfilerType.Physics);
209+
204210
return Impl.CreateSphere(entity, radius, position, rotation, motionType, layer, isTrigger, gravityFactor,
205211
friction, restitution, freezeX, freezeY, freezeZ, is2DPlane, mass, out body);
206212
}
@@ -237,6 +243,8 @@ internal bool CreateCapsule(Entity entity, float height, float radius, Vector3 p
237243
return false;
238244
}
239245

246+
using var profiler = new PerformanceProfiler(PerformanceProfilerType.Physics);
247+
240248
return Impl.CreateCapsule(entity, height, radius, position, rotation, motionType, layer, isTrigger, gravityFactor,
241249
friction, restitution, freezeX, freezeY, freezeZ, is2DPlane, mass, out body);
242250
}
@@ -273,6 +281,8 @@ internal bool CreateCylinder(Entity entity, float height, float radius, Vector3
273281
return false;
274282
}
275283

284+
using var profiler = new PerformanceProfiler(PerformanceProfilerType.Physics);
285+
276286
return Impl.CreateCylinder(entity, height, radius, position, rotation, motionType, layer, isTrigger, gravityFactor,
277287
friction, restitution, freezeX, freezeY, freezeZ, is2DPlane, mass, out body);
278288
}
@@ -308,6 +318,8 @@ internal bool CreateMesh(Entity entity, Mesh mesh, Vector3 position, Quaternion
308318
return false;
309319
}
310320

321+
using var profiler = new PerformanceProfiler(PerformanceProfilerType.Physics);
322+
311323
return Impl.CreateMesh(entity, mesh, position, rotation, motionType, layer, isTrigger, gravityFactor,
312324
friction, restitution, freezeX, freezeY, freezeZ, is2DPlane, mass, out body);
313325
}
@@ -337,6 +349,8 @@ internal bool CreateHeightMap(Entity entity, float[] heights, Vector3 offset, Ve
337349
return false;
338350
}
339351

352+
using var profiler = new PerformanceProfiler(PerformanceProfilerType.Physics);
353+
340354
return Impl.CreateHeightMap(entity, heights, offset, scale, position, rotation, layer, friction, restitution, mass, out body);
341355
}
342356

@@ -351,6 +365,8 @@ internal void DestroyBody(IBody3D body)
351365
return;
352366
}
353367

368+
using var profiler = new PerformanceProfiler(PerformanceProfilerType.Physics);
369+
354370
Impl.DestroyBody(body);
355371
}
356372

@@ -364,6 +380,8 @@ internal void DestroyAllBodies()
364380
return;
365381
}
366382

383+
using var profiler = new PerformanceProfiler(PerformanceProfilerType.Physics);
384+
367385
Impl.DestroyAllBodies();
368386
}
369387

@@ -379,6 +397,8 @@ internal void AddBody(IBody3D body, bool activated)
379397
return;
380398
}
381399

400+
using var profiler = new PerformanceProfiler(PerformanceProfilerType.Physics);
401+
382402
Impl.AddBody(body, activated);
383403
}
384404

@@ -393,6 +413,8 @@ internal void RemoveBody(IBody3D body)
393413
return;
394414
}
395415

416+
using var profiler = new PerformanceProfiler(PerformanceProfilerType.Physics);
417+
396418
Impl.RemoveBody(body);
397419
}
398420

@@ -416,6 +438,8 @@ public bool RayCast(Ray ray, out IBody3D body, out float fraction, LayerMask lay
416438
return false;
417439
}
418440

441+
using var profiler = new PerformanceProfiler(PerformanceProfilerType.Physics);
442+
419443
return Impl.RayCast(ray, out body, out fraction, layerMask, triggerQuery, maxDistance);
420444
}
421445

@@ -431,6 +455,8 @@ public float GravityFactor(IBody3D body)
431455
return default;
432456
}
433457

458+
using var profiler = new PerformanceProfiler(PerformanceProfilerType.Physics);
459+
434460
return Impl.GravityFactor(body);
435461
}
436462

@@ -446,6 +472,8 @@ public void SetGravityFactor(IBody3D body, float factor)
446472
return;
447473
}
448474

475+
using var profiler = new PerformanceProfiler(PerformanceProfilerType.Physics);
476+
449477
Impl.SetGravityFactor(body, factor);
450478
}
451479

@@ -461,6 +489,8 @@ public void SetBodyPosition(IBody3D body, Vector3 newPosition)
461489
return;
462490
}
463491

492+
using var profiler = new PerformanceProfiler(PerformanceProfilerType.Physics);
493+
464494
Impl.SetBodyPosition(body, newPosition);
465495
}
466496

@@ -476,6 +506,8 @@ public void SetBodyRotation(IBody3D body, Quaternion newRotation)
476506
return;
477507
}
478508

509+
using var profiler = new PerformanceProfiler(PerformanceProfilerType.Physics);
510+
479511
Impl.SetBodyRotation(body, newRotation);
480512
}
481513

@@ -491,6 +523,8 @@ public void SetBodyTrigger(IBody3D body, bool value)
491523
return;
492524
}
493525

526+
using var profiler = new PerformanceProfiler(PerformanceProfilerType.Physics);
527+
494528
Impl.SetBodyTrigger(body, value);
495529
}
496530

@@ -506,6 +540,8 @@ public IBody3D GetBody(Entity entity)
506540
return default;
507541
}
508542

543+
using var profiler = new PerformanceProfiler(PerformanceProfilerType.Physics);
544+
509545
return Impl.GetBody(entity);
510546
}
511547

@@ -521,6 +557,8 @@ public void AddForce(IBody3D body, Vector3 force)
521557
return;
522558
}
523559

560+
using var profiler = new PerformanceProfiler(PerformanceProfilerType.Physics);
561+
524562
Impl.AddForce(body, force);
525563
}
526564

@@ -536,6 +574,8 @@ public void AddImpulse(IBody3D body, Vector3 impulse)
536574
return;
537575
}
538576

577+
using var profiler = new PerformanceProfiler(PerformanceProfilerType.Physics);
578+
539579
Impl.AddImpulse(body, impulse);
540580
}
541581

@@ -551,6 +591,8 @@ public void AddAngularImpulse(IBody3D body, Vector3 impulse)
551591
return;
552592
}
553593

594+
using var profiler = new PerformanceProfiler(PerformanceProfilerType.Physics);
595+
554596
Impl.AddAngularImpulse(body, impulse);
555597
}
556598

@@ -565,7 +607,9 @@ public void RecreateBody(Entity entity)
565607
return;
566608
}
567609

568-
if(entity.TryGetComponent<RigidBody3D>(out var rigidBody))
610+
using var profiler = new PerformanceProfiler(PerformanceProfilerType.Physics);
611+
612+
if (entity.TryGetComponent<RigidBody3D>(out var rigidBody))
569613
{
570614
if (rigidBody.body != null)
571615
{
@@ -609,6 +653,8 @@ public void Startup()
609653
return;
610654
}
611655

656+
using var profiler = new PerformanceProfiler(PerformanceProfilerType.Physics);
657+
612658
var rigidBody = (RigidBody3D)component;
613659

614660
rigidBody.body = CreateBody(entity, world);
@@ -621,6 +667,8 @@ public void Startup()
621667
return;
622668
}
623669

670+
using var profiler = new PerformanceProfiler(PerformanceProfilerType.Physics);
671+
624672
var character = (Character3D)component;
625673

626674
character.body = CreateBody(entity, world);
@@ -633,6 +681,8 @@ public void Startup()
633681
return;
634682
}
635683

684+
using var profiler = new PerformanceProfiler(PerformanceProfilerType.Physics);
685+
636686
var rigidBody = (RigidBody3D)component;
637687

638688
DestroyBody(rigidBody.body);
@@ -647,6 +697,8 @@ public void Startup()
647697
return;
648698
}
649699

700+
using var profiler = new PerformanceProfiler(PerformanceProfilerType.Physics);
701+
650702
var character = (Character3D)component;
651703

652704
DestroyBody(character.body);
@@ -683,7 +735,9 @@ public void Update()
683735
return;
684736
}
685737

686-
if(needsSubsystemCheck)
738+
using var profiler = new PerformanceProfiler(PerformanceProfilerType.Physics);
739+
740+
if (needsSubsystemCheck)
687741
{
688742
needsSubsystemCheck = false;
689743

@@ -698,6 +752,8 @@ public void Update()
698752

699753
public void BodyActivated(IBody3D body)
700754
{
755+
using var profiler = new PerformanceProfiler(PerformanceProfilerType.Physics);
756+
701757
lock (lockObject)
702758
{
703759
foreach (var system in physicsReceivers)
@@ -709,6 +765,8 @@ public void BodyActivated(IBody3D body)
709765

710766
public void BodyDeactivated(IBody3D body)
711767
{
768+
using var profiler = new PerformanceProfiler(PerformanceProfilerType.Physics);
769+
712770
lock (lockObject)
713771
{
714772
foreach (var system in physicsReceivers)
@@ -720,6 +778,8 @@ public void BodyDeactivated(IBody3D body)
720778

721779
public void ContactAdded(IBody3D A, IBody3D B)
722780
{
781+
using var profiler = new PerformanceProfiler(PerformanceProfilerType.Physics);
782+
723783
lock (lockObject)
724784
{
725785
foreach (var system in physicsReceivers)
@@ -731,6 +791,8 @@ public void ContactAdded(IBody3D A, IBody3D B)
731791

732792
public void ContactPersisted(IBody3D A, IBody3D B)
733793
{
794+
using var profiler = new PerformanceProfiler(PerformanceProfilerType.Physics);
795+
734796
lock (lockObject)
735797
{
736798
foreach (var system in physicsReceivers)
@@ -742,6 +804,8 @@ public void ContactPersisted(IBody3D A, IBody3D B)
742804

743805
public void ContactRemoved(IBody3D A, IBody3D B)
744806
{
807+
using var profiler = new PerformanceProfiler(PerformanceProfilerType.Physics);
808+
745809
lock (lockObject)
746810
{
747811
foreach (var system in physicsReceivers)
@@ -753,6 +817,8 @@ public void ContactRemoved(IBody3D A, IBody3D B)
753817

754818
public bool ContactValidate(IBody3D A, IBody3D B)
755819
{
820+
using var profiler = new PerformanceProfiler(PerformanceProfilerType.Physics);
821+
756822
lock (lockObject)
757823
{
758824
foreach (var system in physicsReceivers)

Engine/Staple.Core/Rendering/RenderSystem/Backend/Impls/SDLGPU/SDLGPURendererBackend+Textures.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,13 @@ internal bool TryGetTextureSamplers(Texture[] vertexTextures, Texture[] fragment
10021002

10031003
if (vertexSamplers != null)
10041004
{
1005+
if(vertexTextures == null)
1006+
{
1007+
vertexSamplers = fragmentSamplers = default;
1008+
1009+
return false;
1010+
}
1011+
10051012
for (var i = 0; i < vertexSamplers.Length; i++)
10061013
{
10071014
if (vertexTextures[i]?.impl is not SDLGPUTexture texture ||
@@ -1020,6 +1027,13 @@ internal bool TryGetTextureSamplers(Texture[] vertexTextures, Texture[] fragment
10201027

10211028
if (fragmentSamplers != null)
10221029
{
1030+
if (fragmentTextures == null)
1031+
{
1032+
vertexSamplers = fragmentSamplers = default;
1033+
1034+
return false;
1035+
}
1036+
10231037
for (var i = 0; i < fragmentSamplers.Length; i++)
10241038
{
10251039
if (fragmentTextures[i]?.impl is not SDLGPUTexture texture ||

Engine/Staple.Core/Rendering/Windowing/RenderWindow.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
43
using System.Threading;
54

65
namespace Staple.Internal;

Engine/Staple.Core/Staple.Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@
286286
<Compile Include="UI\UIPanel+API.cs" />
287287
<Compile Include="UI\UIPanel+Internal.cs" />
288288
<Compile Include="UI\UIPanel.cs" />
289+
<Compile Include="UI\UIPerformanceDisplayer.cs" />
289290
<Compile Include="UI\UIRenderStats.cs" />
290291
<Compile Include="UI\UIScrollableFrame.cs" />
291292
<Compile Include="UI\UIScrollBar.cs" />

0 commit comments

Comments
 (0)