diff options
Diffstat (limited to 'gameloop/src/loopManager.cpp')
-rw-r--r-- | gameloop/src/loopManager.cpp | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/gameloop/src/loopManager.cpp b/gameloop/src/loopManager.cpp index ef2decf..c439a3e 100644 --- a/gameloop/src/loopManager.cpp +++ b/gameloop/src/loopManager.cpp @@ -1,4 +1,5 @@ #include "loopManager.h" +#include "timer.h" LoopManager::LoopManager(){ } void LoopManager::processInput(){ @@ -15,23 +16,53 @@ void LoopManager::processInput(){ break; } } +void LoopManager::fixedUpdate(){ + fprintf(stderr,"fixed update\n"); +} void LoopManager::loop(){ + fprintf(stderr,"loop. \n"); + LoopTimer& timer = LoopTimer::getInstance(); while(gameRunning){ - //processInput(); + timer.update(); + lag += timer.getDeltaTime(); + processInput(); + while (lag >= timer.getFixedDeltaTime()) + { + fixedUpdate(); + lag -= timer.getFixedDeltaTime(); + } //update(); - //render(); + //timer.enforceFrameRate(); + render(); } window.destroyWindow(); } 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); + objectList.push_back(square); + } } void LoopManager::render(){ + fprintf(stderr,"**********render********** \n"); if(gameRunning){ - SDL_SetRenderDrawColor(window.getRenderer(),255,0,0,255); - SDL_RenderClear(window.getRenderer()); + window.render(objectList); } } -void LoopManager::update(){ +void LoopManager::update() { + fprintf(stderr,"**********normal update********** \n"); + LoopTimer& timer = LoopTimer::getInstance(); + + 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); + } } + |