1
0
Fork 0

[server] Rework ChunkUpdateRequest logic

This commit is contained in:
Starbeamrainbowlabs 2017-06-24 20:14:43 +01:00
parent 334acdbc18
commit 55cdcf982c
3 changed files with 21 additions and 3 deletions

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using Nibriboard.RippleSpace; using Nibriboard.RippleSpace;
namespace Nibriboard.Client.Messages namespace Nibriboard.Client.Messages
@ -10,10 +11,26 @@ namespace Nibriboard.Client.Messages
/// A list of chunks that the client has intentionally forgotten about, and will need /// A list of chunks that the client has intentionally forgotten about, and will need
/// to be resent to the client. /// to be resent to the client.
/// </summary> /// </summary>
public List<dynamic> ForgottenChunks = new List<dynamic>(); public List<RawChunkReference> ForgottenChunks = new List<RawChunkReference>();
public ChunkUpdateRequestMessage() public ChunkUpdateRequestMessage()
{ {
} }
public List<ChunkReference> ForgottenChunksAsReferences(Plane plane)
{
List<ChunkReference> result = new List<ChunkReference>();
foreach(RawChunkReference rawRef in ForgottenChunks)
{
if(rawRef.planeName as string != plane.Name)
throw new InvalidDataException($"Error: A raw reference was for the plane " +
"'{rawRef.planeName}', but the plane '{plane.Name}' " +
"was specified as the plane to lay the chunk references onto!");
result.Add(new ChunkReference(plane, rawRef.x, rawRef.y));
}
return result;
}
} }
} }

View File

@ -354,12 +354,12 @@ namespace Nibriboard.Client
/// <param name="message">The message to process.</param> /// <param name="message">The message to process.</param>
protected async Task handleChunkUpdateRequestMessage(ChunkUpdateRequestMessage message) protected async Task handleChunkUpdateRequestMessage(ChunkUpdateRequestMessage message)
{ {
chunkCache.Remove(message.ForgottenChunks); chunkCache.Remove(message.ForgottenChunksAsReferences(this.CurrentPlane));
ChunkUpdateMessage response = new ChunkUpdateMessage(); ChunkUpdateMessage response = new ChunkUpdateMessage();
List<ChunkReference> missingChunks = ChunkTools.GetContainingChunkReferences(CurrentPlane, CurrentViewPort); List<ChunkReference> missingChunks = ChunkTools.GetContainingChunkReferences(CurrentPlane, CurrentViewPort);
missingChunks = chunkCache.FindMissing(missingChunks); missingChunks = chunkCache.FindMissing(missingChunks);
response.Chunks = await CurrentPlane.FetchChunks(missingChunks); response.Chunks = await CurrentPlane.FetchChunks(missingChunks);
Send(response); Send(response);

View File

@ -100,6 +100,7 @@
<Compile Include="Client\Messages\LineCompleteMessage.cs" /> <Compile Include="Client\Messages\LineCompleteMessage.cs" />
<Compile Include="Client\Messages\ErrorMessage.cs" /> <Compile Include="Client\Messages\ErrorMessage.cs" />
<Compile Include="Client\Messages\PlaneChangeOkMessage.cs" /> <Compile Include="Client\Messages\PlaneChangeOkMessage.cs" />
<Compile Include="Client\RawChunkReference.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="ClientFiles\index.html" /> <EmbeddedResource Include="ClientFiles\index.html" />