diff --git a/xwords4/android/XWords4/jni/andutils.c b/xwords4/android/XWords4/jni/andutils.c index 5ebe726ec..ad3f51c10 100644 --- a/xwords4/android/XWords4/jni/andutils.c +++ b/xwords4/android/XWords4/jni/andutils.c @@ -158,7 +158,7 @@ getObject( JNIEnv* env, jobject obj, const char* name, const char* sig, jclass cls = (*env)->GetObjectClass( env, obj ); XP_ASSERT( !!cls ); jfieldID fid = (*env)->GetFieldID( env, cls, name, sig ); - XP_ASSERT( !!fid ); /* failed */ + XP_ASSERT( !!fid ); *ret = (*env)->GetObjectField( env, obj, fid ); XP_ASSERT( !!*ret ); @@ -166,6 +166,19 @@ getObject( JNIEnv* env, jobject obj, const char* name, const char* sig, return true; } +void +setObject( JNIEnv* env, jobject obj, const char* name, const char* sig, + jobject val ) +{ + jclass cls = (*env)->GetObjectClass( env, obj ); + XP_ASSERT( !!cls ); + jfieldID fid = (*env)->GetFieldID( env, cls, name, sig ); + XP_ASSERT( !!fid ); + (*env)->SetObjectField( env, obj, fid, val ); + + (*env)->DeleteLocalRef( env, cls ); +} + /* return false on failure, e.g. exception raised */ bool getBool( JNIEnv* env, jobject obj, const char* name ) @@ -236,7 +249,7 @@ getIntFromArray( JNIEnv* env, jintArray arr, bool del ) int result = ints[0]; (*env)->ReleaseIntArrayElements( env, arr, ints, 0); if ( del ) { - (*env)->DeleteLocalRef( env, arr ); + (*env)->DeleteLocalRef( env, arr ); } return result; } @@ -286,27 +299,6 @@ getMethodID( JNIEnv* env, jobject obj, const char* proc, const char* sig ) return mid; } -jobjectArray -makeBitmapsArray( JNIEnv* env, const XP_Bitmaps* bitmaps ) -{ - jobjectArray result = NULL; - - if ( !!bitmaps && bitmaps->nBitmaps > 0 ) { - jclass clazz = (*env)->FindClass( env, - "android/graphics/drawable/BitmapDrawable" ); - XP_ASSERT( !!clazz ); - result = (*env)->NewObjectArray( env, bitmaps->nBitmaps, clazz, NULL ); - (*env)->DeleteLocalRef( env, clazz ); - - int ii; - for ( ii = 0; ii < bitmaps->nBitmaps; ++ii ) { - (*env)->SetObjectArrayElement( env, result, ii, bitmaps->bmps[ii] ); - } - } - - return result; -} - void setJAddrRec( JNIEnv* env, jobject jaddr, const CommsAddrRec* addr ) { diff --git a/xwords4/android/XWords4/jni/andutils.h b/xwords4/android/XWords4/jni/andutils.h index 8c675b59a..2ef65b3a2 100644 --- a/xwords4/android/XWords4/jni/andutils.h +++ b/xwords4/android/XWords4/jni/andutils.h @@ -40,6 +40,8 @@ bool setBool( JNIEnv* env, jobject obj, const char* name, bool value ); bool setString( JNIEnv* env, jobject obj, const char* name, const XP_UCHAR* value ); void getString( JNIEnv* env, jobject jlp, const char* name, XP_UCHAR* buf, int bufLen ); +void setObject( JNIEnv* env, jobject obj, const char* name, const char* sig, + jobject val ); bool getObject( JNIEnv* env, jobject obj, const char* name, const char* sig, jobject* ret ); @@ -55,8 +57,6 @@ void setBoolArray( JNIEnv* env, jbooleanArray jarr, int count, jobjectArray makeStringArray( JNIEnv *env, int size, const XP_UCHAR** vals ); jstring streamToJString( MPFORMAL JNIEnv* env, XWStreamCtxt* stream ); -jobjectArray makeBitmapsArray( JNIEnv* env, const XP_Bitmaps* bitmaps ); - /* Note: jmethodID can be cached. Should not look up more than once. */ jmethodID getMethodID( JNIEnv* env, jobject obj, const char* proc, const char* sig ); diff --git a/xwords4/android/XWords4/jni/xwjni.c b/xwords4/android/XWords4/jni/xwjni.c index 0332c7ed2..8eea5739f 100644 --- a/xwords4/android/XWords4/jni/xwjni.c +++ b/xwords4/android/XWords4/jni/xwjni.c @@ -927,14 +927,14 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1receiveMessage JNIEXPORT void JNICALL Java_org_eehouse_android_xw4_jni_XwJNI_game_1summarize -( JNIEnv* env, jclass C, jint gamePtr, jobject jsummary ) +( JNIEnv* env, jclass C, jint gamePtr, jint nPlayers, jobject jsummary ) { LOG_FUNC(); XWJNI_START(); XP_S16 nMoves = model_getNMoves( state->game.model ); setInt( env, jsummary, "nMoves", nMoves ); - setBool( env, jsummary, "gameOver", - server_getGameIsOver( state->game.server ) ); + XP_Bool gameOver = server_getGameIsOver( state->game.server ); + setBool( env, jsummary, "gameOver", gameOver ); if ( !!state->game.comms ) { CommsAddrRec addr; @@ -949,6 +949,23 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1summarize } } + jint jvals[nPlayers]; + int ii; + if ( gameOver ) { + ScoresArray scores; + model_figureFinalScores( state->game.model, &scores, NULL ); + for ( ii = 0; ii < nPlayers; ++ii ) { + jvals[ii] = scores.arr[ii]; + } + } else { + for ( ii = 0; ii < nPlayers; ++ii ) { + jvals[ii] = model_getPlayerScore( state->game.model, ii ); + } + } + jintArray jarr = makeIntArray( env, nPlayers, jvals ); + setObject( env, jsummary, "scores", "[I", jarr ); + (*env)->DeleteLocalRef( env, jarr ); + XWJNI_END(); LOG_RETURN_VOID(); }