From 990d0d9b91e6a7aeba55e37dc75d21640219f348 Mon Sep 17 00:00:00 2001 From: JerryImMouse Date: Fri, 12 Jul 2024 21:49:15 +0500 Subject: [PATCH 1/3] mount directories before loading icons --- Hypercube.Client/Graphics/Rendering/Renderer.cs | 2 +- .../Graphics/Windows/Manager/GlfwWindowManager.Window.cs | 2 +- Hypercube.Client/Graphics/Windows/Manager/IWindowManager.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Hypercube.Client/Graphics/Rendering/Renderer.cs b/Hypercube.Client/Graphics/Rendering/Renderer.cs index a350fa7..79f6891 100644 --- a/Hypercube.Client/Graphics/Rendering/Renderer.cs +++ b/Hypercube.Client/Graphics/Rendering/Renderer.cs @@ -96,7 +96,7 @@ private void OnStartup(RuntimeStartupEvent args) break; } - var windowIcons = _windowManager.LoadWindowIcon(_textureManager, _resourceManager, "/Icons").ToList(); + var windowIcons = _windowManager.LoadWindowIcons(_textureManager, _resourceManager, "/Icons").ToList(); _windowManager.SetWindowIcons(MainWindow, windowIcons); diff --git a/Hypercube.Client/Graphics/Windows/Manager/GlfwWindowManager.Window.cs b/Hypercube.Client/Graphics/Windows/Manager/GlfwWindowManager.Window.cs index a7df78a..c5a609b 100644 --- a/Hypercube.Client/Graphics/Windows/Manager/GlfwWindowManager.Window.cs +++ b/Hypercube.Client/Graphics/Windows/Manager/GlfwWindowManager.Window.cs @@ -187,7 +187,7 @@ private bool TryGetWindow(Window* window, [NotNullWhen(true)] out GlfwWindowRegi return null; } - public IEnumerable LoadWindowIcon(ITextureManager textureMan, IResourceManager resourceManager, ResourcePath path) + public IEnumerable LoadWindowIcons(ITextureManager textureMan, IResourceManager resourceManager, ResourcePath path) { var files = resourceManager.FindContentFiles(path); diff --git a/Hypercube.Client/Graphics/Windows/Manager/IWindowManager.cs b/Hypercube.Client/Graphics/Windows/Manager/IWindowManager.cs index 65bde37..7d1487b 100644 --- a/Hypercube.Client/Graphics/Windows/Manager/IWindowManager.cs +++ b/Hypercube.Client/Graphics/Windows/Manager/IWindowManager.cs @@ -32,7 +32,7 @@ public interface IWindowManager : IDisposable void WindowSetVisible(WindowRegistration registration, bool visible); void WindowSetSize(WindowRegistration registration, Vector2Int size); void WindowSwapBuffers(WindowRegistration window); - IEnumerable LoadWindowIcon(ITextureManager textureManager, IResourceManager resourceManager, ResourcePath resPath); + IEnumerable LoadWindowIcons(ITextureManager textureManager, IResourceManager resourceManager, ResourcePath resPath); void SetWindowIcons(WindowRegistration window, List images); nint GetProcAddress(string procName); From e9762654a89a40c4df5f7a1cf003d897d0a45d18 Mon Sep 17 00:00:00 2001 From: JerryImMouse Date: Fri, 12 Jul 2024 21:53:29 +0500 Subject: [PATCH 2/3] startup method for resourcesManager --- .../Graphics/Rendering/Renderer.Render.cs | 6 ------ Hypercube.Client/Graphics/Rendering/Renderer.cs | 2 ++ .../Resources/Manager/IResourceManager.cs | 1 + .../Resources/Manager/ResourceManager.cs | 12 +++++++++++- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Hypercube.Client/Graphics/Rendering/Renderer.Render.cs b/Hypercube.Client/Graphics/Rendering/Renderer.Render.cs index dc5a1c6..9803e78 100644 --- a/Hypercube.Client/Graphics/Rendering/Renderer.Render.cs +++ b/Hypercube.Client/Graphics/Rendering/Renderer.Render.cs @@ -32,12 +32,6 @@ public sealed partial class Renderer private void OnLoad() { - // mount directories - _resourceManager.MountContentFolder(".", "/"); - _resourceManager.MountContentFolder("Resources", "/"); - _resourceManager.MountContentFolder("Resources/Textures", "/"); - _resourceManager.MountContentFolder("Resources/Shaders", "/"); - _baseShader = new Shader("/base", _resourceManager); _baseTexture = _textureManager.CreateHandler("/icon.png"); _baseTexture.Bind(); diff --git a/Hypercube.Client/Graphics/Rendering/Renderer.cs b/Hypercube.Client/Graphics/Rendering/Renderer.cs index 79f6891..0e0eed1 100644 --- a/Hypercube.Client/Graphics/Rendering/Renderer.cs +++ b/Hypercube.Client/Graphics/Rendering/Renderer.cs @@ -85,6 +85,8 @@ private void OnStartup(RuntimeStartupEvent args) _currentThread = Thread.CurrentThread; _logger.EngineInfo($"Working thread {_currentThread.Name}"); + _resourceManager.Startup(); + var settings = new WindowCreateSettings(); foreach (var contextInfo in _contextInfos) { diff --git a/Hypercube.Shared/Resources/Manager/IResourceManager.cs b/Hypercube.Shared/Resources/Manager/IResourceManager.cs index ea58bf0..9561dc2 100644 --- a/Hypercube.Shared/Resources/Manager/IResourceManager.cs +++ b/Hypercube.Shared/Resources/Manager/IResourceManager.cs @@ -4,6 +4,7 @@ namespace Hypercube.Shared.Resources.Manager; public interface IResourceManager { + void Startup(); StreamReader WrapStream(Stream stream); void AddRoot(ResourcePath prefix, IContentRoot root); void MountContentFolder(string file, ResourcePath? prefix = null); diff --git a/Hypercube.Shared/Resources/Manager/ResourceManager.cs b/Hypercube.Shared/Resources/Manager/ResourceManager.cs index 03a697f..3f236d8 100644 --- a/Hypercube.Shared/Resources/Manager/ResourceManager.cs +++ b/Hypercube.Shared/Resources/Manager/ResourceManager.cs @@ -10,7 +10,17 @@ public sealed class ResourceManager : IResourceManager private readonly Logger _logger = LoggingManager.GetLogger("resources"); private (ResourcePath prefix, IContentRoot root)[] _roots = Array.Empty<(ResourcePath, IContentRoot)>(); private readonly object _rootLock = new(); - + + public void Startup() + { + // mount directories + MountContentFolder(".", "/"); + MountContentFolder("Resources", "/"); + MountContentFolder("Resources/Textures", "/"); + MountContentFolder("Resources/Shaders", "/"); + _logger.EngineInfo("Mounted resource directories"); + } + public void AddRoot(ResourcePath prefix, IContentRoot root) { lock (_rootLock) From 508dda4b674402ef91bef16496b9bf8c42de1cbe Mon Sep 17 00:00:00 2001 From: Tornado Tech <54727692+Tornado-Technology@users.noreply.github.com> Date: Sat, 13 Jul 2024 08:30:45 +1000 Subject: [PATCH 3/3] Subscribe resource manager to init event --- Hypercube.Client/Graphics/Rendering/Renderer.cs | 2 -- .../Resources/Manager/IResourceManager.cs | 1 - .../Resources/Manager/ResourceManager.cs | 16 +++++++++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Hypercube.Client/Graphics/Rendering/Renderer.cs b/Hypercube.Client/Graphics/Rendering/Renderer.cs index 0e0eed1..79f6891 100644 --- a/Hypercube.Client/Graphics/Rendering/Renderer.cs +++ b/Hypercube.Client/Graphics/Rendering/Renderer.cs @@ -85,8 +85,6 @@ private void OnStartup(RuntimeStartupEvent args) _currentThread = Thread.CurrentThread; _logger.EngineInfo($"Working thread {_currentThread.Name}"); - _resourceManager.Startup(); - var settings = new WindowCreateSettings(); foreach (var contextInfo in _contextInfos) { diff --git a/Hypercube.Shared/Resources/Manager/IResourceManager.cs b/Hypercube.Shared/Resources/Manager/IResourceManager.cs index 9561dc2..ea58bf0 100644 --- a/Hypercube.Shared/Resources/Manager/IResourceManager.cs +++ b/Hypercube.Shared/Resources/Manager/IResourceManager.cs @@ -4,7 +4,6 @@ namespace Hypercube.Shared.Resources.Manager; public interface IResourceManager { - void Startup(); StreamReader WrapStream(Stream stream); void AddRoot(ResourcePath prefix, IContentRoot root); void MountContentFolder(string file, ResourcePath? prefix = null); diff --git a/Hypercube.Shared/Resources/Manager/ResourceManager.cs b/Hypercube.Shared/Resources/Manager/ResourceManager.cs index 3f236d8..95171d7 100644 --- a/Hypercube.Shared/Resources/Manager/ResourceManager.cs +++ b/Hypercube.Shared/Resources/Manager/ResourceManager.cs @@ -1,23 +1,33 @@ using System.Diagnostics.CodeAnalysis; +using Hypercube.Shared.Dependency; +using Hypercube.Shared.EventBus; using Hypercube.Shared.Logging; using Hypercube.Shared.Resources.DirRoot; +using Hypercube.Shared.Runtimes.Event; using Hypercube.Shared.Utilities.Helpers; namespace Hypercube.Shared.Resources.Manager; -public sealed class ResourceManager : IResourceManager +public sealed class ResourceManager : IResourceManager, IPostInject { + [Dependency] private readonly IEventBus _eventBus = default!; + private readonly Logger _logger = LoggingManager.GetLogger("resources"); private (ResourcePath prefix, IContentRoot root)[] _roots = Array.Empty<(ResourcePath, IContentRoot)>(); private readonly object _rootLock = new(); + + public void PostInject() + { + _eventBus.Subscribe(OnInitialization); + } - public void Startup() + private void OnInitialization(RuntimeInitializationEvent args) { - // mount directories MountContentFolder(".", "/"); MountContentFolder("Resources", "/"); MountContentFolder("Resources/Textures", "/"); MountContentFolder("Resources/Shaders", "/"); + _logger.EngineInfo("Mounted resource directories"); }