Fix headers conflicts (for windows + MSVC)
Move gettimeofday() from frame.c to timer.c (for windows) Make sure we include the platform specific include before the others. (so we can correctly use WZ_OS_XXX and so on...) git-svn-id: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/branches/qt-trunk@10854 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
079b8766a6
commit
840c77d13c
|
@ -545,48 +545,6 @@ UDWORD HashStringIgnoreCase( const char *c )
|
|||
return iHashValue;
|
||||
}
|
||||
|
||||
#if defined(WZ_OS_WIN)
|
||||
/**
|
||||
* The difference between the FAT32 and Unix epoch.
|
||||
*
|
||||
* The FAT32 epoch starts at 1 January 1601 while the Unix epoch starts at 1
|
||||
* January 1970. And apparantly we gained 3.25 days in that time period.
|
||||
*
|
||||
* Thus the amount of micro seconds passed between these dates can be computed
|
||||
* as follows:
|
||||
* \f[((1970 - 1601) \cdot 365.25 + 3.25) \cdot 86400 \cdot 1000000\f]
|
||||
*
|
||||
* Use 1461 and 13 instead of 365.25 and 3.25 respectively because we can't use
|
||||
* floating point math here.
|
||||
*/
|
||||
static const uint64_t usecs_between_fat32_and_unix_epoch = (uint64_t)((1970 - 1601) * 1461 + 13) * (uint64_t)86400 / (uint64_t)4 * (uint64_t)1000000;
|
||||
|
||||
int gettimeofday(struct timeval* tv, struct timezone* tz)
|
||||
{
|
||||
ASSERT(tz == NULL, "This gettimeofday implementation doesn't provide timezone info.");
|
||||
|
||||
if (tv)
|
||||
{
|
||||
FILETIME ft;
|
||||
uint64_t systime, usec;
|
||||
|
||||
/* Retrieve the current time expressed as 100 nano-second
|
||||
* intervals since 1 January 1601 (UTC).
|
||||
*/
|
||||
GetSystemTimeAsFileTime(&ft);
|
||||
systime = ((uint64_t)ft.dwHighDateTime << 32) | ft.dwLowDateTime;
|
||||
|
||||
// Convert to micro seconds since 1 January 1970 (UTC).
|
||||
usec = systime / 10 - usecs_between_fat32_and_unix_epoch;
|
||||
|
||||
tv->tv_sec = usec / (uint64_t)1000000;
|
||||
tv->tv_usec = usec % (uint64_t)1000000;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool PHYSFS_printf(PHYSFS_file *file, const char *format, ...)
|
||||
{
|
||||
char vaBuffer[PATH_MAX];
|
||||
|
|
|
@ -109,13 +109,6 @@ extern UDWORD HashStringIgnoreCase( const char *String );
|
|||
}
|
||||
#endif //__cplusplus
|
||||
|
||||
#if defined(WZ_OS_WIN)
|
||||
# include <winsock2.h> /* for struct timeval */
|
||||
|
||||
struct timezone;
|
||||
extern int gettimeofday(struct timeval* tv, struct timezone* tz);
|
||||
#endif
|
||||
|
||||
static inline WZ_DECL_CONST const char * bool2string(bool var)
|
||||
{
|
||||
return (var ? "true" : "false");
|
||||
|
|
|
@ -33,6 +33,10 @@
|
|||
#include <physfs.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(WZ_OS_WIN)
|
||||
# include <winsock2.h> // for sockets
|
||||
#endif
|
||||
|
||||
#include "netplay.h"
|
||||
#include "netlog.h"
|
||||
#include "netsocket.h"
|
||||
|
|
|
@ -17,8 +17,9 @@
|
|||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "timer.h"
|
||||
|
||||
#include "lib/framework/frame.h"
|
||||
#include "timer.h"
|
||||
|
||||
#if defined(WZ_OS_UNIX)
|
||||
# include <sys/time.h>
|
||||
|
@ -31,6 +32,48 @@ static BOOL stopped = false; // stop flag
|
|||
static struct timeval startCount;
|
||||
static struct timeval endCount;
|
||||
|
||||
#if defined(WZ_OS_WIN)
|
||||
/**
|
||||
* The difference between the FAT32 and Unix epoch.
|
||||
*
|
||||
* The FAT32 epoch starts at 1 January 1601 while the Unix epoch starts at 1
|
||||
* January 1970. And apparantly we gained 3.25 days in that time period.
|
||||
*
|
||||
* Thus the amount of micro seconds passed between these dates can be computed
|
||||
* as follows:
|
||||
* \f[((1970 - 1601) \cdot 365.25 + 3.25) \cdot 86400 \cdot 1000000\f]
|
||||
*
|
||||
* Use 1461 and 13 instead of 365.25 and 3.25 respectively because we can't use
|
||||
* floating point math here.
|
||||
*/
|
||||
static const uint64_t usecs_between_fat32_and_unix_epoch = (uint64_t)((1970 - 1601) * 1461 + 13) * (uint64_t)86400 / (uint64_t)4 * (uint64_t)1000000;
|
||||
|
||||
int gettimeofday(struct timeval* tv, struct timezone* tz)
|
||||
{
|
||||
ASSERT(tz == NULL, "This gettimeofday implementation doesn't provide timezone info.");
|
||||
|
||||
if (tv)
|
||||
{
|
||||
FILETIME ft;
|
||||
uint64_t systime, usec;
|
||||
|
||||
/* Retrieve the current time expressed as 100 nano-second
|
||||
* intervals since 1 January 1601 (UTC).
|
||||
*/
|
||||
GetSystemTimeAsFileTime(&ft);
|
||||
systime = ((uint64_t)ft.dwHighDateTime << 32) | ft.dwLowDateTime;
|
||||
|
||||
// Convert to micro seconds since 1 January 1970 (UTC).
|
||||
usec = systime / 10 - usecs_between_fat32_and_unix_epoch;
|
||||
|
||||
tv->tv_sec = usec / (uint64_t)1000000;
|
||||
tv->tv_usec = usec % (uint64_t)1000000;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Uses the highest resolution timers avail on windows & linux
|
||||
void Timer_Init(void)
|
||||
{
|
||||
|
|
|
@ -26,4 +26,11 @@ void Timer_stop(void); // stop the timer
|
|||
double Timer_getElapsedMilliSecs(void); // get elapsed time in milliseconds
|
||||
double Timer_getElapsedMicroSecs(void); // get elapsed time in microseconds
|
||||
|
||||
#if defined(WZ_OS_WIN)
|
||||
# include <winsock2.h> /* for struct timeval */
|
||||
|
||||
struct timezone;
|
||||
extern int gettimeofday(struct timeval* tv, struct timezone* tz);
|
||||
#endif
|
||||
|
||||
#endif // __INCLUDED_LIB_SEQUENCE_TIMER_H__
|
||||
|
|
Loading…
Reference in New Issue