public EPropsDesignBodyChangesListener(EPropElevationManager elevationManager, Repositioner repositioner)
 {
     _elevationManager             = elevationManager;
     _repositioner                 = repositioner;
     _spotIdToElevationIdDict      = new Dictionary <SpotId, EPropElevationPointer>();
     _spotIdToGroupElevationIdDict = new Dictionary <SpotId, List <EPropElevationPointer> >();
 }
Пример #2
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));
        }