/// <summary> /// Initializes a new instance of the <see cref="ChunkCache"/> class. /// </summary> /// <param name="game">The game.</param> /// <param name="maxMapsInMemory">The maximum maps in memory.</param> public ChunkCache(int maxMapsInMemory = 100) // TODO: Don't leave it at 100 { // Setters MaxChunksInMemory = maxMapsInMemory; _chunkWidth = Core.Engine.Instance.Configuration.Chunk.WidthInTiles * 32; // 32 pixels _chunkHeight = Core.Engine.Instance.Configuration.Chunk.HeightInTiles * 32; // 32 pixels _chunkGenerator = new SimpleTerrain(); ChunkStorage = new ChunkStorage(); }
/// <summary> /// Preloads the chunk at the world quadrant. /// </summary> /// <param name="worldQuadrant">The world quadrant.</param> public void PreloadChunkAt(Point worldQuadrant) { // If the storage contains the chunk at worldquadrant if (!ChunkStorage.ContainsKey(worldQuadrant)) { // Load/create missing chunk LoadOrCreateMissingChunk(worldQuadrant); } }
/// <summary> /// Gets the chunk at the world quadrant. /// </summary> /// <param name="worldQuadrant">The world quadrant.</param> /// <returns></returns> public Chunk GetChunkAt(Point worldQuadrant) { // Pre load the chunk PreloadChunkAt(worldQuadrant); // If the chunk exists in the storage if (ChunkStorage.ContainsKey(worldQuadrant)) { // Return the chunk return(ChunkStorage[worldQuadrant]); } else { return(null); } }
/// <summary> /// Unloads the chunk at the world quadrant. /// </summary> /// <param name="worldQuadrant">The world quadrant.</param> public void UnloadChunkAt(Point worldQuadrant) { // Remove from storage ChunkStorage.Remove(worldQuadrant); }