timer.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #ifndef _TIMER_H_
  4. #define _TIMER_H_
  5. #ifdef __WIN32
  6. /* We need winsock lib to have timeval struct - windows is weirdo */
  7. #define __USE_W32_SOCKETS
  8. #include <windows.h>
  9. #endif
  10. #define BASE_TICK 5
  11. #define TIMER_ONCE_AUTODEL 0x1
  12. #define TIMER_INTERVAL 0x2
  13. #define TIMER_REMOVE_HEAP 0x10
  14. #define DIFF_TICK(a,b) ((int)((a)-(b)))
  15. #define INVALID_TIMER -1
  16. // Struct declaration
  17. typedef int (*TimerFunc)(int,unsigned int,int,int);
  18. struct TimerData {
  19. unsigned int tick;
  20. TimerFunc func;
  21. int id;
  22. int data;
  23. int type;
  24. int interval;
  25. int heap_pos;
  26. };
  27. // Function prototype declaration
  28. unsigned int gettick_nocache(void);
  29. unsigned int gettick(void);
  30. int add_timer(unsigned int,TimerFunc f,int,int);
  31. int add_timer_interval(unsigned int tick, TimerFunc func, int id, int data, int interval);
  32. int delete_timer(int,TimerFunc f);
  33. int addtick_timer(int tid,unsigned int tick);
  34. int settick_timer(int tid,unsigned int tick);
  35. struct TimerData *get_timer(int tid);
  36. int do_timer(unsigned int tick);
  37. int add_timer_func_list(TimerFunc func, char* name);
  38. char* search_timer_func_list(TimerFunc f);
  39. unsigned long get_uptime(void);
  40. void timer_init(void);
  41. void timer_final(void);
  42. #endif // _TIMER_H_