Browse Source

refactoring of client

Kajetan Johannes Hammerle 4 years ago
parent
commit
1c727b1e1e

+ 151 - 1
client/GameClient.cpp

@@ -1,4 +1,154 @@
 #include <iostream>
+#include <GL/glew.h>
+#include <GLFW/glfw3.h>
+#include <unordered_map>
+
+#include "GameClient.h"
+#include "common/utils/Types.h"
+#include "client/Keys.h"
+
+struct InternGameClient
+{
+    ~InternGameClient()
+    {
+        if(window != nullptr)
+        {
+            glfwDestroyWindow(window);
+        }
+        if(glfwInitDone)
+        {
+            glfwTerminate();
+        }
+    }
+    
+    bool glfwInitDone = false;
+    GLFWwindow* window = nullptr;
+};
+
+static const u64 NANOS_PER_TICK = 50000000;
+static const float lagFactor = 1.0f / NANOS_PER_TICK;
+static u64 timeFactor = 1;
+static int width = 0;
+static int height = 0;
+static InternGameClient client;
+static Keys keys;
+
+static bool initGLFW()
+{
+    client.glfwInitDone = glfwInit();
+    if(!client.glfwInitDone)
+    {
+        std::cout << "could not initialize GLFW\n";
+        return true;
+    }
+    timeFactor = 1000000000 / glfwGetTimerFrequency();
+    return false;
+}
+
+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)
+    {
+        std::cout << "could not create window\n";
+        return true;
+    }
+    glfwMakeContextCurrent(client.window);
+    glfwSwapInterval(1);
+    return false;
+}
+
+static bool initGLEW()
+{
+    GLenum err = glewInit();
+    if(err != GLEW_OK)
+    {
+        std::cout << "could not initialize GLEW: " << glewGetErrorString(err) << "\n";
+        return true;
+    }
+    std::cout << "using GLEW " << glewGetString(GLEW_VERSION) << "\n";
+    return false;
+}
+
+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)
+        {
+            keys.press(key);
+        }
+        else if(action == GLFW_RELEASE)
+        {
+            keys.release(key);
+        }
+    });
+    //glfwSetMouseButtonCallback(window, onMouseClick);
+    //glfwSetFramebufferSizeCallback(window, onWindowResize); 
+    //glfwSetCursorPosCallback(window, onMouseMove);
+}
+
+static void tick()
+{
+    std::cout << keys.down << std::endl;
+    keys.tick();
+}
+
+static void renderTick(float /*lag*/)
+{
+}
+
+static u64 getTimeNanos()
+{
+    return glfwGetTimerValue() * timeFactor;
+}
+
+static void loop()
+{
+    u64 lastTime = getTimeNanos();
+    u64 lag = 0;
+    while(!glfwWindowShouldClose(client.window))
+    {
+        renderTick(lag * lagFactor);
+        glfwSwapBuffers(client.window);
+        
+        u64 newTime = getTimeNanos();
+        lag += newTime - lastTime;
+        lastTime = newTime;
+        
+        while(lag >= NANOS_PER_TICK)
+        {
+            lag -= NANOS_PER_TICK;
+            tick();
+        }
+        glfwPollEvents();
+    }
+}
+
+void GameClient::start(int w, int h, const char* windowName)
+{
+    if(initGLFW() || initWindow(w, h, windowName) || initGLEW())
+    {
+        return;
+    }
+    initCallbacks();
+    glfwShowWindow(client.window);
+    loop();
+}
+
+/*#include <iostream>
 #include <cmath>
 
 #include "client/GameClient.h"
@@ -135,5 +285,5 @@ void GameClient::onMouseClick(int button, int action, int mods)
     {
         mouseManager.release(button);
     }
-}
+}*/
 

+ 9 - 2
client/GameClient.h

@@ -1,8 +1,15 @@
 #ifndef CLIENT_H
 #define CLIENT_H
 
+#include "common/utils/Types.h"
+
+namespace GameClient
+{
+    void start(int width, int height, const char* windowName);
+}
+
 // these two are not needed here but prevent further errors
-#include <GL/glew.h>
+/*#include <GL/glew.h>
 #include <GLFW/glfw3.h>
 
 #include "client/engine/KeyManager.h"
@@ -61,7 +68,7 @@ private:
     DirectRenderer directRenderer;
     
     GUI* activeGUI = nullptr;
-};
+};*/
 
 #endif
 

+ 67 - 0
client/Keys.cpp

@@ -0,0 +1,67 @@
+#include <GLFW/glfw3.h>
+
+#include "client/Keys.h"
+
+bool Keys::Key::isDown() const
+{
+    return down;
+}
+
+bool Keys::Key::isReleased() const
+{
+    return shouldRelease;
+}
+
+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() << ")"; 
+    return os;
+}
+
+Keys::Keys() : left(keys[0]), right(keys[1]), up(keys[2]), down(keys[3])
+{
+    keys[0].glfwKey = GLFW_KEY_A;
+    keys[1].glfwKey = GLFW_KEY_D;
+    keys[2].glfwKey = GLFW_KEY_W;
+    keys[3].glfwKey = GLFW_KEY_S;
+}
+
+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)
+        {
+            k.down = true;
+            k.shouldRelease = false;
+        }
+    }
+}
+
+void Keys::tick()
+{
+    for(Key& k : keys)
+    {
+        k.downTime += k.down;
+        k.down = k.down && !k.shouldRelease;
+        k.downTime *= !k.shouldRelease;
+        k.shouldRelease = false;
+    }
+}

+ 59 - 0
client/Keys.h

@@ -0,0 +1,59 @@
+#ifndef KEYS_H
+#define KEYS_H
+
+#include <iostream>
+#include <array>
+
+#include "common/utils/Types.h"
+#include "GameClient.h"
+
+class Keys
+{
+public:
+    class Key
+    {
+    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[4];
+    
+public:
+    Keys();
+    const Key& left;
+    const Key& right;
+    const Key& up;
+    const Key& down;
+    
+    void release(int key);
+    void press(int key);
+    void tick();
+    
+private:   
+    Keys(const Keys&) = delete;
+    Keys& operator=(const Keys&) = delete;
+    Keys(Key&&) = delete;
+    Keys& operator=(Keys&&) = delete;
+};
+
+std::ostream& operator<<(std::ostream& os, const Keys::Key& m);
+
+#endif
+

+ 9 - 5
client/Main.cpp

@@ -1,14 +1,18 @@
-#include "client/engine/Wrapper.h"
-#include "client/GameClient.h"
+#include "GameClient.h"
 
-int main(int argc, char** argv) 
+//#include "client/engine/Wrapper.h"
+//#include "client/GameClient.h"
+#include "client/Keys.h"
+
+int main(int /*argc*/, char** /*argv*/) 
 {
-    if(!Engine::init(1024, 620, "Test"))
+    GameClient::start(1024, 620, "Test");   
+    /*if(!Engine::init(1024, 620, "Test"))
     {
        return 0; 
     }
     GameClient client;
-    Engine::start(&client);
+    Engine::start(&client);*/
     return 0;
 }
 

+ 0 - 69
client/engine/KeyManager.cpp

@@ -1,69 +0,0 @@
-#include "client/engine/KeyManager.h"
-
-KeyManager::KeyManager()
-{
-    for(int i = 0; i < NUMBER_OF_KEYS; i++)
-    {
-        mappingArray[i] = 0;
-    }
-}
-
-bool KeyManager::isDown(int mapping)
-{
-    return isInRange(mapping) && keyArray[mappingArray[mapping]].down;
-}
-
-bool KeyManager::isReleased(int mapping)
-{
-    return isInRange(mapping) && keyArray[mappingArray[mapping]].shouldRelease;
-}
-
-unsigned int KeyManager::getDownTime(int mapping)
-{
-    bool m = isInRange(mapping);
-    return m * keyArray[mappingArray[mapping * m]].downTime;
-}
-
-void KeyManager::resetDownTime(int mapping)
-{
-    keyArray[mappingArray[mapping * isInRange(mapping)]].downTime = 0;
-}
-
-bool KeyManager::map(int mapping, int key)
-{
-    bool b = isInRange(mapping) && isInRange(key);
-    mappingArray[mapping * b] = b * key;
-    return b;
-}
-
-bool KeyManager::isInRange(int i)
-{
-    return i >= 0 && i < NUMBER_OF_KEYS;
-}
-
-void KeyManager::tick()
-{
-    for(int i = 0; i < NUMBER_OF_KEYS; i++)
-    {
-        keyArray[i].downTime += keyArray[i].down;
-        
-        keyArray[i].down = keyArray[i].down && !keyArray[i].shouldRelease;
-        keyArray[i].downTime *= !keyArray[i].shouldRelease;
-        keyArray[i].shouldRelease = false;
-    }
-}
-
-void KeyManager::press(int key)
-{
-    int index = isInRange(key) * key;
-    keyArray[index].down = true;
-    keyArray[index].shouldRelease = false;
-}
-
-void KeyManager::release(int key)
-{
-    int index = isInRange(key) * key;
-    keyArray[index].shouldRelease = true;
-}
-
-

+ 0 - 38
client/engine/KeyManager.h

@@ -1,38 +0,0 @@
-#ifndef KEY_H
-#define KEY_H
-
-#include <GLFW/glfw3.h>
-
-class KeyManager
-{
-public:
-    KeyManager();
-    
-    bool isDown(int mapping);
-    bool isReleased(int mapping);
-    unsigned int getDownTime(int mapping);
-    void resetDownTime(int mapping);
-    bool map(int mapping, int key);
-    
-    void tick();
-    void press(int key);
-    void release(int key);
-    
-private:
-    static const int NUMBER_OF_KEYS = GLFW_KEY_LAST + 1;
-    
-    bool isInRange(int i);
-    
-    struct Key
-    {
-        bool down = false;
-        bool shouldRelease = false;
-        unsigned int downTime = 0;
-    };
-    
-    Key keyArray[NUMBER_OF_KEYS];
-    int mappingArray[NUMBER_OF_KEYS];
-};
-
-#endif
-

+ 0 - 142
client/engine/Wrapper.cpp

@@ -36,62 +36,6 @@ WorldPostShader Engine::worldPostShader;
 // shader stage 5 - 2D overlay
 OverlayShader Engine::overlayShader;
 
-bool Engine::init(int width, int height, const char* name)
-{
-    Engine::width = width;
-    Engine::height = height;
-    updateScale();
-    
-    if(!glfwInit())
-    {
-        cout << "could not initialize GLFW" << endl;
-        return false;
-    }
-
-    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);
-    
-    window = glfwCreateWindow(width, height, name, nullptr, nullptr);
-    if(!window)
-    {
-        cout << "could not create window" << endl;
-        glfwTerminate();
-        return false;
-    }
-
-    glfwMakeContextCurrent(window);
-    glfwSwapInterval(1);
-
-    glfwShowWindow(window);
-
-    GLenum err = glewInit();
-    if(GLEW_OK != err)
-    {
-        cout << "could not initialize GLEW: " << glewGetErrorString(err) << endl;
-        return false;
-    }
-    cout << "Status: Using GLEW " << glewGetString(GLEW_VERSION) << endl;
-
-    if(!worldShader.init() || !ssaoShader.init() || !ssaoBlurShader.init() || 
-            !worldPostShader.init() || !overlayShader.init() || !rectangle.init())
-    {
-        glfwDestroyWindow(window);
-        glfwTerminate();
-        return false;
-    }
-    
-    glfwSetKeyCallback(window, onKeyEvent);
-    glfwSetMouseButtonCallback(window, onMouseClick);
-    glfwSetFramebufferSizeCallback(window, onWindowResize); 
-    glfwSetCursorPosCallback(window, onMouseMove);
-    return true;
-}
-
 void Engine::sleep(uint64_t nanos)
 {
     uint64_t end = glfwGetTimerValue() + nanos - 10000;
@@ -108,92 +52,6 @@ void Engine::sleep(uint64_t nanos)
     while(end > glfwGetTimerValue());
 }
 
-void Engine::start(IClient* client)
-{
-    if(client != nullptr)
-    {
-        Engine::client = client;
-    }
-    
-    glEnable(GL_CULL_FACE);
-    glDepthFunc(GL_LEQUAL);
-    
-    uint64_t newTime = glfwGetTimerValue();
-    uint64_t oldTime = newTime;
-    uint64_t lag = 0;
-    uint64_t frameLag = 0;
-    uint64_t lastFrame = 0;
-    
-    while(!glfwWindowShouldClose(window))
-    {
-        oldTime = newTime;
-        newTime = glfwGetTimerValue();
-        lag += newTime - oldTime;
-        frameLag += newTime - oldTime;
-        
-        if(lag >= NANOS_PER_TICK || frameLag >= NANOS_PER_FRAME)
-        {
-            int ticksPerFrame = 0;
-            while(lag >= NANOS_PER_TICK)
-            {
-                lag -= NANOS_PER_TICK;
-
-                Engine::client->tick();           
-                ticksPerFrame++;  
-                
-                resizeTicks -= (resizeTicks >= 0);
-                if(resizeTicks == 0)
-                {
-                    glViewport(0, 0, width, height);
-                    updateScale();
-                    worldShader.resize();
-                    ssaoShader.resize();
-                    ssaoBlurShader.resize();
-                    worldPostShader.resize();
-                }
-
-                if(ticksPerFrame >= MAX_TICKS_PER_FRAME)
-                {
-                    long skip = lag / NANOS_PER_TICK;
-                    lag -= skip * NANOS_PER_TICK;
-                    if(skip > 0)
-                    {
-                        cout << "skipped " << skip << " game ticks " << lag << endl;
-                    }
-                    break;
-                }
-            }
-
-            if(frameLag >= NANOS_PER_FRAME)
-            {
-                frameLag -= NANOS_PER_FRAME;
-                // make sure no frames are rendered immediately after each other
-                // this happens if the game tick takes too long
-                if(lastFrame + NANOS_PER_FRAME - 1000000 < glfwGetTimerValue())
-                {
-                    lastFrame = glfwGetTimerValue();
-                    if(resizeTicks == -1)
-                    {
-                        onRenderTick((float) lag / NANOS_PER_TICK);
-                        glfwSwapBuffers(window);
-                    }
-                }
-            }
-
-            glfwPollEvents();
-        }
-        else
-        {
-            // wait until next frame
-            long waitingTime = min(NANOS_PER_FRAME - frameLag, NANOS_PER_TICK - lag);
-            sleep(waitingTime);
-        }
-    }
-    
-    glfwDestroyWindow(window);
-    glfwTerminate();
-}
-
 void Engine::stop()
 {
     glfwSetWindowShouldClose(window, 1);

+ 15 - 15
common/stream/Stream.cpp

@@ -43,21 +43,21 @@ void Stream::write(const char* writeData)
     write(writeData, strlen(writeData));
 }
 
-void Stream::writeUnsignedChar(uint8_t uc)
+void Stream::writeUnsignedChar(u8 uc)
 {
-    write(&uc, sizeof(uint8_t));
+    write(&uc, sizeof(u8));
 }
 
-void Stream::writeUnsignedShort(uint16_t us)
+void Stream::writeUnsignedShort(u16 us)
 {
     us = htons(us);
-    write(&us, sizeof(uint16_t));
+    write(&us, sizeof(u16));
 }
 
-void Stream::writeUnsignedInt(uint32_t ui)
+void Stream::writeUnsignedInt(u32 ui)
 {
     ui = htonl(ui);
-    write(&ui, sizeof(uint32_t));
+    write(&ui, sizeof(u32));
 }
 
 void Stream::read(void* buffer, size_t length)
@@ -72,25 +72,25 @@ void Stream::read(void* buffer, size_t length)
     }
 }
 
-uint8_t Stream::readUnsignedChar()
+u8 Stream::readUnsignedChar()
 {
-    unsigned char uc;
-    read(&uc, sizeof(unsigned char));
+    u8 uc;
+    read(&uc, sizeof(u8));
     return uc;
 }
 
-uint16_t Stream::readUnsignedShort()
+u16 Stream::readUnsignedShort()
 {
-    uint16_t us;
-    read(&us, sizeof(uint16_t));
+    u16 us;
+    read(&us, sizeof(u16));
     us = ntohs(us);
     return us;
 }
 
-uint32_t Stream::readUnsignedInt()
+u32 Stream::readUnsignedInt()
 {
-    uint32_t ui;
-    read(&ui, sizeof(uint32_t));
+    u32 ui;
+    read(&ui, sizeof(u32));
     ui = ntohl(ui);
     return ui;
 }

+ 7 - 9
common/stream/Stream.h

@@ -1,9 +1,7 @@
 #ifndef STREAM_H
 #define STREAM_H
 
-#include <cstddef>
-#include <cstdint>
-
+#include "common/utils/Types.h"
 #include "common/utils/DataVector.h"
 
 class Stream
@@ -21,14 +19,14 @@ public:
     
     void write(const void* writeData, size_t length);
     void write(const char* writeData);
-    void writeUnsignedChar(uint8_t uc);
-    void writeUnsignedShort(uint16_t us);
-    void writeUnsignedInt(uint32_t ui);
+    void writeUnsignedChar(u8 uc);
+    void writeUnsignedShort(u16 us);
+    void writeUnsignedInt(u32 ui);
     
     void read(void* buffer, size_t length);
-    uint8_t readUnsignedChar();
-    uint16_t readUnsignedShort();
-    uint32_t readUnsignedInt();
+    u8 readUnsignedChar();
+    u16 readUnsignedShort();
+    u32 readUnsignedInt();
     
 private:
     DataVector data;

+ 17 - 27
common/utils/Face.cpp

@@ -2,30 +2,25 @@
 
 Face Face::FACES[6] =
 {
-    Face(0,  0,  1,  0,  1, "Up"),
-    Face(1,  1,  0,  0,  2, "North"),
-    Face(2,  0,  0,  1,  4, "East"),
-    Face(3,  0, -1,  0,  8, "Down"),
-    Face(4, -1,  0,  0, 16, "South"),
-    Face(5,  0,  0, -1, 32, "West")
+    {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::UP = FACES[0];
-Face& Face::DOWN = FACES[3];
+const Face& Face::UP = FACES[0];
+const Face& Face::DOWN = FACES[3];
 
-Face& Face::NORTH = FACES[1];
-Face& Face::SOUTH = FACES[4];
+const Face& Face::NORTH = FACES[1];
+const Face& Face::SOUTH = FACES[4];
 
-Face& Face::EAST = FACES[2];
-Face& Face::WEST = FACES[5];
+const Face& Face::EAST = FACES[2];
+const Face& Face::WEST = FACES[5];
 
-int Face::getCullData(bool up, bool down, bool north, bool south, bool east, bool west)
-{
-    return (up * 1) | (down * 8) | (north * 2) | (south * 16) | (east * 4) | (west * 32);
-}
-
-Face::Face(int index, int offsetX, int offsetY, int offsetZ, int cullBit, const char* name) : 
-    index(index), offsetX(offsetX), offsetY(offsetY), offsetZ(offsetZ), cullBit(cullBit), 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)
 {
 }
 
@@ -54,16 +49,11 @@ const char* Face::getName() const
     return name;
 }
 
-int Face::getCullData() const
-{
-    return cullBit;
-}
-
-void Face::forEach(void* data, void (*fun) (Face&, void*))
+void Face::forEach(const std::function<void(Face&)>& f)
 {
     for(int i = 0; i < 6; i++)
     {
-        fun(FACES[i], data);
+        f(FACES[i]);
     }
 }
 
@@ -81,4 +71,4 @@ std::ostream& operator<<(std::ostream& os, const Face& f)
 {
     os << f.getName();
     return os;
-}
+}

+ 18 - 16
common/utils/Face.h

@@ -2,30 +2,34 @@
 #define FACE_H
 
 #include <iostream>
+#include <functional>
 
 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;
     Face& getOpposite() const;
     const char* getName() const;
-    int getCullData() const;
-    
-    static void forEach(void* data, void (*fun) (Face&, void*));
-    
-    static Face& UP;
-    static Face& DOWN;
-    static Face& NORTH;
-    static Face& SOUTH;
-    static Face& EAST;
-    static Face& WEST;
-    
-    static int getCullData(bool up, bool down, bool north, bool south, bool east, bool west);
-        
+
+    static void forEach(const std::function<void(Face&)>& f);
+    
+    static const Face& UP;
+    static const Face& DOWN;
+    static const Face& NORTH;
+    static const Face& SOUTH;
+    static const Face& EAST;
+    static const Face& WEST;
+
 private:
-    Face(int index, int offsetX, int offsetY, int offsetZ, int cullBit, const char* name);
+    Face(int index, int offsetX, int offsetY, int offsetZ, const char* name);
     
     static Face FACES[6];
     
@@ -35,8 +39,6 @@ private:
     int offsetY;
     int offsetZ;
     
-    int cullBit;
-    
     const char* name;
 };
 

+ 7 - 8
meson.build

@@ -1,12 +1,10 @@
 project('cubes plus plus', 'cpp')
 
-#sourcesCommon = ['common/stream/Stream.cpp', 'common/utils/Face.cpp', 'common/block/Block.cpp', 'common/block/Blocks.cpp', 'common/block/BlockAir.cpp', 'common/world/Chunk.cpp', 'common/world/World.cpp']
+sourcesCommon = ['common/block/BlockRegistry.cpp', 'common/block/Block.cpp', 'common/stream/Stream.cpp', 'common/world/Chunk.cpp', 'common/world/World.cpp', 'common/utils/Face.cpp', 'common/utils/DataVector.cpp']
 
-sourcesCommon = ['common/stream/Stream.cpp', 'common/block/BlockRegistry.cpp','common/block/Block.cpp', 'common/utils/DataVector.cpp', 'common/world/Chunk.cpp', 'common/world/World.cpp']
+sourcesServer = ['server/GameServer.cpp', 'server/commands/CommandUtils.cpp', 'server/commands/ServerCommands.cpp', 'server/commands/CommandManager.cpp', 'server/network/Server.cpp', 'server/Main.cpp']
 
-sourcesServer = ['server/Main.cpp', 'server/GameServer.cpp', 'server/network/Server.cpp', 'server/commands/CommandManager.cpp', 'server/commands/CommandUtils.cpp', 'server/commands/ServerCommands.cpp']
-
-#sourcesClient = ['client/Main.cpp', 'client/engine/Clock.cpp', 'client/engine/DirectRenderer.cpp', 'client/engine/KeyManager.cpp', 'client/engine/Mesh.cpp', 'client/engine/MouseManager.cpp', 'client/engine/Shader.cpp', 'client/engine/Texture.cpp', 'client/engine/Utils.cpp', 'client/engine/Wrapper.cpp', 'client/engine/shader/ShaderProgram.cpp', 'client/engine/shader/WorldShader.cpp', 'client/engine/shader/FramebufferRectangle.cpp', 'client/engine/shader/SSAOShader.cpp', 'client/engine/shader/SSAOBlurShader.cpp', 'client/engine/shader/WorldPostShader.cpp', 'client/engine/shader/OverlayShader.cpp', 'client/GameClient.cpp', 'client/rendering/ChunkRenderer.cpp', 'client/rendering/ClientChunkProvider.cpp', 'client/rendering/block/BlockRenderer.cpp', 'client/rendering/block/BlockRenderers.cpp', 'client/rendering/entity/EntityRenderer.cpp', 'client/rendering/gui/GUI.cpp', 'client/rendering/gui/StartMenu.cpp', 'client/math/Matrix3D.cpp', 'client/math/Matrix3DStack.cpp', 'client/math/StackOverflow.cpp', 'client/math/StackUnderflow.cpp', 'client/math/Vector3D.cpp', 'client/math/Plane3D.cpp', 'client/math/Camera3D.cpp', 'client/network/Client.cpp', 'client/network/ClientListener.cpp']
+sourcesClient = ['client/Main.cpp', 'client/GameClient.cpp', 'client/Keys.cpp']
 
 sourcesTest = ['tests/Main.cpp', 'server/commands/CommandUtils.cpp']
 
@@ -26,9 +24,10 @@ executable('game_server',
 #executable('game_tests', 
 #    sources: sourcesTest)
     
-#executable('game_client', 
-#    sources: sourcesCommon + sourcesClient,
-#    dependencies : [threadDep, glewDep, glfwDep, pngDep])
+executable('game_client', 
+    sources: sourcesCommon + sourcesClient,
+    dependencies : [threadDep, glewDep, glfwDep, pngDep],
+    cpp_args: ['-Wall', '-Wextra', '-pedantic', '-Werror'])
     
 
 	

+ 0 - 8
server/GameServer.cpp

@@ -23,8 +23,6 @@ static const std::chrono::nanoseconds MIN_NANO_SLEEP = std::chrono::nanoseconds(
 static std::vector<std::string> commandQueue;
 static std::mutex comandQueueMutex;
 
-static bool once = false;
-
 static void init()
 {
     rl_bind_key('\t', rl_insert);
@@ -144,12 +142,6 @@ static void loop()
 
 void GameServer::start(u16 port, u16 maxClients)
 {
-    if(once)
-    {
-        return;
-    }
-    once = true;
-    
     init();
     Server::setFullServerClientConnectFunction(onFullServerClientConnect);
     Server::setClientConnectFunction(onClientConnect);

+ 2 - 3
server/commands/CommandManager.cpp

@@ -5,7 +5,7 @@
 #include "server/commands/CommandManager.h"
 #include "server/commands/CommandUtils.h"
 
-static void commandTest(ServerCommands& /*sc*/, 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++)
@@ -14,7 +14,7 @@ static void commandTest(ServerCommands& /*sc*/, const std::vector<std::string>&
     }
 }
 
-static void commandStop(ServerCommands& sc, const std::vector<std::string>& /*args*/)
+static void commandStop(ServerCommands& sc, const std::vector<std::string>&)
 {
     sc.stop();
 }
@@ -30,7 +30,6 @@ static std::unordered_map<std::string, Command> commands(
 void CommandManager::execute(ServerCommands& sc, const std::string& rawCommand)
 {
     std::vector<std::string> args;
-    
     std::string command;
     if(CommandUtils::splitString(rawCommand, command, args))
     {

+ 2 - 2
server/commands/CommandUtils.cpp

@@ -2,8 +2,8 @@
 
 static bool splitStringIntern(const std::string& rawCommand, std::string& command, std::vector<std::string>& args)
 {
-    unsigned long old = 0;
-    unsigned long index = 0;
+    size_t old = 0;
+    size_t index = 0;
     
     // parse first argument
     while(index < rawCommand.size())

+ 3 - 1
server/network/Server.cpp

@@ -48,7 +48,7 @@ struct ConnectedClient
 
 struct InternServer final
 {
-    InternServer() : listenerSocket(-1), shouldRun(true), clients(nullptr)
+    InternServer() : listenerSocket(-1), listenerThread([](){}), shouldRun(true), clients(nullptr)
     {
     }
     
@@ -323,6 +323,8 @@ bool Server::start(u16 port, u16 inMaxClients)
     
     maxClients = inMaxClients;
     server.clients = new ConnectedClient[inMaxClients];
+    // join empty spawn thread
+    server.listenerThread.join();
     server.listenerThread = std::thread(listenForClients);
     return true;
 }