2017-01-06 18:57:58 +00:00
|
|
|
|
using System;
|
2017-01-06 20:45:35 +00:00
|
|
|
|
using System.Collections.Generic;
|
2017-01-06 21:14:31 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2017-01-06 18:57:58 +00:00
|
|
|
|
namespace Nibriboard.RippleSpace
|
|
|
|
|
{
|
2017-01-06 19:05:27 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Represents an infinite plane.
|
|
|
|
|
/// </summary>
|
2017-01-06 18:57:58 +00:00
|
|
|
|
public class Plane
|
|
|
|
|
{
|
2017-01-06 21:14:31 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The name of this plane.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public readonly string Name;
|
|
|
|
|
|
2017-01-06 20:45:35 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The size of the chunks on this plane.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public readonly int ChunkSize;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The chunkspace that holds the currently loaded and active chunks.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected Dictionary<ChunkReference, Chunk> loadedChunkspace = new Dictionary<ChunkReference, Chunk>();
|
|
|
|
|
|
2017-01-06 21:14:31 +00:00
|
|
|
|
public Plane(string inName, int inChunkSize)
|
2017-01-06 18:57:58 +00:00
|
|
|
|
{
|
2017-01-06 21:14:31 +00:00
|
|
|
|
Name = inName;
|
2017-01-06 20:45:35 +00:00
|
|
|
|
ChunkSize = inChunkSize;
|
2017-01-06 18:57:58 +00:00
|
|
|
|
}
|
2017-01-06 21:14:31 +00:00
|
|
|
|
|
|
|
|
|
public async Task<Chunk> FetchChunk(ChunkReference chunkLocation)
|
|
|
|
|
{
|
|
|
|
|
// If the chunk is in the loaded chunk-space, then return it immediately
|
|
|
|
|
if(loadedChunkspace.ContainsKey(chunkLocation))
|
|
|
|
|
{
|
|
|
|
|
return loadedChunkspace[chunkLocation];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Uh-oh! The chunk isn't loaded at moment. Load it quick & then
|
|
|
|
|
// return it fast.
|
|
|
|
|
Chunk loadedChunk = await Chunk.FromFile(this, chunkLocation.AsFilename());
|
|
|
|
|
loadedChunkspace.Add(chunkLocation, loadedChunk);
|
|
|
|
|
|
|
|
|
|
return loadedChunk;
|
|
|
|
|
}
|
2017-01-06 18:57:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|