Skip to content

Commit

Permalink
adding reset method to client, in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
shiffman committed Jul 21, 2013
1 parent 976a810 commit bc0f41a
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions Most-Pixels-Ever-Processing/src/mpe/client/TCPClient.java
Expand Up @@ -68,6 +68,8 @@ public class TCPClient extends Thread {
int frameCount = 0;
float fps = 0.f;
long lastMs = 0;

boolean reset = false;

// Are we broadcasting?
// boolean broadcastingData = false;
Expand Down Expand Up @@ -140,11 +142,15 @@ public void draw() {
}
if (running && rendering) {
placeScreen();

if (reset) {
resetMethod.invoke(p5parent, new Object[] { this });
}

if (frameEventMethod != null) {
try {
// call the method with this object as the argument!
frameEventMethod.invoke(p5parent, new Object[] { this });

} catch (Exception e) {
err("Could not invoke the \"frameEvent()\" method for some reason.");
e.printStackTrace();
Expand Down Expand Up @@ -547,11 +553,12 @@ private void read(String msg) {

// a "G" startbyte will trigger a frameEvent.
char c = msg.charAt(0);
if (c == 'G') {

if (c == 'G' || c == 'R') {

if (c == 'R') reset = true;

String[] tokens = msg.split("\\|");
int fc = Integer.parseInt(tokens[1]);

if (tokens.length > 2) {
// there is a message here with the frameEvent
String[] dataInfo = new String[tokens.length-2];
Expand All @@ -568,7 +575,10 @@ private void read(String msg) {
messageAvailable = false;
}


if (reset) {
frameCount = 0;
}

if (fc == frameCount) {
rendering = true;
// calculate new framerate
Expand Down

0 comments on commit bc0f41a

Please sign in to comment.