/*
Martin Robinson
librairie SDL
=============================
préprocesseur
*/

#pragma once
#ifndef sdlMR_deja
#define sdlMR_deja
#include "sdl/SDL.h"
#include <iostream>

using namespace std;

/*
=============================
fonction
*/

template <unsigned char _R, unsigned char _G, unsigned char _B>
SDL_Surface * ouvrireImage(char nom[])
{
	SDL_Surface * temporaire = SDL_LoadBMP(nom),
		        * optimale;
	Uint32 couleurInvisible;
	if (!temporaire)
	{
		cout << "porblème avec le fichier " << nom << endl;
		return 0;
	}
	optimale = SDL_DisplayFormat( temporaire );
	SDL_FreeSurface( temporaire );

	couleurInvisible = SDL_MapRGB( optimale->format, _R, _G, _B );
	SDL_SetColorKey( optimale, SDL_SRCCOLORKEY, couleurInvisible );

	return optimale;
}

template<unsigned int FPS>
void synchronizeMoi()
{
	static Uint32 next=0;
	Uint32 now = SDL_GetTicks();
	if (now<next)
		SDL_Delay(next-now);
	else
		next = now+(1000/FPS);
}

#endif