timer.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef TIMER_H
  17. #define TIMER_H
  18. #include "types.h"
  19. // Disgrace: for windows compile
  20. #ifdef WIN32
  21. #include <WinSock2.h>
  22. #include <windows.h>
  23. int gettimeofday (timeval *tp, ...);
  24. #endif
  25. class Timer
  26. {
  27. public:
  28. Timer();
  29. Timer(int32 timer_time, bool iUseAcurateTiming = false);
  30. Timer(int32 start, int32 timer, bool iUseAcurateTiming);
  31. ~Timer() { }
  32. bool Check(bool iReset = true);
  33. void Enable();
  34. void Disable();
  35. void Start(int32 set_timer_time=0, bool ChangeResetTimer = true);
  36. void SetTimer(int32 set_timer_time=0);
  37. int32 GetRemainingTime();
  38. int32 GetElapsedTime();
  39. inline const int32& GetTimerTime() { return timer_time; }
  40. inline const int32& GetSetAtTrigger() { return set_at_trigger; }
  41. void Trigger();
  42. void SetAtTrigger(int32 set_at_trigger, bool iEnableIfDisabled = false);
  43. inline bool Enabled() { return enabled; }
  44. inline int32 GetStartTime() { return(start_time); }
  45. inline int32 GetDuration() { return(timer_time); }
  46. static const int32& SetCurrentTime();
  47. static const int32& GetCurrentTime2();
  48. static int32 GetUnixTimeStamp();
  49. private:
  50. int32 start_time;
  51. int32 timer_time;
  52. bool enabled;
  53. int32 set_at_trigger;
  54. // Tells the timer to be more acurate about happening every X ms.
  55. // Instead of Check() setting the start_time = now,
  56. // it it sets it to start_time += timer_time
  57. bool pUseAcurateTiming;
  58. // static int32 current_time;
  59. // static int32 last_time;
  60. };
  61. #endif