
#include "stdafx.h"
#include "CFps.h"

C_FPS_0::C_FPS_0()
{
	_stary_cas=0;
	// Zjisteni pouziti
	LARGE_INTEGER dwFreq;
	if( !QueryPerformanceFrequency(&dwFreq) )
	{
		// error
	}
}

void C_FPS_0::Vypocet()
{
	QueryPerformanceCounter((LARGE_INTEGER*)&_aktualni_cas);
	LARGE_INTEGER dwFreq;
	QueryPerformanceFrequency(&dwFreq);

	double dDiff = (double) (_aktualni_cas - _stary_cas) / dwFreq.QuadPart * 1000;
	_fps = (1.0f / dDiff)*1000;// Počet snímků za sekundu

	static double dFpsPole[50];
	static int iCitac=0;
	if(iCitac >= 50) iCitac = 0;
	dFpsPole[iCitac] = _fps;						   
	iCitac++;

	double celek=0;
	for(register i=0; i < 50; i++)
	{
		celek += dFpsPole[i];
	}
	celek /= 50;
	_fps = celek;
	// Zapis
/*	FILE *soubor;
	soubor = fopen("test.txt", "a+wt");
	fprintf(soubor, "fps : %f - %f\n", _fps, celek);
	fclose(soubor);*/
	_stary_cas = _aktualni_cas;// Pro další průchod
	
}

//////////////////////////////////////////////////////////////////////////
// TIMER
//////////////////////////////////////////////////////////////////////////

CTimer::CTimer()
{
	_staryCas = 0;	
}

int CTimer::GetCas()
{
	int ret=0;
	_aktCas = timeGetTime();
	if( _staryCas != 0 ) ret = _aktCas - _staryCas;
	_staryCas = _aktCas;
	return ret;
}