- Timestamp:
- 02/02/09 17:05:37 (13 years ago)
- Location:
- chess/src/chess
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
chess/src/chess/remote/impl/Remote.java
r11 r12 116 116 // return new Remote(); 117 117 // return new DummyRemote(); 118 return new DebugRemote( );118 return new DebugRemote( 500, 500 ); 119 119 } 120 120 -
chess/src/chess/remote/impl/debug/DebugRemote.java
r11 r12 23 23 private static final Timer TIMER = new Timer(); 24 24 25 private static InputStream prepareLog( final Player player ) { 25 private final int networkLatency; 26 private final int userLatency; 27 28 public DebugRemote( final int networkLatency, 29 final int userLatency ) { 30 this.networkLatency = networkLatency; 31 this.userLatency = userLatency; 32 } 33 34 private InputStream prepareLog( final Player player ) { 26 35 final ByteArrayOutputStream out = new ByteArrayOutputStream(); 27 36 try { 28 37 final int yPawnLine = ( player == Player.WHITE ) ? ( 1 ) : ( 6 ); 29 38 final int dir = player.getDirection(); 30 putAction( player, out, 2 00, 0, yPawnLine, 0, yPawnLine + 2 * dir );39 putAction( player, out, 2 * userLatency, 0, yPawnLine, 0, yPawnLine + 2 * dir ); 31 40 32 putAction( player, out, 12 00, 3, yPawnLine, 3, yPawnLine + 2 * dir );41 putAction( player, out, 12 * userLatency, 3, yPawnLine, 3, yPawnLine + 2 * dir ); 33 42 34 putAction( player, out, 10 60, 4, yPawnLine, 4, yPawnLine + dir );43 putAction( player, out, 10 * userLatency, 4, yPawnLine, 4, yPawnLine + dir ); 35 44 36 putAction( player, out, 20 00, 4, yPawnLine + dir, 4, yPawnLine + 2 * dir );45 putAction( player, out, 20 * userLatency, 4, yPawnLine + dir, 4, yPawnLine + 2 * dir ); 37 46 } catch ( IOException e ) { 38 47 e.printStackTrace(); … … 82 91 } 83 92 84 private staticclass AsyncProcess extends BaseAsyncProcess {93 private class AsyncProcess extends BaseAsyncProcess { 85 94 public AsyncProcess( final IServerListener listener ) { 86 95 super( listener ); … … 93 102 try { 94 103 synchronized ( this ) { 95 wait( 350);104 wait( 4 * networkLatency ); 96 105 } 97 106 } catch ( InterruptedException e ) { … … 110 119 } 111 120 112 private staticclass RemoteNode implements IRemoteNode {121 private class RemoteNode implements IRemoteNode { 113 122 private InputStream is; 114 123 private IConnectionListener listener; … … 137 146 } 138 147 }, 139 2 00148 2 * networkLatency 140 149 ); 141 150 if ( data instanceof SystemAction ) { … … 146 155 } 147 156 if ( sa.type() == SystemAction.YOUR_TURN ) { 148 TIMER.schedule(149 new TimerTask() {150 public void run() {151 Util.log.println( "recv: emulate");152 try {153 final GenericDatagram gd = new GenericDatagram( RemoteNode.this.is );154 Util.log.println( "recv: " + gd.wrapped );155 listener.received( gd.wrapped);157 try { 158 final GenericDatagram aPacket = new GenericDatagram( RemoteNode.this.is ); 159 final GenericDatagram saPacket = new GenericDatagram( RemoteNode.this.is ); 160 Thread.sleep( 5 * networkLatency ); 161 TIMER.schedule( 162 new TimerTask() { 163 public void run() { 164 Util.log.println( "recv: emulate" ); 156 165 157 Thread.sleep( 100 ); 158 final GenericDatagram gd2 = new GenericDatagram( RemoteNode.this.is ); 159 Util.log.println( "recv: " + gd2.wrapped ); 160 listener.received( gd2.wrapped ); 161 } catch ( Exception e ) { 162 e.printStackTrace(); 166 Util.log.println( "recv: " + aPacket.wrapped ); 167 listener.received( aPacket.wrapped ); 168 169 Util.log.println( "recv: " + saPacket.wrapped ); 170 listener.received( saPacket.wrapped ); 163 171 } 164 } 165 }, 166 500 167 ); 172 }, 173 ( ( Action )aPacket.wrapped ).duration() 174 ); 175 } catch ( Exception e ) { 176 e.printStackTrace(); 177 } 178 168 179 } 169 180 } -
chess/src/chess/ui/ChessMIDlet.java
r10 r12 109 109 remote.waitForIncoming( 110 110 new IServerListener() { 111 private boolean retValue = false; 112 111 113 public synchronized boolean incoming( final IRemoteNode client ) { 112 try { 113 client.ensureConnected(); 114 app = new App( 115 ChessMIDlet.this, 116 new Game(), 117 gameCanvas, 118 client, 119 player 120 ); 121 display.setCurrent( gameCanvas ); 122 Util.log.println( "joined client" ); 123 return true; 124 } catch ( IOException e ) { 125 e.printStackTrace(); 126 return false; 114 final Alert dlg = new Alert( "Connect?", client.getName(), null, AlertType.CONFIRMATION ); 115 dlg.setTimeout( Alert.FOREVER ); 116 dlg.addCommand( okCommand ); 117 dlg.addCommand( Alert.DISMISS_COMMAND ); 118 dlg.setCommandListener( 119 new CommandListener() { 120 public void commandAction( final Command command, 121 final Displayable displayable ) { 122 try { 123 if ( command == okCommand ) { 124 Util.log.println( command ); 125 try { 126 client.ensureConnected(); 127 app = new App( 128 ChessMIDlet.this, 129 new Game(), 130 gameCanvas, 131 client, 132 player 133 ); 134 display.setCurrent( gameCanvas ); 135 Util.log.println( "joined client" ); 136 retValue = true; 137 //return true; 138 } catch ( IOException e ) { 139 e.printStackTrace(); 140 retValue = false; 141 //return false; 142 } 143 } else { 144 retValue = false; 145 } 146 } finally { 147 synchronized ( ChessMIDlet.this ) { 148 ChessMIDlet.this.notifyAll(); 149 } 150 } 151 } 152 } 153 ); 154 display.setCurrent( dlg ); 155 synchronized ( ChessMIDlet.this ) { 156 try { 157 ChessMIDlet.this.wait(); 158 } catch ( InterruptedException e ) { 159 e.printStackTrace(); 160 } 127 161 } 162 return retValue; 128 163 } 129 164
Note: See TracChangeset
for help on using the changeset viewer.