expect the array of dicts passed to include the game dict (as part of

changes to always have a game dict and to have player dicts only when
they're different.)
This commit is contained in:
Andy2 2011-04-25 20:16:38 -07:00
parent 6aa0d38c45
commit bf67a88c5a
3 changed files with 34 additions and 16 deletions

View file

@ -422,24 +422,32 @@ and_dictionary_make_empty( MPFORMAL JNIEnv* env, JNIUtilCtxt* jniutil )
}
void
makeDicts( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil, PlayerDicts* dicts,
makeDicts( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil,
DictionaryCtxt** dictp, PlayerDicts* dicts,
jobjectArray jdicts, jobjectArray jnames, jstring jlang )
{
int ii;
jsize len = (*env)->GetArrayLength( env, jdicts );
XP_ASSERT( len == (*env)->GetArrayLength( env, jnames ) );
for ( ii = 0; ii < VSIZE(dicts->dicts); ++ii ) {
for ( ii = 0; ii <= VSIZE(dicts->dicts); ++ii ) {
DictionaryCtxt* dict = NULL;
if ( ii < len ) {
jobject jdict = (*env)->GetObjectArrayElement( env, jdicts, ii );
jstring jname = (*env)->GetObjectArrayElement( env, jnames, ii );
dict = makeDict( MPPARM(mpool) env, jniutil, jdict, jname, jlang );
XP_ASSERT( !!dict );
(*env)->DeleteLocalRef( env, jdict );
(*env)->DeleteLocalRef( env, jname );
}
dicts->dicts[ii] = dict;
if ( NULL != jdict ) {
jstring jname = (*env)->GetObjectArrayElement( env, jnames, ii );
dict = makeDict( MPPARM(mpool) env, jniutil, jdict, jname, jlang );
XP_ASSERT( !!dict );
(*env)->DeleteLocalRef( env, jdict );
(*env)->DeleteLocalRef( env, jname );
}
}
if ( 0 == ii ) {
*dictp = dict;
} else {
XP_ASSERT( ii-1 < VSIZE( dicts->dicts ) );
dicts->dicts[ii-1] = dict;
}
}
}

View file

@ -32,8 +32,10 @@ dict_splitFaces( DictionaryCtxt* dict, const XP_U8* bytes,
DictionaryCtxt* makeDict( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil,
jbyteArray bytes, jstring jname, jstring jlang );
void makeDicts( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil, PlayerDicts* dicts,
jobjectArray jdicts, jobjectArray jnames, jstring jlang );
void makeDicts( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil,
DictionaryCtxt** dict,
PlayerDicts* dicts, jobjectArray jdicts, jobjectArray jnames,
jstring jlang );
void destroyDicts( PlayerDicts* dicts );

View file

@ -59,6 +59,9 @@ makeGI( MPFORMAL JNIEnv* env, jobject j_gi )
jenumFieldToInt( env, j_gi, "serverRole",
"org/eehouse/android/xw4/jni/CurGameInfo$DeviceRole");
getString( env, j_gi, "dictName", buf, VSIZE(buf) );
gi->dictName = copyString( mpool, buf );
XP_ASSERT( gi->nPlayers <= MAX_NUM_PLAYERS );
jobject jplayers;
@ -106,6 +109,7 @@ setJGI( JNIEnv* env, jobject jgi, const CurGameInfo* gi )
setBool( env, jgi, "hintsNotAllowed", gi->hintsNotAllowed );
setBool( env, jgi, "timerEnabled", gi->timerEnabled );
setBool( env, jgi, "allowPickTiles", gi->allowPickTiles );
setString( env, jgi, "dictName", gi->dictName );
intToJenumField( env, jgi, gi->phoniesAction, "phoniesAction",
"org/eehouse/android/xw4/jni/CurGameInfo$XWPhoniesChoice" );
@ -394,15 +398,17 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeNewGame
game_makeNewGame( MPPARM(mpool) &state->game, gi, globals->util, dctx, &cp,
globals->xportProcs );
DictionaryCtxt* dict;
PlayerDicts dicts;
makeDicts( MPPARM(mpool) env, globals->jniutil, &dicts, j_dicts, j_names,
j_lang );
makeDicts( MPPARM(mpool) env, globals->jniutil, &dict, &dicts, j_dicts,
j_names, j_lang );
#ifdef STUBBED_DICT
if ( !dict ) {
XP_LOGF( "falling back to stubbed dict" );
dict = make_stubbed_dict( MPPARM_NOCOMMA(mpool) );
}
#endif
model_setDictionary( state->game.model, dict );
model_setPlayerDicts( state->game.model, &dicts );
XWJNI_END();
} /* makeNewGame */
@ -440,6 +446,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeFromStream
jobject jutil, jobject jniu, jobject jdraw, jobject jcp, jobject jprocs )
{
jboolean result;
DictionaryCtxt* dict;
PlayerDicts dicts;
XWJNI_START_GLOBALS();
@ -447,8 +454,8 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeFromStream
globals->util = makeUtil( MPPARM(mpool) &state->env,
jutil, globals->gi, globals );
globals->jniutil = makeJNIUtil( MPPARM(mpool) &state->env, jniu );
makeDicts( MPPARM(mpool) env, globals->jniutil, &dicts, jdicts, jdictNames,
jlang );
makeDicts( MPPARM(mpool) env, globals->jniutil, &dict, &dicts, jdicts,
jdictNames, jlang );
globals->dctx = makeDraw( MPPARM(mpool) &state->env, jdraw );
globals->xportProcs = makeXportProcs( MPPARM(mpool) &state->env, jprocs );
@ -458,7 +465,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeFromStream
CommonPrefs cp;
loadCommonPrefs( env, &cp, jcp );
result = game_makeFromStream( MPPARM(mpool) stream, &state->game,
globals->gi, NULL, &dicts,
globals->gi, dict, &dicts,
globals->util, globals->dctx, &cp,
globals->xportProcs );
stream_destroy( stream );
@ -472,6 +479,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeFromStream
destroyDraw( &globals->dctx );
destroyXportProcs( &globals->xportProcs );
destroyDicts( &dicts );
dict_destroy( dict );
destroyUtil( &globals->util );
destroyJNIUtil( &globals->jniutil );
destroyGI( MPPARM(mpool) &globals->gi );