mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-29 08:34:37 +01:00
don't save game when it hasn't changed -- when saved bytes are
identical with those we started with.
This commit is contained in:
parent
1743382e1f
commit
1998da45de
2 changed files with 24 additions and 15 deletions
|
@ -1739,8 +1739,9 @@ public class BoardActivity extends XWActivity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
m_jniThread = new JNIThread( m_jniGamePtr, m_gi, m_view,
|
m_jniThread =
|
||||||
m_gameLock, this, handler );
|
new JNIThread( m_jniGamePtr, stream, m_gi,
|
||||||
|
m_view, m_gameLock, this, handler );
|
||||||
// see http://stackoverflow.com/questions/680180/where-to-stop-\
|
// see http://stackoverflow.com/questions/680180/where-to-stop-\
|
||||||
// destroy-threads-in-android-service-class
|
// destroy-threads-in-android-service-class
|
||||||
m_jniThread.setDaemon( true );
|
m_jniThread.setDaemon( true );
|
||||||
|
|
|
@ -22,13 +22,14 @@
|
||||||
package org.eehouse.android.xw4.jni;
|
package org.eehouse.android.xw4.jni;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import java.lang.InterruptedException;
|
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Message;
|
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Message;
|
||||||
|
import java.lang.InterruptedException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
|
||||||
import org.eehouse.android.xw4.R;
|
import org.eehouse.android.xw4.R;
|
||||||
import org.eehouse.android.xw4.DbgUtils;
|
import org.eehouse.android.xw4.DbgUtils;
|
||||||
|
@ -122,6 +123,7 @@ public class JNIThread extends Thread {
|
||||||
private boolean m_stopped = false;
|
private boolean m_stopped = false;
|
||||||
private boolean m_saveOnStop = false;
|
private boolean m_saveOnStop = false;
|
||||||
private int m_jniGamePtr;
|
private int m_jniGamePtr;
|
||||||
|
private byte[] m_gameAtStart;
|
||||||
private GameLock m_lock;
|
private GameLock m_lock;
|
||||||
private Context m_context;
|
private Context m_context;
|
||||||
private CurGameInfo m_gi;
|
private CurGameInfo m_gi;
|
||||||
|
@ -143,10 +145,12 @@ public class JNIThread extends Thread {
|
||||||
Object[] m_args;
|
Object[] m_args;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JNIThread( int gamePtr, CurGameInfo gi, SyncedDraw drawer,
|
public JNIThread( int gamePtr, byte[] gameAtStart, CurGameInfo gi,
|
||||||
GameLock lock, Context context, Handler handler )
|
SyncedDraw drawer, GameLock lock, Context context,
|
||||||
|
Handler handler )
|
||||||
{
|
{
|
||||||
m_jniGamePtr = gamePtr;
|
m_jniGamePtr = gamePtr;
|
||||||
|
m_gameAtStart = gameAtStart;
|
||||||
m_gi = gi;
|
m_gi = gi;
|
||||||
m_drawer = drawer;
|
m_drawer = drawer;
|
||||||
m_lock = lock;
|
m_lock = lock;
|
||||||
|
@ -286,14 +290,18 @@ public class JNIThread extends Thread {
|
||||||
if ( null != m_newDict ) {
|
if ( null != m_newDict ) {
|
||||||
m_gi.dictName = m_newDict;
|
m_gi.dictName = m_newDict;
|
||||||
}
|
}
|
||||||
|
byte[] state = XwJNI.game_saveToStream( m_jniGamePtr, m_gi );
|
||||||
|
if ( Arrays.equals( m_gameAtStart, state ) ) {
|
||||||
|
DbgUtils.logf( "no change in game; can skip saving" );
|
||||||
|
} else {
|
||||||
GameSummary summary = new GameSummary( m_context, m_gi );
|
GameSummary summary = new GameSummary( m_context, m_gi );
|
||||||
XwJNI.game_summarize( m_jniGamePtr, summary );
|
XwJNI.game_summarize( m_jniGamePtr, summary );
|
||||||
byte[] state = XwJNI.game_saveToStream( m_jniGamePtr, m_gi );
|
DBUtils.saveGame( m_context, m_lock, state, false );
|
||||||
GameUtils.saveGame( m_context, state, m_lock, false );
|
|
||||||
DBUtils.saveSummary( m_context, m_lock, summary );
|
DBUtils.saveSummary( m_context, m_lock, summary );
|
||||||
// There'd better be no way for saveGame above to fail!
|
// There'd better be no way for saveGame above to fail!
|
||||||
XwJNI.game_saveSucceeded( m_jniGamePtr );
|
XwJNI.game_saveSucceeded( m_jniGamePtr );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("fallthrough")
|
@SuppressWarnings("fallthrough")
|
||||||
public void run()
|
public void run()
|
||||||
|
|
Loading…
Add table
Reference in a new issue