From c01ccf571eaf48337a6babbe8048d636b68dcea0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Wed, 30 Jul 2025 19:00:22 +0200 Subject: [PATCH] Profiling for starting play mode, fixed unnecessary font loading --- GlitchyEditor/src/EditorLayer.bf | 2 ++ GlitchyEngine/src/Core/RefCounter.bf | 12 ++++++++++++ GlitchyEngine/src/World/Scene.bf | 16 ++++++++++++++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/GlitchyEditor/src/EditorLayer.bf b/GlitchyEditor/src/EditorLayer.bf index 626d209..5c9b0fb 100644 --- a/GlitchyEditor/src/EditorLayer.bf +++ b/GlitchyEditor/src/EditorLayer.bf @@ -837,6 +837,8 @@ namespace GlitchyEditor /// Starts the play mode for the current scene private void OnScenePlay() { + Debug.Profiler.ProfileFunction!(); + Log.EngineLogger.AssertDebug(_scriptSerializer.SerializedObjectCount == 0, "Somehow some entities are serialized."); if (Application.Instance.Settings.EditorSettings.ClearLogOnPlay) diff --git a/GlitchyEngine/src/Core/RefCounter.bf b/GlitchyEngine/src/Core/RefCounter.bf index e2f2d8e..6361fd4 100644 --- a/GlitchyEngine/src/Core/RefCounter.bf +++ b/GlitchyEngine/src/Core/RefCounter.bf @@ -17,5 +17,17 @@ namespace GlitchyEngine.Core { ReleaseRef(); } + + public int ReleaseRefGetCount() + { + int count = ReleaseRefNoDelete(); + + if (count == 0) + { + delete this; + } + + return count; + } } } diff --git a/GlitchyEngine/src/World/Scene.bf b/GlitchyEngine/src/World/Scene.bf index 76f0ab7..f850792 100644 --- a/GlitchyEngine/src/World/Scene.bf +++ b/GlitchyEngine/src/World/Scene.bf @@ -58,7 +58,7 @@ namespace GlitchyEngine.World cameraEntity }; - Font _font ~ _.ReleaseRef(); + static Font _font; /// Gets or sets the name of the scene. 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); } public ~this() { + if (_font.ReleaseRefGetCount() == 0) + { + _font = null; + } } /// 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? public void CopyTo(Scene target, bool copyScripts) { + Debug.Profiler.ProfileFunction!(); + // Copy entities 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. private static void CopyComponents(Scene source, Scene target) where TComponent : struct, new { + Debug.Profiler.ProfileFunction!(); + for (let (sourceHandle, sourceComponent) in source._ecsWorld.Enumerate()) { Entity sourceEntity = .(sourceHandle, source);