aboutsummaryrefslogtreecommitdiff
path: root/gameloop/src/loopManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gameloop/src/loopManager.cpp')
-rw-r--r--gameloop/src/loopManager.cpp38
1 files changed, 21 insertions, 17 deletions
diff --git a/gameloop/src/loopManager.cpp b/gameloop/src/loopManager.cpp
index c439a3e..f7ce886 100644
--- a/gameloop/src/loopManager.cpp
+++ b/gameloop/src/loopManager.cpp
@@ -19,24 +19,28 @@ void LoopManager::processInput(){
void LoopManager::fixedUpdate(){
fprintf(stderr,"fixed update\n");
}
-void LoopManager::loop(){
- fprintf(stderr,"loop. \n");
- LoopTimer& timer = LoopTimer::getInstance();
- while(gameRunning){
- timer.update();
- lag += timer.getDeltaTime();
- processInput();
- while (lag >= timer.getFixedDeltaTime())
- {
- fixedUpdate();
- lag -= timer.getFixedDeltaTime();
- }
- //update();
- //timer.enforceFrameRate();
- render();
- }
- window.destroyWindow();
+void LoopManager::loop() {
+ LoopTimer& timer = LoopTimer::getInstance();
+ timer.start();
+
+ while (gameRunning) {
+ timer.update();
+
+ while (timer.getLag() >= timer.getFixedDeltaTime()) {
+ processInput();
+ fixedUpdate();
+ timer.advanceFixedUpdate();
+ }
+
+ update();
+ render();
+
+ timer.enforceFrameRate();
+ }
+
+ window.destroyWindow();
}
+
void LoopManager::setup(){
gameRunning = window.initWindow();
LoopTimer::getInstance().start();