unix_timer.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. Copyright (C) 2004 Michael Liebscher
  3. Copyright (C) 1997-2001 Id Software, Inc.
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. See the GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. /*
  17. * unix_timer.c: unix timer.
  18. *
  19. * Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
  20. * Date: 2004
  21. *
  22. * Acknowledgement:
  23. * This code was derived from Quake II, and was originally
  24. * written by Id Software, Inc.
  25. *
  26. */
  27. #include "../wolfiphone.h"
  28. PUBLIC W32 curtime;
  29. /*
  30. -----------------------------------------------------------------------------
  31. Function:
  32. Parameters:
  33. Returns:
  34. Notes:
  35. -----------------------------------------------------------------------------
  36. */
  37. PUBLIC W32 Sys_Milliseconds( void )
  38. {
  39. struct timeval tp;
  40. struct timezone tzp;
  41. static int secbase;
  42. gettimeofday( &tp, &tzp );
  43. if( ! secbase )
  44. {
  45. secbase = tp.tv_sec;
  46. return tp.tv_usec / 1000;
  47. }
  48. curtime = (tp.tv_sec - secbase) * 1000 + tp.tv_usec / 1000;
  49. return curtime;
  50. }