timer.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #include "cbasetypes.h"
  6. #include <time.h>
  7. #define DIFF_TICK(a,b) ((int)((a)-(b)))
  8. #define INVALID_TIMER -1
  9. #define CLIF_WALK_TIMER -2
  10. // timer flags
  11. enum {
  12. TIMER_ONCE_AUTODEL = 0x01,
  13. TIMER_INTERVAL = 0x02,
  14. TIMER_REMOVE_HEAP = 0x10,
  15. };
  16. // Struct declaration
  17. typedef int (*TimerFunc)(int tid, unsigned int tick, int id, intptr_t data);
  18. struct TimerData {
  19. unsigned int tick;
  20. TimerFunc func;
  21. unsigned int type;
  22. int interval;
  23. // general-purpose storage
  24. int id;
  25. intptr_t data;
  26. };
  27. // Function prototype declaration
  28. unsigned int gettick(void);
  29. unsigned int gettick_nocache(void);
  30. int add_timer(unsigned int tick, TimerFunc func, int id, intptr_t data);
  31. int add_timer_interval(unsigned int tick, TimerFunc func, int id, intptr_t data, int interval);
  32. const struct TimerData* get_timer(int tid);
  33. int delete_timer(int tid, TimerFunc func);
  34. int addtick_timer(int tid, unsigned int tick);
  35. int settick_timer(int tid, unsigned int tick);
  36. int add_timer_func_list(TimerFunc func, char* name);
  37. unsigned long get_uptime(void);
  38. //transform a timestamp to string
  39. const char* timestamp2string(char* str, size_t size, time_t timestamp, const char* format);
  40. void split_time(int time, int* year, int* month, int* day, int* hour, int* minute, int* second);
  41. double solve_time(char* modif_p);
  42. int do_timer(unsigned int tick);
  43. void timer_init(void);
  44. void timer_final(void);
  45. #endif /* _TIMER_H_ */