Browse Source

integration of gaming core, clean up, removal of uints and co

Kajetan Johannes Hammerle 5 months ago
parent
commit
fbf66f4357
75 changed files with 318 additions and 1102 deletions
  1. 0 10
      client/Game.cpp
  2. 0 1
      client/Game.h
  3. 7 7
      client/Main.cpp
  4. 1 1
      client/input/Keys.cpp
  5. 2 4
      client/input/Keys.h
  6. 1 1
      client/input/MouseButtons.cpp
  7. 2 4
      client/input/MouseButtons.h
  8. 5 5
      client/rendering/FileTexture.cpp
  9. 3 4
      client/rendering/FileTexture.h
  10. 2 2
      client/rendering/FontRenderer.cpp
  11. 4 5
      client/rendering/FontRenderer.h
  12. 1 1
      client/rendering/Framebuffers.cpp
  13. 1 1
      client/rendering/Framebuffers.h
  14. 0 29
      client/rendering/Lines.cpp
  15. 0 23
      client/rendering/Lines.h
  16. 1 1
      client/rendering/Mesh.cpp
  17. 1 1
      client/rendering/Mesh.h
  18. 5 5
      client/rendering/NoiseTexture.cpp
  19. 3 4
      client/rendering/NoiseTexture.h
  20. 0 19
      client/rendering/NormalTexture.cpp
  21. 0 16
      client/rendering/NormalTexture.h
  22. 5 7
      client/rendering/renderer/WorldRenderer.cpp
  23. 1 3
      client/rendering/renderer/WorldRenderer.h
  24. 14 14
      client/rendering/wrapper/Framebuffer.cpp
  25. 18 19
      client/rendering/wrapper/Framebuffer.h
  26. 2 1
      client/rendering/wrapper/GLFWWrapper.cpp
  27. 4 2
      client/rendering/wrapper/GLFWWrapper.h
  28. 3 3
      client/rendering/wrapper/StreamBuffer.cpp
  29. 9 12
      client/rendering/wrapper/StreamBuffer.h
  30. 15 2
      client/rendering/wrapper/Texture.cpp
  31. 9 6
      client/rendering/wrapper/Texture.h
  32. 4 4
      client/rendering/wrapper/VertexBuffer.cpp
  33. 4 6
      client/rendering/wrapper/VertexBuffer.h
  34. 5 10
      client/utils/Clock.cpp
  35. 12 12
      client/utils/Clock.h
  36. 7 7
      client/utils/PNGReader.cpp
  37. 1 3
      client/utils/PNGReader.h
  38. 3 3
      common/block/Block.cpp
  39. 6 6
      common/block/Block.h
  40. 5 5
      common/block/BlockRegistry.cpp
  41. 7 7
      common/block/BlockRegistry.h
  42. 11 0
      common/block/BlockTypes.h
  43. 12 12
      common/network/Packet.cpp
  44. 17 12
      common/network/Packet.h
  45. 0 59
      common/utils/Array.h
  46. 0 97
      common/utils/HashMap.h
  47. 0 29
      common/utils/HashedString.cpp
  48. 0 24
      common/utils/HashedString.h
  49. 0 67
      common/utils/List.h
  50. 0 30
      common/utils/Random.cpp
  51. 0 22
      common/utils/Random.h
  52. 0 31
      common/utils/RingBuffer.h
  53. 0 44
      common/utils/SplitString.cpp
  54. 0 19
      common/utils/SplitString.h
  55. 0 105
      common/utils/String.cpp
  56. 0 54
      common/utils/String.h
  57. 0 26
      common/utils/Types.h
  58. 13 14
      common/world/HighMap.h
  59. 8 8
      common/world/World.cpp
  60. 5 5
      common/world/World.h
  61. 1 1
      gaming-core
  62. 3 12
      meson.build
  63. 6 10
      server/Clock.cpp
  64. 16 14
      server/Clock.h
  65. 6 5
      server/GameServer.cpp
  66. 3 3
      server/Main.cpp
  67. 9 9
      server/commands/CommandManager.cpp
  68. 5 7
      server/commands/CommandManager.h
  69. 11 0
      server/commands/CommandTypes.h
  70. 3 3
      server/commands/ConsoleEditor.cpp
  71. 2 2
      server/commands/ConsoleEditor.h
  72. 1 1
      server/commands/ServerCommands.cpp
  73. 6 6
      server/network/Server.cpp
  74. 6 4
      server/network/Server.h
  75. 1 91
      tests/Main.cpp

+ 0 - 10
client/Game.cpp

@@ -1,15 +1,5 @@
-#include <cmath>
-#include <vector>
-#include <fstream>
-
 #include "client/Game.h"
-#include "rendering/Renderer.h"
-#include "common/utils/String.h"
-#include "common/utils/Random.h"
-#include "gaming-core/math/Quaternion.h"
 #include "gaming-core/utils/Utils.h"
-#include "rendering/wrapper/GLWrapper.h"
-#include "rendering/wrapper/GLFWWrapper.h"
 
 Game::Game(const Control& control, const Clock& fps, const Clock& tps, RenderSettings& settings, const Size& size) :
 control(control), fps(fps), tps(tps), renderSettings(settings), size(size), world(blockRegistry), worldRenderer(world) {

+ 0 - 1
client/Game.h

@@ -5,7 +5,6 @@
 #include "client/utils/Clock.h"
 #include "client/rendering/RenderSettings.h"
 #include "client/rendering/Renderer.h"
-#include "client/rendering/FileTexture.h"
 #include "client/rendering/FontRenderer.h"
 #include "common/world/World.h"
 #include "common/block/BlockRegistry.h"

+ 7 - 7
client/Main.cpp

@@ -54,26 +54,26 @@ int main() {
     if(GLFWWrapper::hasError()) {
         return 0;
     }
-
+    
     Size size(1024, 620);
     Window window(size, "Test");
     if(window.hasError() || initGLEW()) {
         return 0;
     }
-
+    
     Shaders shaders;
     if(shaders.hasError()) {
         return 0;
     }
-
+    
     Framebuffers framebuffers(size);
     if(framebuffers.hasError()) {
         return 0;
     }
-
+    
     RenderSettings renderSettings;
     Engine engine(shaders, framebuffers, size, renderSettings);
-
+    
     Control control;
     Clock fps;
     Clock tps;
@@ -84,8 +84,8 @@ int main() {
     
     GLWrapper::checkAndPrintError("setup error");
 
-    const u64 nanosPerTick = 50000000;
-    u64 lag = 0;
+    const GLFWWrapper::Nanos nanosPerTick = 50000000;
+    GLFWWrapper::Nanos lag = 0;
     while(!window.shouldClose() && game.isRunning()) {
         GLWrapper::checkAndPrintError("loop error");
         engine.renderTick(static_cast<float> (lag) / nanosPerTick, game);

+ 1 - 1
client/input/Keys.cpp

@@ -13,7 +13,7 @@ bool Keys::Key::isReleased() const {
     return shouldRelease;
 }
 
-uint Keys::Key::getDownTime() const {
+int Keys::Key::getDownTime() const {
     return downTime;
 }
 

+ 2 - 4
client/input/Keys.h

@@ -4,8 +4,6 @@
 #include <iostream>
 #include <array>
 
-#include "common/utils/Types.h"
-
 class Keys final {
 public:
 
@@ -15,7 +13,7 @@ public:
 
         bool isDown() const;
         bool isReleased() const;
-        uint getDownTime() const;
+        int getDownTime() const;
 
     private:
         Key();
@@ -27,7 +25,7 @@ public:
         int glfwKey;
         bool down;
         bool shouldRelease;
-        uint downTime;
+        int downTime;
     };
 
 private:

+ 1 - 1
client/input/MouseButtons.cpp

@@ -13,7 +13,7 @@ bool MouseButtons::MouseButton::isReleased() const {
     return shouldRelease;
 }
 
-u32 MouseButtons::MouseButton::getDownTime() const {
+int MouseButtons::MouseButton::getDownTime() const {
     return downTime;
 }
 

+ 2 - 4
client/input/MouseButtons.h

@@ -4,8 +4,6 @@
 #include <iostream>
 #include <array>
 
-#include "common/utils/Types.h"
-
 class MouseButtons final {
 public:
 
@@ -15,7 +13,7 @@ public:
 
         bool isDown() const;
         bool isReleased() const;
-        u32 getDownTime() const;
+        int getDownTime() const;
 
     private:
         MouseButton();
@@ -27,7 +25,7 @@ public:
         int glfwButton;
         bool down;
         bool shouldRelease;
-        u32 downTime;
+        int downTime;
     };
 
 private:

+ 5 - 5
client/rendering/FileTexture.cpp

@@ -2,14 +2,14 @@
 #include "client/utils/PNGReader.h"
 
 FileTexture::FileTexture(const char* path) {
-    u32 maxWidth = 256;
-    u32 maxHeight = 256;
-    u32 buffer[256 * 256];
+    int maxWidth = 256;
+    int maxHeight = 256;
+    int buffer[256 * 256];
     if(PNGReader::load(path, buffer, maxWidth, maxHeight)) {
-        texture.setRGBAData(maxWidth, maxHeight, buffer);
+        texture.setColorData(maxWidth, maxHeight, reinterpret_cast<Color4*>(buffer));
     }
 }
 
-void FileTexture::bind(uint index) const {
+void FileTexture::bind(int index) const {
     texture.bind(index);
 }

+ 3 - 4
client/rendering/FileTexture.h

@@ -4,13 +4,12 @@
 #include "client/rendering/wrapper/Texture.h"
 
 class FileTexture final {
+    Texture texture;
+    
 public:
     FileTexture(const char* path);
 
-    void bind(uint index) const;
-
-private:
-    Texture texture;
+    void bind(int index) const;
 };
 
 #endif

+ 2 - 2
client/rendering/FontRenderer.cpp

@@ -10,10 +10,10 @@ FontRenderer::FontRenderer() : buffer(8 * 1024 * 1024), tex("resources/font8x8.p
 void FontRenderer::drawString(float x, float y, const char* text) {
     vertexBuffer.bind();
 
-    const u64 maxIndex = 256;
+    const int maxIndex = 256;
     buffer.reset(maxIndex * 4 * sizeof (float) * 7);
 
-    u64 index = 0;
+    int index = 0;
     float r = 1.0f;
     float g = 1.0f;
     float b = 1.0f;

+ 4 - 5
client/rendering/FontRenderer.h

@@ -6,15 +6,14 @@
 #include "client/rendering/FileTexture.h"
 
 class FontRenderer final {
+    VertexBuffer vertexBuffer;
+    StreamBuffer buffer;
+    FileTexture tex;
+    
 public:
     FontRenderer();
 
     void drawString(float x, float y, const char* text);
-
-private:
-    VertexBuffer vertexBuffer;
-    StreamBuffer buffer;
-    FileTexture tex;
 };
 
 #endif

+ 1 - 1
client/rendering/Framebuffers.cpp

@@ -7,7 +7,7 @@ ssaoBlur(size, Framebuffer::RED),
 shadow(size, Framebuffer::DEPTH) {
 }
 
-void Framebuffers::resize(uint width, uint height) {
+void Framebuffers::resize(int width, int height) {
     world.resize(width, height);
     ssao.resize(width, height);
     ssaoBlur.resize(width, height);

+ 1 - 1
client/rendering/Framebuffers.h

@@ -6,7 +6,7 @@
 
 struct Framebuffers final {
     Framebuffers(const Size& size);
-    void resize(uint width, uint height);
+    void resize(int width, int height);
     bool hasError() const;
 
     Framebuffer world;

+ 0 - 29
client/rendering/Lines.cpp

@@ -1,29 +0,0 @@
-#include "client/rendering/Lines.h"
-
-Lines::Lines() {
-    vertexBuffer.bind();
-    vertexBuffer.setFloatAttribute(0, 3, 0, 6);
-    vertexBuffer.setFloatAttribute(1, 3, 3, 6);
-}
-
-void Lines::add(const Vector3& a, const Vector3& b, int color) {
-    Vector3 c((color & 0xFF) / 255.0f, ((color >> 8) & 0xFF) / 255.0f, ((color >> 16) & 0xFF) / 255.0f);
-    buffer.add(a);
-    buffer.add(c);
-    buffer.add(b);
-    buffer.add(c);
-}
-
-void Lines::clear() {
-    buffer.clear();
-}
-
-void Lines::build() {
-    vertexBuffer.bindBuffer();
-    vertexBuffer.setData(sizeof (Vector3) * buffer.getLength(), buffer.getData());
-}
-
-void Lines::draw() const {
-    vertexBuffer.bindArray();
-    vertexBuffer.drawLines(buffer.getLength() / 2);
-}

+ 0 - 23
client/rendering/Lines.h

@@ -1,23 +0,0 @@
-#ifndef LINES_H
-#define LINES_H
-
-#include "client/rendering/wrapper/VertexBuffer.h"
-#include "common/utils/List.h"
-#include "client/rendering/Triangle.h"
-
-class Lines final {
-public:
-    Lines();
-
-    void add(const Vector3& a, const Vector3& b, int color);
-
-    void clear();
-    void build();
-    void draw() const;
-
-private:
-    VertexBuffer vertexBuffer;
-    List<Vector3, 20000> buffer;
-};
-
-#endif

+ 1 - 1
client/rendering/Mesh.cpp

@@ -19,7 +19,7 @@ void Mesh::clear() {
 
 void Mesh::build() {
     vertexBuffer.bindBuffer();
-    vertexBuffer.setData(sizeof (Triangle) * buffer.getLength(), buffer.getData());
+    vertexBuffer.setData(sizeof (Triangle) * buffer.getLength(), &(buffer[0]));
 }
 
 void Mesh::draw() const {

+ 1 - 1
client/rendering/Mesh.h

@@ -2,7 +2,7 @@
 #define MESH_H
 
 #include "client/rendering/wrapper/VertexBuffer.h"
-#include "common/utils/List.h"
+#include "gaming-core/utils/List.h"
 #include "client/rendering/Triangle.h"
 
 class Mesh final {

+ 5 - 5
client/rendering/NoiseTexture.cpp

@@ -1,16 +1,16 @@
 #include "client/rendering/NoiseTexture.h"
-#include "common/utils/Random.h"
-#include "common/utils/List.h"
+#include "gaming-core/utils/Random.h"
+#include "gaming-core/utils/List.h"
 
 NoiseTexture::NoiseTexture() {
     Random r(1);
     List<float, 48> data;
-    for(uint i = 0; i < data.getCapacity(); i++) {
+    for(int i = 0; i < 48; i++) {
         data.add(r.nextFloat() * 2.0f - 1.0f);
     }
-    texture.setRGBFloatData(4, 4, data.getData());
+    texture.setRGBFloatData(4, 4, &(data[0]));
 }
 
-void NoiseTexture::bind(uint index) const {
+void NoiseTexture::bind(int index) const {
     texture.bind(index);
 }

+ 3 - 4
client/rendering/NoiseTexture.h

@@ -4,13 +4,12 @@
 #include "client/rendering/wrapper/Texture.h"
 
 class NoiseTexture final {
+    Texture texture;
+    
 public:
     NoiseTexture();
 
-    void bind(uint index) const;
-
-private:
-    Texture texture;
+    void bind(int index) const;
 };
 
 #endif

+ 0 - 19
client/rendering/NormalTexture.cpp

@@ -1,19 +0,0 @@
-#include <cmath>
-#include <iostream>
-
-#include "client/rendering/NormalTexture.h"
-#include "client/utils/PNGReader.h"
-
-NormalTexture::NormalTexture(const char* path) : texture(Texture::LINEAR) {
-    u32 maxWidth = 512;
-    u32 maxHeight = 512;
-    u32* buffer = new u32[maxWidth * maxHeight];
-    if(PNGReader::load(path, buffer, maxWidth, maxHeight)) {
-        texture.setRGBAData(maxWidth, maxHeight, buffer);
-    }
-    delete[] buffer;
-}
-
-void NormalTexture::bind(uint index) const {
-    texture.bind(index);
-}

+ 0 - 16
client/rendering/NormalTexture.h

@@ -1,16 +0,0 @@
-#ifndef NORMALTEXTURE_H
-#define NORMALTEXTURE_H
-
-#include "client/rendering/wrapper/Texture.h"
-
-class NormalTexture final {
-public:
-    NormalTexture(const char* path);
-
-    void bind(uint index) const;
-
-private:
-    Texture texture;
-};
-
-#endif

+ 5 - 7
client/rendering/renderer/WorldRenderer.cpp

@@ -1,10 +1,9 @@
 #include "client/rendering/renderer/WorldRenderer.h"
 
-WorldRenderer::WorldRenderer(const World& world) : world(world), texture("resources/textures.png"),
-normalTexture("resources/normal.png") {
-    for(uint x = 0; x < World::WORLD_SIZE; x++) {
-        for(uint y = 0; y < World::WORLD_SIZE; y++) {
-            for(uint z = 0; z < World::WORLD_SIZE; z++) {
+WorldRenderer::WorldRenderer(const World& world) : world(world), texture("resources/textures.png") {
+    for(int x = 0; x < World::WORLD_SIZE; x++) {
+        for(int y = 0; y < World::WORLD_SIZE; y++) {
+            for(int z = 0; z < World::WORLD_SIZE; z++) {
                 if(world.getBlock(x, y, z).getId() != 0) {
                     addCube(x, y, z,
                             isAir(x, y - 1, z), isAir(x, y + 1, z),
@@ -21,11 +20,10 @@ void WorldRenderer::render(float lag, Renderer& renderer) const {
     (void) lag;
     (void) renderer;
     texture.bind(0);
-    normalTexture.bind(2);
     mesh.draw();
 }
 
-bool WorldRenderer::isAir(uint x, uint y, uint z) const {
+bool WorldRenderer::isAir(int x, int y, int z) const {
     return world.getBlock(x, y, z).getId() == 0;
 }
 

+ 1 - 3
client/rendering/renderer/WorldRenderer.h

@@ -5,7 +5,6 @@
 #include "common/world/World.h"
 #include "client/rendering/Mesh.h"
 #include "client/rendering/FileTexture.h"
-#include "client/rendering/NormalTexture.h"
 
 class WorldRenderer {
 public:
@@ -13,13 +12,12 @@ public:
 
     void render(float lag, Renderer& renderer) const;
     void addCube(float x, float y, float z, bool bottom, bool top, bool left, bool right, bool front, bool back);
-    bool isAir(uint x, uint y, uint z) const;
+    bool isAir(int x, int y, int z) const;
 
 private:
     const World& world;
     Mesh mesh;
     FileTexture texture;
-    NormalTexture normalTexture;
 };
 
 #endif

+ 14 - 14
client/rendering/wrapper/Framebuffer.cpp

@@ -2,7 +2,7 @@
 
 #include "client/rendering/wrapper/Framebuffer.h"
 
-Framebuffer::Framebuffer(const Size& size, uint mode, bool texCompare) : size(size), mode(mode), textures(0),
+Framebuffer::Framebuffer(const Size& size, int mode, bool texCompare) : size(size), mode(mode), textures(0),
 buffer(0), error(false) {
     glGenFramebuffers(1, &buffer);
     glBindFramebuffer(GL_FRAMEBUFFER, buffer);
@@ -14,8 +14,8 @@ buffer(0), error(false) {
     data[4] = {DEPTH, GL_DEPTH_COMPONENT32, GL_DEPTH_COMPONENT, GL_FLOAT};
 
     GLuint attachments[4];
-    uint counter = 0;
-    for(uint i = 0; i < 4; i++) {
+    int counter = 0;
+    for(int i = 0; i < 4; i++) {
         if(mode & data[i].mask) {
             setupTexture(i, size.width, size.height, attachments, counter);
         }
@@ -54,8 +54,8 @@ void Framebuffer::bind() const {
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
 }
 
-void Framebuffer::resize(uint width, uint height) const {
-    for(uint i = 0; i < 5; i++) {
+void Framebuffer::resize(int width, int height) const {
+    for(int i = 0; i < 5; i++) {
         if(mode & data[i].mask) {
             glBindTexture(GL_TEXTURE_2D, textures[i]);
             glTexImage2D(GL_TEXTURE_2D, 0, data[i].internalFormat, width, height, 0, data[i].format, data[i].type, nullptr);
@@ -63,33 +63,33 @@ void Framebuffer::resize(uint width, uint height) const {
     }
 }
 
-void Framebuffer::bindTexture(uint textureUnit, GLuint texture) const {
+void Framebuffer::bindTexture(int textureUnit, GLuint texture) const {
     glActiveTexture(GL_TEXTURE0 + textureUnit);
     glBindTexture(GL_TEXTURE_2D, texture);
 }
 
-void Framebuffer::bindPositionTexture(uint textureUnit) const {
+void Framebuffer::bindPositionTexture(int textureUnit) const {
     bindTexture(textureUnit, textures[0]);
 }
 
-void Framebuffer::bindNormalTexture(uint textureUnit) const {
+void Framebuffer::bindNormalTexture(int textureUnit) const {
     bindTexture(textureUnit, textures[1]);
 }
 
-void Framebuffer::bindColorTexture(uint textureUnit) const {
+void Framebuffer::bindColorTexture(int textureUnit) const {
     bindTexture(textureUnit, textures[2]);
 }
 
-void Framebuffer::bindRedTexture(uint textureUnit) const {
+void Framebuffer::bindRedTexture(int textureUnit) const {
     bindTexture(textureUnit, textures[3]);
 }
 
-void Framebuffer::bindDepthTexture(uint textureUnit) const {
+void Framebuffer::bindDepthTexture(int textureUnit) const {
     bindTexture(textureUnit, textures[4]);
 }
 
-void Framebuffer::genTexture(uint index, uint width, uint height) {
-    glGenTextures(1, textures + index);
+void Framebuffer::genTexture(int index, int width, int height) {
+    glGenTextures(1, &(textures[index]));
     glBindTexture(GL_TEXTURE_2D, textures[index]);
     glTexImage2D(GL_TEXTURE_2D, 0, data[index].internalFormat, width, height, 0, data[index].format, data[index].type, nullptr);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@@ -98,7 +98,7 @@ void Framebuffer::genTexture(uint index, uint width, uint height) {
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 }
 
-void Framebuffer::setupTexture(uint index, uint width, uint height, GLuint* attachments, uint& counter) {
+void Framebuffer::setupTexture(int index, int width, int height, GLuint* attachments, int& counter) {
     genTexture(index, width, height);
     glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + counter, GL_TEXTURE_2D, textures[index], 0);
     attachments[counter] = GL_COLOR_ATTACHMENT0 + counter;

+ 18 - 19
client/rendering/wrapper/Framebuffer.h

@@ -4,18 +4,17 @@
 #include <GL/glew.h>
 
 #include "gaming-core/utils/Size.h"
-#include "common/utils/Array.h"
-#include "common/utils/Types.h"
+#include "gaming-core/utils/Array.h"
 
 class Framebuffer final {
 public:
-    static const uint POSITION = 1;
-    static const uint NORMAL = 2;
-    static const uint COLOR = 4;
-    static const uint RED = 8;
-    static const uint DEPTH = 16;
+    static const int POSITION = 1;
+    static const int NORMAL = 2;
+    static const int COLOR = 4;
+    static const int RED = 8;
+    static const int DEPTH = 16;
 
-    Framebuffer(const Size& size, uint mode, bool texCompare = false);
+    Framebuffer(const Size& size, int mode, bool texCompare = false);
     ~Framebuffer();
     Framebuffer(const Framebuffer& other) = delete;
     Framebuffer(Framebuffer&& other) = delete;
@@ -25,28 +24,28 @@ public:
     bool hasError() const;
     void bind() const;
 
-    void resize(uint width, uint height) const;
+    void resize(int width, int height) const;
 
-    void bindPositionTexture(uint textureUnit) const;
-    void bindNormalTexture(uint textureUnit) const;
-    void bindColorTexture(uint textureUnit) const;
-    void bindRedTexture(uint textureUnit) const;
-    void bindDepthTexture(uint textureUnit) const;
+    void bindPositionTexture(int textureUnit) const;
+    void bindNormalTexture(int textureUnit) const;
+    void bindColorTexture(int textureUnit) const;
+    void bindRedTexture(int textureUnit) const;
+    void bindDepthTexture(int textureUnit) const;
 
 private:
-    void genTexture(uint index, uint width, uint height);
-    void setupTexture(uint index, uint width, uint height, GLuint* attachments, uint& counter);
-    void bindTexture(uint textureUnit, GLuint texture) const;
+    void genTexture(int index, int width, int height);
+    void setupTexture(int index, int width, int height, GLuint* attachments, int& counter);
+    void bindTexture(int textureUnit, GLuint texture) const;
     const char* getErrorString(GLenum error) const;
 
     const Size& size;
-    uint mode;
+    int mode;
     Array<GLuint, 5> textures;
     GLuint buffer;
     bool error;
 
     struct Data final {
-        uint mask;
+        int mask;
         GLint internalFormat;
         GLenum format;
         GLenum type;

+ 2 - 1
client/rendering/wrapper/GLFWWrapper.cpp

@@ -1,4 +1,5 @@
 #include <iostream>
+
 #include <GL/glew.h>
 #include <GLFW/glfw3.h>
 
@@ -24,6 +25,6 @@ bool GLFWWrapper::hasError() {
     return init.error;
 }
 
-u64 GLFWWrapper::getTimeNanos() {
+GLFWWrapper::Nanos GLFWWrapper::getTimeNanos() {
     return glfwGetTimerValue() * (1000000000 / glfwGetTimerFrequency());
 }

+ 4 - 2
client/rendering/wrapper/GLFWWrapper.h

@@ -1,11 +1,13 @@
 #ifndef GLFWWRAPPER_H
 #define GLFWWRAPPER_H
 
-#include "common/utils/Types.h"
+#include "gaming-core/utils/Types.h"
 
 namespace GLFWWrapper {
+    typedef int64 Nanos;
+    
     bool hasError();
-    u64 getTimeNanos();
+    Nanos getTimeNanos();
 }
 
 #endif

+ 3 - 3
client/rendering/wrapper/StreamBuffer.cpp

@@ -3,10 +3,10 @@
 
 #include "client/rendering/wrapper/StreamBuffer.h"
 
-StreamBuffer::StreamBuffer(u64 size) : bufferSize(size), offset(size), index(0), buffer(nullptr) {
+StreamBuffer::StreamBuffer(int size) : bufferSize(size), offset(size), index(0), buffer(nullptr) {
 }
 
-void StreamBuffer::reset(u64 size) {
+void StreamBuffer::reset(int size) {
     if(offset + size >= bufferSize) {
         offset = 0;
         glBufferData(GL_ARRAY_BUFFER, bufferSize, nullptr, GL_STREAM_DRAW);
@@ -21,7 +21,7 @@ StreamBuffer& StreamBuffer::add(float f) {
     return *this;
 }
 
-void StreamBuffer::draw(uint floatPerVertex) {
+void StreamBuffer::draw(int floatPerVertex) {
     glUnmapBuffer(GL_ARRAY_BUFFER);
     glDrawArrays(GL_TRIANGLE_STRIP, offset / (sizeof (float) * floatPerVertex), index / floatPerVertex);
     offset += index * sizeof(float);

+ 9 - 12
client/rendering/wrapper/StreamBuffer.h

@@ -1,26 +1,23 @@
 #ifndef STREAMBUFFER_H
 #define STREAMBUFFER_H
 
-#include "common/utils/Types.h"
-
 class StreamBuffer final {
+    int bufferSize;
+    int offset;
+
+    int index;
+    float* buffer;
+    
 public:
-    StreamBuffer(u64 size);
+    StreamBuffer(int size);
     StreamBuffer(const StreamBuffer& other) = delete;
     StreamBuffer(StreamBuffer&& other) = delete;
     StreamBuffer& operator=(const StreamBuffer& other) = delete;
     StreamBuffer& operator=(StreamBuffer&& other) = delete;
 
-    void reset(u64 size);
+    void reset(int size);
     StreamBuffer& add(float f);
-    void draw(uint floatPerVertex);
-
-private:
-    u64 bufferSize;
-    u64 offset;
-
-    u64 index;
-    float* buffer;
+    void draw(int floatPerVertex);
 };
 
 #endif

+ 15 - 2
client/rendering/wrapper/Texture.cpp

@@ -21,15 +21,28 @@ Texture::~Texture() {
     glDeleteTextures(1, &texture);
 }
 
-void Texture::setRGBAData(int width, int height, const u32* data) {
+void Texture::setColorData(int width, int height, const Color4* data) {
     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
+    //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
+}
+
+void Texture::setColorData(int width, int height, const Color3* data) {
+    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
+}
+
+void Texture::setColorData(int width, int height, const Color2* data) {
+    glTexImage2D(GL_TEXTURE_2D, 0, GL_RG, width, height, 0, GL_RG, GL_UNSIGNED_BYTE, data);
+}
+
+void Texture::setColorData(int width, int height, const Color1* data) {
+    glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, width, height, 0, GL_RED, GL_UNSIGNED_BYTE, data);
 }
 
 void Texture::setRGBFloatData(int width, int height, const float* data) {
     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, width, height, 0, GL_RGB, GL_FLOAT, data);
 }
 
-void Texture::bind(uint index) const {
+void Texture::bind(int index) const {
     glActiveTexture(GL_TEXTURE0 + index);
     glBindTexture(GL_TEXTURE_2D, texture);
 }

+ 9 - 6
client/rendering/wrapper/Texture.h

@@ -3,9 +3,11 @@
 
 #include <GL/glew.h>
 
-#include "common/utils/Types.h"
+#include "gaming-core/utils/Color.h"
 
 class Texture final {
+    GLuint texture;
+
 public:
 
     enum Mode {
@@ -19,13 +21,14 @@ public:
     Texture& operator=(const Texture& other) = delete;
     Texture& operator=(Texture&& other) = delete;
 
-    void setRGBAData(int width, int height, const u32* data);
-    void setRGBFloatData(int width, int height, const float* data);
+    void setColorData(int width, int height, const Color4* data);
+    void setColorData(int width, int height, const Color3* data);
+    void setColorData(int width, int height, const Color2* data);
+    void setColorData(int width, int height, const Color1* data);
 
-    void bind(uint index) const;
+    void setRGBFloatData(int width, int height, const float* data);
 
-private:
-    GLuint texture;
+    void bind(int index) const;
 };
 
 #endif

+ 4 - 4
client/rendering/wrapper/VertexBuffer.cpp

@@ -10,12 +10,12 @@ VertexBuffer::~VertexBuffer() {
     glDeleteVertexArrays(1, &vertexArray);
 }
 
-void VertexBuffer::setFloatAttribute(uint index, uint length, uint offset, uint step) {
+void VertexBuffer::setFloatAttribute(int index, int length, int offset, int step) {
     glVertexAttribPointer(index, length, GL_FLOAT, false, sizeof (float) * step, static_cast<float*> (0) + offset);
     glEnableVertexAttribArray(index);
 }
 
-void VertexBuffer::setData(u64 size, const void* data) {
+void VertexBuffer::setData(int size, const void* data) {
     glBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW);
 }
 
@@ -32,10 +32,10 @@ void VertexBuffer::bind() const {
     bindBuffer();
 }
 
-void VertexBuffer::draw(uint vertices) const {
+void VertexBuffer::draw(int vertices) const {
     glDrawArrays(GL_TRIANGLES, 0, vertices);
 }
 
-void VertexBuffer::drawLines(uint vertices) const {
+void VertexBuffer::drawLines(int vertices) const {
     glDrawArrays(GL_LINES, 0, vertices);
 }

+ 4 - 6
client/rendering/wrapper/VertexBuffer.h

@@ -3,8 +3,6 @@
 
 #include <GL/glew.h>
 
-#include "common/utils/Types.h"
-
 class VertexBuffer final {
 public:
     VertexBuffer();
@@ -14,15 +12,15 @@ public:
     VertexBuffer& operator=(const VertexBuffer& other) = delete;
     VertexBuffer& operator=(VertexBuffer&& other) = delete;
     
-    void setFloatAttribute(uint index, uint length, uint offset, uint step);
-    void setData(u64 size, const void* data);
+    void setFloatAttribute(int index, int length, int offset, int step);
+    void setData(int size, const void* data);
     
     void bindArray() const;
     void bindBuffer() const;
     void bind() const;
     
-    void draw(uint vertices) const;
-    void drawLines(uint vertices) const;
+    void draw(int vertices) const;
+    void drawLines(int vertices) const;
 
 private:
     GLuint vertexArray;

+ 5 - 10
client/utils/Clock.cpp

@@ -1,12 +1,11 @@
 #include "client/utils/Clock.h"
-#include "client/rendering/wrapper/GLFWWrapper.h"
 
-Clock::Clock() : last(GLFWWrapper::getTimeNanos()), index(0), sum(0), time(0) {
+Clock::Clock() : index(0), last(GLFWWrapper::getTimeNanos()), sum(0), time(0) {
 }
 
-u64 Clock::update() {
-    index = (index + 1) & (length - 1);
-    u64 current = GLFWWrapper::getTimeNanos();
+GLFWWrapper::Nanos Clock::update() {
+    index = (index + 1) & (LENGTH - 1);
+    GLFWWrapper::Nanos current = GLFWWrapper::getTimeNanos();
     sum -= time[index];
     time[index] = current - last;
     sum += time[index];
@@ -14,10 +13,6 @@ u64 Clock::update() {
     return time[index];
 }
 
-u64 Clock::getLength() const {
-    return length;
-}
-
 float Clock::getUpdatesPerSecond() const {
-    return length * (1000000000.0f / sum);
+    return LENGTH * (1000000000.0f / sum);
 }

+ 12 - 12
client/utils/Clock.h

@@ -1,23 +1,23 @@
 #ifndef CLOCK_H
 #define CLOCK_H
 
-#include "common/utils/Types.h"
-#include "common/utils/Array.h"
+#include "gaming-core/utils/Array.h"
+#include "client/rendering/wrapper/GLFWWrapper.h"
 
 class Clock final {
+    static constexpr int BITS = 7;
+    static constexpr int LENGTH = 1 << BITS;
+    
+    int index;
+    GLFWWrapper::Nanos last;
+    GLFWWrapper::Nanos sum;
+    Array<GLFWWrapper::Nanos, LENGTH> time;
+    
 public:
     Clock();
-    u64 update();
-    u64 getLength() const;
+    
+    GLFWWrapper::Nanos update();
     float getUpdatesPerSecond() const;
-
-private:
-    static constexpr u64 bits = 7;
-    static constexpr u64 length = 1 << bits;
-    u64 last;
-    u64 index;
-    s64 sum;
-    Array<u64, length> time;
 };
 
 #endif

+ 7 - 7
client/utils/PNGReader.cpp

@@ -17,7 +17,7 @@ static bool checkSignature(const char* path, FILE* file) {
     return false;
 }
 
-static bool load(const char* path, FILE* file, u32* buffer, u32& maxWidth, u32& maxHeight) {
+static bool load(const char* path, FILE* file, int* buffer, int& maxWidth, int& maxHeight) {
     if(checkSignature(path, file)) {
         return false;
     }
@@ -34,7 +34,7 @@ static bool load(const char* path, FILE* file, u32* buffer, u32& maxWidth, u32&
         return false;
     }
 
-    u32** rowPointers = nullptr;
+    int** rowPointers = nullptr;
 
     if(setjmp(png_jmpbuf(png))) { // set callback for errors
         if(rowPointers != nullptr) {
@@ -50,8 +50,8 @@ static bool load(const char* path, FILE* file, u32* buffer, u32& maxWidth, u32&
 
     png_read_info(png, info); // read info data
     
-    u32 width = png_get_image_width(png, info);
-    u32 height = png_get_image_height(png, info);
+    int width = png_get_image_width(png, info);
+    int height = png_get_image_height(png, info);
     if(width > maxWidth || height > maxHeight) {
         std::cout << "texture '" << path << "' is too big: " << maxWidth << " x " << maxHeight << " allowed\n";
         return false;
@@ -60,8 +60,8 @@ static bool load(const char* path, FILE* file, u32* buffer, u32& maxWidth, u32&
     maxHeight = height;
     
     // allocate and set row pointer to correct places in block
-    rowPointers = static_cast<u32**> (png_malloc(png, height * (sizeof (u32*))));
-    for(uint i = 0; i < height; i++) {
+    rowPointers = static_cast<int**> (png_malloc(png, height * (sizeof (int*))));
+    for(int i = 0; i < height; i++) {
         rowPointers[i] = (buffer + i * width);
     }
     png_set_rows(png, info, reinterpret_cast<png_bytepp> (rowPointers));
@@ -73,7 +73,7 @@ static bool load(const char* path, FILE* file, u32* buffer, u32& maxWidth, u32&
     return true;
 }
 
-bool PNGReader::load(const char* path, u32* buffer, u32& maxWidth, u32& maxHeight) {
+bool PNGReader::load(const char* path, int* buffer, int& maxWidth, int& maxHeight) {
     FILE* file = fopen(path, "r");
     if(file == nullptr) {
         std::cout << "texture '" << path << "' cannot be read: " << strerror(errno) << "\n";

+ 1 - 3
client/utils/PNGReader.h

@@ -1,10 +1,8 @@
 #ifndef PNGREADER_H
 #define PNGREADER_H
 
-#include "common/utils/Types.h"
-
 namespace PNGReader {
-    bool load(const char* path, u32* buffer, u32& maxWidth, u32& maxHeight);
+    bool load(const char* path, int* buffer, int& maxWidth, int& maxHeight);
 }
 
 #endif

+ 3 - 3
common/block/Block.cpp

@@ -3,14 +3,14 @@
 Block::Block() : id(0), registry("") {
 }
 
-Block::Block(u16 id, const HashedString& registry, const BlockBuilder& builder) : id(id), registry(registry) {
+Block::Block(BlockId id, const BlockName& registry, const BlockBuilder& builder) : id(id), registry(registry) {
     (void) builder;
 }
 
-u16 Block::getId() const {
+BlockId Block::getId() const {
     return id;
 }
 
-const HashedString& Block::getRegistry() const {
+const BlockName& Block::getRegistry() const {
     return registry;
 }

+ 6 - 6
common/block/Block.h

@@ -1,19 +1,19 @@
 #ifndef BLOCK_H
 #define BLOCK_H
 
-#include "common/utils/HashedString.h"
+#include "common/block/BlockTypes.h"
 #include "common/block/BlockBuilder.h"
 
 class Block final {
 public:
     Block();
-    Block(u16 id, const HashedString& registry, const BlockBuilder& builder);
-    u16 getId() const;
-    const HashedString& getRegistry() const;
+    Block(BlockId id, const BlockName& registry, const BlockBuilder& builder);
+    BlockId getId() const;
+    const BlockName& getRegistry() const;
 
 private:
-    u16 id;
-    HashedString registry;
+    BlockId id;
+    BlockName registry;
 };
 
 #endif

+ 5 - 5
common/block/BlockRegistry.cpp

@@ -1,6 +1,6 @@
 #include "common/block/BlockRegistry.h"
 
-BlockRegistry::BlockRegistry() : registryToId("air", 0) {
+BlockRegistry::BlockRegistry() {
     add("air", BlockBuilder());
     add("stone", BlockBuilder());
     add("dirt", BlockBuilder());
@@ -14,16 +14,16 @@ void BlockRegistry::forEach(void(*f)(const Block&)) const {
 }
 
 void BlockRegistry::add(const char* registry, const BlockBuilder& builder) {
-    u16 id = blocks.getLength();
+    BlockId id = blocks.getLength();
     blocks.add(Block(id, registry, builder));
     registryToId.add(registry, id);
 }
 
-const Block& BlockRegistry::getBlock(const HashedString& registry) const {
-    return blocks[registryToId.search(registry)];
+const Block& BlockRegistry::getBlock(const BlockName& registry) const {
+    return blocks[registryToId.search(registry, 0)];
 }
 
-const Block& BlockRegistry::getBlock(u16 id) const {
+const Block& BlockRegistry::getBlock(BlockId id) const {
     if(id < blocks.getLength()) {
         return blocks[id];
     }

+ 7 - 7
common/block/BlockRegistry.h

@@ -1,25 +1,25 @@
 #ifndef BLOCKREGISTRY_H
 #define BLOCKREGISTRY_H
 
-#include "common/utils/List.h"
-#include "common/utils/HashedString.h"
-#include "common/utils/HashMap.h"
+#include "common/block/BlockTypes.h"
+#include "gaming-core/utils/List.h"
+#include "gaming-core/utils/HashMap.h"
 #include "common/block/Block.h"
 
 class BlockRegistry final {
 public:
     BlockRegistry();
     void forEach(void (*f) (const Block&)) const;
-    const Block& getBlock(const HashedString& registry) const;
-    const Block& getBlock(u16 id) const;
+    const Block& getBlock(const BlockName& registry) const;
+    const Block& getBlock(BlockId id) const;
 
 private:
     void add(const char* registry, const BlockBuilder& builder);
 
-    static constexpr uint MAX_BLOCKS = 4096;
+    static constexpr int MAX_BLOCKS = 4096;
 
     List<Block, MAX_BLOCKS> blocks;
-    HashMap<HashedString, u16, MAX_BLOCKS> registryToId;
+    HashMap<BlockName, BlockId, MAX_BLOCKS> registryToId;
 };
 
 #endif

+ 11 - 0
common/block/BlockTypes.h

@@ -0,0 +1,11 @@
+#ifndef BLOCKTYPES_H
+#define BLOCKTYPES_H
+
+#include "gaming-core/utils/StringBuffer.h"
+
+typedef StringBuffer<32> BlockName;
+typedef unsigned short BlockId;
+
+static_assert(sizeof(BlockId) == 2, "size of block id must be 2 bytes");
+
+#endif

+ 12 - 12
common/network/Packet.cpp

@@ -11,15 +11,15 @@ Packet::~Packet() {
 }
 
 bool Packet::hasData() const {
-    return readIndex < packet->dataLength;
+    return readIndex < static_cast<int>(packet->dataLength);
 }
 
 bool Packet::hasError() const {
     return error;
 }
 
-void Packet::read(void* buffer, uint length) {
-    if(readIndex + length > packet->dataLength) {
+void Packet::read(void* buffer, int length) {
+    if(readIndex + length > static_cast<int>(packet->dataLength)) {
         error = true;
         return;
     }
@@ -27,22 +27,22 @@ void Packet::read(void* buffer, uint length) {
     readIndex += length;
 }
 
-u8 Packet::readU8() {
-    u8 uc;
-    read(&uc, sizeof (u8));
+Packet::int8 Packet::read8() {
+    int8 uc;
+    read(&uc, sizeof (int8));
     return uc;
 }
 
-u16 Packet::readU16() {
-    u16 us;
-    read(&us, sizeof (u16));
+Packet::int16 Packet::read16() {
+    int16 us;
+    read(&us, sizeof (int16));
     us = ntohs(us);
     return us;
 }
 
-u32 Packet::readU32() {
-    u32 ui;
-    read(&ui, sizeof (u32));
+Packet::int32 Packet::read32() {
+    int32 ui;
+    read(&ui, sizeof (int32));
     ui = ntohl(ui);
     return ui;
 }

+ 17 - 12
common/network/Packet.h

@@ -3,29 +3,34 @@
 
 #include "common/enet/enet.h"
 
-#include "common/utils/Types.h"
-
 class Packet {
+    ENetPacket* packet;
+    int readIndex;
+    bool error;
+    
 public:
+    typedef char int8;
+    typedef short int16;
+    typedef int int32;
+
+    static_assert(sizeof (int8) == 1, "size of int8 must be 1 byte");
+    static_assert(sizeof (int16) == 2, "size of int16 must be 2 byte");
+    static_assert(sizeof (int32) == 4, "size of int32 must be 4 byte");
+
     Packet(ENetPacket* packet);
     ~Packet();
     Packet(const Packet&) = delete;
     Packet& operator=(const Packet&) = delete;
     Packet(Packet&&) = delete;
     Packet& operator=(Packet&&) = delete;
-    
+
     bool hasData() const;
     bool hasError() const;
-    
-    void read(void* buffer, uint length);
-    u8 readU8();
-    u16 readU16();
-    u32 readU32();
 
-private:
-    ENetPacket* packet;
-    uint readIndex;
-    bool error;
+    void read(void* buffer, int length);
+    int8 read8();
+    int16 read16();
+    int32 read32();
 };
 
 #endif

+ 0 - 59
common/utils/Array.h

@@ -1,59 +0,0 @@
-#ifndef ARRAY_H
-#define ARRAY_H
-
-#include "common/utils/Types.h"
-
-template<typename T, uint N>
-class Array final {
-public:
-
-    Array() {
-    }
-
-    Array(const T& t) {
-        for(uint i = 0; i < N; i++) {
-            data[i] = t;
-        }
-    }
-
-    const T& operator[](uint index) const {
-        return data[index];
-    }
-
-    T& operator[](uint index) {
-        return data[index];
-    }
-
-    const T* operator+(uint index) const {
-        return data + index;
-    }
-
-    T* operator+(uint index) {
-        return data + index;
-    }
-
-    T* begin() {
-        return data;
-    }
-
-    const T* begin() const {
-        return data;
-    }
-
-    T* end() {
-        return data + N;
-    }
-
-    const T* end() const {
-        return data + N;
-    }
-
-    uint getLength() const {
-        return N;
-    }
-
-private:
-    T data[N];
-};
-
-#endif

+ 0 - 97
common/utils/HashMap.h

@@ -1,97 +0,0 @@
-#ifndef HASHMAP_H
-#define HASHMAP_H
-
-#include "common/utils/Types.h"
-
-template<typename K, typename V, uint L>
-class HashMap final {
-public:
-
-    HashMap(K emptyKey, V emptyValue) : entries(0), emptyKey(emptyKey), emptyValue(emptyValue) {
-        for(uint i = 0; i < LENGTH; i++) {
-            data[i].key = emptyKey;
-            data[i].value = emptyValue;
-        }
-    }
-
-    static constexpr uint getCapacity() {
-        return LENGTH;
-    }
-
-    void add(const K key, const V value) {
-        if(entries >= L) {
-            return;
-        }
-        uint hash = hashCode(key) % LENGTH;
-        while(true) {
-            if(data[hash].key == key) {
-                data[hash].value = value;
-                return;
-            } else if(data[hash].key == emptyKey) {
-                data[hash].key = key;
-                data[hash].value = value;
-                entries++;
-                return;
-            }
-            hash = (hash + 1) % LENGTH;
-        }
-    }
-
-    V search(const K key) const {
-        uint hash = hashCode(key) % LENGTH;
-        while(true) {
-            if(data[hash].key == key) {
-                return data[hash].value;
-            } else if(data[hash].key == emptyKey) {
-                return emptyValue;
-            }
-            hash = (hash + 1) % LENGTH;
-        }
-    }
-
-    void forEach(void (*f)(const K&, V&)) {
-        for(uint i = 0; i < LENGTH; i++) {
-            if(data[i].key != emptyKey) {
-                f(data[i].key, data[i].value);
-            }
-        }
-    }
-
-private:
-
-    static constexpr uint getLength() {
-        constexpr uint SIZE_TABLE[] = {
-            2, 3, 7, 11, 23, 43, 89, 173, 347, 683, 1367, 2731, 5471, 10937, 21851, 43691, 87383, 174763, 349529, 699053,
-            1398107, 2796203, 5592407, 11184829, 22369661, 44739259, 89478503, 178956983, 357913951, 715827883, 1431655777,
-            2863311551
-        };
-        uint i = 0;
-        while(SIZE_TABLE[i] < L) {
-            i++;
-        }
-        return SIZE_TABLE[i];
-    }
-
-    template<typename H>
-    uint hashCode(const H& h) const {
-        return h.hashCode();
-    }
-
-    uint hashCode(const uint& h) const {
-        return h;
-    }
-
-    static constexpr uint LENGTH = getLength();
-
-    uint entries;
-    K emptyKey;
-    V emptyValue;
-
-    struct KeyValuePair {
-        K key;
-        V value;
-    };
-    KeyValuePair data[LENGTH];
-};
-
-#endif

+ 0 - 29
common/utils/HashedString.cpp

@@ -1,29 +0,0 @@
-#include "common/utils/HashedString.h"
-
-HashedString::HashedString() : length(0), hash(0) {
-    data[length] = '\0';
-}
-
-HashedString::HashedString(const char* str) : length(0), hash(0) {
-    for(; length < LENGTH - 1 && str[length] != '\0'; length++) {
-        data[length] = str[length];
-        hash = hash * 257 + str[length];
-    }
-    data[length] = '\0';
-}
-
-bool HashedString::operator==(const HashedString& other) const {
-    return hash == other.hash && length == other.length;
-}
-
-bool HashedString::operator!=(const HashedString& other) const {
-    return !(*this == other);
-}
-
-HashedString::operator const char*() const {
-    return data;
-}
-
-u32 HashedString::hashCode() const {
-    return hash;
-}

+ 0 - 24
common/utils/HashedString.h

@@ -1,24 +0,0 @@
-#ifndef HASHEDSTRING_H
-#define HASHEDSTRING_H
-
-#include "common/utils/Types.h"
-
-class HashedString final {
-public:
-    HashedString();
-    HashedString(const char* str);
-
-    bool operator==(const HashedString& other) const;
-    bool operator!=(const HashedString& other) const;
-    operator const char*() const;
-
-    u32 hashCode() const;
-
-private:
-    static constexpr uint LENGTH = 32 - sizeof (u8) - sizeof (u32);
-    char data[LENGTH];
-    u8 length;
-    u32 hash;
-};
-
-#endif

+ 0 - 67
common/utils/List.h

@@ -1,67 +0,0 @@
-#ifndef LIST_H
-#define LIST_H
-
-#include "common/utils/Types.h"
-
-template<typename T, uint L>
-class List final {
-public:
-
-    List() : entries(0) {
-    }
-
-    List& add(const T& t) {
-        if(entries >= L) {
-            return *this;
-        }
-        data[entries++] = t;
-        return *this;
-    }
-
-    List& clear() {
-        entries = 0;
-        return *this;
-    }
-
-    uint getLength() const {
-        return entries;
-    }
-
-    uint getCapacity() const {
-        return L;
-    }
-
-    T& operator[](uint index) {
-        return data[index];
-    }
-
-    const T& operator[](uint index) const {
-        return data[index];
-    }
-
-    const T* getData() {
-        return data;
-    }
-
-    T* begin() {
-        return data;
-    }
-
-    const T* begin() const {
-        return data;
-    }
-
-    T* end() {
-        return data + entries;
-    }
-
-    const T* end() const {
-        return data + entries;
-    }
-
-private:
-    uint entries;
-    T data[L];
-};
-
-#endif

+ 0 - 30
common/utils/Random.cpp

@@ -1,30 +0,0 @@
-#include <chrono>
-
-#include "common/utils/Random.h"
-
-Random::Random() : seed(std::chrono::steady_clock::now().time_since_epoch().count()) {
-}
-
-Random::Random(u64 seed) : seed(seed) {
-}
-
-u32 Random::next() {
-    return nextSeed() >> 24;
-}
-
-u32 Random::next(uint bound) {
-    return next() % bound;
-}
-
-float Random::nextFloat() {
-    return next() * (1.0f / (0xFFFFFF + 1.0f));
-}
-
-float Random::nextFloat(float scale) {
-    return (nextFloat() - 0.5f) * 2.0f * scale;
-}
-
-u64 Random::nextSeed() {
-    seed = (seed * 0x5DEECE66DL + 0xBL) & 0xFFFFFFFFFFFF;
-    return seed;
-}

+ 0 - 22
common/utils/Random.h

@@ -1,22 +0,0 @@
-#ifndef RANDOM_H
-#define RANDOM_H
-
-#include "common/utils/Types.h"
-
-class Random {
-public:
-    Random();
-    Random(u64 seed);
-
-    u32 next();
-    u32 next(uint bound);
-    float nextFloat();
-    float nextFloat(float scale);
-
-private:
-    u64 nextSeed();
-
-    u64 seed;
-};
-
-#endif

+ 0 - 31
common/utils/RingBuffer.h

@@ -1,31 +0,0 @@
-#ifndef RINGBUFFER_H
-#define RINGBUFFER_H
-
-#include "common/utils/Array.h"
-
-template<typename T, uint N>
-class RingBuffer final {
-public:
-
-    void write(const T& t) {
-        data[writeIndex] = t;
-        writeIndex = (writeIndex + 1) % N;
-    }
-
-    bool canRead() const {
-        return writeIndex != readIndex;
-    }
-
-    T read() {
-        T& t = data[readIndex];
-        readIndex = (readIndex + 1) % N;
-        return t;
-    }
-
-private:
-    Array<T, N> data;
-    uint writeIndex = 0;
-    uint readIndex = 0;
-};
-
-#endif

+ 0 - 44
common/utils/SplitString.cpp

@@ -1,44 +0,0 @@
-#include "common/utils/SplitString.h"
-
-SplitString::SplitString(const char* str) : entries(0) {
-    for(uint i = 0; str[i] != '\0'; i++) {
-        if(str[i] == '"') {
-            if(i >= 1 && str[i - 1] != ' ') {
-                return;
-            }
-            data.append('"');
-            i++;
-            while(str[i] != '"') {
-                if(str[i] == '\0') {
-                    return;
-                }
-                data.append(str[i++]);
-            }
-            if(str[i + 1] != '\0' && str[i + 1] != ' ') {
-                return;
-            }
-            data.append('\0');
-            continue;
-        }
-        data.append(str[i] == ' ' ? '\0' : str[i]);
-    }
-    uint last = 0;
-    for(uint i = 0; i < data.getLength() + 1; i++) {
-        if(data[i] != '\0' && data[i] != '"') {
-            continue;
-        }
-        if(i - last > 0 || (i >= 1 && data[i - 1] == '"')) {
-            starts[entries++] = last;
-        }
-        last = i + 1;
-    }
-}
-
-uint SplitString::getLength() const {
-    return entries;
-}
-
-const char* SplitString::operator[](uint index) const {
-    return data + starts[index];
-}
-

+ 0 - 19
common/utils/SplitString.h

@@ -1,19 +0,0 @@
-#ifndef SPLITSTRING_H
-#define SPLITSTRING_H
-
-#include "common/utils/String.h"
-
-class SplitString final {
-public:
-    SplitString(const char* str);
-    
-    uint getLength() const;
-    const char* operator[](uint index) const;
-
-private:
-    String data;
-    uint entries;
-    u8 starts[String::MAX_LENGTH];
-};
-
-#endif

+ 0 - 105
common/utils/String.cpp

@@ -1,105 +0,0 @@
-#include <cstring>
-#include <cstdio>
-
-#include "common/utils/String.h"
-
-String::String() : length(0) {
-    data[0] = '\0';
-}
-
-String::String(const char* str) : length(0) {
-    for(; length < MAX_LENGTH - 1 && str[length] != '\0'; length++) {
-        data[length] = str[length];
-    }
-    data[length] = '\0';
-}
-
-String::String(const String& other) : length(other.length) {
-    memcpy(data, other.data, length + 1);
-}
-
-String& String::operator=(const String& other) {
-    if(this != &other) {
-        length = other.length;
-        memcpy(data, other.data, length + 1);
-    }
-    return *this;
-}
-
-bool String::operator==(const String& other) const {
-    return length == other.length && strcmp(data, other.data) == 0;
-}
-
-bool String::operator!=(const String& other) const {
-    return !(*this == other);
-}
-
-String::operator const char*() const {
-    return data;
-}
-
-char String::operator[](uint index) const {
-    return data[index];
-}
-
-uint String::getLength() const {
-    return length;
-}
-
-String& String::append(const char* str) {
-    for(uint i = 0; length < MAX_LENGTH - 1 && str[i] != '\0'; length++, i++) {
-        data[length] = str[i];
-    }
-    data[length] = '\0';
-    return *this;
-}
-
-String& String::append(u8 u) {
-    return append(static_cast<s8>(u));
-}
-
-String& String::append(u16 u) {
-    return append("%hu", u);
-}
-
-String& String::append(u32 u) {
-    return append("%u", u);
-}
-
-String& String::append(u64 u) {
-    return append("%lu", u);
-}
-
-String& String::append(s8 c) {
-    if(length < MAX_LENGTH - 1) {
-        data[length++] = c;
-        data[length] = '\0';
-    }
-    return *this;
-}
-
-String& String::append(s16 s) {
-    return append("%hi", s);
-}
-
-String& String::append(s32 s) {
-    return append("%i", s);
-}
-
-String& String::append(s64 s) {
-    return append("%li", s);
-}
-
-String& String::append(float f) {
-    return append("%.2f", f);
-}
-
-String& String::append(bool b) {
-    return append(b ? "true" : "false");
-}
-
-String& String::clear() {
-    data[0] = '\0';
-    length = 0;
-    return *this;
-}

+ 0 - 54
common/utils/String.h

@@ -1,54 +0,0 @@
-#ifndef STRING_H
-#define STRING_H
-
-#include "common/utils/Types.h"
-
-class String final {
-public:
-    String();
-    String(const char* str);
-    String(const String& other);
-    String& operator=(const String& other);
-
-    bool operator==(const String& other) const;
-    bool operator!=(const String& other) const;
-    operator const char*() const;
-    char operator[](uint index) const;
-    uint getLength() const;
-
-    template<typename T>
-    String& append(const char* format, const T& t) {
-        uint left = MAX_LENGTH - length;
-        uint written = snprintf(data + length, left, format, t);
-        if(written < left) {
-            length += written;
-        } else {
-            length = MAX_LENGTH;
-        }
-        return *this;
-    }
-
-    String& append(const char* str);
-    
-    String& append(u8 u);
-    String& append(u16 u);
-    String& append(u32 u);
-    String& append(u64 u);
-    
-    String& append(s8 s);
-    String& append(s16 s);
-    String& append(s32 s);
-    String& append(s64 s);
-    
-    String& append(float f);
-    String& append(bool b);
-    
-    String& clear();
-    
-    static constexpr uint MAX_LENGTH = 255;
-private:
-    char data[MAX_LENGTH];
-    u8 length;
-};
-
-#endif

+ 0 - 26
common/utils/Types.h

@@ -1,26 +0,0 @@
-#ifndef TYPES_H
-#define TYPES_H
-
-typedef unsigned int uint;
-
-typedef unsigned char u8;
-typedef unsigned short u16;
-typedef unsigned int u32;
-typedef unsigned long u64;
-
-static_assert(sizeof(u8) == 1, "u8 is not 8 bit");
-static_assert(sizeof(u16) == 2, "u16 is not 16 bit");
-static_assert(sizeof(u32) == 4, "u32 is not 32 bit");
-static_assert(sizeof(u64) == 8, "u64 is not 64 bit");
-
-typedef char s8;
-typedef short s16;
-typedef int s32;
-typedef long s64;
-
-static_assert(sizeof(s8) == 1, "s8 is not 8 bit");
-static_assert(sizeof(s16) == 2, "s16 is not 16 bit");
-static_assert(sizeof(s32) == 4, "s32 is not 32 bit");
-static_assert(sizeof(s64) == 8, "s64 is not 64 bit");
-
-#endif

+ 13 - 14
common/world/HighMap.h

@@ -1,17 +1,16 @@
 #ifndef HIGHMAP_H
 #define HIGHMAP_H
 
-#include "common/utils/Types.h"
-#include "common/utils/Random.h"
+#include "gaming-core/utils/Random.h"
 
-template<uint W, uint H>
+template<int W, int H>
 class HighMap {
 public:
 
     HighMap() {
         Random r(0);
-        for(uint x = 0; x < W; x++) {
-            for(uint y = 0; y < H; y++) {
+        for(int x = 0; x < W; x++) {
+            for(int y = 0; y < H; y++) {
                 data[x][y] = r.nextFloat();
             }
         }
@@ -23,17 +22,17 @@ public:
 
     void smooth() {
         float oldNoice[W][H];
-        for(uint x = 0; x < W; x++) {
-            for(uint y = 0; y < H; y++) {
+        for(int x = 0; x < W; x++) {
+            for(int y = 0; y < H; y++) {
                 oldNoice[x][y] = data[x][y];
             }
         }
-        for(uint x = 0; x < W; x++) {
-            for(uint y = 0; y < H; y++) {
+        for(int x = 0; x < W; x++) {
+            for(int y = 0; y < H; y++) {
                 float sum = 0.0f;
-                for(uint mx = 0; mx <= 2; mx++) {
-                    for(uint my = 0; my <= 2; my++) {
-                        sum += oldNoice[(x + mx - 1) % W][(y + my - 1) % H];
+                for(int mx = -1; mx <= 1; mx++) {
+                    for(int my = -1; my <= 1; my++) {
+                        sum += oldNoice[(x + mx + W) % W][(y + my + H) % H];
                     }
                 }
                 data[x][y] = sum / 9.0f;
@@ -41,8 +40,8 @@ public:
         }
     }
 
-    uint getHeight(uint x, uint y, uint max) const {
-        return (uint) (data[x][y] * max);
+    int getHeight(int x, int y, int max) const {
+        return (data[x][y] * max);
     }
 
 private:

+ 8 - 8
common/world/World.cpp

@@ -1,28 +1,28 @@
 #include "common/world/World.h"
-#include "common/utils/Random.h"
+#include "gaming-core/utils/Random.h"
 #include "common/world/HighMap.h"
 
 World::World(const BlockRegistry& blockRegistry) : blockRegistry(blockRegistry) {
     Block air = blockRegistry.getBlock("air");
     Block stone = blockRegistry.getBlock("stone");
     HighMap<WORLD_SIZE, WORLD_SIZE> map;
-    for(uint x = 0; x < WORLD_SIZE; x++) {
-        for(uint z = 0; z < WORLD_SIZE; z++) {
-            uint height = map.getHeight(x, z, WORLD_SIZE);
-            for(uint y = 0; y < height; y++) {
+    for(int x = 0; x < WORLD_SIZE; x++) {
+        for(int z = 0; z < WORLD_SIZE; z++) {
+            int height = map.getHeight(x, z, WORLD_SIZE);
+            for(int y = 0; y < height; y++) {
                 setBlock(x, y, z, stone);
             }
-            for(uint y = height; y < WORLD_SIZE; y++) {
+            for(int y = height; y < WORLD_SIZE; y++) {
                 setBlock(x, y, z, air);
             }
         }
     }
 }
 
-void World::setBlock(uint x, uint y, uint z, const Block& block) {
+void World::setBlock(int x, int y, int z, const Block& block) {
     blocks[x & BITMASK][y & BITMASK][z & BITMASK] = block.getId();
 }
 
-const Block& World::getBlock(uint x, uint y, uint z) const {
+const Block& World::getBlock(int x, int y, int z) const {
     return blockRegistry.getBlock(blocks[x & BITMASK][y & BITMASK][z & BITMASK]);
 }

+ 5 - 5
common/world/World.h

@@ -6,16 +6,16 @@
 class World final {
 public:
     World(const BlockRegistry& blockRegistry);
-    void setBlock(uint x, uint y, uint z, const Block& block);
-    const Block& getBlock(uint x, uint y, uint z) const;
+    void setBlock(int x, int y, int z, const Block& block);
+    const Block& getBlock(int x, int y, int z) const;
     
-    static constexpr uint WORLD_SIZE = 32;
+    static constexpr int WORLD_SIZE = 32;
 
 private:
-    static constexpr uint BITMASK = WORLD_SIZE - 1;
+    static constexpr int BITMASK = WORLD_SIZE - 1;
 
     const BlockRegistry& blockRegistry;
-    u16 blocks[WORLD_SIZE][WORLD_SIZE][WORLD_SIZE];
+    BlockId blocks[WORLD_SIZE][WORLD_SIZE][WORLD_SIZE];
 };
 
 #endif

+ 1 - 1
gaming-core

@@ -1 +1 @@
-Subproject commit 2520bce011ef46b775b701f024259929351dfd6d
+Subproject commit ee573a1f51c72c81b7de7e1aa0e998eb41dbd2d8

+ 3 - 12
meson.build

@@ -5,10 +5,7 @@ sourcesCommon = [
     'common/block/BlockBuilder.cpp', 
     'common/block/Block.cpp', 
     'common/block/BlockRegistry.cpp', 
-    'common/utils/HashedString.cpp', 
-    'common/utils/String.cpp', 
-    'common/utils/SplitString.cpp', 
-    'common/utils/Random.cpp', 
+    'gaming-core/utils/Random.cpp', 
     'common/world/World.cpp', 
     'gaming-core/math/Vector.cpp']
 
@@ -51,16 +48,10 @@ sourcesClient = ['client/Main.cpp',
     'client/rendering/wrapper/GLWrapper.cpp',
     'client/rendering/Renderer.cpp',
     'client/rendering/renderer/WorldRenderer.cpp',
-    'client/rendering/NormalTexture.cpp',
     'client/rendering/Vertex.cpp',
-    'client/rendering/Triangle.cpp',
-    'client/rendering/Lines.cpp']
+    'client/rendering/Triangle.cpp']
 
-sourcesTest = ['tests/Main.cpp',
-    'common/utils/String.cpp',
-    'common/utils/SplitString.cpp',
-    'common/utils/HashedString.cpp',
-    'common/utils/Random.cpp']
+sourcesTest = ['tests/Main.cpp']
 
 c_compiler = meson.get_compiler('cpp')
 readline = c_compiler.find_library('readline', required: true)

+ 6 - 10
server/Clock.cpp

@@ -6,9 +6,9 @@
 Clock::Clock() : last(getNanos()), index(0), sum(0), time(0) {
 }
 
-u64 Clock::update() {
-    index = (index + 1) & (length - 1);
-    u64 current = getNanos();
+Clock::Nanos Clock::update() {
+    index = (index + 1) & (LENGTH - 1);
+    Nanos current = getNanos();
     sum -= time[index];
     time[index] = current - last;
     sum += time[index];
@@ -16,18 +16,14 @@ u64 Clock::update() {
     return time[index];
 }
 
-u64 Clock::getLength() const {
-    return length;
-}
-
 float Clock::getUpdatesPerSecond() const {
-    return length * (1000000000.0f / sum);
+    return LENGTH * (1000000000.0f / sum);
 }
 
-u64 Clock::getNanos() const {
+Clock::Nanos Clock::getNanos() const {
     return std::chrono::high_resolution_clock::now().time_since_epoch().count();
 }
 
-void Clock::wait(u64 nanos) const {
+void Clock::wait(Nanos nanos) const {
     std::this_thread::sleep_for(std::chrono::nanoseconds(nanos));
 }

+ 16 - 14
server/Clock.h

@@ -1,26 +1,28 @@
 #ifndef CLOCK_H
 #define CLOCK_H
 
-#include "common/utils/Types.h"
-#include "common/utils/Array.h"
+#include "gaming-core/utils/Types.h"
+#include "gaming-core/utils/Array.h"
+
+struct Clock final {
+    typedef int64 Nanos;
+    
+private:
+    static constexpr int BITS = 7;
+    static constexpr int LENGTH = 1 << BITS;
+    Nanos last;
+    int index;
+    Nanos sum;
+    Array<Nanos, LENGTH> time;
 
-class Clock final {
 public:
     Clock();
-    u64 update();
-    u64 getLength() const;
+    Nanos update();
     float getUpdatesPerSecond() const;
-    void wait(u64 nanos) const;
+    void wait(Nanos nanos) const;
 
 private:
-    u64 getNanos() const;
-    
-    static constexpr u64 bits = 7;
-    static constexpr u64 length = 1 << bits;
-    u64 last;
-    u64 index;
-    s64 sum;
-    Array<u64, length> time;
+    Nanos getNanos() const;
 };
 
 #endif

+ 6 - 5
server/GameServer.cpp

@@ -1,5 +1,6 @@
 #include <iostream>
 
+#include "server/commands/CommandTypes.h"
 #include "server/GameServer.h"
 #include "server/commands/ConsoleEditor.h"
 #include "server/commands/CommandManager.h"
@@ -11,9 +12,9 @@ void GameServer::tick() {
 }
 
 void GameServer::handleCommands(ServerCommands& serverCommands) {
-    String s;
-    while(ConsoleEditor::readCommand(s)) {
-        commandManager.execute(serverCommands, s);
+    RawCommand rawCommand;
+    while(ConsoleEditor::readCommand(rawCommand)) {
+        commandManager.execute(serverCommands, rawCommand);
     }
 }
 
@@ -29,9 +30,9 @@ void GameServer::onClientConnect(Client& client) {
 
 void GameServer::onClientPackage(Client& client, Packet& packet) {
     (void) client;
-    String s;
+    StringBuffer<256> s;
     while(packet.hasData()) {
-        s.append(packet.readU8());
+        s.append(packet.read8());
     }
     std::cout << "Packet: " << s << "\n";
 }

+ 3 - 3
server/Main.cpp

@@ -3,7 +3,6 @@
 #include "server/GameServer.h"
 #include "commands/ConsoleEditor.h"
 
-static const u64 NANOS_PER_TICK = 50000000;
 
 int main() {
     Server server(11196);
@@ -16,7 +15,8 @@ int main() {
     ServerCommands serverCommands;
     
     Clock clock;
-    u64 lag = 0;
+    constexpr Clock::Nanos NANOS_PER_TICK = 50000000;
+    Clock::Nanos lag = 0;
     while(serverCommands.isRunning()) {
         lag += clock.update();
         while(lag >= NANOS_PER_TICK) {
@@ -28,7 +28,7 @@ int main() {
             gameServer.tick();
             ConsoleEditor::printLine();
         }
-        u64 waitNanos = NANOS_PER_TICK - lag;
+        Clock::Nanos waitNanos = NANOS_PER_TICK - lag;
         if(waitNanos > 300000) {
             clock.wait(waitNanos);
         }

+ 9 - 9
server/commands/CommandManager.cpp

@@ -2,34 +2,34 @@
 
 #include "server/commands/CommandManager.h"
 
-static void commandTest(ServerCommands&, const SplitString& args) {
+static void commandTest(ServerCommands&, const CommandArguments& args) {
     std::cout << "test command" << std::endl;
-    for(size_t i = 0; i < args.getLength(); i++) {
+    for(int i = 0; i < args.getLength(); i++) {
         std::cout << " - " << args[i] << std::endl;
     }
 }
 
-static void commandStop(ServerCommands& sc, const SplitString&) {
+static void commandStop(ServerCommands& sc, const CommandArguments&) {
     sc.stop();
 }
 
-static void commandEmpty(ServerCommands&, const SplitString&) {
+static void commandEmpty(ServerCommands&, const CommandArguments&) {
 }
 
-CommandManager::CommandManager() : commands("", commandEmpty) {
+CommandManager::CommandManager() {
     commands.add("test", commandTest);
     commands.add("stop", commandStop);
 }
 
-void CommandManager::execute(ServerCommands& sc, const String& rawCommand) {
-    SplitString args(rawCommand);
+void CommandManager::execute(ServerCommands& sc, const RawCommand& rawCommand) {
+    CommandArguments args(rawCommand);
     if(args.getLength() == 0) {
         std::cout << "Invalid command syntax: '" << rawCommand << "'\n";
         return;
     }
 
-    HashedString command(args[0]);
-    Command c = commands.search(command);
+    CommandName command(args[0]);
+    Command c = commands.search(command, commandEmpty);
     if(c == commandEmpty) {
         std::cout << "Unknown command: '" << command << "'" << std::endl;
         return;

+ 5 - 7
server/commands/CommandManager.h

@@ -2,21 +2,19 @@
 #define COMMANDMANAGER_H
 
 #include "server/commands/ServerCommands.h"
-#include "common/utils/String.h"
-#include "common/utils/SplitString.h"
-#include "common/utils/HashMap.h"
-#include "common/utils/HashedString.h"
+#include "server/commands/CommandTypes.h"
+#include "gaming-core/utils/HashMap.h"
 
 class CommandManager {
 public:
     CommandManager();
 
-    void execute(ServerCommands& sc, const String& rawCommand);
+    void execute(ServerCommands& sc, const RawCommand& rawCommand);
     
 private:
-    typedef void (*Command) (ServerCommands&, const SplitString&);
+    typedef void (*Command) (ServerCommands&, const CommandArguments&);
 
-    HashMap<HashedString, Command, 16> commands;
+    HashMap<CommandName, Command, 16> commands;
 };
 
 #endif

+ 11 - 0
server/commands/CommandTypes.h

@@ -0,0 +1,11 @@
+#ifndef COMMANDTYPES_H
+#define COMMANDTYPES_H
+
+#include "gaming-core/utils/StringBuffer.h"
+#include "gaming-core/utils/SplitString.h"
+
+typedef StringBuffer<32> CommandName;
+typedef StringBuffer<256> RawCommand;
+typedef SplitString<256> CommandArguments;
+
+#endif

+ 3 - 3
server/commands/ConsoleEditor.cpp

@@ -8,7 +8,7 @@
 #include <unistd.h>
 
 #include "server/commands/ConsoleEditor.h"
-#include "common/utils/RingBuffer.h"
+#include "gaming-core/utils/RingBuffer.h"
 
 #include <iostream>
 
@@ -63,11 +63,11 @@ void ConsoleEditor::printLine() {
     rl_forced_update_display();
 }
 
-bool ConsoleEditor::readCommand(String& buffer) {
+bool ConsoleEditor::readCommand(RawCommand& buffer) {
     std::lock_guard<std::mutex> lg(Setup::instance.queueMutex);
     if(Setup::instance.queue.canRead()) {
         char* data = Setup::instance.queue.read();
-        buffer = data;
+        buffer.clear().append(static_cast<const char*>(data));
         free(data);
         return true;
     }

+ 2 - 2
server/commands/ConsoleEditor.h

@@ -1,12 +1,12 @@
 #ifndef COMMANDEDITOR_H
 #define COMMANDEDITOR_H
 
-#include "common/utils/String.h"
+#include "server/commands/CommandTypes.h"
 
 namespace ConsoleEditor {
     void clearPrintLine();
     void printLine();
-    bool readCommand(String& buffer);
+    bool readCommand(RawCommand& buffer);
 }
 
 #endif

+ 1 - 1
server/commands/ServerCommands.cpp

@@ -1,4 +1,4 @@
-#include "ServerCommands.h"
+#include "server/commands/ServerCommands.h"
 
 ServerCommands::ServerCommands() : running(true) {
 }

+ 6 - 6
server/network/Server.cpp

@@ -5,7 +5,7 @@
 #include "server/network/Server.h"
 #include "common/network/Packet.h"
 
-Server::Server(u16 port) : server(nullptr) {
+Server::Server(Port port) : server(nullptr) {
     if(enet_initialize() != 0) {
         std::cout << "an error occurred while initializing ENet\n";
         return;
@@ -13,7 +13,7 @@ Server::Server(u16 port) : server(nullptr) {
 
     ENetAddress address;
     address.host = ENET_HOST_ANY; // localhost
-    static_assert(sizeof (enet_uint16) == sizeof (u16), "enet_uint16 and u16 are not of equal size");
+    static_assert(sizeof (enet_uint16) == sizeof (Port), "enet_uint16 and u16 are not of equal size");
     address.port = port;
 
     server = enet_host_create(&address, clients.getLength(), 2, 0, 0);
@@ -53,7 +53,7 @@ void Server::consumeEvents(GameServer& gameServer) {
 
 void Server::onConnect(ENetEvent& event, GameServer& gameServer) {
     event.peer->data = nullptr;
-    uint index = getFreeIndex();
+    int index = getFreeIndex();
     std::cout << "INDEX: " << index << "\n";
     if(index >= clients.getLength()) {
         Client c;
@@ -62,7 +62,7 @@ void Server::onConnect(ENetEvent& event, GameServer& gameServer) {
         return;
     }
     clients[index].connect(event.peer);
-    event.peer->data = (clients + index);
+    event.peer->data = &(clients[index]);
     gameServer.onClientConnect(clients[index]);
 }
 
@@ -86,8 +86,8 @@ void Server::onDisconnect(ENetEvent& event, GameServer& gameServer) {
     }
 }
 
-uint Server::getFreeIndex() const {
-    for(uint i = 0; i < clients.getLength(); i++) {
+int Server::getFreeIndex() const {
+    for(int i = 0; i < clients.getLength(); i++) {
         if(clients[i].isDisconnected()) {
             return i;
         }

+ 6 - 4
server/network/Server.h

@@ -3,14 +3,16 @@
 
 #include "common/enet/enet.h"
 
-#include "common/utils/Types.h"
+#include "gaming-core/utils/Types.h"
 #include "server/GameServer.h"
-#include "common/utils/Array.h"
+#include "gaming-core/utils/Array.h"
 #include "server/network/Client.h"
 
 class Server final {
 public:
-    Server(u16 port);
+    typedef uint16 Port;
+    
+    Server(Port port);
     ~Server();
     Server(const Server&) = delete;
     Server& operator=(const Server&) = delete;
@@ -24,7 +26,7 @@ private:
     void onConnect(ENetEvent& event, GameServer& gameServer);
     void onPackage(ENetEvent& event, GameServer& gameServer);
     void onDisconnect(ENetEvent& event, GameServer& gameServer);
-    uint getFreeIndex() const;
+    int getFreeIndex() const;
     
     ENetHost* server;
     Array<Client, 50> clients;

+ 1 - 91
tests/Main.cpp

@@ -1,96 +1,6 @@
 #include <iostream>
 
-#include "common/utils/SplitString.h"
-#include "common/utils/Array.h"
-#include "common/utils/List.h"
-#include "common/utils/HashedString.h"
-#include "common/utils/Random.h"
-
-typedef List<const char*, 16> StringList;
-
-const char* RED = "\033[0;31m";
-const char* GREEN = "\033[0;32m";
-
-uint tests = 0;
-uint successTests = 0;
-
-void finalizeTest() {
-    std::cout << ((successTests == tests) ? GREEN : RED);
-    std::cout << successTests << " / " << tests << " succeeded\n";
-    tests = 0;
-    successTests = 0;
-}
-
-template<typename T>
-void checkEqual(const T& wanted, const T& actual, const char* text) {
-    if(wanted == actual) {
-        tests++;
-        successTests++;
-        std::cout << GREEN << tests << ": " << text << "\n";
-    } else {
-        tests++;
-        std::cout << RED << tests << ": " << text << " - ";
-        std::cout << RED << "expected '" << wanted << "' got '" << actual << "'\n";
-    }
-}
-
-void checkCommandParser(const char* rawCommand, const StringList& result, const char* text) {
-    SplitString split(rawCommand);
-    checkEqual(result.getLength(), split.getLength(), text);
-    for(uint i = 0; i < result.getLength() && i < split.getLength(); i++) {
-        checkEqual(String(result[i]), String(split[i]), text);
-    }
-}
-
-void testCommandParser() {
-    StringList list;
-
-    list.clear().add("test");
-    checkCommandParser("test", list, "command without arguments");
-
-    list.clear().add("test").add("aaa");
-    checkCommandParser("test aaa", list, "command with one argument");
-
-    list.clear().add("test").add("aaa").add("bbbb");
-    checkCommandParser("test aaa bbbb", list, "command with two arguments");
-
-    list.clear().add("test").add("aaa").add("bbbb").add("ccccc");
-    checkCommandParser("test aaa bbbb ccccc", list, "command with three arguments");
-
-    list.clear().add("test");
-    checkCommandParser("test    ", list, "command with spaces");
-
-    list.clear().add("test").add("aaa").add("bbbb");
-    checkCommandParser("test  aaa   bbbb", list, "command with arguments and spaces");
-
-    list.clear().add("test").add("aaa bbbb");
-    checkCommandParser("test \"aaa bbbb\"", list, "command with one argument and quotation marks");
-
-    list.clear().add("test").add("aaa bbbb").add("ccc");
-    checkCommandParser("test \"aaa bbbb\" ccc", list, "command with two arguments and quotation marks");
-
-    list.clear().add("test").add("ddd").add("aaa bbbb").add("ccc");
-    checkCommandParser("test ddd \"aaa bbbb\" ccc", list, "command with tree arguments and quotation marks");
-
-    list.clear().add("test").add("");
-    checkCommandParser("test \"\"", list, "command with empty argument");
-
-    list.clear();
-    checkCommandParser("test \"", list, "command syntax exception 1");
-    checkCommandParser("test aaa\"", list, "command syntax exception 2");
-    checkCommandParser("test aaa\"bbb\"", list, "command syntax exception 3");
-    checkCommandParser("test aaa \"bbb\"ccc", list, "command syntax exception 4");
-
-    finalizeTest();
-}
-
-long getNanos() {
-    struct timespec time;
-    clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time);
-    return time.tv_nsec + time.tv_sec * 1000000000;
-}
-
 int main() {
-    //testCommandParser();
+    std::cout << "test\n";
     return 0;
 }