Merge branch 'android_branch' of ssh://xwords.git.sourceforge.net/gitroot/xwords/xwords into android_branch

This commit is contained in:
eehouse@eehouse.org 2011-04-13 06:58:58 -07:00 committed by Andy2
commit 5a21aea2e5
11 changed files with 114 additions and 7 deletions

View file

@ -425,7 +425,6 @@ void
makeDicts( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil, PlayerDicts* dicts,
jobjectArray jdicts, jobjectArray jnames, jstring jlang )
{
LOG_FUNC();
int ii;
jsize len = (*env)->GetArrayLength( env, jdicts );
XP_ASSERT( len == (*env)->GetArrayLength( env, jnames ) );
@ -442,7 +441,6 @@ makeDicts( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil, PlayerDicts* dicts,
}
dicts->dicts[ii] = dict;
}
LOG_RETURN_VOID();
}
DictionaryCtxt*

View file

@ -390,6 +390,28 @@ dict_loadFromStream( DictionaryCtxt* dict, XWStreamCtxt* stream )
} /* dict_loadFromStream */
#endif
#ifdef TEXT_MODEL
/* Return the strlen of the longest face, e.g. 1 for English and Italian;
2 for Spanish; 3 for Catalan */
XP_U16
dict_getMaxWidth( const DictionaryCtxt* dict )
{
XP_U16 result = 0;
Tile tile;
XP_U16 nFaces = dict_numTileFaces( dict );
for ( tile = 0; tile < nFaces; ++tile ) {
const XP_UCHAR* face = dict_getTileString( dict, tile );
XP_U16 len = XP_STRLEN( face );
if ( len > result ) {
result = len;
}
}
return result;
}
#endif
const XP_UCHAR*
dict_getName( const DictionaryCtxt* dict )
{

View file

@ -160,6 +160,12 @@ XP_U32 dict_getWordCount( const DictionaryCtxt* dict );
void dict_writeToStream( const DictionaryCtxt* ctxt, XWStreamCtxt* stream );
void dict_loadFromStream( DictionaryCtxt* dict, XWStreamCtxt* stream );
#ifdef TEXT_MODEL
/* Return the strlen of the longest face, e.g. 1 for English and Italian;
2 for Spanish; 3 for Catalan */
XP_U16 dict_getMaxWidth( const DictionaryCtxt* dict );
#endif
/* These methods get "overridden" by subclasses. That is, they must be
implemented by each platform. */

View file

@ -172,6 +172,47 @@ model_writeToStream( ModelCtxt* model, XWStreamCtxt* stream )
#endif
} /* model_writeToStream */
#ifdef TEXT_MODEL
void
model_writeToTextStream( const ModelCtxt* model, XWStreamCtxt* stream )
{
const DictionaryCtxt* dict = model_getDictionary( model );
int width = dict_getMaxWidth( dict );
XP_UCHAR empty[4] = {0};
XP_U16 ii;
XP_U16 col, row;
for ( ii = 0; ii < width; ++ii ) {
empty[ii] = '.';
}
for ( row = 0; row < model->nRows; ++row ) {
XP_UCHAR buf[256];
XP_U16 len = 0;
for ( col = 0; col < model->nCols; ++col ) {
XP_Bool isBlank;
Tile tile;
if ( model_getTile( model, col, row, XP_FALSE, -1, &tile,
&isBlank, NULL, NULL ) ) {
const XP_UCHAR* face = dict_getTileString( dict, tile );
XP_UCHAR lower[1+XP_STRLEN(face)];
XP_STRNCPY( lower, face, sizeof(lower) );
if ( isBlank ) {
XP_LOWERSTR( lower );
}
len += snprintf( &buf[len], sizeof(buf) - len, "%*s",
width, lower );
} else {
len += snprintf( &buf[len], sizeof(buf) - len, "%s", empty );
}
}
buf[len++] = '\n';
buf[len] = '\0';
stream_catString( stream, buf );
}
}
#endif
void
model_init( ModelCtxt* model, XP_U16 nCols, XP_U16 nRows )
{

View file

@ -109,6 +109,10 @@ ModelCtxt* model_makeFromStream( MPFORMAL XWStreamCtxt* stream,
void model_writeToStream( ModelCtxt* model, XWStreamCtxt* stream );
#ifdef TEXT_MODEL
void model_writeToTextStream( const ModelCtxt* model, XWStreamCtxt* stream );
#endif
void model_init( ModelCtxt* model, XP_U16 nCols, XP_U16 nRows );
void model_destroy( ModelCtxt* model );
void model_setNPlayers( ModelCtxt* model, XP_U16 numPlayers );

View file

@ -110,7 +110,7 @@ newg_load( NewGameCtx* ngc, const CurGameInfo* gi )
XP_S16 ii, jj;
DeviceRole role;
XP_Bool localOnly;
XP_Bool shown[MAX_NUM_PLAYERS] = { XP_FALSE, XP_FALSE, XP_FALSE, XP_FALSE};
XP_Bool shown[MAX_NUM_PLAYERS] = { XP_FALSE };
ngc->juggleEnabled = TRI_ENAB_NONE;
ngc->settingsEnabled = TRI_ENAB_NONE;

View file

@ -87,6 +87,7 @@ DEFINES += -DFEATURE_TRAY_EDIT
DEFINES += -DXWFEATURE_CROSSHAIRS
DEFINES += -DXWFEATURE_CHAT
DEFINES += -DDISABLE_TILE_SEL
DEFINES += -DTEXT_MODEL
ifdef CURSES_CELL_HT
DEFINES += -DCURSES_CELL_HT=$(CURSES_CELL_HT)

View file

@ -740,6 +740,23 @@ game_history( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals )
catGameHistory( &globals->cGlobals );
} /* game_history */
#ifdef TEXT_MODEL
static void
dump_board( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals )
{
if ( !!globals->cGlobals.game.model ) {
XWStreamCtxt* stream =
mem_stream_make( MEMPOOL
globals->cGlobals.params->vtMgr,
globals,
CHANNEL_NONE,
catOnClose );
model_writeToTextStream( globals->cGlobals.game.model, stream );
stream_destroy( stream );
}
}
#endif
static void
final_scores( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals )
{
@ -953,6 +970,10 @@ makeMenus( GtkAppGlobals* globals, int XP_UNUSED(argc),
GTK_SIGNAL_FUNC(tile_values), globals );
(void)createAddItem( fileMenu, "Game history",
GTK_SIGNAL_FUNC(game_history), globals );
#ifdef TEXT_MODEL
(void)createAddItem( fileMenu, "Dump board",
GTK_SIGNAL_FUNC(dump_board), globals );
#endif
(void)createAddItem( fileMenu, "Final scores",
GTK_SIGNAL_FUNC(final_scores), globals );

View file

@ -316,8 +316,7 @@ typedef struct _CmdInfoRec {
static CmdInfoRec CmdInfoRecs[] = {
{ CMD_SKIP_GAMEOVER, false, "skip-final", "skip final scores display" }
,{ CMD_SHOW_OTHERSCORES, false, "no-show-other",
"do not show robot and remote scores" }
,{ CMD_SHOW_OTHERSCORES, false, "show-other", "show robot/remote scores" }
,{ CMD_HOSTIP, true, "hostip", "remote host ip address (for direct connect)" }
,{ CMD_DICT, true, "game-dict", "dictionary name for game" }
,{ CMD_PLAYERDICT, true, "player-dict", "dictionary name for player (in sequence)" }
@ -957,7 +956,7 @@ main( int argc, char** argv )
mainParams.skipCommitConfirm = XP_TRUE;
mainParams.showColors = XP_TRUE;
mainParams.allowPeek = XP_TRUE;
mainParams.showRobotScores = XP_TRUE;
mainParams.showRobotScores = XP_FALSE;
/* serverName = mainParams.info.clientInfo.serverName = "localhost"; */
@ -981,7 +980,7 @@ main( int argc, char** argv )
mainParams.skipGameOver = XP_TRUE;
break;
case CMD_SHOW_OTHERSCORES:
mainParams.showRobotScores = XP_FALSE;
mainParams.showRobotScores = XP_TRUE;
break;
#ifdef XWFEATURE_RELAY
case CMD_ROOMNAME:

View file

@ -24,6 +24,7 @@
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h> /* BAD: use glib to support utf8 */
#include "linuxutl.h"
#include "main.h"
@ -409,3 +410,15 @@ linux_getErrString( UtilErrID id, XP_Bool* silent )
return (XP_UCHAR*)message;
} /* linux_getErrString */
#ifdef TEXT_MODEL
/* This is broken for UTF-8, even Spanish */
void
linux_lowerstr( XP_UCHAR* str )
{
while ( *str ) {
*str = tolower( *str );
++str;
}
}
#endif

View file

@ -104,6 +104,8 @@ void linux_freep( void** ptrp );
#define XP_STRNCMP(s1,s2,len) strncmp((s1),(s2),(len))
#define XP_STRNCPY(s1,s2,len) strncpy((s1),(s2),(len))
#define XP_STRCMP(s1,s2) strcmp((s1),(s2))
void linux_lowerstr( XP_UCHAR* str );
#define XP_LOWERSTR(str) linux_lowerstr(str)
#define XP_RANDOM() random()
#define XP_SNPRINTF snprintf