Esempio n. 1
0
        public void InitializeGlobalInstancingContainer()
        {
            var globalInstancingContainer = new GlobalGpuInstancingContainer();

            _gameInitializationFields.SetField(globalInstancingContainer);

            var updatableElement = new FieldBasedUltraUpdatable()
            {
                StartCameraField  = (currentCamera) => { globalInstancingContainer.StartThread(); },
                UpdateCameraField = (currentCamera) =>
                {
                    globalInstancingContainer.DrawFrame();
                    globalInstancingContainer.FinishUpdateBatch();
                }
            };

            _updatableContainer.AddUpdatableElement(updatableElement);
        }
        public void Start()
        {
            InitializeWelding();
            /// /// VISIBILITY TEXTURE
            var visibilityTextureSideLength = 16;
            var visibilityTexture           = new Texture2D(visibilityTextureSideLength, visibilityTextureSideLength,
                                                            TextureFormat.RFloat, false);

            visibilityTexture.filterMode = FilterMode.Point;

            var visibilityTextureProcessorProxy =
                new Ring1VisibilityTextureProcessorUTProxy(new Ring1VisibilityTextureProcessor(visibilityTexture));

            _ultraUpdatableContainer.Add(visibilityTextureProcessorProxy);

            var visibilityTextureChangeGrabber = new Ring1VisibilityTextureChangeGrabber();

            var terrainParentGameObject = new GameObject("TerrainParent");

            terrainParentGameObject.transform.localPosition = new Vector3(0, 0, 0);

            var globalSideLength      = _gRingConfiguration.Ring1GlobalSideLength;
            var globalSize            = new Vector2(globalSideLength, globalSideLength);
            var unityCoordsCalculator = new UnityCoordsCalculator(globalSize);
            var orderGrabber          = new Ring1PaintingOrderGrabber();

            var painterProxy = new RingTerrainPainterUTProxy(new RingTerrainPainter(_gRingConfiguration.MakeTerrainVisible));

            _ultraUpdatableContainer.Add(painterProxy);

            painterProxy.Update();

            var mainRespondingProxy = new Ring1NodeEventMainRespondingProxy(new Ring1NodeEventMainResponder());

            _ultraUpdatableContainer.AddOtherThreadProxy(new OtherThreadProxyWithPerPostAction()
            {
                OtherThreadProxy = mainRespondingProxy,
                PerPostAction    =
                    () =>
                {
                    var delta = visibilityTextureChangeGrabber.RetriveVisibilityChanges();

                    if (delta.AnyChange)
                    {
                        var visibilityTextureChagnes =
                            visibilityTextureChangeGrabber.RetriveVisibilityChanges();
                        visibilityTextureProcessorProxy.AddOrder(visibilityTextureChagnes);
                    }

                    if (orderGrabber.IsAnyOrder)
                    {
                        painterProxy.AddOrder(orderGrabber.RetriveOrderAndClear());
                    }
                }
            });

            var stainTerrainResourceCreatorUtProxy =
                new StainTerrainResourceCreatorUTProxy(new StainTerrainResourceCreator());

            _ultraUpdatableContainer.Add(stainTerrainResourceCreatorUtProxy);

            var stainTerrainServiceProxy = new StainTerrainServiceProxy(
                new StainTerrainService(
                    new FromFileStainTerrainResourceGenerator(_configuration.StainTerrainServicePath, _gameInitializationFields.Retrive <CommonExecutorUTProxy>()),
                    //new ComputationStainTerrainResourceGenerator(
                    //    new StainTerrainResourceComposer(
                    //        _stainTerrainResourceCreatorUtProxy
                    //        ),
                    //    new StainTerrainArrayMelder(),
                    //    new DummyStainTerrainArrayFromBiomesGenerator(
                    //        new DebugBiomeContainerGenerator().GenerateBiomesContainer(new BiomesContainerConfiguration()),
                    //        new StainTerrainArrayFromBiomesGeneratorConfiguration()
                    //    )),
                    _gRingConfiguration.Ring1GenerationArea));

            _ultraUpdatableContainer.AddOtherThreadProxy(stainTerrainServiceProxy);

            var ring1Tree      = new Ring1Tree(_gRingConfiguration.Ring1TreeConfiguration);
            var ring1TreeProxy = new Ring1TreeProxy(ring1Tree);

            _gameInitializationFields.Retrive <LateAssignBox <Ring1TreeProxy> >().Set(ring1TreeProxy);
            _ultraUpdatableContainer.AddOtherThreadProxy(ring1TreeProxy);

            var terrainShapeDbInitialization = new FETerrainShapeDbInitialization(_ultraUpdatableContainer,
                                                                                  _gameInitializationFields, _configuration, new FilePathsConfiguration());

            terrainShapeDbInitialization.Start();


            var gRing0NodeTerrainCreator = new GRing0NodeTerrainCreator(
                orderGrabber,
                terrainParentGameObject,
                _gameInitializationFields.Retrive <MeshGeneratorUTProxy>(),
                _gameInitializationFields.Retrive <ITerrainShapeDb>(),
                unityCoordsCalculator,
                _gameInitializationFields.Retrive <GRingSpotUpdater>(),
                _gameInitializationFields.Retrive <HeightArrayWeldingPack>(),
                _gRingConfiguration.GroundShapeProviderConfiguration,
                _gRingConfiguration.TerrainMeshProviderConfiguration);

            var gRing1NodeTerrainCreator = new GRing1NodeTerrainCreator(
                orderGrabber,
                terrainParentGameObject,
                _gameInitializationFields.Retrive <MeshGeneratorUTProxy>(),
                _gameInitializationFields.Retrive <ITerrainShapeDb>(),
                stainTerrainServiceProxy,
                unityCoordsCalculator,
                _gameInitializationFields.Retrive <GRingSpotUpdater>(),
                _gameInitializationFields.Retrive <HeightArrayWeldingPack>(),
                _gRingConfiguration.GroundShapeProviderConfiguration,
                _gRingConfiguration.TerrainMeshProviderConfiguration);

            var gRing2PatchesCreatorProxy = _gameInitializationFields.Retrive <GRing2PatchesCreatorProxy>();

            var gRing2NodeTerrainCreator = new GRing2NodeTerrainCreator(
                orderGrabber,
                terrainParentGameObject,
                _gameInitializationFields.Retrive <MeshGeneratorUTProxy>(),
                _gameInitializationFields.Retrive <ITerrainShapeDb>(),
                unityCoordsCalculator,
                gRing2PatchesCreatorProxy,
                _gameInitializationFields.Retrive <GRingSpotUpdater>(),
                _gameInitializationFields.Retrive <HeightArrayWeldingPack>(),
                _gRingConfiguration.GroundShapeProviderConfiguration,
                _gRingConfiguration.TerrainMeshProviderConfiguration);

            var gDebugNodeTerrainCreator = new GDebugLodNodeTerrainCreator(
                orderGrabber,
                terrainParentGameObject,
                unityCoordsCalculator,
                _gameInitializationFields.Retrive <MeshGeneratorUTProxy>()
                );

            var gDebugTerrainedNodeTerrainCreator = new GDebugTerrainedLodNodeTerrainCreator(
                orderGrabber,
                terrainParentGameObject,
                unityCoordsCalculator,
                _gameInitializationFields.Retrive <MeshGeneratorUTProxy>(),
                _gameInitializationFields.Retrive <ITerrainShapeDb>(),
                _gRingConfiguration.GroundShapeProviderConfiguration,
                _gameInitializationFields.Retrive <GRingSpotUpdater>()
                );


            var gStampedRing2NodeTerrainCreator = new GStampedRing2NodeTerrainCreator(
                orderGrabber,
                terrainParentGameObject,
                _gameInitializationFields.Retrive <MeshGeneratorUTProxy>(),
                _gameInitializationFields.Retrive <ITerrainShapeDb>(),
                unityCoordsCalculator,
                gRing2PatchesCreatorProxy,
                _gameInitializationFields.Retrive <Ring2PatchStamplingOverseerFinalizer>(),
                _gameInitializationFields.Retrive <GRingSpotUpdater>(),
                _gameInitializationFields.Retrive <HeightArrayWeldingPack>(),
                _gRingConfiguration.GroundShapeProviderConfiguration,
                _gRingConfiguration.TerrainMeshProviderConfiguration);

            var gCompositeRing2NodeTerrainCreator = new GCompositeRing2NodeTerrainCreator(
                orderGrabber,
                terrainParentGameObject,
                _gameInitializationFields.Retrive <MeshGeneratorUTProxy>(),
                _gameInitializationFields.Retrive <ITerrainShapeDb>(),
                unityCoordsCalculator,
                gRing2PatchesCreatorProxy,
                _gameInitializationFields.Retrive <GRingSpotUpdater>(),
                _gameInitializationFields.Retrive <HeightArrayWeldingPack>(),
                _gameInitializationFields.Retrive <Ring2PatchStamplingOverseerFinalizer>(),
                _gRingConfiguration.GroundShapeProviderConfiguration,
                _gRingConfiguration.TerrainMeshProviderConfiguration);

            //var gCompositeRing2NodeTerrainCreator = new GCompositeRing2NodeTerrainCreator(
            //    new List<INewGRingListenersCreator>()
            //    {
            //        gRing2NodeTerrainCreator,
            //        gStampedRing2NodeTerrainCreator,
            //    });

            var subCreator = new SupremeGRingNodeTerrainCreator(new List <NewListenersCreatorWithLimitation>()
            {
                //new NewListenersCreatorWithLimitation()
                //{
                //    Creator = gDebugTerrainedNodeTerrainCreator,
                //    MaximumLod = new FlatLod(14),
                //    //PositionLimiter = new NewListenersCreatorPositionLimiter(new Vector2(0.5f, 0.6f), 0.025f)
                //},

                //new NewListenersCreatorWithLimitation()
                //{
                //    Creator = gRing0NodeTerrainCreator,
                //    MaximumLod = new FlatLod(5),
                //},

                new NewListenersCreatorWithLimitation()
                {
                    Creator    = new GVoidNodeTerrainCreator(),
                    MaximumLod = new FlatLod(5),
                    //IsFallthroughCreator = true
                },

                new NewListenersCreatorWithLimitation()
                {
                    Creator    = gRing1NodeTerrainCreator,
                    MaximumLod = new FlatLod(10)
                },

                new NewListenersCreatorWithLimitation()
                {
                    Creator    = gRing2NodeTerrainCreator,
                    MaximumLod = new FlatLod(14)
                },

                new NewListenersCreatorWithLimitation()
                {
                    Creator    = gStampedRing2NodeTerrainCreator,
                    MaximumLod = new FlatLod(13)
                },

                new NewListenersCreatorWithLimitation()
                {
                    Creator    = gCompositeRing2NodeTerrainCreator,
                    MaximumLod = new FlatLod(14)
                }

                //new NewListenersCreatorWithLimitation()
                //{
                //    Creator = gDebugNodeTerrainCreator,
                //    MaximumLod = new FlatLod(11)
                //},
            });

            var eventCollector = new Ring1NodeEventCollector(
                new DynamicFlatLodGRingNodeTerrainCreator(subCreator,
                                                          new FlatLodCalculator(unityCoordsCalculator, _gRingConfiguration.FlatLodConfiguration)));

            _ultraUpdatableContainer.AddOtherThreadProxy(
                new OtherThreadProxyWithPerPostAction()
            {
                OtherThreadProxy = ring1TreeProxy,
                PerPostAction    = () =>
                {
                    if (eventCollector.Any)
                    {
                        mainRespondingProxy.AddOrder(eventCollector.RetriveOrderAndClear());
                    }
                }
            }
                );
            var repositioner = _gameInitializationFields.Retrive <Repositioner>();

            _ultraUpdatableContainer.AddUpdatableElement(new FieldBasedUltraUpdatable()
            {
                UpdateCameraField = (camera) =>
                {
                    if (_configuration.UpdateRingTree)
                    {
                        ring1TreeProxy.UpdateCamera(FovData.FromCamera(camera, repositioner));
                    }
                }
            });

            _ultraUpdatableContainer.AddUpdatableElement(new FieldBasedUltraUpdatable()
            {
                StartCameraField = (camera) =>
                {
                    ring1TreeProxy.CreateHeightmap(
                        new Ring1Tree.RootNodeCreationParameters()
                    {
                        InitialCameraPosition = repositioner.InvMove(camera.Position),
                        NodeListener          = eventCollector,
                        PrecisionDistances    = _gRingConfiguration.QuadLodPrecisionDistances,
                        UnityCoordsCalculator = unityCoordsCalculator
                    });
                }
            });
        }
Esempio n. 3
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);
            }
        }