public void UpdateConwaysNoLoopedWorld(int width, int height, int batchCount)
        {
            NativeArray <int> cellsArray = default;

            Measure.Method(() =>
            {
                var job = new UpdateAreaCells_ShiftNeighborsCountJob
                {
                    CellStates = cellsArray
                }.Schedule(cellsArray.Length, batchCount);
                var statesInt4 = cellsArray.Reinterpret <int4>(UnsafeUtility.SizeOf <int>());
                job            = new SetHorizontalSidesInAreasJob
                {
                    Width      = width / 4,
                    CellStates = statesInt4
                }.Schedule(height, 64, job);
                job = new SetVerticalSidesInAreasJob
                {
                    Width      = width / 4,
                    CellStates = statesInt4
                }.Schedule(width / 4, 64, job);
                job.Complete();
            })
            .SetUp(() =>
            {
                cellsArray = new NativeArray <int>(width * height, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
            })
            .CleanUp(() =>
            {
                cellsArray.Dispose();
            })
            .Run();
        }
示例#2
0
 protected override void OnUpdate()
 {
     Dependency.Complete();
     Entities.WithAll <IsConwaysSimulation>()
     .ForEach((Entity e, GameOfLifeTexture texture, in WorldSize world) =>
     {
         var areas       = texture.Value.GetRawTextureData <int>();
         int cycles      = 0;
         long totalTicks = 0;
         var settings    = HasComponent <AdvancedSimulationSettings>(e)
             ? GetComponent <AdvancedSimulationSettings>(e)
             : new AdvancedSimulationSettings {
             MaxCyclesPerFrame = 1
         };
         while (cycles < settings.MaxCyclesPerFrame)
         {
             cycles++;
             _timer.Start();
             var job = new UpdateAreaCells_ManualShiftJob
             {
                 CellStates = areas
             }.Schedule(areas.Length, 256, Dependency);
             var statesInt4   = areas.Reinterpret <int4>(UnsafeUtility.SizeOf <int>());
             var widthInArea4 = world.Size.x / 16;
             job = new SetHorizontalSidesInAreasJob
             {
                 Width      = widthInArea4,
                 CellStates = statesInt4
             }.Schedule(world.Size.y / 3, 32, job);
             Dependency = new SetVerticalSidesInAreasJob
             {
                 Width      = widthInArea4,
                 CellStates = statesInt4
             }.Schedule(widthInArea4, 32, job);
             Dependency.Complete();
             totalTicks += _timer.ElapsedTicks;
             _timer.Reset();
             if (settings.LimitationMs > 0 && totalTicks > settings.LimitationMs * 10000)
             {
                 break;
             }
         }
         if (HasComponent <SimulationStatistic>(e))
         {
             var stats  = GetComponent <SimulationStatistic>(e);
             stats.Age += cycles;
             stats.SimulationTimeMs += totalTicks / 10000f;
             SetComponent(e, stats);
         }
     }).WithoutBurst().Run();
 }