Beispiel #1
0
        public void Start()
        {
            var msw = new MyStopWatch();

            msw.StartSegment("Start");
            TaskUtils.ExecuteActionWithOverridenMultithreading(true, () =>
            {
                _feConfiguration = new FEConfiguration(new FilePathsConfiguration())
                {
                    Multithreading = Multithreading
                };
                _feConfiguration.EngraveTerrainFeatures = true;
                _feConfiguration.EngraveRoadsInTerrain  = true;

                _feConfiguration.TerrainShapeDbConfiguration.UseTextureLoadingFromDisk = true;
                _feConfiguration.TerrainShapeDbConfiguration.UseTextureSavingToDisk    = false;
                _feConfiguration.TerrainShapeDbConfiguration.MergeTerrainDetail        = true;

                var containerGameObject = GameObject.FindObjectOfType <ComputeShaderContainerGameObject>();
                VegetationConfiguration.FeConfiguration = _feConfiguration;

                _heightmapListenersContainer = new HeightmapSegmentFillingListenersContainer();
                _gameInitializationFields    = new GameInitializationFields();
                _updaterUntilException       = new UpdaterUntilException();
                _movementCustodian           = new TravellerMovementCustodian(Traveller);
                _gameInitializationFields.SetField(_movementCustodian);


                _ultraUpdatableContainer = ETerrainTestUtils.InitializeFinalElements(_feConfiguration, containerGameObject, _gameInitializationFields, initializeLegacyDesignBodySpotUpdater: false);

                var startConfiguration = ETerrainHeightPyramidFacadeStartConfiguration.DefaultConfiguration;
                var initializingHelper = InitializeETerrain(startConfiguration);
                initializingHelper.InitializeUTService(new UnityThreadComputeShaderExecutorObject());
                InitializeUI(startConfiguration);

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

            Debug.Log("Init time " + msw.CollectResults());
            _initializationWasSuccessfull = true;
        }
Beispiel #2
0
        public static OneGroundTypeLevelTextureEntitiesGenerator CreateHeightTextureEntitiesGenerator(
            ETerrainHeightPyramidFacadeStartConfiguration startConfiguration, GameInitializationFields initializationFields,
            UltraUpdatableContainer updatableContainer
            , HeightmapSegmentFillingListenersContainer heightmapListenersesContainer)
        {
            startConfiguration.CommonConfiguration.UseNormalTextures = true;
            var textureRendererProxy = initializationFields.Retrive <UTTextureRendererProxy>();
            var dbProxy      = initializationFields.Retrive <TerrainShapeDbProxy>();
            var repositioner = initializationFields.Retrive <Repositioner>();

            return(new OneGroundTypeLevelTextureEntitiesGenerator
            {
                FloorTextureArrayGenerator = () =>
                {
                    var outList = new List <EGroundTexture>()
                    {
                        new EGroundTexture(
                            texture: EGroundTextureGenerator.GenerateEmptyGroundTextureArray(startConfiguration.CommonConfiguration.FloorTextureSize
                                                                                             , startConfiguration.HeightPyramidLevels.Count, startConfiguration.CommonConfiguration.HeightTextureFormat),
                            textureType: EGroundTextureType.HeightMap
                            ),
                    };
                    if (startConfiguration.CommonConfiguration.UseNormalTextures)
                    {
                        outList.Add(
                            new EGroundTexture(
                                texture: EGroundTextureGenerator.GenerateEmptyGroundTextureArray(startConfiguration.CommonConfiguration.FloorTextureSize
                                                                                                 , startConfiguration.HeightPyramidLevels.Count, startConfiguration.CommonConfiguration.NormalTextureFormat),
                                textureType: EGroundTextureType.NormalTexture
                                )
                            );
                    }

                    return outList;
                },
                SegmentFillingListenerGeneratorFunc = (level, floorTextureArrays) =>
                {
                    var usedGroundTypes = new List <EGroundTextureType>()
                    {
                        EGroundTextureType.HeightMap
                    };
                    if (startConfiguration.CommonConfiguration.UseNormalTextures)
                    {
                        usedGroundTypes.Add(EGroundTextureType.NormalTexture);
                    }

                    var segmentModificationManagers = usedGroundTypes.ToDictionary(groundType => groundType,
                                                                                   groundType =>
                    {
                        var groundTexture = floorTextureArrays.First(c => c.TextureType == groundType);

                        var segmentsPlacer = new HeightSegmentPlacer(
                            textureRendererProxy, initializationFields.Retrive <CommonExecutorUTProxy>(), groundTexture.Texture
                            , level.GetIndex(), startConfiguration.CommonConfiguration.SlotMapSize, startConfiguration.CommonConfiguration.FloorTextureSize
                            , startConfiguration.CommonConfiguration.InterSegmentMarginSize, startConfiguration.CommonConfiguration.SegmentTextureResolution
                            , startConfiguration.CommonConfiguration.MergeSegmentsInFloorTexture
                            );
                        var pyramidLevelManager = new GroundLevelTexturesManager(startConfiguration.CommonConfiguration.SlotMapSize);
                        return new SoleLevelGroundTextureSegmentModificationsManager(segmentsPlacer, pyramidLevelManager);
                    });

                    var otherThreadExecutor = new OtherThreadCompoundSegmentFillingOrdersExecutorProxy("Height-" + level.ToString(),
                                                                                                       new CompoundSegmentOrdersFillingExecutor <TerrainDescriptionOutput>(
                                                                                                           async(sap) =>
                    {
                        var surfaceWorldSpaceRectangle = ETerrainUtils.TerrainShapeSegmentAlignedPositionToWorldSpaceArea(level,
                                                                                                                          startConfiguration.PerLevelConfigurations[level], sap);

                        var terrainDescriptionOutput = await dbProxy.Query(new TerrainDescriptionQuery()
                        {
                            QueryArea = repositioner.InvMove(surfaceWorldSpaceRectangle),
                            RequestedElementDetails = new List <TerrainDescriptionQueryElementDetail>()
                            {
                                new TerrainDescriptionQueryElementDetail()
                                {
                                    Resolution = ETerrainUtils.HeightPyramidLevelToTerrainShapeDatabaseResolution(level),
                                    RequiredMergeStatus = RequiredCornersMergeStatus.MERGED,
                                    Type = TerrainDescriptionElementTypeEnum.HEIGHT_ARRAY
                                },
                                new TerrainDescriptionQueryElementDetail()
                                {
                                    Resolution = ETerrainUtils.HeightPyramidLevelToTerrainShapeDatabaseResolution(level),
                                    RequiredMergeStatus = RequiredCornersMergeStatus.NOT_MERGED,
                                    Type = TerrainDescriptionElementTypeEnum.NORMAL_ARRAY
                                },
                            }
                        });
                        return terrainDescriptionOutput;
                    },
                                                                                                           async(sap, terrainDescriptionOutput) =>
                    {
                        var heightSegmentTexture = terrainDescriptionOutput.GetElementOfType(TerrainDescriptionElementTypeEnum.HEIGHT_ARRAY)
                                                   .TokenizedElement.DetailElement.Texture.Texture;
                        await segmentModificationManagers[EGroundTextureType.HeightMap].AddSegmentAsync(heightSegmentTexture, sap);

                        if (startConfiguration.CommonConfiguration.UseNormalTextures)
                        {
                            var normalSegmentTexture = terrainDescriptionOutput.GetElementOfType(TerrainDescriptionElementTypeEnum.NORMAL_ARRAY)
                                                       .TokenizedElement.DetailElement.Texture.Texture;
                            await segmentModificationManagers[EGroundTextureType.NormalTexture].AddSegmentAsync(normalSegmentTexture, sap);
                        }
                    },
                                                                                                           async(terrainDescriptionOutput) =>
                    {
                        await dbProxy.DisposeTerrainDetailElement(terrainDescriptionOutput
                                                                  .GetElementOfType(TerrainDescriptionElementTypeEnum.HEIGHT_ARRAY).TokenizedElement.Token);
                        if (startConfiguration.CommonConfiguration.UseNormalTextures)
                        {
                            await dbProxy.DisposeTerrainDetailElement(terrainDescriptionOutput
                                                                      .GetElementOfType(TerrainDescriptionElementTypeEnum.NORMAL_ARRAY).TokenizedElement.Token);
                        }
                    }
                                                                                                           ));
                    updatableContainer.AddOtherThreadProxy(otherThreadExecutor);

                    var fillingListener = new UnityThreadCompoundSegmentFillingListener(otherThreadExecutor);
                    heightmapListenersesContainer.AddListener(level, fillingListener);

                    var travellerCustodian = initializationFields.Retrive <TravellerMovementCustodian>();
                    travellerCustodian.AddLimiter(() => new MovementBlockingProcess()
                    {
                        ProcessName = "HeightSegmentsGenerationProcess " + level, BlockCount = fillingListener.BlockingProcessesCount()
                    });
                    //initializationFields.Retrive<InitialSegmentsGenerationInspector>().SetConditionToCheck(() => fillingListener.BlockingProcessesCount() == 0);
                    return fillingListener;
                }
            });
        }