public void TestMillionEntitySystem() { const int size = 100_000; var gameWorld = new GameWorld(); var entities = new GameEntityHandle[size]; gameWorld.CreateEntityBulk(entities); var componentType = gameWorld.AsComponentType<IntComponent>(); for (var i = 0; i < size; i++) { gameWorld.AddComponent(entities[i], componentType); } var sw = new Stopwatch(); var lowest = TimeSpan.MaxValue; using var runner = new ThreadBatchRunner(1f); runner.StartPerformanceCriticalSection(); var query = new EntityQuery(gameWorld, new[] {componentType}); var system = new ArchetypeSystem<int>((in ReadOnlySpan<GameEntityHandle> entities, in SystemState<int> state) => { var accessor = new ComponentDataAccessor<IntComponent>(state.World); foreach (ref readonly var entity in entities) accessor[entity].Value++; }, query);
public void TestOne() { var runner = new ThreadBatchRunner(0.5f); var size = 64; var batchObjects = new __BatchTest[size * 4]; var batchIds = new BatchRequest[size * 4]; for (var i = 0; i < batchIds.Length; i += 4) { batchIds[i] = runner.Queue(batchObjects[i] = new __BatchTest(size, 1)); batchIds[i + 1] = runner.Queue(batchObjects[i + 1] = new __BatchTest(size, 2)); batchIds[i + 2] = runner.Queue(batchObjects[i + 2] = new __BatchTest(size, 3)); batchIds[i + 3] = runner.Queue(batchObjects[i + 3] = new __BatchTest(size, 4)); } foreach (var id in batchIds) { while (!runner.IsCompleted(id)) { Thread.Sleep(1); } } Assert.IsTrue(runner.IsCompleted()); foreach (var batch in batchObjects) { Assert.AreEqual(batch.Size, batch.ComputedValue); } Console.WriteLine("Runner Completed"); runner.Dispose(); }
public SimulationApplication(GlobalWorld source, Context overrideContext) : base(source, overrideContext) { // register game world since it's kinda important for the simu app, ahah Data.Context.BindExisting(gameWorld = new GameWorld()); Data.Context.BindExisting <IBatchRunner>(batchRunner = new ThreadBatchRunner(0.5f)); // we only use 50% of the cores targetFrequency = TimeSpan.FromSeconds(0.02); // 100 fps timeApp = new TimeApp(Data.Context); fts = new FixedTimeStep { TargetFrameTimeMs = (int)targetFrequency.TotalMilliseconds }; worker = new ApplicationWorker("Simulation"); }