mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-28 09:58:30 +01:00
extend getSummary() to include array of current scores; add util to set an object
field and remove dead code
This commit is contained in:
parent
b6a89fd8c1
commit
671461f4d4
3 changed files with 37 additions and 28 deletions
|
@ -158,7 +158,7 @@ getObject( JNIEnv* env, jobject obj, const char* name, const char* sig,
|
||||||
jclass cls = (*env)->GetObjectClass( env, obj );
|
jclass cls = (*env)->GetObjectClass( env, obj );
|
||||||
XP_ASSERT( !!cls );
|
XP_ASSERT( !!cls );
|
||||||
jfieldID fid = (*env)->GetFieldID( env, cls, name, sig );
|
jfieldID fid = (*env)->GetFieldID( env, cls, name, sig );
|
||||||
XP_ASSERT( !!fid ); /* failed */
|
XP_ASSERT( !!fid );
|
||||||
*ret = (*env)->GetObjectField( env, obj, fid );
|
*ret = (*env)->GetObjectField( env, obj, fid );
|
||||||
XP_ASSERT( !!*ret );
|
XP_ASSERT( !!*ret );
|
||||||
|
|
||||||
|
@ -166,6 +166,19 @@ getObject( JNIEnv* env, jobject obj, const char* name, const char* sig,
|
||||||
return true;
|
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 */
|
/* return false on failure, e.g. exception raised */
|
||||||
bool
|
bool
|
||||||
getBool( JNIEnv* env, jobject obj, const char* name )
|
getBool( JNIEnv* env, jobject obj, const char* name )
|
||||||
|
@ -236,7 +249,7 @@ getIntFromArray( JNIEnv* env, jintArray arr, bool del )
|
||||||
int result = ints[0];
|
int result = ints[0];
|
||||||
(*env)->ReleaseIntArrayElements( env, arr, ints, 0);
|
(*env)->ReleaseIntArrayElements( env, arr, ints, 0);
|
||||||
if ( del ) {
|
if ( del ) {
|
||||||
(*env)->DeleteLocalRef( env, arr );
|
(*env)->DeleteLocalRef( env, arr );
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -286,27 +299,6 @@ getMethodID( JNIEnv* env, jobject obj, const char* proc, const char* sig )
|
||||||
return mid;
|
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
|
void
|
||||||
setJAddrRec( JNIEnv* env, jobject jaddr, const CommsAddrRec* addr )
|
setJAddrRec( JNIEnv* env, jobject jaddr, const CommsAddrRec* addr )
|
||||||
{
|
{
|
||||||
|
|
|
@ -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 );
|
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,
|
void getString( JNIEnv* env, jobject jlp, const char* name, XP_UCHAR* buf,
|
||||||
int bufLen );
|
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,
|
bool getObject( JNIEnv* env, jobject obj, const char* name, const char* sig,
|
||||||
jobject* ret );
|
jobject* ret );
|
||||||
|
|
||||||
|
@ -55,8 +57,6 @@ void setBoolArray( JNIEnv* env, jbooleanArray jarr, int count,
|
||||||
jobjectArray makeStringArray( JNIEnv *env, int size, const XP_UCHAR** vals );
|
jobjectArray makeStringArray( JNIEnv *env, int size, const XP_UCHAR** vals );
|
||||||
jstring streamToJString( MPFORMAL JNIEnv* env, XWStreamCtxt* stream );
|
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. */
|
/* Note: jmethodID can be cached. Should not look up more than once. */
|
||||||
jmethodID getMethodID( JNIEnv* env, jobject obj, const char* proc,
|
jmethodID getMethodID( JNIEnv* env, jobject obj, const char* proc,
|
||||||
const char* sig );
|
const char* sig );
|
||||||
|
|
|
@ -927,14 +927,14 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1receiveMessage
|
||||||
|
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL
|
||||||
Java_org_eehouse_android_xw4_jni_XwJNI_game_1summarize
|
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();
|
LOG_FUNC();
|
||||||
XWJNI_START();
|
XWJNI_START();
|
||||||
XP_S16 nMoves = model_getNMoves( state->game.model );
|
XP_S16 nMoves = model_getNMoves( state->game.model );
|
||||||
setInt( env, jsummary, "nMoves", nMoves );
|
setInt( env, jsummary, "nMoves", nMoves );
|
||||||
setBool( env, jsummary, "gameOver",
|
XP_Bool gameOver = server_getGameIsOver( state->game.server );
|
||||||
server_getGameIsOver( state->game.server ) );
|
setBool( env, jsummary, "gameOver", gameOver );
|
||||||
|
|
||||||
if ( !!state->game.comms ) {
|
if ( !!state->game.comms ) {
|
||||||
CommsAddrRec addr;
|
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();
|
XWJNI_END();
|
||||||
LOG_RETURN_VOID();
|
LOG_RETURN_VOID();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue