Im trying to create a small game in C and SDL to get started with SDL in a fun way. Ill paste inn my Timer struct and function that will be used to cap the fps in my main game loop. BUT i get a lot of “error C2054: expected ‘(‘ to follow ‘t'”, about 25 errors in total.
Here it is:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "SDL.h"
struct Timer {
int startTicks;
int pausedTicks;
int paused;
int started;
};
void Init( Timer *t )
{
t->startTicks = 0;
t->pausedTicks = 0;
t->paused = 0;
t->started = 0;
}
void StartTimer( Timer *t )
{
t->started = 1;
t->paused = 0;
t->startTicks = SDL_GetTicks();
}
void StopTimer( Timer *t )
{
t->started = 0;
t->paused = 0;
}
void PauseTimer( Timer *t )
{
if( t->started == 1 && t->paused == 0 )
{
t->paused = 1;
t->pausedTicks = SDL_GetTicks() - t->startTicks;
}
}
void UnpauseTimer( Timer *t )
{
if( t->paused == 1 )
{
t->paused = 0;
t->startTicks = SDL_GetTicks() - t->pausedTicks;
t->pausedTicks = 0;
}
}
int GetTicks( Timer *t )
{
if( t->started == 1 )
{
return t->pausedTicks;
}
else
{
return SDL_GetTicks() - t->startTicks;
}
return 0;
}
Whats wrong here? Thanks in advance!
All those
tvariables should be of typestruct Timerrather thanTimer.Or, alternatively, define it as:
to make
Timera “first-class” type.