Im making my first game loop in SDL, and I want to know which is a better design choice for the update() function.
first option would be to declare last_frame_time as a global variable
uint32_t last_frame_time=0;
void update(SDL_Rect* input_rect)
{
while (!SDL_TICKS_PASSED(SDL_GetTicks() , last_frame_time + TARGET_FRAME_TIME));
last_frame_time = SDL_GetTicks();
input_rect->x++;
if (input_rect->y < 500)
input_rect->y++;
}
or I could pass the last_frame_time as a parameter to update
void update(SDL_Rect* input_rect , int* last_frame_time)
{
while (!SDL_TICKS_PASSED(SDL_GetTicks() , last_frame_time + TARGET_FRAME_TIME));
*last_frame_time = SDL_GetTicks();
input_rect->x++;
if (input_rect->y < 500)
input_rect->y++;
}
which way would be better in terms of speed and readability and design everything else ?