public void Start()
        {
            TaskUtils.SetGlobalMultithreading(false);
            TreePrefabManager prefabManager = new TreePrefabManager();
            TreeClan          clan          = prefabManager.LoadTreeClan("clan1");

            _globalInstancingContainer = new GlobalGpuInstancingContainer();
            var representationContainer = new DesignBodyRepresentationContainer();
            DesignBodyInstanceBucketsContainer instanceBucketsContainer =
                new DesignBodyInstanceBucketsContainer(_globalInstancingContainer);

            var quadBillboardMesh = GameObject.CreatePrimitive(PrimitiveType.Quad).GetComponent <MeshFilter>().mesh;
            var shifter           = new TreeClanToDetailProviderShifter(new DetailProviderRepository(), quadBillboardMesh,
                                                                        representationContainer, instanceBucketsContainer);

            shifter.AddClan(clan, VegetationSpeciesEnum.Tree1A);

            _forgingContainerProxy = new ForgingVegetationSubjectInstanceContainerProxy(
                new ForgingVegetationSubjectInstanceContainer(
                    new DesignBodyPortrayalForger(
                        representationContainer,
                        instanceBucketsContainer)));

            ///// GRASSING!!!!!

            var singleGenerationArea = new Vector2(10, 10);
            var positionsProvider    = new CompositeVegetationSubjectsPositionProvider(
                new List <IVegetationSubjectsPositionsProvider>()
            {
                //CreateSamplePositionsDatabase(),
                new GrassVegetationSubjectsPositionsGenerator(
                    new GrassVegetationSubjectsPositionsGenerator.
                    GrassVegetationSubjectsPositionsGeneratorConfiguration()
                {
                    PositionsGridSize = singleGenerationArea
                })
            });

            _debugGrassGroupsGrowerUnderTest = new DebugGrassGroupsGrowerUnderTest(new DebugGrassPlanterUnderTest());
            _debugGrassGroupsGrowerUnderTest.Start(ComputeShaderContainer);

            GrassGroupsGrower    grassGroupsGrower    = _debugGrassGroupsGrowerUnderTest.Grower;
            Grass2RuntimeManager grass2RuntimeManager = new Grass2RuntimeManager(grassGroupsGrower,
                                                                                 new Grass2RuntimeManager.Grass2RuntimeManagerConfiguration()
            {
                GroupSize = singleGenerationArea
            });
            var vegetationSubjectsChangesListener = new CompositeVegetationSubjectsChangesListener(
                new List <VegetationSubjectsInstancingChangeListenerWithFilter>()
            {
                new VegetationSubjectsInstancingChangeListenerWithFilter()
                {
                    ChangeListener = new Grass2RuntimeManagerProxy(grass2RuntimeManager),
                    Filter         = (entity => entity.Detail.SpeciesEnum == VegetationSpeciesEnum.Grass2SpotMarker)
                },
                //new VegetationSubjectsInstancingChangeListenerWithFilter()
                //{
                //    ChangeListener = _forgingContainerProxy,
                //    Filter = entity => true
                //}
            });

            //////

            _runtimeManagement = new VegetationRuntimeManagement(
                positionsProvider: positionsProvider,
                vegetationSubjectsChangesListener: vegetationSubjectsChangesListener,
                visibleEntitiesContainer: new VegetationSubjectsVisibleEntitiesContainer(),
                configuration: new VegetationRuntimeManagementConfiguration()
            {
                DetailFieldsTemplate = new CenterHolesDetailFieldsTemplate(new List <DetailFieldsTemplateOneLine>()
                {
                    new DetailFieldsTemplateOneLine(VegetationDetailLevel.FULL, 0, 60),
                    new DetailFieldsTemplateOneLine(VegetationDetailLevel.REDUCED, 40, 120),
                    new DetailFieldsTemplateOneLine(VegetationDetailLevel.BILLBOARD, 100, 280),
                }),
                UpdateMinDistance = 10
            });

            _vegetationRuntimeManagementProxy = new VegetationRuntimeManagementProxy(_runtimeManagement);
            _forgingContainerProxy.StartThreading(() => { });
        }
예제 #2
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);
            }
        }