Handle loading error and placeholder shaders

This commit is contained in:
Simon Lübeß
2025-07-10 14:59:37 +02:00
parent 1b63c922da
commit c2d330fc8f
8 changed files with 192 additions and 56 deletions
@@ -316,8 +316,7 @@ namespace GlitchyEditor.EditWindows
{
_manager.Update();
// Show History
if (ImGui.Begin("Debug History"))
/*if (ImGui.Begin("Debug History"))
{
ImGui.CollapsingHeader("History");
for (String path in _directoryHistory.[Friend]_history)
@@ -338,7 +337,7 @@ namespace GlitchyEditor.EditWindows
}
ImGui.End();
}
}*/
// Make sure we are in an existing directory.
if (!_manager.AssetHierarchy.FileExists(CurrentDirectory))
@@ -745,57 +744,81 @@ namespace GlitchyEditor.EditWindows
private ImGui.RectangleSelectionData _rectangleSelection;
enum Modifiers
{
None,
Alt,
Ctrl,
Shift
}
private void HandleShortcuts()
{
Modifiers modifiers = .None;
Enum.SetFlagConditionally(ref modifiers, .Alt, Input.IsKeyPressed(.Alt));
Enum.SetFlagConditionally(ref modifiers, .Ctrl, Input.IsKeyPressed(.Control));
Enum.SetFlagConditionally(ref modifiers, .Shift, Input.IsKeyPressed(.Shift));
// TODO: Come up with a good hotkey system...
if (modifiers == .Alt)
{
if (Input.IsKeyPressing(.Up))
{
NavigateUp();
}
if (Input.IsKeyPressing(.Left))
{
NavigateBack();
}
if (Input .IsKeyPressing(.Right))
{
NavigateForward();
}
}
if (Input.IsMouseButtonPressing(.XButton1))
{
NavigateBack();
}
if (Input.IsMouseButtonPressing(.XButton2))
{
NavigateForward();
}
if (modifiers == .Ctrl)
{
if (Input.IsKeyPressing(.C))
{
CopySelectedFiles(cutFiles: false);
}
if (Input.IsKeyPressing(.X))
{
CopySelectedFiles(cutFiles: true);
}
if (Input.IsKeyPressing(.V))
{
PasteFiles(CurrentDirectory);
}
}
if (modifiers == .Ctrl | .Shift)
{
}
}
/// Renders the contents of _currentDirectory. Returns the node of the current directory, or null if the browser isn't in a directory.
private void DrawCurrentDirectory(TreeNode<AssetNode> currentDirectoryNode)
{
if (ImGui.IsWindowHovered())
{
// TODO: Come up with a good hotkey system...
if (Input.IsKeyPressed(.Alt))
{
if (Input.IsKeyPressing(.Up))
{
NavigateUp();
}
if (Input.IsKeyPressing(.Left))
{
NavigateBack();
}
if (Input .IsKeyPressing(.Right))
{
NavigateForward();
}
}
if (Input.IsMouseButtonPressing(.XButton1))
{
NavigateBack();
}
if (Input.IsMouseButtonPressing(.XButton2))
{
NavigateForward();
}
if (Input.IsKeyPressed(.Control))
{
if (Input.IsKeyPressing(.C))
{
CopySelectedFiles(cutFiles: false);
}
if (Input.IsKeyPressing(.X))
{
CopySelectedFiles(cutFiles: true);
}
if (Input.IsKeyPressing(.V))
{
PasteFiles(CurrentDirectory);
}
}
HandleShortcuts();
}
List<TreeNode<AssetNode>> directoryEntries = scope List<TreeNode<AssetNode>>();
+36 -4
View File
@@ -367,7 +367,16 @@ class EditorContentManager : IContentManager
if (!_handleToAsset.TryGetValue(handle, out asset))
{
LoadAsset(handle, blocking);
AssetHandle handleAfterLoading = LoadAsset(handle, blocking);
if (handleAfterLoading == .Invalid)
{
// TODO: If the asset existed at some point, the cache might still know of it.
// Or we store the asset name somewhere else. (For the editor in the asset using it?)
asset = new NewPlaceholderAsset(handle, .Error);
AssignHandleAndManage(asset, handle);
}
}
if (var placeholder = asset as PlaceholderAsset)
@@ -401,6 +410,8 @@ class EditorContentManager : IContentManager
private Asset GetPlaceholderAsset(Type assetType, PlaceholderType placeholderType)
{
// TODO: Probably don't hardcode paths here.
// TODO: Probably verify existence at start of application.
switch (assetType)
{
case typeof(Texture2D):
@@ -414,6 +425,17 @@ class EditorContentManager : IContentManager
AssetHandle handle = LoadAsset("Resources/Textures/ErrorTexture2D.png", true);
return GetAsset(null, handle);
}
case typeof(Effect):
if (placeholderType == .Loading)
{
AssetHandle handle = LoadAsset("Resources/Shaders/PlaceholderLoading.fx", true);
return GetAsset(null, handle);
}
else if (placeholderType == .Error)
{
AssetHandle handle = LoadAsset("Resources/Shaders/PlaceholderError.fx", true);
return GetAsset(null, handle);
}
}
return null;
@@ -623,6 +645,7 @@ class EditorContentManager : IContentManager
using (_finishedEntriesLock.Enter())
{
loadedAsset.Identifier = assetNode.Identifier;
// TODO: AssignHandleAndManage
loadedAsset.[Friend]_contentManager = this;
loadedAsset.[Friend]_handle = handle;
@@ -874,14 +897,23 @@ class EditorContentManager : IContentManager
// If this happens too often we could use a different random generator
}
//_handles.Add(asset.Identifier, handle);
AssignHandleAndManage(asset, handle);
return handle;
}
private void AssignHandleAndManage(Asset asset, AssetHandle handle)
{
if (_handleToAsset.TryGetValue(handle, let existingAsset))
{
existingAsset.ReleaseRef();
}
_handleToAsset.Add(handle, asset);
asset.[Friend]_contentManager = this;
asset.[Friend]_handle = handle;
asset.AddRef();
return handle;
}
private void SwapAsset(Asset oldAsset, Asset newAsset)