#include "Common.h" #include #include #if defined WINDOWS #include #elif defined LINUX #include #endif using namespace std; /* FLOAT_POSITION POSITION::toFloat() { FLOAT_POSITION floatPosition; floatPosition.x = x; floatPosition.y = y; return floatPosition; } */ void set_nonblock(int sock) { #if defined WINDOWS unsigned long mode = 1; ioctlsocket(sock, FIONBIO, &mode); #elif defined LINUX int flags; flags = fcntl(sock, F_GETFL,0); assert(flags != -1); fcntl(sock, F_SETFL, flags | O_NONBLOCK); #endif } unsigned long long getCurrentMillis() { unsigned long long numMilliseconds; #if defined WINDOWS numMilliseconds = GetTickCount(); #elif defined LINUX timespec curTime; clock_gettime(CLOCK_REALTIME, &curTime); numMilliseconds = curTime.tv_sec*(unsigned long long)1000+curTime.tv_nsec/(unsigned long long)1000000; #endif return numMilliseconds; } float posDistance(FLOAT_POSITION pos1, FLOAT_POSITION pos2) { float xDiff = pos2.x - pos1.x; float yDiff = pos2.y - pos1.y; return sqrt( pow(xDiff,2) + pow(yDiff,2) ); }