Browse Source

refactoring

Kajetan Johannes Hammerle 3 years ago
parent
commit
4bfdf82dff

+ 51 - 87
client/Engine.cpp

@@ -1,17 +1,10 @@
 #include "client/Engine.h"
 #include "client/rendering/wrapper/GLFWWrapper.h"
 
-bool Engine::useSSAO = true;
-
-float Engine::testRadius = 0.0005;
-float Engine::testBias = 0.0005;
-bool Engine::ortho = false;
-Vector Engine::testOrthoCenter;
-
-Engine::Engine(Shaders& shaders, Framebuffers& fb, const Keys& keys, const MouseButtons& buttons, Camera& camera,
-        Ray& ray, const Clock& fps, const WindowSize& size) :
-shaders(shaders), fb(fb), keys(keys), buttons(buttons), game(keys, buttons, camera, ray), camera(camera),
-frustum(60.0f, 0.1f, 80.0f), ssaoNoise(4, 4), fps(fps), size(size), running(!shaders.hasError() && !fb.hasError()) {
+Engine::Engine(Shaders& shaders, Framebuffers& fb, Camera& camera, const WindowSize& size,
+        RenderSettings& renderSettings) :
+shaders(shaders), fb(fb), camera(camera), size(size), renderSettings(renderSettings), frustum(60.0f, 0.1f, 80.0f),
+ssaoNoise(4, 4) {
     rectangle.add( {-1, -1, 0, 0, 0, 0, 0, 0});
     rectangle.add( {1, 1, 0, 1, 1, 0, 0, 0});
     rectangle.add( {-1, 1, 0, 0, 1, 0, 0, 0});
@@ -21,45 +14,21 @@ frustum(60.0f, 0.1f, 80.0f), ssaoNoise(4, 4), fps(fps), size(size), running(!sha
     rectangle.build();
 }
 
-bool Engine::isRunning() const {
-    return running;
-}
-
-void Engine::renderTick(float lag) {
+void Engine::renderTick(float lag, const Game& game) {
     camera.update(lag);
     updateWorldProjection();
     updateWorldView();
 
-    renderShadow(lag);
-    renderWorld(lag);
-    if(Engine::useSSAO) {
+    renderShadow(lag, game);
+    renderWorld(lag, game);
+    if(renderSettings.useSSAO) {
         renderSSAO();
     }
     renderPostWorld();
-    renderTextOverlay(lag);
+    renderTextOverlay(lag, game);
 }
 
-void Engine::tick() {
-    game.tick();
-    if(keys.test5.getDownTime() == 1) {
-        ortho = !ortho;
-    }
-    if(keys.test.isDown()) {
-        //ortho = !ortho;
-        testRadius /= 0.95f;
-    }
-    if(keys.test2.isDown()) {
-        testRadius *= 0.95f;
-    }
-    if(keys.test3.isDown()) {
-        testBias /= 0.95f;
-    }
-    if(keys.test4.isDown()) {
-        testBias *= 0.95f;
-    }
-}
-
-void Engine::renderShadow(float lag) {
+void Engine::renderShadow(float lag, const Game& game) {
     fb.shadow.bind();
     glEnable(GL_DEPTH_TEST);
     shaders.shadow.use();
@@ -73,7 +42,7 @@ void Engine::renderShadow(float lag) {
     //glCullFace(GL_BACK);
 }
 
-void Engine::renderWorld(float lag) {
+void Engine::renderWorld(float lag, const Game& game) {
     fb.world.bind();
     glEnable(GL_DEPTH_TEST);
     shaders.world.use();
@@ -89,8 +58,8 @@ void Engine::renderWorld(float lag) {
     model.clear();
     shaders.world.setMatrix("model", model.get().getValues());
     fb.shadow.bindDepthTexture(1);
-    shaders.world.setFloat("radius", Engine::testRadius);
-    shaders.world.setFloat("bias", Engine::testBias);
+    shaders.world.setFloat("radius", renderSettings.testRadius);
+    shaders.world.setFloat("bias", renderSettings.testBias);
     game.renderWorld(lag, model, shaders.world);
 }
 
@@ -127,11 +96,11 @@ void Engine::renderPostWorld() {
     fb.ssaoBlur.bindRedTexture(1);
     fb.world.bindRedTexture(2);
     fb.world.bindNormalTexture(3);
-    shaders.postWorld.setInt("useSSAO", Engine::useSSAO);
+    shaders.postWorld.setInt("useSSAO", renderSettings.useSSAO);
     rectangle.draw();
 }
 
-void Engine::renderTextOverlay(float lag) {
+void Engine::renderTextOverlay(float lag, const Game& game) {
     glDisable(GL_DEPTH_TEST);
     shaders.text.use();
 
@@ -147,9 +116,6 @@ void Engine::renderTextOverlay(float lag) {
     glEnable(GL_BLEND);
     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     glBlendEquation(GL_FUNC_ADD);
-    char buffer[50];
-    snprintf(buffer, 50, "FPS: %f %f %f", fps.getUpdatesPerSecond(), Engine::testRadius, Engine::testBias);
-    fontRenderer.drawString(20, 20, buffer);
     game.renderTextOverlay(lag, model, shaders.text, fontRenderer);
     glDisable(GL_BLEND);
 }
@@ -158,52 +124,56 @@ void Engine::updateWorldProjection() {
     frustum.setProjection(worldProj, size.width, size.height);
 
     // http://cgvr.informatik.uni-bremen.de/teaching/cg_literatur/lighthouse3d_view_frustum_culling/index.html
-    /*float tan = tanf((0.5f * fovY) * M_PI / 180.0f);
+    const float fovY = 60.0f;
+    const float nearClip = 0.1f;
+    const float farClip = 80.0f;
+
+    float tan = tanf((0.5f * fovY) * M_PI / 180.0f);
     float aspect = (float) size.width / size.height;
-    
+
     float closeFarClip = 4;
     float nearHigh = tan * nearClip;
     float nearWidth = nearHigh * aspect;
     float farHigh = tan * closeFarClip;
     float farWidth = farHigh * aspect;
 
-    Vector farCenter = cam.getPosition();
-    farCenter.addMul(cam.getFront(), closeFarClip);
+    Vector farCenter = camera.getPosition();
+    farCenter.addMul(camera.getBack(), -closeFarClip);
 
     Vector farTopLeft = farCenter;
-    farTopLeft.addMul(cam.getLeft(), farWidth);
-    farTopLeft.addMul(cam.getUp(), farHigh);
+    farTopLeft.addMul(camera.getRight(), -farWidth);
+    farTopLeft.addMul(camera.getUp(), farHigh);
 
     Vector farBottomLeft = farCenter;
-    farBottomLeft.addMul(cam.getLeft(), farWidth);
-    farBottomLeft.addMul(cam.getDown(), farHigh);
+    farBottomLeft.addMul(camera.getRight(), -farWidth);
+    farBottomLeft.addMul(camera.getUp(), -farHigh);
 
     Vector farTopRight = farCenter;
-    farTopRight.addMul(cam.getRight(), farWidth);
-    farTopRight.addMul(cam.getUp(), farHigh);
+    farTopRight.addMul(camera.getRight(), farWidth);
+    farTopRight.addMul(camera.getUp(), farHigh);
 
     Vector farBottomRight = farCenter;
-    farBottomRight.addMul(cam.getRight(), farWidth);
-    farBottomRight.addMul(cam.getDown(), farHigh);
+    farBottomRight.addMul(camera.getRight(), farWidth);
+    farBottomRight.addMul(camera.getUp(), -farHigh);
 
-    Vector nearCenter = cam.getPosition();
-    nearCenter.addMul(cam.getFront(), nearClip);
+    Vector nearCenter = camera.getPosition();
+    nearCenter.addMul(camera.getBack(), -nearClip);
 
     Vector nearTopLeft = nearCenter;
-    nearTopLeft.addMul(cam.getLeft(), nearWidth);
-    nearTopLeft.addMul(cam.getUp(), nearHigh);
+    nearTopLeft.addMul(camera.getRight(), -nearWidth);
+    nearTopLeft.addMul(camera.getUp(), nearHigh);
 
     Vector nearBottomLeft = nearCenter;
-    nearBottomLeft.addMul(cam.getLeft(), nearWidth);
-    nearBottomLeft.addMul(cam.getDown(), nearHigh);
+    nearBottomLeft.addMul(camera.getRight(), -nearWidth);
+    nearBottomLeft.addMul(camera.getUp(), -nearHigh);
 
     Vector nearTopRight = nearCenter;
-    nearTopRight.addMul(cam.getRight(), nearWidth);
-    nearTopRight.addMul(cam.getUp(), nearHigh);
+    nearTopRight.addMul(camera.getRight(), nearWidth);
+    nearTopRight.addMul(camera.getUp(), nearHigh);
 
     Vector nearBottomRight = nearCenter;
-    nearBottomRight.addMul(cam.getRight(), nearWidth);
-    nearBottomRight.addMul(cam.getDown(), nearHigh);
+    nearBottomRight.addMul(camera.getRight(), nearWidth);
+    nearBottomRight.addMul(camera.getUp(), -nearHigh);
 
     Vector light(-0.280166, -0.573576, -0.769751);
     Vector lightLeft = light;
@@ -260,22 +230,20 @@ void Engine::updateWorldProjection() {
     //std::cout << "\n" << max << " - " << min << " " << lightHeight << "\n";
 
     // not the real center, but good guess
-    testOrthoCenter = nearCenter;
-    testOrthoCenter.addMul(cam.getFront(), closeFarClip * 0.5f);
+    renderSettings.testOrthoCenter = nearCenter;
+    renderSettings.testOrthoCenter.addMul(camera.getBack(), -closeFarClip * 0.5f);
 
-    if(ortho) {
+    if(renderSettings.ortho) {
         worldProj.setToIdentity();
         worldProj.set(0, 2.0f / lightWidth);
         worldProj.set(5, 2.0f / lightHeight);
         worldProj.set(10, -2.0f / (farClip - nearClip));
     }
 
-    if(once) {
-        worldShadowProj.setToIdentity();
-        worldShadowProj.set(0, 2.0f / lightWidth);
-        worldShadowProj.set(5, 2.0f / lightHeight);
-        worldShadowProj.set(10, -2.0f / (farClip - nearClip));
-    }*/
+    worldShadowProj.setToIdentity();
+    worldShadowProj.set(0, 2.0f / lightWidth);
+    worldShadowProj.set(5, 2.0f / lightHeight);
+    worldShadowProj.set(10, -2.0f / (farClip - nearClip));
 }
 
 void Engine::updateWorldView() {
@@ -284,11 +252,11 @@ void Engine::updateWorldView() {
     Vector back = camera.getBack();
     Vector pos = camera.getPosition();
 
-    if(ortho) {
+    if(renderSettings.ortho) {
         right.set(0.939693f, 0.0f, -0.34202f);
         back.set(0.280166f, 0.573576f, 0.769751f);
         up.set(-0.196175f, 0.819152f, -0.538986f);
-        pos = testOrthoCenter;
+        pos = renderSettings.testOrthoCenter;
     }
 
     worldView.set(0, right.getX());
@@ -304,14 +272,11 @@ void Engine::updateWorldView() {
     worldView.set(13, up.dotInverse(pos));
     worldView.set(14, back.dotInverse(pos));
 
-    //if(once) {
-    // lengthAngle = 20; widthAngle = 35;
     right.set(0.939693f, 0.0f, -0.34202f);
     back.set(0.280166f, 0.573576f, 0.769751f);
     up.set(-0.196175f, 0.819152f, -0.538986f);
-    pos = testOrthoCenter;
+    pos = renderSettings.testOrthoCenter;
 
-    //once = false;
     worldShadowView.set(0, right.getX());
     worldShadowView.set(1, up.getX());
     worldShadowView.set(2, back.getX());
@@ -324,5 +289,4 @@ void Engine::updateWorldView() {
     worldShadowView.set(12, right.dotInverse(pos));
     worldShadowView.set(13, up.dotInverse(pos));
     worldShadowView.set(14, back.dotInverse(pos));
-    //}
 }

+ 15 - 31
client/Engine.h

@@ -5,8 +5,6 @@
 #include <cfloat>
 
 #include "common/utils/Types.h"
-#include "client/input/Keys.h"
-#include "client/input/MouseButtons.h"
 #include "client/math/Ray.h"
 #include "client/rendering/FontRenderer.h"
 #include "client/rendering/Mesh.h"
@@ -19,53 +17,39 @@
 #include "client/Game.h"
 #include "client/rendering/NoiseTexture.h"
 #include "client/utils/Clock.h"
+#include "client/rendering/RenderSettings.h"
 
 class Engine final {
 public:
-    Engine(Shaders& shaders, Framebuffers& fb, const Keys& keys, const MouseButtons& buttons, Camera& camera, 
-            Ray& ray, const Clock& fps, const WindowSize& size);
-    bool isRunning() const;
-    void renderTick(float lag);
-    void tick();
-
-    static bool useSSAO;
-    static float testRadius;
-    static float testBias;
-    static bool ortho;
-    static Vector testOrthoCenter;
-
-    Matrix worldProj;
-    Matrix worldView;
-    Matrix worldShadowProj;
-    Matrix worldShadowView;
-    Matrix worldShadowProjView;
+    Engine(Shaders& shaders, Framebuffers& fb, Camera& camera, const WindowSize& size, RenderSettings& renderSettings);
+    void renderTick(float lag, const Game& game);
 
 private:
-    void renderShadow(float lag);
-    void renderWorld(float lag);
+    void renderShadow(float lag, const Game& game);
+    void renderWorld(float lag, const Game& game);
     void renderSSAO();
     void renderPostWorld();
-    void renderTextOverlay(float lag);
+    void renderTextOverlay(float lag, const Game& game);
     void updateWorldProjection();
     void updateWorldView();
 
     Shaders& shaders;
     Framebuffers& fb;
-
-    const Keys& keys;
-    const MouseButtons& buttons;
-    Game game;
     Camera& camera;
+    const WindowSize& size;
+    RenderSettings& renderSettings;
+    
     Frustum frustum;
     MatrixStack model;
     FontRenderer fontRenderer;
     NoiseTexture ssaoNoise;
     Mesh rectangle;
-    const Clock& fps;
-
-    const WindowSize& size;
-
-    bool running;
+    
+    Matrix worldProj;
+    Matrix worldView;
+    Matrix worldShadowProj;
+    Matrix worldShadowView;
+    Matrix worldShadowProjView;
 };
 
 #endif

+ 48 - 17
client/Game.cpp

@@ -2,8 +2,10 @@
 
 #include "client/Game.h"
 
-Game::Game(const Keys& keys, const MouseButtons& buttons, const Camera& camera, Ray& ray) : keys(keys), buttons(buttons),
-camera(camera), ray(ray), lengthAngle(20.0f), widthAngle(35.0f), texture("resources/textures.png") {
+Game::Game(const Control& control, const Camera& camera, Ray& ray, const Clock& fps, const Clock& tps,
+        RenderSettings& renderSettings) :
+control(control), camera(camera), ray(ray), fps(fps), tps(tps), renderSettings(renderSettings), lengthAngle(20.0f),
+widthAngle(35.0f), texture("resources/textures.png") {
     for(int x = -6; x <= 6; x++) {
         for(int y = -6; y <= 6; y++) {
             for(int z = -6; z <= 6; z++) {
@@ -84,44 +86,60 @@ void Game::addCube(float x, float y, float z, bool bottom, bool top, bool left,
 
 void Game::tick() {
     const float speed = 0.25f;
-    if(keys.down.isDown()) {
+    if(control.keys.down.isDown()) {
         pos.addMul(camera.getFlatBack(), speed);
     }
-    if(keys.up.isDown()) {
+    if(control.keys.up.isDown()) {
         pos.addMul(camera.getFlatBack(), -speed);
     }
-    if(keys.left.isDown()) {
+    if(control.keys.left.isDown()) {
         pos.addMul(camera.getFlatRight(), -speed);
     }
-    if(keys.right.isDown()) {
+    if(control.keys.right.isDown()) {
         pos.addMul(camera.getFlatRight(), speed);
     }
-    if(keys.jump.isDown()) {
+    if(control.keys.jump.isDown()) {
         pos.addMul(camera.getFlatUp(), speed);
     }
-    if(keys.sneak.isDown()) {
+    if(control.keys.sneak.isDown()) {
         pos.addMul(camera.getFlatUp(), -speed);
     }
 
     const float rotation = 5.0f;
-    if(keys.camLeft.isDown()) {
+    if(control.keys.camLeft.isDown()) {
         lengthAngle += rotation;
     }
-    if(keys.camRight.isDown()) {
+    if(control.keys.camRight.isDown()) {
         lengthAngle -= rotation;
     }
-    if(keys.camUp.isDown() && widthAngle - rotation > -90.0f) {
+    if(control.keys.camUp.isDown() && widthAngle - rotation > -90.0f) {
         widthAngle -= rotation;
     }
-    if(keys.camDown.isDown() && widthAngle + rotation < 90.0f) {
+    if(control.keys.camDown.isDown() && widthAngle + rotation < 90.0f) {
         widthAngle += rotation;
     }
 
     ray.store();
     ray.set(pos, lengthAngle, widthAngle);
+    
+    if(control.keys.test5.getDownTime() == 1) {
+        renderSettings.ortho = !renderSettings.ortho;
+    }
+    if(control.keys.test.isDown()) {
+        renderSettings.testRadius /= 0.95f;
+    }
+    if(control.keys.test2.isDown()) {
+        renderSettings.testRadius *= 0.95f;
+    }
+    if(control.keys.test3.isDown()) {
+        renderSettings.testBias /= 0.95f;
+    }
+    if(control.keys.test4.isDown()) {
+        renderSettings.testBias *= 0.95f;
+    }
 }
 
-void Game::renderWorld(float lag, MatrixStack& stack, Shader& sh) {
+void Game::renderWorld(float lag, MatrixStack& stack, Shader& sh) const {
     (void) lag;
     (void) stack;
     (void) sh;
@@ -129,9 +147,22 @@ void Game::renderWorld(float lag, MatrixStack& stack, Shader& sh) {
     m.draw();
 }
 
-void Game::renderTextOverlay(float lag, MatrixStack& stack, Shader& sh, FontRenderer& fr) {
+void Game::renderTextOverlay(float lag, MatrixStack& stack, Shader& sh, FontRenderer& fr) const {
     (void) lag;
-    stack.get().scale(2.0f, 2.0f, 2.0f);
+    //stack.get().scale(2.0f, 2.0f, 2.0f);
     sh.setMatrix("model", stack.get().getValues());
-    fr.drawString(0, 0, "Das ist ein Test");
-}
+
+    char buffer[50];
+    snprintf(buffer, 50, "FPS: %.2f", fps.getUpdatesPerSecond());
+    fr.drawString(10, 10, buffer);
+    snprintf(buffer, 50, "TPS: %.2f", tps.getUpdatesPerSecond());
+    fr.drawString(10, 20, buffer);
+    snprintf(buffer, 50, "Bias: %.6f", renderSettings.testBias);
+    fr.drawString(10, 30, buffer);
+    snprintf(buffer, 50, "Radius: %.6f", renderSettings.testRadius);
+    fr.drawString(10, 40, buffer);
+}
+
+bool Game::isRunning() const {
+    return true;
+}

+ 14 - 8
client/Game.h

@@ -1,9 +1,10 @@
 #ifndef GAME_H
 #define GAME_H
 
-#include "client/input/Keys.h"
-#include "client/input/MouseButtons.h"
+#include "client/input/Control.h"
 #include "client/math/Camera.h"
+#include "client/utils/Clock.h"
+#include "client/rendering/RenderSettings.h"
 #include "client/rendering/wrapper/Shader.h"
 #include "client/math/MatrixStack.h"
 #include "client/rendering/Mesh.h"
@@ -12,20 +13,25 @@
 
 class Game final {
 public:
-    Game(const Keys& keys, const MouseButtons& buttons, const Camera& camera, Ray& ray);
+    Game(const Control& control, const Camera& camera, Ray& ray, const Clock& fps, const Clock& tps, 
+            RenderSettings& renderSettings);
 
     void tick();
-    void renderWorld(float lag, MatrixStack& stack, Shader& sh);
-    void renderTextOverlay(float lag, MatrixStack& stack, Shader& sh, FontRenderer& fr);
+    void renderWorld(float lag, MatrixStack& stack, Shader& sh) const;
+    void renderTextOverlay(float lag, MatrixStack& stack, Shader& sh, FontRenderer& fr) const;
+    
+    bool isRunning() const;
 
 private:
     void addCube(float x, float y, float z, bool bottom, bool top, bool left, bool right, bool front, bool back);
 
-    const Keys& keys;
-    const MouseButtons& buttons;
+    const Control& control;
     const Camera& camera;
     Ray& ray;
-    
+    const Clock& fps;
+    const Clock& tps;
+    RenderSettings& renderSettings;
+
     float lengthAngle;
     float widthAngle;
     Vector pos;

+ 21 - 21
client/Main.cpp

@@ -5,10 +5,10 @@
 #include "client/rendering/wrapper/Window.h"
 #include "client/rendering/Shaders.h"
 #include "client/rendering/Framebuffers.h"
-#include "client/input/Keys.h"
-#include "client/input/MouseButtons.h"
+#include "client/input/Control.h"
 #include "client/Engine.h"
 #include "client/utils/Clock.h"
+#include "client/rendering/RenderSettings.h"
 
 bool initGLEW() {
     GLenum err = glewInit();
@@ -20,11 +20,10 @@ bool initGLEW() {
     return false;
 }
 
-void initCallbacks(Window& w, WindowSize& size, Framebuffers& framebuffers, Keys& keys, MouseButtons& buttons) {
+void initCallbacks(Window& w, WindowSize& size, Framebuffers& framebuffers, Control& control) {
     static WindowSize& cSize = size;
     static Framebuffers& cFramebuffers = framebuffers;
-    static Keys& cKeys = keys;
-    static MouseButtons& cButtons = buttons;
+    static Control& cControl = control;
     w.setFramebufferSizeCallback([](GLFWwindow*, int newWidth, int newHeight) {
         glViewport(0, 0, newWidth, newHeight);
         cSize.width = newWidth;
@@ -33,20 +32,20 @@ void initCallbacks(Window& w, WindowSize& size, Framebuffers& framebuffers, Keys
     });
     w.setKeyCallback([](GLFWwindow*, int key, int, int action, int) {
         if(action == GLFW_PRESS) {
-            cKeys.press(key);
+            cControl.keys.press(key);
         } else if(action == GLFW_RELEASE) {
-            cKeys.release(key);
+            cControl.keys.release(key);
         }
     });
     w.setMouseButtonCallback([](GLFWwindow*, int button, int action, int) {
         if(action == GLFW_PRESS) {
-            cButtons.press(button);
+            cControl.buttons.press(button);
         } else if(action == GLFW_RELEASE) {
-            cButtons.release(button);
+            cControl.buttons.release(button);
         }
     });
     w.setCursorPosCallback([](GLFWwindow*, double x, double y) {
-        cButtons.move(x, y);
+        cControl.buttons.move(x, y);
     });
 }
 
@@ -71,29 +70,30 @@ int main() {
         return 0;
     }
     
-    Keys keys;
-    MouseButtons mButtons;
-    initCallbacks(window, size, framebuffers, keys, mButtons);
-    
     Ray ray;
     Camera camera(ray);
+    RenderSettings renderSettings;
+    Engine engine(shaders, framebuffers, camera, size, renderSettings);
+    
+    Control control;
     Clock fps;
+    Clock tps;
+    Game game(control, camera, ray, fps, tps, renderSettings);
     
-    Engine engine(shaders, framebuffers, keys, mButtons, camera, ray, fps, size);
+    initCallbacks(window, size, framebuffers, control);
     window.show();
 
     const u64 nanosPerTick = 50000000;
     u64 lag = 0;
-    while(!window.shouldClose() && engine.isRunning()) {
-        engine.renderTick((float) lag / nanosPerTick);
+    while(!window.shouldClose() && game.isRunning()) {
+        engine.renderTick((float) lag / nanosPerTick, game);
         window.swapBuffers();
         lag += fps.update();
         while(lag >= nanosPerTick) {
             lag -= nanosPerTick;
-            keys.tick();
-            mButtons.tick();
-            engine.tick();
-            mButtons.postTick();
+            tps.update();
+            control.tick();
+            game.tick();
         }
         glfwPollEvents();
     }

+ 6 - 0
client/input/Control.cpp

@@ -0,0 +1,6 @@
+#include "client/input/Control.h"
+
+void Control::tick() {
+    keys.tick();
+    buttons.tick();
+}

+ 14 - 0
client/input/Control.h

@@ -0,0 +1,14 @@
+#ifndef CONTROL_H
+#define CONTROL_H
+
+#include "client/input/Keys.h"
+#include "client/input/MouseButtons.h"
+
+struct Control {
+    void tick();
+    
+    Keys keys;
+    MouseButtons buttons;
+};
+
+#endif

+ 12 - 10
client/input/MouseButtons.cpp

@@ -23,18 +23,19 @@ std::ostream& operator<<(std::ostream& os, const MouseButtons::MouseButton& m) {
     return os;
 }
 
-MouseButtons::MouseButtons() : primary(buttons[0]), secondary(buttons[1]), middle(buttons[2]), oldX(0), oldY(0), x(0), y(0) {
+MouseButtons::MouseButtons() : primary(buttons[0]), secondary(buttons[1]), middle(buttons[2]), lastX(0), lastY(0),
+x(0), y(0), updateLast(true) {
     buttons[0].glfwButton = GLFW_MOUSE_BUTTON_1;
     buttons[1].glfwButton = GLFW_MOUSE_BUTTON_2;
     buttons[2].glfwButton = GLFW_MOUSE_BUTTON_3;
 }
 
-double MouseButtons::getOldX() const {
-    return oldX;
+double MouseButtons::getLastX() const {
+    return lastX;
 }
 
-double MouseButtons::getOldY() const {
-    return oldY;
+double MouseButtons::getLastY() const {
+    return lastY;
 }
 
 double MouseButtons::getX() const {
@@ -65,18 +66,19 @@ void MouseButtons::press(int button) {
 void MouseButtons::move(double x, double y) {
     MouseButtons::x = x;
     MouseButtons::y = y;
+    updateLast = false;
 }
 
 void MouseButtons::tick() {
+    if(updateLast) {
+        lastX = x;
+        lastY = y;
+    }
+    updateLast = true;
     for(MouseButton& k : buttons) {
         k.downTime += k.down;
         k.down = k.down && !k.shouldRelease;
         k.downTime *= !k.shouldRelease;
         k.shouldRelease = false;
     }
-}
-
-void MouseButtons::postTick() {
-    oldX = x;
-    oldY = y;
 }

+ 5 - 5
client/input/MouseButtons.h

@@ -36,8 +36,8 @@ private:
 public:
     MouseButtons();
 
-    double getOldX() const;
-    double getOldY() const;
+    double getLastX() const;
+    double getLastY() const;
     double getX() const;
     double getY() const;
 
@@ -49,7 +49,6 @@ public:
     void press(int button);
     void move(double x, double y);
     void tick();
-    void postTick();
 
 private:
     MouseButtons(const MouseButtons&) = delete;
@@ -57,10 +56,11 @@ private:
     MouseButtons(MouseButtons&&) = delete;
     MouseButtons& operator=(MouseButtons&&) = delete;
 
-    double oldX;
-    double oldY;
+    double lastX;
+    double lastY;
     double x;
     double y;
+    bool updateLast;
 };
 
 std::ostream& operator<<(std::ostream& os, const MouseButtons::MouseButton& m);

+ 4 - 0
client/rendering/RenderSettings.cpp

@@ -0,0 +1,4 @@
+#include "RenderSettings.h"
+
+RenderSettings::RenderSettings() : useSSAO(true), testRadius(0.0005f), testBias(0.0005), ortho(false) {
+}

+ 16 - 0
client/rendering/RenderSettings.h

@@ -0,0 +1,16 @@
+#ifndef RENDERSETTINGS_H
+#define RENDERSETTINGS_H
+
+#include "client/math/Vector.h"
+
+struct RenderSettings {
+    RenderSettings();
+    
+    bool useSSAO;
+    float testRadius;
+    float testBias;
+    bool ortho;
+    Vector testOrthoCenter;
+};
+
+#endif

+ 1 - 1
meson.build

@@ -4,7 +4,7 @@ sourcesCommon = ['common/block/BlockRegistry.cpp', 'common/block/Block.cpp', 'co
 
 sourcesServer = ['server/GameServer.cpp', 'server/commands/CommandUtils.cpp', 'server/commands/ServerCommands.cpp', 'server/commands/CommandManager.cpp', 'server/network/Server.cpp', 'server/Main.cpp']
 
-sourcesClient = ['client/Main.cpp', 'client/rendering/WindowSize.cpp', 'client/math/Frustum.cpp', 'client/math/Ray.cpp', 'client/rendering/Framebuffers.cpp', 'client/rendering/wrapper/GLFWWrapper.cpp', 'client/rendering/wrapper/Window.cpp', 'client/Engine.cpp', 'client/input/Keys.cpp', 'client/rendering/wrapper/Shader.cpp', 'client/rendering/Shaders.cpp', 'client/Utils.cpp', 'client/rendering/Mesh.cpp', 'client/math/Matrix.cpp', 'client/math/MatrixStack.cpp', 'client/math/Vector.cpp', 'client/math/Camera.cpp', 'client/math/Plane.cpp', 'client/Game.cpp', 'client/input/MouseButtons.cpp', 'client/rendering/Texture.cpp', 'client/rendering/FontRenderer.cpp', 'client/rendering/wrapper/Framebuffer.cpp', 'client/rendering/NoiseTexture.cpp', 'client/utils/Clock.cpp']
+sourcesClient = ['client/Main.cpp', 'client/rendering/WindowSize.cpp', 'client/math/Frustum.cpp', 'client/math/Ray.cpp', 'client/rendering/Framebuffers.cpp', 'client/rendering/wrapper/GLFWWrapper.cpp', 'client/rendering/wrapper/Window.cpp', 'client/Engine.cpp', 'client/input/Keys.cpp', 'client/rendering/wrapper/Shader.cpp', 'client/rendering/Shaders.cpp', 'client/Utils.cpp', 'client/rendering/Mesh.cpp', 'client/math/Matrix.cpp', 'client/math/MatrixStack.cpp', 'client/math/Vector.cpp', 'client/math/Camera.cpp', 'client/math/Plane.cpp', 'client/Game.cpp', 'client/input/MouseButtons.cpp', 'client/rendering/Texture.cpp', 'client/rendering/FontRenderer.cpp', 'client/rendering/wrapper/Framebuffer.cpp', 'client/rendering/NoiseTexture.cpp', 'client/utils/Clock.cpp', 'client/input/Control.cpp', 'client/rendering/RenderSettings.cpp']
 
 sourcesTest = ['tests/Main.cpp', 'server/commands/CommandUtils.cpp']