This is an automated email from the git hooks/post-receive script. odyx pushed a commit to branch upstream/latest in repository colobot.
commit d003247120e43853eacd5a6c32ed4bd80993a2f8 Author: Piotr Dziwinski <piot...@gmail.com> Date: Mon Apr 27 18:35:41 2015 +0200 Provide usleep() in CSystemUtils interface --- src/app/app.cpp | 11 +++++------ src/app/system.h | 3 +++ src/app/system_linux.cpp | 6 ++++++ src/app/system_linux.h | 2 ++ src/app/system_macosx.cpp | 6 ++++++ src/app/system_macosx.h | 3 +++ src/app/system_other.cpp | 4 ++++ src/app/system_other.h | 2 ++ src/app/system_windows.cpp | 11 +++++++++++ src/app/system_windows.h | 2 ++ test/unit/app/system_mock.h | 1 + 11 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index b642cc0..5f98b4c 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -52,7 +52,6 @@ #include <stdlib.h> #include <libintl.h> -#include <unistd.h> #include <getopt.h> #include <localename.h> @@ -169,7 +168,7 @@ CApplication::~CApplication() { delete m_private; m_private = nullptr; - + delete m_input; m_input = nullptr; @@ -394,7 +393,7 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) std::string w, h; std::getline(resolution, w, 'x'); std::getline(resolution, h, 'x'); - + m_deviceConfig.size.x = atoi(w.c_str()); m_deviceConfig.size.y = atoi(h.c_str()); m_resolutionOverride = true; @@ -539,7 +538,7 @@ bool CApplication::Create() m_exitCode = 4; return false; } - + SDL_WM_SetCaption(m_windowTitle.c_str(), m_windowTitle.c_str()); } @@ -1009,7 +1008,7 @@ int CApplication::Run() if (m_lowCPU) { - usleep(20000); // should still give plenty of fps + GetSystemUtils()->Usleep(20000); // should still give plenty of fps } } } @@ -1134,7 +1133,7 @@ Event CApplication::ProcessSystemEvent() event.active.gain = m_private->currentEvent.active.gain == 1; } - + m_input->EventProcess(event); return event; diff --git a/src/app/system.h b/src/app/system.h index d52020b..327f60d 100644 --- a/src/app/system.h +++ b/src/app/system.h @@ -140,6 +140,9 @@ public: //! Returns the save dir location virtual std::string GetSaveDir(); + + //! Sleep for given amount of microseconds + virtual void Usleep(int usecs) = 0; }; //! Global function to get CSystemUtils instance diff --git a/src/app/system_linux.cpp b/src/app/system_linux.cpp index 6fbfb05..1a1b76d 100644 --- a/src/app/system_linux.cpp +++ b/src/app/system_linux.cpp @@ -22,6 +22,7 @@ #include "common/logger.h" #include <stdlib.h> +#include <unistd.h> void CSystemUtilsLinux::Init() @@ -123,3 +124,8 @@ std::string CSystemUtilsLinux::GetSaveDir() return savegameDir; } + +void CSystemUtilsLinux::Usleep(int usec) +{ + usleep(usec); +} diff --git a/src/app/system_linux.h b/src/app/system_linux.h index d8654f9..b60954e 100644 --- a/src/app/system_linux.h +++ b/src/app/system_linux.h @@ -50,6 +50,8 @@ public: virtual std::string GetSaveDir() OVERRIDE; + virtual void Usleep(int usec) OVERRIDE; + private: bool m_zenityAvailable; }; diff --git a/src/app/system_macosx.cpp b/src/app/system_macosx.cpp index 208b4a7..ebd1846 100644 --- a/src/app/system_macosx.cpp +++ b/src/app/system_macosx.cpp @@ -22,6 +22,7 @@ #include "common/logger.h" #include <stdlib.h> +#include <unistd.h> // MacOS-specific headers #include <CoreFoundation/CFBundle.h> @@ -106,3 +107,8 @@ std::string CSystemUtilsMacOSX::GetSaveDir() return savegameDir; } + +void CSystemUtilsMacOSX::Usleep(int usec) +{ + usleep(usec); +} diff --git a/src/app/system_macosx.h b/src/app/system_macosx.h index f3d8734..a853ae4 100644 --- a/src/app/system_macosx.h +++ b/src/app/system_macosx.h @@ -33,6 +33,9 @@ public: virtual std::string GetDataPath() OVERRIDE; virtual std::string GetLangPath() OVERRIDE; virtual std::string GetSaveDir() OVERRIDE; + + virtual void Usleep(int usec) OVERRIDE; + private: std::string m_ASPath; std::string m_dataPath; diff --git a/src/app/system_other.cpp b/src/app/system_other.cpp index c21314c..bedeb23 100644 --- a/src/app/system_other.cpp +++ b/src/app/system_other.cpp @@ -40,3 +40,7 @@ long long int CSystemUtilsOther::TimeStampExactDiff(SystemTimeStamp* before, Sys return (after->sdlTicks - before->sdlTicks) * 1000000ll; } +void CSystemUtilsOther::Usleep(int usec) +{ + SDL_Delay(usec / 1000); // close enough +} diff --git a/src/app/system_other.h b/src/app/system_other.h index db2d0f3..862f63e 100644 --- a/src/app/system_other.h +++ b/src/app/system_other.h @@ -48,5 +48,7 @@ public: virtual void GetCurrentTimeStamp(SystemTimeStamp *stamp) OVERRIDE; virtual long long int GetTimeStampExactResolution() OVERRIDE; virtual long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after) OVERRIDE; + + virtual void Usleep(int usec) OVERRIDE; }; diff --git a/src/app/system_windows.cpp b/src/app/system_windows.cpp index bc1fed9..e16b65a 100644 --- a/src/app/system_windows.cpp +++ b/src/app/system_windows.cpp @@ -130,3 +130,14 @@ std::string CSystemUtilsWindows::GetSaveDir() return savegameDir; } + +void CSystemUtilsWindows::Usleep(int usec) +{ + LARGE_INTEGER ft; + ft.QuadPart = -(10 * usec); // Convert to 100 nanosecond interval, negative value indicates relative time + + HANDLE timer = CreateWaitableTimer(NULL, TRUE, NULL); + SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0); + WaitForSingleObject(timer, INFINITE); + CloseHandle(timer); +} diff --git a/src/app/system_windows.h b/src/app/system_windows.h index 538cfda..e5141cb 100644 --- a/src/app/system_windows.h +++ b/src/app/system_windows.h @@ -48,6 +48,8 @@ public: virtual std::string GetSaveDir() OVERRIDE; + virtual void Usleep(int usec) OVERRIDE; + public: static std::string UTF8_Encode(const std::wstring &wstr); static std::wstring UTF8_Decode(const std::string &str); diff --git a/test/unit/app/system_mock.h b/test/unit/app/system_mock.h index 2f2c464..ac7e590 100644 --- a/test/unit/app/system_mock.h +++ b/test/unit/app/system_mock.h @@ -63,4 +63,5 @@ public: MOCK_METHOD0(GetTimeStampExactResolution, long long()); MOCK_METHOD3(TimeStampDiff, float(SystemTimeStamp *before, SystemTimeStamp *after, SystemTimeUnit unit)); MOCK_METHOD2(TimeStampExactDiff, long long(SystemTimeStamp *before, SystemTimeStamp *after)); + MOCK_METHOD1(Usleep, void(int usec)); }; -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git _______________________________________________ Pkg-games-commits mailing list Pkg-games-commits@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-games-commits