2011-11-21 64 views
-1

我试图在C和SDL中创建一个小型游戏,以有趣的方式开始使用SDL。我会粘贴我的计时器结构和函数,将用于在我的主要游戏循环中封顶fps。在总共约25个错误地狱般的语法错误

这是的,但我得到了很多的“预期‘(’跟随‘T’错误C2054”:?

#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; 
} 

请告诉我错在这里先感谢!

+0

是否找到了所有包含的文件? –

+0

请仔细阅读错误信息 - 哪一行是“错误C2054”?我会开始寻找错误:) – kol

回答

4

所有这些t变量应该是struct Timer类型,而不是Timer

,或者,将其定义为:

typedef struct sTimer { 
    int startTicks; 
    int pausedTicks; 
    int paused; 
    int started; 
} Timer; 

使Timer成为“第一类”类型。

+0

谢谢队友!发现! – Jason94

1

在C语言中,你要么需要这样做:

struct Foo 
{ 
    ... 
}; 

... 

void bar(struct Foo *p); 
     ^

或本:

typedef struct Foo 
{^
    ... 
} Foo; 
^
... 

void bar(Foo *p); 

[我喜欢第二个版本;它节省了不得不写struct到处。]

1

找到第一个错误,并从中工作。通常,其他许多是第一个的后果。

+0

s /通常/很多/ – glglgl

+0

@glglgl:谢谢,修正。 – mouviciel