Browse Source

new code formatting

Kajetan Johannes Hammerle 3 years ago
parent
commit
8692386f41
66 changed files with 716 additions and 1182 deletions
  1. 69 88
      client/Game.cpp
  2. 4 5
      client/Game.h
  3. 102 150
      client/GameClient.cpp
  4. 1 2
      client/GameClient.h
  5. 2 3
      client/Main.cpp
  6. 13 18
      client/Utils.cpp
  7. 16 31
      client/input/Keys.cpp
  8. 11 12
      client/input/Keys.h
  9. 22 42
      client/input/MouseButtons.cpp
  10. 14 15
      client/input/MouseButtons.h
  11. 18 36
      client/math/Camera.cpp
  12. 11 12
      client/math/Camera.h
  13. 23 39
      client/math/Matrix.cpp
  14. 8 9
      client/math/Matrix.h
  15. 4 8
      client/math/MatrixStack.cpp
  16. 2 3
      client/math/MatrixStack.h
  17. 4 7
      client/math/Plane.cpp
  18. 3 4
      client/math/Plane.h
  19. 25 51
      client/math/Vector.cpp
  20. 9 10
      client/math/Vector.h
  21. 18 34
      client/network/Client.cpp
  22. 6 7
      client/network/Client.h
  23. 4 9
      client/network/ClientListener.cpp
  24. 2 4
      client/network/ClientListener.h
  25. 2 4
      client/network/IClientListener.h
  26. 4 7
      common/block/Block.cpp
  27. 2 4
      common/block/Block.h
  28. 9 18
      common/block/BlockRegistry.cpp
  29. 1 2
      common/block/BlockRegistry.h
  30. 26 48
      common/stream/Stream.cpp
  31. 5 6
      common/stream/Stream.h
  32. 27 51
      common/utils/DataVector.cpp
  33. 5 6
      common/utils/DataVector.h
  34. 19 31
      common/utils/Face.cpp
  35. 7 8
      common/utils/Face.h
  36. 6 12
      common/world/Chunk.cpp
  37. 4 5
      common/world/Chunk.h
  38. 2 8
      common/world/World.cpp
  39. 0 2
      common/world/World.h
  40. 7 15
      resources/shader/fragment.fs
  41. 4 9
      resources/shader/overlayFragment.fs
  42. 1 2
      resources/shader/overlayVertex.vs
  43. 3 6
      resources/shader/ssaoBlurFragment.fs
  44. 1 2
      resources/shader/ssaoBlurVertex.vs
  45. 4 7
      resources/shader/ssaoFragment.fs
  46. 1 2
      resources/shader/ssaoVertex.vs
  47. 1 2
      resources/shader/textFragment.fs
  48. 1 2
      resources/shader/textVertex.vs
  49. 1 2
      resources/shader/worldFragment.fs
  50. 4 8
      resources/shader/worldPostFragment.fs
  51. 1 2
      resources/shader/worldPostVertex.vs
  52. 1 2
      resources/shader/worldShadowFragment.fs
  53. 1 2
      resources/shader/worldShadowVertex.vs
  54. 1 2
      resources/shader/worldVertex.vs
  55. 21 42
      server/GameServer.cpp
  56. 2 4
      server/GameServer.h
  57. 1 2
      server/Main.cpp
  58. 7 14
      server/commands/CommandManager.cpp
  59. 2 4
      server/commands/CommandManager.h
  60. 21 39
      server/commands/CommandUtils.cpp
  61. 2 3
      server/commands/CommandUtils.h
  62. 3 6
      server/commands/ServerCommands.cpp
  63. 3 4
      server/commands/ServerCommands.h
  64. 73 125
      server/network/Server.cpp
  65. 2 3
      server/network/Server.h
  66. 37 60
      tests/Main.cpp

+ 69 - 88
client/Game.cpp

@@ -2,16 +2,11 @@
 
 #include "client/Game.h"
 
-Game::Game() : lengthAngle(0.0f), widthAngle(0.0f), texture("resources/textures.png")
-{
-    for(int x = -6; x <= 6; x++)
-    {
-        for(int y = -6; y <= 6; y++)
-        {
-            for(int z = -6; z <= 6; z++)
-            {
-                if(x * x + y * y + z * z < 16)
-                {
+Game::Game() : lengthAngle(0.0f), widthAngle(0.0f), texture("resources/textures.png") {
+    for(int x = -6; x <= 6; x++) {
+        for(int y = -6; y <= 6; y++) {
+            for(int z = -6; z <= 6; z++) {
+                if(x * x + y * y + z * z < 16) {
                     addCube(x - 3, y - 5, z - 10);
                 }
             }
@@ -21,118 +16,105 @@ Game::Game() : lengthAngle(0.0f), widthAngle(0.0f), texture("resources/textures.
     m.build();
 }
 
-void Game::addCube(float x, float y, float z)
-{
+void Game::addCube(float x, float y, float z) {
     const float ERROR = 1.0f / 1024.0f;
     // bottom
-    m.add({x - ERROR, y - ERROR, z - ERROR, 0.125f, 0.0f, 0, -1, 0});
-    m.add({x + 1 + ERROR, y - ERROR, z - ERROR, 0.1875f, 0.0f, 0, -1, 0});
-    m.add({x - ERROR, y - ERROR, z + 1 + ERROR, 0.125f, 0.0625f, 0, -1, 0});
-    
-    m.add({x + 1 + ERROR, y - ERROR, z - ERROR, 0.1875f, 0.0f, 0, -1, 0});
-    m.add({x + 1 + ERROR, y - ERROR, z + 1 + ERROR, 0.1875f, 0.0625f, 0, -1, 0});
-    m.add({x - ERROR, y - ERROR, z + 1 + ERROR, 0.125f, 0.0625f, 0, -1, 0});
-    
+    m.add( {x - ERROR, y - ERROR, z - ERROR, 0.125f, 0.0f, 0, -1, 0});
+    m.add( {x + 1 + ERROR, y - ERROR, z - ERROR, 0.1875f, 0.0f, 0, -1, 0});
+    m.add( {x - ERROR, y - ERROR, z + 1 + ERROR, 0.125f, 0.0625f, 0, -1, 0});
+
+    m.add( {x + 1 + ERROR, y - ERROR, z - ERROR, 0.1875f, 0.0f, 0, -1, 0});
+    m.add( {x + 1 + ERROR, y - ERROR, z + 1 + ERROR, 0.1875f, 0.0625f, 0, -1, 0});
+    m.add( {x - ERROR, y - ERROR, z + 1 + ERROR, 0.125f, 0.0625f, 0, -1, 0});
+
     // top
-    m.add({x - ERROR, y + 1 + ERROR, z - ERROR, 0.25f, 0.0f, 0, 1, 0});
-    m.add({x - ERROR, y + 1 + ERROR, z + 1 + ERROR, 0.25f, 0.0625f, 0, 1, 0});
-    m.add({x + 1 + ERROR, y + 1 + ERROR, z - ERROR, 0.3125f, 0.0f, 0, 1, 0});
-    
-    m.add({x + 1 + ERROR, y + 1 + ERROR, z - ERROR, 0.3125f, 0.0f, 0, 1, 0});
-    m.add({x - ERROR, y + 1 + ERROR, z + 1 + ERROR, 0.25f, 0.0625f, 0, 1, 0});
-    m.add({x + 1 + ERROR, y + 1 + ERROR, z + 1 + ERROR, 0.3125f, 0.0625f, 0, 1, 0});
-    
+    m.add( {x - ERROR, y + 1 + ERROR, z - ERROR, 0.25f, 0.0f, 0, 1, 0});
+    m.add( {x - ERROR, y + 1 + ERROR, z + 1 + ERROR, 0.25f, 0.0625f, 0, 1, 0});
+    m.add( {x + 1 + ERROR, y + 1 + ERROR, z - ERROR, 0.3125f, 0.0f, 0, 1, 0});
+
+    m.add( {x + 1 + ERROR, y + 1 + ERROR, z - ERROR, 0.3125f, 0.0f, 0, 1, 0});
+    m.add( {x - ERROR, y + 1 + ERROR, z + 1 + ERROR, 0.25f, 0.0625f, 0, 1, 0});
+    m.add( {x + 1 + ERROR, y + 1 + ERROR, z + 1 + ERROR, 0.3125f, 0.0625f, 0, 1, 0});
+
     // left
-    m.add({x - ERROR, y - ERROR, z - ERROR, 0.1875f, 0.0625f, -1, 0, 0});
-    m.add({x - ERROR, y - ERROR, z + 1 + ERROR, 0.25f, 0.0625f, -1, 0, 0});
-    m.add({x - ERROR, y + 1 + ERROR, z - ERROR, 0.1875f, 0.0f, -1, 0, 0});
-    
-    m.add({x - ERROR, y - ERROR, z + 1 + ERROR, 0.25f, 0.0625f, -1, 0, 0});
-    m.add({x - ERROR, y + 1 + ERROR, z + 1 + ERROR, 0.25f, 0.0f, -1, 0, 0});
-    m.add({x - ERROR, y + 1 + ERROR, z - ERROR, 0.1875f, 0.0f, -1, 0, 0});
-    
+    m.add( {x - ERROR, y - ERROR, z - ERROR, 0.1875f, 0.0625f, -1, 0, 0});
+    m.add( {x - ERROR, y - ERROR, z + 1 + ERROR, 0.25f, 0.0625f, -1, 0, 0});
+    m.add( {x - ERROR, y + 1 + ERROR, z - ERROR, 0.1875f, 0.0f, -1, 0, 0});
+
+    m.add( {x - ERROR, y - ERROR, z + 1 + ERROR, 0.25f, 0.0625f, -1, 0, 0});
+    m.add( {x - ERROR, y + 1 + ERROR, z + 1 + ERROR, 0.25f, 0.0f, -1, 0, 0});
+    m.add( {x - ERROR, y + 1 + ERROR, z - ERROR, 0.1875f, 0.0f, -1, 0, 0});
+
     // right
-    m.add({x + 1 + ERROR, y - ERROR, z - ERROR, 0.25f, 0.0625f, 1, 0, 0});
-    m.add({x + 1 + ERROR, y + 1 + ERROR, z - ERROR, 0.25f, 0.0f, 1, 0, 0});
-    m.add({x + 1 + ERROR, y - ERROR, z + 1 + ERROR, 0.1875f, 0.0625f, 1, 0, 0});
-    
-    m.add({x + 1 + ERROR, y - ERROR, z + 1 + ERROR, 0.1875f, 0.0625f, 1, 0, 0});
-    m.add({x + 1 + ERROR, y + 1 + ERROR, z - ERROR, 0.25f, 0.0f, 1, 0, 0});
-    m.add({x + 1 + ERROR, y + 1 + ERROR, z + 1 + ERROR, 0.1875f, 0.0f, 1, 0, 0});
-    
+    m.add( {x + 1 + ERROR, y - ERROR, z - ERROR, 0.25f, 0.0625f, 1, 0, 0});
+    m.add( {x + 1 + ERROR, y + 1 + ERROR, z - ERROR, 0.25f, 0.0f, 1, 0, 0});
+    m.add( {x + 1 + ERROR, y - ERROR, z + 1 + ERROR, 0.1875f, 0.0625f, 1, 0, 0});
+
+    m.add( {x + 1 + ERROR, y - ERROR, z + 1 + ERROR, 0.1875f, 0.0625f, 1, 0, 0});
+    m.add( {x + 1 + ERROR, y + 1 + ERROR, z - ERROR, 0.25f, 0.0f, 1, 0, 0});
+    m.add( {x + 1 + ERROR, y + 1 + ERROR, z + 1 + ERROR, 0.1875f, 0.0f, 1, 0, 0});
+
     // front
-    m.add({x - ERROR, y - ERROR, z + 1 + ERROR, 0.1875f, 0.0625f, 0, 0, 1});
-    m.add({x + 1 + ERROR, y - ERROR, z + 1 + ERROR, 0.25f, 0.0625f, 0, 0, 1});
-    m.add({x - ERROR, y + 1 + ERROR, z + 1 + ERROR, 0.1875f, 0.0f, 0, 0, 1});
-    
-    m.add({x + 1 + ERROR, y + 1 + ERROR, z + 1 + ERROR, 0.25f, 0.0f, 0, 0, 1});
-    m.add({x - ERROR, y + 1 + ERROR, z + 1 + ERROR, 0.1875f, 0.0f, 0, 0, 1});
-    m.add({x + 1 + ERROR, y - ERROR, z + 1 + ERROR, 0.25f, 0.0625f, 0, 0, 1});
-    
+    m.add( {x - ERROR, y - ERROR, z + 1 + ERROR, 0.1875f, 0.0625f, 0, 0, 1});
+    m.add( {x + 1 + ERROR, y - ERROR, z + 1 + ERROR, 0.25f, 0.0625f, 0, 0, 1});
+    m.add( {x - ERROR, y + 1 + ERROR, z + 1 + ERROR, 0.1875f, 0.0f, 0, 0, 1});
+
+    m.add( {x + 1 + ERROR, y + 1 + ERROR, z + 1 + ERROR, 0.25f, 0.0f, 0, 0, 1});
+    m.add( {x - ERROR, y + 1 + ERROR, z + 1 + ERROR, 0.1875f, 0.0f, 0, 0, 1});
+    m.add( {x + 1 + ERROR, y - ERROR, z + 1 + ERROR, 0.25f, 0.0625f, 0, 0, 1});
+
     // back
-    m.add({x - ERROR, y - ERROR, z - ERROR, 0.25f, 0.0625f, 0, 0, -1});
-    m.add({x - ERROR, y + 1 + ERROR, z - ERROR, 0.25f, 0.0f, 0, 0, -1});
-    m.add({x + 1 + ERROR, y - ERROR, z - ERROR, 0.1875f, 0.0625f, 0, 0, -1});
-    
-    m.add({x + 1 + ERROR, y + 1 + ERROR, z - ERROR, 0.1875f, 0.0f, 0, 0, -1});
-    m.add({x + 1 + ERROR, y - ERROR, z - ERROR, 0.1875f, 0.0625f, 0, 0, -1}); 
-    m.add({x - ERROR, y + 1 + ERROR, z - ERROR, 0.25f, 0.0f, 0, 0, -1});
+    m.add( {x - ERROR, y - ERROR, z - ERROR, 0.25f, 0.0625f, 0, 0, -1});
+    m.add( {x - ERROR, y + 1 + ERROR, z - ERROR, 0.25f, 0.0f, 0, 0, -1});
+    m.add( {x + 1 + ERROR, y - ERROR, z - ERROR, 0.1875f, 0.0625f, 0, 0, -1});
+
+    m.add( {x + 1 + ERROR, y + 1 + ERROR, z - ERROR, 0.1875f, 0.0f, 0, 0, -1});
+    m.add( {x + 1 + ERROR, y - ERROR, z - ERROR, 0.1875f, 0.0625f, 0, 0, -1});
+    m.add( {x - ERROR, y + 1 + ERROR, z - ERROR, 0.25f, 0.0f, 0, 0, -1});
 }
 
-void Game::tick(const Keys& keys, const MouseButtons& mButtons, Camera& cam)
-{
+void Game::tick(const Keys& keys, const MouseButtons& mButtons, Camera& cam) {
     (void) mButtons;
-    
+
     const float speed = 0.5f;
-    if(keys.down.isDown())
-    {
+    if(keys.down.isDown()) {
         pos.addMul(cam.getFlatBack(), speed);
     }
-    if(keys.up.isDown())
-    {
+    if(keys.up.isDown()) {
         pos.addMul(cam.getFlatFront(), speed);
     }
-    if(keys.left.isDown())
-    {
+    if(keys.left.isDown()) {
         pos.addMul(cam.getFlatLeft(), speed);
     }
-    if(keys.right.isDown())
-    {
+    if(keys.right.isDown()) {
         pos.addMul(cam.getFlatRight(), speed);
     }
-    if(keys.jump.isDown())
-    {
+    if(keys.jump.isDown()) {
         pos.addMul(cam.getFlatUp(), speed);
     }
-    if(keys.sneak.isDown())
-    {
+    if(keys.sneak.isDown()) {
         pos.addMul(cam.getFlatDown(), speed);
     }
-    
+
     const float rotation = 5.0f;
-    if(keys.camLeft.isDown())
-    {
+    if(keys.camLeft.isDown()) {
         lengthAngle += rotation;
     }
-    if(keys.camRight.isDown())
-    {
+    if(keys.camRight.isDown()) {
         lengthAngle -= rotation;
     }
-    if(keys.camUp.isDown() && widthAngle - rotation > -90.0f)
-    {
+    if(keys.camUp.isDown() && widthAngle - rotation > -90.0f) {
         widthAngle -= rotation;
     }
-    if(keys.camDown.isDown() && widthAngle + rotation < 90.0f)
-    {
+    if(keys.camDown.isDown() && widthAngle + rotation < 90.0f) {
         widthAngle += rotation;
     }
-    
+
     cam.storePosition();
     cam.setPosition(pos, lengthAngle, widthAngle);
 }
 
-void Game::renderWorld(float lag, MatrixStack& stack, Shader& sh)
-{
+void Game::renderWorld(float lag, MatrixStack& stack, Shader& sh) {
     (void) lag;
     (void) stack;
     (void) sh;
@@ -140,8 +122,7 @@ void Game::renderWorld(float lag, MatrixStack& stack, Shader& sh)
     m.draw();
 }
 
-void Game::renderTextOverlay(float lag, MatrixStack& stack, Shader& sh, FontRenderer& fr)
-{
+void Game::renderTextOverlay(float lag, MatrixStack& stack, Shader& sh, FontRenderer& fr) {
     (void) lag;
     stack.get().scale(2.0f, 2.0f, 2.0f);
     sh.setMatrix("model", stack.get().getValues());

+ 4 - 5
client/Game.h

@@ -10,18 +10,17 @@
 #include "client/rendering/Texture.h"
 #include "client/rendering/FontRenderer.h"
 
-class Game
-{
+class Game {
 public:
     Game();
-    
+
     void tick(const Keys& keys, const MouseButtons& mButtons, Camera& cam);
     void renderWorld(float lag, MatrixStack& stack, Shader& sh);
     void renderTextOverlay(float lag, MatrixStack& stack, Shader& sh, FontRenderer& fr);
-    
+
 private:
     void addCube(float x, float y, float z);
-    
+
     float lengthAngle;
     float widthAngle;
     Vector pos;

+ 102 - 150
client/GameClient.cpp

@@ -21,20 +21,17 @@
 #include "client/Game.h"
 #include "rendering/NoiseTexture.h"
 
-struct InternGameClient
-{
-    ~InternGameClient()
-    {
-        if(window != nullptr)
-        {
+struct InternGameClient {
+
+    ~InternGameClient() {
+        if(window != nullptr) {
             glfwDestroyWindow(window);
         }
-        if(glfwInitDone)
-        {
+        if(glfwInitDone) {
             glfwTerminate();
         }
     }
-    
+
     bool glfwInitDone = false;
     GLFWwindow* window = nullptr;
 };
@@ -53,23 +50,22 @@ static Keys keys;
 static MouseButtons mButtons;
 static bool useSSAO = false;
 
-struct Shaders
-{
-    Shaders() : 
-        world("resources/shader/worldVertex.vs", "resources/shader/worldFragment.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")
-    {
+struct Shaders {
+
+    Shaders() :
+    world("resources/shader/worldVertex.vs", "resources/shader/worldFragment.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") {
         worldProj.set(11, -1.0f);
         worldProj.set(15, 0.0f);
-        
+
         worldShadowProj.set(11, -1.0f);
         worldShadowProj.set(15, 0.0f);
     }
-    
+
     Shader world;
     Shader ssao;
     Shader ssaoBlur;
@@ -77,33 +73,30 @@ struct Shaders
     Shader postWorld;
     Shader text;
     bool once = true;
-    
+
     Matrix worldProj;
     Matrix worldView;
-    
+
     Matrix worldShadowProj;
     Matrix worldShadowView;
     Matrix worldShadowProjView;
-    
-    bool isValid() const
-    {
-        return world.isValid() && ssao.isValid() && ssaoBlur.isValid() && 
+
+    bool isValid() const {
+        return world.isValid() && ssao.isValid() && ssaoBlur.isValid() &&
                 shadow.isValid() && postWorld.isValid() && text.isValid();
     }
-    
-    void updateWorldProjection()
-    {
+
+    void updateWorldProjection() {
         float tan = tanf((0.5f * fovY) * M_PI / 180.0f);
         float q = 1.0f / tan;
         float aspect = (float) width / height;
-        
+
         worldProj.set(0, q / aspect);
         worldProj.set(5, q);
-        worldProj.set(10,(nearClip + farClip) / (nearClip - farClip));
+        worldProj.set(10, (nearClip + farClip) / (nearClip - farClip));
         worldProj.set(14, (2.0f * nearClip * farClip) / (nearClip - farClip));
 
-        if(once)
-        {
+        if(once) {
             worldShadowProj.setToIdentity();
             worldShadowProj.set(0, 2.0f / (10.0f * aspect));
             worldShadowProj.set(5, 2.0f / (10.0f));
@@ -111,14 +104,13 @@ struct Shaders
         }
     }
 
-    void updateWorldView(float lag, Camera& cam)
-    {
+    void updateWorldView(float lag, Camera& cam) {
         cam.update(lag);
         Vector right = cam.getRight();
         Vector up = cam.getUp();
         Vector back = cam.getBack();
         Vector pos = cam.getPosition();
-        
+
         worldView.set(0, right.getX());
         worldView.set(1, up.getX());
         worldView.set(2, back.getX());
@@ -131,15 +123,14 @@ struct Shaders
         worldView.set(12, right.dotInverse(pos));
         worldView.set(13, up.dotInverse(pos));
         worldView.set(14, back.dotInverse(pos));
-        
-        if(once)
-        {
+
+        if(once) {
             // lengthAngle = 20; widthAngle = 35;
             right.set(0.939693f, 0.0f, -0.34202f);
             back.set(0.280166f, 0.573576f, 0.769751f);
             up.set(-0.196175f, 0.819152f, -0.538986f);
             pos.set(0.0f, 2.5f, 0.0f);
-            
+
             once = false;
             worldShadowView.set(0, right.getX());
             worldShadowView.set(1, up.getX());
@@ -157,48 +148,44 @@ struct Shaders
     }
 };
 
-struct Framebuffers
-{
-    Framebuffers(u32 w, u32 h) : 
-        world(w, h, Framebuffer::POSITION | Framebuffer::NORMAL | Framebuffer::COLOR | Framebuffer::RED | Framebuffer::DEPTH24_STENCIL8, 0),
-        ssao(w, h, Framebuffer::RED, 0), 
-        ssaoBlur(w, h, Framebuffer::RED, 0),
-        shadow(w, h, Framebuffer::DEPTH24_STENCIL8, GL_LEQUAL)
-    {
+struct Framebuffers {
+
+    Framebuffers(u32 w, u32 h) :
+    world(w, h, Framebuffer::POSITION | Framebuffer::NORMAL | Framebuffer::COLOR | Framebuffer::RED | Framebuffer::DEPTH24_STENCIL8, 0),
+    ssao(w, h, Framebuffer::RED, 0),
+    ssaoBlur(w, h, Framebuffer::RED, 0),
+    shadow(w, h, Framebuffer::DEPTH24_STENCIL8, GL_LEQUAL) {
     }
-    
-    void resize(u32 w, u32 h) const
-    {
+
+    void resize(u32 w, u32 h) const {
         world.resize(w, h);
         ssao.resize(w, h);
         ssaoBlur.resize(w, h);
         shadow.resize(w, h);
     }
-    
-    bool isValid() const
-    {
+
+    bool isValid() const {
         return world.isValid() && ssao.isValid() && ssaoBlur.isValid();
     }
-    
+
     Framebuffer world;
     Framebuffer ssao;
     Framebuffer ssaoBlur;
     Framebuffer shadow;
 };
 
-struct InternGame
-{
-    InternGame() : ssaoNoise(4, 4)
-    {
-        rectangle.add({-1, -1, 0, 0, 0, 0, 0, 0});
-        rectangle.add({ 1,  1, 0, 1, 1, 0, 0, 0});
-        rectangle.add({-1,  1, 0, 0, 1, 0, 0, 0});
-        rectangle.add({-1, -1, 0, 0, 0, 0, 0, 0});
-        rectangle.add({ 1, -1, 0, 1, 0, 0, 0, 0});
-        rectangle.add({ 1,  1, 0, 1, 1, 0, 0, 0});
+struct InternGame {
+
+    InternGame() : ssaoNoise(4, 4) {
+        rectangle.add( {-1, -1, 0, 0, 0, 0, 0, 0});
+        rectangle.add( {1, 1, 0, 1, 1, 0, 0, 0});
+        rectangle.add( {-1, 1, 0, 0, 1, 0, 0, 0});
+        rectangle.add( {-1, -1, 0, 0, 0, 0, 0, 0});
+        rectangle.add( {1, -1, 0, 1, 0, 0, 0, 0});
+        rectangle.add( {1, 1, 0, 1, 1, 0, 0, 0});
         rectangle.build();
     }
-    
+
     Game game;
     Camera cam;
     MatrixStack model;
@@ -207,16 +194,13 @@ struct InternGame
     Mesh rectangle;
 };
 
-static u64 getTimeNanos()
-{
+static u64 getTimeNanos() {
     return glfwGetTimerValue() * timeFactor;
 }
 
-static bool initGLFW()
-{
+static bool initGLFW() {
     client.glfwInitDone = glfwInit();
-    if(!client.glfwInitDone)
-    {
+    if(!client.glfwInitDone) {
         std::cout << "could not initialize GLFW\n";
         return true;
     }
@@ -224,22 +208,20 @@ static bool initGLFW()
     return false;
 }
 
-static bool initWindow(int w, int h, const char* windowName)
-{
+static bool initWindow(int w, int h, const char* windowName) {
     width = w;
     height = h;
-    
+
     glfwDefaultWindowHints();
     glfwWindowHint(GLFW_VISIBLE, 0);
     glfwWindowHint(GLFW_RESIZABLE, 1);
-    
+
     glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
     glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
     glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
-    
+
     client.window = glfwCreateWindow(width, height, windowName, nullptr, nullptr);
-    if(client.window == nullptr)
-    {
+    if(client.window == nullptr) {
         std::cout << "could not create window\n";
         return true;
     }
@@ -248,11 +230,9 @@ static bool initWindow(int w, int h, const char* windowName)
     return false;
 }
 
-static bool initGLEW()
-{
+static bool initGLEW() {
     GLenum err = glewInit();
-    if(err != GLEW_OK)
-    {
+    if(err != GLEW_OK) {
         std::cout << "could not initialize GLEW: " << glewGetErrorString(err) << "\n";
         return true;
     }
@@ -260,40 +240,29 @@ static bool initGLEW()
     return false;
 }
 
-static void initCallbacks()
-{
+static void initCallbacks() {
     // GLFWwindow* w, int key, int scancode, int action, int mod
-    glfwSetKeyCallback(client.window, [](GLFWwindow*, int key, int, int action, int)
-    {
-        if(action == GLFW_PRESS)
-        {
+    glfwSetKeyCallback(client.window, [](GLFWwindow*, int key, int, int action, int) {
+        if(action == GLFW_PRESS) {
             keys.press(key);
-        }
-        else if(action == GLFW_RELEASE)
-        {
+        } else if(action == GLFW_RELEASE) {
             keys.release(key);
         }
     });
     // GLFWwindow* w, int button, int action, int mods
-    glfwSetMouseButtonCallback(client.window, [](GLFWwindow*, int button, int action, int)
-    {
-        if(action == GLFW_PRESS)
-        {
+    glfwSetMouseButtonCallback(client.window, [](GLFWwindow*, int button, int action, int) {
+        if(action == GLFW_PRESS) {
             mButtons.press(button);
-        }
-        else if(action == GLFW_RELEASE)
-        {
+        } else if(action == GLFW_RELEASE) {
             mButtons.release(button);
         }
     });
     // GLFWwindow* w, double xpos, double ypos
-    glfwSetCursorPosCallback(client.window, [](GLFWwindow*, double x, double y)
-    {
+    glfwSetCursorPosCallback(client.window, [](GLFWwindow*, double x, double y) {
         mButtons.move(x, y);
     });
     // GLFWwindow* w, int width, int height
-    glfwSetFramebufferSizeCallback(client.window, [](GLFWwindow*, int w, int h)
-    {
+    glfwSetFramebufferSizeCallback(client.window, [](GLFWwindow*, int w, int h) {
         glViewport(0, 0, w, h);
         width = w;
         height = h;
@@ -301,27 +270,24 @@ static void initCallbacks()
     });
 }
 
-static void tick(InternGame& game)
-{
+static void tick(InternGame& game) {
     keys.tick();
     mButtons.tick();
     game.game.tick(keys, mButtons, game.cam);
-    if(keys.test.getDownTime() == 1)
-    {
+    if(keys.test.getDownTime() == 1) {
         useSSAO = !useSSAO;
     }
     mButtons.postTick();
 }
 
-static void renderShadow(float lag, Shaders& shaders, InternGame& game, Framebuffers& fb)
-{
+static void renderShadow(float lag, Shaders& shaders, InternGame& game, Framebuffers& fb) {
     fb.shadow.bind();
     glEnable(GL_DEPTH_TEST);
     shaders.shadow.use();
     shaders.worldShadowProjView = shaders.worldShadowProj;
     shaders.worldShadowProjView.mul(shaders.worldShadowView);
     shaders.shadow.setMatrix("projView", shaders.worldShadowProjView.getValues());
-    
+
     //glEnable(GL_CULL_FACE);
     //glCullFace(GL_FRONT);
     //glEnable(GL_POLYGON_OFFSET_FILL);
@@ -331,17 +297,16 @@ static void renderShadow(float lag, Shaders& shaders, InternGame& game, Framebuf
     //glDisable(GL_POLYGON_OFFSET_FILL);
 }
 
-static void renderWorld(float lag, Shaders& shaders, InternGame& game, Framebuffers& fb)
-{
+static void renderWorld(float lag, Shaders& shaders, InternGame& game, Framebuffers& fb) {
     fb.world.bind();
     glEnable(GL_DEPTH_TEST);
     shaders.world.use();
-    
+
     Matrix rWorldShadowProjView;
     rWorldShadowProjView.translate(0.5f, 0.5f, 0.5f);
     rWorldShadowProjView.scale(0.5f, 0.5f, 0.5f);
     rWorldShadowProjView.mul(shaders.worldShadowProjView);
-    
+
     shaders.world.setMatrix("projViewShadow", rWorldShadowProjView.getValues());
     shaders.world.setMatrix("proj", shaders.worldProj.getValues());
     shaders.world.setMatrix("view", shaders.worldView.getValues());
@@ -351,16 +316,15 @@ static void renderWorld(float lag, Shaders& shaders, InternGame& game, Framebuff
     game.game.renderWorld(lag, game.model, shaders.world);
 }
 
-static void renderSSAO(Shaders& shaders, InternGame& game, Framebuffers& fb)
-{
+static void renderSSAO(Shaders& shaders, InternGame& game, Framebuffers& fb) {
     // ssao
     shaders.ssao.use();
-    
+
     Matrix rProj;
     rProj.translate(0.5f, 0.5f, 0.5f);
     rProj.scale(0.5f, 0.5f, 0.5f);
     rProj.mul(shaders.worldProj);
-    
+
     shaders.ssao.setMatrix("proj", rProj.getValues());
     shaders.ssao.setInt("width", width);
     shaders.ssao.setInt("height", height);
@@ -378,8 +342,7 @@ static void renderSSAO(Shaders& shaders, InternGame& game, Framebuffers& fb)
     game.rectangle.draw();
 }
 
-static void renderPostWorld(Shaders& shaders, InternGame& game, Framebuffers& fb)
-{
+static void renderPostWorld(Shaders& shaders, InternGame& game, Framebuffers& fb) {
     glBindFramebuffer(GL_FRAMEBUFFER, 0);
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
     shaders.postWorld.use();
@@ -396,11 +359,10 @@ static u64 sum = 0;
 static u64 tindex = 0;
 static std::array<u64, 128> values;
 
-static void renderTextOverlay(float lag, Shaders& shaders, InternGame& game)
-{
+static void renderTextOverlay(float lag, Shaders& shaders, InternGame& game) {
     glDisable(GL_DEPTH_TEST);
     shaders.text.use();
-    
+
     Matrix m;
     shaders.text.setMatrix("proj", m.getValues());
     m.translate(-1.0f, 1.0f, 0.0f);
@@ -409,7 +371,7 @@ static void renderTextOverlay(float lag, Shaders& shaders, InternGame& game)
     game.model.clear();
     game.model.get().scale(2.0f, 2.0f, 2.0f);
     shaders.text.setMatrix("model", game.model.get().getValues());
-    
+
     glEnable(GL_BLEND);
     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     glBlendEquation(GL_FUNC_ADD);
@@ -420,61 +382,53 @@ static void renderTextOverlay(float lag, Shaders& shaders, InternGame& game)
     glDisable(GL_BLEND);
 }
 
-static void renderTick(float lag, Shaders& shaders, InternGame& game, Framebuffers& fb)
-{
+static void renderTick(float lag, Shaders& shaders, InternGame& game, Framebuffers& fb) {
     u64 current = getTimeNanos();
     sum -= values[tindex];
     values[tindex] = current - last;
     sum += values[tindex];
     last = current;
     tindex = (tindex + 1) & (127);
-    
-    if(resize)
-    {
+
+    if(resize) {
         fb.resize(width, height);
         resize = false;
     }
     shaders.updateWorldProjection();
     shaders.updateWorldView(lag, game.cam);
-    
+
     renderShadow(lag, shaders, game, fb);
     renderWorld(lag, shaders, game, fb);
-    if(useSSAO)
-    {
+    if(useSSAO) {
         renderSSAO(shaders, game, fb);
     }
     renderPostWorld(shaders, game, fb);
     renderTextOverlay(lag, shaders, game);
 }
 
-static void loop()
-{
+static void loop() {
     Shaders shaders;
-    if(!shaders.isValid())
-    {
+    if(!shaders.isValid()) {
         return;
     }
     Framebuffers fb(width, height);
-    if(!fb.isValid())
-    {
+    if(!fb.isValid()) {
         return;
     }
     InternGame game;
-    
+
     last = getTimeNanos();
     u64 lastTime = getTimeNanos();
     u64 lag = 0;
-    while(!glfwWindowShouldClose(client.window))
-    {
+    while(!glfwWindowShouldClose(client.window)) {
         renderTick(lag * lagFactor, shaders, game, fb);
         glfwSwapBuffers(client.window);
-        
+
         u64 newTime = getTimeNanos();
         lag += newTime - lastTime;
         lastTime = newTime;
-        
-        while(lag >= NANOS_PER_TICK)
-        {
+
+        while(lag >= NANOS_PER_TICK) {
             lag -= NANOS_PER_TICK;
             tick(game);
         }
@@ -482,10 +436,8 @@ static void loop()
     }
 }
 
-void GameClient::start(int w, int h, const char* windowName)
-{
-    if(initGLFW() || initWindow(w, h, windowName) || initGLEW())
-    {
+void GameClient::start(int w, int h, const char* windowName) {
+    if(initGLFW() || initWindow(w, h, windowName) || initGLEW()) {
         return;
     }
     initCallbacks();

+ 1 - 2
client/GameClient.h

@@ -3,8 +3,7 @@
 
 #include "common/utils/Types.h"
 
-namespace GameClient
-{
+namespace GameClient {
     void start(int width, int height, const char* windowName);
 }
 

+ 2 - 3
client/Main.cpp

@@ -1,7 +1,6 @@
 #include "client/GameClient.h"
 
-int main(int /*argc*/, char** /*argv*/) 
-{
-    GameClient::start(1024, 620, "Test");   
+int main(int /*argc*/, char** /*argv*/) {
+    GameClient::start(1024, 620, "Test");
     return 0;
 }

+ 13 - 18
client/Utils.cpp

@@ -4,32 +4,30 @@
 
 #include "client/Utils.h"
 
-bool checkAndPrintError(const char* message)
-{
+bool checkAndPrintError(const char* message) {
     GLenum error = glGetError();
-    switch(error)
-    {
-        case GL_NO_ERROR: 
+    switch(error) {
+        case GL_NO_ERROR:
             return false;
-        case GL_INVALID_ENUM: 
+        case GL_INVALID_ENUM:
             std::cout << message << ": an unacceptable value is specified for an enumerated argument.\n";
             break;
-        case GL_INVALID_VALUE: 
+        case GL_INVALID_VALUE:
             std::cout << message << ": a numeric argument is out of range.\n";
             break;
-        case GL_INVALID_OPERATION: 
+        case GL_INVALID_OPERATION:
             std::cout << message << ": the specified operation is not allowed in the current state.\n";
             break;
-        case GL_INVALID_FRAMEBUFFER_OPERATION: 
+        case GL_INVALID_FRAMEBUFFER_OPERATION:
             std::cout << message << ": the framebuffer object is not complete.\n";
             break;
-        case GL_OUT_OF_MEMORY: 
+        case GL_OUT_OF_MEMORY:
             std::cout << message << ": there is not enough memory left to execute the command.\n";
             break;
-        case GL_STACK_UNDERFLOW: 
+        case GL_STACK_UNDERFLOW:
             std::cout << message << ": an attempt has been made to perform an operation that would cause an internal stack to underflow.\n";
             break;
-        case GL_STACK_OVERFLOW: 
+        case GL_STACK_OVERFLOW:
             std::cout << message << ": an attempt has been made to perform an operation that would cause an internal stack to overflow.\n";
             break;
         default:
@@ -38,17 +36,14 @@ bool checkAndPrintError(const char* message)
     return true;
 }
 
-float interpolate(float lag, float from, float to)
-{
+float interpolate(float lag, float from, float to) {
     return from + lag * (to - from);
 }
 
-void printMatrix(const float* data)
-{
+void printMatrix(const float* data) {
     std::cout << "MatrixData\n(\n";
     std::cout << std::fixed << std::setprecision(5);
-    for(int i = 0; i < 4; i++)
-    {
+    for(int i = 0; i < 4; i++) {
         std::cout << std::setw(15);
         std::cout << data[i] << ", ";
         std::cout << std::setw(15);

+ 16 - 31
client/input/Keys.cpp

@@ -2,33 +2,26 @@
 
 #include "client/input/Keys.h"
 
-bool Keys::Key::isDown() const
-{
+bool Keys::Key::isDown() const {
     return down;
 }
 
-bool Keys::Key::isReleased() const
-{
+bool Keys::Key::isReleased() const {
     return shouldRelease;
 }
 
-u32 Keys::Key::getDownTime() const
-{
+u32 Keys::Key::getDownTime() const {
     return downTime;
 }
 
-std::ostream& operator <<(std::ostream& os, const Keys::Key& k)
-{
-    os << "Key(down: " << k.isDown() << ", release: " << k.isReleased() << 
-            ", time: " << k.getDownTime() << ")"; 
+std::ostream& operator<<(std::ostream& os, const Keys::Key& k) {
+    os << "Key(down: " << k.isDown() << ", release: " << k.isReleased() <<
+            ", time: " << k.getDownTime() << ")";
     return os;
 }
 
-Keys::Keys() : left(keys[0]), right(keys[1]), up(keys[2]), down(keys[3]), 
-        jump(keys[4]), sneak(keys[5]),
-        camLeft(keys[6]), camRight(keys[7]), camUp(keys[8]), camDown(keys[9]), 
-        test(keys[10])
-{
+Keys::Keys() : left(keys[0]), right(keys[1]), up(keys[2]), down(keys[3]), jump(keys[4]), sneak(keys[5]),
+camLeft(keys[6]), camRight(keys[7]), camUp(keys[8]), camDown(keys[9]), test(keys[10]) {
     keys[0].glfwKey = GLFW_KEY_A;
     keys[1].glfwKey = GLFW_KEY_D;
     keys[2].glfwKey = GLFW_KEY_W;
@@ -42,33 +35,25 @@ Keys::Keys() : left(keys[0]), right(keys[1]), up(keys[2]), down(keys[3]),
     keys[10].glfwKey = GLFW_KEY_T;
 }
 
-void Keys::release(int key)
-{
-    for(Key& k : keys)
-    {
-        if(k.glfwKey == key)
-        {
+void Keys::release(int key) {
+    for(Key& k : keys) {
+        if(k.glfwKey == key) {
             k.shouldRelease = true;
         }
     }
 }
 
-void Keys::press(int key)
-{
-    for(Key& k : keys)
-    {
-        if(k.glfwKey == key)
-        {
+void Keys::press(int key) {
+    for(Key& k : keys) {
+        if(k.glfwKey == key) {
             k.down = true;
             k.shouldRelease = false;
         }
     }
 }
 
-void Keys::tick()
-{
-    for(Key& k : keys)
-    {
+void Keys::tick() {
+    for(Key& k : keys) {
         k.downTime += k.down;
         k.down = k.down && !k.shouldRelease;
         k.downTime *= !k.shouldRelease;

+ 11 - 12
client/input/Keys.h

@@ -6,34 +6,33 @@
 
 #include "common/utils/Types.h"
 
-class Keys final
-{
+class Keys final {
 public:
-    class Key final
-    {
+
+    class Key final {
     public:
         friend class Keys;
 
         bool isDown() const;
         bool isReleased() const;
         u32 getDownTime() const;
-      
+
     private:
         Key() = default;
         Key(const Key&) = delete;
         Key(Key&&) = delete;
         Key& operator=(const Key&) = delete;
         Key& operator=(Key&&) = delete;
-    
+
         int glfwKey;
         bool down;
         bool shouldRelease;
         u32 downTime;
     };
-    
+
 private:
-   Key keys[11];
-    
+    Key keys[11];
+
 public:
     Keys();
     const Key& left;
@@ -47,12 +46,12 @@ public:
     const Key& camUp;
     const Key& camDown;
     const Key& test;
-    
+
     void release(int key);
     void press(int key);
     void tick();
-    
-private:   
+
+private:
     Keys(const Keys&) = delete;
     Keys& operator=(const Keys&) = delete;
     Keys(Key&&) = delete;

+ 22 - 42
client/input/MouseButtons.cpp

@@ -2,89 +2,70 @@
 
 #include "client/input/MouseButtons.h"
 
-bool MouseButtons::MouseButton::isDown() const
-{
+bool MouseButtons::MouseButton::isDown() const {
     return down;
 }
 
-bool MouseButtons::MouseButton::isReleased() const
-{
+bool MouseButtons::MouseButton::isReleased() const {
     return shouldRelease;
 }
 
-u32 MouseButtons::MouseButton::getDownTime() const
-{
+u32 MouseButtons::MouseButton::getDownTime() const {
     return downTime;
 }
 
-std::ostream& operator <<(std::ostream& os, const MouseButtons::MouseButton& m)
-{
-    os << "Mouse(down: " << m.isDown() << ", release: " << m.isReleased() << 
-            ", time: " << m.getDownTime() << ")"; 
+std::ostream& operator<<(std::ostream& os, const MouseButtons::MouseButton& m) {
+    os << "Mouse(down: " << m.isDown() << ", release: " << m.isReleased() <<
+            ", time: " << m.getDownTime() << ")";
     return os;
 }
 
-MouseButtons::MouseButtons() : primary(buttons[0]), secondary(buttons[1]), 
-        middle(buttons[2]), oldX(0), oldY(0), x(0), y(0)
-{
-    buttons[0].glfwButton= GLFW_MOUSE_BUTTON_1;
+MouseButtons::MouseButtons() : primary(buttons[0]), secondary(buttons[1]), middle(buttons[2]), oldX(0), oldY(0), x(0), y(0) {
+    buttons[0].glfwButton = GLFW_MOUSE_BUTTON_1;
     buttons[1].glfwButton = GLFW_MOUSE_BUTTON_2;
     buttons[2].glfwButton = GLFW_MOUSE_BUTTON_3;
 }
 
-double MouseButtons::getOldX() const
-{
+double MouseButtons::getOldX() const {
     return oldX;
 }
 
-double MouseButtons::getOldY() const
-{
+double MouseButtons::getOldY() const {
     return oldY;
 }
 
-double MouseButtons::getX() const
-{
+double MouseButtons::getX() const {
     return x;
 }
 
-double MouseButtons::getY() const
-{
+double MouseButtons::getY() const {
     return y;
 }
 
-void MouseButtons::release(int button)
-{
-    for(MouseButton& k : buttons)
-    {
-        if(k.glfwButton == button)
-        {
+void MouseButtons::release(int button) {
+    for(MouseButton& k : buttons) {
+        if(k.glfwButton == button) {
             k.shouldRelease = true;
         }
     }
 }
 
-void MouseButtons::press(int button)
-{
-    for(MouseButton& k : buttons)
-    {
-        if(k.glfwButton == button)
-        {
+void MouseButtons::press(int button) {
+    for(MouseButton& k : buttons) {
+        if(k.glfwButton == button) {
             k.down = true;
             k.shouldRelease = false;
         }
     }
 }
 
-void MouseButtons::move(double x, double y)
-{
+void MouseButtons::move(double x, double y) {
     MouseButtons::x = x;
     MouseButtons::y = y;
 }
 
-void MouseButtons::tick()
-{
-    for(MouseButton& k : buttons)
-    {
+void MouseButtons::tick() {
+    for(MouseButton& k : buttons) {
         k.downTime += k.down;
         k.down = k.down && !k.shouldRelease;
         k.downTime *= !k.shouldRelease;
@@ -92,8 +73,7 @@ void MouseButtons::tick()
     }
 }
 
-void MouseButtons::postTick()
-{
+void MouseButtons::postTick() {
     oldX = x;
     oldY = y;
 }

+ 14 - 15
client/input/MouseButtons.h

@@ -6,58 +6,57 @@
 
 #include "common/utils/Types.h"
 
-class MouseButtons final
-{
+class MouseButtons final {
 public:
-    class MouseButton final
-    {
+
+    class MouseButton final {
     public:
         friend class MouseButtons;
 
         bool isDown() const;
         bool isReleased() const;
         u32 getDownTime() const;
-      
+
     private:
         MouseButton() = default;
         MouseButton(const MouseButton&) = delete;
         MouseButton(MouseButton&&) = delete;
         MouseButton& operator=(const MouseButton&) = delete;
         MouseButton& operator=(MouseButton&&) = delete;
-    
+
         int glfwButton;
         bool down;
         bool shouldRelease;
         u32 downTime;
     };
-    
+
 private:
-   MouseButton buttons[3];
-    
+    MouseButton buttons[3];
+
 public:
     MouseButtons();
-    
+
     double getOldX() const;
     double getOldY() const;
     double getX() const;
     double getY() const;
-    
+
     const MouseButton& primary;
     const MouseButton& secondary;
     const MouseButton& middle;
-    
+
     void release(int button);
     void press(int button);
     void move(double x, double y);
     void tick();
     void postTick();
-    
-private:   
+
+private:
     MouseButtons(const MouseButtons&) = delete;
     MouseButtons& operator=(const MouseButtons&) = delete;
     MouseButtons(MouseButtons&&) = delete;
     MouseButtons& operator=(MouseButtons&&) = delete;
-    
+
     double oldX;
     double oldY;
     double x;

+ 18 - 36
client/math/Camera.cpp

@@ -1,92 +1,74 @@
 #include "client/math/Camera.h"
 #include "client/Utils.h"
 
-Camera::Camera() : oldLengthAngle(0), lengthAngle(0), oldWidthAngle(0), widthAngle(0)
-{
-
+Camera::Camera() : oldLengthAngle(0), lengthAngle(0), oldWidthAngle(0), widthAngle(0) {
 }
 
-const Vector& Camera::getFront() const
-{
+const Vector& Camera::getFront() const {
     return front;
 }
 
-const Vector& Camera::getBack() const
-{
+const Vector& Camera::getBack() const {
     return back;
 }
 
-const Vector& Camera::getRight() const
-{
+const Vector& Camera::getRight() const {
     return right;
 }
 
-const Vector& Camera::getLeft() const
-{
+const Vector& Camera::getLeft() const {
     return left;
 }
 
-const Vector& Camera::getUp() const
-{
+const Vector& Camera::getUp() const {
     return up;
 }
 
-const Vector& Camera::getDown() const
-{
+const Vector& Camera::getDown() const {
     return down;
 }
 
-const Vector& Camera::getFlatFront() const
-{
+const Vector& Camera::getFlatFront() const {
     return flatFront;
 }
 
-const Vector& Camera::getFlatBack() const
-{
+const Vector& Camera::getFlatBack() const {
     return flatBack;
 }
 
-const Vector& Camera::getFlatRight() const
-{
+const Vector& Camera::getFlatRight() const {
     return flatRight;
 }
 
-const Vector& Camera::getFlatLeft() const
-{
+const Vector& Camera::getFlatLeft() const {
     return flatLeft;
 }
 
-const Vector& Camera::getFlatUp() const
-{
+const Vector& Camera::getFlatUp() const {
     return flatUp;
 }
 
-const Vector& Camera::getFlatDown() const
-{
+const Vector& Camera::getFlatDown() const {
     return flatDown;
 }
 
-const Vector& Camera::getPosition() const
-{
+const Vector& Camera::getPosition() const {
     return interPosition;
 }
 
-void Camera::storePosition()
-{
+void Camera::storePosition() {
     oldPosition = position;
     oldLengthAngle = lengthAngle;
     oldWidthAngle = widthAngle;
 }
 
-void Camera::setPosition(const Vector& pos, float length, float width)
-{
+void Camera::setPosition(const Vector& pos, float length, float width) {
     position = pos;
     lengthAngle = length;
     widthAngle = width;
 }
 
-void Camera::update(float lag)
-{
+void Camera::update(float lag) {
     // back
     back.setAngles(interpolate(lag, oldLengthAngle, lengthAngle), interpolate(lag, oldWidthAngle, widthAngle));
     // front
@@ -107,7 +89,7 @@ void Camera::update(float lag)
     interPosition = oldPosition;
     interPosition.addMul(position, lag);
     interPosition.addMul(oldPosition, -lag);
-    
+
     // flat back
     flatBack = back;
     flatBack.setY(0.0f);

+ 11 - 12
client/math/Camera.h

@@ -3,31 +3,30 @@
 
 #include "client/math/Vector.h"
 
-class Camera final
-{
+class Camera final {
 public:
     Camera();
-    
+
     const Vector& getFront() const;
     const Vector& getBack() const;
     const Vector& getRight() const;
     const Vector& getLeft() const;
     const Vector& getUp() const;
     const Vector& getDown() const;
-    
+
     const Vector& getFlatFront() const;
     const Vector& getFlatBack() const;
     const Vector& getFlatRight() const;
     const Vector& getFlatLeft() const;
     const Vector& getFlatUp() const;
     const Vector& getFlatDown() const;
-    
+
     const Vector& getPosition() const;
     void storePosition();
     void setPosition(const Vector& pos, float length, float width);
-    
+
     void update(float lag);
-    
+
 private:
     Vector oldPosition;
     Vector position;
@@ -35,22 +34,22 @@ private:
     float lengthAngle;
     float oldWidthAngle;
     float widthAngle;
-    
+
     Vector interPosition;
-    
+
     Vector front;
     Vector back;
     Vector right;
     Vector left;
     Vector up;
-    Vector down;  
-    
+    Vector down;
+
     Vector flatFront;
     Vector flatBack;
     Vector flatRight;
     Vector flatLeft;
     Vector flatUp;
-    Vector flatDown; 
+    Vector flatDown;
 };
 
 #endif

+ 23 - 39
client/math/Matrix.cpp

@@ -4,13 +4,11 @@
 
 #include "client/math/Matrix.h"
 
-Matrix::Matrix()
-{
+Matrix::Matrix() {
     setToIdentity();
 }
 
-void Matrix::setToIdentity()
-{
+void Matrix::setToIdentity() {
     data[0] = 1.0f;
     data[1] = 0.0f;
     data[2] = 0.0f;
@@ -29,18 +27,15 @@ void Matrix::setToIdentity()
     data[15] = 1.0f;
 }
 
-void Matrix::set(unsigned int index, float f)
-{
+void Matrix::set(unsigned int index, float f) {
     data[index] = f;
 }
 
-const float* Matrix::getValues() const
-{
+const float* Matrix::getValues() const {
     return data;
 }
 
-void Matrix::mul(const Matrix& m)
-{
+void 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];
@@ -58,11 +53,10 @@ void Matrix::mul(const Matrix& m)
     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);
+    std::memcpy(data, mNew, sizeof (float) * 16);
 }
 
-void Matrix::scale(float sx, float sy, float sz)
-{
+void Matrix::scale(float sx, float sy, float sz) {
     data[0] *= sx;
     data[1] *= sx;
     data[2] *= sx;
@@ -77,40 +71,35 @@ void Matrix::scale(float sx, float sy, float sz)
     data[11] *= sz;
 }
 
-void Matrix::translate(float tx, float ty, float tz) 
-{
+void Matrix::translate(float tx, float ty, float tz) {
     data[12] += data[0] * tx + data[4] * ty + data[8] * tz;
     data[13] += data[1] * tx + data[5] * ty + data[9] * tz;
     data[14] += data[2] * tx + data[6] * ty + data[10] * tz;
     data[15] += data[3] * tx + data[7] * ty + data[11] * tz;
 }
 
-void Matrix::translateX(float tx) 
-{
+void Matrix::translateX(float tx) {
     data[12] += data[0] * tx;
     data[13] += data[1] * tx;
     data[14] += data[2] * tx;
     data[15] += data[3] * tx;
 }
 
-void Matrix::translateY(float ty) 
-{
+void Matrix::translateY(float ty) {
     data[12] += data[4] * ty;
     data[13] += data[5] * ty;
     data[14] += data[6] * ty;
     data[15] += data[7] * ty;
 }
 
-void Matrix::translateZ(float tz) 
-{
+void Matrix::translateZ(float tz) {
     data[12] += data[8] * tz;
     data[13] += data[9] * tz;
     data[14] += data[10] * tz;
     data[15] += data[11] * tz;
 }
 
-void Matrix::translateTo(float tx, float ty, float tz) 
-{
+void Matrix::translateTo(float tx, float ty, float tz) {
     data[0] = 1.0f;
     data[1] = 0.0f;
     data[2] = 0.0f;
@@ -129,12 +118,11 @@ void Matrix::translateTo(float tx, float ty, float tz)
     data[15] = 1.0f;
 }
 
-void Matrix::rotateX(float degrees) 
-{
+void Matrix::rotateX(float degrees) {
     degrees *= M_PI / 180.0f;
     float sin = sinf(degrees);
-    float cos =  cosf(degrees);
-    
+    float cos = cosf(degrees);
+
     float a = data[4];
     float b = data[8];
     data[4] = a * cos + b * sin;
@@ -156,12 +144,11 @@ void Matrix::rotateX(float degrees)
     data[11] = a * -sin + b * cos;
 }
 
-void Matrix::rotateY(float degrees) 
-{
+void Matrix::rotateY(float degrees) {
     degrees *= M_PI / 180.0f;
     float sin = sinf(degrees);
-    float cos =  cosf(degrees);
-    
+    float cos = cosf(degrees);
+
     float a = data[0];
     float b = data[8];
     data[0] = a * cos + b * -sin;
@@ -183,12 +170,11 @@ void Matrix::rotateY(float degrees)
     data[11] = a * sin + b * cos;
 }
 
-void Matrix::rotateZ(float degrees) 
-{
+void Matrix::rotateZ(float degrees) {
     degrees *= M_PI / 180.0f;
     float sin = sinf(degrees);
-    float cos =  cosf(degrees);
-    
+    float cos = cosf(degrees);
+
     float a = data[0];
     float b = data[4];
     data[0] = a * cos + b * sin;
@@ -210,13 +196,11 @@ void Matrix::rotateZ(float degrees)
     data[7] = a * -sin + b * cos;
 }
 
-std::ostream& operator<<(std::ostream& os, const Matrix& m)
-{
+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++)
-    {
+    for(int i = 0; i < 4; i++) {
         os << std::setw(15);
         os << data[i] << ", ";
         os << std::setw(15);

+ 8 - 9
client/math/Matrix.h

@@ -3,30 +3,29 @@
 
 #include <iostream>
 
-class Matrix final
-{
+class Matrix final {
 public:
     Matrix();
-    
+
     void setToIdentity();
     void set(unsigned int index, float f);
-    
+
     const float* getValues() const;
-    
+
     void mul(const Matrix& m);
-    
+
     void scale(float sx, float sy, float sz);
-    
+
     void translate(float tx, float ty, float tz);
     void translateX(float tx);
     void translateY(float ty);
     void translateZ(float tz);
     void translateTo(float tx, float ty, float tz);
-    
+
     void rotateX(float degrees);
     void rotateY(float degrees);
     void rotateZ(float degrees);
-    
+
 private:
     float data[16];
 };

+ 4 - 8
client/math/MatrixStack.cpp

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

+ 2 - 3
client/math/MatrixStack.h

@@ -5,14 +5,13 @@
 
 #include "client/math/Matrix.h"
 
-class MatrixStack final
-{
+class MatrixStack final {
 public:
     void pop();
     void push();
     Matrix& get();
     void clear();
-    
+
 private:
     std::array<Matrix, 10> stack;
     size_t index = 0;

+ 4 - 7
client/math/Plane.cpp

@@ -1,25 +1,22 @@
 #include "client/math/Plane.h"
 
-Plane::Plane() : a(0), b(0), c(0), d(0)
-{
+Plane::Plane() : a(0), b(0), c(0), d(0) {
 }
 
-void Plane::set(const Vector& va, const Vector& vb, const Vector& vc)
-{
+void Plane::set(const Vector& va, const Vector& vb, const Vector& vc) {
     Vector h1 = vb;
     h1.sub(va);
     Vector h2 = vc;
     h2.sub(va);
     h1.cross(h2);
     h1.normalize();
-    
+
     a = h1.getX();
     b = h1.getY();
     c = h1.getZ();
     d = -h1.dot(va);
 }
 
-float Plane::getSignedDistance(float x, float y, float z) const
-{
+float Plane::getSignedDistance(float x, float y, float z) const {
     return x * a + y * b + z * c + d;
 }

+ 3 - 4
client/math/Plane.h

@@ -3,14 +3,13 @@
 
 #include "client/math/Vector.h"
 
-class Plane final
-{
+class Plane final {
 public:
     Plane();
-    
+
     void set(const Vector& va, const Vector& vb, const Vector& vc);
     float getSignedDistance(float x, float y, float z) const;
-    
+
 private:
     float a;
     float b;

+ 25 - 51
client/math/Vector.cpp

@@ -2,98 +2,81 @@
 
 #include "client/math/Vector.h"
 
-Vector::Vector() : x(0), y(0), z(0)
-{
+Vector::Vector() : x(0), y(0), z(0) {
 }
 
-Vector::Vector(float ix, float iy, float iz) : x(ix), y(iy), z(iz)
-{
+Vector::Vector(float ix, float iy, float iz) : x(ix), y(iy), z(iz) {
 }
 
-float Vector::getX() const
-{
+float Vector::getX() const {
     return x;
 }
 
-float Vector::getY() const
-{
+float Vector::getY() const {
     return y;
 }
 
-float Vector::getZ() const
-{
+float Vector::getZ() const {
     return z;
 }
 
-void Vector::setX(float ix)
-{
+void Vector::setX(float ix) {
     x = ix;
 }
 
-void Vector::setY(float iy)
-{
+void Vector::setY(float iy) {
     y = iy;
 }
 
-void Vector::setZ(float iz)
-{
+void Vector::setZ(float iz) {
     z = iz;
 }
 
-void Vector::set(float ix, float iy, float iz)
-{
+void Vector::set(float ix, float iy, float iz) {
     x = ix;
     y = iy;
     z = iz;
 }
 
-void Vector::setInverse(const Vector& v)
-{
+void Vector::setInverse(const Vector& v) {
     x = -v.x;
     y = -v.y;
     z = -v.z;
 }
 
-void Vector::setMul(const Vector& v, float f)
-{
+void Vector::setMul(const Vector& v, float f) {
     x = v.x * f;
     y = v.y * f;
     z = v.z * f;
 }
 
-void Vector::setAngles(float lengthAngle, float widthAngle)
-{
+void Vector::setAngles(float lengthAngle, float widthAngle) {
     lengthAngle = lengthAngle * M_PI / 180.0f;
     widthAngle = widthAngle * M_PI / 180.0f;
     x = cosf(widthAngle) * sinf(lengthAngle);
     y = sinf(widthAngle);
-    z = cosf(widthAngle) * cosf(lengthAngle); 
+    z = cosf(widthAngle) * cosf(lengthAngle);
 }
 
-
-void Vector::add(const Vector& v)
-{
+void Vector::add(const Vector& v) {
     x += v.x;
     y += v.y;
     z += v.z;
 }
 
-void Vector::sub(const Vector& v)
-{
+void Vector::sub(const Vector& v) {
     x -= v.x;
     y -= v.y;
     z -= v.z;
 }
 
-void Vector::mul(float f)
-{
+void Vector::mul(float f) {
     x *= f;
     y *= f;
     z *= f;
 }
 
-void Vector::mul(const Matrix& m)
-{
+void Vector::mul(const Matrix& m) {
     const float* d = m.getValues();
     const float w = 1.0f;
     float nx = x * d[0] + y * d[4] + z * d[8] + w * d[12];
@@ -103,48 +86,39 @@ void Vector::mul(const Matrix& m)
     set(nx / nw, ny / nw, nz / nw);
 }
 
-void Vector::addMul(const Vector& v, float f)
-{
+void Vector::addMul(const Vector& v, float f) {
     x += v.x * f;
     y += v.y * f;
     z += v.z * f;
 }
 
-
-void Vector::cross(float ix, float iy, float iz)
-{
+void Vector::cross(float ix, float iy, float iz) {
     set(y * iz - z * iy, z * ix - x * iz, x * iy - y * ix);
 }
 
-void Vector::cross(const Vector& v)
-{
+void Vector::cross(const Vector& v) {
     set(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x);
 }
 
-void Vector::normalize()
-{
+void Vector::normalize() {
     float f = 1.0f / sqrtf(squareLength());
     x *= f;
     y *= f;
     z *= f;
 }
 
-float Vector::squareLength() const
-{
+float Vector::squareLength() const {
     return x * x + y * y + z * z;
 }
 
-float Vector::dot(const Vector& v) const
-{
+float Vector::dot(const Vector& v) const {
     return x * v.x + y * v.y + z * v.z;
 }
 
-float Vector::dotInverse(const Vector& v) const
-{
+float Vector::dotInverse(const Vector& v) const {
     return x * (-v.x) + y * (-v.y) + z * (-v.z);
 }
 
-std::ostream& operator<<(std::ostream& os, const Vector& v)
-{
+std::ostream& operator<<(std::ostream& os, const Vector& v) {
     return os << "Vector(x = " << v.getX() << ", y = " << v.getY() << ", z = " << v.getZ() << ")";
 }

+ 9 - 10
client/math/Vector.h

@@ -5,40 +5,39 @@
 
 #include "client/math/Matrix.h"
 
-class Vector final
-{
+class Vector final {
 public:
     Vector();
     Vector(float ix, float iy, float iz);
-    
+
     float getX() const;
     float getY() const;
     float getZ() const;
-    
+
     void setX(float ix);
     void setY(float iy);
     void setZ(float iz);
-    
+
     void set(float ix, float iy, float iz);
     void setInverse(const Vector& v);
     void setMul(const Vector& v, float f);
     void setAngles(float lengthAngle, float widthAngle);
-    
+
     void add(const Vector& v);
     void sub(const Vector& v);
     void mul(float f);
     void mul(const Matrix& m);
     void addMul(const Vector& v, float f);
-    
+
     void cross(float ix, float iy, float iz);
     void cross(const Vector& v);
-    
+
     void normalize();
     float squareLength() const;
-    
+
     float dot(const Vector& v) const;
     float dotInverse(const Vector& v) const;
-    
+
 private:
     float x;
     float y;

+ 18 - 34
client/network/Client.cpp

@@ -9,37 +9,30 @@
 #include "client/network/Client.h"
 #include "common/stream/Stream.h"
 
-Client::Client()
-{
+Client::Client() {
 }
 
-Client::~Client()
-{
-    if(connectionSocket != -1)
-    {
+Client::~Client() {
+    if(connectionSocket != -1) {
         close(connectionSocket);
     }
 }
 
-bool Client::start(const string& ip, unsigned short port, IClientListener* listener)
-{
+bool Client::start(const string& ip, unsigned short port, IClientListener* listener) {
     connectionSocket = socket(AF_INET, SOCK_STREAM, 0);
-    if(connectionSocket == -1)
-    {
+    if(connectionSocket == -1) {
         throw runtime_error(string("cannot create socket: ") + strerror(errno));
     }
 
     struct sockaddr_in socketData;
-    memset(&socketData, 0, sizeof(struct sockaddr_in));
+    memset(&socketData, 0, sizeof (struct sockaddr_in));
     socketData.sin_family = AF_INET;
     socketData.sin_port = htons(port);
-    if(inet_aton(ip.data(), &socketData.sin_addr) == 0)
-    {
+    if(inet_aton(ip.data(), &socketData.sin_addr) == 0) {
         throw runtime_error(ip + " is not a valid ip");
     }
 
-    if(connect(connectionSocket, (struct sockaddr*) &socketData, sizeof(struct sockaddr_in)) == 0)
-    {
+    if(connect(connectionSocket, (struct sockaddr*) &socketData, sizeof (struct sockaddr_in)) == 0) {
         clientListener = listener;
         shouldRun = true;
         serverListenThread = thread(&Client::listenOnServer, this);
@@ -48,42 +41,33 @@ bool Client::start(const string& ip, unsigned short port, IClientListener* liste
     return false;
 }
 
-void Client::stop()
-{
+void Client::stop() {
     shouldRun = false;
     serverListenThread.join();
 }
 
-void Client::listenOnServer()
-{
+void Client::listenOnServer() {
     struct pollfd fds;
     fds.fd = connectionSocket;
     fds.events = POLLIN;
     fds.revents = 0;
-    
+
     clientListener->onServerJoin(connectionSocket);
-    
+
     Stream st;
-    
-    while(shouldRun)
-    {
+
+    while(shouldRun) {
         int pollData = poll(&fds, 1, 100);
-        if(pollData > 0)
-        {
+        if(pollData > 0) {
             st.readSocket(connectionSocket);
-            if(st.hasData())
-            {
+            if(st.hasData()) {
                 clientListener->onServerPackage(connectionSocket, st);
-            }
-            else
-            {
+            } else {
                 // server closed connection
                 clientListener->onServerClose(connectionSocket);
                 break;
             }
-        }
-        else if(pollData == -1)
-        {
+        } else if(pollData == -1) {
             cout << "poll error: " << strerror(errno) << endl;
         }
     }

+ 6 - 7
client/network/Client.h

@@ -8,23 +8,22 @@
 
 using namespace std;
 
-class Client
-{
+class Client {
 public:
     Client();
     virtual ~Client();
-    
+
     bool start(const string& ip, unsigned short port, IClientListener* listener);
     void stop();
-    
+
 private:
     void listenOnServer();
-    
+
     int connectionSocket = -1;
     volatile bool shouldRun = false;
-    
+
     thread serverListenThread;
-    
+
     IClientListener* clientListener;
 };
 

+ 4 - 9
client/network/ClientListener.cpp

@@ -1,15 +1,10 @@
 #include "client/network/ClientListener.h"
 
-void ClientListener::onServerJoin(int serverSocket)
-{
+void ClientListener::onServerJoin(int serverSocket) {
 }
 
-void ClientListener::onServerPackage(int serverSocket, Stream& in)
-{
+void ClientListener::onServerPackage(int serverSocket, Stream& in) {
 }
 
-void ClientListener::onServerClose(int socket)
-{
-}
-
-
+void ClientListener::onServerClose(int socket) {
+}

+ 2 - 4
client/network/ClientListener.h

@@ -3,13 +3,11 @@
 
 #include "client/network/IClientListener.h"
 
-class ClientListener : public IClientListener
-{
+class ClientListener : public IClientListener {
 public:
     void onServerJoin(int serverSocket) override;
     void onServerPackage(int serverSocket, Stream& in) override;
     void onServerClose(int socket) override;
 };
 
-#endif
-
+#endif

+ 2 - 4
client/network/IClientListener.h

@@ -3,8 +3,7 @@
 
 #include "common/stream/Stream.h"
 
-class IClientListener
-{
+class IClientListener {
 public:
     virtual ~IClientListener() = default;
     virtual void onServerJoin(int serverSocket) = 0;
@@ -12,5 +11,4 @@ public:
     virtual void onServerClose(int socket) = 0;
 };
 
-#endif
-
+#endif

+ 4 - 7
common/block/Block.cpp

@@ -1,15 +1,12 @@
 #include "common/block/Block.h"
 
-Block::Block(u16 id, const std::string& registry) : id(id), registry(registry)
-{
+Block::Block(u16 id, const std::string& registry) : id(id), registry(registry) {
 }
 
-u16 Block::getId() const
-{
+u16 Block::getId() const {
     return id;
 }
 
-const std::string& Block::getRegistry() const
-{
+const std::string& Block::getRegistry() const {
     return registry;
-}
+}

+ 2 - 4
common/block/Block.h

@@ -5,8 +5,7 @@
 
 #include "common/utils/Types.h"
 
-class Block
-{
+class Block {
 public:
     Block(u16 id, const std::string& registry);
     u16 getId() const;
@@ -17,5 +16,4 @@ private:
     const std::string registry;
 };
 
-#endif
-
+#endif

+ 9 - 18
common/block/BlockRegistry.cpp

@@ -9,21 +9,17 @@ static Block NULL_BLOCK(0, "null_block");
 static std::unordered_map<std::string, u16> registry;
 static std::vector<Block> idMap = {NULL_BLOCK};
 
-void BlockRegistry::loadFromFile(const std::string& path)
-{
+void BlockRegistry::loadFromFile(const std::string& path) {
     std::ifstream in;
     in.open(path);
-    if(in.fail())
-    {
+    if(in.fail()) {
         std::cout << "cannot read blocks from file '" << path << "'" << std::endl;
         return;
     }
     std::string line;
-    while(true)
-    {
+    while(true) {
         std::getline(in, line, '\n');
-        if(in.fail())
-        {
+        if(in.fail()) {
             break;
         }
         u16 id = idMap.size();
@@ -32,22 +28,17 @@ void BlockRegistry::loadFromFile(const std::string& path)
     }
 }
 
-const Block& BlockRegistry::getBlock(const std::string& name)
-{
+const Block& BlockRegistry::getBlock(const std::string& name) {
     const std::unordered_map<std::string, u16>::const_iterator& iter = registry.find(name);
-    if(iter == registry.end())
-    {
+    if(iter == registry.end()) {
         return NULL_BLOCK;
     }
     return idMap[iter->second];
 }
 
-const Block& BlockRegistry::getBlock(u16 id)
-{
-    if(id >= idMap.size())
-    {
+const Block& BlockRegistry::getBlock(u16 id) {
+    if(id >= idMap.size()) {
         return NULL_BLOCK;
     }
     return idMap[id];
-}
-
+}

+ 1 - 2
common/block/BlockRegistry.h

@@ -4,8 +4,7 @@
 #include "common/utils/Types.h"
 #include "common/block/Block.h"
 
-namespace BlockRegistry
-{
+namespace BlockRegistry {
     void loadFromFile(const std::string& path);
     const Block& getBlock(const std::string& registry);
     const Block& getBlock(u16 id);

+ 26 - 48
common/stream/Stream.cpp

@@ -3,105 +3,83 @@
 
 #include "common/stream/Stream.h"
 
-Stream::Stream() : error(false), writeIndex(0), readIndex(0)
-{
+Stream::Stream() : error(false), writeIndex(0), readIndex(0) {
 }
 
-Stream::Stream(size_t capacity) : data(capacity), error(false), writeIndex(0), readIndex(0)
-{
+Stream::Stream(size_t capacity) : data(capacity), error(false), writeIndex(0), readIndex(0) {
 }
 
-bool Stream::hasData() const
-{
+bool Stream::hasData() const {
     return readIndex < writeIndex;
 }
 
-bool Stream::hasError() const
-{
+bool Stream::hasError() const {
     return error;
 }
 
-void Stream::clearError()
-{
+void Stream::clearError() {
     error = false;
 }
 
-void Stream::write(const void* writeData, size_t length)
-{
-    if(data.write(writeIndex, writeData, length))
-    {
+void Stream::write(const void* writeData, size_t length) {
+    if(data.write(writeIndex, writeData, length)) {
         writeIndex += length;
-    }
-    else
-    {
+    } else {
         error = true;
     }
 }
 
-void Stream::write(const char* writeData)
-{
+void Stream::write(const char* writeData) {
     write(writeData, strlen(writeData));
 }
 
-void Stream::writeUnsignedChar(u8 uc)
-{
-    write(&uc, sizeof(u8));
+void Stream::writeUnsignedChar(u8 uc) {
+    write(&uc, sizeof (u8));
 }
 
-void Stream::writeUnsignedShort(u16 us)
-{
+void Stream::writeUnsignedShort(u16 us) {
     us = htons(us);
-    write(&us, sizeof(u16));
+    write(&us, sizeof (u16));
 }
 
-void Stream::writeUnsignedInt(u32 ui)
-{
+void Stream::writeUnsignedInt(u32 ui) {
     ui = htonl(ui);
-    write(&ui, sizeof(u32));
+    write(&ui, sizeof (u32));
 }
 
-void Stream::read(void* buffer, size_t length)
-{
-    if(readIndex + length <= writeIndex && data.read(readIndex, buffer, length))
-    {
+void Stream::read(void* buffer, size_t length) {
+    if(readIndex + length <= writeIndex && data.read(readIndex, buffer, length)) {
         readIndex += length;
-    }
-    else
-    {
+    } else {
         error = true;
     }
 }
 
-u8 Stream::readUnsignedChar()
-{
+u8 Stream::readUnsignedChar() {
     u8 uc;
-    read(&uc, sizeof(u8));
+    read(&uc, sizeof (u8));
     return uc;
 }
 
-u16 Stream::readUnsignedShort()
-{
+u16 Stream::readUnsignedShort() {
     u16 us;
-    read(&us, sizeof(u16));
+    read(&us, sizeof (u16));
     us = ntohs(us);
     return us;
 }
 
-u32 Stream::readUnsignedInt()
-{
+u32 Stream::readUnsignedInt() {
     u32 ui;
-    read(&ui, sizeof(u32));
+    read(&ui, sizeof (u32));
     ui = ntohl(ui);
     return ui;
 }
 
-bool Stream::readSocket(int socket)
-{
+bool Stream::readSocket(int socket) {
     readIndex = 0;
     return data.readSocket(socket, writeIndex);
 }
 
-void Stream::sendToSocket(int socket) const
-{
+void Stream::sendToSocket(int socket) const {
     data.sendToSocket(socket, writeIndex);
 }

+ 5 - 6
common/stream/Stream.h

@@ -4,30 +4,29 @@
 #include "common/utils/Types.h"
 #include "common/utils/DataVector.h"
 
-class Stream
-{
+class Stream {
 public:
     Stream();
     Stream(size_t capacity);
 
     bool readSocket(int socket);
     void sendToSocket(int socket) const;
-    
+
     bool hasData() const;
     bool hasError() const;
     void clearError();
-    
+
     void write(const void* writeData, size_t length);
     void write(const char* writeData);
     void writeUnsignedChar(u8 uc);
     void writeUnsignedShort(u16 us);
     void writeUnsignedInt(u32 ui);
-    
+
     void read(void* buffer, size_t length);
     u8 readUnsignedChar();
     u16 readUnsignedShort();
     u32 readUnsignedInt();
-    
+
 private:
     DataVector data;
     bool error;

+ 27 - 51
common/utils/DataVector.cpp

@@ -9,31 +9,25 @@
 
 #include "DataVector.h"
 
-DataVector::DataVector(size_t capacity) : capacity(capacity), data(new char[capacity])
-{
+DataVector::DataVector(size_t capacity) : capacity(capacity), data(new char[capacity]) {
     memset(data, 0, capacity);
 }
 
-DataVector::DataVector(const DataVector& orig) : capacity(orig.capacity), data(new char[capacity])
-{
+DataVector::DataVector(const DataVector& orig) : capacity(orig.capacity), data(new char[capacity]) {
     memcpy(data, orig.data, capacity);
 }
 
-DataVector::DataVector(DataVector&& other) : capacity(other.capacity), data(other.data)
-{
+DataVector::DataVector(DataVector&& other) : capacity(other.capacity), data(other.data) {
     other.capacity = 0;
     other.data = nullptr;
 }
 
-DataVector::~DataVector()
-{
+DataVector::~DataVector() {
     delete[] data;
 }
 
-DataVector& DataVector::operator=(const DataVector& other)
-{
-    if(this != &other)
-    {
+DataVector& DataVector::operator=(const DataVector& other) {
+    if(this != &other) {
         delete[] data;
         capacity = other.capacity;
         data = new char[capacity];
@@ -42,10 +36,8 @@ DataVector& DataVector::operator=(const DataVector& other)
     return *this;
 }
 
-DataVector& DataVector::operator=(DataVector&& other)
-{
-    if(this != &other)
-    {
+DataVector& DataVector::operator=(DataVector&& other) {
+    if(this != &other) {
         capacity = other.capacity;
         data = other.data;
         other.capacity = 0;
@@ -54,57 +46,47 @@ DataVector& DataVector::operator=(DataVector&& other)
     return *this;
 }
 
-bool DataVector::read(size_t fromIndex, void* buffer, size_t length) const
-{
-    if(fromIndex + length >= capacity)
-    {
+bool DataVector::read(size_t fromIndex, void* buffer, size_t length) const {
+    if(fromIndex + length >= capacity) {
         return false;
     }
     memcpy(buffer, data + fromIndex, length);
     return true;
 }
 
-bool DataVector::write(size_t toIndex, const void* writeData, size_t length)
-{
-    if(toIndex + length >= capacity)
-    {
+bool DataVector::write(size_t toIndex, const void* writeData, size_t length) {
+    if(toIndex + length >= capacity) {
         return false;
     }
     memcpy(data + toIndex, writeData, length);
     return true;
 }
 
-bool DataVector::readSocket(int socket, size_t& readBytes)
-{
+bool DataVector::readSocket(int socket, size_t& readBytes) {
     readBytes = 0;
-    
+
     uint32_t packetSize = 0;
     ssize_t readLength = recv(socket, &packetSize, 4, 0);
-    if(readLength != 4)
-    {
+    if(readLength != 4) {
         return false;
     }
     packetSize = ntohl(packetSize);
-    if(packetSize > capacity)
-    {
+    if(packetSize > capacity) {
         return false;
     }
-            
+
     size_t bytesLeft = packetSize;
-    
-    while(true)
-    {
+
+    while(true) {
         ssize_t readLength = recv(socket, data + readBytes, bytesLeft, MSG_DONTWAIT);
         if(readLength < 0) // an error occurred
         {
-            if(errno == EAGAIN || errno == EWOULDBLOCK)
-            {
+            if(errno == EAGAIN || errno == EWOULDBLOCK) {
                 struct pollfd fds;
                 fds.fd = socket;
                 fds.events = POLLIN;
                 fds.revents = 0;
-                if(poll(&fds, 1, 3000) <= 0)
-                {
+                if(poll(&fds, 1, 3000) <= 0) {
                     // client took to long to send the full packet
                     readBytes = 0;
                     return false;
@@ -114,13 +96,10 @@ bool DataVector::readSocket(int socket, size_t& readBytes)
             // a real error occurred
             perror("cannot receive data");
             return true;
-        }
-        else if(readLength == 0) // socket closed / shutdown
+        } else if(readLength == 0) // socket closed / shutdown
         {
             return true;
-        }
-        else
-        {
+        } else {
             readBytes += readLength;
             bytesLeft -= readLength;
             if(bytesLeft == 0) // packet fully read
@@ -131,16 +110,13 @@ bool DataVector::readSocket(int socket, size_t& readBytes)
     }
 }
 
-void DataVector::sendToSocket(int socket, size_t toIndex) const
-{
+void DataVector::sendToSocket(int socket, size_t toIndex) const {
     size_t bufferOffset = 0;
     size_t sendLength = toIndex;
-    
-    while(sendLength > 0)
-    {
+
+    while(sendLength > 0) {
         ssize_t writtenLength = send(socket, data + bufferOffset, sendLength, MSG_NOSIGNAL);
-        if(writtenLength == -1)
-        {
+        if(writtenLength == -1) {
             perror("cannot send data");
             return;
         }

+ 5 - 6
common/utils/DataVector.h

@@ -3,23 +3,22 @@
 
 #include <cstddef>
 
-class DataVector final
-{
+class DataVector final {
 public:
     DataVector(size_t capacity = 5 * 1024 * 1024);
     DataVector(const DataVector& orig);
     DataVector(DataVector&& other);
     ~DataVector();
-    
+
     DataVector& operator=(const DataVector& other);
     DataVector& operator=(DataVector&& other);
-    
+
     bool read(size_t fromIndex, void* buffer, size_t length) const;
     bool write(size_t toIndex, const void* data, size_t length);
-    
+
     bool readSocket(int socket, size_t& readBytes);
     void sendToSocket(int socket, size_t toIndex) const;
-    
+
 private:
     size_t capacity;
     char* data;

+ 19 - 31
common/utils/Face.cpp

@@ -1,13 +1,12 @@
 #include "common/utils/Face.h"
 
-Face Face::FACES[6] =
-{
-    {0,  0,  1,  0, "Up"},
-    {1,  1,  0,  0, "North"},
-    {2,  0,  0,  1, "East"},
-    {3,  0, -1,  0, "Down"},
-    {4, -1,  0,  0, "South"},
-    {5,  0,  0, -1, "West"}
+Face Face::FACES[6] = {
+    {0, 0, 1, 0, "Up"},
+    {1, 1, 0, 0, "North"},
+    {2, 0, 0, 1, "East"},
+    {3, 0, -1, 0, "Down"},
+    {4, -1, 0, 0, "South"},
+    {5, 0, 0, -1, "West"}
 };
 
 const Face& Face::UP = FACES[0];
@@ -19,56 +18,45 @@ const Face& Face::SOUTH = FACES[4];
 const Face& Face::EAST = FACES[2];
 const Face& Face::WEST = FACES[5];
 
-Face::Face(int index, int offsetX, int offsetY, int offsetZ, const char* name) : 
-    index(index), offsetX(offsetX), offsetY(offsetY), offsetZ(offsetZ), name(name)
-{
+Face::Face(int index, int offsetX, int offsetY, int offsetZ, const char* name) :
+index(index), offsetX(offsetX), offsetY(offsetY), offsetZ(offsetZ), name(name) {
 }
 
-int Face::getX() const
-{
+int Face::getX() const {
     return offsetX;
 }
 
-int Face::getY() const
-{
+int Face::getY() const {
     return offsetY;
 }
 
-int Face::getZ() const
-{
+int Face::getZ() const {
     return offsetZ;
 }
 
-Face& Face::getOpposite() const
-{
+Face& Face::getOpposite() const {
     return FACES[(index + 3) % 6];
 }
 
-const char* Face::getName() const
-{
+const char* Face::getName() const {
     return name;
 }
 
-void Face::forEach(const std::function<void(Face&)>& f)
-{
-    for(int i = 0; i < 6; i++)
-    {
+void Face::forEach(const std::function<void(Face&)>& f) {
+    for(int i = 0; i < 6; i++) {
         f(FACES[i]);
     }
 }
 
-bool operator==(const Face& l, const Face& r)
-{
+bool operator==(const Face& l, const Face& r) {
     return &l == &r;
 }
 
-bool operator!=(const Face& l, const Face& r)
-{
+bool operator!=(const Face& l, const Face& r) {
     return &l != &r;
 }
 
-std::ostream& operator<<(std::ostream& os, const Face& f)
-{
+std::ostream& operator<<(std::ostream& os, const Face& f) {
     os << f.getName();
     return os;
 }

+ 7 - 8
common/utils/Face.h

@@ -4,15 +4,14 @@
 #include <iostream>
 #include <functional>
 
-class Face
-{
+class Face {
 public:
     // force usage by reference in every situation
     Face(const Face& other) = delete;
     Face& operator=(const Face& other) = delete;
     Face(Face&& other) = delete;
     Face& operator=(Face&& other) = delete;
-    
+
     int getX() const;
     int getY() const;
     int getZ() const;
@@ -20,7 +19,7 @@ public:
     const char* getName() const;
 
     static void forEach(const std::function<void(Face&)>& f);
-    
+
     static const Face& UP;
     static const Face& DOWN;
     static const Face& NORTH;
@@ -30,15 +29,15 @@ public:
 
 private:
     Face(int index, int offsetX, int offsetY, int offsetZ, const char* name);
-    
+
     static Face FACES[6];
-    
+
     int index;
-    
+
     int offsetX;
     int offsetY;
     int offsetZ;
-    
+
     const char* name;
 };
 

+ 6 - 12
common/world/Chunk.cpp

@@ -1,26 +1,20 @@
 #include "common/world/Chunk.h"
 #include "common/block/BlockRegistry.h"
 
-Chunk::Chunk()
-{
-    for(u32 y = 0; y < HEIGHT; y++)
-    {
-        for(u32 x = 0; x < CHUNK_PARTION_SIZE; x++)
-        {
-            for(u32 z = 0; z < CHUNK_PARTION_SIZE; z++)
-            {
+Chunk::Chunk() {
+    for(u32 y = 0; y < HEIGHT; y++) {
+        for(u32 x = 0; x < CHUNK_PARTION_SIZE; x++) {
+            for(u32 z = 0; z < CHUNK_PARTION_SIZE; z++) {
                 blocks[y][x][z] = 0;
             }
         }
     }
 }
 
-const Block& Chunk::getBlock(u32 x, u32 y, u32 z) const
-{
+const Block& Chunk::getBlock(u32 x, u32 y, u32 z) const {
     return BlockRegistry::getBlock(blocks[y & BITMASK_HEIGHT][x & CHUNK_PARTION_SIZE][z & CHUNK_PARTION_SIZE]);
 }
 
-void Chunk::setBlock(u32 x, u32 y, u32 z, const Block& block)
-{
+void Chunk::setBlock(u32 x, u32 y, u32 z, const Block& block) {
     blocks[y & BITMASK_HEIGHT][x & CHUNK_PARTION_SIZE][z & CHUNK_PARTION_SIZE] = block.getId();
 }

+ 4 - 5
common/world/Chunk.h

@@ -4,8 +4,7 @@
 #include "common/block/Block.h"
 #include "common/utils/Types.h"
 
-class Chunk final
-{
+class Chunk final {
 public:
     Chunk();
 
@@ -13,15 +12,15 @@ public:
     const Block& getBlock(u32 x, u32 y, u32 z) const;
 
     static const u32 CHUNK_BIT_SIZE = 4;
-    
+
 private:
     static const u32 CHUNK_PARTION_SIZE = 1 << CHUNK_BIT_SIZE;
     static const u32 HEIGHT_PARTIONS = 16;
     static const u32 HEIGHT = CHUNK_PARTION_SIZE * HEIGHT_PARTIONS;
-    
+
     static const u32 BITMASK = CHUNK_PARTION_SIZE - 1;
     static const u32 BITMASK_HEIGHT = HEIGHT - 1;
-    
+
     u16 blocks[HEIGHT][CHUNK_PARTION_SIZE][CHUNK_PARTION_SIZE];
 };
 

+ 2 - 8
common/world/World.cpp

@@ -1,18 +1,12 @@
 #include "common/world/World.h"
 
-World::World()
-{
-}
-
-void World::setBlock(u32 x, u32 y, u32 z, const Block& block)
-{
+void World::setBlock(u32 x, u32 y, u32 z, const Block& block) {
     u32 cx = (x >> Chunk::CHUNK_BIT_SIZE) & BITMASK;
     u32 cz = (z >> Chunk::CHUNK_BIT_SIZE) & BITMASK;
     chunks[cx][cz].setBlock(x, y, z, block);
 }
 
-const Block& World::getBlock(u32 x, u32 y, u32 z) const
-{
+const Block& World::getBlock(u32 x, u32 y, u32 z) const {
     u32 cx = (x >> Chunk::CHUNK_BIT_SIZE) & BITMASK;
     u32 cz = (z >> Chunk::CHUNK_BIT_SIZE) & BITMASK;
     return chunks[cx][cz].getBlock(x, y, z);

+ 0 - 2
common/world/World.h

@@ -6,8 +6,6 @@
 class World final
 {
 public:
-    World();
-    
     void setBlock(u32 x, u32 y, u32 z, const Block& block);
     const Block& getBlock(u32 x, u32 y, u32 z) const;
     

+ 7 - 15
resources/shader/fragment.fs

@@ -16,25 +16,17 @@ in vec2 tc;
 in vec4 outColor;
 out vec4 color;
 
-void main(void)
-{
-    if(useTexture)
-    {
+void main(void) {
+    if(useTexture) {
         color = texture(samp, tc);
-        if(useColor)
-        {
-            if(useMixColor)
-            {
+        if(useColor) {
+            if(useMixColor) {
                 color = (color + mixColor) * 0.5;
-            }
-            else
-            {
+            } else {
                 color = vec4(outColor.xyz, color.w);
             }
         }
-    }
-    else
-    {
+    } else {
         color = outColor;
     }
-}
+}

+ 4 - 9
resources/shader/overlayFragment.fs

@@ -10,18 +10,13 @@ in vec2 varTextureCoord;
 
 out vec4 color;
 
-void main()
-{
-    if(useTexture)
-    {
+void main() {
+    if(useTexture) {
         color = texture(samp, varTextureCoord);
-        if(useColor)
-        {
+        if(useColor) {
             color = vec4(varColor.xyz, color.w);
         }
-    }
-    else
-    {
+    } else {
         color = varColor;
     }
 }  

+ 1 - 2
resources/shader/overlayVertex.vs

@@ -11,8 +11,7 @@ uniform mat4 modelMatrix;
 out vec2 varTextureCoord;
 out vec4 varColor;
 
-void main(void)
-{ 
+void main(void) { 
     varTextureCoord = textureCoord;
     varColor = color;
     gl_Position = viewMatrix * modelMatrix * vec4(position, 1.0);

+ 3 - 6
resources/shader/ssaoBlurFragment.fs

@@ -5,15 +5,12 @@ layout (binding = 0) uniform sampler2D ssaoSamp;
 in vec2 varTex;
 out float color;
 
-void main()
-{
+void main() {
     vec2 texelSize = 1.0 / vec2(textureSize(ssaoSamp, 0));
     float result = 0.0;
     const int radius = 2;
-    for(int x = -radius; x < radius; x++) 
-    {
-        for(int y = -radius; y < radius; y++) 
-        {
+    for(int x = -radius; x < radius; x++) {
+        for(int y = -radius; y < radius; y++) {
             vec2 offset = vec2(float(x), float(y)) * texelSize;
             result += texture(ssaoSamp, varTex + offset).r;
         }

+ 1 - 2
resources/shader/ssaoBlurVertex.vs

@@ -6,8 +6,7 @@ layout (location = 2) in vec3 normal;
 
 out vec2 varTex;
 
-void main(void)
-{ 
+void main(void) { 
     gl_Position = vec4(position, 1.0);
     varTex = tex;
 }

+ 4 - 7
resources/shader/ssaoFragment.fs

@@ -7,8 +7,7 @@ layout (binding = 3) uniform sampler2D worldDepthSamp;
 layout (binding = 4) uniform sampler2D ssaoNoise;
 
 const int numberOfSamples = 64;
-const vec3 ssaoKernel[64] =
-{
+const vec3 ssaoKernel[64] = {
     vec3( 0.009,  0.006, -0.007), vec3( 0.008, -0.003,  0.014), vec3( 0.004, -0.005, -0.019), vec3( 0.016, -0.012, -0.014), 
     vec3(-0.022, -0.018, -0.007), vec3(-0.018, -0.028, -0.006), vec3( 0.023, -0.028,  0.016), vec3( 0.010, -0.044,  0.000), 
     vec3( 0.037, -0.035,  0.007), vec3( 0.028,  0.015, -0.048), vec3( 0.030, -0.023,  0.053), vec3(-0.003,  0.042,  0.059), 
@@ -35,14 +34,12 @@ const float radius = 0.25;
 in vec2 varTex;
 out float color;
 
-void main()
-{     
+void main() {     
     vec3 fragPos = texture(worldPositionSamp, varTex).xyz;
     vec3 random = texture(ssaoNoise, varTex * vec2(width * 0.25, height * 0.25)).xyz * radius * 0.25; 
 
     float occlusion = 0.0;
-    for(int i = 0; i < numberOfSamples; i++)
-    {
+    for(int i = 0; i < numberOfSamples; i++) {
         vec4 projFragPos = proj * vec4(fragPos + ssaoKernel[i] * radius + random, 1.0);
         projFragPos.xyz /= projFragPos.w;
 
@@ -53,4 +50,4 @@ void main()
         occlusion += float(depth2 >= depth1) * rangeCheck;
     }
     color = 1 - occlusion / numberOfSamples;
-} 
+} 

+ 1 - 2
resources/shader/ssaoVertex.vs

@@ -6,8 +6,7 @@ layout (location = 2) in vec3 normal;
 
 out vec2 varTex;
 
-void main(void)
-{ 
+void main(void) { 
     gl_Position = vec4(position, 1.0);
     varTex = tex;
 }

+ 1 - 2
resources/shader/textFragment.fs

@@ -7,7 +7,6 @@ in vec3 varColor;
 
 out vec4 color;
 
-void main()
-{
+void main() {
     color = vec4(varColor, texture(samp, varTex).r);
 }  

+ 1 - 2
resources/shader/textVertex.vs

@@ -11,8 +11,7 @@ uniform mat4 model;
 out vec2 varTex;
 out vec3 varColor;
 
-void main(void)
-{ 
+void main(void) { 
     varTex = tex;
     varColor = color;
     gl_Position = proj * view * model * vec4(position, 0.0, 1.0);

+ 1 - 2
resources/shader/worldFragment.fs

@@ -17,8 +17,7 @@ in vec2 varTex;
 in vec3 varNormal;
 in vec4 varShadow;
 
-void main(void)
-{
+void main(void) {
     worldPosition = varPosition;
     worldNormal = normalize(varNormal);
 

+ 4 - 8
resources/shader/worldPostFragment.fs

@@ -13,14 +13,10 @@ out vec4 color;
 
 const vec3 light = vec3(-0.280166, -0.573576, -0.769751);
 
-void main()
-{
-    if(useSSAO)
-    {
+void main() {
+    if(useSSAO) {
         color = vec4(texture(colorSamp, varTex).xyz * (texture(ssaoSamp, varTex).r + 0.5), 1.0);
-    }
-    else
-    {
+    } else {
         color = vec4(texture(colorSamp, varTex).xyz, 1.0);
     }
 
@@ -32,4 +28,4 @@ void main()
     //color *= f * 0.5 + 0.5;
 
     //color = texture(worldNormalSamp, varTex);
-}  
+}  

+ 1 - 2
resources/shader/worldPostVertex.vs

@@ -6,8 +6,7 @@ layout (location = 2) in vec3 normals;
 
 out vec2 varTex;
 
-void main(void)
-{ 
+void main(void) { 
     varTex = tex;
     gl_Position = vec4(position, 1.0);
 }

+ 1 - 2
resources/shader/worldShadowFragment.fs

@@ -2,7 +2,6 @@
 
 out vec4 color;
 
-void main(void)
-{
+void main(void) {
     color = vec4(1.0, 0.0, 1.0, 1.0);
 }

+ 1 - 2
resources/shader/worldShadowVertex.vs

@@ -6,7 +6,6 @@ layout (location = 2) in vec3 normal;
 
 uniform mat4 projView;
 
-void main(void)
-{ 
+void main(void) { 
     gl_Position = projView * vec4(position, 1.0);
 }

+ 1 - 2
resources/shader/worldVertex.vs

@@ -19,8 +19,7 @@ out vec4 varShadow;
 
 const vec3 light = vec3(-0.280166, -0.573576, -0.769751);
 
-void main(void)
-{ 
+void main(void) { 
     // transforming normals must not use the fourth dimension
     // should be the inverse transposed matrix
     varNormal = (model * vec4(normal, 0.0)).xyz;

+ 21 - 42
server/GameServer.cpp

@@ -23,31 +23,24 @@ static const std::chrono::nanoseconds MIN_NANO_SLEEP = std::chrono::nanoseconds(
 static std::vector<std::string> commandQueue;
 static std::mutex comandQueueMutex;
 
-static void init()
-{
+static void init() {
     rl_bind_key('\t', rl_insert);
-    rl_event_hook = []() 
-    {
-        if(!serverCommands.isRunning())
-        {
+    rl_event_hook = []() {
+        if(!serverCommands.isRunning()) {
             rl_stuff_char('\n');
         }
         return 0;
     };
 }
 
-static void readFromConsole()
-{
-    while(serverCommands.isRunning())
-    {
+static void readFromConsole() {
+    while(serverCommands.isRunning()) {
         char* test = readline("> ");
-        if(test == nullptr)
-        {
+        if(test == nullptr) {
             continue;
         }
         std::string command(test);
-        if(command.size() != 0)
-        {
+        if(command.size() != 0) {
             add_history(test);
             std::lock_guard<std::mutex> lg(comandQueueMutex);
             commandQueue.push_back(command);
@@ -56,33 +49,28 @@ static void readFromConsole()
     }
 }
 
-static void handleCommandQueue()
-{
+static void handleCommandQueue() {
     std::lock_guard<std::mutex> lg(comandQueueMutex);
-    for(std::string& s : commandQueue)
-    {
+    for(std::string& s : commandQueue) {
         CommandManager::execute(serverCommands, s);
     }
     commandQueue.clear();
 }
 
-static void tick()
-{
+static void tick() {
     rl_clear_visible_line();
     handleCommandQueue();
     std::cout << "tick\n";
     rl_forced_update_display();
 }
 
-static void onFullServerClientConnect(int socket)
-{
+static void onFullServerClientConnect(int socket) {
     Stream answer;
     answer.write("Sorry, the server is full");
     answer.sendToSocket(socket);
 }
 
-static void onClientConnect(int socket)
-{
+static void onClientConnect(int socket) {
     std::cout << socket << " has connected\n";
 
     Stream answer;
@@ -90,11 +78,9 @@ static void onClientConnect(int socket)
     answer.sendToSocket(socket);
 }
 
-static void onClientPackage(int socket, Stream& in)
-{
+static void onClientPackage(int socket, Stream& in) {
     std::string s = "";
-    while(in.hasData())
-    {
+    while(in.hasData()) {
         char c;
         in.read(&c, 1);
         s = c + s;
@@ -105,8 +91,7 @@ static void onClientPackage(int socket, Stream& in)
     answer.sendToSocket(socket);
 }
 
-static void onClientDisconnect(int socket)
-{
+static void onClientDisconnect(int socket) {
     std::cout << socket << " has disconnected\n";
 
     Stream answer;
@@ -114,41 +99,35 @@ static void onClientDisconnect(int socket)
     answer.sendToSocket(socket);
 }
 
-static void loop()
-{
+static void loop() {
     auto lastTime = std::chrono::steady_clock::now().time_since_epoch();
     auto lag = lastTime.zero();
 
     std::thread commandThread = std::thread(readFromConsole);
-    while(serverCommands.isRunning())
-    {
+    while(serverCommands.isRunning()) {
         auto time = std::chrono::steady_clock::now().time_since_epoch();
         lag += time - lastTime;
         lastTime = time;
-        while(lag >= NANOS_PER_TICK)
-        {
+        while(lag >= NANOS_PER_TICK) {
             lag -= NANOS_PER_TICK;
             tick();
         }
 
         auto waitTime = NANOS_PER_TICK - lag - MIN_NANO_SLEEP;
-        if(waitTime > MIN_NANO_SLEEP)
-        {
+        if(waitTime > MIN_NANO_SLEEP) {
             std::this_thread::sleep_for(waitTime);
         }
     }
     commandThread.join();
 }
 
-void GameServer::start(u16 port, u16 maxClients)
-{
+void GameServer::start(u16 port, u16 maxClients) {
     init();
     Server::setFullServerClientConnectFunction(onFullServerClientConnect);
     Server::setClientConnectFunction(onClientConnect);
     Server::setClientPackageFunction(onClientPackage);
     Server::setClientDisconnectFunction(onClientDisconnect);
-    if(!Server::start(port, maxClients))
-    {
+    if(!Server::start(port, maxClients)) {
         return;
     }
     loop();

+ 2 - 4
server/GameServer.h

@@ -3,10 +3,8 @@
 
 #include "common/utils/Types.h"
 
-namespace GameServer
-{   
+namespace GameServer {
     void start(u16 port, u16 maxClients);
 }
 
-#endif
-
+#endif

+ 1 - 2
server/Main.cpp

@@ -1,8 +1,7 @@
 #include "server/GameServer.h"
 #include "common/block/BlockRegistry.h"
 
-int main(int /*argc*/, char** /*argv*/)
-{
+int main(int /*argc*/, char** /*argv*/) {
     BlockRegistry::loadFromFile("resources/blocks");
     GameServer::start(25565, 2);
     return 0;

+ 7 - 14
server/commands/CommandManager.cpp

@@ -5,41 +5,34 @@
 #include "server/commands/CommandManager.h"
 #include "server/commands/CommandUtils.h"
 
-static void commandTest(ServerCommands&, const std::vector<std::string>& args)
-{
+static void commandTest(ServerCommands&, const std::vector<std::string>& args) {
     std::cout << "test command" << std::endl;
-    for(size_t i = 0; i < args.size(); i++)
-    {
+    for(size_t i = 0; i < args.size(); i++) {
         std::cout << " - " << args[i] << std::endl;
     }
 }
 
-static void commandStop(ServerCommands& sc, const std::vector<std::string>&)
-{
+static void commandStop(ServerCommands& sc, const std::vector<std::string>&) {
     sc.stop();
 }
 
 typedef void (*Command) (ServerCommands&, const std::vector<std::string>&);
 
-static std::unordered_map<std::string, Command> commands(
-{
+static std::unordered_map<std::string, Command> commands( {
     {"test", commandTest},
     {"stop", commandStop}
 });
 
-void CommandManager::execute(ServerCommands& sc, const std::string& rawCommand)
-{
+void CommandManager::execute(ServerCommands& sc, const std::string& rawCommand) {
     std::vector<std::string> args;
     std::string command;
-    if(CommandUtils::splitString(rawCommand, command, args))
-    {
+    if(CommandUtils::splitString(rawCommand, command, args)) {
         std::cout << "Invalid command syntax: '" << rawCommand << "'\n";
         return;
     }
 
     const std::unordered_map<std::string, Command>::const_iterator& iter = commands.find(command);
-    if(iter == commands.end())
-    {
+    if(iter == commands.end()) {
         std::cout << "Unknown command: '" << command << "'" << std::endl;
         return;
     }

+ 2 - 4
server/commands/CommandManager.h

@@ -3,10 +3,8 @@
 
 #include "ServerCommands.h"
 
-namespace CommandManager
-{
+namespace CommandManager {
     void execute(ServerCommands& sc, const std::string& rawCommand);
 }
 
-#endif
-
+#endif

+ 21 - 39
server/commands/CommandUtils.cpp

@@ -1,15 +1,12 @@
 #include "server/commands/CommandUtils.h"
 
-static bool splitStringIntern(const std::string& rawCommand, std::string& command, std::vector<std::string>& args)
-{
+static bool splitStringIntern(const std::string& rawCommand, std::string& command, std::vector<std::string>& args) {
     size_t old = 0;
     size_t index = 0;
-    
+
     // parse first argument
-    while(index < rawCommand.size())
-    {
-        if(rawCommand[index] == ' ')
-        {
+    while(index < rawCommand.size()) {
+        if(rawCommand[index] == ' ') {
             command = rawCommand.substr(old, index - old);
             old = index + 1;
             index++;
@@ -18,70 +15,55 @@ static bool splitStringIntern(const std::string& rawCommand, std::string& comman
         index++;
     }
     // if the command name is the whole raw command
-    if(index == rawCommand.size())
-    {
+    if(index == rawCommand.size()) {
         command = rawCommand.substr(old, index - old);
         return false;
     }
-    
+
     // parse remainding arguments
-    while(index < rawCommand.size())
-    {
-        if(rawCommand[index] == '"')
-        {
+    while(index < rawCommand.size()) {
+        if(rawCommand[index] == '"') {
             // no space before the quotation mark
-            if(index != old) 
-            {
+            if(index != old) {
                 return true;
             }
             old = index + 1;
-            while(true)
-            {
+            while(true) {
                 index++;
                 // quotation mark not closed
-                if(index >= rawCommand.size())
-                {
+                if(index >= rawCommand.size()) {
                     return true;
-                }
-                else if(rawCommand[index] == '"')
-                {
+                } else if(rawCommand[index] == '"') {
                     break;
                 }
             }
             // no space after quotation mark
-            if(index + 1 < rawCommand.size() && rawCommand[index + 1] != ' ') 
-            {
+            if(index + 1 < rawCommand.size() && rawCommand[index + 1] != ' ') {
                 return true;
             }
             args.push_back(rawCommand.substr(old, index - old));
             old = index + 2;
-        }
-        else if(rawCommand[index] == ' ')
-        {
-            if(index > old && index - old > 0)
-            {
+        } else if(rawCommand[index] == ' ') {
+            if(index > old && index - old > 0) {
                 args.push_back(rawCommand.substr(old, index - old));
             }
             old = index + 1;
         }
         index++;
     }
-    
-    if(index > old && index - old > 0)
-    {
+
+    if(index > old && index - old > 0) {
         args.push_back(rawCommand.substr(old, index - old));
     }
-    
+
     return false;
 }
 
-bool CommandUtils::splitString(const std::string& rawCommand, std::string& command, std::vector<std::string>& args)
-{
+bool CommandUtils::splitString(const std::string& rawCommand, std::string& command, std::vector<std::string>& args) {
     bool b = splitStringIntern(rawCommand, command, args);
-    if(b)
-    {
+    if(b) {
         args.clear();
         command = "";
     }
     return b;
-}
+}

+ 2 - 3
server/commands/CommandUtils.h

@@ -4,9 +4,8 @@
 #include <string>
 #include <vector>
 
-namespace CommandUtils
-{
+namespace CommandUtils {
     bool splitString(const std::string& rawCommand, std::string& command, std::vector<std::string>& args);
 }
 
-#endif
+#endif

+ 3 - 6
server/commands/ServerCommands.cpp

@@ -1,15 +1,12 @@
 #include "ServerCommands.h"
 
-ServerCommands::ServerCommands() : running(true)
-{
+ServerCommands::ServerCommands() : running(true) {
 }
 
-bool ServerCommands::isRunning() const
-{
+bool ServerCommands::isRunning() const {
     return running;
 }
 
-void ServerCommands::stop()
-{
+void ServerCommands::stop() {
     running = false;
 }

+ 3 - 4
server/commands/ServerCommands.h

@@ -3,14 +3,13 @@
 
 #include <atomic>
 
-class ServerCommands
-{
+class ServerCommands {
 public:
     ServerCommands();
-    
+
     bool isRunning() const;
     void stop();
-    
+
 private:
     std::atomic_bool running;
 };

+ 73 - 125
server/network/Server.cpp

@@ -12,64 +12,53 @@
 
 #include "server/network/Server.h"
 
-static void printError(const char* message)
-{
+static void printError(const char* message) {
     std::cout << message << ": " << strerror(errno) << "\n";
 }
 
-struct ConnectedClient
-{
-    ~ConnectedClient()
-    {
-        if(socket != -1)
-        {
-            if(shutdown(socket, SHUT_RDWR))
-            {
+struct ConnectedClient {
+
+    ~ConnectedClient() {
+        if(socket != -1) {
+            if(shutdown(socket, SHUT_RDWR)) {
                 printError("cannot shutdown client socket");
             }
-            if(close(socket) == -1)
-            {
+            if(close(socket) == -1) {
                 printError("cannot close client socket");
             }
         }
-        if(th.joinable())
-        {
+        if(th.joinable()) {
             th.join();
-        }
-        else
-        {
+        } else {
             std::cout << "cannot join client connection thread\n";
         }
     }
-    
-    std::thread th = std::thread([]() {});
+
+    std::thread th = std::thread([]() {
+    });
     int socket = -1;
 };
 
-struct InternServer final
-{
-    InternServer() : listenerSocket(-1), listenerThread([](){}), shouldRun(true), clients(nullptr)
-    {
+struct InternServer final {
+    InternServer() : listenerSocket(-1), listenerThread([]() {
+    })
+, shouldRun(true), clients(nullptr) {
     }
-    
-    ~InternServer()
-    {
+
+    ~InternServer() {
         shouldRun = false;
         listenerThread.join();
 
-        if(listenerSocket != -1)
-        {
-            if(close(listenerSocket) == -1)
-            {
+        if(listenerSocket != -1) {
+            if(close(listenerSocket) == -1) {
                 printError("cannot close listener socket");
             }
         }
-        if(clients != nullptr)
-        {
+        if(clients != nullptr) {
             delete[] clients;
         }
     }
-    
+
     int listenerSocket;
     std::thread listenerThread;
     std::atomic_bool shouldRun;
@@ -78,23 +67,19 @@ struct InternServer final
 
 static InternServer server;
 
-static void defaultFullServerClientConnect(int)
-{
+static void defaultFullServerClientConnect(int) {
     std::cout << "default onFullServerClientConnectFunction\n";
 }
 
-static void defaultClientConnect(int)
-{
+static void defaultClientConnect(int) {
     std::cout << "default onClientConnectFunction\n";
 }
 
-static void defaultClientPackage(int, Stream&)
-{
+static void defaultClientPackage(int, Stream&) {
     std::cout << "default onClientPackageFunction\n";
 }
 
-static void defaultClientDisconnect(int)
-{
+static void defaultClientDisconnect(int) {
     std::cout << "default onClientDisconnectFunction\n";
 }
 
@@ -106,71 +91,57 @@ static Server::ClientConnectFunction onClientConnect = defaultClientConnect;
 static Server::ClientPackageFunction onClientPackage = defaultClientPackage;
 static Server::ClientDisconnectFunction onClientDisconnect = defaultClientDisconnect;
 
-void Server::setFullServerClientConnectFunction(Server::FullServerClientConnectFunction f)
-{
+void Server::setFullServerClientConnectFunction(Server::FullServerClientConnectFunction f) {
     onFullServerClientConnect = f;
 }
 
-void Server::setClientConnectFunction(Server::ClientConnectFunction f)
-{
+void Server::setClientConnectFunction(Server::ClientConnectFunction f) {
     onClientConnect = f;
 }
 
-void Server::setClientPackageFunction(Server::ClientPackageFunction f)
-{
+void Server::setClientPackageFunction(Server::ClientPackageFunction f) {
     onClientPackage = f;
 }
 
-void Server::setClientDisconnectFunction(Server::ClientDisconnectFunction f)
-{
+void Server::setClientDisconnectFunction(Server::ClientDisconnectFunction f) {
     onClientDisconnect = f;
 }
 
-static void listenOnClient(ConnectedClient& cc)
-{
+static void listenOnClient(ConnectedClient& cc) {
     // poll data
     struct pollfd fds;
     fds.fd = cc.socket; // file descriptor for polling
     fds.events = POLLIN; // wait until data is ready to read
     fds.revents = 0; // return events - none
-    
+
     onClientConnect(cc.socket);
-    
+
     Stream st;
-    while(server.shouldRun)
-    {
+    while(server.shouldRun) {
         // nfds_t - 1 - amount of passed in structs
         // timeout - 100 - milliseconds to wait until an event occurs
         // returns 0 on timeout, -1 on error, and >0 on success
         int pollData = poll(&fds, 1, 100);
-        if(pollData > 0)
-        {
+        if(pollData > 0) {
             st.readSocket(cc.socket);
-            if(st.hasData())
-            {
+            if(st.hasData()) {
                 onClientPackage(cc.socket, st);
-            }
-            else
-            {
+            } else {
                 // client closed connection
                 break;
             }
-        }
-        else if(pollData == -1)
-        {
+        } else if(pollData == -1) {
             printError("cannot poll from client");
             break;
         }
     }
-    
+
     onClientDisconnect(cc.socket);
-    
+
     // reset slot for another client
-    if(server.shouldRun)
-    {
+    if(server.shouldRun) {
         std::lock_guard<std::mutex> lg(clientMutex);
-        if(close(cc.socket) == -1)
-        {
+        if(close(cc.socket) == -1) {
             printError("cannot close socket of client");
         }
         cc.socket = -1;
@@ -178,36 +149,28 @@ static void listenOnClient(ConnectedClient& cc)
     }
 }
 
-static bool addClient(int clientSocket)
-{
+static bool addClient(int clientSocket) {
     std::lock_guard<std::mutex> lg(clientMutex);
-    if(clientAmount >= maxClients)
-    {
+    if(clientAmount >= maxClients) {
         onFullServerClientConnect(clientSocket);
         return true;
-    }
-    else
-    {
+    } else {
         // search for free slot
         uint16_t index = 0;
-        while(index < maxClients)
-        {
-            if(server.clients[index].socket == -1)
-            {
+        while(index < maxClients) {
+            if(server.clients[index].socket == -1) {
                 break;
             }
             index++;
         }
-        
-        if(index >= maxClients)
-        {
+
+        if(index >= maxClients) {
             std::cout << "cannot find free slot - even if there should be one\n";
             return true;
         }
 
         //ensure old thread has ended
-        if(!server.clients[index].th.joinable())
-        {
+        if(!server.clients[index].th.joinable()) {
             std::cout << "cannot join thread of non used client connection\n";
             return true;
         }
@@ -222,10 +185,8 @@ static bool addClient(int clientSocket)
     }
 }
 
-static void listenForClients()
-{
-    while(server.shouldRun)
-    {
+static void listenForClients() {
+    while(server.shouldRun) {
         // wait until a connection arrives with timeout, this prevents being 
         // stuck in accept
         struct pollfd fds;
@@ -236,50 +197,40 @@ static void listenForClients()
         // timeout - 100 - milliseconds to wait until an event occurs
         // returns 0 on timeout, -1 on error, and >0 on success
         int pollData = poll(&fds, 1, 100);
-        if(pollData > 0)
-        {
+        if(pollData > 0) {
             struct sockaddr_in clientSocketData;
             // accepts an incoming client connection and stores the data in the
             // given struct, returns a nonnegative file descriptor on success
-            socklen_t addrlen = sizeof(struct sockaddr_in);
+            socklen_t addrlen = sizeof (struct sockaddr_in);
             int clientSocket = accept(server.listenerSocket, (struct sockaddr*) &clientSocketData, &addrlen);
-            if(clientSocket >= 0)
-            {
-                if(addClient(clientSocket))
-                {
-                    if(close(clientSocket) == -1)
-                    {
+            if(clientSocket >= 0) {
+                if(addClient(clientSocket)) {
+                    if(close(clientSocket) == -1) {
                         printError("cannot close client socket");
                     }
                 }
-            }
-            else
-            {
+            } else {
                 printError("accept error");
                 break;
             }
-        }
-        else if(pollData == -1)
-        {
+        } else if(pollData == -1) {
             printError("poll error");
             break;
         }
     }
 }
 
-bool Server::start(u16 port, u16 inMaxClients)
-{
+bool Server::start(u16 port, u16 inMaxClients) {
     // create socket for incoming connections
     // domain - AF_INET - IPv4 Internet protocols
     // type - SOCK_STREAM - two-way, connection-based byte streams
     // protocol - 0 - use standard protocol for the given socket type
     server.listenerSocket = socket(AF_INET, SOCK_STREAM, 0);
-    if(server.listenerSocket == -1)
-    {
+    if(server.listenerSocket == -1) {
         printError("cannot create listener socket");
         return false;
     }
-    
+
     // prevents clients from blocking the port if the server exits
     // this is useful if server and client run on the same system
     struct linger sl;
@@ -288,39 +239,36 @@ bool Server::start(u16 port, u16 inMaxClients)
     // sockfd - listenerSocket - modified socket
     // level - SOL_SOCKET - manipulate options at the sockets API level
     // optname - SO_LINGER - identifier of the option
-    if(setsockopt(server.listenerSocket, SOL_SOCKET, SO_LINGER, &sl, sizeof(struct linger)) == -1)
-    {
+    if(setsockopt(server.listenerSocket, SOL_SOCKET, SO_LINGER, &sl, sizeof (struct linger)) == -1) {
         printError("cannot set non lingering");
         return false;
     }
-    
+
     // specify binding data
     struct sockaddr_in connectSocketData;
     // clear padding
-    memset(&connectSocketData, 0, sizeof(struct sockaddr_in));
+    memset(&connectSocketData, 0, sizeof (struct sockaddr_in));
     // IPv4 Internet protocols
-    connectSocketData.sin_family = AF_INET; 
+    connectSocketData.sin_family = AF_INET;
     // port in network byte order
-    connectSocketData.sin_port = htons(port); 
+    connectSocketData.sin_port = htons(port);
     // address in network byte order, accept any incoming messages
-    connectSocketData.sin_addr.s_addr = htons(INADDR_ANY); 
+    connectSocketData.sin_addr.s_addr = htons(INADDR_ANY);
     // bind the socket
-    if(bind(server.listenerSocket, (struct sockaddr*) &connectSocketData, sizeof(struct sockaddr_in)) == -1)
-    {
+    if(bind(server.listenerSocket, (struct sockaddr*) &connectSocketData, sizeof (struct sockaddr_in)) == -1) {
         printError("cannot bind listener socket");
         return false;
     }
-    
+
     // mark the socket as handler for connection requests
     // backlog - 5 - max queue length of pending connections
-    if(listen(server.listenerSocket, 5) == -1)
-    {
+    if(listen(server.listenerSocket, 5) == -1) {
         printError("cannot start listening on socket");
         return false;
     }
 
-    server.shouldRun = true;    
-    
+    server.shouldRun = true;
+
     maxClients = inMaxClients;
     server.clients = new ConnectedClient[inMaxClients];
     // join empty spawn thread

+ 2 - 3
server/network/Server.h

@@ -4,13 +4,12 @@
 #include "common/utils/Types.h"
 #include "common/stream/Stream.h"
 
-namespace Server
-{
+namespace Server {
     typedef void (*FullServerClientConnectFunction) (int);
     typedef void (*ClientConnectFunction) (int);
     typedef void (*ClientPackageFunction) (int, Stream&);
     typedef void (*ClientDisconnectFunction) (int);
-    
+
     bool start(u16 port, u16 maxClients);
     void setFullServerClientConnectFunction(FullServerClientConnectFunction f);
     void setClientConnectFunction(ClientConnectFunction f);

+ 37 - 60
tests/Main.cpp

@@ -13,21 +13,18 @@ const char* GREEN = "\033[0;32m";
 int tests = 0;
 int successTests = 0;
 
-void notifySuccess(string text)
-{
+void notifySuccess(string text) {
     tests++;
     successTests++;
-    cout << GREEN << tests << ". " << text << endl; 
+    cout << GREEN << tests << ". " << text << endl;
 }
 
-void notifyFail(string text)
-{
+void notifyFail(string text) {
     tests++;
     cout << RED << tests << ". " << text << endl;
 }
 
-void finalizeTest()
-{
+void finalizeTest() {
     cout << successTests << " / " << tests << " succeeded" << endl;
     tests = 0;
     successTests = 0;
@@ -37,50 +34,34 @@ void finalizeTest()
 // checks
 // -----------------------------------------------------------------------------
 
-void checkEqual(int a, int b, string text)
-{
-    if(a == b)
-    {
+void checkEqual(int a, int b, string text) {
+    if(a == b) {
         notifySuccess(text);
-    }
-    else
-    {
+    } else {
         notifyFail(text + " - expected '" + std::to_string(a) + "' got '" + std::to_string(b) + "'");
     }
 }
 
-void checkEqual(string a, string b, string text)
-{
-    if(a == b)
-    {
+void checkEqual(string a, string b, string text) {
+    if(a == b) {
         notifySuccess(text);
-    }
-    else
-    {
+    } else {
         notifyFail(text + " - expected '" + a + "' got '" + b + "'");
     }
 }
 
-void checkBool(bool a, bool b, string text)
-{
-    if(a == b)
-    {
+void checkBool(bool a, bool b, string text) {
+    if(a == b) {
         notifySuccess(text);
-    }
-    else
-    {
+    } else {
         notifyFail(text + " - expected '" + std::to_string(a) + "' got '" + std::to_string(b) + "'");
     }
 }
 
-void checkGreaterOrEqual(int a, int b, string text)
-{
-    if(a >= b)
-    {
+void checkGreaterOrEqual(int a, int b, string text) {
+    if(a >= b) {
         notifySuccess(text);
-    }
-    else
-    {
+    } else {
         notifyFail(text + " - expected " + std::to_string(a) + " >= " + std::to_string(b));
     }
 }
@@ -89,65 +70,62 @@ void checkGreaterOrEqual(int a, int b, string text)
 // tests of command parser
 // -----------------------------------------------------------------------------
 
-void checkCommandParser(string rawCommand, string command, vector<string>& args, string text)
-{
+void checkCommandParser(string rawCommand, string command, vector<string>& args, string text) {
     string parsedCommand;
     vector<string> parsedArgs;
-    
+
     CommandUtils::splitString(rawCommand, parsedCommand, parsedArgs);
-    
+
     checkEqual(command, parsedCommand, text);
     checkEqual(args.size(), parsedArgs.size(), text);
-    
-    for(unsigned long i = 0; i < args.size() && i < parsedArgs.size(); i++)
-    {
+
+    for(unsigned long i = 0; i < args.size() && i < parsedArgs.size(); i++) {
         checkEqual(args[i], parsedArgs[i], text);
     }
 }
 
-void testCommandParser()
-{
+void testCommandParser() {
     vector<string> args;
-    
+
     args = {};
     checkCommandParser("test", "test", args, "command without arguments");
-    
+
     args = {"aaa"};
     checkCommandParser("test aaa", "test", args, "command with one argument");
-    
+
     args = {"aaa", "bbbb"};
     checkCommandParser("test aaa bbbb", "test", args, "command with two arguments");
-    
+
     args = {"aaa", "bbbb", "ccccc"};
     checkCommandParser("test aaa bbbb ccccc", "test", args, "command with three arguments");
-    
+
     args = {};
     checkCommandParser("test    ", "test", args, "command with spaces");
-    
+
     args = {"aaa", "bbbb"};
     checkCommandParser("test  aaa   bbbb", "test", args, "command with arguments and spaces");
-    
+
     args = {"aaa", "bbbb"};
     checkCommandParser("test  aaa   bbbb", "test", args, "command with arguments and spaces");
-    
+
     args = {"aaa bbbb"};
     checkCommandParser("test \"aaa bbbb\"", "test", args, "command with one argument and quotation marks");
-    
+
     args = {"aaa bbbb", "ccc"};
     checkCommandParser("test \"aaa bbbb\" ccc", "test", args, "command with two arguments and quotation marks");
-    
+
     args = {"ddd", "aaa bbbb", "ccc"};
     checkCommandParser("test ddd \"aaa bbbb\" ccc", "test", args, "command with tree arguments and quotation marks");
-    
+
     args = {};
     checkCommandParser("test \"", "", args, "command syntax exception 1");
-    
+
     args = {};
     checkCommandParser("test aaa\"", "", args, "command syntax exception 2");
-    
+
     args = {};
     checkCommandParser("test aaa\"bbb\"", "", args, "command syntax exception 3");
-    
+
     args = {};
     checkCommandParser("test aaa \"bbb\"ccc", "", args, "command syntax exception 4");
 }
@@ -156,8 +134,7 @@ void testCommandParser()
 // main
 // -----------------------------------------------------------------------------
 
-int main(int argc, char** argv)
-{
+int main(int argc, char** argv) {
     testCommandParser();
     return 0;
 }