mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-25 16:35:33 +00:00
rejigged the base systems classes and interfaces
This commit is contained in:
@@ -1,46 +1,14 @@
|
||||
using MonoGame.Extended.Collections;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace MonoGame.Extended.Entities.Systems
|
||||
{
|
||||
public abstract class EntityUpdateSystem : UpdateSystem
|
||||
public abstract class EntityUpdateSystem : EntitySystem, IUpdateSystem
|
||||
{
|
||||
protected EntityUpdateSystem(AspectBuilder aspectBuilder)
|
||||
protected EntityUpdateSystem(AspectBuilder aspectBuilder)
|
||||
: base(aspectBuilder)
|
||||
{
|
||||
_aspectBuilder = aspectBuilder;
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
if (_world != null)
|
||||
{
|
||||
_world.EntityManager.EntityAdded -= OnEntityAdded;
|
||||
_world.EntityManager.EntityRemoved -= OnEntityRemoved;
|
||||
}
|
||||
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
private readonly AspectBuilder _aspectBuilder;
|
||||
private EntitySubscription _subscription;
|
||||
|
||||
private EntityWorld _world;
|
||||
public EntityWorld World
|
||||
{
|
||||
get => _world;
|
||||
internal set
|
||||
{
|
||||
_world = value;
|
||||
_subscription = new EntitySubscription(_world.EntityManager, _aspectBuilder.Build(_world.ComponentManager));
|
||||
_world.EntityManager.EntityAdded += OnEntityAdded;
|
||||
_world.EntityManager.EntityRemoved += OnEntityRemoved;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnEntityAdded(int entityId) { }
|
||||
protected virtual void OnEntityRemoved(int entityId) { }
|
||||
|
||||
public Bag<int> ActiveEntities => _subscription.ActiveEntities;
|
||||
|
||||
public abstract void Initialize(IComponentMapperService mapperService);
|
||||
public abstract void Update(GameTime gameTime);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user