diff --git a/Client/Client.cs b/Client/Client.cs index e6a62b4..008c09d 100644 --- a/Client/Client.cs +++ b/Client/Client.cs @@ -50,9 +50,14 @@ namespace Client Console.WriteLine("-- Could not connect to the VR engine. Please make sure you are running the simulation!"); Console.WriteLine("-- Press ENTER to retry connecting to the VR engine."); Console.WriteLine("-- Press 'q' and then ENTER to not connect to the VR engine"); - Console.WriteLine(Console.Read()); - - engineConnection.CreateConnection(); + string input = Console.ReadLine(); + if (input == string.Empty) engineConnection.CreateConnection(); + else + { + Console.WriteLine("Skipping connecting to VR engine..."); + engineConnection.Stop(); + } + } private void engineConnected() diff --git a/Client/EngineConnection.cs b/Client/EngineConnection.cs index 84aaddb..5a89713 100644 --- a/Client/EngineConnection.cs +++ b/Client/EngineConnection.cs @@ -110,16 +110,6 @@ namespace Client WriteTextMessage(tunnelCreate); - // wait until we have a tunnel id - //while (tunnelId == string.Empty) { } - //if (tunnelId != null) - //{ - // Write("got tunnel id! " + tunnelId); - // Connected = true; - // OnSuccessFullConnection?.Invoke(); - - //} - } @@ -201,26 +191,13 @@ namespace Client SendMessageAndOnResponse(mainCommand.addPanel("panelAdd", bikeId), "panelAdd", (message) => { - + panelId = JSONParser.getPanelID(message); WriteTextMessage(mainCommand.ColorPanel(panelId)); WriteTextMessage(mainCommand.ClearPanel(panelId)); - SendMessageAndOnResponse(mainCommand.MoveTo(panelId, "panelMove", new float[] { 0f, 0f, 0f }, "Z", 1, 5), "panelMove", - (message) => - { - Console.WriteLine(message); - - SendMessageAndOnResponse(mainCommand.bikeSpeed(panelId, "bikeSpeed", 5.0), "bikeSpeed", - (message) => - { - WriteTextMessage(mainCommand.SwapPanel(panelId)); - }); - }); - - - //while (!(speedReplied && moveReplied)) { } + showPanel(mainCommand, 5.3, 83, 52, 53); while (cameraId == string.Empty) { } SetFollowSpeed(5.0f); @@ -228,6 +205,34 @@ namespace Client }); } + private void showPanel(Command mainCommand, double bikeSpeed, int bpm, int power, int resistance) + { + SendMessageAndOnResponse(mainCommand.showBikespeed(panelId, "bikeSpeed", bikeSpeed), "bikeSpeed", + (message) => + { + // TODO check if is drawn + }); + SendMessageAndOnResponse(mainCommand.showHeartrate(panelId, "bpm", bpm), "bpm", + (message) => + { + // TODO check if is drawn + }); + SendMessageAndOnResponse(mainCommand.showPower(panelId, "power", power), "power", + (message) => + { + // TODO check if is drawn + }); + SendMessageAndOnResponse(mainCommand.showResistance(panelId, "resistance", resistance), "resistance", + (message) => + { + // TODO check if is drawn + }); + + // Check if every text is drawn! + + WriteTextMessage(mainCommand.SwapPanel(panelId)); + } + private void SetFollowSpeed(float speed) { WriteTextMessage(mainCommand.RouteFollow(routeId, bikeId, speed, new float[] { 0, -(float)Math.PI / 2f, 0 }, new float[] { 0, 0, 0 })); @@ -270,6 +275,12 @@ namespace Client } #endregion + + public void Stop() + { + serverResponseReader.Stop(); + + } public void Write(string msg) { Console.WriteLine( "[ENGINECONNECT] " + msg); diff --git a/RH-Engine/ServerResponseReader.cs b/RH-Engine/ServerResponseReader.cs index 17e86ba..bafa442 100644 --- a/RH-Engine/ServerResponseReader.cs +++ b/RH-Engine/ServerResponseReader.cs @@ -9,6 +9,8 @@ namespace RH_Engine public class ServerResponseReader { + private bool running; + private Thread t; public OnResponse callback { get; set; @@ -23,7 +25,7 @@ namespace RH_Engine public void StartRead() { - Thread t = new Thread(() => + t = new Thread(() => { if (this.callback == null) { @@ -31,8 +33,9 @@ namespace RH_Engine } else { + running = true; Console.WriteLine("[SERVERRESPONSEREADER] Starting loop for reading"); - while (true) + while (running) { string res = ReadPrefMessage(Stream); //Console.WriteLine("[SERVERRESPONSEREADER] got message from server: " + res); @@ -44,6 +47,13 @@ namespace RH_Engine t.Start(); } + public void Stop() + { + running = false; + t.Join(); + Stream.Close(); + } + /// /// reads a response from the server ///