/* Delay execution to maintain a constant framerate and calculate fps. 
Generate a delay to accomodate currently set framerate. Call once in the graphics/rendering loop. If the computer cannot keep up with the rate (i.e. drawing too slow), the delay is zero and the delay interpolation is reset. */
Uint32 SDL_framerateDelay(FPSmanager *manager)
/* Delay execution to maintain a constant framerate and calculate fps. 
Generate a delay to accomodate currently set framerate. Call once in the graphics/rendering loop. If the computer cannot keep up with the rate (i.e. drawing too slow), the delay is zero and the delay interpolation is reset. */
Uint32 SDL_framerateDelay(FPSmanager *manager)
{
	Uint32 current_ticks;
	Uint32 target_ticks;
	Uint32 the_delay;
	Uint32 time_passed = 0;
	if (manager == NULL) {
		return 0;
	}
	if (manager->baseticks == 0) {
		SDL_initFramerate(manager);
	}
	manager->framecount++;
	current_ticks = _getTicks();
	time_passed = current_ticks - manager->lastticks;
	manager->lastticks = current_ticks;
	target_ticks = manager->baseticks + (Uint32) ((float) manager->framecount * manager->rateticks);
	if (current_ticks <= target_ticks) {
		the_delay = target_ticks - current_ticks;
		SDL_Delay(the_delay);
	} else {
		manager->framecount = 0;
		manager->baseticks = _getTicks();
	}
	return time_passed;
}