// 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, }); }
public void Start() { InitializeWelding(); /// /// 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)); _ultraUpdatableContainer.Add(visibilityTextureProcessorProxy); var visibilityTextureChangeGrabber = new Ring1VisibilityTextureChangeGrabber(); var terrainParentGameObject = new GameObject("TerrainParent"); terrainParentGameObject.transform.localPosition = new Vector3(0, 0, 0); var globalSideLength = _gRingConfiguration.Ring1GlobalSideLength; var globalSize = new Vector2(globalSideLength, globalSideLength); var unityCoordsCalculator = new UnityCoordsCalculator(globalSize); var orderGrabber = new Ring1PaintingOrderGrabber(); var painterProxy = new RingTerrainPainterUTProxy(new RingTerrainPainter(_gRingConfiguration.MakeTerrainVisible)); _ultraUpdatableContainer.Add(painterProxy); painterProxy.Update(); var mainRespondingProxy = new Ring1NodeEventMainRespondingProxy(new Ring1NodeEventMainResponder()); _ultraUpdatableContainer.AddOtherThreadProxy(new OtherThreadProxyWithPerPostAction() { OtherThreadProxy = mainRespondingProxy, PerPostAction = () => { var delta = visibilityTextureChangeGrabber.RetriveVisibilityChanges(); if (delta.AnyChange) { var visibilityTextureChagnes = visibilityTextureChangeGrabber.RetriveVisibilityChanges(); visibilityTextureProcessorProxy.AddOrder(visibilityTextureChagnes); } if (orderGrabber.IsAnyOrder) { painterProxy.AddOrder(orderGrabber.RetriveOrderAndClear()); } } }); var stainTerrainResourceCreatorUtProxy = new StainTerrainResourceCreatorUTProxy(new StainTerrainResourceCreator()); _ultraUpdatableContainer.Add(stainTerrainResourceCreatorUtProxy); var stainTerrainServiceProxy = new StainTerrainServiceProxy( new StainTerrainService( new FromFileStainTerrainResourceGenerator(_configuration.StainTerrainServicePath, _gameInitializationFields.Retrive <CommonExecutorUTProxy>()), //new ComputationStainTerrainResourceGenerator( // new StainTerrainResourceComposer( // _stainTerrainResourceCreatorUtProxy // ), // new StainTerrainArrayMelder(), // new DummyStainTerrainArrayFromBiomesGenerator( // new DebugBiomeContainerGenerator().GenerateBiomesContainer(new BiomesContainerConfiguration()), // new StainTerrainArrayFromBiomesGeneratorConfiguration() // )), _gRingConfiguration.Ring1GenerationArea)); _ultraUpdatableContainer.AddOtherThreadProxy(stainTerrainServiceProxy); var ring1Tree = new Ring1Tree(_gRingConfiguration.Ring1TreeConfiguration); var ring1TreeProxy = new Ring1TreeProxy(ring1Tree); _gameInitializationFields.Retrive <LateAssignBox <Ring1TreeProxy> >().Set(ring1TreeProxy); _ultraUpdatableContainer.AddOtherThreadProxy(ring1TreeProxy); var terrainShapeDbInitialization = new FETerrainShapeDbInitialization(_ultraUpdatableContainer, _gameInitializationFields, _configuration, new FilePathsConfiguration()); terrainShapeDbInitialization.Start(); var gRing0NodeTerrainCreator = new GRing0NodeTerrainCreator( orderGrabber, terrainParentGameObject, _gameInitializationFields.Retrive <MeshGeneratorUTProxy>(), _gameInitializationFields.Retrive <ITerrainShapeDb>(), unityCoordsCalculator, _gameInitializationFields.Retrive <GRingSpotUpdater>(), _gameInitializationFields.Retrive <HeightArrayWeldingPack>(), _gRingConfiguration.GroundShapeProviderConfiguration, _gRingConfiguration.TerrainMeshProviderConfiguration); var gRing1NodeTerrainCreator = new GRing1NodeTerrainCreator( orderGrabber, terrainParentGameObject, _gameInitializationFields.Retrive <MeshGeneratorUTProxy>(), _gameInitializationFields.Retrive <ITerrainShapeDb>(), stainTerrainServiceProxy, unityCoordsCalculator, _gameInitializationFields.Retrive <GRingSpotUpdater>(), _gameInitializationFields.Retrive <HeightArrayWeldingPack>(), _gRingConfiguration.GroundShapeProviderConfiguration, _gRingConfiguration.TerrainMeshProviderConfiguration); var gRing2PatchesCreatorProxy = _gameInitializationFields.Retrive <GRing2PatchesCreatorProxy>(); var gRing2NodeTerrainCreator = new GRing2NodeTerrainCreator( orderGrabber, terrainParentGameObject, _gameInitializationFields.Retrive <MeshGeneratorUTProxy>(), _gameInitializationFields.Retrive <ITerrainShapeDb>(), unityCoordsCalculator, gRing2PatchesCreatorProxy, _gameInitializationFields.Retrive <GRingSpotUpdater>(), _gameInitializationFields.Retrive <HeightArrayWeldingPack>(), _gRingConfiguration.GroundShapeProviderConfiguration, _gRingConfiguration.TerrainMeshProviderConfiguration); var gDebugNodeTerrainCreator = new GDebugLodNodeTerrainCreator( orderGrabber, terrainParentGameObject, unityCoordsCalculator, _gameInitializationFields.Retrive <MeshGeneratorUTProxy>() ); var gDebugTerrainedNodeTerrainCreator = new GDebugTerrainedLodNodeTerrainCreator( orderGrabber, terrainParentGameObject, unityCoordsCalculator, _gameInitializationFields.Retrive <MeshGeneratorUTProxy>(), _gameInitializationFields.Retrive <ITerrainShapeDb>(), _gRingConfiguration.GroundShapeProviderConfiguration, _gameInitializationFields.Retrive <GRingSpotUpdater>() ); var gStampedRing2NodeTerrainCreator = new GStampedRing2NodeTerrainCreator( orderGrabber, terrainParentGameObject, _gameInitializationFields.Retrive <MeshGeneratorUTProxy>(), _gameInitializationFields.Retrive <ITerrainShapeDb>(), unityCoordsCalculator, gRing2PatchesCreatorProxy, _gameInitializationFields.Retrive <Ring2PatchStamplingOverseerFinalizer>(), _gameInitializationFields.Retrive <GRingSpotUpdater>(), _gameInitializationFields.Retrive <HeightArrayWeldingPack>(), _gRingConfiguration.GroundShapeProviderConfiguration, _gRingConfiguration.TerrainMeshProviderConfiguration); var gCompositeRing2NodeTerrainCreator = new GCompositeRing2NodeTerrainCreator( orderGrabber, terrainParentGameObject, _gameInitializationFields.Retrive <MeshGeneratorUTProxy>(), _gameInitializationFields.Retrive <ITerrainShapeDb>(), unityCoordsCalculator, gRing2PatchesCreatorProxy, _gameInitializationFields.Retrive <GRingSpotUpdater>(), _gameInitializationFields.Retrive <HeightArrayWeldingPack>(), _gameInitializationFields.Retrive <Ring2PatchStamplingOverseerFinalizer>(), _gRingConfiguration.GroundShapeProviderConfiguration, _gRingConfiguration.TerrainMeshProviderConfiguration); //var gCompositeRing2NodeTerrainCreator = new GCompositeRing2NodeTerrainCreator( // new List<INewGRingListenersCreator>() // { // gRing2NodeTerrainCreator, // gStampedRing2NodeTerrainCreator, // }); var subCreator = new SupremeGRingNodeTerrainCreator(new List <NewListenersCreatorWithLimitation>() { //new NewListenersCreatorWithLimitation() //{ // Creator = gDebugTerrainedNodeTerrainCreator, // MaximumLod = new FlatLod(14), // //PositionLimiter = new NewListenersCreatorPositionLimiter(new Vector2(0.5f, 0.6f), 0.025f) //}, //new NewListenersCreatorWithLimitation() //{ // Creator = gRing0NodeTerrainCreator, // MaximumLod = new FlatLod(5), //}, new NewListenersCreatorWithLimitation() { Creator = new GVoidNodeTerrainCreator(), MaximumLod = new FlatLod(5), //IsFallthroughCreator = true }, new NewListenersCreatorWithLimitation() { Creator = gRing1NodeTerrainCreator, MaximumLod = new FlatLod(10) }, new NewListenersCreatorWithLimitation() { Creator = gRing2NodeTerrainCreator, MaximumLod = new FlatLod(14) }, new NewListenersCreatorWithLimitation() { Creator = gStampedRing2NodeTerrainCreator, MaximumLod = new FlatLod(13) }, new NewListenersCreatorWithLimitation() { Creator = gCompositeRing2NodeTerrainCreator, MaximumLod = new FlatLod(14) } //new NewListenersCreatorWithLimitation() //{ // Creator = gDebugNodeTerrainCreator, // MaximumLod = new FlatLod(11) //}, }); var eventCollector = new Ring1NodeEventCollector( new DynamicFlatLodGRingNodeTerrainCreator(subCreator, new FlatLodCalculator(unityCoordsCalculator, _gRingConfiguration.FlatLodConfiguration))); _ultraUpdatableContainer.AddOtherThreadProxy( new OtherThreadProxyWithPerPostAction() { OtherThreadProxy = ring1TreeProxy, PerPostAction = () => { if (eventCollector.Any) { mainRespondingProxy.AddOrder(eventCollector.RetriveOrderAndClear()); } } } ); var repositioner = _gameInitializationFields.Retrive <Repositioner>(); _ultraUpdatableContainer.AddUpdatableElement(new FieldBasedUltraUpdatable() { UpdateCameraField = (camera) => { if (_configuration.UpdateRingTree) { ring1TreeProxy.UpdateCamera(FovData.FromCamera(camera, repositioner)); } } }); _ultraUpdatableContainer.AddUpdatableElement(new FieldBasedUltraUpdatable() { StartCameraField = (camera) => { ring1TreeProxy.CreateHeightmap( new Ring1Tree.RootNodeCreationParameters() { InitialCameraPosition = repositioner.InvMove(camera.Position), NodeListener = eventCollector, PrecisionDistances = _gRingConfiguration.QuadLodPrecisionDistances, UnityCoordsCalculator = unityCoordsCalculator }); } }); }