Skip to content

Commit

Permalink
Merge pull request #15 from JerryImMouse/fix-window-icons
Browse files Browse the repository at this point in the history
Mount directories before icons load
  • Loading branch information
Tornado-Technology authored Jul 12, 2024
2 parents 5a38cb5 + 508dda4 commit 40edf83
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
6 changes: 0 additions & 6 deletions Hypercube.Client/Graphics/Rendering/Renderer.Render.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion Hypercube.Client/Graphics/Rendering/Renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ private bool TryGetWindow(Window* window, [NotNullWhen(true)] out GlfwWindowRegi
return null;
}

public IEnumerable<ITexture> LoadWindowIcon(ITextureManager textureMan, IResourceManager resourceManager, ResourcePath path)
public IEnumerable<ITexture> LoadWindowIcons(ITextureManager textureMan, IResourceManager resourceManager, ResourcePath path)
{
var files = resourceManager.FindContentFiles(path);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ITexture> LoadWindowIcon(ITextureManager textureManager, IResourceManager resourceManager, ResourcePath resPath);
IEnumerable<ITexture> LoadWindowIcons(ITextureManager textureManager, IResourceManager resourceManager, ResourcePath resPath);
void SetWindowIcons(WindowRegistration window, List<ITexture> images);

nint GetProcAddress(string procName);
Expand Down
22 changes: 21 additions & 1 deletion Hypercube.Shared/Resources/Manager/ResourceManager.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
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<RuntimeInitializationEvent>(OnInitialization);
}

private void OnInitialization(RuntimeInitializationEvent args)
{
MountContentFolder(".", "/");
MountContentFolder("Resources", "/");
MountContentFolder("Resources/Textures", "/");
MountContentFolder("Resources/Shaders", "/");

_logger.EngineInfo("Mounted resource directories");
}

public void AddRoot(ResourcePath prefix, IContentRoot root)
{
lock (_rootLock)
Expand Down

0 comments on commit 40edf83

Please sign in to comment.