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; MoonWorks.Input.Inputs Inputs;
public InputSystem(MoonWorks.Input.Inputs inputs) public InputSystem(World world, MoonWorks.Input.Inputs inputs) : base(world)
{ {
Inputs = inputs; Inputs = inputs;
} }

View File

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

View File

@ -5,9 +5,16 @@ namespace MoonWorksECSTest
{ {
public class PositionSystem : MoonTools.ECS.System 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) public override void Update(TimeSpan delta)
{ {
foreach (var entity in ReadEntities<PositionComponent>()) foreach (var entity in PositionFilter.Entities)
{ {
foreach (var inputMessage in ReadMessages<InputMessage>()) foreach (var inputMessage in ReadMessages<InputMessage>())
{ {