1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
void MainLoop()
{
InitLoop();
while ( !QuitMain )
{
frametime = SDL_GetTicks() - start;
if ( frametime < 1000.f/FPS ) SDL_Delay( 1000.f/FPS - ( SDL_GetTicks() - start ) );
start = SDL_GetTicks();
HandleInput();
Display();
Update();
PrintSDLError();
PrintGLError();
FPSTracker.Average = (FPSTracker.Frame*FPSTracker.Average + (1000.f/frametime))/float(FPSTracker.Frame+1);
FPSTracker.Frame++;
}
}
void HandleInput()
{
while ( SDL_PollEvent(&Event) )
{
int x,y;
SDL_GetMouseState(&x,&y);
switch( Event.type )
{
case SDL_QUIT:
Close();
break;
case SDL_KEYDOWN:
KeyPress(Event.key.keysym.sym, x, y);
break;
case SDL_KEYUP:
KeyRelease(Event.key.keysym.sym, x, y);
break;
case SDL_MOUSEBUTTONDOWN:
MousePress(Event.button.button, x, y);
break;
case SDL_MOUSEBUTTONUP:
MouseRelease(Event.button.button, x, y);
break;
case SDL_MOUSEMOTION:
if ( !( Event.motion.state & SDL_BUTTON_LMASK or Event.motion.state & SDL_BUTTON_RMASK ) )
PassiveMouseMotion(x,y);
else
ActiveMouseMotion(x,y);
break;
case SDL_MOUSEWHEEL:
MouseWheel(Sign( Event.wheel.y ), x, y);
break;
case SDL_WINDOWEVENT:
if ( Event.window.type == SDL_WINDOWEVENT_RESIZED )
Resize( Event.window.data1, Event.window.data2 );
break;
case SDL_SYSWMEVENT:
{
UINT Message = Event.syswm.msg->msg.win.msg;
WPARAM wParam = Event.syswm.msg->msg.win.wParam;
LPARAM lParam = Event.syswm.msg->msg.win.lParam;
SysWM(Message, wParam, lParam);
}
break;
}
}
}
|