From 7efc4b29bfd8433cb82c25f805ac9c6686a76edc Mon Sep 17 00:00:00 2001 From: Eric House Date: Tue, 9 Feb 2021 17:53:30 -0800 Subject: [PATCH] get mqtt working again --- xwords4/wasm/main.c | 22 +++++------ xwords4/wasm/shell_minimal.html | 66 +++++++++++++++++++++++++++++++-- xwords4/wasm/wasmdict.c | 6 +-- xwords4/wasm/wasmdraw.c | 4 -- 4 files changed, 77 insertions(+), 21 deletions(-) diff --git a/xwords4/wasm/main.c b/xwords4/wasm/main.c index 2431f41d9..ca3a554f7 100644 --- a/xwords4/wasm/main.c +++ b/xwords4/wasm/main.c @@ -59,8 +59,8 @@ EM_JS(bool, call_confirm, (const char* str), { EM_JS(void, call_alert, (const char* str), { alert(UTF8ToString(str)); }); -EM_JS(void, call_haveDevID, (const char* devid), { - onHaveDevID(UTF8ToString(devid)); +EM_JS(void, call_haveDevID, (void* closure, const char* devid), { + onHaveDevID(closure, UTF8ToString(devid)); }); EM_JS(void, call_mqttSend, (const char* topic, const uint8_t* ptr, int len), { @@ -135,7 +135,7 @@ initDeviceGlobals( Globals* globals ) XP_UCHAR buf[32]; XP_SNPRINTF( buf, VSIZE(buf), MQTTDevID_FMT, devID ); XP_LOGFF( "got mqtt devID: %s", buf ); - call_haveDevID( buf ); + call_haveDevID( globals, buf ); } static void @@ -157,9 +157,9 @@ startGame( Globals* globals ) } (void)server_do( globals->game.server, NULL ); /* assign tiles, etc. */ - /* if ( !!globals->game.comms ) { */ - /* comms_resendAll( globals->game.comms, NULL, COMMS_CONN_NONE, XP_TRUE ); */ - /* } */ + if ( !!globals->game.comms ) { + comms_resendAll( globals->game.comms, NULL, COMMS_CONN_MQTT, XP_TRUE ); + } updateScreen( globals ); LOG_RETURN_VOID(); @@ -184,7 +184,7 @@ makeAndDraw( Globals* globals, bool forceNew, bool p0robot, bool p1robot ) globals->gi.players[0].isLocal = XP_TRUE; globals->gi.players[0].robotIQ = p0robot ? 99 : 0; - globals->gi.players[1].name = copyString( globals->mpool, "Player 1" ); + globals->gi.players[1].name = copyString( globals->mpool, "Player 2" ); globals->gi.players[1].isLocal = XP_TRUE; globals->gi.players[1].robotIQ = p1robot ? 99 : 0; @@ -502,11 +502,11 @@ newgame(bool p0, bool p1) } void -gotMQTTMsg( int len, const uint8_t* msg ) +gotMQTTMsg( void* closure, int len, const uint8_t* msg ) { - XP_LOGFF( "got msg of len %d", len ); - - dvc_parseMQTTPacket( sGlobals->dutil, NULL, msg, len ); + XP_LOGFF( "got msg of len %d (%p vs %p)", len, closure, sGlobals ); + Globals* globals = (Globals*)closure; + dvc_parseMQTTPacket( globals->dutil, NULL, msg, len ); } int diff --git a/xwords4/wasm/shell_minimal.html b/xwords4/wasm/shell_minimal.html index 7ffd0f42e..f6cc258a4 100644 --- a/xwords4/wasm/shell_minimal.html +++ b/xwords4/wasm/shell_minimal.html @@ -7,6 +7,7 @@ - +
emscripten
Downloading...
@@ -176,6 +177,10 @@ }; {{{ SCRIPT }}} diff --git a/xwords4/wasm/wasmdict.c b/xwords4/wasm/wasmdict.c index c51918404..1ef15a209 100644 --- a/xwords4/wasm/wasmdict.c +++ b/xwords4/wasm/wasmdict.c @@ -249,9 +249,9 @@ dict_splitFaces( DictionaryCtxt* dict, XWEnv xwe, const XP_U8* utf8, XP_ASSERT( !dict->facePtrs ); dict->facePtrs = ptrs; - for ( int ii = 0; ii < nFaces; ++ii ) { - XP_LOGFF( "face %d: %s", ii, dict->facePtrs[ii] ); - } + /* for ( int ii = 0; ii < nFaces; ++ii ) { */ + /* XP_LOGFF( "face %d: %s", ii, dict->facePtrs[ii] ); */ + /* } */ } /* dict_splitFaces */ void diff --git a/xwords4/wasm/wasmdraw.c b/xwords4/wasm/wasmdraw.c index b9977dc81..281ddec2a 100644 --- a/xwords4/wasm/wasmdraw.c +++ b/xwords4/wasm/wasmdraw.c @@ -359,11 +359,7 @@ drawCrosshairs( WasmDrawCtx* wdctx, const XP_Rect* rect, CellFlags flags ) const SDL_Color* color = &sOtherColors[COLOR_FOCUS]; if ( 0 != (flags & CELL_CROSSHOR) ) { XP_Rect hairRect = *rect; - XP_LOGFF( "hairRect before: l: %d, t: %d, w: %d, h: %d", - hairRect.left, hairRect.top, hairRect.width, hairRect.height ); insetRect( &hairRect, 0, hairRect.height / 3 ); - XP_LOGFF( "hairRect after: l: %d, t: %d, w: %d, h: %d", - hairRect.left, hairRect.top, hairRect.width, hairRect.height ); fillRect( wdctx, &hairRect, color ); } if ( 0 != (flags & CELL_CROSSVERT) ) {