示例#1
0
        public void Reset()
        {
            EditorSceneManager.NewScene(NewSceneSetup.EmptyScene);
            mockMesher           = new MockMesher(mockGetComponent);
            mockMesher.CullFaces = true;//by default mesher is dependent on neighbour, as only the naive mesher is not
            mockProvider         = new MockProvider();
            mockComponentStorage = new Dictionary <Vector3Int, MockChunkComponent>();
            mockPlayChunkID      = Vector3Int.zero;
            mockLightManager     = Substitute.For <ILightManager>();
            mockLightManager.CreateGenerationJob(Arg.Any <Vector3Int>())
            .Returns(args =>
            {
                return(new BasicFunctionJob <LightmapGenerationJobResult>(() => new LightmapGenerationJobResult()));
            });

            mockManager = Substitute.For <IChunkManager>();
            mockManager.GetChunkComponent(Arg.Any <Vector3Int>())
            .Returns(args =>
            {
                var chunkId = (Vector3Int)args[0];
                return(mockGetComponent(chunkId));
            });
            mockManager.GetManhattanDistanceFromPlayer(Arg.Any <Vector3Int>())
            .Returns(args => {
                var chunkId = (Vector3Int)args[0];
                return(MockGetPriorityOfChunk(chunkId));
            });
            worldLimits = new WorldSizeLimits(false, 0);
            worldLimits.Initalise();
            mockManager.WorldLimits.Returns(worldLimits);
        }
示例#2
0
        public void SetTargetOfOutOfBoundsChunk()
        {
            worldLimits = new WorldSizeLimits(true, 8);
            worldLimits.Initalise();
            mockManager.WorldLimits.Returns(worldLimits);
            MakePipeline(1000, 1, 1, true, includeLighting: true);

            var testChunkID = new Vector3Int(0, 8, 0);//This chunk is outside the vertical limits

            mockComponentStorage.Add(testChunkID, new MockChunkComponent()
            {
                ChunkID = testChunkID, Data = Substitute.For <IChunkData>()
            });
            pipeline.AddWithData(testChunkID, pipeline.FullyGeneratedStage);

            AssertChunkStages(testChunkID, pipeline.FullyGeneratedStage);

            pipeline.SetTarget(testChunkID, pipeline.OwnStructuresStage);

            pipeline.Update();

            //Nothing should have been downgraded, as the chunk is outside the vertical limits
            AssertChunkStages(testChunkID, pipeline.FullyGeneratedStage);
        }
示例#3
0
        public void Reset()
        {
            maxIntensity    = LightValue.MaxIntensity;
            heightMapYValue = 0;
            chunkDimensions = new Vector3Int(16, 16, 16);
            chunkStorage    = new Dictionary <Vector3Int, IChunkData>();

            lampId           = (VoxelTypeID)1;
            blockerId        = (VoxelTypeID)2;
            voxelTypeManager = Substitute.For <IVoxelTypeManager>();
            voxelTypeManager.LastVoxelID.Returns(blockerId);
            voxelTypeManager.GetLightProperties(Arg.Any <VoxelTypeID>())
            .Returns((args) =>
            {
                var typeId = (VoxelTypeID)args[0];
                if (typeId.Equals(lampId))
                {
                    return(maxIntensity, maxIntensity);
                }
                else if (typeId.Equals(blockerId))
                {
                    return(0, maxIntensity);
                }
                return(0, 1);
            });

            fullyGenerated = new HashSet <Vector3Int>();
            chunkManager   = Substitute.For <IChunkManager>();
            chunkManager.IsChunkFullyGenerated(Arg.Any <Vector3Int>())
            .Returns((args) =>
            {
                var id = (Vector3Int)args[0];
                return(fullyGenerated.Contains(id));
            });

            var worldLimits = new WorldSizeLimits(false, 0);

            worldLimits.Initalise();
            chunkManager.WorldLimits.Returns(worldLimits);

            chunkManager.ChunkToWorldPosition(Arg.Any <Vector3Int>())
            .Returns((args) =>
            {
                var chunkId = (Vector3Int)args[0];
                return(chunkId * chunkDimensions);
            });

            chunkManager.GetReadOnlyChunkData(Arg.Any <Vector3Int>())
            .Returns((args) =>
            {
                var chunkId = (Vector3Int)args[0];
                return(new RestrictedChunkData(GetMockChunkData(chunkId)));
            });

            chunkManager.GetChunkData(Arg.Any <Vector3Int>())
            .Returns((args) =>
            {
                var chunkId = (Vector3Int)args[0];
                return(GetMockChunkData(chunkId));
            });

            chunkManager.ChunkDimensions.Returns(chunkDimensions);

            IHeightMapProvider heightMapProvider = Substitute.For <IHeightMapProvider>();

            heightMapProvider.GetHeightMapForColumn(Arg.Any <Vector2Int>())
            .Returns((args) =>
            {
                return(getFlatHeightMap(heightMapYValue));
            });

            lightManager = new LightManager();
            lightManager.Initialise(voxelTypeManager, chunkManager, heightMapProvider);
        }
示例#4
0
        private void SetupMocks(Vector3Int chunkDimensions, WorldSizeLimits worldSizeLimits = null, bool generateStructures = true)
        {
            if (worldSizeLimits == null)
            {
                worldSizeLimits = new WorldSizeLimits(false, 0);
                worldSizeLimits.Initalise();
            }


            mockManager = Substitute.For <IChunkManager>();
            mockManager.GenerateStructures.Returns(generateStructures);
            mockManager.WorldToChunkPosition(Arg.Any <Vector3>()).Returns(args => WorldToChunkPos((Vector3)args[0], chunkDimensions));

            mockManager.WorldLimits.Returns(worldSizeLimits);
            mockManager.GetAllLoadedChunkIds().Returns((_) => statusMap.Keys.ToArray());

            mockPipeline = Substitute.For <IChunkPipeline>();
            mockPipeline.TerrainDataStage.Returns(0);
            mockPipeline.OwnStructuresStage.Returns(1);
            mockPipeline.FullyGeneratedStage.Returns(2);
            mockPipeline.RenderedStage.Returns(3);
            mockPipeline.CompleteStage.Returns(4);

            statusMap = new Dictionary <Vector3Int, int>();

            //Mock set target to write to the status map instead
            mockManager
            .When(_ => _.SetTargetStageOfChunk(Arg.Any <Vector3Int>(), Arg.Any <int>(), Arg.Any <TargetUpdateMode>()))
            .Do(args =>
            {
                Vector3Int pos = (Vector3Int)args[0];
                int newStatus  = (int)args[1];
                var mode       = (TargetUpdateMode)args[2];

                if (statusMap.TryGetValue(pos, out var currentStatus))
                {    //If the pos exists, ensure update modes are respected
                    if (newStatus > currentStatus && mode.allowsUpgrade())
                    {
                        statusMap[pos] = newStatus;
                    }
                    else if (newStatus < currentStatus && mode.allowsDowngrade())
                    {
                        statusMap[pos] = newStatus;
                    }
                }
                else
                {    //Otherwise, add the new pos and status
                    statusMap[pos] = newStatus;
                }
            });

            //Mock deactivate to remove from the status map
            mockManager
            .When(_ => _.TryDeactivateChunk(Arg.Any <Vector3Int>()))
            .Do(args =>
            {
                Vector3Int pos = (Vector3Int)args[0];
                statusMap.Remove(pos);
            });

            player          = Substitute.For <IVoxelPlayer>();
            player.Position = Vector3.zero;
        }