#include "util_time.h" static struct { float max_ticks_per_frame; //< cuantos ticks (tiempo demora) un frame Uint32 counted_frames; //< cuantos frames han pasado Uint32 start_ticks; //< ticks al iniciar la iteracion del loop Uint32 beg_ticks; //< ticks desde el inicio del juego Uint32 time_per_frame; } TIME = { 1000.0f / 60.0f, 0, 0, 0, 0 }; void Time_Init() { TIME.beg_ticks = SDL_GetTicks(); } void Time_Begin() { TIME.start_ticks = SDL_GetTicks(); } float Time_End() { TIME.counted_frames += 1; float FPS = TIME.counted_frames / ( (float)(SDL_GetTicks() - TIME.beg_ticks) / 1000.f ); float frameTicks = (float)(SDL_GetTicks() - TIME.start_ticks); TIME.time_per_frame = frameTicks; if(frameTicks < TIME.max_ticks_per_frame){ SDL_Delay( (Uint32)(TIME.max_ticks_per_frame - frameTicks) ); } return FPS; } float Time_GetFrameTime() { return (float)TIME.time_per_frame / 1000.0f; } void Time_SetMaxFramesPerSecond(Uint32 frames) { TIME.max_ticks_per_frame = 1000.0f / (float)frames; } Uint32 Time_GetCountedFrames() { return TIME.counted_frames; }