Ejemplo n.º 1
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.º 2
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,
            });
        }