Refactor project structure and enhance functionality
Changed the project namespace from `Ghost.Editor` to `Ghost.App` across multiple files. Changed the `InternalsVisibleTo` attribute in `AssemblyInfo.cs` to include `Ghost.App`. Changed the `ProjectRepository` class to add new asynchronous methods for retrieving projects by ID, name, and metadata path. Changed the `ProjectService` class to utilize the new asynchronous project loading methods. Changed the `SceneGraph` classes to improve node management and serialization. Changed the `EntityManager` class to enhance entity management with new component handling methods. Added new test classes, `EntityTest` and `SerializationTest`, to ensure reliability in entity and serialization systems. Added the `Ghost.App` project file to establish a modular project structure. Added the `Ghost.Generator` project for automated component serialization code generation. Updated UI components to reflect the new namespace for proper functionality.
This commit is contained in:
@@ -18,8 +18,12 @@ internal interface IComponentPool : IDisposable
|
||||
get;
|
||||
}
|
||||
|
||||
public void Add(Entity entity, IComponentData component);
|
||||
public bool Remove(Entity entity);
|
||||
public bool Has(Entity entity);
|
||||
public IComponentData Get(Entity entity);
|
||||
|
||||
public IEnumerable<(Entity entity, IComponentData component)> Enumerate();
|
||||
}
|
||||
|
||||
internal interface IComponentPool<T> : IComponentPool
|
||||
@@ -56,6 +60,10 @@ internal class ComponentPool<T> : IComponentPool<T>
|
||||
_lookup.AsSpan().Fill(Entity.INVALID_ID);
|
||||
}
|
||||
|
||||
public ComponentPool() : this(16)
|
||||
{
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static EntityID GetLookupIndex(Entity entity)
|
||||
{
|
||||
@@ -68,6 +76,16 @@ internal class ComponentPool<T> : IComponentPool<T>
|
||||
return _lookup[GetLookupIndex(entity)];
|
||||
}
|
||||
|
||||
public void Add(Entity entity, IComponentData component)
|
||||
{
|
||||
if (component is not T typedComponent)
|
||||
{
|
||||
throw new ArgumentException($"Component type mismatch. Expected {typeof(T)}, but got {component.GetType()}.");
|
||||
}
|
||||
|
||||
Add(entity, typedComponent);
|
||||
}
|
||||
|
||||
public void Add(Entity entity, T component)
|
||||
{
|
||||
if (!entity.IsValid)
|
||||
@@ -117,6 +135,11 @@ internal class ComponentPool<T> : IComponentPool<T>
|
||||
return true;
|
||||
}
|
||||
|
||||
public IComponentData Get(Entity entity)
|
||||
{
|
||||
return GetRef(entity);
|
||||
}
|
||||
|
||||
public ref T GetRef(Entity entity)
|
||||
{
|
||||
if (!entity.IsValid)
|
||||
@@ -128,6 +151,17 @@ internal class ComponentPool<T> : IComponentPool<T>
|
||||
return ref _components[index].data;
|
||||
}
|
||||
|
||||
public IEnumerable<(Entity entity, IComponentData component)> Enumerate()
|
||||
{
|
||||
for (var i = 0; i < _nextId; i++)
|
||||
{
|
||||
if (_components[i].owner.IsValid)
|
||||
{
|
||||
yield return (_components[i].owner, _components[i].data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool Has(Entity entity)
|
||||
{
|
||||
if (entity.ID >= _lookup.Length)
|
||||
@@ -194,6 +228,16 @@ internal class ScriptComponentPool : IComponentPool<ScriptComponent>
|
||||
_executionList.Sort((a, b) => a.ExecutionOrder.CompareTo(b.ExecutionOrder));
|
||||
}
|
||||
|
||||
public void Add(Entity entity, IComponentData component)
|
||||
{
|
||||
if (component is not ScriptComponent scriptComponent)
|
||||
{
|
||||
throw new ArgumentException($"Component type mismatch. Expected {typeof(ScriptComponent)}, but got {component.GetType()}.");
|
||||
}
|
||||
|
||||
Add(entity, scriptComponent);
|
||||
}
|
||||
|
||||
public void Add(Entity entity, ScriptComponent component)
|
||||
{
|
||||
if (!IsInitialized)
|
||||
@@ -283,12 +327,33 @@ internal class ScriptComponentPool : IComponentPool<ScriptComponent>
|
||||
return _scriptComponents?.ContainsKey(entity) ?? false;
|
||||
}
|
||||
|
||||
public List<ScriptComponent>? Get(Entity entity)
|
||||
public IComponentData Get(Entity entity)
|
||||
{
|
||||
throw new NotSupportedException("Use GetAll instead of Get for ScriptComponentPool.");
|
||||
}
|
||||
|
||||
public IEnumerable<(Entity entity, IComponentData component)> Enumerate()
|
||||
{
|
||||
if (_scriptComponents == null)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
foreach (var kvp in _scriptComponents)
|
||||
{
|
||||
foreach (var script in kvp.Value)
|
||||
{
|
||||
yield return (kvp.Key, script);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<IComponentData> GetAll(Entity entity)
|
||||
{
|
||||
if (_scriptComponents == null
|
||||
|| !_scriptComponents.TryGetValue(entity, out var scriptList))
|
||||
{
|
||||
return null;
|
||||
return Enumerable.Empty<ScriptComponent>();
|
||||
}
|
||||
|
||||
return scriptList;
|
||||
|
||||
Reference in New Issue
Block a user