mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-11 08:48:06 +01:00
cleanup (and get rid of constant JS error)
This commit is contained in:
parent
430b6894f0
commit
c859caae8d
3 changed files with 62 additions and 60 deletions
|
@ -56,7 +56,7 @@
|
||||||
#define WASM_HOR_SCORE_TOP 0
|
#define WASM_HOR_SCORE_TOP 0
|
||||||
|
|
||||||
#define WINDOW_WIDTH 400
|
#define WINDOW_WIDTH 400
|
||||||
#define WINDOW_HEIGHT 600
|
#define WINDOW_HEIGHT 520
|
||||||
#define BDWIDTH WINDOW_WIDTH
|
#define BDWIDTH WINDOW_WIDTH
|
||||||
#define BDHEIGHT WINDOW_HEIGHT
|
#define BDHEIGHT WINDOW_HEIGHT
|
||||||
|
|
||||||
|
@ -90,6 +90,9 @@
|
||||||
#define BUTTON_NAME "My Name"
|
#define BUTTON_NAME "My Name"
|
||||||
#define MAX_BUTTONS 20 /* not sure what's safe here */
|
#define MAX_BUTTONS 20 /* not sure what's safe here */
|
||||||
|
|
||||||
|
// I get a JS exception if I do this... So don't
|
||||||
|
// #define GLOBALS_ON_STACK
|
||||||
|
|
||||||
typedef struct _NewGameParams {
|
typedef struct _NewGameParams {
|
||||||
bool isRobotNotRemote;
|
bool isRobotNotRemote;
|
||||||
bool hintsNotAllowed;
|
bool hintsNotAllowed;
|
||||||
|
@ -1700,58 +1703,6 @@ inviteFromArgv( Globals* globals, NetLaunchInfo* nlip,
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
initNoReturn( int argc, const char** argv )
|
|
||||||
{
|
|
||||||
time_t now = getCurMS();
|
|
||||||
srandom( now );
|
|
||||||
XP_LOGFF( "called(srandom( %x )", now );
|
|
||||||
|
|
||||||
Globals globals = {0}; // calloc(1, sizeof(*globals));
|
|
||||||
#ifdef DEBUG
|
|
||||||
globals._GUARD = GUARD_GLOB;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
NetLaunchInfo nli = {0};
|
|
||||||
NetLaunchInfo* nlip = NULL;
|
|
||||||
if ( inviteFromArgv( &globals, &nli, argc, argv ) ) {
|
|
||||||
nlip = &nli;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Init( SDL_INIT_EVENTS );
|
|
||||||
TTF_Init();
|
|
||||||
|
|
||||||
SDL_CreateWindowAndRenderer( WINDOW_WIDTH, WINDOW_HEIGHT, 0,
|
|
||||||
&globals.window, &globals.renderer );
|
|
||||||
|
|
||||||
/* wipe the canvas to background */
|
|
||||||
SDL_SetRenderDrawColor( globals.renderer, 155, 155, 155, 255 );
|
|
||||||
SDL_RenderClear( globals.renderer );
|
|
||||||
|
|
||||||
initDeviceGlobals( &globals );
|
|
||||||
|
|
||||||
char lastKey[16] = {0};
|
|
||||||
int gameID = 0;
|
|
||||||
XP_U32 len = sizeof(gameID);
|
|
||||||
const XP_UCHAR* keys[] = {KEY_LAST_GID, NULL};
|
|
||||||
dutil_loadPtr( globals.dutil, NULL, keys, (XP_U8*)&gameID, &len );
|
|
||||||
if ( len == sizeof(gameID) ) {
|
|
||||||
formatGameID( lastKey, sizeof(lastKey), gameID );
|
|
||||||
}
|
|
||||||
XP_LOGFF( "loaded KEY_LAST_GID: %s", lastKey );
|
|
||||||
loadAndDraw( &globals, nlip, lastKey, NULL );
|
|
||||||
|
|
||||||
updateDeviceButtons( &globals );
|
|
||||||
|
|
||||||
#if 1
|
|
||||||
emscripten_set_main_loop_arg( looper, &globals, -1, 1 );
|
|
||||||
#else
|
|
||||||
/* crashes on button press, touching board, etc. if I do this, but hasn't
|
|
||||||
always */
|
|
||||||
emscripten_set_main_loop_arg( looper, &globals, -1, 0 );
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MQTTConnectedChanged( void* closure, bool connected )
|
MQTTConnectedChanged( void* closure, bool connected )
|
||||||
{
|
{
|
||||||
|
@ -1813,7 +1764,56 @@ void
|
||||||
mainPostSync( int argc, const char** argv )
|
mainPostSync( int argc, const char** argv )
|
||||||
{
|
{
|
||||||
XP_LOGFF( "(argc=%d)", argc );
|
XP_LOGFF( "(argc=%d)", argc );
|
||||||
initNoReturn( argc, argv );
|
time_t now = getCurMS();
|
||||||
|
srandom( now );
|
||||||
|
XP_LOGFF( "called(srandom( %x )", now );
|
||||||
|
|
||||||
|
#ifdef GLOBALS_ON_STACK
|
||||||
|
Globals _globals = {0};
|
||||||
|
Globals* globals = &_globals;
|
||||||
|
#else
|
||||||
|
Globals* globals = calloc(1, sizeof(*globals));
|
||||||
|
#endif
|
||||||
|
#ifdef DEBUG
|
||||||
|
globals->_GUARD = GUARD_GLOB;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
NetLaunchInfo nli = {0};
|
||||||
|
NetLaunchInfo* nlip = NULL;
|
||||||
|
if ( inviteFromArgv( globals, &nli, argc, argv ) ) {
|
||||||
|
nlip = &nli;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Init( SDL_INIT_EVENTS );
|
||||||
|
TTF_Init();
|
||||||
|
|
||||||
|
SDL_CreateWindowAndRenderer( WINDOW_WIDTH, WINDOW_HEIGHT, 0,
|
||||||
|
&globals->window, &globals->renderer );
|
||||||
|
|
||||||
|
/* wipe the canvas to background */
|
||||||
|
SDL_SetRenderDrawColor( globals->renderer, 155, 155, 155, 255 );
|
||||||
|
SDL_RenderClear( globals->renderer );
|
||||||
|
|
||||||
|
initDeviceGlobals( globals );
|
||||||
|
|
||||||
|
char lastKey[16] = {0};
|
||||||
|
int gameID = 0;
|
||||||
|
XP_U32 len = sizeof(gameID);
|
||||||
|
const XP_UCHAR* keys[] = {KEY_LAST_GID, NULL};
|
||||||
|
dutil_loadPtr( globals->dutil, NULL, keys, (XP_U8*)&gameID, &len );
|
||||||
|
if ( len == sizeof(gameID) ) {
|
||||||
|
formatGameID( lastKey, sizeof(lastKey), gameID );
|
||||||
|
}
|
||||||
|
XP_LOGFF( "loaded KEY_LAST_GID: %s", lastKey );
|
||||||
|
loadAndDraw( globals, nlip, lastKey, NULL );
|
||||||
|
|
||||||
|
updateDeviceButtons( globals );
|
||||||
|
|
||||||
|
#ifdef GLOBALS_ON_STACK
|
||||||
|
emscripten_set_main_loop_arg( looper, globals, -1, 1 );
|
||||||
|
#else
|
||||||
|
emscripten_set_main_loop_arg( looper, globals, -1, 0 );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
EM_JS( void, loadDBThen, (const char* root, int argc, const char** argv), {
|
EM_JS( void, loadDBThen, (const char* root, int argc, const char** argv), {
|
||||||
|
@ -1831,7 +1831,7 @@ EM_JS( void, loadDBThen, (const char* root, int argc, const char** argv), {
|
||||||
int
|
int
|
||||||
main( int argc, const char** argv )
|
main( int argc, const char** argv )
|
||||||
{
|
{
|
||||||
XP_LOGFF( "(argc=%d)", argc );
|
XP_LOGFF( "MAIN ENTRY(argc=%d)", argc );
|
||||||
loadDBThen( ROOT_PATH, argc, argv );
|
loadDBThen( ROOT_PATH, argc, argv );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -354,8 +354,8 @@ wasm_draw_measureRemText( DrawCtx* dctx, XWEnv xwe, const XP_Rect* rect,
|
||||||
|
|
||||||
WasmDrawCtx* wdctx = (WasmDrawCtx*)dctx;
|
WasmDrawCtx* wdctx = (WasmDrawCtx*)dctx;
|
||||||
int width, height;
|
int width, height;
|
||||||
measureText( wdctx, buf, rect->height, &width, &height );
|
measureText( wdctx, buf, rect->height/2, &width, &height );
|
||||||
*widthP = XP_MIN( width, rect->width );
|
*widthP = XP_MIN( width * 5 / 3, rect->width );
|
||||||
*heightP = XP_MIN( height, rect->height );
|
*heightP = XP_MIN( height, rect->height );
|
||||||
}
|
}
|
||||||
return drawIt;
|
return drawIt;
|
||||||
|
@ -369,7 +369,8 @@ wasm_draw_drawRemText( DrawCtx* dctx, XWEnv xwe, const XP_Rect* rInner,
|
||||||
WasmDrawCtx* wdctx = (WasmDrawCtx*)dctx;
|
WasmDrawCtx* wdctx = (WasmDrawCtx*)dctx;
|
||||||
XP_UCHAR buf[4];
|
XP_UCHAR buf[4];
|
||||||
XP_SNPRINTF( buf, VSIZE(buf), "%d", nTilesLeft );
|
XP_SNPRINTF( buf, VSIZE(buf), "%d", nTilesLeft );
|
||||||
textInRect( wdctx, buf, rInner, NULL );
|
fillRect( wdctx, rOuter, &sOtherColors[BLACK] );
|
||||||
|
textInRect( wdctx, buf, rInner, &sOtherColors[WHITE] );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -43,7 +43,9 @@ typedef struct _WasmDUtilCtxt {
|
||||||
|
|
||||||
EM_JS( void, fsSyncOut, (StringProc proc, void* closure), {
|
EM_JS( void, fsSyncOut, (StringProc proc, void* closure), {
|
||||||
FS.syncfs(false, function (err) {
|
FS.syncfs(false, function (err) {
|
||||||
|
if ( err ) {
|
||||||
console.log('sync done: ' + err);
|
console.log('sync done: ' + err);
|
||||||
|
}
|
||||||
if ( proc ) {
|
if ( proc ) {
|
||||||
let str = !err ? "success" : err.toString();
|
let str = !err ? "success" : err.toString();
|
||||||
ccall('cbckString', null, ['number', 'number', 'string'],
|
ccall('cbckString', null, ['number', 'number', 'string'],
|
||||||
|
@ -266,7 +268,6 @@ wasm_dutil_storePtr( XW_DUtilCtxt* duc, XWEnv xwe,
|
||||||
XP_ASSERT( nWritten == len );
|
XP_ASSERT( nWritten == len );
|
||||||
|
|
||||||
++((WasmDUtilCtxt*)duc)->dirtyCount;
|
++((WasmDUtilCtxt*)duc)->dirtyCount;
|
||||||
LOG_RETURN_VOID();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Add table
Reference in a new issue