mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-06 05:01:53 +00:00
Reprocess, load and hot swap changed assets using new asset pipeline
This commit is contained in:
@@ -35,14 +35,21 @@ class AssetCache
|
||||
/// Current format version of loose asset file (.laf) file reader and writer.
|
||||
public const uint16 FormatVersion = 1;
|
||||
|
||||
private append String _directory = .() ~ delete:append _;
|
||||
private append String _directory = .();// ~ delete:append _;
|
||||
|
||||
private append Dictionary<AssetHandle, CachedAsset> _assets ~ delete:append _;
|
||||
private append Dictionary<AssetHandle, CachedAsset> _assets = .();// ~ delete:append _;
|
||||
|
||||
public StringView CacheDirectory => _directory;
|
||||
|
||||
private bool _cacheLoaded;
|
||||
|
||||
private EditorContentManager _contentManager;
|
||||
|
||||
public this(EditorContentManager contentManager)
|
||||
{
|
||||
_contentManager = contentManager;
|
||||
}
|
||||
|
||||
public ~this()
|
||||
{
|
||||
ClearCache();
|
||||
@@ -198,7 +205,7 @@ class AssetCache
|
||||
|
||||
switch (asset.Compression)
|
||||
{
|
||||
case .L4Z:
|
||||
case .LZ4:
|
||||
uint maxCompressedSize = LZ4.LZ4F_CompressFrameBound((uint)data.Length);
|
||||
|
||||
uint8[] compressedData = new uint8[maxCompressedSize];
|
||||
@@ -233,7 +240,7 @@ class AssetCache
|
||||
|
||||
Try!(writer.Write(dataToWrite));
|
||||
|
||||
// TODO: Notify content manager!
|
||||
_contentManager.QueueAssetReload(asset.Handle);
|
||||
|
||||
return .Ok;
|
||||
}
|
||||
@@ -262,7 +269,7 @@ class AssetCache
|
||||
FileStream fileStream = new FileStream();
|
||||
Try!(OpenFileStream(asset, fileStream));
|
||||
return fileStream;
|
||||
case .L4Z:
|
||||
case .LZ4:
|
||||
FileStream compressedStream = scope FileStream();
|
||||
Try!(OpenFileStream(asset, compressedStream));
|
||||
|
||||
|
||||
@@ -26,6 +26,8 @@ class AssetHierarchy
|
||||
private append String _resourcesDirectory = .();
|
||||
private append String _assetsDirectory = .();
|
||||
|
||||
private const float FileSystemDebounceSeconds = 0.5f;
|
||||
|
||||
private EditorContentManager _contentManager;
|
||||
|
||||
public TreeNode<AssetNode> RootNode => _assetRootNode;
|
||||
@@ -257,21 +259,31 @@ class AssetHierarchy
|
||||
|
||||
private bool _fileTreeUpdateRequested = false;
|
||||
|
||||
private float _fileSystemDebounce;
|
||||
|
||||
/// Invokes the the file tree update on the mainthread.
|
||||
private void DeferFileTreeUpdate()
|
||||
{
|
||||
_fileSystemDebounce = FileSystemDebounceSeconds;
|
||||
|
||||
if (!_fileTreeUpdateRequested)
|
||||
{
|
||||
_fileTreeUpdateRequested = true;
|
||||
|
||||
Application.Instance.InvokeOnMainThread(new () =>
|
||||
{
|
||||
_fileSystemDebounce -= Application.Instance.GameTime.DeltaTime;
|
||||
|
||||
if (_fileSystemDebounce > 0)
|
||||
return false;
|
||||
|
||||
UpdateFiles();
|
||||
_fileTreeUpdateRequested = false;
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Initializes the FSW for the current ContentDirectory and registers the events.
|
||||
private void SetupFileSystemWatcher()
|
||||
{
|
||||
@@ -518,7 +530,7 @@ class AssetHierarchy
|
||||
fileName.RemoveFromEnd(AssetFile.ConfigFileExtension.Length);
|
||||
|
||||
String fileNameWithContentRoot = scope .();
|
||||
Path.InternalCombine(fileNameWithContentRoot, _assetsDirectory, fileName);
|
||||
Path.Combine(fileNameWithContentRoot, _assetsDirectory, fileName);
|
||||
|
||||
var nodeResult = GetNodeFromPath(fileNameWithContentRoot);
|
||||
|
||||
@@ -535,7 +547,21 @@ class AssetHierarchy
|
||||
if (node->IsDirectory)
|
||||
return;
|
||||
|
||||
OnFileContentChanged(node.Value);
|
||||
if (!(node->AssetFile?.UseNewAssetPipeline ?? false))
|
||||
OnFileContentChanged(node.Value);
|
||||
|
||||
_fileSystemDebounce = FileSystemDebounceSeconds;
|
||||
|
||||
Application.Instance.InvokeOnMainThread(new () => {
|
||||
_fileSystemDebounce -= Application.Instance.GameTime.DeltaTime;
|
||||
if (_fileSystemDebounce > 0)
|
||||
return false;
|
||||
|
||||
node->AssetFile?.CheckForReprocessing();
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void FileRenamed(StringView oldFilePath, StringView newFilePath)
|
||||
@@ -546,7 +572,6 @@ class AssetHierarchy
|
||||
if (oldFilePath.EndsWith(AssetFile.ConfigFileExtension))
|
||||
return;
|
||||
|
||||
|
||||
String oldFileNameWithContentRoot = scope .();
|
||||
Path.InternalCombine(oldFileNameWithContentRoot, _assetsDirectory, oldFilePath);
|
||||
|
||||
@@ -560,7 +585,10 @@ class AssetHierarchy
|
||||
|
||||
if (File.Exists(oldConfigFileName) && !File.Exists(newConfigFileName))
|
||||
{
|
||||
if (File.Move(oldConfigFileName, newConfigFileName) case .Err(let value))
|
||||
// TODO: Actually Move, but it's a bit complicated to manage cases, where external programs move the original file and
|
||||
// rename an new file to the original name. So just copy the config to retain it.
|
||||
// I don't think there is a clean way to solve this.
|
||||
if (File.Copy(oldConfigFileName, newConfigFileName) case .Err(let value))
|
||||
{
|
||||
Log.EngineLogger.Error($"Failed to move file {oldConfigFileName} to {newConfigFileName}. Code: {value}");
|
||||
}
|
||||
|
||||
@@ -222,6 +222,7 @@ class TextureImporter : IAssetImporter
|
||||
}
|
||||
}
|
||||
|
||||
[BonTarget]
|
||||
enum GenerateMipMaps
|
||||
{
|
||||
No,
|
||||
@@ -717,7 +718,10 @@ class TextureLoader : IProcessedAssetLoader
|
||||
Runtime.NotImplemented();
|
||||
}
|
||||
|
||||
result.SamplerState = SamplerStateManager.GetSampler(sampler);
|
||||
using (SamplerState samplerState = SamplerStateManager.GetSampler(sampler))
|
||||
{
|
||||
result.SamplerState = samplerState;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ class TextureAssetPropertiesEditor : AssetPropertiesEditor
|
||||
|
||||
public override void ShowEditor()
|
||||
{
|
||||
return;
|
||||
|
||||
if (_textureConfig == null)
|
||||
return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user