private void ExecuteAddScene() { var scene = new Scene(); var sceneViewModel = new SceneViewModel { Index = SceneViewModels.Count + 1, Scene = scene }; Story.Scenes.Add(scene); SceneViewModels.Add(sceneViewModel); }
public void CreateSceneViewModel(object parameter) { var sceneViewModel = new SceneViewModel(@"C:\Repos\NovahTracer\Source\Novah.Tracer.Client\Scenes\LensScene.xml", 1920, 1080, 1080 / 10); SceneViewModels.Add(sceneViewModel); foreach (var chunk in sceneViewModel.Scene.Chunks) { ChunksToProcess.Add(chunk); } }
private void ExecuteMoveSceneDown(ISceneViewModel sceneViewModel) { var index = SceneViewModels.IndexOf(sceneViewModel); if (index < SceneViewModels.Count - 1) { SceneViewModels.Move(index, index + 1); SceneViewModels[index].Index--; sceneViewModel.Index++; } }
private void ExecuteMoveSceneUp(ISceneViewModel sceneViewModel) { var index = SceneViewModels.IndexOf(sceneViewModel); if (index > 0) { SceneViewModels.Move(index, index - 1); SceneViewModels[index].Index++; sceneViewModel.Index--; } }
public void CreateSceneViewModel(object parameter) { var sceneViewModel = new SceneViewModel(@"C:\Repos\Pix\Source\TestScene.xml", 640, 480, 480 / 2); SceneViewModels.Add(sceneViewModel); var random = new Random(); foreach (var chunk in sceneViewModel.Scene.Chunks.OrderBy(_ => random)) { ChunksToProcess.Add(chunk); } }
public async void HandleConnection(TcpClient client) { var messageReader = new MessageReader(client); var chunksBeingProcessed = new List <Chunk>(); try { while (true) { var message = await messageReader.GetMessage(); if (message == null) { break; // Client disconnected; remove client from the list of active clients. } if (message is ChunkRequestedMessage) { var chunkToProcess = ChunksToProcess.Take(); chunksBeingProcessed.Add(chunkToProcess); chunkToProcess.IsBeingWorkedOn = true; var networkStream = client.GetStream(); using (var writer = new BinaryWriter(networkStream, Encoding.Default, true)) { var sceneAsBytes = Encoding.ASCII.GetBytes(chunkToProcess.Scene.SceneXml); writer.Write((int)SendMessageType.ChunkSentForProcessing); writer.Write(sizeof(int) * 6 + sceneAsBytes.Length + 1); writer.Write(chunkToProcess.Scene.SceneId); writer.Write(chunkToProcess.ChunkId); writer.Write(chunkToProcess.Width); writer.Write(chunkToProcess.Scene.Height); writer.Write(chunkToProcess.Height); writer.Write(chunkToProcess.StartY); writer.Write(sceneAsBytes); writer.Write((byte)0); writer.Flush(); } } else if (message is ChunkCompletedMessage) { var chunkCompletedMessage = (ChunkCompletedMessage)message; var sceneViewModel = SceneViewModels.SingleOrDefault(x => x.Scene.SceneId == chunkCompletedMessage.SceneId); var chunk = sceneViewModel?.Scene.Chunks.SingleOrDefault(x => x.ChunkId == chunkCompletedMessage.ChunkId); if (chunk != null) { chunksBeingProcessed.Remove(chunk); chunk.IsBeingWorkedOn = false; chunk.IsCompleted = true; sceneViewModel.UpdateChunk(chunk, chunkCompletedMessage.ColorData); } } } } catch { } finally { Clients.Remove(client); foreach (var chunk in chunksBeingProcessed) // Add any unfinished chunks back into the work queue. { ChunksToProcess.Add(chunk); } } }
private void ExecuteDeleteScene(ISceneViewModel sceneViewModel) { SceneViewModels.Remove(sceneViewModel); Story.Scenes.Remove(sceneViewModel.Scene); }
public async void HandleConnection(TcpClient client) { var messageReader = new MessageReader(client); var chunksBeingProcessed = new List <Chunk>(); try { while (true) { var message = await messageReader.GetMessage(); if (message == null) { break; // Client disconnected; remove client from the list of active clients. } switch (message) { case RequestChunkMessage _: var chunkToProcess = ChunksToProcess.Take(); chunksBeingProcessed.Add(chunkToProcess); chunkToProcess.IsBeingWorkedOn = true; var networkStream = client.GetStream(); var chunkToProcessMessage = new ChunkToProcessMessage( chunkToProcess.Scene.SceneId, chunkToProcess.ChunkId, chunkToProcess.Width, chunkToProcess.Scene.Height, chunkToProcess.Height, chunkToProcess.StartY, chunkToProcess.MaxSubPixelX, chunkToProcess.MaxSubPixelY, chunkToProcess.SubPixelStartX, chunkToProcess.SubPixelStartY, chunkToProcess.SubPixelEndX, chunkToProcess.SubPixelEndY, chunkToProcess.Scene.SceneXml); var messageBytes = chunkToProcessMessage.ToBytes(); await networkStream.WriteAsync(messageBytes, 0, messageBytes.Length); break; case ChunkCompletedMessage chunkCompletedMessage: var sceneViewModel = SceneViewModels.SingleOrDefault(x => x.Scene.SceneId == chunkCompletedMessage.SceneId); var chunk = sceneViewModel?.Scene.Chunks.SingleOrDefault(x => x.ChunkId == chunkCompletedMessage.ChunkId); if (chunk != null) { chunksBeingProcessed.Remove(chunk); chunk.IsBeingWorkedOn = false; chunk.IsCompleted = true; sceneViewModel.Scene.UpdateChunk(chunk, chunkCompletedMessage.ColorData); sceneViewModel.UpdateChunk(chunk); } break; } } } catch { } finally { if (Clients.Contains(client)) { Clients.Remove(client); } foreach (var chunk in chunksBeingProcessed) // Add any unfinished chunks back into the work queue. { ChunksToProcess.Add(chunk); } } }