/***************************************************************************/
/** @file       fps_counter.cpp
    @brief      
    @author     shom
    @internal
----------------------------------------------------------------------------
    $id
****************************************************************************/

#include "pch_core.h"

#include "fps_counter.h"

#ifdef _DEBUG

#include "core/font/Font_Def.h"


///--	グローバル変数，実体定義

namespace
{
	u32	s_uTimeBefore = timeGetTime();
	u32	s_uCounter = 0;
	
	u32	s_uFps = 0;

	font_def::FontContext_t	s_FontCntext;
}

///--


/**
 * 初期処理
 */
void	fps_counter::fps_counter_init()
{
	s_FontCntext.uPosX = 10;
	s_FontCntext.uPosY = 10;
	s_FontCntext.v2Size = mm::get_v2_all( 20.f );
	s_FontCntext.uColor = COLOR_WHITE;
}

/**
 * FPS計測 
 */
namespace
{
	const u32 sc_uTimeMeasuringInterval = 1000;
}

void	fps_counter::fps_counter_update()
{
	///--	count
	++s_uCounter;
	///--

	///--	measure fps
	ct u32 uTimeNow = timeGetTime();
	ct u32 uTimeElapsed = uTimeNow - s_uTimeBefore;

	if( uTimeElapsed >= sc_uTimeMeasuringInterval )
	{
		//--	calculate
		s_uFps = sc_uTimeMeasuringInterval * s_uCounter / uTimeElapsed + 1/*小数点以下切り上げ還元*/;
		//--

		//--	clear
		s_uTimeBefore = uTimeNow;
		s_uCounter = 0;
		//--
	}
	///--
}

/**
 * FPSテキスト描画
 */
u32		fps_counter::fps_counter_get()
{
	return s_uFps;
}

#endif
