2010-01-30 15:38:44 +01:00
|
|
|
/* -*-mode: C; compile-command: "../../scripts/ndkbuild.sh"; -*- */
|
2010-01-02 20:10:08 +01:00
|
|
|
#include <string.h>
|
2010-01-12 14:39:19 +01:00
|
|
|
#include <sys/time.h>
|
|
|
|
|
2010-01-02 20:10:08 +01:00
|
|
|
#include <jni.h>
|
|
|
|
#include <android/log.h>
|
|
|
|
|
|
|
|
#include "comtypes.h"
|
|
|
|
#include "game.h"
|
|
|
|
#include "board.h"
|
|
|
|
#include "mempool.h"
|
|
|
|
#include "strutils.h"
|
|
|
|
|
|
|
|
#include "utilwrapper.h"
|
|
|
|
#include "drawwrapper.h"
|
2010-01-30 15:38:44 +01:00
|
|
|
#include "xportwrapper.h"
|
2010-01-02 20:10:08 +01:00
|
|
|
#include "anddict.h"
|
2010-01-16 15:16:27 +01:00
|
|
|
#include "andutils.h"
|
2010-02-11 14:27:09 +01:00
|
|
|
#include "jniutlswrapper.h"
|
2010-01-02 20:10:08 +01:00
|
|
|
|
|
|
|
static CurGameInfo*
|
|
|
|
makeGI( MPFORMAL JNIEnv* env, jobject j_gi )
|
|
|
|
{
|
2010-01-09 14:30:23 +01:00
|
|
|
CurGameInfo* gi = (CurGameInfo*)XP_CALLOC( mpool, sizeof(*gi) );
|
2010-01-02 20:10:08 +01:00
|
|
|
XP_UCHAR buf[256]; /* in case needs whole path */
|
|
|
|
|
2010-01-30 21:06:06 +01:00
|
|
|
gi->nPlayers = getInt( env, j_gi, "nPlayers");
|
2010-02-18 05:44:30 +01:00
|
|
|
gi->gameSeconds = getInt( env, j_gi, "gameSeconds");
|
2010-01-30 21:06:06 +01:00
|
|
|
gi->boardSize = getInt( env, j_gi, "boardSize" );
|
2010-02-14 18:38:40 +01:00
|
|
|
gi->gameID = getInt( env, j_gi, "gameID" );
|
2010-01-30 21:06:06 +01:00
|
|
|
gi->robotSmartness = getInt( env, j_gi, "robotSmartness" );
|
|
|
|
gi->hintsNotAllowed = getBool( env, j_gi, "hintsNotAllowed" );
|
|
|
|
gi->timerEnabled = getBool( env, j_gi, "timerEnabled" );
|
|
|
|
gi->allowPickTiles = getBool( env, j_gi, "allowPickTiles" );
|
|
|
|
gi->allowHintRect = getBool( env, j_gi, "allowHintRect" );
|
|
|
|
|
2010-01-30 14:44:12 +01:00
|
|
|
gi->serverRole =
|
|
|
|
jenumFieldToInt( env, j_gi, "serverRole",
|
|
|
|
"org/eehouse/android/xw4/jni/CurGameInfo$DeviceRole");
|
2010-01-02 20:10:08 +01:00
|
|
|
|
|
|
|
getString( env, j_gi, "dictName", buf, VSIZE(buf) );
|
|
|
|
gi->dictName = copyString( mpool, buf );
|
|
|
|
|
2010-01-30 21:06:06 +01:00
|
|
|
XP_ASSERT( gi->nPlayers <= MAX_NUM_PLAYERS );
|
2010-01-02 20:10:08 +01:00
|
|
|
|
|
|
|
jobject jplayers;
|
|
|
|
if ( getObject( env, j_gi, "players",
|
|
|
|
"[Lorg/eehouse/android/xw4/jni/LocalPlayer;",
|
|
|
|
&jplayers ) ) {
|
2010-01-09 18:19:25 +01:00
|
|
|
int ii;
|
2010-01-02 20:10:08 +01:00
|
|
|
for ( ii = 0; ii < gi->nPlayers; ++ii ) {
|
|
|
|
LocalPlayer* lp = &gi->players[ii];
|
|
|
|
|
|
|
|
jobject jlp = (*env)->GetObjectArrayElement( env, jplayers, ii );
|
2010-01-20 07:43:10 +01:00
|
|
|
XP_ASSERT( !!jlp );
|
2010-01-02 20:10:08 +01:00
|
|
|
|
2010-01-30 21:06:06 +01:00
|
|
|
lp->isRobot = getBool( env, jlp, "isRobot" );
|
|
|
|
lp->isLocal = getBool( env, jlp, "isLocal" );
|
2010-01-02 20:10:08 +01:00
|
|
|
|
2010-01-16 15:16:27 +01:00
|
|
|
getString( env, jlp, "name", buf, VSIZE(buf) );
|
2010-01-02 20:10:08 +01:00
|
|
|
lp->name = copyString( mpool, buf );
|
2010-01-16 15:16:27 +01:00
|
|
|
getString( env, jlp, "password", buf, VSIZE(buf) );
|
2010-01-02 20:10:08 +01:00
|
|
|
lp->password = copyString( mpool, buf );
|
|
|
|
|
|
|
|
lp->secondsUsed = 0;
|
|
|
|
|
|
|
|
(*env)->DeleteLocalRef( env, jlp );
|
|
|
|
}
|
|
|
|
(*env)->DeleteLocalRef( env, jplayers );
|
|
|
|
} else {
|
|
|
|
XP_ASSERT(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return gi;
|
|
|
|
} /* makeGI */
|
|
|
|
|
2010-01-09 18:19:25 +01:00
|
|
|
static void
|
|
|
|
setJGI( JNIEnv* env, jobject jgi, const CurGameInfo* gi )
|
|
|
|
{
|
|
|
|
// set fields
|
2010-01-30 21:06:06 +01:00
|
|
|
setInt( env, jgi, "nPlayers", gi->nPlayers );
|
2010-02-18 05:44:30 +01:00
|
|
|
setInt( env, jgi, "gameSeconds", gi->gameSeconds );
|
2010-01-30 21:06:06 +01:00
|
|
|
setInt( env, jgi, "boardSize", gi->boardSize );
|
2010-02-14 18:38:40 +01:00
|
|
|
setInt( env, jgi, "gameID", gi->gameID );
|
2010-01-30 21:06:06 +01:00
|
|
|
setInt( env, jgi, "robotSmartness", gi->robotSmartness );
|
|
|
|
setBool( env, jgi, "hintsNotAllowed", gi->hintsNotAllowed );
|
|
|
|
setBool( env, jgi, "timerEnabled", gi->timerEnabled );
|
|
|
|
setBool( env, jgi, "allowPickTiles", gi->allowPickTiles );
|
|
|
|
setBool( env, jgi, "allowHintRect", gi->allowHintRect );
|
|
|
|
setString( env, jgi, "dictName", gi->dictName );
|
2010-01-09 18:19:25 +01:00
|
|
|
|
2010-01-30 14:44:12 +01:00
|
|
|
intToJenumField( env, jgi, gi->serverRole, "serverRole",
|
|
|
|
"org/eehouse/android/xw4/jni/CurGameInfo$DeviceRole" );
|
|
|
|
|
2010-01-09 18:19:25 +01:00
|
|
|
jobject jplayers;
|
|
|
|
if ( getObject( env, jgi, "players",
|
|
|
|
"[Lorg/eehouse/android/xw4/jni/LocalPlayer;",
|
|
|
|
&jplayers ) ) {
|
|
|
|
int ii;
|
|
|
|
for ( ii = 0; ii < gi->nPlayers; ++ii ) {
|
|
|
|
const LocalPlayer* lp = &gi->players[ii];
|
|
|
|
|
|
|
|
jobject jlp = (*env)->GetObjectArrayElement( env, jplayers, ii );
|
2010-01-20 07:43:10 +01:00
|
|
|
XP_ASSERT( !!jlp );
|
2010-01-09 18:19:25 +01:00
|
|
|
|
|
|
|
setBool( env, jlp, "isRobot", lp->isRobot );
|
|
|
|
setBool( env, jlp, "isLocal", lp->isLocal );
|
|
|
|
setString( env, jlp, "name", lp->name );
|
|
|
|
setString( env, jlp, "password", lp->password );
|
|
|
|
setInt( env, jlp, "secondsUsed", lp->secondsUsed );
|
|
|
|
|
|
|
|
(*env)->DeleteLocalRef( env, jlp );
|
|
|
|
}
|
|
|
|
(*env)->DeleteLocalRef( env, jplayers );
|
|
|
|
} else {
|
|
|
|
XP_ASSERT(0);
|
|
|
|
}
|
2010-01-20 07:43:10 +01:00
|
|
|
} /* setJGI */
|
2010-01-09 18:19:25 +01:00
|
|
|
|
2010-01-09 14:30:23 +01:00
|
|
|
static void
|
2010-02-09 15:25:52 +01:00
|
|
|
destroyGI( MPFORMAL CurGameInfo** gip )
|
2010-01-09 14:30:23 +01:00
|
|
|
{
|
2010-02-09 15:25:52 +01:00
|
|
|
CurGameInfo* gi = *gip;
|
|
|
|
if ( !!gi ) {
|
|
|
|
gi_disposePlayerInfo( MPPARM(mpool) gi );
|
|
|
|
XP_FREE( mpool, gi );
|
|
|
|
*gip = NULL;
|
|
|
|
}
|
2010-01-09 14:30:23 +01:00
|
|
|
}
|
|
|
|
|
2010-01-30 21:06:06 +01:00
|
|
|
static void
|
2010-01-02 20:10:08 +01:00
|
|
|
loadCommonPrefs( JNIEnv* env, CommonPrefs* cp, jobject j_cp )
|
|
|
|
{
|
2010-01-30 21:06:06 +01:00
|
|
|
cp->showBoardArrow = getBool( env, j_cp, "showBoardArrow" );
|
|
|
|
cp->showRobotScores = getBool( env, j_cp, "showRobotScores" );
|
|
|
|
cp->hideTileValues = getBool( env, j_cp, "hideTileValues" );
|
|
|
|
cp->skipCommitConfirm = getBool( env, j_cp, "skipCommitConfirm" );
|
2010-02-01 16:06:12 +01:00
|
|
|
cp->showColors = getBool( env, j_cp, "showColors" );
|
2010-01-02 20:10:08 +01:00
|
|
|
}
|
|
|
|
|
2010-01-16 15:16:27 +01:00
|
|
|
static XWStreamCtxt*
|
2010-01-31 22:17:21 +01:00
|
|
|
streamFromJStream( MPFORMAL JNIEnv* env, VTableMgr* vtMgr, jbyteArray jstream )
|
2010-01-16 15:16:27 +01:00
|
|
|
{
|
2010-01-31 22:17:21 +01:00
|
|
|
XWStreamCtxt* stream = mem_stream_make( MPPARM(mpool) vtMgr,
|
|
|
|
NULL, 0, NULL );
|
|
|
|
int len = (*env)->GetArrayLength( env, jstream );
|
|
|
|
jbyte* jelems = (*env)->GetByteArrayElements( env, jstream, NULL );
|
|
|
|
stream_putBytes( stream, jelems, len );
|
|
|
|
(*env)->ReleaseByteArrayElements( env, jstream, jelems, 0 );
|
2010-01-16 15:16:27 +01:00
|
|
|
return stream;
|
2010-01-31 22:17:21 +01:00
|
|
|
} /* streamFromJStream */
|
2010-01-16 15:16:27 +01:00
|
|
|
|
2010-01-15 14:44:29 +01:00
|
|
|
/****************************************************
|
2010-01-30 21:06:06 +01:00
|
|
|
* These three methods are stateless: no gamePtr
|
2010-01-15 14:44:29 +01:00
|
|
|
****************************************************/
|
|
|
|
JNIEXPORT jbyteArray JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_gi_1to_1stream
|
|
|
|
(JNIEnv* env, jclass C, jobject jgi )
|
|
|
|
{
|
|
|
|
LOG_FUNC();
|
|
|
|
jbyteArray result;
|
|
|
|
#ifdef MEM_DEBUG
|
|
|
|
MemPoolCtx* mpool = mpool_make();
|
|
|
|
#endif
|
|
|
|
CurGameInfo* gi = makeGI( MPPARM(mpool) env, jgi );
|
|
|
|
VTableMgr* vtMgr = make_vtablemgr( MPPARM_NOCOMMA(mpool) );
|
|
|
|
XWStreamCtxt* stream = mem_stream_make( MPPARM(mpool) vtMgr,
|
|
|
|
NULL, 0, NULL );
|
|
|
|
|
2010-02-14 23:01:06 +01:00
|
|
|
/* Unlike on other platforms, gi is created without a call to
|
|
|
|
game_makeNewGame, which sets gameID. So check here if it's still unset
|
|
|
|
and if necessary set it. */
|
|
|
|
while ( 0 == gi->gameID ) {
|
|
|
|
gi->gameID = and_util_getCurSeconds( NULL );
|
|
|
|
}
|
|
|
|
|
2010-01-15 14:44:29 +01:00
|
|
|
game_saveToStream( NULL, gi, stream );
|
2010-02-09 15:25:52 +01:00
|
|
|
destroyGI( MPPARM(mpool) &gi );
|
2010-01-15 14:44:29 +01:00
|
|
|
|
|
|
|
int nBytes = stream_getSize( stream );
|
|
|
|
result = (*env)->NewByteArray( env, nBytes );
|
|
|
|
jbyte* jelems = (*env)->GetByteArrayElements( env, result, NULL );
|
|
|
|
stream_getBytes( stream, jelems, nBytes );
|
|
|
|
(*env)->ReleaseByteArrayElements( env, result, jelems, 0 );
|
|
|
|
stream_destroy( stream );
|
|
|
|
|
|
|
|
vtmgr_destroy( MPPARM(mpool) vtMgr );
|
|
|
|
#ifdef MEM_DEBUG
|
|
|
|
mpool_destroy( mpool );
|
|
|
|
#endif
|
|
|
|
LOG_RETURN_VOID();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_gi_1from_1stream
|
|
|
|
( JNIEnv* env, jclass C, jobject jgi, jbyteArray jstream )
|
|
|
|
{
|
|
|
|
#ifdef MEM_DEBUG
|
|
|
|
MemPoolCtx* mpool = mpool_make();
|
|
|
|
#endif
|
|
|
|
VTableMgr* vtMgr = make_vtablemgr( MPPARM_NOCOMMA(mpool) );
|
|
|
|
|
2010-01-31 22:17:21 +01:00
|
|
|
XWStreamCtxt* stream = streamFromJStream( MPPARM(mpool) env, vtMgr, jstream );
|
2010-01-15 14:44:29 +01:00
|
|
|
|
|
|
|
CurGameInfo gi;
|
|
|
|
XP_MEMSET( &gi, 0, sizeof(gi) );
|
|
|
|
if ( game_makeFromStream( MPPARM(mpool) stream, NULL,
|
|
|
|
&gi, NULL, NULL, NULL, NULL, NULL ) ) {
|
|
|
|
setJGI( env, jgi, &gi );
|
|
|
|
} else {
|
|
|
|
XP_LOGF( "%s: game_makeFromStream failed", __func__ );
|
|
|
|
}
|
|
|
|
|
|
|
|
gi_disposePlayerInfo( MPPARM(mpool) &gi );
|
|
|
|
|
|
|
|
stream_destroy( stream );
|
|
|
|
vtmgr_destroy( MPPARM(mpool) vtMgr );
|
|
|
|
#ifdef MEM_DEBUG
|
|
|
|
mpool_destroy( mpool );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-01-30 21:06:06 +01:00
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_comms_1getInitialAddr
|
|
|
|
( JNIEnv* env, jclass C, jobject jaddr )
|
|
|
|
{
|
|
|
|
LOG_FUNC();
|
|
|
|
CommsAddrRec addr;
|
|
|
|
comms_getInitialAddr( &addr );
|
|
|
|
setJAddrRec( env, jaddr, &addr );
|
|
|
|
}
|
|
|
|
|
2010-02-11 14:27:09 +01:00
|
|
|
/* Dictionary methods: don't use gamePtr */
|
|
|
|
JNIEXPORT jboolean JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_dict_1tilesAreSame
|
|
|
|
( JNIEnv* env, jclass C, jint dictPtr1, jint dictPtr2 )
|
|
|
|
{
|
|
|
|
LOG_FUNC();
|
|
|
|
jboolean result;
|
|
|
|
const DictionaryCtxt* dict1 = (DictionaryCtxt*)dictPtr1;
|
|
|
|
const DictionaryCtxt* dict2 = (DictionaryCtxt*)dictPtr2;
|
|
|
|
result = dict_tilesAreSame( dict1, dict2 );
|
|
|
|
LOG_RETURNF( "%d", result );
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jobjectArray JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_dict_1getChars
|
|
|
|
( JNIEnv* env, jclass C, jint dictPtr )
|
|
|
|
{
|
|
|
|
LOG_FUNC();
|
|
|
|
jobject result = NULL;
|
|
|
|
result = and_dictionary_getChars( env, (DictionaryCtxt*)dictPtr );
|
|
|
|
(*env)->DeleteLocalRef( env, result );
|
|
|
|
LOG_RETURNF( "%p", result );
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-01-10 18:29:09 +01:00
|
|
|
typedef struct _JNIState {
|
2010-01-02 20:10:08 +01:00
|
|
|
XWGame game;
|
2010-01-10 18:29:09 +01:00
|
|
|
JNIEnv* env;
|
|
|
|
AndGlobals globals;
|
2010-01-02 20:10:08 +01:00
|
|
|
MPSLOT
|
2010-01-10 18:29:09 +01:00
|
|
|
} JNIState;
|
|
|
|
|
|
|
|
#define XWJNI_START() { \
|
|
|
|
XP_ASSERT( 0 != gamePtr ); \
|
|
|
|
JNIState* state = (JNIState*)gamePtr; \
|
2010-01-11 00:38:49 +01:00
|
|
|
MPSLOT; \
|
|
|
|
MPASSIGN( mpool, state->mpool); \
|
2010-01-10 18:29:09 +01:00
|
|
|
/* if reentrant must be from same thread */ \
|
|
|
|
XP_ASSERT( state->env == 0 || state->env == env ); \
|
|
|
|
JNIEnv* _oldEnv = state->env; \
|
|
|
|
state->env = env;
|
|
|
|
|
2010-02-12 08:13:42 +01:00
|
|
|
#define XWJNI_START_GLOBALS() \
|
|
|
|
XWJNI_START() \
|
|
|
|
AndGlobals* globals = &state->globals; \
|
|
|
|
|
2010-01-10 18:29:09 +01:00
|
|
|
#define XWJNI_END() \
|
|
|
|
state->env = _oldEnv; \
|
|
|
|
}
|
2010-01-02 20:10:08 +01:00
|
|
|
|
|
|
|
JNIEXPORT jint JNICALL
|
2010-01-09 18:19:25 +01:00
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_initJNI
|
|
|
|
( JNIEnv* env, jclass C )
|
2010-01-02 20:10:08 +01:00
|
|
|
{
|
2010-01-12 14:39:19 +01:00
|
|
|
struct timeval tv;
|
|
|
|
gettimeofday( &tv, NULL );
|
|
|
|
srandom( tv.tv_sec );
|
2010-01-11 00:38:49 +01:00
|
|
|
#ifdef MEM_DEBUG
|
2010-01-02 20:10:08 +01:00
|
|
|
MemPoolCtx* mpool = mpool_make();
|
2010-01-11 00:38:49 +01:00
|
|
|
#endif
|
2010-01-10 18:29:09 +01:00
|
|
|
JNIState* state = (JNIState*)XP_CALLOC( mpool, sizeof(*state) );
|
|
|
|
AndGlobals* globals = &state->globals;
|
2010-01-31 22:17:21 +01:00
|
|
|
globals->state = (struct JNIState*)state;
|
2010-01-11 00:38:49 +01:00
|
|
|
MPASSIGN( state->mpool, mpool );
|
2010-01-02 20:10:08 +01:00
|
|
|
globals->vtMgr = make_vtablemgr(MPPARM_NOCOMMA(mpool));
|
|
|
|
|
2010-01-10 18:29:09 +01:00
|
|
|
return (jint) state;
|
2010-01-09 18:19:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeNewGame
|
2010-02-11 14:27:09 +01:00
|
|
|
( JNIEnv* env, jclass C, jint gamePtr, jobject j_gi, jobject j_util,
|
|
|
|
jobject jniu, jobject j_draw, jobject j_cp, jobject j_procs,
|
|
|
|
jbyteArray jDictBytes )
|
2010-01-09 18:19:25 +01:00
|
|
|
{
|
2010-02-12 08:13:42 +01:00
|
|
|
XWJNI_START_GLOBALS();
|
2010-01-02 20:10:08 +01:00
|
|
|
CurGameInfo* gi = makeGI( MPPARM(mpool) env, j_gi );
|
|
|
|
globals->gi = gi;
|
2010-02-11 14:27:09 +01:00
|
|
|
globals->util = makeUtil( MPPARM(mpool) &state->env, j_util, gi,
|
|
|
|
globals );
|
|
|
|
globals->jniutil = makeJNIUtil( MPPARM(mpool) &state->env, jniu );
|
2010-01-10 18:29:09 +01:00
|
|
|
DrawCtx* dctx = makeDraw( MPPARM(mpool) &state->env, j_draw );
|
2010-01-02 20:10:08 +01:00
|
|
|
globals->dctx = dctx;
|
2010-01-30 15:38:44 +01:00
|
|
|
globals->xportProcs = makeXportProcs( MPPARM(mpool) &state->env, j_procs );
|
2010-01-02 20:10:08 +01:00
|
|
|
CommonPrefs cp;
|
2010-01-30 21:06:06 +01:00
|
|
|
loadCommonPrefs( env, &cp, j_cp );
|
2010-01-02 20:10:08 +01:00
|
|
|
|
|
|
|
XP_LOGF( "calling game_makeNewGame" );
|
2010-02-11 14:27:09 +01:00
|
|
|
game_makeNewGame( MPPARM(mpool) &state->game, gi, globals->util, dctx, &cp,
|
2010-01-31 22:35:07 +01:00
|
|
|
globals->xportProcs );
|
2010-01-02 20:10:08 +01:00
|
|
|
|
2010-02-11 14:27:09 +01:00
|
|
|
DictionaryCtxt* dict = makeDict( MPPARM(mpool) env, globals->jniutil,
|
|
|
|
jDictBytes );
|
2010-01-02 20:10:08 +01:00
|
|
|
#ifdef STUBBED_DICT
|
|
|
|
if ( !dict ) {
|
|
|
|
XP_LOGF( "falling back to stubbed dict" );
|
2010-01-11 00:38:49 +01:00
|
|
|
dict = make_stubbed_dict( MPPARM_NOCOMMA(mpool) );
|
2010-01-02 20:10:08 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
XP_ASSERT( !!dict );
|
2010-01-10 18:29:09 +01:00
|
|
|
model_setDictionary( state->game.model, dict );
|
|
|
|
XWJNI_END();
|
2010-01-09 14:30:23 +01:00
|
|
|
} /* makeNewGame */
|
2010-01-02 20:10:08 +01:00
|
|
|
|
2010-01-10 18:29:09 +01:00
|
|
|
JNIEXPORT void JNICALL Java_org_eehouse_android_xw4_jni_XwJNI_game_1dispose
|
|
|
|
( JNIEnv * env, jclass claz, jint gamePtr )
|
|
|
|
{
|
|
|
|
LOG_FUNC();
|
|
|
|
JNIState* state = (JNIState*)gamePtr;
|
2010-01-11 00:38:49 +01:00
|
|
|
#ifdef MEM_DEBUG
|
2010-01-10 18:29:09 +01:00
|
|
|
MemPoolCtx* mpool = state->mpool;
|
2010-01-11 00:38:49 +01:00
|
|
|
#endif
|
2010-01-10 18:29:09 +01:00
|
|
|
AndGlobals* globals = &state->globals;
|
|
|
|
|
2010-02-09 15:25:52 +01:00
|
|
|
destroyGI( MPPARM(mpool) &globals->gi );
|
2010-01-10 18:29:09 +01:00
|
|
|
|
|
|
|
JNIEnv* oldEnv = state->env;
|
|
|
|
state->env = env;
|
|
|
|
game_dispose( &state->game );
|
|
|
|
|
2010-02-09 15:25:52 +01:00
|
|
|
destroyDraw( &globals->dctx );
|
|
|
|
destroyXportProcs( &globals->xportProcs );
|
|
|
|
destroyUtil( &globals->util );
|
2010-02-11 14:27:09 +01:00
|
|
|
destroyJNIUtil( &globals->jniutil );
|
2010-01-11 00:38:49 +01:00
|
|
|
vtmgr_destroy( MPPARM(mpool) globals->vtMgr );
|
2010-01-10 18:29:09 +01:00
|
|
|
|
|
|
|
state->env = oldEnv;
|
|
|
|
XP_FREE( mpool, state );
|
|
|
|
mpool_destroy( mpool );
|
|
|
|
LOG_RETURN_VOID();
|
2010-01-15 14:44:29 +01:00
|
|
|
} /* game_dispose */
|
2010-01-10 18:29:09 +01:00
|
|
|
|
2010-01-09 18:19:25 +01:00
|
|
|
JNIEXPORT jboolean JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeFromStream
|
|
|
|
( JNIEnv* env, jclass C, jint gamePtr, jbyteArray jstream,
|
2010-02-11 14:27:09 +01:00
|
|
|
jobject /*out*/jgi, jbyteArray jdict, jobject jutil, jobject jniu,
|
|
|
|
jobject jdraw, jobject jcp, jobject jprocs )
|
2010-01-09 18:19:25 +01:00
|
|
|
{
|
2010-01-10 18:29:09 +01:00
|
|
|
jboolean result;
|
2010-02-12 08:13:42 +01:00
|
|
|
XWJNI_START_GLOBALS();
|
2010-01-09 18:19:25 +01:00
|
|
|
|
|
|
|
globals->gi = (CurGameInfo*)XP_CALLOC( mpool, sizeof(*globals->gi) );
|
2010-02-09 15:25:52 +01:00
|
|
|
globals->util = makeUtil( MPPARM(mpool) &state->env,
|
|
|
|
jutil, globals->gi, globals );
|
2010-02-11 14:27:09 +01:00
|
|
|
globals->jniutil = makeJNIUtil( MPPARM(mpool) &state->env, jniu );
|
|
|
|
DictionaryCtxt* dict = makeDict( MPPARM(mpool) env, globals->jniutil, jdict );
|
2010-01-10 18:29:09 +01:00
|
|
|
globals->dctx = makeDraw( MPPARM(mpool) &state->env, jdraw );
|
2010-01-30 15:38:44 +01:00
|
|
|
globals->xportProcs = makeXportProcs( MPPARM(mpool) &state->env, jprocs );
|
2010-01-09 18:19:25 +01:00
|
|
|
|
2010-01-31 22:17:21 +01:00
|
|
|
XWStreamCtxt* stream = streamFromJStream( MPPARM(mpool) env,
|
|
|
|
globals->vtMgr, jstream );
|
2010-01-09 18:19:25 +01:00
|
|
|
|
|
|
|
CommonPrefs cp;
|
2010-01-30 21:06:06 +01:00
|
|
|
loadCommonPrefs( env, &cp, jcp );
|
2010-01-11 00:38:49 +01:00
|
|
|
result = game_makeFromStream( MPPARM(mpool) stream, &state->game,
|
2010-01-10 18:29:09 +01:00
|
|
|
globals->gi, dict,
|
|
|
|
globals->util, globals->dctx, &cp,
|
2010-01-30 15:38:44 +01:00
|
|
|
globals->xportProcs );
|
2010-01-09 18:19:25 +01:00
|
|
|
stream_destroy( stream );
|
|
|
|
|
2010-01-15 14:44:29 +01:00
|
|
|
if ( result ) {
|
2010-02-14 18:38:40 +01:00
|
|
|
XP_ASSERT( 0 != globals->gi->gameID );
|
2010-02-09 15:25:52 +01:00
|
|
|
if ( !!jgi ) {
|
|
|
|
setJGI( env, jgi, globals->gi );
|
|
|
|
}
|
2010-01-15 14:44:29 +01:00
|
|
|
} else {
|
2010-02-09 15:25:52 +01:00
|
|
|
destroyDraw( &globals->dctx );
|
|
|
|
destroyXportProcs( &globals->xportProcs );
|
2010-01-20 07:43:10 +01:00
|
|
|
dict_destroy( dict );
|
2010-02-09 15:25:52 +01:00
|
|
|
dict = NULL;
|
|
|
|
destroyUtil( &globals->util );
|
2010-02-11 14:27:09 +01:00
|
|
|
destroyJNIUtil( &globals->jniutil );
|
2010-02-09 15:25:52 +01:00
|
|
|
destroyGI( MPPARM(mpool) &globals->gi );
|
2010-01-15 14:44:29 +01:00
|
|
|
}
|
2010-01-09 18:19:25 +01:00
|
|
|
|
2010-01-10 18:29:09 +01:00
|
|
|
XWJNI_END();
|
2010-01-09 18:19:25 +01:00
|
|
|
return result;
|
|
|
|
} /* makeFromStream */
|
|
|
|
|
|
|
|
JNIEXPORT jbyteArray JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_game_1saveToStream
|
|
|
|
( JNIEnv* env, jclass C, jint gamePtr, jobject jgi )
|
|
|
|
{
|
2010-01-10 18:29:09 +01:00
|
|
|
jbyteArray result;
|
2010-02-12 08:13:42 +01:00
|
|
|
XWJNI_START_GLOBALS();
|
2010-01-09 18:19:25 +01:00
|
|
|
|
2010-02-11 14:27:09 +01:00
|
|
|
/* Use our copy of gi if none's provided. That's because only the caller
|
|
|
|
knows if its gi should win -- user has changed game config -- or if
|
|
|
|
ours should -- changes like remote players being added. */
|
|
|
|
CurGameInfo* gi =
|
|
|
|
(NULL == jgi) ? globals->gi : makeGI( MPPARM(mpool) env, jgi );
|
2010-01-11 00:38:49 +01:00
|
|
|
XWStreamCtxt* stream = mem_stream_make( MPPARM(mpool) globals->vtMgr,
|
2010-01-09 18:19:25 +01:00
|
|
|
NULL, 0, NULL );
|
2010-01-10 18:29:09 +01:00
|
|
|
|
|
|
|
game_saveToStream( &state->game, gi, stream );
|
2010-02-11 14:27:09 +01:00
|
|
|
|
|
|
|
if ( NULL != jgi ) {
|
|
|
|
destroyGI( MPPARM(mpool) &gi );
|
|
|
|
}
|
2010-01-09 18:19:25 +01:00
|
|
|
|
|
|
|
int nBytes = stream_getSize( stream );
|
2010-01-10 18:29:09 +01:00
|
|
|
result = (*env)->NewByteArray( env, nBytes );
|
|
|
|
jbyte* jelems = (*env)->GetByteArrayElements( env, result, NULL );
|
2010-01-09 18:19:25 +01:00
|
|
|
stream_getBytes( stream, jelems, nBytes );
|
2010-01-10 18:29:09 +01:00
|
|
|
(*env)->ReleaseByteArrayElements( env, result, jelems, 0 );
|
2010-01-09 18:19:25 +01:00
|
|
|
stream_destroy( stream );
|
|
|
|
|
2010-01-10 18:29:09 +01:00
|
|
|
(*env)->DeleteLocalRef( env, result );
|
|
|
|
XWJNI_END();
|
|
|
|
return result;
|
2010-01-02 20:10:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_board_1invalAll
|
|
|
|
( JNIEnv *env, jclass C, jint gamePtr )
|
|
|
|
{
|
2010-01-10 18:29:09 +01:00
|
|
|
XWJNI_START();
|
|
|
|
board_invalAll( state->game.board );
|
|
|
|
XWJNI_END();
|
2010-01-02 20:10:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_board_1draw
|
|
|
|
( JNIEnv *env, jclass C, jint gamePtr )
|
|
|
|
{
|
2010-01-10 18:29:09 +01:00
|
|
|
jboolean result;
|
|
|
|
XWJNI_START();
|
|
|
|
result = board_draw( state->game.board );
|
|
|
|
XWJNI_END();
|
|
|
|
return result;
|
2010-01-02 20:10:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_board_1setPos
|
|
|
|
(JNIEnv *env, jclass C, jint gamePtr, jint left, jint top, jboolean lefty )
|
|
|
|
{
|
2010-01-10 18:29:09 +01:00
|
|
|
XWJNI_START();
|
|
|
|
board_setPos( state->game.board, left, top, lefty );
|
|
|
|
XWJNI_END();
|
2010-01-02 20:10:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_board_1setScale
|
|
|
|
(JNIEnv *env, jclass C, jint gamePtr, jint hscale, jint vscale )
|
|
|
|
{
|
2010-01-10 18:29:09 +01:00
|
|
|
XWJNI_START();
|
|
|
|
board_setScale( state->game.board, hscale, vscale );
|
|
|
|
XWJNI_END();
|
2010-01-02 20:10:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_board_1setScoreboardLoc
|
|
|
|
( JNIEnv *env, jclass C, jint gamePtr, jint left, jint top,
|
|
|
|
jint width, jint height, jboolean divideHorizontally )
|
|
|
|
{
|
2010-01-10 18:29:09 +01:00
|
|
|
XWJNI_START();
|
|
|
|
board_setScoreboardLoc( state->game.board, left, top, width,
|
|
|
|
height, divideHorizontally );
|
|
|
|
XWJNI_END();
|
2010-01-02 20:10:08 +01:00
|
|
|
}
|
|
|
|
|
2010-02-18 05:44:30 +01:00
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_board_1setTimerLoc
|
|
|
|
( JNIEnv* env, jclass C, jint gamePtr, jint timerLeft, jint timerTop,
|
|
|
|
jint timerWidth, jint timerHeight )
|
|
|
|
{
|
|
|
|
XWJNI_START();
|
|
|
|
XP_LOGF( "%s(%d,%d,%d,%d)", __func__, timerLeft, timerTop,
|
|
|
|
timerWidth, timerHeight );
|
|
|
|
board_setTimerLoc( state->game.board, timerLeft, timerTop,
|
|
|
|
timerWidth, timerHeight );
|
|
|
|
XWJNI_END();
|
|
|
|
}
|
|
|
|
|
2010-01-02 20:10:08 +01:00
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_board_1setTrayLoc
|
|
|
|
( JNIEnv *env, jclass C, jint gamePtr, jint left, jint top,
|
|
|
|
jint width, jint height, jint minDividerWidth )
|
|
|
|
{
|
2010-01-10 18:29:09 +01:00
|
|
|
XWJNI_START();
|
|
|
|
board_setTrayLoc( state->game.board, left, top, width, height,
|
|
|
|
minDividerWidth );
|
|
|
|
XWJNI_END();
|
2010-01-02 20:10:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_board_1handlePenDown
|
|
|
|
(JNIEnv *env, jclass C, jint gamePtr, jint xx, jint yy, jbooleanArray barray )
|
|
|
|
{
|
2010-01-10 18:29:09 +01:00
|
|
|
jboolean result;
|
|
|
|
XWJNI_START();
|
2010-01-02 20:10:08 +01:00
|
|
|
XP_Bool bb; /* drop this for now */
|
2010-01-10 18:29:09 +01:00
|
|
|
result = board_handlePenDown( state->game.board, xx, yy, &bb );
|
|
|
|
XWJNI_END();
|
|
|
|
return result;
|
2010-01-02 20:10:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_board_1handlePenMove
|
|
|
|
( JNIEnv *env, jclass C, jint gamePtr, jint xx, jint yy )
|
|
|
|
{
|
2010-01-10 18:29:09 +01:00
|
|
|
jboolean result;
|
|
|
|
XWJNI_START();
|
|
|
|
result = board_handlePenMove( state->game.board, xx, yy );
|
|
|
|
XWJNI_END();
|
|
|
|
return result;
|
2010-01-02 20:10:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_board_1handlePenUp
|
|
|
|
( JNIEnv *env, jclass C, jint gamePtr, jint xx, jint yy )
|
|
|
|
{
|
2010-01-10 18:29:09 +01:00
|
|
|
jboolean result;
|
|
|
|
XWJNI_START();
|
|
|
|
result = board_handlePenUp( state->game.board, xx, yy );
|
|
|
|
XWJNI_END();
|
|
|
|
return result;
|
2010-01-02 20:10:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_board_1juggleTray
|
|
|
|
(JNIEnv* env, jclass C, jint gamePtr )
|
|
|
|
{
|
2010-01-10 18:29:09 +01:00
|
|
|
jboolean result;
|
|
|
|
XWJNI_START();
|
|
|
|
result = board_juggleTray( state->game.board );
|
|
|
|
XWJNI_END();
|
|
|
|
return result;
|
2010-01-02 20:10:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jint JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_board_1getTrayVisState
|
|
|
|
(JNIEnv* env, jclass C, jint gamePtr)
|
|
|
|
{
|
2010-01-10 18:29:09 +01:00
|
|
|
jboolean result;
|
|
|
|
XWJNI_START();
|
|
|
|
result = board_getTrayVisState( state->game.board );
|
|
|
|
XWJNI_END();
|
|
|
|
return result;
|
2010-01-02 20:10:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_board_1hideTray
|
|
|
|
(JNIEnv* env, jclass C, jint gamePtr)
|
|
|
|
{
|
2010-01-10 18:29:09 +01:00
|
|
|
jboolean result;
|
|
|
|
XWJNI_START();
|
|
|
|
result = board_hideTray( state->game.board );
|
|
|
|
XWJNI_END();
|
|
|
|
return result;
|
2010-01-02 20:10:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_board_1showTray
|
|
|
|
(JNIEnv* env, jclass C, jint gamePtr)
|
|
|
|
{
|
2010-01-10 18:29:09 +01:00
|
|
|
jboolean result;
|
|
|
|
XWJNI_START();
|
|
|
|
result = board_showTray( state->game.board );
|
|
|
|
XWJNI_END();
|
|
|
|
return result;
|
2010-01-02 20:10:08 +01:00
|
|
|
}
|
|
|
|
|
2010-01-13 13:29:11 +01:00
|
|
|
JNIEXPORT jboolean JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_board_1beginTrade
|
|
|
|
( JNIEnv* env, jclass C, jint gamePtr )
|
|
|
|
{
|
|
|
|
jboolean result;
|
|
|
|
XWJNI_START();
|
|
|
|
result = board_beginTrade( state->game.board );
|
|
|
|
XWJNI_END();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-01-12 14:39:19 +01:00
|
|
|
JNIEXPORT jboolean JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_board_1toggle_1showValues
|
|
|
|
( JNIEnv* env, jclass C, jint gamePtr )
|
|
|
|
{
|
|
|
|
jboolean result;
|
|
|
|
XWJNI_START();
|
|
|
|
result = board_toggle_showValues( state->game.board );
|
|
|
|
XWJNI_END();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-01-02 20:10:08 +01:00
|
|
|
JNIEXPORT jboolean JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_board_1commitTurn
|
|
|
|
(JNIEnv* env, jclass C, jint gamePtr)
|
|
|
|
{
|
2010-01-10 18:29:09 +01:00
|
|
|
jboolean result;
|
|
|
|
XWJNI_START();
|
|
|
|
result = board_commitTurn( state->game.board );
|
|
|
|
XWJNI_END();
|
|
|
|
return result;
|
2010-01-02 20:10:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_board_1flip
|
|
|
|
(JNIEnv* env, jclass C, jint gamePtr)
|
|
|
|
{
|
2010-01-10 18:29:09 +01:00
|
|
|
jboolean result;
|
|
|
|
XWJNI_START();
|
|
|
|
result = board_flip( state->game.board );
|
|
|
|
XWJNI_END();
|
|
|
|
return result;
|
2010-01-02 20:10:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_board_1replaceTiles
|
|
|
|
(JNIEnv* env, jclass C, jint gamePtr)
|
|
|
|
{
|
2010-01-10 18:29:09 +01:00
|
|
|
jboolean result;
|
|
|
|
XWJNI_START();
|
|
|
|
result = board_replaceTiles( state->game.board );
|
|
|
|
XWJNI_END();
|
|
|
|
return result;
|
2010-01-02 20:10:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_server_1handleUndo
|
|
|
|
(JNIEnv* env, jclass C, jint gamePtr)
|
|
|
|
{
|
2010-01-10 18:29:09 +01:00
|
|
|
XWJNI_START();
|
|
|
|
server_handleUndo( state->game.server );
|
|
|
|
XWJNI_END();
|
2010-01-02 20:10:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_server_1do
|
|
|
|
(JNIEnv* env, jclass C, jint gamePtr )
|
|
|
|
{
|
2010-01-10 18:29:09 +01:00
|
|
|
jboolean result;
|
|
|
|
XWJNI_START();
|
|
|
|
result = server_do( state->game.server );
|
|
|
|
XWJNI_END();
|
|
|
|
return result;
|
2010-01-02 20:10:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL
|
2010-01-12 14:39:19 +01:00
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_board_1resetEngine
|
2010-01-02 20:10:08 +01:00
|
|
|
(JNIEnv* env, jclass C, jint gamePtr )
|
|
|
|
{
|
2010-01-10 18:29:09 +01:00
|
|
|
XWJNI_START();
|
|
|
|
board_resetEngine( state->game.board );
|
|
|
|
XWJNI_END();
|
2010-01-02 20:10:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_board_1requestHint
|
|
|
|
( JNIEnv* env, jclass C, jint gamePtr, jboolean useLimits,
|
|
|
|
jbooleanArray workRemains )
|
|
|
|
{
|
2010-01-10 18:29:09 +01:00
|
|
|
jboolean result;
|
|
|
|
XWJNI_START();
|
2010-01-02 20:10:08 +01:00
|
|
|
XP_Bool tmpbool;
|
2010-02-12 08:13:42 +01:00
|
|
|
result = board_requestHint( state->game.board,
|
|
|
|
#ifdef XWFEATURE_SEARCHLIMIT
|
|
|
|
useLimits,
|
|
|
|
#endif
|
|
|
|
&tmpbool );
|
2010-01-02 20:10:08 +01:00
|
|
|
/* If passed need to do workRemains[0] = tmpbool */
|
2010-01-12 14:39:19 +01:00
|
|
|
if ( workRemains ) {
|
|
|
|
jboolean* jelems = (*env)->GetBooleanArrayElements(env, workRemains, NULL );
|
|
|
|
*jelems = tmpbool;
|
|
|
|
(*env)->ReleaseBooleanArrayElements( env, workRemains, jelems, 0 );
|
|
|
|
}
|
2010-01-10 18:29:09 +01:00
|
|
|
XWJNI_END();
|
2010-01-02 20:10:08 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_timerFired
|
|
|
|
( JNIEnv* env, jclass C, jint gamePtr, jint why, jint when, jint handle )
|
|
|
|
{
|
2010-01-10 18:29:09 +01:00
|
|
|
jboolean result;
|
2010-02-12 08:13:42 +01:00
|
|
|
XWJNI_START_GLOBALS();
|
2010-01-02 20:10:08 +01:00
|
|
|
XW_UtilCtxt* util = globals->util;
|
2010-01-10 18:29:09 +01:00
|
|
|
result = utilTimerFired( util, why, handle );
|
|
|
|
XWJNI_END();
|
|
|
|
return result;
|
2010-01-02 20:10:08 +01:00
|
|
|
}
|
2010-01-16 15:16:27 +01:00
|
|
|
|
|
|
|
JNIEXPORT jstring JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_board_1formatRemainingTiles
|
|
|
|
(JNIEnv* env, jclass C, jint gamePtr )
|
|
|
|
{
|
|
|
|
jstring result;
|
2010-02-12 08:13:42 +01:00
|
|
|
XWJNI_START_GLOBALS();
|
2010-01-16 15:16:27 +01:00
|
|
|
XWStreamCtxt* stream = mem_stream_make( MPPARM(mpool) globals->vtMgr,
|
|
|
|
NULL, 0, NULL );
|
|
|
|
board_formatRemainingTiles( state->game.board, stream );
|
|
|
|
result = streamToJString( MPPARM(mpool) env, stream );
|
|
|
|
stream_destroy( stream );
|
|
|
|
(*env)->DeleteLocalRef( env, result );
|
|
|
|
|
|
|
|
XWJNI_END();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jstring JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_server_1formatDictCounts
|
|
|
|
( JNIEnv* env, jclass C, jint gamePtr, jint nCols )
|
|
|
|
{
|
|
|
|
jstring result;
|
2010-02-12 08:13:42 +01:00
|
|
|
XWJNI_START_GLOBALS();
|
2010-01-31 22:17:21 +01:00
|
|
|
XWStreamCtxt* stream = and_empty_stream( MPPARM(mpool) globals );
|
2010-01-16 15:16:27 +01:00
|
|
|
server_formatDictCounts( state->game.server, stream, nCols );
|
|
|
|
result = streamToJString( MPPARM(mpool) env, stream );
|
|
|
|
stream_destroy( stream );
|
|
|
|
(*env)->DeleteLocalRef( env, result );
|
|
|
|
XWJNI_END();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_server_1getGameIsOver
|
|
|
|
( JNIEnv* env, jclass C, jint gamePtr )
|
|
|
|
{
|
|
|
|
jboolean result;
|
|
|
|
XWJNI_START();
|
|
|
|
result = server_getGameIsOver( state->game.server );
|
|
|
|
XWJNI_END();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jstring JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_model_1writeGameHistory
|
|
|
|
( JNIEnv* env, jclass C, jint gamePtr, jboolean gameOver )
|
|
|
|
{
|
|
|
|
jstring result;
|
2010-02-12 08:13:42 +01:00
|
|
|
XWJNI_START_GLOBALS();
|
2010-01-31 22:17:21 +01:00
|
|
|
XWStreamCtxt* stream = and_empty_stream( MPPARM(mpool) globals );
|
2010-01-16 15:16:27 +01:00
|
|
|
model_writeGameHistory( state->game.model, stream, state->game.server,
|
|
|
|
gameOver );
|
|
|
|
result = streamToJString( MPPARM(mpool) env, stream );
|
2010-01-20 07:43:10 +01:00
|
|
|
(*env)->DeleteLocalRef( env, result );
|
|
|
|
stream_destroy( stream );
|
|
|
|
XWJNI_END();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jstring JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_server_1writeFinalScores
|
|
|
|
( JNIEnv* env, jclass C, jint gamePtr )
|
|
|
|
{
|
|
|
|
jstring result;
|
2010-02-12 08:13:42 +01:00
|
|
|
XWJNI_START_GLOBALS();
|
2010-01-31 22:17:21 +01:00
|
|
|
XWStreamCtxt* stream = and_empty_stream( MPPARM(mpool) globals );
|
2010-01-20 07:43:10 +01:00
|
|
|
server_writeFinalScores( state->game.server, stream );
|
|
|
|
result = streamToJString( MPPARM(mpool) env, stream );
|
|
|
|
(*env)->DeleteLocalRef( env, result );
|
|
|
|
stream_destroy( stream );
|
2010-01-16 15:16:27 +01:00
|
|
|
XWJNI_END();
|
|
|
|
return result;
|
|
|
|
}
|
2010-01-30 15:38:44 +01:00
|
|
|
|
2010-01-31 22:17:21 +01:00
|
|
|
void
|
2010-01-30 15:38:44 +01:00
|
|
|
and_send_on_close( XWStreamCtxt* stream, void* closure )
|
|
|
|
{
|
2010-01-31 22:17:21 +01:00
|
|
|
AndGlobals* globals = (AndGlobals*)closure;
|
|
|
|
JNIState* state = (JNIState*)globals->state;
|
2010-01-30 15:38:44 +01:00
|
|
|
|
|
|
|
XP_ASSERT( !!state->game.comms );
|
|
|
|
comms_send( state->game.comms, stream );
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_server_1initClientConnection
|
|
|
|
( JNIEnv* env, jclass C, jint gamePtr )
|
|
|
|
{
|
|
|
|
LOG_FUNC();
|
2010-02-12 08:13:42 +01:00
|
|
|
XWJNI_START_GLOBALS();
|
2010-01-31 22:17:21 +01:00
|
|
|
XWStreamCtxt* stream = and_empty_stream( MPPARM(mpool) globals );
|
2010-01-30 15:38:44 +01:00
|
|
|
stream_setOnCloseProc( stream, and_send_on_close );
|
|
|
|
server_initClientConnection( state->game.server, stream );
|
|
|
|
XWJNI_END();
|
|
|
|
LOG_RETURN_VOID();
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_comms_1start
|
|
|
|
( JNIEnv* env, jclass C, jint gamePtr )
|
|
|
|
{
|
|
|
|
XWJNI_START();
|
|
|
|
if ( !!state->game.comms ) {
|
|
|
|
comms_start( state->game.comms );
|
|
|
|
}
|
|
|
|
XWJNI_END();
|
|
|
|
}
|
|
|
|
|
2010-01-30 21:06:06 +01:00
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_comms_1getAddr
|
|
|
|
(JNIEnv* env, jclass C, jint gamePtr, jobject jaddr )
|
|
|
|
{
|
|
|
|
XWJNI_START();
|
|
|
|
LOG_FUNC();
|
|
|
|
XP_ASSERT( state->game.comms );
|
|
|
|
CommsAddrRec addr;
|
|
|
|
comms_getAddr( state->game.comms, &addr );
|
|
|
|
setJAddrRec( env, jaddr, &addr );
|
|
|
|
XWJNI_END();
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_comms_1setAddr
|
|
|
|
( JNIEnv* env, jclass C, jint gamePtr, jobject jaddr )
|
|
|
|
{
|
|
|
|
XWJNI_START();
|
|
|
|
if ( state->game.comms ) {
|
|
|
|
CommsAddrRec addr;
|
|
|
|
getJAddrRec( env, &addr, jaddr );
|
|
|
|
comms_setAddr( state->game.comms, &addr );
|
|
|
|
} else {
|
2010-02-12 08:13:42 +01:00
|
|
|
XP_LOGF( "%s: no comms this game", __func__ );
|
2010-01-30 21:06:06 +01:00
|
|
|
}
|
|
|
|
XWJNI_END();
|
|
|
|
}
|
2010-01-31 22:17:21 +01:00
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_game_1receiveMessage
|
|
|
|
( JNIEnv* env, jclass C, jint gamePtr, jbyteArray jstream )
|
|
|
|
{
|
|
|
|
jboolean result;
|
2010-02-12 08:13:42 +01:00
|
|
|
XWJNI_START_GLOBALS();
|
2010-01-31 22:17:21 +01:00
|
|
|
XP_ASSERT( state->game.comms );
|
|
|
|
XP_ASSERT( state->game.server );
|
|
|
|
|
|
|
|
XWStreamCtxt* stream = streamFromJStream( MPPARM(mpool) env, globals->vtMgr,
|
|
|
|
jstream );
|
|
|
|
result = comms_checkIncomingStream( state->game.comms, stream, NULL )
|
|
|
|
&& server_receiveMessage( state->game.server, stream );
|
|
|
|
|
|
|
|
stream_destroy( stream );
|
|
|
|
|
|
|
|
XWJNI_END();
|
|
|
|
return result;
|
|
|
|
}
|
2010-02-01 16:06:12 +01:00
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_board_1prefsChanged
|
|
|
|
( JNIEnv* env, jclass C, jint gamePtr, jobject jcp )
|
|
|
|
{
|
|
|
|
jboolean result;
|
|
|
|
XWJNI_START();
|
|
|
|
|
|
|
|
CommonPrefs cp;
|
|
|
|
loadCommonPrefs( env, &cp, jcp );
|
|
|
|
|
|
|
|
result = board_prefsChanged( state->game.board, &cp );
|
|
|
|
|
|
|
|
XWJNI_END();
|
|
|
|
return result;
|
|
|
|
}
|
2010-02-09 15:25:52 +01:00
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL
|
|
|
|
Java_org_eehouse_android_xw4_jni_XwJNI_game_1hasComms
|
|
|
|
( JNIEnv* env, jclass C, jint gamePtr )
|
|
|
|
{
|
|
|
|
jboolean result;
|
|
|
|
XWJNI_START();
|
|
|
|
result = NULL != state->game.comms;
|
|
|
|
XWJNI_END();
|
|
|
|
return result;
|
|
|
|
}
|