mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-07 05:24:46 +01:00
use native js for idle (timers next)
This commit is contained in:
parent
40e72f8b29
commit
1813552b5e
2 changed files with 42 additions and 4 deletions
|
@ -48,7 +48,7 @@ main.html: ${INPUTS} $(MAKEFILE) shell_minimal.html
|
||||||
--preload-file assets_dir --shell-file shell_minimal.html \
|
--preload-file assets_dir --shell-file shell_minimal.html \
|
||||||
-s USE_SDL_TTF=2 -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS='["png"]' \
|
-s USE_SDL_TTF=2 -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS='["png"]' \
|
||||||
-s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall']" \
|
-s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall']" \
|
||||||
-s EXPORTED_FUNCTIONS='["_main", "_button", "_newgame", "_gotMQTTMsg"]' -s WASM=0 \
|
-s EXPORTED_FUNCTIONS='["_main", "_button", "_newgame", "_gotMQTTMsg", "_jscallback"]' \
|
||||||
-s WASM=1 \
|
-s WASM=1 \
|
||||||
${INPUTS} -o $@
|
${INPUTS} -o $@
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,15 @@ EM_JS(bool, call_mqttSend, (const char* topic, const uint8_t* ptr, int len), {
|
||||||
return mqttSend(topStr, buffer);
|
return mqttSend(topStr, buffer);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
typedef void (*JSCallback)(void* closure);
|
||||||
|
|
||||||
|
EM_JS(void, jscallback_set, (JSCallback proc, void* closure, int inMS), {
|
||||||
|
let timerproc = function(closure) {
|
||||||
|
ccall('jscallback', null, ['number', 'number'], [proc, closure]);
|
||||||
|
};
|
||||||
|
setTimeout( timerproc, inMS, closure );
|
||||||
|
});
|
||||||
|
|
||||||
static void updateScreen( Globals* globals, bool doSave );
|
static void updateScreen( Globals* globals, bool doSave );
|
||||||
|
|
||||||
static Globals* sGlobals;
|
static Globals* sGlobals;
|
||||||
|
@ -388,12 +397,34 @@ main_alert( Globals* globals, const XP_UCHAR* msg )
|
||||||
call_alert( msg );
|
call_alert( msg );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct _IdleClosure {
|
||||||
|
Globals* globals;
|
||||||
|
IdleProc proc;
|
||||||
|
void* closure;
|
||||||
|
} IdleClosure;
|
||||||
|
|
||||||
|
static void
|
||||||
|
onIdleFired( void* closure )
|
||||||
|
{
|
||||||
|
LOG_FUNC();
|
||||||
|
IdleClosure* ic = (IdleClosure*)closure;
|
||||||
|
XP_Bool draw = (*ic->proc)(ic->closure);
|
||||||
|
if ( draw ) {
|
||||||
|
updateScreen( ic->globals, true );
|
||||||
|
}
|
||||||
|
XP_FREE( ic->globals->mpool, ic );
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
main_set_idle( Globals* globals, IdleProc proc, void* closure )
|
main_set_idle( Globals* globals, IdleProc proc, void* closure )
|
||||||
{
|
{
|
||||||
XP_ASSERT( !globals->idleProc || globals->idleProc == proc );
|
LOG_FUNC();
|
||||||
globals->idleProc = proc;
|
IdleClosure* ic = XP_MALLOC( globals->mpool, sizeof(*ic) );
|
||||||
globals->idleClosure = closure;
|
ic->globals = globals;
|
||||||
|
ic->proc = proc;
|
||||||
|
ic->closure = closure;
|
||||||
|
|
||||||
|
jscallback_set( onIdleFired, ic, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
static XP_Bool
|
static XP_Bool
|
||||||
|
@ -615,6 +646,13 @@ gotMQTTMsg( void* closure, int len, const uint8_t* msg )
|
||||||
dvc_parseMQTTPacket( globals->dutil, NULL, msg, len );
|
dvc_parseMQTTPacket( globals->dutil, NULL, msg, len );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
jscallback( JSCallback proc, void* closure )
|
||||||
|
{
|
||||||
|
LOG_FUNC();
|
||||||
|
(*proc)(closure);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main( int argc, const char** argv )
|
main( int argc, const char** argv )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue