public void Start()
        {
            var db = VegetationDatabaseFileUtils.LoadRawFromFile($@"C:\inz\dbs2\db_636481152000000000.json");

            Dictionary <VegetationSpeciesEnum, int> speciesDict = new Dictionary <VegetationSpeciesEnum, int>();
            var ranksDict = new Dictionary <VegetationLevelRank, int>();

            foreach (var entity in db)
            {
                var specie = entity.SpeciesEnum;
                if (!speciesDict.ContainsKey(specie))
                {
                    speciesDict[specie] = 1;
                }
                speciesDict[specie]++;

                var rank = entity.Rank;
                if (!ranksDict.ContainsKey(rank))
                {
                    ranksDict[rank] = 0;
                }
                ranksDict[rank]++;
            }
            Debug.Log("By species: " + StringUtils.ToString(speciesDict.Select(c => c.Key + "  " + c.Value)));
            Debug.Log("By rank: " + StringUtils.ToString(ranksDict.Select(c => c.Key + "  " + c.Value)));
        }
        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);
        }
        public void Start2()
        {
            var db = VegetationDatabaseFileUtils.LoadRawFromFile(@"C:\inz\dbs2\db_636477696000000000.json");

            var treesPerFile = 1000;

            var buffer = new List <VegetationDatabaseFileUtils.VegetationSubjectJson>();
            int i      = 0;

            foreach (var entity in db)
            {
                buffer.Add(entity);
                if (buffer.Count >= treesPerFile)
                {
                    VegetationDatabaseFileUtils.WriteRawToFile(buffer, $@"C:\inz\dbs3\db_{i}.json");
                    buffer.Clear();
                    i++;
                }
            }
        }
示例#4
0
        private void StartTreesRuntimeManagment()
        {
            var globalInstancingContainer = _initializationFields.Retrive <GlobalGpuInstancingContainer>();
            var representationContainer   = new DesignBodyRepresentationContainer();
            var instanceBucketsContainer  = new DesignBodyInstanceBucketsContainer(globalInstancingContainer);

            var quadBillboardMesh = GameObject.CreatePrimitive(PrimitiveType.Quad).GetComponent <MeshFilter>().mesh;

            IDesignBodyRepresentationInstanceCombinationProvider combinationProvider;

            if (_veConfiguration.Mode == VegetationMode.Legacy)
            {
                var gShifter        = new GTreeDetailProviderShifter(new DetailProviderRepository(), quadBillboardMesh);
                var treeFileManager = new TreeFileManager(new TreeFileManagerConfiguration()
                {
                    WritingTreeCompletedClanDirectory = _veConfiguration.TreeCompletedClanDirectiory
                });
                combinationProvider = new GDesignBodyRepresentationInstanceCombinationProvider(treeFileManager, gShifter);
            }
            else
            {
                var eVegetationShifter = new EVegetationDetailProviderShifter(
                    _veConfiguration.ShaderNames,
                    new DetailProviderRepository(), quadBillboardMesh,
                    _veConfiguration.ReferencedAssets, _materialCommonPack);
                combinationProvider = new EVegetationDesignBodyRepresentationInstanceCombinationProvider(new TreePrefabManager(), eVegetationShifter, _veConfiguration.ReferencedAssets);
            }

            foreach (var pair in _veConfiguration.ShiftingConfigurations.Where(c => _veConfiguration.SupportedVegetationSpecies.Contains(c.Key)))
            {
                var clanRepresentations = combinationProvider.CreateRepresentations(pair.Value, pair.Key);
                representationContainer.InitializeLists(clanRepresentations);
                instanceBucketsContainer.InitializeLists(clanRepresentations);
            }

            var designBodySpotUpdaterProxy = _initializationFields.Retrive <DesignBodySpotUpdaterProxy>();
            var mediatorSpotUpdater        = new ListenerCenteredMediatorDesignBodyChangesUpdater(designBodySpotUpdaterProxy);

            var rootMediator = _initializationFields.Retrive <RootMediatorSpotPositionsUpdater>();

            rootMediator.AddListener(mediatorSpotUpdater);

            var repositioner          = _veConfiguration.VegetationRepositioner;
            var forgingContainerProxy = new ForgingVegetationSubjectInstanceContainerProxy(
                new ForgingVegetationSubjectInstanceContainer(
                    new DesignBodyPortrayalForger(
                        representationContainer,
                        instanceBucketsContainer,
                        repositioner),
                    mediatorSpotUpdater//teraz napisz tak, zeby info zwrotne se spotupdatera wracalo zgodnie z multithreadingiem (szlo do innego watku!)
                    ));

            mediatorSpotUpdater.SetTargetChangesListener(new LambdaSpotPositionChangesListener(dict =>
            {
                forgingContainerProxy.AddSpotModifications(dict);
            }));

            _ultraUpdatableContainer.AddOtherThreadProxy(forgingContainerProxy);

            MyProfiler.BeginSample("Vegetation1: Loading from file");
            var baseVegetationList = VegetationDatabaseFileUtils.LoadListFromFiles(_veConfiguration.LoadingVegetationDatabaseDictionaryPath);

            MyProfiler.EndSample();

            if (_veConfiguration.GenerateTrees)
            {
                MyProfiler.BeginSample("Vegetation2: pushingToFile");
                foreach (var pair in _veConfiguration.PerRankVegetationRuntimeManagementConfigurations)
                {
                    var rank = pair.Key;
                    var managementConfiguration = pair.Value;

                    var baseRankedDb = baseVegetationList[rank];

                    var supportedSpecies = _veConfiguration.SupportedTreeSpecies;

                    var filteredEntities = baseRankedDb.Where(c => supportedSpecies.Contains(c.Detail.SpeciesEnum)).ToList();

                    var stagnantEntities    = new List <VegetationSubjectEntity>();
                    var nonStagnantEntities = new List <VegetationSubjectEntity>();

                    var nonStagnantVegetationRect = _veConfiguration.NonStagnantVegetationArea;
                    foreach (var entity in filteredEntities)
                    {
                        if (nonStagnantVegetationRect.Contains(entity.Position2D))
                        {
                            nonStagnantEntities.Add(entity);
                        }
                        else
                        {
                            stagnantEntities.Add(entity);
                        }
                    }

                    var stagnantVegetationRuntimeManagement = new StagnantVegetationRuntimeManagement(forgingContainerProxy,
                                                                                                      stagnantEntities, _veConfiguration.StagnantVegetationRuntimeManagementConfiguration);
                    var stagnantVegetationRuntimaManagementProxy = new StagnantVegetationRuntimeManagementProxy(stagnantVegetationRuntimeManagement);

                    _ultraUpdatableContainer.AddUpdatableElement(new FieldBasedUltraUpdatable()
                    {
                        StartField = () => { stagnantVegetationRuntimaManagementProxy.StartThreading(); }
                    });


                    var quadtree = new Quadtree <VegetationSubjectEntity>();
                    foreach (var entity in nonStagnantEntities)
                    {
                        quadtree.Insert(MyNetTopologySuiteUtils.ToPointEnvelope(entity.Position2D), entity);
                    }

                    var positionsProvider = new VegetationSubjectsPositionsDatabase(quadtree);

                    var runtimeManagement = new VegetationRuntimeManagement(
                        positionsProvider: positionsProvider,
                        vegetationSubjectsChangesListener: forgingContainerProxy,
                        visibleEntitiesContainer: new VegetationSubjectsVisibleEntitiesContainer(),
                        configuration: managementConfiguration);

                    var outerVegetationRuntimeManagementProxy = new VegetationRuntimeManagementProxy(runtimeManagement);

                    _ultraUpdatableContainer.AddUpdatableElement(new FieldBasedUltraUpdatable()
                    {
                        StartCameraField = (camera) =>
                        {
                            outerVegetationRuntimeManagementProxy.StartThreading();
                            var position = camera.Position;
                            outerVegetationRuntimeManagementProxy.Start(repositioner.InvMove(position));
                        },
                        UpdateCameraField = (camera) =>
                        {
                            var position = camera.Position;
                            outerVegetationRuntimeManagementProxy.AddUpdate(repositioner.InvMove(position));
                            outerVegetationRuntimeManagementProxy.SynchronicUpdate(repositioner.InvMove(position));
                        },
                    });
                }
                MyProfiler.EndSample();
            }

            if (_veConfiguration.GenerateBigBushes)
            {
                InitializeBushObjectsDb(baseVegetationList[VegetationLevelRank.Small], forgingContainerProxy);
            }
        }