source: network-game/common/Common.cpp@ b81cea1

Last change on this file since b81cea1 was 8f85180, checked in by dportnoy <dmp1488@…>, 12 years ago

Added a method for measuring milliseconds and implemented smooth player movement

  • Property mode set to 100644
File size: 833 bytes
RevLine 
[edfd1d0]1#include "Common.h"
2
[8f85180]3#include <iostream>
4using namespace std;
5
6#if defined WINDOWS
7 #include <Windows.h>
8#elif defined LINUX
9 #include <time.h>
10#endif
11
[edfd1d0]12void set_nonblock(int sock)
13{
[4c202e0]14 #if defined WINDOWS
[edfd1d0]15 unsigned long mode = 1;
16 ioctlsocket(sock, FIONBIO, &mode);
[4c202e0]17 #elif defined LINUX
[edfd1d0]18 int flags;
19 flags = fcntl(sock, F_GETFL,0);
20 assert(flags != -1);
21 fcntl(sock, F_SETFL, flags | O_NONBLOCK);
22 #endif
23}
[8f85180]24
25unsigned long long getCurrentMillis()
26{
27 unsigned long long numMilliseconds;
28
29 #if defined WINDOWS
30 numMilliseconds = GetTickCount();
31 #elif defined LINUX
32 timespec curTime;
33 clock_gettime(CLOCK_REALTIME, &curTime);
34
35 numMilliseconds = curTime.tv_sec*(unsigned long long)1000+curTime.tv_nsec/(unsigned long long)1000000;
36 #endif
37
38 return numMilliseconds;
39}
Note: See TracBrowser for help on using the repository browser.