testing filter

main
cosmonaut 2022-03-07 11:46:51 -08:00
parent 5b67c82c71
commit 223a6b3147
4 changed files with 15 additions and 11 deletions

@ -1 +1 @@
Subproject commit 229a0651bdaac5918b4550866cdca9122bf0d78b
Subproject commit 1d7db58d437ce370a31e2ae11a17350cec2089f7

View File

@ -7,7 +7,7 @@ namespace MoonWorksECSTest
{
MoonWorks.Input.Inputs Inputs;
public InputSystem(MoonWorks.Input.Inputs inputs)
public InputSystem(World world, MoonWorks.Input.Inputs inputs) : base(world)
{
Inputs = inputs;
}

View File

@ -6,7 +6,7 @@ namespace MoonWorksECSTest
{
class MoonWorksECSTestGame : Game
{
World world;
World world = new World();
public MoonWorksECSTestGame(
WindowCreateInfo windowCreateInfo,
@ -14,14 +14,11 @@ namespace MoonWorksECSTest
bool debugMode
) : base(windowCreateInfo, presentMode, 60, debugMode)
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddSystem(new InputSystem(Inputs));
worldBuilder.AddSystem(new PositionSystem());
new InputSystem(world, Inputs);
new PositionSystem(world);
var entity = worldBuilder.CreateEntity();
worldBuilder.Set(entity, new PositionComponent { Position = new MoonWorks.Math.Vector2(200, 200) });
world = worldBuilder.Build();
var entity = world.CreateEntity();
world.Set(entity, new PositionComponent { Position = new MoonWorks.Math.Vector2(200, 200) });
}
protected override void Update(System.TimeSpan dt)

View File

@ -5,9 +5,16 @@ namespace MoonWorksECSTest
{
public class PositionSystem : MoonTools.ECS.System
{
Filter PositionFilter;
public PositionSystem(World world) : base(world)
{
PositionFilter = FilterBuilder.Include<PositionComponent>().Build();
}
public override void Update(TimeSpan delta)
{
foreach (var entity in ReadEntities<PositionComponent>())
foreach (var entity in PositionFilter.Entities)
{
foreach (var inputMessage in ReadMessages<InputMessage>())
{