Changed Vector3Field.cs to derive from ValueControl<Vector3> and use NumberBox controls for better UI handling. Changed EditorControls.xaml to update resource paths for new controls. Changed InternalControls.xaml to simplify the resource dictionary by removing unnecessary references. Changed IComponentEditor.cs to reflect updates in the component editor's lifecycle methods. Changed project files for Ghost.Editor and Ghost.Core to include new dependencies and project references. Changed FileExtensions.cs and IInspectorService.cs to align with the new namespace structure. Changed Result.cs to enhance error handling and success checking methods. Changed TypeHandle.cs to improve type handling compatibility. Changed AssemblyInfo.cs files to include new assembly visibility attributes for better encapsulation. Added new graphics-related classes and interfaces in the Ghost.Engine project, including IGraphicsDevice and DX12GraphicsDevice. Added a new Mesh class to handle 3D mesh data and provide methods for creating geometric shapes. Added GraphicsPipeline.cs to manage the graphics rendering loop and device initialization. Added ScenePage.xaml and ScenePage.xaml.cs to create a new page for rendering scenes. Updated HierarchyPage.xaml.cs and InspectorPage.xaml.cs to use the new service locator pattern for service retrieval. Updated LandingWindow.xaml.cs and EngineEditorWindow.xaml.cs to utilize the new service locator pattern for better service access. Updated Logger.cs to enhance logging capabilities with optional stack traces and assertion logging. Updated QueryFilter.cs and QueryEnumerable.cs to use the new TypeHandle structure for improved efficiency. Updated WorldNode.cs and WorldNodeSerializer.cs to enhance serialization and management of world nodes. Updated AssetDatabase and related classes to improve asset management and metadata generation. Updated Ghost.UnitTest.csproj to include new project references and package dependencies for unit tests.
147 lines
3.9 KiB
C#
147 lines
3.9 KiB
C#
using Ghost.Entities.Components;
|
|
using Ghost.Entities.Query;
|
|
using Ghost.Entities.Systems;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace Ghost.Entities;
|
|
|
|
// TODO: Archetype system for better performance
|
|
public partial class World
|
|
{
|
|
private static List<World> s_worlds = new(4);
|
|
private static Queue<WorldID> s_freeWorldSlots = new();
|
|
|
|
public static int WorldCount => s_worlds.Count - s_freeWorldSlots.Count;
|
|
|
|
public static World Create(int entityCapacity = 16)
|
|
{
|
|
lock (s_worlds)
|
|
{
|
|
if (s_freeWorldSlots.TryDequeue(out var index))
|
|
{
|
|
s_worlds[index] = new World(index, entityCapacity);
|
|
}
|
|
else
|
|
{
|
|
if (s_worlds.Count >= WorldID.MaxValue)
|
|
{
|
|
throw new InvalidOperationException("Maximum number of worlds reached");
|
|
}
|
|
|
|
index = (WorldID)s_worlds.Count;
|
|
s_worlds.Add(new World(index, entityCapacity));
|
|
}
|
|
|
|
return s_worlds[index];
|
|
}
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static World GetWorld(int index)
|
|
{
|
|
return s_worlds[index];
|
|
}
|
|
}
|
|
|
|
public partial class World : IDisposable, IEquatable<World>
|
|
{
|
|
private readonly WorldID _id;
|
|
private readonly EntityManager _entityManager;
|
|
private readonly ComponentStorage _componentStorage;
|
|
private readonly SystemStorage _systemStorage;
|
|
|
|
internal ComponentStorage ComponentStorage => _componentStorage;
|
|
|
|
public WorldID ID => _id;
|
|
public EntityManager EntityManager => _entityManager;
|
|
public SystemStorage SystemStorage => _systemStorage;
|
|
|
|
public event Action<World, Entity, Type>? ComponentChanged;
|
|
|
|
private World(WorldID id, int entityCapacity)
|
|
{
|
|
_id = id;
|
|
_entityManager = new EntityManager(this, entityCapacity);
|
|
_componentStorage = new ComponentStorage(this);
|
|
_systemStorage = new SystemStorage(this);
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public Ref<T> GetSingleton<T>()
|
|
where T : unmanaged, IComponentData
|
|
{
|
|
ref var component = ref CollectionsMarshal.GetValueRefOrAddDefault(SingletonContainer<T>.container, _id, out _);
|
|
return new Ref<T>(ref component);
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public IEnumerable<ScriptComponent> QueryScript()
|
|
{
|
|
if (_componentStorage.ScriptComponentPool.IsInitialized)
|
|
{
|
|
return _componentStorage.ScriptComponentPool.ExecutionList!;
|
|
}
|
|
|
|
return Enumerable.Empty<ScriptComponent>();
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public void NotifyComponentChanged(Entity entity, Type type)
|
|
{
|
|
//#if GHOST_EDITOR
|
|
ComponentChanged?.Invoke(this, entity, type);
|
|
//#endif
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public void NotifyComponentChanged<T>(Entity entity)
|
|
where T : unmanaged, IComponentData
|
|
{
|
|
NotifyComponentChanged(entity, typeof(T));
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_entityManager.Dispose();
|
|
_componentStorage.Dispose();
|
|
_systemStorage.Dispose();
|
|
|
|
s_freeWorldSlots.Enqueue(_id);
|
|
}
|
|
|
|
public bool Equals(World? other)
|
|
{
|
|
if (other is null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (ReferenceEquals(this, other))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return _id == other._id;
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return _id.GetHashCode();
|
|
}
|
|
|
|
public override bool Equals(object? obj)
|
|
{
|
|
return obj is World other && Equals(other);
|
|
}
|
|
|
|
public static bool operator ==(World? left, World? right)
|
|
{
|
|
return left?.Equals(right) ?? right is null;
|
|
}
|
|
|
|
public static bool operator !=(World? left, World? right)
|
|
{
|
|
return !(left == right);
|
|
}
|
|
} |