Skip to content

Commit 283bdd5

Browse files
committed
Merge branch 'batching-reuse'
2 parents 7ad144b + fc54f1b commit 283bdd5

File tree

227 files changed

+5809
-1714
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

227 files changed

+5809
-1714
lines changed

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: 2.0.{build}
1+
version: 3.0.{build}
22
branches:
33
only:
44
- master

build/pack.bat

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
set version=1.0.0
1+
set version=3.0.0
22
dotnet pack ../src/EcsRx.MicroRx -c Release -o ../../_dist /p:version=%version%
33
dotnet pack ../src/EcsRx -c Release -o ../../_dist /p:version=%version%
4-
dotnet pack ../src/EcsRx.Systems -c Release -o ../../_dist /p:version=%version%
5-
dotnet pack ../src/EcsRx.Views -c Release -o ../../_dist /p:version=%version%
4+
dotnet pack ../src/EcsRx.Plugins.ReactiveSystems -c Release -o ../../_dist /p:version=%version%
5+
dotnet pack ../src/EcsRx.Plugins.Views -c Release -o ../../_dist /p:version=%version%
6+
dotnet pack ../src/EcsRx.Plugins.Computeds -c Release -o ../../_dist /p:version=%version%
7+
dotnet pack ../src/EcsRx.Plugins.Batching -c Release -o ../../_dist /p:version=%version%
68
dotnet pack ../src/EcsRx.Infrastructure -c Release -o ../../_dist /p:version=%version%
79
dotnet pack ../src/EcsRx.Infrastructure.Ninject -c Release -o ../../_dist /p:version=%version%
810
dotnet pack ../src/EcsRx.ReactiveData -c Release -o ../../_dist /p:version=%version%
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
11
using EcsRx.Infrastructure;
22
using EcsRx.Infrastructure.Dependencies;
33
using EcsRx.Infrastructure.Ninject;
4+
using EcsRx.Plugins.Batching;
5+
using EcsRx.Plugins.Computeds;
6+
using EcsRx.Plugins.ReactiveSystems;
7+
using EcsRx.Plugins.Views;
8+
using EcsRx.Plugins.Views.Extensions;
49

510
namespace EcsRx.Examples.Application
611
{
712
public abstract class EcsRxConsoleApplication : EcsRxApplication
813
{
914
public override IDependencyContainer Container { get; } = new NinjectDependencyContainer();
15+
16+
protected override void LoadPlugins()
17+
{
18+
RegisterPlugin(new ReactiveSystemsPlugin());
19+
RegisterPlugin(new ComputedsPlugin());
20+
RegisterPlugin(new ViewsPlugin());
21+
RegisterPlugin(new BatchPlugin());
22+
}
23+
24+
protected override void StartSystems()
25+
{
26+
this.StartAllBoundSystems();
27+
}
1028
}
1129
}

src/EcsRx.Examples/EcsRx.Examples.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<PropertyGroup>
33
<OutputType>Exe</OutputType>
44
<TargetFramework>netcoreapp2.0</TargetFramework>
5+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
6+
<LangVersion>7.3</LangVersion>
57
</PropertyGroup>
68
<ItemGroup>
79
<PackageReference Include="Ninject" Version="3.3.4" />
@@ -12,6 +14,9 @@
1214
<Project>{AD7EB200-BF3C-433B-96D2-D114DBE5B1E2}</Project>
1315
<Name>EcsRx.Infrastructure</Name>
1416
</ProjectReference>
17+
<ProjectReference Include="..\EcsRx.Plugins.Batching\EcsRx.Plugins.Batching.csproj" />
18+
<ProjectReference Include="..\EcsRx.Plugins.Computeds\EcsRx.Plugins.Computeds.csproj" />
19+
<ProjectReference Include="..\EcsRx.Plugins.Views\EcsRx.Plugins.Views.csproj" />
1520
<ProjectReference Include="..\EcsRx.ReactiveData\EcsRx.ReactiveData.csproj" />
1621
<ProjectReference Include="..\EcsRx\EcsRx.csproj" />
1722
</ItemGroup>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using EcsRx.Components.Lookups;
3+
using EcsRx.Examples.Application;
4+
using EcsRx.Examples.ExampleApps.BatchedGroupExample.Blueprints;
5+
using EcsRx.Examples.ExampleApps.BatchedGroupExample.Components;
6+
using EcsRx.Examples.ExampleApps.BatchedGroupExample.Modules;
7+
using EcsRx.Examples.ExampleApps.HelloWorldExample.Components;
8+
using EcsRx.Extensions;
9+
using EcsRx.Infrastructure.Extensions;
10+
11+
namespace EcsRx.Examples.ExampleApps.BatchedGroupExample
12+
{
13+
public class BatchedGroupExampleApplication : EcsRxConsoleApplication
14+
{
15+
private bool _quit;
16+
private int _entityCount = 2;
17+
18+
protected override void LoadModules()
19+
{
20+
base.LoadModules();
21+
Container.LoadModule<CustomComponentLookupsModule>();
22+
}
23+
24+
protected override void ApplicationStarted()
25+
{
26+
var blueprint = new MoveableBlueprint();
27+
28+
var defaultPool = EntityCollectionManager.GetCollection();
29+
30+
for (var i = 0; i < _entityCount; i++)
31+
{ defaultPool.CreateEntity(blueprint); }
32+
33+
HandleInput();
34+
}
35+
36+
private void HandleInput()
37+
{
38+
while (!_quit)
39+
{
40+
var keyPressed = Console.ReadKey();
41+
if (keyPressed.Key == ConsoleKey.Escape)
42+
{ _quit = true; }
43+
}
44+
}
45+
}
46+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using EcsRx.Blueprints;
3+
using EcsRx.Components.Lookups;
4+
using EcsRx.Entities;
5+
using EcsRx.Extensions;
6+
using EcsRx.Examples.ExampleApps.BatchedGroupExample.Components;
7+
using EcsRx.Examples.ExampleApps.BatchedGroupExample.Lookups;
8+
9+
namespace EcsRx.Examples.ExampleApps.BatchedGroupExample.Blueprints
10+
{
11+
public class MoveableBlueprint : IBlueprint
12+
{
13+
private const float MinimumMovementSpeed = 1;
14+
private const float MaximumMovementSpeed = 5;
15+
16+
private readonly Random _random = new Random();
17+
18+
public void Apply(IEntity entity)
19+
{
20+
entity.AddComponent(new NameComponent {Name = $"BatchedEntity-{entity.Id}"});
21+
entity.AddComponent<PositionComponent>(ComponentLookupTypes.PositionComponentId);
22+
23+
ref var movementSpeedComponent = ref entity.AddComponent<MovementSpeedComponent>(ComponentLookupTypes.MovementSpeedComponentId);
24+
movementSpeedComponent.Speed = (float)_random.NextDouble() * (MaximumMovementSpeed - MinimumMovementSpeed) + MinimumMovementSpeed;
25+
}
26+
}
27+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using EcsRx.Components;
2+
3+
namespace EcsRx.Examples.ExampleApps.BatchedGroupExample.Components
4+
{
5+
public struct MovementSpeedComponent : IComponent
6+
{
7+
public float Speed;
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using EcsRx.Components;
2+
3+
namespace EcsRx.Examples.ExampleApps.BatchedGroupExample.Components
4+
{
5+
public class NameComponent : IComponent
6+
{
7+
public string Name { get; set; }
8+
}
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Numerics;
2+
using EcsRx.Components;
3+
4+
namespace EcsRx.Examples.ExampleApps.BatchedGroupExample.Components
5+
{
6+
public struct PositionComponent : IComponent
7+
{
8+
public Vector3 Position;
9+
}
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace EcsRx.Examples.ExampleApps.BatchedGroupExample.Lookups
2+
{
3+
public static class ComponentLookupTypes
4+
{
5+
public static int NameComponentId = 0;
6+
public static int PositionComponentId = 1;
7+
public static int MovementSpeedComponentId = 2;
8+
}
9+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using EcsRx.Components.Lookups;
4+
using EcsRx.Examples.ExampleApps.BatchedGroupExample.Components;
5+
using EcsRx.Examples.ExampleApps.BatchedGroupExample.Lookups;
6+
using EcsRx.Infrastructure.Dependencies;
7+
using EcsRx.Infrastructure.Extensions;
8+
9+
namespace EcsRx.Examples.ExampleApps.BatchedGroupExample.Modules
10+
{
11+
public class CustomComponentLookupsModule : IDependencyModule
12+
{
13+
public void Setup(IDependencyContainer container)
14+
{
15+
container.Unbind<IComponentTypeLookup>();
16+
var explicitTypeLookups = new Dictionary<Type, int>
17+
{
18+
{typeof(NameComponent), ComponentLookupTypes.NameComponentId},
19+
{typeof(PositionComponent), ComponentLookupTypes.PositionComponentId},
20+
{typeof(MovementSpeedComponent), ComponentLookupTypes.MovementSpeedComponentId}
21+
};
22+
var explicitComponentLookup = new ComponentTypeLookup(explicitTypeLookups);
23+
container.Bind<IComponentTypeLookup>(new BindingConfiguration{ToInstance = explicitComponentLookup});
24+
}
25+
}
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Numerics;
3+
using System.Reactive.Linq;
4+
using EcsRx.Components.Database;
5+
using EcsRx.Components.Lookups;
6+
using EcsRx.Examples.ExampleApps.BatchedGroupExample.Components;
7+
using EcsRx.Plugins.Batching.Factories;
8+
using EcsRx.Plugins.Batching.Systems;
9+
using EcsRx.Threading;
10+
11+
namespace EcsRx.Examples.ExampleApps.BatchedGroupExample.Systems
12+
{
13+
public class BatchedMovementSystem : BatchedSystem<PositionComponent, MovementSpeedComponent>
14+
{
15+
public BatchedMovementSystem(IComponentDatabase componentDatabase, IComponentTypeLookup componentTypeLookup, IBatchBuilderFactory batchBuilderFactory, IThreadHandler threadHandler) : base(componentDatabase, componentTypeLookup, batchBuilderFactory, threadHandler)
16+
{}
17+
18+
protected override IObservable<bool> ReactWhen()
19+
{ return Observable.Interval(TimeSpan.FromSeconds(0.5f)).Select(x => true); }
20+
21+
protected override void Process(int entityId, ref PositionComponent positionComponent, ref MovementSpeedComponent movementSpeedComponent)
22+
{
23+
positionComponent.Position += Vector3.One * movementSpeedComponent.Speed;
24+
}
25+
}
26+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Reactive.Linq;
3+
using EcsRx.Blueprints;
4+
using EcsRx.Collections;
5+
using EcsRx.Examples.ExampleApps.BatchedGroupExample.Blueprints;
6+
using EcsRx.Groups;
7+
using EcsRx.Groups.Observable;
8+
using EcsRx.Systems;
9+
10+
namespace EcsRx.Examples.ExampleApps.BatchedGroupExample.Systems
11+
{
12+
public class SpawnerSystem : IManualSystem
13+
{
14+
private IDisposable _sub;
15+
private IBlueprint _blueprint = new MoveableBlueprint();
16+
17+
public IGroup Group { get; } = new EmptyGroup();
18+
public IEntityCollection DefaultCollection { get; }
19+
20+
public SpawnerSystem(IEntityCollectionManager collectionManager)
21+
{ DefaultCollection = collectionManager.GetCollection(); }
22+
23+
public void StartSystem(IObservableGroup observableGroup)
24+
{ _sub = Observable.Interval(TimeSpan.FromSeconds(2)).Subscribe(x => Spawn()); }
25+
26+
public void Spawn()
27+
{ DefaultCollection.CreateEntity(_blueprint); }
28+
29+
public void StopSystem(IObservableGroup observableGroup)
30+
{ _sub.Dispose(); }
31+
}
32+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.Reactive.Linq;
3+
using EcsRx.Components.Lookups;
4+
using EcsRx.Entities;
5+
using EcsRx.Examples.ExampleApps.BatchedGroupExample.Components;
6+
using EcsRx.Examples.ExampleApps.BatchedGroupExample.Lookups;
7+
using EcsRx.Extensions;
8+
using EcsRx.Groups;
9+
using EcsRx.Groups.Observable;
10+
using EcsRx.Plugins.ReactiveSystems.Systems;
11+
12+
namespace EcsRx.Examples.ExampleApps.BatchedGroupExample.Systems
13+
{
14+
public class LoggingSystem : IReactToGroupExSystem
15+
{
16+
public IGroup Group { get; } = new Group(typeof(NameComponent), typeof(PositionComponent));
17+
18+
public IObservable<IObservableGroup> ReactToGroup(IObservableGroup observableGroup)
19+
{ return Observable.Interval(TimeSpan.FromSeconds(1)).Select(x => observableGroup); }
20+
21+
public void Process(IEntity entity)
22+
{
23+
var nameComponent = entity.GetComponent<NameComponent>();
24+
var positionComponent = entity.GetComponent<PositionComponent>(ComponentLookupTypes.PositionComponentId);
25+
Console.WriteLine($"{nameComponent.Name} - {positionComponent.Position}");
26+
}
27+
28+
public void BeforeProcessing()
29+
{
30+
Console.SetCursorPosition(0,0);
31+
Console.Clear();
32+
}
33+
34+
public void AfterProcessing() {}
35+
}
36+
}

src/EcsRx.Examples/ExampleApps/ComputedGroupExample/Blueprints/CharacterBlueprint.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using EcsRx.Blueprints;
22
using EcsRx.Entities;
33
using EcsRx.Examples.ExampleApps.ComputedGroupExample.Components;
4+
using EcsRx.Extensions;
45

56
namespace EcsRx.Examples.ExampleApps.ComputedGroupExample.Blueprints
67
{

src/EcsRx.Examples/ExampleApps/ComputedGroupExample/ComputedGroupExampleApplication.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using EcsRx.Examples.ExampleApps.ComputedGroupExample.Blueprints;
44
using EcsRx.Examples.ExampleApps.ComputedGroupExample.Components;
55
using EcsRx.Examples.ExampleApps.ComputedGroupExample.ComputedGroups;
6+
using EcsRx.Examples.ExampleApps.ComputedGroupExample.Modules;
67
using EcsRx.Examples.ExampleApps.ComputedGroupExample.Systems;
78
using EcsRx.Groups;
89
using EcsRx.Infrastructure.Extensions;
@@ -13,16 +14,14 @@ public class ComputedGroupExampleApplication : EcsRxConsoleApplication
1314
{
1415
private bool _quit;
1516

16-
protected override void ApplicationStarted()
17+
protected override void LoadModules()
1718
{
18-
var namedHealthGroup = EntityCollectionManager.GetObservableGroup(new Group(typeof(HasHealthComponent), typeof(HasNameComponent)));
19-
var computedGroup = new LowestHealthComputedGroup(namedHealthGroup);
20-
var displayHealthSystem = new DisplayLowestHealthSystem(computedGroup);
21-
22-
SystemExecutor.AddSystem(displayHealthSystem);
23-
24-
this.StartAllBoundSystems();
19+
base.LoadModules();
20+
Container.LoadModule<ComputedModule>();
21+
}
2522

23+
protected override void ApplicationStarted()
24+
{
2625
var defaultPool = EntityCollectionManager.GetCollection();
2726
defaultPool.CreateEntity(new CharacterBlueprint("Bob", 200));
2827
defaultPool.CreateEntity(new CharacterBlueprint("Tom", 150));

src/EcsRx.Examples/ExampleApps/ComputedGroupExample/ComputedGroups/ILowestHealthComputedGroup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using EcsRx.Computed;
1+
using EcsRx.Plugins.Computeds.Groups;
22

33
namespace EcsRx.Examples.ExampleApps.ComputedGroupExample.ComputedGroups
44
{

src/EcsRx.Examples/ExampleApps/ComputedGroupExample/ComputedGroups/LowestHealthComputedGroup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Reactive.Linq;
5-
using EcsRx.Computed;
65
using EcsRx.Entities;
76
using EcsRx.Examples.ExampleApps.ComputedGroupExample.Extensions;
87
using EcsRx.Groups.Observable;
8+
using EcsRx.Plugins.Computeds.Groups;
99

1010
namespace EcsRx.Examples.ExampleApps.ComputedGroupExample.ComputedGroups
1111
{
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using EcsRx.Examples.ExampleApps.ComputedGroupExample.Components;
2+
using EcsRx.Examples.ExampleApps.ComputedGroupExample.ComputedGroups;
3+
using EcsRx.Groups;
4+
using EcsRx.Infrastructure.Dependencies;
5+
using EcsRx.Infrastructure.Extensions;
6+
7+
namespace EcsRx.Examples.ExampleApps.ComputedGroupExample.Modules
8+
{
9+
public class ComputedModule : IDependencyModule
10+
{
11+
public void Setup(IDependencyContainer container)
12+
{
13+
var namedHealthGroup = container.ResolveObservableGroup(new Group(typeof(HasHealthComponent), typeof(HasNameComponent)));
14+
var computedHealthGroup = new LowestHealthComputedGroup(namedHealthGroup);
15+
container.Bind<ILowestHealthComputedGroup>(x => x.ToInstance(computedHealthGroup));
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)