mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-30 10:26:58 +01:00
move TransportProcs into cGlobals to fix gtk crash
This commit is contained in:
parent
47ea296c39
commit
1e447e9d60
6 changed files with 40 additions and 49 deletions
|
@ -52,8 +52,6 @@ struct CursesBoardGlobals {
|
|||
CursesMenuState* menuState; /* null if we're not using menus */
|
||||
int refCount;
|
||||
|
||||
TransportProcs procs;
|
||||
|
||||
union {
|
||||
struct {
|
||||
XWStreamCtxt* stream; /* how we can reach the server */
|
||||
|
@ -224,7 +222,7 @@ cb_newFor( CursesBoardState* cbState, const NetLaunchInfo* nli,
|
|||
initCP( cGlobals );
|
||||
if ( game_makeFromInvite( &cGlobals->game, NULL_XWE, nli, &selfAddr,
|
||||
cGlobals->util, (DrawCtx*)NULL,
|
||||
&cGlobals->cp, &bGlobals->procs ) ) {
|
||||
&cGlobals->cp, &cGlobals->procs ) ) {
|
||||
linuxSaveGame( cGlobals );
|
||||
} else {
|
||||
XP_ASSERT( 0 );
|
||||
|
@ -363,6 +361,30 @@ curses_socket_acceptor( int listener, Acceptor func, CommonGlobals* cGlobals,
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
initTProcsCurses( CommonGlobals* cGlobals )
|
||||
{
|
||||
cGlobals->procs.closure = cGlobals;
|
||||
cGlobals->procs.sendMsg = linux_send;
|
||||
#ifdef XWFEATURE_COMMS_INVITE
|
||||
cGlobals->procs.sendInvt = linux_send_invt;
|
||||
#endif
|
||||
#ifdef COMMS_HEARTBEAT
|
||||
cGlobals->procs.reset = linux_reset;
|
||||
#endif
|
||||
#ifdef XWFEATURE_RELAY
|
||||
cGlobals->procs.rstatus = relay_status_curses;
|
||||
cGlobals->procs.rconnd = relay_connd_curses;
|
||||
cGlobals->procs.rerror = relay_error_curses;
|
||||
cGlobals->procs.sendNoConn = relay_sendNoConn_curses;
|
||||
#endif
|
||||
cGlobals->procs.countChanged = curses_countChanged;
|
||||
cGlobals->procs.getFlags = curses_getFlags;
|
||||
# ifdef RELAY_VIA_HTTP
|
||||
cGlobals->procs.requestJoin = relay_requestJoin_curses;
|
||||
#endif
|
||||
}
|
||||
|
||||
static CursesBoardGlobals*
|
||||
commonInit( CursesBoardState* cbState, sqlite3_int64 rowid,
|
||||
const CurGameInfo* gip )
|
||||
|
@ -386,26 +408,7 @@ commonInit( CursesBoardState* cbState, sqlite3_int64 rowid,
|
|||
cGlobals->onSaveClosure = bGlobals;
|
||||
cGlobals->addAcceptor = curses_socket_acceptor;
|
||||
|
||||
bGlobals->procs.closure = cGlobals;
|
||||
bGlobals->procs.sendMsg = linux_send;
|
||||
#ifdef XWFEATURE_COMMS_INVITE
|
||||
bGlobals->procs.sendInvt = linux_send_invt;
|
||||
#endif
|
||||
#ifdef COMMS_HEARTBEAT
|
||||
bGlobals->procs.reset = linux_reset;
|
||||
#endif
|
||||
#ifdef XWFEATURE_RELAY
|
||||
bGlobals->procs.rstatus = relay_status_curses;
|
||||
bGlobals->procs.rconnd = relay_connd_curses;
|
||||
bGlobals->procs.rerror = relay_error_curses;
|
||||
bGlobals->procs.sendNoConn = relay_sendNoConn_curses;
|
||||
#endif
|
||||
bGlobals->procs.countChanged = curses_countChanged;
|
||||
bGlobals->procs.getFlags = curses_getFlags;
|
||||
# ifdef RELAY_VIA_HTTP
|
||||
bGlobals->procs.requestJoin = relay_requestJoin_curses;
|
||||
#endif
|
||||
|
||||
initTProcsCurses( cGlobals );
|
||||
makeSelfAddress( &cGlobals->selfAddr, params );
|
||||
|
||||
setOneSecondTimer( cGlobals );
|
||||
|
@ -566,7 +569,7 @@ initNoDraw( CursesBoardState* cbState, sqlite3_int64 rowid,
|
|||
|
||||
initCP( cGlobals );
|
||||
|
||||
if ( linuxOpenGame( cGlobals, &result->procs ) ) {
|
||||
if ( linuxOpenGame( cGlobals ) ) {
|
||||
result = ref( result );
|
||||
} else {
|
||||
disposeBoard( result );
|
||||
|
|
|
@ -486,6 +486,7 @@ countChanged_gtk( XWEnv XP_UNUSED(xwe), void* closure, XP_U16 newCount )
|
|||
static void
|
||||
setTransportProcs( TransportProcs* procs, GtkGameGlobals* globals )
|
||||
{
|
||||
XP_ASSERT( !procs->closure );
|
||||
procs->closure = globals;
|
||||
procs->sendMsg = linux_send;
|
||||
#ifdef XWFEATURE_COMMS_INVITE
|
||||
|
@ -618,10 +619,7 @@ createOrLoadObjects( GtkGameGlobals* globals )
|
|||
cGlobals->draw = gtkDrawCtxtMake( globals->drawing_area,
|
||||
globals );
|
||||
|
||||
TransportProcs procs;
|
||||
setTransportProcs( &procs, globals );
|
||||
|
||||
if ( linuxOpenGame( cGlobals, &procs ) ) {
|
||||
if ( linuxOpenGame( cGlobals ) ) {
|
||||
if ( !params->fileName && !!params->dbName ) {
|
||||
XP_UCHAR buf[64];
|
||||
snprintf( buf, sizeof(buf), "%s / %lld", params->dbName,
|
||||
|
@ -843,20 +841,10 @@ new_game_impl( GtkGameGlobals* globals, XP_Bool fireConnDlg )
|
|||
if ( success ) {
|
||||
XP_Bool isClient = gi->serverRole == SERVER_ISCLIENT;
|
||||
XP_ASSERT( !isClient ); /* Doesn't make sense! Send invitation. */
|
||||
TransportProcs procs = {
|
||||
.closure = globals,
|
||||
.sendMsg = linux_send,
|
||||
#ifdef XWFEATURE_COMMS_INVITE
|
||||
.sendInvt = linux_send_invt,
|
||||
#endif
|
||||
#ifdef COMMS_HEARTBEAT
|
||||
.reset = linux_reset,
|
||||
#endif
|
||||
};
|
||||
|
||||
(void)game_reset( MEMPOOL &cGlobals->game, NULL_XWE, gi,
|
||||
&cGlobals->selfAddr, NULL, cGlobals->util,
|
||||
&cGlobals->cp, &procs );
|
||||
&cGlobals->cp, &cGlobals->procs );
|
||||
|
||||
(void)server_do( cGlobals->game.server, NULL_XWE ); /* assign tiles, etc. */
|
||||
board_invalAll( cGlobals->game.board );
|
||||
|
@ -2426,6 +2414,8 @@ initGlobalsNoDraw( GtkGameGlobals* globals, LaunchParams* params,
|
|||
memset( globals, 0, sizeof(*globals) );
|
||||
|
||||
CommonGlobals* cGlobals = &globals->cGlobals;
|
||||
setTransportProcs( &cGlobals->procs, globals );
|
||||
|
||||
cGlobals->gi = &cGlobals->_gi;
|
||||
if ( !gi ) {
|
||||
gi = ¶ms->pgi;
|
||||
|
@ -2667,9 +2657,6 @@ loadGameNoDraw( GtkGameGlobals* globals, LaunchParams* params,
|
|||
sqlite3* pDb = params->pDb;
|
||||
initGlobalsNoDraw( globals, params, NULL );
|
||||
|
||||
TransportProcs procs;
|
||||
setTransportProcs( &procs, globals );
|
||||
|
||||
CommonGlobals* cGlobals = &globals->cGlobals;
|
||||
cGlobals->rowid = rowid;
|
||||
XWStreamCtxt* stream = mem_stream_make_raw( MPPARM(cGlobals->util->mpool)
|
||||
|
@ -2678,7 +2665,8 @@ loadGameNoDraw( GtkGameGlobals* globals, LaunchParams* params,
|
|||
if ( loaded ) {
|
||||
loaded = game_makeFromStream( MEMPOOL NULL_XWE, stream, &cGlobals->game,
|
||||
cGlobals->gi,
|
||||
cGlobals->util, (DrawCtx*)NULL, &cGlobals->cp, &procs );
|
||||
cGlobals->util, (DrawCtx*)NULL,
|
||||
&cGlobals->cp, &cGlobals->procs );
|
||||
if ( loaded ) {
|
||||
XP_LOGF( "%s: game loaded", __func__ );
|
||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||
|
|
|
@ -719,10 +719,9 @@ gameFromInvite( GtkAppGlobals* apg, const NetLaunchInfo* nli )
|
|||
makeSelfAddress( &selfAddr, params );
|
||||
|
||||
CommonPrefs* cp = &cGlobals->cp;
|
||||
TransportProcs* procs = NULL;
|
||||
game_makeFromInvite( &cGlobals->game, NULL_XWE, nli,
|
||||
&selfAddr, cGlobals->util, cGlobals->draw,
|
||||
cp, procs );
|
||||
cp, &cGlobals->procs );
|
||||
|
||||
linuxSaveGame( cGlobals );
|
||||
sqlite3_int64 rowid = cGlobals->rowid;
|
||||
|
|
|
@ -160,7 +160,7 @@ send_msgs_idle( gpointer data )
|
|||
}
|
||||
|
||||
bool
|
||||
linuxOpenGame( CommonGlobals* cGlobals, const TransportProcs* procs )
|
||||
linuxOpenGame( CommonGlobals* cGlobals )
|
||||
{
|
||||
XWStreamCtxt* stream = NULL;
|
||||
XP_Bool opened = XP_FALSE;
|
||||
|
@ -189,7 +189,7 @@ linuxOpenGame( CommonGlobals* cGlobals, const TransportProcs* procs )
|
|||
opened = game_makeFromStream( MEMPOOL NULL_XWE, stream, &cGlobals->game,
|
||||
cGlobals->gi,
|
||||
cGlobals->util, cGlobals->draw,
|
||||
&cGlobals->cp, procs );
|
||||
&cGlobals->cp, &cGlobals->procs );
|
||||
XP_LOGFF( "loaded gi at %p", &cGlobals->gi );
|
||||
stream_destroy( stream, NULL_XWE );
|
||||
}
|
||||
|
@ -202,7 +202,7 @@ linuxOpenGame( CommonGlobals* cGlobals, const TransportProcs* procs )
|
|||
}
|
||||
game_makeNewGame( MEMPOOL NULL_XWE, &cGlobals->game, cGlobals->gi,
|
||||
&cGlobals->selfAddr, hostAddr, cGlobals->util,
|
||||
cGlobals->draw, &cGlobals->cp, procs
|
||||
cGlobals->draw, &cGlobals->cp, &cGlobals->procs
|
||||
#ifdef SET_GAMESEED
|
||||
, params->gameSeed
|
||||
#endif
|
||||
|
|
|
@ -114,7 +114,7 @@ XP_Bool parseSMSParams( LaunchParams* params, gchar** myPhone, XP_U16* myPort );
|
|||
void makeSelfAddress( CommsAddrRec* selfAddr, const LaunchParams* params );
|
||||
|
||||
unsigned int makeRandomInt();
|
||||
bool linuxOpenGame( CommonGlobals* cGlobals, const TransportProcs* procs );
|
||||
bool linuxOpenGame( CommonGlobals* cGlobals );
|
||||
void tryConnectToServer( CommonGlobals* cGlobals );
|
||||
void ensureLocalPlayerNames( LaunchParams* params, CurGameInfo* gi );
|
||||
void cancelTimers( CommonGlobals* cGlobals );
|
||||
|
|
|
@ -224,6 +224,7 @@ typedef void (*OnSaveFunc)( void* closure, sqlite3_int64 rowid,
|
|||
struct CommonGlobals {
|
||||
CurGameInfo _gi;
|
||||
LaunchParams* params;
|
||||
TransportProcs procs;
|
||||
CommonPrefs cp;
|
||||
XW_UtilCtxt* util;
|
||||
|
||||
|
|
Loading…
Reference in a new issue