public void IsSplatmapStored() { var heightmap = new HeightmapDto(); var splatmap = new SplatmapDto(); var mockHeightmapGenerator = new Mock <IDiamondSquareGenerator>(); mockHeightmapGenerator.Setup(x => x.Generate( It.IsAny <int>(), It.IsAny <float>(), It.IsAny <float>(), It.IsAny <int?>() )).Returns(heightmap); var mockSplatmapGenerator = new Mock <IHeightBasedSplatmapGenerator>(); mockSplatmapGenerator.Setup(x => x.Generate( It.IsAny <float[, ]>(), It.IsAny <float>(), It.IsAny <float>(), It.IsAny <float>() )).Returns(splatmap); var mockRepository = new Mock <IRepository>(); var terrainService = new TerrainService(mockRepository.Object, mockSplatmapGenerator.Object, null, mockHeightmapGenerator.Object, null); var id = terrainService.Generate(new DiamondSquareHeightmapRequestDto { Size = 17, OffsetRange = 10, OffsetReductionRate = 0.5f }); mockRepository.Verify(mock => mock.AddSplatmap(splatmap), Times.Once()); }
private void GenerateSplatmap(HeightmapDto heightmapDto) { var splatmap = heightBasedSplatmapGenerator.Generate(heightmapDto.HeightmapOriginalArray, 0.3f, 0.17f, 0.16f); splatmap.Id = heightmapDto.Id; repository.AddSplatmap(splatmap); }
public void AddHeightmap(HeightmapDto heightmapDto) { var heightmap = new Heightmap { Id = heightmapDto.Id, Width = heightmapDto.Width, Height = heightmapDto.Height, OverlappedSize = heightmapDto.OverlappedSize, HeightmapByteArray = heightmapDto.HeightmapByteArray, }; heightmaps.Add(heightmapDto.Id, heightmap); }
private Guid CreateHeightmap(HeightmapDto heightmapDto) { var id = Guid.NewGuid(); heightmapDto.Id = id; repository.AddHeightmap(heightmapDto); GenerateSplatmap(heightmapDto); repository.SaveChanges(); return(id); }
public HeightmapDto GetTestSteepnessMap(HeightmapDto heightmapDto) { int width = heightmapDto.Width; int height = heightmapDto.Height; float[,] steepnessMap = GetSteepnessMap(heightmapDto.HeightmapOriginalArray); return(new HeightmapDto { Width = width, Height = height, HeightmapOriginalArray = steepnessMap, HeightmapByteArray = BitmapHelper.WriteToByteArray(steepnessMap) }); }
public void IsHeightmapChunkGenerated() { Guid id = Guid.NewGuid(); int offsetX = 5; int offsetZ = 6; HeightmapDto heightmapDto = new HeightmapDto(); var mockGenerator = new Mock <IOpenSimplexGenerator>(); mockGenerator.Setup(x => x.Generate( It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <float>(), It.IsAny <int>(), It.IsAny <float>(), It.IsAny <float>(), It.IsAny <int>(), It.IsAny <int>() )).Returns(heightmapDto); var mockRepository = new Mock <IRepository>(); mockRepository.Setup(x => x.IsHeightmapChunkExists( It.Is <Guid>(i => i == id), It.Is <int>(i => i == offsetX), It.Is <int>(i => i == offsetZ) )).Returns(false); mockRepository.Setup(x => x.GetBaseHeightmapChunk( It.Is <Guid>(i => i == id) )).Returns(new BaseHeightmapChunkDto()); var terrainService = new TerrainService(mockRepository.Object, null, null, null, mockGenerator.Object); terrainService.GetHeightmapChunk(id, offsetX, offsetZ); mockRepository.Verify(mock => mock.AddHeightmapChunk(id, offsetX, offsetZ, heightmapDto), Times.Once()); }
public void AddHeightmapChunk(Guid baseChunkId, int offsetX, int offsetZ, HeightmapDto heightmapDto) { var baseChunk = baseHeightmapChunks[baseChunkId]; if (baseChunk == null) { throw new PtgNotFoundException("Chunk not found"); } baseChunk.ChildChunks.Add(new HeightmapChunk { OffsetX = offsetX, OffsetZ = offsetZ, Heightmap = new Heightmap { Id = heightmapDto.Id, Width = heightmapDto.Width, Height = heightmapDto.Height, OverlappedSize = heightmapDto.OverlappedSize, HeightmapByteArray = heightmapDto.HeightmapByteArray, } }); }