diff --git a/clients/java/VisualClient.java b/clients/java/VisualClient.java index a4ba479..a13a2f5 100644 --- a/clients/java/VisualClient.java +++ b/clients/java/VisualClient.java @@ -1,6 +1,5 @@ import java.awt.*; -import java.io.IOException; -import java.io.OutputStream; +import java.io.*; import java.net.Socket; import java.util.Formatter; import java.util.Locale; @@ -10,6 +9,8 @@ public class VisualClient { Socket socket; OutputStream outputStream; + InputStream inputStream; + BufferedReader reader; final String DEFAULT_HOST = "127.0.0.1"; final int DEFAULT_PORT = 13579;//13579 @@ -18,6 +19,8 @@ public VisualClient() { try { socket = new Socket(DEFAULT_HOST, DEFAULT_PORT); outputStream = socket.getOutputStream(); + inputStream = socket.getInputStream(); + reader = new BufferedReader(new InputStreamReader(inputStream)); } catch (IOException e) { e.printStackTrace(); } @@ -140,4 +143,25 @@ public void stop() { e.printStackTrace(); } } -} \ No newline at end of file + + /** + * synchronizes local-runner with the render commands from bot, call AFTER you have sent + * render commands for tick=tickIndex + */ + public void sync(int tickIndex) { + try { + while(true) { + String line = reader.readLine(); + if (line.startsWith("sync ")) { + int tick = Integer.parseInt(line.substring(5).trim()); + sendCommand("ack"); + if (tick >= tickIndex) { + break; + } + } + } + } catch (IOException e) { + e.printStackTrace(); + } + } +}