From 59a1f2052cb3abef7cbc24f8f9fde3ebc0db2275 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Mon, 17 May 2010 18:03:07 +0200 Subject: Fixed pausing and broken event handling. --- application.cpp | 19 +++++++++++++------ application.h | 1 + 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/application.cpp b/application.cpp index 072c7a8..371ef2f 100644 --- a/application.cpp +++ b/application.cpp @@ -135,6 +135,7 @@ Application::~Application() { void Application::run() { elapsed = 0; + paused = false; font = new FTPixmapFont("VeraMono.ttf"); font->FaceSize(12); @@ -153,16 +154,18 @@ void Application::run() { shader->attach(shader2); shader->link(); - unsigned int lasttick = SDL_GetTicks(); + lasttick = SDL_GetTicks(); while(1) { SDL_Event event; - SDL_PollEvent(&event); - if(event.type == SDL_QUIT) { - break; - } else if(event.type == SDL_KEYDOWN) { - event_keypress(event.key.keysym.sym); + while(SDL_PollEvent(&event)) { + if(event.type == SDL_QUIT) { + break; + } else if(event.type == SDL_KEYDOWN) { + event_keypress(event.key.keysym.sym); + } } + if(please_quit) { return; } @@ -280,6 +283,10 @@ void Application::event_keypress(SDLKey key) { case SDLK_ESCAPE: quit(); break; + case SDLK_SPACE: + paused = !paused; + lasttick = SDL_GetTicks(); + break; default: break; } diff --git a/application.h b/application.h index c9867b8..e40af07 100644 --- a/application.h +++ b/application.h @@ -15,6 +15,7 @@ class Application { bool please_quit; bool paused; + unsigned int lasttick; unsigned int elapsed; unsigned int frames; unsigned int lastframes; -- cgit v1.2.3