#include <SDL/SDL.h>

int fps=0, mo=0, nframe=0, atime=0;
int frametime;

int iter_timer = 0;
float iter_scale = 1.0f;

// ===============
// ==== Timer ====
// ===============

int Ticks()
{
	return (int)SDL_GetTicks();
}

void SpeedDown(int ticks)
{
    do{}while(Ticks() - frametime < ticks);
    frametime = Ticks();
}

float GetIterScale()
{
	return iter_scale;
}

bool IsIterReady(int ticks)
{
	float ticks_passed = (float)(Ticks() - iter_timer);
	if (ticks_passed > ticks)
	{
		iter_timer = Ticks();
		iter_scale = ticks_passed / (float)ticks;
		return true;
	}
	else
		return false;
}

int CountFPS()
{
    if (Ticks()-atime>=1000)
    {
		atime = Ticks();
		mo=(nframe-fps);
        fps=nframe;
		printf("%d\n",mo);
    }
    return mo;
}

float GetInterval(float atime, float midtime, float btime)
{
	return (midtime - atime) / (btime - atime);
}
