Browse Source

clean up, removed math lib - replaced by gaming core

Kajetan Johannes Hammerle 3 years ago
parent
commit
9e6a8c4d85
53 changed files with 216 additions and 1955 deletions
  1. 37 395
      client/Game.cpp
  2. 4 39
      client/Game.h
  3. 7 7
      client/Main.cpp
  4. 0 33
      client/math/Frustum.cpp
  5. 0 19
      client/math/Frustum.h
  6. 0 194
      client/math/Matrix.cpp
  7. 0 42
      client/math/Matrix.h
  8. 0 23
      client/math/MatrixStack.cpp
  9. 0 20
      client/math/MatrixStack.h
  10. 0 16
      client/math/Plane.cpp
  11. 0 18
      client/math/Plane.h
  12. 0 137
      client/math/Quaternion.cpp
  13. 0 37
      client/math/Quaternion.h
  14. 34 58
      client/rendering/Engine.cpp
  15. 4 4
      client/rendering/Engine.h
  16. 3 13
      client/rendering/Framebuffers.cpp
  17. 2 4
      client/rendering/Framebuffers.h
  18. 3 26
      client/rendering/Mesh.cpp
  19. 0 1
      client/rendering/Mesh.h
  20. 1 2
      client/rendering/RenderSettings.cpp
  21. 0 2
      client/rendering/RenderSettings.h
  22. 20 29
      client/rendering/Renderer.cpp
  23. 5 5
      client/rendering/Renderer.h
  24. 3 5
      client/rendering/Shaders.cpp
  25. 0 2
      client/rendering/Shaders.h
  26. 1 13
      client/rendering/Triangle.cpp
  27. 5 8
      client/rendering/Triangle.h
  28. 1 1
      client/rendering/Vertex.h
  29. 0 4
      client/rendering/WindowSize.cpp
  30. 0 11
      client/rendering/WindowSize.h
  31. 1 1
      client/rendering/renderer/WorldRenderer.cpp
  32. 11 23
      client/rendering/wrapper/Framebuffer.cpp
  33. 6 11
      client/rendering/wrapper/Framebuffer.h
  34. 1 1
      client/rendering/wrapper/Shader.cpp
  35. 1 1
      client/rendering/wrapper/Window.cpp
  36. 2 2
      client/rendering/wrapper/Window.h
  37. 0 5
      client/utils/Utils.cpp
  38. 0 6
      client/utils/Utils.h
  39. 0 45
      common/math/Vector.cpp
  40. 0 127
      common/math/Vector.h
  41. 0 333
      common/utils/KDTree.cpp
  42. 0 69
      common/utils/KDTree.h
  43. 62 10
      meson.build
  44. 0 20
      resources/shader/antialiasFragment.fs
  45. 0 11
      resources/shader/antialiasVertex.vs
  46. 0 32
      resources/shader/fragment.fs
  47. 0 16
      resources/shader/lineFragment.fs
  48. 0 18
      resources/shader/lineVertex.vs
  49. 0 22
      resources/shader/overlayFragment.fs
  50. 0 18
      resources/shader/overlayVertex.vs
  51. 1 9
      resources/shader/worldFragment.fs
  52. 1 4
      resources/shader/worldPostFragment.fs
  53. 0 3
      resources/shader/worldVertex.vs

+ 37 - 395
client/Game.cpp

@@ -3,433 +3,75 @@
 #include <fstream>
 
 #include "client/Game.h"
-#include "client/utils/Utils.h"
 #include "rendering/Renderer.h"
 #include "common/utils/String.h"
 #include "common/utils/Random.h"
-#include "math/Quaternion.h"
+#include "gaming-core/math/Quaternion.h"
+#include "gaming-core/utils/Utils.h"
 #include "rendering/wrapper/GLWrapper.h"
 #include "rendering/wrapper/GLFWWrapper.h"
 
-static float readFloat(std::ifstream& in) {
-    float f;
-    in >> f;
-    in.get();
-    return f;
-}
-
-static Vector3 readVector3(std::ifstream& in) {
-    float x = readFloat(in);
-    float y = readFloat(in);
-    float z = readFloat(in);
-    return Vector3(x, y, z);
-}
-
-static Vector2 readVector2(std::ifstream& in) {
-    float x = readFloat(in);
-    float y = readFloat(in);
-    return Vector2(x, y);
-}
-
-Game::Game(const Control& control, const Clock& fps, const Clock& tps, RenderSettings& renderSettings,
-        const WindowSize& size, const char* file) :
-control(control), fps(fps), tps(tps), renderSettings(renderSettings), size(size), world(blockRegistry),
-worldRenderer(world), pointIndex(0), moveSpeed(0.125f), movedLength(0.0f), mode(Mode::AUTO) {
-    Random r(0);
-    float h = World::WORLD_SIZE * 0.6f;
-    float mid = World::WORLD_SIZE * 0.5f;
-    float randLength = World::WORLD_SIZE * 0.125f * 0.25f;
-    pos.set(0, h, 0);
-    lastPos = pos;
-
-    rotation = Quaternion(Vector3(1, 0, 0), -80);
-    lastRotation = rotation;
-
-    Quaternion q;
-    for(uint i = 0; i < cameraPoints.getCapacity(); i++) {
-        Vector3 offset(mid, h, mid);
-        offset += Vector3(r.nextFloat(randLength), r.nextFloat(randLength), r.nextFloat(randLength));
-        Vector3 v(i * 360.0f / cameraPoints.getCapacity(), 0.0f);
-        v *= mid * 0.5f;
-        v += offset;
-
-        q.mul(Quaternion(Vector3(r.nextFloat() * 360.0f, r.nextFloat() * -90.0f), -10.0f));
-        cameraPoints.add({v, q, 0.0f});
-    }
-    updateDistances();
-
-    std::vector<KDTree::Triangle> data;
-
-    (void) readFloat;
-    (void) file;
-
-    std::ifstream in;
-    in.open(file);
-    if(in.good()) {
-        while(true) {
-            Vector3 a = readVector3(in);
-            Vector2 ta = readVector2(in);
-
-            Vector3 b = readVector3(in);
-            Vector2 tb = readVector2(in);
-
-            Vector3 c = readVector3(in);
-            Vector2 tc = readVector2(in);
-
-            if(in.eof()) {
-                break;
-            }
-
-            data.push_back(KDTree::Triangle(a, b, c));
-            treeData.add(Triangle(Vertex(a, ta), Vertex(b, tb), Vertex(c, tc)));
-        }
-    }
-
-    //generateSphere(data);
-    //generateRandom(data);
-
-    /*for(KDTree::Triangle& t : data) {
-        treeData.add(Triangle(
-                Vertex(t[0], Vector2(8.0f / 16.0f, 0.0f)),
-                Vertex(t[1], Vector2(9.0f / 16.0f, 0.0f)),
-                Vertex(t[2], Vector2(9.0f / 16.0f, 1.0f / 16.0f))
-                ));
-    }*/
-    treeData.build();
-
-    u64 time = GLFWWrapper::getTimeNanos();
-    kdTree.build(data);
-    time = GLFWWrapper::getTimeNanos() - time;
-    std::cout << "KD-Tree-Build-Time: " << time << "ns for " << data.size() << " triangles\n";
-    kdTree.fillLines(lines);
+Game::Game(const Control& control, const Clock& fps, const Clock& tps, RenderSettings& settings, const Size& size) :
+control(control), fps(fps), tps(tps), renderSettings(settings), size(size), world(blockRegistry), worldRenderer(world) {
+    pos = Vector3(16.0f, 24.0f, 0.0f);
 }
 
 void Game::tick() {
     lastRotation = rotation;
     lastPos = pos;
 
-    Matrix m = rotation.toMatrix();
-    Vector3 right = m * Vector3(1.0f, 0.0f, 0.0f);
-    Vector3 up = m * Vector3(0.0f, 1.0f, 0.0f);
-    Vector3 back = m * Vector3(0.0f, 0.0f, -1.0f);
-
-    if(mode == Mode::PLAYER) {
-        const float speed = 1.0f;
-        if(control.keys.down.isDown()) {
-            pos += back * speed;
-        }
-        if(control.keys.up.isDown()) {
-            pos -= back * speed;
-        }
-        if(control.keys.left.isDown()) {
-            pos -= right * speed;
-        }
-        if(control.keys.right.isDown()) {
-            pos += right * speed;
-        }
-        if(control.keys.jump.isDown()) {
-            pos += up * speed;
-        }
-        if(control.keys.sneak.isDown()) {
-            pos -= up * speed;
-        }
-
-        const float rotationSpeed = 5.0f;
-        if(control.keys.camLeft.isDown()) {
-            rotation.mul(Quaternion(up, rotationSpeed));
-        }
-        if(control.keys.camRight.isDown()) {
-            rotation.mul(Quaternion(up, -rotationSpeed));
-        }
-        if(control.keys.camUp.isDown()) {
-            rotation.mul(Quaternion(right, rotationSpeed));
-        }
-        if(control.keys.camDown.isDown()) {
-            rotation.mul(Quaternion(right, -rotationSpeed));
-        }
+    Vector3 right = rotation * Vector3(1.0f, 0.0f, 0.0f);
+    Vector3 up = rotation * Vector3(0.0f, 1.0f, 0.0f);
+    Vector3 back = rotation * Vector3(0.0f, 0.0f, -1.0f);
 
-        if(control.keys.test3.getDownTime() == 1) {
-            cameraPoints.add({pos, rotation, 0.0f});
-        }
-    } else if(mode == Mode::AUTO) {
-        movedLength += moveSpeed;
-
-        if(control.keys.camUp.isDown()) {
-            moveSpeed += 0.0125f;
-            if(moveSpeed > 1.0f) {
-                moveSpeed = 1.0f;
-            }
-        }
-        if(control.keys.camDown.isDown()) {
-            moveSpeed -= 0.0125f;
-            if(moveSpeed < 0.0f) {
-                moveSpeed = 0.0f;
-            }
-        }
-
-        if(control.keys.test3.isDown()) {
-            mode = Mode::PLAYER;
-            cameraPoints.clear();
-        }
+    const float speed = 1.0f;
+    if(control.keys.down.isDown()) {
+        pos += back * speed;
     }
-
-    if(control.keys.test.isDown()) {
-        mode = Mode::PLAYER;
+    if(control.keys.up.isDown()) {
+        pos -= back * speed;
     }
-    if(control.keys.test2.isDown() && cameraPoints.getLength() >= 3) {
-        mode = Mode::AUTO;
-        movedLength = 0.0f;
-        updateDistances();
+    if(control.keys.left.isDown()) {
+        pos -= right * speed;
     }
-    if(control.keys.test4.getDownTime() == 1) {
-        renderSettings.shadows = !renderSettings.shadows;
+    if(control.keys.right.isDown()) {
+        pos += right * speed;
     }
-    if(control.keys.test5.getDownTime() == 1) {
-        renderSettings.ssao = !renderSettings.ssao;
+    if(control.keys.jump.isDown()) {
+        pos += up * speed;
     }
-    if(control.keys.test6.getDownTime() == 1) {
-        renderSettings.bump += 0.05f;
-        if(renderSettings.bump > 1.0f) {
-            renderSettings.bump = 0.0f;
-        }
+    if(control.keys.sneak.isDown()) {
+        pos -= up * speed;
     }
-    if(control.keys.factor.getDownTime() == 1) {
-        if(renderSettings.factor == 1) {
-            renderSettings.factor = 2;
-        } else if(renderSettings.factor == 2) {
-            renderSettings.factor = 3;
-        } else {
-            renderSettings.factor = 1;
-        }
-        renderSettings.dirtyFactor = true;
-    }
-
-    if(control.buttons.primary.getDownTime() == 1) {
-        float hWidth = size.width * 0.5f;
-        float hHeight = size.height * 0.5f;
-
-        float x = (control.buttons.getX() - hWidth) / hWidth;
-        float y = -(control.buttons.getY() - hHeight) / hHeight;
-
-        float aspect = hWidth / hHeight;
-        float tan = tanf((0.5f * 60.0f) * M_PI / 180.0f);
-        float q = 1.0f / tan;
-
-        Vector3 direction(x / (q / aspect), y / q, 1.0f);
-        direction.normalize();
-        direction = m * direction;
 
-        clickLine.clear();
-        clickLine.add(pos, pos + direction * 100.0f, 0xFF00FF);
-
-        u64 time = GLFWWrapper::getTimeNanos();
-        bool check = kdTree.findIntersection(pos, direction);
-        time = GLFWWrapper::getTimeNanos() - time;
-        std::cout << "Intersection-Time: " << time << "ns\n";
-        if(check) {
-            KDTree::Triangle t = kdTree.getIntersectedTriangle();
-
-            clickLine.add(t[0], t[1], 0xFFFF00);
-            clickLine.add(t[1], t[2], 0xFFFF00);
-            clickLine.add(t[2], t[0], 0xFFFF00);
-
-            Vector3 hit = kdTree.getIntersection();
-            float diff = 0.2f;
-
-            clickLine.add(hit - Vector3(diff, 0.0f, 0.0f), hit + Vector3(diff, 0.0f, 0.0f), 0x00FF00);
-            clickLine.add(hit - Vector3(0.0f, diff, 0.0f), hit + Vector3(0.0f, diff, 0.0f), 0x00FF00);
-            clickLine.add(hit - Vector3(0.0f, 0.0f, diff), hit + Vector3(0.0f, 0.0f, diff), 0x00FF00);
-        }
-
-        clickLine.build();
-
-        kdTree.fillLines(lines);
+    const float rotationSpeed = 5.0f;
+    if(control.keys.camLeft.isDown()) {
+        rotation = Quaternion(up, -rotationSpeed) * rotation;
+    }
+    if(control.keys.camRight.isDown()) {
+        rotation = Quaternion(up, rotationSpeed) * rotation;
+    }
+    if(control.keys.camUp.isDown()) {
+        rotation = Quaternion(right, -rotationSpeed) * rotation;
+    }
+    if(control.keys.camDown.isDown()) {
+        rotation = Quaternion(right, rotationSpeed) * rotation;
     }
 }
 
 void Game::renderWorld(float lag, Renderer& renderer) const {
-    if(mode == Mode::AUTO) {
-        float leftLength = (movedLength - moveSpeed) + moveSpeed * lag;
-        uint index = 0;
-        while(leftLength >= cameraPoints[index].distance) {
-            leftLength -= cameraPoints[index].distance;
-            index = (index + 1) % cameraPoints.getLength();
-        }
-        float t = leftLength / cameraPoints[index].distance;
-        Vector3 interpolatedPos = pointUntilDistance(leftLength, index, 4000);
-
-        uint a = index == 0 ? cameraPoints.getLength() - 1 : index - 1;
-        uint b = (a + 1) % cameraPoints.getLength();
-        uint c = (a + 2) % cameraPoints.getLength();
-        uint d = (a + 3) % cameraPoints.getLength();
-
-        renderer.update(interpolatedPos, cameraPoints[b].q.squad(t, cameraPoints[a].q, cameraPoints[c].q, cameraPoints[d].q));
-        pos = interpolatedPos;
-    } else if(mode == Mode::PLAYER) {
-        Vector3 v = lastPos + (pos - lastPos) * lag;
-        renderer.update(v, lastRotation.slerp(lag, rotation));
-    }
+    renderer.update(Utils::interpolate(lastPos, pos, lag), lastRotation.lerp(lag, rotation));
     worldRenderer.render(lag, renderer);
-    treeData.draw();
-}
-
-void Game::renderWorldLines(float lag, Renderer& renderer) const {
-    (void) lag;
-    renderer.translateTo(0.0f, 0.0f, 0.0f);
-    renderer.update();
-    if(control.keys.kdTree.isDown()) {
-        GLWrapper::setLineThickness(1.0f);
-        lines.draw();
-    }
-    GLWrapper::setLineThickness(5.0f);
-    clickLine.draw();
 }
 
 void Game::renderTextOverlay(float lag, Renderer& renderer, FontRenderer& fr) const {
     (void) lag;
     renderer.scale(2.0f).update();
-
-    String s;
-    fr.drawString(10, 10, s.append("FPS: ").append(fps.getUpdatesPerSecond()).append(" TPS: ").append(tps.getUpdatesPerSecond()));
-    fr.drawString(10, 19, s.clear().append("Speed: ").append(moveSpeed));
-    Vector3 inter = kdTree.getIntersection();
-    fr.drawString(10, 29, s.clear().append("Intersection: (").append(inter[0]).append(", ").append(inter[1]).append(", ").append(inter[2]).append(")"));
-    s.clear();
-    s += pos;
-    fr.drawString(10, 38, s);
-    for(uint i = 0; i < cameraPoints.getLength(); i++) {
-        s.clear().append(i + 1).append(": ");
-        s += cameraPoints[i].pos;
-        fr.drawString(10, i * 9 + 47, s);
-    }
+    StringBuffer<100> s;
+    s.append("FPS: ").append(fps.getUpdatesPerSecond()).append(" TPS: ").append(tps.getUpdatesPerSecond());
+    fr.drawString(10, 10, s);
 }
 
 bool Game::isRunning() const {
     return true;
-}
-
-Vector3 Game::splineTangent(const Vector3& prev, const Vector3& current, const Vector3& next) const {
-    (void) current;
-    //Vector3 v(current);
-    //v.sub(prev).mul(0.5f).addMul(next, 0.5f).addMul(current, -0.5f);
-    return (next - prev) * 0.5f;
-}
-
-Vector3 Game::interpolate(const Vector3& a, const Vector3& b, const Vector3& tanA, const Vector3& tanB, float t) const {
-    float t2 = t * t;
-    float t3 = t2 * t;
-    return a * (2.0f * t3 - 3.0f * t2 + 1.0f) +
-            b * (-2.0f * t3 + 3.0f * t2) +
-            tanA * (t3 - 2.0f * t2 + t) +
-            tanB * (t3 - t2);
-}
-
-float Game::distance(uint index, uint splits) const {
-    Vector3 a;
-    Vector3 b;
-    Vector3 tanA;
-    Vector3 tanB;
-    getPointsAndTangents(index, a, b, tanA, tanB);
-
-    Vector3 currentPos;
-    Vector3 currentNext = interpolate(a, b, tanA, tanB, 0.0f);
-
-    float sum = 0.0f;
-    for(uint i = 0; i <= splits; i++) {
-        currentPos = currentNext;
-        float t = (i + 1.0f) / (splits + 1.0f);
-        currentNext = interpolate(a, b, tanA, tanB, t);
-        float l = static_cast<Vector3> (currentPos - currentNext).length();
-        sum += l;
-    }
-    return sum;
-}
-
-Vector3 Game::pointUntilDistance(float leftDistance, uint index, uint splits) const {
-    Vector3 a;
-    Vector3 b;
-    Vector3 tanA;
-    Vector3 tanB;
-    getPointsAndTangents(index, a, b, tanA, tanB);
-
-    Vector3 currentPos;
-    Vector3 currentNext = interpolate(a, b, tanA, tanB, 0.0f);
-
-    float sum = 0.0f;
-    uint i = 0;
-    while(leftDistance > sum) {
-        currentPos = currentNext;
-        float t = (i + 1.0f) / (splits + 1.0f);
-        currentNext = interpolate(a, b, tanA, tanB, t);
-        float l = static_cast<Vector3> (currentPos - currentNext).length();
-        sum += l;
-        i++;
-    }
-    return currentNext;
-}
-
-void Game::getPointsAndTangents(uint index, Vector3& a, Vector3& b, Vector3& tanA, Vector3& tanB) const {
-    uint prev = index == 0 ? cameraPoints.getLength() - 1 : index - 1;
-    uint currentA = (prev + 1) % cameraPoints.getLength();
-    uint currentB = (prev + 2) % cameraPoints.getLength();
-    uint next = (prev + 3) % cameraPoints.getLength();
-
-    a = cameraPoints[currentA].pos;
-    b = cameraPoints[currentB].pos;
-
-    tanA = splineTangent(cameraPoints[prev].pos, a, b);
-    tanB = splineTangent(a, b, cameraPoints[next].pos);
-}
-
-void Game::updateDistances() {
-    for(uint i = 0; i < cameraPoints.getLength(); i++) {
-        cameraPoints[i].distance = distance(i, 10000);
-    }
-}
-
-void Game::generateSphere(std::vector<KDTree::Triangle>& data) {
-    int fieldSize = 8;
-    int quality = 3;
-    float radius = 30;
-
-    int triangles = fieldSize * quality;
-    int layers = (2 + fieldSize) * quality;
-
-    for(int l = 0; l < layers; l++) {
-        float high1 = cosf((M_PI * l) / layers);
-        float high2 = cosf((M_PI * (l + 1)) / layers);
-
-        float r1 = sqrtf(1 - high1 * high1) * radius;
-        float r2 = sqrtf(1 - high2 * high2) * radius;
-
-        high1 *= radius;
-        high2 *= radius;
-
-        for(int i = 0; i < triangles; i++) {
-            float first = 2 * M_PI * i / triangles;
-            float second = 2 * M_PI * (i + 1) / triangles;
-
-            data.push_back(KDTree::Triangle(
-                    Vector3(r2 * cosf(first), high2, r2 * sinf(first)),
-                    Vector3(r1 * cosf(first), high1, r1 * sinf(first)),
-                    Vector3(r1 * cosf(second), high1, r1 * sinf(second))));
-
-            data.push_back(KDTree::Triangle(
-                    Vector3(r2 * cosf(first), high2, r2 * sinf(first)),
-                    Vector3(r1 * cosf(second), high1, r1 * sinf(second)),
-                    Vector3(r2 * cosf(second), high2, r2 * sinf(second))));
-        }
-    }
-}
-
-void Game::generateRandom(std::vector<KDTree::Triangle>& data) {
-    float radius = 25.0f;
-    float diff = 5.0f;
-    Random r(0);
-    for(int i = 0; i < 10000; i++) {
-        Vector3 a(r.nextFloat() * radius, r.nextFloat() * radius, r.nextFloat() * radius);
-        Vector3 b = a + Vector3(r.nextFloat() * diff, r.nextFloat() * diff, r.nextFloat() * diff);
-        Vector3 c = a + Vector3(r.nextFloat() * diff, r.nextFloat() * diff, r.nextFloat() * diff);
-        data.push_back(KDTree::Triangle(a, b, c));
-    }
 }

+ 4 - 39
client/Game.h

@@ -5,20 +5,16 @@
 #include "client/utils/Clock.h"
 #include "client/rendering/RenderSettings.h"
 #include "client/rendering/Renderer.h"
-#include "client/rendering/Mesh.h"
 #include "client/rendering/FileTexture.h"
 #include "client/rendering/FontRenderer.h"
 #include "common/world/World.h"
 #include "common/block/BlockRegistry.h"
 #include "rendering/renderer/WorldRenderer.h"
-#include "common/utils/KDTree.h"
-#include "client/rendering/Lines.h"
-#include "client/rendering/WindowSize.h"
+#include "gaming-core/utils/Size.h"
 
 class Game final {
 public:
-    Game(const Control& control, const Clock& fps, const Clock& tps, RenderSettings& renderSettings,
-            const WindowSize& size, const char* file);
+    Game(const Control& control, const Clock& fps, const Clock& tps, RenderSettings& renderSettings, const Size& size);
 
     void tick();
     void renderWorld(float lag, Renderer& renderer) const;
@@ -28,24 +24,14 @@ public:
     bool isRunning() const;
 
 private:
-    Vector3 splineTangent(const Vector3& prev, const Vector3& current, const Vector3& next) const;
-    Vector3 interpolate(const Vector3& a, const Vector3& b, const Vector3& tanA, const Vector3& tanB, float t) const;
-    float distance(uint index, uint splits) const;
-    Vector3 pointUntilDistance(float leftDistance, uint index, uint splits) const;
-    void getPointsAndTangents(uint index, Vector3& a, Vector3& b, Vector3& tanA, Vector3& tanB) const;
-    void updateDistances();
-
-    void generateSphere(std::vector<KDTree::Triangle>& data);
-    void generateRandom(std::vector<KDTree::Triangle>& data);
-
     const Control& control;
     const Clock& fps;
     const Clock& tps;
     RenderSettings& renderSettings;
-    const WindowSize& size;
+    const Size& size;
 
     Vector3 lastPos;
-    mutable Vector3 pos;
+    Vector3 pos;
     Quaternion lastRotation;
     Quaternion rotation;
 
@@ -53,27 +39,6 @@ private:
     World world;
 
     WorldRenderer worldRenderer;
-
-    struct Point {
-        Vector3 pos;
-        Quaternion q;
-        float distance;
-    };
-
-    List<Point, 25> cameraPoints;
-    uint pointIndex;
-    float moveSpeed;
-    float movedLength;
-
-    enum Mode {
-        AUTO, PLAYER
-    };
-
-    Mode mode;
-    KDTree kdTree;
-    Lines lines;
-    Mesh treeData;
-    Lines clickLine;
 };
 
 #endif

+ 7 - 7
client/Main.cpp

@@ -1,7 +1,7 @@
 #include <iostream>
 
 #include "client/rendering/wrapper/GLFWWrapper.h"
-#include "client/rendering/WindowSize.h"
+#include "gaming-core/utils/Size.h"
 #include "client/rendering/wrapper/Window.h"
 #include "client/rendering/Shaders.h"
 #include "client/rendering/Framebuffers.h"
@@ -21,8 +21,8 @@ bool initGLEW() {
     return false;
 }
 
-void initCallbacks(Window& w, WindowSize& size, Framebuffers& framebuffers, Control& control) {
-    static WindowSize& cSize = size;
+void initCallbacks(Window& w, Size& size, Framebuffers& framebuffers, Control& control) {
+    static Size& cSize = size;
     static Framebuffers& cFramebuffers = framebuffers;
     static Control& cControl = control;
     w.setFramebufferSizeCallback([](GLFWwindow*, int newWidth, int newHeight) {
@@ -50,12 +50,12 @@ void initCallbacks(Window& w, WindowSize& size, Framebuffers& framebuffers, Cont
     });
 }
 
-int main(int argAmount, const char** args) {
-    if(argAmount < 2 || GLFWWrapper::hasError()) {
+int main() {
+    if(GLFWWrapper::hasError()) {
         return 0;
     }
 
-    WindowSize size(1024, 620);
+    Size size(1024, 620);
     Window window(size, "Test");
     if(window.hasError() || initGLEW()) {
         return 0;
@@ -77,7 +77,7 @@ int main(int argAmount, const char** args) {
     Control control;
     Clock fps;
     Clock tps;
-    static Game game(control, fps, tps, renderSettings, size, args[1]);
+    static Game game(control, fps, tps, renderSettings, size);
 
     initCallbacks(window, size, framebuffers, control);
     window.show();

+ 0 - 33
client/math/Frustum.cpp

@@ -1,33 +0,0 @@
-#include <cmath>
-
-#include "client/math/Frustum.h"
-
-Frustum::Frustum(float fovY, float nearClip, float farClip) : fovY(fovY), nearClip(nearClip), farClip(farClip) {
-}
-
-void Frustum::setProjection(Matrix& m, int width, int height) {
-    float tan = tanf((0.5f * fovY) * M_PI / 180.0f);
-    float q = 1.0f / tan;
-    float aspect = (float) width / height;
-
-    m.set(0, q / aspect);
-    m.set(1, 0.0f);
-    m.set(2, 0.0f);
-    m.set(3, 0.0f);
-    m.set(4, 0.0f);
-    m.set(5, q);
-    m.set(6, 0.0f);
-    m.set(7, 0.0f);
-    m.set(8, 0.0f);
-    m.set(9, 0.0f);
-    m.set(10, (nearClip + farClip) / (nearClip - farClip));
-    m.set(11, -1.0f);
-    m.set(12, 0.0f);
-    m.set(13, 0.0f);
-    m.set(14, (2.0f * nearClip * farClip) / (nearClip - farClip));
-    m.set(15, 0.0f);
-}
-
-float Frustum::getClipDifference() const {
-    return farClip - nearClip;
-}

+ 0 - 19
client/math/Frustum.h

@@ -1,19 +0,0 @@
-#ifndef FRUSTUM_H
-#define FRUSTUM_H
-
-#include "client/math/Matrix.h"
-
-class Frustum final {
-public:
-    Frustum(float fovY, float nearClip, float farClip);
-    void setProjection(Matrix& m, int width, int height);
-    
-    float getClipDifference() const;
-
-private:
-    float fovY;
-    float nearClip;
-    float farClip;
-};
-
-#endif

+ 0 - 194
client/math/Matrix.cpp

@@ -1,194 +0,0 @@
-#include <cmath>
-#include <iomanip>
-#include <cstring>
-#include <x86intrin.h>
-
-#include "client/math/Matrix.h"
-
-Matrix::Matrix() {
-    setToIdentity();
-}
-
-Matrix& Matrix::set(const Matrix& other) {
-    *this = other;
-    return *this;
-}
-
-Matrix& Matrix::setToIdentity() {
-    data[0] = 1.0f;
-    data[1] = 0.0f;
-    data[2] = 0.0f;
-    data[3] = 0.0f;
-    data[4] = 0.0f;
-    data[5] = 1.0f;
-    data[6] = 0.0f;
-    data[7] = 0.0f;
-    data[8] = 0.0f;
-    data[9] = 0.0f;
-    data[10] = 1.0f;
-    data[11] = 0.0f;
-    data[12] = 0.0f;
-    data[13] = 0.0f;
-    data[14] = 0.0f;
-    data[15] = 1.0f;
-    return *this;
-}
-
-Matrix& Matrix::set(uint index, float f) {
-    data[index] = f;
-    return *this;
-}
-
-const float* Matrix::getValues() const {
-    return data;
-}
-
-Matrix& Matrix::mul(const Matrix& m) {
-    float mNew[16];
-    mNew[0] = data[0] * m.data[0] + data[4] * m.data[1] + data[8] * m.data[2] + data[12] * m.data[3];
-    mNew[1] = data[1] * m.data[0] + data[5] * m.data[1] + data[9] * m.data[2] + data[13] * m.data[3];
-    mNew[2] = data[2] * m.data[0] + data[6] * m.data[1] + data[10] * m.data[2] + data[14] * m.data[3];
-    mNew[3] = data[3] * m.data[0] + data[7] * m.data[1] + data[11] * m.data[2] + data[15] * m.data[3];
-    mNew[4] = data[0] * m.data[4] + data[4] * m.data[5] + data[8] * m.data[6] + data[12] * m.data[7];
-    mNew[5] = data[1] * m.data[4] + data[5] * m.data[5] + data[9] * m.data[6] + data[13] * m.data[7];
-    mNew[6] = data[2] * m.data[4] + data[6] * m.data[5] + data[10] * m.data[6] + data[14] * m.data[7];
-    mNew[7] = data[3] * m.data[4] + data[7] * m.data[5] + data[11] * m.data[6] + data[15] * m.data[7];
-    mNew[8] = data[0] * m.data[8] + data[4] * m.data[9] + data[8] * m.data[10] + data[12] * m.data[11];
-    mNew[9] = data[1] * m.data[8] + data[5] * m.data[9] + data[9] * m.data[10] + data[13] * m.data[11];
-    mNew[10] = data[2] * m.data[8] + data[6] * m.data[9] + data[10] * m.data[10] + data[14] * m.data[11];
-    mNew[11] = data[3] * m.data[8] + data[7] * m.data[9] + data[11] * m.data[10] + data[15] * m.data[11];
-    mNew[12] = data[0] * m.data[12] + data[4] * m.data[13] + data[8] * m.data[14] + data[12] * m.data[15];
-    mNew[13] = data[1] * m.data[12] + data[5] * m.data[13] + data[9] * m.data[14] + data[13] * m.data[15];
-    mNew[14] = data[2] * m.data[12] + data[6] * m.data[13] + data[10] * m.data[14] + data[14] * m.data[15];
-    mNew[15] = data[3] * m.data[12] + data[7] * m.data[13] + data[11] * m.data[14] + data[15] * m.data[15];
-    std::memcpy(data, mNew, sizeof (float) * 16);
-    return *this;
-}
-
-Matrix& Matrix::scale(float sx, float sy, float sz) {
-    data[0] *= sx;
-    data[1] *= sx;
-    data[2] *= sx;
-    data[3] *= sx;
-    data[4] *= sy;
-    data[5] *= sy;
-    data[6] *= sy;
-    data[7] *= sy;
-    data[8] *= sz;
-    data[9] *= sz;
-    data[10] *= sz;
-    data[11] *= sz;
-    return *this;
-}
-
-Matrix& Matrix::scale(float s) {
-    return scale(s, s, s);
-}
-
-Matrix& Matrix::translate(float tx, float ty, float tz) {
-    return translateX(tx).translateY(ty).translateZ(tz);
-}
-
-Matrix& Matrix::translateX(float tx) {
-    data[12] += data[0] * tx;
-    data[13] += data[1] * tx;
-    data[14] += data[2] * tx;
-    data[15] += data[3] * tx;
-    return *this;
-}
-
-Matrix& Matrix::translateY(float ty) {
-    data[12] += data[4] * ty;
-    data[13] += data[5] * ty;
-    data[14] += data[6] * ty;
-    data[15] += data[7] * ty;
-    return *this;
-}
-
-Matrix& Matrix::translateZ(float tz) {
-    data[12] += data[8] * tz;
-    data[13] += data[9] * tz;
-    data[14] += data[10] * tz;
-    data[15] += data[11] * tz;
-    return *this;
-}
-
-Matrix& Matrix::translateTo(float tx, float ty, float tz) {
-    data[0] = 1.0f;
-    data[1] = 0.0f;
-    data[2] = 0.0f;
-    data[3] = 0.0f;
-    data[4] = 0.0f;
-    data[5] = 1.0f;
-    data[6] = 0.0f;
-    data[7] = 0.0f;
-    data[8] = 0.0f;
-    data[9] = 0.0f;
-    data[10] = 1.0f;
-    data[11] = 0.0f;
-    data[12] = tx;
-    data[13] = ty;
-    data[14] = tz;
-    data[15] = 1.0f;
-    return *this;
-}
-
-Matrix& Matrix::rotate(float degrees, uint indexA, uint indexB) {
-    degrees *= M_PIf32 / 180.0f;
-    float sin;
-    float cos;
-    sincosf(degrees, &sin, &cos);
-
-    __m128 va = _mm_load_ps(data + indexA);
-    __m128 vb = _mm_load_ps(data + indexB);
-
-    __m128 vcos = _mm_set1_ps(cos);
-
-    __m128 vresult1 = _mm_add_ps(_mm_mul_ps(va, vcos), _mm_mul_ps(vb, _mm_set1_ps(sin)));
-    __m128 vresult2 = _mm_add_ps(_mm_mul_ps(va, _mm_set1_ps(-sin)), _mm_mul_ps(vb, vcos));
-
-    _mm_store_ps(data + indexA, vresult1);
-    _mm_store_ps(data + indexB, vresult2);
-    return *this;
-}
-
-Matrix& Matrix::rotateX(float degrees) {
-    return rotate(degrees, 4, 8);
-}
-
-Matrix& Matrix::rotateY(float degrees) {
-    return rotate(degrees, 0, 8);
-}
-
-Matrix& Matrix::rotateZ(float degrees) {
-    return rotate(degrees, 0, 4);
-}
-
-std::ostream& operator<<(std::ostream& os, const Matrix& m) {
-    const float* data = m.getValues();
-    os << "Matrix\n(\n";
-    os << std::fixed << std::setprecision(5);
-    for(int i = 0; i < 4; i++) {
-        os << std::setw(15);
-        os << data[i] << ", ";
-        os << std::setw(15);
-        os << data[i + 4] << ", ";
-        os << std::setw(15);
-        os << data[i + 8] << ", ";
-        os << std::setw(15);
-        os << data[i + 12] << "\n";
-    }
-    os << std::defaultfloat;
-    os << ")";
-    return os;
-}
-
-Vector<3> operator*(const Matrix& m, const Vector<3>& v) {
-    const float* d = m.getValues();
-    Vector<3> result(
-            v[0] * d[0] + v[1] * d[4] + v[2] * d[8] + d[12],
-            v[0] * d[1] + v[1] * d[5] + v[2] * d[9] + d[13],
-            v[0] * d[2] + v[1] * d[6] + v[2] * d[10] + d[14]);
-    result *= 1.0f / (v[1] * d[3] + v[1] * d[7] + v[2] * d[11] + d[15]);
-    return result;
-}

+ 0 - 42
client/math/Matrix.h

@@ -1,42 +0,0 @@
-#ifndef MATRIX_H
-#define MATRIX_H
-
-#include <iostream>
-
-#include "common/math/Vector.h"
-
-class Matrix final {
-public:
-    Matrix();
-
-    Matrix& set(const Matrix& other);
-    Matrix& setToIdentity();
-    Matrix& set(uint index, float f);
-
-    const float* getValues() const;
-
-    Matrix& mul(const Matrix& m);
-
-    Matrix& scale(float sx, float sy, float sz);
-    Matrix& scale(float s);
-
-    Matrix& translate(float tx, float ty, float tz);
-    Matrix& translateX(float tx);
-    Matrix& translateY(float ty);
-    Matrix& translateZ(float tz);
-    Matrix& translateTo(float tx, float ty, float tz);
-
-    Matrix& rotateX(float degrees);
-    Matrix& rotateY(float degrees);
-    Matrix& rotateZ(float degrees);
-
-private:
-    Matrix& rotate(float degrees, uint indexA, uint indexB);
-
-    alignas(16) float data[16];
-};
-
-std::ostream& operator<<(std::ostream& os, const Matrix& m);
-Vector<3> operator*(const Matrix& m, const Vector<3>& v);
-
-#endif

+ 0 - 23
client/math/MatrixStack.cpp

@@ -1,23 +0,0 @@
-#include <cassert>
-
-#include "client/math/MatrixStack.h"
-
-void MatrixStack::pop() {
-    assert(index > 0);
-    index--;
-}
-
-void MatrixStack::push() {
-    assert(index < stack.size() - 1);
-    index++;
-    stack[index] = stack[index - 1];
-}
-
-Matrix& MatrixStack::get() {
-    return stack[index];
-}
-
-void MatrixStack::clear() {
-    index = 0;
-    stack[0].setToIdentity();
-}

+ 0 - 20
client/math/MatrixStack.h

@@ -1,20 +0,0 @@
-#ifndef MATRIXSTACK_H
-#define MATRIXSTACK_H
-
-#include <array>
-
-#include "client/math/Matrix.h"
-
-class MatrixStack final {
-public:
-    void pop();
-    void push();
-    Matrix& get();
-    void clear();
-
-private:
-    std::array<Matrix, 10> stack;
-    size_t index = 0;
-};
-
-#endif

+ 0 - 16
client/math/Plane.cpp

@@ -1,16 +0,0 @@
-#include "client/math/Plane.h"
-
-Plane::Plane() : d(0) {
-}
-
-void Plane::set(const Vector3& va, const Vector3& vb, const Vector3& vc) {
-    Vector3 h1 = vb - va;
-    Vector3 h2 = vc - va;
-    abc = h1.cross(h2);
-    abc.normalize();
-    d = -abc.dot(va);
-}
-
-float Plane::getSignedDistance(const Vector3& v) const {
-    return abc.dot(v) + d;
-}

+ 0 - 18
client/math/Plane.h

@@ -1,18 +0,0 @@
-#ifndef PLANE3D_H
-#define PLANE3D_H
-
-#include "common/math/Vector.h"
-
-class Plane final {
-public:
-    Plane();
-
-    void set(const Vector3& va, const Vector3& vb, const Vector3& vc);
-    float getSignedDistance(const Vector3& v) const;
-
-private:
-    Vector3 abc;
-    float d;
-};
-
-#endif

+ 0 - 137
client/math/Quaternion.cpp

@@ -1,137 +0,0 @@
-#include <cmath>
-
-#include "client/math/Quaternion.h"
-
-Quaternion::Quaternion() : xyz(0.0f, 0.0f, 0.0f), w(1.0f) {
-}
-
-Quaternion::Quaternion(float x, float y, float z, float w) : xyz(x, y, z), w(w) {
-}
-
-Quaternion::Quaternion(const Vector3& axis, float angle) : xyz(axis) {
-    xyz.normalize();
-    float sin;
-    sincosf(angle * (M_PI / 360.0f), &sin, &w);
-    xyz *= sin;
-}
-
-Quaternion Quaternion::lerp(float f, const Quaternion& other) const {
-    return interpolate(1 - f, f, other).normalize();
-}
-
-Quaternion Quaternion::slerp(float f, const Quaternion& other) const {
-    float angle = xyz.dot(other.xyz) + w * other.w;
-    if(angle >= 1.0f) {
-        return *this;
-    } else if(angle < -1.0f) {
-        angle = -1.0f;
-    }
-    float arccos = acosf(angle);
-    float sin = 1.0f / sinf(arccos);
-    return interpolate(sinf((1 - f) * arccos) * sin, sinf(f * arccos) * sin, other);
-}
-
-Quaternion Quaternion::interpolate(float a, float b, const Quaternion& other) const {
-    Vector3 interpolated = xyz * a + other.xyz * b;
-    return Quaternion(interpolated[0], interpolated[1], interpolated[2], w * a + other.w * b);
-}
-
-Quaternion Quaternion::squad(float f, const Quaternion& prev, const Quaternion& next, const Quaternion& nextNext) const {
-    float diff = static_cast<Vector3>(xyz - next.xyz).squareLength() + (w - next.w) * (w - next.w);
-    if(diff < 0.0001f) {
-        return *this;
-    }
-    Quaternion s1 = squadControl(prev, next);
-    Quaternion s2 = next.squadControl(*this, nextNext);
-    return slerp(f, next).slerp(2.0f * f * (1.0f - f), s1.slerp(f, s2));
-}
-
-Quaternion Quaternion::squadControl(const Quaternion& prev, const Quaternion& next) const {
-    Quaternion conjugate(*this);
-    conjugate.conjugate();
-    Quaternion s1(next);
-    s1.mul(conjugate).log().add(Quaternion(prev).mul(conjugate).log()).mul(-0.25f).exp().mul(*this);
-    return s1;
-}
-
-Quaternion& Quaternion::normalize() {
-    float f = 1.0f / sqrtf(xyz.squareLength() + w * w);
-    xyz *= f;
-    w *= f;
-    return *this;
-}
-
-Matrix Quaternion::toMatrix() const {
-    float x = xyz[0];
-    float y = xyz[1];
-    float z = xyz[2];
-
-    float x2 = 2 * x * x;
-    float y2 = 2 * y * y;
-    float z2 = 2 * z * z;
-
-    float xy = 2 * x * y;
-    float xz = 2 * x * z;
-    float xw = 2 * x * w;
-    float zw = 2 * z * w;
-    float yz = 2 * y * z;
-    float yw = 2 * y * w;
-
-    Matrix m;
-    m.set(0, 1 - y2 - z2).set(1, xy - zw).set(2, xz + yw);
-    m.set(4, xy + zw).set(5, 1 - x2 - z2).set(6, yz - xw);
-    m.set(8, xz - yw).set(9, yz + xw).set(10, 1 - x2 - y2);
-    return m;
-}
-
-Quaternion& Quaternion::mul(const Quaternion& other) {
-    Vector3 v = other.xyz * w + xyz * other.w + xyz.cross(other.xyz);
-    w = w * other.w - xyz.dot(other.xyz);
-    xyz = v;
-    return *this;
-}
-
-Quaternion& Quaternion::mul(float f) {
-    xyz *= f;
-    w *= f;
-    return *this;
-}
-
-Quaternion& Quaternion::add(const Quaternion& other) {
-    xyz += other.xyz;
-    w += other.w;
-    return *this;
-}
-
-Quaternion& Quaternion::conjugate() {
-    xyz = -xyz;
-    return *this;
-}
-
-Quaternion& Quaternion::log() {
-    // general log
-    //float length = sqrtf(xyz.dot(xyz) + w * w);
-    //float arccos = acos(w / length);
-    //w = logf(length);
-    //xyz.mul(arccos / xyz.length());
-
-    // optimized use case log
-    xyz.normalize();
-    xyz *= acos(w);
-    w = 0.0f;
-    return *this;
-}
-
-Quaternion& Quaternion::exp() {
-    // general exp
-    //float expw = expf(w);
-    //float length = xyz.length();
-    //w = expw * cosf(length);
-    //xyz.mul((expw * sin(length)) / length);
-
-    // optimized use case exp
-    float length = xyz.length();
-    w = cosf(length);
-    xyz *= sinf(length) / length;
-    return *this;
-}

+ 0 - 37
client/math/Quaternion.h

@@ -1,37 +0,0 @@
-#ifndef QUATERNION_H
-#define QUATERNION_H
-
-#include "common/math/Vector.h"
-#include "client/math/Matrix.h"
-
-class Quaternion {
-public:
-    Quaternion();
-    Quaternion(const Vector3& axis, float angle);
-    
-    Quaternion lerp(float f, const Quaternion& other) const;
-    Quaternion slerp(float f, const Quaternion& other) const;
-    Quaternion squad(float f, const Quaternion& prev, const Quaternion& next, const Quaternion& nextNext) const;
-    
-    Matrix toMatrix() const;
-    Quaternion& mul(const Quaternion& other);
-
-private:
-    Quaternion(float x, float y, float z, float w);
-    
-    Quaternion interpolate(float a, float b, const Quaternion& other) const;
-    Quaternion& normalize();
-    
-    Quaternion squadControl(const Quaternion& prev, const Quaternion& next) const;
-    
-    Quaternion& conjugate();
-    Quaternion& log();
-    Quaternion& exp();
-    Quaternion& mul(float f);
-    Quaternion& add(const Quaternion& other);
-    
-    Vector3 xyz;
-    float w;
-};
-
-#endif

+ 34 - 58
client/rendering/Engine.cpp

@@ -5,26 +5,21 @@
 #include "client/rendering/wrapper/GLFWWrapper.h"
 #include "client/rendering/wrapper/GLWrapper.h"
 #include "client/rendering/Renderer.h"
-#include "client/math/Plane.h"
 
-Engine::Engine(Shaders& shaders, Framebuffers& fb, const WindowSize& size, RenderSettings& renderSettings) :
-shaders(shaders), framebuffers(fb), size(size), renderSettings(renderSettings), frustum(60.0f, 0.1f, 1000.0f) {
+Engine::Engine(Shaders& shaders, Framebuffers& fb, const Size& size, RenderSettings& renderSettings) :
+shaders(shaders), framebuffers(fb), size(size), renderSettings(renderSettings), frustum(60.0f, 0.1f, 1000.0f, size) {
     rectangle.add(Triangle(
-            Vertex(Vector3(-1, -1, 0), Vector2(0, 0)),
-            Vertex(Vector3(1, 1, 0), Vector2(1, 1)),
-            Vertex(Vector3(-1, 1, 0), Vector2(0, 1))));
+            Vertex(Vector3(-1.0f, -1.0f, 0.0f), Vector2(0, 0.0f)),
+            Vertex(Vector3(1.0f, 1.0f, 0.0f), Vector2(1.0f, 1.0f)),
+            Vertex(Vector3(-1.0f, 1.0f, 0.0f), Vector2(0.0f, 1.0f))));
     rectangle.add(Triangle(
-            Vertex(Vector3(-1, -1, 0), Vector2(0, 0)),
-            Vertex(Vector3(1, -1, 0), Vector2(1, 0)),
-            Vertex(Vector3(1, 1, 0), Vector2(1, 1))));
+            Vertex(Vector3(-1.0f, -1.0f, 0.0f), Vector2(0, 0.0f)),
+            Vertex(Vector3(1.0f, -1.0f, 0.0f), Vector2(1.0f, 0.0f)),
+            Vertex(Vector3(1.0f, 1.0f, 0.0f), Vector2(1.0f, 1.0f))));
     rectangle.build();
 }
 
 void Engine::renderTick(float lag, const Game& game) {
-    if(renderSettings.dirtyFactor) {
-        framebuffers.setFactor(renderSettings.factor);
-    }
-
     updateWorldProjection();
     updateWorldView();
 
@@ -43,10 +38,11 @@ void Engine::renderShadow(float lag, const Game& game) {
     framebuffers.shadow.bind();
     GLWrapper::enableDepthTesting();
     shaders.shadow.use();
-    worldShadowProjView.set(worldShadowProj).mul(worldShadowView);
+    worldShadowProjView = worldShadowProj;
+    worldShadowProjView *= worldShadowView;
     shaders.shadow.setMatrix("projView", worldShadowProjView.getValues());
     model.clear();
-    shaders.shadow.setMatrix("model", model.get().getValues());
+    shaders.shadow.setMatrix("model", model.peek().getValues());
     Renderer renderer(shaders.shadow, model, worldView);
     game.renderWorld(lag, renderer);
 }
@@ -57,38 +53,33 @@ void Engine::renderWorld(float lag, const Game& game) {
     shaders.world.use();
 
     Matrix rWorldShadowProjView;
-    rWorldShadowProjView.translate(0.5f, 0.5f, 0.5f).scale(0.5f).mul(worldShadowProjView);
+    rWorldShadowProjView.scale(0.5f).translate(Vector3(0.5f, 0.5f, 0.5f));
+    rWorldShadowProjView *= worldShadowProjView;
 
     shaders.world.setMatrix("projViewShadow", rWorldShadowProjView.getValues());
     shaders.world.setMatrix("proj", worldProj.getValues());
-    shaders.world.setMatrix("view", worldView.setToIdentity().getValues());
+    worldView = Matrix();
+    shaders.world.setMatrix("view", worldView.getValues());
     model.clear();
-    shaders.world.setMatrix("model", model.get().getValues());
+    shaders.world.setMatrix("model", model.peek().getValues());
     framebuffers.shadow.bindDepthTexture(1);
     shaders.world.setInt("shadows", renderSettings.shadows);
     shaders.world.setFloat("radius", renderSettings.testRadius);
     shaders.world.setFloat("zbias", renderSettings.testBias);
     Renderer renderer(shaders.world, model, worldView);
     game.renderWorld(lag, renderer);
-
-    shaders.worldLines.use();
-    shaders.worldLines.setMatrix("proj", worldProj.getValues());
-    shaders.worldLines.setMatrix("view", worldView.getValues());
-    model.clear();
-    shaders.worldLines.setMatrix("model", model.get().getValues());
-    Renderer lineRenderer(shaders.worldLines, model, worldView);
-    game.renderWorldLines(lag, lineRenderer);
 }
 
 void Engine::renderSSAO() {
     shaders.ssao.use();
 
     Matrix rProj;
-    rProj.translate(0.5f, 0.5f, 0.5f).scale(0.5f).mul(worldProj);
+    rProj.scale(0.5f).translate(Vector3(0.5f, 0.5f, 0.5f));
+    rProj *= worldProj;
 
     shaders.ssao.setMatrix("proj", rProj.getValues());
-    shaders.ssao.setInt("width", size.width * renderSettings.factor);
-    shaders.ssao.setInt("height", size.height * renderSettings.factor);
+    shaders.ssao.setInt("width", size.width);
+    shaders.ssao.setInt("height", size.height);
     framebuffers.world.bindPositionTexture(0);
     framebuffers.world.bindNormalTexture(1);
     framebuffers.world.bindColorTexture(2);
@@ -104,7 +95,7 @@ void Engine::renderSSAO() {
 }
 
 void Engine::renderPostWorld() {
-    framebuffers.antialias.bind();
+    GLWrapper::prepareMainFramebuffer();
     shaders.postWorld.use();
     framebuffers.world.bindColorTexture(0);
     framebuffers.ssaoBlur.bindRedTexture(1);
@@ -112,14 +103,6 @@ void Engine::renderPostWorld() {
     framebuffers.world.bindNormalTexture(3);
     shaders.postWorld.setInt("ssao", renderSettings.ssao);
     shaders.postWorld.setInt("shadows", renderSettings.shadows);
-    shaders.postWorld.setFloat("bump", renderSettings.bump);
-    rectangle.draw();
-
-    GLWrapper::prepareMainFramebuffer();
-    glViewport(0, 0, size.width, size.height);
-    shaders.antialias.use();
-    shaders.antialias.setInt("radius", renderSettings.factor);
-    framebuffers.antialias.bindColorTexture(0);
     rectangle.draw();
 }
 
@@ -129,10 +112,10 @@ void Engine::renderTextOverlay(float lag, const Game& game) {
 
     Matrix m;
     shaders.text.setMatrix("proj", m.getValues());
-    m.translate(-1.0f, 1.0f, 0.0f).scale(2.0f / size.width, -2.0f / size.height, 1.0f);
+    m.scale(Vector3(2.0f / size.width, -2.0f / size.height, 1.0f)).translate(Vector3(-1.0f, 1.0f, 0.0f));
     shaders.text.setMatrix("view", m.getValues());
     model.clear();
-    shaders.text.setMatrix("model", model.get().getValues());
+    shaders.text.setMatrix("model", model.peek().getValues());
 
     GLWrapper::enableBlending();
     Renderer renderer(shaders.text, model, m);
@@ -141,15 +124,16 @@ void Engine::renderTextOverlay(float lag, const Game& game) {
 }
 
 void Engine::updateWorldProjection() {
-    frustum.setProjection(worldProj, size.width, size.height);
+    worldProj = frustum.updateProjection();
 
     if(!renderSettings.shadows) {
         return;
     }
-    worldShadowProj.setToIdentity();
-    worldShadowProj.set(0, 2.0f / 40.0f);
-    worldShadowProj.set(5, 2.0f / 30.0f);
-    worldShadowProj.set(10, -2.0f / frustum.getClipDifference());
+    
+    worldShadowProj.set(0, Vector4(2.0f / 40.0f, 0.0f, 0.0f, 0.0f));
+    worldShadowProj.set(1, Vector4(0.0f, 2.0f / 30.0f, 0.0f, 0.0f));
+    worldShadowProj.set(2, Vector4(0.0f, 0.0f, -2.0f / (1000.0f - 0.1f), 0.0f));
+    worldShadowProj.set(3, Vector4(0.0f, 0.0f, 0.0f, 1.0f));
 }
 
 void Engine::updateWorldView() {
@@ -161,17 +145,9 @@ void Engine::updateWorldView() {
     Vector3 back(0.280166f, 0.573576f, 0.769751f);
     Vector3 up(-0.196175f, 0.819152f, -0.538986f);
     Vector3 center(16.0f, 24.0f, 24.0f);
-
-    worldShadowView.set(0, right[0]);
-    worldShadowView.set(1, up[0]);
-    worldShadowView.set(2, back[0]);
-    worldShadowView.set(4, right[1]);
-    worldShadowView.set(5, up[1]);
-    worldShadowView.set(6, back[1]);
-    worldShadowView.set(8, right[2]);
-    worldShadowView.set(9, up[2]);
-    worldShadowView.set(10, back[2]);
-    worldShadowView.set(12, right.dot(-center));
-    worldShadowView.set(13, up.dot(-center));
-    worldShadowView.set(14, back.dot(-center));
+    
+    worldShadowView.set(0, Vector4(right[0],  right[1], right[2], right.dot(-center)));
+    worldShadowView.set(1, Vector4(up[0], up[1], up[2], up.dot(-center)));
+    worldShadowView.set(2, Vector4(back[0], back[1], back[2], back.dot(-center)));
+    worldShadowView.set(3, Vector4(0.0f, 0.0f, 0.0f, 1.0f));
 }

+ 4 - 4
client/rendering/Engine.h

@@ -5,14 +5,14 @@
 #include "client/rendering/Framebuffers.h"
 #include "client/rendering/RenderSettings.h"
 #include "client/Game.h"
-#include "client/math/Frustum.h"
+#include "gaming-core/math/Frustum.h"
 #include "client/rendering/FontRenderer.h"
 #include "client/rendering/NoiseTexture.h"
 #include "client/rendering/Mesh.h"
 
 class Engine final {
 public:
-    Engine(Shaders& shaders, Framebuffers& fb, const WindowSize& size, RenderSettings& renderSettings);
+    Engine(Shaders& shaders, Framebuffers& fb, const Size& size, RenderSettings& renderSettings);
     void renderTick(float lag, const Game& game);
 
 private:
@@ -26,11 +26,11 @@ private:
 
     Shaders& shaders;
     Framebuffers& framebuffers;
-    const WindowSize& size;
+    const Size& size;
     RenderSettings& renderSettings;
 
     Frustum frustum;
-    MatrixStack model;
+    MatrixStack<16> model;
     FontRenderer fontRenderer;
     NoiseTexture ssaoNoise;
     Mesh rectangle;

+ 3 - 13
client/rendering/Framebuffers.cpp

@@ -1,11 +1,10 @@
 #include "client/rendering/Framebuffers.h"
 
-Framebuffers::Framebuffers(const WindowSize& size) :
+Framebuffers::Framebuffers(const Size& size) :
 world(size, Framebuffer::POSITION | Framebuffer::NORMAL | Framebuffer::COLOR | Framebuffer::RED | Framebuffer::DEPTH),
 ssao(size, Framebuffer::RED),
 ssaoBlur(size, Framebuffer::RED),
-shadow(size, Framebuffer::DEPTH),
-antialias(size, Framebuffer::COLOR) {
+shadow(size, Framebuffer::DEPTH) {
 }
 
 void Framebuffers::resize(uint width, uint height) {
@@ -13,17 +12,8 @@ void Framebuffers::resize(uint width, uint height) {
     ssao.resize(width, height);
     ssaoBlur.resize(width, height);
     shadow.resize(width, height);
-    antialias.resize(width, height);
 }
 
 bool Framebuffers::hasError() const {
-    return world.hasError() || ssao.hasError() || ssaoBlur.hasError() || shadow.hasError() || antialias.hasError();
-}
-
-void Framebuffers::setFactor(int factor) {
-    world.setFactor(factor);
-    ssao.setFactor(factor);
-    ssaoBlur.setFactor(factor);
-    shadow.setFactor(factor);
-    antialias.setFactor(factor);
+    return world.hasError() || ssao.hasError() || ssaoBlur.hasError() || shadow.hasError();
 }

+ 2 - 4
client/rendering/Framebuffers.h

@@ -1,20 +1,18 @@
 #ifndef FRAMEBUFFERS_H
 #define FRAMEBUFFERS_H
 
-#include "client/rendering/WindowSize.h"
+#include "gaming-core/utils/Size.h"
 #include "client/rendering/wrapper/Framebuffer.h"
 
 struct Framebuffers final {
-    Framebuffers(const WindowSize& size);
+    Framebuffers(const Size& size);
     void resize(uint width, uint height);
     bool hasError() const;
-    void setFactor(int factor);
 
     Framebuffer world;
     Framebuffer ssao;
     Framebuffer ssaoBlur;
     Framebuffer shadow;
-    Framebuffer antialias;
 };
 
 #endif

+ 3 - 26
client/rendering/Mesh.cpp

@@ -4,10 +4,9 @@
 
 Mesh::Mesh() {
     vertexBuffer.bind();
-    vertexBuffer.setFloatAttribute(0, 3, 0, 11);
-    vertexBuffer.setFloatAttribute(1, 2, 3, 11);
-    vertexBuffer.setFloatAttribute(2, 3, 5, 11);
-    vertexBuffer.setFloatAttribute(3, 3, 8, 11);
+    vertexBuffer.setFloatAttribute(0, 3, 0, 8);
+    vertexBuffer.setFloatAttribute(1, 2, 3, 8);
+    vertexBuffer.setFloatAttribute(2, 3, 5, 8);
 }
 
 void Mesh::add(const Triangle& data) {
@@ -26,26 +25,4 @@ void Mesh::build() {
 void Mesh::draw() const {
     vertexBuffer.bindArray();
     vertexBuffer.draw(buffer.getLength() * 3);
-}
-
-void Mesh::save() {
-    std::ofstream out;
-    out.open("scene");
-    for(Triangle& t : buffer) {
-        out << t.a.position[0] << ", ";
-        out << t.a.position[1] << ", ";
-        out << t.a.position[2] << ", ";
-        out << t.a.texture[0] << ", ";
-        out << t.a.texture[1] << "\n";
-        out << t.b.position[0] << ", ";
-        out << t.b.position[1] << ", ";
-        out << t.b.position[2] << ", ";
-        out << t.b.texture[0] << ", ";
-        out << t.b.texture[1] << "\n";
-        out << t.c.position[0] << ", ";
-        out << t.c.position[1] << ", ";
-        out << t.c.position[2] << ", ";
-        out << t.c.texture[0] << ", ";
-        out << t.c.texture[1] << "\n";
-    }
 }

+ 0 - 1
client/rendering/Mesh.h

@@ -14,7 +14,6 @@ public:
     void clear();
     void build();
     void draw() const;
-    void save();
 
 private:
     VertexBuffer vertexBuffer;

+ 1 - 2
client/rendering/RenderSettings.cpp

@@ -1,5 +1,4 @@
 #include "client/rendering/RenderSettings.h"
 
-RenderSettings::RenderSettings() : ssao(true), shadows(true), testRadius(0.01f), testBias(0.0002f), bump(0.5f),
-factor(1), dirtyFactor(false) {
+RenderSettings::RenderSettings() : ssao(true), shadows(true), testRadius(0.01f), testBias(0.0002f), bump(0.5f) {
 }

+ 0 - 2
client/rendering/RenderSettings.h

@@ -9,8 +9,6 @@ struct RenderSettings final {
     float testRadius;
     float testBias;
     float bump;
-    int factor;
-    bool dirtyFactor;
 };
 
 #endif

+ 20 - 29
client/rendering/Renderer.cpp

@@ -1,6 +1,6 @@
 #include "client/rendering/Renderer.h"
 
-Renderer::Renderer(Shader& shader, MatrixStack& stack, Matrix& view) : shader(shader), stack(stack), view(view) {
+Renderer::Renderer(Shader& shader, MatrixStack<16>& stack, Matrix& view) : shader(shader), stack(stack), view(view) {
 }
 
 void Renderer::pop() {
@@ -12,79 +12,70 @@ void Renderer::push() {
 }
 
 Renderer& Renderer::update() {
-    shader.setMatrix("model", stack.get().getValues());
+    shader.setMatrix("model", stack.peek().getValues());
     return *this;
 }
 
 Renderer& Renderer::update(const Vector3& pos, const Quaternion& rotation) {
-    Matrix m = rotation.toMatrix();
-    Vector3 right = m * Vector3(1.0f, 0.0f, 0.0f);
-    Vector3 up = m * Vector3(0.0f, 1.0f, 0.0f);
-    Vector3 back = m * Vector3(0.0f, 0.0f, -1.0f);
-
-    view.set(0, right[0]);
-    view.set(1, up[0]);
-    view.set(2, back[0]);
-    view.set(4, right[1]);
-    view.set(5, up[1]);
-    view.set(6, back[1]);
-    view.set(8, right[2]);
-    view.set(9, up[2]);
-    view.set(10, back[2]);
-    view.set(12, right.dot(-pos));
-    view.set(13, up.dot(-pos));
-    view.set(14, back.dot(-pos));
+    Vector3 right = rotation * Vector3(1.0f, 0.0f, 0.0f);
+    Vector3 up = rotation * Vector3(0.0f, 1.0f, 0.0f);
+    Vector3 back = rotation * Vector3(0.0f, 0.0f, -1.0f);
+
+    view.set(0, Vector4(right[0],  right[1], right[2], right.dot(-pos)));
+    view.set(1, Vector4(up[0], up[1], up[2], up.dot(-pos)));
+    view.set(2, Vector4(back[0], back[1], back[2], back.dot(-pos)));
+    view.set(3, Vector4(0.0f, 0.0f, 0.0f, 1.0f));
     
     shader.setMatrix("view", view.getValues());
     return *this;
 }
 
 Renderer& Renderer::scale(float sx, float sy, float sz) {
-    stack.get().scale(sx, sy, sz);
+    stack.peek().scale(Vector3(sx, sy, sz));
     return *this;
 }
 
 Renderer& Renderer::scale(float s) {
-    stack.get().scale(s);
+    stack.peek().scale(s);
     return *this;
 }
 
 Renderer& Renderer::translate(float tx, float ty, float tz) {
-    stack.get().translate(tx, ty, tz);
+    stack.peek().translate(Vector3(tx, ty, tz));
     return *this;
 }
 
 Renderer& Renderer::translateX(float tx) {
-    stack.get().translateX(tx);
+    stack.peek().translateX(tx);
     return *this;
 }
 
 Renderer& Renderer::translateY(float ty) {
-    stack.get().translateY(ty);
+    stack.peek().translateY(ty);
     return *this;
 }
 
 Renderer& Renderer::translateZ(float tz) {
-    stack.get().translateZ(tz);
+    stack.peek().translateZ(tz);
     return *this;
 }
 
 Renderer& Renderer::translateTo(float tx, float ty, float tz) {
-    stack.get().translateTo(tx, ty, tz);
+    stack.peek().translateTo(Vector3(tx, ty, tz));
     return *this;
 }
 
 Renderer& Renderer::rotateX(float degrees) {
-    stack.get().rotateX(degrees);
+    stack.peek().rotateX(degrees);
     return *this;
 }
 
 Renderer& Renderer::rotateY(float degrees) {
-    stack.get().rotateY(degrees);
+    stack.peek().rotateY(degrees);
     return *this;
 }
 
 Renderer& Renderer::rotateZ(float degrees) {
-    stack.get().rotateZ(degrees);
+    stack.peek().rotateZ(degrees);
     return *this;
 }

+ 5 - 5
client/rendering/Renderer.h

@@ -2,13 +2,13 @@
 #define RENDERER_H
 
 #include "client/rendering/wrapper/Shader.h"
-#include "client/math/MatrixStack.h"
-#include "common/math/Vector.h"
-#include "client/math/Quaternion.h"
+#include "gaming-core/math/MatrixStack.h"
+#include "gaming-core/math/Vector.h"
+#include "gaming-core/math/Quaternion.h"
 
 class Renderer final {
 public:
-    Renderer(Shader& shader, MatrixStack& stack, Matrix& view);
+    Renderer(Shader& shader, MatrixStack<16>& stack, Matrix& view);
     
     void pop();
     void push();
@@ -31,7 +31,7 @@ public:
 
 private:
     Shader& shader;
-    MatrixStack& stack;
+    MatrixStack<16>& stack;
     Matrix& view;
 };
 

+ 3 - 5
client/rendering/Shaders.cpp

@@ -2,16 +2,14 @@
 
 Shaders::Shaders() :
 world("resources/shader/worldVertex.vs", "resources/shader/worldFragment.fs"),
-worldLines("resources/shader/lineVertex.vs", "resources/shader/lineFragment.fs"),
 ssao("resources/shader/ssaoVertex.vs", "resources/shader/ssaoFragment.fs"),
 ssaoBlur("resources/shader/ssaoBlurVertex.vs", "resources/shader/ssaoBlurFragment.fs"),
 shadow("resources/shader/worldShadowVertex.vs", "resources/shader/worldShadowFragment.fs"),
 postWorld("resources/shader/worldPostVertex.vs", "resources/shader/worldPostFragment.fs"),
-text("resources/shader/textVertex.vs", "resources/shader/textFragment.fs"),
-antialias("resources/shader/antialiasVertex.vs", "resources/shader/antialiasFragment.fs") {
+text("resources/shader/textVertex.vs", "resources/shader/textFragment.fs") {
 }
 
 bool Shaders::hasError() const {
-    return world.hasError() || worldLines.hasError() || ssao.hasError() || ssaoBlur.hasError() || shadow.hasError() || postWorld.hasError() ||
-            text.hasError() || antialias.hasError();
+    return world.hasError() || ssao.hasError() || ssaoBlur.hasError() || shadow.hasError() || postWorld.hasError() ||
+            text.hasError();
 }

+ 0 - 2
client/rendering/Shaders.h

@@ -8,13 +8,11 @@ struct Shaders final {
     bool hasError() const;
 
     Shader world;
-    Shader worldLines;
     Shader ssao;
     Shader ssaoBlur;
     Shader shadow;
     Shader postWorld;
     Shader text;
-    Shader antialias;
 };
 
 #endif

+ 1 - 13
client/rendering/Triangle.cpp

@@ -4,19 +4,7 @@ Triangle::Triangle() {
 }
 
 Triangle::Triangle(const Vertex& a, const Vertex& b, const Vertex& c) : a(a), b(b), c(c) {
-    Vector3 ab = b.position - a.position;
-    Vector3 ac = c.position - a.position;
-    normalA = ab.cross(ac);
+    normalA = static_cast<Vector3>(b.position - a.position).cross(c.position - a.position);
     normalB = normalA;
     normalC = normalA;
-    
-    Vector2 abt = b.texture - a.texture;
-    Vector2 act = c.texture - a.texture;
-    
-    float f = 1.0f / (abt[0] * act[1] - act[0] * abt[1]);
-    
-    tangentA = f * (act[1] * ab - abt[1] * ac);
-    tangentA.normalize();
-    tangentB = tangentA;
-    tangentC = tangentA;
 }

+ 5 - 8
client/rendering/Triangle.h

@@ -3,20 +3,17 @@
 
 #include "client/rendering/Vertex.h"
 
-struct Triangle final {
-    Triangle();
-    Triangle(const Vertex& a, const Vertex& b, const Vertex& c);
-
-//private:
+class Triangle final {
     Vertex a;
     Vector3 normalA;
-    Vector3 tangentA;
     Vertex b;
     Vector3 normalB;
-    Vector3 tangentB;
     Vertex c;
     Vector3 normalC;
-    Vector3 tangentC;
+
+public:
+    Triangle();
+    Triangle(const Vertex& a, const Vertex& b, const Vertex& c);
 };
 
 #endif

+ 1 - 1
client/rendering/Vertex.h

@@ -1,7 +1,7 @@
 #ifndef VERTEX_H
 #define VERTEX_H
 
-#include "common/math/Vector.h"
+#include "gaming-core/math/Vector.h"
 
 struct Vertex final {
     Vertex();

+ 0 - 4
client/rendering/WindowSize.cpp

@@ -1,4 +0,0 @@
-#include "client/rendering/WindowSize.h"
-
-WindowSize::WindowSize(int width, int height) : width(width), height(height) {
-}

+ 0 - 11
client/rendering/WindowSize.h

@@ -1,11 +0,0 @@
-#ifndef WINDOWSIZE_H
-#define WINDOWSIZE_H
-
-struct WindowSize final {
-    WindowSize(int width, int height);
-    
-    int width;
-    int height;
-};
-
-#endif

+ 1 - 1
client/rendering/renderer/WorldRenderer.cpp

@@ -22,7 +22,7 @@ void WorldRenderer::render(float lag, Renderer& renderer) const {
     (void) renderer;
     texture.bind(0);
     normalTexture.bind(2);
-    //mesh.draw();
+    mesh.draw();
 }
 
 bool WorldRenderer::isAir(uint x, uint y, uint z) const {

+ 11 - 23
client/rendering/wrapper/Framebuffer.cpp

@@ -2,8 +2,8 @@
 
 #include "client/rendering/wrapper/Framebuffer.h"
 
-Framebuffer::Framebuffer(const WindowSize& size, uint mode, bool texCompare) : size(size), mode(mode), textures(0),
-buffer(0), error(false), factor(1) {
+Framebuffer::Framebuffer(const Size& size, uint mode, bool texCompare) : size(size), mode(mode), textures(0),
+buffer(0), error(false) {
     glGenFramebuffers(1, &buffer);
     glBindFramebuffer(GL_FRAMEBUFFER, buffer);
 
@@ -11,23 +11,22 @@ buffer(0), error(false), factor(1) {
     data[1] = {NORMAL, GL_RGB16F, GL_RGB, GL_FLOAT};
     data[2] = {COLOR, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE};
     data[3] = {RED, GL_R32F, GL_RGB, GL_FLOAT};
-    data[4] = {TANGENT, GL_RGB16F, GL_RGB, GL_FLOAT};
-    data[5] = {DEPTH, GL_DEPTH_COMPONENT32, GL_DEPTH_COMPONENT, GL_FLOAT};
+    data[4] = {DEPTH, GL_DEPTH_COMPONENT32, GL_DEPTH_COMPONENT, GL_FLOAT};
 
-    GLuint attachments[5];
+    GLuint attachments[4];
     uint counter = 0;
-    for(uint i = 0; i < 5; i++) {
+    for(uint i = 0; i < 4; i++) {
         if(mode & data[i].mask) {
             setupTexture(i, size.width, size.height, attachments, counter);
         }
     }
     if(mode & DEPTH) {
-        genTexture(5, size.width, size.height);
+        genTexture(4, size.width, size.height);
         if(texCompare) {
             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
         }
-        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, textures[5], 0);
+        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, textures[4], 0);
     }
     glDrawBuffers(counter, attachments);
 
@@ -50,15 +49,13 @@ bool Framebuffer::hasError() const {
 }
 
 void Framebuffer::bind() const {
-    glViewport(0, 0, size.width * factor, size.height * factor);
+    glViewport(0, 0, size.width, size.height);
     glBindFramebuffer(GL_FRAMEBUFFER, buffer);
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
 }
 
 void Framebuffer::resize(uint width, uint height) const {
-    width *= factor;
-    height *= factor;
-    for(uint i = 0; i < 6; i++) {
+    for(uint i = 0; i < 5; i++) {
         if(mode & data[i].mask) {
             glBindTexture(GL_TEXTURE_2D, textures[i]);
             glTexImage2D(GL_TEXTURE_2D, 0, data[i].internalFormat, width, height, 0, data[i].format, data[i].type, nullptr);
@@ -87,12 +84,8 @@ void Framebuffer::bindRedTexture(uint textureUnit) const {
     bindTexture(textureUnit, textures[3]);
 }
 
-void Framebuffer::bindTangentTexture(uint textureUnit) const {
-    bindTexture(textureUnit, textures[4]);
-}
-
 void Framebuffer::bindDepthTexture(uint textureUnit) const {
-    bindTexture(textureUnit, textures[5]);
+    bindTexture(textureUnit, textures[4]);
 }
 
 void Framebuffer::genTexture(uint index, uint width, uint height) {
@@ -124,9 +117,4 @@ const char* Framebuffer::getErrorString(GLenum error) const {
         case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS: return "GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS";
     }
     return "unknown error";
-}
-
-void Framebuffer::setFactor(int factor) {
-    this->factor = factor;
-    resize(size.width, size.height);
-}
+}

+ 6 - 11
client/rendering/wrapper/Framebuffer.h

@@ -3,7 +3,7 @@
 
 #include <GL/glew.h>
 
-#include "client/rendering/WindowSize.h"
+#include "gaming-core/utils/Size.h"
 #include "common/utils/Array.h"
 #include "common/utils/Types.h"
 
@@ -13,10 +13,9 @@ public:
     static const uint NORMAL = 2;
     static const uint COLOR = 4;
     static const uint RED = 8;
-    static const uint TANGENT = 16;
-    static const uint DEPTH = 32;
+    static const uint DEPTH = 16;
 
-    Framebuffer(const WindowSize& size, uint mode, bool texCompare = false);
+    Framebuffer(const Size& size, uint mode, bool texCompare = false);
     ~Framebuffer();
     Framebuffer(const Framebuffer& other) = delete;
     Framebuffer(Framebuffer&& other) = delete;
@@ -32,10 +31,7 @@ public:
     void bindNormalTexture(uint textureUnit) const;
     void bindColorTexture(uint textureUnit) const;
     void bindRedTexture(uint textureUnit) const;
-    void bindTangentTexture(uint textureUnit) const;
     void bindDepthTexture(uint textureUnit) const;
-    
-    void setFactor(int factor);
 
 private:
     void genTexture(uint index, uint width, uint height);
@@ -43,12 +39,11 @@ private:
     void bindTexture(uint textureUnit, GLuint texture) const;
     const char* getErrorString(GLenum error) const;
 
-    const WindowSize& size;
+    const Size& size;
     uint mode;
-    Array<GLuint, 6> textures;
+    Array<GLuint, 5> textures;
     GLuint buffer;
     bool error;
-    int factor;
 
     struct Data final {
         uint mask;
@@ -56,7 +51,7 @@ private:
         GLenum format;
         GLenum type;
     };
-    Data data[6];
+    Data data[5];
 };
 
 #endif

+ 1 - 1
client/rendering/wrapper/Shader.cpp

@@ -77,7 +77,7 @@ void Shader::use() const {
 }
 
 void Shader::setMatrix(const GLchar* name, const GLfloat* data) const {
-    glUniformMatrix4fv(glGetUniformLocation(program, name), 1, GL_FALSE, data);
+    glUniformMatrix4fv(glGetUniformLocation(program, name), 1, GL_TRUE, data);
 }
 
 void Shader::setInt(const GLchar* name, GLint data) const {

+ 1 - 1
client/rendering/wrapper/Window.cpp

@@ -2,7 +2,7 @@
 
 #include "client/rendering/wrapper/Window.h"
 
-Window::Window(const WindowSize& size, const char* windowName) : window(nullptr) {
+Window::Window(const Size& size, const char* windowName) : window(nullptr) {
     glfwDefaultWindowHints();
     glfwWindowHint(GLFW_VISIBLE, 0);
     glfwWindowHint(GLFW_RESIZABLE, 1);

+ 2 - 2
client/rendering/wrapper/Window.h

@@ -4,11 +4,11 @@
 #include <GL/glew.h>
 #include <GLFW/glfw3.h>
 
-#include "client/rendering/WindowSize.h"
+#include "gaming-core/utils/Size.h"
 
 class Window final {
 public:
-    Window(const WindowSize& size, const char* windowName);
+    Window(const Size& size, const char* windowName);
     ~Window();
 
     Window(const Window&) = delete;

+ 0 - 5
client/utils/Utils.cpp

@@ -1,5 +0,0 @@
-#include "client/utils/Utils.h"
-
-float interpolate(float lag, float from, float to) {
-    return from + lag * (to - from);
-}

+ 0 - 6
client/utils/Utils.h

@@ -1,6 +0,0 @@
-#ifndef UTILS_H
-#define UTILS_H
-
-float interpolate(float lag, float from, float to);
-
-#endif

+ 0 - 45
common/math/Vector.cpp

@@ -1,45 +0,0 @@
-#include "common/math/Vector.h"
-
-template<>
-Vector<3>::Vector(float x, float y, float z) {
-    values[0] = x;
-    values[1] = y;
-    values[2] = z;
-}
-
-template<>
-Vector<2>::Vector(float x, float y) {
-    values[0] = x;
-    values[1] = y;
-}
-
-template<>
-Vector<3>& Vector<3>::setAngles(float lengthAngle, float widthAngle) {
-    lengthAngle *= (M_PI / 180.0f);
-    widthAngle *= (M_PI / 180.0f);
-    values[0] = cosf(widthAngle) * sinf(lengthAngle);
-    values[1] = sinf(widthAngle);
-    values[2] = cosf(widthAngle) * cosf(lengthAngle);
-    return *this;
-}
-
-template<>
-Vector<3>::Vector(float lengthAngle, float widthAngle) {
-    setAngles(lengthAngle, widthAngle);
-}
-
-template<>
-Vector<3>& Vector<3>::set(float x, float y, float z) {
-    values[0] = x;
-    values[1] = y;
-    values[2] = z;
-    return *this;
-}
-
-template<>
-Vector<3> Vector<3>::cross(const Vector<3>& other) const {
-    return Vector<3>(
-            values[1] * other.values[2] - values[2] * other.values[1],
-            values[2] * other.values[0] - values[0] * other.values[2],
-            values[0] * other.values[1] - values[1] * other.values[0]);
-}

+ 0 - 127
common/math/Vector.h

@@ -1,127 +0,0 @@
-#ifndef VECTOR_H
-#define VECTOR_H
-
-#include <cmath>
-
-#include "common/utils/String.h"
-
-template<uint N>
-struct Vector final {
-
-    Vector() {
-        for(uint i = 0; i < N; i++) {
-            values[i] = 0.0f;
-        }
-    }
-
-    Vector(float, float) = delete;
-    Vector(float, float, float) = delete;
-    Vector& set(float, float, float) = delete;
-    Vector& setAngles(float, float) = delete;
-    Vector cross(const Vector&) const = delete;
-
-    Vector& operator+=(const Vector& other) {
-        for(uint i = 0; i < N; i++) {
-            values[i] += other.values[i];
-        }
-        return *this;
-    }
-
-    Vector operator+(const Vector& other) const {
-        Vector v = *this;
-        v += other;
-        return v;
-    }
-
-    Vector& operator-=(const Vector& other) {
-        for(uint i = 0; i < N; i++) {
-            values[i] -= other.values[i];
-        }
-        return *this;
-    }
-
-    Vector operator-() const {
-        Vector v = *this;
-        for(uint i = 0; i < N; i++) {
-            v.values[i] = -v.values[i];
-        }
-        return v;
-    }
-
-    Vector operator-(const Vector& other) const {
-        Vector v = *this;
-        v -= other;
-        return v;
-    }
-
-    Vector& operator*=(float factor) {
-        for(uint i = 0; i < N; i++) {
-            values[i] *= factor;
-        }
-        return *this;
-    }
-
-    Vector operator*(float factor) const {
-        Vector v = *this;
-        v *= factor;
-        return v;
-    }
-
-    float dot(const Vector& v) const {
-        float length = 0.0f;
-        for(uint i = 0; i < N; i++) {
-            length += values[i] * v.values[i];
-        }
-        return length;
-    }
-
-    float squareLength() const {
-        return dot(*this);
-    }
-
-    float length() const {
-        return sqrtf(squareLength());
-    }
-
-    Vector& normalize() {
-        *this *= 1.0f / length();
-        return *this;
-    }
-
-    const float& operator[](uint index) const {
-        return values[index];
-    }
-
-private:
-    float values[N];
-};
-
-template<uint N>
-Vector<N> operator*(float factor, const Vector<N>& v) {
-    return v * factor;
-}
-
-template<> Vector<3>::Vector(float x, float y, float z);
-template<> Vector<2>::Vector(float x, float y);
-template<> Vector<3>& Vector<3>::setAngles(float lengthAngle, float widthAngle);
-template<> Vector<3>::Vector(float lengthAngle, float widthAngle);
-template<> Vector<3>& Vector<3>::set(float x, float y, float z);
-template<> Vector<3> Vector<3>::cross(const Vector<3>& other) const;
-
-template<uint N>
-String& operator+=(String& buffer, const Vector<N>& v) {
-    buffer.append('(');
-    if(N > 0) {
-        buffer.append(v[0]);
-    }
-    for(uint i = 1; i < N; i++) {
-        buffer.append(", ").append(v[i]);
-    }
-    buffer.append(')');
-    return buffer;
-}
-
-typedef Vector<3> Vector3;
-typedef Vector<2> Vector2;
-
-#endif

+ 0 - 333
common/utils/KDTree.cpp

@@ -1,333 +0,0 @@
-#include <algorithm>
-#include <iostream>
-
-#include "common/utils/KDTree.h"
-
-KDTree::Triangle::Triangle(const Vector3& a, const Vector3& b, const Vector3& c) {
-    v[0] = a;
-    v[1] = b;
-    v[2] = c;
-    mid = (a + b + c) * (1.0f / 3.0f);
-}
-
-const Array<Vector3, 3>& KDTree::Triangle::data() const {
-    return v;
-}
-
-const Vector3& KDTree::Triangle::operator[](int index) const {
-    return v[index];
-}
-
-const Vector3& KDTree::Triangle::getMid() const {
-    return mid;
-}
-
-KDTree::Node::Node() : splitDim(0), splitValue(0.0f), color(0xFFFFFF) {
-    childs[0] = nullptr;
-    childs[1] = nullptr;
-}
-
-KDTree::~KDTree() {
-    clean(&root);
-}
-
-void KDTree::clean(Node* n) {
-    if(n->childs[0] != nullptr) {
-        clean(n->childs[0]);
-    }
-    if(n->childs[1] != nullptr) {
-        clean(n->childs[1]);
-    }
-    delete n->childs[0];
-    delete n->childs[1];
-}
-
-void KDTree::build(std::vector<KDTree::Triangle>& data) {
-    if(data.size() == 0) {
-        return;
-    }
-    min = data[0][0];
-    max = data[0][0];
-    for(const Triangle& t : data) {
-        for(const Vector3& v : t.data()) {
-            min.set(std::min(min[0], v[0]), std::min(min[1], v[1]), std::min(min[2], v[2]));
-            max.set(std::max(max[0], v[0]), std::max(max[1], v[1]), std::max(max[2], v[2]));
-        }
-    }
-    build(&root, data);
-}
-
-float KDTree::median(std::vector<KDTree::Triangle>& data, int dim) const {
-    auto compare = [dim](const Triangle& a, const Triangle & b) {
-        return a.getMid()[dim] < b.getMid()[dim];
-    };
-    size_t length = data.size();
-    if((length & 1) == 0) {
-        std::nth_element(data.begin(), data.begin() + (length / 2 - 1), data.end(), compare);
-        float tmp = data[length / 2 - 1].getMid()[dim];
-        std::nth_element(data.begin(), data.begin() + (length / 2), data.end(), compare);
-        return (tmp + data[length / 2].getMid()[dim]) / 2;
-    }
-    std::nth_element(data.begin(), data.begin() + (length / 2), data.end(), compare);
-    return data[length / 2].getMid()[dim];
-}
-
-void KDTree::build(Node* n, std::vector<KDTree::Triangle>& data) {
-    if(data.size() == 0) {
-        return;
-    } else if(data.size() == 1) {
-        n->data.push_back(data[0]);
-        return;
-    }
-    // find min and max coordinates
-    Vector3 min = data[0][0];
-    Vector3 max = data[0][0];
-    for(const Triangle& t : data) {
-        for(const Vector3& v : t.data()) {
-            min.set(std::min(min[0], v[0]), std::min(min[1], v[1]), std::min(min[2], v[2]));
-            max.set(std::max(max[0], v[0]), std::max(max[1], v[1]), std::max(max[2], v[2]));
-        }
-    }
-    // find biggest span and its dimension
-    int splitDim = 0;
-    float maxSpan = max[0] - min[0];
-    for(int i = 1; i < 3; i++) {
-        float span = max[i] - min[i];
-        if(span > maxSpan) {
-            splitDim = i;
-            maxSpan = span;
-        }
-    }
-    // assign data to node
-    n->splitDim = splitDim;
-    n->splitValue = median(data, splitDim);
-    // storage for split data
-    std::vector<KDTree::Triangle> lessEqualData;
-    std::vector<KDTree::Triangle> greaterData;
-    // actually split the data
-    for(const Triangle& t : data) {
-        // count points on each split side
-        int lessEqualCounter = 0;
-        int greaterCount = 0;
-        for(const Vector3& v : t.data()) {
-            if(v[n->splitDim] <= n->splitValue) {
-                lessEqualCounter++;
-            } else {
-                greaterCount++;
-            }
-        }
-        // put the data in the correct container
-        if(lessEqualCounter == 3) {
-            lessEqualData.push_back(t);
-        } else if(greaterCount == 3) {
-            greaterData.push_back(t);
-        } else {
-            n->data.push_back(t);
-        }
-    }
-    if(lessEqualData.size() == 0 || greaterData.size() == 0) {
-        for(KDTree::Triangle& t : lessEqualData) {
-            n->data.push_back(t);
-        }
-        for(KDTree::Triangle& t : greaterData) {
-            n->data.push_back(t);
-        }
-        return;
-    }
-    // recursive calls
-    if(lessEqualData.size() > 0) {
-        n->childs[0] = new Node();
-        build(n->childs[0], lessEqualData);
-    }
-    if(greaterData.size() > 0) {
-        n->childs[1] = new Node();
-        build(n->childs[1], greaterData);
-    }
-}
-
-void KDTree::fillLines(Lines& lines) const {
-    lines.clear();
-    lines.add(Vector3(min[0], min[1], min[2]), Vector3(max[0], min[1], min[2]), root.color);
-    lines.add(Vector3(min[0], min[1], min[2]), Vector3(min[0], min[1], max[2]), root.color);
-    lines.add(Vector3(max[0], min[1], min[2]), Vector3(max[0], min[1], max[2]), root.color);
-    lines.add(Vector3(min[0], min[1], max[2]), Vector3(max[0], min[1], max[2]), root.color);
-
-    lines.add(Vector3(min[0], min[1], min[2]), Vector3(min[0], max[1], min[2]), root.color);
-    lines.add(Vector3(max[0], min[1], min[2]), Vector3(max[0], max[1], min[2]), root.color);
-    lines.add(Vector3(min[0], min[1], max[2]), Vector3(min[0], max[1], max[2]), root.color);
-    lines.add(Vector3(max[0], min[1], max[2]), Vector3(max[0], max[1], max[2]), root.color);
-
-    lines.add(Vector3(min[0], max[1], min[2]), Vector3(max[0], max[1], min[2]), root.color);
-    lines.add(Vector3(min[0], max[1], min[2]), Vector3(min[0], max[1], max[2]), root.color);
-    lines.add(Vector3(max[0], max[1], min[2]), Vector3(max[0], max[1], max[2]), root.color);
-    lines.add(Vector3(min[0], max[1], max[2]), Vector3(max[0], max[1], max[2]), root.color);
-
-    fillLines(lines, &root, min, max);
-
-    lines.build();
-}
-
-void KDTree::fillLines(Lines& lines, const Node* n, const Vector3& min, const Vector3& max) const {
-    if(n->childs[0] == nullptr && n->childs[1] == nullptr) {
-        return;
-    }
-    switch(n->splitDim) {
-        case 0:
-            lines.add(Vector3(n->splitValue, min[1], min[2]), Vector3(n->splitValue, max[1], min[2]), n->color);
-            lines.add(Vector3(n->splitValue, max[1], min[2]), Vector3(n->splitValue, max[1], max[2]), n->color);
-            lines.add(Vector3(n->splitValue, max[1], max[2]), Vector3(n->splitValue, min[1], max[2]), n->color);
-            lines.add(Vector3(n->splitValue, min[1], max[2]), Vector3(n->splitValue, min[1], min[2]), n->color);
-            if(n->childs[0] != nullptr) {
-                fillLines(lines, n->childs[0], min, Vector3(n->splitValue, max[1], max[2]));
-            }
-            if(n->childs[1] != nullptr) {
-                fillLines(lines, n->childs[1], Vector3(n->splitValue, min[1], min[2]), max);
-            }
-            break;
-        case 1:
-            lines.add(Vector3(min[0], n->splitValue, min[2]), Vector3(max[0], n->splitValue, min[2]), n->color);
-            lines.add(Vector3(min[0], n->splitValue, min[2]), Vector3(min[0], n->splitValue, max[2]), n->color);
-            lines.add(Vector3(max[0], n->splitValue, min[2]), Vector3(max[0], n->splitValue, max[2]), n->color);
-            lines.add(Vector3(min[0], n->splitValue, max[2]), Vector3(max[0], n->splitValue, max[2]), n->color);
-            if(n->childs[0] != nullptr) {
-                fillLines(lines, n->childs[0], min, Vector3(max[0], n->splitValue, max[2]));
-            }
-            if(n->childs[1] != nullptr) {
-                fillLines(lines, n->childs[1], Vector3(min[0], n->splitValue, min[2]), max);
-            }
-            break;
-        case 2:
-            lines.add(Vector3(min[0], min[1], n->splitValue), Vector3(min[0], max[1], n->splitValue), n->color);
-            lines.add(Vector3(min[0], max[1], n->splitValue), Vector3(max[0], max[1], n->splitValue), n->color);
-            lines.add(Vector3(max[0], max[1], n->splitValue), Vector3(max[0], min[1], n->splitValue), n->color);
-            lines.add(Vector3(max[0], min[1], n->splitValue), Vector3(min[0], min[1], n->splitValue), n->color);
-            if(n->childs[0] != nullptr) {
-                fillLines(lines, n->childs[0], min, Vector3(max[0], max[1], n->splitValue));
-            }
-            if(n->childs[1] != nullptr) {
-                fillLines(lines, n->childs[1], Vector3(min[0], min[1], n->splitValue), max);
-            }
-            break;
-    }
-}
-
-void KDTree::cleanVisited(Node* n) {
-    if(n->childs[0] != nullptr) {
-        cleanVisited(n->childs[0]);
-    }
-    if(n->childs[1] != nullptr) {
-        cleanVisited(n->childs[1]);
-    }
-    n->color = 0xFFFFFF;
-}
-
-bool KDTree::findIntersection(const Vector3& pos, const Vector3& direction) {
-    minDistance = 9999999.0f;
-    original = pos;
-    cleanVisited(&root);
-
-    float t = 0.0f;
-    for(int i = 0; i < 3; i++) {
-        if(direction[i] == 0.0f) {
-            continue;
-        }
-        t = std::max(t, std::abs((min[i] - pos[i]) / direction[i]));
-        t = std::max(t, std::abs((max[i] - pos[i]) / direction[i]));
-    }
-
-    return findIntersection(&root, pos, direction, t);
-}
-
-Vector3 KDTree::getIntersection() const {
-    return intersection;
-}
-
-KDTree::Triangle KDTree::getIntersectedTriangle() const {
-    return intersectionTriangle;
-}
-
-bool KDTree::findIntersection(Node* n, const Vector3& pos, const Vector3& direction, float tMax) {
-    if(n == nullptr) {
-        return false;
-    }
-    n->color = 0x00FFFF;
-    int dim = n->splitDim;
-    // lessEqual = 0
-    // greater = 1
-    bool r = false;
-    bool first = pos[dim] > n->splitValue;
-    if(direction[dim] == 0.0f) {
-        r = findIntersection(n->childs[first], pos, direction, tMax);
-    } else {
-        float t = (n->splitValue - pos[dim]) / direction[dim];
-        if(t >= 0.0f && t < tMax) {
-            r = findIntersection(n->childs[first], pos, direction, t);
-            r = findIntersection(n->childs[!first], pos + t * direction, direction, tMax - t) || r;
-        } else {
-            r = findIntersection(n->childs[first], pos, direction, tMax);
-        }
-    }
-    
-    for(KDTree::Triangle& tri : n->data) {
-        float t = testIntersection(pos, direction, tri);
-        if(t < 0.0f) {
-            continue;
-        }
-        Vector3 i = pos + t * direction;
-        float distance = static_cast<Vector3> (original - i).squareLength();
-        if(distance > minDistance) {
-            continue;
-        }
-        intersectionTriangle = tri;
-        intersection = i;
-        minDistance = distance;
-        r = true;
-    }
-    return r;
-}
-
-float KDTree::orient(const Vector3& a, const Vector3& b, const Vector3& c, const Vector3& d) const {
-    return static_cast<Vector3> (a - d).dot(static_cast<Vector3> (b - d).cross(c - d));
-}
-
-float KDTree::testIntersection(const Vector3& pos, const Vector3& direction, const KDTree::Triangle& t) const {
-    const float eps = 0.0001f;
-    Vector3 h1 = t[1] - t[0];
-    Vector3 h2 = t[2] - t[0];
-    Vector3 abc = h1.cross(h2);
-    if(abc.squareLength() < eps) {
-        return -1.0f;
-    }
-    abc.normalize();
-    float d = -abc.dot(t[0]);
-
-    float check = abc.dot(direction);
-    if(std::abs(check) < eps) {
-        return -1.0f;
-    }
-    float factor = -(abc.dot(pos) + d) / check;
-    Vector3 inter = pos + factor * direction;
-
-    int sideA = 0;
-    int sideB = 0;
-
-    for(int i = 0; i < 3; i++) {
-        const Vector3& a = t[i];
-        const Vector3& b = t[(i + 1) % 3];
-        const Vector3 c = t[i] + abc;
-        float o = orient(a, b, c, inter);
-        if(o < -eps) {
-            sideA++;
-        } else if(o > eps) {
-            sideB++;
-        } else {
-            sideA++;
-            sideB++;
-        }
-    }
-
-    if(sideA >= 3 || sideB >= 3) {
-        return factor;
-    }
-    return -1.0f;
-}

+ 0 - 69
common/utils/KDTree.h

@@ -1,69 +0,0 @@
-#ifndef KDTREE_H
-#define KDTREE_H
-
-#include <vector>
-
-#include "common/utils/Array.h"
-#include "common/math/Vector.h"
-#include "client/rendering/Lines.h"
-
-struct KDTree final {
-
-    class Triangle {
-        Array<Vector3, 3> v;
-        Vector3 mid;
-    public:
-        Triangle() = default;
-        Triangle(const Vector3& a, const Vector3& b, const Vector3& c);
-        const Array<Vector3, 3>& data() const;
-        const Vector3& operator[](int index) const;
-        const Vector3& getMid() const;
-    };
-
-private:
-
-    struct Node {
-        std::vector<Triangle> data;
-        int splitDim;
-        float splitValue;
-        Node* childs[2];
-        int color;
-        Node();
-    };
-
-    Node root;
-    
-    float minDistance;
-    Vector3 intersection;
-    KDTree::Triangle intersectionTriangle;
-    Vector3 original;
-    Vector3 min;
-    Vector3 max;
-
-public:
-    KDTree() = default;
-    ~KDTree();
-    KDTree(const KDTree& other) = delete;
-    KDTree(KDTree&& other) = delete;
-    KDTree& operator=(const KDTree& other) = delete;
-    KDTree& operator=(KDTree&& other) = delete;
-
-    void build(std::vector<KDTree::Triangle>& data);
-    void fillLines(Lines& lines) const;
-    bool findIntersection(const Vector3& pos, const Vector3& direction);
-    Vector3 getIntersection() const;
-    KDTree::Triangle getIntersectedTriangle() const;
-    
-private:
-    void clean(Node* n);
-    void cleanVisited(Node* n);
-    float median(std::vector<KDTree::Triangle>& data, int dim) const;
-    void build(Node* n, std::vector<KDTree::Triangle>& data);
-    void fillLines(Lines& lines, const Node* n, const Vector3& min, const Vector3& max) const;
-    bool findIntersection(Node* n, const Vector3& pos, const Vector3& direction, float tMax);
-    
-    float orient(const Vector3& a, const Vector3& b, const Vector3& c, const Vector3& d) const;
-    float testIntersection(const Vector3& pos, const Vector3& direction, const KDTree::Triangle& t) const;
-};
-
-#endif

+ 62 - 10
meson.build

@@ -1,14 +1,66 @@
 project('cubes plus plus', 'cpp')
 
-# 'common/world/Chunk.cpp', 'common/world/World.cpp', 'common/utils/Face.cpp'
+sourcesCommon = [
+    'common/network/Packet.cpp', 
+    'common/block/BlockBuilder.cpp', 
+    'common/block/Block.cpp', 
+    'common/block/BlockRegistry.cpp', 
+    'common/utils/HashedString.cpp', 
+    'common/utils/String.cpp', 
+    'common/utils/SplitString.cpp', 
+    'common/utils/Random.cpp', 
+    'common/world/World.cpp', 
+    'gaming-core/math/Vector.cpp']
 
-sourcesCommon = ['common/network/Packet.cpp', 'common/block/BlockBuilder.cpp', 'common/block/Block.cpp', 'common/block/BlockRegistry.cpp', 'common/utils/HashedString.cpp', 'common/utils/String.cpp', 'common/utils/SplitString.cpp', 'common/utils/Random.cpp', 'common/world/World.cpp', 'common/math/Vector.cpp']
+sourcesServer = ['server/Main.cpp',
+    'server/network/Server.cpp',
+    'server/network/Client.cpp',
+    'server/GameServer.cpp',
+    'server/commands/ServerCommands.cpp',
+    'server/commands/CommandManager.cpp',
+    'server/commands/ConsoleEditor.cpp',
+    'server/Clock.cpp']
 
-sourcesServer = ['server/Main.cpp', 'server/network/Server.cpp', 'server/network/Client.cpp', 'server/GameServer.cpp', 'server/commands/ServerCommands.cpp', 'server/commands/CommandManager.cpp', 'server/commands/ConsoleEditor.cpp', 'server/Clock.cpp']
+sourcesClient = ['client/Main.cpp',
+    'gaming-core/utils/Size.cpp',
+    'gaming-core/math/Frustum.cpp',
+    'gaming-core/math/Plane.cpp',
+    'client/rendering/Framebuffers.cpp',
+    'client/rendering/wrapper/GLFWWrapper.cpp',
+    'client/rendering/wrapper/Window.cpp',
+    'client/rendering/Engine.cpp',
+    'client/input/Keys.cpp',
+    'client/rendering/wrapper/Shader.cpp',
+    'client/rendering/Shaders.cpp',
+    'client/rendering/Mesh.cpp',
+    'gaming-core/math/Matrix.cpp',
+    'gaming-core/math/Quaternion.cpp',
+    'client/Game.cpp',
+    'client/input/MouseButtons.cpp',
+    'client/rendering/FileTexture.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',
+    'client/rendering/wrapper/VertexBuffer.cpp',
+    'client/rendering/wrapper/StreamBuffer.cpp',
+    'client/rendering/wrapper/Texture.cpp',
+    'client/utils/PNGReader.cpp',
+    'client/rendering/wrapper/GLWrapper.cpp',
+    'client/rendering/Renderer.cpp',
+    'client/rendering/renderer/WorldRenderer.cpp',
+    'client/rendering/NormalTexture.cpp',
+    'client/rendering/Vertex.cpp',
+    'client/rendering/Triangle.cpp',
+    'client/rendering/Lines.cpp']
 
-sourcesClient = ['client/Main.cpp', 'client/rendering/WindowSize.cpp', 'client/math/Frustum.cpp', 'client/rendering/Framebuffers.cpp', 'client/rendering/wrapper/GLFWWrapper.cpp', 'client/rendering/wrapper/Window.cpp', 'client/rendering/Engine.cpp', 'client/input/Keys.cpp', 'client/rendering/wrapper/Shader.cpp', 'client/rendering/Shaders.cpp', 'client/utils/Utils.cpp', 'client/rendering/Mesh.cpp', 'client/math/Matrix.cpp', 'client/math/MatrixStack.cpp', 'client/math/Quaternion.cpp', 'client/math/Plane.cpp', 'client/Game.cpp', 'client/input/MouseButtons.cpp', 'client/rendering/FileTexture.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', 'client/rendering/wrapper/VertexBuffer.cpp', 'client/rendering/wrapper/StreamBuffer.cpp', 'client/rendering/wrapper/Texture.cpp', 'client/utils/PNGReader.cpp', 'client/rendering/wrapper/GLWrapper.cpp', 'client/rendering/Renderer.cpp', 'client/rendering/renderer/WorldRenderer.cpp', 'client/rendering/NormalTexture.cpp', 'client/rendering/Vertex.cpp', 'client/rendering/Triangle.cpp', 'client/rendering/Lines.cpp', 'common/utils/KDTree.cpp']
-
-sourcesTest = ['tests/Main.cpp', 'common/utils/String.cpp', 'common/utils/SplitString.cpp', 'common/utils/HashedString.cpp', 'common/utils/Random.cpp']
+sourcesTest = ['tests/Main.cpp',
+    'common/utils/String.cpp',
+    'common/utils/SplitString.cpp',
+    'common/utils/HashedString.cpp',
+    'common/utils/Random.cpp']
 
 c_compiler = meson.get_compiler('cpp')
 readline = c_compiler.find_library('readline', required: true)
@@ -21,16 +73,16 @@ pngDep = dependency('libpng')
 executable('game_server', 
     sources: sourcesCommon + sourcesServer,
     dependencies : [threadDep, readline],
+    include_directories : include_directories('gaming-core'),
     cpp_args: ['-Wall', '-Wextra', '-pedantic', '-Werror'])
     
 executable('game_tests', 
     sources: sourcesTest,
+    include_directories : include_directories('gaming-core'),
     cpp_args: ['-Wall', '-Wextra', '-pedantic', '-Werror'])
     
 executable('game_client', 
     sources: sourcesCommon + sourcesClient,
     dependencies : [threadDep, glewDep, glfwDep, pngDep],
-    cpp_args: ['-Wall', '-Wextra', '-pedantic', '-Werror'])
-    
-
-	
+    include_directories : include_directories('gaming-core'),
+    cpp_args: ['-Wall', '-Wextra', '-pedantic', '-Werror'])

+ 0 - 20
resources/shader/antialiasFragment.fs

@@ -1,20 +0,0 @@
-#version 430
-
-layout (binding = 0) uniform sampler2D colorSamp;
-
-in vec2 varTex;
-out vec4 color;
-
-uniform int radius;
-
-void main() {
-    vec2 texelSize = 1.0 / vec2(textureSize(colorSamp, 0));
-    color = vec4(0.0, 0.0, 0.0, 0.0);
-    for(float x = 0; x < radius; x++) {
-        for(float y = 0; y < radius; y++) {
-            vec2 offset = vec2(x, y) * texelSize;
-            color += texture(colorSamp, varTex + offset);
-        }
-    }
-    color /= (radius * radius);
-}  

+ 0 - 11
resources/shader/antialiasVertex.vs

@@ -1,11 +0,0 @@
-#version 430
-
-layout (location = 0) in vec3 position;
-layout (location = 1) in vec2 tex;
-
-out vec2 varTex;
-
-void main(void) { 
-    gl_Position = vec4(position, 1.0);
-    varTex = tex;
-}

+ 0 - 32
resources/shader/fragment.fs

@@ -1,32 +0,0 @@
-#version 430
-
-layout (binding = 0) uniform sampler2D samp;
-
-uniform mat4 projMatrix;
-uniform mat4 viewMatrix;
-uniform mat4 modelMatrix;
-
-uniform bool useTexture;
-uniform bool useColor;
-uniform bool useMixColor;
-uniform vec4 mixColor;
-uniform bool useNormals;
-
-in vec2 tc;
-in vec4 outColor;
-out vec4 color;
-
-void main(void) {
-    if(useTexture) {
-        color = texture(samp, tc);
-        if(useColor) {
-            if(useMixColor) {
-                color = (color + mixColor) * 0.5;
-            } else {
-                color = vec4(outColor.xyz, color.w);
-            }
-        }
-    } else {
-        color = outColor;
-    }
-}

+ 0 - 16
resources/shader/lineFragment.fs

@@ -1,16 +0,0 @@
-#version 430
-
-layout (location = 0) out vec3 worldPosition;
-layout (location = 1) out vec3 worldNormal;
-layout (location = 2) out vec4 worldColor;
-layout (location = 3) out float worldShadow;
-
-in vec3 varPosition;
-in vec3 varColor;
-
-void main(void) {
-    worldPosition = varPosition;
-    worldNormal = vec3(0.0, 0.0, 1.0);
-    worldColor = vec4(varColor, 1.0);
-    worldShadow = 1.0;
-}

+ 0 - 18
resources/shader/lineVertex.vs

@@ -1,18 +0,0 @@
-#version 430
-
-layout (location = 0) in vec3 position;
-layout (location = 1) in vec3 color;
-
-uniform mat4 proj;
-uniform mat4 view;
-uniform mat4 model;
-
-out vec3 varPosition;
-out vec3 varColor;
-
-void main(void) { 
-    vec4 worldPos = view * model * vec4(position, 1.0);
-    varPosition = worldPos.xyz;
-    gl_Position = proj * worldPos;
-    varColor = color;
-}

+ 0 - 22
resources/shader/overlayFragment.fs

@@ -1,22 +0,0 @@
-#version 430
-
-layout (binding = 0) uniform sampler2D samp;
-
-uniform bool useTexture;
-uniform bool useColor;
-
-in vec4 varColor;
-in vec2 varTextureCoord;
-
-out vec4 color;
-
-void main() {
-    if(useTexture) {
-        color = texture(samp, varTextureCoord);
-        if(useColor) {
-            color = vec4(varColor.xyz, color.w);
-        }
-    } else {
-        color = varColor;
-    }
-}  

+ 0 - 18
resources/shader/overlayVertex.vs

@@ -1,18 +0,0 @@
-#version 430
-
-layout (location = 0) in vec3 position;
-layout (location = 1) in vec4 color;
-layout (location = 2) in vec2 textureCoord;
-layout (location = 3) in vec3 normal;
-
-uniform mat4 viewMatrix;
-uniform mat4 modelMatrix;
-
-out vec2 varTextureCoord;
-out vec4 varColor;
-
-void main(void) { 
-    varTextureCoord = textureCoord;
-    varColor = color;
-    gl_Position = viewMatrix * modelMatrix * vec4(position, 1.0);
-}

+ 1 - 9
resources/shader/worldFragment.fs

@@ -7,13 +7,11 @@ layout (location = 3) out float worldShadow;
 
 layout (binding = 0) uniform sampler2D samp;
 layout (binding = 1) uniform sampler2D shadowSamp;
-layout (binding = 2) uniform sampler2D normalSamp;
 
 in vec3 varPosition;
 in vec2 varTex;
 in vec3 varNormal;
 in vec4 varShadow;
-in vec3 varTangent;
 
 uniform bool shadows;
 uniform float radius;
@@ -43,13 +41,7 @@ const vec3 light = vec3(-0.280166, -0.573576, -0.769751);
 
 void main(void) {
     worldPosition = varPosition;
-
-    vec3 tangent = normalize(varTangent);
-    vec3 normal = normalize(varNormal);
-    vec3 biTangent = cross(normal, tangent);
-    mat3 tbn = mat3(tangent, biTangent, normal);
-
-    worldNormal = tbn * normalize(texture(normalSamp, varTex).xyz * 2.0 - 1.0);
+    worldNormal = varNormal;
 
     if(shadows) {
         vec3 pos = varShadow.xyz / varShadow.w;

+ 1 - 4
resources/shader/worldPostFragment.fs

@@ -7,7 +7,6 @@ layout (binding = 3) uniform sampler2D worldNormalSamp;
 
 uniform bool ssao;
 uniform bool shadows;
-uniform float bump;
 
 in vec2 varTex;
 
@@ -21,9 +20,7 @@ void main() {
         color = vec4(color.xyz * (texture(ssaoSamp, varTex).r + 0.5), 1.0);
     }
     if(shadows) {
-        float f = texture(shadowSamp, varTex).r;
+        float f = texture(shadowSamp, varTex).r * max(dot(texture(worldNormalSamp, varTex).xyz, -light), 0.0);
         color *= f * 0.5 + 0.5;
     }
-    float diffuseLight = max(dot(texture(worldNormalSamp, varTex).xyz, -light), 0.0) * bump + (1.0 - bump);
-    color *= diffuseLight;
 }  

+ 0 - 3
resources/shader/worldVertex.vs

@@ -3,7 +3,6 @@
 layout (location = 0) in vec3 position;
 layout (location = 1) in vec2 tex;
 layout (location = 2) in vec3 normal;
-layout (location = 3) in vec3 tangent;
 
 uniform mat4 proj;
 uniform mat4 view;
@@ -15,13 +14,11 @@ out vec3 varPosition;
 out vec2 varTex;
 out vec3 varNormal;
 out vec4 varShadow;
-out vec3 varTangent;
 
 void main(void) { 
     // transforming normals must not use the fourth dimension
     // should be the inverse transposed matrix
     varNormal = (model * vec4(normal, 0.0)).xyz;
-    varTangent = (model * vec4(tangent, 0.0)).xyz;
     
     varTex = tex;