2014-11-18 21:04:19 +01:00
|
|
|
/************************************************************************
|
|
|
|
* Minetest-c55
|
|
|
|
* Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
|
|
|
|
*
|
|
|
|
* porting.h
|
|
|
|
* voxelands - 3d voxel world sandbox game
|
|
|
|
* Copyright (C) Lisa 'darkrose' Milne 2014 <lisa@ltmnet.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
* License updated from GPLv2 or later to GPLv3 or later by Lisa Milne
|
|
|
|
* for Voxelands.
|
|
|
|
************************************************************************/
|
2013-04-15 14:42:24 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Random portability stuff
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PORTING_HEADER
|
|
|
|
#define PORTING_HEADER
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
// Included for u32 and such
|
|
|
|
#include "common_irrlicht.h"
|
2014-07-12 13:27:32 +02:00
|
|
|
#include "debug.h"
|
2013-04-15 14:42:24 +02:00
|
|
|
#include "constants.h"
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define SWPRINTF_CHARSTRING L"%S"
|
|
|
|
#else
|
|
|
|
#define SWPRINTF_CHARSTRING L"%s"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#define sleep_ms(x) Sleep(x)
|
|
|
|
#else
|
2014-07-12 13:27:37 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
#define sleep_ms(x) usleep(x*1000)
|
2013-04-15 14:42:24 +02:00
|
|
|
#endif
|
|
|
|
|
2015-06-10 12:52:37 +02:00
|
|
|
#if defined(__APPLE__) || defined(__FreeBSD__)
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#endif
|
|
|
|
|
2013-04-15 14:42:24 +02:00
|
|
|
namespace porting
|
|
|
|
{
|
|
|
|
|
|
|
|
/*
|
|
|
|
Signal handler (grabs Ctrl-C on POSIX systems)
|
|
|
|
*/
|
|
|
|
|
|
|
|
void signal_handler_init(void);
|
|
|
|
// Returns a pointer to a bool.
|
|
|
|
// When the bool is true, program should quit.
|
|
|
|
bool * signal_handler_killstatus(void);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Resolution is 10-20ms.
|
|
|
|
Remember to check for overflows.
|
|
|
|
Overflow can occur at any value higher than 10000000.
|
|
|
|
*/
|
|
|
|
#ifdef _WIN32 // Windows
|
|
|
|
#include <windows.h>
|
|
|
|
inline u32 getTimeMs()
|
|
|
|
{
|
|
|
|
return GetTickCount();
|
|
|
|
}
|
|
|
|
#else // Posix
|
|
|
|
#include <sys/time.h>
|
|
|
|
inline u32 getTimeMs()
|
|
|
|
{
|
|
|
|
struct timeval tv;
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
|
|
|
}
|
|
|
|
/*#include <sys/timeb.h>
|
|
|
|
inline u32 getTimeMs()
|
|
|
|
{
|
|
|
|
struct timeb tb;
|
|
|
|
ftime(&tb);
|
|
|
|
return tb.time * 1000 + tb.millitm;
|
|
|
|
}*/
|
|
|
|
#endif
|
|
|
|
|
2015-03-24 06:26:03 +01:00
|
|
|
std::string getUser();
|
|
|
|
|
2013-04-15 14:42:24 +02:00
|
|
|
} // namespace porting
|
|
|
|
|
|
|
|
#endif // PORTING_HEADER
|
|
|
|
|