game from a downloaded wordlist works!!!!

This commit is contained in:
Eric House 2021-02-27 21:16:01 -08:00
parent afc3ff156e
commit d5e7dc4c97
11 changed files with 211 additions and 216 deletions

View file

@ -34,8 +34,7 @@ typedef enum { UNPAUSED,
AUTOPAUSED,
} DupPauseType;
typedef XP_Bool (*OnOneProc)(void* closure, const XP_UCHAR* indx,
const void* val, XP_U32 valLen);
typedef XP_Bool (*OnOneProc)(void* closure, const XP_UCHAR* indx);
typedef struct _DUtilVtable {
XP_U32 (*m_dutil_getCurSeconds)( XW_DUtilCtxt* duc, XWEnv xwe );
@ -90,8 +89,8 @@ 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 );
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,
@ -171,8 +170,8 @@ 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_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) )

View file

@ -120,18 +120,19 @@ setListeners( XWGame* game, const CommonPrefs* cp )
server_setTimerChangeListener( game->server, timerChangeListener, game );
}
static DictionaryCtxt*
static const DictionaryCtxt*
getDicts( const CurGameInfo* gi, XW_UtilCtxt* util, XWEnv xwe,
PlayerDicts* playerDicts )
XP_LangCode langCode, PlayerDicts* playerDicts )
{
XW_DUtilCtxt* dutil = util_getDevUtilCtxt( util, xwe );
DictionaryCtxt* result = dutil_getDict( dutil, xwe, gi->dictName );
const DictionaryCtxt* result = dutil_getDict( dutil, 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 ) {
playerDicts->dicts[ii] = dutil_getDict( dutil, xwe, lp->dictName );
playerDicts->dicts[ii] = dutil_getDict( dutil, xwe, langCode,
lp->dictName );
}
}
}
@ -139,7 +140,7 @@ getDicts( const CurGameInfo* gi, XW_UtilCtxt* util, XWEnv xwe,
}
static void
unrefDicts( XWEnv xwe, DictionaryCtxt* dict, PlayerDicts* playerDicts )
unrefDicts( XWEnv xwe, const DictionaryCtxt* dict, PlayerDicts* playerDicts )
{
if ( !!dict ) {
dict_unref( dict, xwe );
@ -175,7 +176,7 @@ game_makeNewGame( MPFORMAL XWEnv xwe, XWGame* game, CurGameInfo* gi,
game->util = util;
PlayerDicts playerDicts;
DictionaryCtxt* dict = getDicts( gi, util, xwe, &playerDicts );
const DictionaryCtxt* dict = getDicts( gi, util, xwe, gi->dictLang, &playerDicts );
XP_Bool success = !!dict;
if ( success ) {
@ -333,7 +334,8 @@ game_makeFromStream( MPFORMAL XWEnv xwe, XWStreamCtxt* stream,
? 0 : stream_getU32( stream );
PlayerDicts playerDicts;
DictionaryCtxt* dict = getDicts( gi, util, xwe, &playerDicts );
const DictionaryCtxt* dict = getDicts( gi, util, xwe,
gi->dictLang, &playerDicts );
if ( !dict ) {
break;
}

View file

@ -423,7 +423,7 @@ lcToLocale( XP_LangCode lc )
/* <item>@string/lang_name_slovak</item> */
/* <item>@string/lang_name_hungarian</item> */
}
XP_ASSERT( !!result );
return result;
}

View file

@ -44,6 +44,7 @@ DEFINES += -DPLATFORM_WASM
DEFINES += -DXWFEATURE_CROSSHAIRS
DEFINES += -DXWFEATURE_STREAMREF
DEFINES += -DXWFEATURE_TURNCHANGENOTIFY
DEFINES += -DXWFEATURE_INDEXSTORE
DEFINES += -DNATIVE_NLI
DEFINES += -DDEBUG_REF
DEFINES += -Wno-switch

View file

@ -1 +0,0 @@
../../android/app/src/main/assets/CollegeEng_2to8.xwd

View file

@ -62,14 +62,10 @@
#define KEY_LAST_GID "cur_game"
#define KEY_PLAYER_NAME "player_name"
#define KEY_DICTS "dicts_3"
#define KEY_GAME "game_data"
#define KEY_NAME "game_name"
#define KEY_NEXT_GAME "next_game"
#define DICTNAME "assets_dir/CollegeEng_2to8.xwd"
#define BUTTON_OK "OK"
#define BUTTON_CANCEL "Cancel"
@ -513,14 +509,19 @@ onGameChosen( void* closure, const char* key )
}
static XP_Bool
onOneIndx( void* closure, const XP_UCHAR* indx, const void* val, XP_U32 valLen )
onOneIndx( void* closure, const XP_UCHAR* indx )
{
XP_LOGFF( "(indx: %s, len: %d, val: %s)", indx, valLen, (char*)val );
XP_LOGFF( "(indx: %s)", indx );
NameIterState* nis = (NameIterState*)closure;
Globals* globals = nis->globals;
++nis->count;
nis->names = XP_REALLOC( globals->mpool, nis->names,
nis->count * sizeof(nis->names[0]) );
XP_U32 valLen;
dutil_loadIndxPtr( globals->dutil, NULL, KEY_NAME, indx, NULL, &valLen );
uint8_t val[valLen];
dutil_loadIndxPtr( globals->dutil, NULL, KEY_NAME, indx, val, &valLen );
nis->names[nis->count-1] = XP_MALLOC( globals->mpool, valLen );
XP_MEMCPY( nis->names[nis->count-1], val, valLen );
@ -651,7 +652,7 @@ onDeviceButton( void* closure, const char* button )
}
static XP_Bool
upCounter( void* closure, const XP_UCHAR* indx, const void* val, XP_U32 valLen )
upCounter( void* closure, const XP_UCHAR* indx )
{
XP_LOGFF("(indx: %s)", indx);
int* intp = (int*)closure;
@ -667,12 +668,31 @@ countGames( Globals* globals )
return nFound;
}
static XP_Bool
onOneDictCount( void* closure, const XP_UCHAR* indx )
{
int* ip = (int*)closure;
++*ip;
return XP_TRUE;
}
static int
countDicts( Globals* globals )
{
int count = 0;
dutil_forEachIndx( globals->dutil, NULL, KEY_DICTS, onOneDictCount, &count );
LOG_RETURNF( "%d", count );
return count;
}
static void
updateDeviceButtons( Globals* globals )
{
const char* buttons[MAX_BUTTONS];
int cur = 0;
buttons[cur++] = BUTTON_GAME_NEW;
if ( 0 < countDicts( globals ) ) {
buttons[cur++] = BUTTON_GAME_NEW;
}
if ( 0 < countGames(globals) ) {
buttons[cur++] = BUTTON_GAME_OPEN;
}
@ -707,46 +727,6 @@ onFocussed( void* closure, const char* ignored )
/* } */
}
static DictionaryCtxt*
playLoadingDict( Globals* globals )
{
/* Looking at whether the storage system can hold a dict. Let's see if
it's stored, and if it isn't store it. They try passing a ptr for
making the actual dict from. */
XP_U32 len = 0;
dutil_loadIndxPtr( globals->dutil, NULL, KEY_DICTS, DICTNAME, NULL, &len );
if ( 0 == len ) {
XP_LOGFF( "not found; storing now..." );
XP_U32 dictLen;
uint8_t* dictBytes = wasm_dictionary_load(MPPARM(globals->mpool)
DICTNAME, &dictLen);
if ( !!dictBytes ) {
XP_LOGFF( "loaded %d bytes of dict", dictLen );
dutil_storeIndxPtr( globals->dutil, NULL, KEY_DICTS, DICTNAME,
dictBytes, dictLen );
XP_FREE( globals->mpool, dictBytes );
}
len = dictLen;
} else {
XP_LOGFF( "using stored wordlist of len %d", len );
}
XP_U32 oldLen = len;
XP_LOGFF( "oldLen: %d", oldLen );
uint8_t* bytes = XP_MALLOC( globals->mpool, len );
dutil_loadIndxPtr( globals->dutil, NULL, KEY_DICTS, DICTNAME,
bytes, &len );
XP_ASSERT( len == oldLen );
DictionaryCtxt* dict =
wasm_dictionary_make( MPPARM(globals->mpool) NULL,
globals, DICTNAME, false, bytes );
LOG_RETURNF( "%p", dict );
return dict;
}
static void
onMqttMsg(void* closure, const uint8_t* data, int len )
{
@ -773,10 +753,6 @@ initDeviceGlobals( Globals* globals )
globals->dutil = wasm_dutil_make( MPPARM(globals->mpool) globals->vtMgr, globals );
globals->dictMgr = dmgr_make( MPPARM_NOCOMMA(globals->mpool) );
globals->dict = playLoadingDict( globals );
dict_ref( globals->dict, NULL );
globals->draw = wasm_draw_make( MPPARM(globals->mpool)
WINDOW_WIDTH, WINDOW_HEIGHT );
@ -788,7 +764,9 @@ initDeviceGlobals( Globals* globals )
int now = dutil_getCurSeconds( globals->dutil, NULL );
call_setup( globals, buf, GITREV, now, onConflict, onFocussed, onMqttMsg );
call_get_dict( globals );
if ( 0 == countDicts( globals ) ) {
call_get_dict( globals );
}
}
static void
@ -812,10 +790,7 @@ startGame( GameState* gs, const char* name )
WASM_BOARD_LEFT, WASM_HOR_SCORE_TOP, BDWIDTH, BDHEIGHT,
110, 150, 200, BDWIDTH-25, BDWIDTH/15, BDHEIGHT/15,
XP_FALSE, &dims );
XP_LOGFF( "calling board_applyLayout" );
board_applyLayout( gs->game.board, NULL, &dims );
XP_LOGFF( "calling model_setDictionary" );
model_setDictionary( gs->game.model, NULL, gs->globals->dict );
board_invalAll( gs->game.board ); /* redraw screen on loading new game */
@ -849,7 +824,6 @@ newFromInvite( Globals* globals, const NetLaunchInfo* invite )
game_makeFromInvite( MPPARM(globals->mpool) NULL, invite,
&gs->game, &gs->gi, playerName,
globals->dict, NULL,
gs->util, globals->draw,
&globals->cp, &globals->procs );
if ( invite->gameName[0] ) {
@ -936,7 +910,6 @@ getSavedGame( Globals* globals, int gameID )
XP_LOGFF( "there's a saved game!!" );
loaded = game_makeFromStream( MPPARM(globals->mpool) NULL, stream,
&gs->game, &gs->gi,
globals->dict, NULL,
gs->util, globals->draw,
&globals->cp, &globals->procs );
@ -1013,6 +986,37 @@ nameGame( GameState* gs, const char* name )
XP_LOGFF( "named game: %s", gs->gameName );
}
typedef struct _FindOneState {
Globals* globals;
DictionaryCtxt* dict;
} FindOneState;
static XP_Bool
onOneDict( void* closure, const XP_UCHAR* indx )
{
XP_LOGFF( "indx: %s", indx );
FindOneState* fos = (FindOneState*)closure;
XW_DUtilCtxt* dutil = fos->globals->dutil;
XP_U32 len = 0;
dutil_loadIndxPtr( dutil, NULL, KEY_DICTS, indx, NULL, &len );
uint8_t* ptr = XP_MALLOC( fos->globals->mpool, len );
dutil_loadIndxPtr( dutil, NULL, KEY_DICTS, indx, ptr, &len );
XP_ASSERT( !fos->dict );
fos->dict = wasm_dictionary_make( fos->globals, NULL, indx, ptr, len );
return XP_FALSE;
}
static DictionaryCtxt*
loadAnyDict( Globals* globals )
{
FindOneState fos = {.globals = globals,
};
dutil_forEachIndx( globals->dutil, NULL, KEY_DICTS, onOneDict, &fos );
LOG_RETURNF( "%p", fos.dict );
return fos.dict;
}
static void
loadAndDraw( Globals* globals, const NetLaunchInfo* invite,
const char* gameIDStr, NewGameParams* params )
@ -1035,47 +1039,53 @@ loadAndDraw( Globals* globals, const NetLaunchInfo* invite,
}
if ( !gs ) {
char playerName[32];
getPlayerName( globals, playerName, sizeof(playerName) );
DictionaryCtxt* dict = loadAnyDict( globals );
if ( !!dict ) {
char playerName[32];
getPlayerName( globals, playerName, sizeof(playerName) );
gs = newGameState( globals );
gs->gi.serverRole = !!params && !params->isRobotNotRemote
? SERVER_ISSERVER : SERVER_STANDALONE;
gs = newGameState( globals );
gs->gi.serverRole = !!params && !params->isRobotNotRemote
? SERVER_ISSERVER : SERVER_STANDALONE;
gs->gi.phoniesAction = PHONIES_WARN;
gs->gi.hintsNotAllowed = !!params && params->hintsNotAllowed || false;
gs->gi.gameID = 0;
gs->gi.dictLang = 1; /* English only for now */
replaceStringIfDifferent( globals->mpool, &gs->gi.dictName,
"CollegeEng_2to8" );
gs->gi.nPlayers = 2;
gs->gi.boardSize = 15;
gs->gi.players[0].name = copyString( globals->mpool, playerName );
gs->gi.players[0].isLocal = XP_TRUE;
gs->gi.players[0].robotIQ = 0;
gs->gi.phoniesAction = PHONIES_WARN;
gs->gi.hintsNotAllowed = !!params && params->hintsNotAllowed || false;
gs->gi.gameID = 0;
gs->gi.dictLang = dict_getLangCode(dict);
replaceStringIfDifferent( globals->mpool, &gs->gi.dictName,
dict_getShortName(dict) );
gs->gi.nPlayers = 2;
gs->gi.boardSize = 15;
gs->gi.players[0].name = copyString( globals->mpool, playerName );
gs->gi.players[0].isLocal = XP_TRUE;
gs->gi.players[0].robotIQ = 0;
gs->gi.players[1].name = copyString( globals->mpool, "Robot" );
gs->gi.players[1].isLocal = !!params ? params->isRobotNotRemote : true;
XP_LOGFF( "set isLocal[1]: %d", gs->gi.players[1].isLocal );
gs->gi.players[1].robotIQ = 99; /* doesn't matter if remote */
gs->gi.players[1].name = copyString( globals->mpool, "Robot" );
gs->gi.players[1].isLocal = !!params ? params->isRobotNotRemote : true;
XP_LOGFF( "set isLocal[1]: %d", gs->gi.players[1].isLocal );
gs->gi.players[1].robotIQ = 99; /* doesn't matter if remote */
gs->util = wasm_util_make( MPPARM(globals->mpool) &gs->gi,
globals->dutil, gs );
gs->util = wasm_util_make( MPPARM(globals->mpool) &gs->gi,
globals->dutil, gs );
XP_LOGFF( "calling game_makeNewGame()" );
game_makeNewGame( MPPARM(globals->mpool) NULL,
&gs->game, &gs->gi,
gs->util, globals->draw,
&globals->cp, &globals->procs );
XP_LOGFF( "calling game_makeNewGame()" );
game_makeNewGame( MPPARM(globals->mpool) NULL,
&gs->game, &gs->gi,
gs->util, globals->draw,
&globals->cp, &globals->procs );
ensureName( gs );
if ( !!gs->game.comms ) {
CommsAddrRec addr = {0};
makeSelfAddr( globals, &addr );
comms_augmentHostAddr( gs->game.comms, NULL, &addr );
ensureName( gs );
if ( !!gs->game.comms ) {
CommsAddrRec addr = {0};
makeSelfAddr( globals, &addr );
comms_augmentHostAddr( gs->game.comms, NULL, &addr );
}
dict_unref( dict, NULL );
}
}
startGame( gs, NULL );
if ( !!gs ) {
startGame( gs, NULL );
}
LOG_RETURN_VOID();
}
@ -1640,9 +1650,13 @@ gotDictBinary( void* closure, const char* xwd, const char* lang,
const char* lc, int len, uint8_t* data )
{
XP_LOGFF( "xwd: %s; lang: %s, lc: %s, len: %d", xwd, lang, lc, len );
for ( int ii = 0; ii < 10; ++ii ) {
XP_LOGFF( "byte[%d]: 0x%X", ii, data[ii] );
}
CAST_GLOB(Globals*, globals, closure);
char key[64];
formatDictIndx( key, sizeof(key), lc, xwd );
dutil_storeIndxPtr( globals->dutil, NULL, KEY_DICTS, key, data, len );
updateDeviceButtons( globals );
}
int

View file

@ -60,7 +60,6 @@ typedef struct Globals {
VTableMgr* vtMgr;
XW_DUtilCtxt* dutil;
DrawCtx* draw;
DictionaryCtxt* dict;
TransportProcs procs;
CommonPrefs cp;
DictMgrCtxt* dictMgr;
@ -76,6 +75,8 @@ typedef struct Globals {
#define CAST_GLOB(typ, var, ptr) XP_ASSERT(((typ)(ptr))->_GUARD == GUARD_GLOB); typ var = (typ)(ptr)
#define CAST_GS(typ, var, ptr) XP_ASSERT(((typ)(ptr))->_GUARD == GUARD_GS); typ var = (typ)(ptr)
#define KEY_DICTS "dicts_3"
void main_set_timer( GameState* gs, XWTimerReason why, XP_U16 when,
XWTimerProc proc, void* closure );
void main_clear_timer( GameState* gs, XWTimerReason why );

View file

@ -49,43 +49,16 @@ getShortName( const DictionaryCtxt* dict )
}
static XP_Bool
initFromDictFile( WasmDictionaryCtxt* dctx, const char* fileName,
uint8_t* dictBase )
initFromPtr( WasmDictionaryCtxt* dctx, const char* name,
uint8_t* dictBase, size_t len )
{
XP_Bool formatOk = XP_TRUE;
size_t dictLength;
XP_U32 topOffset;
char path[256];
if ( !!fileName ) {
snprintf( path, VSIZE(path), "%s", fileName );
} else { // if ( !getDictPath( params, fileName, path, VSIZE(path) ) ) {
XP_LOGF( "%s: path=%s", __func__, path );
goto closeAndExit;
}
struct stat statbuf;
if ( 0 != stat( path, &statbuf ) || 0 == statbuf.st_size ) {
goto closeAndExit;
}
dctx->dictLength = statbuf.st_size;
{
FILE* dictF = fopen( path, "r" );
XP_ASSERT( !!dictF );
if ( !!dictBase ) {
dctx->dictBase = dictBase;
} else if ( dctx->useMMap ) {
dctx->dictBase = mmap( NULL, dctx->dictLength, PROT_READ,
MAP_PRIVATE, fileno(dictF), 0 );
} else {
dctx->dictBase = XP_MALLOC( dctx->super.mpool, dctx->dictLength );
if ( dctx->dictLength != fread( dctx->dictBase, 1,
dctx->dictLength, dictF ) ) {
XP_ASSERT( 0 );
}
}
fclose( dictF );
}
dctx->dictLength = len;
dctx->dictBase = dictBase;
const XP_U8* ptr = dctx->dictBase;
const XP_U8* end = ptr + dctx->dictLength;
@ -120,7 +93,7 @@ initFromDictFile( WasmDictionaryCtxt* dctx, const char* fileName,
numEdges = 0;
}
dctx->super.name = copyString( dctx->super.mpool, fileName );
dctx->super.name = copyString( dctx->super.mpool, name );
if ( ! checkSanity( &dctx->super, numEdges ) ) {
goto closeAndExit;
@ -191,65 +164,33 @@ wasm_dictionary_destroy( DictionaryCtxt* dict, XWEnv xwe )
}
DictionaryCtxt*
wasm_dictionary_make( MPFORMAL XWEnv xwe, Globals* globals,
const char* dictFileName, bool useMMap,
uint8_t* base )
wasm_dictionary_make( Globals* globals, XWEnv xwe,
const char* name, uint8_t* base, size_t len )
{
WasmDictionaryCtxt* result = NULL;
if ( !!dictFileName ) {
/* dmgr_get increments ref count before returning! */
result = (WasmDictionaryCtxt*)dmgr_get( globals->dictMgr, xwe,
dictFileName );
}
if ( !result ) {
result = (WasmDictionaryCtxt*)XP_CALLOC(mpool, sizeof(*result));
result->globals = globals;
dict_super_init( MPPARM(mpool) &result->super );
result->super.destructor = wasm_dictionary_destroy;
result->useMMap = useMMap;
if ( !!dictFileName ) {
XP_Bool success = initFromDictFile( result, dictFileName, base );
if ( success ) {
result->super.func_dict_getShortName = getShortName;
setBlankTile( &result->super );
} else {
XP_ASSERT( 0 ); /* gonna crash anyway */
XP_FREE( mpool, result );
result = NULL;
}
dmgr_put( globals->dictMgr, xwe, dictFileName, &result->super );
} else {
XP_LOGF( "%s(): no file name!!", __func__ );
}
(void)dict_ref( &result->super, xwe );
WasmDictionaryCtxt* result = (WasmDictionaryCtxt*)
XP_CALLOC(globals->mpool, sizeof(*result));
result->globals = globals;
dict_super_init( MPPARM(globals->mpool) &result->super );
result->super.destructor = wasm_dictionary_destroy;
result->useMMap = false;
XP_Bool success = initFromPtr( result, name, base, len );
if ( success ) {
result->super.func_dict_getShortName = getShortName;
setBlankTile( &result->super );
} else {
XP_ASSERT( 0 ); /* gonna crash anyway */
XP_FREE( globals->mpool, result );
result = NULL;
}
(void)dict_ref( &result->super, xwe );
LOG_RETURNF( "%p", &result->super );
return &result->super;
}
uint8_t*
wasm_dictionary_load(MPFORMAL const char* dictFileName, XP_U32* len )
{
uint8_t* result = NULL;
*len = 0;
struct stat statbuf;
if ( 0 == stat( dictFileName, &statbuf ) && 0 != statbuf.st_size ) {
result = XP_MALLOC( mpool, statbuf.st_size );
FILE* dictF = fopen( dictFileName, "r" );
size_t nRead = fread( result, 1, statbuf.st_size, dictF );
XP_ASSERT( nRead == statbuf.st_size );
fclose( dictF );
*len = statbuf.st_size;
XP_LOGFF( "loaded %d bytes", statbuf.st_size );
}
return result;
}
void
dict_splitFaces( DictionaryCtxt* dict, XWEnv xwe, const XP_U8* utf8,
XP_U16 nBytes, XP_U16 nFaces )
@ -302,3 +243,9 @@ computeChecksum( DictionaryCtxt* dctx, XWEnv xwe, const XP_U8* ptr,
{
*out = '\0';
}
void
formatDictIndx( char buf[], size_t len, const char* lang, const char* name )
{
snprintf( buf, len, "%s/%s", lang, name );
}

View file

@ -24,9 +24,8 @@
#include "dictnry.h"
#include "main.h"
DictionaryCtxt* wasm_dictionary_make( MPFORMAL XWEnv xwe, Globals* globals,
const char* dictFileName, bool useMMap,
uint8_t* base );
uint8_t* wasm_dictionary_load(MPFORMAL const char* dictFileName, XP_U32* len );
DictionaryCtxt* wasm_dictionary_make( Globals* globals, XWEnv xwe,
const char* name, uint8_t* base, size_t len );
void formatDictIndx( char buf[], size_t len, const char* lang, const char* name );
#endif

View file

@ -21,11 +21,14 @@
#include <emscripten.h>
#include "strutils.h"
#include "wasmdutil.h"
#include "main.h"
#include "dbgutil.h"
#include "LocalizedStrIncludes.h"
#include "wasmasm.h"
#include "wasmdict.h"
typedef struct _WasmDUtilCtxt {
XW_DUtilCtxt super;
@ -340,6 +343,7 @@ typedef struct _ForEachStateKey {
OnOneProc onOneProc;
void* onOneClosure;
const char* key;
bool doMore;
} ForEachStateKey;
/* I'm called with a full key, PREFIX + KEY + INDEX. I'm interested in it IFF
@ -349,17 +353,13 @@ static void
withOneKey( void* closure, const char* fullKey )
{
ForEachStateKey* fes = (ForEachStateKey*)closure;
char key[128];
char indx[128];
if ( splitFullKey( key, indx, fullKey ) ) {
if ( 0 == strcmp(key, fes->key) ) {
XP_U32 len = 0;
wasm_dutil_loadIndxPtr( fes->duc, fes->xwe, key, indx, NULL, &len );
uint8_t val[len];
wasm_dutil_loadIndxPtr( fes->duc, fes->xwe, key, indx, val, &len );
(*fes->onOneProc)(fes->onOneClosure, indx, val, len);
if ( fes->doMore ) {
char key[128];
char indx[128];
if ( splitFullKey( key, indx, fullKey ) ) {
if ( 0 == strcmp(key, fes->key) ) {
fes->doMore = (*fes->onOneProc)(fes->onOneClosure, indx);
}
}
}
}
@ -369,10 +369,11 @@ wasm_dutil_forEachIndx( XW_DUtilCtxt* duc, XWEnv xwe, const XP_UCHAR* key,
OnOneProc proc, void* closure )
{
ForEachStateKey fes = { .duc = duc,
.xwe = xwe,
.onOneProc = proc,
.onOneClosure = closure,
.key = key,
.xwe = xwe,
.onOneProc = proc,
.onOneClosure = closure,
.key = key,
.doMore = true,
};
call_for_each_key( withOneKey, &fes );
}
@ -440,6 +441,35 @@ wasm_dutil_md5sum( XW_DUtilCtxt* duc, XWEnv xwe, const XP_U8* ptr,
return NULL;
}
static const DictionaryCtxt*
wasm_dutil_getDict( XW_DUtilCtxt* duc, XWEnv xwe,
XP_LangCode lang, const XP_UCHAR* dictName )
{
XP_LOGFF( "(dictName: %s)", dictName );
char indx[64];
const char* lc = lcToLocale( lang );
formatDictIndx( indx, sizeof(indx), lc, dictName );
CAST_GLOB( Globals*, globals, duc->closure );
const DictionaryCtxt* result = dmgr_get( globals->dictMgr, xwe, indx );
if ( !result ) {
XP_U32 len = 0;
dutil_loadIndxPtr( duc, xwe, KEY_DICTS, indx, NULL, &len );
if ( 0 < len ) {
uint8_t* ptr = XP_MALLOC( duc->mpool, len );
dutil_loadIndxPtr( duc, xwe, KEY_DICTS, indx, ptr, &len );
result = wasm_dictionary_make( globals, xwe, dictName, ptr, len );
dmgr_put( globals->dictMgr, xwe, indx, result );
} else {
XP_LOGFF( "indx %s not found", indx );
}
}
LOG_RETURNF( "%p", result );
return result;
}
static void
wasm_dutil_notifyPause( XW_DUtilCtxt* XP_UNUSED(duc), XWEnv XP_UNUSED(xwe),
XP_U32 XP_UNUSED_DBG(gameID),
@ -517,6 +547,7 @@ wasm_dutil_make( MPFORMAL VTableMgr* vtMgr, void* closure )
SET_PROC(md5sum);
#endif
SET_PROC(getDict);
SET_PROC(notifyPause);
SET_PROC(onDupTimerChanged);
SET_PROC(onInviteReceived);

View file

@ -411,8 +411,10 @@ static DictionaryCtxt*
wasm_util_makeEmptyDict( XW_UtilCtxt* uc, XWEnv xwe )
{
LOG_FUNC(); /* firing */
return wasm_dictionary_make( MPPARM(uc->mpool) NULL, uc->closure,
NULL, false, NULL );
XP_ASSERT(0);
/* return wasm_dictionary_make( MPPARM(uc->mpool) NULL, uc->closure, */
/* NULL, false, NULL ); */
return NULL;
}
static void