mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-16 15:41:16 +01:00
cancel old timer before setting a new one
This commit is contained in:
parent
2d23ffddd3
commit
ca6c35ad78
2 changed files with 21 additions and 5 deletions
|
@ -1036,6 +1036,16 @@ fireTimer( GtkAppGlobals* globals, XWTimerReason why )
|
||||||
(*proc)( closure, why );
|
(*proc)( closure, why );
|
||||||
} /* fireTimer */
|
} /* fireTimer */
|
||||||
|
|
||||||
|
static void
|
||||||
|
cancelTimer( GtkAppGlobals* globals, XWTimerReason why )
|
||||||
|
{
|
||||||
|
guint src = globals->timerSources[why-1];
|
||||||
|
if ( src != 0 ) {
|
||||||
|
g_source_remove( src );
|
||||||
|
globals->timerSources[why-1] = 0;
|
||||||
|
}
|
||||||
|
} /* cancelTimer */
|
||||||
|
|
||||||
static gint
|
static gint
|
||||||
pentimer_idle_func( gpointer data )
|
pentimer_idle_func( gpointer data )
|
||||||
{
|
{
|
||||||
|
@ -1078,27 +1088,31 @@ gtk_util_setTimer( XW_UtilCtxt* uc, XWTimerReason why, XP_U16 when,
|
||||||
TimerProc proc, void* closure )
|
TimerProc proc, void* closure )
|
||||||
{
|
{
|
||||||
GtkAppGlobals* globals = (GtkAppGlobals*)uc->closure;
|
GtkAppGlobals* globals = (GtkAppGlobals*)uc->closure;
|
||||||
|
guint newSrc;
|
||||||
|
|
||||||
globals->cGlobals.timerProcs[why-1] = proc;
|
cancelTimer( globals, why );
|
||||||
globals->cGlobals.timerClosures[why-1] = closure;
|
|
||||||
|
|
||||||
if ( why == TIMER_PENDOWN ) {
|
if ( why == TIMER_PENDOWN ) {
|
||||||
globals->penTimerInterval = 35 * 10000;
|
globals->penTimerInterval = 35 * 10000;
|
||||||
|
|
||||||
(void)gettimeofday( &globals->penTv, NULL );
|
(void)gettimeofday( &globals->penTv, NULL );
|
||||||
(void)gtk_idle_add( pentimer_idle_func, globals );
|
newSrc = g_idle_add( pentimer_idle_func, globals );
|
||||||
} else if ( why == TIMER_TIMERTICK ) {
|
} else if ( why == TIMER_TIMERTICK ) {
|
||||||
globals->scoreTimerInterval = 100 * 10000;
|
globals->scoreTimerInterval = 100 * 10000;
|
||||||
|
|
||||||
(void)gettimeofday( &globals->scoreTv, NULL );
|
(void)gettimeofday( &globals->scoreTv, NULL );
|
||||||
|
|
||||||
(void)g_timeout_add( 1000, score_timer_func, globals );
|
newSrc = g_timeout_add( 1000, score_timer_func, globals );
|
||||||
} else if ( why == TIMER_HEARTBEAT ) {
|
} else if ( why == TIMER_HEARTBEAT ) {
|
||||||
(void)g_timeout_add( 1000 * when, heartbeat_timer_func, globals );
|
newSrc = g_timeout_add( 1000 * when, heartbeat_timer_func, globals );
|
||||||
} else {
|
} else {
|
||||||
XP_ASSERT( 0 );
|
XP_ASSERT( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
globals->cGlobals.timerProcs[why-1] = proc;
|
||||||
|
globals->cGlobals.timerClosures[why-1] = closure;
|
||||||
|
XP_ASSERT( newSrc != 0 );
|
||||||
|
globals->timerSources[why-1] = newSrc;
|
||||||
} /* gtk_util_setTimer */
|
} /* gtk_util_setTimer */
|
||||||
|
|
||||||
static gint
|
static gint
|
||||||
|
|
|
@ -86,6 +86,8 @@ typedef struct GtkAppGlobals {
|
||||||
|
|
||||||
ClientStreamRec clientRecs[MAX_NUM_PLAYERS];
|
ClientStreamRec clientRecs[MAX_NUM_PLAYERS];
|
||||||
|
|
||||||
|
guint timerSources[TIMER_NUM_PLUS_ONE - 1];
|
||||||
|
|
||||||
CommonPrefs cp;
|
CommonPrefs cp;
|
||||||
|
|
||||||
XP_Bool gridOn;
|
XP_Bool gridOn;
|
||||||
|
|
Loading…
Reference in a new issue