Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

time.cpp 1015B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*!
  2. * \file include/utils/time.h
  3. * \brief Time handling utilities
  4. *
  5. * \author xythobuz
  6. */
  7. #include "utils/time.h"
  8. #if defined(unix) || defined(__APPLE__) || defined (__linux__)
  9. #include <sys/time.h>
  10. struct timeval system_timer_start;
  11. struct timeval system_timer_stop;
  12. struct timezone system_timer_zone;
  13. unsigned long systemTimerGet() {
  14. gettimeofday(&system_timer_stop, &system_timer_zone);
  15. return ((system_timer_stop.tv_sec - system_timer_start.tv_sec) * 1000)
  16. + (((system_timer_stop.tv_usec - system_timer_start.tv_usec) / 1000));
  17. }
  18. void systemTimerReset() {
  19. gettimeofday(&system_timer_start, &system_timer_zone);
  20. }
  21. #elif defined(WIN32)
  22. #include <Windows.h>
  23. DWORD system_timer_start = 0;
  24. unsigned long systemTimerGet() {
  25. return GetTickCount() - system_timer_start;
  26. }
  27. void systemTimerReset() {
  28. system_timer_start = GetTickCount();
  29. }
  30. #else
  31. #warn "No support for timer on this platform!"
  32. unsigned long systemTimerGet() { return 0; }
  33. void systemTimerReset() { }
  34. #endif