// assumed to be run on the main thread private async void MainLoop() { var sw = new Stopwatch(); sw.Start(); while (sending) { game.ApplyInputs( (await Task.WhenAll(localPlayers.Read().Select(x => (x.input.Next())).ToArray())).ToDictionary(x => x.Id, x => x)); await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync( CoreDispatcherPriority.Normal, () => { CanvasLeft.Invalidate(); CanvasRight.Invalidate(); }); frame.thing++; while ((1000.0 * frame.thing / 60.0) > sw.ElapsedMilliseconds) { } //await Task.Delay(1); // let someone else have a go //await Task.Delay((int)Math.Max(0, (1000.0 * frame.frame / 60.0) - sw.ElapsedMilliseconds)); } StoppedSending.SetResult(true); }
public async Task SaveRoomInToFile(Windows.Storage.CreationCollisionOption openType = Windows.Storage.CreationCollisionOption.OpenIfExists) { Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder; Windows.Storage.StorageFile roomFile = await storageFolder.CreateFileAsync("Rooms.txt", openType); await Windows.Storage.FileIO.AppendTextAsync(roomFile, Name + "|" + CanvasLeft.ToString() + "|" + CanvasTop.ToString() + "|" + Height.ToString() + "|" + Width.ToString() + "|" + Auto.ToString() + "|" + OnLevel.ToString() + "|\n"); return; }
private void CanvasRight_OnLoaded(object sender, RoutedEventArgs e) { //Ellipse EllipsePoint = new Ellipse(); //EllipsePoint.Stroke = brush; //EllipsePoint.Width = 3; //EllipsePoint.Height = 3; //EllipsePoint.StrokeThickness = 2; //Canvas.SetLeft(EllipsePoint, BitmapSize * item[0]); //Canvas.SetTop(EllipsePoint, BitmapSize * item[1]); //CanvasLeft.Children.Add(EllipsePoint); /// var brush = new SolidColorBrush(Colors.Black); foreach (var item in PointsList) { Ellipse EllipsePoint = new Ellipse(); EllipsePoint.Stroke = brush; EllipsePoint.Width = 10; EllipsePoint.Height = 10; EllipsePoint.StrokeThickness = 5; Canvas.SetLeft(EllipsePoint, BitmapSize * item[0]); Canvas.SetTop(EllipsePoint, BitmapSize * item[1]); CanvasLeft.Children.Add(EllipsePoint); EllipsePoint = new Ellipse(); EllipsePoint.Stroke = brush; EllipsePoint.Width = 10; EllipsePoint.Height = 10; EllipsePoint.StrokeThickness = 5; Canvas.SetLeft(EllipsePoint, BitmapSize * item[2]); Canvas.SetTop(EllipsePoint, BitmapSize * item[3]); CanvasRight.Children.Add(EllipsePoint); //Line L = new Line(); //L.Stroke = new SolidColorBrush(Colors.Black); //L.X1 = 0; //L.X2 = 0; //L.Y1 = 0; //L.Y2 = 400; //L.StrokeThickness = 2; //CanvasRight.Children.Add(L); } //////Ellipse EllipsePoint1 = new Ellipse(); //////EllipsePoint1.Stroke = brush; //////EllipsePoint1.Width = 10; //////EllipsePoint1.Height = 10; //////EllipsePoint1.StrokeThickness = 5; //////Canvas.SetLeft(EllipsePoint1, BitmapSize * SideDeteriminantPoint[0]); //////Canvas.SetTop(EllipsePoint1, BitmapSize * SideDeteriminantPoint[1]); //////CanvasLeft.Children.Add(EllipsePoint1); //////EllipsePoint1 = new Ellipse(); //////EllipsePoint1.Stroke = brush; //////EllipsePoint1.Width = 10; //////EllipsePoint1.Height = 10; //////EllipsePoint1.StrokeThickness = 5; //////Canvas.SetLeft(EllipsePoint1, BitmapSize * SideDeteriminantPoint[2]); //////Canvas.SetTop(EllipsePoint1, BitmapSize * SideDeteriminantPoint[3]); //////CanvasRight.Children.Add(EllipsePoint1); //Line L; Rectangle R; //double epsilonToSnapBoder = 0.009; //for (int i = 0; i < PointsList.Count; i++) //{ //R = new Rectangle(); //R.StrokeThickness = 2; //Ustawić jako proporcjonalna do newton forward step //R.Width = 400; //R.Height = 400; //R.Stroke = brush; //CanvasLeft.Children.Add(R); //R = new Rectangle(); //R.StrokeThickness = 1; //Ustawić jako proporcjonalna do newton forward step //R.Width = 400; //R.Height = 400; //R.Stroke = brush; //CanvasRight.Children.Add(R); // //if (Math.Abs(PointsList[i][0]) >= epsilonToSnapBoder && // // Math.Abs(PointsList[i][0] - 1) >= epsilonToSnapBoder && // // Math.Abs(PointsList[i][1]) >= epsilonToSnapBoder && // // Math.Abs(PointsList[i][1] - 1) >= epsilonToSnapBoder) // //{ // L = new Line(); // L.Stroke = brush; // L.StrokeThickness = 2; // L.X1 = PointsList[i][0] * BitmapSize; // L.Y1 = PointsList[i][1] * BitmapSize; // //if (Math.Abs(PointsList[i][0]) >= epsilonToSnapBoder)// && // // Math.Abs(PointsList[i][0] - 1) >= epsilonToSnapBoder && // // Math.Abs(PointsList[i][1]) >= epsilonToSnapBoder && // // Math.Abs(PointsList[i][1] - 1) >= epsilonToSnapBoder) // if (Math.Abs(PointsList[i][0]) >= epsilonToSnapBoder && // Math.Abs(PointsList[i][0] - 1) >= epsilonToSnapBoder && // Math.Abs(PointsList[i][1]) >= epsilonToSnapBoder && // Math.Abs(PointsList[i][1] - 1) >= epsilonToSnapBoder) // { // if (i < PointsList.Count - 1) // { // L.X2 = PointsList[i + 1][0] * BitmapSize; // L.Y2 = PointsList[i + 1][1] * BitmapSize; // } // else // { // L.X2 = PointsList[0][0] * BitmapSize; // L.Y2 = PointsList[0][1] * BitmapSize; // } // CanvasLeft.Children.Add(L); // } //else if (Math.Abs(PointsList[i][0]) < epsilonToSnapBoder) //{ // L.X2 = 0; // L.Y2 = PointsList[i][1] * BitmapSize; // brush = new SolidColorBrush(Colors.Aqua); //} //else if (Math.Abs(PointsList[i][0] - 1) < epsilonToSnapBoder) //{ // L.X2 = BitmapSize; // L.Y2 = PointsList[i][1] * BitmapSize; // brush = new SolidColorBrush(Colors.Beige); //} //else if (Math.Abs(PointsList[i][1]) < epsilonToSnapBoder) //{ // L.X2 = PointsList[i][0] * BitmapSize; // L.Y2 = 0; // brush = new SolidColorBrush(Colors.Chocolate); //} //else if (Math.Abs(PointsList[i][1]-1) < epsilonToSnapBoder) //{ // L.X2 = PointsList[i][0] * BitmapSize; // L.Y2 = BitmapSize; // brush = new SolidColorBrush(Colors.DarkBlue); //} // L.Stroke = brush; // CanvasLeft.Children.Add(L); //brush = new SolidColorBrush(Colors.Black); CanvasLeft.InvalidateVisual(); }