//------------------------------------------------------------------------------
// Lamp : Open source game middleware
// Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//------------------------------------------------------------------------------

/** @file
 * FPS計測実装
 * @author Junpee
 */

#include "LampBasic.h"
#include "Core/Utility/FPSMeasurement.h"

namespace Lamp{

//------------------------------------------------------------------------------
// コンストラクタ
FPSMeasurement::FPSMeasurement(){
	reset();
}
//------------------------------------------------------------------------------
// デストラクタ
FPSMeasurement::~FPSMeasurement(){
}
//------------------------------------------------------------------------------
// リセット
void FPSMeasurement::reset(){
	fps_ = 0.f;
	lastTime_ = Timer::getTick();
	frameCount_ = 0;
}
//------------------------------------------------------------------------------
// 計測
float FPSMeasurement::measurement(){
	Timer::Tick nowTime = Timer::getTick();
	float time = Timer::getInterval(lastTime_, nowTime);
	frameCount_++;
	// 一秒平均を取る
	if(time > 1000.f){
		fps_ = frameCount_ * 1000.f / time;
		lastTime_ = nowTime;
		frameCount_ = 0;
	}
	return fps_;
}
//------------------------------------------------------------------------------
} // End of namespace Lamp
//------------------------------------------------------------------------------
