Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added sync to java client #10

Merged
merged 1 commit into from Nov 10, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 27 additions & 3 deletions 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;
Expand All @@ -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

Expand All @@ -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();
}
Expand Down Expand Up @@ -140,4 +143,25 @@ public void stop() {
e.printStackTrace();
}
}
}

/**
* 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();
}
}
}