Beispiel #1
0
        static void SetupScenario(BaseDB.ConfigContainer cfg, IEnumerable <Entity> entities)
        {
            BaseDB.PutConfigAsync(cfg).Wait();
            //Simulation.Configure(new ShardID(), cfg, true);
            //if (DB.HasAdminAccess)
            InconsistencyCoverage.CommonResolution = (int)Math.Ceiling(1f / cfg.r);
            var clearTask = BaseDB.ClearSimulationDataAsync();

            SDSFactory[,,] grid = new SDSFactory[cfg.extent.X, cfg.extent.Y, cfg.extent.Z];
            cfg.extent.Cover(at =>
            {
                grid[at.X, at.Y, at.Z] = new SDSFactory(at, null /*new SimulationContext(false)*/, cfg.extent);
            }
                             );
            var gridBox         = IntBox.FromMinAndMax(Int3.Zero, cfg.extent, Bool3.False);
            var simulationSpace = Box.FromMinAndMax(Vec3.Zero, new Vec3(cfg.extent), Bool3.True);

            foreach (var e in entities)
            {
                if (!simulationSpace.Contains(e.ID.Position))
                {
                    throw new Exception("Scenario entity " + e + " is located outside simulation space");
                }
                var cell = gridBox.Clamp(e.ID.Position.FloorInt3);
                grid[cell.X, cell.Y, cell.Z].Include(e);
            }

            clearTask.Wait();
            Task[] tasks = new Task[cfg.extent.Product];
            int    idx   = 0;

            foreach (var factory in grid)
            {
                tasks[idx++] = DB.PutAsync(factory.Finish(), true);
            }

            Task.WaitAll(tasks);
        }