diff options
author | Piotr Dziwinski <piotrdz@gmail.com> | 2013-03-30 15:01:00 +0100 |
---|---|---|
committer | Piotr Dziwinski <piotrdz@gmail.com> | 2013-03-30 15:23:05 +0100 |
commit | e218dcfdf2c58f8841e7ebd220527d08e870a6d5 (patch) | |
tree | a567db04a8a51e2db87f80e259faf222a7d4becd /src/app/system.h | |
parent | bfc701e286259d9a7aa2ff8240704eab2ba3a237 (diff) | |
parent | e607fed265070be8c518d4302d8b76f738421fb3 (diff) | |
download | colobot-e218dcfdf2c58f8841e7ebd220527d08e870a6d5.tar.gz colobot-e218dcfdf2c58f8841e7ebd220527d08e870a6d5.tar.bz2 colobot-e218dcfdf2c58f8841e7ebd220527d08e870a6d5.zip |
Merge branch 'dev'
Merging content from dev
Diffstat (limited to 'src/app/system.h')
-rw-r--r-- | src/app/system.h | 96 |
1 files changed, 66 insertions, 30 deletions
diff --git a/src/app/system.h b/src/app/system.h index e216842..6ae05d6 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,73 @@ 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; + + //! Displays a fallback system dialog using console + TEST_VIRTUAL SystemDialogResult ConsoleSystemDialog(SystemDialogType type, const std::string& title, const std::string& message); + + //! Creates a new time stamp object + TEST_VIRTUAL SystemTimeStamp* CreateTimeStamp(); -//! Destroys a time stamp object -void DestroyTimeStamp(SystemTimeStamp *stamp); + //! Destroys a time stamp object + TEST_VIRTUAL void DestroyTimeStamp(SystemTimeStamp *stamp); -//! Copies the time stamp from \a src to \a dst -void CopyTimeStamp(SystemTimeStamp *dst, SystemTimeStamp *src); + //! Copies the time stamp from \a src to \a dst + TEST_VIRTUAL void CopyTimeStamp(SystemTimeStamp *dst, SystemTimeStamp *src); -//! Returns a time stamp associated with current time -void GetCurrentTimeStamp(SystemTimeStamp *stamp); + //! Returns a time stamp associated with current time + virtual void GetCurrentTimeStamp(SystemTimeStamp *stamp) = 0; -//! Returns the platform's expected time stamp resolution -float GetTimeStampResolution(SystemTimeUnit unit = STU_SEC); + //! Returns the platform's expected time stamp resolution + TEST_VIRTUAL float GetTimeStampResolution(SystemTimeUnit unit = STU_SEC); -//! Returns the platform's exact (in nanosecond units) expected time stamp resolution -long long GetTimeStampExactResolution(); + //! 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. */ -float TimeStampDiff(SystemTimeStamp *before, SystemTimeStamp *after, SystemTimeUnit unit = STU_SEC); + //! 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. */ -long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after); + //! 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; + + //! Returns the profile (colobot.ini) file location + virtual std::string profileFileLocation(); + + //! Returns the savegame directory location + virtual std::string savegameDirectoryLocation(); +}; + +//! Global function to get CSystemUtils instance +inline CSystemUtils* GetSystemUtils() +{ + return CSystemUtils::GetInstancePointer(); +} |