public void Initialise(IVoxelTypeManager voxelTypeManager, IChunkManager chunkManager, IHeightMapProvider heightMapProvider) { this.chunkManager = chunkManager; this.voxelTypeManager = voxelTypeManager; this.heightMapProvider = heightMapProvider; chunkDimensions = chunkManager.ChunkDimensions; pendingLightUpdatesByChunk = new Dictionary <Vector3Int, ChunkUpdateRequest>(); pendingLightUpdatesOrder = new Queue <Vector3Int>(); chunksWhereLightChangedOnBorderSinceLastUpdate = new HashSet <Vector3Int>(); List <int> emissions = new List <int>(); List <int> absorptions = new List <int>(); for (ushort i = 0; i <= voxelTypeManager.LastVoxelID; i++) { var(emission, absorption) = voxelTypeManager.GetLightProperties((VoxelTypeID)i); emissions.Add(emission); absorptions.Add(absorption); } voxelTypeToEmissionMap = emissions.ToArray().ToNative(Allocator.Persistent); voxelTypeToAbsorptionMap = absorptions.ToArray().ToNative(Allocator.Persistent); int3[] dVecs = new int3[DirectionExtensions.numDirections]; for (int i = 0; i < DirectionExtensions.numDirections; i++) { dVecs[i] = DirectionExtensions.Vectors[i].ToNative(); } directionVectors = dVecs.ToNative(Allocator.Persistent); }
public void Initialise(IVoxelTypeManager voxelTypeManager, IChunkManager chunkManager, IHeightMapProvider heightMapProvider) { var lm = new LightManager(); lm.Parallel = parallel; lm.MaxChunksGeneratedPerUpdate = MaxChunksGeneratedPerUpdate; lm.MaxLightUpdates = MaxPropPerUpdate; lightManager = lm; lightManager.Initialise(voxelTypeManager, chunkManager, heightMapProvider); }
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); }