aboutsummaryrefslogtreecommitdiff
path: root/gameloop/src/loopManager.cpp
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-09-18 16:52:54 +0200
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-09-18 16:52:54 +0200
commit8bf919f750807060f3ac2c640b8a02300af1733c (patch)
tree7bae57855fc3b98779bdfecbea141e7ec1eed68c /gameloop/src/loopManager.cpp
parent61e382cedd71127033f91551298607e2e78c3809 (diff)
gameloop poc working with variable and constant update
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();