diff --git a/third_party/gameswf/base/tu_timer.cpp b/third_party/gameswf/base/tu_timer.cpp index 9b1607a..a57b889 100644 --- a/third_party/gameswf/base/tu_timer.cpp +++ b/third_party/gameswf/base/tu_timer.cpp @@ -7,9 +7,16 @@ //Pete H - no sys/timeb in marmalade //#include // for ftime() -#ifndef _TIME_T -#define _TIME_T -typedef long time_t; +#include +#ifndef _WIN32 +#include +#endif + +#if !defined(_WIN32) && !defined(__EMSCRIPTEN__) && \ + !defined(_TIME_T_DEFINED) && !defined(__time_t_defined) && \ + !defined(_TIME_T) + typedef long time_t; + #define _TIME_T_DEFINED #endif struct timeb { @@ -19,7 +26,23 @@ struct timeb { short dstflag; /* [XSI] non-zero if DST in effect */ }; -void ftime (timeb* b) {} +void ftime (timeb* b) +{ + if (b) + { +#ifndef _WIN32 + struct timeval tv; + gettimeofday(&tv, 0); + b->time = (time_t) tv.tv_sec; + b->millitm = (unsigned short) (tv.tv_usec / 1000); +#else + b->time = time(NULL); + b->millitm = 0; +#endif + b->timezone = 0; + b->dstflag = 0; + } +} #include @@ -35,7 +58,11 @@ Uint32 tu_timer::get_ticks() { struct timeb tv; ftime(&tv); - return (tv.time - s_start_time.time) * 1000 + (tv.millitm - s_start_time.millitm); + if (s_start_time.time == 0) + { + s_start_time = tv; + } + return (Uint32) ((tv.time - s_start_time.time) * 1000 + (tv.millitm - s_start_time.millitm)); } tu_datetime::tu_datetime()