diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-09-21 15:35:05 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-09-21 15:35:05 +0200 |
commit | 44affb6635359ef2f619562800165ccfff438ae4 (patch) | |
tree | 4da7fa01953055740f9e668e94c59259d4d7749f /mwe/gameloop/src/loopManager.cpp | |
parent | ca393b6b47618e48c107ad5c021d86700343648e (diff) |
`make format`
Diffstat (limited to 'mwe/gameloop/src/loopManager.cpp')
-rw-r--r-- | mwe/gameloop/src/loopManager.cpp | 75 |
1 files changed, 36 insertions, 39 deletions
diff --git a/mwe/gameloop/src/loopManager.cpp b/mwe/gameloop/src/loopManager.cpp index f7ce886..cb532cc 100644 --- a/mwe/gameloop/src/loopManager.cpp +++ b/mwe/gameloop/src/loopManager.cpp @@ -1,72 +1,69 @@ #include "loopManager.h" #include "timer.h" -LoopManager::LoopManager(){ -} -void LoopManager::processInput(){ +LoopManager::LoopManager() {} +void LoopManager::processInput() { SDL_Event event; SDL_PollEvent(&event); - switch(event.type){ + switch (event.type) { case SDL_QUIT: gameRunning = false; break; case SDL_KEYDOWN: - if(event.key.keysym.sym == SDLK_ESCAPE){ + if (event.key.keysym.sym == SDLK_ESCAPE) { gameRunning = false; } - break; + break; } } -void LoopManager::fixedUpdate(){ - fprintf(stderr,"fixed update\n"); -} +void LoopManager::fixedUpdate() { fprintf(stderr, "fixed update\n"); } void LoopManager::loop() { - LoopTimer& timer = LoopTimer::getInstance(); - timer.start(); + LoopTimer & timer = LoopTimer::getInstance(); + timer.start(); - while (gameRunning) { - timer.update(); + while (gameRunning) { + timer.update(); - while (timer.getLag() >= timer.getFixedDeltaTime()) { - processInput(); - fixedUpdate(); - timer.advanceFixedUpdate(); - } + while (timer.getLag() >= timer.getFixedDeltaTime()) { + processInput(); + fixedUpdate(); + timer.advanceFixedUpdate(); + } - update(); - render(); + update(); + render(); - timer.enforceFrameRate(); - } + timer.enforceFrameRate(); + } - window.destroyWindow(); + window.destroyWindow(); } -void LoopManager::setup(){ +void LoopManager::setup() { gameRunning = window.initWindow(); LoopTimer::getInstance().start(); LoopTimer::getInstance().setFPS(50); - - for(int i = 0; i < 2;i++){ - GameObject* square = new GameObject("square2",i*40,i*40,20,20,0,0); + + for (int i = 0; i < 2; i++) { + GameObject * square + = new GameObject("square2", i * 40, i * 40, 20, 20, 0, 0); objectList.push_back(square); } } -void LoopManager::render(){ - fprintf(stderr,"**********render********** \n"); - if(gameRunning){ +void LoopManager::render() { + fprintf(stderr, "**********render********** \n"); + if (gameRunning) { window.render(objectList); } } void LoopManager::update() { - fprintf(stderr,"**********normal update********** \n"); - LoopTimer& timer = LoopTimer::getInstance(); - - float delta= timer.getDeltaTime(); + fprintf(stderr, "**********normal update********** \n"); + LoopTimer & timer = LoopTimer::getInstance(); - for (int i = 0; i < objectList.size(); i++) { - objectList[i]->setX(objectList[i]->getX() + 50 * delta); - objectList[i]->setY(objectList[i]->getY() + 50 * delta); - } -} + float delta = timer.getDeltaTime(); + for (int i = 0; i < objectList.size(); i++) { + objectList[i]->setX(objectList[i]->getX() + 50 * delta); + objectList[i]->setY(objectList[i]->getY() + 50 * delta); + } +} |