Better asset processor selection, process subassets

This commit is contained in:
Simon Lübeß
2024-06-13 15:44:27 +02:00
parent 36e98311c6
commit cd434d64f9
22 changed files with 356 additions and 292 deletions
+4 -4
View File
@@ -35,13 +35,13 @@ public class AssetIdentifier
[AllowAppend]
public this(StringView assetIdentifier, StringView subAssetIdentifier)
{
String identifier = append String(assetIdentifier.Length + 1 + subAssetIdentifier.Length);
identifier.AppendF($"{assetIdentifier}:{subAssetIdentifier}");
String fullIdentifier = append String(assetIdentifier.Length + 1 + subAssetIdentifier.Length);
fullIdentifier.AppendF($"{assetIdentifier}:{subAssetIdentifier}");
Fixup(identifier);
Fixup(fullIdentifier);
_fullIdentifier = fullIdentifier;
_subassetSeperator = _fullIdentifier.IndexOf(':', 0);
}
public static StringView operator implicit(AssetIdentifier identifier) => identifier.FullIdentifier;
@@ -105,6 +105,19 @@ namespace GlitchyEngine.Content
return (T)asset;
}
/// Loads the specified asset with the given contentManager or the current applications content manager.
public static Asset GetAsset(AssetHandle handle, IContentManager contentManager = null)
{
var contentManager;
if (contentManager == null)
contentManager = Application.Instance.ContentManager;
Asset asset = contentManager.GetAsset(null, handle);
return asset;
}
public static AssetHandle ManageAsset(Asset asset, IContentManager contentManager = null)
{
+19
View File
@@ -0,0 +1,19 @@
using System;
using System.IO;
using System.Collections;
using GlitchyEngine.Math;
using GlitchyEngine.Renderer;
using System.Threading;
namespace GlitchyEngine.Content;
class SpriteLoader : IProcessedAssetLoader
{
public Result<Asset> Load(Stream dataStream)
{
AssetHandle textureHandle = Try!(dataStream.Read<AssetHandle>());
float4 textureCoordinates = Try!(dataStream.Read<float4>());
return new Sprite(textureHandle, textureCoordinates);
}
}
@@ -3,6 +3,7 @@ using System.IO;
using System.Collections;
using GlitchyEngine.Math;
using GlitchyEngine.Renderer;
using System.Threading;
namespace GlitchyEngine.Content;
@@ -73,6 +74,8 @@ class TextureLoader : IProcessedAssetLoader
result.SamplerState = samplerState;
}
//Thread.Sleep(1000);
return result;
}
+16 -1
View File
@@ -1091,7 +1091,22 @@ namespace GlitchyEngine.Renderer
public static void DrawSprite(Matrix transform, SpriteRendererComponent* spriteRenderer, uint32 entityId)
{
DrawQuad(transform, spriteRenderer.Sprite.Get() ?? s_whiteTexture, spriteRenderer.Color, spriteRenderer.UvTransform, entityId);
Asset asset = Content.GetAsset(spriteRenderer.Sprite);
Texture2D spriteTexture = null;
float4 uvTransform = spriteRenderer.UvTransform;
if (Texture2D texture = asset as Texture2D)
{
spriteTexture = texture;
}
else if (Sprite sprite = asset as Sprite)
{
spriteTexture = Content.GetAsset<Texture2D>(sprite.TextureHandle);
uvTransform = sprite.TextureCoordinates;
}
DrawQuad(transform, spriteTexture ?? s_whiteTexture, spriteRenderer.Color, uvTransform, entityId);
}
public static void DrawCircle(Matrix transform, CircleRendererComponent* spriteRenderer, uint32 entityId)
+20
View File
@@ -0,0 +1,20 @@
using GlitchyEngine.Content;
using GlitchyEngine.Math;
namespace GlitchyEngine.Renderer;
class Sprite : Asset
{
private AssetHandle _textureHandle;
private float4 _textureCoordinates;
public AssetHandle TextureHandle => _textureHandle;
public float4 TextureCoordinates => _textureCoordinates;
public this(AssetHandle textureHandle, float4 textureCoordinates)
{
_textureHandle = textureHandle;
_textureCoordinates = textureCoordinates;
}
}
@@ -45,7 +45,7 @@ namespace GlitchyEngine.World
[Component("Sprite Renderer")]
struct SpriteRendererComponent
{
public AssetHandle<Texture2D> Sprite = .Invalid;
public AssetHandle Sprite = .Invalid;
public ColorRGBA Color = .White;
public float4 UvTransform = .(0, 0, 1, 1);