mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-26 07:58:52 +01:00
add new periodic (one-second) timer, and commandline option that sets
what percent of the times that timer fires will result in a move being undone. Will be used to interject random out-of-order undos into games played for testing. (Currently the tests fail when this is enabled; I need to fix that.)
This commit is contained in:
parent
2db02f9aa5
commit
cd89885cd2
5 changed files with 55 additions and 1 deletions
|
@ -1734,6 +1734,7 @@ cursesmain( XP_Bool isServer, LaunchParams* params )
|
|||
|
||||
#ifdef USE_GLIBLOOP
|
||||
cursesListenOnSocket( &g_globals, 0, handle_stdin );
|
||||
setOneSecondTimer( &g_globals.cGlobals );
|
||||
#else
|
||||
cursesListenOnSocket( &g_globals, 0 ); /* stdin */
|
||||
|
||||
|
@ -1764,7 +1765,6 @@ cursesmain( XP_Bool isServer, LaunchParams* params )
|
|||
#endif
|
||||
};
|
||||
|
||||
|
||||
if ( !!params->pipe && !!params->fileName ) {
|
||||
read_pipe_then_close( &g_globals.cGlobals, &procs );
|
||||
} else if ( !!params->nbs && !!params->fileName ) {
|
||||
|
|
|
@ -2388,6 +2388,8 @@ gtkmain( LaunchParams* params, int argc, char *argv[] )
|
|||
g_signal_connect( GTK_OBJECT(drawing_area), "button_release_event",
|
||||
G_CALLBACK(button_release_event), &globals );
|
||||
|
||||
setOneSecondTimer( &globals.cGlobals );
|
||||
|
||||
#ifdef KEY_SUPPORT
|
||||
# ifdef KEYBOARD_NAV
|
||||
g_signal_connect( GTK_OBJECT(window), "key_press_event",
|
||||
|
|
|
@ -370,6 +370,36 @@ do_nbs_then_close( CommonGlobals* cGlobals, const TransportProcs* procs )
|
|||
LOG_RETURN_VOID();
|
||||
} /* do_nbs_then_close */
|
||||
|
||||
#ifdef USE_GLIBLOOP
|
||||
static gboolean
|
||||
secondTimerFired( gpointer data )
|
||||
{
|
||||
CommonGlobals* cGlobals = (CommonGlobals*)data;
|
||||
|
||||
/* Undo */
|
||||
XWGame* game = &cGlobals->game;
|
||||
if ( !!game->server && !!game->board ) {
|
||||
XP_U16 undoRatio = cGlobals->params->undoRatio;
|
||||
if ( 0 != undoRatio ) {
|
||||
if ( (XP_RANDOM() % 100) < undoRatio ) {
|
||||
XP_LOGF( "%s: calling server_handleUndo", __func__ );
|
||||
if ( server_handleUndo( game->server ) ) {
|
||||
board_draw( game->board );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
setOneSecondTimer( CommonGlobals* cGlobals )
|
||||
{
|
||||
(void)g_timeout_add_seconds( 1, secondTimerFired, cGlobals );
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
CMD_SKIP_GAMEOVER
|
||||
,CMD_SHOW_OTHERSCORES
|
||||
|
@ -436,6 +466,9 @@ typedef enum {
|
|||
,CMD_SLOWROBOT
|
||||
,CMD_TRADEPCT
|
||||
#endif
|
||||
#ifdef USE_GLIBLOOP /* just because hard to implement otherwise */
|
||||
,CMD_UNDOPCT
|
||||
#endif
|
||||
#if defined PLATFORM_GTK && defined PLATFORM_NCURSES
|
||||
,CMD_GTK
|
||||
,CMD_CURSES
|
||||
|
@ -521,6 +554,9 @@ static CmdInfoRec CmdInfoRecs[] = {
|
|||
,{ CMD_SLOWROBOT, true, "slow-robot", "make robot slower to test network" }
|
||||
,{ CMD_TRADEPCT, true, "trade-pct", "what pct of the time should robot trade" }
|
||||
#endif
|
||||
#ifdef USE_GLIBLOOP
|
||||
,{ CMD_UNDOPCT, true, "undo-pct", "each second, what are the odds of doing an undo" }
|
||||
#endif
|
||||
#if defined PLATFORM_GTK && defined PLATFORM_NCURSES
|
||||
,{ CMD_GTK, false, "gtk", "use GTK for display" }
|
||||
,{ CMD_CURSES, false, "curses", "use curses for display" }
|
||||
|
@ -1592,6 +1628,15 @@ main( int argc, char** argv )
|
|||
break;
|
||||
#endif
|
||||
|
||||
#ifdef USE_GLIBLOOP
|
||||
case CMD_UNDOPCT:
|
||||
mainParams.undoRatio = atoi( optarg );
|
||||
if ( mainParams.undoRatio < 0 || mainParams.undoRatio > 100 ) {
|
||||
usage(argv[0], "must be 0 <= n <= 100" );
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined PLATFORM_GTK && defined PLATFORM_NCURSES
|
||||
case CMD_GTK:
|
||||
useCurses = XP_FALSE;
|
||||
|
|
|
@ -81,4 +81,10 @@ void read_pipe_then_close( CommonGlobals* cGlobals,
|
|||
void do_nbs_then_close( CommonGlobals* cGlobals,
|
||||
const TransportProcs* procs );
|
||||
|
||||
#ifdef USE_GLIBLOOP
|
||||
void setOneSecondTimer( CommonGlobals* cGlobals );
|
||||
#else
|
||||
# define setOneSecondTimer( cGlobals )
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -58,6 +58,7 @@ typedef struct LaunchParams {
|
|||
XP_U16 gameSeed;
|
||||
XP_S16 dropNthRcvd; /* negative means use for random calc */
|
||||
XP_U16 nPacketsRcvd; /* toward dropNthRcvd */
|
||||
XP_U16 undoRatio;
|
||||
XP_Bool askNewGame;
|
||||
XP_S16 quitAfter;
|
||||
XP_Bool sleepOnAnchor;
|
||||
|
|
Loading…
Add table
Reference in a new issue