Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

FPSController.h

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 // Lamp : Open source game middleware
00003 // Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
00004 //
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 //------------------------------------------------------------------------------
00019 
00020 /** @file
00021  * FPSコントローラヘッダ
00022  * @author Junpee
00023  */
00024 
00025 #ifndef FPS_CONTROLLER_H_
00026 #define FPS_CONTROLLER_H_
00027 
00028 #include <Core/Utility/Timer.h>
00029 #include <Core/Thread/CriticalSection.h>
00030 #include <Core/Container/Deque.h>
00031 
00032 namespace Lamp{
00033 
00034 class Thread;
00035 
00036 //------------------------------------------------------------------------------
00037 /**
00038  * FPSコントローラ
00039  */
00040 class FPSController{
00041 public:
00042     /// 60FPS
00043     static const float interval60FPS;
00044     /// 30FPS
00045     static const float interval30FPS;
00046 
00047     /**
00048      * コンストラクタ
00049      * @param targetInterval 目標時間間隔をミリ秒で指定
00050      */
00051     FPSController(float targetInterval = interval60FPS);
00052 
00053     /**
00054      * デストラクタ
00055      */
00056     virtual ~FPSController();
00057 
00058     //--------------------------------------------------------------------------
00059     /**
00060      * 目標時間間隔の設定
00061      * @param targetInterval 目標時間間隔をミリ秒で指定
00062      */
00063     virtual void setTargetInterval(float targetInterval){
00064         targetInterval_ = targetInterval;
00065         sleepTime_ = targetInterval_;
00066         intervalTime_ = targetInterval_;
00067     }
00068 
00069     /**
00070      * 目標時間間隔の取得
00071      * @return 目標時間間隔をミリ秒で返す
00072      */
00073     virtual float getTargetInterval() const{ return targetInterval_; }
00074 
00075     /**
00076      * FPSを維持するためにカレントスレッドをsleepする
00077      * @return 前回のsleepとの時間間隔
00078      */
00079     virtual float sleep();
00080 
00081     /**
00082      * インターバルの取得
00083      * @return インターバルをミリ秒で取得
00084      */
00085     virtual float getIntervalTime() const{ return intervalTime_; }
00086 
00087     /**
00088      * スリープ時間の取得
00089      * @return スリープ時間をミリ秒で取得
00090      */
00091     virtual float getSleepTime() const{ return sleepTime_; }
00092 
00093     /**
00094      * 処理時間の取得
00095      * @return 処理時間をミリ秒で取得
00096      */
00097     virtual float getProcessingTime() const{
00098         return intervalTime_ - sleepTime_;
00099     }
00100 
00101     /**
00102      * 処理割合の取得
00103      * @return 処理割合
00104      */
00105     virtual float getProcessingRate() const{
00106         return getProcessingTime() / getIntervalTime();
00107     }
00108 
00109     //--------------------------------------------------------------------------
00110     /**
00111      * バックグラウンドスレッドの登録
00112      * @param backgroundThread バックグラウンドスレッド
00113      */
00114     virtual void registerBackgroundThread(Thread* backgroundThread);
00115 
00116     /**
00117      * バックグラウンドスレッド数の取得
00118      * @return バックグラウンドスレッド数
00119      */
00120     virtual int getBackgroundThreadCount();
00121 
00122     /**
00123      * バックグラウンドスレッド数の取得
00124      * @param index インデックス
00125      * @return バックグラウンドスレッド数
00126      */
00127     virtual Thread* getBackgroundThread(int index);
00128 
00129     //--------------------------------------------------------------------------
00130     /**
00131      * 文字列への変換
00132      * @return 文字列
00133      */
00134     virtual String toString() const;
00135 
00136 private:
00137     // コピーコンストラクタの隠蔽
00138     FPSController(const FPSController& copy);
00139 
00140     // 代入コピーの隠蔽
00141     void operator =(const FPSController& copy);
00142 
00143     // バックグラウンドスレッド
00144     Deque<Thread*> backgroundThreads_;
00145     // クリティカルセクション
00146     CriticalSection criticalSection_;
00147     // 時間
00148     Timer::Tick tick_;
00149     // 間隔
00150     float intervalTime_;
00151     // ターゲット間隔
00152     float targetInterval_;
00153     // sleep時間
00154     float sleepTime_;
00155 };
00156 
00157 //------------------------------------------------------------------------------
00158 } // End of namespace Lamp
00159 #endif // End of FPS_CONTROLLER_H_
00160 //------------------------------------------------------------------------------
00161 

Generated on Wed Mar 16 10:29:30 2005 for Lamp by doxygen 1.3.2