forked from Misaki/GhostEngine
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:
16
Ghost.Test/Ghost.Test.csproj
Normal file
16
Ghost.Test/Ghost.Test.csproj
Normal file
@@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Ghost.Data\Ghost.Data.csproj" />
|
||||
<ProjectReference Include="..\Ghost.Engine\Ghost.Engine.csproj" />
|
||||
<ProjectReference Include="..\Ghost.Entities\Ghost.Entities.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
48
Ghost.Test/Program.cs
Normal file
48
Ghost.Test/Program.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using Ghost.Entities;
|
||||
using System.Numerics;
|
||||
|
||||
var world = new World();
|
||||
|
||||
var entity1 = world.CreateEntity();
|
||||
var entity2 = world.CreateEntity();
|
||||
var entity3 = world.CreateEntity();
|
||||
|
||||
world.AddComponent(entity1, new Transform { position = new Vector3(1, 2, 3) });
|
||||
world.AddComponent(entity1, new Mesh { index = 42 });
|
||||
world.AddComponent(entity2, new Transform { position = new Vector3(4, 5, 6) });
|
||||
world.AddComponent(entity2, new Mesh { index = 43 });
|
||||
world.AddComponent(entity3, new Transform { position = new Vector3(7, 8, 9) });
|
||||
|
||||
world.Query<Transform>((Entity entity, ref Transform transform) =>
|
||||
{
|
||||
transform.position += new Vector3(1, 1, 1);
|
||||
});
|
||||
|
||||
world.Query<Mesh>((Entity entity, ref Mesh mesh) =>
|
||||
{
|
||||
mesh.index += 1;
|
||||
});
|
||||
|
||||
world.RemoveEntity(entity2);
|
||||
var entity4 = world.CreateEntity();
|
||||
world.AddComponent(entity4, new Transform { position = new Vector3(10, 11, 12) });
|
||||
world.AddComponent(entity4, new Mesh { index = 44 });
|
||||
|
||||
world.Query<Transform, Mesh>((Entity entity, ref Transform transform, ref Mesh mesh) =>
|
||||
{
|
||||
Console.WriteLine($"Entity {entity.ID}: Transform Position = {transform.position}, Mesh Index = {mesh.index}");
|
||||
});
|
||||
|
||||
world.Dispose();
|
||||
|
||||
public struct Transform : IComponent
|
||||
{
|
||||
public Vector3 position;
|
||||
public Quaternion rotation;
|
||||
public Vector3 scale;
|
||||
}
|
||||
|
||||
public struct Mesh : IComponent
|
||||
{
|
||||
public uint index;
|
||||
}
|
||||
Reference in New Issue
Block a user