From 728109bfc6612fb3fd1b011cb235b728acbc4d57 Mon Sep 17 00:00:00 2001 From: Evan Hemsley Date: Sat, 21 Dec 2019 17:58:07 -0800 Subject: [PATCH] beginning query syntax system --- encompass-cs/Engine.cs | 12 ++++---- encompass-cs/EntitySetQuery.cs | 48 ++++++++++++++++++++++++++++++++ encompass-cs/encompass-cs.csproj | 11 ++++---- test/EngineTest.cs | 2 +- 4 files changed, 61 insertions(+), 12 deletions(-) create mode 100644 encompass-cs/EntitySetQuery.cs diff --git a/encompass-cs/Engine.cs b/encompass-cs/Engine.cs index e89ea34..cd17789 100644 --- a/encompass-cs/Engine.cs +++ b/encompass-cs/Engine.cs @@ -561,7 +561,7 @@ namespace Encompass /// The time that will elapse before time is fully dilated, in real time. /// The length of real time that time will be fully dilated. /// The time that will elapse before time is fully undilated. - public void ActivateTimeDilation(double factor, double easeInTime, double activeTime, double easeOutTime) + protected void ActivateTimeDilation(double factor, double easeInTime, double activeTime, double easeOutTime) { timeManager.ActivateTimeDilation(factor, easeInTime, activeTime, easeOutTime); } @@ -576,7 +576,7 @@ namespace Encompass /// An easing function for the easing in of time dilation. /// The length of real time that time will be fully dilated. /// The time that will elapse before time is fully undilated. - public void ActivateTimeDilation(double factor, double easeInTime, System.Func easeInFunction, double activeTime, double easeOutTime) + protected void ActivateTimeDilation(double factor, double easeInTime, System.Func easeInFunction, double activeTime, double easeOutTime) { timeManager.ActivateTimeDilation(factor, easeInTime, easeInFunction, activeTime, easeOutTime); } @@ -591,7 +591,7 @@ namespace Encompass /// The length of real time that time will be fully dilated. /// The time that will elapse before time is fully undilated. /// An easing function for the easing out of time dilation. - public void ActivateTimeDilation(double factor, double easeInTime, double activeTime, double easeOutTime, System.Func easeOutFunction) + protected void ActivateTimeDilation(double factor, double easeInTime, double activeTime, double easeOutTime, System.Func easeOutFunction) { timeManager.ActivateTimeDilation(factor, easeInTime, activeTime, easeOutTime, easeOutFunction); } @@ -607,14 +607,14 @@ namespace Encompass /// The length of real time that time will be fully dilated. /// The time that will elapse before time is fully undilated. /// An easing function for the easing out of time dilation. - public void ActivateTimeDilation(double factor, double easeInTime, System.Func easeInFunction, double activeTime, double easeOutTime, System.Func easeOutFunction) + protected void ActivateTimeDilation(double factor, double easeInTime, System.Func easeInFunction, double activeTime, double easeOutTime, System.Func easeOutFunction) { timeManager.ActivateTimeDilation(factor, easeInTime, easeInFunction, activeTime, easeOutTime, easeOutFunction); } - public IEnumerable EntitiesWithComponents(IEnumerable types) + protected EntitySetQuery QueryEntities() { - return componentManager.EntitiesWithComponents(types); + return new EntitySetQuery(componentManager); } } } diff --git a/encompass-cs/EntitySetQuery.cs b/encompass-cs/EntitySetQuery.cs new file mode 100644 index 0000000..25d5b7e --- /dev/null +++ b/encompass-cs/EntitySetQuery.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.Immutable; + +namespace Encompass +{ + public struct EntitySetQuery : IEnumerable + { + private EntitySetQuery(ComponentManager componentManager, ImmutableArray includes, ImmutableArray excludes) + { + ComponentManager = componentManager; + Includes = includes; + Excludes = excludes; + } + + internal EntitySetQuery(ComponentManager componentManager) + { + ComponentManager = componentManager; + Includes = ImmutableArray.Create(); + Excludes = ImmutableArray.Create(); + } + + private ComponentManager ComponentManager { get; } + private ImmutableArray Includes { get; } + private ImmutableArray Excludes { get; } + + public EntitySetQuery With() where TComponent : struct, IComponent + { + return new EntitySetQuery(ComponentManager, Includes.Add(typeof(TComponent)), Excludes); + } + + public EntitySetQuery Without() where TComponent : struct, IComponent + { + return new EntitySetQuery(ComponentManager, Includes, Excludes.Add(typeof(TComponent))); + } + + public IEnumerator GetEnumerator() + { + return ComponentManager.EntitiesWithComponents(Includes).GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } +} diff --git a/encompass-cs/encompass-cs.csproj b/encompass-cs/encompass-cs.csproj index be72ace..cb51bab 100644 --- a/encompass-cs/encompass-cs.csproj +++ b/encompass-cs/encompass-cs.csproj @@ -1,4 +1,4 @@ - + netstandard2.0 Encompass @@ -9,7 +9,7 @@ Moonside Games Encompass ECS https://github.com/encompass-ecs - + Evan Hemsley 2019 Encompass is an engine-agnostic Hyper ECS framework to help you code games, or other kinds of simulations. true @@ -19,10 +19,11 @@ True - + - + + - + \ No newline at end of file diff --git a/test/EngineTest.cs b/test/EngineTest.cs index 0a0464c..a82af05 100644 --- a/test/EngineTest.cs +++ b/test/EngineTest.cs @@ -1096,7 +1096,7 @@ namespace Tests { public override void Update(double dt) { - queriedEntities = EntitiesWithComponents(new Type[] { typeof(MockComponent), typeof(MockComponentB) }).ToArray(); + queriedEntities = QueryEntities().With().With().ToArray(); } }