
#pragma once
#include <DxLib.h>

namespace DXFW
{
///	<summary>時間と日付のクラス</summary>
///	<example>
///	[サンプルコード:未完成]<br></br>
/// サンプル説明
///	<code>
///	int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow )<br></br>
///	{<br></br>
///		if( !Dx::Initialise() ) return -1;<br></br>
///		Dx::End();<br></br>
///		return 0;<br></br>
/// }<br></br>
/// </code>
/// </example>
class Time
{
private:
	int count;
	double hiCount;
	DATEDATA date;		
	double prevTime;
	double fps;
	double start;

	Time(void)
	{
		this->ResetCount();
	}
	~Time(void){};

	static Time& Single()
	{
		static Time value;
		return value;
	}

public:
	
	///<summary>時間の初期化</summary>
	static bool ResetCount()
	{
		Single().count   = DxLib::GetNowCount();
		Single().hiCount = double(DxLib::GetNowHiPerformanceCount())/1000;
		return true;
	}
	
	///<summary>リセット後の経過時間をミリ秒で取得</summary>
	static int GetNowCount()
	{
		return DxLib::GetNowCount() - Single().count;
	}
	
	///<summary>リセット後の経過時間のミリ秒で取得(小数点以下)</summary>
	static double GetDoubleCount()
	{
		return double(DxLib::GetNowHiPerformanceCount())/1000 - Single().hiCount;
	}

	///<summary>日付を取得</summary>
	static DATEDATA GetDate()
	{
		DxLib::GetDateTime( &Single().date );
		return Single().date;
	}
	
	///<summary>FPSを取得</summary>
	static double GetFPS()
	{
		return Single().fps;
	}
	
	///<summary>FPSの計測開始</summary>
	static void ResetFPS()
	{
		Single().prevTime = double(GetNowHiPerformanceCount()/1000);
	}
	
	///<summary>FPS計測を更新</summary>
	static void CheckFPS()
	{
		Single().fps = 1000000.0 / ( GetNowHiPerformanceCount() - Single().prevTime*1000 );
		Single().prevTime = double(GetNowHiPerformanceCount())/1000;
	}
	
	///<summary>処理時間計測開始</summary>
	static void StartWatch()
	{
		Single().start = double(GetNowHiPerformanceCount())/1000;
	}
	
	///<summary>処理時間計測終了</summary>
	///StartWatchからの経過時間をミリ秒単位で描画
	///続けてDrawWatchする事も可能
	static void DrawWatch(int x , int y , const char* str)
	{
		std::string buf = str;
		buf += " = %f";

		Drawing::String( x , y , Color::White , buf.c_str() , (double)(GetNowHiPerformanceCount() - Single().start*1000) / 1000 );
		Single().start = 0;
	}
};

}