2017-01-06 18:57:58 +00:00
|
|
|
|
using System;
|
2017-01-06 21:14:31 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
2017-01-06 18:57:58 +00:00
|
|
|
|
namespace Nibriboard.RippleSpace
|
|
|
|
|
{
|
2017-01-06 19:05:27 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Represents a single chunk of an infinite <see cref="Nibriboard.RippleSpace.Plane" />.
|
|
|
|
|
/// </summary>
|
2017-01-06 21:14:31 +00:00
|
|
|
|
public class Chunk : IEnumerable<DrawnLine>
|
2017-01-06 18:57:58 +00:00
|
|
|
|
{
|
2017-01-06 21:14:31 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The lines that this chunk currently contains.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private List<DrawnLine> lines = new List<DrawnLine>();
|
|
|
|
|
|
2017-01-06 20:48:53 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The plane that this chunk is located on.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public readonly Plane Plane;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The size of this chunk.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public readonly int Size;
|
|
|
|
|
|
2017-01-06 21:14:31 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The time at which this chunk was loaded.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public readonly DateTime TimeLoaded = DateTime.Now;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The time at which this chunk was last accessed.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public DateTime TimeLastAccessed { get; private set; } = DateTime.Now;
|
|
|
|
|
|
2017-01-06 20:48:53 +00:00
|
|
|
|
public Chunk(Plane inPlane, int inSize)
|
2017-01-06 18:57:58 +00:00
|
|
|
|
{
|
2017-01-06 20:48:53 +00:00
|
|
|
|
Plane = inPlane;
|
|
|
|
|
Size = inSize;
|
2017-01-06 18:57:58 +00:00
|
|
|
|
}
|
2017-01-06 21:14:31 +00:00
|
|
|
|
|
|
|
|
|
public void UpdateAccessTime()
|
|
|
|
|
{
|
|
|
|
|
TimeLastAccessed = DateTime.Now;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DrawnLine this[int i]
|
|
|
|
|
{
|
|
|
|
|
get {
|
|
|
|
|
UpdateAccessTime();
|
|
|
|
|
return lines[i];
|
|
|
|
|
}
|
|
|
|
|
set {
|
|
|
|
|
UpdateAccessTime();
|
|
|
|
|
lines[i] = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerator<DrawnLine> GetEnumerator()
|
|
|
|
|
{
|
|
|
|
|
UpdateAccessTime();
|
|
|
|
|
return lines.GetEnumerator();
|
|
|
|
|
}
|
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
|
|
|
{
|
|
|
|
|
UpdateAccessTime();
|
|
|
|
|
return GetEnumerator();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async Task<Chunk> FromFile(Plane plane, string filename)
|
|
|
|
|
{
|
|
|
|
|
StreamReader chunkSource = new StreamReader(filename);
|
|
|
|
|
return await FromStream(plane, chunkSource);
|
|
|
|
|
}
|
|
|
|
|
public static async Task<Chunk> FromStream(Plane plane, StreamReader chunkSource)
|
|
|
|
|
{
|
|
|
|
|
Chunk result = new Chunk(
|
|
|
|
|
plane,
|
|
|
|
|
int.Parse(chunkSource.ReadLine())
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
string nextLine = string.Empty;
|
|
|
|
|
while((nextLine = await chunkSource.ReadLineAsync()) != null)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2017-01-06 18:57:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|