Develop and Download Open Source Software

Browse Subversion Repository

Contents of /common/Delay.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 272 - (show annotations) (download) (as text)
Sat Mar 8 20:51:59 2008 UTC (16 years, 1 month ago) by satofumi
File MIME type: text/x-c++src
File size: 1073 byte(s)
Visual Studio 2005 の警告を修正。
1 /*!
2 \file
3 \brief 遅延時間を制御可能な delay() 関数
4
5 \author Satofumi KAMIMURA
6
7 $Id$
8 */
9
10 #include "Delay.h"
11 #include "SdlInit.h"
12 #include "LockGuard.h"
13 #include "DetectOS.h"
14
15
16 using namespace beego;
17
18
19 static double WaitRatio = 1.0;
20 static SDL_mutex* Mutex = NULL;
21
22 /*!
23 \brief SdlInit の初期化クラス
24 */
25 class SdlInitClass : private SdlInit {
26 };
27
28 static void mutexInitialize(void) {
29 static SdlInitClass sdl_init;
30 static SDL_mutex* obj = SDL_CreateMutex();
31 if (Mutex == NULL) {
32 Mutex = obj;
33 }
34 }
35
36
37 /*!
38 \brief 待機関数
39
40 指定時間だけ待機する。
41
42 \param msec [i] 待機時間 [msec]
43 */
44 void beego::delay(size_t msec) {
45 mutexInitialize();
46
47 LockMutex(Mutex);
48 unsigned long delay_msec =
49 static_cast<unsigned long>(msec * WaitRatio);
50 UnlockMutex(Mutex);
51
52 SDL_Delay(delay_msec);
53 }
54
55
56 /*!
57 \brief 時間の進行比率を設定
58
59 モニタ機能にて、早送りなどを実現するのに利用する。
60
61 \param ratio [i] 時間のすすみ具合。2.0 だと2倍速
62 */
63 void setDelayRatio(double ratio) {
64 mutexInitialize();
65
66 LockMutex(Mutex);
67 WaitRatio = ratio;
68 UnlockMutex(Mutex);
69 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26