Ejemplo n.º 1
0
        private void CreateGrass2IntensityDb()
        {
            HabitatToGrassIntensityMapGenerator habitatToGrassIntensityMapGenerator =
                new HabitatToGrassIntensityMapGenerator(
                    _initializationFields.Retrive <ComputeShaderContainerGameObject>(),
                    _initializationFields.Retrive <UnityThreadComputeShaderExecutorObject>(),
                    _initializationFields.Retrive <CommonExecutorUTProxy>(),
                    _veConfiguration.HabitatToGrassIntensityMapGeneratorConfiguration);

            HabitatMapDbProxy habitatDbProxy = _initializationFields.Retrive <HabitatMapDbProxy>();

            var pathProximityTextureDbProxy = _initializationFields.Retrive <PathProximityTextureDbProxy>();

            var mapsGenerator = new Grass2IntensityMapGenerator(
                habitatToGrassIntensityMapGenerator,
                new HabitatTexturesGenerator(habitatDbProxy,
                                             _veConfiguration.HabitatTexturesGeneratorConfiguration,
                                             _initializationFields.Retrive <TextureConcieverUTProxy>()),
                _veConfiguration.Grass2IntensityMapGeneratorConfiguration,
                pathProximityTextureDbProxy);

            var db = new SpatialDb <List <Grass2TypeWithIntensity> >(mapsGenerator,
                                                                     _veConfiguration.Grass2IntensityDbConfiguration
                                                                     );

            var databaseProxy = new Grass2IntensityDbProxy(db);

            _ultraUpdatableContainer.AddOtherThreadProxy(databaseProxy);
            _ultraUpdatableContainer.AddOtherThreadProxy(habitatDbProxy);

            _initializationFields.SetField(databaseProxy);
        }
Ejemplo n.º 2
0
 public HabitatTexturesGenerator(HabitatMapDbProxy habitatDbProxy,
                                 HabitatTexturesGeneratorConfiguration configuration,
                                 TextureConcieverUTProxy textureConciever)
 {
     _habitatDbProxy   = habitatDbProxy;
     _configuration    = configuration;
     _textureConciever = textureConciever;
 }
        public void Compute()
        {
            CommonExecutorUTProxy commonExecutor    = new CommonExecutorUTProxy();
            HabitatMapDbProxy     habitatMapDbProxy = _gameInitializationFields.Retrive <HabitatMapDbProxy>();

            ComputeShaderContainerGameObject computeShaderContainer =
                _gameInitializationFields.Retrive <ComputeShaderContainerGameObject>();
            UnityThreadComputeShaderExecutorObject shaderExecutorObject =
                _gameInitializationFields.Retrive <UnityThreadComputeShaderExecutorObject>();

            var templatesDict          = _vegetationConfiguration.FloraDomainCreationTemplates;
            var floraConfiguration     = _vegetationConfiguration.FloraConfiguration;
            var spatialDbConfiguration = _vegetationConfiguration.FloraDomainSpatialDbConfiguration;

            var dbsDict = new Dictionary <HabitatAndZoneType, ISpatialDb <FloraDomainIntensityArea> >();

            foreach (var pair in templatesDict)
            {
                IStoredPartsGenerator <FloraDomainIntensityArea> partsGenerator =
                    new FloraDomainIntensityGenerator(pair.Value, computeShaderContainer, shaderExecutorObject,
                                                      commonExecutor, 1f, floraConfiguration);
                var spatialDb =
                    new CacheingSpatialDb <FloraDomainIntensityArea>(
                        new SpatialDb <FloraDomainIntensityArea>(partsGenerator, spatialDbConfiguration),
                        spatialDbConfiguration);
                dbsDict[pair.Key] = spatialDb;
            }
            var floraDomainDb = new FloraDomainDbProxy(dbsDict);


            var biomeProvidersGenerators = _vegetationConfiguration.BiomeConfigurationsDict(floraDomainDb)
                                           .ToDictionary(c => c.Key, c => new BiomeProvidersFromHabitatGenerator(habitatMapDbProxy, c.Value));

            var genralPlacer = new GeneralMultiDistrictPlacer(
                _vegetationConfiguration.GeneralMultiDistrictPlacerConfiguration,
                _gameInitializationFields.Retrive <TerrainShapeDbProxy>(),
                commonExecutor,
                biomeProvidersGenerators);

            var database = genralPlacer.Generate(
                _vegetationConfiguration.GenerationArea,
                _vegetationConfiguration.RankDependentSpeciesCharacteristics(),
                _vegetationConfiguration.GenerationCenter);

            var vegetationOnRoadRemover = new VegetationOnRoadRemover(
                _gameInitializationFields.Retrive <RoadDatabaseProxy>(),
                _vegetationConfiguration.VegetationOnRoadRemoverConfiguration
                );

            var newDb = vegetationOnRoadRemover.RemoveCollidingTrees(database, _vegetationConfiguration.GenerationArea);

            //CreateDebugObjects(newDb.Subjects.ToDictionary(c => c.Key, c => c.Value.QueryAll()));


            VegetationDatabaseFileUtils.WriteToFileNonOverwrite(
                _pathsConfiguration.LoadingVegetationDatabaseDictionaryPath, newDb);
        }
Ejemplo n.º 4
0
        public void Load()
        {
            if (_habitatMap == null)
            {
                var fileManager = new HabitatMapFileManager();
                _habitatMap = fileManager.LoadHabitatMap(_filesConfiguration.HabitatDbFilePath);
            }
            var proxy = new HabitatMapDbProxy(new HabitatMapDb(new HabitatMapDb.HabitatMapDbInitializationInfo()
            {
                Map = _habitatMap
            }));

            _gameInitializationFields.SetField(proxy);
        }
Ejemplo n.º 5
0
        public void InitializeMonoliticRing2RegionsDatabase()
        {
            var habitatMap = new HabitatMapDbProxy(new HabitatMapDb(_configuration.HabitatDbInitializationInfo));

            _updatableContainer.AddOtherThreadProxy(habitatMap);

            _gameInitializationFields.SetField(habitatMap);

            var regionsDbGenerator = new Ring2RegionsDbGenerator(habitatMap,
                                                                 _configuration.Ring2RegionsDbGeneratorConfiguration(new Ring2AreaDistanceDatabase()),
                                                                 _gameInitializationFields.Retrive <RoadDatabaseProxy>());
            var regionsDatabase = regionsDbGenerator.GenerateDatabaseAsync(_configuration.Ring2GenerationArea).Result;

            _gameInitializationFields.SetField(regionsDatabase);
        }
Ejemplo n.º 6
0
        public void InitializeComplexRing2RegionsDatabase(Dictionary <int, Ring2RegionsDbGeneratorConfiguration> configurations)
        {
            var habitatMap = new HabitatMapDbProxy(new HabitatMapDb(_configuration.HabitatDbInitializationInfo));

            _updatableContainer.AddOtherThreadProxy(habitatMap);

            _gameInitializationFields.SetField(habitatMap);

            var monoliticDbs = configurations.ToDictionary(pair => pair.Key, pair =>
            {
                var regionsDbGenerator = new Ring2RegionsDbGenerator(habitatMap,
                                                                     pair.Value,
                                                                     _gameInitializationFields.Retrive <RoadDatabaseProxy>());
                return(regionsDbGenerator.GenerateDatabaseAsync(_configuration.Ring2GenerationArea).Result);
            });
            var regionsDatabase = new ComplexRing2RegionsDatabase(monoliticDbs);

            _gameInitializationFields.SetField(regionsDatabase);
        }
Ejemplo n.º 7
0
        public void Start()
        {
            TaskUtils.SetGlobalMultithreading(false);

            var queryingArea = new MyRectangle(526 * 90, 582 * 90, 90, 90);


            HabitatToGrassIntensityMapGenerator habitatToGrassIntensityMapGenerator =
                new HabitatToGrassIntensityMapGenerator(ComputeShaderContainer,
                                                        new UnityThreadComputeShaderExecutorObject(), new CommonExecutorUTProxy(),
                                                        new HabitatToGrassIntensityMapGenerator.HabitatToGrassIntensityMapGeneratorConfiguration()
            {
                GrassTypeToSourceHabitats = new Dictionary <GrassType, List <HabitatType> >()
                {
                    { GrassType.Debug1, new List <HabitatType>()
                      {
                          HabitatType.Forest
                      } },
                    { GrassType.Debug2, new List <HabitatType>()
                      {
                          HabitatType.Meadow, HabitatType.Fell
                      } },
                },
                OutputPixelsPerUnit = 1
            });

            HabitatMapDbProxy habitatDbProxy = new HabitatMapDbProxy(new HabitatMapDb(
                                                                         new HabitatMapDb.HabitatMapDbInitializationInfo()
            {
                RootSerializationPath = @"C:\inz\habitating2\"
            }));

            var mapsGenerator = new Grass2IntensityMapGenerator(
                habitatToGrassIntensityMapGenerator,
                new HabitatTexturesGenerator(habitatDbProxy,
                                             new HabitatTexturesGenerator.HabitatTexturesGeneratorConfiguration()
            {
                HabitatMargin       = 5,
                HabitatSamplingUnit = 3
            }, new TextureConcieverUTProxy()),
                new Grass2IntensityMapGenerator.Grass2IntensityMapGeneratorConfiguration()
            {
                HabitatSamplingUnit = 3
            }, null);

            var db = new SpatialDb <List <Grass2TypeWithIntensity> >(mapsGenerator,
                                                                     new SpatialDbConfiguration()
            {
                QueryingCellSize = new Vector2(90, 90)
            });

            var retrivedMap = db.ProvidePartsAt(queryingArea).Result.CoordedPart.Part;

            Debug.Log("Ret: " + retrivedMap.Count);

            retrivedMap.Select(c => new Grass2TypeWithIntensity()
            {
                GrassType       = c.GrassType,
                IntensityFigure = c.IntensityFigure
            }).Select((c, i) =>
            {
                HabitatToGrassIntensityMapGeneratorDebugObject.CreateDebugObject(c, i);
                return(0);
            }).ToList();
        }