Profiling for starting play mode, fixed unnecessary font loading

This commit is contained in:
Simon Lübeß
2025-07-30 19:00:22 +02:00
parent ed644b5b41
commit c01ccf571e
3 changed files with 28 additions and 2 deletions
+2
View File
@@ -837,6 +837,8 @@ namespace GlitchyEditor
/// Starts the play mode for the current scene /// Starts the play mode for the current scene
private void OnScenePlay() private void OnScenePlay()
{ {
Debug.Profiler.ProfileFunction!();
Log.EngineLogger.AssertDebug(_scriptSerializer.SerializedObjectCount == 0, "Somehow some entities are serialized."); Log.EngineLogger.AssertDebug(_scriptSerializer.SerializedObjectCount == 0, "Somehow some entities are serialized.");
if (Application.Instance.Settings.EditorSettings.ClearLogOnPlay) if (Application.Instance.Settings.EditorSettings.ClearLogOnPlay)
+12
View File
@@ -17,5 +17,17 @@ namespace GlitchyEngine.Core
{ {
ReleaseRef(); ReleaseRef();
} }
public int ReleaseRefGetCount()
{
int count = ReleaseRefNoDelete();
if (count == 0)
{
delete this;
}
return count;
}
} }
} }
+14 -2
View File
@@ -58,7 +58,7 @@ namespace GlitchyEngine.World
cameraEntity cameraEntity
}; };
Font _font ~ _.ReleaseRef(); static Font _font;
/// Gets or sets the name of the scene. /// Gets or sets the name of the scene.
public StringView Name public StringView Name
@@ -122,12 +122,20 @@ namespace GlitchyEngine.World
} }
}); });
_font = new Font(@"C:\Windows\Fonts\arial.ttf", 24); if (_font == null)
_font = new Font(@"C:\Windows\Fonts\arial.ttf", 24);
else
_font..AddRef();
//_font = new Font(@"C:\Windows\Fonts\Cascadia Code.ttf", 24); //_font = new Font(@"C:\Windows\Fonts\Cascadia Code.ttf", 24);
} }
public ~this() public ~this()
{ {
if (_font.ReleaseRefGetCount() == 0)
{
_font = null;
}
} }
/// Copies all entities with their components to the given target-scene. /// Copies all entities with their components to the given target-scene.
@@ -138,6 +146,8 @@ namespace GlitchyEngine.World
/// TODO: Honestly, I'm not quite sure what simulation mode is actually good for. Maybe we better just remove it? /// TODO: Honestly, I'm not quite sure what simulation mode is actually good for. Maybe we better just remove it?
public void CopyTo(Scene target, bool copyScripts) public void CopyTo(Scene target, bool copyScripts)
{ {
Debug.Profiler.ProfileFunction!();
// Copy entities // Copy entities
for (let sourceHandle in _ecsWorld.Enumerate()) for (let sourceHandle in _ecsWorld.Enumerate())
{ {
@@ -198,6 +208,8 @@ namespace GlitchyEngine.World
/// Copies the all components of type TComponent from source scene to the corresponding entities in target scene. /// Copies the all components of type TComponent from source scene to the corresponding entities in target scene.
private static void CopyComponents<TComponent>(Scene source, Scene target) where TComponent : struct, new private static void CopyComponents<TComponent>(Scene source, Scene target) where TComponent : struct, new
{ {
Debug.Profiler.ProfileFunction!();
for (let (sourceHandle, sourceComponent) in source._ecsWorld.Enumerate<TComponent>()) for (let (sourceHandle, sourceComponent) in source._ecsWorld.Enumerate<TComponent>())
{ {
Entity sourceEntity = .(sourceHandle, source); Entity sourceEntity = .(sourceHandle, source);