mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-15 15:41:24 +01:00
move getDict from dutil to util
It's in the context of a game, and we might want info about the game when notifying the user. For wasm, though, I just download after failure to open. User has to try again to open the game. Good enough for now since missing a wordlist shouldn't happen if you're not me changing where they're stored.
This commit is contained in:
parent
87621c3b51
commit
b1532f19a4
7 changed files with 96 additions and 68 deletions
|
@ -82,9 +82,6 @@ typedef struct _DUtilVtable {
|
|||
XP_UCHAR* (*m_dutil_md5sum)( XW_DUtilCtxt* duc, XWEnv xwe, const XP_U8* ptr, XP_U32 len );
|
||||
#endif
|
||||
|
||||
const DictionaryCtxt* (*m_dutil_getDict)( XW_DUtilCtxt* duc, XWEnv xwe,
|
||||
XP_LangCode lang, 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 );
|
||||
|
@ -153,9 +150,6 @@ void dutil_super_init( MPFORMAL XW_DUtilCtxt* dutil );
|
|||
(duc)->vtable.m_dutil_md5sum((duc), (e), (p), (l))
|
||||
#endif
|
||||
|
||||
#define dutil_getDict( duc, xwe, lc, dictName ) \
|
||||
(duc)->vtable.m_dutil_getDict( (duc), (xwe), (lc), (dictName) )
|
||||
|
||||
#define dutil_notifyPause( duc, e, id, ip, p, n, m ) \
|
||||
(duc)->vtable.m_dutil_notifyPause( (duc), (e), (id), (ip), (p), (n), (m) )
|
||||
|
||||
|
|
|
@ -125,14 +125,14 @@ getDicts( const CurGameInfo* gi, XW_UtilCtxt* util, XWEnv xwe,
|
|||
XP_LangCode langCode, PlayerDicts* playerDicts )
|
||||
{
|
||||
XW_DUtilCtxt* dutil = util_getDevUtilCtxt( util, xwe );
|
||||
const DictionaryCtxt* result = dutil_getDict( dutil, xwe, langCode, gi->dictName );
|
||||
const DictionaryCtxt* result = util_getDict( util, xwe, langCode, 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 && lp->dictName[0] ) {
|
||||
playerDicts->dicts[ii] = dutil_getDict( dutil, xwe, langCode,
|
||||
lp->dictName );
|
||||
playerDicts->dicts[ii] = util_getDict( util, xwe, langCode,
|
||||
lp->dictName );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -128,6 +128,9 @@ typedef struct UtilVtable {
|
|||
const XP_UCHAR* newSum,
|
||||
XWPhoniesChoice phoniesAction );
|
||||
|
||||
const DictionaryCtxt* (*m_util_getDict)( XW_UtilCtxt* uc, XWEnv xwe,
|
||||
XP_LangCode lang, const XP_UCHAR* dictName );
|
||||
|
||||
void (*m_util_notifyGameOver)( XW_UtilCtxt* uc, XWEnv xwe, XP_S16 quitter );
|
||||
#ifdef XWFEATURE_HILITECELL
|
||||
XP_Bool (*m_util_hiliteCell)( XW_UtilCtxt* uc, XWEnv xwe, XP_U16 col, XP_U16 row );
|
||||
|
@ -251,6 +254,9 @@ struct XW_UtilCtxt {
|
|||
#define util_informNetDict(uc,e, cd, on, nn, ns, pa ) \
|
||||
(uc)->vtable->m_util_informNetDict( (uc), (e), (cd), (on), (nn), (ns), \
|
||||
(pa) )
|
||||
#define util_getDict( uc, xwe, lang, dictName ) \
|
||||
(uc)->vtable->m_util_getDict((uc), (xwe), (lang), (dictName))
|
||||
|
||||
#define util_notifyGameOver( uc,e, q ) \
|
||||
(uc)->vtable->m_util_notifyGameOver((uc), (e), (q))
|
||||
|
||||
|
|
|
@ -1837,6 +1837,23 @@ main_updateScreen( GameState* gs )
|
|||
updateScreen( gs, true );
|
||||
}
|
||||
|
||||
static void
|
||||
onGotMissingDict( void* closure, GotDictData* gdd )
|
||||
{
|
||||
CAST_GLOB(Globals*, globals, closure);
|
||||
if ( !!gdd->data
|
||||
&& 0 < gdd->len ) {
|
||||
storeAsDict( globals, gdd );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
main_needDictForGame(GameState* gs, XP_LangCode lang, const XP_UCHAR* dictName)
|
||||
{
|
||||
const char* lc = lcToLocale(lang);
|
||||
call_get_dict( lc, onGotMissingDict, gs->globals );
|
||||
}
|
||||
|
||||
static void
|
||||
looper( void* closure )
|
||||
{
|
||||
|
|
|
@ -109,5 +109,6 @@ void main_turnChanged(GameState* gs, int newTurn);
|
|||
void main_pickBlank( GameState* gs, int playerNum, int col, int row,
|
||||
const char** tileFaces, int nTiles );
|
||||
void main_updateScreen( GameState* gs );
|
||||
void main_needDictForGame(GameState* gs, XP_LangCode lang, const XP_UCHAR* dictName);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -380,64 +380,6 @@ wasm_dutil_md5sum( XW_DUtilCtxt* duc, XWEnv xwe, const XP_U8* ptr,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
typedef struct _ForLangState {
|
||||
XW_DUtilCtxt* duc;
|
||||
XWEnv xwe;
|
||||
uint8_t* ptr;
|
||||
XP_U32 len;
|
||||
} ForLangState;
|
||||
|
||||
static XP_Bool
|
||||
gotForLang( void* closure, const XP_UCHAR* keys[] )
|
||||
{
|
||||
XP_LOGFF("name: %s", keys[2]);
|
||||
ForLangState* fls = (ForLangState*)closure;
|
||||
fls->ptr = wasm_dutil_mallocAndLoad( fls->duc, keys, &fls->len );
|
||||
if ( !fls->ptr ) {
|
||||
XP_LOGFF( "nothing for %s/%s", keys[1], keys[2] );
|
||||
}
|
||||
return NULL == fls->ptr;
|
||||
}
|
||||
|
||||
static const DictionaryCtxt*
|
||||
wasm_dutil_getDict( XW_DUtilCtxt* duc, XWEnv xwe,
|
||||
XP_LangCode lang, const XP_UCHAR* dictName )
|
||||
{
|
||||
XP_LOGFF( "(dictName: %s)", dictName );
|
||||
|
||||
const char* lc = lcToLocale( lang );
|
||||
|
||||
CAST_GLOB( Globals*, globals, duc->closure );
|
||||
const DictionaryCtxt* result = dmgr_get( globals->dictMgr, xwe, dictName );
|
||||
if ( !result ) {
|
||||
XP_U32 len = 0;
|
||||
const char* keys[] = {KEY_DICTS, lc, KEY_DICTS, dictName, NULL };
|
||||
|
||||
uint8_t* ptr = wasm_dutil_mallocAndLoad( duc, keys, &len );
|
||||
if ( !ptr ) {
|
||||
XP_LOGFF( "trying for another %s dict", lc );
|
||||
ForLangState fls = { .duc = duc,
|
||||
.xwe = xwe,
|
||||
};
|
||||
const char* langKeys[] = {KEY_DICTS, lc, KEY_DICTS, KEY_WILDCARD, NULL};
|
||||
dutil_forEach( duc, xwe, langKeys, gotForLang, &fls );
|
||||
if ( !!fls.ptr ) {
|
||||
ptr = fls.ptr;
|
||||
len = fls.len;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !!ptr ) {
|
||||
result = wasm_dictionary_make( globals, xwe, dictName, ptr, len );
|
||||
XP_FREE( globals->mpool, ptr );
|
||||
dmgr_put( globals->dictMgr, xwe, dictName, result );
|
||||
}
|
||||
}
|
||||
|
||||
XP_LOGFF("(%s, %s)=>%p", lc, dictName, result );
|
||||
return result;
|
||||
}
|
||||
|
||||
static void
|
||||
wasm_dutil_notifyPause( XW_DUtilCtxt* XP_UNUSED(duc), XWEnv XP_UNUSED(xwe),
|
||||
XP_U32 XP_UNUSED_DBG(gameID),
|
||||
|
@ -540,7 +482,6 @@ wasm_dutil_make( MPFORMAL VTableMgr* vtMgr, void* closure )
|
|||
SET_PROC(md5sum);
|
||||
#endif
|
||||
|
||||
SET_PROC(getDict);
|
||||
SET_PROC(notifyPause);
|
||||
SET_PROC(onDupTimerChanged);
|
||||
SET_PROC(onInviteReceived);
|
||||
|
|
|
@ -19,9 +19,11 @@
|
|||
|
||||
#include "util.h"
|
||||
#include "comtypes.h"
|
||||
#include "strutils.h"
|
||||
#include "main.h"
|
||||
#include "dbgutil.h"
|
||||
#include "wasmdict.h"
|
||||
#include "wasmdutil.h"
|
||||
|
||||
typedef struct _WasmUtilCtx {
|
||||
XW_UtilCtxt super;
|
||||
|
@ -478,6 +480,71 @@ wasm_util_playerScoreHeld( XW_UtilCtxt* uc, XWEnv xwe, XP_U16 player )
|
|||
main_playerScoreHeld( gs, player );
|
||||
}
|
||||
|
||||
typedef struct _ForLangState {
|
||||
XW_DUtilCtxt* duc;
|
||||
XWEnv xwe;
|
||||
uint8_t* ptr;
|
||||
XP_U32 len;
|
||||
} ForLangState;
|
||||
|
||||
static XP_Bool
|
||||
gotForLang( void* closure, const XP_UCHAR* keys[] )
|
||||
{
|
||||
XP_LOGFF("name: %s", keys[2]);
|
||||
ForLangState* fls = (ForLangState*)closure;
|
||||
fls->ptr = wasm_dutil_mallocAndLoad( fls->duc, keys, &fls->len );
|
||||
if ( !fls->ptr ) {
|
||||
XP_LOGFF( "nothing for %s/%s", keys[1], keys[2] );
|
||||
}
|
||||
return NULL == fls->ptr;
|
||||
}
|
||||
|
||||
static const DictionaryCtxt*
|
||||
wasm_util_getDict( XW_UtilCtxt* uc, XWEnv xwe,
|
||||
XP_LangCode lang, const XP_UCHAR* dictName )
|
||||
{
|
||||
XP_LOGFF( "(dictName: %s)", dictName );
|
||||
WasmUtilCtx* wuctxt = (WasmUtilCtx*)uc;
|
||||
GameState* gs = wuctxt->closure;
|
||||
Globals* globals = gs->globals;
|
||||
XW_DUtilCtxt* duc = util_getDevUtilCtxt(uc, xwe);
|
||||
|
||||
const char* lc = lcToLocale( lang );
|
||||
|
||||
const DictionaryCtxt* result = dmgr_get( globals->dictMgr, xwe, dictName );
|
||||
if ( !result ) {
|
||||
XP_U32 len = 0;
|
||||
const char* keys[] = {KEY_DICTS, lc, KEY_DICTS, dictName, NULL };
|
||||
|
||||
uint8_t* ptr = wasm_dutil_mallocAndLoad( duc, keys, &len );
|
||||
if ( !ptr ) {
|
||||
XP_LOGFF( "trying for another %s dict", lc );
|
||||
ForLangState fls = { .duc = duc,
|
||||
.xwe = xwe,
|
||||
};
|
||||
const char* langKeys[] = {KEY_DICTS, lc, KEY_DICTS, KEY_WILDCARD, NULL};
|
||||
dutil_forEach( duc, xwe, langKeys, gotForLang, &fls );
|
||||
if ( !!fls.ptr ) {
|
||||
ptr = fls.ptr;
|
||||
len = fls.len;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !!ptr ) {
|
||||
result = wasm_dictionary_make( globals, xwe, dictName, ptr, len );
|
||||
XP_FREE( globals->mpool, ptr );
|
||||
dmgr_put( globals->dictMgr, xwe, dictName, result );
|
||||
}
|
||||
}
|
||||
|
||||
if ( !result ) {
|
||||
main_needDictForGame( gs, lang, dictName );
|
||||
}
|
||||
|
||||
XP_LOGFF("(%s, %s)=>%p", lc, dictName, result );
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef XWFEATURE_BOARDWORDS
|
||||
static void
|
||||
wasm_util_cellSquareHeld( XW_UtilCtxt* uc, XWEnv xwe, XWStreamCtxt* words )
|
||||
|
@ -584,6 +651,8 @@ wasm_util_make( MPFORMAL CurGameInfo* gi, XW_DUtilCtxt* dctxt, GameState* closur
|
|||
SET_VTABLE_ENTRY( wuctxt->super.vtable, util_bonusSquareHeld, wasm );
|
||||
SET_VTABLE_ENTRY( wuctxt->super.vtable, util_playerScoreHeld, wasm );
|
||||
|
||||
SET_VTABLE_ENTRY( wuctxt->super.vtable, util_getDict, wasm );
|
||||
|
||||
#ifdef XWFEATURE_BOARDWORDS
|
||||
SET_VTABLE_ENTRY( wuctxt->super.vtable, util_cellSquareHeld, wasm );
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue