2012-06-25 17:59:17 +00:00
|
|
|
// * This file is part of the COLOBOT source code
|
|
|
|
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
|
|
|
|
// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
|
|
|
|
// *
|
|
|
|
// * 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/.
|
|
|
|
|
|
|
|
|
|
|
|
#include "app/system.h"
|
|
|
|
|
|
|
|
#include "common/config.h"
|
|
|
|
|
2012-07-15 17:17:49 +00:00
|
|
|
|
2012-06-25 17:59:17 +00:00
|
|
|
#if defined(PLATFORM_WINDOWS)
|
2012-10-17 19:55:45 +00:00
|
|
|
#include "app/system_windows.h"
|
2012-07-15 17:17:49 +00:00
|
|
|
|
2012-06-25 17:59:17 +00:00
|
|
|
#elif defined(PLATFORM_LINUX)
|
2012-10-17 19:55:45 +00:00
|
|
|
#include "app/system_linux.h"
|
2012-07-15 17:17:49 +00:00
|
|
|
|
2012-06-25 17:59:17 +00:00
|
|
|
#else
|
2012-10-17 19:55:45 +00:00
|
|
|
#include "app/system_other.h"
|
2012-07-15 17:17:49 +00:00
|
|
|
|
2012-06-25 17:59:17 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2012-07-15 17:17:49 +00:00
|
|
|
#include <cassert>
|
2012-06-25 17:59:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays a system dialog with info, error, question etc. message.
|
|
|
|
*
|
|
|
|
* \param type type of dialog
|
|
|
|
* \param message text of message (in UTF-8)
|
|
|
|
* \param title dialog title (in UTF-8)
|
|
|
|
* \returns result (which button was clicked)
|
|
|
|
*/
|
|
|
|
SystemDialogResult SystemDialog(SystemDialogType type, const std::string& title, const std::string& message)
|
|
|
|
{
|
2012-07-15 17:17:49 +00:00
|
|
|
#if defined(PLATFORM_WINDOWS)
|
2012-06-26 20:23:05 +00:00
|
|
|
return SystemDialog_Windows(type, title, message);
|
2012-07-15 17:17:49 +00:00
|
|
|
#elif defined(PLATFORM_LINUX)
|
2012-06-26 20:23:05 +00:00
|
|
|
return SystemDialog_Linux(type, title, message);
|
2012-07-15 17:17:49 +00:00
|
|
|
#else
|
2012-06-26 20:23:05 +00:00
|
|
|
return SystemDialog_Other(type, title, message);
|
2012-07-15 17:17:49 +00:00
|
|
|
#endif
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
2012-07-15 17:17:49 +00:00
|
|
|
SystemTimeStamp* CreateTimeStamp()
|
2012-06-25 17:59:17 +00:00
|
|
|
{
|
2012-07-15 17:17:49 +00:00
|
|
|
return new SystemTimeStamp();
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
2012-07-15 17:17:49 +00:00
|
|
|
void DestroyTimeStamp(SystemTimeStamp *stamp)
|
2012-06-25 17:59:17 +00:00
|
|
|
{
|
2012-07-15 17:17:49 +00:00
|
|
|
delete stamp;
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
2012-07-15 17:17:49 +00:00
|
|
|
void CopyTimeStamp(SystemTimeStamp *dst, SystemTimeStamp *src)
|
2012-06-25 17:59:17 +00:00
|
|
|
{
|
2012-07-15 17:17:49 +00:00
|
|
|
*dst = *src;
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
2012-07-15 17:17:49 +00:00
|
|
|
void GetCurrentTimeStamp(SystemTimeStamp *stamp)
|
|
|
|
{
|
|
|
|
#if defined(PLATFORM_WINDOWS)
|
|
|
|
GetCurrentTimeStamp_Windows(stamp);
|
2012-06-25 17:59:17 +00:00
|
|
|
#elif defined(PLATFORM_LINUX)
|
2012-07-15 17:17:49 +00:00
|
|
|
GetCurrentTimeStamp_Linux(stamp);
|
|
|
|
#else
|
|
|
|
GetCurrentTimeStamp_Other(stamp);
|
|
|
|
#endif
|
|
|
|
}
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-07-15 17:17:49 +00:00
|
|
|
float GetTimeStampResolution(SystemTimeUnit unit)
|
2012-06-25 17:59:17 +00:00
|
|
|
{
|
2012-07-15 17:17:49 +00:00
|
|
|
unsigned long long exact = 0;
|
|
|
|
#if defined(PLATFORM_WINDOWS)
|
|
|
|
exact = GetTimeStampExactResolution_Windows();
|
|
|
|
#elif defined(PLATFORM_LINUX)
|
|
|
|
exact = GetTimeStampExactResolution_Linux();
|
|
|
|
#else
|
|
|
|
exact = GetTimeStampExactResolution_Other();
|
|
|
|
#endif
|
|
|
|
float result = 0.0f;
|
|
|
|
if (unit == STU_SEC)
|
|
|
|
result = exact * 1e-9;
|
|
|
|
else if (unit == STU_MSEC)
|
|
|
|
result = exact * 1e-6;
|
|
|
|
else if (unit == STU_USEC)
|
|
|
|
result = exact * 1e-3;
|
|
|
|
else
|
|
|
|
assert(false);
|
2012-06-26 20:23:05 +00:00
|
|
|
return result;
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
2012-07-15 17:17:49 +00:00
|
|
|
long long GetTimeStampExactResolution()
|
|
|
|
{
|
|
|
|
#if defined(PLATFORM_WINDOWS)
|
|
|
|
return GetTimeStampExactResolution_Windows();
|
|
|
|
#elif defined(PLATFORM_LINUX)
|
|
|
|
return GetTimeStampExactResolution_Linux();
|
2012-06-25 17:59:17 +00:00
|
|
|
#else
|
2012-07-15 17:17:49 +00:00
|
|
|
return GetTimeStampExactResolution_Other();
|
|
|
|
#endif
|
|
|
|
}
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-07-15 17:17:49 +00:00
|
|
|
float TimeStampDiff(SystemTimeStamp *before, SystemTimeStamp *after, SystemTimeUnit unit)
|
2012-06-25 17:59:17 +00:00
|
|
|
{
|
2012-07-15 17:17:49 +00:00
|
|
|
long long exact = 0;
|
|
|
|
#if defined(PLATFORM_WINDOWS)
|
|
|
|
exact = TimeStampExactDiff_Windows(before, after);
|
|
|
|
#elif defined(PLATFORM_LINUX)
|
|
|
|
exact = TimeStampExactDiff_Linux(before, after);
|
|
|
|
#else
|
|
|
|
exact = TimeStampExactDiff_Other(before, after);
|
|
|
|
#endif
|
|
|
|
float result = 0.0f;
|
|
|
|
if (unit == STU_SEC)
|
|
|
|
result = exact * 1e-9;
|
|
|
|
else if (unit == STU_MSEC)
|
|
|
|
result = exact * 1e-6;
|
|
|
|
else if (unit == STU_USEC)
|
|
|
|
result = exact * 1e-3;
|
|
|
|
else
|
|
|
|
assert(false);
|
2012-06-26 20:23:05 +00:00
|
|
|
return result;
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
2012-07-15 17:17:49 +00:00
|
|
|
|
|
|
|
long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after)
|
|
|
|
{
|
|
|
|
#if defined(PLATFORM_WINDOWS)
|
|
|
|
return TimeStampExactDiff_Windows(before, after);
|
|
|
|
#elif defined(PLATFORM_LINUX)
|
|
|
|
return TimeStampExactDiff_Linux(before, after);
|
|
|
|
#else
|
|
|
|
return TimeStampExactDiff_Other(before, after);
|
|
|
|
#endif
|
|
|
|
}
|