public GCompositeRing2NodeTerrainCreator(
     Ring1PaintingOrderGrabber orderGrabber,
     GameObject parentObject,
     MeshGeneratorUTProxy meshGenerator,
     ITerrainShapeDb terrainShapeDb,
     UnityCoordsCalculator coordsCalculator,
     GRing2PatchesCreatorProxy patchesCreator,
     GRingSpotUpdater spotUpdater,
     HeightArrayWeldingPack weldingPack,
     Ring2PatchStamplingOverseerFinalizer patchStamper,
     GRingGroundShapeProviderConfiguration groundShapeProviderConfiguration,
     GRingTerrainMeshProviderConfiguration terrainMeshProviderConfiguration)
 {
     _orderGrabber     = orderGrabber;
     _parentObject     = parentObject;
     _meshGenerator    = meshGenerator;
     _terrainShapeDb   = terrainShapeDb;
     _coordsCalculator = coordsCalculator;
     _patchesCreator   = patchesCreator;
     _spotUpdater      = spotUpdater;
     _weldingPack      = weldingPack;
     _patchStamper     = patchStamper;
     _groundShapeProviderConfiguration = groundShapeProviderConfiguration;
     _terrainMeshProviderConfiguration = terrainMeshProviderConfiguration;
 }
Ejemplo n.º 2
0
 public GDebugLodNodeTerrainCreator(Ring1PaintingOrderGrabber orderGrabber, GameObject parentObject,
                                    UnityCoordsCalculator coordsCalculator, MeshGeneratorUTProxy meshGeneratorUtProxy)
 {
     _orderGrabber         = orderGrabber;
     _parentObject         = parentObject;
     _coordsCalculator     = coordsCalculator;
     _meshGeneratorUtProxy = meshGeneratorUtProxy;
 }
Ejemplo n.º 3
0
 public GRingTerrainMeshProvider(MeshGeneratorUTProxy meshGenerator, FlatLod flatLod,
                                 GRingTerrainMeshProviderConfiguration configuration)
 {
     _meshGenerator = meshGenerator;
     _flatLod       = flatLod;
     _configuration = configuration;
     CalculateMeshResolution();
 }
Ejemplo n.º 4
0
 public ETerrainHeightPyramidFacade(ETerrainHeightBuffersManager buffersManager,
                                    MeshGeneratorUTProxy meshGeneratorUtProxy, UTTextureRendererProxy textureRendererProxy,
                                    ETerrainHeightPyramidFacadeStartConfiguration startConfiguration)
 {
     _buffersManager       = buffersManager;
     _meshGeneratorUtProxy = meshGeneratorUtProxy;
     _textureRendererProxy = textureRendererProxy;
     _startConfiguration   = startConfiguration;
 }
Ejemplo n.º 5
0
 public GDebugLodNodeTerrain(
     Ring1PaintingOrderGrabber orderGrabber,
     GameObject parentObject,
     GRingTripletProvider tripletProvider,
     FlatLod flatLod,
     MeshGeneratorUTProxy meshGeneratorUtProxy)
 {
     _orderGrabber         = orderGrabber;
     _parentObject         = parentObject;
     _tripletProvider      = tripletProvider;
     _flatLod              = flatLod;
     _meshGeneratorUtProxy = meshGeneratorUtProxy;
 }
Ejemplo n.º 6
0
 public GDebugTerrainedLodNodeTerrainCreator(
     Ring1PaintingOrderGrabber orderGrabber, GameObject parentObject,
     UnityCoordsCalculator coordsCalculator, MeshGeneratorUTProxy meshGeneratorUtProxy,
     ITerrainShapeDb terrainShapeDb, GRingGroundShapeProviderConfiguration groundShapeProviderConfiguration,
     GRingSpotUpdater gRingSpotUpdater = null)
 {
     _orderGrabber                     = orderGrabber;
     _parentObject                     = parentObject;
     _coordsCalculator                 = coordsCalculator;
     _meshGeneratorUtProxy             = meshGeneratorUtProxy;
     _terrainShapeDb                   = terrainShapeDb;
     _groundShapeProviderConfiguration = groundShapeProviderConfiguration;
     _gRingSpotUpdater                 = gRingSpotUpdater;
 }
Ejemplo n.º 7
0
 public Ring1NodeShaderHeightTerrain(
     Ring1Node ring1Node,
     Ring1VisibilityTextureChangeGrabber ring1VisibilityTextureChangeGrabber,
     Texture2D visibilityTexture,
     GameObject terrainParentObject,
     UnityCoordsCalculator coordsCalculator,
     Ring1PaintingOrderGrabber orderGrabber,
     TerrainShapeDbProxy terrainShapeDb,
     MeshGeneratorUTProxy meshGenerator,
     StainTerrainServiceProxy stainTerrainServiceProxy)
     : base(ring1Node, ring1VisibilityTextureChangeGrabber, orderGrabber, terrainParentObject)
 {
     _visibilityTexture        = visibilityTexture;
     _coordsCalculator         = coordsCalculator;
     _terrainShapeDb           = terrainShapeDb;
     _meshGenerator            = meshGenerator;
     _stainTerrainServiceProxy = stainTerrainServiceProxy;
 }
 public Ring1NodeDirectHeightTerrain(
     Ring1Node ring1Node,
     Ring1VisibilityTextureChangeGrabber ring1VisibilityTextureChangeGrabber,
     Texture2D visibilityTexture,
     GameObject terrainParentObject,
     UnityCoordsCalculator coordsCalculator,
     Ring1PaintingOrderGrabber orderGrabber,
     TerrainShapeDbProxy terrainShapeDb,
     HeightmapArray globalHeightmap,
     MeshGeneratorUTProxy meshGenerator
     )
     : base(ring1Node, ring1VisibilityTextureChangeGrabber, orderGrabber, terrainParentObject)
 {
     _visibilityTexture = visibilityTexture;
     _coordsCalculator  = coordsCalculator;
     _globalHeightmap   = globalHeightmap;
     _meshGenerator     = meshGenerator;
     _terrainShapeDb    = terrainShapeDb;
 }
Ejemplo n.º 9
0
 public GRing0NodeTerrainCreator(
     Ring1PaintingOrderGrabber orderGrabber,
     GameObject parentObject,
     MeshGeneratorUTProxy meshGenerator,
     ITerrainShapeDb terrainShapeDb,
     UnityCoordsCalculator coordsCalculator, GRingSpotUpdater spotUpdater,
     HeightArrayWeldingPack weldingPack,
     GRingGroundShapeProviderConfiguration groundShapeProviderConfiguration,
     GRingTerrainMeshProviderConfiguration terrainMeshProviderConfiguration)
 {
     _orderGrabber     = orderGrabber;
     _parentObject     = parentObject;
     _meshGenerator    = meshGenerator;
     _terrainShapeDb   = terrainShapeDb;
     _coordsCalculator = coordsCalculator;
     _spotUpdater      = spotUpdater;
     _groundShapeProviderConfiguration = groundShapeProviderConfiguration;
     _terrainMeshProviderConfiguration = terrainMeshProviderConfiguration;
     _weldingPack = weldingPack;
 }
Ejemplo n.º 10
0
        public void Start()
        {
            TaskUtils.SetGlobalMultithreading(false);
            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());


            eTerrainHeightPyramidFacades = new List <ETerrainHeightPyramidFacade>()
            {
                StartTerrainThings(meshGeneratorUtProxy, textureRendererProxy, containerGameObject,
                                   new List <HeightPyramidLevel>()
                {
                    HeightPyramidLevel.Top
                }),
                //StartTerrainThings(meshGeneratorUtProxy, textureRendererProxy, containerGameObject,
                //    new List<HeightPyramidLevel>() {HeightPyramidLevel.Top, HeightPyramidLevel.Mid, HeightPyramidLevel.Bottom})
            };
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
0
        // Use this for initialization
        void Start()
        {
            _updatableContainer = new UpdatableContainer();
            TaskUtils.SetGlobalMultithreading(false);

            _ring1Tree = new Ring1Tree();

            //////////////////

            var rgbaMainTexture = SavingFileManager.LoadPngTextureFromFile(@"C:\inz\cont\n49_e019_1arc_v3.png", 3600,
                                                                           3600,
                                                                           TextureFormat.ARGB32, true, false);


            CommonExecutorUTProxy commonExecutorUtProxy = new CommonExecutorUTProxy(); //todo

            _updatableContainer.AddUpdatableElement(commonExecutorUtProxy);
            TerrainTextureFormatTransformator transformator =
                new TerrainTextureFormatTransformator(commonExecutorUtProxy);
            var globalHeightTexture = transformator.EncodedHeightTextureToPlain(new TextureWithSize()
            {
                Size    = new IntVector2(3600, 3600),
                Texture = rgbaMainTexture
            });

            /// /// 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));

            _updatableContainer.AddUpdatableElement(visibilityTextureProcessorProxy);


            var visibilityTextureChangeGrabber = new Ring1VisibilityTextureChangeGrabber();

            var terrainParentGameObject = new GameObject("TerrainParent");

            var unityCoordsCalculator = new UnityCoordsCalculator(new Vector2(24 * 240 * 2, 24 * 240 * 2));
            var orderGrabber          = new Ring1PaintingOrderGrabber();

            var painterProxy = new RingTerrainPainterUTProxy(new RingTerrainPainter());

            _updatableContainer.AddUpdatableElement(painterProxy);

            painterProxy.Update();

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

            _otherThreadActionPairs.Add(new OtherThreadProxyAndActionPair()
            {
                Proxy           = mainRespondingProxy,
                EveryPostAction =
                    () =>
                {
                    var delta = visibilityTextureChangeGrabber.RetriveVisibilityChanges();

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

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


            UTTextureRendererProxy textureRendererProxy = new UTTextureRendererProxy(new TextureRendererService(
                                                                                         new MultistepTextureRenderer(ContainerGameObject), new TextureRendererServiceConfiguration()
            {
                StepSize = new Vector2(500, 500)
            }));

            _updatableContainer.AddUpdatableElement(textureRendererProxy);

            UnityThreadComputeShaderExecutorObject computeShaderExecutorObject =
                new UnityThreadComputeShaderExecutorObject();

            _updatableContainer.AddUpdatableElement(computeShaderExecutorObject);
            _updatableContainer.AddUpdatableElement(commonExecutorUtProxy);

            TerrainDetailGenerator terrainDetailGenerator =
                CreateTerrainDetailGenerator(
                    globalHeightTexture, textureRendererProxy, commonExecutorUtProxy, computeShaderExecutorObject,
                    ContainerGameObject);
            TerrainDetailProvider terrainDetailProvider =
                CreateTerrainDetailProvider(terrainDetailGenerator);

            var terrainShapeDb = FETerrainShapeDbInitialization.CreateTerrainShapeDb(terrainDetailProvider, commonExecutorUtProxy
                                                                                     , new TerrainDetailAlignmentCalculator(240), false, false, false, null);
            TerrainShapeDbProxy terrainShapeDbProxy = new TerrainShapeDbProxy(terrainShapeDb);

            terrainDetailGenerator.SetBaseTerrainDetailProvider(BaseTerrainDetailProvider.CreateFrom(terrainShapeDb));

            _otherThreadActionPairs.Add(new OtherThreadProxyAndActionPair()
            {
                Proxy = terrainShapeDbProxy
            });

            var meshGeneratorProxy = new MeshGeneratorUTProxy(new MeshGeneratorService());

            _updatableContainer.AddUpdatableElement(meshGeneratorProxy);

            _stainTerrainResourceCreatorUtProxy =
                new StainTerrainResourceCreatorUTProxy(new StainTerrainResourceCreator());
            _updatableContainer.AddUpdatableElement(_stainTerrainResourceCreatorUtProxy);

            var stainTerrainServiceProxy = new StainTerrainServiceProxy(
                new StainTerrainService(
                    new ComputationStainTerrainResourceGenerator(
                        new StainTerrainResourceComposer(
                            _stainTerrainResourceCreatorUtProxy
                            ),
                        new StainTerrainArrayMelder(),
                        new DummyStainTerrainArrayFromBiomesGenerator(
                            new DebugBiomeContainerGenerator().GenerateBiomesContainer(
                                new BiomesContainerConfiguration()),
                            new StainTerrainArrayFromBiomesGeneratorConfiguration()
                            )),
                    new MyRectangle(0, 0, 24 * 240 * 2, 24 * 240 * 2)));

            _otherThreadActionPairs.Add(new OtherThreadProxyAndActionPair()
            {
                Proxy = stainTerrainServiceProxy
            });

            var gRing1NodeTerrainCreator = new GRing1NodeTerrainCreator(
                orderGrabber,
                terrainParentGameObject,
                meshGeneratorProxy,
                terrainShapeDbProxy,
                stainTerrainServiceProxy,
                unityCoordsCalculator,
                null,
                null,
                new GRingGroundShapeProviderConfiguration(),
                new GRingTerrainMeshProviderConfiguration());

            var gRing2NodeTerrainCreator = new GRing2NodeTerrainCreator(
                orderGrabber,
                terrainParentGameObject,
                meshGeneratorProxy,
                terrainShapeDbProxy,
                unityCoordsCalculator,
                new GRing2PatchesCreatorProxy(CreateRing2PatchesCreator()),
                null,
                null,
                new GRingGroundShapeProviderConfiguration(),
                new GRingTerrainMeshProviderConfiguration());

            UTRing2PlateStamperProxy stamperProxy = new UTRing2PlateStamperProxy(
                new Ring2PlateStamper(new Ring2PlateStamperConfiguration()
            {
                PlateStampPixelsPerUnit = new Dictionary <int, float>()
            }, ContainerGameObject));

            _updatableContainer.AddUpdatableElement(stamperProxy);

            Ring2PatchStamplingOverseerFinalizer patchStamper =
                new Ring2PatchStamplingOverseerFinalizer(stamperProxy, textureRendererProxy, commonExecutorUtProxy);

            var gStampedRing2NodeTerrainCreator = new GStampedRing2NodeTerrainCreator(
                orderGrabber,
                terrainParentGameObject,
                meshGeneratorProxy,
                terrainShapeDbProxy,
                unityCoordsCalculator,
                new GRing2PatchesCreatorProxy(CreateRing2PatchesCreator()),
                patchStamper,
                null,
                null,
                new GRingGroundShapeProviderConfiguration(),
                new GRingTerrainMeshProviderConfiguration());

            var subCreator = new SupremeGRingNodeTerrainCreator(new List <NewListenersCreatorWithLimitation>()
            {
                //new NewListenersCreatorWithMaximumLod()
                //{
                //    Creator = gRing1NodeTerrainCreator,
                //    MaximumLod = new FlatLod(6)
                //},
                new NewListenersCreatorWithLimitation()
                {
                    Creator    = new GVoidNodeTerrainCreator(),
                    MaximumLod = new FlatLod(6)
                },
                //new NewListenersCreatorWithMaximumLod()
                //{
                //    Creator = gRing2NodeTerrainCreator,
                //    MaximumLod = new FlatLod(8)
                //}
                new NewListenersCreatorWithLimitation()
                {
                    Creator    = gStampedRing2NodeTerrainCreator,
                    MaximumLod = new FlatLod(9)
                }
            });

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

            _ring1TreeProxy = new Ring1TreeProxy(_ring1Tree);
            _otherThreadActionPairs.Add(new OtherThreadProxyAndActionPair()
            {
                Proxy           = _ring1TreeProxy,
                EveryPostAction =
                    () =>
                {
                    if (eventCollector.Any)
                    {
                        mainRespondingProxy.AddOrder(eventCollector.RetriveOrderAndClear());
                    }
                }
            });

            var baseQuadSideLength = 90f;

            StartThreading(_otherThreadActionPairs);
            _ring1TreeProxy.CreateHeightmap(new Ring1Tree.RootNodeCreationParameters()
            {
                UnityCoordsCalculator = unityCoordsCalculator,
                NodeListener          = eventCollector,
                PrecisionDistances    =
                    new Dictionary <float, int>
                {
                    //{4f * 50f/3f, 9},
                    //{4f * 50f/2f, 8},
                    { CalculatePrecisionDistance(baseQuadSideLength, 2, 1), 7 },
                    { 6.5f * 50f, 6 },
                    { 20 * 50f, 5 },
                    { 40 * 50f, 4 },
                    { 50 * 50f, 3 },
                    { 100 * 50f, 2 },
                    { 200 * 50f, 1 }
                },
                InitialCameraPosition = Vector3.zero,
            });
        }
Ejemplo n.º 13
0
 public SeparateMeshPerTemplateShapeInstancer(MeshGeneratorUTProxy meshGenerator, HeightPyramidCommonConfiguration commonConfiguration, HeightPyramidPerLevelConfiguration perLevelConfiguration)
 {
     _meshGenerator         = meshGenerator;
     _commonConfiguration   = commonConfiguration;
     _perLevelConfiguration = perLevelConfiguration;
 }
Ejemplo n.º 14
0
 public MergedMeshesPyramidShapeInstancer(MeshGeneratorUTProxy meshGenerator, HeightPyramidCommonConfiguration commonConfiguration, HeightPyramidPerLevelConfiguration perLevelConfiguration)
 {
     _meshGenerator         = meshGenerator;
     _commonConfiguration   = commonConfiguration;
     _perLevelConfiguration = perLevelConfiguration;
 }
Ejemplo n.º 15
0
        // Use this for initialization
        void Start()
        {
            _updatableContainer = new UpdatableContainer();
            TaskUtils.SetGlobalMultithreading(true);

            int minSubmapWidth = 256; //(int)Math.Floor((double)filePixelWidth/subTerrainCount)-1 ;
            var ring1Array     = SavingFileManager.LoadFromFile("map.dat", 2048, 2048);

            ring1Array = BasicHeightmapModifier.Multiply(1000, ring1Array);
            _ring1Tree = new Ring1Tree();

            //////////////////

            var tessalationRequirementTextureGenerator = new TessalationRequirementTextureGenerator();
            var tessalationReqTexture =
                tessalationRequirementTextureGenerator.GenerateTessalationRequirementTexture(ring1Array, 64);

            var heightmapBundle = SavingFileManager.LoadHeightmapBundlesFromFiles("heightmapBundle", 4, 2048);

            var submapTextures = new Ring1SubmapTextures(heightmapBundle, tessalationReqTexture);

            /// /// 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));

            _updatableContainer.AddUpdatableElement(visibilityTextureProcessorProxy);


            var visibilityTextureChangeGrabber = new Ring1VisibilityTextureChangeGrabber();

            var terrainParentGameObject = new GameObject("TerrainParent");

            var unityCoordsCalculator = new UnityCoordsCalculator(new Vector2(256, 256));
            var orderGrabber          = new Ring1PaintingOrderGrabber();

            var painterProxy = new RingTerrainPainterUTProxy(new RingTerrainPainter());

            _updatableContainer.AddUpdatableElement(painterProxy);

            painterProxy.Update();

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

            _otherThreadActionPairs.Add(new OtherThreadProxyAndActionPair()
            {
                Proxy           = mainRespondingProxy,
                EveryPostAction =
                    () =>
                {
                    var delta = visibilityTextureChangeGrabber.RetriveVisibilityChanges();

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

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

            var commonExecutor = new CommonExecutorUTProxy();

            _updatableContainer.AddUpdatableElement(commonExecutor);

            TerrainShapeDbProxy terrainShapeDbProxy = new TerrainShapeDbProxy(
                FETerrainShapeDbInitialization.CreateTerrainShapeDb(null /*todo here*/, commonExecutor, new TerrainDetailAlignmentCalculator(240),
                                                                    false, false, false, null));

            _otherThreadActionPairs.Add(new OtherThreadProxyAndActionPair()
            {
                Proxy = terrainShapeDbProxy
            });


            var meshGeneratorProxy = new MeshGeneratorUTProxy(new MeshGeneratorService());

            _updatableContainer.AddUpdatableElement(meshGeneratorProxy);

            //var eventCollector = new Ring1NodeEventCollector((node) =>
            //    new Ring1NodeDirectHeightTerrain(
            //        node,
            //        visibilityTextureChangeGrabber,
            //        visibilityTexture,
            //        terrainParentGameObject,
            //        unityCoordsCalculator,
            //        orderGrabber,
            //        terrainShapeDbProxy,
            //        ring1Array,
            //        meshGeneratorProxy));
            var eventCollector = new Ring1NodeEventCollector(new FromLambdaListenersCreator((node) =>
                                                                                            new Ring1ListenerToGRingListener(
                                                                                                new Ring1NodeShaderHeightTerrain(
                                                                                                    node,
                                                                                                    visibilityTextureChangeGrabber,
                                                                                                    visibilityTexture,
                                                                                                    terrainParentGameObject,
                                                                                                    unityCoordsCalculator,
                                                                                                    orderGrabber,
                                                                                                    terrainShapeDbProxy,
                                                                                                    meshGeneratorProxy,
                                                                                                    null)))); //todo if you want this to work

            var ring1Proxy = new Ring1TreeProxy(_ring1Tree);

            _otherThreadActionPairs.Add(new OtherThreadProxyAndActionPair()
            {
                Proxy           = ring1Proxy,
                EveryPostAction =
                    () =>
                {
                    if (eventCollector.Any)
                    {
                        mainRespondingProxy.AddOrder(eventCollector.RetriveOrderAndClear());
                    }
                }
            });

            StartThreading();
            ring1Proxy.CreateHeightmap(
                new Ring1Tree.RootNodeCreationParameters()
            {
                UnityCoordsCalculator = unityCoordsCalculator,
                NodeListener          = eventCollector,
                PrecisionDistances    = Ring1TestDefaults.PrecisionDistances,
                InitialCameraPosition = Vector3.zero,
            });
        }
Ejemplo n.º 16
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));
        }