forked from Misaki/GhostEngine
Major architectural update to graphics/material/shader system: - Introduced strongly-typed key structs (Key64/Key128) for passes, variants, and pipelines; removed legacy key types. - Implemented robust hashing and key generation utilities for efficient variant and pipeline lookup/caching. - Shader compiler now compiles/caches all keyword variants using new key system; includes handled as lists. - Switched to push constant root signature for per-draw data; updated HLSL and C# codegen accordingly. - Refactored Material, Shader, and Pass data structures for cache efficiency and variant support. - Pipeline library and PSO management now use 128-bit keys and variant-specific caching. - Replaced WorldNode with SceneNode in editor/scene graph; introduced ComponentManager for archetype/query management. - Migrated math utilities to Misaki.HighPerformance.Mathematics; updated editor controls. - Updated all HLSL and codegen for new buffer/push constant layouts and macros. - Misc: project reference cleanup, D3D12 Work Graph support, doc updates, and code modernization.
54 lines
1.8 KiB
C#
54 lines
1.8 KiB
C#
using Ghost.Editor.Core.Progress;
|
|
using Ghost.Editor.Core.Resources;
|
|
using Ghost.Editor.Core.Utilities;
|
|
using System.Text.Json;
|
|
|
|
namespace Ghost.Editor.Core.SceneGraph;
|
|
|
|
public enum OpenWorldMode
|
|
{
|
|
Single,
|
|
Additive,
|
|
AdditiveWithoutLoading
|
|
}
|
|
|
|
public static class EditorSceneManager
|
|
{
|
|
// TODO: Use guid keys instead of string paths for better performance and uniqueness
|
|
private static readonly Dictionary<string, SceneNode> s_loadedWorlds = new();
|
|
public static IEnumerable<SceneNode> LoadedWorlds => s_loadedWorlds.Values;
|
|
|
|
public static event Action<SceneNode>? OnWorldLoaded;
|
|
public static event Action<SceneNode>? OnWorldUnloaded;
|
|
|
|
public static async Task LoadSceneAsync(string worldPath)
|
|
{
|
|
if (s_loadedWorlds.ContainsKey(worldPath)
|
|
|| !File.Exists(worldPath)
|
|
|| Path.GetExtension(worldPath) != FileExtensions.SCENE_FILE_EXTENSION)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var progressService = EditorApplication.GetService<IProgressService>();
|
|
progressService.ShowIndeterminateProgress("Loading world...");
|
|
|
|
foreach (var world in s_loadedWorlds)
|
|
{
|
|
world.Value.Unload();
|
|
OnWorldUnloaded?.Invoke(world.Value);
|
|
}
|
|
|
|
await using var readStream = new FileStream(worldPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
|
var deserializedScene = await JsonSerializer.DeserializeAsync<SceneNode>(readStream, Engine.Resources.EngineResource.defaultSerializerOptions) ?? throw new Exception("Deserialization failed.");
|
|
|
|
s_loadedWorlds.Clear();
|
|
|
|
s_loadedWorlds[worldPath] = deserializedScene;
|
|
await deserializedScene.LoadAsync();
|
|
|
|
progressService.HideProgress();
|
|
OnWorldLoaded?.Invoke(deserializedScene);
|
|
}
|
|
}
|