Skip to content

Commit

Permalink
renamed IRunner, IRunnable and DefaultRunner to more explicit IParall…
Browse files Browse the repository at this point in the history
…elRunner, IParallelRunnable and DefaultParallelRunner
  • Loading branch information
Doraku committed Dec 15, 2019
1 parent 6a4748f commit 4dd7334
Show file tree
Hide file tree
Showing 21 changed files with 94 additions and 94 deletions.
8 changes: 4 additions & 4 deletions source/DefaultEcs.Benchmark/DefaultEcs/System.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private struct Speed

private sealed class TestSystem : AEntitySystem<float>
{
public TestSystem(World world, IRunner runner)
public TestSystem(World world, IParallelRunner runner)
: base(world.GetEntities().With<Position>().With<Speed>().AsSet(), runner)
{ }

Expand All @@ -52,7 +52,7 @@ protected override void Update(float state, in Entity entity)

private sealed class Test2System : AEntitySystem<float>
{
public Test2System(World world, IRunner runner)
public Test2System(World world, IParallelRunner runner)
: base(world.GetEntities().With<Position>().With<Speed>().AsSet(), runner)
{ }

Expand Down Expand Up @@ -102,7 +102,7 @@ public void Dispose()
}

private World _world;
private DefaultRunner _runner;
private DefaultParallelRunner _runner;
private ISystem<float> _systemSingle;
private ISystem<float> _system;
private ISystem<float> _system2Single;
Expand All @@ -116,7 +116,7 @@ public void Dispose()
public void Setup()
{
_world = new World(EntityCount);
_runner = new DefaultRunner(Environment.ProcessorCount);
_runner = new DefaultParallelRunner(Environment.ProcessorCount);
_systemSingle = new TestSystem(_world, null);
_system = new TestSystem(_world, _runner);
_system2Single = new Test2System(_world, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private struct DefaultPosition

private sealed class DefaultEcsSystem : AEntitySystem<float>
{
public DefaultEcsSystem(DefaultWorld world, IRunner runner)
public DefaultEcsSystem(DefaultWorld world, IParallelRunner runner)
: base(world.GetEntities().With<DefaultSpeed>().With<DefaultPosition>().AsSet(), runner)
{ }

Expand Down Expand Up @@ -84,7 +84,7 @@ protected override void Execute(EntitasEntity entity)
private DefaultWorld _defaultWorld;
private DefaultEntitySet _defaultEntitySet;
private DefaultEcsSystem _defaultSystem;
private DefaultRunner _defaultRunner;
private DefaultParallelRunner _defaultRunner;
private DefaultEcsSystem _defaultMultiSystem;

private EntitiasWorld _entitasWorld;
Expand All @@ -100,7 +100,7 @@ public void Setup()
_defaultWorld = new DefaultWorld(EntityCount);
_defaultEntitySet = _defaultWorld.GetEntities().With<DefaultSpeed>().With<DefaultPosition>().AsSet();
_defaultSystem = new DefaultEcsSystem(_defaultWorld);
_defaultRunner = new DefaultRunner(Environment.ProcessorCount);
_defaultRunner = new DefaultParallelRunner(Environment.ProcessorCount);
_defaultMultiSystem = new DefaultEcsSystem(_defaultWorld, _defaultRunner);

_entitasWorld = new Context<EntitasEntity>(2, () => new EntitasEntity());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private struct DefaultComponent

private sealed class DefaultEcsSystem : AEntitySystem<int>
{
public DefaultEcsSystem(DefaultWorld world, IRunner runner)
public DefaultEcsSystem(DefaultWorld world, IParallelRunner runner)
: base(world.GetEntities().With<DefaultComponent>().AsSet(), runner)
{ }

Expand All @@ -40,7 +40,7 @@ protected override void Update(int state, ReadOnlySpan<DefaultEntity> entities)

private sealed class DefaultEcsComponentSystem : AComponentSystem<int, DefaultComponent>
{
public DefaultEcsComponentSystem(DefaultWorld world, IRunner runner)
public DefaultEcsComponentSystem(DefaultWorld world, IParallelRunner runner)
: base(world, runner)
{ }

Expand Down Expand Up @@ -80,7 +80,7 @@ protected override void Execute(EntitasEntity entity)
private DefaultWorld _defaultWorld;
private DefaultEntitySet _defaultEntitySet;
private DefaultEcsSystem _defaultSystem;
private DefaultRunner _defaultRunner;
private DefaultParallelRunner _defaultRunner;
private DefaultEcsSystem _defaultMultiSystem;
private DefaultEcsComponentSystem _defaultComponentSystem;
private DefaultEcsComponentSystem _defaultComponentMultiSystem;
Expand All @@ -98,7 +98,7 @@ public void Setup()
_defaultWorld = new DefaultWorld(EntityCount);
_defaultEntitySet = _defaultWorld.GetEntities().With<DefaultComponent>().AsSet();
_defaultSystem = new DefaultEcsSystem(_defaultWorld);
_defaultRunner = new DefaultRunner(Environment.ProcessorCount);
_defaultRunner = new DefaultParallelRunner(Environment.ProcessorCount);
_defaultMultiSystem = new DefaultEcsSystem(_defaultWorld, _defaultRunner);
_defaultComponentSystem = new DefaultEcsComponentSystem(_defaultWorld);
_defaultComponentMultiSystem = new DefaultEcsComponentSystem(_defaultWorld, _defaultRunner);
Expand Down
4 changes: 2 additions & 2 deletions source/DefaultEcs.Test/System/AComponentSystemTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public System(World world)
: base(world)
{ }

public System(World world, IRunner runner)
public System(World world, IParallelRunner runner)
: base(world, runner)
{ }

Expand Down Expand Up @@ -86,7 +86,7 @@ public void Update_Should_not_call_update_When_disabled()
[Fact]
public void Update_with_runner_Should_call_update()
{
using DefaultRunner runner = new DefaultRunner(2);
using DefaultParallelRunner runner = new DefaultParallelRunner(2);
using World world = new World(3);

Entity entity1 = world.CreateEntity();
Expand Down
6 changes: 3 additions & 3 deletions source/DefaultEcs.Test/System/AEntitySystemTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public System(World world)
: base(world)
{ }

public System(EntitySet set, IRunner runner)
public System(EntitySet set, IParallelRunner runner)
: base(set, runner)
{ }

public System(World world, IRunner runner)
public System(World world, IParallelRunner runner)
: base(world, runner)
{ }

Expand Down Expand Up @@ -184,7 +184,7 @@ public void Update_Should_not_call_update_When_disabled()
[Fact]
public void Update_with_runner_Should_call_update()
{
using DefaultRunner runner = new DefaultRunner(2);
using DefaultParallelRunner runner = new DefaultParallelRunner(2);
using World world = new World(4);

Entity entity1 = world.CreateEntity();
Expand Down
10 changes: 5 additions & 5 deletions source/DefaultEcs.Test/System/ParallelSystemTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void ParallelSystem_Should_throw_When_systems_is_null()
{
ISystem<float>[] systems = null;

Check.ThatCode(() => new ParallelSystem<float>(Substitute.For<IRunner>(), systems)).Throws<ArgumentNullException>();
Check.ThatCode(() => new ParallelSystem<float>(Substitute.For<IParallelRunner>(), systems)).Throws<ArgumentNullException>();
}

[Fact]
Expand All @@ -34,7 +34,7 @@ public void Update_Should_call_update_on_all_systems()

using (ISystem<int> system = new ParallelSystem<int>(
new ActionSystem<int>(_ => mainDone = true),
new DefaultRunner(1),
new DefaultParallelRunner(1),
new ActionSystem<int>(_ => done1 = true),
new ActionSystem<int>(_ => done2 = true)))
{
Expand All @@ -54,7 +54,7 @@ public void Update_with_runner_Should_call_update_on_all_systems()
bool done3 = false;
bool done4 = false;

using (DefaultRunner runner = new DefaultRunner(2))
using (DefaultParallelRunner runner = new DefaultParallelRunner(2))
using (ISystem<int> system = new ParallelSystem<int>(
runner,
new ActionSystem<int>(_ => done1 = true),
Expand All @@ -79,7 +79,7 @@ public void Update_with_runner_Should_not_call_update_on_any_systems_When_disabl
bool done3 = false;
bool done4 = false;

using (DefaultRunner runner = new DefaultRunner(2))
using (DefaultParallelRunner runner = new DefaultParallelRunner(2))
using (ISystem<int> system = new ParallelSystem<int>(
runner,
new ActionSystem<int>(_ => done1 = true),
Expand Down Expand Up @@ -109,7 +109,7 @@ public void Dispose_Should_call_Dispose_on_all_systems()
s1.When(s => s.Dispose()).Do(_ => done1 = true);
s2.When(s => s.Dispose()).Do(_ => done2 = true);

ISystem<int> system = new ParallelSystem<int>(s1, Substitute.For<IRunner>(), s2);
ISystem<int> system = new ParallelSystem<int>(s1, Substitute.For<IParallelRunner>(), s2);

system.Dispose();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

namespace DefaultEcs.Test.Threading
{
public sealed class DefaultRunnerTest
public sealed class DefaultParallelRunnerTest
{
#region Tests

[Fact]
public void DefaultRunner_Should_throw_When_degreeOfParallelism_is_inferior_to_one()
{
Check.ThatCode(() => new DefaultRunner(-1)).Throws<ArgumentException>();
Check.ThatCode(() => new DefaultParallelRunner(-1)).Throws<ArgumentException>();
}

#endregion
Expand Down
4 changes: 2 additions & 2 deletions source/DefaultEcs/DefaultEcs.Release.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
<Version>0.13.0</Version>
<PackageReleaseNotes>
breaking change:
removed SystemRunner type, use DefaultEcs.Threading.DefaultRunner instead
removed SystemRunner type, use DefaultEcs.Threading.DefaultParallelRunner instead
removed ASystem type
refactored EntitySetBuilder to a more fluent syntax, Build changed to AsSet, *Either&lt;T1, T2&gt;() replaced by *Either&lt;T1&gt;().Or&lt;T2&gt;()

added World.GetDisabledEntities method to create EntitySet for disabled entities
added DisabledAttribute to auto construct EntitySet of disabled entities for AEntitySystem
added EntitySet.Contains method to check for an Entity inclusion
added IRunner to allow custom implementation to process AEntitySystem, AComponentSystem and ParallelSystem in parallel
added IParallelRunner to allow custom implementation to process AEntitySystem, AComponentSystem and ParallelSystem in parallel
added Entity.World property

fixed EntityCommandRecorder SetSameAs and Dispose command size
Expand Down
14 changes: 7 additions & 7 deletions source/DefaultEcs/System/AComponentSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public abstract class AComponentSystem<TState, TComponent> : ISystem<TState>
{
#region Types

private class Runnable : IRunnable
private class Runnable : IParallelRunnable
{
private readonly AComponentSystem<TState, TComponent> _system;

Expand All @@ -38,27 +38,27 @@ public void Run(int index, int maxIndex)

#region Fields

private readonly IRunner _runner;
private readonly IParallelRunner _runner;
private readonly Runnable _runnable;
private readonly ComponentPool<TComponent> _component;

#endregion

#region Initialisation

private AComponentSystem(IRunner runner)
private AComponentSystem(IParallelRunner runner)
{
_runner = runner ?? DefaultRunner.Default;
_runner = runner ?? DefaultParallelRunner.Default;
_runnable = new Runnable(this);
}

/// <summary>
/// Initialise a new instance of the <see cref="AComponentSystem{TState, TComponent}"/> class with the given <see cref="World"/> and <see cref="IRunner"/>.
/// Initialise a new instance of the <see cref="AComponentSystem{TState, TComponent}"/> class with the given <see cref="World"/> and <see cref="IParallelRunner"/>.
/// </summary>
/// <param name="world">The <see cref="World"/> on which to process the update.</param>
/// <param name="runner">The <see cref="IRunner"/> used to process the update in parallel if not null.</param>
/// <param name="runner">The <see cref="IParallelRunner"/> used to process the update in parallel if not null.</param>
/// <exception cref="ArgumentNullException"><paramref name="world"/> is null.</exception>
protected AComponentSystem(World world, IRunner runner)
protected AComponentSystem(World world, IParallelRunner runner)
: this(runner)
{
_component = ComponentManager<TComponent>.GetOrCreate(world?.WorldId ?? throw new ArgumentNullException(nameof(world)));
Expand Down
18 changes: 9 additions & 9 deletions source/DefaultEcs/System/AEntitySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public abstract class AEntitySystem<T> : ISystem<T>
{
#region Types

private class Runnable : IRunnable
private class Runnable : IParallelRunnable
{
private readonly AEntitySystem<T> _system;

Expand All @@ -36,7 +36,7 @@ public void Run(int index, int maxIndex)

#region Fields

private readonly IRunner _runner;
private readonly IParallelRunner _runner;
private readonly Runnable _runnable;
private readonly EntitySet _set;

Expand All @@ -62,19 +62,19 @@ public event ActionIn<Entity> EntityRemoved

#region Initialisation

private AEntitySystem(IRunner runner)
private AEntitySystem(IParallelRunner runner)
{
_runner = runner ?? DefaultRunner.Default;
_runner = runner ?? DefaultParallelRunner.Default;
_runnable = new Runnable(this);
}

/// <summary>
/// Initialise a new instance of the <see cref="AEntitySystem{T}"/> class with the given <see cref="EntitySet"/> and <see cref="IRunner"/>.
/// Initialise a new instance of the <see cref="AEntitySystem{T}"/> class with the given <see cref="EntitySet"/> and <see cref="IParallelRunner"/>.
/// </summary>
/// <param name="set">The <see cref="EntitySet"/> on which to process the update.</param>
/// <param name="runner">The <see cref="IRunner"/> used to process the update in parallel if not null.</param>
/// <param name="runner">The <see cref="IParallelRunner"/> used to process the update in parallel if not null.</param>
/// <exception cref="ArgumentNullException"><paramref name="set"/> is null.</exception>
protected AEntitySystem(EntitySet set, IRunner runner)
protected AEntitySystem(EntitySet set, IParallelRunner runner)
: this(runner)
{
_set = set ?? throw new ArgumentNullException(nameof(set));
Expand All @@ -94,9 +94,9 @@ protected AEntitySystem(EntitySet set)
/// To create the inner <see cref="EntitySet"/>, <see cref="WithAttribute"/> and <see cref="WithoutAttribute"/> attributes will be used.
/// </summary>
/// <param name="world">The <see cref="World"/> from which to get the <see cref="Entity"/> instances to process the update.</param>
/// <param name="runner">The <see cref="IRunner"/> used to process the update in parallel if not null.</param>
/// <param name="runner">The <see cref="IParallelRunner"/> used to process the update in parallel if not null.</param>
/// <exception cref="ArgumentNullException"><paramref name="world"/> is null.</exception>
protected AEntitySystem(World world, IRunner runner)
protected AEntitySystem(World world, IParallelRunner runner)
: this(runner)
{
_set = EntitySetFactory.Create(GetType())(world ?? throw new ArgumentNullException(nameof(world)));
Expand Down
22 changes: 11 additions & 11 deletions source/DefaultEcs/System/ParallelSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public sealed class ParallelSystem<T> : ISystem<T>
{
#region Types

private class Runnable : IRunnable
private class Runnable : IParallelRunnable
{
private readonly ParallelSystem<T> _system;

Expand Down Expand Up @@ -44,7 +44,7 @@ public void Run(int index, int maxIndex)

#region Fields

private readonly IRunner _runner;
private readonly IParallelRunner _runner;
private readonly Runnable _runnable;
private readonly ISystem<T> _mainSystem;
private readonly ISystem<T>[] _systems;
Expand All @@ -53,7 +53,7 @@ public void Run(int index, int maxIndex)

#region Initialisation

private ParallelSystem(IRunner runner)
private ParallelSystem(IParallelRunner runner)
{
_runner = runner ?? throw new ArgumentNullException(nameof(runner));
_runnable = new Runnable(this);
Expand All @@ -63,11 +63,11 @@ private ParallelSystem(IRunner runner)
/// Initialises a new instance of the <see cref="ParallelSystem{T}"/> class.
/// </summary>
/// <param name="mainSystem">The <see cref="ISystem{T}"/> instance to be updated on the calling thread.</param>
/// <param name="runner">The <see cref="IRunner"/> used to process the update in parallel if not null.</param>
/// <param name="runner">The <see cref="IParallelRunner"/> used to process the update in parallel if not null.</param>
/// <param name="systems">The <see cref="ISystem{T}"/> instances.</param>
/// <exception cref="ArgumentNullException"><paramref name="runner"/> is null.</exception>
/// <exception cref="ArgumentNullException"><paramref name="systems"/> is null.</exception>
public ParallelSystem(ISystem<T> mainSystem, IRunner runner, IEnumerable<ISystem<T>> systems)
public ParallelSystem(ISystem<T> mainSystem, IParallelRunner runner, IEnumerable<ISystem<T>> systems)
: this(runner)
{
_mainSystem = mainSystem;
Expand All @@ -78,33 +78,33 @@ public ParallelSystem(ISystem<T> mainSystem, IRunner runner, IEnumerable<ISystem
/// Initialises a new instance of the <see cref="ParallelSystem{T}"/> class.
/// </summary>
/// <param name="mainSystem">The <see cref="ISystem{T}"/> instance to be updated on the calling thread.</param>
/// <param name="runner">The <see cref="IRunner"/> used to process the update in parallel if not null.</param>
/// <param name="runner">The <see cref="IParallelRunner"/> used to process the update in parallel if not null.</param>
/// <param name="systems">The <see cref="ISystem{T}"/> instances.</param>
/// <exception cref="ArgumentNullException"><paramref name="runner"/> is null.</exception>
/// <exception cref="ArgumentNullException"><paramref name="systems"/> is null.</exception>
public ParallelSystem(ISystem<T> mainSystem, IRunner runner, params ISystem<T>[] systems)
public ParallelSystem(ISystem<T> mainSystem, IParallelRunner runner, params ISystem<T>[] systems)
: this(mainSystem, runner, systems as IEnumerable<ISystem<T>>)
{ }

/// <summary>
/// Initialises a new instance of the <see cref="ParallelSystem{T}"/> class.
/// </summary>
/// <param name="runner">The <see cref="IRunner"/> used to process the update in parallel if not null.</param>
/// <param name="runner">The <see cref="IParallelRunner"/> used to process the update in parallel if not null.</param>
/// <param name="systems">The <see cref="ISystem{T}"/> instances.</param>
/// <exception cref="ArgumentNullException"><paramref name="runner"/> is null.</exception>
/// <exception cref="ArgumentNullException"><paramref name="systems"/> is null.</exception>
public ParallelSystem(IRunner runner, IEnumerable<ISystem<T>> systems)
public ParallelSystem(IParallelRunner runner, IEnumerable<ISystem<T>> systems)
: this(null, runner, systems)
{ }

/// <summary>
/// Initialises a new instance of the <see cref="ParallelSystem{T}"/> class.
/// </summary>
/// <param name="runner">The <see cref="IRunner"/> used to process the update in parallel if not null.</param>
/// <param name="runner">The <see cref="IParallelRunner"/> used to process the update in parallel if not null.</param>
/// <param name="systems">The <see cref="ISystem{T}"/> instances.</param>
/// <exception cref="ArgumentNullException"><paramref name="runner"/> is null.</exception>
/// <exception cref="ArgumentNullException"><paramref name="systems"/> is null.</exception>
public ParallelSystem(IRunner runner, params ISystem<T>[] systems)
public ParallelSystem(IParallelRunner runner, params ISystem<T>[] systems)
: this(runner, systems as IEnumerable<ISystem<T>>)
{ }

Expand Down
Loading

0 comments on commit 4dd7334

Please sign in to comment.