Пример #1
0
        private FEInitializingHelper InitializeETerrain(ETerrainHeightPyramidFacadeStartConfiguration startConfiguration)
        {
            startConfiguration.CommonConfiguration.YScale = _gameInitializationFields.Retrive <HeightDenormalizer>().DenormalizationMultiplier;
            startConfiguration.HeightPyramidLevels        = new List <HeightPyramidLevel>()
            {
                HeightPyramidLevel.Top, HeightPyramidLevel.Mid, HeightPyramidLevel.Bottom
            };

            var buffersManager = new ETerrainHeightBuffersManager();

            _eTerrainHeightPyramidFacade = new ETerrainHeightPyramidFacade(buffersManager,
                                                                           _gameInitializationFields.Retrive <MeshGeneratorUTProxy>(),
                                                                           _gameInitializationFields.Retrive <UTTextureRendererProxy>(), startConfiguration);

            var perLevelTemplates = _eTerrainHeightPyramidFacade.GenerateLevelTemplates();
            var levels            = startConfiguration.PerLevelConfigurations.Keys.Where(c => startConfiguration.HeightPyramidLevels.Contains(c));

            buffersManager.InitializeBuffers(levels.ToDictionary(c => c, c => new EPyramidShaderBuffersGeneratorPerRingInput()
            {
                FloorTextureResolution = startConfiguration.CommonConfiguration.FloorTextureSize.X, //TODO i use only X, - works only for squares
                HeightMergeRanges      = perLevelTemplates[c].PerRingTemplates.ToDictionary(k => k.Key, k => k.Value.HeightMergeRange),
                CeilSliceWorldSize     =
                    startConfiguration.PerLevelConfigurations[c].FloorTextureWorldSize.x, // TODO works only for square pyramids - i use width
                RingUvRanges = startConfiguration.CommonConfiguration.RingsUvRange
            }), startConfiguration.CommonConfiguration.MaxLevelsCount, startConfiguration.CommonConfiguration.MaxRingsPerLevelCount);

            var dbInitialization =
                new FETerrainShapeDbInitialization(_ultraUpdatableContainer, _gameInitializationFields, _feConfiguration, new FilePathsConfiguration());

            dbInitialization.Start();

            var initializingHelper = new FEInitializingHelper(_gameInitializationFields, _ultraUpdatableContainer, _feConfiguration);

            initializingHelper.InitializeGlobalInstancingContainer();


            _eTerrainHeightPyramidFacade.Start(perLevelTemplates,
                                               new Dictionary <EGroundTextureType, OneGroundTypeLevelTextureEntitiesGenerator>
            {
                [EGroundTextureType.HeightMap] = ETerrainInitializationHelper.CreateHeightTextureEntitiesGenerator(
                    startConfiguration, _gameInitializationFields, _ultraUpdatableContainer, _heightmapListenersContainer),
                [EGroundTextureType.SurfaceTexture] = ETerrainInitializationHelper.CreateSurfaceTextureEntitiesGenerator(
                    _feConfiguration, startConfiguration, _gameInitializationFields, _ultraUpdatableContainer)
            }
                                               );
            return(initializingHelper);
        }
Пример #2
0
        private ETerrainHeightPyramidFacade StartTerrainThings(MeshGeneratorUTProxy meshGeneratorUtProxy, UTTextureRendererProxy textureRendererProxy,
                                                               ComputeShaderContainerGameObject containerGameObject, List <HeightPyramidLevel> startConfigurationHeightPyramidLevels)
        {
            var startConfiguration = ETerrainHeightPyramidFacadeStartConfiguration.DefaultConfiguration;

            //startConfiguration.HeightPyramidLevels = new List<HeightPyramidLevel>() {HeightPyramidLevel.Top};
            startConfiguration.HeightPyramidLevels = startConfigurationHeightPyramidLevels;

            ETerrainHeightBuffersManager buffersManager = new ETerrainHeightBuffersManager();
            var eTerrainHeightPyramidFacade             = new ETerrainHeightPyramidFacade(buffersManager, meshGeneratorUtProxy, textureRendererProxy, startConfiguration);

            var perLevelTemplates = eTerrainHeightPyramidFacade.GenerateLevelTemplates();
            var levels            = startConfiguration.HeightPyramidLevels;

            buffersManager.InitializeBuffers(levels.ToDictionary(c => c, c => new EPyramidShaderBuffersGeneratorPerRingInput()
            {
                FloorTextureResolution = startConfiguration.CommonConfiguration.FloorTextureSize.X,            //TODO i use only X, - works only for squares
                HeightMergeRanges      = perLevelTemplates[c].PerRingTemplates.ToDictionary(k => k.Key, k => k.Value.HeightMergeRange),
                CeilSliceWorldSize     = startConfiguration.PerLevelConfigurations[c].FloorTextureWorldSize.x, // TODO works only for square pyramids - i use width
                RingUvRanges           = startConfiguration.CommonConfiguration.RingsUvRange
            }), startConfiguration.CommonConfiguration.MaxLevelsCount, startConfiguration.CommonConfiguration.MaxRingsPerLevelCount);


            var configuration = new FEConfiguration(new FilePathsConfiguration());
            GlobalServicesProfileInfo servicesProfileInfo = new GlobalServicesProfileInfo();
            var ultraUpdatableContainer = new UltraUpdatableContainer(
                configuration.SchedulerConfiguration,
                servicesProfileInfo,
                configuration.UpdatableContainerConfiguration);
            var updatableContainer            = new UpdatableContainer();
            var intensityPatternPixelsPerUnit = new Dictionary <int, float>()
            {
                { 1, 1 }
            };
            int mipmapLevelToExtract    = 2;
            var plateStampPixelsPerUnit = new Dictionary <int, float>()
            {
                { 1, 3 }
            };
            var surfacePatchProvider = ESurfaceProviderInitializationHelper.ConstructProvider(
                ultraUpdatableContainer, intensityPatternPixelsPerUnit, containerGameObject, mipmapLevelToExtract, plateStampPixelsPerUnit);
            var surfaceTextureFormat = RenderTextureFormat.ARGB32;

            eTerrainHeightPyramidFacade.Start(perLevelTemplates,
                                              new Dictionary <EGroundTextureType, OneGroundTypeLevelTextureEntitiesGenerator>()
            {
                //{
                //    EGroundTextureType.SurfaceTexture, new OneGroundTypeLevelTextureEntitiesGenerator()
                //    {
                //        SegmentFillingListenerGeneratorFunc = (level) =>
                //        {
                //            var floorTexture = EGroundTextureGenerator.GenerateEmptyGroundTexture(startConfiguration.CommonConfiguration.FloorTextureSize,
                //                surfaceTextureFormat);
                //            var segmentsPlacer = new ESurfaceSegmentPlacer(textureRendererProxy, floorTexture
                //                , startConfiguration.CommonConfiguration.SlotMapSize, startConfiguration.CommonConfiguration.FloorTextureSize);
                //            var pyramidLevelManager = new GroundLevelTexturesManager(startConfiguration.CommonConfiguration.SlotMapSize);
                //            var segmentModificationManager = new SoleLevelGroundTextureSegmentModificationsManager(segmentsPlacer, pyramidLevelManager);

                //            return new SegmentFillingListenerWithFloorTexture()
                //            {
                //                FloorTexture = floorTexture,
                //                SegmentFillingListener =
                //                    new LambdaSegmentFillingListener(
                //                        (c) =>
                //                        {
                //                            var segmentLength = startConfiguration.PerLevelConfigurations[level].BiggestShapeObjectInGroupLength;
                //                            var sap = c.SegmentAlignedPosition;
                //                            MyRectangle surfaceWorldSpaceRectangle = new MyRectangle(sap.X * segmentLength, sap.Y * segmentLength,
                //                                segmentLength, segmentLength);
                //                            var texturesPack = surfacePatchProvider.ProvideSurfaceDetailAsync(surfaceWorldSpaceRectangle, new FlatLod(1, 1)).Result;
                //                            if (texturesPack != null)
                //                            {
                //                                var mainTexture = texturesPack.MainTexture;
                //                                segmentModificationManager.AddSegmentAsync(mainTexture, c.SegmentAlignedPosition);
                //                                GameObject.Destroy(mainTexture);
                //                            }

                //                            //}
                //                        },
                //                        (c) => { },
                //                        (c) => { })
                //            };

                //        },
                //    }
                //}
            }
                                              );

            Traveller.transform.position = new Vector3(startConfiguration.InitialTravellerPosition.x, 0, startConfiguration.InitialTravellerPosition.y);
            eTerrainHeightPyramidFacade.DisableLevelShapes(HeightPyramidLevel.Bottom);

            return(eTerrainHeightPyramidFacade);
        }
Пример #3
0
        public void Start()
        {
            UnityEngine.Random.InitState(412);
            TaskUtils.SetGlobalMultithreading(false);
            UnityThreadComputeShaderExecutorObject shaderExecutorObject = new UnityThreadComputeShaderExecutorObject();
            ComputeShaderContainerGameObject       containerGameObject  = GameObject.FindObjectOfType <ComputeShaderContainerGameObject>();
            UTTextureRendererProxy textureRendererProxy = new UTTextureRendererProxy(new TextureRendererService(
                                                                                         new MultistepTextureRenderer(containerGameObject), new TextureRendererServiceConfiguration()
            {
                StepSize = new Vector2(400, 400)
            }));
            var meshGeneratorUtProxy = new MeshGeneratorUTProxy(new MeshGeneratorService());

            var startConfiguration = ETerrainHeightPyramidFacadeStartConfiguration.DefaultConfiguration;

            ETerrainHeightBuffersManager buffersManager = new ETerrainHeightBuffersManager();

            _eTerrainHeightPyramidFacade = new ETerrainHeightPyramidFacade(buffersManager, meshGeneratorUtProxy, textureRendererProxy, startConfiguration);

            var perLevelTemplates = _eTerrainHeightPyramidFacade.GenerateLevelTemplates();

            var levels = startConfiguration.PerLevelConfigurations.Keys;
            var ePyramidShaderBuffersGeneratorPerRingInputs = levels.ToDictionary(c => c, c => new EPyramidShaderBuffersGeneratorPerRingInput()
            {
                FloorTextureResolution = startConfiguration.CommonConfiguration.FloorTextureSize.X,            //TODO i use only X, - works only for squares
                HeightMergeRanges      = perLevelTemplates[c].PerRingTemplates.ToDictionary(k => k.Key, k => k.Value.HeightMergeRange),
                CeilSliceWorldSize     = startConfiguration.PerLevelConfigurations[c].FloorTextureWorldSize.x, // TODO works only for square pyramids - i use width
                RingUvRanges           = startConfiguration.CommonConfiguration.RingsUvRange
            });

            buffersManager.InitializeBuffers(ePyramidShaderBuffersGeneratorPerRingInputs, startConfiguration.CommonConfiguration.MaxLevelsCount, startConfiguration.CommonConfiguration.MaxRingsPerLevelCount);

            _eTerrainHeightPyramidFacade.Start(perLevelTemplates,
                                               new Dictionary <EGroundTextureType, OneGroundTypeLevelTextureEntitiesGenerator>()
            {
                //{
                //    EGroundTextureType.HeightMap, new OneGroundTypeLevelTextureEntitiesGenerator()
                //    {
                //        SegmentFillingListenerGeneratorFunc = (level) =>
                //        {
                //            var floorTexture =
                //                EGroundTextureGenerator.GenerateEmptyGroundTexture(startConfiguration.CommonConfiguration.FloorTextureSize,
                //                    startConfiguration.CommonConfiguration.HeightTextureFormat);
                //            var segmentsPlacer = new ESurfaceSegmentPlacer(textureRendererProxy, floorTexture
                //                , startConfiguration.CommonConfiguration.SlotMapSize, startConfiguration.CommonConfiguration.FloorTextureSize);
                //            var pyramidLevelManager = new GroundLevelTexturesManager(startConfiguration.CommonConfiguration.SlotMapSize);
                //            var segmentModificationManager = new SoleLevelGroundTextureSegmentModificationsManager(segmentsPlacer, pyramidLevelManager);
                //            return new SegmentFillingListenerWithFloorTexture()
                //            {
                //                FloorTexture = floorTexture,
                //                SegmentFillingListener = new LambdaSegmentFillingListener(
                //                    (c) =>
                //                    {
                //                        var segmentTexture = ETerrainIntegrationMultipleSegmentsDEO.CreateDummySegmentTexture(c, level);
                //                        segmentModificationManager.AddSegmentAsync(segmentTexture, c.SegmentAlignedPosition);
                //                    },
                //                    (c) => { },
                //                    (c) => { }

                //                )
                //            };

                //        },
                //    }
                //}
            }
                                               );
            //_eTerrainHeightPyramidFacade.DisableShapes();
            _eTerrainHeightPyramidFacade.DisableLevelShapes(HeightPyramidLevel.Bottom);

            Traveller.transform.position = new Vector3(startConfiguration.InitialTravellerPosition.x, 0, startConfiguration.InitialTravellerPosition.y);

            var ePropLocationConfiguration = new EPropElevationConfiguration();
            EPropConstantPyramidParameters ePropConstantPyramidParameters = new EPropConstantPyramidParameters()
            {
                LevelsCount        = startConfiguration.HeightPyramidLevels.Count,
                RingsPerLevelCount = startConfiguration.CommonConfiguration.MaxRingsPerLevelCount, //TODO parametrize
                HeightScale        = startConfiguration.CommonConfiguration.YScale
            };

            _elevationManager = new EPropElevationManager(new CommonExecutorUTProxy(), shaderExecutorObject, ePropLocationConfiguration, ePropConstantPyramidParameters);
            var heightFloorTextureArray = _eTerrainHeightPyramidFacade.FloorTextureArrays.Where(c => c.TextureType == EGroundTextureType.HeightMap).Select(c => c.Texture).First();
            var initializedBuffers      = _elevationManager.Initialize(buffersManager.PyramidPerFrameParametersBuffer, buffersManager.EPyramidConfigurationBuffer,
                                                                       heightFloorTextureArray);
            var ePropLocaleBuffer = initializedBuffers.EPropLocaleBuffer;
            var ePropIdsBuffer    = initializedBuffers.EPropIdsBuffer;

            _dummyObjectsDisplayer = new EPropDummyObjectsDisplayer(ePropLocationConfiguration.ScopeLength, ePropLocaleBuffer, ePropIdsBuffer, FindObjectOfType <BufferReloaderRootGO>());
            _dummyObjectsDisplayer.Start();

            _dummyObjectsInstancingDisplayer = new EPropDummyObjectsInstancingDisplayer(DebugMesh, DebugMeshMaterial);
            _dummyObjectsInstancingDisplayer.Start();
            _dummyObjectsInstancingDisplayer.SetLocaleBuffers(ePropLocaleBuffer, ePropIdsBuffer, ePropLocationConfiguration.ScopeLength);

            _sectorAreasDisplayer = new EPropDebugSectorAreasDisplayer();
            _sectorAreasDisplayer.Start();

            _mergeRingsDisplayer = new EPropDebugMergeRingsDisplayer();
            _mergeRingsDisplayer.Start();
            var levelWorldSizes = startConfiguration.PerLevelConfigurations.ToDictionary(c => c.Key, c => c.Value.FloorTextureWorldSize);
            var ringMergeRanges = perLevelTemplates.ToDictionary(c => c.Key,
                                                                 c => c.Value.PerRingTemplates.ToDictionary(k => k.Key, k => k.Value.HeightMergeRange));

            _ePropHotAreaSelector = new EPropHotAreaSelector(levelWorldSizes, ringMergeRanges);

            _elevationManager.DebugInitializeSectors(new MyRectangle(-200, -200, 400, 400));
        }