timer.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright (c) rAthena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #ifndef _TIMER_HPP_
  4. #define _TIMER_HPP_
  5. #include <time.h>
  6. #include "cbasetypes.hpp"
  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. #define TIMER_FUNC(x) int x ( int tid, unsigned int tick, int id, intptr_t data )
  17. // Struct declaration
  18. typedef TIMER_FUNC((*TimerFunc));
  19. struct TimerData {
  20. unsigned int tick;
  21. TimerFunc func;
  22. unsigned int type;
  23. int interval;
  24. // general-purpose storage
  25. int id;
  26. intptr_t data;
  27. };
  28. // Function prototype declaration
  29. unsigned int gettick(void);
  30. unsigned int gettick_nocache(void);
  31. int add_timer(unsigned int tick, TimerFunc func, int id, intptr_t data);
  32. int add_timer_interval(unsigned int tick, TimerFunc func, int id, intptr_t data, int interval);
  33. const struct TimerData* get_timer(int tid);
  34. int delete_timer(int tid, TimerFunc func);
  35. int addtick_timer(int tid, unsigned int tick);
  36. int settick_timer(int tid, unsigned int tick);
  37. int add_timer_func_list(TimerFunc func, const char* name);
  38. unsigned long get_uptime(void);
  39. //transform a timestamp to string
  40. const char* timestamp2string(char* str, size_t size, time_t timestamp, const char* format);
  41. void split_time(int time, int* year, int* month, int* day, int* hour, int* minute, int* second);
  42. double solve_time(char* modif_p);
  43. int do_timer(unsigned int tick);
  44. void timer_init(void);
  45. void timer_final(void);
  46. #endif /* _TIMER_HPP_ */