diff options
| author | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-02-01 22:59:06 +0000 |
|---|---|---|
| committer | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-02-01 22:59:06 +0000 |
| commit | 6d4e1eae16b84918009625a866104ec26a234277 (patch) | |
| tree | a340a8a547a60c9f63c8dfafe8909242f9c9bbd8 /src/myTimer.c | |
nahranie tarballu tuxanci-ng na SVN server
Dusan Durech ( Oroborus )
git-svn-id: http://opensvn.csie.org/tuxanci_ng@1 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
Diffstat (limited to 'src/myTimer.c')
| -rw-r--r-- | src/myTimer.c | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/src/myTimer.c b/src/myTimer.c new file mode 100644 index 0000000..1faca9b --- /dev/null +++ b/src/myTimer.c @@ -0,0 +1,101 @@ + +#include <time.h> +#include <assert.h> +#include <stdlib.h> + +#include "main.h" +#include "interface.h" +#include "list.h" +#include "myTimer.h" + +static list_t *listTime; + +static bool_t isTimerInit = FALSE; + +bool_t isMyTimerInicialized() +{ + return isTimerInit; +} + +void initTimer() +{ + assert( isInterfaceInicialized() == TRUE ); + + listTime = newList(); + isTimerInit = TRUE; +} + +int addTimer(void (*fce)(void *p), void *arg, int my_time) +{ + static int new_id = 0; + my_timer_t *new; + Uint32 currentTime; + + currentTime = SDL_GetTicks(); + + new = malloc( sizeof(my_timer_t) ); + assert( new != NULL ); + + new->id = new_id++; + new->fce = fce; + new->arg = arg; + new->time = currentTime + my_time; + + addList(listTime, new); + + return new->id; +} + +void eventTimer() +{ + int i; + my_timer_t *thisTimer; + Uint32 currentTime; + + currentTime = SDL_GetTicks(); + + for( i = 0 ; i < listTime->count ; i++ ) + { + thisTimer = (my_timer_t *)listTime->list[i]; + assert( thisTimer != NULL ); + + if( currentTime >= thisTimer->time ) + { + thisTimer->fce(thisTimer->arg); + delListItem(listTime, i, free); + i--; + } + } +} + +void delTimer(int id) +{ + int i; + my_timer_t *thisTimer; + + for( i = 0 ; i < listTime->count ; i++ ) + { + thisTimer = (my_timer_t *)listTime->list[i]; + assert( thisTimer != NULL ); + + if( thisTimer->id == id ) + { + delListItem(listTime, i, free); + return; + } + } + + assert( ! "Uloha s id nenajdena !" ); +} + +void delAllItemTimer() +{ + quitTimer(); + initTimer(); +} + +void quitTimer() +{ + destroyListItem(listTime, free); + isTimerInit = FALSE; +} |