import java.io.*; import java.util.*; import java.net.*; import java.awt.*; public class WorkSender { static boolean[] doneLines; static long[] startTimes; static long[] finishTimes; static int lastLine, magicPrime; static Dimension bounds; static World w; static PictureKeeper pk; public WorkSender(Dimension boundsin, World win, PictureKeeper pkk) { bounds = boundsin; w = win; startTimes = new long[bounds.height]; finishTimes = new long[bounds.height]; lastLine = -1; magicPrime = -1; pk = pkk; } public void sendWorld(ObjectOutputStream oos) { try { oos.writeObject(bounds); oos.writeObject(w); } catch (Exception e) { System.out.println("sendWorld: " + e); } } public synchronized void sendLine(ObjectOutputStream oos) { int currentLine = nextLineNumber(); startTimes[currentLine] = System.currentTimeMillis(); try { oos.writeObject(new Integer(currentLine)); oos.flush(); } catch (Exception e) { System.out.println("sendLine: " + e); } lastLine = currentLine; } private int nextLineNumber() // We'd synchronize, but only { // synchronized SendLine calls it if (magicPrime == -1) { if (bounds.height % 73 != 0) { magicPrime = 73; } else if (bounds.height % 59 != 0) { magicPrime = 59; } else magicPrime = 1079; } int trythis = (lastLine + magicPrime) % bounds.height; if(pk.doneLine(trythis)) { for(int i=0; i