Browse Source

replaced clock with clock from gaming core

Kajetan Johannes Hammerle 3 years ago
parent
commit
eea8f12a34
7 changed files with 8 additions and 61 deletions
  1. 3 3
      Main.cpp
  2. 1 1
      gaming-core
  3. 1 1
      meson.build
  4. 3 4
      rendering/wrapper/GLFW.cpp
  5. 0 6
      rendering/wrapper/GLFW.h
  6. 0 22
      utils/Clock.cpp
  7. 0 24
      utils/Clock.h

+ 3 - 3
Main.cpp

@@ -5,7 +5,7 @@
 #include "rendering/wrapper/GLWrapper.h"
 #include "rendering/wrapper/Window.h"
 #include "rendering/Options.h"
-#include "utils/Clock.h"
+#include "gaming-core/utils/Clock.h"
 #include "rendering/wrapper/Shader.h"
 #include "rendering/Renderer.h"
 #include "Game.h"
@@ -68,8 +68,8 @@ int main(int argAmount, char* const* args) {
 
     window.show();
 
-    const Nanos nanosPerTick = 10'000'000;
-    Nanos lag = 0;
+    const Clock::Nanos nanosPerTick = 10'000'000;
+    Clock::Nanos lag = 0;
     while(!window.shouldClose() && game.isRunning()) {
         GLWrapper::checkAndPrintError("GL-Error");
 

+ 1 - 1
gaming-core

@@ -1 +1 @@
-Subproject commit 2520bce011ef46b775b701f024259929351dfd6d
+Subproject commit 375ceefe325e4b3394b613f6a8952eef20410f3d

+ 1 - 1
meson.build

@@ -5,7 +5,7 @@ sources = [
     'rendering/wrapper/GLFW.cpp', 
     'gaming-core/utils/Size.cpp', 
     'rendering/wrapper/Window.cpp', 
-    'utils/Clock.cpp', 
+    'gaming-core/utils/Clock.cpp', 
     'rendering/wrapper/Shader.cpp', 
     'rendering/wrapper/GLWrapper.cpp',
     'Game.cpp',

+ 3 - 4
rendering/wrapper/GLFW.cpp

@@ -1,5 +1,8 @@
 #include <iostream>
 
+#include <GL/glew.h>
+#include <GLFW/glfw3.h>
+
 #include "rendering/wrapper/GLFW.h"
 
 bool GLFW::init() {
@@ -11,8 +14,4 @@ bool GLFW::init() {
     }
     std::cout << "could not initialize GLFW\n";
     return true;
-}
-
-Nanos GLFW::getNanos() {
-    return glfwGetTimerValue() * (1000000000 / glfwGetTimerFrequency());
 }

+ 0 - 6
rendering/wrapper/GLFW.h

@@ -1,14 +1,8 @@
 #ifndef GLFW_H
 #define GLFW_H
 
-#include <GL/glew.h>
-#include <GLFW/glfw3.h>
-
-typedef uint64_t Nanos;
-
 namespace GLFW {
     bool init();
-    Nanos getNanos();
 }
 
 #endif

+ 0 - 22
utils/Clock.cpp

@@ -1,22 +0,0 @@
-#include "utils/Clock.h"
-
-Clock::Clock() : index(0), last(GLFW::getNanos()), sum(0), time(0) {
-}
-
-Nanos Clock::update() {
-    index = (index + 1) & (length - 1);
-    Nanos current = GLFW::getNanos();
-    sum -= time[index];
-    time[index] = current - last;
-    sum += time[index];
-    last = current;
-    return time[index];
-}
-
-Nanos Clock::getLength() const {
-    return length;
-}
-
-float Clock::getUpdatesPerSecond() const {
-    return length * (1000000000.0f / sum);
-}

+ 0 - 24
utils/Clock.h

@@ -1,24 +0,0 @@
-#ifndef CLOCK_H
-#define CLOCK_H
-
-#include "utils/Array.h"
-
-#include "rendering/wrapper/GLFW.h"
-
-class Clock final {
-    static constexpr int bits = 7;
-    static constexpr int length = 1 << bits;
-    
-    int index;
-    Nanos last;
-    Nanos sum;
-    Array<Nanos, length> time;
-    
-public:
-    Clock();
-    Nanos update();
-    Nanos getLength() const;
-    float getUpdatesPerSecond() const;
-};
-
-#endif