aboutsummaryrefslogtreecommitdiff
path: root/mwe/gameloop
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-04 08:31:05 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-04 08:31:05 +0100
commit63d50eea4e389e73e26f41452829dd48e6190c70 (patch)
tree82a8ef7a28fe7e069dbe9830adc28fd49dd85846 /mwe/gameloop
parent06f65659fc6ffde7cabd2135040cbfbf089e5a24 (diff)
parent2585dc3cab48ccad0cfa0c63354662d656c86c46 (diff)
Merge branch 'master' of github.com:lonkaars/crepe
Diffstat (limited to 'mwe/gameloop')
-rw-r--r--mwe/gameloop/include/loopManager.h4
-rw-r--r--mwe/gameloop/include/timer.h2
-rw-r--r--mwe/gameloop/src/loopManager.cpp18
3 files changed, 15 insertions, 9 deletions
diff --git a/mwe/gameloop/include/loopManager.h b/mwe/gameloop/include/loopManager.h
index 1befb69..7d37253 100644
--- a/mwe/gameloop/include/loopManager.h
+++ b/mwe/gameloop/include/loopManager.h
@@ -1,11 +1,11 @@
#pragma once
-#include "event.h"
#include "gameObject.h"
#include "window.h"
#include <SDL2/SDL.h>
class LoopManager {
public:
LoopManager();
+ ~LoopManager();
void setup();
void loop();
@@ -17,7 +17,7 @@ private:
void fixedUpdate();
void render();
bool gameRunning = false;
- WindowManager window;
+ WindowManager * window;
int timeScale = 1;
float accumulator = 0.0;
double currentTime;
diff --git a/mwe/gameloop/include/timer.h b/mwe/gameloop/include/timer.h
index 8273746..3c38594 100644
--- a/mwe/gameloop/include/timer.h
+++ b/mwe/gameloop/include/timer.h
@@ -25,7 +25,7 @@ private:
double maximumDeltaTime = 0.25;
double deltaTime;
double frameTargetTime = FPS / 1000;
- double fixedDeltaTime = 0.01;
+ double fixedDeltaTime = 0.02;
double elapsedTime;
double elapsedFixedTime;
double time;
diff --git a/mwe/gameloop/src/loopManager.cpp b/mwe/gameloop/src/loopManager.cpp
index 0392853..49d65fb 100644
--- a/mwe/gameloop/src/loopManager.cpp
+++ b/mwe/gameloop/src/loopManager.cpp
@@ -1,6 +1,12 @@
#include "loopManager.h"
#include "timer.h"
-LoopManager::LoopManager() {}
+LoopManager::LoopManager() { this->window = new WindowManager(); }
+LoopManager::~LoopManager() {
+ for (GameObject * object : this->objectList) {
+ delete object;
+ }
+ delete this->window;
+}
void LoopManager::processInput() {
SDL_Event event;
SDL_PollEvent(&event);
@@ -42,14 +48,14 @@ void LoopManager::loop() {
timer.enforceFrameRate();
}
- window.destroyWindow();
+ window->destroyWindow();
}
void LoopManager::setup() {
- gameRunning = window.initWindow();
- LoopTimer::getInstance().start();
- LoopTimer::getInstance().setFPS(500);
+ LoopTimer::getInstance().start();
+ LoopTimer::getInstance().setFPS(10);
+ this->gameRunning = true;
for (int i = 1; i < 3; i++) {
GameObject * square
= new GameObject("square2", i * 60, i * 60, 20, 20, 0, 0);
@@ -59,7 +65,7 @@ void LoopManager::setup() {
void LoopManager::render() {
fprintf(stderr, "**********render********** \n");
if (gameRunning) {
- window.render(objectList);
+ window->render(objectList);
}
}