This commit is contained in:
Eric House 2021-03-05 12:04:07 -08:00
parent 567c3dbf9e
commit 39be910b13
5 changed files with 50 additions and 19 deletions

View file

@ -110,8 +110,6 @@ static void saveName( GameState* gs );
static bool isVisible( GameState* gs );
static int countDicts( Globals* globals );
typedef void (*BinProc)(void* closure, const uint8_t* data, int len );
EM_JS(void, call_get_dict, (void* closure), {
getDict(closure);
});
@ -159,7 +157,6 @@ EM_JS(void, call_pickGame, (const char* msg, char** ids, char** names,
const namesMem = HEAP32[(names + (ii * 4)) >> 2];
let id = UTF8ToString(idsMem);
map[id] = UTF8ToString(namesMem);
console.log('added ' + id + ' -> ' + map[id]);
}
nbGamePick(UTF8ToString(msg), map, proc, closure);
@ -216,11 +213,9 @@ EM_JS(void, callNewGame, (const char* msg, void* closure), {
nbGetNewGame(closure, jsmsg);
});
typedef void (*ConfirmProc)( void* closure, bool confirmed );
typedef struct _ConfirmState {
Globals* globals;
ConfirmProc proc;
BoolProc proc;
void* closure;
} ConfirmState;
@ -235,7 +230,7 @@ onConfirmed( void* closure, const char* button )
static void
call_confirm( Globals* globals, const char* msg,
ConfirmProc proc, void* closure )
BoolProc proc, void* closure )
{
const char* buttons[] = { BUTTON_CANCEL, BUTTON_OK, NULL };
ConfirmState* cs = XP_MALLOC( globals->mpool, sizeof(*cs) );
@ -1497,6 +1492,8 @@ looper( void* closure )
updateScreen( gs, true );
}
}
wasm_dutil_syncIf( globals->dutil );
#ifdef MEM_DEBUG
if ( mpool_getStats( globals->mpool, &globals->mpstats ) ) {
show_pool(globals->mpstats.curBytes, globals->mpstats.maxBytes);

View file

@ -34,6 +34,8 @@ typedef struct _TimerState {
} TimerState;
typedef XP_Bool (*IdleProc)(void* closure);
typedef void (*BinProc)(void* closure, const uint8_t* data, int len );
typedef void (*BoolProc)(void* closure, bool result);
typedef struct GameState {
#ifdef DEBUG

View file

@ -373,9 +373,16 @@ wasm_draw_drawRemText( DrawCtx* dctx, XWEnv xwe, const XP_Rect* rInner,
}
static void
formatScoreText(XP_UCHAR* out, int outLen, const XP_UCHAR* name, int score )
formatScoreText(XP_UCHAR* out, int outLen, const DrawScoreInfo* dsi )
{
XP_SNPRINTF( out, outLen, "%s: %d", name, score );
const char* name = dsi->name;
int score = dsi->totalScore;
int offset = XP_SNPRINTF( out, outLen, "%s:%d", name, score );
int nTilesLeft = dsi->nTilesLeft;
if ( (nTilesLeft < MAX_TRAY_TILES) && (nTilesLeft > 0) ) {
XP_SNPRINTF( out + offset, outLen-offset, ":%d", nTilesLeft );
}
}
static void
@ -386,7 +393,8 @@ wasm_draw_measureScoreText( DrawCtx* dctx, XWEnv xwe,
{
WasmDrawCtx* wdctx = (WasmDrawCtx*)dctx;
XP_UCHAR buf[32];
formatScoreText( buf, sizeof(buf), dsi->name, dsi->totalScore );
formatScoreText( buf, sizeof(buf), dsi );
int fontHeight = rect->height;
if ( !dsi->isTurn ) {
@ -408,7 +416,7 @@ wasm_draw_score_drawPlayer( DrawCtx* dctx, XWEnv xwe,
{
WasmDrawCtx* wdctx = (WasmDrawCtx*)dctx;
XP_UCHAR buf[32];
formatScoreText( buf, sizeof(buf), dsi->name, dsi->totalScore );
formatScoreText( buf, sizeof(buf), dsi );
textInRect( wdctx, buf, rInner, &sPlayerColors[dsi->playerNum] );
}

View file

@ -38,15 +38,16 @@
typedef struct _WasmDUtilCtxt {
XW_DUtilCtxt super;
int dirtyCount;
} WasmDUtilCtxt;
EM_JS( void, fsSyncOut, (), {
EM_JS( void, fsSyncOut, (StringProc proc, void* closure), {
FS.syncfs(false, function (err) {
// assert(!err);
if ( err ) {
console.log('sync err: ' + err);
} else {
console.log('sync succeeded');
console.log('sync done: ' + err);
if ( proc ) {
let str = !err ? "success" : err.toString();
ccall('cbckString', null, ['number', 'number', 'string'],
[proc, closure, str]);
}
});
});
@ -264,7 +265,7 @@ wasm_dutil_storePtr( XW_DUtilCtxt* duc, XWEnv xwe,
// XP_LOGFF( "wrote %d bytes to path %s", nWritten, path );
XP_ASSERT( nWritten == len );
fsSyncOut();
++((WasmDUtilCtxt*)duc)->dirtyCount;
LOG_RETURN_VOID();
}
@ -382,7 +383,7 @@ wasm_dutil_remove( XW_DUtilCtxt* duc, const XP_UCHAR* keys[] )
XP_LOGFF( "(path: %s)", path );
deleteAll(path);
fsSyncOut();
++((WasmDUtilCtxt*)duc)->dirtyCount;
}
#ifdef XWFEATURE_DEVID
@ -480,6 +481,28 @@ wasm_dutil_onGameGoneReceived( XW_DUtilCtxt* duc, XWEnv XP_UNUSED(xwe),
main_onGameGone( globals, gameID );
}
static void
onSynced(void* closure, const char* str)
{
XW_DUtilCtxt* duc = (XW_DUtilCtxt*)closure;
XP_LOGFF( "(str: %s)", str );
if ( 0 == strcmp( "success", str ) ) {
WasmDUtilCtxt* wduc = (WasmDUtilCtxt*)closure;
wduc->dirtyCount = 0;
}
}
void
wasm_dutil_syncIf( XW_DUtilCtxt* duc )
{
WasmDUtilCtxt* wduc = (WasmDUtilCtxt*)duc;
if ( 0 < wduc->dirtyCount ) {
wduc->dirtyCount = 0;
StringProc proc = NULL; // onSynced;
fsSyncOut(proc, duc);
}
}
XW_DUtilCtxt*
wasm_dutil_make( MPFORMAL VTableMgr* vtMgr, void* closure )
{

View file

@ -26,6 +26,7 @@
#include "mempool.h"
XW_DUtilCtxt* wasm_dutil_make( MPFORMAL VTableMgr* vtMgr, void* closure );
void wasm_dutil_syncIf( XW_DUtilCtxt* duc );
void wasm_dutil_destroy( XW_DUtilCtxt* dutil );
#endif