From 14bdde7ff0678535fba700b3c241c9ed6709aa93 Mon Sep 17 00:00:00 2001 From: Eric House Date: Thu, 7 Apr 2016 09:27:00 -0700 Subject: [PATCH] save game whenever refcount is released. Works around BoardDelegate reloading the game every time it resumes. Better fix would be to have JNIThread() own loading the game and only do so when first created. --- .../org/eehouse/android/xw4/jni/JNIThread.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 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 f2f3c34fc..1dc39c259 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 @@ -334,8 +334,14 @@ public class JNIThread extends Thread { m_gi.dictName = m_newDict; } byte[] state = XwJNI.game_saveToStream( m_jniGamePtr, m_gi ); + boolean arraysEqual = Arrays.equals( m_gameAtStart, state ); + boolean hashesEqual = Arrays.hashCode( m_gameAtStart) == Arrays.hashCode(state); + DbgUtils.logf( "arraysEqual: %b; hashesEqual: %b", arraysEqual, hashesEqual ); + // PENDING: once certain this is true, stop saving the full array and + // instead save the hash. Also, update it after each save. + Assert.assertTrue( arraysEqual == hashesEqual ); if ( Arrays.equals( m_gameAtStart, state ) ) { - // DbgUtils.logf( "no change in game; can skip saving" ); + DbgUtils.logdf( "JNIThread.save_jni(): no change in game; can skip saving" ); } else { synchronized( this ) { Assert.assertNotNull( m_lock ); @@ -393,11 +399,6 @@ public class JNIThread extends Thread { continue; } save_jni(); - // This is gross: we take the relay connection down - // then bring it right back up again each time there's - // a message received (to save any state changes it - // brought). There must be a better way. - // XwJNI.comms_start( m_jniGamePtr ); break; case CMD_DRAW: @@ -732,6 +733,8 @@ public class JNIThread extends Thread { if ( stop ) { waitToStop( true ); + } else { + handle( JNICmd.CMD_SAVE ); // in case releaser has made changes } }