beginning query syntax system

pull/5/head
Evan Hemsley 2019-12-21 17:58:07 -08:00
parent 2abffd1cf9
commit 728109bfc6
4 changed files with 61 additions and 12 deletions

View File

@ -561,7 +561,7 @@ namespace Encompass
/// <param name="easeInTime">The time that will elapse before time is fully dilated, in real time.</param>
/// <param name="activeTime">The length of real time that time will be fully dilated.</param>
/// <param name="easeOutTime">The time that will elapse before time is fully undilated.</param>
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
/// <param name="easeInFunction">An easing function for the easing in of time dilation.</param>
/// <param name="activeTime">The length of real time that time will be fully dilated.</param>
/// <param name="easeOutTime">The time that will elapse before time is fully undilated.</param>
public void ActivateTimeDilation(double factor, double easeInTime, System.Func<double, double, double, double, double> easeInFunction, double activeTime, double easeOutTime)
protected void ActivateTimeDilation(double factor, double easeInTime, System.Func<double, double, double, double, double> easeInFunction, double activeTime, double easeOutTime)
{
timeManager.ActivateTimeDilation(factor, easeInTime, easeInFunction, activeTime, easeOutTime);
}
@ -591,7 +591,7 @@ namespace Encompass
/// <param name="activeTime">The length of real time that time will be fully dilated.</param>
/// <param name="easeOutTime">The time that will elapse before time is fully undilated.</param>
/// <param name="easeOutFunction">An easing function for the easing out of time dilation.</param>
public void ActivateTimeDilation(double factor, double easeInTime, double activeTime, double easeOutTime, System.Func<double, double, double, double, double> easeOutFunction)
protected void ActivateTimeDilation(double factor, double easeInTime, double activeTime, double easeOutTime, System.Func<double, double, double, double, double> easeOutFunction)
{
timeManager.ActivateTimeDilation(factor, easeInTime, activeTime, easeOutTime, easeOutFunction);
}
@ -607,14 +607,14 @@ namespace Encompass
/// <param name="activeTime">The length of real time that time will be fully dilated.</param>
/// <param name="easeOutTime">The time that will elapse before time is fully undilated.</param>
/// <param name="easeOutFunction">An easing function for the easing out of time dilation.</param>
public void ActivateTimeDilation(double factor, double easeInTime, System.Func<double, double, double, double, double> easeInFunction, double activeTime, double easeOutTime, System.Func<double, double, double, double, double> easeOutFunction)
protected void ActivateTimeDilation(double factor, double easeInTime, System.Func<double, double, double, double, double> easeInFunction, double activeTime, double easeOutTime, System.Func<double, double, double, double, double> easeOutFunction)
{
timeManager.ActivateTimeDilation(factor, easeInTime, easeInFunction, activeTime, easeOutTime, easeOutFunction);
}
public IEnumerable<Entity> EntitiesWithComponents(IEnumerable<Type> types)
protected EntitySetQuery QueryEntities()
{
return componentManager.EntitiesWithComponents(types);
return new EntitySetQuery(componentManager);
}
}
}

View File

@ -0,0 +1,48 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
namespace Encompass
{
public struct EntitySetQuery : IEnumerable<Entity>
{
private EntitySetQuery(ComponentManager componentManager, ImmutableArray<Type> includes, ImmutableArray<Type> excludes)
{
ComponentManager = componentManager;
Includes = includes;
Excludes = excludes;
}
internal EntitySetQuery(ComponentManager componentManager)
{
ComponentManager = componentManager;
Includes = ImmutableArray.Create<Type>();
Excludes = ImmutableArray.Create<Type>();
}
private ComponentManager ComponentManager { get; }
private ImmutableArray<Type> Includes { get; }
private ImmutableArray<Type> Excludes { get; }
public EntitySetQuery With<TComponent>() where TComponent : struct, IComponent
{
return new EntitySetQuery(ComponentManager, Includes.Add(typeof(TComponent)), Excludes);
}
public EntitySetQuery Without<TComponent>() where TComponent : struct, IComponent
{
return new EntitySetQuery(ComponentManager, Includes, Excludes.Add(typeof(TComponent)));
}
public IEnumerator<Entity> GetEnumerator()
{
return ComponentManager.EntitiesWithComponents(Includes).GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>Encompass</RootNamespace>
@ -24,5 +24,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="MoonTools.Core.Graph" Version="1.0.0"/>
<PackageReference Include="System.Collections.Immutable" Version="1.7.0"/>
</ItemGroup>
</Project>

View File

@ -1096,7 +1096,7 @@ namespace Tests
{
public override void Update(double dt)
{
queriedEntities = EntitiesWithComponents(new Type[] { typeof(MockComponent), typeof(MockComponentB) }).ToArray();
queriedEntities = QueryEntities().With<MockComponent>().With<MockComponentB>().ToArray();
}
}