mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-31 19:57:06 +01:00
get rid of dict processing where possible
The old API required passing dict into game creation/loading. New doesn't, but in some places I was doing other stuff there (like checking existance), so can't remove there. Still code goes away.
This commit is contained in:
parent
970c2f6f9a
commit
17311dc757
6 changed files with 58 additions and 93 deletions
|
@ -131,8 +131,6 @@ public class GameUtils {
|
||||||
{
|
{
|
||||||
CurGameInfo gi = new CurGameInfo( context );
|
CurGameInfo gi = new CurGameInfo( context );
|
||||||
CommsAddrRec addr = null;
|
CommsAddrRec addr = null;
|
||||||
String[] dictNames = gi.dictNames();
|
|
||||||
DictUtils.DictPairs pairs = DictUtils.openDicts( context, dictNames );
|
|
||||||
|
|
||||||
try ( GamePtr gamePtr = loadMakeGame( context, gi, lockSrc ) ) {
|
try ( GamePtr gamePtr = loadMakeGame( context, gi, lockSrc ) ) {
|
||||||
if ( XwJNI.game_hasComms( gamePtr ) ) {
|
if ( XwJNI.game_hasComms( gamePtr ) ) {
|
||||||
|
@ -141,10 +139,8 @@ public class GameUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
try ( GamePtr gamePtr = XwJNI
|
try ( GamePtr gamePtr = XwJNI
|
||||||
.initNew( gi, dictNames, pairs.m_bytes, pairs.m_paths,
|
.initNew( gi, (UtilCtxt)null, (DrawCtx)null,
|
||||||
gi.langName( context ), (UtilCtxt)null,
|
CommonPrefs.get( context ), (TransportProcs)null ) ) {
|
||||||
(DrawCtx)null, CommonPrefs.get( context ),
|
|
||||||
(TransportProcs)null ) ) {
|
|
||||||
|
|
||||||
if ( juggle ) {
|
if ( juggle ) {
|
||||||
gi.juggle();
|
gi.juggle();
|
||||||
|
@ -411,16 +407,11 @@ public class GameUtils {
|
||||||
TextUtils.join( ",", dictNames ) );
|
TextUtils.join( ",", dictNames ) );
|
||||||
} else {
|
} else {
|
||||||
String langName = gi.langName( context );
|
String langName = gi.langName( context );
|
||||||
gamePtr = XwJNI.initFromStream( rowid, stream, gi, dictNames,
|
gamePtr = XwJNI.initFromStream( rowid, stream, gi, util, null,
|
||||||
pairs.m_bytes, pairs.m_paths,
|
|
||||||
langName, util,
|
|
||||||
null,
|
|
||||||
CommonPrefs.get(context),
|
CommonPrefs.get(context),
|
||||||
tp );
|
tp );
|
||||||
if ( null == gamePtr ) {
|
if ( null == gamePtr ) {
|
||||||
gamePtr = XwJNI.initNew( gi, dictNames,
|
gamePtr = XwJNI.initNew( gi, (UtilCtxt)null, null,
|
||||||
pairs.m_bytes, pairs.m_paths,
|
|
||||||
langName, (UtilCtxt)null, null,
|
|
||||||
CommonPrefs.get(context), null );
|
CommonPrefs.get(context), null );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1099,15 +1090,9 @@ public class GameUtils {
|
||||||
// first time required so dictNames() will work
|
// first time required so dictNames() will work
|
||||||
gi.replaceDicts( context, newDict );
|
gi.replaceDicts( context, newDict );
|
||||||
|
|
||||||
String[] dictNames = gi.dictNames();
|
|
||||||
DictUtils.DictPairs pairs = DictUtils.openDicts( context,
|
|
||||||
dictNames );
|
|
||||||
|
|
||||||
try ( GamePtr gamePtr =
|
try ( GamePtr gamePtr =
|
||||||
XwJNI.initFromStream( rowid, stream, gi, dictNames,
|
XwJNI.initFromStream( rowid, stream, gi, null, null,
|
||||||
pairs.m_bytes, pairs.m_paths,
|
CommonPrefs.get( context ), null ) ) {
|
||||||
gi.langName( context ), null,
|
|
||||||
null, CommonPrefs.get( context ), null ) ) {
|
|
||||||
// second time required as game_makeFromStream can overwrite
|
// second time required as game_makeFromStream can overwrite
|
||||||
gi.replaceDicts( context, newDict );
|
gi.replaceDicts( context, newDict );
|
||||||
|
|
||||||
|
@ -1140,9 +1125,6 @@ public class GameUtils {
|
||||||
// somesuch. But: do we have a way to save changes to a gi
|
// somesuch. But: do we have a way to save changes to a gi
|
||||||
// that don't reset the game, e.g. player name for standalone
|
// that don't reset the game, e.g. player name for standalone
|
||||||
// games?
|
// games?
|
||||||
String[] dictNames = gi.dictNames();
|
|
||||||
DictUtils.DictPairs pairs = DictUtils.openDicts( context, dictNames );
|
|
||||||
String langName = gi.langName( context );
|
|
||||||
boolean madeGame = false;
|
boolean madeGame = false;
|
||||||
CommonPrefs cp = CommonPrefs.get( context );
|
CommonPrefs cp = CommonPrefs.get( context );
|
||||||
|
|
||||||
|
@ -1154,8 +1136,6 @@ public class GameUtils {
|
||||||
try ( GamePtr gamePtr = XwJNI
|
try ( GamePtr gamePtr = XwJNI
|
||||||
.initFromStream( lock.getRowid(), stream,
|
.initFromStream( lock.getRowid(), stream,
|
||||||
new CurGameInfo(context),
|
new CurGameInfo(context),
|
||||||
dictNames, pairs.m_bytes,
|
|
||||||
pairs.m_paths, langName,
|
|
||||||
null, null, cp, null ) ) {
|
null, null, cp, null ) ) {
|
||||||
if ( null != gamePtr ) {
|
if ( null != gamePtr ) {
|
||||||
applyChanges( context, sink, gi, car, disab,
|
applyChanges( context, sink, gi, car, disab,
|
||||||
|
@ -1166,9 +1146,8 @@ public class GameUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( forceNew || !madeGame ) {
|
if ( forceNew || !madeGame ) {
|
||||||
try ( GamePtr gamePtr = XwJNI.initNew( gi, dictNames, pairs.m_bytes,
|
try ( GamePtr gamePtr = XwJNI.initNew( gi, util, (DrawCtx)null,
|
||||||
pairs.m_paths, langName, util,
|
cp, sink ) ) {
|
||||||
(DrawCtx)null, cp, sink ) ) {
|
|
||||||
if ( null != gamePtr ) {
|
if ( null != gamePtr ) {
|
||||||
applyChanges( context, sink, gi, car, disab, lock, gamePtr );
|
applyChanges( context, sink, gi, car, disab, lock, gamePtr );
|
||||||
}
|
}
|
||||||
|
|
|
@ -337,15 +337,16 @@ public class DUtilCtxt {
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDictPath( int lang, String name )
|
public void getDictPath( int lang, String name, String[] path, byte[][] bytes )
|
||||||
{
|
{
|
||||||
Log.d( TAG, "getDictPath(%d, %s)", lang, name );
|
Log.d( TAG, "getDictPath(%d, %s)", lang, name );
|
||||||
String[] names = { name };
|
String[] names = { name };
|
||||||
DictUtils.DictPairs pairs = DictUtils.openDicts( m_context, names );
|
DictUtils.DictPairs pairs = DictUtils.openDicts( m_context, names );
|
||||||
String path = pairs.m_paths[0];
|
Log.d( TAG, "openDicts() => %s", pairs );
|
||||||
Assert.assertNotNull( path );
|
path[0] = pairs.m_paths[0];
|
||||||
Log.d( TAG, "getDictPath(%s) => %s", name, path );
|
bytes[0] = pairs.m_bytes[0];
|
||||||
return path;
|
Log.d( TAG, "getDictPath(%s): have path: %s; bytes: %s", name, path[0], bytes[0] );
|
||||||
|
Assert.assertTrue( path[0] != null || bytes[0] != null );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDupTimerChanged( int gameID, int oldVal, int newVal )
|
public void onDupTimerChanged( int gameID, int oldVal, int newVal )
|
||||||
|
|
|
@ -230,16 +230,10 @@ public class JNIThread extends Thread implements AutoCloseable {
|
||||||
m_jniGamePtr = null;
|
m_jniGamePtr = null;
|
||||||
if ( null != stream ) {
|
if ( null != stream ) {
|
||||||
m_jniGamePtr = XwJNI.initFromStream( m_rowid, stream, m_gi,
|
m_jniGamePtr = XwJNI.initFromStream( m_rowid, stream, m_gi,
|
||||||
dictNames, pairs.m_bytes,
|
|
||||||
pairs.m_paths,
|
|
||||||
m_gi.langName( m_context ),
|
|
||||||
utils, null, cp, m_xport );
|
utils, null, cp, m_xport );
|
||||||
}
|
}
|
||||||
if ( null == m_jniGamePtr ) {
|
if ( null == m_jniGamePtr ) {
|
||||||
m_jniGamePtr = XwJNI.initNew( m_gi, dictNames, pairs.m_bytes,
|
m_jniGamePtr = XwJNI.initNew( m_gi, utils, null, cp, m_xport );
|
||||||
pairs.m_paths,
|
|
||||||
m_gi.langName(m_context),
|
|
||||||
utils, null, cp, m_xport );
|
|
||||||
}
|
}
|
||||||
Assert.assertNotNull( m_jniGamePtr );
|
Assert.assertNotNull( m_jniGamePtr );
|
||||||
notifyAll();
|
notifyAll();
|
||||||
|
|
|
@ -285,15 +285,12 @@ public class XwJNI {
|
||||||
|
|
||||||
public static synchronized GamePtr
|
public static synchronized GamePtr
|
||||||
initFromStream( long rowid, byte[] stream, CurGameInfo gi,
|
initFromStream( long rowid, byte[] stream, CurGameInfo gi,
|
||||||
String[] dictNames, byte[][] dictBytes,
|
|
||||||
String[] dictPaths, String langName,
|
|
||||||
UtilCtxt util, DrawCtx draw,
|
UtilCtxt util, DrawCtx draw,
|
||||||
CommonPrefs cp, TransportProcs procs )
|
CommonPrefs cp, TransportProcs procs )
|
||||||
|
|
||||||
{
|
{
|
||||||
GamePtr gamePtr = initGameJNI( rowid );
|
GamePtr gamePtr = initGameJNI( rowid );
|
||||||
if ( ! game_makeFromStream( gamePtr, stream, gi, dictNames, dictBytes,
|
if ( ! game_makeFromStream( gamePtr, stream, gi, util, draw,
|
||||||
dictPaths, langName, util, draw,
|
|
||||||
cp, procs ) ) {
|
cp, procs ) ) {
|
||||||
gamePtr.release();
|
gamePtr.release();
|
||||||
gamePtr = null;
|
gamePtr = null;
|
||||||
|
@ -303,13 +300,11 @@ public class XwJNI {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized GamePtr
|
public static synchronized GamePtr
|
||||||
initNew( CurGameInfo gi, String[] dictNames, byte[][] dictBytes,
|
initNew( CurGameInfo gi, UtilCtxt util, DrawCtx draw,
|
||||||
String[] dictPaths, String langName, UtilCtxt util,
|
CommonPrefs cp, TransportProcs procs )
|
||||||
DrawCtx draw, CommonPrefs cp, TransportProcs procs )
|
|
||||||
{
|
{
|
||||||
GamePtr gamePtr = initGameJNI( 0 );
|
GamePtr gamePtr = initGameJNI( 0 );
|
||||||
game_makeNewGame( gamePtr, gi, dictNames, dictBytes, dictPaths,
|
game_makeNewGame( gamePtr, gi, util, draw, cp, procs );
|
||||||
langName, util, draw, cp, procs );
|
|
||||||
return gamePtr;
|
return gamePtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,10 +316,6 @@ public class XwJNI {
|
||||||
|
|
||||||
private static native void game_makeNewGame( GamePtr gamePtr,
|
private static native void game_makeNewGame( GamePtr gamePtr,
|
||||||
CurGameInfo gi,
|
CurGameInfo gi,
|
||||||
String[] dictNames,
|
|
||||||
byte[][] dictBytes,
|
|
||||||
String[] dictPaths,
|
|
||||||
String langName,
|
|
||||||
UtilCtxt util,
|
UtilCtxt util,
|
||||||
DrawCtx draw, CommonPrefs cp,
|
DrawCtx draw, CommonPrefs cp,
|
||||||
TransportProcs procs );
|
TransportProcs procs );
|
||||||
|
@ -332,10 +323,6 @@ public class XwJNI {
|
||||||
private static native boolean game_makeFromStream( GamePtr gamePtr,
|
private static native boolean game_makeFromStream( GamePtr gamePtr,
|
||||||
byte[] stream,
|
byte[] stream,
|
||||||
CurGameInfo gi,
|
CurGameInfo gi,
|
||||||
String[] dictNames,
|
|
||||||
byte[][] dictBytes,
|
|
||||||
String[] dictPaths,
|
|
||||||
String langName,
|
|
||||||
UtilCtxt util,
|
UtilCtxt util,
|
||||||
DrawCtx draw,
|
DrawCtx draw,
|
||||||
CommonPrefs cp,
|
CommonPrefs cp,
|
||||||
|
|
|
@ -822,16 +822,22 @@ and_dutil_getDict( XW_DUtilCtxt* duc, XWEnv xwe,
|
||||||
dmgr_get( dictMgr, xwe, dictName );
|
dmgr_get( dictMgr, xwe, dictName );
|
||||||
if ( !dict ) {
|
if ( !dict ) {
|
||||||
jstring jname = (*env)->NewStringUTF( env, dictName );
|
jstring jname = (*env)->NewStringUTF( env, dictName );
|
||||||
jstring jpath = NULL;
|
|
||||||
DUTIL_CBK_HEADER( "getDictPath", "(ILjava/lang/String;)Ljava/lang/String;" );
|
jobjectArray jstrs = makeStringArray( env, 1, NULL );
|
||||||
jpath = (*env)->CallObjectMethod( env, dutil->jdutil, mid, lang, jname );
|
jobjectArray jbytes = makeByteArrayArray( env, 1 );
|
||||||
|
|
||||||
|
DUTIL_CBK_HEADER( "getDictPath", "(ILjava/lang/String;[Ljava/lang/String;[[B)V" );
|
||||||
|
(*env)->CallVoidMethod( env, dutil->jdutil, mid, lang, jname, jstrs, jbytes );
|
||||||
DUTIL_CBK_TAIL();
|
DUTIL_CBK_TAIL();
|
||||||
|
|
||||||
|
jstring jpath = (*env)->GetObjectArrayElement( env, jstrs, 0 );
|
||||||
|
jbyteArray jdata = (*env)->GetObjectArrayElement( env, jbytes, 0 );
|
||||||
|
|
||||||
dict = makeDict( MPPARM(duc->mpool) xwe,
|
dict = makeDict( MPPARM(duc->mpool) xwe,
|
||||||
TI_IF(&globalState->ti)
|
TI_IF(&globalState->ti)
|
||||||
dictMgr, jniutil,
|
dictMgr, jniutil,
|
||||||
jname, NULL, jpath, NULL, false );
|
jname, jdata, jpath, NULL, false );
|
||||||
deleteLocalRefs( env, jname, jpath, DELETE_NO_REF );
|
deleteLocalRefs( env, jname, jstrs, jbytes, jdata, jpath, DELETE_NO_REF );
|
||||||
}
|
}
|
||||||
LOG_RETURNF( "%p", dict );
|
LOG_RETURNF( "%p", dict );
|
||||||
return dict;
|
return dict;
|
||||||
|
|
|
@ -1359,8 +1359,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_envDone
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL
|
||||||
Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeNewGame
|
Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeNewGame
|
||||||
( JNIEnv* env, jclass C, GamePtrType gamePtr, jobject j_gi,
|
( JNIEnv* env, jclass C, GamePtrType gamePtr, jobject j_gi,
|
||||||
jobjectArray j_names, jobjectArray j_dicts, jobjectArray j_paths,
|
jobject j_util, jobject j_draw, jobject j_cp,
|
||||||
jstring j_lang, jobject j_util, jobject j_draw, jobject j_cp,
|
|
||||||
jobject j_procs )
|
jobject j_procs )
|
||||||
{
|
{
|
||||||
XWJNI_START_GLOBALS();
|
XWJNI_START_GLOBALS();
|
||||||
|
@ -1385,24 +1384,24 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeNewGame
|
||||||
game_makeNewGame( MPPARM(mpool) env, &state->game, gi,
|
game_makeNewGame( MPPARM(mpool) env, &state->game, gi,
|
||||||
globals->util, dctx, &cp, globals->xportProcs );
|
globals->util, dctx, &cp, globals->xportProcs );
|
||||||
|
|
||||||
DictionaryCtxt* dict;
|
/* DictionaryCtxt* dict; */
|
||||||
PlayerDicts dicts;
|
/* PlayerDicts dicts; */
|
||||||
|
|
||||||
makeDicts( MPPARM(state->globalJNI->mpool) env,
|
/* makeDicts( MPPARM(state->globalJNI->mpool) env, */
|
||||||
TI_IF(&state->globalJNI->ti)
|
/* TI_IF(&state->globalJNI->ti) */
|
||||||
state->globalJNI->dictMgr,
|
/* state->globalJNI->dictMgr, */
|
||||||
globals->jniutil, &dict, &dicts, j_names, j_dicts,
|
/* globals->jniutil, &dict, &dicts, j_names, j_dicts, */
|
||||||
j_paths, j_lang );
|
/* j_paths, j_lang ); */
|
||||||
#ifdef STUBBED_DICT
|
/* #ifdef STUBBED_DICT */
|
||||||
if ( !dict ) {
|
/* if ( !dict ) { */
|
||||||
XP_LOGFF( "falling back to stubbed dict" );
|
/* XP_LOGFF( "falling back to stubbed dict" ); */
|
||||||
dict = make_stubbed_dict( MPPARM_NOCOMMA(mpool) );
|
/* dict = make_stubbed_dict( MPPARM_NOCOMMA(mpool) ); */
|
||||||
}
|
/* } */
|
||||||
#endif
|
/* #endif */
|
||||||
model_setDictionary( state->game.model, env, dict );
|
/* model_setDictionary( state->game.model, env, dict ); */
|
||||||
dict_unref( dict, env ); /* game owns it now */
|
/* dict_unref( dict, env ); /\* game owns it now *\/ */
|
||||||
model_setPlayerDicts( state->game.model, env, &dicts );
|
/* model_setPlayerDicts( state->game.model, env, &dicts ); */
|
||||||
dict_unref_all( &dicts, env );
|
/* dict_unref_all( &dicts, env ); */
|
||||||
XWJNI_END();
|
XWJNI_END();
|
||||||
} /* makeNewGame */
|
} /* makeNewGame */
|
||||||
|
|
||||||
|
@ -1437,12 +1436,11 @@ JNIEXPORT void JNICALL Java_org_eehouse_android_xw4_jni_XwJNI_game_1dispose
|
||||||
JNIEXPORT jboolean JNICALL
|
JNIEXPORT jboolean JNICALL
|
||||||
Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeFromStream
|
Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeFromStream
|
||||||
( JNIEnv* env, jclass C, GamePtrType gamePtr, jbyteArray jstream, jobject /*out*/jgi,
|
( JNIEnv* env, jclass C, GamePtrType gamePtr, jbyteArray jstream, jobject /*out*/jgi,
|
||||||
jobjectArray jdictNames, jobjectArray jdicts, jobjectArray jpaths,
|
jobject jutil, jobject jdraw, jobject jcp, jobject jprocs )
|
||||||
jstring jlang, jobject jutil, jobject jdraw, jobject jcp, jobject jprocs )
|
|
||||||
{
|
{
|
||||||
jboolean result;
|
jboolean result;
|
||||||
DictionaryCtxt* dict;
|
/* DictionaryCtxt* dict; */
|
||||||
PlayerDicts dicts;
|
/* PlayerDicts dicts; */
|
||||||
XWJNI_START_GLOBALS();
|
XWJNI_START_GLOBALS();
|
||||||
|
|
||||||
globals->gi = (CurGameInfo*)XP_CALLOC( mpool, sizeof(*globals->gi) );
|
globals->gi = (CurGameInfo*)XP_CALLOC( mpool, sizeof(*globals->gi) );
|
||||||
|
@ -1450,11 +1448,11 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeFromStream
|
||||||
TI_IF(&state->globalJNI->ti)
|
TI_IF(&state->globalJNI->ti)
|
||||||
jutil, globals->gi, globals);
|
jutil, globals->gi, globals);
|
||||||
globals->jniutil = state->globalJNI->jniutil;
|
globals->jniutil = state->globalJNI->jniutil;
|
||||||
makeDicts( MPPARM(state->globalJNI->mpool) env,
|
/* makeDicts( MPPARM(state->globalJNI->mpool) env, */
|
||||||
TI_IF(&state->globalJNI->ti)
|
/* TI_IF(&state->globalJNI->ti) */
|
||||||
state->globalJNI->dictMgr,
|
/* state->globalJNI->dictMgr, */
|
||||||
globals->jniutil, &dict, &dicts, jdictNames, jdicts, jpaths,
|
/* globals->jniutil, &dict, &dicts, jdictNames, jdicts, jpaths, */
|
||||||
jlang );
|
/* jlang ); */
|
||||||
if ( !!jdraw ) {
|
if ( !!jdraw ) {
|
||||||
globals->dctx = makeDraw( MPPARM(mpool) env,
|
globals->dctx = makeDraw( MPPARM(mpool) env,
|
||||||
TI_IF(&state->globalJNI->ti)
|
TI_IF(&state->globalJNI->ti)
|
||||||
|
@ -1473,8 +1471,8 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeFromStream
|
||||||
globals->gi, globals->util, globals->dctx,
|
globals->gi, globals->util, globals->dctx,
|
||||||
&cp, globals->xportProcs );
|
&cp, globals->xportProcs );
|
||||||
stream_destroy( stream, env );
|
stream_destroy( stream, env );
|
||||||
dict_unref( dict, env ); /* game owns it now */
|
/* dict_unref( dict, env ); /\* game owns it now *\/ */
|
||||||
dict_unref_all( &dicts, env );
|
/* dict_unref_all( &dicts, env ); */
|
||||||
|
|
||||||
/* If game_makeFromStream() fails, the platform-side caller still needs to
|
/* If game_makeFromStream() fails, the platform-side caller still needs to
|
||||||
call game_dispose. That requirement's better than having cleanup code
|
call game_dispose. That requirement's better than having cleanup code
|
||||||
|
|
Loading…
Add table
Reference in a new issue