implement showValues; pause engine to handle events; call srandom

during init; add menus and call notImpl() for them.
This commit is contained in:
ehouse 2010-01-12 13:39:19 +00:00
parent 839e707069
commit 14372216d0
7 changed files with 93 additions and 17 deletions

View file

@ -22,7 +22,7 @@ import org.eehouse.android.xw4.jni.*;
public class BoardActivity extends Activity implements XW_UtilCtxt, Runnable {
private static final String CUR_GAME = "cur_game";
private static final String CUR_GAME = "cur_game" + XWConstants.GAME_EXTN;
private static final int PICK_TILE_REQUEST = 1;
private BoardView m_view;
@ -176,6 +176,23 @@ public class BoardActivity extends Activity implements XW_UtilCtxt, Runnable {
case R.id.board_menu_hint_next:
m_jniThread.handle( JNIThread.JNICmd.CMD_NEXT_HINT );
break;
case R.id.board_menu_values:
m_jniThread.handle( JNIThread.JNICmd.CMD_VALUES );
break;
case R.id.board_menu_game_counts:
case R.id.board_menu_game_left:
case R.id.board_menu_game_info:
case R.id.board_menu_game_history:
case R.id.board_menu_game_final:
case R.id.board_menu_game_resend:
case R.id.board_menu_file_prefs:
Utils.notImpl(this);
break;
case R.id.board_menu_file_about:
Utils.about(this);
break;
default:
Utils.logf( "menuitem " + item.getItemId() + " not handled" );
handled = false;
@ -261,6 +278,14 @@ public class BoardActivity extends Activity implements XW_UtilCtxt, Runnable {
m_handler.post( this );
}
public void remSelected() {
// Send a message to the main thread or follow the docs to add
// a looper inside JNIThread::run()
XP_LOGF( "remSelected() can't call notImpl() as hasn't "
+ "called Looper.prepare()" );
// Utils.notImpl( this );
}
public void setTimer( int why, int when, int handle )
{
if ( null != m_timers[why] ) {
@ -313,9 +338,8 @@ public class BoardActivity extends Activity implements XW_UtilCtxt, Runnable {
return tile;
}
// Don't need this unless we have a scroll thumb to indicate position
// public void yOffsetChange( int oldOffset, int newOffset )
// {
// Utils.logf( "yOffsetChange(" + oldOffset + "," + newOffset + ")" );
// }
}
public boolean engineProgressCallback()
{
return !m_jniThread.busy();
}
} // class BoardActivity

View file

@ -5,6 +5,9 @@
package org.eehouse.android.xw4;
public interface XWConstants {
public static final String GAME_EXTN = ".xwg";
public static final String PICK_TILE_TILES
= "org.eehouse.android.xw4.PICK_TILE_TILES";
public static final String PICK_TILE_TILE

View file

@ -27,6 +27,7 @@ public class JNIThread extends Thread {
CMD_UNDO_LAST,
CMD_HINT,
CMD_NEXT_HINT,
CMD_VALUES,
};
private boolean m_stopped = false;
@ -61,6 +62,12 @@ public class JNIThread extends Thread {
}
}
public boolean busy()
{ // synchronize this!!!
int siz = m_queue.size();
return siz > 0;
}
private boolean toggleTray() {
boolean draw;
int state = XwJNI.board_getTrayVisState( m_jniGamePtr );
@ -74,7 +81,7 @@ public class JNIThread extends Thread {
public void run()
{
boolean[] handled = new boolean[1];
boolean[] barr = new boolean[1]; // scratch boolean
while ( !m_stopped ) {
QueueElem elem;
Object[] args;
@ -99,7 +106,7 @@ public class JNIThread extends Thread {
draw = XwJNI.board_handlePenDown( m_jniGamePtr,
((Integer)args[0]).intValue(),
((Integer)args[1]).intValue(),
handled );
barr );
break;
case CMD_PEN_MOVE:
draw = XwJNI.board_handlePenMove( m_jniGamePtr,
@ -137,7 +144,14 @@ public class JNIThread extends Thread {
XwJNI.board_resetEngine( m_jniGamePtr );
// fallthru
case CMD_NEXT_HINT:
draw = XwJNI.board_requestHint( m_jniGamePtr, false, null );
draw = XwJNI.board_requestHint( m_jniGamePtr, false, barr );
if ( barr[0] ) {
handle( CMD_NEXT_HINT );
}
break;
case CMD_VALUES:
draw = XwJNI.board_toggle_showValues( m_jniGamePtr );
break;
case CMD_TIMER_FIRED:

View file

@ -11,11 +11,12 @@ public interface XW_UtilCtxt {
int getSquareBonus( int col, int row );
int userPickTile( /* PickInfo* pi, add once tile-picking is enabled */
int playerNum, String[] texts );
boolean engineProgressCallback();
void setTimer( int why, int when, int handle );
void clearTimer( int why );
void requestTime();
void remSelected();
// Don't need this unless we have a scroll thumb to indicate position
//void yOffsetChange( int oldOffset, int newOffset );

View file

@ -1,4 +1,4 @@
/* -*- compile-command: "cd ../../../../../../; ant reinstall"; -*- */
package org.eehouse.android.xw4.jni;
@ -64,6 +64,7 @@ public class XwJNI {
public static native int board_getTrayVisState( int gamePtr );
public static native boolean board_hideTray( int gamePtr );
public static native boolean board_showTray( int gamePtr );
public static native boolean board_toggle_showValues( int gamePtr );
public static native boolean board_commitTurn( int gamePtr );
public static native boolean board_flip( int gamePtr );
public static native boolean board_replaceTiles( int gamePtr );

View file

@ -17,7 +17,10 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <sys/time.h>
#include <jni.h>
#include "utilwrapper.h"
#include "andutils.h"
@ -152,8 +155,11 @@ and_util_hiliteCell( XW_UtilCtxt* uc, XP_U16 col, XP_U16 row )
static XP_Bool
and_util_engineProgressCallback( XW_UtilCtxt* uc )
{
/* don't log; this is getting called a lot */
return XP_TRUE;
AndUtil* util = (AndUtil*)uc;
JNIEnv* env = *util->env;
const char* sig = "()Z";
jmethodID mid = getMethodID( env, util->j_util, "engineProgressCallback", sig );
return (*env)->CallBooleanMethod( env, util->j_util, mid );
}
/* This is added for java, not part of the util api */
@ -215,7 +221,9 @@ and_util_altKeyDown( XW_UtilCtxt* uc )
static XP_U32
and_util_getCurSeconds( XW_UtilCtxt* uc )
{
LOG_FUNC();
struct timeval tv;
gettimeofday( &tv, NULL );
return tv.tv_sec;
}
@ -246,6 +254,11 @@ static void
and_util_remSelected(XW_UtilCtxt* uc)
{
LOG_FUNC();
AndUtil* util = (AndUtil*)uc;
JNIEnv* env = *util->env;
const char* sig = "()V";
jmethodID mid = getMethodID( env, util->j_util, "remSelected", sig );
(*env)->CallVoidMethod( env, util->j_util, mid );
}

View file

@ -1,5 +1,7 @@
/* -*-mode: C; compile-command: "cd XWords4; ../scripts/ndkbuild.sh"; -*- */
#include <string.h>
#include <sys/time.h>
#include <jni.h>
#include <android/log.h>
@ -158,6 +160,9 @@ JNIEXPORT jint JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_initJNI
( JNIEnv* env, jclass C )
{
struct timeval tv;
gettimeofday( &tv, NULL );
srandom( tv.tv_sec );
#ifdef MEM_DEBUG
MemPoolCtx* mpool = mpool_make();
#endif
@ -440,6 +445,17 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1showTray
return result;
}
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;
}
JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1commitTurn
(JNIEnv* env, jclass C, jint gamePtr)
@ -494,7 +510,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_server_1do
}
JNIEXPORT void JNICALL
org_eehouse_android_xw4_jni_XwJNI_board_1resetEngine
Java_org_eehouse_android_xw4_jni_XwJNI_board_1resetEngine
(JNIEnv* env, jclass C, jint gamePtr )
{
XWJNI_START();
@ -512,7 +528,11 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1requestHint
XP_Bool tmpbool;
result = board_requestHint( state->game.board, useLimits, &tmpbool );
/* If passed need to do workRemains[0] = tmpbool */
XP_ASSERT( !workRemains );
if ( workRemains ) {
jboolean* jelems = (*env)->GetBooleanArrayElements(env, workRemains, NULL );
*jelems = tmpbool;
(*env)->ReleaseBooleanArrayElements( env, workRemains, jelems, 0 );
}
XWJNI_END();
return result;
}