Skip to content

Commit

Permalink
finish sim mode and testing #24
Browse files Browse the repository at this point in the history
  • Loading branch information
shiffman committed Aug 4, 2013
1 parent 3224dbd commit bce6256
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Most-Pixels-Ever-Examples/data/mpe0.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
</master_dimensions>
<offset_window>true</offset_window>
<verbose>true</verbose>
<simulation fps="30">true</simulation>
<simulation fps="30">false</simulation>
</settings>
2 changes: 1 addition & 1 deletion Most-Pixels-Ever-Examples/data/mpe1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
</master_dimensions>
<offset_window>true</offset_window>
<verbose>true</verbose>
<simulation fps="30">true</simulation>
<simulation fps="30">false</simulation>
</settings>
12 changes: 6 additions & 6 deletions Most-Pixels-Ever-Examples/src/mpe/examples/AutoBalls.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

public class AutoBalls extends PApplet {
//--------------------------------------
final int ID = 1;
final int ID = 0;

ArrayList<Ball> balls;
TCPClient client;
Expand All @@ -27,10 +27,9 @@ public void setup() {
// make a new Client using an INI file
// sketchPath() is used so that the INI file is local to the sketch
client = new TCPClient(this, "mpe"+ID+".xml");

// the size is determined by the client's local width and height
size(client.getLWidth(), client.getLHeight());

resetEvent(client);

// IMPORTANT, YOU MUST START THE CLIENT!
Expand All @@ -43,15 +42,16 @@ public void resetEvent(TCPClient c) {

// add a "randomly" placed ball
balls = new ArrayList<Ball>();
Ball ball = new Ball(random(client.getMWidth()), random(client.getMHeight()));
balls.add(ball);
balls.add(new Ball(100,50));
balls.add(new Ball(500,50));

}

//--------------------------------------
// Keep the motor running... draw() needs to be added in auto mode, even if
// it is empty to keep things rolling.
public void draw() {}
public void draw() {
}


public void dataEvent(TCPClient c) {
Expand Down
53 changes: 30 additions & 23 deletions Most-Pixels-Ever-Processing/src/mpe/client/TCPClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.Socket;
import java.net.UnknownHostException;
Expand Down Expand Up @@ -100,12 +99,8 @@ public class TCPClient extends Thread {
* The parent PApplet must have a method called "frameEvent(Client c)".
*
* The frameEvent handles syncing up the frame rate on the
* multiple screens. A typical implementation may look like this:
* multiple screens and should be implemented like draw().
*
* public void frameEvent(Client c){
* if (!started) started = true;
* redraw();
* }
*
*/
public TCPClient(PApplet _p, String _fileString) {
Expand Down Expand Up @@ -181,10 +176,11 @@ public void draw() {
// Just keep moving
try {
frameEventMethod.invoke(p5parent, new Object[] { this });
frameCount++;
} catch (Exception e) {
e.printStackTrace();
}
// Otherwise typical MPE stuff
// Otherwise typical MPE stuff
} else if (running && rendering) {
placeScreen();

Expand Down Expand Up @@ -272,7 +268,8 @@ private void loadSettings(String filename) {
XML simxml = xml.getChild("simulation");
if (simxml != null) {
simulation = Boolean.parseBoolean(simxml.getContent());
simFPS = simxml.getInt("FPS");
simFPS = simxml.getInt("fps");
if (simFPS < 1) simFPS = 30;
}

setMasterDimensions(mw,mh);
Expand Down Expand Up @@ -584,7 +581,13 @@ public void start() {
*/
public void run() {

if (VERBOSE) out("Starting!");
if (VERBOSE) {
if (simulation) {
out("Running in simulation mode (no server connection, will not receive data)!");
} else {
out("Starting!");
}
}

// Don't bother to connect to server if you are in simulation mode
if (!simulation) {
Expand Down Expand Up @@ -615,23 +618,27 @@ public void run() {
send("S|" + id);
}

}

try {
while (running) {
// read packet
String msg = brin.readLine();
if (msg == null) {
//running = false;
break;
} else {
read(msg);

try {
while (running) {
// read packet
String msg = brin.readLine();
if (msg == null) {
//running = false;
break;
} else {
read(msg);
}
}
is.close();
} catch (IOException e) {
e.printStackTrace();
}
} else {
while (running) {
//System.out.println("GOGOGO");
}
is.close();

} catch (IOException e) {
e.printStackTrace();
}
}

Expand Down

0 comments on commit bce6256

Please sign in to comment.