EditorContentManager Part 1

This commit is contained in:
Simon Lübeß
2023-01-01 16:53:45 +01:00
parent dffd43a36f
commit c389a77274
29 changed files with 3774 additions and 81 deletions
+85 -5
View File
@@ -1,6 +1,8 @@
using System;
using System.IO;
using xxHash;
using System.Collections;
using Bon;
namespace GlitchyEngine.Content
{
@@ -22,17 +24,95 @@ namespace GlitchyEngine.Content
_hash = xxHash.ComputeHash(id);
}
}
[BonTarget, BonPolyRegister]
abstract class AssetLoaderConfig
{
[BonIgnore]
protected bool _changed;
public bool Changed => _changed;
protected bool SetIfChanged<T>(ref T field, T value)
{
if (field == value)
return false;
field = value;
_changed = true;
return true;
}
}
interface IAssetLoader
{
static List<StringView> FileExtensions { get; }
AssetLoaderConfig GetDefaultConfig();
/// Loads the asset from the given data stream with the specified config.
/// @param file The stream containing the asset.
/// @param config The configuration which specifies the settings used to load the asset.
/// @returns The loaded asset.
IRefCounted LoadAsset(Stream file, AssetLoaderConfig config);
}
static
{
/// Loads the specified asset with the given contentManager or the current applications content manager.
public static T LoadAsset<T>(StringView assetIdentifier, IContentManager contentManager = null) where T : IRefCounted
{
var contentManager;
if (contentManager == null)
contentManager = Application.Get().ContentManager;
Object o = contentManager.LoadAsset(assetIdentifier);
Log.EngineLogger.AssertDebug(o is T);
return (T)o;
}
}
interface IContentManager
{
void GetFilePath(String outFilename, String filename);
/// Loads the given asset.
IRefCounted LoadAsset(StringView assetIdentifier);
Stream GetFile(String filename);
/// Returns a data stream for the given asset.
Stream GetStream(StringView assetIdentifier);
void RegisterAssetLoader<T>() where T : new, class, IAssetLoader;
void SetAsDefaultAssetLoader<T>(params StringView[] fileExtensions) where T : IAssetLoader;
//void GetFilePath(String outFilename, String filename);
//Stream GetFile(String filename);
}
class ContentManager : IContentManager
class RuntimeContentManager : IContentManager
{
private String _contentRoot;
public IRefCounted LoadAsset(StringView identifier)
{
Runtime.NotImplemented();
}
public Stream GetStream(StringView assetIdentifier)
{
Runtime.NotImplemented();
}
public void RegisterAssetLoader<T>() where T : IAssetLoader where T : class where T : new
{
Runtime.NotImplemented();
}
public void SetAsDefaultAssetLoader<T>(params StringView[] fileExtensions) where T : IAssetLoader
{
Runtime.NotImplemented();
}
/*private String _contentRoot;
[AllowAppend]
public this(String contentRoot)
@@ -65,6 +145,6 @@ namespace GlitchyEngine.Content
}
return stream;
}
}*/
}
}