From 4436d14f9a4259c03d86d1de5987cae0ecd4ef18 Mon Sep 17 00:00:00 2001 From: Ullrich Praetz Date: Fri, 9 Aug 2024 11:47:38 +0200 Subject: [PATCH] Tests - add BoostedQuery() example --- src/Tests/ECS/Examples/HelloWorld.cs | 4 ++-- src/Tests/ECS/Examples/Optimization.cs | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/Tests/ECS/Examples/HelloWorld.cs b/src/Tests/ECS/Examples/HelloWorld.cs index 822b8a09..e5a6be59 100644 --- a/src/Tests/ECS/Examples/HelloWorld.cs +++ b/src/Tests/ECS/Examples/HelloWorld.cs @@ -5,13 +5,13 @@ // ReSharper disable UnusedParameter.Local // ReSharper disable CheckNamespace namespace Tests.Examples { + +public struct Velocity : IComponent { public Vector3 value; } // See: https://github.com/friflo/Friflo.Engine.ECS#-examples public static class HelloWorldExample { -public struct Velocity : IComponent { public Vector3 value; } - [Test] public static void HelloWorld() { diff --git a/src/Tests/ECS/Examples/Optimization.cs b/src/Tests/ECS/Examples/Optimization.cs index f72eb6e3..2b0ff05f 100644 --- a/src/Tests/ECS/Examples/Optimization.cs +++ b/src/Tests/ECS/Examples/Optimization.cs @@ -1,13 +1,14 @@ using System; +using System.Numerics; using Friflo.Engine.ECS; using NUnit.Framework; using static Tests.Examples.General; #if !UNITY_5_3_OR_NEWER using System.Runtime.Intrinsics; - #endif +// ReSharper disable ArrangeTypeMemberModifiers // ReSharper disable UnusedVariable // ReSharper disable UnusedParameter.Local // ReSharper disable CheckNamespace @@ -17,6 +18,24 @@ namespace Tests.Examples { public static class Optimization { +[Test] +public static void BoostedQuery() +{ + var store = new EntityStore(); + for (int n = 0; n < 100; n++) { + store.CreateEntity(new Position(n, 0, 0), new Velocity{ value = new Vector3(0, n, 0)}); + } + var query = store.Query(); + query.Each(new MoveEach()); // requires https://www.nuget.org/packages/Friflo.Engine.ECS.Boost +} + +struct MoveEach : IEach +{ + public void Execute(ref Position position, ref Velocity velocity) { + position.value += velocity.value; + } +} + [Test] public static void EnumerateQueryChunks() {