diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-09-18 15:11:04 +0200 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-09-18 15:11:04 +0200 |
commit | 61e382cedd71127033f91551298607e2e78c3809 (patch) | |
tree | db946bf0dac5cbb504ac7875fb323243d2a6db74 /gameloop/include | |
parent | 7eafe293868d5d3875d0bec147e22a266e4ec86c (diff) |
gameloop save
Diffstat (limited to 'gameloop/include')
-rw-r--r-- | gameloop/include/gameObject.h | 29 | ||||
-rw-r--r-- | gameloop/include/loopManager.h | 14 | ||||
-rw-r--r-- | gameloop/include/timer.h | 31 | ||||
-rw-r--r-- | gameloop/include/window.h | 12 |
4 files changed, 76 insertions, 10 deletions
diff --git a/gameloop/include/gameObject.h b/gameloop/include/gameObject.h new file mode 100644 index 0000000..0e17991 --- /dev/null +++ b/gameloop/include/gameObject.h @@ -0,0 +1,29 @@ +#pragma once +#include <iostream> +class GameObject { + public: + GameObject(); + GameObject(std::string name, float x, float y, float width, float height, float velX, float velY); + std::string getName() const; + float getX() const; + float getY() const; + float getWidth() const; + float getHeight() const; + float getVelX() const; + float getVelY() const; + void setName(std::string value); + void setX(float value); + void setY(float value); + void setWidth(float value); + void setHeight(float value); + void setVelX(float value); + void setVelY(float value); + private: + std::string name = ""; + float x = 0; + float y = 0; + float width = 0; + float height = 0; + float velX = 0; + float velY = 0; +}; diff --git a/gameloop/include/loopManager.h b/gameloop/include/loopManager.h index 03b07a9..5ed918d 100644 --- a/gameloop/include/loopManager.h +++ b/gameloop/include/loopManager.h @@ -1,6 +1,7 @@ #pragma once #include <SDL2/SDL.h> #include "window.h" +#include "gameObject.h" class LoopManager{ public: LoopManager(); @@ -8,11 +9,18 @@ class LoopManager{ void loop(); private: - + std::vector<GameObject*> objectList; void processInput(); void update(); + void lateUpdate(); + void fixedUpdate(); void render(); - bool gameRunning; + bool gameRunning = false; WindowManager window; - + int timeScale = 1; + float lag = 0.0; + double currentTime; + double t = 0.0; + double dt = 0.01; + state previous; }; diff --git a/gameloop/include/timer.h b/gameloop/include/timer.h new file mode 100644 index 0000000..2769e4d --- /dev/null +++ b/gameloop/include/timer.h @@ -0,0 +1,31 @@ +#pragma once + +#include <SDL2/SDL.h> + +class LoopTimer { +public: + static LoopTimer& getInstance(); + void start(); + void update(); + float getDeltaTime() const; + float getDeltaTimeMs() const; + float getFixedDeltaTime() const; + int getCurrentTime() const; + void setFPS(int FPS); + int getFPS() const; + void enforceFrameRate(); + float getLag() const; +private: + LoopTimer(); + int FPS = 30; + float frameTargetTime = FPS / 1000; + int lastTime; + float fixedDeltaTime = 2; + float maxDeltaTime = 1; + float fixedTime = 0; + int lastFrameTime; + float deltaTime; + float time = 0; + int frequency; + float lag; +}; diff --git a/gameloop/include/window.h b/gameloop/include/window.h index b4f2b78..cfde0e9 100644 --- a/gameloop/include/window.h +++ b/gameloop/include/window.h @@ -1,20 +1,18 @@ #pragma once #include <SDL2/SDL.h> +#include <vector> +#include "gameObject.h" +#include <iostream> class WindowManager{ public: WindowManager(); virtual ~WindowManager(); - bool loadMedia(); - void update(); - bool init(); - void close(); + void render(std::vector<GameObject*> objects); bool initWindow(); void destroyWindow(); + SDL_Renderer* getRenderer(); private: - //Loads media - //Frees media and shuts down SDL - const int SCREEN_WIDTH = 800; const int SCREEN_HEIGHT = 600; SDL_Window* window = NULL; |