diff options
Diffstat (limited to 'mwe/events/src/loopManager.cpp')
-rw-r--r-- | mwe/events/src/loopManager.cpp | 45 |
1 files changed, 21 insertions, 24 deletions
diff --git a/mwe/events/src/loopManager.cpp b/mwe/events/src/loopManager.cpp index 6defda0..8ecb932 100644 --- a/mwe/events/src/loopManager.cpp +++ b/mwe/events/src/loopManager.cpp @@ -12,17 +12,15 @@ void LoopManager::processInput() { triggerEvent(KeyPressedEvent(getCustomKey(event.key.keysym.sym))); break; case SDL_MOUSEBUTTONDOWN: - int x, y; - SDL_GetMouseState(&x, &y); - triggerEvent(MousePressedEvent(x, y)); - break; + int x, y; + SDL_GetMouseState(&x, &y); + triggerEvent(MousePressedEvent(x, y)); + break; } } -void LoopManager::setRunning(bool running){ - this->gameRunning = running; -} -void LoopManager::fixedUpdate() { - //fprintf(stderr, "fixed update\n"); +void LoopManager::setRunning(bool running) { this->gameRunning = running; } +void LoopManager::fixedUpdate() { + //fprintf(stderr, "fixed update\n"); } void LoopManager::loop() { LoopTimer & timer = LoopTimer::getInstance(); @@ -45,30 +43,29 @@ void LoopManager::loop() { window.destroyWindow(); } -void onKey(const KeyPressedEvent& e) -{ - int keyCode = e.getKeyCode(); +void onKey(const KeyPressedEvent & e) { + int keyCode = e.getKeyCode(); std::cout << "keycode pressed: " << keyCode << std::endl; - } -void onMouse(const MousePressedEvent& e){ - fprintf(stderr, "mouse Position X: %d Y: %d\n", e.getMousePosition().first, e.getMousePosition().second); +void onMouse(const MousePressedEvent & e) { + fprintf(stderr, "mouse Position X: %d Y: %d\n", e.getMousePosition().first, + e.getMousePosition().second); } void LoopManager::setup() { gameRunning = window.initWindow(); LoopTimer::getInstance().start(); LoopTimer::getInstance().setFPS(50); EventHandler<KeyPressedEvent> callback = onKey; - subscribe<KeyPressedEvent>(callback,false); + subscribe<KeyPressedEvent>(callback, false); EventHandler<MousePressedEvent> mouseCallback = onMouse; - subscribe<MousePressedEvent>(mouseCallback ,false); - EventHandler<KeyPressedEvent> closeWindowCallback = [this](const KeyPressedEvent& e) { - if(e.getKeyCode() == Escape){ - this->setRunning(false); - } - }; - subscribe<KeyPressedEvent>(closeWindowCallback,false); - + subscribe<MousePressedEvent>(mouseCallback, false); + EventHandler<KeyPressedEvent> closeWindowCallback + = [this](const KeyPressedEvent & e) { + if (e.getKeyCode() == Escape) { + this->setRunning(false); + } + }; + subscribe<KeyPressedEvent>(closeWindowCallback, false); } void LoopManager::render() { //fprintf(stderr, "**********render********** \n"); |