diff --git a/raknet/Export.h b/raknet/Export.h new file mode 100644 index 0000000..37aae9e --- /dev/null +++ b/raknet/Export.h @@ -0,0 +1,6 @@ +// Fuck it, GCC won't compile with exports. Someone else can fix this if they want +#if defined(_WIN32) && !(defined(__GNUC__) || defined(__GCCXML__)) && !defined(_RAKNET_LIB) && defined(_RAKNET_DLL) +#define RAK_DLL_EXPORT __declspec(dllexport) +#else +#define RAK_DLL_EXPORT +#endif diff --git a/raknet/GetTime.cpp b/raknet/GetTime.cpp new file mode 100644 index 0000000..baf3d30 --- /dev/null +++ b/raknet/GetTime.cpp @@ -0,0 +1,105 @@ +/// \file +/// +/// This file is part of RakNet Copyright 2003 Kevin Jenkins. +/// +/// Usage of RakNet is subject to the appropriate license agreement. +/// Creative Commons Licensees are subject to the +/// license found at +/// http://creativecommons.org/licenses/by-nc/2.5/ +/// Single application licensees are subject to the license found at +/// http://www.rakkarsoft.com/SingleApplicationLicense.html +/// Custom license users are subject to the terms therein. +/// GPL license users are subject to the GNU General Public +/// License as published by the Free +/// Software Foundation; either version 2 of the License, or (at your +/// option) any later version. + +#include "GetTime.h" +#ifdef _COMPATIBILITY_1 +#include "Compatibility1Includes.h" // Developers of a certain platform will know what to do here. +#elif defined(_WIN32) +#include +#elif defined(_COMPATIBILITY_2) +#include "Compatibility2Includes.h" +#include +#include +#else +#include +#include +#endif + +static bool initialized=false; +#ifdef _WIN32 +static LARGE_INTEGER yo; +#else +static timeval tp, initialTime; +#endif + +RakNetTime RakNet::GetTime( void ) +{ + if ( initialized == false ) + { +#ifdef _WIN32 + QueryPerformanceFrequency( &yo ); + // The original code shifted right 10 bits + //counts = yo.QuadPart >> 10; + // It gives the wrong value since 2^10 is not 1000 + // counts = yo.QuadPart;// / 1000; +#else + gettimeofday( &initialTime, 0 ); +#endif + + initialized = true; + } + +#ifdef _WIN32 + LARGE_INTEGER PerfVal; + + QueryPerformanceCounter( &PerfVal ); + + return (RakNetTime)(PerfVal.QuadPart*1000 / yo.QuadPart); +#else + gettimeofday( &tp, 0 ); + + // Seconds to ms and microseconds to ms + return ( tp.tv_sec - initialTime.tv_sec ) * 1000 + ( tp.tv_usec - initialTime.tv_usec ) / 1000; + +#endif +} + + +RakNetTimeNS RakNet::GetTimeNS( void ) +{ + if ( initialized == false ) + { +#ifdef _WIN32 + QueryPerformanceFrequency( &yo ); + // The original code shifted right 10 bits + //counts = yo.QuadPart >> 10; + // It gives the wrong value since 2^10 is not 1000 + // counts = yo.QuadPart;// / 1000; +#else + gettimeofday( &initialTime, 0 ); +#endif + + initialized = true; + } + +#ifdef _WIN32 + LARGE_INTEGER PerfVal; + + QueryPerformanceCounter( &PerfVal ); + + __int64 quotient, remainder; + quotient=((PerfVal.QuadPart*1000) / yo.QuadPart); + remainder=((PerfVal.QuadPart*1000) % yo.QuadPart); + //return (PerfVal.QuadPart*1000 / (yo.QuadPart/1000)); + return quotient*1000 + (remainder*1000 / yo.QuadPart); + +#else + gettimeofday( &tp, 0 ); + + return ( tp.tv_sec - initialTime.tv_sec ) * (RakNetTimeNS) 1000000 + ( tp.tv_usec - initialTime.tv_usec ); + +#endif +} diff --git a/raknet/GetTime.h b/raknet/GetTime.h new file mode 100644 index 0000000..64cc1ad --- /dev/null +++ b/raknet/GetTime.h @@ -0,0 +1,33 @@ +/// \file +/// \brief Returns the value from QueryPerformanceCounter. This is the function RakNet uses to represent time. +/// +/// This file is part of RakNet Copyright 2003 Kevin Jenkins. +/// +/// Usage of RakNet is subject to the appropriate license agreement. +/// Creative Commons Licensees are subject to the +/// license found at +/// http://creativecommons.org/licenses/by-nc/2.5/ +/// Single application licensees are subject to the license found at +/// http://www.rakkarsoft.com/SingleApplicationLicense.html +/// Custom license users are subject to the terms therein. +/// GPL license users are subject to the GNU General Public +/// License as published by the Free +/// Software Foundation; either version 2 of the License, or (at your +/// option) any later version. + +#ifndef __GET_TIME_H +#define __GET_TIME_H + +#include "Export.h" +#include "NetworkTypes.h" // For RakNetTime + +/// The namespace RakNet is not consistently used. It's only purpose is to avoid compiler errors for classes whose names are very common. +/// For the most part I've tried to avoid this simply by using names very likely to be unique for my classes. +namespace RakNet +{ + /// Returns the value from QueryPerformanceCounter. This is the function RakNet uses to represent time. + RakNetTime RAK_DLL_EXPORT GetTime( void ); + RakNetTimeNS RAK_DLL_EXPORT GetTimeNS( void ); +} + +#endif diff --git a/raknet/NetworkTypes.cpp b/raknet/NetworkTypes.cpp new file mode 100644 index 0000000..73361a6 --- /dev/null +++ b/raknet/NetworkTypes.cpp @@ -0,0 +1 @@ +// TODO: Implement NetworkTypes.cpp \ No newline at end of file diff --git a/raknet/NetworkTypes.h b/raknet/NetworkTypes.h new file mode 100644 index 0000000..f1d44d7 --- /dev/null +++ b/raknet/NetworkTypes.h @@ -0,0 +1,16 @@ +// TODO: Implement NetworkTypes.h + +#ifndef __NETWORK_TYPES_H +#define __NETWORK_TYPES_H + +// Define __GET_TIME_64BIT if you want to use large types for GetTime (takes more bandwidth when you transmit time though!) +// You would want to do this if your system is going to run long enough to overflow the millisecond counter (over a month) +#ifdef __GET_TIME_64BIT +typedef long long RakNetTime; +typedef long long RakNetTimeNS; +#else +typedef unsigned int RakNetTime; +typedef long long RakNetTimeNS; +#endif + +#endif