From e5373f92249cc2b8d2c8357ed514dcd26dc43969 Mon Sep 17 00:00:00 2001 From: Dusan Durech Date: Sun, 2 Nov 2008 00:19:32 +0100 Subject: Automatic filtration of short intervals going after long intervals (in timer) --- src/client/interface.c | 43 ++++++++++++++++++++++++++++--------------- src/client/interface.h | 1 - src/screen/screen_world.c | 2 -- 3 files changed, 28 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/client/interface.c b/src/client/interface.c index 75efca9..f9fd0d5 100644 --- a/src/client/interface.c +++ b/src/client/interface.c @@ -117,7 +117,6 @@ int initSDL() srand((unsigned) time(NULL)); isInterfaceInit = TRUE; - isSlowHack = FALSE; return 0; } @@ -194,31 +193,46 @@ static void action_esc() } */ -void activeSlowHack() -{ - isSlowHack = TRUE; -} - -static void slowHackRoutine() +int hack_slow() { static time_t lastTime = 0; + static bool_t isSlowHack = FALSE; + time_t currentTime; + + currentTime = getMyTime(); if( lastTime == 0 ) { + lastTime = currentTime; + return 0; + } + + //printf("DEBUG: time interval %d\n", currentTime - lastTime); + + if( isSlowHack == FALSE && currentTime - lastTime >= 100 ) + { + printf("start slow hack (%d)\n", currentTime - lastTime); + isSlowHack = TRUE; lastTime = getMyTime(); - return; + return 1; } - if( getMyTime() - lastTime >= 50 ) + if( isSlowHack == TRUE && currentTime - lastTime >= 50 ) { - lastTime = 0; + printf("stop slow hack (%d)\n", currentTime - lastTime); isSlowHack = FALSE; - return; + lastTime = getMyTime(); + return 0; } - //printf("SLOW HACK : %d\n", (getMyTime() - lastTime)); + if( isSlowHack == TRUE ) + { + printf("hack time interval %d\n", currentTime - lastTime); + } lastTime = getMyTime(); + + return isSlowHack; } int eventAction() @@ -252,12 +266,11 @@ int eventAction() case SDL_USEREVENT: switch (event.user.code) { case USR_EVT_TIMER: - if( isSlowHack ) + if( hack_slow() ) { - slowHackRoutine(); break; } - + drawScreen(); eventScreen(); eventHotKey(); diff --git a/src/client/interface.h b/src/client/interface.h index daf1275..b5df62a 100644 --- a/src/client/interface.h +++ b/src/client/interface.h @@ -33,7 +33,6 @@ extern bool_t isInterfaceInicialized(); extern void enableKeyboardBuffer(); extern void disableKeyboardBuffer(); extern int initSDL(); -extern void activeSlowHack(); extern SDL_Surface *getSDL_Screen(); extern void getMousePosition(int *x, int *y); extern int isMouseClicked(); diff --git a/src/screen/screen_world.c b/src/screen/screen_world.c index eb91554..a2d0baf 100644 --- a/src/screen/screen_world.c +++ b/src/screen/screen_world.c @@ -497,8 +497,6 @@ void startWorld() setGameType(); initChat(); prepareArena(); - - activeSlowHack(); // !!! } static void action_analyze(space_t * space, tux_t * tux, void *p) -- cgit v1.2.3