From bb90dce2c403f945df1d50b06a45eccbd66a761f Mon Sep 17 00:00:00 2001 From: eehouse Date: Sat, 30 Jan 2010 15:33:57 +0000 Subject: [PATCH] coalesce CMD_DO messages; fixes robot-vs-robot game. --- .../src/org/eehouse/android/xw4/jni/JNIThread.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java index 16cdbb141..20f6b9656 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java @@ -140,6 +140,12 @@ public class JNIThread extends Thread { XwJNI.board_invalAll( m_jniGamePtr ); } + private boolean nextSame( JNICmd cmd ) + { + QueueElem nextElem = m_queue.peek(); + return null != nextElem && nextElem.m_cmd == cmd; + } + public void run() { boolean[] barr = new boolean[1]; // scratch boolean @@ -176,6 +182,9 @@ public class JNIThread extends Thread { draw = XwJNI.server_do( m_jniGamePtr ); break; case CMD_DO: + if ( nextSame( JNICmd.CMD_DO ) ) { + continue; + } draw = XwJNI.server_do( m_jniGamePtr ); break; @@ -186,9 +195,7 @@ public class JNIThread extends Thread { barr ); break; case CMD_PEN_MOVE: - QueueElem nextElem = m_queue.peek(); - if ( null != nextElem && nextElem.m_cmd == JNICmd.CMD_PEN_MOVE ) { - Utils.logf( "dropping CMD_PEN_MOVE" ); + if ( nextSame( JNICmd.CMD_PEN_MOVE ) ) { continue; } draw = XwJNI.board_handlePenMove( m_jniGamePtr, @@ -283,6 +290,7 @@ public class JNIThread extends Thread { public void handle( JNICmd cmd, Object... args ) { QueueElem elem = new QueueElem( cmd, args ); + // Utils.logf( "adding: " + cmd.toString() ); m_queue.add( elem ); } }