All Classes Namespaces Files Functions Variables Enumerations Enumerator
libs/system/c/urg_ticks.c
Go to the documentation of this file.
00001 
00010 #include "urg_ticks.h"
00011 #include "detect_os.h"
00012 #if defined WINDOWS_OS
00013 #include <time.h>
00014 #else
00015 #include <sys/time.h>
00016 #include <stdio.h>
00017 #endif
00018 
00019 
00020 long urg_ticks(void)
00021 {
00022   long current_ticks = 0;
00023 
00024 #if defined(LINUX_OS)
00025   // Linux で SDL がない場合の実装。最初の呼び出しは 0 を返す
00026   static long first_ticks = 0;
00027   struct timeval tvp;
00028   gettimeofday(&tvp, NULL);
00029   long global_ticks = tvp.tv_sec * 1000 + tvp.tv_usec / 1000;
00030   if (first_ticks == 0) {
00031     first_ticks = global_ticks;
00032   }
00033   current_ticks = global_ticks - first_ticks;
00034 
00035 #else
00036   current_ticks = (long)(clock() / (CLOCKS_PER_SEC / 1000.0));
00037 #endif
00038   return current_ticks;
00039 }