X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fporting.h;h=b5a5d00f284120184e4cb1ffba0b53fb94181111;hb=c410e9182d322a8c095ef94fbadf4d8f541e6b98;hp=be26e428246877a1e78cd4bdad2145743ad780d8;hpb=34904a0744ee08d387a67619a5e2c46ce4928c12;p=minetest.git diff --git a/src/porting.h b/src/porting.h index be26e4282..b5a5d00f2 100644 --- a/src/porting.h +++ b/src/porting.h @@ -123,6 +123,11 @@ with this program; if not, write to the Free Software Foundation, Inc., #define PADDING(x, y) ((ALIGNOF(y) - ((uintptr_t)(x) & (ALIGNOF(y) - 1))) & (ALIGNOF(y) - 1)) +#if defined(__APPLE__) + #include + #include +#endif + namespace porting { @@ -220,9 +225,13 @@ void initIrrlicht(irr::IrrlichtDevice * ); } #else // Posix - #include - #include - +#include +#include +#ifdef __MACH__ +#include +#include +#endif + inline u32 getTimeS() { struct timeval tv; @@ -247,7 +256,18 @@ void initIrrlicht(irr::IrrlichtDevice * ); inline u32 getTimeNs() { struct timespec ts; + // from http://stackoverflow.com/questions/5167269/clock-gettime-alternative-in-mac-os-x +#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time + clock_serv_t cclock; + mach_timespec_t mts; + host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); + clock_get_time(cclock, &mts); + mach_port_deallocate(mach_task_self(), cclock); + ts.tv_sec = mts.tv_sec; + ts.tv_nsec = mts.tv_nsec; +#else clock_gettime(CLOCK_REALTIME, &ts); +#endif return ts.tv_sec * 1000000000 + ts.tv_nsec; } @@ -275,6 +295,21 @@ inline u32 getTime(TimePrecision prec) return 0; } +/** + * Delta calculation function taking two 32bit arguments. + * @param old_time_ms old time for delta calculation (order is relevant!) + * @param new_time_ms new time for delta calculation (order is relevant!) + * @return positive 32bit delta value + */ +inline u32 getDeltaMs(u32 old_time_ms, u32 new_time_ms) +{ + if (new_time_ms >= old_time_ms) { + return (new_time_ms - old_time_ms); + } else { + return (old_time_ms - new_time_ms); + } +} + #if defined(linux) || defined(__linux) #include @@ -336,11 +371,6 @@ v2u32 getDisplaySize(); v2u32 getWindowSize(); #endif -#ifdef SERVER -void daemonize(); -void cleanup_pid(); -#endif - } // namespace porting #endif // PORTING_HEADER