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 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 ) jobjectArray jdicts, jobjectArray jnames, jstring jlang )
{ {
int ii; int ii;
jsize len = (*env)->GetArrayLength( env, jdicts ); jsize len = (*env)->GetArrayLength( env, jdicts );
XP_ASSERT( len == (*env)->GetArrayLength( env, jnames ) ); 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; DictionaryCtxt* dict = NULL;
if ( ii < len ) { if ( ii < len ) {
jobject jdict = (*env)->GetObjectArrayElement( env, jdicts, ii ); jobject jdict = (*env)->GetObjectArrayElement( env, jdicts, ii );
jstring jname = (*env)->GetObjectArrayElement( env, jnames, ii ); if ( NULL != jdict ) {
dict = makeDict( MPPARM(mpool) env, jniutil, jdict, jname, jlang ); jstring jname = (*env)->GetObjectArrayElement( env, jnames, ii );
XP_ASSERT( !!dict ); dict = makeDict( MPPARM(mpool) env, jniutil, jdict, jname, jlang );
(*env)->DeleteLocalRef( env, jdict ); XP_ASSERT( !!dict );
(*env)->DeleteLocalRef( env, jname ); (*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;
} }
dicts->dicts[ii] = dict;
} }
} }

View file

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

View file

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