1
0
Fork 0

[server] Get nibri clients to listen for chunk updates and send them down the wire

This commit is contained in:
Starbeamrainbowlabs 2017-04-16 15:19:59 +01:00
parent ce3197dd98
commit 48c2011500
1 changed files with 28 additions and 3 deletions

View File

@ -288,16 +288,28 @@ namespace Nibriboard.Client
/// </summary>
protected Task handlePlaneChangeMessage(PlaneChangeMessage message)
{
// Create a new plane with the specified name if it doesn't exist already
if(manager.SpaceManager[message.NewPlaneName] == default(Plane))
throw new NotImplementedException(); // todo create a new plane here
throw new NotImplementedException("Plane creation hasn't been implemented yet"); // todo create a new plane here
// Remove the event listener from the old plane if there is indeed an old plane to remove it from
if(CurrentPlane != null)
CurrentPlane.OnChunkUpdate -= handleChunkUpdateEvent;
// Swap out the current plane
CurrentPlane = manager.SpaceManager[message.NewPlaneName];
// Attach a listener to the new plane
CurrentPlane.OnChunkUpdate += handleChunkUpdateEvent;
// Tell the client that the switchove all went according to plan
message.IsOK = true;
Send(message);
return Task.CompletedTask;
}
/// <summary>
/// Handles requests from clients for chunk updates.
/// </summary>
/// <param name="message">The message to process.</param>
protected async Task handleChunkUpdateRequestMessage(ChunkUpdateRequestMessage message)
{
chunkCache.Remove(message.ForgottenChunks);
@ -316,6 +328,7 @@ namespace Nibriboard.Client
/// <summary>
/// Handles an incoming cursor position message from the client..
/// </summary>
/// <param name="message">The message to process.</param>
protected Task handleCursorPositionMessage(CursorPositionMessage message) {
AbsoluteCursorPosition = message.AbsCursorPosition;
@ -361,6 +374,18 @@ namespace Nibriboard.Client
#endregion
#region RippleSpace Event Handlers
protected void handleChunkUpdateEvent(object sender, ChunkUpdateEventArgs eventArgs)
{
ChunkUpdateMessage clientNotification = new ChunkUpdateMessage() {
Chunks = new List<Chunk>() { sender as Chunk }
};
Send(clientNotification);
}
#endregion
/// <summary>
/// Generates an update message that contains information about the locations and states of all connected clients.