Implement core entity management features
Added `Archetype` struct with chunk management and disposal. Added `BitSet` class for managing collections of bits. Added `Class1.cs` as a placeholder for graphics functionality. Added `ComponentData` struct and `ComponentPool` class for component management. Added `ComponentRegistry` for efficient component registration. Added `EntityChangeQueue` as a placeholder for future changes. Added `Helpers.ttinclude` and `QueryRefComponent.tt` for code generation. Added `Signature` struct for managing component signatures. Added `World` struct to manage the game world and entities. Added `QueryRefComponent` delegates for querying entities. Changed `Archetype.cs` to implement `IDisposable`. Changed `AssemblyInfo.cs` to update global using directives. Changed `Chunk.cs` to introduce `ChunkCollection` for chunk management. Changed `Component.cs` to refine component management methods. Changed `Entity.cs` to improve properties and methods. Changed `Ghost.Entities.csproj` to update project properties. Changed `Program.cs` to demonstrate entity creation and querying. Changed `World.Query.cs` to facilitate querying with components.
This commit is contained in:
53
Ghost.ArchetypeEntities/Signature.cs
Normal file
53
Ghost.ArchetypeEntities/Signature.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using Misaki.HighPerformance.Unsafe.Collections;
|
||||
using Misaki.HighPerformance.Unsafe.Helpers;
|
||||
|
||||
namespace Ghost.Entities;
|
||||
|
||||
internal struct Signature : IDisposable, IEquatable<Signature>
|
||||
{
|
||||
public UnsafeArray<ComponentData> componentDatas;
|
||||
private int _hashCode;
|
||||
|
||||
public Signature(params Span<ComponentData> components)
|
||||
{
|
||||
componentDatas = new UnsafeArray<ComponentData>(components.Length, Allocator.Persistent);
|
||||
componentDatas.CopyFrom(components);
|
||||
|
||||
_hashCode = -1;
|
||||
_hashCode = GetHashCode();
|
||||
}
|
||||
|
||||
public bool Equals(Signature other)
|
||||
{
|
||||
return GetHashCode() == other.GetHashCode();
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if (obj is Signature other)
|
||||
{
|
||||
return Equals(other);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
if (_hashCode != -1)
|
||||
{
|
||||
return _hashCode;
|
||||
}
|
||||
|
||||
unchecked
|
||||
{
|
||||
_hashCode = Component.GetHashCode(componentDatas.AsSpan());
|
||||
return _hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
componentDatas.Dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user