diff options
author | Piotr Dziwinski <piotrdz@gmail.com> | 2013-03-24 00:03:37 +0100 |
---|---|---|
committer | Piotr Dziwinski <piotrdz@gmail.com> | 2013-03-24 12:00:12 +0100 |
commit | 195d6cded05f7ef5bde695ee047b341a0265eab3 (patch) | |
tree | af6ffa3622ae9bf7f2f5f065e269e86a019af854 /src/app/system.h | |
parent | c211b001d2a4c9b36034a812650f1a2ac693ee54 (diff) | |
download | colobot-195d6cded05f7ef5bde695ee047b341a0265eab3.tar.gz colobot-195d6cded05f7ef5bde695ee047b341a0265eab3.tar.bz2 colobot-195d6cded05f7ef5bde695ee047b341a0265eab3.zip |
Fixed timer functions on win32
* changed win32 implementation to QueryPerformaceTimer system function
* refactored system utils code
* proper tests for time utils and update event creation in application
* should fix issue #134
Diffstat (limited to 'src/app/system.h')
-rw-r--r-- | src/app/system.h | 90 |
1 files changed, 60 insertions, 30 deletions
diff --git a/src/app/system.h b/src/app/system.h index e216842..278a4bf 100644 --- a/src/app/system.h +++ b/src/app/system.h @@ -22,12 +22,10 @@ #pragma once +#include "common/singleton.h" #include <string> - -/* Dialog utils */ - /** * \enum SystemDialogType * \brief Type of system dialog @@ -60,12 +58,10 @@ enum SystemDialogResult SDR_NO }; -//! Displays a system dialog -SystemDialogResult SystemDialog(SystemDialogType, const std::string &title, const std::string &message); - - -/* Time utils */ - +/** + * \enum SystemTimeUnit + * \brief Time unit + */ enum SystemTimeUnit { //! seconds @@ -76,33 +72,67 @@ enum SystemTimeUnit STU_USEC }; -/* Forward declaration of time stamp struct - * SystemTimeStamp should be used in a pointer context. - * The implementation details are hidden because of platform dependence. */ +/* + * Forward declaration of time stamp struct + * SystemTimeStamp should only be used in a pointer context. + * The implementation details are hidden because of platform dependence. + */ struct SystemTimeStamp; -//! Creates a new time stamp object -SystemTimeStamp* CreateTimeStamp(); +/** + * \class CSystemUtils + * \brief Platform-specific utils + * + * This class provides system-specific utilities like displaying user dialogs and + * querying system timers for exact timestamps. + */ +class CSystemUtils : public CSingleton<CSystemUtils> +{ +protected: + CSystemUtils(); + +public: + //! Creates system utils for specific platform + static CSystemUtils* Create(); + + //! Performs platform-specific initialization + virtual void Init() = 0; + + //! Displays a system dialog + virtual SystemDialogResult SystemDialog(SystemDialogType, const std::string &title, const std::string &message) = 0; -//! Destroys a time stamp object -void DestroyTimeStamp(SystemTimeStamp *stamp); + //! Displays a fallback system dialog using console + TEST_VIRTUAL SystemDialogResult ConsoleSystemDialog(SystemDialogType type, const std::string& title, const std::string& message); -//! Copies the time stamp from \a src to \a dst -void CopyTimeStamp(SystemTimeStamp *dst, SystemTimeStamp *src); + //! Creates a new time stamp object + TEST_VIRTUAL SystemTimeStamp* CreateTimeStamp(); -//! Returns a time stamp associated with current time -void GetCurrentTimeStamp(SystemTimeStamp *stamp); + //! Destroys a time stamp object + TEST_VIRTUAL void DestroyTimeStamp(SystemTimeStamp *stamp); -//! Returns the platform's expected time stamp resolution -float GetTimeStampResolution(SystemTimeUnit unit = STU_SEC); + //! Copies the time stamp from \a src to \a dst + TEST_VIRTUAL void CopyTimeStamp(SystemTimeStamp *dst, SystemTimeStamp *src); -//! Returns the platform's exact (in nanosecond units) expected time stamp resolution -long long GetTimeStampExactResolution(); + //! Returns a time stamp associated with current time + virtual void GetCurrentTimeStamp(SystemTimeStamp *stamp) = 0; -//! Returns a difference between two timestamps in given time unit -/** The difference is \a after - \a before. */ -float TimeStampDiff(SystemTimeStamp *before, SystemTimeStamp *after, SystemTimeUnit unit = STU_SEC); + //! Returns the platform's expected time stamp resolution + TEST_VIRTUAL float GetTimeStampResolution(SystemTimeUnit unit = STU_SEC); -//! Returns the exact (in nanosecond units) difference between two timestamps -/** The difference is \a after - \a before. */ -long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after); + //! Returns the platform's exact (in nanosecond units) expected time stamp resolution + virtual long long GetTimeStampExactResolution() = 0; + + //! Returns a difference between two timestamps in given time unit + /** The difference is \a after - \a before. */ + TEST_VIRTUAL float TimeStampDiff(SystemTimeStamp *before, SystemTimeStamp *after, SystemTimeUnit unit = STU_SEC); + + //! Returns the exact (in nanosecond units) difference between two timestamps + /** The difference is \a after - \a before. */ + virtual long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after) = 0; +}; + +//! Global function to get CSystemUtils instance +inline CSystemUtils* GetSystemUtils() +{ + return CSystemUtils::GetInstancePointer(); +} |