mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-27 07:58:49 +01:00
make game ask for dicts when needed
It's awkward for platform code to create a dictionary prior to opening a game whose data contains the information about what dict to open. So add a dutil method to fetch a dict, and call it from inside game opening code. Makes linux code better at least.
This commit is contained in:
parent
7924c046d6
commit
afc3ff156e
13 changed files with 173 additions and 134 deletions
|
@ -90,6 +90,9 @@ typedef struct _DUtilVtable {
|
|||
XP_UCHAR* (*m_dutil_md5sum)( XW_DUtilCtxt* duc, XWEnv xwe, const XP_U8* ptr, XP_U32 len );
|
||||
#endif
|
||||
|
||||
DictionaryCtxt* (*m_dutil_getDict)( XW_DUtilCtxt* duc, XWEnv xwe,
|
||||
const XP_UCHAR* dictName );
|
||||
|
||||
void (*m_dutil_notifyPause)( XW_DUtilCtxt* duc, XWEnv xwe, XP_U32 gameID,
|
||||
DupPauseType pauseTyp, XP_U16 pauser,
|
||||
const XP_UCHAR* name, const XP_UCHAR* msg );
|
||||
|
@ -168,13 +171,15 @@ void dutil_super_init( MPFORMAL XW_DUtilCtxt* dutil );
|
|||
(duc)->vtable.m_dutil_md5sum((duc), (e), (p), (l))
|
||||
#endif
|
||||
|
||||
#define dutil_getDict( duc, xwe, dictName ) \
|
||||
(duc)->vtable.m_dutil_getDict( (duc), (xwe), (dictName) )
|
||||
|
||||
#define dutil_notifyPause( duc, e, id, ip, p, n, m ) \
|
||||
(duc)->vtable.m_dutil_notifyPause( (duc), (e), (id), (ip), (p), (n), (m) )
|
||||
|
||||
#define dutil_onDupTimerChanged(duc, e, id, ov, nv) \
|
||||
(duc)->vtable.m_dutil_onDupTimerChanged( (duc), (e), (id), (ov), (nv))
|
||||
|
||||
|
||||
#define dutil_onInviteReceived(duc, xwe, nli) \
|
||||
(duc)->vtable.m_dutil_onInviteReceived( (duc), (xwe), (nli) )
|
||||
#define dutil_onMessageReceived(duc, xwe, gameID, from, stream) \
|
||||
|
|
|
@ -120,7 +120,39 @@ setListeners( XWGame* game, const CommonPrefs* cp )
|
|||
server_setTimerChangeListener( game->server, timerChangeListener, game );
|
||||
}
|
||||
|
||||
void
|
||||
static DictionaryCtxt*
|
||||
getDicts( const CurGameInfo* gi, XW_UtilCtxt* util, XWEnv xwe,
|
||||
PlayerDicts* playerDicts )
|
||||
{
|
||||
XW_DUtilCtxt* dutil = util_getDevUtilCtxt( util, xwe );
|
||||
DictionaryCtxt* result = dutil_getDict( dutil, xwe, gi->dictName );
|
||||
XP_MEMSET( playerDicts, 0, sizeof(*playerDicts) );
|
||||
if ( !!result ) {
|
||||
for ( int ii = 0; ii < gi->nPlayers; ++ii ) {
|
||||
const LocalPlayer* lp = &gi->players[ii];
|
||||
if ( lp->isLocal && !!lp->dictName ) {
|
||||
playerDicts->dicts[ii] = dutil_getDict( dutil, xwe, lp->dictName );
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static void
|
||||
unrefDicts( XWEnv xwe, DictionaryCtxt* dict, PlayerDicts* playerDicts )
|
||||
{
|
||||
if ( !!dict ) {
|
||||
dict_unref( dict, xwe );
|
||||
}
|
||||
for ( int ii = 0; ii < VSIZE(playerDicts->dicts); ++ii ) {
|
||||
const DictionaryCtxt* dict = playerDicts->dicts[ii];
|
||||
if ( !!dict ) {
|
||||
dict_unref( dict, xwe );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
XP_Bool
|
||||
game_makeNewGame( MPFORMAL XWEnv xwe, XWGame* game, CurGameInfo* gi,
|
||||
XW_UtilCtxt* util, DrawCtx* draw,
|
||||
const CommonPrefs* cp, const TransportProcs* procs
|
||||
|
@ -142,37 +174,53 @@ game_makeNewGame( MPFORMAL XWEnv xwe, XWGame* game, CurGameInfo* gi,
|
|||
game->created = dutil_getCurSeconds( util_getDevUtilCtxt( util, xwe ), xwe );
|
||||
game->util = util;
|
||||
|
||||
game->model = model_make( MPPARM(mpool) xwe, (DictionaryCtxt*)NULL,
|
||||
NULL, util, gi->boardSize );
|
||||
PlayerDicts playerDicts;
|
||||
DictionaryCtxt* dict = getDicts( gi, util, xwe, &playerDicts );
|
||||
XP_Bool success = !!dict;
|
||||
|
||||
if ( success ) {
|
||||
gi->dictLang = dict_getLangCode( dict );
|
||||
game->model = model_make( MPPARM(mpool) xwe, (DictionaryCtxt*)NULL,
|
||||
NULL, util, gi->boardSize );
|
||||
|
||||
model_setDictionary( game->model, xwe, dict );
|
||||
model_setPlayerDicts( game->model, xwe, &playerDicts );
|
||||
|
||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||
if ( gi->serverRole != SERVER_STANDALONE ) {
|
||||
game->comms = comms_make( MPPARM(mpool) xwe, util,
|
||||
gi->serverRole != SERVER_ISCLIENT,
|
||||
nPlayersHere, nPlayersTotal,
|
||||
procs, onRoleChanged, game,
|
||||
gi->forceChannel
|
||||
if ( gi->serverRole != SERVER_STANDALONE ) {
|
||||
game->comms = comms_make( MPPARM(mpool) xwe, util,
|
||||
gi->serverRole != SERVER_ISCLIENT,
|
||||
nPlayersHere, nPlayersTotal,
|
||||
procs, onRoleChanged, game,
|
||||
gi->forceChannel
|
||||
#ifdef SET_GAMESEED
|
||||
, gameSeed
|
||||
, gameSeed
|
||||
#endif
|
||||
);
|
||||
} else {
|
||||
game->comms = (CommsCtxt*)NULL;
|
||||
}
|
||||
#endif
|
||||
game->server = server_make( MPPARM(mpool) xwe, game->model,
|
||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||
game->comms,
|
||||
#else
|
||||
(CommsCtxt*)NULL,
|
||||
#endif
|
||||
util );
|
||||
game->board = board_make( MPPARM(mpool) xwe, game->model, game->server,
|
||||
NULL, util );
|
||||
board_setCallbacks( game->board, xwe );
|
||||
);
|
||||
} else {
|
||||
game->comms = (CommsCtxt*)NULL;
|
||||
}
|
||||
|
||||
board_setDraw( game->board, xwe, draw );
|
||||
setListeners( game, cp );
|
||||
|
||||
#endif
|
||||
game->server = server_make( MPPARM(mpool) xwe, game->model,
|
||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||
game->comms,
|
||||
#else
|
||||
(CommsCtxt*)NULL,
|
||||
#endif
|
||||
util );
|
||||
game->board = board_make( MPPARM(mpool) xwe, game->model, game->server,
|
||||
NULL, util );
|
||||
board_setCallbacks( game->board, xwe );
|
||||
|
||||
board_setDraw( game->board, xwe, draw );
|
||||
setListeners( game, cp );
|
||||
}
|
||||
|
||||
unrefDicts( xwe, dict, &playerDicts );
|
||||
|
||||
return success;
|
||||
} /* game_makeNewGame */
|
||||
|
||||
XP_Bool
|
||||
|
@ -252,10 +300,9 @@ game_changeDict( MPFORMAL XWGame* game, XWEnv xwe, CurGameInfo* gi, DictionaryCt
|
|||
#endif
|
||||
|
||||
XP_Bool
|
||||
game_makeFromStream( MPFORMAL XWEnv xwe, XWStreamCtxt* stream, XWGame* game,
|
||||
CurGameInfo* gi, DictionaryCtxt* dict,
|
||||
const PlayerDicts* dicts, XW_UtilCtxt* util,
|
||||
DrawCtx* draw, CommonPrefs* cp,
|
||||
game_makeFromStream( MPFORMAL XWEnv xwe, XWStreamCtxt* stream,
|
||||
XWGame* game, CurGameInfo* gi,
|
||||
XW_UtilCtxt* util, DrawCtx* draw, CommonPrefs* cp,
|
||||
const TransportProcs* procs )
|
||||
{
|
||||
XP_Bool success = XP_FALSE;
|
||||
|
@ -285,6 +332,13 @@ game_makeFromStream( MPFORMAL XWEnv xwe, XWStreamCtxt* stream, XWGame* game,
|
|||
game->created = strVersion < STREAM_VERS_GICREATED
|
||||
? 0 : stream_getU32( stream );
|
||||
|
||||
PlayerDicts playerDicts;
|
||||
DictionaryCtxt* dict = getDicts( gi, util, xwe, &playerDicts );
|
||||
if ( !dict ) {
|
||||
break;
|
||||
}
|
||||
XP_ASSERT( gi->dictLang == dict_getLangCode(dict) );
|
||||
|
||||
/* Previous stream versions didn't save anything if built
|
||||
* standalone. Now we always save something. But we need to know
|
||||
* if the previous version didn't save. PREV_WAS_STANDALONE_ONLY
|
||||
|
@ -314,7 +368,7 @@ game_makeFromStream( MPFORMAL XWEnv xwe, XWStreamCtxt* stream, XWGame* game,
|
|||
}
|
||||
|
||||
game->model = model_makeFromStream( MPPARM(mpool) xwe, stream, dict,
|
||||
dicts, util );
|
||||
&playerDicts, util );
|
||||
|
||||
game->server = server_makeFromStream( MPPARM(mpool) xwe, stream,
|
||||
game->model, game->comms,
|
||||
|
@ -326,6 +380,7 @@ game_makeFromStream( MPFORMAL XWEnv xwe, XWStreamCtxt* stream, XWGame* game,
|
|||
setListeners( game, cp );
|
||||
board_setDraw( game->board, xwe, draw );
|
||||
success = XP_TRUE;
|
||||
unrefDicts( xwe, dict, &playerDicts );
|
||||
} while( XP_FALSE );
|
||||
}
|
||||
|
||||
|
@ -347,7 +402,6 @@ game_makeFromStream( MPFORMAL XWEnv xwe, XWStreamCtxt* stream, XWGame* game,
|
|||
XP_Bool
|
||||
game_makeFromInvite( MPFORMAL XWEnv xwe, const NetLaunchInfo* nli,
|
||||
XWGame* game, CurGameInfo* gi, const XP_UCHAR* plyrName,
|
||||
DictionaryCtxt* dict, const PlayerDicts* dicts,
|
||||
XW_UtilCtxt* util, DrawCtx* draw,
|
||||
CommonPrefs* cp, const TransportProcs* procs )
|
||||
{
|
||||
|
@ -362,15 +416,13 @@ game_makeFromInvite( MPFORMAL XWEnv xwe, const NetLaunchInfo* nli,
|
|||
replaceStringIfDifferent( mpool, &gi->players[0].name, plyrName );
|
||||
replaceStringIfDifferent( mpool, &gi->dictName, nli->dict );
|
||||
|
||||
game_makeNewGame( MPPARM(mpool) xwe, game, gi, util, draw, cp, procs );
|
||||
model_setDictionary( game->model, xwe, dict );
|
||||
model_setPlayerDicts( game->model, xwe, dicts );
|
||||
|
||||
CommsAddrRec returnAddr;
|
||||
nli_makeAddrRec( nli, &returnAddr );
|
||||
comms_augmentHostAddr( game->comms, NULL, &returnAddr );
|
||||
|
||||
return XP_TRUE;
|
||||
XP_Bool success = game_makeNewGame( MPPARM(mpool) xwe, game, gi, util, draw, cp, procs );
|
||||
if ( success ) {
|
||||
CommsAddrRec returnAddr;
|
||||
nli_makeAddrRec( nli, &returnAddr );
|
||||
comms_augmentHostAddr( game->comms, NULL, &returnAddr );
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -62,13 +62,13 @@ typedef struct _XWGame {
|
|||
XP_U32 created; /* dutil_getCurSeconds() of creation */
|
||||
} XWGame;
|
||||
|
||||
void game_makeNewGame( MPFORMAL XWEnv xwe, XWGame* game, CurGameInfo* gi,
|
||||
XW_UtilCtxt* util, DrawCtx* draw,
|
||||
const CommonPrefs* cp, const TransportProcs* procs
|
||||
XP_Bool game_makeNewGame( MPFORMAL XWEnv xwe, XWGame* game, CurGameInfo* gi,
|
||||
XW_UtilCtxt* util, DrawCtx* draw,
|
||||
const CommonPrefs* cp, const TransportProcs* procs
|
||||
#ifdef SET_GAMESEED
|
||||
,XP_U16 gameSeed
|
||||
,XP_U16 gameSeed
|
||||
#endif
|
||||
);
|
||||
);
|
||||
XP_Bool game_reset( MPFORMAL XWGame* game, XWEnv xwe, CurGameInfo* gi,
|
||||
XW_UtilCtxt* util, CommonPrefs* cp,
|
||||
const TransportProcs* procs );
|
||||
|
@ -77,13 +77,11 @@ void game_changeDict( MPFORMAL XWGame* game, XWEnv xwe, CurGameInfo* gi,
|
|||
|
||||
XP_Bool game_makeFromStream( MPFORMAL XWEnv xwe, XWStreamCtxt* stream,
|
||||
XWGame* game, CurGameInfo* gi,
|
||||
DictionaryCtxt* dict, const PlayerDicts* dicts,
|
||||
XW_UtilCtxt* util, DrawCtx* draw,
|
||||
CommonPrefs* cp, const TransportProcs* procs );
|
||||
|
||||
XP_Bool game_makeFromInvite( MPFORMAL XWEnv xwe, const NetLaunchInfo* nli,
|
||||
XWGame* game, CurGameInfo* gi, const XP_UCHAR* plyrName,
|
||||
DictionaryCtxt* dict, const PlayerDicts* dicts,
|
||||
XW_UtilCtxt* util, DrawCtx* draw,
|
||||
CommonPrefs* cp, const TransportProcs* procs );
|
||||
|
||||
|
|
|
@ -396,6 +396,37 @@ finishHash( XP_U32 hash )
|
|||
return hash;
|
||||
}
|
||||
|
||||
const XP_UCHAR*
|
||||
lcToLocale( XP_LangCode lc )
|
||||
{
|
||||
const XP_UCHAR* result = NULL;
|
||||
switch ( lc ) {
|
||||
/* <item>@string/lang_unknown</item> <!-- Unknown --> */
|
||||
case 1: result = "en"; break;
|
||||
case 2: result = "fr"; break;
|
||||
case 3: result = "de"; break;
|
||||
/* <item>@string/lang_name_turkish</item> <!-- 4 --> */
|
||||
/* <item>@string/lang_name_arabic</item> <!-- 5 --> */
|
||||
case 6: result = "es"; break;
|
||||
/* <item>@string/lang_name_swedish</item> <!-- 7 --> */
|
||||
/* <item>@string/lang_name_polish</item> <!-- 8 --> */
|
||||
/* <item>@string/lang_name_danish</item> <!-- 9 --> */
|
||||
case 0xA: result = "it"; break;
|
||||
/* <item>@string/lang_name_dutch</item> <!-- B --> */
|
||||
case 0xC: result = "ca"; break;
|
||||
/* <item>@string/lang_name_portuguese</item> <!-- D --> */
|
||||
/* <item></item> <!-- E --> */
|
||||
/* <item>@string/lang_name_russian</item> */
|
||||
/* <item></item> <!-- 10 --> */
|
||||
/* <item>@string/lang_name_czech</item> */
|
||||
/* <item>@string/lang_name_greek</item> */
|
||||
/* <item>@string/lang_name_slovak</item> */
|
||||
/* <item>@string/lang_name_hungarian</item> */
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* A wrapper for printing etc. potentially null strings.
|
||||
*/
|
||||
|
|
|
@ -86,6 +86,8 @@ void insetRect( XP_Rect* rect, XP_S16 byWidth, XP_S16 byHeight );
|
|||
XP_U32 augmentHash( XP_U32 hash, const XP_U8* ptr, XP_U16 len );
|
||||
XP_U32 finishHash( XP_U32 hash );
|
||||
|
||||
const XP_UCHAR* lcToLocale( XP_LangCode lc );
|
||||
|
||||
void p_replaceStringIfDifferent( MPFORMAL XP_UCHAR** curLoc,
|
||||
const XP_UCHAR* newStr
|
||||
#ifdef MEM_DEBUG
|
||||
|
|
|
@ -438,14 +438,6 @@ commonInit( CursesBoardState* cbState, sqlite3_int64 rowid,
|
|||
|
||||
copyParmsAddr( cGlobals );
|
||||
|
||||
CurGameInfo* gi = cGlobals->gi;
|
||||
if ( !!gi ) {
|
||||
XP_ASSERT( !cGlobals->dict );
|
||||
cGlobals->dict = linux_dictionary_make( MPPARM(cGlobals->util->mpool)
|
||||
NULL_XWE, params, gi->dictName, XP_TRUE );
|
||||
gi->dictLang = dict_getLangCode( cGlobals->dict );
|
||||
}
|
||||
|
||||
setOneSecondTimer( cGlobals );
|
||||
return bGlobals;
|
||||
} /* commonInit */
|
||||
|
@ -479,10 +471,6 @@ disposeBoard( CursesBoardGlobals* bGlobals )
|
|||
gi_disposePlayerInfo( MPPARM(cGlobals->util->mpool) cGlobals->gi );
|
||||
game_dispose( &cGlobals->game, NULL_XWE );
|
||||
|
||||
if ( !!cGlobals->dict ) {
|
||||
dict_unref( cGlobals->dict, NULL_XWE );
|
||||
}
|
||||
|
||||
disposeUtil( cGlobals );
|
||||
|
||||
CursesBoardState* cbState = bGlobals->cbState;
|
||||
|
@ -529,12 +517,11 @@ utf8_len( const char* face )
|
|||
}
|
||||
|
||||
static void
|
||||
getFromDict( const CommonGlobals* cGlobals, XP_U16* fontWidthP,
|
||||
getFromDict( const DictionaryCtxt* dict, XP_U16* fontWidthP,
|
||||
XP_U16* fontHtP )
|
||||
{
|
||||
int maxSide = 1;
|
||||
|
||||
DictionaryCtxt* dict = cGlobals->dict;
|
||||
for ( Tile tile = 0; tile < dict->nFaces; ++tile ) {
|
||||
const XP_UCHAR* face = dict_getTileString( dict, tile );
|
||||
int thisLen = utf8_len( face );
|
||||
|
@ -558,7 +545,8 @@ setupBoard( CursesBoardGlobals* bGlobals )
|
|||
const int height = bGlobals->winHeight;
|
||||
|
||||
XP_U16 fontWidth, fontHt;
|
||||
getFromDict( cGlobals, &fontWidth, &fontHt );
|
||||
const DictionaryCtxt* dict = model_getDictionary( cGlobals->game.model );
|
||||
getFromDict( dict, &fontWidth, &fontHt );
|
||||
BoardDims dims;
|
||||
board_figureLayout( board, NULL_XWE, cGlobals->gi,
|
||||
0, 0, width, height, 100,
|
||||
|
|
|
@ -757,7 +757,6 @@ cleanup( GtkGameGlobals* globals )
|
|||
#endif
|
||||
game_dispose( &cGlobals->game, NULL_XWE );
|
||||
gi_disposePlayerInfo( MEMPOOL cGlobals->gi );
|
||||
dict_unref( cGlobals->dict, NULL_XWE );
|
||||
|
||||
linux_util_vt_destroy( cGlobals->util );
|
||||
free( cGlobals->util );
|
||||
|
@ -2513,12 +2512,6 @@ initBoardGlobalsGtk( GtkGameGlobals* globals, LaunchParams* params,
|
|||
GtkWidget* hbox;
|
||||
|
||||
initGlobalsNoDraw( globals, params, gi );
|
||||
if ( !!gi ) {
|
||||
XP_ASSERT( !cGlobals->dict );
|
||||
cGlobals->dict = linux_dictionary_make( MEMPOOL NULL_XWE, params,
|
||||
gi->dictName, XP_TRUE );
|
||||
gi->dictLang = dict_getLangCode( cGlobals->dict );
|
||||
}
|
||||
|
||||
globals->window = window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
|
||||
if ( !!params->fileName ) {
|
||||
|
@ -2684,13 +2677,9 @@ loadGameNoDraw( GtkGameGlobals* globals, LaunchParams* params,
|
|||
params->vtMgr );
|
||||
XP_Bool loaded = gdb_loadGame( stream, pDb, rowid );
|
||||
if ( loaded ) {
|
||||
if ( NULL == cGlobals->dict ) {
|
||||
cGlobals->dict = makeDictForStream( cGlobals, stream );
|
||||
}
|
||||
loaded = game_makeFromStream( MEMPOOL NULL_XWE, stream, &cGlobals->game,
|
||||
cGlobals->gi, cGlobals->dict,
|
||||
&cGlobals->dicts, cGlobals->util,
|
||||
(DrawCtx*)NULL, &cGlobals->cp, &procs );
|
||||
cGlobals->gi,
|
||||
cGlobals->util, (DrawCtx*)NULL, &cGlobals->cp, &procs );
|
||||
if ( loaded ) {
|
||||
XP_LOGF( "%s: game loaded", __func__ );
|
||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||
|
@ -2729,12 +2718,6 @@ makeNewGame( GtkGameGlobals* globals )
|
|||
CurGameInfo* gi = cGlobals->gi;
|
||||
XP_Bool success = gtkNewGameDialog( globals, gi, &cGlobals->addr,
|
||||
XP_TRUE, XP_FALSE );
|
||||
if ( success && !!gi->dictName && !cGlobals->dict ) {
|
||||
cGlobals->dict =
|
||||
linux_dictionary_make( MEMPOOL NULL_XWE, cGlobals->params,
|
||||
gi->dictName, XP_TRUE );
|
||||
gi->dictLang = dict_getLangCode( cGlobals->dict );
|
||||
}
|
||||
LOG_RETURNF( "%s", boolToStr(success) );
|
||||
return success;
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ findOpenGame( const GtkAppGlobals* apg, sqlite3_int64 rowid )
|
|||
}
|
||||
|
||||
enum { ROW_ITEM, ROW_THUMB, NAME_ITEM, CREATED_ITEM, ROOM_ITEM, GAMEID_ITEM,
|
||||
SEED_ITEM, ROLE_ITEM, CONN_ITEM, RELAYID_ITEM, OVER_ITEM, TURN_ITEM,
|
||||
LANG_ITEM, SEED_ITEM, ROLE_ITEM, CONN_ITEM, RELAYID_ITEM, OVER_ITEM, TURN_ITEM,
|
||||
LOCAL_ITEM, NMOVES_ITEM, NTOTAL_ITEM, MISSING_ITEM, LASTTURN_ITEM,
|
||||
DUPTIMER_ITEM,
|
||||
|
||||
|
@ -176,6 +176,7 @@ init_games_list( GtkAppGlobals* apg )
|
|||
addTextColumn( list, "Created", CREATED_ITEM );
|
||||
addTextColumn( list, "Room", ROOM_ITEM );
|
||||
addTextColumn( list, "GameID", GAMEID_ITEM );
|
||||
addTextColumn( list, "Lang", LANG_ITEM );
|
||||
addTextColumn( list, "Seed", SEED_ITEM );
|
||||
addTextColumn( list, "Role", ROLE_ITEM );
|
||||
addTextColumn( list, "Conn. via", CONN_ITEM );
|
||||
|
@ -196,6 +197,7 @@ init_games_list( GtkAppGlobals* apg )
|
|||
G_TYPE_STRING, /* CREATED_ITEM */
|
||||
G_TYPE_STRING, /* ROOM_ITEM */
|
||||
G_TYPE_INT, /* GAMEID_ITEM */
|
||||
G_TYPE_STRING, /* LANG_ITEM */
|
||||
G_TYPE_INT, /* SEED_ITEM */
|
||||
G_TYPE_INT, /* ROLE_ITEM */
|
||||
G_TYPE_STRING, /* CONN_ITEM */
|
||||
|
@ -269,6 +271,7 @@ add_to_list( GtkWidget* list, sqlite3_int64 rowid, XP_Bool isNew,
|
|||
CREATED_ITEM, createdStr,
|
||||
ROOM_ITEM, gib->room,
|
||||
GAMEID_ITEM, gib->gameID,
|
||||
LANG_ITEM, lcToLocale(gib->dictLang),
|
||||
SEED_ITEM, gib->seed,
|
||||
ROLE_ITEM, gib->role,
|
||||
CONN_ITEM, gib->conn,
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
#include "dbgutil.h"
|
||||
#include "LocalizedStrIncludes.h"
|
||||
#include "nli.h"
|
||||
|
||||
#include "linuxdict.h"
|
||||
#include "cursesmain.h"
|
||||
#include "gtkmain.h"
|
||||
|
||||
|
@ -58,6 +60,16 @@ static XP_UCHAR* linux_dutil_md5sum( XW_DUtilCtxt* duc, XWEnv xwe, const XP_U8*
|
|||
XP_U32 len );
|
||||
#endif
|
||||
|
||||
static DictionaryCtxt*
|
||||
linux_dutil_getDict( XW_DUtilCtxt* duc, XWEnv xwe,
|
||||
const XP_UCHAR* dictName )
|
||||
{
|
||||
LaunchParams* params = (LaunchParams*)duc->closure;
|
||||
DictionaryCtxt* result = linux_dictionary_make( MPPARM(duc->mpool) xwe,
|
||||
params, dictName, XP_TRUE );
|
||||
return result;
|
||||
}
|
||||
|
||||
static void
|
||||
linux_dutil_notifyPause( XW_DUtilCtxt* XP_UNUSED(duc), XWEnv XP_UNUSED(xwe),
|
||||
XP_U32 XP_UNUSED_DBG(gameID),
|
||||
|
@ -126,7 +138,7 @@ linux_dutil_onGameGoneReceived( XW_DUtilCtxt* duc, XWEnv XP_UNUSED(xwe),
|
|||
}
|
||||
|
||||
XW_DUtilCtxt*
|
||||
dutils_init( MPFORMAL VTableMgr* vtMgr, void* closure )
|
||||
linux_dutils_init( MPFORMAL VTableMgr* vtMgr, void* closure )
|
||||
{
|
||||
XW_DUtilCtxt* result = XP_CALLOC( mpool, sizeof(*result) );
|
||||
|
||||
|
@ -156,7 +168,7 @@ dutils_init( MPFORMAL VTableMgr* vtMgr, void* closure )
|
|||
#ifdef COMMS_CHECKSUM
|
||||
SET_PROC(md5sum);
|
||||
#endif
|
||||
|
||||
SET_PROC(getDict);
|
||||
SET_PROC(notifyPause);
|
||||
SET_PROC(onDupTimerChanged);
|
||||
SET_PROC(onInviteReceived);
|
||||
|
@ -170,7 +182,8 @@ dutils_init( MPFORMAL VTableMgr* vtMgr, void* closure )
|
|||
return result;
|
||||
}
|
||||
|
||||
void dutils_free( XW_DUtilCtxt** dutil )
|
||||
void
|
||||
linux_dutils_free( XW_DUtilCtxt** dutil )
|
||||
{
|
||||
kplr_cleanup( *dutil );
|
||||
# ifdef MEM_DEBUG
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
#include "dutil.h"
|
||||
|
||||
XW_DUtilCtxt* dutils_init( MPFORMAL VTableMgr* vtMgr, void* closure );
|
||||
void dutils_free( XW_DUtilCtxt** ducp );
|
||||
XW_DUtilCtxt* linux_dutils_init( MPFORMAL VTableMgr* vtMgr, void* closure );
|
||||
void linux_dutils_free( XW_DUtilCtxt** ducp );
|
||||
|
||||
#endif
|
||||
|
|
|
@ -200,15 +200,9 @@ linuxOpenGame( CommonGlobals* cGlobals, const TransportProcs* procs,
|
|||
}
|
||||
|
||||
if ( !!stream ) {
|
||||
if ( NULL == cGlobals->dict ) {
|
||||
cGlobals->dict = makeDictForStream( cGlobals, stream );
|
||||
XP_ASSERT( !!cGlobals->dict );
|
||||
}
|
||||
|
||||
opened = game_makeFromStream( MEMPOOL NULL_XWE, stream, &cGlobals->game,
|
||||
cGlobals->gi, cGlobals->dict,
|
||||
&cGlobals->dicts, cGlobals->util,
|
||||
cGlobals->draw,
|
||||
cGlobals->gi,
|
||||
cGlobals->util, cGlobals->draw,
|
||||
&cGlobals->cp, procs );
|
||||
XP_LOGF( "%s: loaded gi at %p", __func__, &cGlobals->gi );
|
||||
stream_destroy( stream, NULL_XWE );
|
||||
|
@ -281,10 +275,7 @@ linuxOpenGame( CommonGlobals* cGlobals, const TransportProcs* procs,
|
|||
}
|
||||
}
|
||||
|
||||
XP_ASSERT( !!cGlobals->dict );
|
||||
model_setDictionary( cGlobals->game.model, NULL_XWE, cGlobals->dict );
|
||||
setSquareBonuses( cGlobals );
|
||||
model_setPlayerDicts( cGlobals->game.model, NULL_XWE, &cGlobals->dicts );
|
||||
|
||||
/* Need to save in order to have a valid selRow for the first send */
|
||||
linuxSaveGame( cGlobals );
|
||||
|
@ -405,25 +396,6 @@ streamFromDB( CommonGlobals* cGlobals )
|
|||
}
|
||||
#endif
|
||||
|
||||
DictionaryCtxt*
|
||||
makeDictForStream( CommonGlobals* cGlobals, XWStreamCtxt* stream )
|
||||
{
|
||||
CurGameInfo gi = {0};
|
||||
XWStreamPos pos = stream_getPos( stream, POS_READ );
|
||||
if ( !game_makeFromStream( MPPARM(cGlobals->util->mpool) NULL_XWE, stream,
|
||||
NULL, &gi, NULL, NULL, NULL, NULL, NULL, NULL ) ) {
|
||||
XP_ASSERT(0);
|
||||
}
|
||||
stream_setPos( stream, POS_READ, pos );
|
||||
|
||||
DictionaryCtxt* dict =
|
||||
linux_dictionary_make( MPPARM(cGlobals->util->mpool) NULL_XWE, cGlobals->params,
|
||||
gi.dictName, XP_TRUE );
|
||||
gi_disposePlayerInfo( MPPARM(cGlobals->util->mpool) &gi );
|
||||
XP_ASSERT( !!dict );
|
||||
return dict;
|
||||
}
|
||||
|
||||
void
|
||||
gameGotBuf( CommonGlobals* cGlobals, XP_Bool hasDraw, const XP_U8* buf,
|
||||
XP_U16 len, const CommsAddrRec* from )
|
||||
|
@ -631,10 +603,8 @@ handle_messages_from( CommonGlobals* cGlobals, const TransportProcs* procs,
|
|||
XP_Bool opened =
|
||||
#endif
|
||||
game_makeFromStream( MPPARM(cGlobals->util->mpool)
|
||||
NULL_XWE, stream, &cGlobals->game,
|
||||
cGlobals->gi, cGlobals->dict,
|
||||
&cGlobals->dicts, cGlobals->util,
|
||||
NULL /*draw*/,
|
||||
NULL_XWE, stream, &cGlobals->game, cGlobals->gi,
|
||||
cGlobals->util, NULL /*draw*/,
|
||||
&cGlobals->cp, procs );
|
||||
XP_ASSERT( opened );
|
||||
stream_destroy( stream, NULL_XWE );
|
||||
|
@ -679,9 +649,8 @@ read_pipe_then_close( CommonGlobals* cGlobals, const TransportProcs* procs )
|
|||
#endif
|
||||
game_makeFromStream( MPPARM(cGlobals->util->mpool)
|
||||
NULL_XWE, stream, &cGlobals->game,
|
||||
cGlobals->gi, cGlobals->dict,
|
||||
&cGlobals->dicts, cGlobals->util,
|
||||
NULL /*draw*/,
|
||||
cGlobals->gi,
|
||||
cGlobals->util, NULL /*draw*/,
|
||||
&cGlobals->cp, procs );
|
||||
XP_ASSERT( opened );
|
||||
stream_destroy( stream, NULL_XWE );
|
||||
|
@ -2587,7 +2556,7 @@ initParams( LaunchParams* params )
|
|||
/* params->util->vtable->m_util_setIsServer = linux_util_setIsServer; */
|
||||
#endif
|
||||
|
||||
params->dutil = dutils_init( MPPARM(params->mpool) params->vtMgr, params );
|
||||
params->dutil = linux_dutils_init( MPPARM(params->mpool) params->vtMgr, params );
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -2597,7 +2566,7 @@ freeParams( LaunchParams* params )
|
|||
params->pDb = NULL;
|
||||
|
||||
vtmgr_destroy( MPPARM(params->mpool) params->vtMgr );
|
||||
dutils_free( ¶ms->dutil );
|
||||
linux_dutils_free( ¶ms->dutil );
|
||||
dmgr_destroy( params->dictMgr, NULL_XWE );
|
||||
|
||||
gi_disposePlayerInfo( MPPARM(params->mpool) ¶ms->pgi );
|
||||
|
|
|
@ -100,9 +100,6 @@ void assertDrawCallbacksSet( const DrawCtxVTable* vtable );
|
|||
void setupUtil( CommonGlobals* cGlobals );
|
||||
void disposeUtil( CommonGlobals* cGlobals );
|
||||
|
||||
DictionaryCtxt* makeDictForStream( CommonGlobals* cGlobals,
|
||||
XWStreamCtxt* stream );
|
||||
|
||||
void sendRelayReg( LaunchParams* params, sqlite3* pDb );
|
||||
void gameGotBuf( CommonGlobals* globals, XP_Bool haveDraw,
|
||||
const XP_U8* buf, XP_U16 len, const CommsAddrRec* from );
|
||||
|
|
|
@ -229,8 +229,6 @@ struct CommonGlobals {
|
|||
DrawCtx* draw;
|
||||
CurGameInfo* gi;
|
||||
CommsAddrRec addr;
|
||||
DictionaryCtxt* dict;
|
||||
PlayerDicts dicts;
|
||||
XP_U16 lastNTilesToUse;
|
||||
XP_U16 lastStreamSize;
|
||||
XP_U16 nMissing;
|
||||
|
|
Loading…
Add table
Reference in a new issue