diff options
author | chai <215380520@qq.com> | 2024-06-03 10:15:45 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2024-06-03 10:15:45 +0800 |
commit | acea7b2e728787a0d83bbf83c8c1f042d2c32e7e (patch) | |
tree | 0bfec05c1ca2d71be2c337bcd110a0421f19318b /Plugins/MonoGame.Extended/source/MonoGame.Extended.Entities/Systems | |
parent | 88febcb02bf127d961c6471d9e846c0e1315f5c3 (diff) |
+ plugins project
Diffstat (limited to 'Plugins/MonoGame.Extended/source/MonoGame.Extended.Entities/Systems')
7 files changed, 146 insertions, 0 deletions
diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Entities/Systems/DrawSystem.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Entities/Systems/DrawSystem.cs new file mode 100644 index 0000000..b9e63eb --- /dev/null +++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Entities/Systems/DrawSystem.cs @@ -0,0 +1,16 @@ +using Microsoft.Xna.Framework; + +namespace MonoGame.Extended.Entities.Systems +{ + public interface IDrawSystem : ISystem + { + void Draw(GameTime gameTime); + } + + public abstract class DrawSystem : IDrawSystem + { + public virtual void Dispose() { } + public virtual void Initialize(World world) { } + public abstract void Draw(GameTime gameTime); + } +}
\ No newline at end of file diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Entities/Systems/EntityDrawSystem.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Entities/Systems/EntityDrawSystem.cs new file mode 100644 index 0000000..5a0d6b9 --- /dev/null +++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Entities/Systems/EntityDrawSystem.cs @@ -0,0 +1,14 @@ +using Microsoft.Xna.Framework; + +namespace MonoGame.Extended.Entities.Systems +{ + public abstract class EntityDrawSystem : EntitySystem, IDrawSystem + { + protected EntityDrawSystem(AspectBuilder aspect) + : base(aspect) + { + } + + public abstract void Draw(GameTime gameTime); + } +}
\ No newline at end of file diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Entities/Systems/EntityProcessingSystem.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Entities/Systems/EntityProcessingSystem.cs new file mode 100644 index 0000000..c4d9339 --- /dev/null +++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Entities/Systems/EntityProcessingSystem.cs @@ -0,0 +1,26 @@ +using Microsoft.Xna.Framework; + +namespace MonoGame.Extended.Entities.Systems +{ + public abstract class EntityProcessingSystem : EntityUpdateSystem + { + protected EntityProcessingSystem(AspectBuilder aspectBuilder) + : base(aspectBuilder) + { + } + + public override void Update(GameTime gameTime) + { + Begin(); + + foreach (var entityId in ActiveEntities) + Process(gameTime, entityId); + + End(); + } + + public virtual void Begin() { } + public abstract void Process(GameTime gameTime, int entityId); + public virtual void End() { } + } +}
\ No newline at end of file diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Entities/Systems/EntitySystem.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Entities/Systems/EntitySystem.cs new file mode 100644 index 0000000..2c95107 --- /dev/null +++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Entities/Systems/EntitySystem.cs @@ -0,0 +1,51 @@ +using MonoGame.Extended.Collections; + +namespace MonoGame.Extended.Entities.Systems +{ + public abstract class EntitySystem : ISystem + { + protected EntitySystem(AspectBuilder aspectBuilder) + { + _aspectBuilder = aspectBuilder; + } + + public void Dispose() + { + if (_world != null) + { + _world.EntityManager.EntityAdded -= OnEntityAdded; + _world.EntityManager.EntityRemoved -= OnEntityRemoved; + } + } + + private readonly AspectBuilder _aspectBuilder; + private EntitySubscription _subscription; + + private World _world; + + protected virtual void OnEntityChanged(int entityId) { } + protected virtual void OnEntityAdded(int entityId) { } + protected virtual void OnEntityRemoved(int entityId) { } + + public Bag<int> ActiveEntities => _subscription.ActiveEntities; + + public virtual void Initialize(World world) + { + _world = world; + + var aspect = _aspectBuilder.Build(_world.ComponentManager); + _subscription = new EntitySubscription(_world.EntityManager, aspect); + _world.EntityManager.EntityAdded += OnEntityAdded; + _world.EntityManager.EntityRemoved += OnEntityRemoved; + _world.EntityManager.EntityChanged += OnEntityChanged; + + Initialize(world.ComponentManager); + } + + public abstract void Initialize(IComponentMapperService mapperService); + + protected void DestroyEntity(int entityId) => _world.DestroyEntity(entityId); + protected Entity CreateEntity() => _world.CreateEntity(); + protected Entity GetEntity(int entityId) => _world.GetEntity(entityId); + } +}
\ No newline at end of file diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Entities/Systems/EntityUpdateSystem.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Entities/Systems/EntityUpdateSystem.cs new file mode 100644 index 0000000..97a61d5 --- /dev/null +++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Entities/Systems/EntityUpdateSystem.cs @@ -0,0 +1,14 @@ +using Microsoft.Xna.Framework; + +namespace MonoGame.Extended.Entities.Systems +{ + public abstract class EntityUpdateSystem : EntitySystem, IUpdateSystem + { + protected EntityUpdateSystem(AspectBuilder aspectBuilder) + : base(aspectBuilder) + { + } + + public abstract void Update(GameTime gameTime); + } +}
\ No newline at end of file diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Entities/Systems/ISystem.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Entities/Systems/ISystem.cs new file mode 100644 index 0000000..d4511fc --- /dev/null +++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Entities/Systems/ISystem.cs @@ -0,0 +1,9 @@ +using System; + +namespace MonoGame.Extended.Entities.Systems +{ + public interface ISystem : IDisposable + { + void Initialize(World world); + } +}
\ No newline at end of file diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Entities/Systems/UpdateSystem.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Entities/Systems/UpdateSystem.cs new file mode 100644 index 0000000..e85c964 --- /dev/null +++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Entities/Systems/UpdateSystem.cs @@ -0,0 +1,16 @@ +using Microsoft.Xna.Framework; + +namespace MonoGame.Extended.Entities.Systems +{ + public interface IUpdateSystem : ISystem + { + void Update(GameTime gameTime); + } + + public abstract class UpdateSystem : IUpdateSystem + { + public virtual void Dispose() { } + public virtual void Initialize(World world) { } + public abstract void Update(GameTime gameTime); + } +}
\ No newline at end of file |