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

Timer.cpp

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  * タイマ実装
00022  * @author Junpee
00023  */
00024 
00025 #include <windows.h>
00026 #include "LampBasic.h"
00027 #include "Core/Utility/Timer.h"
00028 #include "Core/Debug/ErrorOutput.h"
00029 
00030 namespace Lamp{
00031 
00032 // 1msあたりのクロック数
00033 float Timer::tickPerMillisecond_ = 0.f;
00034 
00035 // 初期化済みフラグ
00036 bool Timer::initialized_ = false;
00037 
00038 //------------------------------------------------------------------------------
00039 // 初期化
00040 void Timer::initialize(){
00041     if(initialized_){ return; }
00042     Tick frequencyValue;
00043     BOOL success = QueryPerformanceFrequency((LARGE_INTEGER*)&frequencyValue);
00044     if(success){
00045         tickPerMillisecond_ = (float)(frequencyValue.tick / 1000.f);
00046     }else{
00047         ErrorOut("高精度タイマの初期化に失敗しました。");
00048         return;
00049     }
00050     initialized_ = true;
00051 }
00052 //------------------------------------------------------------------------------
00053 // 時間の取得
00054 Timer::Tick Timer::getTick(){
00055     Tick tick;
00056     QueryPerformanceCounter((LARGE_INTEGER*)&tick);
00057     return tick;
00058 }
00059 //------------------------------------------------------------------------------
00060 // 時間間隔の取得
00061 float Timer::getInterval(const Tick& previousTick){
00062     Tick nowTick = getTick();
00063     return (nowTick.tick - previousTick.tick) / tickPerMillisecond_;
00064 }
00065 //------------------------------------------------------------------------------
00066 // 時間間隔の取得
00067 float Timer::getInterval(const Tick& previousTick, const Tick& afterTick){
00068     return (afterTick.tick - previousTick.tick) / tickPerMillisecond_;
00069 }
00070 //------------------------------------------------------------------------------
00071 } // End of namespace Lamp
00072 //------------------------------------------------------------------------------

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