public void Start()
        {
            TaskUtils.SetGlobalMultithreading(false);
            var shaderContainerGO = FindObjectOfType <ComputeShaderContainerGameObject>();

            var configuration = new FEConfiguration(new FilePathsConfiguration());
            GlobalServicesProfileInfo servicesProfileInfo = new GlobalServicesProfileInfo();
            var ultraUpdatableContainer = new UltraUpdatableContainer(
                configuration.SchedulerConfiguration,
                servicesProfileInfo,
                configuration.UpdatableContainerConfiguration);
            Dictionary <int, float> intensityPatternPixelsPerUnit = new Dictionary <int, float>()
            {
                { 1, 1 }
            };
            int mipmapLevelToExtract = 2;
            Dictionary <int, float> plateStampPixelsPerUnit = new Dictionary <int, float>()
            {
                { 1, 5 }
            };

            _updatableContainer = new UltraUpdatableContainer(new MyUtSchedulerConfiguration(), new GlobalServicesProfileInfo(), new UltraUpdatableContainerConfiguration());
            _provider           = ESurfaceProviderInitializationHelper.ConstructProvider(
                _updatableContainer, intensityPatternPixelsPerUnit, shaderContainerGO, mipmapLevelToExtract, plateStampPixelsPerUnit);

            _patchesCreatorProxy = new GRing2PatchesCreatorProxy(ESurfaceProviderInitializationHelper.CreateRing2PatchesCreator(_updatableContainer, intensityPatternPixelsPerUnit));

            RegeneratePatch();
        }
예제 #2
0
        private void InitializeTerrainDb(bool useTerrainDetailFileCache = false)
        {
            var ultraUpdatableContainer = new UltraUpdatableContainer(new MyUtSchedulerConfiguration(),
                                                                      new GlobalServicesProfileInfo(), new UltraUpdatableContainerConfiguration());

            var feConfiguration      = new FEConfiguration(new FilePathsConfiguration());
            var feGRingConfiguration = new FeGRingConfiguration();

            feGRingConfiguration.FeConfiguration = feConfiguration;

            feConfiguration.TerrainShapeDbConfiguration.UseTextureSavingToDisk    = useTerrainDetailFileCache;
            feConfiguration.TerrainShapeDbConfiguration.UseTextureLoadingFromDisk = useTerrainDetailFileCache;
            feConfiguration.EngraveRoadsInTerrain = false;

            TaskUtils.SetGlobalMultithreading(feConfiguration.Multithreading);
            TaskUtils.SetMultithreadingOverride(true);

            _gameInitializationFields.SetField(feConfiguration.Repositioner);
            _gameInitializationFields.SetField(feConfiguration.HeightDenormalizer);

            var initializingHelper =
                new FEInitializingHelper(_gameInitializationFields, ultraUpdatableContainer, feConfiguration);

            initializingHelper.InitializeUTService(new TextureConcieverUTProxy());
            initializingHelper.InitializeUTService(new UnityThreadComputeShaderExecutorObject());
            initializingHelper.InitializeUTService(new CommonExecutorUTProxy());

            initializingHelper.InitializeUTRendererProxy();


            var finalTerrainShapeDb = new FETerrainShapeDbInitialization(ultraUpdatableContainer,
                                                                         _gameInitializationFields, feConfiguration, _filePathsConfiguration);

            finalTerrainShapeDb.Start();
        }
예제 #3
0
        public static UltraUpdatableContainer InitializeFinalElements(FEConfiguration configuration, ComputeShaderContainerGameObject containerGameObject,
                                                                      GameInitializationFields gameInitializationFields, Dictionary <int, Ring2RegionsDbGeneratorConfiguration> ring2RegionsDatabasesConfiguration = null
                                                                      , bool initializeLegacyDesignBodySpotUpdater = false)
        {
            TaskUtils.SetGlobalMultithreading(configuration.Multithreading);
            return(TaskUtils.ExecuteFunctionWithOverridenMultithreading(true, () =>
            {
                var servicesProfileInfo = new GlobalServicesProfileInfo();
                gameInitializationFields.SetField(servicesProfileInfo);
                var ultraUpdatableContainer = new UltraUpdatableContainer(
                    configuration.SchedulerConfiguration,
                    servicesProfileInfo,
                    configuration.UpdatableContainerConfiguration);

                configuration.TerrainShapeDbConfiguration.UseTextureSavingToDisk = true;

                gameInitializationFields.SetField(containerGameObject);
                gameInitializationFields.SetField(configuration.Repositioner);
                gameInitializationFields.SetField(configuration.HeightDenormalizer);

                var initializingHelper =
                    new FEInitializingHelper(gameInitializationFields, ultraUpdatableContainer, configuration);
                initializingHelper.InitializeUTService(new TextureConcieverUTProxy());
                initializingHelper.InitializeUTService(new UnityThreadComputeShaderExecutorObject());
                initializingHelper.InitializeUTService(new CommonExecutorUTProxy());
                initializingHelper.CreatePathProximityTextureDb();

                if (initializeLegacyDesignBodySpotUpdater)
                {
                    initializingHelper.InitializeDesignBodySpotUpdater();
                }

                initializingHelper.InitializeUTRendererProxy();
                initializingHelper.InitializeUTService(new MeshGeneratorUTProxy(new MeshGeneratorService()));
                if (ring2RegionsDatabasesConfiguration != null)
                {
                    initializingHelper.InitializeComplexRing2RegionsDatabase(ring2RegionsDatabasesConfiguration);
                }
                else
                {
                    initializingHelper.InitializeMonoliticRing2RegionsDatabase();
                }

                //var finalTerrainInitialization = new FinalTerrainInitialization(_ultraUpdatableContainer, _gameInitializationFields, _configuration, FeGRingConfiguration);
                //finalTerrainInitialization.Start();

                initializingHelper.InitializeGlobalInstancingContainer();
                //var finalVegetation = new FinalVegetation(_gameInitializationFields, _ultraUpdatableContainer, VegetationConfiguration);
                //finalVegetation.Start();
                return ultraUpdatableContainer;
            }));
        }
예제 #4
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;
        }
예제 #5
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);
        }
예제 #6
0
 public PrecomputationConfiguration(FEConfiguration feConfiguration,
                                    FilePathsConfiguration filePathsConfiguration)
 {
     _feConfiguration        = feConfiguration;
     _filePathsConfiguration = filePathsConfiguration;
 }
예제 #7
0
        public static OneGroundTypeLevelTextureEntitiesGenerator CreateSurfaceTextureEntitiesGenerator(
            FEConfiguration configuration, ETerrainHeightPyramidFacadeStartConfiguration startConfiguration, GameInitializationFields gameInitializationFields
            , UltraUpdatableContainer ultraUpdatableContainer)
        {
            var repositioner         = gameInitializationFields.Retrive <Repositioner>();
            var surfaceTextureFormat = RenderTextureFormat.ARGB32;
            var commonExecutor       = gameInitializationFields.Retrive <CommonExecutorUTProxy>();

            var feRing2PatchConfiguration = new Ring2PatchInitializerConfiguration(configuration);

            feRing2PatchConfiguration.Ring2PlateStamperConfiguration.PlateStampPixelsPerUnit =
                feRing2PatchConfiguration.Ring2PlateStamperConfiguration.PlateStampPixelsPerUnit.ToDictionary(
                    c => c.Key,
                    c => c.Value * Mathf.Pow(2, feRing2PatchConfiguration.MipmapLevelToExtract)
                    );

            var patchInitializer = new Ring2PatchInitializer(gameInitializationFields, ultraUpdatableContainer, feRing2PatchConfiguration);

            patchInitializer.Start();

            var mipmapExtractor               = new MipmapExtractor(gameInitializationFields.Retrive <UTTextureRendererProxy>());
            var patchesCreatorProxy           = gameInitializationFields.Retrive <GRing2PatchesCreatorProxy>();
            var patchStamperOverseerFinalizer = gameInitializationFields.Retrive <Ring2PatchStamplingOverseerFinalizer>();
            var surfacePatchProvider          = new ESurfacePatchProvider(patchesCreatorProxy, patchStamperOverseerFinalizer, commonExecutor,
                                                                          mipmapExtractor, feRing2PatchConfiguration.MipmapLevelToExtract);

            var cachedSurfacePatchProvider =
                new CachedESurfacePatchProvider(surfacePatchProvider
                                                , new InMemoryAssetsCache <ESurfaceTexturesPackToken, NullableESurfaceTexturesPack>(
                                                    FETerrainShapeDbInitialization.CreateLevel2AssetsCache <ESurfaceTexturesPackToken, NullableESurfaceTexturesPack>(
                                                        cachingConfiguration: new CachingConfiguration()
            {
                SaveAssetsToFile = true,
                UseFileCaching   = true,
            }
                                                        , new InMemoryCacheConfiguration() /*{ MaxTextureMemoryUsed = 0}*/
                                                        , new ESurfaceTexturesPackEntityActionsPerformer(commonExecutor)
                                                        , new ESurfaceTexturesPackFileManager(commonExecutor, configuration.FilePathsConfiguration.SurfacePatchCachePath))));

            cachedSurfacePatchProvider.Initialize().Wait();

            var cachedSurfacePatchDbProxy = new ESurfacePatchDbProxy(cachedSurfacePatchProvider);

            ultraUpdatableContainer.AddOtherThreadProxy(cachedSurfacePatchDbProxy);

            var textureRendererProxy = gameInitializationFields.Retrive <UTTextureRendererProxy>();

            return(new OneGroundTypeLevelTextureEntitiesGenerator()
            {
                FloorTextureArrayGenerator = () =>
                {
                    return new List <EGroundTexture>()
                    {
                        new EGroundTexture(EGroundTextureGenerator.GenerateEmptyGroundTextureArray(startConfiguration.CommonConfiguration.FloorTextureSize,
                                                                                                   startConfiguration.HeightPyramidLevels.Count, surfaceTextureFormat),
                                           EGroundTextureType.SurfaceTexture)
                    };
                },
                SegmentFillingListenerGeneratorFunc = (level, floorTextureArrays) =>
                {
                    var floorTextureArray = floorTextureArrays.First(c => c.TextureType == EGroundTextureType.SurfaceTexture);
                    var segmentsPlacer = new ESurfaceSegmentPlacer(textureRendererProxy, floorTextureArray.Texture, level.GetIndex()
                                                                   , startConfiguration.CommonConfiguration.SlotMapSize, startConfiguration.CommonConfiguration.FloorTextureSize);
                    var pyramidLevelManager = new GroundLevelTexturesManager(startConfiguration.CommonConfiguration.SlotMapSize);
                    var segmentModificationManager = new SoleLevelGroundTextureSegmentModificationsManager(segmentsPlacer, pyramidLevelManager);

                    var otherThreadExecutor = new OtherThreadCompoundSegmentFillingOrdersExecutorProxy("ESurface-" + level.ToString(),
                                                                                                       new CompoundSegmentOrdersFillingExecutor <TokenizedESurfaceTexturesPackToken>(
                                                                                                           async(sap) =>
                    {
                        var surfaceWorldSpaceRectangle = ETerrainUtils.SurfaceTextureSegmentAlignedPositionToWorldSpaceArea(level,
                                                                                                                            startConfiguration.PerLevelConfigurations[level], sap);
                        var lod = ETerrainUtils.HeightPyramidLevelToSurfaceTextureFlatLod(level);
                        return await cachedSurfacePatchDbProxy.ProvideSurfaceDetail(repositioner.InvMove(surfaceWorldSpaceRectangle), lod);
                    },
                                                                                                           async(sap, packAndToken) =>
                    {
                        var pack = packAndToken.Pack;
                        if (pack != null)
                        {
                            var mainTexture = pack.MainTexture;
                            await segmentModificationManager.AddSegmentAsync(mainTexture, sap);
                        }
                    },
                                                                                                           segmentRemovalFunc: async(packAndToken) =>
                    {
                        if (packAndToken != null)
                        {
                            var pack = packAndToken.Pack;
                            if (pack != null)
                            {
                                Preconditions.Assert(packAndToken.Token != null, "Token is null. Unexpected");
                                cachedSurfacePatchDbProxy.RemoveSurfaceDetailAsync(pack, packAndToken.Token);
                            }
                        }
                    }
                                                                                                           ));

                    ultraUpdatableContainer.AddOtherThreadProxy(otherThreadExecutor);
                    var fillingListener = new UnityThreadCompoundSegmentFillingListener(otherThreadExecutor);
                    var travellerCustodian = gameInitializationFields.Retrive <TravellerMovementCustodian>();
                    travellerCustodian.AddLimiter(() => new MovementBlockingProcess()
                    {
                        BlockCount = fillingListener.BlockingProcessesCount(), ProcessName = "SurfaceSegmentsGeneration " + level
                    });
                    return fillingListener;
                }
            });
        }